@agentage/extension 0.6.0 → 0.6.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.
package/dist/context/secrets.js
CHANGED
|
@@ -2,14 +2,20 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
export const SECRETS_DIR = '/run/secrets';
|
|
4
4
|
export const camelName = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
5
|
-
|
|
5
|
+
// Only a missing file reads as no value; any other error stops the part with its code.
|
|
6
|
+
const valueOf = (file, refused) => readFile(file, 'utf8').then((text) => text.replace(/\r?\n$/, ''), (err) => {
|
|
7
|
+
if (err.code === 'ENOENT')
|
|
8
|
+
return '';
|
|
9
|
+
throw new Error(`${refused} cannot be read: ${err.code ?? 'unknown'}`);
|
|
10
|
+
});
|
|
6
11
|
// Each declared name from its mounted file; a missing or empty file stops the part, named, never valued.
|
|
7
12
|
export const readSecrets = async (names, dir, part) => {
|
|
8
|
-
const
|
|
13
|
+
const refused = (name) => `${part} refused to start: secret ${name}`;
|
|
14
|
+
const read = names.map(async (name) => [name, await valueOf(join(dir, name), refused(name))]);
|
|
9
15
|
const pairs = await Promise.all(read);
|
|
10
16
|
const missing = pairs.find(([, value]) => value === '');
|
|
11
17
|
if (missing)
|
|
12
|
-
throw new Error(`${
|
|
18
|
+
throw new Error(`${refused(missing[0])} has no value`);
|
|
13
19
|
const secrets = Object.fromEntries(pairs.map(([name, value]) => [camelName(name), value]));
|
|
14
20
|
return Object.freeze(secrets);
|
|
15
21
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type Express } from 'express';
|
|
2
|
+
import { type Env } from '../runtime/build-info.js';
|
|
2
3
|
import { type PartAppBase } from '../server/app.js';
|
|
3
4
|
import { type PagesSite } from './pages.js';
|
|
4
5
|
export interface PagesAppOptions extends PartAppBase {
|
|
5
6
|
site: PagesSite;
|
|
7
|
+
platform?: string[];
|
|
6
8
|
}
|
|
9
|
+
export declare const platformSources: (env: Env) => string[];
|
|
7
10
|
export declare const NOT_FOUND_PAGE = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><title>Not found</title></head><body><p>Not found</p></body></html>\n";
|
|
8
11
|
export declare const createPagesApp: (options: PagesAppOptions) => Express;
|
package/dist/pages/pages-app.js
CHANGED
|
@@ -1,26 +1,51 @@
|
|
|
1
|
+
import { extname } from 'node:path';
|
|
1
2
|
import {} from 'express';
|
|
2
3
|
import { z } from 'zod';
|
|
4
|
+
import {} from '../runtime/build-info.js';
|
|
3
5
|
import { createPartApp } from '../server/app.js';
|
|
4
6
|
import {} from './pages.js';
|
|
7
|
+
// One host (a port allowed), or *. over at least two labels: never a whole top-level domain.
|
|
8
|
+
const AUDIENCE = /^(\*\.[a-z0-9-]+(\.[a-z0-9-]+)+|[a-z0-9-]+(\.[a-z0-9-]+)*)(:\d+)?$/;
|
|
9
|
+
const WEB = ['http:', 'https:'];
|
|
10
|
+
const webUrl = (url) => {
|
|
11
|
+
const parsed = url && URL.canParse(url) ? new URL(url) : undefined;
|
|
12
|
+
return parsed && WEB.includes(parsed.protocol) ? parsed : undefined;
|
|
13
|
+
};
|
|
14
|
+
// A shell page talks to auth and mounts widgets from its siblings: the platform's own hosts only.
|
|
15
|
+
export const platformSources = (env) => {
|
|
16
|
+
const issuer = webUrl(env['AGENTAGE_ISSUER'])?.origin;
|
|
17
|
+
const scheme = webUrl(env['AGENTAGE_ORIGIN'])?.protocol ?? 'https:';
|
|
18
|
+
const audience = env['AGENTAGE_AUDIENCE'] ?? '';
|
|
19
|
+
return [issuer, AUDIENCE.test(audience) ? `${scheme}//${audience}` : undefined].filter((source) => Boolean(source));
|
|
20
|
+
};
|
|
21
|
+
const TYPES = { '.js': 'js', '.mjs': 'js', '.css': 'css', '.json': 'json' };
|
|
5
22
|
const SiteSchema = z.record(z.string().regex(/^\/[A-Za-z0-9._~/-]*$/), z.string());
|
|
6
23
|
export const NOT_FOUND_PAGE = '<!doctype html>\n<html lang="en"><head><meta charset="utf-8"><title>Not found</title></head><body><p>Not found</p></body></html>\n';
|
|
7
24
|
const serve = (site) => (req, res, next) => {
|
|
8
25
|
const html = site[req.path];
|
|
9
26
|
if (html === undefined)
|
|
10
27
|
return next();
|
|
11
|
-
res.type('html').setHeader('Cache-Control', 'no-cache');
|
|
28
|
+
res.type(TYPES[extname(req.path)] ?? 'html').setHeader('Cache-Control', 'no-cache');
|
|
12
29
|
res.send(html);
|
|
13
30
|
};
|
|
14
31
|
const missing = (_req, res) => {
|
|
15
32
|
res.status(404).type('html').send(NOT_FOUND_PAGE);
|
|
16
33
|
};
|
|
17
|
-
// Everything the gateway does not reserve comes here: a
|
|
34
|
+
// Everything the gateway does not reserve comes here: a site map entry (typed by its extension), or an HTML 404.
|
|
18
35
|
export const createPagesApp = (options) => {
|
|
19
36
|
const site = SiteSchema.parse(options.site);
|
|
20
37
|
return createPartApp({
|
|
21
38
|
...options,
|
|
22
39
|
part: 'pages',
|
|
23
|
-
helmet: {
|
|
40
|
+
helmet: {
|
|
41
|
+
contentSecurityPolicy: {
|
|
42
|
+
directives: {
|
|
43
|
+
scriptSrc: ["'self'", ...(options.platform ?? [])],
|
|
44
|
+
connectSrc: ["'self'", ...(options.platform ?? [])],
|
|
45
|
+
upgradeInsecureRequests: null,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
24
49
|
mount: (app) => {
|
|
25
50
|
app.get(/.*/, serve(site));
|
|
26
51
|
app.get(/.*/, missing);
|
|
@@ -8,7 +8,7 @@ import { hasStore } from '../manifest/parts.js';
|
|
|
8
8
|
import {} from '../manifest/primitives.schema.js';
|
|
9
9
|
import { createMcpApp } from '../mcp/mcp-app.js';
|
|
10
10
|
import { createToolRegistry } from '../mcp/tools.js';
|
|
11
|
-
import { createPagesApp } from '../pages/pages-app.js';
|
|
11
|
+
import { createPagesApp, platformSources } from '../pages/pages-app.js';
|
|
12
12
|
import { createApiApp, createPartApp } from '../server/app.js';
|
|
13
13
|
import { mountApi } from '../server/api-routes.js';
|
|
14
14
|
import {} from './build-info.js';
|
|
@@ -34,7 +34,7 @@ const mcp = async (input) => {
|
|
|
34
34
|
};
|
|
35
35
|
const pages = async (input) => {
|
|
36
36
|
const site = (await callCreate(input, 'pages', input.ctx()));
|
|
37
|
-
return { app: createPagesApp({ ...input.base, site }) };
|
|
37
|
+
return { app: createPagesApp({ ...input.base, site, platform: platformSources(input.env) }) };
|
|
38
38
|
};
|
|
39
39
|
const ui = async (input) => ({
|
|
40
40
|
app: createUiApp({
|
package/dist/tool/contracts.js
CHANGED
|
@@ -14,8 +14,19 @@ import { registeredRoutes } from './record-extras.js';
|
|
|
14
14
|
import { generatedMcp } from './rules/surface.js';
|
|
15
15
|
import { exists } from './stage.js';
|
|
16
16
|
const readText = (file) => readFile(file, 'utf8').catch(() => undefined);
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// Only a parse failure (a file a run left half-written) reads as different: --write replaces it.
|
|
18
|
+
const parsed = (text) => {
|
|
19
|
+
try {
|
|
20
|
+
return text === undefined ? undefined : JSON.parse(text);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const sameJson = (text, value) => {
|
|
27
|
+
const old = parsed(text);
|
|
28
|
+
return old !== undefined && JSON.stringify(canonical(old)) === JSON.stringify(canonical(value));
|
|
29
|
+
};
|
|
19
30
|
const json = (value) => `${JSON.stringify(value, null, 2)}\n`;
|
|
20
31
|
const writeMcp = async (dir, pkg) => {
|
|
21
32
|
const file = `${pkg.agentage.id}.mcpc.json`;
|
package/dist/tool/up/health.js
CHANGED
|
@@ -28,9 +28,15 @@ const notOk = (data) => Object.entries(Object(data['checks']))
|
|
|
28
28
|
.filter(([, status]) => status !== 'ok')
|
|
29
29
|
.map(([name, status]) => `${name} ${String(status)}`)
|
|
30
30
|
.join(' · ');
|
|
31
|
+
// A part that gives no answer is its own FAIL line: the exit code and the command's last line.
|
|
32
|
+
const noAnswer = (err) => {
|
|
33
|
+
const code = /exit code (\d+)/.exec(err.message)?.[1];
|
|
34
|
+
return `no answer${code ? ` (exit ${code})` : ''}: ${err.message.split('\n').at(-1) ?? ''}`;
|
|
35
|
+
};
|
|
31
36
|
// Docker's healthy only says the probe answered; the body must name this build and this part.
|
|
32
37
|
export const assertHealthBodies = async (run, target, parts, commit) => {
|
|
33
|
-
const
|
|
38
|
+
const exec = (part) => compose(run, target, ['exec', '-T', part, 'node', '-e', FETCH]);
|
|
39
|
+
const read = parts.map((part) => exec(part).catch(noAnswer));
|
|
34
40
|
const bodies = await Promise.all(read);
|
|
35
41
|
const data = bodies.map(dataOf);
|
|
36
42
|
const failed = parts.flatMap((part, i) => mismatch(part, commit, data[i], bodies[i] ?? '') ?? []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "The agentage extension kit: create(ctx) per part (pages, ui, api, mcp, worker, cli), the store, /health, discovery, the envelope, and the build tool with up and token",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|