extrait 0.5.5 → 0.5.6
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/README.md +20 -0
- package/dist/index.cjs +16 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -4
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -485,6 +485,14 @@ const result = await llm.structured(
|
|
|
485
485
|
},
|
|
486
486
|
// Optional: transform tool arguments before the tool is called
|
|
487
487
|
transformToolArguments: (args, call) => args,
|
|
488
|
+
// Optional: transform the full MCP call payload, including _meta
|
|
489
|
+
transformToolCallParams: (params, call) => ({
|
|
490
|
+
...params,
|
|
491
|
+
_meta: {
|
|
492
|
+
source: "extrait-docs",
|
|
493
|
+
clientId: call.clientId,
|
|
494
|
+
},
|
|
495
|
+
}),
|
|
488
496
|
// Optional: custom error message when an unknown tool is called
|
|
489
497
|
unknownToolError: (toolName) => `Tool "${toolName}" is not available.`,
|
|
490
498
|
},
|
|
@@ -494,6 +502,18 @@ const result = await llm.structured(
|
|
|
494
502
|
await mcpClient.close?.();
|
|
495
503
|
```
|
|
496
504
|
|
|
505
|
+
`transformToolArguments()` only receives the tool input object. `transformToolCallParams()` runs after it and receives the full `MCPCallToolParams` payload that will be sent to the MCP client:
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
type MCPCallToolParams = {
|
|
509
|
+
name: string;
|
|
510
|
+
arguments?: Record<string, unknown>;
|
|
511
|
+
_meta?: Record<string, unknown>;
|
|
512
|
+
};
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
Use `transformToolCallParams()` when you need to attach MCP-specific metadata, override the final remote tool name, or otherwise change the full request passed to `client.callTool()`. This hook is exported as `LLMToolCallParamsTransformer`.
|
|
516
|
+
|
|
497
517
|
### Timeouts
|
|
498
518
|
|
|
499
519
|
Use `timeout` to set per-request and per-tool-call time limits without managing `AbortSignal` manually.
|
package/dist/index.cjs
CHANGED
|
@@ -1317,6 +1317,17 @@ async function executeMCPToolCalls(calls, toolset, context) {
|
|
|
1317
1317
|
remoteName: tool.remoteName,
|
|
1318
1318
|
clientId: tool.clientId
|
|
1319
1319
|
}) : rawArgs;
|
|
1320
|
+
const toolParams = context.request.transformToolCallParams ? await context.request.transformToolCallParams({
|
|
1321
|
+
name: tool.remoteName,
|
|
1322
|
+
arguments: args
|
|
1323
|
+
}, {
|
|
1324
|
+
name: toolName,
|
|
1325
|
+
remoteName: tool.remoteName,
|
|
1326
|
+
clientId: tool.clientId
|
|
1327
|
+
}) : {
|
|
1328
|
+
name: tool.remoteName,
|
|
1329
|
+
arguments: args
|
|
1330
|
+
};
|
|
1320
1331
|
const metadata = {
|
|
1321
1332
|
id: callId,
|
|
1322
1333
|
type: call.type ?? "function",
|
|
@@ -1326,10 +1337,7 @@ async function executeMCPToolCalls(calls, toolset, context) {
|
|
|
1326
1337
|
const startedAt = new Date().toISOString();
|
|
1327
1338
|
const startedAtMs = Date.now();
|
|
1328
1339
|
try {
|
|
1329
|
-
const output = await tool.client.callTool(
|
|
1330
|
-
name: tool.remoteName,
|
|
1331
|
-
arguments: args
|
|
1332
|
-
});
|
|
1340
|
+
const output = await tool.client.callTool(toolParams);
|
|
1333
1341
|
const executionContext = {
|
|
1334
1342
|
callId,
|
|
1335
1343
|
type: call.type ?? "function",
|
|
@@ -4495,6 +4503,10 @@ async function callModel(adapter, options) {
|
|
|
4495
4503
|
parallelToolCalls: options.request?.parallelToolCalls,
|
|
4496
4504
|
maxToolRounds: options.request?.maxToolRounds,
|
|
4497
4505
|
onToolExecution: options.request?.onToolExecution,
|
|
4506
|
+
transformToolOutput: options.request?.transformToolOutput,
|
|
4507
|
+
transformToolArguments: options.request?.transformToolArguments,
|
|
4508
|
+
transformToolCallParams: options.request?.transformToolCallParams,
|
|
4509
|
+
unknownToolError: options.request?.unknownToolError,
|
|
4498
4510
|
toolDebug: options.request?.toolDebug,
|
|
4499
4511
|
body: options.request?.body,
|
|
4500
4512
|
signal: requestSignal
|
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,4 @@ export { createOpenAICompatibleAdapter, type OpenAICompatibleAdapterOptions, } f
|
|
|
14
14
|
export { createAnthropicCompatibleAdapter, DEFAULT_ANTHROPIC_MAX_TOKENS, DEFAULT_ANTHROPIC_VERSION, type AnthropicCompatibleAdapterOptions, } from "./providers/anthropic-compatible";
|
|
15
15
|
export { DEFAULT_MAX_TOOL_ROUNDS } from "./providers/mcp-runtime";
|
|
16
16
|
export { createDefaultProviderRegistry, createModelAdapter, createProviderRegistry, registerBuiltinProviders, type BuiltinProviderKind, type ModelAdapterConfig, type ProviderFactory, type ProviderRegistry, type ProviderTransportConfig, } from "./providers/registry";
|
|
17
|
-
export type { CandidateDiagnostics, EmbeddingRequest, EmbeddingResult, LLMImageContent, LLMMessageContent, LLMTextContent, ExtractJsonCandidatesOptions, ExtractionCandidate, ExtractionHeuristicsOptions, ExtractionParseHint, HTTPHeaders, LLMAdapter, LLMMessage, LLMRequest, LLMResponse, LLMStreamCallbacks, LLMStreamChunk, LLMToolCall, LLMToolCallRef, LLMToolDebugOptions, LLMToolExecution, LLMToolOutputTransformer, LLMToolArgumentsTransformer, LLMToolChoice, MCPCallToolParams, MCPListToolsResult, MCPToolClient, MCPToolDescriptor, MCPToolSchema, LLMUsage, MarkdownCodeBlock, MarkdownCodeOptions, ParseLLMOutputOptions, ParseLLMOutputResult, ParseTraceEvent, PipelineError, StructuredAttempt, StructuredCallOptions, StructuredDebugOptions, StructuredError, StructuredMode, StructuredOptions, StructuredPromptBuilder, StructuredPromptContext, StructuredPromptPayload, StructuredPromptResolver, StructuredPromptValue, StructuredResult, StructuredStreamData, StructuredStreamEvent, StructuredStreamInput, StructuredStreamOptions, StructuredSelfHealInput, StructuredTimeoutOptions, ThinkDiagnostics, ThinkBlock, StructuredTraceEvent, } from "./types";
|
|
17
|
+
export type { CandidateDiagnostics, EmbeddingRequest, EmbeddingResult, LLMImageContent, LLMMessageContent, LLMTextContent, ExtractJsonCandidatesOptions, ExtractionCandidate, ExtractionHeuristicsOptions, ExtractionParseHint, HTTPHeaders, LLMAdapter, LLMMessage, LLMRequest, LLMResponse, LLMStreamCallbacks, LLMStreamChunk, LLMToolCall, LLMToolCallRef, LLMToolDebugOptions, LLMToolExecution, LLMToolOutputTransformer, LLMToolArgumentsTransformer, LLMToolCallParamsTransformer, LLMToolChoice, MCPCallToolParams, MCPListToolsResult, MCPToolClient, MCPToolDescriptor, MCPToolSchema, LLMUsage, MarkdownCodeBlock, MarkdownCodeOptions, ParseLLMOutputOptions, ParseLLMOutputResult, ParseTraceEvent, PipelineError, StructuredAttempt, StructuredCallOptions, StructuredDebugOptions, StructuredError, StructuredMode, StructuredOptions, StructuredPromptBuilder, StructuredPromptContext, StructuredPromptPayload, StructuredPromptResolver, StructuredPromptValue, StructuredResult, StructuredStreamData, StructuredStreamEvent, StructuredStreamInput, StructuredStreamOptions, StructuredSelfHealInput, StructuredTimeoutOptions, ThinkDiagnostics, ThinkBlock, StructuredTraceEvent, } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1228,6 +1228,17 @@ async function executeMCPToolCalls(calls, toolset, context) {
|
|
|
1228
1228
|
remoteName: tool.remoteName,
|
|
1229
1229
|
clientId: tool.clientId
|
|
1230
1230
|
}) : rawArgs;
|
|
1231
|
+
const toolParams = context.request.transformToolCallParams ? await context.request.transformToolCallParams({
|
|
1232
|
+
name: tool.remoteName,
|
|
1233
|
+
arguments: args
|
|
1234
|
+
}, {
|
|
1235
|
+
name: toolName,
|
|
1236
|
+
remoteName: tool.remoteName,
|
|
1237
|
+
clientId: tool.clientId
|
|
1238
|
+
}) : {
|
|
1239
|
+
name: tool.remoteName,
|
|
1240
|
+
arguments: args
|
|
1241
|
+
};
|
|
1231
1242
|
const metadata = {
|
|
1232
1243
|
id: callId,
|
|
1233
1244
|
type: call.type ?? "function",
|
|
@@ -1237,10 +1248,7 @@ async function executeMCPToolCalls(calls, toolset, context) {
|
|
|
1237
1248
|
const startedAt = new Date().toISOString();
|
|
1238
1249
|
const startedAtMs = Date.now();
|
|
1239
1250
|
try {
|
|
1240
|
-
const output = await tool.client.callTool(
|
|
1241
|
-
name: tool.remoteName,
|
|
1242
|
-
arguments: args
|
|
1243
|
-
});
|
|
1251
|
+
const output = await tool.client.callTool(toolParams);
|
|
1244
1252
|
const executionContext = {
|
|
1245
1253
|
callId,
|
|
1246
1254
|
type: call.type ?? "function",
|
|
@@ -4406,6 +4414,10 @@ async function callModel(adapter, options) {
|
|
|
4406
4414
|
parallelToolCalls: options.request?.parallelToolCalls,
|
|
4407
4415
|
maxToolRounds: options.request?.maxToolRounds,
|
|
4408
4416
|
onToolExecution: options.request?.onToolExecution,
|
|
4417
|
+
transformToolOutput: options.request?.transformToolOutput,
|
|
4418
|
+
transformToolArguments: options.request?.transformToolArguments,
|
|
4419
|
+
transformToolCallParams: options.request?.transformToolCallParams,
|
|
4420
|
+
unknownToolError: options.request?.unknownToolError,
|
|
4409
4421
|
toolDebug: options.request?.toolDebug,
|
|
4410
4422
|
body: options.request?.body,
|
|
4411
4423
|
signal: requestSignal
|
package/dist/types.d.ts
CHANGED
|
@@ -110,6 +110,7 @@ export interface MCPListToolsResult {
|
|
|
110
110
|
export interface MCPCallToolParams {
|
|
111
111
|
name: string;
|
|
112
112
|
arguments?: Record<string, unknown>;
|
|
113
|
+
_meta?: Record<string, unknown>;
|
|
113
114
|
}
|
|
114
115
|
export interface MCPToolClient {
|
|
115
116
|
id: string;
|
|
@@ -156,6 +157,7 @@ export interface LLMRequest {
|
|
|
156
157
|
onToolExecution?: (execution: LLMToolExecution) => void;
|
|
157
158
|
transformToolOutput?: LLMToolOutputTransformer;
|
|
158
159
|
transformToolArguments?: LLMToolArgumentsTransformer;
|
|
160
|
+
transformToolCallParams?: LLMToolCallParamsTransformer;
|
|
159
161
|
unknownToolError?: (toolName: string) => string;
|
|
160
162
|
toolDebug?: boolean | LLMToolDebugOptions;
|
|
161
163
|
body?: Record<string, unknown>;
|
|
@@ -237,6 +239,11 @@ export type LLMToolArgumentsTransformer = (args: Record<string, unknown>, contex
|
|
|
237
239
|
remoteName: string;
|
|
238
240
|
clientId: string;
|
|
239
241
|
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
242
|
+
export type LLMToolCallParamsTransformer = (params: MCPCallToolParams, context: {
|
|
243
|
+
name: string;
|
|
244
|
+
remoteName: string;
|
|
245
|
+
clientId: string;
|
|
246
|
+
}) => MCPCallToolParams | Promise<MCPCallToolParams>;
|
|
240
247
|
export interface LLMToolDebugOptions {
|
|
241
248
|
enabled?: boolean;
|
|
242
249
|
logger?: (line: string) => void;
|