@jini-ai/core 0.6.23 → 0.7.1
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 +26 -0
- package/dist/approval.d.ts +34 -3
- package/dist/approval.js +27 -4
- package/dist/batch-tool-inputs.d.ts +13 -0
- package/dist/batch-tool-inputs.js +37 -6
- package/dist/contracts/cards.d.ts +382 -0
- package/dist/contracts/cards.js +2 -0
- package/dist/contracts/content-types.d.ts +32 -0
- package/dist/contracts/content-types.js +3 -0
- package/dist/contracts/credentials.d.ts +402 -0
- package/dist/contracts/credentials.js +2 -0
- package/dist/contracts/hosted-mcp/config.d.ts +253 -0
- package/dist/contracts/hosted-mcp/config.js +2 -0
- package/dist/contracts/hosted-mcp/record.d.ts +198 -0
- package/dist/contracts/hosted-mcp/record.js +2 -0
- package/dist/contracts/hosted-mcp/vocabulary.d.ts +14 -0
- package/dist/contracts/hosted-mcp/vocabulary.js +2 -0
- package/dist/contracts/hosted-mcp.d.ts +5 -0
- package/dist/contracts/hosted-mcp.js +2 -0
- package/dist/contracts/mail/adapter-module.d.ts +31 -0
- package/dist/contracts/mail/adapter-module.js +2 -0
- package/dist/contracts/mail/engine-contracts.d.ts +130 -0
- package/dist/contracts/mail/engine-contracts.js +2 -0
- package/dist/contracts/mail/ports.d.ts +93 -0
- package/dist/contracts/mail/ports.js +3 -0
- package/dist/contracts/mail/provider.d.ts +84 -0
- package/dist/contracts/mail/provider.js +2 -0
- package/dist/contracts/mail.d.ts +128 -0
- package/dist/contracts/mail.js +3 -0
- package/dist/contracts/oauth/details.d.ts +46 -0
- package/dist/contracts/oauth/details.js +2 -0
- package/dist/contracts/oauth/flow.d.ts +253 -0
- package/dist/contracts/oauth/flow.js +2 -0
- package/dist/contracts/oauth.d.ts +139 -0
- package/dist/contracts/oauth.js +2 -0
- package/dist/contracts/server.d.ts +84 -0
- package/dist/contracts/server.js +15 -0
- package/dist/contracts/vault/ports.d.ts +34 -0
- package/dist/contracts/vault/ports.js +2 -0
- package/dist/contracts/vault/records.d.ts +149 -0
- package/dist/contracts/vault/records.js +2 -0
- package/dist/contracts/vault/vendor-credential-sets.d.ts +75 -0
- package/dist/contracts/vault/vendor-credential-sets.js +7 -0
- package/dist/contracts/vault.d.ts +14 -0
- package/dist/contracts/vault.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/primitives/http.d.ts +2 -0
- package/dist/settings/agent-value-write-tools.d.ts +3 -1
- package/dist/settings/agent-value-write-tools.js +11 -4
- package/dist/settings/tool-registrations.js +1 -1
- package/dist/surface-cards.d.ts +2 -0
- package/dist/surface-cards.js +2 -0
- package/dist/text/descriptor-i18n.d.ts +24 -0
- package/dist/text/descriptor-i18n.js +65 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.js +1 -0
- package/dist/tool-metadata-types.d.ts +6 -0
- package/dist/user-facing-error.d.ts +28 -1
- package/dist/user-facing-error.js +87 -4
- package/package.json +50 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## 0.7.1
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- 873f10c: Adds the `@jini-ai/core/contracts/server` subpath: the types-only `Server` route contract on web `Request`/`Response`. It exports `ServerMethod` (including `HEAD` and `OPTIONS`), `ServerHandler` (handlers get `{ request, params, client? }`, where `client.address` is the socket peer), `ServerRoute` (one route as data, so a host can mount a package's route list) and `Server`. It also fixes route precedence: a literal segment beats a `:name` segment at the first position where they differ, and registration order never decides. Not exported from the root barrel.
|
|
6
|
+
|
|
7
|
+
## 0.7.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 41ff2ff: Add host-neutral credential-set contracts to `@jini-ai/core/contracts/credentials`: record, safe
|
|
12
|
+
summary, scope, connection input, token hint, keyring, project half and repository port types,
|
|
13
|
+
with notes on metadata-only reads, private vault context, CAS and trusted ownership. Types only.
|
|
14
|
+
- a266ba8: Add `CredentialedRequestPort` and `SourceControlWritePort` to `@jini-ai/core/contracts/credentials`:
|
|
15
|
+
request/target/verify/probe/error-classification and build/validate/plan/commit ports with exact
|
|
16
|
+
result, plan and failure types, plus agent notes on target-before-decrypt, held DELETE, caller-safe
|
|
17
|
+
egress messages and plan-bound commits on the same provider. Types only.
|
|
18
|
+
- 27063ef: Add the type-only `@jini-ai/core/contracts/hosted-mcp` contract area: the one canonical hosted MCP connection record, repository, save/view/config/target, sealed payload, connect-start and vocabulary unions, plus `McpBearerTokenSupplier`.
|
|
19
|
+
- 6ab1d81: Add the type-only `OAuthFlowOperations` contract and its signature closure (moved from `@jini-ai/oauth`) to `@jini-ai/core/contracts/oauth`.
|
|
20
|
+
- 699b478: Expose six type-only contract areas in core and retain existing type exports. Reconcile card contracts with the complete UI presentation shapes so hosts can wire package objects without cross-package type imports.
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 8fe045b: `@jini-ai/core/text` exports `parseDescriptorI18n` and the `DescriptorI18n` type: the parser for a contribution descriptor's per-locale text map, shared by every contribution kind that carries translated labels.
|
|
25
|
+
- 39cf677: `@jini-ai/core` exports `SurfaceCardsPort` and its card types: a types-only description of the five card builders, so a package that needs a card declares the port and the host passes the builders in.
|
|
26
|
+
|
|
1
27
|
## 0.6.23
|
|
2
28
|
|
|
3
29
|
- Security hardening.
|
package/dist/approval.d.ts
CHANGED
|
@@ -2,13 +2,44 @@ import { type HumanConfirmer } from './registration-kit.js';
|
|
|
2
2
|
import type { ToolExecutionContext, ToolExecutionOptions, ToolHandler, ToolRegistration } from './tool-registry.js';
|
|
3
3
|
/** Maximum human approval wait for one invocation, independent of execution time. */
|
|
4
4
|
export declare const APPROVAL_WAIT_TIMEOUT_MS = 120000;
|
|
5
|
-
/**
|
|
6
|
-
export interface
|
|
5
|
+
/** An exact access change. The host rechecks this revision and authority before applying it. */
|
|
6
|
+
export interface AccessApprovalResource {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
readonly scope: {
|
|
10
|
+
readonly personId: string;
|
|
11
|
+
readonly siteId?: string;
|
|
12
|
+
readonly chatId?: string;
|
|
13
|
+
};
|
|
14
|
+
readonly previous: unknown;
|
|
15
|
+
readonly proposed: unknown;
|
|
16
|
+
readonly revision: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface AccessApprovalDescription {
|
|
19
|
+
readonly resources: readonly AccessApprovalResource[];
|
|
20
|
+
}
|
|
21
|
+
/** A host describes the action; access changes always require a fresh human decision. */
|
|
22
|
+
export type ApprovalPlan<TDescription> = {
|
|
23
|
+
readonly kind?: 'action';
|
|
7
24
|
readonly ask: boolean;
|
|
8
25
|
readonly description: TDescription;
|
|
9
26
|
/** Only reusable escalation grants receive a key. Irreversible actions omit it. */
|
|
10
27
|
readonly rememberKey?: string;
|
|
11
|
-
}
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: 'access';
|
|
30
|
+
readonly ask: true;
|
|
31
|
+
readonly description: TDescription;
|
|
32
|
+
readonly access: AccessApprovalDescription;
|
|
33
|
+
readonly rememberKey?: never;
|
|
34
|
+
};
|
|
35
|
+
/** Detach the fixed disclosure and enforce its resource and UTF-8 JSON bounds before asking.
|
|
36
|
+
* No credentials belong in these values. This function grants no authority.
|
|
37
|
+
* @throws ToolInputError when no resources, over 128 resources or over 128 KiB are proposed.
|
|
38
|
+
* @complexity O(n) disclosure bytes in time and space; no I/O.
|
|
39
|
+
*/
|
|
40
|
+
export declare function snapshotAccessApproval({ access }: {
|
|
41
|
+
access: AccessApprovalDescription;
|
|
42
|
+
}, _options?: {}): AccessApprovalDescription;
|
|
12
43
|
export type ApprovalAnswer = {
|
|
13
44
|
confirmed: true;
|
|
14
45
|
choice?: string;
|
package/dist/approval.js
CHANGED
|
@@ -3,6 +3,21 @@ import { ToolInputError } from './tool-registry.js';
|
|
|
3
3
|
import { isNonArrayRecord } from './records.js';
|
|
4
4
|
/** Maximum human approval wait for one invocation, independent of execution time. */
|
|
5
5
|
export const APPROVAL_WAIT_TIMEOUT_MS = 120_000;
|
|
6
|
+
/** Detach the fixed disclosure and enforce its resource and UTF-8 JSON bounds before asking.
|
|
7
|
+
* No credentials belong in these values. This function grants no authority.
|
|
8
|
+
* @throws ToolInputError when no resources, over 128 resources or over 128 KiB are proposed.
|
|
9
|
+
* @complexity O(n) disclosure bytes in time and space; no I/O.
|
|
10
|
+
*/
|
|
11
|
+
export function snapshotAccessApproval({ access }, _options = {}) {
|
|
12
|
+
if (access.resources.length < 1 || access.resources.length > 128) {
|
|
13
|
+
throw new ToolInputError({ message: 'An access approval must describe between 1 and 128 resources. Request a smaller, explicit change.' });
|
|
14
|
+
}
|
|
15
|
+
const serialized = JSON.stringify(access);
|
|
16
|
+
if (new TextEncoder().encode(serialized).byteLength > 128 * 1024) {
|
|
17
|
+
throw new ToolInputError({ message: 'This access proposal exceeds 128 KiB. Request a smaller, explicit change.' });
|
|
18
|
+
}
|
|
19
|
+
return structuredClone(access);
|
|
20
|
+
}
|
|
6
21
|
/** The decision reducer shared by parked tool calls and the browser's explicit reply transport.
|
|
7
22
|
* An answer never revives an aborted operation. Transport failures propagate without an effect.
|
|
8
23
|
* @param optional.onApprovalStateChange Reports only the human wait, released on every outcome.
|
|
@@ -40,7 +55,7 @@ export function createApprovalHandler(steps, { remembered } = {}) {
|
|
|
40
55
|
const confirmed = () => ({ confirmed: true });
|
|
41
56
|
const abandoned = (prepared) => ({ confirmed: false, result: steps.notConfirmed({ reason: 'abandoned', prepared: prepared.value }) });
|
|
42
57
|
/** A remembered grant applies only when the plan offers a key and the host bound a store. */
|
|
43
|
-
const grantSlot = (plan) => plan.rememberKey !== undefined && remembered ? { store: remembered, key: plan.rememberKey } : undefined;
|
|
58
|
+
const grantSlot = (plan) => plan.kind !== 'access' && plan.rememberKey !== undefined && remembered ? { store: remembered, key: plan.rememberKey } : undefined;
|
|
44
59
|
/** Ask the host transport; record the choice and any reusable grant only on an explicit yes. */
|
|
45
60
|
const askFresh = async ({ prepared, plan }, options = {}) => {
|
|
46
61
|
const { ctx } = prepared;
|
|
@@ -63,14 +78,17 @@ export function createApprovalHandler(steps, { remembered } = {}) {
|
|
|
63
78
|
const value = await steps.prepare({ ctx: snapshot }, options);
|
|
64
79
|
if (snapshot.signal.aborted)
|
|
65
80
|
return { ctx: snapshot, value };
|
|
66
|
-
const
|
|
81
|
+
const description = await steps.describe({ ctx: snapshot, prepared: value }, options);
|
|
82
|
+
const plan = description.kind === 'access'
|
|
83
|
+
? { ...structuredClone(description), access: snapshotAccessApproval({ access: description.access }) }
|
|
84
|
+
: description;
|
|
67
85
|
return { ctx: snapshot, value, plan };
|
|
68
86
|
},
|
|
69
87
|
askHuman: async ({ prepared }, options = {}) => {
|
|
70
88
|
const { ctx, plan } = prepared;
|
|
71
89
|
if (ctx.signal.aborted || !plan)
|
|
72
90
|
return abandoned(prepared);
|
|
73
|
-
if (!plan.ask)
|
|
91
|
+
if (plan.kind !== 'access' && !plan.ask)
|
|
74
92
|
return confirmed();
|
|
75
93
|
const slot = grantSlot(plan);
|
|
76
94
|
if (slot) {
|
|
@@ -142,7 +160,12 @@ export function createBatchApprovalHandler({ steps, combineDescriptions }, { max
|
|
|
142
160
|
plans.push(await steps.describe(entry, options));
|
|
143
161
|
if (!prepared.batch)
|
|
144
162
|
return plans[0];
|
|
145
|
-
|
|
163
|
+
const description = combineDescriptions({ descriptions: plans.map(plan => plan.description) });
|
|
164
|
+
const accessPlans = plans.filter(plan => plan.kind === 'access');
|
|
165
|
+
if (accessPlans.length > 0)
|
|
166
|
+
return { kind: 'access', ask: true, description,
|
|
167
|
+
access: { resources: accessPlans.flatMap(plan => plan.access.resources) } };
|
|
168
|
+
return { ask: plans.some(plan => plan.ask), description };
|
|
146
169
|
},
|
|
147
170
|
askHuman: steps.askHuman,
|
|
148
171
|
run: async ({ prepared, confirmer, choice }, options) => {
|
|
@@ -44,6 +44,13 @@ export type BatchItemResult = {
|
|
|
44
44
|
readonly error: string;
|
|
45
45
|
readonly result?: unknown;
|
|
46
46
|
};
|
|
47
|
+
interface BatchPreviewImage {
|
|
48
|
+
readonly type: 'image';
|
|
49
|
+
readonly mimeType: string;
|
|
50
|
+
readonly data: string;
|
|
51
|
+
readonly title?: string;
|
|
52
|
+
readonly href?: string;
|
|
53
|
+
}
|
|
47
54
|
/** What a batch call returns. A failed item never stops the ones after it. */
|
|
48
55
|
export interface BatchResult {
|
|
49
56
|
readonly batch: true;
|
|
@@ -53,6 +60,11 @@ export interface BatchResult {
|
|
|
53
60
|
readonly succeeded: number;
|
|
54
61
|
readonly failed: number;
|
|
55
62
|
readonly results: readonly BatchItemResult[];
|
|
63
|
+
/** Bounded previews outside item JSON, with a text summary for MCP consumers. */
|
|
64
|
+
readonly content?: readonly ({
|
|
65
|
+
readonly type: 'text';
|
|
66
|
+
readonly text: string;
|
|
67
|
+
} | BatchPreviewImage)[];
|
|
56
68
|
}
|
|
57
69
|
/** Classify a batch result, including legacy envelopes, without dropping per-item evidence.
|
|
58
70
|
* @returns Undefined for non-batches; error when every item failed, partial_failure for a mix.
|
|
@@ -155,4 +167,5 @@ export declare function defaultBatchableTools({ registrations }: {
|
|
|
155
167
|
optOut?: readonly BatchOptOut[];
|
|
156
168
|
settings?: readonly BatchableTool[];
|
|
157
169
|
}): BatchableTool[];
|
|
170
|
+
export {};
|
|
158
171
|
//# sourceMappingURL=batch-tool-inputs.d.ts.map
|
|
@@ -165,14 +165,40 @@ function schemaTypeLabel(property) {
|
|
|
165
165
|
return typeof type === 'string' ? type : 'unknown';
|
|
166
166
|
}
|
|
167
167
|
/** A batch result is one JSON value, so an item's MCP `image` block would reach the model and the
|
|
168
|
-
* chat as base64 text (a 20-item import batch, 20 previews).
|
|
169
|
-
*
|
|
168
|
+
* chat as base64 text (a 20-item import batch, 20 previews). Keep images outside item JSON; a
|
|
169
|
+
* bounded top-level envelope carries previews, while each item's text retains its saved result. */
|
|
170
170
|
function withoutItemImages(output) {
|
|
171
171
|
if (!isPlainObject(output) || !Array.isArray(output.content))
|
|
172
172
|
return output;
|
|
173
173
|
const content = output.content.filter((block) => !isPlainObject(block) || block.type !== 'image');
|
|
174
174
|
return content.length === output.content.length ? output : { ...output, content };
|
|
175
175
|
}
|
|
176
|
+
/** Collect at most four previews and two million serialized image characters per batch. Saved-media
|
|
177
|
+
* text stays in every item even when a preview exceeds this delivery budget.
|
|
178
|
+
* @complexity O(b) content blocks per item, O(1) retained preview count and bounded byte space. */
|
|
179
|
+
function collectBatchImages({ output, images }) {
|
|
180
|
+
if (!isPlainObject(output) || !Array.isArray(output.content) || images.length >= 4)
|
|
181
|
+
return;
|
|
182
|
+
let bytes = images.reduce((sum, image) => sum + JSON.stringify(image).length, 0);
|
|
183
|
+
for (const block of output.content) {
|
|
184
|
+
const image = batchPreviewImage(block);
|
|
185
|
+
const imageBytes = image ? JSON.stringify(image).length : 0;
|
|
186
|
+
if (!image || bytes + imageBytes > 2_000_000)
|
|
187
|
+
continue;
|
|
188
|
+
images.push(image);
|
|
189
|
+
bytes += imageBytes;
|
|
190
|
+
if (images.length >= 4)
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Retain only the existing image-delivery fields, never arbitrary nested plugin properties. */
|
|
195
|
+
function batchPreviewImage(block) {
|
|
196
|
+
if (!isPlainObject(block) || block.type !== 'image' || typeof block.mimeType !== 'string' || typeof block.data !== 'string')
|
|
197
|
+
return undefined;
|
|
198
|
+
return { type: 'image', mimeType: block.mimeType, data: block.data,
|
|
199
|
+
...(typeof block.title === 'string' ? { title: block.title } : {}),
|
|
200
|
+
...(typeof block.href === 'string' ? { href: block.href } : {}) };
|
|
201
|
+
}
|
|
176
202
|
/** Classify one returned output without dropping error payloads or normalization notes.
|
|
177
203
|
* @complexity O(n) for a nested batch's n results, plus formatting its notes; no effects.
|
|
178
204
|
*/
|
|
@@ -186,10 +212,11 @@ function batchItemResult({ index, output, notes }, _options = {}) {
|
|
|
186
212
|
/** Summarize all item outcomes, retaining their order and evidence.
|
|
187
213
|
* @complexity O(n) time and space for n results; no effects.
|
|
188
214
|
*/
|
|
189
|
-
function summarizeBatchResults({ results }, _options = {}) {
|
|
215
|
+
function summarizeBatchResults({ results, images }, _options = {}) {
|
|
190
216
|
const succeeded = results.filter((result) => result.ok).length;
|
|
191
217
|
const outcome = outcomeFor({ failed: results.length - succeeded, total: results.length });
|
|
192
|
-
|
|
218
|
+
const summary = { batch: true, outcome, ...(succeeded === 0 ? { isError: true } : {}), total: results.length, succeeded, failed: results.length - succeeded, results };
|
|
219
|
+
return images.length ? { ...summary, content: [{ type: 'text', text: JSON.stringify(summary) }, ...images] } : summary;
|
|
193
220
|
}
|
|
194
221
|
/**
|
|
195
222
|
* Wraps one registration so it also accepts `items`. Single calls retain their handler.
|
|
@@ -241,6 +268,7 @@ export function withBatchInput({ registration, tool }, { mode = tool.mode ?? 'it
|
|
|
241
268
|
const { items: rawItems, ...shared } = ctx.input;
|
|
242
269
|
const items = readItems({ items: rawItems, toolId, maxItems });
|
|
243
270
|
const results = [];
|
|
271
|
+
const images = [];
|
|
244
272
|
for (const [index, item] of items.entries()) {
|
|
245
273
|
ctx.signal.throwIfAborted();
|
|
246
274
|
let notes = [];
|
|
@@ -251,13 +279,16 @@ export function withBatchInput({ registration, tool }, { mode = tool.mode ?? 'it
|
|
|
251
279
|
if (!options?.invokeTool)
|
|
252
280
|
throw new Error(`${toolId}: batch items require the gated ToolExecutor invocation port`);
|
|
253
281
|
const output = await options.invokeTool({ toolId, input: normalized.input }, { registry: itemRegistry });
|
|
254
|
-
|
|
282
|
+
const result = batchItemResult({ index, output: withoutItemImages(output), notes: normalized.notes });
|
|
283
|
+
results.push(result);
|
|
284
|
+
if (result.ok)
|
|
285
|
+
collectBatchImages({ output, images });
|
|
255
286
|
}
|
|
256
287
|
catch (error) {
|
|
257
288
|
results.push({ index, ok: false, error: withNormalizationNotes({ output: itemErrorMessage({ error, toolId }), notes }) });
|
|
258
289
|
}
|
|
259
290
|
}
|
|
260
|
-
return summarizeBatchResults({ results });
|
|
291
|
+
return summarizeBatchResults({ results, images });
|
|
261
292
|
};
|
|
262
293
|
return { ...registration, descriptor, handler,
|
|
263
294
|
// Domain normalization belongs to each merged item, not the incomplete shared layer.
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/** @agent-note Types only. The runtime parts come from the host; this area usually from `@jini-ai/ui`. */
|
|
2
|
+
/**
|
|
3
|
+
* The card builders a tool needs to ask a human for input, described as types only.
|
|
4
|
+
*
|
|
5
|
+
* The builders themselves render HTML and stay in the UI package; a domain package that needs a
|
|
6
|
+
* card cannot import that package, so it declares this port and the host passes the builders in.
|
|
7
|
+
* The resource a builder returns is a type parameter: callers hand it back unread, never inspect it.
|
|
8
|
+
*/
|
|
9
|
+
import type { SurfaceAskThenReport, SurfaceExchangeStore } from '../surface-exchanges.js';
|
|
10
|
+
import type { ToolExecutionContext, ToolExecutionOptions } from '../tool-registry.js';
|
|
11
|
+
export type SurfaceCardUri = `ui://${string}`;
|
|
12
|
+
export type SurfaceCardApp = BridgeScriptSpec;
|
|
13
|
+
export type SurfaceCardDetail = SurfaceDetail;
|
|
14
|
+
export type SurfaceCardChoice = SelectOption;
|
|
15
|
+
export type SurfaceCardStringField = StringField;
|
|
16
|
+
export type SurfaceCardEnumField = EnumField;
|
|
17
|
+
export type SurfaceCardMultiEnumField = MultiEnumField;
|
|
18
|
+
export type SurfaceCardField = SurfaceField;
|
|
19
|
+
/** A secret field never carries a value. `allowBlank` keeps a stored value or permits a public client. */
|
|
20
|
+
export type SurfaceCardSecretField = SecretCardField;
|
|
21
|
+
export type SurfaceCardSecretForm = SecretCardForm;
|
|
22
|
+
export interface SurfaceCardFormSpec extends FormSurfaceSpec {
|
|
23
|
+
readonly uri: SurfaceCardUri;
|
|
24
|
+
}
|
|
25
|
+
export type SurfaceCardOutcome = SurfaceOutcomeSpec;
|
|
26
|
+
export type SurfaceCardSecretRun<Saved> = {
|
|
27
|
+
readonly status: 'saved';
|
|
28
|
+
readonly saved: Saved;
|
|
29
|
+
} | {
|
|
30
|
+
readonly status: 'cancelled';
|
|
31
|
+
} | {
|
|
32
|
+
readonly status: 'expired';
|
|
33
|
+
} | {
|
|
34
|
+
readonly status: 'abandoned';
|
|
35
|
+
} | {
|
|
36
|
+
readonly status: 'blank';
|
|
37
|
+
} | {
|
|
38
|
+
readonly status: 'failed';
|
|
39
|
+
readonly safeMessage: string;
|
|
40
|
+
};
|
|
41
|
+
/** Authorization and target resolution happen in `prepare`, persistence in `save`.
|
|
42
|
+
* @agent-note `save` receives the exact submitted bytes and must keep them in the host's sealed
|
|
43
|
+
* store; it returns only a safe summary. `outcome` and `result` never see submitted values. */
|
|
44
|
+
export interface SurfaceCardSecretSpec<Prep, Saved, Result> {
|
|
45
|
+
readonly toolId: string;
|
|
46
|
+
prepare(required: {
|
|
47
|
+
ctx: ToolExecutionContext;
|
|
48
|
+
}): Promise<Prep>;
|
|
49
|
+
form(required: {
|
|
50
|
+
prep: Prep;
|
|
51
|
+
}): SurfaceCardSecretForm;
|
|
52
|
+
save(required: {
|
|
53
|
+
values: Readonly<Record<string, unknown>>;
|
|
54
|
+
prep: Prep;
|
|
55
|
+
signal: AbortSignal;
|
|
56
|
+
}): Promise<Saved>;
|
|
57
|
+
outcome(required: {
|
|
58
|
+
prep: Prep;
|
|
59
|
+
run: SurfaceCardSecretRun<Saved>;
|
|
60
|
+
}): SurfaceCardOutcome | undefined;
|
|
61
|
+
result(required: {
|
|
62
|
+
prep: Prep;
|
|
63
|
+
run: SurfaceCardSecretRun<Saved>;
|
|
64
|
+
}): Result;
|
|
65
|
+
}
|
|
66
|
+
export interface SurfaceCardSecretOptions {
|
|
67
|
+
readonly safeError?: (error: unknown) => string | undefined;
|
|
68
|
+
readonly text?: {
|
|
69
|
+
readonly noEmitter?: string;
|
|
70
|
+
readonly saveFailure?: string;
|
|
71
|
+
readonly cancelLabel?: string;
|
|
72
|
+
};
|
|
73
|
+
readonly frameSize?: readonly [string, string];
|
|
74
|
+
readonly uriHost?: string;
|
|
75
|
+
readonly logFailure?: (metadata: {
|
|
76
|
+
toolId: string;
|
|
77
|
+
exchangeId: string;
|
|
78
|
+
saved: false;
|
|
79
|
+
}) => void;
|
|
80
|
+
}
|
|
81
|
+
/** @agent-note Both members come from the daemon the tool runs in: `surfaceExchanges` is the same
|
|
82
|
+
* store instance the host's answer route delivers into (a second store never receives the answer),
|
|
83
|
+
* and `askThenReport` is the daemon's helper from its surface-exchanges entry. */
|
|
84
|
+
export interface SurfaceCardSecretDeps {
|
|
85
|
+
readonly surfaceExchanges: Pick<SurfaceExchangeStore, 'open'>;
|
|
86
|
+
readonly askThenReport: SurfaceAskThenReport;
|
|
87
|
+
}
|
|
88
|
+
export interface SurfaceCardSecretTool<Prep, Result> {
|
|
89
|
+
readonly toolId: string;
|
|
90
|
+
secretFieldNames(prep: Prep): string[];
|
|
91
|
+
handler(deps: SurfaceCardSecretDeps): (required: ToolExecutionContext, optional?: ToolExecutionOptions) => Promise<Result>;
|
|
92
|
+
}
|
|
93
|
+
export type SurfaceCardSignInState = {
|
|
94
|
+
state: 'waiting';
|
|
95
|
+
signInUrl: string;
|
|
96
|
+
exchangeId?: string;
|
|
97
|
+
} | {
|
|
98
|
+
state: 'connected' | 'skipped';
|
|
99
|
+
};
|
|
100
|
+
export interface SurfaceCardSignInSpec {
|
|
101
|
+
uri: SurfaceCardUri;
|
|
102
|
+
toolId: string;
|
|
103
|
+
app: SurfaceCardApp;
|
|
104
|
+
waiting: {
|
|
105
|
+
title: string;
|
|
106
|
+
description: string;
|
|
107
|
+
message: string;
|
|
108
|
+
openLinkLabel: string;
|
|
109
|
+
cancelLabel: string;
|
|
110
|
+
};
|
|
111
|
+
connected: {
|
|
112
|
+
title: string;
|
|
113
|
+
message: string;
|
|
114
|
+
};
|
|
115
|
+
skipped: {
|
|
116
|
+
title: string;
|
|
117
|
+
message: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** @agent-note `card` must render every state under one URI: the last emission replaces the
|
|
121
|
+
* waiting card. `connect` must honor its `signal`; Skip aborts only this wait, never the run. */
|
|
122
|
+
export interface SurfaceCardSignInWait<Resource, Result> {
|
|
123
|
+
surfaceExchanges: Pick<SurfaceExchangeStore, 'open'>;
|
|
124
|
+
ctx: ToolExecutionContext;
|
|
125
|
+
toolId: string;
|
|
126
|
+
card: (state: SurfaceCardSignInState) => Resource;
|
|
127
|
+
missingEmitterMessage: string;
|
|
128
|
+
skippedResult: () => Result;
|
|
129
|
+
connect: (input: {
|
|
130
|
+
signal: AbortSignal;
|
|
131
|
+
showSignIn: (input: {
|
|
132
|
+
signInUrl: string;
|
|
133
|
+
}) => Promise<void>;
|
|
134
|
+
}) => Promise<Result>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The five card builders, with the signatures the UI package exports.
|
|
138
|
+
* @agent-note Fulfilled by `mcpUiCards` from `@jini-ai/ui/mcp-ui/cards`, which the UI package pins
|
|
139
|
+
* with `satisfies SurfaceCardsPort<UIResource>`; the host passes it in one line. A consumer that
|
|
140
|
+
* calls `waitAtSignInCard` is generic in `Resource` (the type flows back through `card`); one that
|
|
141
|
+
* only builds may take `Omit<SurfaceCardsPort, 'waitAtSignInCard'>`. Never key a form `uri` by a
|
|
142
|
+
* confirmation token.
|
|
143
|
+
*/
|
|
144
|
+
export interface SurfaceCardsPort<Resource = unknown> {
|
|
145
|
+
readonly defineSecretCardTool: <Prep, Saved, Result>(required: SurfaceCardSecretSpec<Prep, Saved, Result>, options?: SurfaceCardSecretOptions) => SurfaceCardSecretTool<Prep, Result>;
|
|
146
|
+
readonly buildSignInCard: (required: SurfaceCardSignInSpec & SurfaceCardSignInState, optional?: Record<string, never>) => Resource;
|
|
147
|
+
readonly waitAtSignInCard: <Result extends {
|
|
148
|
+
status: string;
|
|
149
|
+
}>(required: SurfaceCardSignInWait<Resource, Result>, optional?: ToolExecutionOptions) => Promise<Result>;
|
|
150
|
+
readonly buildFormSurface: (spec: SurfaceCardFormSpec) => Resource;
|
|
151
|
+
readonly buildOutcomeSurface: (spec: SurfaceCardOutcome & {
|
|
152
|
+
readonly uri: SurfaceCardUri;
|
|
153
|
+
}) => Resource;
|
|
154
|
+
}
|
|
155
|
+
/** One fact. Values and previous snapshots must be JSON-serializable; strings remain supported. */
|
|
156
|
+
export interface SurfaceDetail {
|
|
157
|
+
readonly label: string;
|
|
158
|
+
readonly value: unknown;
|
|
159
|
+
/** Presence enables a diff, including an explicitly absent previous override. */
|
|
160
|
+
readonly previous?: unknown;
|
|
161
|
+
/** Explicit, optionally translated labels keyed by dotted object path. */
|
|
162
|
+
readonly labels?: Readonly<Record<string, string>>;
|
|
163
|
+
/** Optional secondary context beneath the label, using the shared muted hint style. */
|
|
164
|
+
readonly description?: string;
|
|
165
|
+
/**
|
|
166
|
+
* `code` discloses a monospace `<pre>` that keeps line breaks and scrolls inside its own box
|
|
167
|
+
* past a fixed height, so long SQL or JSON remains readable without stretching the dialog past
|
|
168
|
+
* its frame. `status` reserves one line for a short outcome value. Omitted (or `text`) permits
|
|
169
|
+
* value-sensitive presentation, preserving plain inline strings for short prose.
|
|
170
|
+
*/
|
|
171
|
+
readonly format?: 'text' | 'code' | 'status';
|
|
172
|
+
}
|
|
173
|
+
interface SurfaceFieldBase {
|
|
174
|
+
/** HTML `name`, DOM `id` suffix, and the params key the value is posted under. */
|
|
175
|
+
readonly name: string;
|
|
176
|
+
readonly label: string;
|
|
177
|
+
/** Help text, wired up with `aria-describedby`. */
|
|
178
|
+
readonly hint?: string;
|
|
179
|
+
readonly required?: boolean;
|
|
180
|
+
/** Waive on an exact choice or an alternative control; headerNames restricts entered headers. Kept secrets are validated by the host. */
|
|
181
|
+
readonly requiredUnless?: {
|
|
182
|
+
readonly field: string;
|
|
183
|
+
readonly equals: string;
|
|
184
|
+
readonly orPresent?: string;
|
|
185
|
+
readonly headerNames?: readonly string[];
|
|
186
|
+
};
|
|
187
|
+
/** Require only while the controlling public field matches one of these choices. */
|
|
188
|
+
readonly requiredWhen?: {
|
|
189
|
+
readonly field: string;
|
|
190
|
+
readonly in: readonly string[];
|
|
191
|
+
};
|
|
192
|
+
readonly disabled?: boolean;
|
|
193
|
+
}
|
|
194
|
+
export interface StringField extends SurfaceFieldBase {
|
|
195
|
+
readonly kind: 'string';
|
|
196
|
+
/** A sealed saved value satisfies validation while the requirement remains visible. */
|
|
197
|
+
readonly hasSavedValue?: boolean;
|
|
198
|
+
readonly value?: string;
|
|
199
|
+
readonly placeholder?: string;
|
|
200
|
+
readonly multiline?: boolean;
|
|
201
|
+
readonly rows?: number;
|
|
202
|
+
/** Renders as a masked input or multiline textarea; pre-filled values are forbidden.
|
|
203
|
+
* See {@link TextInputProps.secret}. */
|
|
204
|
+
readonly secret?: boolean;
|
|
205
|
+
}
|
|
206
|
+
export interface NumberField extends SurfaceFieldBase {
|
|
207
|
+
readonly kind: 'number';
|
|
208
|
+
readonly value?: number;
|
|
209
|
+
readonly placeholder?: string;
|
|
210
|
+
readonly min?: number;
|
|
211
|
+
readonly max?: number;
|
|
212
|
+
readonly step?: number;
|
|
213
|
+
}
|
|
214
|
+
export interface BooleanField extends SurfaceFieldBase {
|
|
215
|
+
readonly kind: 'boolean';
|
|
216
|
+
readonly value?: boolean;
|
|
217
|
+
}
|
|
218
|
+
export interface EnumField extends SurfaceFieldBase {
|
|
219
|
+
readonly kind: 'enum';
|
|
220
|
+
readonly value?: string;
|
|
221
|
+
readonly options: readonly SelectOption[];
|
|
222
|
+
readonly placeholder?: string;
|
|
223
|
+
/**
|
|
224
|
+
* How the same one-of-N value is drawn. `select` (the default) hides the options until opened —
|
|
225
|
+
* right for a long list; `radio` shows them all at once — right for a short one the human is
|
|
226
|
+
* meant to compare before choosing. Presentation only: both post one string under `name`, and
|
|
227
|
+
* both read back through the same `control.value` path, so `kind` stays `'enum'` either way.
|
|
228
|
+
*/
|
|
229
|
+
readonly presentation?: 'select' | 'radio';
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* A pick-any-number-of-N field.
|
|
233
|
+
*
|
|
234
|
+
* Its own kind rather than a flag on {@link EnumField}, because it is the only field whose value is
|
|
235
|
+
* an **array** — `form.ts`'s `readField` and `isBlank` both branch on that, and no `presentation`
|
|
236
|
+
* discriminator would have told them to.
|
|
237
|
+
*/
|
|
238
|
+
export interface MultiEnumField extends SurfaceFieldBase {
|
|
239
|
+
readonly kind: 'multi-enum';
|
|
240
|
+
/** Pre-checked values. Unknown entries check nothing rather than erroring. */
|
|
241
|
+
readonly value?: readonly string[];
|
|
242
|
+
readonly options: readonly SelectOption[];
|
|
243
|
+
}
|
|
244
|
+
export type SurfaceField = StringField | NumberField | BooleanField | EnumField | MultiEnumField;
|
|
245
|
+
export interface FormSurfaceSpec {
|
|
246
|
+
readonly title: string;
|
|
247
|
+
/** Resource framing carried through host form projections; ignored by HTML rendering. */
|
|
248
|
+
readonly preferredFrameSize?: readonly [string, string];
|
|
249
|
+
readonly description?: string;
|
|
250
|
+
/** Read-only context shown above the fields — what the input is *about*. */
|
|
251
|
+
readonly details?: readonly SurfaceDetail[];
|
|
252
|
+
readonly fields: readonly SurfaceField[];
|
|
253
|
+
/** Callout above the buttons. */
|
|
254
|
+
readonly warning?: string;
|
|
255
|
+
/** Styles the submit button as destructive. */
|
|
256
|
+
readonly danger?: boolean;
|
|
257
|
+
readonly submitLabel: string;
|
|
258
|
+
/** Alternative submit buttons collect the same fields, with explicit action params. */
|
|
259
|
+
readonly additionalSubmitActions?: readonly {
|
|
260
|
+
readonly id: string;
|
|
261
|
+
readonly label: string;
|
|
262
|
+
readonly params: Readonly<Record<string, unknown>>;
|
|
263
|
+
}[];
|
|
264
|
+
/** The tool the collected values are sent to. */
|
|
265
|
+
readonly toolName: string;
|
|
266
|
+
/**
|
|
267
|
+
* Merged UNDER the collected field values, so a field can never be shadowed by a base param it
|
|
268
|
+
* shares a name with. Where a confirmation token belongs when the form is a confirmation.
|
|
269
|
+
*/
|
|
270
|
+
readonly baseParams?: Readonly<Record<string, unknown>>;
|
|
271
|
+
/** Omit for a form with no cancel button. Give it a tool name to notify the server of the dismissal. */
|
|
272
|
+
readonly cancel?: {
|
|
273
|
+
readonly label: string;
|
|
274
|
+
readonly toolName?: string;
|
|
275
|
+
readonly params?: Readonly<Record<string, unknown>>;
|
|
276
|
+
};
|
|
277
|
+
readonly text?: Partial<SurfaceStatusText & SecretInputText>;
|
|
278
|
+
readonly app?: BridgeScriptSpec;
|
|
279
|
+
readonly lang?: string;
|
|
280
|
+
readonly tokens?: Partial<Record<SurfaceTokenName, string>>;
|
|
281
|
+
}
|
|
282
|
+
export interface SurfaceOutcomeSpec {
|
|
283
|
+
readonly title: string;
|
|
284
|
+
/** Resource framing carried through host outcome projections; ignored by HTML rendering. */
|
|
285
|
+
readonly preferredFrameSize?: readonly [string, string];
|
|
286
|
+
readonly description?: string;
|
|
287
|
+
/** The facts of what actually happened — same shape as a confirmation's own `details`, but
|
|
288
|
+
* reporting the RESULT (e.g. the real URL, the real status) rather than what was proposed. */
|
|
289
|
+
readonly details?: readonly SurfaceDetail[];
|
|
290
|
+
/**
|
|
291
|
+
* Styles the status line and, when {@link openLinkUrl} is also present, the open-link button.
|
|
292
|
+
* THREE states, not a boolean — matching this package's own callers, which distinguish a genuine
|
|
293
|
+
* partial outcome (e.g. a downstream product's static-publish "uploaded, but not yet confirmed reachable") from
|
|
294
|
+
* both a plain success and a plain failure specifically so neither is misreported: folding
|
|
295
|
+
* `'partial'` into `'success'` would claim something is live when it may not be reachable yet;
|
|
296
|
+
* folding it into `'failure'` would hide that the operation itself did NOT fail (nothing needs
|
|
297
|
+
* retrying, only a separate follow-up step). See `document.ts`'s own `[data-state="partial"]` rule
|
|
298
|
+
* for why this needs a third visual state as well as a third value here, not merely a third string
|
|
299
|
+
* that renders identically to one of the other two.
|
|
300
|
+
*/
|
|
301
|
+
readonly state: 'success' | 'partial' | 'failure';
|
|
302
|
+
/** The one human-facing sentence explaining the outcome — the actionable message on failure, or a
|
|
303
|
+
* short confirmation on success. Never a raw credential or provider response body; that boundary
|
|
304
|
+
* is the CALLER's responsibility (this builder only renders what it is given). */
|
|
305
|
+
readonly message: string;
|
|
306
|
+
/** When present, renders one button ("Open site" by default) that calls the bridge's `openLink`.
|
|
307
|
+
* Only meaningful alongside `state: 'success'` — a caller should not supply this for a failure. */
|
|
308
|
+
readonly openLinkUrl?: string;
|
|
309
|
+
readonly openLinkLabel?: string;
|
|
310
|
+
/** A pending external action may be skipped through its existing surface exchange. */
|
|
311
|
+
readonly cancel?: ConfirmationToolAction;
|
|
312
|
+
/** Identity reported to the Host in `ui/initialize`. Defaults to a generic one. */
|
|
313
|
+
readonly app?: BridgeScriptSpec;
|
|
314
|
+
readonly lang?: string;
|
|
315
|
+
readonly tokens?: Partial<Record<SurfaceTokenName, string>>;
|
|
316
|
+
}
|
|
317
|
+
export interface SelectOption {
|
|
318
|
+
/** The value posted back. */
|
|
319
|
+
readonly value: string;
|
|
320
|
+
/** What the human reads. Defaults to `value`. */
|
|
321
|
+
readonly label?: string;
|
|
322
|
+
readonly disabled?: boolean;
|
|
323
|
+
}
|
|
324
|
+
export interface BridgeScriptSpec {
|
|
325
|
+
/** Reported to the Host as `appInfo.name` in `ui/initialize`. */
|
|
326
|
+
readonly appName: string;
|
|
327
|
+
/** Reported to the Host as `appInfo.version`. */
|
|
328
|
+
readonly appVersion: string;
|
|
329
|
+
/** Defaults to {@link MCP_UI_PROTOCOL_VERSION}. */
|
|
330
|
+
readonly protocolVersion?: string;
|
|
331
|
+
}
|
|
332
|
+
/** Verbs the host can translate for a secret's reveal toggle; the field label is appended. */
|
|
333
|
+
export interface SecretInputText {
|
|
334
|
+
readonly showSecret: string;
|
|
335
|
+
readonly hideSecret: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Every user-visible string a surface's script writes at runtime.
|
|
339
|
+
*
|
|
340
|
+
* Surfaces are HTML strings built outside React, so `features/i18n`'s `useT` cannot reach them — a
|
|
341
|
+
* translated surface is one whose builder was handed translated text. These are the defaults for a
|
|
342
|
+
* caller that has none.
|
|
343
|
+
*/
|
|
344
|
+
export interface SurfaceStatusText {
|
|
345
|
+
/** Shown while a tool call is in flight. */
|
|
346
|
+
readonly working: string;
|
|
347
|
+
/** Shown when the call resolves. */
|
|
348
|
+
readonly done: string;
|
|
349
|
+
/** Prefixed to the Host's own error message when the call rejects. */
|
|
350
|
+
readonly failedPrefix: string;
|
|
351
|
+
/** Shown when the human dismisses a surface that has no cancel tool to call. */
|
|
352
|
+
readonly dismissed: string;
|
|
353
|
+
/** Prefixed to the comma-joined labels of unfilled required fields. */
|
|
354
|
+
readonly missingPrefix: string;
|
|
355
|
+
/** Shown when the Host says the dialog is no longer pending; the buttons stay disabled. */
|
|
356
|
+
readonly expired: string;
|
|
357
|
+
}
|
|
358
|
+
/** A button that calls a tool when clicked. */
|
|
359
|
+
export interface ConfirmationToolAction {
|
|
360
|
+
readonly label: string;
|
|
361
|
+
readonly toolName: string;
|
|
362
|
+
/** Passed verbatim as the tool's `arguments`. The only safe home for a confirmation token. */
|
|
363
|
+
readonly params: Readonly<Record<string, unknown>>;
|
|
364
|
+
}
|
|
365
|
+
/** The token names a caller may override. */
|
|
366
|
+
export type SurfaceTokenName = "--jini-mcpui-bg" | "--jini-mcpui-panel" | "--jini-mcpui-border" | "--jini-mcpui-border-strong" | "--jini-mcpui-text" | "--jini-mcpui-text-strong" | "--jini-mcpui-text-muted" | "--jini-mcpui-text-soft" | "--jini-mcpui-text-faint" | "--jini-mcpui-accent" | "--jini-mcpui-accent-strong" | "--jini-mcpui-accent-ink" | "--jini-mcpui-danger" | "--jini-mcpui-radius-xs" | "--jini-mcpui-radius-sm" | "--jini-mcpui-radius-md" | "--jini-mcpui-radius-lg" | "--jini-mcpui-radius-xl" | "--jini-mcpui-radius-pill" | "--jini-mcpui-font" | "--jini-mcpui-font-mono";
|
|
367
|
+
/** Secret fields cannot carry a value, even through a previously declared variable.
|
|
368
|
+
* `allowBlank` permits an empty string for stored-value preservation or public-client auth. */
|
|
369
|
+
export type SecretCardField = (SurfaceField & {
|
|
370
|
+
readonly secret?: false;
|
|
371
|
+
}) | (Omit<StringField, 'value' | 'secret'> & {
|
|
372
|
+
readonly secret: true;
|
|
373
|
+
readonly value?: never;
|
|
374
|
+
readonly allowBlank?: boolean;
|
|
375
|
+
});
|
|
376
|
+
/** The host controls copy, field construction and display; routing/dismissal belong to the engine. */
|
|
377
|
+
export type SecretCardForm = Omit<FormSurfaceSpec, 'fields' | 'toolName' | 'baseParams' | 'cancel'> & {
|
|
378
|
+
readonly fields: readonly SecretCardField[];
|
|
379
|
+
readonly cancelLabel?: string;
|
|
380
|
+
};
|
|
381
|
+
export {};
|
|
382
|
+
//# sourceMappingURL=cards.d.ts.map
|