@juspay/neurolink 5.2.0 → 5.3.0
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/CHANGELOG.md +8 -2
- package/dist/cli/factories/command-factory.js +6 -5
- package/dist/core/base-provider.js +24 -13
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +1 -0
- package/dist/lib/core/base-provider.js +24 -13
- package/dist/lib/core/constants.d.ts +1 -0
- package/dist/lib/core/constants.js +1 -0
- package/dist/lib/mcp/client.d.ts +1 -0
- package/dist/lib/mcp/client.js +1 -0
- package/dist/lib/mcp/context-manager.d.ts +1 -0
- package/dist/lib/mcp/context-manager.js +8 -4
- package/dist/lib/mcp/function-calling.d.ts +13 -0
- package/dist/lib/mcp/function-calling.js +133 -34
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +1 -0
- package/dist/lib/mcp/neurolink-mcp-client.js +21 -5
- package/dist/lib/providers/function-calling-provider.d.ts +64 -2
- package/dist/lib/providers/function-calling-provider.js +208 -9
- package/dist/lib/providers/mcp-provider.js +20 -5
- package/dist/lib/services/streaming/streaming-manager.js +11 -10
- package/dist/lib/services/websocket/websocket-server.js +12 -11
- package/dist/lib/telemetry/telemetry-service.js +8 -7
- package/dist/mcp/client.d.ts +1 -0
- package/dist/mcp/client.js +1 -0
- package/dist/mcp/context-manager.d.ts +1 -0
- package/dist/mcp/context-manager.js +8 -4
- package/dist/mcp/function-calling.d.ts +13 -0
- package/dist/mcp/function-calling.js +133 -34
- package/dist/mcp/neurolink-mcp-client.d.ts +1 -0
- package/dist/mcp/neurolink-mcp-client.js +21 -5
- package/dist/providers/function-calling-provider.d.ts +64 -2
- package/dist/providers/function-calling-provider.js +208 -9
- package/dist/providers/mcp-provider.js +20 -5
- package/dist/services/streaming/streaming-manager.js +11 -10
- package/dist/services/websocket/websocket-server.js +12 -11
- package/dist/telemetry/telemetry-service.js +8 -7
- package/package.json +12 -10
|
@@ -4,6 +4,7 @@ import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentation
|
|
|
4
4
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
5
5
|
import { Resource } from "@opentelemetry/resources";
|
|
6
6
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
|
|
7
|
+
import { logger } from "../utils/logger.js";
|
|
7
8
|
export class TelemetryService {
|
|
8
9
|
static instance;
|
|
9
10
|
sdk;
|
|
@@ -25,7 +26,7 @@ export class TelemetryService {
|
|
|
25
26
|
this.initializeTelemetry();
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
|
|
29
|
+
logger.debug("[Telemetry] Disabled - set NEUROLINK_TELEMETRY_ENABLED=true or configure OTEL_EXPORTER_OTLP_ENDPOINT to enable");
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
static getInstance() {
|
|
@@ -56,10 +57,10 @@ export class TelemetryService {
|
|
|
56
57
|
this.meter = metrics.getMeter("neurolink-ai");
|
|
57
58
|
this.tracer = trace.getTracer("neurolink-ai");
|
|
58
59
|
this.initializeMetrics();
|
|
59
|
-
|
|
60
|
+
logger.debug("[Telemetry] Initialized with endpoint:", process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
|
-
|
|
63
|
+
logger.error("[Telemetry] Failed to initialize:", error);
|
|
63
64
|
this.enabled = false;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -95,10 +96,10 @@ export class TelemetryService {
|
|
|
95
96
|
}
|
|
96
97
|
try {
|
|
97
98
|
await this.sdk?.start();
|
|
98
|
-
|
|
99
|
+
logger.debug("[Telemetry] SDK started successfully");
|
|
99
100
|
}
|
|
100
101
|
catch (error) {
|
|
101
|
-
|
|
102
|
+
logger.error("[Telemetry] Failed to start SDK:", error);
|
|
102
103
|
this.enabled = false;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -249,10 +250,10 @@ export class TelemetryService {
|
|
|
249
250
|
if (this.enabled && this.sdk) {
|
|
250
251
|
try {
|
|
251
252
|
await this.sdk.shutdown();
|
|
252
|
-
|
|
253
|
+
logger.debug("[Telemetry] SDK shutdown completed");
|
|
253
254
|
}
|
|
254
255
|
catch (error) {
|
|
255
|
-
|
|
256
|
+
logger.error("[Telemetry] Error during shutdown:", error);
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
}
|
package/dist/mcp/client.d.ts
CHANGED
package/dist/mcp/client.js
CHANGED
|
@@ -130,6 +130,7 @@ export class NeuroLinkMCPClient extends EventEmitter {
|
|
|
130
130
|
const tools = {};
|
|
131
131
|
for (const [name, tool] of this.tools) {
|
|
132
132
|
tools[name] = {
|
|
133
|
+
name: name, // Include the tool name as a property
|
|
133
134
|
description: tool.description,
|
|
134
135
|
inputSchema: tool.inputSchema,
|
|
135
136
|
};
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export class ContextManager {
|
|
11
11
|
sessionCounter = 0;
|
|
12
12
|
activeContexts = new Map();
|
|
13
|
+
static cachedLogger = null;
|
|
13
14
|
/**
|
|
14
15
|
* Create a new execution context with rich information
|
|
15
16
|
*
|
|
@@ -64,6 +65,7 @@ export class ContextManager {
|
|
|
64
65
|
},
|
|
65
66
|
path: {
|
|
66
67
|
join: (...paths) => {
|
|
68
|
+
// Use dynamic require for synchronous path operations
|
|
67
69
|
const path = require("path");
|
|
68
70
|
return path.join(...paths);
|
|
69
71
|
},
|
|
@@ -85,11 +87,13 @@ export class ContextManager {
|
|
|
85
87
|
},
|
|
86
88
|
},
|
|
87
89
|
grantedPermissions: request.permissions || [],
|
|
88
|
-
log: (level, message, data) => {
|
|
89
|
-
// Use logger if available, otherwise
|
|
90
|
+
log: async (level, message, data) => {
|
|
91
|
+
// Use cached logger if available, otherwise import and cache
|
|
90
92
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
if (!ContextManager.cachedLogger) {
|
|
94
|
+
ContextManager.cachedLogger = await import("../utils/logger.js").then(({ logger }) => logger);
|
|
95
|
+
}
|
|
96
|
+
ContextManager.cachedLogger[level](message, data);
|
|
93
97
|
}
|
|
94
98
|
catch {
|
|
95
99
|
console[level === "debug" ? "log" : level](message, data);
|
|
@@ -14,6 +14,7 @@ export declare function mcpToolToAISDKTool(tool: NeuroLinkMCPTool, serverId: str
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function getAvailableFunctionTools(): Promise<{
|
|
16
16
|
tools: Tool[];
|
|
17
|
+
toolsObject: Record<string, Tool>;
|
|
17
18
|
toolMap: Map<string, {
|
|
18
19
|
serverId: string;
|
|
19
20
|
toolName: string;
|
|
@@ -49,3 +50,15 @@ export declare function getFunctionToolsForCategory(category?: string, maxTools?
|
|
|
49
50
|
* Check if function calling is available
|
|
50
51
|
*/
|
|
51
52
|
export declare function isFunctionCallingAvailable(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Utility function to create a named tool object for debugging
|
|
55
|
+
*/
|
|
56
|
+
export declare function createNamedTool(name: string, toolDef: any): any & {
|
|
57
|
+
name: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Get tools with proper name properties for debugging
|
|
61
|
+
*/
|
|
62
|
+
export declare function getToolsWithNames(): Promise<Record<string, any & {
|
|
63
|
+
name: string;
|
|
64
|
+
}>>;
|
|
@@ -8,6 +8,100 @@ import { z } from "zod";
|
|
|
8
8
|
import { unifiedRegistry } from "./unified-registry.js";
|
|
9
9
|
import { createExecutionContext } from "./context-manager.js";
|
|
10
10
|
import { mcpLogger } from "./logging.js";
|
|
11
|
+
/**
|
|
12
|
+
* Parses neurolink-specific function name patterns to extract the server ID and tool name.
|
|
13
|
+
*
|
|
14
|
+
* @param {string[]} parts - An array of strings representing parts of a function name,
|
|
15
|
+
* typically obtained by splitting the function name on underscores.
|
|
16
|
+
* @returns {{ serverId: string; toolName: string } | null} An object containing the `serverId`
|
|
17
|
+
* and `toolName` if the input matches a neurolink-specific pattern, or `null` if no match is found.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Returns { serverId: "neurolink_ai_core", toolName: "generate" }
|
|
21
|
+
* parseNeuroLinkPattern(["neurolink", "ai", "core", "generate"]);
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Returns { serverId: "neurolink_utility", toolName: "format_number" }
|
|
25
|
+
* parseNeuroLinkPattern(["neurolink", "utility", "format_number"]);
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Returns null
|
|
29
|
+
* parseNeuroLinkPattern(["other", "pattern"]);
|
|
30
|
+
*/
|
|
31
|
+
function parseNeuroLinkPattern(parts) {
|
|
32
|
+
if (parts.length >= 3 &&
|
|
33
|
+
parts[0] === "neurolink" &&
|
|
34
|
+
(parts[1] === "ai" || parts[1] === "utility")) {
|
|
35
|
+
// neurolink_ai_core_generate -> serverId: "neurolink_ai_core", toolName: "generate"
|
|
36
|
+
// neurolink_utility_format_number -> serverId: "neurolink_utility", toolName: "format_number"
|
|
37
|
+
if (parts[1] === "ai" && parts[2] === "core") {
|
|
38
|
+
return {
|
|
39
|
+
serverId: "neurolink_ai_core",
|
|
40
|
+
toolName: parts.slice(3).join("_"),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else if (parts[1] === "utility") {
|
|
44
|
+
return {
|
|
45
|
+
serverId: "neurolink_utility",
|
|
46
|
+
toolName: parts.slice(2).join("_"),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parse underscore-separated function name format
|
|
54
|
+
*/
|
|
55
|
+
function parseUnderscoreFormat(functionName) {
|
|
56
|
+
const parts = functionName.split("_");
|
|
57
|
+
if (parts.length >= 2) {
|
|
58
|
+
// Try neurolink-specific patterns first
|
|
59
|
+
const neurolinkResult = parseNeuroLinkPattern(parts);
|
|
60
|
+
if (neurolinkResult) {
|
|
61
|
+
return neurolinkResult;
|
|
62
|
+
}
|
|
63
|
+
// Default underscore parsing
|
|
64
|
+
return {
|
|
65
|
+
serverId: parts[0],
|
|
66
|
+
toolName: parts.slice(1).join("_"),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parse dot-separated function name format (legacy support)
|
|
73
|
+
*/
|
|
74
|
+
function parseDotFormat(functionName) {
|
|
75
|
+
const parts = functionName.split(".");
|
|
76
|
+
if (parts.length >= 2) {
|
|
77
|
+
return {
|
|
78
|
+
serverId: parts[0],
|
|
79
|
+
toolName: parts.slice(1).join("."),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parse function name to extract server ID and tool name
|
|
86
|
+
* Handles various naming patterns including neurolink server patterns
|
|
87
|
+
*/
|
|
88
|
+
function parseFunctionName(functionName) {
|
|
89
|
+
// Try underscore format first (most common)
|
|
90
|
+
const underscoreResult = parseUnderscoreFormat(functionName);
|
|
91
|
+
if (underscoreResult) {
|
|
92
|
+
return underscoreResult;
|
|
93
|
+
}
|
|
94
|
+
// Fallback to dot format for backward compatibility
|
|
95
|
+
const dotResult = parseDotFormat(functionName);
|
|
96
|
+
if (dotResult) {
|
|
97
|
+
return dotResult;
|
|
98
|
+
}
|
|
99
|
+
// Final fallback - return as-is with unknown server
|
|
100
|
+
return {
|
|
101
|
+
serverId: "unknown",
|
|
102
|
+
toolName: functionName,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
11
105
|
/**
|
|
12
106
|
* Convert MCP tool to AI SDK function definition
|
|
13
107
|
*/
|
|
@@ -55,6 +149,7 @@ export function mcpToolToAISDKTool(tool, serverId) {
|
|
|
55
149
|
export async function getAvailableFunctionTools() {
|
|
56
150
|
const functionTag = "getAvailableFunctionTools";
|
|
57
151
|
const tools = [];
|
|
152
|
+
const toolsObject = {};
|
|
58
153
|
const toolMap = new Map();
|
|
59
154
|
try {
|
|
60
155
|
// Add overall timeout for the entire function
|
|
@@ -281,6 +376,8 @@ export async function getAvailableFunctionTools() {
|
|
|
281
376
|
},
|
|
282
377
|
});
|
|
283
378
|
tools.push(aiTool);
|
|
379
|
+
// Store tool with proper name association
|
|
380
|
+
toolsObject[functionName] = aiTool;
|
|
284
381
|
// Store mapping for execution - CRITICAL: Use sanitized functionName as key
|
|
285
382
|
toolMap.set(functionName, {
|
|
286
383
|
serverId: typeof toolInfo.serverId === "string"
|
|
@@ -302,7 +399,7 @@ export async function getAvailableFunctionTools() {
|
|
|
302
399
|
if (overallTimeoutId) {
|
|
303
400
|
clearTimeout(overallTimeoutId);
|
|
304
401
|
}
|
|
305
|
-
return { tools, toolMap };
|
|
402
|
+
return { tools, toolsObject, toolMap };
|
|
306
403
|
}
|
|
307
404
|
catch (error) {
|
|
308
405
|
if (overallTimeoutId) {
|
|
@@ -315,7 +412,7 @@ export async function getAvailableFunctionTools() {
|
|
|
315
412
|
}
|
|
316
413
|
catch (error) {
|
|
317
414
|
mcpLogger.error(`[${functionTag}] Error getting function tools:`, error);
|
|
318
|
-
return { tools: [], toolMap: new Map() };
|
|
415
|
+
return { tools: [], toolsObject: {}, toolMap: new Map() };
|
|
319
416
|
}
|
|
320
417
|
}
|
|
321
418
|
/**
|
|
@@ -345,38 +442,12 @@ export async function executeFunctionCall(functionName, parameters, context) {
|
|
|
345
442
|
});
|
|
346
443
|
}
|
|
347
444
|
// Parse server and tool name from function name
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const firstPart = parts[0];
|
|
355
|
-
if (firstPart && typeof firstPart === "string" && firstPart.length > 0) {
|
|
356
|
-
serverId = firstPart;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
serverId = "unknown";
|
|
360
|
-
}
|
|
361
|
-
toolName = parts.slice(1).join("_"); // Rejoin in case tool name had underscores
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
// Fallback to dot format for backward compatibility
|
|
365
|
-
parts = functionName.split(".");
|
|
366
|
-
if (parts.length === 2) {
|
|
367
|
-
const parsedServerId = parts[0];
|
|
368
|
-
const parsedToolName = parts[1];
|
|
369
|
-
if (parsedServerId && parsedToolName) {
|
|
370
|
-
serverId = parsedServerId;
|
|
371
|
-
toolName = parsedToolName;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
// Can't parse - try executing as-is through unified registry
|
|
376
|
-
mcpLogger.debug(`[${functionTag}] Cannot parse function name format: ${functionName}, trying unified registry`);
|
|
377
|
-
const result = await unifiedRegistry.executeTool(functionName, actualParameters, finalContext);
|
|
378
|
-
return result;
|
|
379
|
-
}
|
|
445
|
+
const { serverId, toolName } = parseFunctionName(functionName);
|
|
446
|
+
if (serverId === "unknown") {
|
|
447
|
+
// Can't parse - try executing as-is through unified registry
|
|
448
|
+
mcpLogger.debug(`[${functionTag}] Cannot parse function name format: ${functionName}, trying unified registry`);
|
|
449
|
+
const result = await unifiedRegistry.executeTool(functionName, actualParameters, finalContext);
|
|
450
|
+
return result;
|
|
380
451
|
}
|
|
381
452
|
// Handle built-in NeuroLink servers directly
|
|
382
453
|
if (serverId === "neurolink-utility" ||
|
|
@@ -541,3 +612,31 @@ export async function isFunctionCallingAvailable() {
|
|
|
541
612
|
return false;
|
|
542
613
|
}
|
|
543
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Utility function to create a named tool object for debugging
|
|
617
|
+
*/
|
|
618
|
+
export function createNamedTool(name, toolDef) {
|
|
619
|
+
return {
|
|
620
|
+
name,
|
|
621
|
+
description: toolDef.description,
|
|
622
|
+
parameters: toolDef.parameters,
|
|
623
|
+
execute: toolDef.execute,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Get tools with proper name properties for debugging
|
|
628
|
+
*/
|
|
629
|
+
export async function getToolsWithNames() {
|
|
630
|
+
try {
|
|
631
|
+
const { toolsObject } = await getAvailableFunctionTools();
|
|
632
|
+
const namedTools = {};
|
|
633
|
+
for (const [name, tool] of Object.entries(toolsObject)) {
|
|
634
|
+
namedTools[name] = createNamedTool(name, tool);
|
|
635
|
+
}
|
|
636
|
+
return namedTools;
|
|
637
|
+
}
|
|
638
|
+
catch (error) {
|
|
639
|
+
mcpLogger.warn("[getToolsWithNames] Failed to get tools with names:", error);
|
|
640
|
+
return {};
|
|
641
|
+
}
|
|
642
|
+
}
|
|
@@ -244,11 +244,26 @@ Response (JSON array only):`;
|
|
|
244
244
|
exists: async () => false,
|
|
245
245
|
},
|
|
246
246
|
path: {
|
|
247
|
-
join: (...paths) =>
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
join: (...paths) => {
|
|
248
|
+
const pathModule = require("path");
|
|
249
|
+
return pathModule.join(...paths);
|
|
250
|
+
},
|
|
251
|
+
resolve: (...paths) => {
|
|
252
|
+
const pathModule = require("path");
|
|
253
|
+
return pathModule.resolve(...paths);
|
|
254
|
+
},
|
|
255
|
+
relative: (from, to) => {
|
|
256
|
+
const pathModule = require("path");
|
|
257
|
+
return pathModule.relative(from, to);
|
|
258
|
+
},
|
|
259
|
+
dirname: (pathArg) => {
|
|
260
|
+
const pathModule = require("path");
|
|
261
|
+
return pathModule.dirname(pathArg);
|
|
262
|
+
},
|
|
263
|
+
basename: (pathArg, ext) => {
|
|
264
|
+
const pathModule = require("path");
|
|
265
|
+
return pathModule.basename(pathArg, ext);
|
|
266
|
+
},
|
|
252
267
|
},
|
|
253
268
|
grantedPermissions: [],
|
|
254
269
|
log: console.log,
|
|
@@ -409,6 +424,7 @@ Please provide a natural response based on the tool results.`;
|
|
|
409
424
|
const tools = {};
|
|
410
425
|
for (const [name, tool] of this.tools) {
|
|
411
426
|
tools[name] = {
|
|
427
|
+
name: name, // Include the tool name as a property
|
|
412
428
|
description: tool.description,
|
|
413
429
|
inputSchema: tool.inputSchema,
|
|
414
430
|
};
|
|
@@ -16,10 +16,15 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
16
16
|
private enableFunctionCalling;
|
|
17
17
|
private sessionId;
|
|
18
18
|
private userId;
|
|
19
|
+
private cachedToolsObject;
|
|
20
|
+
private cachedToolMap;
|
|
21
|
+
private cacheTimestamp;
|
|
22
|
+
private readonly cacheExpiryMs;
|
|
19
23
|
constructor(baseProvider: AIProvider, options?: {
|
|
20
24
|
enableFunctionCalling?: boolean;
|
|
21
25
|
sessionId?: string;
|
|
22
26
|
userId?: string;
|
|
27
|
+
cacheExpiryMs?: number;
|
|
23
28
|
});
|
|
24
29
|
/**
|
|
25
30
|
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
@@ -31,7 +36,11 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
31
36
|
*/
|
|
32
37
|
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
33
38
|
/**
|
|
34
|
-
* Generate text using AI SDK's
|
|
39
|
+
* Generate text with tools using the AI SDK's generate function (with tools object)
|
|
40
|
+
*/
|
|
41
|
+
private generateWithToolsObject;
|
|
42
|
+
/**
|
|
43
|
+
* Generate text using AI SDK's native function calling (legacy array-based)
|
|
35
44
|
*/
|
|
36
45
|
private generateWithTools;
|
|
37
46
|
/**
|
|
@@ -44,7 +53,11 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
44
53
|
*/
|
|
45
54
|
private sanitizeToolName;
|
|
46
55
|
/**
|
|
47
|
-
*
|
|
56
|
+
* Wrap tools with proper execution context (for object-based tools)
|
|
57
|
+
*/
|
|
58
|
+
private wrapToolsWithExecution;
|
|
59
|
+
/**
|
|
60
|
+
* Convert our tools to AI SDK format with proper execution (legacy array-based)
|
|
48
61
|
*/
|
|
49
62
|
private convertToAISDKTools;
|
|
50
63
|
/**
|
|
@@ -54,6 +67,53 @@ export declare class FunctionCallingProvider implements AIProvider {
|
|
|
54
67
|
/**
|
|
55
68
|
* Alias for generate() - CLI-SDK consistency
|
|
56
69
|
*/
|
|
70
|
+
/**
|
|
71
|
+
* Clear cached tools - Cache Invalidation Strategy
|
|
72
|
+
*
|
|
73
|
+
* WHEN TO CALL clearToolsCache():
|
|
74
|
+
*
|
|
75
|
+
* 1. **MCP Server Changes**: When MCP servers are added, removed, or restarted
|
|
76
|
+
* - After calling unifiedRegistry.addServer() or removeServer()
|
|
77
|
+
* - When MCP server configurations change
|
|
78
|
+
* - After MCP server restart or reconnection
|
|
79
|
+
*
|
|
80
|
+
* 2. **Tool Registration Changes**: When custom tools are modified
|
|
81
|
+
* - After registering new SDK tools via registerTool()
|
|
82
|
+
* - When tool implementations change
|
|
83
|
+
* - After unregistering tools
|
|
84
|
+
*
|
|
85
|
+
* 3. **Provider Reinitialization**: When the provider context changes
|
|
86
|
+
* - Before switching between different AI providers
|
|
87
|
+
* - When session context changes significantly
|
|
88
|
+
* - After provider authentication refresh
|
|
89
|
+
*
|
|
90
|
+
* 4. **Error Recovery**: When tool execution encounters systematic failures
|
|
91
|
+
* - After MCP connection errors are resolved
|
|
92
|
+
* - When tool discovery needs to be re-run
|
|
93
|
+
* - During error recovery workflows
|
|
94
|
+
*
|
|
95
|
+
* 5. **Development/Testing**: During development and testing cycles
|
|
96
|
+
* - Between test cases that modify tool availability
|
|
97
|
+
* - When testing different tool configurations
|
|
98
|
+
* - During hot reloading scenarios
|
|
99
|
+
*
|
|
100
|
+
* CACHE LIFECYCLE:
|
|
101
|
+
* - Cache is populated on first generate() call via getAvailableFunctionTools()
|
|
102
|
+
* - Cache persists across multiple generate() calls for performance
|
|
103
|
+
* - Cache is invalidated by calling this method
|
|
104
|
+
* - Next generate() call will rebuild cache from current tool state
|
|
105
|
+
*
|
|
106
|
+
* PERFORMANCE IMPACT:
|
|
107
|
+
* - Clearing cache forces tool discovery on next usage (~100-500ms overhead)
|
|
108
|
+
* - Recommended to clear cache proactively rather than reactively
|
|
109
|
+
* - Consider batching tool changes before clearing cache
|
|
110
|
+
*
|
|
111
|
+
* THREAD SAFETY:
|
|
112
|
+
* - This method is not thread-safe
|
|
113
|
+
* - Avoid calling during active generate() operations
|
|
114
|
+
* - Safe to call between separate AI generation requests
|
|
115
|
+
*/
|
|
116
|
+
clearToolsCache(): void;
|
|
57
117
|
/**
|
|
58
118
|
* Short alias for generate() - CLI-SDK consistency
|
|
59
119
|
*/
|
|
@@ -66,6 +126,7 @@ export declare function createFunctionCallingProvider(baseProvider: AIProvider,
|
|
|
66
126
|
enableFunctionCalling?: boolean;
|
|
67
127
|
sessionId?: string;
|
|
68
128
|
userId?: string;
|
|
129
|
+
cacheExpiryMs?: number;
|
|
69
130
|
}): AIProvider;
|
|
70
131
|
/**
|
|
71
132
|
* Enhanced MCP Provider Factory that creates function-calling enabled providers
|
|
@@ -77,4 +138,5 @@ export declare function createMCPAwareProviderV3(baseProvider: AIProvider, optio
|
|
|
77
138
|
enableFunctionCalling?: boolean;
|
|
78
139
|
sessionId?: string;
|
|
79
140
|
userId?: string;
|
|
141
|
+
cacheExpiryMs?: number;
|
|
80
142
|
}): AIProvider;
|