@mcpmesh/sdk 0.8.0-beta.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/dist/__tests__/claude-handler.test.d.ts +7 -0
- package/dist/__tests__/claude-handler.test.d.ts.map +1 -0
- package/dist/__tests__/claude-handler.test.js +455 -0
- package/dist/__tests__/claude-handler.test.js.map +1 -0
- package/dist/__tests__/config.test.d.ts +7 -0
- package/dist/__tests__/config.test.d.ts.map +1 -0
- package/dist/__tests__/config.test.js +156 -0
- package/dist/__tests__/config.test.js.map +1 -0
- package/dist/__tests__/errors.test.d.ts +7 -0
- package/dist/__tests__/errors.test.d.ts.map +1 -0
- package/dist/__tests__/errors.test.js +170 -0
- package/dist/__tests__/errors.test.js.map +1 -0
- package/dist/__tests__/generic-handler.test.d.ts +7 -0
- package/dist/__tests__/generic-handler.test.d.ts.map +1 -0
- package/dist/__tests__/generic-handler.test.js +243 -0
- package/dist/__tests__/generic-handler.test.js.map +1 -0
- package/dist/__tests__/llm-provider.test.d.ts +7 -0
- package/dist/__tests__/llm-provider.test.d.ts.map +1 -0
- package/dist/__tests__/llm-provider.test.js +217 -0
- package/dist/__tests__/llm-provider.test.js.map +1 -0
- package/dist/__tests__/openai-handler.test.d.ts +7 -0
- package/dist/__tests__/openai-handler.test.d.ts.map +1 -0
- package/dist/__tests__/openai-handler.test.js +359 -0
- package/dist/__tests__/openai-handler.test.js.map +1 -0
- package/dist/__tests__/provider-handler-registry.test.d.ts +9 -0
- package/dist/__tests__/provider-handler-registry.test.d.ts.map +1 -0
- package/dist/__tests__/provider-handler-registry.test.js +187 -0
- package/dist/__tests__/provider-handler-registry.test.js.map +1 -0
- package/dist/__tests__/response-parser.test.d.ts +7 -0
- package/dist/__tests__/response-parser.test.d.ts.map +1 -0
- package/dist/__tests__/response-parser.test.js +360 -0
- package/dist/__tests__/response-parser.test.js.map +1 -0
- package/dist/__tests__/route.test.d.ts +7 -0
- package/dist/__tests__/route.test.d.ts.map +1 -0
- package/dist/__tests__/route.test.js +281 -0
- package/dist/__tests__/route.test.js.map +1 -0
- package/dist/__tests__/sse.test.d.ts +7 -0
- package/dist/__tests__/sse.test.d.ts.map +1 -0
- package/dist/__tests__/sse.test.js +172 -0
- package/dist/__tests__/sse.test.js.map +1 -0
- package/dist/__tests__/template.test.d.ts +7 -0
- package/dist/__tests__/template.test.d.ts.map +1 -0
- package/dist/__tests__/template.test.js +176 -0
- package/dist/__tests__/template.test.js.map +1 -0
- package/dist/__tests__/tracing.test.d.ts +7 -0
- package/dist/__tests__/tracing.test.d.ts.map +1 -0
- package/dist/__tests__/tracing.test.js +264 -0
- package/dist/__tests__/tracing.test.js.map +1 -0
- package/dist/agent.d.ts +165 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +626 -0
- package/dist/agent.js.map +1 -0
- package/dist/api-runtime.d.ts +166 -0
- package/dist/api-runtime.d.ts.map +1 -0
- package/dist/api-runtime.js +459 -0
- package/dist/api-runtime.js.map +1 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/debug.d.ts +47 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +86 -0
- package/dist/debug.js.map +1 -0
- package/dist/errors.d.ts +99 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +110 -0
- package/dist/errors.js.map +1 -0
- package/dist/express.d.ts +146 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +371 -0
- package/dist/express.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/llm-agent.d.ts +193 -0
- package/dist/llm-agent.d.ts.map +1 -0
- package/dist/llm-agent.js +634 -0
- package/dist/llm-agent.js.map +1 -0
- package/dist/llm-provider.d.ts +323 -0
- package/dist/llm-provider.d.ts.map +1 -0
- package/dist/llm-provider.js +446 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/llm.d.ts +194 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +304 -0
- package/dist/llm.js.map +1 -0
- package/dist/provider-handlers/claude-handler.d.ts +98 -0
- package/dist/provider-handlers/claude-handler.d.ts.map +1 -0
- package/dist/provider-handlers/claude-handler.js +268 -0
- package/dist/provider-handlers/claude-handler.js.map +1 -0
- package/dist/provider-handlers/gemini-handler.d.ts +82 -0
- package/dist/provider-handlers/gemini-handler.d.ts.map +1 -0
- package/dist/provider-handlers/gemini-handler.js +152 -0
- package/dist/provider-handlers/gemini-handler.js.map +1 -0
- package/dist/provider-handlers/generic-handler.d.ts +78 -0
- package/dist/provider-handlers/generic-handler.d.ts.map +1 -0
- package/dist/provider-handlers/generic-handler.js +152 -0
- package/dist/provider-handlers/generic-handler.js.map +1 -0
- package/dist/provider-handlers/index.d.ts +29 -0
- package/dist/provider-handlers/index.d.ts.map +1 -0
- package/dist/provider-handlers/index.js +32 -0
- package/dist/provider-handlers/index.js.map +1 -0
- package/dist/provider-handlers/openai-handler.d.ts +86 -0
- package/dist/provider-handlers/openai-handler.d.ts.map +1 -0
- package/dist/provider-handlers/openai-handler.js +160 -0
- package/dist/provider-handlers/openai-handler.js.map +1 -0
- package/dist/provider-handlers/provider-handler-registry.d.ts +124 -0
- package/dist/provider-handlers/provider-handler-registry.d.ts.map +1 -0
- package/dist/provider-handlers/provider-handler-registry.js +180 -0
- package/dist/provider-handlers/provider-handler-registry.js.map +1 -0
- package/dist/provider-handlers/provider-handler.d.ts +245 -0
- package/dist/provider-handlers/provider-handler.d.ts.map +1 -0
- package/dist/provider-handlers/provider-handler.js +238 -0
- package/dist/provider-handlers/provider-handler.js.map +1 -0
- package/dist/proxy.d.ts +44 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +324 -0
- package/dist/proxy.js.map +1 -0
- package/dist/response-parser.d.ts +103 -0
- package/dist/response-parser.d.ts.map +1 -0
- package/dist/response-parser.js +232 -0
- package/dist/response-parser.js.map +1 -0
- package/dist/route.d.ts +185 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +310 -0
- package/dist/route.js.map +1 -0
- package/dist/sse.d.ts +45 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +77 -0
- package/dist/sse.js.map +1 -0
- package/dist/template.d.ts +86 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +206 -0
- package/dist/template.js.map +1 -0
- package/dist/tracing.d.ts +88 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +193 -0
- package/dist/tracing.js.map +1 -0
- package/dist/types.d.ts +618 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base provider handler interface for vendor-specific LLM behavior.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the interface for provider-specific handlers
|
|
5
|
+
* that customize how different LLM vendors (Claude, OpenAI, Gemini, etc.) are called.
|
|
6
|
+
*
|
|
7
|
+
* Based on Python's BaseProviderHandler:
|
|
8
|
+
* src/runtime/python/_mcp_mesh/engine/provider_handlers/base_provider_handler.py
|
|
9
|
+
*/
|
|
10
|
+
import type { LlmMessage } from "../types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Output mode for structured responses.
|
|
13
|
+
*
|
|
14
|
+
* - strict: Use response_format for guaranteed schema compliance (slowest, 100% reliable)
|
|
15
|
+
* - hint: Use prompt-based JSON instructions (medium speed, ~95% reliable)
|
|
16
|
+
* - text: Plain text output for string return types (fastest)
|
|
17
|
+
*/
|
|
18
|
+
export type OutputMode = "strict" | "hint" | "text";
|
|
19
|
+
/**
|
|
20
|
+
* Vendor capability flags.
|
|
21
|
+
*/
|
|
22
|
+
export interface VendorCapabilities {
|
|
23
|
+
/** Native function/tool calling support */
|
|
24
|
+
nativeToolCalling: boolean;
|
|
25
|
+
/** Native structured output via response_format */
|
|
26
|
+
structuredOutput: boolean;
|
|
27
|
+
/** Streaming response support */
|
|
28
|
+
streaming: boolean;
|
|
29
|
+
/** Vision/image input support */
|
|
30
|
+
vision: boolean;
|
|
31
|
+
/** JSON mode via response_format */
|
|
32
|
+
jsonMode: boolean;
|
|
33
|
+
/** Prompt caching support (Claude) */
|
|
34
|
+
promptCaching?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Tool schema in OpenAI format.
|
|
38
|
+
*/
|
|
39
|
+
export interface ToolSchema {
|
|
40
|
+
type: "function";
|
|
41
|
+
function: {
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
parameters?: Record<string, unknown>;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Prepared request parameters for the LLM API.
|
|
49
|
+
*/
|
|
50
|
+
export interface PreparedRequest {
|
|
51
|
+
/** Messages to send (may be transformed) */
|
|
52
|
+
messages: LlmMessage[];
|
|
53
|
+
/** Tools in vendor-specific format (if provided) */
|
|
54
|
+
tools?: ToolSchema[];
|
|
55
|
+
/** Response format configuration (for structured output) */
|
|
56
|
+
responseFormat?: {
|
|
57
|
+
type: "json_schema";
|
|
58
|
+
jsonSchema: {
|
|
59
|
+
name: string;
|
|
60
|
+
schema: Record<string, unknown>;
|
|
61
|
+
strict?: boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/** Additional vendor-specific parameters */
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* JSON Schema for output type validation.
|
|
69
|
+
*/
|
|
70
|
+
export interface OutputSchema {
|
|
71
|
+
/** Schema name (typically the type name) */
|
|
72
|
+
name: string;
|
|
73
|
+
/** JSON Schema definition */
|
|
74
|
+
schema: Record<string, unknown>;
|
|
75
|
+
/** Number of fields in the schema */
|
|
76
|
+
fieldCount?: number;
|
|
77
|
+
/** Whether the schema has nested objects */
|
|
78
|
+
hasNestedObjects?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* AI SDK v6 tool result output format.
|
|
82
|
+
*/
|
|
83
|
+
export interface ToolResultOutput {
|
|
84
|
+
type: "text" | "json";
|
|
85
|
+
value: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Wrap tool result content in AI SDK v6 ToolResultOutput format.
|
|
89
|
+
*
|
|
90
|
+
* AI SDK v6 requires tool result output to be structured as:
|
|
91
|
+
* - { type: 'text', value: string } for text content
|
|
92
|
+
* - { type: 'json', value: JSONValue } for JSON content
|
|
93
|
+
*
|
|
94
|
+
* @param content - Raw tool result content (string)
|
|
95
|
+
* @returns Properly formatted ToolResultOutput
|
|
96
|
+
*/
|
|
97
|
+
export declare function wrapToolResultOutput(content: string | null | undefined): ToolResultOutput;
|
|
98
|
+
/**
|
|
99
|
+
* Convert messages to Vercel AI SDK format for multi-turn tool conversations.
|
|
100
|
+
*
|
|
101
|
+
* Both Anthropic and OpenAI require specific message formats for tool calls:
|
|
102
|
+
* - Assistant messages with tool_calls → content array with "tool-call" parts
|
|
103
|
+
* - Tool result messages → content array with "tool-result" parts
|
|
104
|
+
*
|
|
105
|
+
* This conversion ensures Vercel AI SDK properly converts to each provider's native format.
|
|
106
|
+
*
|
|
107
|
+
* @param messages - Messages in OpenAI-style format (from mesh network)
|
|
108
|
+
* @returns Messages in Vercel AI SDK format
|
|
109
|
+
*/
|
|
110
|
+
export declare function convertMessagesToVercelFormat(messages: LlmMessage[]): LlmMessage[];
|
|
111
|
+
/**
|
|
112
|
+
* Base tool calling instructions shared across all providers.
|
|
113
|
+
*
|
|
114
|
+
* Claude handler adds anti-XML instruction on top of this.
|
|
115
|
+
*/
|
|
116
|
+
export declare const BASE_TOOL_INSTRUCTIONS = "\nIMPORTANT TOOL CALLING RULES:\n- You have access to tools that you can call to gather information\n- Make ONE tool call at a time\n- After receiving tool results, you can make additional calls if needed\n- Once you have all needed information, provide your final response\n";
|
|
117
|
+
/**
|
|
118
|
+
* Anti-XML instruction for Claude (prevents <invoke> style tool calls).
|
|
119
|
+
*/
|
|
120
|
+
export declare const CLAUDE_ANTI_XML_INSTRUCTION = "- NEVER use XML-style syntax like <invoke name=\"tool_name\"/>";
|
|
121
|
+
/**
|
|
122
|
+
* Options for making a schema strict.
|
|
123
|
+
*/
|
|
124
|
+
export interface MakeSchemaStrictOptions {
|
|
125
|
+
/**
|
|
126
|
+
* If true, set 'required' to include ALL property keys.
|
|
127
|
+
* OpenAI and Gemini require this; Claude does not.
|
|
128
|
+
* Default: true
|
|
129
|
+
*/
|
|
130
|
+
addAllRequired?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Make a JSON schema strict for structured output.
|
|
134
|
+
*
|
|
135
|
+
* This is a shared utility used by OpenAI, Gemini, and Claude handlers.
|
|
136
|
+
* Adds additionalProperties: false to all object types and optionally
|
|
137
|
+
* ensures 'required' includes all property keys.
|
|
138
|
+
*
|
|
139
|
+
* @param schema - JSON schema to make strict
|
|
140
|
+
* @param options - Configuration options
|
|
141
|
+
* @returns New schema with strict constraints (original not mutated)
|
|
142
|
+
*/
|
|
143
|
+
export declare function makeSchemaStrict(schema: Record<string, unknown>, options?: MakeSchemaStrictOptions): Record<string, unknown>;
|
|
144
|
+
/**
|
|
145
|
+
* Default implementation of determineOutputMode.
|
|
146
|
+
*
|
|
147
|
+
* Most providers (OpenAI, Gemini) use strict mode for schemas.
|
|
148
|
+
* Claude overrides this with more sophisticated logic.
|
|
149
|
+
*
|
|
150
|
+
* @param outputSchema - The output schema (null for string return type)
|
|
151
|
+
* @param overrideMode - Optional explicit mode override
|
|
152
|
+
* @returns The determined output mode
|
|
153
|
+
*/
|
|
154
|
+
export declare function defaultDetermineOutputMode(outputSchema: OutputSchema | null, overrideMode?: OutputMode): OutputMode;
|
|
155
|
+
/**
|
|
156
|
+
* Interface for provider-specific LLM handlers.
|
|
157
|
+
*
|
|
158
|
+
* Each vendor (Claude, OpenAI, Gemini, etc.) can have its own handler
|
|
159
|
+
* that customizes request preparation, system prompt formatting, and
|
|
160
|
+
* response parsing to work optimally with that vendor's API.
|
|
161
|
+
*
|
|
162
|
+
* Handler Selection:
|
|
163
|
+
* The ProviderHandlerRegistry selects handlers based on the vendor
|
|
164
|
+
* extracted from the model string (e.g., "anthropic/claude-sonnet-4-5" → "anthropic").
|
|
165
|
+
*
|
|
166
|
+
* Extensibility:
|
|
167
|
+
* New handlers can be added by:
|
|
168
|
+
* 1. Implementing ProviderHandler interface
|
|
169
|
+
* 2. Registering in ProviderHandlerRegistry
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* class MyHandler implements ProviderHandler {
|
|
174
|
+
* readonly vendor = "myvendor";
|
|
175
|
+
*
|
|
176
|
+
* prepareRequest(messages, tools, outputSchema, options) {
|
|
177
|
+
* return { messages, tools, ...vendorSpecificParams };
|
|
178
|
+
* }
|
|
179
|
+
*
|
|
180
|
+
* formatSystemPrompt(basePrompt, toolSchemas, outputSchema) {
|
|
181
|
+
* return basePrompt + "\n\nVendor-specific instructions...";
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* getCapabilities() {
|
|
185
|
+
* return { nativeToolCalling: true, structuredOutput: true, ... };
|
|
186
|
+
* }
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export interface ProviderHandler {
|
|
191
|
+
/** Vendor name (e.g., "anthropic", "openai", "google") */
|
|
192
|
+
readonly vendor: string;
|
|
193
|
+
/**
|
|
194
|
+
* Prepare vendor-specific request parameters.
|
|
195
|
+
*
|
|
196
|
+
* This method allows customization of the request sent to the LLM provider.
|
|
197
|
+
* For example:
|
|
198
|
+
* - Claude: Add cache_control for prompt caching
|
|
199
|
+
* - OpenAI: Add response_format for structured output
|
|
200
|
+
* - Gemini: Add generation config
|
|
201
|
+
*
|
|
202
|
+
* @param messages - List of messages to send
|
|
203
|
+
* @param tools - Optional list of tool schemas (OpenAI format)
|
|
204
|
+
* @param outputSchema - Optional schema for expected response
|
|
205
|
+
* @param options - Additional options (outputMode, temperature, etc.)
|
|
206
|
+
* @returns Prepared request parameters
|
|
207
|
+
*/
|
|
208
|
+
prepareRequest(messages: LlmMessage[], tools: ToolSchema[] | null, outputSchema: OutputSchema | null, options?: {
|
|
209
|
+
outputMode?: OutputMode;
|
|
210
|
+
temperature?: number;
|
|
211
|
+
maxOutputTokens?: number;
|
|
212
|
+
topP?: number;
|
|
213
|
+
[key: string]: unknown;
|
|
214
|
+
}): PreparedRequest;
|
|
215
|
+
/**
|
|
216
|
+
* Format system prompt for vendor-specific requirements.
|
|
217
|
+
*
|
|
218
|
+
* Different vendors have different best practices for system prompts:
|
|
219
|
+
* - Claude: Prefers detailed instructions, handles XML well, needs anti-XML for tools
|
|
220
|
+
* - OpenAI: Structured output mode makes JSON instructions optional
|
|
221
|
+
* - Gemini: System instructions separate from messages
|
|
222
|
+
*
|
|
223
|
+
* @param basePrompt - Base system prompt (from template or config)
|
|
224
|
+
* @param toolSchemas - Optional list of tool schemas (if tools available)
|
|
225
|
+
* @param outputSchema - Optional schema for response validation
|
|
226
|
+
* @param outputMode - Optional override for output mode
|
|
227
|
+
* @returns Formatted system prompt string optimized for this vendor
|
|
228
|
+
*/
|
|
229
|
+
formatSystemPrompt(basePrompt: string, toolSchemas: ToolSchema[] | null, outputSchema: OutputSchema | null, outputMode?: OutputMode): string;
|
|
230
|
+
/**
|
|
231
|
+
* Get vendor-specific capability flags.
|
|
232
|
+
*
|
|
233
|
+
* @returns Dictionary of capability flags
|
|
234
|
+
*/
|
|
235
|
+
getCapabilities(): VendorCapabilities;
|
|
236
|
+
/**
|
|
237
|
+
* Determine the optimal output mode based on schema complexity.
|
|
238
|
+
*
|
|
239
|
+
* @param outputSchema - The output schema (null for string return type)
|
|
240
|
+
* @param overrideMode - Optional explicit mode override
|
|
241
|
+
* @returns The determined output mode
|
|
242
|
+
*/
|
|
243
|
+
determineOutputMode(outputSchema: OutputSchema | null, overrideMode?: OutputMode): OutputMode;
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=provider-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-handler.d.ts","sourceRoot":"","sources":["../../src/provider-handlers/provider-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQ9C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,iBAAiB,EAAE,OAAO,CAAC;IAC3B,mDAAmD;IACnD,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iCAAiC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,iCAAiC;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,oDAAoD;IACpD,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,4DAA4D;IAC5D,cAAc,CAAC,EAAE;QACf,IAAI,EAAE,aAAa,CAAC;QACpB,UAAU,EAAE;YACV,IAAI,EAAE,MAAM,CAAC;YACb,MA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,IAAI,EACjC,YAAY,CAAC,EAAE,UAAU,GACxB,UAAU,CAaZ;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;;;;;;;;OAcG;IACH,cAAc,CACZ,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,EAC1B,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,GACA,eAAe,CAAC;IAEnB;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,EAChC,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,UAAU,CAAC,EAAE,UAAU,GACtB,MAAM,CAAC;IAEV;;;;OAIG;IACH,eAAe,IAAI,kBAAkB,CAAC;IAEtC;;;;;;OAMG;IACH,mBAAmB,CACjB,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,YAAY,CAAC,EAAE,UAAU,GACxB,UAAU,CAAC;CACf"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base provider handler interface for vendor-specific LLM behavior.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the interface for provider-specific handlers
|
|
5
|
+
* that customize how different LLM vendors (Claude, OpenAI, Gemini, etc.) are called.
|
|
6
|
+
*
|
|
7
|
+
* Based on Python's BaseProviderHandler:
|
|
8
|
+
* src/runtime/python/_mcp_mesh/engine/provider_handlers/base_provider_handler.py
|
|
9
|
+
*/
|
|
10
|
+
import { createDebug } from "../debug.js";
|
|
11
|
+
const debug = createDebug("provider-handler");
|
|
12
|
+
/**
|
|
13
|
+
* Wrap tool result content in AI SDK v6 ToolResultOutput format.
|
|
14
|
+
*
|
|
15
|
+
* AI SDK v6 requires tool result output to be structured as:
|
|
16
|
+
* - { type: 'text', value: string } for text content
|
|
17
|
+
* - { type: 'json', value: JSONValue } for JSON content
|
|
18
|
+
*
|
|
19
|
+
* @param content - Raw tool result content (string)
|
|
20
|
+
* @returns Properly formatted ToolResultOutput
|
|
21
|
+
*/
|
|
22
|
+
export function wrapToolResultOutput(content) {
|
|
23
|
+
if (content === null || content === undefined || content === "") {
|
|
24
|
+
return { type: "text", value: "" };
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(content);
|
|
28
|
+
// JSON-parsed strings should use text type
|
|
29
|
+
if (typeof parsed === "string") {
|
|
30
|
+
return { type: "text", value: parsed };
|
|
31
|
+
}
|
|
32
|
+
// null/undefined from JSON.parse should use text
|
|
33
|
+
if (parsed === null || parsed === undefined) {
|
|
34
|
+
return { type: "text", value: content };
|
|
35
|
+
}
|
|
36
|
+
// Objects, arrays, numbers, booleans use json type
|
|
37
|
+
return { type: "json", value: parsed };
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Not valid JSON - treat as text
|
|
41
|
+
return { type: "text", value: content };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convert messages to Vercel AI SDK format for multi-turn tool conversations.
|
|
46
|
+
*
|
|
47
|
+
* Both Anthropic and OpenAI require specific message formats for tool calls:
|
|
48
|
+
* - Assistant messages with tool_calls → content array with "tool-call" parts
|
|
49
|
+
* - Tool result messages → content array with "tool-result" parts
|
|
50
|
+
*
|
|
51
|
+
* This conversion ensures Vercel AI SDK properly converts to each provider's native format.
|
|
52
|
+
*
|
|
53
|
+
* @param messages - Messages in OpenAI-style format (from mesh network)
|
|
54
|
+
* @returns Messages in Vercel AI SDK format
|
|
55
|
+
*/
|
|
56
|
+
export function convertMessagesToVercelFormat(messages) {
|
|
57
|
+
return messages.map((msg) => {
|
|
58
|
+
// System and user messages pass through
|
|
59
|
+
if (msg.role === "system" || msg.role === "user") {
|
|
60
|
+
return {
|
|
61
|
+
role: msg.role,
|
|
62
|
+
content: msg.content ?? "",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Assistant messages - convert tool_calls to content blocks
|
|
66
|
+
if (msg.role === "assistant") {
|
|
67
|
+
const hasToolCalls = msg.tool_calls && msg.tool_calls.length > 0;
|
|
68
|
+
if (!hasToolCalls) {
|
|
69
|
+
return {
|
|
70
|
+
role: "assistant",
|
|
71
|
+
content: msg.content ?? "",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// For tool calls, use content blocks format
|
|
75
|
+
// This is what Vercel AI SDK expects for proper provider conversion
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const contentParts = [];
|
|
78
|
+
// Add text content if present
|
|
79
|
+
if (msg.content) {
|
|
80
|
+
contentParts.push({ type: "text", text: msg.content });
|
|
81
|
+
}
|
|
82
|
+
// Add tool calls as content blocks
|
|
83
|
+
// AI SDK v6 uses 'input' instead of 'args' for tool call parameters
|
|
84
|
+
for (const tc of msg.tool_calls) {
|
|
85
|
+
// Parse arguments with fallback for malformed JSON
|
|
86
|
+
let input = {};
|
|
87
|
+
try {
|
|
88
|
+
input = JSON.parse(tc.function.arguments);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
debug(`Failed to parse tool call arguments for ${tc.function.name}: ${err}. Using empty object.`);
|
|
92
|
+
}
|
|
93
|
+
contentParts.push({
|
|
94
|
+
type: "tool-call",
|
|
95
|
+
toolCallId: tc.id,
|
|
96
|
+
toolName: tc.function.name,
|
|
97
|
+
input,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
role: "assistant",
|
|
102
|
+
content: contentParts,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Tool result messages - convert to content blocks with tool-result type
|
|
106
|
+
if (msg.role === "tool") {
|
|
107
|
+
return {
|
|
108
|
+
role: "tool",
|
|
109
|
+
content: [{
|
|
110
|
+
type: "tool-result",
|
|
111
|
+
toolCallId: msg.tool_call_id ?? "",
|
|
112
|
+
toolName: msg.name ?? "",
|
|
113
|
+
output: wrapToolResultOutput(msg.content),
|
|
114
|
+
}],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Fallback - return as-is
|
|
118
|
+
return msg;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Shared Constants
|
|
123
|
+
// ============================================================================
|
|
124
|
+
/**
|
|
125
|
+
* Base tool calling instructions shared across all providers.
|
|
126
|
+
*
|
|
127
|
+
* Claude handler adds anti-XML instruction on top of this.
|
|
128
|
+
*/
|
|
129
|
+
export const BASE_TOOL_INSTRUCTIONS = `
|
|
130
|
+
IMPORTANT TOOL CALLING RULES:
|
|
131
|
+
- You have access to tools that you can call to gather information
|
|
132
|
+
- Make ONE tool call at a time
|
|
133
|
+
- After receiving tool results, you can make additional calls if needed
|
|
134
|
+
- Once you have all needed information, provide your final response
|
|
135
|
+
`;
|
|
136
|
+
/**
|
|
137
|
+
* Anti-XML instruction for Claude (prevents <invoke> style tool calls).
|
|
138
|
+
*/
|
|
139
|
+
export const CLAUDE_ANTI_XML_INSTRUCTION = `- NEVER use XML-style syntax like <invoke name="tool_name"/>`;
|
|
140
|
+
/**
|
|
141
|
+
* Make a JSON schema strict for structured output.
|
|
142
|
+
*
|
|
143
|
+
* This is a shared utility used by OpenAI, Gemini, and Claude handlers.
|
|
144
|
+
* Adds additionalProperties: false to all object types and optionally
|
|
145
|
+
* ensures 'required' includes all property keys.
|
|
146
|
+
*
|
|
147
|
+
* @param schema - JSON schema to make strict
|
|
148
|
+
* @param options - Configuration options
|
|
149
|
+
* @returns New schema with strict constraints (original not mutated)
|
|
150
|
+
*/
|
|
151
|
+
export function makeSchemaStrict(schema, options = {}) {
|
|
152
|
+
const { addAllRequired = true } = options;
|
|
153
|
+
// Deep clone to avoid mutating original
|
|
154
|
+
const result = JSON.parse(JSON.stringify(schema));
|
|
155
|
+
addStrictConstraintsRecursive(result, addAllRequired);
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Recursively add strict constraints to a schema object.
|
|
160
|
+
*
|
|
161
|
+
* @param obj - Schema object to process (mutated in place)
|
|
162
|
+
* @param addAllRequired - Whether to set required to all property keys
|
|
163
|
+
*/
|
|
164
|
+
function addStrictConstraintsRecursive(obj, addAllRequired) {
|
|
165
|
+
if (typeof obj !== "object" || obj === null) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const record = obj;
|
|
169
|
+
// If this is an object type, add additionalProperties: false
|
|
170
|
+
if (record.type === "object") {
|
|
171
|
+
record.additionalProperties = false;
|
|
172
|
+
// Optionally set required to include all property keys
|
|
173
|
+
if (addAllRequired && record.properties && typeof record.properties === "object") {
|
|
174
|
+
record.required = Object.keys(record.properties);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Process $defs (used for nested models)
|
|
178
|
+
if (record.$defs && typeof record.$defs === "object") {
|
|
179
|
+
for (const defSchema of Object.values(record.$defs)) {
|
|
180
|
+
addStrictConstraintsRecursive(defSchema, addAllRequired);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Process properties
|
|
184
|
+
if (record.properties && typeof record.properties === "object") {
|
|
185
|
+
for (const propSchema of Object.values(record.properties)) {
|
|
186
|
+
addStrictConstraintsRecursive(propSchema, addAllRequired);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Process items (for arrays)
|
|
190
|
+
// items can be an object (single schema) or an array (tuple validation in older drafts)
|
|
191
|
+
if (record.items) {
|
|
192
|
+
if (Array.isArray(record.items)) {
|
|
193
|
+
for (const item of record.items) {
|
|
194
|
+
addStrictConstraintsRecursive(item, addAllRequired);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
addStrictConstraintsRecursive(record.items, addAllRequired);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Process prefixItems (tuple validation in JSON Schema draft 2020-12)
|
|
202
|
+
if (Array.isArray(record.prefixItems)) {
|
|
203
|
+
for (const item of record.prefixItems) {
|
|
204
|
+
addStrictConstraintsRecursive(item, addAllRequired);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Process anyOf, oneOf, allOf
|
|
208
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
209
|
+
if (Array.isArray(record[key])) {
|
|
210
|
+
for (const item of record[key]) {
|
|
211
|
+
addStrictConstraintsRecursive(item, addAllRequired);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Default implementation of determineOutputMode.
|
|
218
|
+
*
|
|
219
|
+
* Most providers (OpenAI, Gemini) use strict mode for schemas.
|
|
220
|
+
* Claude overrides this with more sophisticated logic.
|
|
221
|
+
*
|
|
222
|
+
* @param outputSchema - The output schema (null for string return type)
|
|
223
|
+
* @param overrideMode - Optional explicit mode override
|
|
224
|
+
* @returns The determined output mode
|
|
225
|
+
*/
|
|
226
|
+
export function defaultDetermineOutputMode(outputSchema, overrideMode) {
|
|
227
|
+
// Allow explicit override
|
|
228
|
+
if (overrideMode) {
|
|
229
|
+
return overrideMode;
|
|
230
|
+
}
|
|
231
|
+
// No schema means text mode
|
|
232
|
+
if (!outputSchema) {
|
|
233
|
+
return "text";
|
|
234
|
+
}
|
|
235
|
+
// Default: use strict mode for schemas
|
|
236
|
+
return "strict";
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=provider-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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,CAAC;QACH,CAAC;aAAM,CAAC;YACN,6BAA6B,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,WAAwB,EAAE,CAAC;YACnD,6BAA6B,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,8BAA8B;IAC9B,KAAK,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,EAAE,CAAC;QACvD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,GAAG,CAAc,EAAE,CAAC;gBAC5C,6BAA6B,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,YAAiC,EACjC,YAAyB;IAEzB,0BAA0B;IAC1B,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,4BAA4B;IAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uCAAuC;IACvC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Mesh proxy implementation for dependency injection.
|
|
3
|
+
*
|
|
4
|
+
* Provides HTTP client proxies for calling remote MCP agents.
|
|
5
|
+
*/
|
|
6
|
+
import type { McpMeshAgent, DependencyKwargs } from "./types.js";
|
|
7
|
+
import type { TraceContext } from "./tracing.js";
|
|
8
|
+
/**
|
|
9
|
+
* Run a function with trace context.
|
|
10
|
+
* The context is automatically propagated to all async operations within the callback.
|
|
11
|
+
* This is the preferred way to set trace context for tool execution.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runWithTraceContext<T>(ctx: TraceContext, fn: () => T | Promise<T>): T | Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current trace context.
|
|
16
|
+
* Returns the trace context for the current async execution context,
|
|
17
|
+
* or null if not within a traced context.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCurrentTraceContext(): TraceContext | null;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use runWithTraceContext() instead for async-safe context propagation.
|
|
22
|
+
* This function is kept for backward compatibility but does nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setCurrentTraceContext(_ctx: TraceContext | null): void;
|
|
25
|
+
/**
|
|
26
|
+
* Create an McpMeshAgent proxy for a resolved dependency.
|
|
27
|
+
*
|
|
28
|
+
* The returned object is callable (invokes the bound function)
|
|
29
|
+
* and also has methods for calling other tools on the agent.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createProxy(endpoint: string, capability: string, functionName: string, kwargs?: DependencyKwargs): McpMeshAgent;
|
|
32
|
+
/**
|
|
33
|
+
* Normalize a DependencySpec to canonical form.
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeDependency(dep: string | {
|
|
36
|
+
capability: string;
|
|
37
|
+
tags?: string[];
|
|
38
|
+
version?: string;
|
|
39
|
+
}): {
|
|
40
|
+
capability: string;
|
|
41
|
+
tags: string[];
|
|
42
|
+
version?: string;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAcjD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEhB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,GAAG,IAAI,CAE5D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAGtE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,gBAAgB,GACxB,YAAY,CAyCd;AAgSD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAS1D"}
|