@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.
- package/dist/auth/part-auth.js +4 -5
- package/dist/context/context.d.ts +0 -1
- package/dist/host/child-env.d.ts +11 -0
- package/dist/host/child-env.js +12 -0
- package/dist/host/{daemon/guard.js → guard.js} +1 -1
- package/dist/host/host-extension.js +1 -1
- package/dist/host/host-main.d.ts +1 -0
- package/dist/host/host-main.js +3 -0
- package/dist/host/index.d.ts +1 -5
- package/dist/host/index.js +1 -5
- package/dist/host/kit-shell.d.ts +1 -0
- package/dist/host/kit-shell.js +2 -0
- package/dist/host/serve-host.js +1 -1
- package/dist/internal/index.d.ts +29 -0
- package/dist/internal/index.js +30 -0
- package/dist/runtime/part-mounts.d.ts +0 -1
- package/dist/runtime/part-mounts.js +1 -1
- package/dist/runtime/run-part.js +0 -2
- package/dist/server/app.d.ts +0 -1
- package/dist/server/app.js +4 -5
- package/dist/tool/check.js +3 -0
- package/dist/tool/recipe.js +2 -2
- package/dist/tool/up/gateway.js +0 -3
- package/package.json +5 -1
- package/dist/host/daemon/add.d.ts +0 -11
- package/dist/host/daemon/add.js +0 -93
- package/dist/host/daemon/app-files.d.ts +0 -8
- package/dist/host/daemon/app-files.js +0 -34
- package/dist/host/daemon/app-header.d.ts +0 -2
- package/dist/host/daemon/app-header.js +0 -12
- package/dist/host/daemon/app-reload.d.ts +0 -10
- package/dist/host/daemon/app-reload.js +0 -18
- package/dist/host/daemon/child-files.d.ts +0 -20
- package/dist/host/daemon/child-files.js +0 -53
- package/dist/host/daemon/child.d.ts +0 -30
- package/dist/host/daemon/child.js +0 -126
- package/dist/host/daemon/cli-user-watch.d.ts +0 -9
- package/dist/host/daemon/cli-user-watch.js +0 -47
- package/dist/host/daemon/cli-user.d.ts +0 -2
- package/dist/host/daemon/cli-user.js +0 -42
- package/dist/host/daemon/daemon-files.d.ts +0 -20
- package/dist/host/daemon/daemon-files.js +0 -46
- package/dist/host/daemon/daemon-owner.d.ts +0 -1
- package/dist/host/daemon/daemon-owner.js +0 -32
- package/dist/host/daemon/daemon.d.ts +0 -19
- package/dist/host/daemon/daemon.js +0 -137
- package/dist/host/daemon/entries.d.ts +0 -21
- package/dist/host/daemon/entries.js +0 -24
- package/dist/host/daemon/gate.d.ts +0 -3
- package/dist/host/daemon/gate.js +0 -19
- package/dist/host/daemon/health-routes.d.ts +0 -18
- package/dist/host/daemon/health-routes.js +0 -75
- package/dist/host/daemon/host-token.d.ts +0 -6
- package/dist/host/daemon/host-token.js +0 -28
- package/dist/host/daemon/installation.d.ts +0 -35
- package/dist/host/daemon/installation.js +0 -90
- package/dist/host/daemon/installer-call.d.ts +0 -21
- package/dist/host/daemon/installer-call.js +0 -48
- package/dist/host/daemon/json-file.d.ts +0 -6
- package/dist/host/daemon/json-file.js +0 -90
- package/dist/host/daemon/lane.d.ts +0 -9
- package/dist/host/daemon/lane.js +0 -24
- package/dist/host/daemon/last-words.d.ts +0 -2
- package/dist/host/daemon/last-words.js +0 -28
- package/dist/host/daemon/limits.d.ts +0 -16
- package/dist/host/daemon/limits.js +0 -31
- package/dist/host/daemon/ops.d.ts +0 -12
- package/dist/host/daemon/ops.js +0 -94
- package/dist/host/daemon/patch-values.d.ts +0 -6
- package/dist/host/daemon/patch-values.js +0 -39
- package/dist/host/daemon/pending.d.ts +0 -15
- package/dist/host/daemon/pending.js +0 -18
- package/dist/host/daemon/proxy.d.ts +0 -11
- package/dist/host/daemon/proxy.js +0 -106
- package/dist/host/daemon/queue.d.ts +0 -3
- package/dist/host/daemon/queue.js +0 -27
- package/dist/host/daemon/redact-stream.d.ts +0 -4
- package/dist/host/daemon/redact-stream.js +0 -24
- package/dist/host/daemon/reload-marker.d.ts +0 -8
- package/dist/host/daemon/reload-marker.js +0 -57
- package/dist/host/daemon/reload.d.ts +0 -10
- package/dist/host/daemon/reload.js +0 -72
- package/dist/host/daemon/restart.d.ts +0 -14
- package/dist/host/daemon/restart.js +0 -59
- package/dist/host/daemon/routes.d.ts +0 -6
- package/dist/host/daemon/routes.js +0 -101
- package/dist/host/daemon/run-lock.d.ts +0 -1
- package/dist/host/daemon/run-lock.js +0 -15
- package/dist/host/daemon/seal-reach.d.ts +0 -2
- package/dist/host/daemon/seal-reach.js +0 -38
- package/dist/host/daemon/seal.d.ts +0 -20
- package/dist/host/daemon/seal.js +0 -93
- package/dist/host/daemon/shell-events.d.ts +0 -9
- package/dist/host/daemon/shell-events.js +0 -36
- package/dist/host/daemon/shell-routes.d.ts +0 -29
- package/dist/host/daemon/shell-routes.js +0 -68
- package/dist/host/daemon/sign-in-page.d.ts +0 -3
- package/dist/host/daemon/sign-in-page.js +0 -30
- package/dist/host/daemon/start-checks.d.ts +0 -6
- package/dist/host/daemon/start-checks.js +0 -29
- package/dist/host/daemon/stopping.d.ts +0 -10
- package/dist/host/daemon/stopping.js +0 -28
- package/dist/host/daemon/supervisor.d.ts +0 -59
- package/dist/host/daemon/supervisor.js +0 -107
- package/dist/host/daemon/write-all.d.ts +0 -8
- package/dist/host/daemon/write-all.js +0 -45
- package/dist/shell/dist/index.html +0 -49
- package/dist/shell/dist/shell.css +0 -2
- package/dist/shell/dist/shell.js +0 -69
- package/dist/shell/dist/vendor/app.js +0 -1
- package/dist/shell/dist/vendor/chunk-AOJ3DQEL.js +0 -14
- package/dist/shell/dist/vendor/chunk-LW5HXGAJ.js +0 -14
- package/dist/shell/dist/vendor/chunk-PQJPUKWH.js +0 -14
- package/dist/shell/dist/vendor/chunk-SQE76S5B.js +0 -1
- package/dist/shell/dist/vendor/jsx-runtime.js +0 -1
- package/dist/shell/dist/vendor/react-dom-client.js +0 -33
- package/dist/shell/dist/vendor/react-dom.js +0 -1
- package/dist/shell/dist/vendor/react.js +0 -1
- package/dist/shell/package.json +0 -5
- /package/dist/host/{daemon/guard.d.ts → guard.d.ts} +0 -0
package/dist/auth/part-auth.js
CHANGED
|
@@ -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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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))
|
|
@@ -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 '
|
|
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 './
|
|
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;
|
package/dist/host/index.d.ts
CHANGED
|
@@ -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 './
|
|
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';
|
package/dist/host/index.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export { combineHost, } from '../discovery/combine.js';
|
|
2
2
|
export { capabilities } from '../tool/capabilities.js';
|
|
3
|
-
export { localOnly } from './
|
|
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;
|
package/dist/host/serve-host.js
CHANGED
|
@@ -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 './
|
|
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';
|
|
@@ -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,
|
|
32
|
+
return { mount: (app) => mountApiRoutes(app, options), record };
|
|
33
33
|
};
|
|
34
34
|
const mcp = async (input) => {
|
|
35
35
|
const registry = createToolRegistry();
|
package/dist/runtime/run-part.js
CHANGED
|
@@ -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
|
};
|
package/dist/server/app.d.ts
CHANGED
package/dist/server/app.js
CHANGED
|
@@ -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
|
|
121
|
-
app.use(
|
|
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
|
-
|
|
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(
|
|
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) });
|
package/dist/tool/check.js
CHANGED
|
@@ -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';
|
package/dist/tool/recipe.js
CHANGED
|
@@ -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
|
|
5
|
-
const HEALTH_PROBE = `fetch('http://127.0.0.1
|
|
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',
|
package/dist/tool/up/gateway.js
CHANGED
|
@@ -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.
|
|
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
|
-
}>;
|
package/dist/host/daemon/add.js
DELETED
|
@@ -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,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 {};
|