@agentage/extension 0.20.4 → 0.22.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 +2 -0
- 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/server/app.js +5 -0
- package/dist/server/caller-route.d.ts +5 -0
- package/dist/server/caller-route.js +18 -0
- package/dist/vendor/app/app.types.d.ts +10 -0
- package/dist/vendor/app/index.d.ts +1 -1
- package/dist/vendor/app/test-host.d.ts +2 -1
- package/dist/vendor/app/test-host.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ correlation id, the response envelope, the store pool, the scheduler and argumen
|
|
|
7
7
|
`@agentage/extension/host` is the host and the daemon, `@agentage/extension/contracts` the wire
|
|
8
8
|
schemas. The host document has the optional key `program { version, commit }` since 0.20.4: a cloud
|
|
9
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.
|
|
11
|
+
The app kit has `setNavSection` since 0.22.0: an open app gives the shell a titled nav section.
|
|
10
12
|
`@agentage/extension/logs` is the event line (`EventSchema`, `parseLine`, `createLogger`,
|
|
11
13
|
`createEventsClient`, `KINDS`, `LEVELS`, `USER_TYPES`), built into the kit's own tarball.
|
|
12
14
|
`@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';
|
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
|
+
};
|
|
@@ -16,12 +16,22 @@ export interface ShellPort {
|
|
|
16
16
|
closeAside: () => void;
|
|
17
17
|
navigate: (page: string) => void;
|
|
18
18
|
setPages: (pages: PageLink[]) => void;
|
|
19
|
+
setNavSection: (section: NavSection | null) => void;
|
|
19
20
|
setBottomBar: (bar: BottomBar | null) => void;
|
|
20
21
|
}
|
|
21
22
|
export interface PageLink {
|
|
22
23
|
title: string;
|
|
23
24
|
path: string;
|
|
24
25
|
}
|
|
26
|
+
export interface NavItem {
|
|
27
|
+
title: string;
|
|
28
|
+
path: string;
|
|
29
|
+
icon?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface NavSection {
|
|
32
|
+
title: string;
|
|
33
|
+
items: NavItem[];
|
|
34
|
+
}
|
|
25
35
|
export interface BottomBar {
|
|
26
36
|
title: string;
|
|
27
37
|
count?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AppContextValue, AppHost, AppRoute, AppShell, AppUser, AsideKey, HostAdapter, BottomBar, ExtensionInfo, HostInfo, HostKind, Notice, NoticeKind, RegionHost, RegionName, PageLink, ShellPort, StateStore, } from './app.types.js';
|
|
1
|
+
export type { AppContextValue, AppHost, AppRoute, AppShell, AppUser, AsideKey, HostAdapter, BottomBar, ExtensionInfo, HostInfo, HostKind, Notice, NoticeKind, RegionHost, RegionName, PageLink, NavItem, NavSection, ShellPort, StateStore, } from './app.types.js';
|
|
2
2
|
export { AppApiError, checkApiPath, newAgcid } from './api.js';
|
|
3
3
|
export { AppBoundary } from './boundary.js';
|
|
4
4
|
export { AppContext, useAppHost, useAppShell } from './context.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import type { AppRoute, AppUser, AsideKey, BottomBar, HostInfo, Notice, PageLink, StateStore } from './app.types.js';
|
|
2
|
+
import type { AppRoute, AppUser, AsideKey, BottomBar, HostInfo, Notice, NavSection, PageLink, StateStore } from './app.types.js';
|
|
3
3
|
export interface TestCall {
|
|
4
4
|
id: string;
|
|
5
5
|
path: string;
|
|
@@ -13,6 +13,7 @@ export interface TestRecord {
|
|
|
13
13
|
aside: AsideKey | null;
|
|
14
14
|
pages: string[];
|
|
15
15
|
pageLinks: PageLink[];
|
|
16
|
+
navSection: NavSection | null;
|
|
16
17
|
bottomBar: BottomBar | null;
|
|
17
18
|
}
|
|
18
19
|
export interface TestHostProps {
|
|
@@ -14,6 +14,7 @@ export const createTestRecord = () => ({
|
|
|
14
14
|
aside: null,
|
|
15
15
|
pages: [],
|
|
16
16
|
pageLinks: [],
|
|
17
|
+
navSection: null,
|
|
17
18
|
bottomBar: null,
|
|
18
19
|
});
|
|
19
20
|
const testRequest = (record, reply) => async (id, path, init) => {
|
|
@@ -31,6 +32,7 @@ const testShell = (record) => ({
|
|
|
31
32
|
closeAside: () => void (record.aside = null),
|
|
32
33
|
navigate: (page) => void record.pages.push(page),
|
|
33
34
|
setPages: (pages) => void (record.pageLinks = pages),
|
|
35
|
+
setNavSection: (section) => void (record.navSection = section),
|
|
34
36
|
setBottomBar: (bar) => void (record.bottomBar = bar),
|
|
35
37
|
});
|
|
36
38
|
const useRegionHost = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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",
|