@agentage/extension 0.7.0 → 0.9.0
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/agcid/agcid.d.ts +1 -3
- package/dist/agcid/agcid.js +2 -3
- package/dist/agcid/current.d.ts +2 -0
- package/dist/agcid/current.js +1 -0
- package/dist/agcid/fetch.d.ts +1 -0
- package/dist/agcid/fetch.js +11 -0
- package/dist/agcid/header.d.ts +3 -0
- package/dist/agcid/header.js +3 -0
- package/dist/agcid/scope.js +4 -2
- package/dist/api/openapi-doc.d.ts +1 -0
- package/dist/api/openapi-doc.js +5 -3
- package/dist/api/routes.js +2 -5
- package/dist/auth/part-auth.d.ts +1 -0
- package/dist/auth/part-auth.js +1 -1
- package/dist/auth/revoked.js +2 -1
- package/dist/auth/token-check.d.ts +5 -2
- package/dist/auth/token-check.js +10 -3
- package/dist/auth/verify-token.js +2 -2
- package/dist/command/check-cli.js +3 -2
- package/dist/command/cli-context.d.ts +15 -0
- package/dist/command/cli-context.js +37 -0
- package/dist/command/command.types.d.ts +13 -0
- package/dist/command/command.types.js +4 -0
- package/dist/command/run-command.d.ts +4 -1
- package/dist/command/run-command.js +12 -8
- package/dist/context/context.d.ts +2 -0
- package/dist/context/context.js +4 -2
- package/dist/context/recording-log.d.ts +7 -0
- package/dist/context/recording-log.js +10 -0
- package/dist/context/test-command-context.d.ts +36 -0
- package/dist/context/test-command-context.js +60 -0
- package/dist/context/test-context.d.ts +6 -23
- package/dist/context/test-context.js +10 -35
- package/dist/contracts/index.d.ts +6 -0
- package/dist/contracts/index.js +6 -0
- package/dist/envelope/envelope.schema.js +1 -1
- package/dist/index.d.ts +8 -12
- package/dist/index.js +7 -10
- package/dist/log/log.d.ts +6 -0
- package/dist/log/log.js +29 -8
- package/dist/log/span.d.ts +9 -0
- package/dist/log/span.js +19 -0
- package/dist/mcp/snapshot.js +2 -1
- package/dist/mcp/tools.js +5 -4
- package/dist/pages/pages-app.js +2 -3
- package/dist/runtime/build-info.d.ts +1 -0
- package/dist/runtime/build-info.js +2 -1
- package/dist/runtime/part-runners.js +7 -1
- package/dist/runtime/run-part.js +1 -1
- package/dist/server/api-routes.js +1 -1
- package/dist/server/app.js +3 -0
- package/dist/server/request-line.d.ts +4 -0
- package/dist/server/request-line.js +25 -0
- package/dist/store/migrate.js +1 -1
- package/dist/tool/build-info.js +4 -4
- package/dist/tool/index.d.ts +4 -1
- package/dist/tool/index.js +4 -1
- package/dist/worker/run-log.js +7 -3
- package/dist/worker/runs.d.ts +1 -0
- package/dist/worker/runs.js +4 -2
- package/dist/worker/scheduler.js +8 -1
- package/package.json +5 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createRouteRegistry } from '../api/routes.js';
|
|
2
2
|
import {} from '../api/well-known.js';
|
|
3
|
-
import {} from '../
|
|
4
|
-
import {
|
|
5
|
-
import { messageOf } from '../log/log.js';
|
|
3
|
+
import {} from '../log/log.js';
|
|
4
|
+
import { createSpan } from '../log/span.js';
|
|
6
5
|
import { createToolRegistry } from '../mcp/tools.js';
|
|
7
6
|
import { migrate } from '../store/migrations.js';
|
|
8
7
|
import { createTestStore } from '../store/test-store.js';
|
|
@@ -11,18 +10,12 @@ import { runLog } from '../worker/run-log.js';
|
|
|
11
10
|
import { memoryRuns } from '../worker/runs.js';
|
|
12
11
|
import { createScheduler } from '../worker/scheduler.js';
|
|
13
12
|
import {} from '../manifest/primitives.schema.js';
|
|
14
|
-
import { packageExtension } from './package-extension.js';
|
|
15
13
|
import { NO_STORE } from './context.js';
|
|
16
|
-
import {} from '
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
level: 'error',
|
|
22
|
-
message: messageOf(error),
|
|
23
|
-
fields: { ...fields, err: error },
|
|
24
|
-
}),
|
|
25
|
-
});
|
|
14
|
+
import { packageExtension } from './package-extension.js';
|
|
15
|
+
import { recordingLog } from './recording-log.js';
|
|
16
|
+
import { commandContext, } from './test-command-context.js';
|
|
17
|
+
export {} from './recording-log.js';
|
|
18
|
+
export {} from './test-command-context.js';
|
|
26
19
|
const testStore = (option, log) => {
|
|
27
20
|
if (!option)
|
|
28
21
|
return undefined;
|
|
@@ -65,6 +58,7 @@ const identityOf = (options) => {
|
|
|
65
58
|
const serverContext = (options) => {
|
|
66
59
|
const logs = [];
|
|
67
60
|
const log = runLog(recordingLog(logs));
|
|
61
|
+
const spans = [];
|
|
68
62
|
const { extension, ...open } = identityOf(options);
|
|
69
63
|
const store = testStore(open.store, recordingLog([]));
|
|
70
64
|
const caller = { sub: 'usr_test', scopes: [`${extension.id}:read`] };
|
|
@@ -73,6 +67,8 @@ const serverContext = (options) => {
|
|
|
73
67
|
auth: { caller: () => caller },
|
|
74
68
|
log,
|
|
75
69
|
logs,
|
|
70
|
+
span: createSpan(log, spans),
|
|
71
|
+
spans,
|
|
76
72
|
settings: { ...options.settings },
|
|
77
73
|
store: store ?? NO_STORE,
|
|
78
74
|
secrets: Object.freeze({ ...options.secrets }),
|
|
@@ -80,27 +76,6 @@ const serverContext = (options) => {
|
|
|
80
76
|
...recorders(log),
|
|
81
77
|
};
|
|
82
78
|
};
|
|
83
|
-
// One recorded line per line written, the trailing newline dropped.
|
|
84
|
-
const lines = (into) => (text) => void into.push(...text.replace(/\n$/, '').split('\n'));
|
|
85
|
-
const commandContext = (options) => {
|
|
86
|
-
const output = { stdout: [], stderr: [] };
|
|
87
|
-
const out = createOut({
|
|
88
|
-
json: options.json ?? false,
|
|
89
|
-
stdout: lines(output.stdout),
|
|
90
|
-
stderr: lines(output.stderr),
|
|
91
|
-
});
|
|
92
|
-
const { id = 'test', version = '0.0.0' } = packageExtension();
|
|
93
|
-
const extension = { id, version, ...options.extension, part: 'cli' };
|
|
94
|
-
return {
|
|
95
|
-
extension,
|
|
96
|
-
args: { ...options.args },
|
|
97
|
-
out,
|
|
98
|
-
output,
|
|
99
|
-
get exitCode() {
|
|
100
|
-
return out.exitCode;
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
79
|
export function createTestContext(options = {}) {
|
|
105
80
|
return 'args' in options ? commandContext(options) : serverContext(options);
|
|
106
81
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
|
|
2
|
+
export { DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from '../discovery/discovery.schema.js';
|
|
3
|
+
export { ERROR_CODES, type ErrorCode } from '../envelope/codes.js';
|
|
4
|
+
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from '../envelope/envelope.schema.js';
|
|
5
|
+
export { type ErrorEnvelope, type OkEnvelope } from '../envelope/envelope.js';
|
|
6
|
+
export { HealthSchema, type HealthBody, type HealthStatus } from '../health/health.schema.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
|
|
2
|
+
export { DiscoveryDocumentSchema, ExtensionRecordSchema, } from '../discovery/discovery.schema.js';
|
|
3
|
+
export { ERROR_CODES } from '../envelope/codes.js';
|
|
4
|
+
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from '../envelope/envelope.schema.js';
|
|
5
|
+
export {} from '../envelope/envelope.js';
|
|
6
|
+
export { HealthSchema } from '../health/health.schema.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { AGCID_PATTERN } from '../agcid/
|
|
2
|
+
import { AGCID_PATTERN } from '../agcid/header.js';
|
|
3
3
|
import { ERROR_CODES } from './codes.js';
|
|
4
4
|
const AgcidSchema = z.string().regex(AGCID_PATTERN);
|
|
5
5
|
const ErrorCodeSchema = z.enum(ERROR_CODES);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,24 +2,20 @@ export { type ApiContext, type ParamsOf, type RouteHandler, type RouteMethod, ty
|
|
|
2
2
|
export { pageOf, PageQuerySchema, type Pagination } from './api/page.js';
|
|
3
3
|
export { type Access, type Caller } from './auth/token-check.js';
|
|
4
4
|
export { type ArgValue } from './command/args.js';
|
|
5
|
-
export { type CliContext, type CliCreate, type CommandExtension, type CommandHandler, } from './command/command.types.js';
|
|
5
|
+
export { type CliClient, type CliContext, type CliCreate, type CommandExtension, type CommandHandler, } from './command/command.types.js';
|
|
6
6
|
export { type Out } from './command/out.js';
|
|
7
7
|
export { type ExtensionInfo, type PartContext, type ServerPartKind, type SettingValue, } from './context/context.js';
|
|
8
8
|
export { type Secrets } from './context/secrets.js';
|
|
9
|
-
export { createTestContext, type LogEntry, type ScheduledJob, type TestCommandContext, type TestCommandOptions, type TestContext, type TestContextOptions, } from './context/test-context.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
9
|
+
export { createTestContext, type ClientCall, type LogEntry, type ScheduledJob, type TestCommandContext, type TestCommandOptions, type TestContext, type TestContextOptions, } from './context/test-context.js';
|
|
10
|
+
export { type DiscoveryDocument, type ExtensionRecord } from './discovery/discovery.schema.js';
|
|
11
|
+
export { ERROR_STATUS, type ErrorCode } from './envelope/codes.js';
|
|
12
|
+
export { fail, ok, reply, type ErrorDetail, type ErrorEnvelope, type Failure, type FailOptions, type OkEnvelope, type Reply, type ReplyOptions, } from './envelope/envelope.js';
|
|
13
|
+
export { DiscoveryDocumentSchema } from './discovery/discovery.schema.js';
|
|
14
14
|
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from './envelope/envelope.schema.js';
|
|
15
15
|
export { parse, type ParseSchema } from './envelope/parse.js';
|
|
16
|
-
export {
|
|
16
|
+
export { type HealthBody, type HealthStatus } from './health/health.schema.js';
|
|
17
17
|
export { type Log, type LogFields } from './log/log.js';
|
|
18
|
-
export {
|
|
19
|
-
export { imageParts } from './manifest/parts.js';
|
|
20
|
-
export { SERVED_KINDS, STORE_KINDS, type StoreKind } from './manifest/primitives.schema.js';
|
|
21
|
-
export { readManifest, validateManifest } from './manifest/read-manifest.js';
|
|
22
|
-
export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, type McpSnapshot, type ProtocolVersion, } from './mcp/snapshot.js';
|
|
18
|
+
export { type Span, type SpanRecord } from './log/span.js';
|
|
23
19
|
export { type McpContext, type ToolHandler, type ToolRegistrar, type ToolSpec, } from './mcp/tools.js';
|
|
24
20
|
export { versionPage, type PagesContext, type PagesSite } from './pages/pages.js';
|
|
25
21
|
export { type ApiCreate, type ApiHandler, type ApiPart } from './server/part.types.js';
|
package/dist/index.js
CHANGED
|
@@ -7,19 +7,16 @@ export {} from './command/out.js';
|
|
|
7
7
|
export {} from './context/context.js';
|
|
8
8
|
export {} from './context/secrets.js';
|
|
9
9
|
export { createTestContext, } from './context/test-context.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
|
|
10
|
+
export {} from './discovery/discovery.schema.js';
|
|
11
|
+
export { ERROR_STATUS } from './envelope/codes.js';
|
|
12
|
+
export { fail, ok, reply, } from './envelope/envelope.js';
|
|
13
|
+
// Also in /contracts: main drops them once probe master's e2e reads them from there.
|
|
14
|
+
export { DiscoveryDocumentSchema } from './discovery/discovery.schema.js';
|
|
14
15
|
export { ErrorEnvelopeSchema, OkEnvelopeSchema } from './envelope/envelope.schema.js';
|
|
15
16
|
export { parse } from './envelope/parse.js';
|
|
16
|
-
export {
|
|
17
|
+
export {} from './health/health.schema.js';
|
|
17
18
|
export {} from './log/log.js';
|
|
18
|
-
export {
|
|
19
|
-
export { imageParts } from './manifest/parts.js';
|
|
20
|
-
export { SERVED_KINDS, STORE_KINDS } from './manifest/primitives.schema.js';
|
|
21
|
-
export { readManifest, validateManifest } from './manifest/read-manifest.js';
|
|
22
|
-
export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, } from './mcp/snapshot.js';
|
|
19
|
+
export {} from './log/span.js';
|
|
23
20
|
export {} from './mcp/tools.js';
|
|
24
21
|
export { versionPage } from './pages/pages.js';
|
|
25
22
|
export {} from './server/part.types.js';
|
package/dist/log/log.d.ts
CHANGED
|
@@ -8,7 +8,13 @@ export interface Log {
|
|
|
8
8
|
export interface LogTags {
|
|
9
9
|
extension: string;
|
|
10
10
|
part: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
base?: LogFields;
|
|
11
13
|
}
|
|
12
14
|
export type LogWrite = (line: string) => void;
|
|
13
15
|
export declare const messageOf: (error: unknown) => string;
|
|
16
|
+
export declare const errorFields: (error: unknown) => LogFields;
|
|
17
|
+
export type LineAt = (level: LogLevel, message: string, fields: LogFields) => void;
|
|
18
|
+
export declare const withLineAt: (log: Log, at: LineAt) => Log;
|
|
14
19
|
export declare const createLog: (tags: LogTags, write?: LogWrite) => Log;
|
|
20
|
+
export declare const logAt: (log: Log, level: LogLevel, message: string, fields: LogFields) => void;
|
package/dist/log/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { currentAgcid } from '../agcid/current.js';
|
|
2
2
|
export const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
3
|
-
const errorFields = (error) => {
|
|
3
|
+
export const errorFields = (error) => {
|
|
4
4
|
if (!(error instanceof Error))
|
|
5
5
|
return { err: { message: String(error) } };
|
|
6
6
|
return { err: { type: error.name, message: error.message, stack: error.stack } };
|
|
@@ -9,13 +9,34 @@ const errorFields = (error) => {
|
|
|
9
9
|
const line = (level, message, tags, fields) => {
|
|
10
10
|
const agcid = currentAgcid();
|
|
11
11
|
const ids = { 'extension.id': tags.extension, 'extension.part': tags.part };
|
|
12
|
-
const
|
|
12
|
+
const version = tags.version === undefined ? {} : { version: tags.version };
|
|
13
|
+
const own = { time: new Date().toISOString(), level, msg: message, ...ids, ...version };
|
|
13
14
|
const fixed = agcid ? { ...own, agcid } : own;
|
|
14
|
-
return `${JSON.stringify({ ...fixed, ...fields, ...fixed })}\n`;
|
|
15
|
+
return `${JSON.stringify({ ...fixed, ...tags.base, ...fields, ...fixed })}\n`;
|
|
15
16
|
};
|
|
16
17
|
const stderrWrite = (text) => void process.stderr.write(text);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const raw = new WeakMap();
|
|
19
|
+
// Registers how a Log writes a line as given, so logAt keeps every field on it.
|
|
20
|
+
export const withLineAt = (log, at) => {
|
|
21
|
+
raw.set(log, at);
|
|
22
|
+
return log;
|
|
23
|
+
};
|
|
24
|
+
export const createLog = (tags, write = stderrWrite) => {
|
|
25
|
+
const at = (level, message, fields) => write(line(level, message, tags, fields));
|
|
26
|
+
const log = {
|
|
27
|
+
info: (message, fields = {}) => at('info', message, fields),
|
|
28
|
+
warn: (message, fields = {}) => at('warn', message, fields),
|
|
29
|
+
error: (error, fields = {}) => at('error', messageOf(error), { ...fields, ...errorFields(error) }),
|
|
30
|
+
};
|
|
31
|
+
return withLineAt(log, at);
|
|
32
|
+
};
|
|
33
|
+
// A line at any level with no err field (an error-level line that is not an error event).
|
|
34
|
+
export const logAt = (log, level, message, fields) => {
|
|
35
|
+
const at = raw.get(log);
|
|
36
|
+
if (at)
|
|
37
|
+
at(level, message, fields);
|
|
38
|
+
else if (level === 'error')
|
|
39
|
+
log.error(message, fields);
|
|
40
|
+
else
|
|
41
|
+
log[level](message, fields);
|
|
42
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Log } from './log.js';
|
|
2
|
+
export interface SpanRecord {
|
|
3
|
+
name: string;
|
|
4
|
+
ms: number;
|
|
5
|
+
ok: boolean;
|
|
6
|
+
err?: unknown;
|
|
7
|
+
}
|
|
8
|
+
export type Span = <T>(name: string, fn: () => T | Promise<T>) => Promise<T>;
|
|
9
|
+
export declare const createSpan: (log: Log, spans?: SpanRecord[]) => Span;
|
package/dist/log/span.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { errorFields, logAt } from './log.js';
|
|
2
|
+
// One line per span; a nested span is its own line, the agcid on both links them.
|
|
3
|
+
export const createSpan = (log, spans) => async (name, fn) => {
|
|
4
|
+
const start = performance.now();
|
|
5
|
+
const end = (ok, err) => {
|
|
6
|
+
const span = { name, ms: Math.round(performance.now() - start), ok };
|
|
7
|
+
spans?.push(ok ? span : { ...span, err });
|
|
8
|
+
logAt(log, ok ? 'info' : 'error', 'span', ok ? span : { ...span, ...errorFields(err) });
|
|
9
|
+
};
|
|
10
|
+
try {
|
|
11
|
+
const value = await fn();
|
|
12
|
+
end(true);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
end(false, err);
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
};
|
package/dist/mcp/snapshot.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { kitFetch } from '../agcid/fetch.js';
|
|
1
2
|
export const PROTOCOL_VERSIONS = ['2025-11-25', '2026-07-28'];
|
|
2
3
|
const CLIENT = { name: 'agentage-snapshot', version: '1.0.0' };
|
|
3
4
|
// Key order never counts: the two eras serialize the same schema in different orders.
|
|
@@ -44,7 +45,7 @@ const post = async (url, version, method, params) => {
|
|
|
44
45
|
method,
|
|
45
46
|
params: modern ? { ...params, _meta: META } : params,
|
|
46
47
|
};
|
|
47
|
-
return payload(await
|
|
48
|
+
return payload(await kitFetch(url, { method: 'POST', headers, body: JSON.stringify(body) }));
|
|
48
49
|
};
|
|
49
50
|
const serverInfoOf = async (url, version) => {
|
|
50
51
|
if (version === '2025-11-25') {
|
package/dist/mcp/tools.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {} from 'zod';
|
|
2
|
-
import {} from '../auth/token-check.js';
|
|
2
|
+
import { ACCESS, badScope } from '../auth/token-check.js';
|
|
3
3
|
import {} from '../context/context.js';
|
|
4
4
|
const TOOL_NAME = /^[a-z][a-z0-9_-]*$/;
|
|
5
|
-
const
|
|
5
|
+
const TOOL_ACCESS = ACCESS.filter((access) => access !== 'optional');
|
|
6
6
|
export const createToolRegistry = () => {
|
|
7
7
|
const tools = [];
|
|
8
8
|
const tool = (name, spec, handler) => {
|
|
@@ -12,8 +12,9 @@ export const createToolRegistry = () => {
|
|
|
12
12
|
throw new Error(`tool ${name} is registered twice`);
|
|
13
13
|
if (!spec.description)
|
|
14
14
|
throw new Error(`tool ${name} needs a description: it routes the model`);
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const bad = badScope(spec.scope, TOOL_ACCESS);
|
|
16
|
+
if (bad)
|
|
17
|
+
throw new Error(`tool ${name} ${bad}`);
|
|
17
18
|
tools.push({ name, spec, handler: handler });
|
|
18
19
|
};
|
|
19
20
|
return { tool, tools };
|
package/dist/pages/pages-app.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { extname } from 'node:path';
|
|
2
2
|
import {} from 'express';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { isAudience } from '../auth/part-auth.js';
|
|
4
5
|
import {} from '../runtime/build-info.js';
|
|
5
6
|
import { createPartApp } from '../server/app.js';
|
|
6
7
|
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
8
|
const WEB = ['http:', 'https:'];
|
|
10
9
|
const webUrl = (url) => {
|
|
11
10
|
const parsed = url && URL.canParse(url) ? new URL(url) : undefined;
|
|
@@ -16,7 +15,7 @@ export const platformSources = (env) => {
|
|
|
16
15
|
const issuer = webUrl(env['AGENTAGE_ISSUER'])?.origin;
|
|
17
16
|
const scheme = webUrl(env['AGENTAGE_ORIGIN'])?.protocol ?? 'https:';
|
|
18
17
|
const audience = env['AGENTAGE_AUDIENCE'] ?? '';
|
|
19
|
-
return [issuer,
|
|
18
|
+
return [issuer, isAudience(audience) ? `${scheme}//${audience}` : undefined].filter((source) => Boolean(source));
|
|
20
19
|
};
|
|
21
20
|
const TYPES = { '.js': 'js', '.mjs': 'js', '.css': 'css', '.json': 'json' };
|
|
22
21
|
const SiteSchema = z.record(z.string().regex(/^\/[A-Za-z0-9._~/-]*$/), z.string());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type BuildInfo } from '../discovery/discovery.js';
|
|
2
2
|
export type Env = Readonly<Record<string, string | undefined>>;
|
|
3
3
|
export declare const isoSeconds: (date: Date) => string;
|
|
4
|
+
export declare const buildTimeOf: (env: Env, now: Date) => string;
|
|
4
5
|
export declare const buildInfoFromEnv: (env: Env, now?: Date) => BuildInfo;
|
|
5
6
|
export declare const portFromEnv: (env: Env, fallback?: number) => number;
|
|
@@ -3,10 +3,11 @@ import { FULL_SHA } from '../manifest/primitives.schema.js';
|
|
|
3
3
|
const UNKNOWN_COMMIT = '0'.repeat(40);
|
|
4
4
|
export const isoSeconds = (date) => `${date.toISOString().slice(0, 19)}Z`;
|
|
5
5
|
const commitOf = (sha = '') => (FULL_SHA.test(sha) ? sha : UNKNOWN_COMMIT);
|
|
6
|
+
export const buildTimeOf = (env, now) => env['BUILD_TIME'] || isoSeconds(now);
|
|
6
7
|
// COMMIT_SHA and BUILD_TIME are baked into every image by the recipe; a bare dev run shows zeros.
|
|
7
8
|
export const buildInfoFromEnv = (env, now = new Date()) => ({
|
|
8
9
|
commit: commitOf(env['COMMIT_SHA']),
|
|
9
|
-
buildTime: env
|
|
10
|
+
buildTime: buildTimeOf(env, now),
|
|
10
11
|
});
|
|
11
12
|
export const portFromEnv = (env, fallback = 3000) => {
|
|
12
13
|
const port = Number(env['PORT']);
|
|
@@ -6,6 +6,7 @@ import {} from '../manifest/manifest.schema.js';
|
|
|
6
6
|
import { loadCreate } from '../manifest/entry.js';
|
|
7
7
|
import { hasStore } from '../manifest/parts.js';
|
|
8
8
|
import {} from '../manifest/primitives.schema.js';
|
|
9
|
+
import { createSpan } from '../log/span.js';
|
|
9
10
|
import { createMcpApp } from '../mcp/mcp-app.js';
|
|
10
11
|
import { createToolRegistry } from '../mcp/tools.js';
|
|
11
12
|
import { createPagesApp, platformSources } from '../pages/pages-app.js';
|
|
@@ -48,7 +49,12 @@ const worker = async (input) => {
|
|
|
48
49
|
const log = runLog(ctx.log);
|
|
49
50
|
const runs = hasStore(input.pkg, 'postgres') ? storeRuns(ctx.store) : memoryRuns();
|
|
50
51
|
const scheduler = createScheduler({ runs, log });
|
|
51
|
-
await callCreate(input, 'worker', {
|
|
52
|
+
await callCreate(input, 'worker', {
|
|
53
|
+
...ctx,
|
|
54
|
+
log,
|
|
55
|
+
span: createSpan(log),
|
|
56
|
+
schedule: scheduler.schedule,
|
|
57
|
+
});
|
|
52
58
|
const checks = { ...input.base.checks, ...scheduler.checks() };
|
|
53
59
|
scheduler.start();
|
|
54
60
|
return {
|
package/dist/runtime/run-part.js
CHANGED
|
@@ -89,7 +89,7 @@ const inputFor = async (options, start) => {
|
|
|
89
89
|
export const runPart = async (options) => {
|
|
90
90
|
const pkg = await readManifest(options.dir);
|
|
91
91
|
const part = partOf(pkg, options.part);
|
|
92
|
-
const log = createLog({ extension: pkg.agentage.id, part });
|
|
92
|
+
const log = createLog({ extension: pkg.agentage.id, part, version: pkg.version });
|
|
93
93
|
const names = part === 'ui' ? [] : (pkg.agentage.secrets ?? []);
|
|
94
94
|
const secrets = await readSecrets(names, options.secretsDir ?? SECRETS_DIR, part);
|
|
95
95
|
const start = { pkg, part, env: options.env, log, secrets };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
import { inQuery } from '../api/openapi-doc.js';
|
|
2
3
|
import { createRouteRegistry } from '../api/routes.js';
|
|
3
4
|
import {} from '../api/well-known.js';
|
|
4
5
|
import {} from '../context/context.js';
|
|
5
6
|
import { isReply, ok, reply } from '../envelope/envelope.js';
|
|
6
7
|
import { parse } from '../envelope/parse.js';
|
|
7
8
|
import {} from './part.types.js';
|
|
8
|
-
const inQuery = (method) => method === 'get' || method === 'delete';
|
|
9
9
|
const inputOf = ({ method, spec }, query, body) => {
|
|
10
10
|
if (!spec.input)
|
|
11
11
|
return {};
|
package/dist/server/app.js
CHANGED
|
@@ -12,6 +12,7 @@ import {} from '../log/log.js';
|
|
|
12
12
|
import {} from '../manifest/manifest.schema.js';
|
|
13
13
|
import {} from '../manifest/primitives.schema.js';
|
|
14
14
|
import { errorHandler, notFound } from './errors.js';
|
|
15
|
+
import { requestLine } from './request-line.js';
|
|
15
16
|
import {} from './part.types.js';
|
|
16
17
|
// api-standards section 6: CORS * without credentials on /.well-known/, /api/, /ui/ and /mcp.
|
|
17
18
|
export const PUBLIC_CORS = {
|
|
@@ -48,6 +49,8 @@ export const createPartApp = (options) => {
|
|
|
48
49
|
app.set('trust proxy', 'loopback, linklocal, uniquelocal');
|
|
49
50
|
app.use(dropCookie, agcidMiddleware, helmet(options.helmet));
|
|
50
51
|
app.get('/health', healthHandler(options));
|
|
52
|
+
// After /health: it is probed every few seconds and never gets a request line.
|
|
53
|
+
app.use(requestLine(options.log));
|
|
51
54
|
if (options.part !== 'worker') {
|
|
52
55
|
app.use('/.well-known', cors(PUBLIC_CORS));
|
|
53
56
|
app.get('/.well-known/agentage-extension.json', discoveryHandler(options));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {} from 'express';
|
|
2
|
+
import { agcidOfResponse } from '../agcid/scope.js';
|
|
3
|
+
import { logAt } from '../log/log.js';
|
|
4
|
+
const MOUNTS = ['/api/v1', '/mcp', '/.well-known', '/ui'];
|
|
5
|
+
const levelOf = (status) => status >= 500 ? 'error' : status >= 400 ? 'warn' : 'info';
|
|
6
|
+
// The matched route template, never the raw URL, so no id or query string reaches the log.
|
|
7
|
+
export const routeOf = (req) => {
|
|
8
|
+
const url = req.originalUrl.split('?')[0] ?? '';
|
|
9
|
+
const prefix = MOUNTS.find((m) => url === m || url.startsWith(`${m}/`)) ?? '/';
|
|
10
|
+
const path = req.route?.path;
|
|
11
|
+
if (typeof path !== 'string')
|
|
12
|
+
return prefix;
|
|
13
|
+
return path.startsWith(prefix) ? path : `${prefix}${path}`;
|
|
14
|
+
};
|
|
15
|
+
// One line per request on finish; the 5xx error itself is errors.ts's line, never repeated here.
|
|
16
|
+
export const requestLine = (log) => (req, res, next) => {
|
|
17
|
+
const start = performance.now();
|
|
18
|
+
res.on('finish', () => {
|
|
19
|
+
const { statusCode: status } = res;
|
|
20
|
+
const ms = Math.round(performance.now() - start);
|
|
21
|
+
const fields = { agcid: agcidOfResponse(res), method: req.method, route: routeOf(req) };
|
|
22
|
+
logAt(log, levelOf(status), 'request', { ...fields, status, ms });
|
|
23
|
+
});
|
|
24
|
+
next();
|
|
25
|
+
};
|
package/dist/store/migrate.js
CHANGED
|
@@ -9,7 +9,7 @@ const MIGRATE_TIMEOUTS = { connectMs: 10_000, statementMs: 300_000 };
|
|
|
9
9
|
let log = createLog({ extension: 'unknown', part: 'migrate' });
|
|
10
10
|
try {
|
|
11
11
|
const pkg = await readManifest(process.cwd());
|
|
12
|
-
log = createLog({ extension: pkg.agentage.id, part: 'migrate' });
|
|
12
|
+
log = createLog({ extension: pkg.agentage.id, part: 'migrate', version: pkg.version });
|
|
13
13
|
const store = createStore(process.env, log, MIGRATE_TIMEOUTS);
|
|
14
14
|
const result = await migrate(store, process.cwd(), log);
|
|
15
15
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
package/dist/tool/build-info.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {} from '../discovery/discovery.js';
|
|
2
2
|
import { FULL_SHA } from '../manifest/primitives.schema.js';
|
|
3
|
-
import {
|
|
3
|
+
import { buildTimeOf } from '../runtime/build-info.js';
|
|
4
4
|
import { mustRun } from './exec.js';
|
|
5
|
-
const
|
|
5
|
+
const headCommit = async (dir, env, run) => {
|
|
6
6
|
const given = env['COMMIT_SHA'] || env['GITHUB_SHA'];
|
|
7
7
|
if (given)
|
|
8
8
|
return given;
|
|
@@ -10,8 +10,8 @@ const commitOf = async (dir, env, run) => {
|
|
|
10
10
|
};
|
|
11
11
|
// The commit every image label, /health and the record carry: CI's sha, else the checkout's HEAD.
|
|
12
12
|
export const resolveBuildInfo = async (dir, env, run, now = new Date()) => {
|
|
13
|
-
const commit = await
|
|
13
|
+
const commit = await headCommit(dir, env, run);
|
|
14
14
|
if (!FULL_SHA.test(commit))
|
|
15
15
|
throw new Error(`commit is not a full 40-hex sha: ${commit}`);
|
|
16
|
-
return { commit, buildTime: env
|
|
16
|
+
return { commit, buildTime: buildTimeOf(env, now) };
|
|
17
17
|
};
|
package/dist/tool/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { checkCli } from '../command/check-cli.js';
|
|
2
2
|
export { runCommand, type RunCommandOptions } from '../command/run-command.js';
|
|
3
|
-
export { type
|
|
3
|
+
export { PackageSchema, type CommandSpec, type ExtensionPackage, } from '../manifest/manifest.schema.js';
|
|
4
|
+
export { imageParts } from '../manifest/parts.js';
|
|
5
|
+
export { SERVED_KINDS, STORE_KINDS, type StoreKind } from '../manifest/primitives.schema.js';
|
|
4
6
|
export { readManifest, validateManifest } from '../manifest/read-manifest.js';
|
|
7
|
+
export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, type McpSnapshot, type ProtocolVersion, } from '../mcp/snapshot.js';
|
|
5
8
|
export { build, type BuildDeps, type BuildOptions, type BuildResult, type BuiltImage, } from './build.js';
|
|
6
9
|
export { check, type CheckProblem, type CheckReport } from './check.js';
|
|
7
10
|
export { writeContracts } from './contracts.js';
|
package/dist/tool/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { checkCli } from '../command/check-cli.js';
|
|
2
2
|
export { runCommand } from '../command/run-command.js';
|
|
3
|
-
export {} from '../manifest/manifest.schema.js';
|
|
3
|
+
export { PackageSchema, } from '../manifest/manifest.schema.js';
|
|
4
|
+
export { imageParts } from '../manifest/parts.js';
|
|
5
|
+
export { SERVED_KINDS, STORE_KINDS } from '../manifest/primitives.schema.js';
|
|
4
6
|
export { readManifest, validateManifest } from '../manifest/read-manifest.js';
|
|
7
|
+
export { canonical, mcpSnapshot, PROTOCOL_VERSIONS, } from '../mcp/snapshot.js';
|
|
5
8
|
export { build, } from './build.js';
|
|
6
9
|
export { check } from './check.js';
|
|
7
10
|
export { writeContracts } from './contracts.js';
|
package/dist/worker/run-log.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { messageOf } from '../log/log.js';
|
|
2
|
+
import { logAt, messageOf, withLineAt, } from '../log/log.js';
|
|
3
3
|
export const LOG_CAP_BYTES = 64 * 1024;
|
|
4
4
|
const TRUNCATED = '\n[log truncated at 64 KB]\n';
|
|
5
5
|
const current = new AsyncLocalStorage();
|
|
@@ -22,7 +22,11 @@ const record = (level, message) => {
|
|
|
22
22
|
append(buffer, `${level} ${message}`);
|
|
23
23
|
};
|
|
24
24
|
// ctx.log for a worker: the usual JSON line, and inside a run also the run's own log.
|
|
25
|
-
|
|
25
|
+
const runLogAt = (base) => (level, message, fields) => {
|
|
26
|
+
record(level, message);
|
|
27
|
+
logAt(base, level, message, fields);
|
|
28
|
+
};
|
|
29
|
+
export const runLog = (base) => withLineAt({
|
|
26
30
|
info: (message, fields) => {
|
|
27
31
|
record('info', message);
|
|
28
32
|
base.info(message, fields);
|
|
@@ -35,4 +39,4 @@ export const runLog = (base) => ({
|
|
|
35
39
|
record('error', messageOf(error));
|
|
36
40
|
base.error(error, fields);
|
|
37
41
|
},
|
|
38
|
-
});
|
|
42
|
+
}, runLogAt(base));
|
package/dist/worker/runs.d.ts
CHANGED
package/dist/worker/runs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JOB_RUNS_SQL } from '../store/kit-migrations.js';
|
|
2
2
|
import {} from '../store/store.types.js';
|
|
3
3
|
export const KEEP_RUNS = 50;
|
|
4
|
-
const INSERT = `insert into agentage_job_runs
|
|
5
|
-
values ($1, $2, $3, $4, $5, $6)`;
|
|
4
|
+
const INSERT = `insert into agentage_job_runs
|
|
5
|
+
(job, started_at, ended_at, status, log, timeout_ms, agcid) values ($1, $2, $3, $4, $5, $6, $7)`;
|
|
6
6
|
const PRUNE = `delete from agentage_job_runs where job = $1 and id not in
|
|
7
7
|
(select id from agentage_job_runs where job = $1 order by id desc limit ${KEEP_RUNS})`;
|
|
8
8
|
const fromRow = (row) => ({
|
|
@@ -12,6 +12,7 @@ const fromRow = (row) => ({
|
|
|
12
12
|
status: row.status,
|
|
13
13
|
log: row.log,
|
|
14
14
|
...(row.timeout_ms === null ? {} : { timeoutMs: row.timeout_ms }),
|
|
15
|
+
...(row.agcid ? { agcid: row.agcid } : {}),
|
|
15
16
|
});
|
|
16
17
|
const LAST = 'select * from agentage_job_runs where job = $1 order by id desc limit 1';
|
|
17
18
|
const valuesOf = (run) => [
|
|
@@ -21,6 +22,7 @@ const valuesOf = (run) => [
|
|
|
21
22
|
run.status,
|
|
22
23
|
run.log,
|
|
23
24
|
run.timeoutMs ?? null,
|
|
25
|
+
run.agcid ?? null,
|
|
24
26
|
];
|
|
25
27
|
// Runs live in the extension's own store, in a table the kit owns; the last 50 per job are kept.
|
|
26
28
|
export const storeRuns = (store) => {
|
package/dist/worker/scheduler.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { uuidv7 } from '../agcid/agcid.js';
|
|
2
|
+
import { requestScope } from '../agcid/current.js';
|
|
1
3
|
import {} from '../health/health.js';
|
|
2
4
|
import {} from '../log/log.js';
|
|
3
5
|
import { nextRun, parseCron } from './cron.js';
|
|
@@ -45,14 +47,19 @@ const runJob = async (entry, log, buffer) => {
|
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
// Never twice at once; every run saved with its log, a failed save is logged and the job goes on.
|
|
48
|
-
const execute =
|
|
50
|
+
const execute = (s, entry) => requestScope.run({ agcid: uuidv7() }, () => executeScoped(s, entry));
|
|
51
|
+
// Inside the run's scope: every log line of the job, its failure and its save share one agcid.
|
|
52
|
+
const executeScoped = async (s, entry) => {
|
|
49
53
|
const startedAt = s.now();
|
|
50
54
|
Object.assign(entry, { running: true, runningSince: startedAt, overran: false });
|
|
51
55
|
const buffer = { text: '', truncated: false };
|
|
52
56
|
const status = await runJob(entry, s.deps.log, buffer);
|
|
53
57
|
entry.running = false;
|
|
54
58
|
entry.last = status;
|
|
59
|
+
const agcid = requestScope.getStore()?.agcid;
|
|
55
60
|
const run = { job: entry.name, startedAt, endedAt: s.now(), status, log: buffer.text };
|
|
61
|
+
if (agcid)
|
|
62
|
+
run.agcid = agcid;
|
|
56
63
|
if (entry.timeoutMs !== undefined)
|
|
57
64
|
run.timeoutMs = entry.timeoutMs;
|
|
58
65
|
await s.deps.runs.save(run).catch((err) => s.deps.log.error(err, { job: entry.name }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"types": "./dist/tool/index.d.ts",
|
|
29
29
|
"default": "./dist/tool/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./contracts": {
|
|
32
|
+
"types": "./dist/contracts/index.d.ts",
|
|
33
|
+
"default": "./dist/contracts/index.js"
|
|
34
|
+
},
|
|
31
35
|
"./migrate": {
|
|
32
36
|
"default": "./dist/store/migrate.js"
|
|
33
37
|
},
|