@routecraft/ai 0.3.0 → 0.4.0-canary.10
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 +5 -5
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +258 -22
- package/dist/index.d.ts +258 -22
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ResolveKey, Exchange, Destination, MergedOptions, CraftContext, CraftPlugin, DirectServerOptions, DirectRouteMetadata, Source } from '@routecraft/routecraft';
|
|
1
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
-
import { Exchange, Destination, MergedOptions, CraftContext, CraftPlugin, DirectServerOptions, DirectRouteMetadata, Source } from '@routecraft/routecraft';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Cross-instance identity for @routecraft/ai: Symbol.for() keys and type guards.
|
|
@@ -10,9 +10,92 @@ declare const BRAND: {
|
|
|
10
10
|
};
|
|
11
11
|
declare function isMcpAdapter(obj: unknown): boolean;
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Type registries for AI adapter compile-time safety via declaration merging.
|
|
15
|
+
*
|
|
16
|
+
* Users populate these empty interfaces to constrain `llm()` and `mcp()`
|
|
17
|
+
* adapters to only accept configured providers and servers. When a registry
|
|
18
|
+
* is empty, the adapter falls back to accepting any string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* declare module '@routecraft/ai' {
|
|
23
|
+
* interface LlmProviderRegistry {
|
|
24
|
+
* openai: true;
|
|
25
|
+
* anthropic: true;
|
|
26
|
+
* ollama: true;
|
|
27
|
+
* }
|
|
28
|
+
* interface McpServerRegistry {
|
|
29
|
+
* github: true;
|
|
30
|
+
* 'local-postgres': true;
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // Now llm('openai:gpt-5') autocompletes the provider prefix.
|
|
35
|
+
* // llm('qwen:model') shows a red line if qwen is not registered.
|
|
36
|
+
* // mcp('github:create_issue') autocompletes server names.
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Registry for configured LLM providers.
|
|
42
|
+
*
|
|
43
|
+
* Keys are provider names (e.g. 'openai', 'anthropic', 'ollama'),
|
|
44
|
+
* values should be `true`. Populate via declaration merging to constrain
|
|
45
|
+
* the `llm()` adapter's model ID prefix.
|
|
46
|
+
*
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
interface LlmProviderRegistry {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Registry for configured MCP servers.
|
|
53
|
+
*
|
|
54
|
+
* Keys are server names (e.g. 'github', 'local-postgres'),
|
|
55
|
+
* values should be `true`. Populate via declaration merging to constrain
|
|
56
|
+
* the `mcp()` adapter's shorthand syntax.
|
|
57
|
+
*
|
|
58
|
+
* @experimental
|
|
59
|
+
*/
|
|
60
|
+
interface McpServerRegistry {
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolved LLM model ID type.
|
|
64
|
+
* When `LlmProviderRegistry` is populated, constrains to `'provider:modelName'`
|
|
65
|
+
* where provider must be a registered key. Falls back to `string` when empty.
|
|
66
|
+
*
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
|
+
type RegisteredLlmModelId = keyof LlmProviderRegistry extends never ? string : `${Extract<keyof LlmProviderRegistry, string>}:${string}`;
|
|
70
|
+
/**
|
|
71
|
+
* Resolved MCP server key type.
|
|
72
|
+
* When `McpServerRegistry` is populated, resolves to the union of registered server keys
|
|
73
|
+
* (e.g. `'github' | 'local-postgres'`) via `ResolveKey<McpServerRegistry>`.
|
|
74
|
+
* Falls back to `string` when empty.
|
|
75
|
+
*
|
|
76
|
+
* For the `'server:tool'` shorthand format, see `RegisteredMcpShorthand`.
|
|
77
|
+
*
|
|
78
|
+
* @experimental
|
|
79
|
+
*/
|
|
80
|
+
type RegisteredMcpServer = ResolveKey<McpServerRegistry>;
|
|
81
|
+
/**
|
|
82
|
+
* Resolved MCP shorthand type for 'server:tool' syntax.
|
|
83
|
+
* When `McpServerRegistry` is populated, constrains the server prefix.
|
|
84
|
+
* Falls back to `` `${string}:${string}` `` when empty.
|
|
85
|
+
*
|
|
86
|
+
* @experimental
|
|
87
|
+
*/
|
|
88
|
+
type RegisteredMcpShorthand = keyof McpServerRegistry extends never ? `${string}:${string}` : `${Extract<keyof McpServerRegistry, string>}:${string}`;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Store key for plugin-registered providers (provider id -> LlmModelConfig).
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
14
94
|
declare const ADAPTER_LLM_PROVIDERS: unique symbol;
|
|
15
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* Store key for context-level default LLM options.
|
|
97
|
+
* @experimental
|
|
98
|
+
*/
|
|
16
99
|
declare const ADAPTER_LLM_OPTIONS: unique symbol;
|
|
17
100
|
declare module "@routecraft/routecraft" {
|
|
18
101
|
interface StoreRegistry {
|
|
@@ -152,10 +235,11 @@ interface LlmPluginOptions {
|
|
|
152
235
|
* registered via llmPlugin({ providers: { ollama: { provider: "ollama" }, ... } }).
|
|
153
236
|
* When options.outputSchema is provided, the result type narrows so body.output is typed downstream.
|
|
154
237
|
*
|
|
238
|
+
* @experimental
|
|
155
239
|
* @param modelId - "providerId:modelName"; the provider is resolved from the plugin, the model name is sent to the provider.
|
|
156
240
|
* @param options - Optional overrides (systemPrompt, userPrompt, temperature, maxTokens, outputSchema, etc.). User prompt defaults to exchange.body.
|
|
157
241
|
*/
|
|
158
|
-
declare function llm<S extends StandardSchemaV1 | undefined = undefined>(modelId:
|
|
242
|
+
declare function llm<S extends StandardSchemaV1 | undefined = undefined>(modelId: RegisteredLlmModelId, options?: Partial<LlmOptions> & {
|
|
159
243
|
outputSchema?: S;
|
|
160
244
|
}): Destination<unknown, LlmResultWithOutput<S>>;
|
|
161
245
|
|
|
@@ -164,6 +248,7 @@ declare function llm<S extends StandardSchemaV1 | undefined = undefined>(modelId
|
|
|
164
248
|
* resolves the provider from the plugin store, merges options, and calls the provider with the model name.
|
|
165
249
|
* Use with .enrich(llm("providerId:modelName", options)) or .to(llm(...)).
|
|
166
250
|
*
|
|
251
|
+
* @experimental
|
|
167
252
|
* @template S - Output schema type when outputSchema is provided; narrows result.output for downstream typing.
|
|
168
253
|
*/
|
|
169
254
|
declare class LlmDestinationAdapter<S extends StandardSchemaV1 | undefined = undefined> implements Destination<unknown, LlmResultWithOutput<S>>, MergedOptions<LlmOptionsMerged> {
|
|
@@ -187,6 +272,8 @@ declare class LlmDestinationAdapter<S extends StandardSchemaV1 | undefined = und
|
|
|
187
272
|
*
|
|
188
273
|
* Advanced users can set the store directly: context.setStore(ADAPTER_LLM_PROVIDERS, map)
|
|
189
274
|
* and context.setStore(ADAPTER_LLM_OPTIONS, partialOptions) without using this plugin.
|
|
275
|
+
*
|
|
276
|
+
* @experimental
|
|
190
277
|
*/
|
|
191
278
|
declare function llmPlugin(options?: LlmPluginOptions): CraftPlugin;
|
|
192
279
|
|
|
@@ -196,14 +283,97 @@ declare function llmPlugin(options?: LlmPluginOptions): CraftPlugin;
|
|
|
196
283
|
*/
|
|
197
284
|
declare function validateLlmPluginOptions(options: LlmPluginOptions): void;
|
|
198
285
|
|
|
199
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Central registry of all MCP tools from all sources.
|
|
288
|
+
* Stored in context store under MCP_TOOL_REGISTRY for agent adapter discovery.
|
|
289
|
+
*
|
|
290
|
+
* Sources:
|
|
291
|
+
* - "local": mcp() routes from ADAPTER_DIRECT_REGISTRY (tools exposed by this context)
|
|
292
|
+
* - stdio clients: long-lived subprocess MCP servers
|
|
293
|
+
* - HTTP clients: remote HTTP MCP servers (tools refreshed periodically)
|
|
294
|
+
*
|
|
295
|
+
* @experimental
|
|
296
|
+
*/
|
|
297
|
+
declare class McpToolRegistry {
|
|
298
|
+
/** Nested Map: source -> toolName -> McpToolRegistryEntry */
|
|
299
|
+
private tools;
|
|
300
|
+
/**
|
|
301
|
+
* Set all tools for a given source (replaces previous tools from that source).
|
|
302
|
+
* Called on initial tool listing and on re-listing after restart/refresh.
|
|
303
|
+
*
|
|
304
|
+
* @param source - Identifier for the tool source (e.g. server ID or "local")
|
|
305
|
+
* @param transport - How the tools are reached ("stdio", "http", or "local")
|
|
306
|
+
* @param tools - Tool definitions to register for this source
|
|
307
|
+
*/
|
|
308
|
+
setToolsForSource(source: string, transport: "stdio" | "http" | "local", tools: Array<{
|
|
309
|
+
name: string;
|
|
310
|
+
description?: string;
|
|
311
|
+
inputSchema: Record<string, unknown>;
|
|
312
|
+
}>): void;
|
|
313
|
+
/**
|
|
314
|
+
* Remove all tools for a source (when a client is permanently stopped).
|
|
315
|
+
*
|
|
316
|
+
* @param source - Source identifier whose tools should be removed
|
|
317
|
+
*/
|
|
318
|
+
removeSource(source: string): void;
|
|
319
|
+
/**
|
|
320
|
+
* Get all tools across all sources.
|
|
321
|
+
*
|
|
322
|
+
* @returns Array of every registered tool entry
|
|
323
|
+
*/
|
|
324
|
+
getTools(): McpToolRegistryEntry[];
|
|
325
|
+
/**
|
|
326
|
+
* Get tools from a specific source/server.
|
|
327
|
+
*
|
|
328
|
+
* @param serverId - Source identifier to filter by
|
|
329
|
+
* @returns Array of tool entries belonging to that source
|
|
330
|
+
*/
|
|
331
|
+
getToolsByServer(serverId: string): McpToolRegistryEntry[];
|
|
332
|
+
/**
|
|
333
|
+
* Get a specific tool by name. Returns first match if name exists in multiple sources.
|
|
334
|
+
*
|
|
335
|
+
* @param name - Tool name to search for
|
|
336
|
+
* @returns The first matching entry, or undefined
|
|
337
|
+
*/
|
|
338
|
+
getTool(name: string): McpToolRegistryEntry | undefined;
|
|
339
|
+
/**
|
|
340
|
+
* Get a specific tool by source and name.
|
|
341
|
+
*
|
|
342
|
+
* @param source - Source identifier
|
|
343
|
+
* @param name - Tool name
|
|
344
|
+
* @returns The matching entry, or undefined
|
|
345
|
+
*/
|
|
346
|
+
getToolBySource(source: string, name: string): McpToolRegistryEntry | undefined;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Store key set by mcpPlugin() when applied; routes using .from(mcp(...)) require it.
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
200
353
|
declare const MCP_PLUGIN_REGISTERED: unique symbol;
|
|
201
|
-
/**
|
|
354
|
+
/**
|
|
355
|
+
* Store key for named remote MCP servers (mcpPlugin({ clients })). Used by McpClient to resolve serverId.
|
|
356
|
+
* @internal
|
|
357
|
+
*/
|
|
202
358
|
declare const ADAPTER_MCP_CLIENT_SERVERS: unique symbol;
|
|
359
|
+
/**
|
|
360
|
+
* Store key for the unified MCP tool registry. Used by agent adapter for tool discovery.
|
|
361
|
+
* @internal
|
|
362
|
+
*/
|
|
363
|
+
declare const MCP_TOOL_REGISTRY: unique symbol;
|
|
364
|
+
/**
|
|
365
|
+
* Store key for stdio client managers. Used by destination adapter to call tools on stdio clients.
|
|
366
|
+
* @internal
|
|
367
|
+
*/
|
|
368
|
+
declare const MCP_STDIO_MANAGERS: unique symbol;
|
|
203
369
|
declare module "@routecraft/routecraft" {
|
|
204
370
|
interface StoreRegistry {
|
|
205
371
|
[MCP_PLUGIN_REGISTERED]: boolean;
|
|
206
|
-
[ADAPTER_MCP_CLIENT_SERVERS]: Map<string, McpClientHttpConfig$1 | string>;
|
|
372
|
+
[ADAPTER_MCP_CLIENT_SERVERS]: Map<string, McpClientHttpConfig$1 | McpClientStdioConfig | string>;
|
|
373
|
+
[MCP_TOOL_REGISTRY]: McpToolRegistry;
|
|
374
|
+
[MCP_STDIO_MANAGERS]: Map<string, {
|
|
375
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
376
|
+
}>;
|
|
207
377
|
}
|
|
208
378
|
}
|
|
209
379
|
/**
|
|
@@ -215,15 +385,22 @@ interface McpClientHttpConfig$1 {
|
|
|
215
385
|
url: string;
|
|
216
386
|
}
|
|
217
387
|
/**
|
|
218
|
-
* Stdio client config for a
|
|
219
|
-
*
|
|
388
|
+
* Stdio client config for a local MCP server subprocess.
|
|
389
|
+
* Used in mcpPlugin({ clients: { name: config } }).
|
|
390
|
+
* The plugin spawns the process, manages its lifecycle, and auto-restarts on crash.
|
|
220
391
|
*/
|
|
221
392
|
interface McpClientStdioConfig {
|
|
222
393
|
transport: "stdio";
|
|
394
|
+
/** The executable to run (e.g. "npx", "node", "python"). */
|
|
223
395
|
command: string;
|
|
396
|
+
/** Command line arguments to pass to the executable. */
|
|
224
397
|
args?: string[];
|
|
398
|
+
/** Environment variables for the child process. Defaults to a safe subset of the parent env. */
|
|
399
|
+
env?: Record<string, string>;
|
|
400
|
+
/** Working directory for the child process. Defaults to the current working directory. */
|
|
401
|
+
cwd?: string;
|
|
225
402
|
}
|
|
226
|
-
/** Union of client configs
|
|
403
|
+
/** Union of client configs accepted by mcpPlugin({ clients }). */
|
|
227
404
|
type McpClientServerConfig = McpClientHttpConfig$1 | McpClientStdioConfig;
|
|
228
405
|
/**
|
|
229
406
|
* Options for the MCP plugin (mcpPlugin).
|
|
@@ -246,10 +423,32 @@ interface McpPluginOptions {
|
|
|
246
423
|
*/
|
|
247
424
|
tools?: string[] | ((meta: DirectRouteMetadata) => boolean);
|
|
248
425
|
/**
|
|
249
|
-
* Named remote MCP servers for .to(mcp("name:tool")).
|
|
250
|
-
*
|
|
426
|
+
* Named remote MCP servers for .to(mcp("name:tool")).
|
|
427
|
+
* Keys are server names; values are HTTP or stdio config.
|
|
428
|
+
* Stdio clients are managed as subprocesses with auto-restart.
|
|
429
|
+
* HTTP clients are used for ephemeral tool calls.
|
|
251
430
|
*/
|
|
252
|
-
clients?: Record<string, McpClientHttpConfig$1>;
|
|
431
|
+
clients?: Record<string, McpClientHttpConfig$1 | McpClientStdioConfig>;
|
|
432
|
+
/**
|
|
433
|
+
* Max auto-restart attempts for stdio clients before giving up.
|
|
434
|
+
* Applies to all stdio clients. Default: 5.
|
|
435
|
+
*/
|
|
436
|
+
maxRestarts?: number;
|
|
437
|
+
/**
|
|
438
|
+
* Base delay in ms before the first restart attempt.
|
|
439
|
+
* Subsequent attempts use exponential backoff. Default: 1000.
|
|
440
|
+
*/
|
|
441
|
+
restartDelayMs?: number;
|
|
442
|
+
/**
|
|
443
|
+
* Multiplier for exponential backoff between restart attempts.
|
|
444
|
+
* Delay = restartDelayMs * (restartBackoffMultiplier ^ restartCount). Default: 2.
|
|
445
|
+
*/
|
|
446
|
+
restartBackoffMultiplier?: number;
|
|
447
|
+
/**
|
|
448
|
+
* Interval in ms to re-list tools from HTTP clients.
|
|
449
|
+
* Set to 0 to disable periodic refresh. Default: 60000 (60s).
|
|
450
|
+
*/
|
|
451
|
+
toolRefreshIntervalMs?: number;
|
|
253
452
|
}
|
|
254
453
|
/**
|
|
255
454
|
* Options for mcp() when used as a server in .from().
|
|
@@ -268,9 +467,11 @@ type McpArgsExtractor$1 = (exchange: Exchange<unknown>) => Record<string, unknow
|
|
|
268
467
|
* Options for mcp() when used as a Client in .to() to call a remote MCP server.
|
|
269
468
|
* Provide either url (inline HTTP) or serverId (from plugin/store); tool is required.
|
|
270
469
|
*
|
|
271
|
-
*
|
|
272
|
-
* HTTP endpoint or `serverId` for a named backend
|
|
273
|
-
*
|
|
470
|
+
* Supported transports:
|
|
471
|
+
* - **HTTP:** use `url` for an inline endpoint or `serverId` for a named backend.
|
|
472
|
+
* - **Stdio:** use `serverId` referencing a stdio client from mcpPlugin({ clients }).
|
|
473
|
+
* The destination adapter resolves the manager from the context store and calls
|
|
474
|
+
* tools directly on the subprocess -- no HTTP involved.
|
|
274
475
|
*/
|
|
275
476
|
interface McpClientOptions {
|
|
276
477
|
/** URL of the remote MCP server (HTTP/HTTPS only). Omit when using serverId. */
|
|
@@ -281,7 +482,7 @@ interface McpClientOptions {
|
|
|
281
482
|
serverId?: string;
|
|
282
483
|
/**
|
|
283
484
|
* Extract tool arguments from the exchange. Receives the full exchange.
|
|
284
|
-
* Default: body as object
|
|
485
|
+
* Default: body as object -> use as args; otherwise { input: body }.
|
|
285
486
|
*/
|
|
286
487
|
args?: McpArgsExtractor$1;
|
|
287
488
|
}
|
|
@@ -298,6 +499,22 @@ interface McpTool {
|
|
|
298
499
|
[key: string]: unknown;
|
|
299
500
|
};
|
|
300
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* A tool entry in the unified MCP tool registry.
|
|
504
|
+
* Combines local mcp() route tools and remote client tools (stdio and HTTP).
|
|
505
|
+
*/
|
|
506
|
+
interface McpToolRegistryEntry {
|
|
507
|
+
/** Tool name (unique within a source, may collide across sources). */
|
|
508
|
+
name: string;
|
|
509
|
+
/** Human-readable description of the tool. */
|
|
510
|
+
description?: string;
|
|
511
|
+
/** JSON Schema for tool input. */
|
|
512
|
+
inputSchema: Record<string, unknown>;
|
|
513
|
+
/** Source server ID. Local mcp() routes use "local". */
|
|
514
|
+
source: string;
|
|
515
|
+
/** Transport type of the source. */
|
|
516
|
+
transport: "stdio" | "http" | "local";
|
|
517
|
+
}
|
|
301
518
|
/**
|
|
302
519
|
* MCP tool call result
|
|
303
520
|
*/
|
|
@@ -329,6 +546,7 @@ interface McpClientHttpConfig {
|
|
|
329
546
|
/**
|
|
330
547
|
* Brand symbol for MCP adapter type checking.
|
|
331
548
|
* Used internally to identify MCP adapters.
|
|
549
|
+
* @experimental
|
|
332
550
|
*/
|
|
333
551
|
declare const BRAND_MCP_ADAPTER: unique symbol;
|
|
334
552
|
|
|
@@ -358,6 +576,8 @@ declare const defaultArgs: McpArgsExtractor$1;
|
|
|
358
576
|
* @param options - Server options (source) or args extractor (destination)
|
|
359
577
|
* @returns Source when called with two arguments; Destination when called with one argument
|
|
360
578
|
*
|
|
579
|
+
* @experimental
|
|
580
|
+
*
|
|
361
581
|
* @example
|
|
362
582
|
* ```typescript
|
|
363
583
|
* // Source route (MCP tool)
|
|
@@ -374,23 +594,29 @@ declare function mcp<S extends StandardSchemaV1 | undefined = undefined>(endpoin
|
|
|
374
594
|
schema?: S;
|
|
375
595
|
}): Source<McpMessage<S>>;
|
|
376
596
|
declare function mcp(clientOptions: McpClientOptions): Destination<unknown, unknown>;
|
|
377
|
-
declare function mcp(shorthand:
|
|
597
|
+
declare function mcp(shorthand: RegisteredMcpShorthand, options?: {
|
|
378
598
|
args?: McpArgsExtractor$1;
|
|
379
599
|
}): Destination<unknown, unknown>;
|
|
380
600
|
|
|
381
601
|
/**
|
|
382
602
|
* MCP plugin: one plugin per adapter. Starts the MCP server during plugin apply (before routes start) so startup failures fail context build. Exposes mcp() routes to external MCP clients.
|
|
383
603
|
* Optional clients: register named remote MCP servers so routes can use .to(mcp("name:tool")) without passing url.
|
|
604
|
+
* Stdio clients are spawned as subprocesses with auto-restart; HTTP clients are used for ephemeral tool calls.
|
|
605
|
+
* All discovered external tools (stdio, HTTP) are stored in a unified McpToolRegistry for agent adapter discovery.
|
|
384
606
|
* Required when any route uses .from(mcp(...)); the route will fail at start if this plugin is not applied.
|
|
607
|
+
*
|
|
608
|
+
* @experimental
|
|
385
609
|
*/
|
|
386
610
|
declare function mcpPlugin(options?: McpPluginOptions): CraftPlugin;
|
|
387
611
|
|
|
388
612
|
/**
|
|
389
|
-
* McpServer wraps the MCP SDK and bridges it to
|
|
613
|
+
* McpServer wraps the MCP SDK and bridges it to Routecraft's DirectChannel infrastructure.
|
|
390
614
|
* It reads the MCP route registry lazily (on first tools/list request) to ensure routes have subscribed.
|
|
391
615
|
*
|
|
392
616
|
* Note: Uses dynamic imports to avoid TypeScript compatibility issues with the MCP SDK.
|
|
393
617
|
* Supports both stdio and streamable-http transports.
|
|
618
|
+
*
|
|
619
|
+
* @experimental
|
|
394
620
|
*/
|
|
395
621
|
declare class McpServer {
|
|
396
622
|
private context;
|
|
@@ -439,7 +665,7 @@ declare class McpServer {
|
|
|
439
665
|
*/
|
|
440
666
|
getAvailableTools(): Array<Record<string, unknown>>;
|
|
441
667
|
/**
|
|
442
|
-
* Convert
|
|
668
|
+
* Convert Routecraft mcp() route metadata to MCP tool format
|
|
443
669
|
*/
|
|
444
670
|
private metadataToMcpTool;
|
|
445
671
|
/**
|
|
@@ -503,6 +729,7 @@ interface AgentResult {
|
|
|
503
729
|
/**
|
|
504
730
|
* Create an agent destination.
|
|
505
731
|
*
|
|
732
|
+
* @experimental
|
|
506
733
|
* @param options Agent options (modelId, systemPrompt, allowedRoutes, etc.)
|
|
507
734
|
* @returns Destination that produces AgentResult
|
|
508
735
|
*/
|
|
@@ -511,6 +738,8 @@ declare function agent(options: AgentOptions): Destination<unknown, AgentResult>
|
|
|
511
738
|
/**
|
|
512
739
|
* Agent destination adapter.
|
|
513
740
|
* Use via agent(); do not instantiate AgentRunner directly.
|
|
741
|
+
*
|
|
742
|
+
* @experimental
|
|
514
743
|
*/
|
|
515
744
|
declare class AgentDestinationAdapter implements Destination<unknown, AgentResult> {
|
|
516
745
|
readonly adapterId = "routecraft.adapter.agent";
|
|
@@ -583,6 +812,8 @@ type EmbeddingModelId = "huggingface:all-MiniLM-L6-v2" | "huggingface:sentence-t
|
|
|
583
812
|
* Embedding destination adapter. Expects model id as "providerId:modelName"
|
|
584
813
|
* (e.g. huggingface:all-MiniLM-L6-v2), resolves the provider from the plugin store,
|
|
585
814
|
* and returns { embedding: number[] }. Use with .enrich(embedding("provider:model", { using: ... })).
|
|
815
|
+
*
|
|
816
|
+
* @experimental
|
|
586
817
|
*/
|
|
587
818
|
declare class EmbeddingDestinationAdapter<T = unknown> implements Destination<T, EmbeddingResult>, MergedOptions<EmbeddingOptions> {
|
|
588
819
|
private readonly modelId;
|
|
@@ -598,6 +829,7 @@ declare class EmbeddingDestinationAdapter<T = unknown> implements Destination<T,
|
|
|
598
829
|
* Use with .enrich(). Pass model id as "providerId:modelName" (e.g. huggingface:all-MiniLM-L6-v2).
|
|
599
830
|
* The provider must be registered via embeddingPlugin({ providers: { huggingface: {} } }).
|
|
600
831
|
*
|
|
832
|
+
* @experimental
|
|
601
833
|
* @param modelId - "providerId:modelName"; the provider is resolved from the plugin.
|
|
602
834
|
* @param options - using(exchange) returns the string (or string[]) to embed.
|
|
603
835
|
*/
|
|
@@ -608,6 +840,8 @@ declare function embedding<T = unknown>(modelId: EmbeddingModelId, options?: Par
|
|
|
608
840
|
* cache when the context stops (releases native/ONNX resources).
|
|
609
841
|
* Use embedding("providerId:modelName", { using: ... }),
|
|
610
842
|
* e.g. embedding("huggingface:all-MiniLM-L6-v2", { using: (e) => e.body.title }).
|
|
843
|
+
*
|
|
844
|
+
* @experimental
|
|
611
845
|
*/
|
|
612
846
|
declare function embeddingPlugin(options?: EmbeddingPluginOptions): CraftPlugin;
|
|
613
847
|
|
|
@@ -615,10 +849,12 @@ declare function embeddingPlugin(options?: EmbeddingPluginOptions): CraftPlugin;
|
|
|
615
849
|
* Dispose all cached HuggingFace pipelines and clear the cache. Call on context
|
|
616
850
|
* shutdown so pipeline.dispose() releases native/ONNX resources.
|
|
617
851
|
*
|
|
618
|
-
* Callers must avoid process.exit() after this
|
|
852
|
+
* Callers must avoid process.exit() after this -- let the event loop drain
|
|
619
853
|
* naturally so ONNX Runtime's C++ statics aren't torn down prematurely
|
|
620
854
|
* (onnxruntime#25038: "mutex lock failed: Invalid argument").
|
|
855
|
+
*
|
|
856
|
+
* @experimental
|
|
621
857
|
*/
|
|
622
858
|
declare function disposeEmbeddingPipelineCache(): Promise<void>;
|
|
623
859
|
|
|
624
|
-
export { ADAPTER_LLM_OPTIONS, ADAPTER_LLM_PROVIDERS, ADAPTER_MCP_CLIENT_SERVERS, AgentDestinationAdapter, type AgentModelId, type AgentOptions, type AgentPromptSource, type AgentResult, BRAND, BRAND_MCP_ADAPTER, EmbeddingDestinationAdapter, type EmbeddingModelConfig, type EmbeddingModelConfigHuggingFace, type EmbeddingModelConfigOllama, type EmbeddingModelConfigOpenAI, type EmbeddingModelId, type EmbeddingOptions, type EmbeddingPluginOptions, type EmbeddingPluginProviders, type EmbeddingProviderType, type EmbeddingResult, type LlmAnthropicProviderOptions, LlmDestinationAdapter, type LlmGeminiProviderOptions, type LlmModelConfig, type LlmModelConfigAnthropic, type LlmModelConfigGemini, type LlmModelConfigOllama, type LlmModelConfigOpenAI, type LlmModelConfigOpenRouter, type LlmModelId, type LlmOllamaProviderOptions, type LlmOpenAIProviderOptions, type LlmOpenRouterProviderOptions, type LlmOptions, type LlmPluginOptions, type LlmPluginProviders, type LlmPromptSource, type LlmProviderType, type LlmResult, type LlmUsage, MCP_PLUGIN_REGISTERED, type McpArgsExtractor, type McpClientHttpConfig, type McpClientOptions, type McpClientServerConfig, type McpClientStdioConfig, type McpMessage, type McpOptions, type McpPluginOptions, McpServer, type McpServerOptions, type McpTool, type McpToolResult, agent, defaultArgs, disposeEmbeddingPipelineCache, embedding, embeddingPlugin, isMcpAdapter, llm, llmPlugin, mcp, mcpPlugin, validateLlmPluginOptions, validateWithSchema };
|
|
860
|
+
export { ADAPTER_LLM_OPTIONS, ADAPTER_LLM_PROVIDERS, ADAPTER_MCP_CLIENT_SERVERS, AgentDestinationAdapter, type AgentModelId, type AgentOptions, type AgentPromptSource, type AgentResult, BRAND, BRAND_MCP_ADAPTER, EmbeddingDestinationAdapter, type EmbeddingModelConfig, type EmbeddingModelConfigHuggingFace, type EmbeddingModelConfigOllama, type EmbeddingModelConfigOpenAI, type EmbeddingModelId, type EmbeddingOptions, type EmbeddingPluginOptions, type EmbeddingPluginProviders, type EmbeddingProviderType, type EmbeddingResult, type LlmAnthropicProviderOptions, LlmDestinationAdapter, type LlmGeminiProviderOptions, type LlmModelConfig, type LlmModelConfigAnthropic, type LlmModelConfigGemini, type LlmModelConfigOllama, type LlmModelConfigOpenAI, type LlmModelConfigOpenRouter, type LlmModelId, type LlmOllamaProviderOptions, type LlmOpenAIProviderOptions, type LlmOpenRouterProviderOptions, type LlmOptions, type LlmPluginOptions, type LlmPluginProviders, type LlmPromptSource, type LlmProviderRegistry, type LlmProviderType, type LlmResult, type LlmUsage, MCP_PLUGIN_REGISTERED, MCP_STDIO_MANAGERS, MCP_TOOL_REGISTRY, type McpArgsExtractor, type McpClientHttpConfig, type McpClientOptions, type McpClientServerConfig, type McpClientStdioConfig, type McpMessage, type McpOptions, type McpPluginOptions, McpServer, type McpServerOptions, type McpServerRegistry, type McpTool, McpToolRegistry, type McpToolRegistryEntry, type McpToolResult, type RegisteredLlmModelId, type RegisteredMcpServer, type RegisteredMcpShorthand, agent, defaultArgs, disposeEmbeddingPipelineCache, embedding, embeddingPlugin, isMcpAdapter, llm, llmPlugin, mcp, mcpPlugin, validateLlmPluginOptions, validateWithSchema };
|