@jini-ai/agent-plugins 0.4.7 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/admin-surfaces/action-dispatcher.d.ts +37 -0
  4. package/dist/admin-surfaces/action-dispatcher.js +69 -0
  5. package/dist/admin-surfaces/action-schema.d.ts +56 -0
  6. package/dist/admin-surfaces/action-schema.js +167 -0
  7. package/dist/admin-surfaces/action-tools.d.ts +40 -0
  8. package/dist/admin-surfaces/action-tools.js +52 -0
  9. package/dist/admin-surfaces/callback-field-inbox.d.ts +35 -0
  10. package/dist/admin-surfaces/callback-field-inbox.js +53 -0
  11. package/dist/admin-surfaces/capability-declarations.d.ts +41 -0
  12. package/dist/admin-surfaces/capability-declarations.js +102 -0
  13. package/dist/admin-surfaces/contribution.d.ts +49 -0
  14. package/dist/admin-surfaces/contribution.js +30 -0
  15. package/dist/admin-surfaces/delivery-bindings.d.ts +76 -0
  16. package/dist/admin-surfaces/delivery-bindings.js +99 -0
  17. package/dist/admin-surfaces/descriptor.d.ts +69 -0
  18. package/dist/admin-surfaces/descriptor.js +196 -0
  19. package/dist/admin-surfaces/external-links.d.ts +45 -0
  20. package/dist/admin-surfaces/external-links.js +70 -0
  21. package/dist/admin-surfaces/host-validator.d.ts +62 -0
  22. package/dist/admin-surfaces/host-validator.js +87 -0
  23. package/dist/admin-surfaces/index.d.ts +23 -0
  24. package/dist/admin-surfaces/index.js +21 -0
  25. package/dist/admin-surfaces/protocol.d.ts +103 -0
  26. package/dist/admin-surfaces/protocol.js +25 -0
  27. package/dist/admin-surfaces/sandbox.d.ts +78 -0
  28. package/dist/admin-surfaces/sandbox.js +92 -0
  29. package/dist/admin-surfaces/settings-value.d.ts +28 -0
  30. package/dist/admin-surfaces/settings-value.js +45 -0
  31. package/dist/admin-surfaces/surface-capabilities.d.ts +167 -0
  32. package/dist/admin-surfaces/surface-capabilities.js +215 -0
  33. package/dist/admin-surfaces/surface-client.d.ts +116 -0
  34. package/dist/admin-surfaces/surface-client.js +219 -0
  35. package/dist/admin-surfaces/surface-handlers.d.ts +111 -0
  36. package/dist/admin-surfaces/surface-handlers.js +172 -0
  37. package/dist/admin-surfaces/theme.d.ts +59 -0
  38. package/dist/admin-surfaces/theme.js +57 -0
  39. package/dist/folder-zip-node.js +59 -49
  40. package/dist/folder-zip.js +9 -7
  41. package/dist/lifecycle/automatic-use.d.ts +79 -0
  42. package/dist/lifecycle/automatic-use.js +165 -0
  43. package/dist/lifecycle/compatibility-metadata.d.ts +19 -0
  44. package/dist/lifecycle/compatibility-metadata.js +45 -0
  45. package/dist/lifecycle/compatibility.d.ts +52 -0
  46. package/dist/lifecycle/compatibility.js +60 -0
  47. package/dist/lifecycle/fetch-archive.js +26 -24
  48. package/dist/lifecycle/index.d.ts +14 -2
  49. package/dist/lifecycle/index.js +8 -1
  50. package/dist/lifecycle/install.js +7 -0
  51. package/dist/lifecycle/installed-package-index.js +41 -29
  52. package/dist/lifecycle/installed-package-roots.js +28 -20
  53. package/dist/lifecycle/manifest.d.ts +13 -0
  54. package/dist/lifecycle/manifest.js +115 -101
  55. package/dist/lifecycle/package-paths.js +3 -3
  56. package/dist/lifecycle/ports.d.ts +1 -1
  57. package/dist/lifecycle/provider-contribution.d.ts +65 -0
  58. package/dist/lifecycle/provider-contribution.js +93 -0
  59. package/dist/lifecycle/resolve-agent-plugin-refs.js +15 -2
  60. package/dist/lifecycle/retire-bundled.js +20 -18
  61. package/dist/lifecycle/search.d.ts +6 -1
  62. package/dist/lifecycle/search.js +45 -7
  63. package/dist/lifecycle/set-enabled.d.ts +2 -1
  64. package/dist/lifecycle/set-enabled.js +52 -8
  65. package/dist/lifecycle/skill-file-reader.js +85 -71
  66. package/dist/lifecycle/tools/capabilities.d.ts +199 -0
  67. package/dist/lifecycle/tools/capabilities.js +213 -0
  68. package/dist/lifecycle/tools/definition.d.ts +32 -0
  69. package/dist/lifecycle/tools/definition.js +33 -0
  70. package/dist/lifecycle/tools/index.d.ts +10 -0
  71. package/dist/lifecycle/tools/index.js +10 -0
  72. package/dist/lifecycle/tools/manifest.d.ts +33 -0
  73. package/dist/lifecycle/tools/manifest.js +89 -0
  74. package/dist/lifecycle/tools/projection.d.ts +90 -0
  75. package/dist/lifecycle/tools/projection.js +283 -0
  76. package/dist/lifecycle/types.d.ts +2 -0
  77. package/dist/lifecycle/uninstall.d.ts +3 -1
  78. package/dist/lifecycle/uninstall.js +51 -27
  79. package/dist/lifecycle/update-plan.d.ts +18 -0
  80. package/dist/lifecycle/update-plan.js +22 -0
  81. package/dist/lifecycle/update-store.d.ts +71 -0
  82. package/dist/lifecycle/update-store.js +150 -0
  83. package/dist/lifecycle/update.d.ts +55 -0
  84. package/dist/lifecycle/update.js +321 -0
  85. package/package.json +38 -6
  86. package/ui-ux-design/plugin.json +7 -2
@@ -0,0 +1,213 @@
1
+ /**
2
+ * @file Host capabilities a plugin tool receives at invocation, typed as ports: the host supplies
3
+ * every implementation (token store, guarded HTTP, limiter, artifact store) and Jini never names a
4
+ * provider. A per-call session wraps them so that (1) every capability stops working the moment the
5
+ * plugin's tools are revoked, even for a module that kept a reference, and (2) an access token the
6
+ * call obtained can never leave through the tool's result or error text. Those two gates are
7
+ * `openCapabilityGate`, shared with the admin-surface session so both enforce them identically.
8
+ *
9
+ * Plugin state reaches a tool read-only: the plugin's admin surface writes its settings (for example
10
+ * which of its products are on), and its tools must honor them, but an agent tool never changes them.
11
+ */
12
+ /** One limit for every reader and writer of plugin state; the admin-surface limits reuse it. */
13
+ export const PLUGIN_STATE_MAX_KEY_LENGTH = 128;
14
+ const STATE_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
15
+ export const REVOKED_MESSAGE = 'This plugin tool was disabled; its capabilities are revoked. Re-enable the plugin and retry.';
16
+ export const WITHHELD_OUTPUT_MESSAGE = 'The plugin tool result was withheld because it contained a connection credential.';
17
+ export const WITHHELD_ERROR_MESSAGE = 'The plugin tool failed and its error was withheld because it contained a connection credential.';
18
+ /** Newest tokens kept; access tokens are short-lived, so older ones matter less than bounded memory. */
19
+ export const ISSUED_TOKEN_MEMORY_LIMIT = 64;
20
+ /**
21
+ * One token memory per plugin, shared by every context that runs that plugin's code: its tools, its
22
+ * surface handlers and their state writes. Why per plugin and not per context or generation: those
23
+ * contexts can share module scope (a common lib module), and Node caches an imported module, so its
24
+ * scope outlives a re-sync; a memory per context or per generation would let a token obtained in one
25
+ * leave through the other. A host creates ONE and passes it to both seams.
26
+ * @complexity O(1) per lookup; space O(plugins * ISSUED_TOKEN_MEMORY_LIMIT).
27
+ */
28
+ export function createIssuedTokenMemories(_required = {}, _optional = {}) {
29
+ const byPlugin = new Map();
30
+ return Object.freeze({
31
+ forPlugin({ pluginId }) {
32
+ let issued = byPlugin.get(pluginId);
33
+ if (issued === undefined)
34
+ byPlugin.set(pluginId, issued = new Set());
35
+ return issued;
36
+ },
37
+ });
38
+ }
39
+ /** Records `token` as newest, dropping the oldest beyond the limit. @complexity O(1) amortized. */
40
+ function remember(issued, token) {
41
+ issued.delete(token);
42
+ issued.add(token);
43
+ if (issued.size > ISSUED_TOKEN_MEMORY_LIMIT)
44
+ issued.delete(issued.values().next().value);
45
+ }
46
+ /** True when `text` holds any issued token, raw or JSON-escaped. @complexity O(n * t). */
47
+ function textMentions(text, issued) {
48
+ for (const token of issued)
49
+ if (text.includes(token) || text.includes(JSON.stringify(token).slice(1, -1)))
50
+ return true;
51
+ return false;
52
+ }
53
+ /** True when `value` (serialized) mentions any issued token. Unserializable values fail closed.
54
+ * @complexity O(n * t) for serialized size n and t issued tokens (t ≤ ISSUED_TOKEN_MEMORY_LIMIT). */
55
+ function mentionsToken(value, issued) {
56
+ if (issued.size === 0)
57
+ return false;
58
+ let text;
59
+ try {
60
+ text = JSON.stringify(value);
61
+ }
62
+ catch {
63
+ return true;
64
+ }
65
+ return text !== undefined && textMentions(text, issued);
66
+ }
67
+ /**
68
+ * Objects an error scan visits before it gives up and withholds the error. Generous for any real
69
+ * error (a few causes, an `AggregateError` of a few dozen), small enough to bound a hostile graph.
70
+ */
71
+ const ERROR_SCAN_NODE_LIMIT = 256;
72
+ /**
73
+ * Everything one object can hold a token in: every own property, non-enumerable and symbol-keyed
74
+ * ones too (`message`, `stack`, `cause`, `AggregateError.errors`), plus Map and Set contents.
75
+ * Null when reading it threw (a hostile getter or proxy): the caller fails closed.
76
+ * @complexity O(own properties + entries).
77
+ */
78
+ function childrenOf(value) {
79
+ try {
80
+ const own = Reflect.ownKeys(value).map(key => value[key]);
81
+ if (value instanceof Map)
82
+ return [...own, ...value.keys(), ...value.values()];
83
+ return value instanceof Set ? [...own, ...value.values()] : own;
84
+ }
85
+ catch {
86
+ return null;
87
+ }
88
+ }
89
+ /**
90
+ * True when any string reachable from `error` mentions an issued token. JSON would miss the
91
+ * non-enumerable `cause` and `AggregateError.errors`, and errors held in plain objects, so this walks
92
+ * the object graph instead, to any depth. It fails closed: an unreadable object, or a graph past
93
+ * `ERROR_SCAN_NODE_LIMIT` objects, counts as mentioning a token.
94
+ * @complexity O(v * t) for v visited values (objects bounded by the node limit) and t issued tokens.
95
+ */
96
+ function errorMentionsToken(error, issued) {
97
+ if (issued.size === 0)
98
+ return false;
99
+ const seen = new Set();
100
+ const pending = [error];
101
+ while (pending.length > 0) {
102
+ const next = scanStep(pending.pop(), issued, seen);
103
+ if (next === true)
104
+ return true;
105
+ // A loop, not push(...next): a huge array would exceed the engine's argument limit.
106
+ for (const child of next)
107
+ pending.push(child);
108
+ }
109
+ return false;
110
+ }
111
+ /** One value of the scan: `true` when it mentions a token or cannot be scanned, else what it holds. */
112
+ function scanStep(value, issued, seen) {
113
+ if (typeof value === 'string')
114
+ return textMentions(value, issued) || [];
115
+ if (typeof value !== 'object' || value === null || seen.has(value))
116
+ return [];
117
+ seen.add(value);
118
+ return (seen.size > ERROR_SCAN_NODE_LIMIT ? null : childrenOf(value)) ?? true;
119
+ }
120
+ /**
121
+ * The credential scans alone, for plugin answers that need no capabilities (a tool's
122
+ * affected-resources disclosure): `mentionsToken`, and `sanitize` (an error, or a credential-free
123
+ * replacement without `cause`, since the cause may hold the token).
124
+ * @param required.issued - The plugin's token memory (see `createIssuedTokenMemories`).
125
+ * @complexity O(1) to open; the scans are O(scanned size * remembered tokens).
126
+ */
127
+ export function openCredentialScan(required, _optional = {}) {
128
+ const { issued } = required;
129
+ return {
130
+ mentionsToken: ({ value }) => mentionsToken(value, issued),
131
+ sanitize({ error }) {
132
+ return errorMentionsToken(error, issued) ? new Error(WITHHELD_ERROR_MESSAGE) : error;
133
+ },
134
+ };
135
+ }
136
+ /**
137
+ * The revocation and credential gates every capability session shares: this file's tool session and
138
+ * the admin-surface session (`../../admin-surfaces/surface-capabilities.ts`), so both revoke and scan
139
+ * the same way.
140
+ * @param required.isLive - False once the contributing plugin's contributions are revoked.
141
+ * @param required.issued - The plugin's token memory (see `createIssuedTokenMemories`).
142
+ * @returns `guard` (wraps a capability so it refuses once revoked), `noteToken` (records a token the
143
+ * call obtained), `mentionsToken`, and the `release` (result) and `sanitize` (error) gates.
144
+ * @complexity O(1) to open; the scans are O(serialized size * remembered tokens).
145
+ */
146
+ export function openCapabilityGate(required, _optional = {}) {
147
+ const { isLive, issued } = required;
148
+ return {
149
+ guard: (call) => async (...args) => {
150
+ if (!isLive())
151
+ throw new Error(REVOKED_MESSAGE);
152
+ return call(...args);
153
+ },
154
+ noteToken({ token }) {
155
+ if (token)
156
+ remember(issued, token);
157
+ return token;
158
+ },
159
+ ...openCredentialScan({ issued }),
160
+ /** The result, unless it mentions a token this plugin obtained. */
161
+ release({ value }) {
162
+ if (mentionsToken(value, issued))
163
+ throw new Error(WITHHELD_OUTPUT_MESSAGE);
164
+ return value;
165
+ },
166
+ };
167
+ }
168
+ /** The host capabilities every session wraps the same way: guarded HTTP, limiter and artifacts
169
+ * (artifacts only when the host gives a store: absent stays absent, never a wrapper that throws). @complexity O(1). */
170
+ export function guardSharedCapabilities(required, _optional = {}) {
171
+ const { gate: { guard }, host } = required;
172
+ const { artifacts } = host;
173
+ return {
174
+ http: Object.freeze({ fetch: guard((input, options) => host.http.fetch(input, options)) }),
175
+ limiter: Object.freeze({ check: guard((input) => host.limiter.check(input)) }),
176
+ ...(artifacts !== undefined && { artifacts: Object.freeze({ write: guard((input) => artifacts.write(input)) }) }),
177
+ };
178
+ }
179
+ /** The key shape every plugin state call shares, so a key never reaches the host as a path or a scope. */
180
+ export function checkedStateKey(required, _optional = {}) {
181
+ const { key } = required;
182
+ if (typeof key !== 'string' || !STATE_KEY_PATTERN.test(key))
183
+ throw new Error(`A settings key must be a short name of at most ${PLUGIN_STATE_MAX_KEY_LENGTH} characters.`);
184
+ return key;
185
+ }
186
+ /**
187
+ * The read-only state view a session hands out: `get` alone, the key checked and passed on by itself
188
+ * (so plugin code cannot add a scope the host might honor), revoked with the session's gate.
189
+ * @complexity O(1) plus the key check.
190
+ */
191
+ export function guardStateReader(required, _optional = {}) {
192
+ const { gate, state } = required;
193
+ return Object.freeze({ get: gate.guard(({ key }) => state.get({ key: checkedStateKey({ key }) })) });
194
+ }
195
+ /**
196
+ * Opens the capability session for one tool call.
197
+ * @param required.capabilities - The host's capabilities for this call.
198
+ * @param required.isLive - False once the contributing plugin's tools are revoked.
199
+ * @param required.issued - The plugin's token memory, shared by all its calls and its surface handlers.
200
+ * @returns Wrapped capabilities plus `release` (result gate) and `sanitize` (error gate).
201
+ * @complexity O(1) to open; gates are O(serialized size).
202
+ */
203
+ export function openCapabilitySession(required, _optional = {}) {
204
+ const { capabilities: host, isLive, issued } = required;
205
+ const gate = openCapabilityGate({ isLive, issued });
206
+ const capabilities = Object.freeze({
207
+ connections: Object.freeze({ getAccessToken: gate.guard(async (input) => gate.noteToken({ token: await host.connections.getAccessToken({ connectionRef: input.connectionRef }) })) }),
208
+ ...guardSharedCapabilities({ gate, host }),
209
+ state: guardStateReader({ gate, state: host.state }),
210
+ });
211
+ return { capabilities, release: gate.release, sanitize: gate.sanitize };
212
+ }
213
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @file The executable tool contribution, defined on the lifecycle's one executable loader
3
+ * (`defineExecutablePluginContribution`) so tool modules pass the same gates as every other seam
4
+ * that runs plugin code: active plugin, bundled digest, contained `.mjs` path. No second loader.
5
+ * The filename is the host's: Jini never names a product's contribution file.
6
+ */
7
+ import { type LoadedPluginContribution, type PluginContributionDefinition } from '../contribution-loader.js';
8
+ import type { AgentPluginToolCapabilities } from './capabilities.js';
9
+ import { type AgentPluginToolDescriptor } from './manifest.js';
10
+ /** What a tool module's default export must be. `input` has already passed the declared schema. */
11
+ export interface AgentPluginToolModule {
12
+ readonly invoke: (required: {
13
+ readonly input: Readonly<Record<string, unknown>>;
14
+ readonly capabilities: AgentPluginToolCapabilities;
15
+ readonly signal?: AbortSignal;
16
+ }, optional?: Record<string, never>) => unknown;
17
+ /** Human-readable resources the call would change, shown before confirmation. Required unless `read`. */
18
+ readonly describeAffectedResources?: (required: {
19
+ readonly input: Readonly<Record<string, unknown>>;
20
+ }, optional?: Record<string, never>) => unknown;
21
+ }
22
+ export type LoadedAgentPluginTool = LoadedPluginContribution<AgentPluginToolDescriptor, AgentPluginToolModule>;
23
+ /**
24
+ * Defines the tool contribution for a host-chosen filename (e.g. `<product>-agent-tools.json`).
25
+ * @param required.filename - The file a plugin ships at its package root to contribute tools.
26
+ * @returns A definition for `loadPluginContributions`; executable, so activation is always required.
27
+ * @complexity O(1); each load is one contained import per declared tool (Node caches per file URL).
28
+ */
29
+ export declare function defineAgentPluginToolContribution(required: {
30
+ readonly filename: string;
31
+ }, _optional?: Record<string, never>): PluginContributionDefinition<AgentPluginToolDescriptor, LoadedAgentPluginTool>;
32
+ //# sourceMappingURL=definition.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file The executable tool contribution, defined on the lifecycle's one executable loader
3
+ * (`defineExecutablePluginContribution`) so tool modules pass the same gates as every other seam
4
+ * that runs plugin code: active plugin, bundled digest, contained `.mjs` path. No second loader.
5
+ * The filename is the host's: Jini never names a product's contribution file.
6
+ */
7
+ import { defineExecutablePluginContribution } from '../contribution-loader.js';
8
+ import { parseAgentPluginToolsFile } from './manifest.js';
9
+ /** The module's export as a tool module, or why not. Shape only; effect rules apply at projection. @complexity O(1). */
10
+ function validateToolModule({ exported }) {
11
+ if (typeof exported !== 'object' || exported === null)
12
+ return "its module's default export is not an object";
13
+ const candidate = exported;
14
+ if (typeof candidate.invoke !== 'function')
15
+ return "its module's default export has no invoke()";
16
+ if (candidate.describeAffectedResources !== undefined && typeof candidate.describeAffectedResources !== 'function')
17
+ return 'describeAffectedResources must be a function';
18
+ return exported;
19
+ }
20
+ /**
21
+ * Defines the tool contribution for a host-chosen filename (e.g. `<product>-agent-tools.json`).
22
+ * @param required.filename - The file a plugin ships at its package root to contribute tools.
23
+ * @returns A definition for `loadPluginContributions`; executable, so activation is always required.
24
+ * @complexity O(1); each load is one contained import per declared tool (Node caches per file URL).
25
+ */
26
+ export function defineAgentPluginToolContribution(required, _optional = {}) {
27
+ return defineExecutablePluginContribution({
28
+ filename: required.filename, contribution: 'agent tools',
29
+ parse: parseAgentPluginToolsFile, modulePath: ({ descriptor }) => descriptor.module, validate: validateToolModule,
30
+ refusal: ({ plugin, descriptor, reason }) => `agent tool '${descriptor.name}' from '${plugin.pluginId}' was not loaded: ${reason}`,
31
+ });
32
+ }
33
+ //# sourceMappingURL=definition.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Public surface of `@jini-ai/agent-plugins/lifecycle/tools`: executable Agent Plugin tools.
3
+ * A separate subpath because it needs the optional `@cfworker/json-schema` peer; consumers of
4
+ * `./lifecycle` alone do not. The plugin tool contract arrives as host ports, never an import. See this folder's README.md.
5
+ */
6
+ export { parseAgentPluginToolsFile, type AgentPluginToolDescriptor, type AgentPluginToolEffect } from './manifest.js';
7
+ export { defineAgentPluginToolContribution, type AgentPluginToolModule, type LoadedAgentPluginTool } from './definition.js';
8
+ export { WITHHELD_OUTPUT_MESSAGE, createIssuedTokenMemories, type IssuedTokenMemories, type AgentPluginToolCapabilities, type AgentPluginToolCapabilitiesPort, type AgentPluginToolCapabilityScope, type AgentPluginHttpOptions, type AgentPluginLimitResult, type AgentPluginStateReader, type AgentPluginStateValue, } from './capabilities.js';
9
+ export { createAgentPluginToolProjection, type AgentPluginToolDisclosure, type AgentPluginToolProjectionPorts, type AgentPluginAdditionalTool, type AgentPluginToolSnapshot, type AgentPluginContractTool, type AgentPluginToolInvocation, } from './projection.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Public surface of `@jini-ai/agent-plugins/lifecycle/tools`: executable Agent Plugin tools.
3
+ * A separate subpath because it needs the optional `@cfworker/json-schema` peer; consumers of
4
+ * `./lifecycle` alone do not. The plugin tool contract arrives as host ports, never an import. See this folder's README.md.
5
+ */
6
+ export { parseAgentPluginToolsFile } from './manifest.js';
7
+ export { defineAgentPluginToolContribution } from './definition.js';
8
+ export { WITHHELD_OUTPUT_MESSAGE, createIssuedTokenMemories, } from './capabilities.js';
9
+ export { createAgentPluginToolProjection, } from './projection.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file Parses an Agent Plugin's tool contribution file: the data half of an executable tool.
3
+ * Name, description, effect class and input schema are declared as reviewable data so the host can
4
+ * list, namespace and validate a tool without running plugin code; only `module` points at code.
5
+ * Pure: no I/O. A file that fails any rule is refused whole, so a plugin never ships half its tools.
6
+ */
7
+ import type { PluginContributionParseResult } from '../contribution-loader.js';
8
+ /**
9
+ * Declared change class; `write` and `destructive` tools must also disclose affected resources.
10
+ * The mirror of `PluginToolEffect` in `@jini-ai/plugins/host` (agent-plugins may not import it); the
11
+ * projection's contract tool reuses this type, so these two are the only declarations.
12
+ */
13
+ export type AgentPluginToolEffect = 'read' | 'write' | 'destructive';
14
+ /** One declared tool. `name` is local; the host namespaces it as `p_<plugin>__<name>`. */
15
+ export interface AgentPluginToolDescriptor {
16
+ readonly name: string;
17
+ readonly description: string;
18
+ readonly effect: AgentPluginToolEffect;
19
+ /** Plain-JS module inside the plugin root (`.mjs`); containment is checked on disk at import. */
20
+ readonly module: string;
21
+ /** JSON Schema (2020-12) for the tool input; must describe an object. */
22
+ readonly inputSchema: Readonly<Record<string, unknown>>;
23
+ }
24
+ /**
25
+ * Parses the raw contribution file. A local name declared twice is refused (duplicate id).
26
+ * @param required.raw - The file text as read from a trusted package.
27
+ * @returns Descriptors in declaration order, or the reason the whole file is refused.
28
+ * @complexity O(t^2 + s) for t declarations (t <= 128) and s total schema size.
29
+ */
30
+ export declare function parseAgentPluginToolsFile(required: {
31
+ readonly raw: string;
32
+ }, _optional?: Record<string, never>): PluginContributionParseResult<AgentPluginToolDescriptor>;
33
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1,89 @@
1
+ // Bounds mirror the existing tier-3 tool capture (`@jini-ai/plugins/host` contributions.ts) so one
2
+ // plugin tool contract has one set of limits, whichever loader admitted it.
3
+ const NAME_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
4
+ const MAX_TOOLS = 128;
5
+ const MAX_DESCRIPTION = 8000;
6
+ const MAX_MODULE_PATH = 256;
7
+ const MAX_SCHEMA_BYTES = 65536;
8
+ const EFFECTS = new Set(['read', 'write', 'destructive']);
9
+ function isRecord(value) {
10
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
11
+ }
12
+ /** Why the input schema is unusable, or undefined. Detaches nothing; the caller copies. @complexity O(s) schema size. */
13
+ function schemaProblem(schema) {
14
+ if (!isRecord(schema) || schema.type !== 'object')
15
+ return 'inputSchema must be a JSON Schema describing an object';
16
+ if (new TextEncoder().encode(JSON.stringify(schema)).byteLength > MAX_SCHEMA_BYTES)
17
+ return 'inputSchema is larger than 64 KiB';
18
+ return undefined;
19
+ }
20
+ /** Why a description is unusable, or undefined. @complexity O(1). */
21
+ function descriptionProblem(name, description) {
22
+ if (typeof description === 'string' && description.trim() && description.length <= MAX_DESCRIPTION)
23
+ return undefined;
24
+ return `tool '${name}' needs a description of at most ${MAX_DESCRIPTION} characters`;
25
+ }
26
+ /** Why a module path is unusable here, or undefined; containment is checked on disk at import. @complexity O(1). */
27
+ function moduleProblem(name, module) {
28
+ if (typeof module === 'string' && module.endsWith('.mjs') && module.length <= MAX_MODULE_PATH)
29
+ return undefined;
30
+ return `tool '${name}' module must be a .mjs path inside the plugin`;
31
+ }
32
+ /** Why one declaration's scalar fields are invalid, or undefined. @complexity O(1). */
33
+ function fieldProblem(entry) {
34
+ const { name } = entry;
35
+ if (typeof name !== 'string' || !NAME_PATTERN.test(name))
36
+ return 'a tool name must be lower snake case, at most 64 characters';
37
+ const effectProblem = EFFECTS.has(entry.effect) ? undefined : `tool '${name}' effect must be read, write or destructive`;
38
+ return descriptionProblem(name, entry.description) ?? effectProblem ?? moduleProblem(name, entry.module);
39
+ }
40
+ /** One declaration, or why it is refused. Unknown keys are ignored. @complexity O(s) schema size. */
41
+ function parseEntry(entry) {
42
+ if (!isRecord(entry))
43
+ return 'every tool declaration must be an object';
44
+ const problem = fieldProblem(entry) ?? schemaProblem(entry.inputSchema);
45
+ if (problem)
46
+ return problem;
47
+ return Object.freeze({
48
+ name: entry.name, description: entry.description, effect: entry.effect,
49
+ module: entry.module, inputSchema: JSON.parse(JSON.stringify(entry.inputSchema)),
50
+ });
51
+ }
52
+ /** The declaration list from the raw file, or why the file is refused. @complexity O(n) file size. */
53
+ function declarations(raw) {
54
+ let value;
55
+ try {
56
+ value = JSON.parse(raw);
57
+ }
58
+ catch {
59
+ return 'not valid JSON';
60
+ }
61
+ if (!isRecord(value) || value.schemaVersion !== 1)
62
+ return 'schemaVersion must be 1';
63
+ const { tools } = value;
64
+ if (!Array.isArray(tools) || tools.length === 0 || tools.length > MAX_TOOLS)
65
+ return `tools must list 1 to ${MAX_TOOLS} declarations`;
66
+ return tools;
67
+ }
68
+ /**
69
+ * Parses the raw contribution file. A local name declared twice is refused (duplicate id).
70
+ * @param required.raw - The file text as read from a trusted package.
71
+ * @returns Descriptors in declaration order, or the reason the whole file is refused.
72
+ * @complexity O(t^2 + s) for t declarations (t <= 128) and s total schema size.
73
+ */
74
+ export function parseAgentPluginToolsFile(required, _optional = {}) {
75
+ const tools = declarations(required.raw);
76
+ if (typeof tools === 'string')
77
+ return { ok: false, reason: tools };
78
+ const descriptors = [];
79
+ for (const entry of tools) {
80
+ const parsed = parseEntry(entry);
81
+ if (typeof parsed === 'string')
82
+ return { ok: false, reason: parsed };
83
+ if (descriptors.some(existing => existing.name === parsed.name))
84
+ return { ok: false, reason: `tool '${parsed.name}' is declared more than once` };
85
+ descriptors.push(parsed);
86
+ }
87
+ return { ok: true, descriptors };
88
+ }
89
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1,90 @@
1
+ import { type AgentPluginToolCapabilitiesPort, type IssuedTokenMemories } from './capabilities.js';
2
+ import type { LoadedAgentPluginTool } from './definition.js';
3
+ import type { AgentPluginToolEffect } from './manifest.js';
4
+ /** What one call receives from the plugin tool contract. Structural: the host owns that contract. */
5
+ export interface AgentPluginToolInvocation {
6
+ readonly pluginId: string;
7
+ readonly auth: {
8
+ readonly workspaceId: string;
9
+ readonly principalId?: string;
10
+ };
11
+ readonly input: unknown;
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /** One tool in the contract's shape (`PluginToolContribution` in `@jini-ai/plugins/host`). */
15
+ export interface AgentPluginContractTool {
16
+ readonly name: string;
17
+ readonly description: string;
18
+ readonly inputSchema: Readonly<Record<string, unknown>>;
19
+ /** Always set here; optional so the host's own snapshot type (where it is optional) fits the port. */
20
+ readonly effect?: AgentPluginToolEffect;
21
+ handler(required: AgentPluginToolInvocation, optional?: Record<string, never>): unknown;
22
+ }
23
+ /** A host adapter over another admitted contribution, using its existing execution owner. */
24
+ export interface AgentPluginAdditionalTool {
25
+ readonly pluginId: string;
26
+ readonly tool: AgentPluginContractTool;
27
+ readonly describeAffectedResources: (required: {
28
+ readonly input: unknown;
29
+ }) => readonly string[] | Promise<readonly string[]>;
30
+ }
31
+ /** One plugin's generation in the contract's snapshot shape; routes and widgets stay empty. */
32
+ export interface AgentPluginToolSnapshot {
33
+ readonly pluginId: string;
34
+ readonly sdk: object;
35
+ readonly routes: readonly unknown[];
36
+ readonly widgets: readonly unknown[];
37
+ readonly tools: readonly AgentPluginContractTool[];
38
+ }
39
+ /** Host ports: its contribution registry and its tool-id namespacing rule (`pluginToolIdFor`). */
40
+ export interface AgentPluginToolProjectionPorts {
41
+ readonly registry: {
42
+ replace(required: {
43
+ readonly contributions: AgentPluginToolSnapshot;
44
+ }, optional?: Record<string, never>): void;
45
+ detach(required: {
46
+ readonly pluginId: string;
47
+ }, optional?: Record<string, never>): void;
48
+ list(required: Record<string, never>, optional?: Record<string, never>): readonly unknown[];
49
+ };
50
+ readonly toolIdFor: (required: {
51
+ readonly pluginId: string;
52
+ readonly name: string;
53
+ }, optional?: Record<string, never>) => string;
54
+ readonly capabilities: AgentPluginToolCapabilitiesPort;
55
+ /** The host's ONE token memory source, also passed to its admin-surface host (see `createIssuedTokenMemories`). */
56
+ readonly issuedTokens: IssuedTokenMemories;
57
+ }
58
+ /** What the host shows before confirming a call. */
59
+ export interface AgentPluginToolDisclosure {
60
+ readonly effect: AgentPluginToolEffect;
61
+ readonly resources: readonly string[];
62
+ }
63
+ /**
64
+ * Creates the projection for one dedicated contribution registry (keyed by plugin id, so it must not
65
+ * be shared with site plugins whose ids could match). Call `sync` after every load: on boot and on
66
+ * every activation change. A plugin missing from a load is detached: its tools disappear and its
67
+ * calls' capabilities are revoked.
68
+ * @param required.registry - Registry the host attached with `attachPluginContributionTools`.
69
+ * @param required.toolIdFor - The contract's namespacing rule (`pluginToolIdFor`), so ids match the registry's.
70
+ * @param required.capabilities - Host port building one call's capabilities.
71
+ * @param required.issuedTokens - Per-plugin token memory shared with the plugin's admin-surface handlers.
72
+ * @complexity sync is O(t) tools plus schema compilation; disclosure lookup is O(1).
73
+ */
74
+ export declare function createAgentPluginToolProjection(required: AgentPluginToolProjectionPorts, _optional?: Record<string, never>): {
75
+ /** Projects one load result. @returns The loader's refusals plus this seam's own, in order. */
76
+ sync(input: {
77
+ readonly loaded: readonly LoadedAgentPluginTool[];
78
+ readonly refusals: readonly string[];
79
+ readonly additionalTools?: readonly AgentPluginAdditionalTool[];
80
+ }, _options?: Record<string, never>): {
81
+ readonly refusals: readonly string[];
82
+ };
83
+ /** What a call would change, for the confirmation prompt; null for an unknown or withdrawn tool.
84
+ * @throws ToolInputError for input that fails the schema; Error for an invalid hook answer. */
85
+ describeAffectedResources(input: {
86
+ readonly toolId: string;
87
+ readonly input: unknown;
88
+ }, _options?: Record<string, never>): Promise<AgentPluginToolDisclosure | null>;
89
+ };
90
+ //# sourceMappingURL=projection.d.ts.map