@agentage/extension 0.8.0 → 0.10.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/header.d.ts +3 -0
- package/dist/agcid/header.js +3 -0
- package/dist/api/openapi-doc.d.ts +1 -0
- package/dist/api/openapi-doc.js +15 -10
- package/dist/api/routes.d.ts +15 -6
- package/dist/api/routes.js +2 -5
- package/dist/auth/part-auth.d.ts +3 -0
- package/dist/auth/part-auth.js +12 -1
- package/dist/auth/route-access.d.ts +1 -0
- package/dist/auth/route-access.js +1 -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/cli-context.js +4 -1
- package/dist/command/command.types.d.ts +2 -0
- package/dist/command/command.types.js +1 -0
- package/dist/context/context.d.ts +10 -0
- package/dist/context/context.js +14 -1
- package/dist/context/recording-log.js +3 -3
- package/dist/context/test-command-context.d.ts +2 -0
- package/dist/context/test-command-context.js +13 -4
- package/dist/context/test-context.d.ts +4 -1
- package/dist/context/test-context.js +6 -1
- package/dist/contracts/index.d.ts +6 -0
- package/dist/contracts/index.js +6 -0
- package/dist/envelope/envelope.d.ts +8 -5
- package/dist/envelope/envelope.js +15 -3
- package/dist/envelope/envelope.schema.d.ts +3 -5
- package/dist/envelope/envelope.schema.js +8 -4
- package/dist/index.d.ts +9 -12
- package/dist/index.js +8 -10
- package/dist/log/log.d.ts +3 -0
- package/dist/log/log.js +7 -3
- package/dist/log/span.d.ts +9 -0
- package/dist/log/span.js +19 -0
- package/dist/mcp/tools.js +5 -4
- package/dist/pages/inline-hashes.d.ts +3 -0
- package/dist/pages/inline-hashes.js +27 -0
- package/dist/pages/pages-app.js +22 -11
- package/dist/pages/pages.d.ts +5 -1
- package/dist/pages/site-from-dir.d.ts +7 -0
- package/dist/pages/site-from-dir.js +31 -0
- package/dist/pages/types.d.ts +3 -0
- package/dist/pages/types.js +40 -0
- package/dist/runtime/build-info.d.ts +1 -0
- package/dist/runtime/build-info.js +2 -1
- package/dist/runtime/part-runners.js +9 -2
- package/dist/runtime/run-part.js +2 -1
- package/dist/server/api-routes.js +16 -3
- package/dist/server/app.d.ts +4 -0
- package/dist/server/app.js +13 -2
- package/dist/testing/test-server.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/package.json +5 -1
- package/schemas/error-envelope.schema.json +27 -27
package/dist/agcid/agcid.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare const AGCID_PATTERN: RegExp;
|
|
3
|
-
export declare const isAgcid: (value: unknown) => value is string;
|
|
1
|
+
export { AGCID_HEADER, AGCID_PATTERN, isAgcid } from './header.js';
|
|
4
2
|
export declare const uuidv7: (now?: number, random?: Buffer) => string;
|
|
5
3
|
export declare const agcidOf: (incoming: unknown) => string;
|
package/dist/agcid/agcid.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export const isAgcid = (value) => typeof value === 'string' && AGCID_PATTERN.test(value);
|
|
2
|
+
import { isAgcid } from './header.js';
|
|
3
|
+
export { AGCID_HEADER, AGCID_PATTERN, isAgcid } from './header.js';
|
|
5
4
|
const hyphenate = (hex) => [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20)].join('-');
|
|
6
5
|
// RFC 9562 UUIDv7: 48-bit unix ms, version 7, variant 10, the rest random.
|
|
7
6
|
export const uuidv7 = (now = Date.now(), random = randomBytes(10)) => {
|
|
@@ -2,5 +2,6 @@ import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
|
2
2
|
import { type RouteEntry } from './routes.js';
|
|
3
3
|
type Json = Record<string, unknown>;
|
|
4
4
|
export declare const schemaOf: (zod: object, io: "input" | "output") => Json;
|
|
5
|
+
export declare const inQuery: (method: string) => boolean;
|
|
5
6
|
export declare const generatedOpenapi: (pkg: ExtensionPackage, routes: RouteEntry[]) => Json;
|
|
6
7
|
export {};
|
package/dist/api/openapi-doc.js
CHANGED
|
@@ -13,7 +13,8 @@ const bare = (zod, io) => {
|
|
|
13
13
|
const json = (schema) => ({ 'application/json': { schema } });
|
|
14
14
|
const content = (description, schema) => ({ description, content: json(schema) });
|
|
15
15
|
const STRING = { type: 'string' };
|
|
16
|
-
const okResponse = ({
|
|
16
|
+
const okResponse = (spec) => spec.status === 204 ? { description: 'no content' } : okBody(spec);
|
|
17
|
+
const okBody = ({ output, etag }) => ({
|
|
17
18
|
...content('the envelope', {
|
|
18
19
|
type: 'object',
|
|
19
20
|
properties: {
|
|
@@ -25,7 +26,7 @@ const okResponse = ({ output, etag }) => ({
|
|
|
25
26
|
...(etag && { headers: { ETag: { schema: STRING } } }),
|
|
26
27
|
});
|
|
27
28
|
const refusal = (code) => content(code, { $ref: '#/components/schemas/Error' });
|
|
28
|
-
const inQuery = (
|
|
29
|
+
export const inQuery = (method) => method === 'get' || method === 'delete';
|
|
29
30
|
const fields = (zod) => bare(zod, 'input');
|
|
30
31
|
const pathParameters = ({ path, spec }) => {
|
|
31
32
|
const typed = spec.params ? (fields(spec.params).properties ?? {}) : {};
|
|
@@ -36,17 +37,19 @@ const pathParameters = ({ path, spec }) => {
|
|
|
36
37
|
schema: typed[name] ?? STRING,
|
|
37
38
|
}));
|
|
38
39
|
};
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { properties = {}, required = [] } = fields(entry.spec.input);
|
|
43
|
-
return Object.entries(properties).map(([name, schema]) => ({
|
|
40
|
+
const queryOf = (schema) => {
|
|
41
|
+
const { properties = {}, required = [] } = fields(schema);
|
|
42
|
+
return Object.entries(properties).map(([name, field]) => ({
|
|
44
43
|
name,
|
|
45
44
|
in: 'query',
|
|
46
45
|
required: required.includes(name),
|
|
47
|
-
schema,
|
|
46
|
+
schema: field,
|
|
48
47
|
}));
|
|
49
48
|
};
|
|
49
|
+
const queryParameters = ({ method, spec }) => [
|
|
50
|
+
...(spec.input && inQuery(method) ? queryOf(spec.input) : []),
|
|
51
|
+
...(spec.query ? queryOf(spec.query) : []),
|
|
52
|
+
];
|
|
50
53
|
const IF_MATCH = { name: 'If-Match', in: 'header', required: false, schema: STRING };
|
|
51
54
|
const parameters = (entry) => [
|
|
52
55
|
...pathParameters(entry),
|
|
@@ -56,7 +59,7 @@ const parameters = (entry) => [
|
|
|
56
59
|
const responses = (entry) => {
|
|
57
60
|
const { input, params, scope, etag } = entry.spec;
|
|
58
61
|
return {
|
|
59
|
-
|
|
62
|
+
[entry.spec.status ?? 200]: okResponse(entry.spec),
|
|
60
63
|
...((input || params) && { '400': refusal('VALIDATION_ERROR') }),
|
|
61
64
|
...(scope !== 'public' && { '401': refusal('UNAUTHORIZED'), '403': refusal('FORBIDDEN') }),
|
|
62
65
|
...(entry.path.includes('{') && { '404': refusal('NOT_FOUND') }),
|
|
@@ -80,7 +83,9 @@ const operation = (id, entry) => {
|
|
|
80
83
|
security: securityOf(id, scope),
|
|
81
84
|
...(params.length > 0 && { parameters: params }),
|
|
82
85
|
...(input &&
|
|
83
|
-
!inQuery(entry) && {
|
|
86
|
+
!inQuery(entry.method) && {
|
|
87
|
+
requestBody: { required: true, content: json(bare(input, 'input')) },
|
|
88
|
+
}),
|
|
84
89
|
responses: responses(entry),
|
|
85
90
|
};
|
|
86
91
|
};
|
package/dist/api/routes.d.ts
CHANGED
|
@@ -6,26 +6,35 @@ import { type WellKnownRegistrar } from './well-known.js';
|
|
|
6
6
|
export declare const ROUTE_METHODS: readonly ["get", "post", "put", "patch", "delete"];
|
|
7
7
|
export type RouteMethod = (typeof ROUTE_METHODS)[number];
|
|
8
8
|
type ObjectSchema = z.ZodObject;
|
|
9
|
-
export interface RouteSpec<I extends ObjectSchema, O extends z.ZodType, S extends Access = Access, Q extends ObjectSchema = never> {
|
|
9
|
+
export interface RouteSpec<I extends ObjectSchema, O extends z.ZodType, S extends Access = Access, Q extends ObjectSchema = never, Y extends ObjectSchema = never> {
|
|
10
10
|
summary: string;
|
|
11
11
|
scope?: S;
|
|
12
12
|
input?: I;
|
|
13
13
|
output?: O;
|
|
14
14
|
params?: Q;
|
|
15
|
+
query?: Y;
|
|
15
16
|
etag?: true;
|
|
17
|
+
status?: 200 | 201 | 204;
|
|
16
18
|
}
|
|
17
19
|
export type ParamsOf<P extends string> = P extends `${string}{${infer N}}${infer R}` ? {
|
|
18
20
|
[K in N]: string;
|
|
19
21
|
} & ParamsOf<R> : Record<never, string>;
|
|
20
|
-
export interface RouteRequest<I, P extends string, S extends Access = Access, Q = never> {
|
|
22
|
+
export interface RouteRequest<I, P extends string, S extends Access = Access, Q = never, Y = never> {
|
|
21
23
|
input: I;
|
|
24
|
+
query: [Y] extends [never] ? Record<never, never> : Y;
|
|
25
|
+
ip: string;
|
|
22
26
|
params: [Q] extends [never] ? ParamsOf<P> : Q;
|
|
23
27
|
caller: S extends 'public' | 'optional' ? Caller | null : Caller;
|
|
24
28
|
ifMatch?: string;
|
|
29
|
+
header: (name: string) => string | undefined;
|
|
25
30
|
}
|
|
26
31
|
type Answer<T> = T | Reply<T>;
|
|
27
|
-
export type RouteHandler<I extends ObjectSchema, O extends z.ZodType, P extends string, S extends Access = Access, Q extends ObjectSchema = never> = (request: RouteRequest<z.output<I>, P, S, [
|
|
28
|
-
|
|
32
|
+
export type RouteHandler<I extends ObjectSchema, O extends z.ZodType, P extends string, S extends Access = Access, Q extends ObjectSchema = never, Y extends ObjectSchema = never> = (request: RouteRequest<z.output<I>, P, S, [
|
|
33
|
+
Q
|
|
34
|
+
] extends [never] ? never : z.output<Q>, [
|
|
35
|
+
Y
|
|
36
|
+
] extends [never] ? never : z.output<Y>>) => Answer<z.input<O>> | Promise<Answer<z.input<O>>>;
|
|
37
|
+
export type RouteRegistrar = <P extends string, I extends ObjectSchema = z.ZodObject<Record<never, z.ZodType>>, O extends z.ZodType = z.ZodUnknown, S extends Access = 'read', Q extends ObjectSchema = never, Y extends ObjectSchema = never>(method: RouteMethod, path: P, spec: RouteSpec<I, O, S, Q, Y>, handler: RouteHandler<I, O, P, S, Q, Y>) => void;
|
|
29
38
|
export interface ApiContext extends PartContext {
|
|
30
39
|
readonly route: RouteRegistrar;
|
|
31
40
|
readonly wellKnown: WellKnownRegistrar;
|
|
@@ -34,8 +43,8 @@ type Params = Record<string, unknown>;
|
|
|
34
43
|
export interface RouteEntry {
|
|
35
44
|
method: RouteMethod;
|
|
36
45
|
path: string;
|
|
37
|
-
spec: RouteSpec<ObjectSchema, z.ZodType, Access, ObjectSchema>;
|
|
38
|
-
handler: (request: RouteRequest<Record<string, unknown>, string, 'public', Params>) => unknown;
|
|
46
|
+
spec: RouteSpec<ObjectSchema, z.ZodType, Access, ObjectSchema, ObjectSchema>;
|
|
47
|
+
handler: (request: RouteRequest<Record<string, unknown>, string, 'public', Params, Params>) => unknown;
|
|
39
48
|
}
|
|
40
49
|
export declare const createRouteRegistry: () => {
|
|
41
50
|
wellKnown: WellKnownRegistrar;
|
package/dist/api/routes.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {} from 'zod';
|
|
2
|
-
import {} from '../auth/token-check.js';
|
|
2
|
+
import { badScope } from '../auth/token-check.js';
|
|
3
3
|
import {} from '../context/context.js';
|
|
4
4
|
import {} from '../envelope/envelope.js';
|
|
5
5
|
import { createWellKnownRegistry } from './well-known.js';
|
|
6
6
|
export const ROUTE_METHODS = ['get', 'post', 'put', 'patch', 'delete'];
|
|
7
7
|
const PATH = /^(\/([A-Za-z0-9._~-]+|\{[A-Za-z_][A-Za-z0-9_]*\}))+$/;
|
|
8
|
-
const SCOPES = ['public', 'optional', 'read', 'write', 'admin'];
|
|
9
8
|
const problemOf = (routes, { method, path, spec }) => {
|
|
10
9
|
if (!ROUTE_METHODS.includes(method))
|
|
11
10
|
return `method ${String(method)}: one of get, post, put, patch, delete`;
|
|
@@ -15,9 +14,7 @@ const problemOf = (routes, { method, path, spec }) => {
|
|
|
15
14
|
return 'is registered twice';
|
|
16
15
|
if (!spec.summary)
|
|
17
16
|
return 'needs a summary: it documents the route';
|
|
18
|
-
|
|
19
|
-
return `scope ${String(spec.scope)}: one of ${SCOPES.join(', ')}`;
|
|
20
|
-
return null;
|
|
17
|
+
return badScope(spec.scope);
|
|
21
18
|
};
|
|
22
19
|
export const createRouteRegistry = () => {
|
|
23
20
|
const routes = [];
|
package/dist/auth/part-auth.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { type PlatformInfo } from '../context/context.js';
|
|
1
2
|
import { type Log } from '../log/log.js';
|
|
2
3
|
import { type Env } from '../runtime/build-info.js';
|
|
4
|
+
export declare const isAudience: (audience: string) => boolean;
|
|
5
|
+
export declare const platformOf: (env: Env) => PlatformInfo;
|
|
3
6
|
export declare const covers: (audience: string, host: string) => boolean;
|
|
4
7
|
export declare const partAuth: (env: Env, id: string, log: Log, scopes: string[]) => Promise<{
|
|
5
8
|
tokenCheck: import("./token-check.js").TokenCheck;
|
package/dist/auth/part-auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import {} from '../context/context.js';
|
|
2
3
|
import { OriginSchema } from '../discovery/discovery.schema.js';
|
|
3
4
|
import { messageOf } from '../log/log.js';
|
|
4
5
|
import { formatIssues } from '../manifest/read-manifest.js';
|
|
@@ -7,7 +8,7 @@ import { createRevokedList, REVOKED_POLL_MS } from './revoked.js';
|
|
|
7
8
|
import { accessOfSecurity, scopeOf } from './token-check.js';
|
|
8
9
|
import { createTokenCheck, remoteKeys } from './verify-token.js';
|
|
9
10
|
// *.{a domain of two labels or more}, or one host, as a deployment's origin may name it.
|
|
10
|
-
const isAudience = (audience) => {
|
|
11
|
+
export const isAudience = (audience) => {
|
|
11
12
|
const host = audience.startsWith('*.') ? audience.slice(2) : audience;
|
|
12
13
|
return ['https', 'http'].some((scheme) => OriginSchema.safeParse(`${scheme}://${host}`).success);
|
|
13
14
|
};
|
|
@@ -18,6 +19,16 @@ const AuthEnvSchema = z.object({
|
|
|
18
19
|
AGENTAGE_AUDIENCE: z.string().refine(isAudience, '*.{domain} or one host'),
|
|
19
20
|
AGENTAGE_ORIGIN: z.url(),
|
|
20
21
|
});
|
|
22
|
+
const valid = (env, key) => {
|
|
23
|
+
const parsed = AuthEnvSchema.shape[key].safeParse(env[key]);
|
|
24
|
+
return parsed.success ? parsed.data : '';
|
|
25
|
+
};
|
|
26
|
+
// ctx.platform from the token check's env; pages and worker start without it and get ''.
|
|
27
|
+
export const platformOf = (env) => {
|
|
28
|
+
const telemetry = env['AGENTAGE_TELEMETRY_URL'] || undefined;
|
|
29
|
+
const issuer = valid(env, 'AGENTAGE_ISSUER');
|
|
30
|
+
return { issuer, audience: valid(env, 'AGENTAGE_AUDIENCE'), ...(telemetry && { telemetry }) };
|
|
31
|
+
};
|
|
21
32
|
// *.agentage.io covers the domain and every host under it at any depth; else one exact host.
|
|
22
33
|
export const covers = (audience, host) => audience.startsWith('*.')
|
|
23
34
|
? host === audience.slice(2) || host.endsWith(audience.slice(1))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { accessOfSecurity, strongest } from './token-check.js';
|
|
2
2
|
const PARAM = /^\{.+\}$/;
|
|
3
3
|
// As Express routes: without case, and one trailing slash ignored.
|
|
4
|
-
const sameShape = (template, path) => {
|
|
4
|
+
export const sameShape = (template, path) => {
|
|
5
5
|
const want = template.toLowerCase().split('/');
|
|
6
6
|
const got = path
|
|
7
7
|
.toLowerCase()
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const ACCESS: readonly ["public", "optional", "read", "write", "admin"];
|
|
2
|
+
export type Access = (typeof ACCESS)[number];
|
|
3
|
+
export declare const VERBS: readonly ["read", "write", "admin"];
|
|
4
|
+
export declare const badScope: (scope: unknown, allowed?: readonly Access[]) => string | null;
|
|
2
5
|
export interface Caller {
|
|
3
6
|
sub: string;
|
|
4
7
|
scopes: readonly string[];
|
|
@@ -6,7 +9,7 @@ export interface Caller {
|
|
|
6
9
|
export type TokenCheck = (authorization: string | undefined, access: Access) => Promise<Caller | null>;
|
|
7
10
|
export declare const setCaller: (request: object, caller: Caller | null) => void;
|
|
8
11
|
export declare const callerOf: (request: object) => Caller | null;
|
|
9
|
-
export declare const
|
|
12
|
+
export declare const rank: (access: Access) => number;
|
|
10
13
|
export declare const scopeOf: (id: string, access?: Access) => string;
|
|
11
14
|
export declare const strongest: (needed: readonly Access[]) => Access;
|
|
12
15
|
export declare const accessOfSecurity: (security: unknown) => Access;
|
package/dist/auth/token-check.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
|
+
// What a route or tool declares (api-standards section 5): public, optional (anonymous or a read bearer), or a verb.
|
|
3
|
+
export const ACCESS = ['public', 'optional', 'read', 'write', 'admin'];
|
|
4
|
+
export const VERBS = ['read', 'write', 'admin'];
|
|
5
|
+
// Where a route or a tool may declare its scope: tools have no optional.
|
|
6
|
+
export const badScope = (scope, allowed = ACCESS) => scope === undefined || allowed.includes(scope)
|
|
7
|
+
? null
|
|
8
|
+
: `scope ${String(scope)}: one of ${allowed.join(', ')}`;
|
|
2
9
|
const callers = new WeakMap();
|
|
3
10
|
export const setCaller = (request, caller) => void callers.set(request, caller);
|
|
4
11
|
export const callerOf = (request) => callers.get(request) ?? null;
|
|
5
|
-
export const
|
|
12
|
+
export const rank = (access) => ACCESS.indexOf(access);
|
|
6
13
|
export const scopeOf = (id, access = 'read') => access === 'public' ? 'public' : `${id}:${access === 'optional' ? 'read' : access}`;
|
|
7
|
-
export const strongest = (needed) => needed.reduce((top, access) => (
|
|
8
|
-
const VERB =
|
|
14
|
+
export const strongest = (needed) => needed.reduce((top, access) => (rank(access) > rank(top) ? access : top), 'public');
|
|
15
|
+
const VERB = new RegExp(`:(${VERBS.join('|')})$`);
|
|
9
16
|
const isAnonymous = (requirement) => typeof requirement === 'object' && requirement !== null && Object.keys(requirement).length === 0;
|
|
10
17
|
// OpenAPI security: [] is public, [{}, {pat}] optional, a scope names the verb; nothing declared needs read.
|
|
11
18
|
export const accessOfSecurity = (security) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRemoteJWKSet, errors, jwtVerify } from 'jose';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { fail, isFailure } from '../envelope/envelope.js';
|
|
4
|
-
import {
|
|
4
|
+
import { rank, retryOnce, scopeOf, VERBS } from './token-check.js';
|
|
5
5
|
const VERIFY = { algorithms: ['EdDSA'], requiredClaims: ['exp'] };
|
|
6
6
|
const ClaimsSchema = z.object({
|
|
7
7
|
sub: z.string().min(1),
|
|
@@ -51,7 +51,7 @@ const claimsOf = async (authorization, deps) => {
|
|
|
51
51
|
};
|
|
52
52
|
export const grants = (scope, id, access) => {
|
|
53
53
|
const held = new Set(scope.split(' '));
|
|
54
|
-
return
|
|
54
|
+
return VERBS.some((verb) => rank(verb) >= rank(access) && held.has(`${id}:${verb}`));
|
|
55
55
|
};
|
|
56
56
|
export const createTokenCheck = (deps) => async (authorization, access) => {
|
|
57
57
|
// optional: no bearer is anonymous, but a bearer sent is checked like read, never ignored.
|
|
@@ -2,6 +2,7 @@ import { chmodSync, mkdirSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import {} from '../auth/token-check.js';
|
|
4
4
|
import { createLog } from '../log/log.js';
|
|
5
|
+
import { createSpan } from '../log/span.js';
|
|
5
6
|
import {} from '../manifest/manifest.schema.js';
|
|
6
7
|
import {} from './command.types.js';
|
|
7
8
|
import {} from './out.js';
|
|
@@ -20,11 +21,13 @@ export const cliContext = (pkg, run) => {
|
|
|
20
21
|
const { id } = pkg.agentage;
|
|
21
22
|
const tags = { extension: id, part: 'cli', version: pkg.version, base: { command: run.command } };
|
|
22
23
|
const dir = ownDir(run.dataDir, id);
|
|
24
|
+
const log = createLog(tags, run.stderr);
|
|
23
25
|
return Object.freeze({
|
|
24
26
|
extension: Object.freeze({ id, version: pkg.version, part: 'cli' }),
|
|
25
27
|
args: Object.freeze(run.args),
|
|
26
28
|
out: run.out,
|
|
27
|
-
log
|
|
29
|
+
log,
|
|
30
|
+
span: createSpan(log),
|
|
28
31
|
user: run.user ?? null,
|
|
29
32
|
client: run.client ?? NO_CLIENT,
|
|
30
33
|
get dir() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type RouteMethod } from '../api/routes.js';
|
|
2
2
|
import { type Caller } from '../auth/token-check.js';
|
|
3
3
|
import { type Log } from '../log/log.js';
|
|
4
|
+
import { type Span } from '../log/span.js';
|
|
4
5
|
import { type Out } from './out.js';
|
|
5
6
|
import { type ArgValue } from './args.js';
|
|
6
7
|
export interface CommandExtension {
|
|
@@ -17,6 +18,7 @@ export interface CliContext {
|
|
|
17
18
|
readonly args: Readonly<Record<string, ArgValue>>;
|
|
18
19
|
readonly out: Out;
|
|
19
20
|
readonly log: Log;
|
|
21
|
+
readonly span: Span;
|
|
20
22
|
readonly user: Caller | null;
|
|
21
23
|
readonly client: CliClient;
|
|
22
24
|
readonly dir: string;
|
|
@@ -2,6 +2,7 @@ import { type Caller } from '../auth/token-check.js';
|
|
|
2
2
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
3
3
|
import { type StoreKind } from '../manifest/primitives.schema.js';
|
|
4
4
|
import { type Log } from '../log/log.js';
|
|
5
|
+
import { type Span } from '../log/span.js';
|
|
5
6
|
import { type Store } from '../store/store.types.js';
|
|
6
7
|
import { type Secrets } from './secrets.js';
|
|
7
8
|
export type ServerPartKind = 'pages' | 'api' | 'mcp' | 'worker';
|
|
@@ -14,15 +15,23 @@ export interface ExtensionInfo {
|
|
|
14
15
|
commit: string;
|
|
15
16
|
store?: StoreKind;
|
|
16
17
|
}
|
|
18
|
+
export interface PlatformInfo {
|
|
19
|
+
issuer: string;
|
|
20
|
+
audience: string;
|
|
21
|
+
telemetry?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const NO_PLATFORM: PlatformInfo;
|
|
17
24
|
export interface PartContext {
|
|
18
25
|
readonly extension: Readonly<ExtensionInfo>;
|
|
19
26
|
readonly auth: {
|
|
20
27
|
caller(request: object): Caller | null;
|
|
21
28
|
};
|
|
22
29
|
readonly log: Log;
|
|
30
|
+
readonly span: Span;
|
|
23
31
|
readonly settings: Readonly<Record<string, SettingValue>>;
|
|
24
32
|
readonly store: Store;
|
|
25
33
|
readonly secrets: Secrets;
|
|
34
|
+
readonly platform: Readonly<PlatformInfo>;
|
|
26
35
|
}
|
|
27
36
|
export declare const NO_STORE: Store;
|
|
28
37
|
export declare const settingDefaults: (pkg: ExtensionPackage) => Record<string, SettingValue>;
|
|
@@ -35,5 +44,6 @@ export interface ContextInput {
|
|
|
35
44
|
settings?: Record<string, SettingValue>;
|
|
36
45
|
store?: Store;
|
|
37
46
|
secrets?: Secrets;
|
|
47
|
+
platform?: PlatformInfo;
|
|
38
48
|
}
|
|
39
49
|
export declare const createContext: (input: ContextInput) => PartContext;
|
package/dist/context/context.js
CHANGED
|
@@ -3,8 +3,10 @@ import {} from '../manifest/manifest.schema.js';
|
|
|
3
3
|
import { storeOf } from '../manifest/parts.js';
|
|
4
4
|
import {} from '../manifest/primitives.schema.js';
|
|
5
5
|
import { createLog } from '../log/log.js';
|
|
6
|
+
import { createSpan } from '../log/span.js';
|
|
6
7
|
import {} from '../store/store.types.js';
|
|
7
8
|
import {} from './secrets.js';
|
|
9
|
+
export const NO_PLATFORM = Object.freeze({ issuer: '', audience: '' });
|
|
8
10
|
// ctx.store is always there; without a store part in the manifest it says so on first use.
|
|
9
11
|
export const NO_STORE = {
|
|
10
12
|
query: async () => {
|
|
@@ -27,5 +29,16 @@ export const createContext = (input) => {
|
|
|
27
29
|
const settings = Object.freeze({ ...settingDefaults(pkg), ...input.settings });
|
|
28
30
|
const auth = Object.freeze({ caller: callerOf });
|
|
29
31
|
const secrets = input.secrets ?? {};
|
|
30
|
-
|
|
32
|
+
const span = createSpan(log);
|
|
33
|
+
const platform = Object.freeze({ ...(input.platform ?? NO_PLATFORM) });
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
extension,
|
|
36
|
+
auth,
|
|
37
|
+
log,
|
|
38
|
+
span,
|
|
39
|
+
settings,
|
|
40
|
+
store: store ?? NO_STORE,
|
|
41
|
+
secrets,
|
|
42
|
+
platform,
|
|
43
|
+
});
|
|
31
44
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { messageOf } from '../log/log.js';
|
|
2
|
-
export const recordingLog = (logs) => ({
|
|
1
|
+
import { messageOf, withLineAt } from '../log/log.js';
|
|
2
|
+
export const recordingLog = (logs) => withLineAt({
|
|
3
3
|
info: (message, fields = {}) => void logs.push({ level: 'info', message, fields }),
|
|
4
4
|
warn: (message, fields = {}) => void logs.push({ level: 'warn', message, fields }),
|
|
5
5
|
error: (error, fields = {}) => void logs.push({
|
|
@@ -7,4 +7,4 @@ export const recordingLog = (logs) => ({
|
|
|
7
7
|
message: messageOf(error),
|
|
8
8
|
fields: { ...fields, err: error },
|
|
9
9
|
}),
|
|
10
|
-
});
|
|
10
|
+
}, (level, message, fields) => void logs.push({ level, message, fields }));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ArgValue } from '../command/args.js';
|
|
2
2
|
import { type Caller } from '../auth/token-check.js';
|
|
3
3
|
import { type CliClient, type CliContext } from '../command/command.types.js';
|
|
4
|
+
import { type SpanRecord } from '../log/span.js';
|
|
4
5
|
import { type LogEntry } from './recording-log.js';
|
|
5
6
|
export type ClientCall = {
|
|
6
7
|
kind: 'api';
|
|
@@ -19,6 +20,7 @@ export interface TestCommandContext extends CliContext {
|
|
|
19
20
|
};
|
|
20
21
|
readonly exitCode: number | undefined;
|
|
21
22
|
readonly logs: LogEntry[];
|
|
23
|
+
readonly spans: SpanRecord[];
|
|
22
24
|
readonly calls: ClientCall[];
|
|
23
25
|
}
|
|
24
26
|
export interface TestCommandOptions {
|
|
@@ -5,6 +5,7 @@ import {} from '../command/args.js';
|
|
|
5
5
|
import {} from '../auth/token-check.js';
|
|
6
6
|
import {} from '../command/command.types.js';
|
|
7
7
|
import { createOut } from '../command/out.js';
|
|
8
|
+
import { createSpan } from '../log/span.js';
|
|
8
9
|
import { packageExtension } from './package-extension.js';
|
|
9
10
|
import { recordingLog } from './recording-log.js';
|
|
10
11
|
// One recorded line per line written, the trailing newline dropped.
|
|
@@ -28,17 +29,25 @@ const recorded = (options) => {
|
|
|
28
29
|
const output = { stdout: [], stderr: [] };
|
|
29
30
|
const json = options.json ?? false;
|
|
30
31
|
const out = createOut({ json, stdout: lines(output.stdout), stderr: lines(output.stderr) });
|
|
31
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
out,
|
|
34
|
+
output,
|
|
35
|
+
logs: [],
|
|
36
|
+
spans: [],
|
|
37
|
+
calls: [],
|
|
38
|
+
};
|
|
32
39
|
};
|
|
33
40
|
export const commandContext = (options) => {
|
|
34
|
-
const { out, output, logs, calls } = recorded(options);
|
|
41
|
+
const { out, output, logs, spans, calls } = recorded(options);
|
|
35
42
|
const { id = 'test', version = '0.0.0' } = packageExtension();
|
|
36
43
|
const extension = { id, version, ...options.extension, part: 'cli' };
|
|
37
44
|
const fixedUser = { sub: 'usr_test', scopes: [`${extension.id}:read`] };
|
|
38
45
|
const dir = lazyDir();
|
|
46
|
+
const log = recordingLog(logs);
|
|
39
47
|
return {
|
|
40
|
-
...{ extension, args: { ...options.args }, out, output, logs, calls },
|
|
41
|
-
log
|
|
48
|
+
...{ extension, args: { ...options.args }, out, output, logs, spans, calls },
|
|
49
|
+
log,
|
|
50
|
+
span: createSpan(log, spans),
|
|
42
51
|
user: options.user === undefined ? fixedUser : options.user,
|
|
43
52
|
client: recordingClient(calls, options.client),
|
|
44
53
|
get dir() {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type RouteEntry, type RouteRegistrar } from '../api/routes.js';
|
|
2
2
|
import { type WellKnownRegistrar } from '../api/well-known.js';
|
|
3
|
+
import { type SpanRecord } from '../log/span.js';
|
|
3
4
|
import { type ToolEntry, type ToolRegistrar } from '../mcp/tools.js';
|
|
4
5
|
import { type JobOptions } from '../worker/job-options.js';
|
|
5
6
|
import { type JobRun } from '../worker/runs.js';
|
|
6
7
|
import { type Schedule } from '../worker/scheduler.js';
|
|
7
|
-
import { type ExtensionInfo, type PartContext, type SettingValue } from './context.js';
|
|
8
|
+
import { type ExtensionInfo, type PlatformInfo, type PartContext, type SettingValue } from './context.js';
|
|
8
9
|
import { type LogEntry } from './recording-log.js';
|
|
9
10
|
import { type TestCommandContext, type TestCommandOptions } from './test-command-context.js';
|
|
10
11
|
export { type LogEntry } from './recording-log.js';
|
|
@@ -19,6 +20,7 @@ export interface TestContext extends PartContext {
|
|
|
19
20
|
readonly routes: RouteEntry[];
|
|
20
21
|
readonly wellKnown: WellKnownRegistrar;
|
|
21
22
|
readonly jobs: ScheduledJob[];
|
|
23
|
+
readonly spans: SpanRecord[];
|
|
22
24
|
runJob(name: string): Promise<JobRun | undefined>;
|
|
23
25
|
}
|
|
24
26
|
export interface ScheduledJob {
|
|
@@ -33,6 +35,7 @@ export interface TestContextOptions {
|
|
|
33
35
|
store?: boolean | {
|
|
34
36
|
dir: string;
|
|
35
37
|
};
|
|
38
|
+
platform?: PlatformInfo;
|
|
36
39
|
}
|
|
37
40
|
export declare function createTestContext(options: TestCommandOptions): TestCommandContext;
|
|
38
41
|
export declare function createTestContext(options?: TestContextOptions): TestContext;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRouteRegistry } from '../api/routes.js';
|
|
2
2
|
import {} from '../api/well-known.js';
|
|
3
3
|
import {} from '../log/log.js';
|
|
4
|
+
import { createSpan } from '../log/span.js';
|
|
4
5
|
import { createToolRegistry } from '../mcp/tools.js';
|
|
5
6
|
import { migrate } from '../store/migrations.js';
|
|
6
7
|
import { createTestStore } from '../store/test-store.js';
|
|
@@ -9,7 +10,7 @@ import { runLog } from '../worker/run-log.js';
|
|
|
9
10
|
import { memoryRuns } from '../worker/runs.js';
|
|
10
11
|
import { createScheduler } from '../worker/scheduler.js';
|
|
11
12
|
import {} from '../manifest/primitives.schema.js';
|
|
12
|
-
import { NO_STORE } from './context.js';
|
|
13
|
+
import { NO_PLATFORM, NO_STORE, } from './context.js';
|
|
13
14
|
import { packageExtension } from './package-extension.js';
|
|
14
15
|
import { recordingLog } from './recording-log.js';
|
|
15
16
|
import { commandContext, } from './test-command-context.js';
|
|
@@ -57,6 +58,7 @@ const identityOf = (options) => {
|
|
|
57
58
|
const serverContext = (options) => {
|
|
58
59
|
const logs = [];
|
|
59
60
|
const log = runLog(recordingLog(logs));
|
|
61
|
+
const spans = [];
|
|
60
62
|
const { extension, ...open } = identityOf(options);
|
|
61
63
|
const store = testStore(open.store, recordingLog([]));
|
|
62
64
|
const caller = { sub: 'usr_test', scopes: [`${extension.id}:read`] };
|
|
@@ -65,9 +67,12 @@ const serverContext = (options) => {
|
|
|
65
67
|
auth: { caller: () => caller },
|
|
66
68
|
log,
|
|
67
69
|
logs,
|
|
70
|
+
span: createSpan(log, spans),
|
|
71
|
+
spans,
|
|
68
72
|
settings: { ...options.settings },
|
|
69
73
|
store: store ?? NO_STORE,
|
|
70
74
|
secrets: Object.freeze({ ...options.secrets }),
|
|
75
|
+
platform: Object.freeze({ ...(options.platform ?? NO_PLATFORM) }),
|
|
71
76
|
close: async () => store?.close(),
|
|
72
77
|
...recorders(log),
|
|
73
78
|
};
|
|
@@ -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';
|
|
@@ -8,25 +8,27 @@ export interface OkEnvelope<T> {
|
|
|
8
8
|
data: T;
|
|
9
9
|
meta?: Record<string, unknown>;
|
|
10
10
|
}
|
|
11
|
+
export type ErrorDetails = ErrorDetail[] | Record<string, unknown>;
|
|
11
12
|
export interface ErrorBody {
|
|
12
|
-
code:
|
|
13
|
+
code: string;
|
|
13
14
|
message: string;
|
|
14
15
|
agcid: string;
|
|
15
|
-
details?:
|
|
16
|
+
details?: ErrorDetails;
|
|
16
17
|
}
|
|
17
18
|
export interface ErrorEnvelope {
|
|
18
19
|
success: false;
|
|
19
20
|
error: ErrorBody;
|
|
20
21
|
}
|
|
21
22
|
export interface Failure extends Error {
|
|
22
|
-
readonly code:
|
|
23
|
+
readonly code: string;
|
|
23
24
|
readonly status: number;
|
|
24
|
-
readonly details?:
|
|
25
|
+
readonly details?: ErrorDetails;
|
|
25
26
|
readonly retryAfter?: number;
|
|
26
27
|
readonly headers?: Readonly<Record<string, string>>;
|
|
27
28
|
}
|
|
28
29
|
export interface FailOptions {
|
|
29
|
-
details?:
|
|
30
|
+
details?: ErrorDetails;
|
|
31
|
+
code?: string;
|
|
30
32
|
retryAfter?: number;
|
|
31
33
|
headers?: Record<string, string>;
|
|
32
34
|
}
|
|
@@ -34,6 +36,7 @@ declare const REPLY: unique symbol;
|
|
|
34
36
|
export interface ReplyOptions {
|
|
35
37
|
meta?: Record<string, unknown>;
|
|
36
38
|
etag?: string;
|
|
39
|
+
status?: 200 | 201 | 204;
|
|
37
40
|
}
|
|
38
41
|
export interface Reply<T> extends ReplyOptions {
|
|
39
42
|
readonly [REPLY]: true;
|