@xpert-ai/plugin-sdk 3.18.3 → 3.18.5

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 (32) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +26 -1
  3. package/index.cjs.js +249 -27
  4. package/index.esm.js +244 -30
  5. package/model-provider.cjs.js +8 -0
  6. package/model-provider.esm.js +7 -1
  7. package/package.json +2 -2
  8. package/runtime-capabilities.md +49 -0
  9. package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +3 -0
  10. package/src/lib/agent/middleware/runtime.d.ts +2 -14
  11. package/src/lib/ai-model/types/rerank.d.ts +2 -0
  12. package/src/lib/ai-model/utils/tokenizer.d.ts +6 -0
  13. package/src/lib/connector/runtime-capability.d.ts +19 -0
  14. package/src/lib/evolution/runtime-capability.d.ts +2 -1
  15. package/src/lib/mcp/resource-template.d.ts +2 -3
  16. package/src/lib/mcp/resource.d.ts +5 -1
  17. package/src/lib/rag/textsplitter/strategy.interface.d.ts +15 -4
  18. package/src/lib/rag/transformer/strategy.interface.d.ts +3 -0
  19. package/src/lib/runtime/capabilities/actor-token.d.ts +12 -0
  20. package/src/lib/runtime/capabilities/artifacts.d.ts +2 -0
  21. package/src/lib/runtime/capabilities/knowledge-document-visual-assets.d.ts +16 -5
  22. package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +50 -1
  23. package/src/lib/runtime/capabilities/knowledgebase.d.ts +1 -0
  24. package/src/lib/runtime/capabilities/workspace-files.d.ts +2 -0
  25. package/src/lib/runtime/index.d.ts +1 -0
  26. package/src/lib/runtime/runtime-scope.d.ts +14 -0
  27. package/src/lib/tool-provider/index.d.ts +2 -0
  28. package/src/lib/tool-provider/prepared-result.d.ts +18 -0
  29. package/src/lib/tool-provider/tool-result.d.ts +16 -0
  30. package/src/lib/tool-provider/types.d.ts +8 -2
  31. package/src/lib/toolset/define-tool.d.ts +2 -1
  32. package/src/lib/types.d.ts +12 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @xpert-ai/plugin-sdk
2
2
 
3
+ ## 3.18.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 6a51c17: Add a shared knowledge document language hint and bounded, model-free language detection for natural text chunk boundaries. Preserve Auto strategy routing, explicit separators, token limits, and parent-child behavior, and expose the requested and detected languages in chunk previews.
8
+ - 8402f72: Prepare the Xpert 3.18.5 patch release, including plugin-sdk.
9
+
10
+ Add knowledge document chunk token limits, question generation, automatic and
11
+ structure-aware chunking, spreadsheet table metadata, and format-specific scoped
12
+ parsers with diagnostics. Preserve OCR chunk limits and table context.
13
+
14
+ Extend MCP resource reads with scoped workspace files and the requested resource
15
+ URI, preserve confirmation sessions, and reauthorize queued execution. Add PPTX
16
+ preview and editing with binary workspace saves and edited downloads.
17
+
18
+ The target platform version is 3.18.5. Verify contracts, plugin-sdk, and xpert-ui
19
+ all resolve to this version in the release version PR, including changelogs,
20
+ internal dependency references, and lockfile entries.
21
+
22
+ - Updated dependencies [6a51c17]
23
+ - Updated dependencies [95ec638]
24
+ - Updated dependencies [8402f72]
25
+ - @xpert-ai/contracts@3.18.5
26
+
27
+ ## 3.18.4
28
+
29
+ ### Patch Changes
30
+
31
+ - 3f72082: Add opt-in lazy template catalogs, summary pagination, explicit prompt locales and source revision tracking. Existing eager template providers remain compatible.
32
+
33
+ Restore role skill bindings when switching templates and preserve localized skill names during installation and selection.
34
+
35
+ - 4be390b: Release Xpert 3.18.4 with aligned contracts, plugin-sdk, and Web application versions.
36
+
37
+ - 63cd444: Allow host-enabled graph Connector providers in scoped runtime credentials while preserving explicit binding checks. Existing Connector APIs remain compatible.
38
+ - Updated dependencies [3f72082]
39
+ - Updated dependencies [7b97fee]
40
+ - Updated dependencies [4be390b]
41
+ - Updated dependencies [4e8c7ed]
42
+ - @xpert-ai/contracts@3.18.4
43
+
3
44
  ## 3.18.3
4
45
 
5
46
  ### Patch Changes
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Plugin SDK
2
2
 
3
+ ## Runtime capabilities
4
+
5
+ See [platform capabilities and scoped factories](./runtime-capabilities.md) for domain registration, execution-scoped APIs and usage outside Agent middleware.
6
+
3
7
  ## Building
4
8
 
5
9
  Run `nx build plugin-sdk` to build the library.
@@ -61,7 +65,9 @@ export class OrderOperationsTools {
61
65
  }
62
66
  ```
63
67
 
64
- MCP exposure is explicit. Provide strict Zod input/output schemas and return an allowlisted DTO; the host validates the output and maps it to `structuredContent`. Invocation context is constructed for every call and must never be cached on the Provider singleton. `getMiddlewareExtensions()` may add Agent-only hooks such as `wrapToolCall`, but business-critical behavior belongs in the method or shared service.
68
+ MCP exposure is explicit. Provide strict Zod input/output schemas and return an allowlisted DTO; the host validates the output and maps it to `structuredContent` and a JSON `TextContent` block so clients that only expose text can still read the result. With `resultFormat: 'tool_result'`, image and other content blocks are preserved and the validated structured metadata also receives a JSON text fallback. Invocation context is constructed for every call and must never be cached on the Provider singleton. `getMiddlewareExtensions()` may add Agent-only hooks such as `wrapToolCall`, but business-critical behavior belongs in the method or shared service.
69
+
70
+ For completed operations, `prepareToolResult(() => project(result), () => minimalReceipt)` defers output mapping to the adapter. The normal path maps and validates once; projection, validation or JSON serialization failures recover a bounded receipt without executing the business method again. Declare `outputSchema: z.union([normalSchema, receiptSchema])`, with strict objects in every branch. The fallback is validated too. Business exceptions thrown before the method returns remain errors. With `tool_result`, both callbacks return the content envelope and the union describes its structured metadata. The MCP protocol still validates the published JSON Schema; custom Zod refinements remain enforced by the SDK. Do not put side effects inside either callback.
65
71
 
66
72
  For a host-native MCP App, declare each static HTML bundle once in the Provider's `apps` array, then bind a Tool with `mcp.app.resourceKey` and include `app` visibility. The App key must exist in the same Provider and its entry must be a relative `.html` path inside the packaged plugin. The host publishes the bundle as a `ui://` resource; plugins must not create a stdio server or put CSP/credentials in Tool results.
67
73
 
@@ -85,3 +91,22 @@ import {
85
91
  ```
86
92
 
87
93
  This entry point excludes the NestJS and Node.js dependencies used by the server SDK.
94
+
95
+ ### Native MCP invocation defaults
96
+
97
+ A decorated tool can declare `mcp.defaultApprovalMode: 'allow' | 'confirm' | 'deny'`.
98
+ The native capability descriptor carries this default through auto-publication and
99
+ provider synchronization. Explicit Publication administrator policies take
100
+ precedence. Omitting the field retains the existing risk defaults: reads allow,
101
+ writes confirm, and dangerous tools deny. A dangerous tool can run directly only
102
+ when its owner explicitly declares `allow`; risk annotations remain unchanged.
103
+ Manual Publications review changes to this declaration before adopting them.
104
+
105
+ For public Artifact links authorized by trusted application policy, runtime callers
106
+ may pass `access.publicLinkAuthorization: 'application_policy'` instead of
107
+ asserting `userConfirmedPublicLink`. This field must be derived by trusted plugin
108
+ code, never exposed as a tool argument. Existing user-confirmation calls retain
109
+ their behavior; user identity and Artifact scope checks still apply.
110
+
111
+ These additions require matching host contracts/runtime support and an SDK build
112
+ containing these interfaces. They are not part of the published SDK 3.18.3 baseline.
package/index.cjs.js CHANGED
@@ -37,7 +37,7 @@ var base$1 = require('@langchain/core/language_models/base');
37
37
  var connector = require('./connector.cjs.js');
38
38
  var collaborationClient = require('./collaboration-client.cjs.js');
39
39
  var tools = require('@langchain/core/tools');
40
- require('zod/v3');
40
+ var v3 = require('zod/v3');
41
41
 
42
42
  function _interopNamespaceDefault(e) {
43
43
  var n = Object.create(null);
@@ -3597,17 +3597,11 @@ class OpenAICompatibleReranker {
3597
3597
  if (!Array.isArray(output)) {
3598
3598
  throw new Error('Invalid response format: missing results array');
3599
3599
  }
3600
- // Collect raw scores and normalize them.
3601
- const scores = output.map((r)=>r.relevance_score);
3602
- const minScore = Math.min(...scores);
3603
- const maxScore = Math.max(...scores);
3604
- const scoreRange = maxScore !== minScore ? maxScore - minScore : 1.0;
3605
3600
  const reranked = output.map((r)=>{
3606
3601
  const index = r.index;
3607
- const normalizedScore = (r.relevance_score - minScore) / scoreRange;
3608
3602
  const result = {
3609
3603
  index,
3610
- relevanceScore: normalizedScore
3604
+ relevanceScore: r.relevance_score
3611
3605
  };
3612
3606
  if (options.returnDocuments) {
3613
3607
  var _r_document, _docs_index, _docs_index1;
@@ -3657,6 +3651,44 @@ class Speech2TextChatModel extends chat_models.BaseChatModel {
3657
3651
  }
3658
3652
 
3659
3653
  const encodingCache = new Map();
3654
+ /** Exact, model-independent text count for hard chunk limits. Treat special-token spellings as literal document text. */ function textEncoding() {
3655
+ const cacheKey = 'encoding:cl100k_base';
3656
+ let encoder = encodingCache.get(cacheKey);
3657
+ if (!encoder) {
3658
+ encoder = jsTiktoken.getEncoding('cl100k_base');
3659
+ encodingCache.set(cacheKey, encoder);
3660
+ }
3661
+ return encoder;
3662
+ }
3663
+ function countTextTokens(text) {
3664
+ if (!text) return 0;
3665
+ // A hard limit must fail if tokenization fails, never fall back to an estimate.
3666
+ return textEncoding().encode(text, [], []).length;
3667
+ }
3668
+ /** Token boundaries that also end on complete Unicode characters, in UTF-16 source offsets. */ function textTokenBoundaries(text) {
3669
+ const encoder = textEncoding();
3670
+ const tokens = encoder.encode(text, [], []);
3671
+ const boundaries = [
3672
+ {
3673
+ offset: 0,
3674
+ tokens: 0
3675
+ }
3676
+ ];
3677
+ let offset = 0;
3678
+ let start = 0;
3679
+ for(let end = 1; end <= tokens.length; end++){
3680
+ const decoded = encoder.decode(tokens.slice(start, end));
3681
+ if (!decoded || !text.startsWith(decoded, offset)) continue;
3682
+ offset += decoded.length;
3683
+ boundaries.push({
3684
+ offset,
3685
+ tokens: end
3686
+ });
3687
+ start = end;
3688
+ }
3689
+ if (offset !== text.length) throw new Error('Tokenization could not preserve the source text.');
3690
+ return boundaries;
3691
+ }
3660
3692
  /**
3661
3693
  * Fallback token estimation method.
3662
3694
  *
@@ -4121,6 +4153,9 @@ exports.SSOProviderRegistry = __decorate([
4121
4153
  const ConnectorRuntimeCapability = modelProvider.createRuntimeCapability('platform.connector', {
4122
4154
  description: 'Resolve connector credentials for agent middleware.'
4123
4155
  });
4156
+ const ConnectorRuntimeFactoryCapability = modelProvider.createRuntimeCapability('platform.connector.factory', {
4157
+ description: 'Create a connector API restricted to host-granted connectors and the authorized execution identity.'
4158
+ });
4124
4159
 
4125
4160
  const CONNECTOR_STRATEGY = 'CONNECTOR_STRATEGY';
4126
4161
  const ConnectorStrategyKey = (provider)=>common.applyDecorators(common.SetMetadata(CONNECTOR_STRATEGY, provider), common.SetMetadata(STRATEGY_META_KEY, CONNECTOR_STRATEGY));
@@ -5884,6 +5919,9 @@ const EVOLUTION_RUNTIME_SERVICE_TOKEN = 'XPERT_EVOLUTION_RUNTIME_SERVICE';
5884
5919
  const EvolutionRuntimeCapability = modelProvider.createRuntimeCapability('platform.agent-evolution', {
5885
5920
  description: 'Ingest learning signals and resolve immutable capability versions for domain runtimes.'
5886
5921
  });
5922
+ const EvolutionChangeRuntimeCapability = modelProvider.createRuntimeCapability('platform.agent-evolution.changes', {
5923
+ description: 'Prepare, evaluate and publish versioned changes through target-owned validators and effect providers.'
5924
+ });
5887
5925
 
5888
5926
  function defineMcpApp(definition) {
5889
5927
  return Object.freeze(definition);
@@ -6047,6 +6085,12 @@ function validateProviderOptions(options) {
6047
6085
  }
6048
6086
  function validateToolOptions(options, methodName) {
6049
6087
  var _options_description;
6088
+ if (options.resultFormat && options.resultFormat !== 'dto' && options.resultFormat !== 'tool_result') {
6089
+ throw new Error(`Tool '${options.name}' declares an invalid resultFormat.`);
6090
+ }
6091
+ if (options.resultFormat === 'tool_result' && !options.outputSchema) {
6092
+ throw new Error(`Tool '${options.name}' requires outputSchema for tool_result.`);
6093
+ }
6050
6094
  if (!TOOL_NAME_PATTERN.test(options.name) || options.name.length > 191) {
6051
6095
  throw new Error(`Method '${methodName}' declares invalid Tool name '${options.name}'.`);
6052
6096
  }
@@ -6062,6 +6106,9 @@ function validateToolOptions(options, methodName) {
6062
6106
  throw new Error(`MCP Tool '${options.name}' requires at least one execution context.`);
6063
6107
  }
6064
6108
  if (options.mcp) {
6109
+ if (options.mcp.defaultApprovalMode !== undefined && !includesValue(contracts.MCP_CAPABILITY_APPROVAL_MODES, options.mcp.defaultApprovalMode)) {
6110
+ throw new Error(`MCP Tool '${options.name}' declares invalid defaultApprovalMode.`);
6111
+ }
6065
6112
  const behavior = options.mcp.behavior;
6066
6113
  if (!includesValue(contracts.MCP_TOOL_RISKS, behavior == null ? void 0 : behavior.risk) || !includesValue(contracts.MCP_TOOL_SIDE_EFFECTS, behavior == null ? void 0 : behavior.sideEffect) || !includesValue(contracts.MCP_TOOL_IDEMPOTENCY, behavior == null ? void 0 : behavior.idempotency)) {
6067
6114
  throw new Error(`MCP Tool '${options.name}' requires valid behavior annotations.`);
@@ -6088,6 +6135,19 @@ function assertStrictObjectSchema(schema, toolName, role) {
6088
6135
  if (!schema || typeof Reflect.get(schema, 'parseAsync') !== 'function') {
6089
6136
  throw new Error(`Tool '${toolName}' requires a Zod ${role} schema.`);
6090
6137
  }
6138
+ // Refinements preserve the strict object shape while enforcing cross-field invariants.
6139
+ // Plugins can load a different physical copy of Zod; use its explicit type tag.
6140
+ while(schema._def.typeName === 'ZodEffects'){
6141
+ const refinement = schema;
6142
+ if (refinement._def.effect.type !== 'refinement') break;
6143
+ schema = refinement.innerType();
6144
+ }
6145
+ if (role === 'output' && schema._def.typeName === 'ZodUnion') {
6146
+ // Recovery receipts may have a different shape, but every branch must reject extra fields.
6147
+ const union = schema;
6148
+ for (const option of union.options)assertStrictObjectSchema(option, toolName, role);
6149
+ return;
6150
+ }
6091
6151
  const definition = Reflect.get(schema, '_def');
6092
6152
  if (!definition || Reflect.get(definition, 'unknownKeys') !== 'strict') {
6093
6153
  throw new Error(`Tool '${toolName}' ${role} schema must be a strict Zod object.`);
@@ -6161,6 +6221,141 @@ exports.XpertToolProviderRegistry = __decorate([
6161
6221
  ])
6162
6222
  ], exports.XpertToolProviderRegistry);
6163
6223
 
6224
+ // Invariants: recovery starts only after the business method returns successfully.
6225
+ // Projection and recovery callbacks must be free of business side effects.
6226
+ // The adapter validates normal output once and validates any fallback separately;
6227
+ // neither path may rerun the operation or suppress input, authorization or commit failures.
6228
+ // Installed plugins may resolve a different physical SDK copy from the host.
6229
+ const PREPARED_RESULT = Symbol.for('xpert.tool.prepared-result.v1');
6230
+ /** Defer output projection until the adapter can validate and recover its result. */ function prepareToolResult(project, recover) {
6231
+ return {
6232
+ [PREPARED_RESULT]: true,
6233
+ project,
6234
+ recover
6235
+ };
6236
+ }
6237
+ function isPrepared(value) {
6238
+ return typeof value === 'object' && value !== null && PREPARED_RESULT in value && value[PREPARED_RESULT] === true && 'project' in value && typeof value.project === 'function' && 'recover' in value && typeof value.recover === 'function';
6239
+ }
6240
+ async function resolveToolResult(value, validate) {
6241
+ if (!isPrepared(value)) return validate(value);
6242
+ try {
6243
+ return await validate(await value.project());
6244
+ } catch (error) {
6245
+ const diagnostic = {
6246
+ code: 'tool_output_invalid',
6247
+ issues: error instanceof v3.ZodError ? error.issues.slice(0, 10).map((issue)=>({
6248
+ path: issue.path.join('.').slice(0, 240),
6249
+ code: issue.code
6250
+ })) : []
6251
+ };
6252
+ // A malformed fallback is a programming error too; never send unchecked data.
6253
+ return validate(await value.recover(diagnostic));
6254
+ }
6255
+ }
6256
+
6257
+ // Why this exists: MCP media blocks and business metadata have different contracts.
6258
+ // Validate metadata with the declared output schema, preserve bounded media blocks,
6259
+ // and include the same DTO in text for clients that hide structuredContent.
6260
+ const XPERT_TOOL_RESULT_FORMAT_VERSION = 1;
6261
+ const contentSchema = v3.z.discriminatedUnion('type', [
6262
+ v3.z.object({
6263
+ type: v3.z.literal('text'),
6264
+ text: v3.z.string().max(2 * 1024 * 1024)
6265
+ }).strict(),
6266
+ v3.z.object({
6267
+ type: v3.z.literal('image'),
6268
+ data: v3.z.string().min(1).max(8 * 1024 * 1024),
6269
+ mimeType: v3.z.enum([
6270
+ 'image/png',
6271
+ 'image/jpeg',
6272
+ 'image/webp',
6273
+ 'image/gif'
6274
+ ])
6275
+ }).strict(),
6276
+ v3.z.object({
6277
+ type: v3.z.literal('audio'),
6278
+ data: v3.z.string().min(1).max(8 * 1024 * 1024),
6279
+ mimeType: v3.z.string().min(1).max(100)
6280
+ }).strict(),
6281
+ v3.z.object({
6282
+ type: v3.z.literal('resource_link'),
6283
+ uri: v3.z.string().min(1).max(4096),
6284
+ name: v3.z.string().max(240).optional()
6285
+ }).strict()
6286
+ ]);
6287
+ /** Validate the envelope separately so binary content never enters the business DTO. */ async function parseDecoratedToolResult(value, outputSchema) {
6288
+ var _result_content;
6289
+ const envelope = v3.z.object({
6290
+ content: v3.z.array(contentSchema).max(32).optional(),
6291
+ structuredContent: outputSchema,
6292
+ isError: v3.z.boolean().optional()
6293
+ }).strict();
6294
+ const result = await envelope.parseAsync(value);
6295
+ var _result_content_map;
6296
+ const content = (_result_content_map = (_result_content = result.content) == null ? void 0 : _result_content.map((item)=>{
6297
+ switch(item.type){
6298
+ case 'text':
6299
+ return {
6300
+ type: 'text',
6301
+ text: item.text
6302
+ };
6303
+ case 'image':
6304
+ return {
6305
+ type: 'image',
6306
+ data: item.data,
6307
+ mimeType: item.mimeType
6308
+ };
6309
+ case 'audio':
6310
+ return {
6311
+ type: 'audio',
6312
+ data: item.data,
6313
+ mimeType: item.mimeType
6314
+ };
6315
+ case 'resource_link':
6316
+ return _extends._extends({
6317
+ type: 'resource_link',
6318
+ uri: item.uri
6319
+ }, item.name ? {
6320
+ name: item.name
6321
+ } : {});
6322
+ }
6323
+ })) != null ? _result_content_map : [];
6324
+ // MCP clients may expose only content to the model. Keep the validated DTO
6325
+ // readable there too, while retaining binary blocks and App structured data.
6326
+ const text = JSON.stringify(result.structuredContent);
6327
+ if (!content.some((item)=>item.type === 'text' && item.text === text)) content.push({
6328
+ type: 'text',
6329
+ text
6330
+ });
6331
+ return _extends._extends({
6332
+ structuredContent: result.structuredContent,
6333
+ content
6334
+ }, result.isError === undefined ? {} : {
6335
+ isError: result.isError
6336
+ });
6337
+ }
6338
+ function agentContent(content) {
6339
+ return (content != null ? content : []).map((item)=>{
6340
+ if (item.type === 'image') return {
6341
+ type: 'image_url',
6342
+ image_url: {
6343
+ url: `data:${item.mimeType};base64,${item.data}`
6344
+ }
6345
+ };
6346
+ if (item.type === 'text') return item;
6347
+ var _item_name;
6348
+ if (item.type === 'resource_link') return {
6349
+ type: 'text',
6350
+ text: `${(_item_name = item.name) != null ? _item_name : 'Resource'}: ${item.uri}`
6351
+ };
6352
+ return {
6353
+ type: 'text',
6354
+ text: `Audio content (${item.mimeType}) is available through MCP.`
6355
+ };
6356
+ });
6357
+ }
6358
+
6164
6359
  class DecoratedToolsetStrategy {
6165
6360
  validateConfig() {
6166
6361
  return Promise.resolve();
@@ -6265,13 +6460,27 @@ function createAgentTool(instance, descriptor, middlewareContext, middlewareOpti
6265
6460
  return tools.tool(async (input, config)=>{
6266
6461
  const parsedInput = await descriptor.options.inputSchema.parseAsync(input);
6267
6462
  const output = await invoke(parsedInput, agentExecutionContext(middlewareContext, middlewareOptions, config));
6268
- const parsedOutput = descriptor.options.outputSchema ? await descriptor.options.outputSchema.parseAsync(output) : output;
6269
- return stringifyDto(parsedOutput, descriptor.options.name);
6463
+ if (descriptor.options.resultFormat === 'tool_result' && descriptor.options.outputSchema) {
6464
+ const result = await resolveToolResult(output, (value)=>parseDecoratedToolResult(value, descriptor.options.outputSchema));
6465
+ var _result_isError;
6466
+ return [
6467
+ agentContent(result.content),
6468
+ {
6469
+ structuredContent: result.structuredContent,
6470
+ isError: (_result_isError = result.isError) != null ? _result_isError : false
6471
+ }
6472
+ ];
6473
+ }
6474
+ return resolveToolResult(output, async (value)=>{
6475
+ const parsedOutput = descriptor.options.outputSchema ? await descriptor.options.outputSchema.parseAsync(value) : value;
6476
+ return stringifyDto(parsedOutput, descriptor.options.name);
6477
+ });
6270
6478
  }, _extends._extends({
6271
6479
  name: descriptor.options.name,
6272
6480
  description: descriptor.options.description,
6273
6481
  schema: descriptor.options.inputSchema,
6274
- verboseParsingErrors: true
6482
+ verboseParsingErrors: true,
6483
+ responseFormat: descriptor.options.resultFormat === 'tool_result' ? 'content_and_artifact' : 'content'
6275
6484
  }, descriptor.options.metadata ? {
6276
6485
  metadata: descriptor.options.metadata
6277
6486
  } : {}));
@@ -6295,7 +6504,10 @@ function createMcpTool(instance, descriptor) {
6295
6504
  eligible: true
6296
6505
  }
6297
6506
  },
6298
- behavior: mcp.behavior,
6507
+ behavior: mcp.behavior
6508
+ }, mcp.defaultApprovalMode ? {
6509
+ defaultApprovalMode: mcp.defaultApprovalMode
6510
+ } : {}, {
6299
6511
  requiredContext: [
6300
6512
  ...mcp.requiredContext
6301
6513
  ],
@@ -6315,18 +6527,23 @@ function createMcpTool(instance, descriptor) {
6315
6527
  execute: async (input, context)=>{
6316
6528
  const parsedInput = await descriptor.options.inputSchema.parseAsync(input);
6317
6529
  const output = await invoke(parsedInput, mcpExecutionContext(context));
6318
- const parsedOutput = await outputSchema.parseAsync(output);
6319
- const dto = jsonDto(parsedOutput, descriptor.options.name);
6320
- var _descriptor_options_title;
6321
- return {
6322
- content: [
6323
- {
6324
- type: 'text',
6325
- text: `${(_descriptor_options_title = descriptor.options.title) != null ? _descriptor_options_title : descriptor.options.name} completed. See structuredContent for the result.`
6326
- }
6327
- ],
6328
- structuredContent: dto
6329
- };
6530
+ if (descriptor.options.resultFormat === 'tool_result') {
6531
+ return resolveToolResult(output, (value)=>parseDecoratedToolResult(value, outputSchema));
6532
+ }
6533
+ return resolveToolResult(output, async (value)=>{
6534
+ const parsedOutput = await outputSchema.parseAsync(value);
6535
+ // Serialize once so text-only clients and MCP Apps receive the same JSON-safe DTO.
6536
+ const text = stringifyDto(parsedOutput, descriptor.options.name);
6537
+ return {
6538
+ content: [
6539
+ {
6540
+ type: 'text',
6541
+ text
6542
+ }
6543
+ ],
6544
+ structuredContent: JSON.parse(text)
6545
+ };
6546
+ });
6330
6547
  }
6331
6548
  });
6332
6549
  }
@@ -6391,9 +6608,6 @@ function stringifyDto(value, toolName) {
6391
6608
  if (result === undefined) throw new Error(`Tool '${toolName}' returned a non-JSON value.`);
6392
6609
  return result;
6393
6610
  }
6394
- function jsonDto(value, toolName) {
6395
- return JSON.parse(stringifyDto(value, toolName));
6396
- }
6397
6611
  function asI18n(value) {
6398
6612
  return {
6399
6613
  en_US: value,
@@ -6482,6 +6696,7 @@ Object.defineProperty(exports, "ASSISTANT_CONTEXT_SET_COMMAND", {
6482
6696
  get: function () { return contracts.ASSISTANT_CONTEXT_SET_COMMAND; }
6483
6697
  });
6484
6698
  exports.ActorTokenRuntimeCapability = modelProvider.ActorTokenRuntimeCapability;
6699
+ exports.ActorTokenRuntimeFactoryCapability = modelProvider.ActorTokenRuntimeFactoryCapability;
6485
6700
  exports.ArtifactsRuntimeCapability = modelProvider.ArtifactsRuntimeCapability;
6486
6701
  exports.BaseTool = modelProvider.BaseTool;
6487
6702
  exports.BaseToolset = modelProvider.BaseToolset;
@@ -6489,6 +6704,7 @@ exports.BuiltinToolset = modelProvider.BuiltinToolset;
6489
6704
  exports.DefaultAgentMiddlewareRuntimeCapabilityRegistry = modelProvider.DefaultRuntimeCapabilityRegistry;
6490
6705
  exports.DefaultRuntimeCapabilityRegistry = modelProvider.DefaultRuntimeCapabilityRegistry;
6491
6706
  exports.KnowledgeDocumentVisualAssetsRuntimeCapability = modelProvider.KnowledgeDocumentVisualAssetsRuntimeCapability;
6707
+ exports.KnowledgeDocumentVisualAssetsRuntimeFactoryCapability = modelProvider.KnowledgeDocumentVisualAssetsRuntimeFactoryCapability;
6492
6708
  exports.KnowledgebaseDocumentsRuntimeCapability = modelProvider.KnowledgebaseDocumentsRuntimeCapability;
6493
6709
  exports.KnowledgebaseProvisioningRuntimeCapability = modelProvider.KnowledgebaseProvisioningRuntimeCapability;
6494
6710
  exports.KnowledgebaseRuntimeCapability = modelProvider.KnowledgebaseRuntimeCapability;
@@ -6547,6 +6763,7 @@ exports.CollaborationDocumentProvider = CollaborationDocumentProvider;
6547
6763
  exports.CollaborationRuntimeCapability = CollaborationRuntimeCapability;
6548
6764
  exports.CommonParameterRules = CommonParameterRules;
6549
6765
  exports.ConnectorRuntimeCapability = ConnectorRuntimeCapability;
6766
+ exports.ConnectorRuntimeFactoryCapability = ConnectorRuntimeFactoryCapability;
6550
6767
  exports.ConnectorStrategyKey = ConnectorStrategyKey;
6551
6768
  exports.CreateModelClientCommand = CreateModelClientCommand;
6552
6769
  exports.CredentialsValidateFailedError = CredentialsValidateFailedError;
@@ -6571,6 +6788,7 @@ exports.DocumentSourceStrategy = DocumentSourceStrategy;
6571
6788
  exports.DocumentTransformerStrategy = DocumentTransformerStrategy;
6572
6789
  exports.EVOLUTION_RUNTIME_SERVICE_TOKEN = EVOLUTION_RUNTIME_SERVICE_TOKEN;
6573
6790
  exports.EVOLUTION_TARGET_PROVIDER = EVOLUTION_TARGET_PROVIDER;
6791
+ exports.EvolutionChangeRuntimeCapability = EvolutionChangeRuntimeCapability;
6574
6792
  exports.EvolutionRuntimeCapability = EvolutionRuntimeCapability;
6575
6793
  exports.EvolutionTargetProviderStrategy = EvolutionTargetProviderStrategy;
6576
6794
  exports.FILE_STORAGE_PROVIDER = FILE_STORAGE_PROVIDER;
@@ -6669,6 +6887,7 @@ exports.XPERT_AGENT_MIDDLEWARE_RUNTIME_TOKEN = XPERT_AGENT_MIDDLEWARE_RUNTIME_TO
6669
6887
  exports.XPERT_TOOL_METHOD_METADATA = XPERT_TOOL_METHOD_METADATA;
6670
6888
  exports.XPERT_TOOL_PROVIDER = XPERT_TOOL_PROVIDER;
6671
6889
  exports.XPERT_TOOL_PROVIDER_METADATA = XPERT_TOOL_PROVIDER_METADATA;
6890
+ exports.XPERT_TOOL_RESULT_FORMAT_VERSION = XPERT_TOOL_RESULT_FORMAT_VERSION;
6672
6891
  exports.XpFileSystem = XpFileSystem;
6673
6892
  exports.XpertServerPlugin = XpertServerPlugin;
6674
6893
  exports.XpertTool = XpertTool;
@@ -6681,6 +6900,7 @@ exports.calculateLLMUsagePrice = calculateLLMUsagePrice;
6681
6900
  exports.calculateModelPrice = calculateModelPrice;
6682
6901
  exports.calculateModelUsageCharge = calculateModelUsageCharge;
6683
6902
  exports.chunkText = chunkText;
6903
+ exports.countTextTokens = countTextTokens;
6684
6904
  exports.countTokensSafe = countTokensSafe;
6685
6905
  exports.createI18nInstance = createI18nInstance;
6686
6906
  exports.createPluginLogger = createPluginLogger;
@@ -6722,6 +6942,7 @@ exports.mergeCredentials = mergeCredentials;
6722
6942
  exports.mergeParentChildChunks = mergeParentChildChunks;
6723
6943
  exports.normalizeContextSize = normalizeContextSize;
6724
6944
  exports.pluginArtifactTableName = pluginArtifactTableName;
6945
+ exports.prepareToolResult = prepareToolResult;
6725
6946
  exports.processAsyncAIGCManagedJob = processAsyncAIGCManagedJob;
6726
6947
  exports.renderRemoteModuleIframeHtml = renderRemoteModuleIframeHtml;
6727
6948
  exports.renderRemoteReactIframeHtml = renderRemoteReactIframeHtml;
@@ -6739,3 +6960,4 @@ exports.runWithRequestContext = runWithRequestContext;
6739
6960
  exports.secondsToMilliseconds = secondsToMilliseconds;
6740
6961
  exports.setDefaultTenantId = setDefaultTenantId;
6741
6962
  exports.sumTokenUsage = sumTokenUsage;
6963
+ exports.textTokenBoundaries = textTokenBoundaries;