@agentage/extension 0.20.1 → 0.20.3

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 (120) hide show
  1. package/dist/auth/part-auth.js +4 -5
  2. package/dist/context/context.d.ts +0 -1
  3. package/dist/host/child-env.d.ts +11 -0
  4. package/dist/host/child-env.js +12 -0
  5. package/dist/host/{daemon/guard.js → guard.js} +1 -1
  6. package/dist/host/host-extension.js +1 -1
  7. package/dist/host/host-main.d.ts +1 -0
  8. package/dist/host/host-main.js +3 -0
  9. package/dist/host/index.d.ts +1 -5
  10. package/dist/host/index.js +1 -5
  11. package/dist/host/kit-shell.d.ts +1 -0
  12. package/dist/host/kit-shell.js +2 -0
  13. package/dist/host/serve-host.js +1 -1
  14. package/dist/internal/index.d.ts +29 -0
  15. package/dist/internal/index.js +30 -0
  16. package/dist/runtime/part-mounts.d.ts +0 -1
  17. package/dist/runtime/part-mounts.js +1 -1
  18. package/dist/runtime/run-part.js +0 -2
  19. package/dist/server/app.d.ts +0 -1
  20. package/dist/server/app.js +4 -5
  21. package/dist/tool/check.js +3 -0
  22. package/dist/tool/recipe.js +2 -2
  23. package/dist/tool/up/gateway.js +0 -3
  24. package/package.json +5 -1
  25. package/dist/host/daemon/add.d.ts +0 -11
  26. package/dist/host/daemon/add.js +0 -93
  27. package/dist/host/daemon/app-files.d.ts +0 -8
  28. package/dist/host/daemon/app-files.js +0 -34
  29. package/dist/host/daemon/app-header.d.ts +0 -2
  30. package/dist/host/daemon/app-header.js +0 -12
  31. package/dist/host/daemon/app-reload.d.ts +0 -10
  32. package/dist/host/daemon/app-reload.js +0 -18
  33. package/dist/host/daemon/child-files.d.ts +0 -20
  34. package/dist/host/daemon/child-files.js +0 -53
  35. package/dist/host/daemon/child.d.ts +0 -30
  36. package/dist/host/daemon/child.js +0 -126
  37. package/dist/host/daemon/cli-user-watch.d.ts +0 -9
  38. package/dist/host/daemon/cli-user-watch.js +0 -47
  39. package/dist/host/daemon/cli-user.d.ts +0 -2
  40. package/dist/host/daemon/cli-user.js +0 -42
  41. package/dist/host/daemon/daemon-files.d.ts +0 -20
  42. package/dist/host/daemon/daemon-files.js +0 -46
  43. package/dist/host/daemon/daemon-owner.d.ts +0 -1
  44. package/dist/host/daemon/daemon-owner.js +0 -32
  45. package/dist/host/daemon/daemon.d.ts +0 -19
  46. package/dist/host/daemon/daemon.js +0 -137
  47. package/dist/host/daemon/entries.d.ts +0 -21
  48. package/dist/host/daemon/entries.js +0 -24
  49. package/dist/host/daemon/gate.d.ts +0 -3
  50. package/dist/host/daemon/gate.js +0 -19
  51. package/dist/host/daemon/health-routes.d.ts +0 -18
  52. package/dist/host/daemon/health-routes.js +0 -75
  53. package/dist/host/daemon/host-token.d.ts +0 -6
  54. package/dist/host/daemon/host-token.js +0 -28
  55. package/dist/host/daemon/installation.d.ts +0 -35
  56. package/dist/host/daemon/installation.js +0 -90
  57. package/dist/host/daemon/installer-call.d.ts +0 -21
  58. package/dist/host/daemon/installer-call.js +0 -48
  59. package/dist/host/daemon/json-file.d.ts +0 -6
  60. package/dist/host/daemon/json-file.js +0 -90
  61. package/dist/host/daemon/lane.d.ts +0 -9
  62. package/dist/host/daemon/lane.js +0 -24
  63. package/dist/host/daemon/last-words.d.ts +0 -2
  64. package/dist/host/daemon/last-words.js +0 -28
  65. package/dist/host/daemon/limits.d.ts +0 -16
  66. package/dist/host/daemon/limits.js +0 -31
  67. package/dist/host/daemon/ops.d.ts +0 -12
  68. package/dist/host/daemon/ops.js +0 -94
  69. package/dist/host/daemon/patch-values.d.ts +0 -6
  70. package/dist/host/daemon/patch-values.js +0 -39
  71. package/dist/host/daemon/pending.d.ts +0 -15
  72. package/dist/host/daemon/pending.js +0 -18
  73. package/dist/host/daemon/proxy.d.ts +0 -11
  74. package/dist/host/daemon/proxy.js +0 -106
  75. package/dist/host/daemon/queue.d.ts +0 -3
  76. package/dist/host/daemon/queue.js +0 -27
  77. package/dist/host/daemon/redact-stream.d.ts +0 -4
  78. package/dist/host/daemon/redact-stream.js +0 -24
  79. package/dist/host/daemon/reload-marker.d.ts +0 -8
  80. package/dist/host/daemon/reload-marker.js +0 -57
  81. package/dist/host/daemon/reload.d.ts +0 -10
  82. package/dist/host/daemon/reload.js +0 -72
  83. package/dist/host/daemon/restart.d.ts +0 -14
  84. package/dist/host/daemon/restart.js +0 -59
  85. package/dist/host/daemon/routes.d.ts +0 -6
  86. package/dist/host/daemon/routes.js +0 -101
  87. package/dist/host/daemon/run-lock.d.ts +0 -1
  88. package/dist/host/daemon/run-lock.js +0 -15
  89. package/dist/host/daemon/seal-reach.d.ts +0 -2
  90. package/dist/host/daemon/seal-reach.js +0 -38
  91. package/dist/host/daemon/seal.d.ts +0 -20
  92. package/dist/host/daemon/seal.js +0 -93
  93. package/dist/host/daemon/shell-events.d.ts +0 -9
  94. package/dist/host/daemon/shell-events.js +0 -36
  95. package/dist/host/daemon/shell-routes.d.ts +0 -29
  96. package/dist/host/daemon/shell-routes.js +0 -68
  97. package/dist/host/daemon/sign-in-page.d.ts +0 -3
  98. package/dist/host/daemon/sign-in-page.js +0 -30
  99. package/dist/host/daemon/start-checks.d.ts +0 -6
  100. package/dist/host/daemon/start-checks.js +0 -29
  101. package/dist/host/daemon/stopping.d.ts +0 -10
  102. package/dist/host/daemon/stopping.js +0 -28
  103. package/dist/host/daemon/supervisor.d.ts +0 -59
  104. package/dist/host/daemon/supervisor.js +0 -107
  105. package/dist/host/daemon/write-all.d.ts +0 -8
  106. package/dist/host/daemon/write-all.js +0 -45
  107. package/dist/shell/dist/index.html +0 -49
  108. package/dist/shell/dist/shell.css +0 -2
  109. package/dist/shell/dist/shell.js +0 -69
  110. package/dist/shell/dist/vendor/app.js +0 -1
  111. package/dist/shell/dist/vendor/chunk-AOJ3DQEL.js +0 -14
  112. package/dist/shell/dist/vendor/chunk-LW5HXGAJ.js +0 -14
  113. package/dist/shell/dist/vendor/chunk-PQJPUKWH.js +0 -14
  114. package/dist/shell/dist/vendor/chunk-SQE76S5B.js +0 -1
  115. package/dist/shell/dist/vendor/jsx-runtime.js +0 -1
  116. package/dist/shell/dist/vendor/react-dom-client.js +0 -33
  117. package/dist/shell/dist/vendor/react-dom.js +0 -1
  118. package/dist/shell/dist/vendor/react.js +0 -1
  119. package/dist/shell/package.json +0 -5
  120. /package/dist/host/{daemon/guard.d.ts → guard.d.ts} +0 -0
@@ -24,11 +24,10 @@ const valid = (env, key) => {
24
24
  return parsed.success ? parsed.data : '';
25
25
  };
26
26
  // ctx.platform from the token check's env; pages and worker start without it and get ''.
27
- export const platformOf = (env) => {
28
- const telemetry = env['AGENTAGE_TELEMETRY_URL'] || undefined;
29
- const issuer = valid(env, 'AGENTAGE_ISSUER');
30
- return { issuer, audience: valid(env, 'AGENTAGE_AUDIENCE'), ...(telemetry && { telemetry }) };
31
- };
27
+ export const platformOf = (env) => ({
28
+ issuer: valid(env, 'AGENTAGE_ISSUER'),
29
+ audience: valid(env, 'AGENTAGE_AUDIENCE'),
30
+ });
32
31
  // *.agentage.io covers the domain and every host under it at any depth; else one exact host.
33
32
  export const covers = (audience, host) => audience.startsWith('*.')
34
33
  ? host === audience.slice(2) || host.endsWith(audience.slice(1))
@@ -19,7 +19,6 @@ export interface ExtensionInfo {
19
19
  export interface PlatformInfo {
20
20
  issuer: string;
21
21
  audience: string;
22
- telemetry?: string;
23
22
  }
24
23
  export declare const NO_PLATFORM: PlatformInfo;
25
24
  export interface PartContext {
@@ -0,0 +1,11 @@
1
+ export interface LaunchSpec {
2
+ id: string;
3
+ dir: string;
4
+ dataDir: string;
5
+ settings: Record<string, unknown>;
6
+ secrets: Record<string, string>;
7
+ origin: string;
8
+ storeOpenMs?: number;
9
+ userSub?: string;
10
+ }
11
+ export declare const childEnv: (spec: LaunchSpec, secretsDir: string, runDir?: string) => Record<string, string>;
@@ -0,0 +1,12 @@
1
+ // What dist/host/main.js reads (docs/part-image.md), on a port the OS picks.
2
+ export const childEnv = (spec, secretsDir, runDir) => ({
3
+ PORT: '0',
4
+ AGENTAGE_EXTENSION_DIR: spec.dir,
5
+ AGENTAGE_DATA_DIR: spec.dataDir,
6
+ AGENTAGE_SETTINGS: JSON.stringify(spec.settings),
7
+ AGENTAGE_SECRETS_DIR: secretsDir,
8
+ AGENTAGE_ORIGIN: spec.origin,
9
+ ...(runDir && { AGENTAGE_RUN_DIR: runDir }),
10
+ ...(spec.storeOpenMs && { AGENTAGE_STORE_OPEN_MS: String(spec.storeOpenMs) }),
11
+ ...(spec.userSub && { AGENTAGE_USER_SUB: spec.userSub }),
12
+ });
@@ -1,5 +1,5 @@
1
1
  import {} from 'express';
2
- import { fail } from '../../envelope/envelope.js';
2
+ import { fail } from '../envelope/envelope.js';
3
3
  // What a browser says of a request another site started (an <img>, a link, a form).
4
4
  const FOREIGN = ['cross-site', 'same-site'];
5
5
  const hostsAt = (port) => [`127.0.0.1:${port}`, `localhost:${port}`];
@@ -14,7 +14,7 @@ import { readManifest } from '../manifest/read-manifest.js';
14
14
  import { buildInfoFromEnv } from '../runtime/build-info.js';
15
15
  import {} from '../server/app.js';
16
16
  import { hostClockRate } from '../worker/clock.js';
17
- import { localOnly } from './daemon/guard.js';
17
+ import { localOnly } from './guard.js';
18
18
  import { hostPartsOf } from './host-parts.js';
19
19
  import { openHostStore, STORE_OPEN_MS } from './host-store.js';
20
20
  import { hostStoreChecks } from './host-url-store.js';
@@ -0,0 +1 @@
1
+ export declare const HOST_MAIN: string;
@@ -0,0 +1,3 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ // The entry each child of an app host runs: one package, its parts (docs/part-image.md).
3
+ export const HOST_MAIN = fileURLToPath(new URL('./main.js', import.meta.url));
@@ -1,8 +1,4 @@
1
1
  export { combineHost, type Answer, type CallerState, type Combined, type CombineInput, type HostInstallation, type Refusal, type Route, } from '../discovery/combine.js';
2
2
  export { capabilities } from '../tool/capabilities.js';
3
- export { localOnly } from './daemon/guard.js';
4
- export { createDaemon, DAEMON_PORT, type Daemon, type DaemonOptions } from './daemon/daemon.js';
5
- export { type Installer, type State } from './daemon/supervisor.js';
6
- export { withFileLock } from './daemon/json-file.js';
7
- export { updateInstallation, type InstallEntry, type Installation } from './daemon/installation.js';
3
+ export { localOnly } from './guard.js';
8
4
  export { hostExtension, type HostedExtension, type HostOptions } from './host-extension.js';
@@ -1,8 +1,4 @@
1
1
  export { combineHost, } from '../discovery/combine.js';
2
2
  export { capabilities } from '../tool/capabilities.js';
3
- export { localOnly } from './daemon/guard.js';
4
- export { createDaemon, DAEMON_PORT } from './daemon/daemon.js';
5
- export {} from './daemon/supervisor.js';
6
- export { withFileLock } from './daemon/json-file.js';
7
- export { updateInstallation } from './daemon/installation.js';
3
+ export { localOnly } from './guard.js';
8
4
  export { hostExtension } from './host-extension.js';
@@ -0,0 +1 @@
1
+ export declare const kitShellDir: () => undefined;
@@ -0,0 +1,2 @@
1
+ // Deprecated: @agentage/apphost 0.1.0 imports it by name; the kit carries no shell. Remove at the next kit minor.
2
+ export const kitShellDir = () => undefined;
@@ -4,7 +4,7 @@ import { setTimeout as sleep } from 'node:timers/promises';
4
4
  import { createLog } from '../log/log.js';
5
5
  import {} from '../runtime/build-info.js';
6
6
  import { listen, shutdownOn } from '../server/serve.js';
7
- import { loopbackPorts } from './daemon/guard.js';
7
+ import { loopbackPorts } from './guard.js';
8
8
  import { guardOf, hostEnvOf } from './host-env.js';
9
9
  import { hostBuildInfo, hostWith } from './host-extension.js';
10
10
  export const ORPHAN_MS = 10_000;
@@ -0,0 +1,29 @@
1
+ export { agcidMiddleware } from '../agcid/scope.js';
2
+ export { download } from '../api/download.js';
3
+ export { type ApiContext } from '../api/routes.js';
4
+ export { fits, type Setting } from '../context/settings.js';
5
+ export { type Answer, type CallerState, combineHost, type CombineInput, } from '../discovery/combine.js';
6
+ export { DiscoveryDocumentSchema } from '../discovery/discovery.schema.js';
7
+ export { HostDocumentSchema, type HostEntry } from '../discovery/host-document.schema.js';
8
+ export { SERVES_KINDS } from '../discovery/served.schema.js';
9
+ export { fail, ok } from '../envelope/envelope.js';
10
+ export { parse } from '../envelope/parse.js';
11
+ export { type AppRow, appRowIn, appStatic } from '../host/app-bundle.js';
12
+ export { childEnv, type LaunchSpec } from '../host/child-env.js';
13
+ export { clearOldLock, DATA_DIR_LOCKED, lockDataDir } from '../host/data-lock.js';
14
+ export { localOnly } from '../host/guard.js';
15
+ export { guardOf } from '../host/host-env.js';
16
+ export { HOST_MAIN } from '../host/host-main.js';
17
+ export { kitShellDir } from '../host/kit-shell.js';
18
+ export { serveHost } from '../host/serve-host.js';
19
+ export { createLog, type Log } from '../log/log.js';
20
+ export { type ExtensionPackage } from '../manifest/manifest.schema.js';
21
+ export { hasStore, hostParts, mountedIn, secretNames } from '../manifest/parts.js';
22
+ export { ExtensionIdSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
23
+ export { readManifest } from '../manifest/read-manifest.js';
24
+ export { BODY_LIMIT } from '../server/app.js';
25
+ export { errorHandler, notFound } from '../server/errors.js';
26
+ export { closeNow, listen } from '../server/serve.js';
27
+ export { startOn, startTestServer, type TestServer } from '../testing/test-server.js';
28
+ export { KIT_VERSION } from '../tool/kit-version.js';
29
+ export { CLOCK_RATE_ENV, parseClockRate } from '../worker/clock.js';
@@ -0,0 +1,30 @@
1
+ // The kit modules the app host program (@agentage/apphost) builds on; not a public api.
2
+ export { agcidMiddleware } from '../agcid/scope.js';
3
+ export { download } from '../api/download.js';
4
+ export {} from '../api/routes.js';
5
+ export { fits } from '../context/settings.js';
6
+ export { combineHost, } from '../discovery/combine.js';
7
+ export { DiscoveryDocumentSchema } from '../discovery/discovery.schema.js';
8
+ export { HostDocumentSchema } from '../discovery/host-document.schema.js';
9
+ export { SERVES_KINDS } from '../discovery/served.schema.js';
10
+ export { fail, ok } from '../envelope/envelope.js';
11
+ export { parse } from '../envelope/parse.js';
12
+ export { appRowIn, appStatic } from '../host/app-bundle.js';
13
+ export { childEnv } from '../host/child-env.js';
14
+ export { clearOldLock, DATA_DIR_LOCKED, lockDataDir } from '../host/data-lock.js';
15
+ export { localOnly } from '../host/guard.js';
16
+ export { guardOf } from '../host/host-env.js';
17
+ export { HOST_MAIN } from '../host/host-main.js';
18
+ export { kitShellDir } from '../host/kit-shell.js';
19
+ export { serveHost } from '../host/serve-host.js';
20
+ export { createLog } from '../log/log.js';
21
+ export {} from '../manifest/manifest.schema.js';
22
+ export { hasStore, hostParts, mountedIn, secretNames } from '../manifest/parts.js';
23
+ export { ExtensionIdSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
24
+ export { readManifest } from '../manifest/read-manifest.js';
25
+ export { BODY_LIMIT } from '../server/app.js';
26
+ export { errorHandler, notFound } from '../server/errors.js';
27
+ export { closeNow, listen } from '../server/serve.js';
28
+ export { startOn, startTestServer } from '../testing/test-server.js';
29
+ export { KIT_VERSION } from '../tool/kit-version.js';
30
+ export { CLOCK_RATE_ENV, parseClockRate } from '../worker/clock.js';
@@ -16,7 +16,6 @@ export interface RunnerInput {
16
16
  base: PartAppBase;
17
17
  openapi: Record<string, unknown> | null;
18
18
  importModule?: ImportModule;
19
- apiAliases?: string[];
20
19
  mcpPaths?: string[];
21
20
  openListing?: boolean;
22
21
  }
@@ -29,7 +29,7 @@ const api = async (input) => {
29
29
  const openapi = routes.length > 0 ? generatedOpenapi(input.pkg, routes) : input.openapi;
30
30
  const options = { ...input.base, router, routes, openapi, wellKnown: documents, files };
31
31
  const record = openapi ? { openapi: openapiPath(input.pkg.agentage.id) } : {};
32
- return { mount: (app) => mountApiRoutes(app, { ...options, aliases: input.apiAliases }), record };
32
+ return { mount: (app) => mountApiRoutes(app, options), record };
33
33
  };
34
34
  const mcp = async (input) => {
35
35
  const registry = createToolRegistry();
@@ -103,8 +103,6 @@ const inputFor = async (options, start) => {
103
103
  base,
104
104
  openapi,
105
105
  importModule: options.importModule,
106
- // The old prefix as a second mount, so next stays green; it goes in phase 4.
107
- apiAliases: ['/api/v1'],
108
106
  // /mcp/{id} (and /connector/{id}) as the app host routes it; bare /mcp for the estate gateway.
109
107
  mcpPaths: [MCP_PATH, mcpPathOf(start.pkg.agentage.id)],
110
108
  };
@@ -42,7 +42,6 @@ export interface ApiAppOptions extends PartAppBase {
42
42
  method: string;
43
43
  path: string;
44
44
  }[];
45
- aliases?: string[];
46
45
  files?: FilesEntry;
47
46
  }
48
47
  export declare const PUBLIC_CORS: CorsOptions;
@@ -117,15 +117,14 @@ export const mountApiRoutes = (app, options) => {
117
117
  const { id } = options.pkg.agentage;
118
118
  if (options.files)
119
119
  mountFiles(app, id, options.files, options.tokenCheck);
120
- const prefixes = [apiPrefix(id), ...(options.aliases ?? [])];
121
- app.use(prefixes, cors(PUBLIC_CORS));
120
+ const prefix = apiPrefix(id);
121
+ app.use(prefix, cors(PUBLIC_CORS));
122
122
  for (const { name, render } of options.wellKnown ?? [])
123
123
  app.get(`/.well-known/${name}`, wellKnownHandler(render));
124
124
  const { openapi } = options;
125
125
  if (openapi)
126
- for (const at of prefixes)
127
- app.get(`${at}/openapi.json`, openapiHandler(openapi));
126
+ app.get(`${prefix}/openapi.json`, openapiHandler(openapi));
128
127
  const json = express.json({ limit: BODY_LIMIT });
129
- app.use(prefixes, routeGuard(options), json, options.router);
128
+ app.use(prefix, routeGuard(options), json, options.router);
130
129
  };
131
130
  export const createApiApp = (options) => createPartApp({ ...options, part: 'api', mount: (app) => mountApiRoutes(app, options) });
@@ -20,12 +20,15 @@ import { assertBuilt, exists } from './stage.js';
20
20
  const RECIPE = /^(?:dockerfile|containerfile)(?:\..+)?$|^(?:docker-)?compose(?:\.[\w-]+)?\.ya?ml$/i;
21
21
  export const NOT_BUILT = 'is missing: build the package first (npm run build)';
22
22
  const NO_PACKAGE = 'is missing: run it in an extension package folder';
23
+ const NOT_EXTENSION = 'has no agentage key: not an extension';
23
24
  const manifest = {
24
25
  name: 'manifest',
25
26
  run: async ({ dir }) => {
26
27
  const value = await readJsonIfExists(join(dir, 'package.json'));
27
28
  if (value === undefined)
28
29
  return [{ file: 'package.json', problem: NO_PACKAGE }];
30
+ if (!(value instanceof Object) || !('agentage' in value))
31
+ return [{ file: 'package.json', problem: NOT_EXTENSION }];
29
32
  const issues = PackageSchema.safeParse(value).error?.issues ?? [];
30
33
  const recipes = (await readdir(dir)).filter((file) => RECIPE.test(file)).sort();
31
34
  const recipe = 'is not allowed: the kit writes every image recipe';
@@ -1,8 +1,8 @@
1
1
  import {} from '../manifest/primitives.schema.js';
2
2
  import { DATA_VOLUME_LINES, GIT_INSTALL, STORE_DIR } from './container-recipe.js';
3
3
  const PART_PORT = 3000;
4
- // 503 passes: a restart cannot fix a dependency outage, so only a dead or 404 part is unhealthy.
5
- const HEALTH_PROBE = `fetch('http://127.0.0.1:${PART_PORT}/health')` +
4
+ // 503 passes (a restart cannot fix an outage); PORT: a host that sets it (the estate: 8080) is probed there.
5
+ const HEALTH_PROBE = `fetch('http://127.0.0.1:'+(process.env.PORT||${PART_PORT})+'/health')` +
6
6
  '.then((r) => process.exit(r.status === 200 || r.status === 503 ? 0 : 1), () => process.exit(1))';
7
7
  const BASE = [
8
8
  '# syntax=docker/dockerfile:1',
@@ -32,9 +32,6 @@ const partRouters = (routed, of) => {
32
32
  const routers = {};
33
33
  for (const part of routed)
34
34
  routers[part] = router(ruleOf(part, of), PRIORITY[part] ?? 100, part);
35
- // The old api prefix, as runPart serves it, until phase 4.
36
- if (routed.includes('api'))
37
- routers['api-v1'] = router('PathPrefix(`/api/v1/`)', 100, 'api');
38
35
  // ctx.files (git smart-HTTP) is on the api part.
39
36
  if (routed.includes('api'))
40
37
  routers['files'] = router(`PathPrefix(\`/files/${of.id}/\`)`, 100, 'api');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/extension",
3
- "version": "0.20.1",
3
+ "version": "0.20.3",
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",
@@ -40,6 +40,10 @@
40
40
  "types": "./dist/core-client/index.d.ts",
41
41
  "default": "./dist/core-client/index.js"
42
42
  },
43
+ "./internal": {
44
+ "types": "./dist/internal/index.d.ts",
45
+ "default": "./dist/internal/index.js"
46
+ },
43
47
  "./logs": {
44
48
  "types": "./dist/logs/index.d.ts",
45
49
  "default": "./dist/logs/index.js"
@@ -1,11 +0,0 @@
1
- import { z } from 'zod';
2
- import { type Entries } from './entries.js';
3
- import { type SupervisorDeps } from './supervisor.js';
4
- export declare const VersionSpecSchema: z.ZodString;
5
- export declare const addExtension: (deps: SupervisorDeps, entries: Entries, body: unknown) => Promise<{
6
- error?: string | undefined;
7
- pid?: number | undefined;
8
- id: string;
9
- version: string;
10
- state: import("./supervisor.js").State;
11
- }>;
@@ -1,93 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { rm } from 'node:fs/promises';
3
- import { isAbsolute } from 'node:path';
4
- import { validRange } from 'semver';
5
- import { z } from 'zod';
6
- import { fail } from '../../envelope/envelope.js';
7
- import { parse } from '../../envelope/parse.js';
8
- import { ExtensionIdSchema } from '../../manifest/primitives.schema.js';
9
- import { readManifest } from '../../manifest/read-manifest.js';
10
- import { persist, summary } from './entries.js';
11
- import { runInstaller } from './installer-call.js';
12
- import {} from './installation.js';
13
- import { clearRunDir, dataDirOf } from './daemon-files.js';
14
- import { needsSecret } from './start-checks.js';
15
- import { startEntry, startFailed } from './supervisor.js';
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));
20
- // POST and PATCH: the same rule, so no route hands the installer a path.
21
- export const VersionSpecSchema = z
22
- .string()
23
- .min(1)
24
- .refine(isVersionSpec, 'a version, a range or a dist-tag');
25
- // enabled: false records the extension and never starts it (a profile "off" entry).
26
- const AddSchema = z.union([
27
- z.strictObject({
28
- id: ExtensionIdSchema,
29
- version: VersionSpecSchema.optional(),
30
- enabled: z.boolean().optional(),
31
- }),
32
- z.strictObject({
33
- source: z.string().refine(isAbsolute, 'an absolute path'),
34
- enabled: z.boolean().optional(),
35
- }),
36
- ]);
37
- // The entry a 409 names, so a client can tell a repeat from another package of that id.
38
- const existing = ({ id, version, install }) => ({
39
- id,
40
- ...(version ? { version } : {}),
41
- ...(install.source ? { source: install.source } : {}),
42
- });
43
- const reserve = (entries, id) => {
44
- if (id === RESERVED_ID)
45
- throw fail('VALIDATION_ERROR', 'the id host is reserved');
46
- const has = entries.get(id);
47
- if (has)
48
- throw fail('CONFLICT', `${id} is installed`, { details: existing(has) });
49
- };
50
- const sourceEntry = async (source) => {
51
- const pkg = await readManifest(source).catch((err) => {
52
- throw fail('VALIDATION_ERROR', `${source}: ${err.message}`);
53
- });
54
- return { install: { id: pkg.agentage.id, source }, dir: source, version: pkg.version };
55
- };
56
- const marketEntry = async (deps, entries, id, version) => {
57
- reserve(entries, id);
58
- const got = await runInstaller(deps, { id, version });
59
- return { install: { id: got.id, version: got.version }, dir: got.dir, version: got.version };
60
- };
61
- // C6: a new id that did not start leaves no row; only a data folder this start made goes too.
62
- const rollBack = async (deps, entries, entry, fresh) => {
63
- entries.delete(entry.id);
64
- await persist(deps, entry.id);
65
- await clearRunDir(deps.configDir, entry.id);
66
- if (fresh)
67
- await rm(dataDirOf(deps.configDir, entry.id), { recursive: true, force: true });
68
- };
69
- // The first start; refused and rolled back unless it waits for a secret or the daemon stops (kept).
70
- const firstStart = async (deps, entries, entry) => {
71
- const fresh = !existsSync(dataDirOf(deps.configDir, entry.id));
72
- const err = await startEntry(deps, entry);
73
- if (!err || needsSecret(err) || deps.stopping.signal.aborted)
74
- return;
75
- await rollBack(deps, entries, entry, fresh);
76
- throw startFailed(entry, err);
77
- };
78
- // POST: installs (or links a folder), records it, then starts it (C6: a failed start is refused).
79
- export const addExtension = async (deps, entries, body) => {
80
- const spec = parse(AddSchema, body, 'Invalid body');
81
- const got = 'source' in spec
82
- ? await sourceEntry(spec.source)
83
- : await marketEntry(deps, entries, spec.id, spec.version);
84
- reserve(entries, got.install.id);
85
- const off = spec.enabled === false;
86
- const install = off ? { ...got.install, enabled: false } : got.install;
87
- await persist(deps, install.id, install);
88
- const entry = { ...got, id: install.id, install, state: 'disabled' };
89
- entries.set(entry.id, entry);
90
- if (!off)
91
- await firstStart(deps, entries, entry);
92
- return summary(entry);
93
- };
@@ -1,8 +0,0 @@
1
- import { type Express } from 'express';
2
- import { type AppRow } from '../app-bundle.js';
3
- import { type Entries } from './entries.js';
4
- import { type Entry } from './supervisor.js';
5
- export { type AppRow };
6
- export declare const appRowOf: (entry: Entry) => Promise<AppRow | undefined>;
7
- export declare const hasApp: (entries: Entries, id: string) => Promise<boolean>;
8
- export declare const appRoutes: (app: Express, entries: Entries) => void;
@@ -1,34 +0,0 @@
1
- import {} from 'express';
2
- import { fail } from '../../envelope/envelope.js';
3
- import { readManifest } from '../../manifest/read-manifest.js';
4
- import { appRowIn, appStatic } from '../app-bundle.js';
5
- import {} from './entries.js';
6
- import {} from './supervisor.js';
7
- export {};
8
- // The nav row of an enabled entry whose package has the app part, built; else none.
9
- export const appRowOf = async (entry) => {
10
- const dir = entry.dir;
11
- if (!dir || entry.install.enabled === false)
12
- return undefined;
13
- const pkg = await readManifest(dir).catch(() => undefined);
14
- return pkg && appRowIn(dir, pkg, entry.id);
15
- };
16
- // The app id of a page path, when the id is installed and has an app row.
17
- export const hasApp = async (entries, id) => {
18
- const entry = entries.get(id);
19
- return entry !== undefined && (await appRowOf(entry)) !== undefined;
20
- };
21
- const appDirOf = async (entries, id) => {
22
- const entry = entries.get(id);
23
- if (!entry || !(await appRowOf(entry)))
24
- throw fail('NOT_FOUND', `${id} has no app`);
25
- return entry.dir ?? '';
26
- };
27
- // GET /app/{id}/*: static from the package folder (not the child), so it answers while the child is down.
28
- const serveApp = (entries) => async (req, res, next) => {
29
- const root = await appDirOf(entries, String(req.params['id']));
30
- appStatic(root, false)(req, res, (err) => next(err && fail('NOT_FOUND', `${String(req.params['id'])} has no such app file`)));
31
- };
32
- export const appRoutes = (app, entries) => {
33
- app.use('/app/:id', serveApp(entries));
34
- };
@@ -1,2 +0,0 @@
1
- import { type RequestHandler } from 'express';
2
- export declare const ownAppOnly: RequestHandler;
@@ -1,12 +0,0 @@
1
- import {} from 'express';
2
- import { fail } from '../../envelope/envelope.js';
3
- // What useAppHost().api sends: the app that made the call.
4
- const APP_HEADER = 'x-agentage-app';
5
- // K10: an app calls only its own extension; a raw fetch with no header is not stopped (stated limit).
6
- export const ownAppOnly = (req, _res, next) => {
7
- const from = req.get(APP_HEADER);
8
- const id = String(req.params['id']);
9
- if (from !== undefined && from !== id)
10
- throw fail('FORBIDDEN', `the app ${from} may not call the extension ${id}`);
11
- next();
12
- };
@@ -1,10 +0,0 @@
1
- import { type Entries } from './entries.js';
2
- import { type ShellEvents } from './shell-events.js';
3
- export declare const isAppReload: (body: unknown) => boolean;
4
- export declare const reloadApp: (entries: Entries, id: string, events: ShellEvents) => Promise<{
5
- id: string;
6
- version: string;
7
- state: import("./supervisor.js").State;
8
- reloaded: boolean;
9
- part: string;
10
- }>;
@@ -1,18 +0,0 @@
1
- import { fail } from '../../envelope/envelope.js';
2
- import { appRowOf } from './app-files.js';
3
- import { entryOf } from './entries.js';
4
- import {} from './shell-events.js';
5
- // The body of a reload that names the app part: the child keeps running.
6
- export const isAppReload = (body) => typeof body === 'object' &&
7
- body !== null &&
8
- Object.keys(body).length === 1 &&
9
- body.part === 'app';
10
- // K8: the new build is in dist/app already; the shell re-imports the entry the event names.
11
- export const reloadApp = async (entries, id, events) => {
12
- const entry = entryOf(entries, id);
13
- const row = await appRowOf(entry);
14
- if (!row)
15
- throw fail('VALIDATION_ERROR', `${id} has no built app: run the app build first`);
16
- events.send('app', { id, entry: row.entry, css: row.css });
17
- return { id, version: entry.version, state: entry.state, reloaded: true, part: 'app' };
18
- };
@@ -1,20 +0,0 @@
1
- interface RunSpec {
2
- id: string;
3
- dir: string;
4
- dataDir: string;
5
- secrets: Record<string, string>;
6
- }
7
- export interface RunFolders {
8
- runDir: string;
9
- secretsDir: string;
10
- tmpDir: string;
11
- made: {
12
- run?: string;
13
- data: boolean;
14
- };
15
- }
16
- export declare const configDirOf: (dataDir: string) => string;
17
- export declare const makeRun: (spec: RunSpec) => Promise<RunFolders>;
18
- export declare const fillRun: (run: RunFolders, spec: RunSpec) => Promise<void>;
19
- export declare const undoRun: ({ runDir, made }: RunFolders, dataDir: string) => Promise<void>;
20
- export {};
@@ -1,53 +0,0 @@
1
- import { mkdir, rm, rmdir, writeFile } from 'node:fs/promises';
2
- import { dirname, join } from 'node:path';
3
- import { secretNames } from '../../manifest/parts.js';
4
- import { SecretNameSchema } from '../../manifest/primitives.schema.js';
5
- import { readManifest } from '../../manifest/read-manifest.js';
6
- import { clearOldLock } from '../data-lock.js';
7
- import { runDirOf } from './daemon-files.js';
8
- import { clearRunLock } from './run-lock.js';
9
- // The supervisor's dataDir is <configDir>/data/{id}, so run/{id} sits beside data/ (C2).
10
- export const configDirOf = (dataDir) => dirname(dirname(dataDir));
11
- // Only the names the package declares now: a row can still hold one an older version declared.
12
- const declared = async (spec) => {
13
- const names = new Set(secretNames(await readManifest(spec.dir)));
14
- return Object.entries(spec.secrets).filter(([name]) => names.has(name));
15
- };
16
- // The folders first, so undoRun knows what this launch made; data/{id} before the fork (PGlite).
17
- export const makeRun = async (spec) => {
18
- const runDir = runDirOf(configDirOf(spec.dataDir), spec.id);
19
- const made = { run: await mkdir(runDir, { recursive: true, mode: 0o700 }), data: false };
20
- const run = { runDir, secretsDir: join(runDir, 'secrets'), tmpDir: join(runDir, 'tmp'), made };
21
- const data = await mkdir(spec.dataDir, { recursive: true }).catch(async (err) => {
22
- await undoRun(run, spec.dataDir);
23
- throw err;
24
- });
25
- made.data = data !== undefined;
26
- return run;
27
- };
28
- // Fresh secrets and tmp; the old lock beside data/{id} and a left-over run lock are cleared.
29
- export const fillRun = async (run, spec) => {
30
- for (const dir of [run.secretsDir, run.tmpDir]) {
31
- await rm(dir, { recursive: true, force: true });
32
- await mkdir(dir, { mode: 0o700 });
33
- }
34
- await clearOldLock(`${spec.dataDir}.lock`);
35
- await clearRunLock(join(run.runDir, 'store.lock'), run.runDir);
36
- for (const [name, value] of await declared(spec))
37
- await writeFile(join(run.secretsDir, SecretNameSchema.parse(name)), value, { mode: 0o600 });
38
- };
39
- // From dir up to top, each folder only while it is empty: rmdir refuses one that is not.
40
- const emptyUpTo = async (dir, top) => {
41
- for (; dir.startsWith(top); dir = dirname(dir))
42
- if (await rmdir(dir).catch(() => 'kept'))
43
- return;
44
- };
45
- // A child that never reported its port: what this launch made goes, run/ only while empty.
46
- export const undoRun = async ({ runDir, made }, dataDir) => {
47
- if (made.run)
48
- await rm(runDir, { recursive: true, force: true });
49
- if (made.run)
50
- await emptyUpTo(dirname(runDir), made.run);
51
- if (made.data)
52
- await rmdir(dataDir).catch(() => undefined);
53
- };
@@ -1,30 +0,0 @@
1
- import { type Seal } from './seal.js';
2
- interface LaunchSpec {
3
- id: string;
4
- dir: string;
5
- dataDir: string;
6
- settings: Record<string, unknown>;
7
- secrets: Record<string, string>;
8
- origin: string;
9
- storeOpenMs?: number;
10
- userSub?: string;
11
- }
12
- export interface Exit {
13
- code: number | null;
14
- signal: string | null;
15
- words?: string;
16
- }
17
- export interface Child {
18
- port: number;
19
- pid: number;
20
- exited: Promise<Exit>;
21
- stop(): Promise<void>;
22
- }
23
- export type Launch = ((spec: LaunchSpec) => Promise<Child>) & {
24
- clockRate?: number;
25
- seal?: Seal;
26
- node?: string;
27
- };
28
- export declare const childEnv: (spec: LaunchSpec, secretsDir: string, runDir?: string) => Record<string, string>;
29
- export declare const forkLaunch: (main?: string, startMs?: number, rate?: number, node?: string) => Launch;
30
- export {};