@agentage/extension 0.20.3 → 0.21.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/README.md +3 -1
- package/dist/api/routes.js +3 -0
- package/dist/auth/caller.schema.d.ts +8 -0
- package/dist/auth/caller.schema.js +9 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/discovery/combine.d.ts +3 -2
- package/dist/discovery/combine.js +8 -4
- package/dist/discovery/host-document.schema.d.ts +9 -0
- package/dist/discovery/host-document.schema.js +3 -0
- package/dist/internal/index.d.ts +4 -3
- package/dist/internal/index.js +3 -2
- package/dist/server/app.js +5 -0
- package/dist/server/caller-route.d.ts +5 -0
- package/dist/server/caller-route.js +18 -0
- package/package.json +1 -1
- package/schemas/host-document.schema.json +18 -0
package/README.md
CHANGED
|
@@ -5,7 +5,9 @@ The agentage extension kit. Each server and cli part (pages, api, mcp, worker, c
|
|
|
5
5
|
correlation id, the response envelope, the store pool, the scheduler and argument parsing.
|
|
6
6
|
`@agentage/extension/tool` is the tool behind `agentage extension check | build | up --docker | down | token`.
|
|
7
7
|
`@agentage/extension/host` is the host and the daemon, `@agentage/extension/contracts` the wire
|
|
8
|
-
schemas.
|
|
8
|
+
schemas. The host document has the optional key `program { version, commit }` since 0.20.4: a cloud
|
|
9
|
+
app host fills it with its program; the daemon leaves it out.
|
|
10
|
+
The route `GET /api/{id}/caller` (the caller's own token facts) exists since 0.21.0.
|
|
9
11
|
`@agentage/extension/logs` is the event line (`EventSchema`, `parseLine`, `createLogger`,
|
|
10
12
|
`createEventsClient`, `KINDS`, `LEVELS`, `USER_TYPES`), built into the kit's own tarball.
|
|
11
13
|
`@agentage/extension/core` is the one client of the core's services (see "The core client").
|
package/dist/api/routes.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {} from 'zod';
|
|
2
|
+
import { CALLER_PATH } from '../auth/caller.schema.js';
|
|
2
3
|
import { badScope } from '../auth/token-check.js';
|
|
3
4
|
import {} from '../context/context.js';
|
|
4
5
|
import {} from '../envelope/envelope.js';
|
|
@@ -20,6 +21,8 @@ const problemOf = (routes, { method, path, spec }) => {
|
|
|
20
21
|
return `method ${String(method)}: one of get, post, put, patch, delete`;
|
|
21
22
|
if (!PATH.test(path))
|
|
22
23
|
return 'path: /segments and {param} segments under /api/{id}';
|
|
24
|
+
if (path.toLowerCase() === CALLER_PATH)
|
|
25
|
+
return 'is the kit route of the caller: pick another path';
|
|
23
26
|
if (routes.some((r) => r.method === method && r.path === path))
|
|
24
27
|
return 'is registered twice';
|
|
25
28
|
if (!spec.summary)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CALLER_PATH = "/caller";
|
|
3
|
+
export declare const callerPath: (id: string) => string;
|
|
4
|
+
export declare const CallerAnswerSchema: z.ZodObject<{
|
|
5
|
+
sub: z.ZodString;
|
|
6
|
+
scopes: z.ZodArray<z.ZodString>;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export type CallerAnswer = z.infer<typeof CallerAnswerSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// The kit's own route under /api/{id}: an extension cannot register it.
|
|
3
|
+
export const CALLER_PATH = '/caller';
|
|
4
|
+
export const callerPath = (id) => `/api/${id}${CALLER_PATH}`;
|
|
5
|
+
// The data of GET /api/{id}/caller: the caller's own token facts and nothing else.
|
|
6
|
+
export const CallerAnswerSchema = z.strictObject({
|
|
7
|
+
sub: z.string().min(1),
|
|
8
|
+
scopes: z.array(z.string()),
|
|
9
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
|
|
2
|
+
export { CallerAnswerSchema, callerPath, type CallerAnswer } from '../auth/caller.schema.js';
|
|
2
3
|
export { CloudDiscoveryDocumentSchema, DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from '../discovery/discovery.schema.js';
|
|
3
4
|
export { combineHost, entryOfDocument, type Answer, type CallerState, type Combined, type CombineInput, type HostInstallation, type Refusal, type Route, } from '../discovery/combine.js';
|
|
4
5
|
export { HostDocumentSchema, type HostDocument, type HostEntry, } from '../discovery/host-document.schema.js';
|
package/dist/contracts/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
|
|
2
|
+
export { CallerAnswerSchema, callerPath } from '../auth/caller.schema.js';
|
|
2
3
|
export { CloudDiscoveryDocumentSchema, DiscoveryDocumentSchema, ExtensionRecordSchema, } from '../discovery/discovery.schema.js';
|
|
3
4
|
export { combineHost, entryOfDocument, } from '../discovery/combine.js';
|
|
4
5
|
export { HostDocumentSchema, } from '../discovery/host-document.schema.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Answer, type Refusal } from './combine-answers.js';
|
|
2
|
-
import { type Expose, type HostDocument, type HostKind } from './host-document.schema.js';
|
|
2
|
+
import { type Expose, type HostDocument, type HostKind, type Program } from './host-document.schema.js';
|
|
3
3
|
import { type Route } from './route-table.js';
|
|
4
4
|
export { entryOfDocument, type Answer, type Refusal } from './combine-answers.js';
|
|
5
5
|
export { type Route } from './route-table.js';
|
|
@@ -27,5 +27,6 @@ export interface CombineInput {
|
|
|
27
27
|
installation: HostInstallation;
|
|
28
28
|
answers: Answer[];
|
|
29
29
|
states?: Record<string, CallerState>;
|
|
30
|
+
program?: Program;
|
|
30
31
|
}
|
|
31
|
-
export declare const combineHost: (
|
|
32
|
+
export declare const combineHost: (input: CombineInput) => Combined;
|
|
@@ -20,10 +20,13 @@ const entryOf = (row, served, told) => {
|
|
|
20
20
|
const parts = SERVES_KINDS.filter((kind) => docs.some((d) => d.parts.includes(kind)));
|
|
21
21
|
return { ...docs.reduceRight((later, doc) => ({ ...later, ...doc })), parts, expose, state };
|
|
22
22
|
};
|
|
23
|
-
const documentOf = (
|
|
23
|
+
const documentOf = (input, entries) => {
|
|
24
|
+
const { installation, kind, program } = input;
|
|
24
25
|
const { shell } = installation;
|
|
25
26
|
const named = shell && { shell: { package: shell.package, version: shell.version } };
|
|
26
|
-
|
|
27
|
+
const own = program && { program: { version: program.version, commit: program.commit } };
|
|
28
|
+
const { host } = installation;
|
|
29
|
+
return HostDocumentSchema.parse({ host, kind, ...own, ...named, extensions: entries });
|
|
27
30
|
};
|
|
28
31
|
const pagesRefusal = (route, site) => ({
|
|
29
32
|
upstream: route.upstream,
|
|
@@ -32,13 +35,14 @@ const pagesRefusal = (route, site) => ({
|
|
|
32
35
|
});
|
|
33
36
|
// No I/O: the installation and each container's answer in; the host document and routes out.
|
|
34
37
|
// Throws only on an installation the host schema refuses (two rows of one id); a bad answer is refused.
|
|
35
|
-
export const combineHost = (
|
|
38
|
+
export const combineHost = (input) => {
|
|
39
|
+
const { installation, answers, states } = input;
|
|
36
40
|
const { byId, refused } = sortAnswers(installation.extensions, answers);
|
|
37
41
|
const rows = installation.extensions.map((row) => {
|
|
38
42
|
const served = byId.get(row.id) ?? [];
|
|
39
43
|
return { entry: entryOf(row, served, states?.[row.id]), served };
|
|
40
44
|
});
|
|
41
|
-
const document = documentOf(
|
|
45
|
+
const document = documentOf(input, rows.map((r) => r.entry));
|
|
42
46
|
const { routes, dropped } = routeTable(rows);
|
|
43
47
|
const site = routes.find((r) => r.part === 'pages');
|
|
44
48
|
return { document, routes, refused: [...refused, ...dropped.map((r) => pagesRefusal(r, site))] };
|
|
@@ -57,12 +57,20 @@ export declare const ExtensionEntrySchema: z.ZodObject<{
|
|
|
57
57
|
down: "down";
|
|
58
58
|
}>;
|
|
59
59
|
}, z.core.$strict>;
|
|
60
|
+
export declare const ProgramSchema: z.ZodObject<{
|
|
61
|
+
version: z.ZodString;
|
|
62
|
+
commit: z.ZodString;
|
|
63
|
+
}, z.core.$strict>;
|
|
60
64
|
export declare const HostDocumentSchema: z.ZodObject<{
|
|
61
65
|
host: z.ZodString;
|
|
62
66
|
kind: z.ZodEnum<{
|
|
63
67
|
cloud: "cloud";
|
|
64
68
|
local: "local";
|
|
65
69
|
}>;
|
|
70
|
+
program: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
version: z.ZodString;
|
|
72
|
+
commit: z.ZodString;
|
|
73
|
+
}, z.core.$strict>>;
|
|
66
74
|
shell: z.ZodOptional<z.ZodObject<{
|
|
67
75
|
package: z.ZodString;
|
|
68
76
|
version: z.ZodString;
|
|
@@ -116,3 +124,4 @@ export type HostDocument = z.infer<typeof HostDocumentSchema>;
|
|
|
116
124
|
export type HostEntry = HostDocument['extensions'][number];
|
|
117
125
|
export type HostKind = (typeof HOST_KINDS)[number];
|
|
118
126
|
export type Expose = z.infer<typeof ExposeSchema>;
|
|
127
|
+
export type Program = z.infer<typeof ProgramSchema>;
|
|
@@ -36,6 +36,8 @@ export const ExtensionEntrySchema = z
|
|
|
36
36
|
.refine(toolsAreOwn, TOOLS_RULE);
|
|
37
37
|
// The shell is a library the host serves: named here only, never a row of extensions.
|
|
38
38
|
const ShellSchema = z.strictObject({ package: PackageNameSchema, version: VersionSchema });
|
|
39
|
+
// The app host program that serves this document (a cloud host); the daemon leaves it out.
|
|
40
|
+
export const ProgramSchema = z.strictObject({ version: VersionSchema, commit: CommitSchema });
|
|
39
41
|
const uniqueIds = ({ extensions }) => new Set(extensions.map((e) => e.id)).size === extensions.length;
|
|
40
42
|
// GET /.well-known/agentage-host.json: one app host, built from the documents of its extensions.
|
|
41
43
|
export const HostDocumentSchema = z
|
|
@@ -45,6 +47,7 @@ export const HostDocumentSchema = z
|
|
|
45
47
|
.max(63)
|
|
46
48
|
.regex(/^[a-z][a-z0-9-]*$/),
|
|
47
49
|
kind: z.enum(HOST_KINDS),
|
|
50
|
+
program: ProgramSchema.optional(),
|
|
48
51
|
shell: ShellSchema.optional(),
|
|
49
52
|
extensions: z.array(ExtensionEntrySchema),
|
|
50
53
|
})
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ export { agcidMiddleware } from '../agcid/scope.js';
|
|
|
2
2
|
export { download } from '../api/download.js';
|
|
3
3
|
export { type ApiContext } from '../api/routes.js';
|
|
4
4
|
export { fits, type Setting } from '../context/settings.js';
|
|
5
|
-
export { type Answer, type CallerState, combineHost, type CombineInput, } from '../discovery/combine.js';
|
|
5
|
+
export { type Answer, type CallerState, combineHost, type CombineInput, type HostInstallation, } from '../discovery/combine.js';
|
|
6
6
|
export { DiscoveryDocumentSchema } from '../discovery/discovery.schema.js';
|
|
7
|
-
export { HostDocumentSchema, type HostEntry } from '../discovery/host-document.schema.js';
|
|
7
|
+
export { ExposeSchema, HostDocumentSchema, type HostEntry, type Program, } from '../discovery/host-document.schema.js';
|
|
8
8
|
export { SERVES_KINDS } from '../discovery/served.schema.js';
|
|
9
9
|
export { fail, ok } from '../envelope/envelope.js';
|
|
10
10
|
export { parse } from '../envelope/parse.js';
|
|
@@ -19,10 +19,11 @@ export { serveHost } from '../host/serve-host.js';
|
|
|
19
19
|
export { createLog, type Log } from '../log/log.js';
|
|
20
20
|
export { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
21
21
|
export { hasStore, hostParts, mountedIn, secretNames } from '../manifest/parts.js';
|
|
22
|
-
export { ExtensionIdSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
22
|
+
export { CommitSchema, ExtensionIdSchema, PackageNameSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
23
23
|
export { readManifest } from '../manifest/read-manifest.js';
|
|
24
24
|
export { BODY_LIMIT } from '../server/app.js';
|
|
25
25
|
export { errorHandler, notFound } from '../server/errors.js';
|
|
26
|
+
export { requestLine } from '../server/request-line.js';
|
|
26
27
|
export { closeNow, listen } from '../server/serve.js';
|
|
27
28
|
export { startOn, startTestServer, type TestServer } from '../testing/test-server.js';
|
|
28
29
|
export { KIT_VERSION } from '../tool/kit-version.js';
|
package/dist/internal/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export {} from '../api/routes.js';
|
|
|
5
5
|
export { fits } from '../context/settings.js';
|
|
6
6
|
export { combineHost, } from '../discovery/combine.js';
|
|
7
7
|
export { DiscoveryDocumentSchema } from '../discovery/discovery.schema.js';
|
|
8
|
-
export { HostDocumentSchema } from '../discovery/host-document.schema.js';
|
|
8
|
+
export { ExposeSchema, HostDocumentSchema, } from '../discovery/host-document.schema.js';
|
|
9
9
|
export { SERVES_KINDS } from '../discovery/served.schema.js';
|
|
10
10
|
export { fail, ok } from '../envelope/envelope.js';
|
|
11
11
|
export { parse } from '../envelope/parse.js';
|
|
@@ -20,10 +20,11 @@ export { serveHost } from '../host/serve-host.js';
|
|
|
20
20
|
export { createLog } from '../log/log.js';
|
|
21
21
|
export {} from '../manifest/manifest.schema.js';
|
|
22
22
|
export { hasStore, hostParts, mountedIn, secretNames } from '../manifest/parts.js';
|
|
23
|
-
export { ExtensionIdSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
23
|
+
export { CommitSchema, ExtensionIdSchema, PackageNameSchema, SecretNameSchema, VersionSchema, } from '../manifest/primitives.schema.js';
|
|
24
24
|
export { readManifest } from '../manifest/read-manifest.js';
|
|
25
25
|
export { BODY_LIMIT } from '../server/app.js';
|
|
26
26
|
export { errorHandler, notFound } from '../server/errors.js';
|
|
27
|
+
export { requestLine } from '../server/request-line.js';
|
|
27
28
|
export { closeNow, listen } from '../server/serve.js';
|
|
28
29
|
export { startOn, startTestServer } from '../testing/test-server.js';
|
|
29
30
|
export { KIT_VERSION } from '../tool/kit-version.js';
|
package/dist/server/app.js
CHANGED
|
@@ -5,6 +5,7 @@ import {} from '../api/well-known.js';
|
|
|
5
5
|
import { agcidMiddleware } from '../agcid/scope.js';
|
|
6
6
|
import { mountFiles } from '../api/files.js';
|
|
7
7
|
import {} from '../api/files-registry.js';
|
|
8
|
+
import { CALLER_PATH } from '../auth/caller.schema.js';
|
|
8
9
|
import { methodsOf, routeAccess, sameShape } from '../auth/route-access.js';
|
|
9
10
|
import { setCaller, setCleared } from '../auth/token-check.js';
|
|
10
11
|
import {} from '../discovery/discovery.js';
|
|
@@ -14,6 +15,7 @@ import { createHealthHandler } from '../health/health.js';
|
|
|
14
15
|
import {} from '../log/log.js';
|
|
15
16
|
import {} from '../manifest/manifest.schema.js';
|
|
16
17
|
import {} from '../manifest/primitives.schema.js';
|
|
18
|
+
import { callerHandler } from './caller-route.js';
|
|
17
19
|
import { discoveryHandler } from './discovery-handler.js';
|
|
18
20
|
import { errorHandler, notFound } from './errors.js';
|
|
19
21
|
import { requestLine } from './request-line.js';
|
|
@@ -124,6 +126,9 @@ export const mountApiRoutes = (app, options) => {
|
|
|
124
126
|
const { openapi } = options;
|
|
125
127
|
if (openapi)
|
|
126
128
|
app.get(`${prefix}/openapi.json`, openapiHandler(openapi));
|
|
129
|
+
// Only where tokens are checked: a host with no check has no caller to name.
|
|
130
|
+
if (options.tokenCheck)
|
|
131
|
+
app.get(`${prefix}${CALLER_PATH}`, callerHandler(id, options.tokenCheck));
|
|
127
132
|
const json = express.json({ limit: BODY_LIMIT });
|
|
128
133
|
app.use(prefix, routeGuard(options), json, options.router);
|
|
129
134
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type RequestHandler } from 'express';
|
|
2
|
+
import { type CallerAnswer } from '../auth/caller.schema.js';
|
|
3
|
+
import { type Caller, type TokenCheck } from '../auth/token-check.js';
|
|
4
|
+
export declare const callerAnswer: (id: string, caller: Caller) => CallerAnswer;
|
|
5
|
+
export declare const callerHandler: (id: string, tokenCheck: TokenCheck) => RequestHandler;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {} from 'express';
|
|
2
|
+
import { CallerAnswerSchema } from '../auth/caller.schema.js';
|
|
3
|
+
import { scopeOf, setCaller, VERBS } from '../auth/token-check.js';
|
|
4
|
+
import { fail, ok } from '../envelope/envelope.js';
|
|
5
|
+
// Only the {id}:{verb} scopes the token holds: never another extension's, never an implied verb.
|
|
6
|
+
export const callerAnswer = (id, caller) => CallerAnswerSchema.parse({
|
|
7
|
+
sub: caller.sub,
|
|
8
|
+
scopes: VERBS.map((verb) => scopeOf(id, verb)).filter((s) => caller.scopes.includes(s)),
|
|
9
|
+
});
|
|
10
|
+
// GET /api/{id}/caller at read: admin and write imply read, so they pass too.
|
|
11
|
+
export const callerHandler = (id, tokenCheck) => async (req, res) => {
|
|
12
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
13
|
+
const caller = await tokenCheck(req.get('authorization'), 'read');
|
|
14
|
+
if (!caller)
|
|
15
|
+
throw fail('UNAUTHORIZED', 'Missing token');
|
|
16
|
+
setCaller(req, caller);
|
|
17
|
+
res.json(ok(callerAnswer(id, caller)));
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.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",
|
|
@@ -16,6 +16,24 @@
|
|
|
16
16
|
"cloud"
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
|
+
"program": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"properties": {
|
|
22
|
+
"version": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
|
|
25
|
+
},
|
|
26
|
+
"commit": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"pattern": "^[0-9a-f]{40}$"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"required": [
|
|
32
|
+
"version",
|
|
33
|
+
"commit"
|
|
34
|
+
],
|
|
35
|
+
"additionalProperties": false
|
|
36
|
+
},
|
|
19
37
|
"shell": {
|
|
20
38
|
"type": "object",
|
|
21
39
|
"properties": {
|