@jini-ai/agent-plugins 0.4.6 → 0.4.8
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/CHANGELOG.md +30 -0
- package/README.md +48 -0
- package/dist/admin-surfaces/action-dispatcher.d.ts +37 -0
- package/dist/admin-surfaces/action-dispatcher.js +69 -0
- package/dist/admin-surfaces/action-schema.d.ts +56 -0
- package/dist/admin-surfaces/action-schema.js +167 -0
- package/dist/admin-surfaces/action-tools.d.ts +40 -0
- package/dist/admin-surfaces/action-tools.js +52 -0
- package/dist/admin-surfaces/callback-field-inbox.d.ts +35 -0
- package/dist/admin-surfaces/callback-field-inbox.js +53 -0
- package/dist/admin-surfaces/capability-declarations.d.ts +41 -0
- package/dist/admin-surfaces/capability-declarations.js +102 -0
- package/dist/admin-surfaces/contribution.d.ts +49 -0
- package/dist/admin-surfaces/contribution.js +30 -0
- package/dist/admin-surfaces/delivery-bindings.d.ts +76 -0
- package/dist/admin-surfaces/delivery-bindings.js +99 -0
- package/dist/admin-surfaces/descriptor.d.ts +69 -0
- package/dist/admin-surfaces/descriptor.js +196 -0
- package/dist/admin-surfaces/external-links.d.ts +45 -0
- package/dist/admin-surfaces/external-links.js +70 -0
- package/dist/admin-surfaces/host-validator.d.ts +62 -0
- package/dist/admin-surfaces/host-validator.js +87 -0
- package/dist/admin-surfaces/index.d.ts +23 -0
- package/dist/admin-surfaces/index.js +21 -0
- package/dist/admin-surfaces/protocol.d.ts +103 -0
- package/dist/admin-surfaces/protocol.js +25 -0
- package/dist/admin-surfaces/sandbox.d.ts +78 -0
- package/dist/admin-surfaces/sandbox.js +92 -0
- package/dist/admin-surfaces/settings-value.d.ts +28 -0
- package/dist/admin-surfaces/settings-value.js +45 -0
- package/dist/admin-surfaces/surface-capabilities.d.ts +167 -0
- package/dist/admin-surfaces/surface-capabilities.js +215 -0
- package/dist/admin-surfaces/surface-client.d.ts +116 -0
- package/dist/admin-surfaces/surface-client.js +219 -0
- package/dist/admin-surfaces/surface-handlers.d.ts +111 -0
- package/dist/admin-surfaces/surface-handlers.js +172 -0
- package/dist/admin-surfaces/theme.d.ts +59 -0
- package/dist/admin-surfaces/theme.js +57 -0
- package/dist/folder-zip-node.d.ts +11 -0
- package/dist/folder-zip-node.js +84 -0
- package/dist/folder-zip.d.ts +38 -0
- package/dist/folder-zip.js +134 -0
- package/dist/lifecycle/automatic-use.d.ts +79 -0
- package/dist/lifecycle/automatic-use.js +165 -0
- package/dist/lifecycle/compatibility-metadata.d.ts +19 -0
- package/dist/lifecycle/compatibility-metadata.js +45 -0
- package/dist/lifecycle/compatibility.d.ts +52 -0
- package/dist/lifecycle/compatibility.js +60 -0
- package/dist/lifecycle/fetch-archive.js +26 -24
- package/dist/lifecycle/index.d.ts +14 -2
- package/dist/lifecycle/index.js +8 -1
- package/dist/lifecycle/install-errors.d.ts +14 -0
- package/dist/lifecycle/install-errors.js +9 -0
- package/dist/lifecycle/install.d.ts +2 -13
- package/dist/lifecycle/install.js +12 -123
- package/dist/lifecycle/installed-package-index.d.ts +15 -0
- package/dist/lifecycle/installed-package-index.js +128 -0
- package/dist/lifecycle/installed-package-roots.js +28 -20
- package/dist/lifecycle/manifest.d.ts +14 -0
- package/dist/lifecycle/manifest.js +115 -100
- package/dist/lifecycle/package-paths.js +3 -3
- package/dist/lifecycle/ports.d.ts +1 -1
- package/dist/lifecycle/provider-contribution.d.ts +65 -0
- package/dist/lifecycle/provider-contribution.js +93 -0
- package/dist/lifecycle/resolve-agent-plugin-refs.js +19 -6
- package/dist/lifecycle/retire-bundled.js +20 -18
- package/dist/lifecycle/search.d.ts +6 -1
- package/dist/lifecycle/search.js +45 -7
- package/dist/lifecycle/set-enabled.d.ts +2 -1
- package/dist/lifecycle/set-enabled.js +52 -8
- package/dist/lifecycle/skill-file-reader.js +85 -71
- package/dist/lifecycle/tools/capabilities.d.ts +199 -0
- package/dist/lifecycle/tools/capabilities.js +213 -0
- package/dist/lifecycle/tools/definition.d.ts +32 -0
- package/dist/lifecycle/tools/definition.js +33 -0
- package/dist/lifecycle/tools/index.d.ts +10 -0
- package/dist/lifecycle/tools/index.js +10 -0
- package/dist/lifecycle/tools/manifest.d.ts +33 -0
- package/dist/lifecycle/tools/manifest.js +89 -0
- package/dist/lifecycle/tools/projection.d.ts +90 -0
- package/dist/lifecycle/tools/projection.js +283 -0
- package/dist/lifecycle/types.d.ts +2 -0
- package/dist/lifecycle/uninstall.d.ts +3 -1
- package/dist/lifecycle/uninstall.js +51 -27
- package/dist/lifecycle/update-plan.d.ts +18 -0
- package/dist/lifecycle/update-plan.js +22 -0
- package/dist/lifecycle/update-store.d.ts +71 -0
- package/dist/lifecycle/update-store.js +150 -0
- package/dist/lifecycle/update.d.ts +55 -0
- package/dist/lifecycle/update.js +321 -0
- package/dist/manifest.d.ts +2 -1
- package/dist/manifest.js +2 -1
- package/package.json +50 -6
- package/ui-ux-design/plugin.json +8 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lifecycle/activation.d.ts.map +0 -1
- package/dist/lifecycle/activation.js.map +0 -1
- package/dist/lifecycle/bundled-digests.d.ts.map +0 -1
- package/dist/lifecycle/bundled-digests.js.map +0 -1
- package/dist/lifecycle/bundled-source-archive.d.ts.map +0 -1
- package/dist/lifecycle/bundled-source-archive.js.map +0 -1
- package/dist/lifecycle/capability-projection.d.ts.map +0 -1
- package/dist/lifecycle/capability-projection.js.map +0 -1
- package/dist/lifecycle/contribution-loader.d.ts.map +0 -1
- package/dist/lifecycle/contribution-loader.js.map +0 -1
- package/dist/lifecycle/fetch-archive.d.ts.map +0 -1
- package/dist/lifecycle/fetch-archive.js.map +0 -1
- package/dist/lifecycle/index.d.ts.map +0 -1
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/lifecycle/install-from-url.d.ts.map +0 -1
- package/dist/lifecycle/install-from-url.js.map +0 -1
- package/dist/lifecycle/install.d.ts.map +0 -1
- package/dist/lifecycle/install.js.map +0 -1
- package/dist/lifecycle/installed-package-roots.d.ts.map +0 -1
- package/dist/lifecycle/installed-package-roots.js.map +0 -1
- package/dist/lifecycle/layout.d.ts.map +0 -1
- package/dist/lifecycle/layout.js.map +0 -1
- package/dist/lifecycle/manifest.d.ts.map +0 -1
- package/dist/lifecycle/manifest.js.map +0 -1
- package/dist/lifecycle/mcp-provisioning.d.ts.map +0 -1
- package/dist/lifecycle/mcp-provisioning.js.map +0 -1
- package/dist/lifecycle/node.d.ts.map +0 -1
- package/dist/lifecycle/node.js.map +0 -1
- package/dist/lifecycle/package-paths.d.ts.map +0 -1
- package/dist/lifecycle/package-paths.js.map +0 -1
- package/dist/lifecycle/persistent-state.d.ts.map +0 -1
- package/dist/lifecycle/persistent-state.js.map +0 -1
- package/dist/lifecycle/ports.d.ts.map +0 -1
- package/dist/lifecycle/ports.js.map +0 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts.map +0 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.js.map +0 -1
- package/dist/lifecycle/retire-bundled.d.ts.map +0 -1
- package/dist/lifecycle/retire-bundled.js.map +0 -1
- package/dist/lifecycle/search.d.ts.map +0 -1
- package/dist/lifecycle/search.js.map +0 -1
- package/dist/lifecycle/seed-bundled.d.ts.map +0 -1
- package/dist/lifecycle/seed-bundled.js.map +0 -1
- package/dist/lifecycle/set-enabled.d.ts.map +0 -1
- package/dist/lifecycle/set-enabled.js.map +0 -1
- package/dist/lifecycle/skill-file-reader.d.ts.map +0 -1
- package/dist/lifecycle/skill-file-reader.js.map +0 -1
- package/dist/lifecycle/trusted-plugin-files.d.ts.map +0 -1
- package/dist/lifecycle/trusted-plugin-files.js.map +0 -1
- package/dist/lifecycle/types.d.ts.map +0 -1
- package/dist/lifecycle/types.js.map +0 -1
- package/dist/lifecycle/uninstall.d.ts.map +0 -1
- package/dist/lifecycle/uninstall.js.map +0 -1
- package/dist/lifecycle/yauzl-archive-reader.d.ts.map +0 -1
- package/dist/lifecycle/yauzl-archive-reader.js.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/manifest.js.map +0 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { checkAdminSurfaceActionSchema } from './action-schema.js';
|
|
2
|
+
import { parseAdminSurfaceCapabilityDeclarations } from './capability-declarations.js';
|
|
3
|
+
/** The CSP directives a descriptor may extend. Everything else stays at the strict default. */
|
|
4
|
+
export const ADMIN_SURFACE_CSP_DIRECTIVES = ['script-src', 'style-src', 'img-src', 'font-src', 'connect-src', 'frame-src'];
|
|
5
|
+
const ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
6
|
+
const MAX_ID_LENGTH = 64;
|
|
7
|
+
const MAX_TITLE_LENGTH = 100;
|
|
8
|
+
const MAX_SURFACES = 16;
|
|
9
|
+
const MAX_FILES = 32;
|
|
10
|
+
const MAX_ACTIONS = 32;
|
|
11
|
+
const MAX_SOURCES = 8;
|
|
12
|
+
const MAX_LINK_ORIGINS = 8;
|
|
13
|
+
const MAX_RAW_BYTES = 64 * 1024;
|
|
14
|
+
/** One path segment: no `.`/`..`, no separators, no `%` (no encoded traversal), no leading dot. */
|
|
15
|
+
const SEGMENT_PATTERN = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
16
|
+
const FILE_EXTENSIONS = ['.mjs', '.js', '.css', '.json'];
|
|
17
|
+
/** A bare https origin with a DNS host name: no wildcard, path, query, credentials, IP or scheme keyword. */
|
|
18
|
+
const CSP_SOURCE_PATTERN = /^https:\/\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}(?::\d{1,5})?$/;
|
|
19
|
+
function isPlainObject(value) {
|
|
20
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
const isId = (value) => typeof value === 'string' && value.length <= MAX_ID_LENGTH && ID_PATTERN.test(value);
|
|
23
|
+
/** True when `value` is a relative POSIX path whose every segment is plain and that ends in one of
|
|
24
|
+
* `extensions`. @complexity O(n) in the path length. */
|
|
25
|
+
export function isContainedAdminSurfacePath(required, _optional = {}) {
|
|
26
|
+
const { value, extensions } = required;
|
|
27
|
+
if (typeof value !== 'string' || value.length > 200)
|
|
28
|
+
return false;
|
|
29
|
+
return value.split('/').every((segment) => SEGMENT_PATTERN.test(segment)) && extensions.some((extension) => value.endsWith(extension));
|
|
30
|
+
}
|
|
31
|
+
/** True when `value` is a CSP source this protocol allows a plugin to add.
|
|
32
|
+
* @complexity O(n) in the source length. */
|
|
33
|
+
export function isAllowedAdminSurfaceCspSource(required, _optional = {}) {
|
|
34
|
+
const { value } = required;
|
|
35
|
+
if (typeof value !== 'string' || !CSP_SOURCE_PATTERN.test(value))
|
|
36
|
+
return false;
|
|
37
|
+
// The URL parser normalizes default ports and IDNA forms; anything it rewrites is not a bare origin.
|
|
38
|
+
return new URL(value).origin === value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parses the contribution file. One invalid surface refuses the whole file (the loader reports it).
|
|
42
|
+
* @complexity O(s * (f + a + c)) surfaces with their files, actions and CSP sources; input bounded to 64 KiB.
|
|
43
|
+
*/
|
|
44
|
+
export function parseAdminSurfacesFile(required, _optional = {}) {
|
|
45
|
+
if (required.raw.length > MAX_RAW_BYTES)
|
|
46
|
+
return { ok: false, reason: 'larger than 64 KiB' };
|
|
47
|
+
let value;
|
|
48
|
+
try {
|
|
49
|
+
value = JSON.parse(required.raw);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { ok: false, reason: 'not valid JSON' };
|
|
53
|
+
}
|
|
54
|
+
if (!isPlainObject(value) || value.schemaVersion !== 1)
|
|
55
|
+
return { ok: false, reason: 'schemaVersion must be 1' };
|
|
56
|
+
const descriptors = parseSurfaces(value.surfaces);
|
|
57
|
+
return typeof descriptors === 'string' ? { ok: false, reason: descriptors } : { ok: true, descriptors };
|
|
58
|
+
}
|
|
59
|
+
function parseSurfaces(surfaces) {
|
|
60
|
+
if (!Array.isArray(surfaces) || surfaces.length > MAX_SURFACES)
|
|
61
|
+
return `surfaces must be an array of at most ${MAX_SURFACES}`;
|
|
62
|
+
const descriptors = [];
|
|
63
|
+
for (const [index, entry] of surfaces.entries()) {
|
|
64
|
+
const parsed = parseSurface(entry, `surfaces[${index}]`);
|
|
65
|
+
if (typeof parsed === 'string')
|
|
66
|
+
return parsed;
|
|
67
|
+
if (descriptors.some((seen) => seen.id === parsed.id))
|
|
68
|
+
return `surfaces[${index}].id '${parsed.id}' is declared twice`;
|
|
69
|
+
descriptors.push(parsed);
|
|
70
|
+
}
|
|
71
|
+
return descriptors;
|
|
72
|
+
}
|
|
73
|
+
function parseSurface(entry, at) {
|
|
74
|
+
if (!isPlainObject(entry))
|
|
75
|
+
return `${at} must be an object`;
|
|
76
|
+
const identity = parseIdentity(entry, at);
|
|
77
|
+
if (typeof identity === 'string')
|
|
78
|
+
return identity;
|
|
79
|
+
const files = parseFiles(entry.files ?? [], at);
|
|
80
|
+
if (typeof files === 'string')
|
|
81
|
+
return files;
|
|
82
|
+
const actions = parseActions(entry.actions ?? [], at);
|
|
83
|
+
if (typeof actions === 'string')
|
|
84
|
+
return actions;
|
|
85
|
+
return parseSurfaceExtras(entry, { ...identity, files, actions }, at);
|
|
86
|
+
}
|
|
87
|
+
/** The CSP extensions, the optional link origins and the optional handler fields, after the core fields parsed. */
|
|
88
|
+
function parseSurfaceExtras(entry, surface, at) {
|
|
89
|
+
const csp = parseCsp(entry.csp ?? {}, at);
|
|
90
|
+
if (typeof csp === 'string')
|
|
91
|
+
return csp;
|
|
92
|
+
const linkOrigins = entry.linkOrigins === undefined ? undefined : parseLinkOrigins(entry.linkOrigins, `${at}.linkOrigins`);
|
|
93
|
+
if (typeof linkOrigins === 'string')
|
|
94
|
+
return linkOrigins;
|
|
95
|
+
const handler = parseHandler(entry, surface, at);
|
|
96
|
+
return typeof handler === 'string' ? handler : { ...surface, csp, ...(linkOrigins && { linkOrigins }), ...handler };
|
|
97
|
+
}
|
|
98
|
+
/** At most 8 unique bare https origins, by the CSP source rule: a link the host opens leaves the sandbox. */
|
|
99
|
+
function parseLinkOrigins(value, at) {
|
|
100
|
+
if (!Array.isArray(value) || value.length > MAX_LINK_ORIGINS)
|
|
101
|
+
return `${at} must be an array of at most ${MAX_LINK_ORIGINS}`;
|
|
102
|
+
const bad = value.findIndex((origin, index) => !isAllowedAdminSurfaceCspSource({ value: origin }) || value.indexOf(origin) !== index);
|
|
103
|
+
return bad === -1 ? value : `${at}[${bad}] must be a unique bare https origin (no wildcards, paths or keywords)`;
|
|
104
|
+
}
|
|
105
|
+
function parseHandler(entry, surface, at) {
|
|
106
|
+
const { handlerModule } = entry;
|
|
107
|
+
if (handlerModule === undefined)
|
|
108
|
+
return handlerOnlyFieldRefusal(entry, at) ?? {};
|
|
109
|
+
if (!isContainedAdminSurfacePath({ value: handlerModule, extensions: ['.mjs'] }))
|
|
110
|
+
return `${at}.handlerModule must be a plain relative path ending in .mjs`;
|
|
111
|
+
if (surface.files.includes(handlerModule))
|
|
112
|
+
return `${at}.handlerModule is server code and may not also be served to the frame`;
|
|
113
|
+
const unchecked = surface.actions.findIndex((action) => action.result === undefined);
|
|
114
|
+
if (unchecked !== -1)
|
|
115
|
+
return `${at}.actions[${unchecked}] must declare a result schema when the surface has a handlerModule`;
|
|
116
|
+
const declarations = parseAdminSurfaceCapabilityDeclarations({ entry, at });
|
|
117
|
+
if (typeof declarations === 'string')
|
|
118
|
+
return declarations;
|
|
119
|
+
const handler = parseBootstrap(entry.bootstrap, handlerModule, at);
|
|
120
|
+
return typeof handler === 'string' ? handler : { ...handler, ...declarations };
|
|
121
|
+
}
|
|
122
|
+
/** Fields only a handler module can use; without one they would be dead declarations. */
|
|
123
|
+
function handlerOnlyFieldRefusal(entry, at) {
|
|
124
|
+
if (entry.bootstrap !== undefined)
|
|
125
|
+
return `${at}.bootstrap needs a handlerModule that provides it`;
|
|
126
|
+
const declared = ['connections', 'publicConfig', 'deliveryAdapters', 'forms'].find((name) => entry[name] !== undefined);
|
|
127
|
+
return declared === undefined ? null : `${at}.${declared} needs a handlerModule that uses it`;
|
|
128
|
+
}
|
|
129
|
+
function parseBootstrap(bootstrap, handlerModule, at) {
|
|
130
|
+
if (bootstrap === undefined)
|
|
131
|
+
return { handlerModule };
|
|
132
|
+
const reason = checkAdminSurfaceActionSchema({ schema: bootstrap });
|
|
133
|
+
return reason === null ? { handlerModule, bootstrap: bootstrap } : `${at}.bootstrap ${reason}`;
|
|
134
|
+
}
|
|
135
|
+
function parseIdentity(entry, at) {
|
|
136
|
+
const { id, title, entry: html } = entry;
|
|
137
|
+
if (!isId(id))
|
|
138
|
+
return `${at}.id must be a lowercase hyphenated id`;
|
|
139
|
+
if (typeof title !== 'string' || !title.trim() || title.length > MAX_TITLE_LENGTH)
|
|
140
|
+
return `${at}.title must be a non-empty string of at most ${MAX_TITLE_LENGTH} characters`;
|
|
141
|
+
if (!isContainedAdminSurfacePath({ value: html, extensions: ['.html'] }))
|
|
142
|
+
return `${at}.entry must be a plain relative path ending in .html`;
|
|
143
|
+
return { id, title, entry: html };
|
|
144
|
+
}
|
|
145
|
+
function parseFiles(value, at) {
|
|
146
|
+
if (!Array.isArray(value) || value.length > MAX_FILES)
|
|
147
|
+
return `${at}.files must be an array of at most ${MAX_FILES}`;
|
|
148
|
+
const bad = value.findIndex((file) => !isContainedAdminSurfacePath({ value: file, extensions: FILE_EXTENSIONS }));
|
|
149
|
+
return bad === -1 ? value : `${at}.files[${bad}] must be a plain relative path ending in ${FILE_EXTENSIONS.join(', ')}`;
|
|
150
|
+
}
|
|
151
|
+
function parseActions(value, at) {
|
|
152
|
+
if (!Array.isArray(value) || value.length > MAX_ACTIONS)
|
|
153
|
+
return `${at}.actions must be an array of at most ${MAX_ACTIONS}`;
|
|
154
|
+
const actions = [];
|
|
155
|
+
for (const [index, action] of value.entries()) {
|
|
156
|
+
const parsed = parseAction(action, `${at}.actions[${index}]`);
|
|
157
|
+
if (typeof parsed === 'string')
|
|
158
|
+
return parsed;
|
|
159
|
+
if (actions.some((seen) => seen.name === parsed.name))
|
|
160
|
+
return `${at}.actions[${index}].name '${parsed.name}' is declared twice`;
|
|
161
|
+
actions.push(parsed);
|
|
162
|
+
}
|
|
163
|
+
return actions;
|
|
164
|
+
}
|
|
165
|
+
function parseAction(action, at) {
|
|
166
|
+
if (!isPlainObject(action))
|
|
167
|
+
return `${at} must be an object`;
|
|
168
|
+
if (!isId(action.name))
|
|
169
|
+
return `${at}.name must be a lowercase hyphenated id`;
|
|
170
|
+
const effect = action.effect === undefined ? 'write' : action.effect;
|
|
171
|
+
if (effect !== 'read' && effect !== 'write' && effect !== 'destructive')
|
|
172
|
+
return `${at}.effect must be read, write or destructive`;
|
|
173
|
+
const input = checkAdminSurfaceActionSchema({ schema: action.input });
|
|
174
|
+
if (input !== null)
|
|
175
|
+
return `${at}.input ${input}`;
|
|
176
|
+
if (action.result === undefined)
|
|
177
|
+
return { name: action.name, effect, input: action.input };
|
|
178
|
+
const result = checkAdminSurfaceActionSchema({ schema: action.result });
|
|
179
|
+
if (result !== null)
|
|
180
|
+
return `${at}.result ${result}`;
|
|
181
|
+
return { name: action.name, effect, input: action.input, result: action.result };
|
|
182
|
+
}
|
|
183
|
+
function parseCsp(value, at) {
|
|
184
|
+
if (!isPlainObject(value))
|
|
185
|
+
return `${at}.csp must be an object`;
|
|
186
|
+
for (const [directive, sources] of Object.entries(value)) {
|
|
187
|
+
if (!ADMIN_SURFACE_CSP_DIRECTIVES.includes(directive))
|
|
188
|
+
return `${at}.csp may not extend '${directive.slice(0, 32)}'`;
|
|
189
|
+
if (!Array.isArray(sources) || sources.length > MAX_SOURCES)
|
|
190
|
+
return `${at}.csp['${directive}'] must be an array of at most ${MAX_SOURCES}`;
|
|
191
|
+
if (!sources.every((source) => isAllowedAdminSurfaceCspSource({ value: source })))
|
|
192
|
+
return `${at}.csp['${directive}'] may only list bare https origins (no wildcards, paths or keywords)`;
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=descriptor.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Host-mediated external links: a surface declares the https origins it may link to
|
|
3
|
+
* (`linkOrigins`, parsed in `./descriptor.ts`), and asks the host page to open a URL with an `open-link` message; the host page
|
|
4
|
+
* passes that message to `openAdminSurfaceLink`, which opens it through the host's own opener only
|
|
5
|
+
* when it comes from this mount and names a declared https origin.
|
|
6
|
+
*
|
|
7
|
+
* Why the host opens links: a surface frame is sandboxed without `allow-popups` or top navigation,
|
|
8
|
+
* so it cannot open anything itself, and must not: the host decides HOW (a new tab with `noopener`
|
|
9
|
+
* on the web, the system browser on desktop). Why the gate is this strict: a link the host opens
|
|
10
|
+
* leaves the sandbox entirely, so the destination is limited to what the shipped, digest-checked
|
|
11
|
+
* surfaces file declared, and the opener receives the URL parser's normalized form so it never
|
|
12
|
+
* re-parses a string this gate judged differently.
|
|
13
|
+
*/
|
|
14
|
+
import { type AdminSurfaceMessageEvent, type AdminSurfaceMountRecord } from './host-validator.js';
|
|
15
|
+
import { type AdminSurfaceActionResponse } from './protocol.js';
|
|
16
|
+
/** Host port: opens an already-checked https URL however the host decides (new tab with `noopener`, system browser). */
|
|
17
|
+
export type AdminSurfaceOpenLinkPort = (required: {
|
|
18
|
+
readonly url: string;
|
|
19
|
+
}, optional?: Record<string, never>) => void | Promise<void>;
|
|
20
|
+
/** `ignored`: not this mount's open-link message; drop silently. Otherwise post `response` back to the frame. */
|
|
21
|
+
export type AdminSurfaceLinkVerdict = {
|
|
22
|
+
readonly ok: true;
|
|
23
|
+
readonly url: string;
|
|
24
|
+
readonly response: AdminSurfaceActionResponse;
|
|
25
|
+
} | {
|
|
26
|
+
readonly ok: false;
|
|
27
|
+
readonly ignored: string;
|
|
28
|
+
} | {
|
|
29
|
+
readonly ok: false;
|
|
30
|
+
readonly refused: string;
|
|
31
|
+
readonly response: AdminSurfaceActionResponse;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Judges one `message` event as an open-link request for one mount and, when it passes, opens it
|
|
35
|
+
* through the host's port. Pass every message event here as well as to `validateAdminSurfaceMessage`;
|
|
36
|
+
* each ignores the other's messages.
|
|
37
|
+
* @param required.openLink - The host's opener; called at most once, with the normalized URL.
|
|
38
|
+
* @complexity O(n) in the URL length, plus the opener.
|
|
39
|
+
*/
|
|
40
|
+
export declare function openAdminSurfaceLink(required: {
|
|
41
|
+
readonly event: AdminSurfaceMessageEvent;
|
|
42
|
+
readonly mount: AdminSurfaceMountRecord;
|
|
43
|
+
readonly openLink: AdminSurfaceOpenLinkPort;
|
|
44
|
+
}, _optional?: Record<string, never>): Promise<AdminSurfaceLinkVerdict>;
|
|
45
|
+
//# sourceMappingURL=external-links.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Host-mediated external links: a surface declares the https origins it may link to
|
|
3
|
+
* (`linkOrigins`, parsed in `./descriptor.ts`), and asks the host page to open a URL with an `open-link` message; the host page
|
|
4
|
+
* passes that message to `openAdminSurfaceLink`, which opens it through the host's own opener only
|
|
5
|
+
* when it comes from this mount and names a declared https origin.
|
|
6
|
+
*
|
|
7
|
+
* Why the host opens links: a surface frame is sandboxed without `allow-popups` or top navigation,
|
|
8
|
+
* so it cannot open anything itself, and must not: the host decides HOW (a new tab with `noopener`
|
|
9
|
+
* on the web, the system browser on desktop). Why the gate is this strict: a link the host opens
|
|
10
|
+
* leaves the sandbox entirely, so the destination is limited to what the shipped, digest-checked
|
|
11
|
+
* surfaces file declared, and the opener receives the URL parser's normalized form so it never
|
|
12
|
+
* re-parses a string this gate judged differently.
|
|
13
|
+
*/
|
|
14
|
+
import { frameTransportRefusal, REQUEST_ID_PATTERN } from './host-validator.js';
|
|
15
|
+
import { ADMIN_SURFACE_PROTOCOL, ADMIN_SURFACE_PROTOCOL_VERSION, adminSurfaceActionResponse, } from './protocol.js';
|
|
16
|
+
/** Longer URLs are refused, not cut: a truncated link would open somewhere the plugin did not mean. */
|
|
17
|
+
const MAX_LINK_URL_LENGTH = 2048;
|
|
18
|
+
function isOpenLinkEnvelope(data) {
|
|
19
|
+
if (typeof data !== 'object' || data === null)
|
|
20
|
+
return false;
|
|
21
|
+
const message = data;
|
|
22
|
+
const isProtocol = message.protocol === ADMIN_SURFACE_PROTOCOL && message.version === ADMIN_SURFACE_PROTOCOL_VERSION && message.kind === 'open-link';
|
|
23
|
+
return isProtocol && typeof message.mountId === 'string' && typeof message.requestId === 'string' && REQUEST_ID_PATTERN.test(message.requestId) && typeof message.url === 'string';
|
|
24
|
+
}
|
|
25
|
+
/** The normalized URL when `raw` may be opened, or why not. Messages never echo the URL. @complexity O(n) in the URL length. */
|
|
26
|
+
function checkLink(raw, origins) {
|
|
27
|
+
if (raw.length > MAX_LINK_URL_LENGTH)
|
|
28
|
+
return { code: 'link-too-long', message: 'The link is too long.' };
|
|
29
|
+
if (!URL.canParse(raw))
|
|
30
|
+
return { code: 'link-invalid', message: 'That link is not a valid web address.' };
|
|
31
|
+
const parsed = new URL(raw);
|
|
32
|
+
if (parsed.protocol !== 'https:')
|
|
33
|
+
return { code: 'link-not-https', message: 'Only https links can be opened.' };
|
|
34
|
+
// Credentials in a link are a phishing shape (`https://trusted@elsewhere`) and never needed to open a page.
|
|
35
|
+
if (parsed.username !== '' || parsed.password !== '')
|
|
36
|
+
return { code: 'link-invalid', message: 'That link is not a valid web address.' };
|
|
37
|
+
if (!origins.includes(parsed.origin))
|
|
38
|
+
return { code: 'link-undeclared', message: 'This surface did not declare that link destination.' };
|
|
39
|
+
return { url: parsed.href };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Judges one `message` event as an open-link request for one mount and, when it passes, opens it
|
|
43
|
+
* through the host's port. Pass every message event here as well as to `validateAdminSurfaceMessage`;
|
|
44
|
+
* each ignores the other's messages.
|
|
45
|
+
* @param required.openLink - The host's opener; called at most once, with the normalized URL.
|
|
46
|
+
* @complexity O(n) in the URL length, plus the opener.
|
|
47
|
+
*/
|
|
48
|
+
export async function openAdminSurfaceLink(required, _optional = {}) {
|
|
49
|
+
const { event, mount, openLink } = required;
|
|
50
|
+
const transport = frameTransportRefusal({ event, mount });
|
|
51
|
+
if (transport !== null)
|
|
52
|
+
return { ok: false, ignored: transport };
|
|
53
|
+
if (!isOpenLinkEnvelope(event.data))
|
|
54
|
+
return { ok: false, ignored: 'not-an-open-link' };
|
|
55
|
+
const request = event.data;
|
|
56
|
+
if (request.mountId !== mount.mountId)
|
|
57
|
+
return { ok: false, ignored: 'mount-mismatch' };
|
|
58
|
+
const refuse = (refusal, retryable = false) => ({ ok: false, refused: refusal.code, response: adminSurfaceActionResponse({ request, outcome: { ok: false, error: { ...refusal, retryable } } }) });
|
|
59
|
+
const checked = checkLink(request.url, mount.descriptor.linkOrigins ?? []);
|
|
60
|
+
if (!('url' in checked))
|
|
61
|
+
return refuse(checked);
|
|
62
|
+
try {
|
|
63
|
+
await openLink({ url: checked.url });
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return refuse({ code: 'link-failed', message: 'The host could not open the link. Try again.' }, true);
|
|
67
|
+
}
|
|
68
|
+
return { ok: true, url: checked.url, response: adminSurfaceActionResponse({ request, outcome: { ok: true, result: null } }) };
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=external-links.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AdminSurfaceDescriptor } from './descriptor.js';
|
|
2
|
+
import { type AdminSurfaceActionRequest, type AdminSurfaceActionResponse } from './protocol.js';
|
|
3
|
+
/** The fields of a `MessageEvent` the gate reads; a real event satisfies it structurally. */
|
|
4
|
+
export interface AdminSurfaceMessageEvent {
|
|
5
|
+
readonly origin: string;
|
|
6
|
+
readonly source: unknown;
|
|
7
|
+
readonly data: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface AdminSurfaceMountRecord {
|
|
10
|
+
readonly mountId: string;
|
|
11
|
+
/** The frame's `contentWindow`; the event's `source` must be this exact object. */
|
|
12
|
+
readonly frame: unknown;
|
|
13
|
+
/** `linkOrigins` matters only to `openAdminSurfaceLink`; a record without it opens no links. */
|
|
14
|
+
readonly descriptor: Pick<AdminSurfaceDescriptor, 'actions' | 'linkOrigins'>;
|
|
15
|
+
}
|
|
16
|
+
/** `ignored`: not addressed to this mount; drop silently. `refused`: this mount's request was invalid;
|
|
17
|
+
* post `response` back so the surface can show why. */
|
|
18
|
+
export type AdminSurfaceMessageVerdict = {
|
|
19
|
+
readonly ok: true;
|
|
20
|
+
readonly request: AdminSurfaceActionRequest;
|
|
21
|
+
} | {
|
|
22
|
+
readonly ok: false;
|
|
23
|
+
readonly ignored: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly ok: false;
|
|
26
|
+
readonly refused: string;
|
|
27
|
+
readonly response: AdminSurfaceActionResponse;
|
|
28
|
+
};
|
|
29
|
+
export declare const REQUEST_ID_PATTERN: RegExp;
|
|
30
|
+
/** Character length of the payload as JSON, or Infinity when it is not JSON-serializable. */
|
|
31
|
+
/** Whether `event` comes from `mount`'s frame at all (origin and window), for every inbound message kind.
|
|
32
|
+
* @returns The failed check, or `null`. @complexity O(1). */
|
|
33
|
+
export declare function frameTransportRefusal(required: {
|
|
34
|
+
readonly event: AdminSurfaceMessageEvent;
|
|
35
|
+
readonly mount: Pick<AdminSurfaceMountRecord, 'frame'>;
|
|
36
|
+
}, _optional?: Record<string, never>): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Judges one `message` event against one mount.
|
|
39
|
+
* @complexity O(p) in the payload size (one JSON measure plus one schema walk).
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateAdminSurfaceMessage(required: {
|
|
42
|
+
readonly event: AdminSurfaceMessageEvent;
|
|
43
|
+
readonly mount: AdminSurfaceMountRecord;
|
|
44
|
+
}, _optional?: Record<string, never>): AdminSurfaceMessageVerdict;
|
|
45
|
+
/** Frame heights a host accepts by default (CSS px): tall enough for a notice, short enough that a
|
|
46
|
+
* surface cannot push the admin page out of reach. */
|
|
47
|
+
export declare const ADMIN_SURFACE_MIN_HEIGHT = 96;
|
|
48
|
+
export declare const ADMIN_SURFACE_MAX_HEIGHT = 4000;
|
|
49
|
+
/**
|
|
50
|
+
* The frame height `event` asks for when it is `mount`'s own `resize` message (same origin, window and
|
|
51
|
+
* mount as every other inbound message), clamped to `[min, max]`; null for anything else, which the
|
|
52
|
+
* caller ignores. A size is cosmetic, so a bad one is dropped rather than answered.
|
|
53
|
+
* @complexity O(1).
|
|
54
|
+
*/
|
|
55
|
+
export declare function readAdminSurfaceResize(required: {
|
|
56
|
+
readonly event: AdminSurfaceMessageEvent;
|
|
57
|
+
readonly mount: Pick<AdminSurfaceMountRecord, 'mountId' | 'frame'>;
|
|
58
|
+
}, optional?: {
|
|
59
|
+
readonly min?: number;
|
|
60
|
+
readonly max?: number;
|
|
61
|
+
}): number | null;
|
|
62
|
+
//# sourceMappingURL=host-validator.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The host page's gate for messages arriving from a mounted admin surface frame.
|
|
3
|
+
*
|
|
4
|
+
* Why every check is needed: all sandboxed frames share the origin "null", so the origin check only
|
|
5
|
+
* proves "some sandboxed frame"; the window identity proves it is THIS mount's
|
|
6
|
+
* frame; the nonce proves the frame still runs the document the host initialized (a navigated frame
|
|
7
|
+
* never received it). Action and schema checks here are an early refusal for the person using the
|
|
8
|
+
* surface; the server-side dispatcher repeats them because a host route can be called directly.
|
|
9
|
+
*/
|
|
10
|
+
import { exceedsAdminSurfacePayloadLimit, validateAdminSurfaceActionValue } from './action-schema.js';
|
|
11
|
+
import { ADMIN_SURFACE_PROTOCOL, ADMIN_SURFACE_PROTOCOL_VERSION, SANDBOXED_FRAME_ORIGIN, adminSurfaceActionResponse, } from './protocol.js';
|
|
12
|
+
export const REQUEST_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
|
|
13
|
+
function isRequestEnvelope(data) {
|
|
14
|
+
if (typeof data !== 'object' || data === null)
|
|
15
|
+
return false;
|
|
16
|
+
const message = data;
|
|
17
|
+
const isProtocol = message.protocol === ADMIN_SURFACE_PROTOCOL && message.version === ADMIN_SURFACE_PROTOCOL_VERSION && message.kind === 'action-request';
|
|
18
|
+
return isProtocol && hasRequestFields(message);
|
|
19
|
+
}
|
|
20
|
+
function hasRequestFields(message) {
|
|
21
|
+
return typeof message.mountId === 'string' && typeof message.requestId === 'string' && REQUEST_ID_PATTERN.test(message.requestId)
|
|
22
|
+
&& typeof message.action === 'string' && Object.hasOwn(message, 'payload');
|
|
23
|
+
}
|
|
24
|
+
/** Character length of the payload as JSON, or Infinity when it is not JSON-serializable. */
|
|
25
|
+
/** Whether `event` comes from `mount`'s frame at all (origin and window), for every inbound message kind.
|
|
26
|
+
* @returns The failed check, or `null`. @complexity O(1). */
|
|
27
|
+
export function frameTransportRefusal(required, _optional = {}) {
|
|
28
|
+
const { event, mount } = required;
|
|
29
|
+
// "null" is the origin of every frame sandboxed with `allow-scripts` only; nothing else may speak for a mount.
|
|
30
|
+
if (event.origin !== SANDBOXED_FRAME_ORIGIN)
|
|
31
|
+
return 'origin-mismatch';
|
|
32
|
+
return event.source === mount.frame ? null : 'source-mismatch';
|
|
33
|
+
}
|
|
34
|
+
/** Which transport check `event` fails for `mount`, or `null` when it is this mount's well-formed request. */
|
|
35
|
+
function transportRefusal(event, mount) {
|
|
36
|
+
const frame = frameTransportRefusal({ event, mount });
|
|
37
|
+
if (frame !== null)
|
|
38
|
+
return frame;
|
|
39
|
+
if (!isRequestEnvelope(event.data))
|
|
40
|
+
return 'not-an-action-request';
|
|
41
|
+
return event.data.mountId === mount.mountId ? null : 'mount-mismatch';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Judges one `message` event against one mount.
|
|
45
|
+
* @complexity O(p) in the payload size (one JSON measure plus one schema walk).
|
|
46
|
+
*/
|
|
47
|
+
export function validateAdminSurfaceMessage(required, _optional = {}) {
|
|
48
|
+
const { event, mount } = required;
|
|
49
|
+
const ignored = transportRefusal(event, mount);
|
|
50
|
+
if (ignored !== null)
|
|
51
|
+
return { ok: false, ignored };
|
|
52
|
+
const request = event.data;
|
|
53
|
+
const refuse = (code, message) => ({ ok: false, refused: code, response: adminSurfaceActionResponse({ request, outcome: { ok: false, error: { code, message, retryable: false } } }) });
|
|
54
|
+
const action = mount.descriptor.actions.find((declared) => declared.name === request.action);
|
|
55
|
+
if (action === undefined)
|
|
56
|
+
return refuse('action-undeclared', 'This surface did not declare that action.');
|
|
57
|
+
if (exceedsAdminSurfacePayloadLimit({ payload: request.payload }))
|
|
58
|
+
return refuse('invalid-payload', 'The request is too large.');
|
|
59
|
+
const violation = validateAdminSurfaceActionValue({ schema: action.input, value: request.payload });
|
|
60
|
+
if (violation !== null)
|
|
61
|
+
return refuse('invalid-payload', `The request does not match the action's input: ${violation}.`);
|
|
62
|
+
return { ok: true, request };
|
|
63
|
+
}
|
|
64
|
+
/** Frame heights a host accepts by default (CSS px): tall enough for a notice, short enough that a
|
|
65
|
+
* surface cannot push the admin page out of reach. */
|
|
66
|
+
export const ADMIN_SURFACE_MIN_HEIGHT = 96;
|
|
67
|
+
export const ADMIN_SURFACE_MAX_HEIGHT = 4000;
|
|
68
|
+
function isResizeForMount({ message, mountId }, _options = {}) {
|
|
69
|
+
const isResize = message.protocol === ADMIN_SURFACE_PROTOCOL && message.version === ADMIN_SURFACE_PROTOCOL_VERSION && message.kind === 'resize';
|
|
70
|
+
return isResize && message.mountId === mountId;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The frame height `event` asks for when it is `mount`'s own `resize` message (same origin, window and
|
|
74
|
+
* mount as every other inbound message), clamped to `[min, max]`; null for anything else, which the
|
|
75
|
+
* caller ignores. A size is cosmetic, so a bad one is dropped rather than answered.
|
|
76
|
+
* @complexity O(1).
|
|
77
|
+
*/
|
|
78
|
+
export function readAdminSurfaceResize(required, optional = {}) {
|
|
79
|
+
const { event, mount } = required;
|
|
80
|
+
if (frameTransportRefusal({ event, mount }) !== null || typeof event.data !== 'object' || event.data === null)
|
|
81
|
+
return null;
|
|
82
|
+
const message = event.data;
|
|
83
|
+
if (!isResizeForMount({ message, mountId: mount.mountId }) || typeof message.height !== 'number' || !Number.isFinite(message.height))
|
|
84
|
+
return null;
|
|
85
|
+
return Math.min(optional.max ?? ADMIN_SURFACE_MAX_HEIGHT, Math.max(optional.min ?? ADMIN_SURFACE_MIN_HEIGHT, Math.ceil(message.height)));
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=host-validator.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Public barrel for `@jini-ai/agent-plugins/admin-surfaces`: plugin-owned admin surfaces
|
|
3
|
+
* (sandboxed iframes) and the host-mediated action protocol. See `./README.md`.
|
|
4
|
+
*
|
|
5
|
+
* Explicit on purpose: only what a host composes is public. The parsers, checkers and message
|
|
6
|
+
* constants behind these entry points stay internal, so they can change without a host noticing.
|
|
7
|
+
*/
|
|
8
|
+
export { adminSurfaceInitMessage, adminSurfaceActionResponse, type AdminSurfaceBootstrap, type AdminSurfaceInitMessage, type AdminSurfaceActionRequest, type AdminSurfaceActionFailure, type AdminSurfaceActionOutcome, type AdminSurfaceActionResponse, type AdminSurfaceOpenLinkRequest, type AdminSurfaceResizeMessage, } from './protocol.js';
|
|
9
|
+
export { readAdminSurfaceTheme, adminSurfaceThemeMessage, ADMIN_SURFACE_THEME_TOKENS, type AdminSurfaceTheme, type AdminSurfaceThemeToken, type AdminSurfaceColorScheme, type AdminSurfaceThemeMessage, } from './theme.js';
|
|
10
|
+
export type { AdminSurfaceActionSchema } from './action-schema.js';
|
|
11
|
+
export { parseAdminSurfacesFile, type AdminSurfaceCspDirective, type AdminSurfaceAction, type AdminSurfaceDescriptor } from './descriptor.js';
|
|
12
|
+
export { adminSurfaceFrameAttributes, createAdminSurfaceMount, createAdminSurfaceBootstrap, adminSurfaceBootstrapHeaders } from './sandbox.js';
|
|
13
|
+
export { validateAdminSurfaceMessage, readAdminSurfaceResize, ADMIN_SURFACE_MIN_HEIGHT, ADMIN_SURFACE_MAX_HEIGHT, type AdminSurfaceMessageEvent, type AdminSurfaceMountRecord, type AdminSurfaceMessageVerdict, } from './host-validator.js';
|
|
14
|
+
export { createAdminSurfaceActionDispatcher, AdminSurfaceActionError, type AdminSurfaceActionHandler } from './action-dispatcher.js';
|
|
15
|
+
export { defineAdminSurfaceContribution, readAdminSurfaceFile, type LoadedAdminSurface } from './contribution.js';
|
|
16
|
+
export { defineAdminSurfaceHandlerContribution, createAdminSurfaceHandlerHost, type AdminSurfaceHandlerContext, type AdminSurfacePluginContext, type AdminSurfaceBootstrapCall, type AdminSurfaceHandlerCall, type AdminSurfaceHandlerModule, type LoadedAdminSurfaceHandlers, type AdminSurfaceHostKind, } from './surface-handlers.js';
|
|
17
|
+
export type { AdminSurfaceConnectionDeclaration, AdminSurfaceCapabilityDeclarations } from './capability-declarations.js';
|
|
18
|
+
export { ADMIN_SURFACE_ACTION_INTENTS, ADMIN_SURFACE_STATE_LIMITS, type AdminSurfaceConnectionState, type AdminSurfaceConnectionAction, type AdminSurfaceRevocationOutcome, type AdminSurfaceConnectionStatus, type AdminSurfaceSignInAttempt, type AdminSurfaceAuthorizationStart, type AdminSurfaceConnections, type AdminSurfaceStateValue, type AdminSurfaceState, type AdminSurfacePublicConfig, type AdminSurfaceForm, type AdminSurfaceForms, type AdminSurfaceCapabilities, type AdminSurfaceCapabilitiesPort, } from './surface-capabilities.js';
|
|
19
|
+
export type { AdminSurfaceDeliveryBinding, AdminSurfaceDeliveryBindingDraft, AdminSurfaceDeliveryBindingForms, AdminSurfaceDeliveryBindings, } from './delivery-bindings.js';
|
|
20
|
+
export { openAdminSurfaceLink, type AdminSurfaceOpenLinkPort, type AdminSurfaceLinkVerdict } from './external-links.js';
|
|
21
|
+
export { createAdminSurfaceCallbackInbox, type AdminSurfaceCallbackFieldKey } from './callback-field-inbox.js';
|
|
22
|
+
export { buildAdminSurfaceActionTools, type AdminSurfaceToolSource, type AdminSurfaceToolContext } from './action-tools.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Public barrel for `@jini-ai/agent-plugins/admin-surfaces`: plugin-owned admin surfaces
|
|
3
|
+
* (sandboxed iframes) and the host-mediated action protocol. See `./README.md`.
|
|
4
|
+
*
|
|
5
|
+
* Explicit on purpose: only what a host composes is public. The parsers, checkers and message
|
|
6
|
+
* constants behind these entry points stay internal, so they can change without a host noticing.
|
|
7
|
+
*/
|
|
8
|
+
export { adminSurfaceInitMessage, adminSurfaceActionResponse, } from './protocol.js';
|
|
9
|
+
export { readAdminSurfaceTheme, adminSurfaceThemeMessage, ADMIN_SURFACE_THEME_TOKENS, } from './theme.js';
|
|
10
|
+
export { parseAdminSurfacesFile } from './descriptor.js';
|
|
11
|
+
export { adminSurfaceFrameAttributes, createAdminSurfaceMount, createAdminSurfaceBootstrap, adminSurfaceBootstrapHeaders } from './sandbox.js';
|
|
12
|
+
export { validateAdminSurfaceMessage, readAdminSurfaceResize, ADMIN_SURFACE_MIN_HEIGHT, ADMIN_SURFACE_MAX_HEIGHT, } from './host-validator.js';
|
|
13
|
+
// AdminSurfaceActionError stays public: a host's OWN handlers throw it to send a code the surface can show.
|
|
14
|
+
export { createAdminSurfaceActionDispatcher, AdminSurfaceActionError } from './action-dispatcher.js';
|
|
15
|
+
export { defineAdminSurfaceContribution, readAdminSurfaceFile } from './contribution.js';
|
|
16
|
+
export { defineAdminSurfaceHandlerContribution, createAdminSurfaceHandlerHost, } from './surface-handlers.js';
|
|
17
|
+
export { ADMIN_SURFACE_ACTION_INTENTS, ADMIN_SURFACE_STATE_LIMITS, } from './surface-capabilities.js';
|
|
18
|
+
export { openAdminSurfaceLink } from './external-links.js';
|
|
19
|
+
export { createAdminSurfaceCallbackInbox } from './callback-field-inbox.js';
|
|
20
|
+
export { buildAdminSurfaceActionTools } from './action-tools.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The wire vocabulary shared by the host page, the host server and a plugin's admin surface:
|
|
3
|
+
* protocol constants and the message envelopes (init, action request, open-link request, response).
|
|
4
|
+
*
|
|
5
|
+
* Why a separate file: the host-side validator, the server-side dispatcher and the docs all name the
|
|
6
|
+
* same envelope, and it must stay one definition. The surface-side client (`./surface-client.ts`)
|
|
7
|
+
* deliberately repeats the constants instead of importing them so a plugin can copy that one file;
|
|
8
|
+
* the vertical-slice test proves both sides still agree.
|
|
9
|
+
*/
|
|
10
|
+
import type { AdminSurfaceTheme } from './theme.js';
|
|
11
|
+
/** Discriminates this protocol's messages from anything else posted to the same window. */
|
|
12
|
+
export declare const ADMIN_SURFACE_PROTOCOL = "jini.admin-surface";
|
|
13
|
+
export declare const ADMIN_SURFACE_PROTOCOL_VERSION = 1;
|
|
14
|
+
/** The ONLY sandbox token a surface frame gets. Adding `allow-same-origin` next to `allow-scripts`
|
|
15
|
+
* lets the frame remove its own sandbox, so it is never granted. */
|
|
16
|
+
export declare const ADMIN_SURFACE_SANDBOX = "allow-scripts";
|
|
17
|
+
/** A frame sandboxed without `allow-same-origin` has an opaque origin, which `MessageEvent.origin`
|
|
18
|
+
* serializes as the string "null". Every sandboxed frame shares it, so origin alone never identifies
|
|
19
|
+
* a mount: the per-mount nonce and the frame's window identity do. */
|
|
20
|
+
export declare const SANDBOXED_FRAME_ORIGIN = "null";
|
|
21
|
+
/** Short-lived data the host server issues for one surface render (e.g. a scoped access token plus
|
|
22
|
+
* public config). Never cached (see `adminSurfaceBootstrapHeaders`), refused once `expiresAt` passes. */
|
|
23
|
+
export interface AdminSurfaceBootstrap<D = unknown> {
|
|
24
|
+
readonly surfaceId: string;
|
|
25
|
+
readonly issuedAt: number;
|
|
26
|
+
readonly expiresAt: number;
|
|
27
|
+
readonly data: D;
|
|
28
|
+
}
|
|
29
|
+
/** Host page -> surface, once per mount, after the frame loads. Carries the mount nonce and, when
|
|
30
|
+
* the host shares them, its design tokens (`./theme.ts`; later changes arrive as `theme` messages). */
|
|
31
|
+
export interface AdminSurfaceInitMessage {
|
|
32
|
+
readonly protocol: typeof ADMIN_SURFACE_PROTOCOL;
|
|
33
|
+
readonly version: typeof ADMIN_SURFACE_PROTOCOL_VERSION;
|
|
34
|
+
readonly kind: 'init';
|
|
35
|
+
readonly mountId: string;
|
|
36
|
+
readonly bootstrap?: AdminSurfaceBootstrap;
|
|
37
|
+
readonly theme?: AdminSurfaceTheme;
|
|
38
|
+
}
|
|
39
|
+
/** Surface -> host page. `mountId` must echo the nonce from init. */
|
|
40
|
+
export interface AdminSurfaceActionRequest {
|
|
41
|
+
readonly protocol: typeof ADMIN_SURFACE_PROTOCOL;
|
|
42
|
+
readonly version: typeof ADMIN_SURFACE_PROTOCOL_VERSION;
|
|
43
|
+
readonly kind: 'action-request';
|
|
44
|
+
readonly mountId: string;
|
|
45
|
+
readonly requestId: string;
|
|
46
|
+
readonly action: string;
|
|
47
|
+
readonly payload: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** Surface -> host page: asks the host to open `url` outside the sandbox (`./external-links.ts`).
|
|
50
|
+
* Answered with an `action-response` for `requestId`, like an action. */
|
|
51
|
+
export interface AdminSurfaceOpenLinkRequest {
|
|
52
|
+
readonly protocol: typeof ADMIN_SURFACE_PROTOCOL;
|
|
53
|
+
readonly version: typeof ADMIN_SURFACE_PROTOCOL_VERSION;
|
|
54
|
+
readonly kind: 'open-link';
|
|
55
|
+
readonly mountId: string;
|
|
56
|
+
readonly requestId: string;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
}
|
|
59
|
+
/** Surface-safe failure: `message` is written for the person using the surface and never carries a
|
|
60
|
+
* handler's raw error text, a token or a submitted value. */
|
|
61
|
+
/** Surface -> host: the surface's content height in CSS pixels, so the host can size the frame to fit. */
|
|
62
|
+
export interface AdminSurfaceResizeMessage {
|
|
63
|
+
readonly protocol: typeof ADMIN_SURFACE_PROTOCOL;
|
|
64
|
+
readonly version: typeof ADMIN_SURFACE_PROTOCOL_VERSION;
|
|
65
|
+
readonly kind: 'resize';
|
|
66
|
+
readonly mountId: string;
|
|
67
|
+
readonly height: number;
|
|
68
|
+
}
|
|
69
|
+
export interface AdminSurfaceActionFailure {
|
|
70
|
+
readonly code: string;
|
|
71
|
+
readonly message: string;
|
|
72
|
+
readonly retryable: boolean;
|
|
73
|
+
}
|
|
74
|
+
export type AdminSurfaceActionOutcome = {
|
|
75
|
+
readonly ok: true;
|
|
76
|
+
readonly result: unknown;
|
|
77
|
+
} | {
|
|
78
|
+
readonly ok: false;
|
|
79
|
+
readonly error: AdminSurfaceActionFailure;
|
|
80
|
+
};
|
|
81
|
+
/** Host page -> surface, answering exactly one request. */
|
|
82
|
+
export type AdminSurfaceActionResponse = {
|
|
83
|
+
readonly protocol: typeof ADMIN_SURFACE_PROTOCOL;
|
|
84
|
+
readonly version: typeof ADMIN_SURFACE_PROTOCOL_VERSION;
|
|
85
|
+
readonly kind: 'action-response';
|
|
86
|
+
readonly mountId: string;
|
|
87
|
+
readonly requestId: string;
|
|
88
|
+
} & AdminSurfaceActionOutcome;
|
|
89
|
+
/** Builds the init envelope the host page posts into a freshly loaded frame.
|
|
90
|
+
* @complexity O(1). */
|
|
91
|
+
export declare function adminSurfaceInitMessage(required: {
|
|
92
|
+
readonly mountId: string;
|
|
93
|
+
}, optional?: {
|
|
94
|
+
readonly bootstrap?: AdminSurfaceBootstrap;
|
|
95
|
+
readonly theme?: AdminSurfaceTheme;
|
|
96
|
+
}): AdminSurfaceInitMessage;
|
|
97
|
+
/** Wraps a dispatcher outcome as the response to one validated request.
|
|
98
|
+
* @complexity O(1). */
|
|
99
|
+
export declare function adminSurfaceActionResponse(required: {
|
|
100
|
+
readonly request: Pick<AdminSurfaceActionRequest, 'mountId' | 'requestId'>;
|
|
101
|
+
readonly outcome: AdminSurfaceActionOutcome;
|
|
102
|
+
}, _optional?: Record<string, never>): AdminSurfaceActionResponse;
|
|
103
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Discriminates this protocol's messages from anything else posted to the same window. */
|
|
2
|
+
export const ADMIN_SURFACE_PROTOCOL = 'jini.admin-surface';
|
|
3
|
+
export const ADMIN_SURFACE_PROTOCOL_VERSION = 1;
|
|
4
|
+
/** The ONLY sandbox token a surface frame gets. Adding `allow-same-origin` next to `allow-scripts`
|
|
5
|
+
* lets the frame remove its own sandbox, so it is never granted. */
|
|
6
|
+
export const ADMIN_SURFACE_SANDBOX = 'allow-scripts';
|
|
7
|
+
/** A frame sandboxed without `allow-same-origin` has an opaque origin, which `MessageEvent.origin`
|
|
8
|
+
* serializes as the string "null". Every sandboxed frame shares it, so origin alone never identifies
|
|
9
|
+
* a mount: the per-mount nonce and the frame's window identity do. */
|
|
10
|
+
export const SANDBOXED_FRAME_ORIGIN = 'null';
|
|
11
|
+
/** Builds the init envelope the host page posts into a freshly loaded frame.
|
|
12
|
+
* @complexity O(1). */
|
|
13
|
+
export function adminSurfaceInitMessage(required, optional = {}) {
|
|
14
|
+
return {
|
|
15
|
+
protocol: ADMIN_SURFACE_PROTOCOL, version: ADMIN_SURFACE_PROTOCOL_VERSION, kind: 'init', mountId: required.mountId,
|
|
16
|
+
...(optional.bootstrap ? { bootstrap: optional.bootstrap } : {}), ...(optional.theme ? { theme: optional.theme } : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Wraps a dispatcher outcome as the response to one validated request.
|
|
20
|
+
* @complexity O(1). */
|
|
21
|
+
export function adminSurfaceActionResponse(required, _optional = {}) {
|
|
22
|
+
const { mountId, requestId } = required.request;
|
|
23
|
+
return { protocol: ADMIN_SURFACE_PROTOCOL, version: ADMIN_SURFACE_PROTOCOL_VERSION, kind: 'action-response', mountId, requestId, ...required.outcome };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=protocol.js.map
|