@jini-ai/core 0.6.22 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/approval.d.ts +49 -3
  3. package/dist/approval.js +47 -10
  4. package/dist/batch-tool-inputs.d.ts +13 -0
  5. package/dist/batch-tool-inputs.js +37 -6
  6. package/dist/contracts/cards.d.ts +382 -0
  7. package/dist/contracts/cards.js +2 -0
  8. package/dist/contracts/content-types.d.ts +32 -0
  9. package/dist/contracts/content-types.js +3 -0
  10. package/dist/contracts/credentials.d.ts +402 -0
  11. package/dist/contracts/credentials.js +2 -0
  12. package/dist/contracts/hosted-mcp/config.d.ts +253 -0
  13. package/dist/contracts/hosted-mcp/config.js +2 -0
  14. package/dist/contracts/hosted-mcp/record.d.ts +198 -0
  15. package/dist/contracts/hosted-mcp/record.js +2 -0
  16. package/dist/contracts/hosted-mcp/vocabulary.d.ts +14 -0
  17. package/dist/contracts/hosted-mcp/vocabulary.js +2 -0
  18. package/dist/contracts/hosted-mcp.d.ts +5 -0
  19. package/dist/contracts/hosted-mcp.js +2 -0
  20. package/dist/contracts/mail/adapter-module.d.ts +31 -0
  21. package/dist/contracts/mail/adapter-module.js +2 -0
  22. package/dist/contracts/mail/engine-contracts.d.ts +130 -0
  23. package/dist/contracts/mail/engine-contracts.js +2 -0
  24. package/dist/contracts/mail/ports.d.ts +93 -0
  25. package/dist/contracts/mail/ports.js +3 -0
  26. package/dist/contracts/mail/provider.d.ts +84 -0
  27. package/dist/contracts/mail/provider.js +2 -0
  28. package/dist/contracts/mail.d.ts +128 -0
  29. package/dist/contracts/mail.js +3 -0
  30. package/dist/contracts/oauth/details.d.ts +46 -0
  31. package/dist/contracts/oauth/details.js +2 -0
  32. package/dist/contracts/oauth/flow.d.ts +253 -0
  33. package/dist/contracts/oauth/flow.js +2 -0
  34. package/dist/contracts/oauth.d.ts +139 -0
  35. package/dist/contracts/oauth.js +2 -0
  36. package/dist/contracts/vault/ports.d.ts +34 -0
  37. package/dist/contracts/vault/ports.js +2 -0
  38. package/dist/contracts/vault/records.d.ts +149 -0
  39. package/dist/contracts/vault/records.js +2 -0
  40. package/dist/contracts/vault/vendor-credential-sets.d.ts +75 -0
  41. package/dist/contracts/vault/vendor-credential-sets.js +7 -0
  42. package/dist/contracts/vault.d.ts +14 -0
  43. package/dist/contracts/vault.js +2 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +1 -0
  46. package/dist/primitives/http.d.ts +2 -0
  47. package/dist/settings/agent-value-write-tools.d.ts +3 -1
  48. package/dist/settings/agent-value-write-tools.js +11 -4
  49. package/dist/settings/tool-registrations.js +1 -1
  50. package/dist/surface-cards.d.ts +2 -0
  51. package/dist/surface-cards.js +2 -0
  52. package/dist/teardown.d.ts +30 -0
  53. package/dist/teardown.js +43 -0
  54. package/dist/text/descriptor-i18n.d.ts +24 -0
  55. package/dist/text/descriptor-i18n.js +65 -0
  56. package/dist/text/index.d.ts +2 -0
  57. package/dist/text/index.js +1 -0
  58. package/dist/tool-metadata-types.d.ts +6 -0
  59. package/dist/user-facing-error.d.ts +28 -1
  60. package/dist/user-facing-error.js +87 -4
  61. package/package.json +44 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 0.7.0
2
+
3
+ ### Minor Changes
4
+
5
+ - 41ff2ff: Add host-neutral credential-set contracts to `@jini-ai/core/contracts/credentials`: record, safe
6
+ summary, scope, connection input, token hint, keyring, project half and repository port types,
7
+ with notes on metadata-only reads, private vault context, CAS and trusted ownership. Types only.
8
+ - a266ba8: Add `CredentialedRequestPort` and `SourceControlWritePort` to `@jini-ai/core/contracts/credentials`:
9
+ request/target/verify/probe/error-classification and build/validate/plan/commit ports with exact
10
+ result, plan and failure types, plus agent notes on target-before-decrypt, held DELETE, caller-safe
11
+ egress messages and plan-bound commits on the same provider. Types only.
12
+ - 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`.
13
+ - 6ab1d81: Add the type-only `OAuthFlowOperations` contract and its signature closure (moved from `@jini-ai/oauth`) to `@jini-ai/core/contracts/oauth`.
14
+ - 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.
15
+
16
+ ### Patch Changes
17
+
18
+ - 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.
19
+ - 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.
20
+
21
+ ## 0.6.23
22
+
23
+ - Security hardening.
24
+
1
25
  # @jini-ai/core
2
26
 
3
27
  ## 0.6.22
@@ -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
- /** A host describes the action; core owns the decision lifecycle, never the card format. */
6
- export interface ApprovalPlan<TDescription> {
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;
@@ -35,6 +66,17 @@ export interface RememberedApprovalPort {
35
66
  confirmer: HumanConfirmer;
36
67
  }): Promise<void>;
37
68
  }
69
+ /** Host-owned view/version snapshot captured before asking, then carried into the approved
70
+ * effect. The host validates it at the effect boundary; this port grants no authorization. */
71
+ export interface ApprovalContextPort {
72
+ capture(required: {
73
+ ctx: ToolExecutionContext;
74
+ }): Promise<unknown>;
75
+ prepare(required: {
76
+ ctx: ToolExecutionContext;
77
+ snapshot: unknown;
78
+ }): ToolExecutionContext;
79
+ }
38
80
  export interface ApprovalSteps<TPrepared, TDescription> {
39
81
  prepare(required: {
40
82
  ctx: ToolExecutionContext;
@@ -153,7 +195,10 @@ export declare function createApprovalProposalStore<TDescription>({ responseTool
153
195
  };
154
196
  /** Apply a host classification through the same handler owner used by domain plans.
155
197
  * A host description's string `rememberKey` opts into reusable grants; descriptions remain opaque.
198
+ * Optional context is captured only for asking actions and prepared only after approval.
156
199
  * @returns The registration with one approval handler; authorization policy is preserved.
200
+ * @complexity O(input bytes) snapshot plus bounded injected ports; no retained cross-call state.
201
+ * @overallScore 100
157
202
  */
158
203
  export declare function applyApprovalPolicy<TDescription>({ registration, classify, asks, describe, askHuman, notConfirmed }: {
159
204
  registration: ToolRegistration;
@@ -171,5 +216,6 @@ export declare function applyApprovalPolicy<TDescription>({ registration, classi
171
216
  notConfirmed: ApprovalSteps<string, TDescription>['notConfirmed'];
172
217
  }, optional?: {
173
218
  remembered?: RememberedApprovalPort;
219
+ context?: ApprovalContextPort;
174
220
  }): ToolRegistration;
175
221
  //# sourceMappingURL=approval.d.ts.map
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 plan = await steps.describe({ ctx: snapshot, prepared: value }, options);
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
- return { ask: plans.some(plan => plan.ask), description: combineDescriptions({ descriptions: plans.map(plan => plan.description) }) };
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) => {
@@ -249,20 +272,34 @@ export function createApprovalProposalStore({ responseTool, messages }, { create
249
272
  }
250
273
  /** Apply a host classification through the same handler owner used by domain plans.
251
274
  * A host description's string `rememberKey` opts into reusable grants; descriptions remain opaque.
275
+ * Optional context is captured only for asking actions and prepared only after approval.
252
276
  * @returns The registration with one approval handler; authorization policy is preserved.
277
+ * @complexity O(input bytes) snapshot plus bounded injected ports; no retained cross-call state.
278
+ * @overallScore 100
253
279
  */
254
280
  export function applyApprovalPolicy({ registration, classify, asks, describe, askHuman, notConfirmed }, optional = {}) {
255
281
  return { ...registration, handler: createApprovalHandler({
256
- prepare: async ({ ctx }) => classify({ input: ctx.input }),
282
+ prepare: async ({ ctx }) => {
283
+ const actionClass = classify({ input: ctx.input });
284
+ const ask = asks({ class: actionClass });
285
+ if (!ask || !optional.context)
286
+ return { actionClass, ask };
287
+ return { actionClass, ask, snapshot: await optional.context.capture({ ctx }) };
288
+ },
257
289
  describe: async ({ ctx, prepared }) => {
258
- const ask = asks({ class: prepared });
259
- const description = await describe({ ctx, class: prepared });
290
+ const description = await describe({ ctx, class: prepared.actionClass });
260
291
  const candidate = { value: description };
261
- return { ask, description, ...(isNonArrayRecord(candidate) && typeof candidate.value.rememberKey === 'string'
292
+ return { ask: prepared.ask, description, ...(isNonArrayRecord(candidate) && typeof candidate.value.rememberKey === 'string'
262
293
  ? { rememberKey: candidate.value.rememberKey } : {}) };
263
294
  },
264
- askHuman, notConfirmed,
265
- run: ({ ctx }, options) => registration.handler(ctx, options),
295
+ askHuman,
296
+ notConfirmed: ({ reason, prepared }) => notConfirmed({ reason, prepared: prepared?.actionClass }),
297
+ run: ({ ctx, prepared }, options) => {
298
+ if (!prepared.ask || !optional.context)
299
+ return registration.handler(ctx, options);
300
+ const executionContext = optional.context.prepare({ ctx, snapshot: prepared.snapshot });
301
+ return registration.handler(executionContext, options);
302
+ },
266
303
  }, optional) };
267
304
  }
268
305
  //# sourceMappingURL=approval.js.map
@@ -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). Drop images from item envelopes; the
169
- * item's text blocks still carry its result. Anything that is not an envelope is returned as is. */
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
- return { batch: true, outcome, ...(succeeded === 0 ? { isError: true } : {}), total: results.length, succeeded, failed: results.length - succeeded, results };
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
- results.push(batchItemResult({ index, output: withoutItemImages(output), notes: normalized.notes }));
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.