@agentage/extension 0.12.1 → 0.12.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/README.md +5 -0
- package/dist/agcid/agcid.d.ts +2 -1
- package/dist/agcid/agcid.js +2 -10
- package/dist/agcid/current.d.ts +1 -1
- package/dist/agcid/current.js +8 -1
- package/dist/agcid/fetch.d.ts +1 -0
- package/dist/agcid/fetch.js +4 -2
- package/dist/context/context.js +2 -2
- package/dist/context/package-extension.d.ts +2 -0
- package/dist/context/package-extension.js +5 -4
- package/dist/context/recording-log.d.ts +3 -2
- package/dist/context/recording-log.js +1 -1
- package/dist/context/secrets.d.ts +4 -2
- package/dist/context/secrets.js +17 -3
- package/dist/context/test-context.js +4 -3
- package/dist/discovery/discovery.d.ts +1 -0
- package/dist/discovery/discovery.js +7 -3
- package/dist/discovery/discovery.schema.d.ts +6 -0
- package/dist/discovery/discovery.schema.js +15 -4
- package/dist/health/health.js +3 -1
- package/dist/log/log.d.ts +2 -10
- package/dist/log/log.js +11 -3
- package/dist/log/who.d.ts +1 -0
- package/dist/log/who.js +4 -2
- package/dist/manifest/manifest.schema.d.ts +9 -1
- package/dist/manifest/manifest.schema.js +13 -2
- package/dist/manifest/parts.d.ts +6 -0
- package/dist/manifest/parts.js +8 -0
- package/dist/manifest/primitives.schema.d.ts +7 -0
- package/dist/manifest/primitives.schema.js +2 -0
- package/dist/mcp/mcp-app.js +2 -2
- package/dist/runtime/run-part.js +1 -2
- package/dist/server/request-line.js +2 -2
- package/dist/server/serve.js +19 -7
- package/dist/tool/up/compose.js +3 -2
- package/dist/tool/up/local-record.d.ts +1 -0
- package/dist/tool/up/secrets.js +2 -1
- package/dist/vendor/logs/event.schema.d.ts +0 -1
- package/dist/vendor/logs/event.schema.js +1 -1
- package/dist/vendor/logs/events-client.d.ts +1 -1
- package/dist/vendor/logs/events-client.js +30 -16
- package/dist/vendor/logs/index.d.ts +2 -1
- package/dist/vendor/logs/index.js +2 -1
- package/dist/vendor/logs/logger.d.ts +2 -0
- package/dist/vendor/logs/logger.js +60 -33
- package/dist/vendor/logs/parse-line.js +7 -6
- package/dist/vendor/logs/redact.d.ts +4 -0
- package/dist/vendor/logs/redact.js +41 -5
- package/dist/vendor/logs/rows.d.ts +1 -1
- package/dist/vendor/logs/rows.js +13 -2
- package/dist/worker/run-log.d.ts +1 -1
- package/dist/worker/run-log.js +2 -1
- package/package.json +1 -1
- package/schemas/extension-package.schema.json +35 -3
- package/schemas/extension-record.schema.json +20 -0
- package/dist/vendor/logs/error-row.d.ts +0 -3
- package/dist/vendor/logs/error-row.js +0 -16
package/README.md
CHANGED
|
@@ -27,5 +27,10 @@ false); `file` and `line` are there only when a problem has them:
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
Secrets: `agentage.secrets` lists names, never values. A plain name is mounted in every part
|
|
31
|
+
but ui; `{ "name": "github-app-key", "parts": ["worker"] }` only in the parts it names. Any
|
|
32
|
+
other part starts without it, and a read of `ctx.secrets.githubAppKey` there throws. A test
|
|
33
|
+
takes a part's view with `createTestContext({ extension: { part: 'worker' } })`.
|
|
34
|
+
|
|
30
35
|
See the [platform README](https://github.com/agentage/platform#readme) for every part kind, the
|
|
31
36
|
manifest, the tool and how a part image runs.
|
package/dist/agcid/agcid.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { uuidv7 } from '../vendor/logs/index.js';
|
|
1
2
|
export { AGCID_HEADER, AGCID_PATTERN, isAgcid } from './header.js';
|
|
2
|
-
export
|
|
3
|
+
export { uuidv7 };
|
|
3
4
|
export declare const agcidOf: (incoming: unknown, traceparent?: unknown) => string;
|
package/dist/agcid/agcid.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { uuidv7 } from '../vendor/logs/index.js';
|
|
2
2
|
import { TRACEPARENT_PATTERN } from './current.js';
|
|
3
3
|
import { isAgcid } from './header.js';
|
|
4
4
|
export { AGCID_HEADER, AGCID_PATTERN, isAgcid } from './header.js';
|
|
5
|
-
|
|
6
|
-
export const uuidv7 = (now = Date.now(), random = randomBytes(10)) => {
|
|
7
|
-
const bytes = Buffer.alloc(16);
|
|
8
|
-
bytes.writeUIntBE(now, 0, 6);
|
|
9
|
-
random.copy(bytes, 6, 0, 10);
|
|
10
|
-
bytes.writeUInt8((bytes.readUInt8(6) & 0x0f) | 0x70, 6);
|
|
11
|
-
bytes.writeUInt8((bytes.readUInt8(8) & 0x3f) | 0x80, 8);
|
|
12
|
-
return bytes.toString('hex');
|
|
13
|
-
};
|
|
5
|
+
export { uuidv7 };
|
|
14
6
|
const DASHED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
15
7
|
const ZERO = '0'.repeat(32);
|
|
16
8
|
// 32 hex, or a UUID in its 8-4-4-4-12 form without the dashes; all zeros is no id (W3C).
|
package/dist/agcid/current.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ interface RequestScope extends RowContext {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const requestScope: AsyncLocalStorage<RequestScope>;
|
|
9
9
|
export declare const currentAgcid: () => string | undefined;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const sigtermOnce: () => void;
|
|
11
11
|
export declare const TRACEPARENT_PATTERN: RegExp;
|
|
12
12
|
export {};
|
package/dist/agcid/current.js
CHANGED
|
@@ -3,5 +3,12 @@ import {} from '../vendor/logs/index.js';
|
|
|
3
3
|
// Apart from the middleware, so code the cli loads (logs, the build tool) never imports express.
|
|
4
4
|
export const requestScope = new AsyncLocalStorage();
|
|
5
5
|
export const currentAgcid = () => requestScope.getStore()?.agcid;
|
|
6
|
-
|
|
6
|
+
let exiting = false;
|
|
7
|
+
// One SIGTERM per process: ctx.exit() twice, or in two requests, drains once.
|
|
8
|
+
export const sigtermOnce = () => {
|
|
9
|
+
if (exiting)
|
|
10
|
+
return;
|
|
11
|
+
exiting = true;
|
|
12
|
+
process.kill(process.pid, 'SIGTERM');
|
|
13
|
+
};
|
|
7
14
|
export const TRACEPARENT_PATTERN = /^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$/;
|
package/dist/agcid/fetch.d.ts
CHANGED
package/dist/agcid/fetch.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { AGCID_HEADER, uuidv7 } from './agcid.js';
|
|
2
2
|
import { requestScope } from './current.js';
|
|
3
|
-
|
|
3
|
+
export const KIT_FETCH_TIMEOUT_MS = 10_000;
|
|
4
|
+
// Every fetch the kit makes: the scope's agcid (a fresh one outside a scope), its traceparent, a timeout.
|
|
4
5
|
export const kitFetch = (url, init = {}, impl = fetch) => {
|
|
5
6
|
const scope = requestScope.getStore();
|
|
6
7
|
const headers = new Headers(init.headers);
|
|
7
8
|
headers.set(AGCID_HEADER, scope?.agcid ?? uuidv7());
|
|
8
9
|
if (scope?.traceparent)
|
|
9
10
|
headers.set('traceparent', scope.traceparent);
|
|
10
|
-
|
|
11
|
+
const signal = init.signal ?? AbortSignal.timeout(KIT_FETCH_TIMEOUT_MS);
|
|
12
|
+
return impl(url, { ...init, headers, signal });
|
|
11
13
|
};
|
package/dist/context/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { requestScope } from '../agcid/current.js';
|
|
1
|
+
import { requestScope, sigtermOnce } from '../agcid/current.js';
|
|
2
2
|
import { callerOf } from '../auth/token-check.js';
|
|
3
3
|
import {} from '../manifest/manifest.schema.js';
|
|
4
4
|
import { storeOf } from '../manifest/parts.js';
|
|
@@ -20,7 +20,7 @@ const exitAfterAnswer = () => {
|
|
|
20
20
|
if (scope)
|
|
21
21
|
scope.exit = true;
|
|
22
22
|
else
|
|
23
|
-
|
|
23
|
+
sigtermOnce();
|
|
24
24
|
};
|
|
25
25
|
// ctx.store is always there; without a store part in the manifest it says so on first use.
|
|
26
26
|
export const NO_STORE = {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
1
2
|
import { type ExtensionInfo } from './context.js';
|
|
3
|
+
export declare const packageManifest: (dir?: string) => ExtensionPackage | undefined;
|
|
2
4
|
export declare const packageExtension: (dir?: string) => Partial<ExtensionInfo>;
|
|
@@ -12,11 +12,12 @@ const readJson = (file) => {
|
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
// The id, version and store kind of the package a test runs in; nothing outside an extension.
|
|
15
|
+
export const packageManifest = (dir = process.cwd()) => PackageSchema.safeParse(readJson(join(dir, 'package.json'))).data;
|
|
15
16
|
export const packageExtension = (dir = process.cwd()) => {
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
17
|
+
const pkg = packageManifest(dir);
|
|
18
|
+
if (!pkg)
|
|
18
19
|
return {};
|
|
19
|
-
const { version, agentage } =
|
|
20
|
-
const store = storeOf(
|
|
20
|
+
const { version, agentage } = pkg;
|
|
21
|
+
const store = storeOf(pkg);
|
|
21
22
|
return { id: agentage.id, version, ...(store && { store }) };
|
|
22
23
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Level } from '../vendor/logs/index.js';
|
|
2
|
+
import { type Log, type LogFields } from '../log/log.js';
|
|
2
3
|
export interface LogEntry {
|
|
3
|
-
level:
|
|
4
|
+
level: Level;
|
|
4
5
|
message: string;
|
|
5
6
|
fields: LogFields;
|
|
6
7
|
}
|
|
@@ -3,7 +3,7 @@ import { messageOf } from '../log/log.js';
|
|
|
3
3
|
// The test context's log: every row as an entry; error keeps the thrown value under err.
|
|
4
4
|
export const recordingLog = (logs) => {
|
|
5
5
|
const sink = ({ level, msg, fields }) => void logs.push({ level, message: msg, fields });
|
|
6
|
-
const log = createLogger({ extension: 'test', part: 'test', sink });
|
|
6
|
+
const log = createLogger({ extension: 'test', part: 'test', sink, strict: true });
|
|
7
7
|
const error = (err, where = {}) => {
|
|
8
8
|
const fields = typeof where === 'string' ? { 'agentage.where': where } : where;
|
|
9
9
|
logs.push({ level: 'error', message: messageOf(err), fields: { ...fields, err } });
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
2
|
+
import { type ImagePartKind as Part } from '../manifest/primitives.schema.js';
|
|
1
3
|
export interface Secrets {
|
|
2
4
|
}
|
|
3
5
|
export declare const SECRETS_DIR = "/run/secrets";
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const readSecrets: (pkg: ExtensionPackage, part: Part, dir: string) => Promise<Readonly<Record<string, string>>>;
|
|
7
|
+
export declare const withAbsent: (values: Record<string, string>, part: Part, pkg?: ExtensionPackage) => Record<string, string>;
|
package/dist/context/secrets.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import {} from '../manifest/manifest.schema.js';
|
|
4
|
+
import { mountedIn, unmountedIn } from '../manifest/parts.js';
|
|
5
|
+
import { camelName } from '../manifest/primitives.schema.js';
|
|
3
6
|
export const SECRETS_DIR = '/run/secrets';
|
|
4
|
-
export const camelName = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
5
7
|
// Only a missing file reads as no value; any other error stops the part with its code.
|
|
6
8
|
const valueOf = (file, refused) => readFile(file, 'utf8').then((text) => text.replace(/\r?\n$/, ''), (err) => {
|
|
7
9
|
if (err.code === 'ENOENT')
|
|
@@ -9,7 +11,8 @@ const valueOf = (file, refused) => readFile(file, 'utf8').then((text) => text.re
|
|
|
9
11
|
throw new Error(`${refused} cannot be read: ${err.code ?? 'unknown'}`);
|
|
10
12
|
});
|
|
11
13
|
// Each declared name from its mounted file; a missing or empty file stops the part, named, never valued.
|
|
12
|
-
export const readSecrets = async (
|
|
14
|
+
export const readSecrets = async (pkg, part, dir) => {
|
|
15
|
+
const names = mountedIn(pkg, part);
|
|
13
16
|
const refused = (name) => `${part} refused to start: secret ${name}`;
|
|
14
17
|
const read = names.map(async (name) => [name, await valueOf(join(dir, name), refused(name))]);
|
|
15
18
|
const pairs = await Promise.all(read);
|
|
@@ -17,5 +20,16 @@ export const readSecrets = async (names, dir, part) => {
|
|
|
17
20
|
if (missing)
|
|
18
21
|
throw new Error(`${refused(missing[0])} has no value`);
|
|
19
22
|
const secrets = Object.fromEntries(pairs.map(([name, value]) => [camelName(name), value]));
|
|
20
|
-
return Object.freeze(secrets);
|
|
23
|
+
return Object.freeze(withAbsent(secrets, part, pkg));
|
|
24
|
+
};
|
|
25
|
+
// A secret of other parts throws on read, never reads empty; spread and keys skip it.
|
|
26
|
+
export const withAbsent = (values, part, pkg) => {
|
|
27
|
+
for (const name of unmountedIn(pkg, part))
|
|
28
|
+
Object.defineProperty(values, camelName(name), {
|
|
29
|
+
enumerable: false,
|
|
30
|
+
get: () => {
|
|
31
|
+
throw new Error(`secret ${name} is not mounted in ${part}`);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
return values;
|
|
21
35
|
};
|
|
@@ -11,7 +11,8 @@ import { memoryRuns } from '../worker/runs.js';
|
|
|
11
11
|
import { createScheduler } from '../worker/scheduler.js';
|
|
12
12
|
import {} from '../manifest/primitives.schema.js';
|
|
13
13
|
import { NO_PLATFORM, healthRegistrar, NO_STORE, } from './context.js';
|
|
14
|
-
import { packageExtension } from './package-extension.js';
|
|
14
|
+
import { packageExtension, packageManifest } from './package-extension.js';
|
|
15
|
+
import { withAbsent } from './secrets.js';
|
|
15
16
|
import { recordingLog } from './recording-log.js';
|
|
16
17
|
import { commandContext, } from './test-command-context.js';
|
|
17
18
|
export {} from './recording-log.js';
|
|
@@ -57,7 +58,7 @@ const identityOf = (options) => {
|
|
|
57
58
|
};
|
|
58
59
|
const serverContext = (options) => {
|
|
59
60
|
const logs = [];
|
|
60
|
-
const log = runLog(recordingLog(logs));
|
|
61
|
+
const log = runLog(recordingLog(logs), true);
|
|
61
62
|
const spans = [];
|
|
62
63
|
const { extension, ...open } = identityOf(options);
|
|
63
64
|
const store = testStore(open.store, recordingLog([]));
|
|
@@ -73,7 +74,7 @@ const serverContext = (options) => {
|
|
|
73
74
|
spans,
|
|
74
75
|
settings: { ...options.settings },
|
|
75
76
|
store: store ?? NO_STORE,
|
|
76
|
-
secrets: Object.freeze({ ...options.secrets }),
|
|
77
|
+
secrets: Object.freeze(withAbsent({ ...options.secrets }, extension.part, packageManifest())),
|
|
77
78
|
platform: Object.freeze({ ...(options.platform ?? NO_PLATFORM) }),
|
|
78
79
|
exits,
|
|
79
80
|
exit: () => void exits.push(Date.now()),
|
|
@@ -46,6 +46,7 @@ export declare const discoveryDocument: (record: ExtensionRecord, host: string)
|
|
|
46
46
|
} | undefined;
|
|
47
47
|
};
|
|
48
48
|
secrets?: string[] | undefined;
|
|
49
|
+
secretParts?: Record<string, ("pages" | "api" | "mcp" | "worker")[]> | undefined;
|
|
49
50
|
openapi?: string | undefined;
|
|
50
51
|
tools?: {
|
|
51
52
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatIssues, readJsonIfExists } from '../manifest/read-manifest.js';
|
|
2
2
|
import {} from '../manifest/manifest.schema.js';
|
|
3
|
-
import { normalizeParts } from '../manifest/parts.js';
|
|
3
|
+
import { normalizeParts, scopedSecrets } from '../manifest/parts.js';
|
|
4
4
|
import {} from '../manifest/primitives.schema.js';
|
|
5
5
|
import { ExtensionRecordSchema } from './discovery.schema.js';
|
|
6
6
|
export const DEFAULT_RECORD_FILE = '/run/agentage/agentage-extension.json';
|
|
@@ -15,7 +15,8 @@ const partsOf = (pkg, images, migrations) => {
|
|
|
15
15
|
};
|
|
16
16
|
// From the manifest, the build, the images by digest and what the code serves.
|
|
17
17
|
export const recordOf = (pkg, build, images, extras = {}) => {
|
|
18
|
-
const { id, commands
|
|
18
|
+
const { id, commands } = pkg.agentage;
|
|
19
|
+
const secrets = (pkg.agentage.secrets ?? []).filter((s) => typeof s === 'string');
|
|
19
20
|
const { commit, buildTime } = build;
|
|
20
21
|
const parts = partsOf(pkg, images, extras.migrations);
|
|
21
22
|
const record = { id, version: pkg.version, commit, buildTime, parts };
|
|
@@ -27,8 +28,10 @@ export const recordOf = (pkg, build, images, extras = {}) => {
|
|
|
27
28
|
record.commands = commands.map((command) => command.name);
|
|
28
29
|
if (extras.widgets)
|
|
29
30
|
record.widgets = extras.widgets;
|
|
30
|
-
if (secrets
|
|
31
|
+
if (secrets.length)
|
|
31
32
|
record.secrets = secrets;
|
|
33
|
+
if (Object.keys(scopedSecrets(pkg)).length)
|
|
34
|
+
record.secretParts = scopedSecrets(pkg);
|
|
32
35
|
return record;
|
|
33
36
|
};
|
|
34
37
|
export const validateRecord = (value) => {
|
|
@@ -45,5 +48,6 @@ export const loadRecord = async (file) => {
|
|
|
45
48
|
export const discoveryDocument = (record, host) => {
|
|
46
49
|
const { id, version, commit, buildTime, ...rest } = record;
|
|
47
50
|
delete rest.secrets;
|
|
51
|
+
delete rest.secretParts;
|
|
48
52
|
return { id, version, commit, buildTime, host, ...rest };
|
|
49
53
|
};
|
|
@@ -7,6 +7,12 @@ export declare const WidgetSchema: z.ZodObject<{
|
|
|
7
7
|
}, z.core.$strict>;
|
|
8
8
|
export declare const ExtensionRecordSchema: z.ZodObject<{
|
|
9
9
|
secrets: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
|
+
secretParts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodEnum<{
|
|
11
|
+
pages: "pages";
|
|
12
|
+
api: "api";
|
|
13
|
+
mcp: "mcp";
|
|
14
|
+
worker: "worker";
|
|
15
|
+
}>>>>;
|
|
10
16
|
id: z.ZodString;
|
|
11
17
|
version: z.ZodString;
|
|
12
18
|
commit: z.ZodString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CommandNameSchema, CommitSchema, ExtensionIdSchema, IMAGE_PART_KINDS, PrefixedToolNameSchema, SecretNameSchema, StoreKindSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
2
|
+
import { CommandNameSchema, CommitSchema, ExtensionIdSchema, IMAGE_PART_KINDS, PrefixedToolNameSchema, SecretNameSchema, SecretPartSchema, StoreKindSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
3
3
|
// registry host[:port]/owner/{id}-{part}@sha256: deployed by digest, a version's images never change.
|
|
4
4
|
const ImageDigestRefSchema = z
|
|
5
5
|
.string()
|
|
@@ -52,11 +52,22 @@ const imagesNameTheirExtension = (doc) => IMAGE_PART_KINDS.every((kind) => {
|
|
|
52
52
|
return image === undefined || image.includes(`/${doc.id}-${kind}@sha256:`);
|
|
53
53
|
});
|
|
54
54
|
const IMAGE_RULE = { message: 'every image is {id}-{part}', path: ['parts'] };
|
|
55
|
+
// A scoped name lives only in secretParts, so an estate that does not read it mounts nothing.
|
|
56
|
+
const scoped = (name) => `secret ${name}: one or more parts, none repeated, and never also in secrets`;
|
|
55
57
|
// The build record: written by `build --push` into the package and the release asset; no host.
|
|
56
|
-
// Secret names are for the estate's mounts only; discovery leaves them out.
|
|
58
|
+
// Secret names and scoped parts are for the estate's mounts only; discovery leaves them out.
|
|
57
59
|
export const ExtensionRecordSchema = z
|
|
58
|
-
.strictObject({
|
|
59
|
-
|
|
60
|
+
.strictObject({
|
|
61
|
+
...recordShape,
|
|
62
|
+
secrets: z.array(SecretNameSchema).min(1).optional(),
|
|
63
|
+
secretParts: z.record(SecretNameSchema, z.array(SecretPartSchema)).optional(),
|
|
64
|
+
})
|
|
65
|
+
.refine(imagesNameTheirExtension, IMAGE_RULE)
|
|
66
|
+
.superRefine((doc, ctx) => {
|
|
67
|
+
for (const [name, parts] of Object.entries(doc.secretParts ?? {}))
|
|
68
|
+
if (!parts.length || new Set(parts).size !== parts.length || doc.secrets?.includes(name))
|
|
69
|
+
ctx.addIssue({ code: 'custom', path: ['secretParts', name], message: scoped(name) });
|
|
70
|
+
});
|
|
60
71
|
// What a deployment serves at /.well-known/agentage-extension.json: the record plus its host.
|
|
61
72
|
export const DiscoveryDocumentSchema = z
|
|
62
73
|
.strictObject({ ...recordShape, host: OriginSchema })
|
package/dist/health/health.js
CHANGED
|
@@ -16,7 +16,9 @@ const settle = async (check) => {
|
|
|
16
16
|
timer = setTimeout(() => resolve('unavailable'), CHECK_TIMEOUT_MS).unref();
|
|
17
17
|
});
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
const status = await Promise.race([check(), expiry]);
|
|
20
|
+
// A check answering anything but a status is not a healthy one.
|
|
21
|
+
return Object.hasOwn(RANK, status) ? status : 'unavailable';
|
|
20
22
|
}
|
|
21
23
|
catch {
|
|
22
24
|
return 'unavailable';
|
package/dist/log/log.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { type Fields, type
|
|
2
|
-
export type LogLevel = Level;
|
|
1
|
+
import { type Fields, type Logger, type LoggerOptions } from '../vendor/logs/index.js';
|
|
3
2
|
export type LogFields = Fields;
|
|
4
3
|
export type Log = Logger;
|
|
5
|
-
export interface LogTags {
|
|
6
|
-
extension: string;
|
|
7
|
-
part: string;
|
|
8
|
-
version?: string;
|
|
9
|
-
base?: LogFields;
|
|
10
|
-
}
|
|
11
|
-
export type LogWrite = (line: string) => void;
|
|
12
4
|
export declare const messageOf: (error: unknown) => string;
|
|
13
|
-
export declare const createLog: (tags:
|
|
5
|
+
export declare const createLog: (tags: Pick<LoggerOptions, "extension" | "part" | "version" | "base">, write?: LoggerOptions["write"]) => Log;
|
package/dist/log/log.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { createLogger } from '../vendor/logs/index.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export const
|
|
2
|
+
import { requestScope } from '../agcid/current.js';
|
|
3
|
+
// Never throws: a value with no printable form (a null-prototype object) reads [unprintable].
|
|
4
|
+
export const messageOf = (error) => {
|
|
5
|
+
try {
|
|
6
|
+
return error instanceof Error ? String(error.message) : String(error);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return '[unprintable]';
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const createLog = (tags, write) => createLogger({ ...tags, context: () => requestScope.getStore(), write });
|
package/dist/log/who.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type UserType } from '../vendor/logs/index.js';
|
|
2
2
|
type Header = (name: string) => string | undefined;
|
|
3
|
+
export declare const printable: (text: string | undefined) => string;
|
|
3
4
|
export declare const declaredType: (header: Header) => UserType | undefined;
|
|
4
5
|
export declare const clientOf: (header: Header) => string | null;
|
|
5
6
|
export declare const userTypeOf: (header: Header, path: string) => UserType;
|
package/dist/log/who.js
CHANGED
|
@@ -14,12 +14,14 @@ const AI = ['claude-code', 'cursor', 'chatgpt'];
|
|
|
14
14
|
const BOT = /bot|crawl|spider|slurp|scan|nikto|zgrab|masscan/i;
|
|
15
15
|
const BOT_PATH = /\.(php|asp|aspx|env)$|^\/wp-|^\/\.git/i;
|
|
16
16
|
const MACHINE = /^(curl|wget|node|undici|python|go-http|axios|java|okhttp|libwww)/i;
|
|
17
|
+
// A header value as a line: control characters out (the length cut is the caller's).
|
|
18
|
+
export const printable = (text) => (text ?? '').replace(/[\u0000-\u001f\u007f]/g, '');
|
|
17
19
|
export const declaredType = (header) => {
|
|
18
20
|
const declared = header('x-client-type');
|
|
19
21
|
return declared && DECLARED.includes(declared) ? declared : undefined;
|
|
20
22
|
};
|
|
21
23
|
export const clientOf = (header) => {
|
|
22
|
-
const named = header('x-client')
|
|
24
|
+
const named = printable(header('x-client')).trim().toLowerCase().slice(0, 64);
|
|
23
25
|
if (named)
|
|
24
26
|
return named;
|
|
25
27
|
const agent = header('user-agent') ?? '';
|
|
@@ -41,6 +43,6 @@ export const userTypeOf = (header, path) => {
|
|
|
41
43
|
export const whoOf = (header, path) => ({
|
|
42
44
|
user_type: userTypeOf(header, path),
|
|
43
45
|
client: clientOf(header),
|
|
44
|
-
session: header('agsid')
|
|
46
|
+
session: printable(header('agsid')).slice(0, 128) || null,
|
|
45
47
|
sub: null,
|
|
46
48
|
});
|
|
@@ -117,7 +117,15 @@ export declare const PackageSchema: z.ZodObject<{
|
|
|
117
117
|
enum: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
118
118
|
description: z.ZodOptional<z.ZodString>;
|
|
119
119
|
}, z.core.$strict>>>;
|
|
120
|
-
secrets: z.ZodOptional<z.ZodArray<z.ZodString
|
|
120
|
+
secrets: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
121
|
+
name: z.ZodString;
|
|
122
|
+
parts: z.ZodArray<z.ZodEnum<{
|
|
123
|
+
pages: "pages";
|
|
124
|
+
api: "api";
|
|
125
|
+
mcp: "mcp";
|
|
126
|
+
worker: "worker";
|
|
127
|
+
}>>;
|
|
128
|
+
}, z.core.$strict>]>>>;
|
|
121
129
|
}, z.core.$strict>;
|
|
122
130
|
}, z.core.$loose>;
|
|
123
131
|
export type CodePart = z.infer<typeof CodePartSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CommandNameSchema, ExtensionIdSchema, FIRST_PARTY_IDS, PackageNameSchema, PackagePathSchema, SecretNameSchema, SemverRangeSchema, SettingKeySchema, StoreKindSchema, VersionSchema, } from './primitives.schema.js';
|
|
2
|
+
import { camelName, CommandNameSchema, ExtensionIdSchema, FIRST_PARTY_IDS, PackageNameSchema, PackagePathSchema, SecretNameSchema, SecretPartSchema, SemverRangeSchema, SettingKeySchema, StoreKindSchema, VersionSchema, } from './primitives.schema.js';
|
|
3
3
|
const CodePartSchema = z.union([
|
|
4
4
|
z.boolean(),
|
|
5
5
|
z.strictObject({ entry: PackagePathSchema.optional() }),
|
|
@@ -47,12 +47,17 @@ const SettingSchema = z
|
|
|
47
47
|
.refine((setting) => !setting.enum || setting.enum.includes(String(setting.default)), {
|
|
48
48
|
message: 'default is not one of enum',
|
|
49
49
|
});
|
|
50
|
+
// A plain name goes to every part but ui; the object form to the parts it names only.
|
|
51
|
+
const SecretSchema = z.union([
|
|
52
|
+
SecretNameSchema,
|
|
53
|
+
z.strictObject({ name: SecretNameSchema, parts: z.array(SecretPartSchema).min(1) }),
|
|
54
|
+
]);
|
|
50
55
|
const AgentageBaseSchema = z.strictObject({
|
|
51
56
|
id: ExtensionIdSchema,
|
|
52
57
|
parts: PartsSchema,
|
|
53
58
|
commands: z.array(CommandSchema).min(1).optional(),
|
|
54
59
|
settings: z.record(SettingKeySchema, SettingSchema).optional(),
|
|
55
|
-
secrets: z.array(
|
|
60
|
+
secrets: z.array(SecretSchema).optional(),
|
|
56
61
|
});
|
|
57
62
|
const AgentageSchema = AgentageBaseSchema.superRefine(crossFieldRules);
|
|
58
63
|
export const PackageSchema = z
|
|
@@ -87,6 +92,12 @@ function crossFieldRules(manifest, ctx) {
|
|
|
87
92
|
const names = (manifest.commands ?? []).map((command) => command.name);
|
|
88
93
|
if (new Set(names).size !== names.length)
|
|
89
94
|
issue('command names must be unique', ['commands']);
|
|
95
|
+
for (const s of manifest.secrets ?? [])
|
|
96
|
+
if (typeof s === 'object' && s.parts.some((part) => !isOn(manifest.parts[part])))
|
|
97
|
+
issue(`secret ${s.name} names a part the extension does not have`, ['secrets']);
|
|
98
|
+
const ids = (manifest.secrets ?? []).map((s) => camelName(typeof s === 'string' ? s : s.name));
|
|
99
|
+
if (new Set(ids).size !== ids.length)
|
|
100
|
+
issue('secret names must be unique', ['secrets']);
|
|
90
101
|
if (manifest.settings?.['mcp.listing'] && !isOn(manifest.parts.mcp)) {
|
|
91
102
|
issue('mcp.listing needs the mcp part', ['settings', 'mcp.listing']);
|
|
92
103
|
}
|
package/dist/manifest/parts.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface NormalizedParts {
|
|
|
9
9
|
export declare const normalizeParts: (parts: Parts) => NormalizedParts;
|
|
10
10
|
export declare const imageParts: (pkg: ExtensionPackage) => ImagePartKind[];
|
|
11
11
|
export declare const entryOf: (pkg: ExtensionPackage, part: ImagePartKind | "cli") => string;
|
|
12
|
+
export declare const secretNames: (pkg: ExtensionPackage) => string[];
|
|
13
|
+
export declare const scopedSecrets: (pkg: ExtensionPackage) => {
|
|
14
|
+
[k: string]: ("pages" | "api" | "mcp" | "worker")[];
|
|
15
|
+
};
|
|
16
|
+
export declare const mountedIn: (pkg: ExtensionPackage, part: ImagePartKind, names?: string[]) => string[];
|
|
17
|
+
export declare const unmountedIn: (pkg: ExtensionPackage | undefined, part: ImagePartKind) => string[];
|
|
12
18
|
export declare const storeOf: (pkg: ExtensionPackage) => StoreKind | undefined;
|
|
13
19
|
export declare const hasStore: (pkg: ExtensionPackage, kind: StoreKind) => boolean;
|
|
14
20
|
export declare const migratesStore: (pkg: ExtensionPackage) => boolean;
|
package/dist/manifest/parts.js
CHANGED
|
@@ -22,6 +22,14 @@ export const imageParts = (pkg) => {
|
|
|
22
22
|
return IMAGE_PART_KINDS.filter((kind) => code[kind] !== undefined);
|
|
23
23
|
};
|
|
24
24
|
export const entryOf = (pkg, part) => normalizeParts(pkg.agentage.parts).code[part]?.entry ?? `./dist/${part}/index.js`;
|
|
25
|
+
export const secretNames = (pkg) => (pkg.agentage.secrets ?? []).map((s) => (typeof s === 'string' ? s : s.name));
|
|
26
|
+
const scopedOf = (pkg) => (pkg.agentage.secrets ?? []).flatMap((s) => (typeof s === 'string' ? [] : [s]));
|
|
27
|
+
export const scopedSecrets = (pkg) => Object.fromEntries(scopedOf(pkg).map((s) => [s.name, s.parts]));
|
|
28
|
+
export const mountedIn = (pkg, part, names = secretNames(pkg)) => {
|
|
29
|
+
const scoped = new Map(scopedOf(pkg).map((s) => [s.name, s.parts]));
|
|
30
|
+
return names.filter((n) => part !== 'ui' && (scoped.get(n)?.includes(part) ?? true));
|
|
31
|
+
};
|
|
32
|
+
export const unmountedIn = (pkg, part) => pkg ? secretNames(pkg).filter((n) => !mountedIn(pkg, part).includes(n)) : [];
|
|
25
33
|
export const storeOf = (pkg) => normalizeParts(pkg.agentage.parts).store;
|
|
26
34
|
export const hasStore = (pkg, kind) => storeOf(pkg) === kind;
|
|
27
35
|
// The migrate rule: the api image carries migrations/ and a migrate job only for such a kind.
|
|
@@ -34,4 +34,11 @@ export declare const CommitSchema: z.ZodString;
|
|
|
34
34
|
export declare const PrefixedToolNameSchema: z.ZodString;
|
|
35
35
|
export declare const IMAGE_PART_KINDS: readonly ["pages", "ui", "api", "mcp", "worker"];
|
|
36
36
|
export type ImagePartKind = (typeof IMAGE_PART_KINDS)[number];
|
|
37
|
+
export declare const camelName: (name: string) => string;
|
|
38
|
+
export declare const SecretPartSchema: z.ZodEnum<{
|
|
39
|
+
pages: "pages";
|
|
40
|
+
api: "api";
|
|
41
|
+
mcp: "mcp";
|
|
42
|
+
worker: "worker";
|
|
43
|
+
}>;
|
|
37
44
|
export type StoreKind = keyof typeof STORE_KINDS;
|
|
@@ -60,3 +60,5 @@ export const PrefixedToolNameSchema = z
|
|
|
60
60
|
.max(64)
|
|
61
61
|
.regex(/^[a-z][a-z0-9-]*__[a-z][a-z0-9_-]*$/);
|
|
62
62
|
export const IMAGE_PART_KINDS = ['pages', 'ui', 'api', 'mcp', 'worker'];
|
|
63
|
+
export const camelName = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
64
|
+
export const SecretPartSchema = z.enum(['pages', 'api', 'mcp', 'worker']);
|
package/dist/mcp/mcp-app.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createMcpHandler } from '@modelcontextprotocol/server';
|
|
|
6
6
|
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
|
-
import { declaredType } from '../log/who.js';
|
|
9
|
+
import { declaredType, printable } from '../log/who.js';
|
|
10
10
|
import { BODY_LIMIT, createPartApp, PUBLIC_CORS } from '../server/app.js';
|
|
11
11
|
import { serverFactory } from './server.js';
|
|
12
12
|
import { prefixed } from './tools.js';
|
|
@@ -63,7 +63,7 @@ const markRow = (options, req, res, body) => {
|
|
|
63
63
|
}
|
|
64
64
|
const name = messages.find((m) => m?.method === 'initialize')?.params?.clientInfo?.name;
|
|
65
65
|
if (typeof name === 'string')
|
|
66
|
-
res.locals['clientInfo'] = name.slice(0, 64);
|
|
66
|
+
res.locals['clientInfo'] = printable(name).slice(0, 64);
|
|
67
67
|
};
|
|
68
68
|
const webRequest = (req, body) => {
|
|
69
69
|
const headers = new Headers();
|
package/dist/runtime/run-part.js
CHANGED
|
@@ -99,8 +99,7 @@ export const runPart = async (options) => {
|
|
|
99
99
|
const part = partOf(pkg, options.part);
|
|
100
100
|
const log = createLog({ extension: pkg.agentage.id, part, version: pkg.version });
|
|
101
101
|
running = log;
|
|
102
|
-
const
|
|
103
|
-
const secrets = await readSecrets(names, options.secretsDir ?? SECRETS_DIR, part);
|
|
102
|
+
const secrets = await readSecrets(pkg, part, options.secretsDir ?? SECRETS_DIR);
|
|
104
103
|
const start = { pkg, part, env: options.env, log, secrets };
|
|
105
104
|
const { app, stop } = await RUNNERS[part](await inputFor(options, start));
|
|
106
105
|
if (stop)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {} from 'express';
|
|
2
|
-
import { requestScope } from '../agcid/current.js';
|
|
2
|
+
import { requestScope, sigtermOnce } from '../agcid/current.js';
|
|
3
3
|
import {} from '../log/log.js';
|
|
4
4
|
const MOUNTS = ['/api/v1', '/mcp', '/.well-known', '/ui'];
|
|
5
5
|
const ASSET = /\.(m?js|css|map|png|jpe?g|gif|svg|ico|webp|avif|woff2?|ttf)$/i;
|
|
@@ -38,7 +38,7 @@ export const requestLine = (log) => (req, res, next) => {
|
|
|
38
38
|
clientInfo: localOf(res, 'clientInfo'),
|
|
39
39
|
});
|
|
40
40
|
if (scope?.exit)
|
|
41
|
-
|
|
41
|
+
sigtermOnce();
|
|
42
42
|
});
|
|
43
43
|
next();
|
|
44
44
|
};
|
package/dist/server/serve.js
CHANGED
|
@@ -7,18 +7,30 @@ export const listen = (app, port, host) => new Promise((resolve, reject) => {
|
|
|
7
7
|
const done = (err) => (err ? reject(err) : resolve(server));
|
|
8
8
|
const server = host === undefined ? app.listen(port, done) : app.listen(port, host, done);
|
|
9
9
|
});
|
|
10
|
-
// SIGTERM drains
|
|
10
|
+
// SIGTERM drains; a close error or a drain past the grace period exits 1; a second Ctrl-C at once.
|
|
11
11
|
export const shutdownOn = (server, options) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const exitWith = options.exit ?? ((code) => process.exit(code));
|
|
13
|
+
let [stopping, exited] = [false, false];
|
|
14
|
+
const exit = (code) => {
|
|
15
|
+
if (exited)
|
|
16
|
+
return;
|
|
17
|
+
exited = true;
|
|
18
|
+
exitWith(code);
|
|
19
|
+
};
|
|
20
|
+
const stop = (signal) => {
|
|
21
|
+
if (stopping && signal === 'SIGINT')
|
|
22
|
+
exit(130);
|
|
23
|
+
if (stopping)
|
|
24
|
+
return;
|
|
25
|
+
stopping = true;
|
|
14
26
|
options.log.info('shutting down');
|
|
15
|
-
server.close(() => exit(0));
|
|
27
|
+
server.close((err) => exit(err ? 1 : 0));
|
|
16
28
|
server.closeIdleConnections();
|
|
17
|
-
setTimeout(() => exit(
|
|
29
|
+
setTimeout(() => exit(1), GRACE_MS).unref();
|
|
18
30
|
};
|
|
19
31
|
for (const signal of options.signals ?? ['SIGTERM', 'SIGINT'])
|
|
20
|
-
process.
|
|
21
|
-
return stop;
|
|
32
|
+
process.on(signal, () => stop(signal));
|
|
33
|
+
return () => stop();
|
|
22
34
|
};
|
|
23
35
|
export const serve = async (options) => {
|
|
24
36
|
const server = await listen(options.app, options.port);
|
package/dist/tool/up/compose.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {} from '../../manifest/manifest.schema.js';
|
|
2
|
-
import { hasStore, imageParts } from '../../manifest/parts.js';
|
|
2
|
+
import { hasStore, imageParts, mountedIn } from '../../manifest/parts.js';
|
|
3
3
|
import {} from '../../manifest/primitives.schema.js';
|
|
4
4
|
import { DEV_AUDIENCE, DEV_ISSUER, UP_ISSUER } from './dev-issuer-app.js';
|
|
5
5
|
import { GATEWAY_PORT, ISSUER_PORT, PART_PORT, TRAEFIK_COMMAND, TRAEFIK_IMAGE } from './gateway.js';
|
|
@@ -33,11 +33,12 @@ const dependsOn = (pkg, part) => ({
|
|
|
33
33
|
...(hasStore(pkg, 'postgres') && part !== 'ui' ? { store: HEALTHY } : {}),
|
|
34
34
|
...(part === 'api' || part === 'mcp' ? { issuer: HEALTHY } : {}),
|
|
35
35
|
});
|
|
36
|
+
const withSecrets = (names) => (names.length ? { secrets: names } : {});
|
|
36
37
|
const partService = (input, part) => ({
|
|
37
38
|
image: input.tags[part],
|
|
38
39
|
environment: partEnv(input.pkg, part),
|
|
39
40
|
volumes: [`${input.recordFile}:${RECORD_TARGET}:ro`],
|
|
40
|
-
...(
|
|
41
|
+
...withSecrets(mountedIn(input.pkg, part, Object.keys(input.secretFiles ?? {}))),
|
|
41
42
|
depends_on: dependsOn(input.pkg, part),
|
|
42
43
|
});
|
|
43
44
|
const secretsOf = (files) => Object.fromEntries(Object.entries(files).map(([name, file]) => [name, { file }]));
|
|
@@ -33,6 +33,7 @@ export declare const writeLocalRecord: (dir: string, pkg: ExtensionPackage, buil
|
|
|
33
33
|
} | undefined;
|
|
34
34
|
};
|
|
35
35
|
secrets?: string[] | undefined;
|
|
36
|
+
secretParts?: Record<string, ("pages" | "api" | "mcp" | "worker")[]> | undefined;
|
|
36
37
|
openapi?: string | undefined;
|
|
37
38
|
tools?: {
|
|
38
39
|
name: string;
|
package/dist/tool/up/secrets.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { chmod, mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import {} from '../../manifest/manifest.schema.js';
|
|
4
|
+
import { secretNames } from '../../manifest/parts.js';
|
|
4
5
|
import { readJsonIfExists } from '../../manifest/read-manifest.js';
|
|
5
6
|
import {} from '../../runtime/build-info.js';
|
|
6
7
|
import { LOCAL_DIR } from './local-record.js';
|
|
@@ -19,7 +20,7 @@ const valueOf = (name, env, file) => {
|
|
|
19
20
|
};
|
|
20
21
|
// Each value as a file compose mounts at /run/secrets/<name>; the env wins over the file.
|
|
21
22
|
export const writeUpSecrets = async (dir, pkg, env) => {
|
|
22
|
-
const names = pkg
|
|
23
|
+
const names = secretNames(pkg);
|
|
23
24
|
if (names.length === 0)
|
|
24
25
|
return undefined;
|
|
25
26
|
const file = await fileValues(dir);
|
|
@@ -2,7 +2,6 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const KINDS: readonly ["http", "mcp", "job", "span", "error", "event", "log"];
|
|
3
3
|
export declare const LEVELS: readonly ["info", "warn", "error"];
|
|
4
4
|
export declare const USER_TYPES: readonly ["user", "agent", "automation", "service", "test", "bot"];
|
|
5
|
-
export declare const AGCID_HEX: RegExp;
|
|
6
5
|
export type Kind = (typeof KINDS)[number];
|
|
7
6
|
export type Level = (typeof LEVELS)[number];
|
|
8
7
|
export type UserType = (typeof USER_TYPES)[number];
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
export const KINDS = ['http', 'mcp', 'job', 'span', 'error', 'event', 'log'];
|
|
3
3
|
export const LEVELS = ['info', 'warn', 'error'];
|
|
4
4
|
export const USER_TYPES = ['user', 'agent', 'automation', 'service', 'test', 'bot'];
|
|
5
|
-
|
|
5
|
+
const AGCID_HEX = /^[0-9a-f]{32}$/;
|
|
6
6
|
const name = z.string().min(1).max(64);
|
|
7
7
|
const id = z.string().max(128).nullable().default(null);
|
|
8
8
|
// The line (logs-events section 1): snake_case on the wire; host is set by the shipper or the client.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Event, type EventInput, type Level } from './event.schema.js';
|
|
2
|
-
export declare const MAX_BATCH_BYTES = 900000;
|
|
3
2
|
export declare const MAX_BATCH_ITEMS = 1000;
|
|
4
3
|
export interface EventsClientOptions {
|
|
5
4
|
url: string;
|
|
6
5
|
token: string;
|
|
7
6
|
host?: string;
|
|
8
7
|
timeoutMs?: number;
|
|
8
|
+
retryDelayMs?: number;
|
|
9
9
|
fetch?: typeof fetch;
|
|
10
10
|
}
|
|
11
11
|
export type PostEvent = Omit<EventInput, 'ts' | 'level'> & {
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { hostname } from 'node:os';
|
|
2
2
|
import { EventSchema } from './event.schema.js';
|
|
3
|
-
import { redact } from './redact.js';
|
|
3
|
+
import { redact, scrub } from './redact.js';
|
|
4
4
|
import { uuidv7 } from './uuidv7.js';
|
|
5
|
-
|
|
5
|
+
const MAX_BATCH_BYTES = 900_000;
|
|
6
6
|
export const MAX_BATCH_ITEMS = 1000;
|
|
7
|
+
// A row the schema refuses is dropped with a warning and counted as rejected; the rest still go.
|
|
7
8
|
const complete = (event, host) => {
|
|
8
9
|
const filled = { ts: new Date().toISOString(), level: 'info', agcid: uuidv7(), host, ...event };
|
|
9
|
-
|
|
10
|
+
const msg = typeof event.msg === 'string' ? scrub(event.msg) : event.msg;
|
|
11
|
+
const parsed = EventSchema.safeParse({ ...filled, msg, fields: redact(event.fields ?? {}) });
|
|
12
|
+
if (parsed.success)
|
|
13
|
+
return parsed.data;
|
|
14
|
+
process.emitWarning(`@agentage/logs: dropped an invalid row (${parsed.error.issues[0]?.path.join('.')})`);
|
|
15
|
+
return null;
|
|
10
16
|
};
|
|
11
17
|
const sizeOf = (event) => Buffer.byteLength(JSON.stringify(event)) + 1;
|
|
12
18
|
// A row alone over the batch limit would be a 413: it is dropped with a warning instead.
|
|
13
19
|
const fitting = (event) => {
|
|
20
|
+
if (event === null)
|
|
21
|
+
return false;
|
|
14
22
|
if (sizeOf(event) + 2 <= MAX_BATCH_BYTES)
|
|
15
23
|
return true;
|
|
16
24
|
process.emitWarning(`@agentage/logs: dropped a ${event.kind} row over 900 KB`);
|
|
@@ -50,25 +58,31 @@ const sendOnce = async (o, body) => {
|
|
|
50
58
|
});
|
|
51
59
|
if (!res.ok)
|
|
52
60
|
throw new IngestError(res.status);
|
|
53
|
-
|
|
61
|
+
// A 2xx was taken: an unreadable answer is never retried, it would post the rows twice.
|
|
62
|
+
const reply = (await res.json().catch(() => ({})));
|
|
54
63
|
return reply.data ?? { accepted: 0, rejected: 0 };
|
|
55
64
|
};
|
|
56
|
-
const
|
|
65
|
+
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
66
|
+
const send = (o, body) => sendOnce(o, body).catch(async (err) => {
|
|
57
67
|
if (!retries(err))
|
|
58
68
|
throw err;
|
|
69
|
+
await pause(o.retryDelayMs ?? 1000);
|
|
59
70
|
return sendOnce(o, body);
|
|
60
71
|
});
|
|
72
|
+
const post = async (o, events) => {
|
|
73
|
+
if (!o.url || !o.token)
|
|
74
|
+
throw new Error('@agentage/logs: the events client needs a url and a token');
|
|
75
|
+
const host = o.host ?? hostname();
|
|
76
|
+
const rows = events.map((event) => complete(event, host)).filter(fitting);
|
|
77
|
+
const total = { accepted: 0, rejected: events.length - rows.length };
|
|
78
|
+
for (const batch of batchesOf(rows)) {
|
|
79
|
+
const result = await send(o, JSON.stringify(batch));
|
|
80
|
+
total.accepted += result.accepted;
|
|
81
|
+
total.rejected += result.rejected;
|
|
82
|
+
}
|
|
83
|
+
return total;
|
|
84
|
+
};
|
|
61
85
|
// Posts rows to the ingest; a refused or unreachable ingest rejects: the caller catches.
|
|
62
86
|
export const createEventsClient = (o) => ({
|
|
63
|
-
post:
|
|
64
|
-
const host = o.host ?? hostname();
|
|
65
|
-
const total = { accepted: 0, rejected: 0 };
|
|
66
|
-
const rows = events.map((event) => complete(event, host)).filter(fitting);
|
|
67
|
-
for (const batch of batchesOf(rows)) {
|
|
68
|
-
const result = await send(o, JSON.stringify(batch));
|
|
69
|
-
total.accepted += result.accepted;
|
|
70
|
-
total.rejected += result.rejected;
|
|
71
|
-
}
|
|
72
|
-
return total;
|
|
73
|
-
},
|
|
87
|
+
post: (events) => post(o, events),
|
|
74
88
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EventSchema, KINDS, LEVELS, USER_TYPES, type Event, type EventInput, type Fields, type Kind, type Level, type UserType, } from './event.schema.js';
|
|
2
2
|
export { parseLine, type LineSource } from './parse-line.js';
|
|
3
|
+
export { uuidv7 } from './uuidv7.js';
|
|
3
4
|
export { createLogger, type Logger, type LoggerOptions, type RowContext } from './logger.js';
|
|
4
5
|
export { type HttpRow, type JobRow, type McpRow, type Row } from './rows.js';
|
|
5
6
|
export { createEventsClient, type EventsClientOptions, type PostEvent, type PostResult, } from './events-client.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EventSchema, KINDS, LEVELS, USER_TYPES, } from './event.schema.js';
|
|
2
2
|
export { parseLine } from './parse-line.js';
|
|
3
|
+
export { uuidv7 } from './uuidv7.js';
|
|
3
4
|
export { createLogger } from './logger.js';
|
|
4
5
|
export {} from './rows.js';
|
|
5
6
|
export { createEventsClient, } from './events-client.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {} from './event.schema.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { eventRow, httpRow, jobRow, mcpRow, spanRow, } from './rows.js';
|
|
2
|
+
import { redact, scrub, stringOf } from './redact.js';
|
|
3
|
+
import { errorRow, eventRow, httpRow, jobRow, mcpRow, spanRow, } from './rows.js';
|
|
5
4
|
const timed = async (fn, end) => {
|
|
6
5
|
const start = performance.now();
|
|
7
6
|
const ms = () => Math.round(performance.now() - start);
|
|
@@ -15,42 +14,70 @@ const timed = async (fn, end) => {
|
|
|
15
14
|
throw err;
|
|
16
15
|
}
|
|
17
16
|
};
|
|
18
|
-
//
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
error: (err, where) => row(errorRow(err, where)),
|
|
23
|
-
http: (o) => {
|
|
24
|
-
const r = httpRow(o);
|
|
17
|
+
// Builds and writes a row; outside a strict log, a failed row is dropped, never thrown at the caller.
|
|
18
|
+
const guarded = (row, strict) => (build) => {
|
|
19
|
+
try {
|
|
20
|
+
const r = build();
|
|
25
21
|
if (r)
|
|
26
22
|
row(r);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
if (strict)
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Every method is a row; row is the one sink, so a wrapper replaces only it.
|
|
30
|
+
const loggerOf = (row, strict = false) => {
|
|
31
|
+
const emit = guarded(row, strict);
|
|
32
|
+
return {
|
|
33
|
+
info: (msg, fields = {}) => emit(() => ({ kind: 'log', level: 'info', msg, fields })),
|
|
34
|
+
warn: (msg, fields = {}) => emit(() => ({ kind: 'log', level: 'warn', msg, fields })),
|
|
35
|
+
error: (err, where) => emit(() => errorRow(err, where)),
|
|
36
|
+
http: (o) => emit(() => httpRow(o)),
|
|
37
|
+
mcp: (o) => emit(() => mcpRow(o)),
|
|
38
|
+
job: (o) => emit(() => jobRow(o)),
|
|
39
|
+
span: (name, fn) => timed(fn, (ms, err) => emit(() => spanRow(name, ms, err))),
|
|
40
|
+
event: (name, fields = {}, msg) => emit(() => eventRow(name, fields, msg)),
|
|
41
|
+
row: (r) => emit(() => r),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const CONTROL = /[\u0000-\u001f\u007f]/g;
|
|
45
|
+
// A line over this is written without its fields: a shipper splits longer lines.
|
|
46
|
+
export const MAX_LINE_BYTES = 64 * 1024;
|
|
47
|
+
const text = (value, max) => value == null ? null : scrub(stringOf(value).replace(CONTROL, ''), max) || null;
|
|
48
|
+
// The columns the kit sets from request headers and tokens, bounded as the schema bounds them.
|
|
49
|
+
const columnsOf = (o, r) => {
|
|
35
50
|
const c = o.context?.() ?? {};
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
msg: r.msg.slice(0, MAX_STRING),
|
|
41
|
-
extension: o.extension,
|
|
42
|
-
part: o.part,
|
|
43
|
-
version: o.version ?? '',
|
|
51
|
+
const { extension, part, version = '' } = o;
|
|
52
|
+
const [level, kind, msg] = [r.level, r.kind, scrub(r.msg)];
|
|
53
|
+
return {
|
|
54
|
+
...{ ts: new Date().toISOString(), level, kind, msg, extension, part, version },
|
|
44
55
|
...(o.host ? { host: o.host } : {}),
|
|
45
56
|
agcid: c.agcid ?? null,
|
|
46
|
-
sub: c.sub
|
|
47
|
-
session: c.session
|
|
57
|
+
sub: text(c.sub, 128),
|
|
58
|
+
session: text(c.session, 128),
|
|
48
59
|
user_type: c.user_type ?? 'service',
|
|
49
|
-
client: c.client
|
|
50
|
-
fields: redact({ ...o.base, ...r.fields }),
|
|
60
|
+
client: text(c.client, 64),
|
|
51
61
|
};
|
|
52
|
-
return `${JSON.stringify(event)}\n`;
|
|
53
62
|
};
|
|
54
|
-
const
|
|
63
|
+
const lineOf = (o, r) => {
|
|
64
|
+
const columns = columnsOf(o, r);
|
|
65
|
+
const line = JSON.stringify({
|
|
66
|
+
...columns,
|
|
67
|
+
fields: { ...redact(o.base ?? {}), ...redact(r.fields) },
|
|
68
|
+
});
|
|
69
|
+
if (Buffer.byteLength(line) <= MAX_LINE_BYTES)
|
|
70
|
+
return `${line}\n`;
|
|
71
|
+
return `${JSON.stringify({ ...columns, fields: { 'agentage.dropped': 'fields over 64 KB' } })}\n`;
|
|
72
|
+
};
|
|
73
|
+
let quiet = false;
|
|
74
|
+
// A closed stderr (EPIPE) emits an error event; with no listener that would crash the part.
|
|
75
|
+
const stderr = (line) => {
|
|
76
|
+
if (!quiet) {
|
|
77
|
+
process.stderr.on('error', () => undefined);
|
|
78
|
+
quiet = true;
|
|
79
|
+
}
|
|
80
|
+
process.stderr.write(line);
|
|
81
|
+
};
|
|
55
82
|
// One JSON line per unit of work on stderr; the host ships it.
|
|
56
|
-
export const createLogger = (o) => loggerOf(o.sink ?? ((r) => (o.write ?? stderr)(lineOf(o, r))));
|
|
83
|
+
export const createLogger = (o) => loggerOf(o.sink ?? ((r) => (o.write ?? stderr)(lineOf(o, r))), o.strict);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventSchema } from './event.schema.js';
|
|
2
|
-
import {
|
|
2
|
+
import { cut, redact, scrub } from './redact.js';
|
|
3
3
|
const RAW_ERROR = /\b(ERROR|FATAL)\b/;
|
|
4
4
|
const jsonOf = (text) => {
|
|
5
5
|
try {
|
|
@@ -10,20 +10,21 @@ const jsonOf = (text) => {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
13
|
-
|
|
13
|
+
const nameOf = (value) => cut(value ?? '', 64) || 'unknown';
|
|
14
|
+
// Not a valid event: a raw log row, a JSON object keeping its keys; both redacted as the logger does.
|
|
14
15
|
export const parseLine = (text, source = {}) => {
|
|
15
16
|
const line = text.trim();
|
|
16
17
|
const json = jsonOf(line);
|
|
17
18
|
const parsed = EventSchema.safeParse(json);
|
|
18
19
|
if (parsed.success)
|
|
19
|
-
return parsed.data;
|
|
20
|
+
return { ...parsed.data, msg: scrub(parsed.data.msg), fields: redact(parsed.data.fields) };
|
|
20
21
|
return EventSchema.parse({
|
|
21
22
|
ts: new Date().toISOString(),
|
|
22
23
|
level: RAW_ERROR.test(line) ? 'error' : 'info',
|
|
23
24
|
kind: 'log',
|
|
24
|
-
msg: line
|
|
25
|
-
extension: source.extension
|
|
26
|
-
part: source.part
|
|
25
|
+
msg: scrub(line),
|
|
26
|
+
extension: nameOf(source.extension),
|
|
27
|
+
part: nameOf(source.part),
|
|
27
28
|
fields: { ...(isObject(json) ? redact(json) : {}), 'agentage.raw': true },
|
|
28
29
|
});
|
|
29
30
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type Fields } from './event.schema.js';
|
|
2
2
|
export declare const MAX_STRING = 200;
|
|
3
|
+
export declare const cut: (text: string, max: number) => string;
|
|
4
|
+
export declare const stringOf: (value: unknown) => string;
|
|
5
|
+
export declare const scrub: (text: unknown, max?: number) => string;
|
|
6
|
+
export declare const read: (value: object, key: string) => unknown;
|
|
3
7
|
export declare const redact: (fields: Fields) => Fields;
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
import {} from './event.schema.js';
|
|
2
2
|
const SECRET = /token|secret|password|key|authorization|cookie/i;
|
|
3
|
+
// A JWT (three parts, or a token-length first part a cut left), an aga_ PAT, a Bearer credential.
|
|
4
|
+
const JWT = String.raw `(?<![\w-])eyJ(?:[\w-]{8,}\.[\w-]+\.[\w-]*|[\w-]{17,}(?:\.[\w-]*)?)`;
|
|
5
|
+
const PAT = String.raw `(?<![\w-])aga_[\w.-]{16,}`;
|
|
6
|
+
// An opaque Bearer value is mixed case with a digit, or 32 characters and more.
|
|
7
|
+
const OPAQUE = String.raw `(?=[\w.~+/=-]*\d)(?=[\w.~+/=-]*[A-Z])[\w.~+/=-]{16,}|[\w.~+/=-]{32,}`;
|
|
8
|
+
const BEARER = String.raw `\b[Bb]earer\s+(?:${OPAQUE})`;
|
|
9
|
+
const CREDENTIAL = new RegExp(`${JWT}|${PAT}|${BEARER}`, 'g');
|
|
3
10
|
export const MAX_STRING = 200;
|
|
4
11
|
const MAX_STACK = 2000;
|
|
5
12
|
const MAX_DEPTH = 3;
|
|
6
|
-
|
|
13
|
+
// On a code point boundary: a cut never leaves half a surrogate pair.
|
|
14
|
+
export const cut = (text, max) => text.length > max ? text.slice(0, max).replace(/[\uD800-\uDBFF]$/, '') : text;
|
|
15
|
+
export const stringOf = (value) => {
|
|
16
|
+
try {
|
|
17
|
+
return typeof value === 'string' ? value : String(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return '[unprintable]';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
// Masked before the cut, so the cut never leaves a credential shape half-matched.
|
|
24
|
+
export const scrub = (text, max = MAX_STRING) => cut(stringOf(text).replace(CREDENTIAL, '[redacted]'), max);
|
|
25
|
+
export const read = (value, key) => {
|
|
26
|
+
try {
|
|
27
|
+
return Reflect.get(value, key);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return '[unreadable]';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
7
33
|
const clean = (value, depth) => {
|
|
8
34
|
if (typeof value === 'string')
|
|
9
|
-
return
|
|
35
|
+
return scrub(value);
|
|
36
|
+
if (typeof value === 'bigint')
|
|
37
|
+
return value.toString();
|
|
10
38
|
if (value === null || typeof value !== 'object')
|
|
11
39
|
return value;
|
|
12
40
|
if (depth >= MAX_DEPTH)
|
|
13
41
|
return '[depth]';
|
|
14
42
|
if (Array.isArray(value))
|
|
15
43
|
return value.map((item) => clean(item, depth + 1));
|
|
16
|
-
const entries = Object.
|
|
44
|
+
const entries = Object.keys(value).map((k) => [k, keyed(k, read(value, k), depth + 1)]);
|
|
17
45
|
return Object.fromEntries(entries);
|
|
18
46
|
};
|
|
19
47
|
// A stack keeps more than 200 characters: the first in-app frame is rarely in the first line.
|
|
@@ -21,7 +49,15 @@ const keyed = (key, value, depth) => {
|
|
|
21
49
|
if (SECRET.test(key))
|
|
22
50
|
return '[redacted]';
|
|
23
51
|
if (key === 'exception.stacktrace' && typeof value === 'string')
|
|
24
|
-
return
|
|
52
|
+
return scrub(value, MAX_STACK);
|
|
25
53
|
return clean(value, depth);
|
|
26
54
|
};
|
|
27
|
-
|
|
55
|
+
// Never throws: a getter that throws reads [unreadable], a bigint its digits, a proxy that throws empty.
|
|
56
|
+
export const redact = (fields) => {
|
|
57
|
+
try {
|
|
58
|
+
return clean(fields, 0);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return { 'agentage.unreadable': true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -26,9 +26,9 @@ export interface JobRow {
|
|
|
26
26
|
ms: number;
|
|
27
27
|
error?: unknown;
|
|
28
28
|
}
|
|
29
|
-
export declare const typeOf: (err: unknown) => string;
|
|
30
29
|
export declare const httpRow: (o: HttpRow) => Row | null;
|
|
31
30
|
export declare const mcpRow: (o: McpRow) => Row;
|
|
32
31
|
export declare const jobRow: (o: JobRow) => Row;
|
|
33
32
|
export declare const spanRow: (name: string, ms: number, error?: unknown) => Row;
|
|
34
33
|
export declare const eventRow: (name: string, fields: Fields, msg?: string) => Row;
|
|
34
|
+
export declare const errorRow: (err: unknown, where?: string | Fields) => Row;
|
package/dist/vendor/logs/rows.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {} from './event.schema.js';
|
|
2
|
+
import { cut, MAX_STRING, read, stringOf } from './redact.js';
|
|
2
3
|
const HEALTH = /^\/(health|healthz|livez|readyz)$/;
|
|
3
|
-
|
|
4
|
+
const typeOf = (err) => (err instanceof Error ? err.name : 'Error');
|
|
4
5
|
const failed = (err) => (err === undefined ? {} : { 'error.type': typeOf(err) });
|
|
5
6
|
const httpLevel = (status, ms) => status >= 500 ? 'error' : status >= 400 || ms > 1000 ? 'warn' : 'info';
|
|
6
7
|
// Health probes leave no row (logs-events Q2).
|
|
7
8
|
export const httpRow = (o) => {
|
|
8
9
|
if (HEALTH.test(o.route))
|
|
9
10
|
return null;
|
|
10
|
-
const route = o.route
|
|
11
|
+
const route = cut(o.route, MAX_STRING);
|
|
11
12
|
const fields = {
|
|
12
13
|
'http.request.method': o.method,
|
|
13
14
|
'http.route': route,
|
|
@@ -55,3 +56,13 @@ export const eventRow = (name, fields, msg = name) => ({
|
|
|
55
56
|
msg,
|
|
56
57
|
fields: { 'event.name': name, ...fields },
|
|
57
58
|
});
|
|
59
|
+
// where: the route, tool or job; an author's agentage.fingerprint passes through (Q11 A).
|
|
60
|
+
export const errorRow = (err, where) => {
|
|
61
|
+
const own = typeof where === 'string' ? { 'agentage.where': where } : (where ?? {});
|
|
62
|
+
const error = err instanceof Error;
|
|
63
|
+
const text = (key) => stringOf(read(err, key) ?? '');
|
|
64
|
+
const [type, message] = error ? [text('name'), text('message')] : ['Error', stringOf(err)];
|
|
65
|
+
const stack = error ? { 'exception.stacktrace': text('stack') } : {};
|
|
66
|
+
const fields = { 'exception.type': type, 'exception.message': message, ...stack, ...own };
|
|
67
|
+
return { kind: 'error', level: 'error', msg: `${type}: ${message}`, fields };
|
|
68
|
+
};
|
package/dist/worker/run-log.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export interface RunBuffer {
|
|
|
6
6
|
}
|
|
7
7
|
export declare const withRunBuffer: <T>(buffer: RunBuffer, fn: () => Promise<T>) => Promise<T>;
|
|
8
8
|
export declare const append: (buffer: RunBuffer, line: string) => void;
|
|
9
|
-
export declare const runLog: (base: Log) => Log;
|
|
9
|
+
export declare const runLog: (base: Log, strict?: boolean) => Log;
|
package/dist/worker/run-log.js
CHANGED
|
@@ -23,10 +23,11 @@ const record = (level, message) => {
|
|
|
23
23
|
append(buffer, `${level} ${message}`);
|
|
24
24
|
};
|
|
25
25
|
// ctx.log for a worker: the usual JSON line, and inside a run also the run's own log.
|
|
26
|
-
export const runLog = (base) => ({
|
|
26
|
+
export const runLog = (base, strict = false) => ({
|
|
27
27
|
...createLogger({
|
|
28
28
|
extension: 'worker',
|
|
29
29
|
part: 'worker',
|
|
30
|
+
strict,
|
|
30
31
|
sink: (row) => {
|
|
31
32
|
record(row.level, row.msg);
|
|
32
33
|
base.row(row);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.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",
|
|
@@ -288,9 +288,41 @@
|
|
|
288
288
|
"secrets": {
|
|
289
289
|
"type": "array",
|
|
290
290
|
"items": {
|
|
291
|
-
"
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
"anyOf": [
|
|
292
|
+
{
|
|
293
|
+
"type": "string",
|
|
294
|
+
"maxLength": 48,
|
|
295
|
+
"pattern": "^[a-z][a-z0-9-]*$"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"type": "object",
|
|
299
|
+
"properties": {
|
|
300
|
+
"name": {
|
|
301
|
+
"type": "string",
|
|
302
|
+
"maxLength": 48,
|
|
303
|
+
"pattern": "^[a-z][a-z0-9-]*$"
|
|
304
|
+
},
|
|
305
|
+
"parts": {
|
|
306
|
+
"minItems": 1,
|
|
307
|
+
"type": "array",
|
|
308
|
+
"items": {
|
|
309
|
+
"type": "string",
|
|
310
|
+
"enum": [
|
|
311
|
+
"pages",
|
|
312
|
+
"api",
|
|
313
|
+
"mcp",
|
|
314
|
+
"worker"
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
"required": [
|
|
320
|
+
"name",
|
|
321
|
+
"parts"
|
|
322
|
+
],
|
|
323
|
+
"additionalProperties": false
|
|
324
|
+
}
|
|
325
|
+
]
|
|
294
326
|
}
|
|
295
327
|
}
|
|
296
328
|
},
|
|
@@ -192,6 +192,26 @@
|
|
|
192
192
|
"maxLength": 48,
|
|
193
193
|
"pattern": "^[a-z][a-z0-9-]*$"
|
|
194
194
|
}
|
|
195
|
+
},
|
|
196
|
+
"secretParts": {
|
|
197
|
+
"type": "object",
|
|
198
|
+
"propertyNames": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"maxLength": 48,
|
|
201
|
+
"pattern": "^[a-z][a-z0-9-]*$"
|
|
202
|
+
},
|
|
203
|
+
"additionalProperties": {
|
|
204
|
+
"type": "array",
|
|
205
|
+
"items": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"enum": [
|
|
208
|
+
"pages",
|
|
209
|
+
"api",
|
|
210
|
+
"mcp",
|
|
211
|
+
"worker"
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
195
215
|
}
|
|
196
216
|
},
|
|
197
217
|
"required": [
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {} from './event.schema.js';
|
|
2
|
-
import { typeOf } from './rows.js';
|
|
3
|
-
const exceptionOf = (err) => err instanceof Error
|
|
4
|
-
? {
|
|
5
|
-
'exception.type': typeOf(err),
|
|
6
|
-
'exception.message': err.message,
|
|
7
|
-
'exception.stacktrace': err.stack ?? '',
|
|
8
|
-
}
|
|
9
|
-
: { 'exception.type': 'Error', 'exception.message': String(err) };
|
|
10
|
-
// where: the route, tool or job; an author's agentage.fingerprint passes through (Q11 A).
|
|
11
|
-
export const errorRow = (err, where) => {
|
|
12
|
-
const own = typeof where === 'string' ? { 'agentage.where': where } : (where ?? {});
|
|
13
|
-
const exception = exceptionOf(err);
|
|
14
|
-
const msg = `${String(exception['exception.type'])}: ${String(exception['exception.message'])}`;
|
|
15
|
-
return { kind: 'error', level: 'error', msg, fields: { ...exception, ...own } };
|
|
16
|
-
};
|