@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.
Files changed (145) hide show
  1. package/dist/__tests__/claude-handler.test.d.ts +7 -0
  2. package/dist/__tests__/claude-handler.test.d.ts.map +1 -0
  3. package/dist/__tests__/claude-handler.test.js +455 -0
  4. package/dist/__tests__/claude-handler.test.js.map +1 -0
  5. package/dist/__tests__/config.test.d.ts +7 -0
  6. package/dist/__tests__/config.test.d.ts.map +1 -0
  7. package/dist/__tests__/config.test.js +156 -0
  8. package/dist/__tests__/config.test.js.map +1 -0
  9. package/dist/__tests__/errors.test.d.ts +7 -0
  10. package/dist/__tests__/errors.test.d.ts.map +1 -0
  11. package/dist/__tests__/errors.test.js +170 -0
  12. package/dist/__tests__/errors.test.js.map +1 -0
  13. package/dist/__tests__/generic-handler.test.d.ts +7 -0
  14. package/dist/__tests__/generic-handler.test.d.ts.map +1 -0
  15. package/dist/__tests__/generic-handler.test.js +243 -0
  16. package/dist/__tests__/generic-handler.test.js.map +1 -0
  17. package/dist/__tests__/llm-provider.test.d.ts +7 -0
  18. package/dist/__tests__/llm-provider.test.d.ts.map +1 -0
  19. package/dist/__tests__/llm-provider.test.js +217 -0
  20. package/dist/__tests__/llm-provider.test.js.map +1 -0
  21. package/dist/__tests__/openai-handler.test.d.ts +7 -0
  22. package/dist/__tests__/openai-handler.test.d.ts.map +1 -0
  23. package/dist/__tests__/openai-handler.test.js +359 -0
  24. package/dist/__tests__/openai-handler.test.js.map +1 -0
  25. package/dist/__tests__/provider-handler-registry.test.d.ts +9 -0
  26. package/dist/__tests__/provider-handler-registry.test.d.ts.map +1 -0
  27. package/dist/__tests__/provider-handler-registry.test.js +187 -0
  28. package/dist/__tests__/provider-handler-registry.test.js.map +1 -0
  29. package/dist/__tests__/response-parser.test.d.ts +7 -0
  30. package/dist/__tests__/response-parser.test.d.ts.map +1 -0
  31. package/dist/__tests__/response-parser.test.js +360 -0
  32. package/dist/__tests__/response-parser.test.js.map +1 -0
  33. package/dist/__tests__/route.test.d.ts +7 -0
  34. package/dist/__tests__/route.test.d.ts.map +1 -0
  35. package/dist/__tests__/route.test.js +281 -0
  36. package/dist/__tests__/route.test.js.map +1 -0
  37. package/dist/__tests__/sse.test.d.ts +7 -0
  38. package/dist/__tests__/sse.test.d.ts.map +1 -0
  39. package/dist/__tests__/sse.test.js +172 -0
  40. package/dist/__tests__/sse.test.js.map +1 -0
  41. package/dist/__tests__/template.test.d.ts +7 -0
  42. package/dist/__tests__/template.test.d.ts.map +1 -0
  43. package/dist/__tests__/template.test.js +176 -0
  44. package/dist/__tests__/template.test.js.map +1 -0
  45. package/dist/__tests__/tracing.test.d.ts +7 -0
  46. package/dist/__tests__/tracing.test.d.ts.map +1 -0
  47. package/dist/__tests__/tracing.test.js +264 -0
  48. package/dist/__tests__/tracing.test.js.map +1 -0
  49. package/dist/agent.d.ts +165 -0
  50. package/dist/agent.d.ts.map +1 -0
  51. package/dist/agent.js +626 -0
  52. package/dist/agent.js.map +1 -0
  53. package/dist/api-runtime.d.ts +166 -0
  54. package/dist/api-runtime.d.ts.map +1 -0
  55. package/dist/api-runtime.js +459 -0
  56. package/dist/api-runtime.js.map +1 -0
  57. package/dist/config.d.ts +31 -0
  58. package/dist/config.d.ts.map +1 -0
  59. package/dist/config.js +60 -0
  60. package/dist/config.js.map +1 -0
  61. package/dist/debug.d.ts +47 -0
  62. package/dist/debug.d.ts.map +1 -0
  63. package/dist/debug.js +86 -0
  64. package/dist/debug.js.map +1 -0
  65. package/dist/errors.d.ts +99 -0
  66. package/dist/errors.d.ts.map +1 -0
  67. package/dist/errors.js +110 -0
  68. package/dist/errors.js.map +1 -0
  69. package/dist/express.d.ts +146 -0
  70. package/dist/express.d.ts.map +1 -0
  71. package/dist/express.js +371 -0
  72. package/dist/express.js.map +1 -0
  73. package/dist/index.d.ts +96 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +107 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/llm-agent.d.ts +193 -0
  78. package/dist/llm-agent.d.ts.map +1 -0
  79. package/dist/llm-agent.js +634 -0
  80. package/dist/llm-agent.js.map +1 -0
  81. package/dist/llm-provider.d.ts +323 -0
  82. package/dist/llm-provider.d.ts.map +1 -0
  83. package/dist/llm-provider.js +446 -0
  84. package/dist/llm-provider.js.map +1 -0
  85. package/dist/llm.d.ts +194 -0
  86. package/dist/llm.d.ts.map +1 -0
  87. package/dist/llm.js +304 -0
  88. package/dist/llm.js.map +1 -0
  89. package/dist/provider-handlers/claude-handler.d.ts +98 -0
  90. package/dist/provider-handlers/claude-handler.d.ts.map +1 -0
  91. package/dist/provider-handlers/claude-handler.js +268 -0
  92. package/dist/provider-handlers/claude-handler.js.map +1 -0
  93. package/dist/provider-handlers/gemini-handler.d.ts +82 -0
  94. package/dist/provider-handlers/gemini-handler.d.ts.map +1 -0
  95. package/dist/provider-handlers/gemini-handler.js +152 -0
  96. package/dist/provider-handlers/gemini-handler.js.map +1 -0
  97. package/dist/provider-handlers/generic-handler.d.ts +78 -0
  98. package/dist/provider-handlers/generic-handler.d.ts.map +1 -0
  99. package/dist/provider-handlers/generic-handler.js +152 -0
  100. package/dist/provider-handlers/generic-handler.js.map +1 -0
  101. package/dist/provider-handlers/index.d.ts +29 -0
  102. package/dist/provider-handlers/index.d.ts.map +1 -0
  103. package/dist/provider-handlers/index.js +32 -0
  104. package/dist/provider-handlers/index.js.map +1 -0
  105. package/dist/provider-handlers/openai-handler.d.ts +86 -0
  106. package/dist/provider-handlers/openai-handler.d.ts.map +1 -0
  107. package/dist/provider-handlers/openai-handler.js +160 -0
  108. package/dist/provider-handlers/openai-handler.js.map +1 -0
  109. package/dist/provider-handlers/provider-handler-registry.d.ts +124 -0
  110. package/dist/provider-handlers/provider-handler-registry.d.ts.map +1 -0
  111. package/dist/provider-handlers/provider-handler-registry.js +180 -0
  112. package/dist/provider-handlers/provider-handler-registry.js.map +1 -0
  113. package/dist/provider-handlers/provider-handler.d.ts +245 -0
  114. package/dist/provider-handlers/provider-handler.d.ts.map +1 -0
  115. package/dist/provider-handlers/provider-handler.js +238 -0
  116. package/dist/provider-handlers/provider-handler.js.map +1 -0
  117. package/dist/proxy.d.ts +44 -0
  118. package/dist/proxy.d.ts.map +1 -0
  119. package/dist/proxy.js +324 -0
  120. package/dist/proxy.js.map +1 -0
  121. package/dist/response-parser.d.ts +103 -0
  122. package/dist/response-parser.d.ts.map +1 -0
  123. package/dist/response-parser.js +232 -0
  124. package/dist/response-parser.js.map +1 -0
  125. package/dist/route.d.ts +185 -0
  126. package/dist/route.d.ts.map +1 -0
  127. package/dist/route.js +310 -0
  128. package/dist/route.js.map +1 -0
  129. package/dist/sse.d.ts +45 -0
  130. package/dist/sse.d.ts.map +1 -0
  131. package/dist/sse.js +77 -0
  132. package/dist/sse.js.map +1 -0
  133. package/dist/template.d.ts +86 -0
  134. package/dist/template.d.ts.map +1 -0
  135. package/dist/template.js +206 -0
  136. package/dist/template.js.map +1 -0
  137. package/dist/tracing.d.ts +88 -0
  138. package/dist/tracing.d.ts.map +1 -0
  139. package/dist/tracing.js +193 -0
  140. package/dist/tracing.js.map +1 -0
  141. package/dist/types.d.ts +618 -0
  142. package/dist/types.d.ts.map +1 -0
  143. package/dist/types.js +5 -0
  144. package/dist/types.js.map +1 -0
  145. package/package.json +68 -0
@@ -0,0 +1,323 @@
1
+ /**
2
+ * LLM Provider implementation for @mcpmesh/sdk.
3
+ *
4
+ * Provides mesh.llmProvider() for zero-code LLM providers using Vercel AI SDK.
5
+ * This is the TypeScript equivalent of Python's @mesh.llm_provider decorator.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { FastMCP } from "fastmcp";
10
+ * import { mesh } from "@mcpmesh/sdk";
11
+ *
12
+ * const server = new FastMCP({ name: "Claude Provider", version: "1.0.0" });
13
+ *
14
+ * // Zero-code LLM provider
15
+ * server.addTool(mesh.llmProvider({
16
+ * model: "anthropic/claude-sonnet-4-5",
17
+ * capability: "llm",
18
+ * tags: ["llm", "claude", "anthropic", "provider"],
19
+ * }));
20
+ *
21
+ * const agent = mesh(server, { name: "claude-provider", port: 9011 });
22
+ * ```
23
+ */
24
+ import { z } from "zod";
25
+ import type { LlmProviderConfig } from "./types.js";
26
+ /**
27
+ * Extract vendor name from model string.
28
+ *
29
+ * Uses vendor/model format (e.g., "anthropic/claude-sonnet-4-5" → "anthropic").
30
+ *
31
+ * @param model - Model string (e.g., "anthropic/claude-sonnet-4-5")
32
+ * @returns Vendor name or null if not extractable
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * extractVendorFromModel("anthropic/claude-sonnet-4-5") // "anthropic"
37
+ * extractVendorFromModel("openai/gpt-4o") // "openai"
38
+ * extractVendorFromModel("gpt-4") // null
39
+ * ```
40
+ */
41
+ export declare function extractVendorFromModel(model: string): string | null;
42
+ /**
43
+ * Extract model name without vendor prefix.
44
+ *
45
+ * @param model - Model string (e.g., "anthropic/claude-sonnet-4-5")
46
+ * @returns Model name without vendor prefix
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * extractModelName("anthropic/claude-sonnet-4-5") // "claude-sonnet-4-5"
51
+ * extractModelName("gpt-4") // "gpt-4"
52
+ * ```
53
+ */
54
+ export declare function extractModelName(model: string): string;
55
+ /**
56
+ * Zod schema for MeshLlmRequest input.
57
+ */
58
+ declare const MeshLlmRequestSchema: z.ZodObject<{
59
+ request: z.ZodObject<{
60
+ messages: z.ZodArray<z.ZodObject<{
61
+ role: z.ZodEnum<["system", "user", "assistant", "tool"]>;
62
+ content: z.ZodNullable<z.ZodString>;
63
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
+ id: z.ZodString;
65
+ type: z.ZodLiteral<"function">;
66
+ function: z.ZodObject<{
67
+ name: z.ZodString;
68
+ arguments: z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ name: string;
71
+ arguments: string;
72
+ }, {
73
+ name: string;
74
+ arguments: string;
75
+ }>;
76
+ }, "strip", z.ZodTypeAny, {
77
+ function: {
78
+ name: string;
79
+ arguments: string;
80
+ };
81
+ type: "function";
82
+ id: string;
83
+ }, {
84
+ function: {
85
+ name: string;
86
+ arguments: string;
87
+ };
88
+ type: "function";
89
+ id: string;
90
+ }>, "many">>;
91
+ tool_call_id: z.ZodOptional<z.ZodString>;
92
+ name: z.ZodOptional<z.ZodString>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ content: string | null;
95
+ role: "system" | "user" | "assistant" | "tool";
96
+ tool_calls?: {
97
+ function: {
98
+ name: string;
99
+ arguments: string;
100
+ };
101
+ type: "function";
102
+ id: string;
103
+ }[] | undefined;
104
+ name?: string | undefined;
105
+ tool_call_id?: string | undefined;
106
+ }, {
107
+ content: string | null;
108
+ role: "system" | "user" | "assistant" | "tool";
109
+ tool_calls?: {
110
+ function: {
111
+ name: string;
112
+ arguments: string;
113
+ };
114
+ type: "function";
115
+ id: string;
116
+ }[] | undefined;
117
+ name?: string | undefined;
118
+ tool_call_id?: string | undefined;
119
+ }>, "many">;
120
+ tools: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
121
+ type: z.ZodLiteral<"function">;
122
+ function: z.ZodObject<{
123
+ name: z.ZodString;
124
+ description: z.ZodOptional<z.ZodString>;
125
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
126
+ }, "strip", z.ZodTypeAny, {
127
+ name: string;
128
+ description?: string | undefined;
129
+ parameters?: Record<string, unknown> | undefined;
130
+ }, {
131
+ name: string;
132
+ description?: string | undefined;
133
+ parameters?: Record<string, unknown> | undefined;
134
+ }>;
135
+ }, "strip", z.ZodTypeAny, {
136
+ function: {
137
+ name: string;
138
+ description?: string | undefined;
139
+ parameters?: Record<string, unknown> | undefined;
140
+ };
141
+ type: "function";
142
+ }, {
143
+ function: {
144
+ name: string;
145
+ description?: string | undefined;
146
+ parameters?: Record<string, unknown> | undefined;
147
+ };
148
+ type: "function";
149
+ }>, "many">>>;
150
+ model_params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
151
+ context: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
152
+ request_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
153
+ caller_agent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
154
+ }, "strip", z.ZodTypeAny, {
155
+ messages: {
156
+ content: string | null;
157
+ role: "system" | "user" | "assistant" | "tool";
158
+ tool_calls?: {
159
+ function: {
160
+ name: string;
161
+ arguments: string;
162
+ };
163
+ type: "function";
164
+ id: string;
165
+ }[] | undefined;
166
+ name?: string | undefined;
167
+ tool_call_id?: string | undefined;
168
+ }[];
169
+ tools?: {
170
+ function: {
171
+ name: string;
172
+ description?: string | undefined;
173
+ parameters?: Record<string, unknown> | undefined;
174
+ };
175
+ type: "function";
176
+ }[] | null | undefined;
177
+ model_params?: Record<string, unknown> | null | undefined;
178
+ context?: Record<string, unknown> | null | undefined;
179
+ request_id?: string | null | undefined;
180
+ caller_agent?: string | null | undefined;
181
+ }, {
182
+ messages: {
183
+ content: string | null;
184
+ role: "system" | "user" | "assistant" | "tool";
185
+ tool_calls?: {
186
+ function: {
187
+ name: string;
188
+ arguments: string;
189
+ };
190
+ type: "function";
191
+ id: string;
192
+ }[] | undefined;
193
+ name?: string | undefined;
194
+ tool_call_id?: string | undefined;
195
+ }[];
196
+ tools?: {
197
+ function: {
198
+ name: string;
199
+ description?: string | undefined;
200
+ parameters?: Record<string, unknown> | undefined;
201
+ };
202
+ type: "function";
203
+ }[] | null | undefined;
204
+ model_params?: Record<string, unknown> | null | undefined;
205
+ context?: Record<string, unknown> | null | undefined;
206
+ request_id?: string | null | undefined;
207
+ caller_agent?: string | null | undefined;
208
+ }>;
209
+ }, "strip", z.ZodTypeAny, {
210
+ request: {
211
+ messages: {
212
+ content: string | null;
213
+ role: "system" | "user" | "assistant" | "tool";
214
+ tool_calls?: {
215
+ function: {
216
+ name: string;
217
+ arguments: string;
218
+ };
219
+ type: "function";
220
+ id: string;
221
+ }[] | undefined;
222
+ name?: string | undefined;
223
+ tool_call_id?: string | undefined;
224
+ }[];
225
+ tools?: {
226
+ function: {
227
+ name: string;
228
+ description?: string | undefined;
229
+ parameters?: Record<string, unknown> | undefined;
230
+ };
231
+ type: "function";
232
+ }[] | null | undefined;
233
+ model_params?: Record<string, unknown> | null | undefined;
234
+ context?: Record<string, unknown> | null | undefined;
235
+ request_id?: string | null | undefined;
236
+ caller_agent?: string | null | undefined;
237
+ };
238
+ }, {
239
+ request: {
240
+ messages: {
241
+ content: string | null;
242
+ role: "system" | "user" | "assistant" | "tool";
243
+ tool_calls?: {
244
+ function: {
245
+ name: string;
246
+ arguments: string;
247
+ };
248
+ type: "function";
249
+ id: string;
250
+ }[] | undefined;
251
+ name?: string | undefined;
252
+ tool_call_id?: string | undefined;
253
+ }[];
254
+ tools?: {
255
+ function: {
256
+ name: string;
257
+ description?: string | undefined;
258
+ parameters?: Record<string, unknown> | undefined;
259
+ };
260
+ type: "function";
261
+ }[] | null | undefined;
262
+ model_params?: Record<string, unknown> | null | undefined;
263
+ context?: Record<string, unknown> | null | undefined;
264
+ request_id?: string | null | undefined;
265
+ caller_agent?: string | null | undefined;
266
+ };
267
+ }>;
268
+ type MeshLlmRequestInput = z.infer<typeof MeshLlmRequestSchema>;
269
+ /**
270
+ * Create a zero-code LLM provider tool definition.
271
+ *
272
+ * This is the TypeScript equivalent of Python's @mesh.llm_provider decorator.
273
+ * It generates a process_chat function that handles MeshLlmRequest and returns
274
+ * MeshLlmResponse with tool_calls and usage metadata.
275
+ *
276
+ * @param config - LLM provider configuration
277
+ * @returns fastmcp tool definition
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * import { FastMCP } from "fastmcp";
282
+ * import { mesh } from "@mcpmesh/sdk";
283
+ *
284
+ * const server = new FastMCP({ name: "Claude Provider", version: "1.0.0" });
285
+ *
286
+ * server.addTool(mesh.llmProvider({
287
+ * model: "anthropic/claude-sonnet-4-5",
288
+ * capability: "llm",
289
+ * tags: ["llm", "claude", "anthropic", "provider"],
290
+ * maxOutputTokens: 4096,
291
+ * temperature: 0.7,
292
+ * }));
293
+ *
294
+ * const agent = mesh(server, { name: "claude-provider", port: 9011 });
295
+ * ```
296
+ */
297
+ export declare function llmProvider(config: LlmProviderConfig): {
298
+ name: string;
299
+ description: string;
300
+ parameters: typeof MeshLlmRequestSchema;
301
+ execute: (args: MeshLlmRequestInput) => Promise<string>;
302
+ _meshMeta?: {
303
+ capability: string;
304
+ tags: string[];
305
+ version: string;
306
+ vendor: string;
307
+ };
308
+ };
309
+ /**
310
+ * Check if a tool definition is an LLM provider.
311
+ */
312
+ export declare function isLlmProviderTool(tool: unknown): tool is ReturnType<typeof llmProvider>;
313
+ /**
314
+ * Get LLM provider metadata from a tool definition.
315
+ */
316
+ export declare function getLlmProviderMeta(tool: ReturnType<typeof llmProvider>): {
317
+ capability: string;
318
+ tags: string[];
319
+ version: string;
320
+ vendor: string;
321
+ } | null;
322
+ export {};
323
+ //# sourceMappingURL=llm-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-provider.d.ts","sourceRoot":"","sources":["../src/llm-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EACV,iBAAiB,EAKlB,MAAM,YAAY,CAAC;AAwDpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtD;AAgGD;;GAEG;AACH,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuCxB,CAAC;AAEH,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,oBAAoB,CAAC;IACxC,OAAO,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAExD,SAAS,CAAC,EAAE;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAuRA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,UAAU,CAAC,OAAO,WAAW,CAAC,CAOxC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,GAAG;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,IAAI,CAEP"}