@juspay/neurolink 6.1.0 → 6.2.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/CHANGELOG.md +16 -6
- package/dist/agent/direct-tools.js +6 -5
- package/dist/cli/commands/config.d.ts +13 -13
- package/dist/cli/index.js +3 -9
- package/dist/config/configManager.js +11 -10
- package/dist/core/analytics.d.ts +11 -1
- package/dist/core/analytics.js +2 -2
- package/dist/core/base-provider.js +4 -18
- package/dist/core/dynamic-models.d.ts +8 -8
- package/dist/core/factory.js +3 -11
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -11
- package/dist/lib/agent/direct-tools.js +6 -5
- package/dist/lib/config/configManager.js +11 -10
- package/dist/lib/core/analytics.d.ts +11 -1
- package/dist/lib/core/analytics.js +2 -2
- package/dist/lib/core/base-provider.js +4 -18
- package/dist/lib/core/dynamic-models.d.ts +8 -8
- package/dist/lib/core/factory.js +3 -11
- package/dist/lib/index.d.ts +2 -4
- package/dist/lib/index.js +2 -11
- package/dist/lib/mcp/factory.d.ts +1 -1
- package/dist/lib/mcp/index.d.ts +9 -21
- package/dist/lib/mcp/index.js +16 -57
- package/dist/lib/mcp/registry.js +1 -1
- package/dist/lib/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/lib/mcp/tool-registry.js +1 -1
- package/dist/lib/neurolink.d.ts +1 -9
- package/dist/lib/neurolink.js +22 -71
- package/dist/lib/providers/amazon-bedrock.js +5 -16
- package/dist/lib/providers/anthropic-baseprovider.js +3 -21
- package/dist/lib/providers/anthropic.js +4 -7
- package/dist/lib/providers/azure-openai.js +6 -3
- package/dist/lib/providers/google-vertex.js +5 -9
- package/dist/lib/providers/huggingFace.js +5 -10
- package/dist/lib/providers/mistral.js +5 -8
- package/dist/lib/providers/openAI.js +4 -7
- package/dist/lib/telemetry/index.js +2 -1
- package/dist/lib/utils/logger.d.ts +62 -2
- package/dist/lib/utils/logger.js +174 -9
- package/dist/lib/utils/providerConfig.d.ts +117 -0
- package/dist/lib/utils/providerConfig.js +353 -0
- package/dist/lib/utils/providerUtils.d.ts +2 -1
- package/dist/lib/utils/providerUtils.js +53 -36
- package/dist/lib/utils/timeout.d.ts +72 -1
- package/dist/lib/utils/timeout.js +203 -2
- package/dist/mcp/factory.d.ts +1 -1
- package/dist/mcp/index.d.ts +9 -21
- package/dist/mcp/index.js +16 -57
- package/dist/mcp/registry.js +1 -1
- package/dist/mcp/servers/ai-providers/ai-analysis-tools.js +2 -1
- package/dist/mcp/tool-registry.js +1 -1
- package/dist/neurolink.d.ts +1 -9
- package/dist/neurolink.js +22 -71
- package/dist/providers/amazon-bedrock.js +5 -16
- package/dist/providers/anthropic-baseprovider.js +3 -21
- package/dist/providers/anthropic.js +4 -7
- package/dist/providers/azure-openai.js +6 -3
- package/dist/providers/google-vertex.js +5 -9
- package/dist/providers/huggingFace.js +5 -10
- package/dist/providers/mistral.js +5 -8
- package/dist/providers/openAI.js +4 -7
- package/dist/telemetry/index.js +2 -1
- package/dist/utils/logger.d.ts +62 -2
- package/dist/utils/logger.js +174 -9
- package/dist/utils/providerConfig.d.ts +117 -0
- package/dist/utils/providerConfig.js +353 -0
- package/dist/utils/providerUtils.d.ts +2 -1
- package/dist/utils/providerUtils.js +53 -36
- package/dist/utils/timeout.d.ts +72 -1
- package/dist/utils/timeout.js +203 -2
- package/package.json +1 -1
- package/dist/chat/client-utils.d.ts +0 -95
- package/dist/chat/client-utils.js +0 -315
- package/dist/chat/index.d.ts +0 -24
- package/dist/chat/index.js +0 -33
- package/dist/chat/session-storage.d.ts +0 -77
- package/dist/chat/session-storage.js +0 -233
- package/dist/chat/session.d.ts +0 -96
- package/dist/chat/session.js +0 -257
- package/dist/chat/sse-handler.d.ts +0 -49
- package/dist/chat/sse-handler.js +0 -259
- package/dist/chat/types.d.ts +0 -74
- package/dist/chat/types.js +0 -5
- package/dist/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/chat/websocket-chat-handler.js +0 -262
- package/dist/cli/commands/mcp.d.ts +0 -20
- package/dist/cli/commands/mcp.js +0 -1272
- package/dist/core/defaults.d.ts +0 -19
- package/dist/core/defaults.js +0 -29
- package/dist/core/evaluation-config.d.ts +0 -29
- package/dist/core/evaluation-config.js +0 -144
- package/dist/factories/compatibility-factory.d.ts +0 -35
- package/dist/factories/compatibility-factory.js +0 -71
- package/dist/factories/provider-generate-factory.d.ts +0 -20
- package/dist/factories/provider-generate-factory.js +0 -93
- package/dist/lib/chat/client-utils.d.ts +0 -95
- package/dist/lib/chat/client-utils.js +0 -315
- package/dist/lib/chat/index.d.ts +0 -24
- package/dist/lib/chat/index.js +0 -33
- package/dist/lib/chat/session-storage.d.ts +0 -77
- package/dist/lib/chat/session-storage.js +0 -233
- package/dist/lib/chat/session.d.ts +0 -96
- package/dist/lib/chat/session.js +0 -257
- package/dist/lib/chat/sse-handler.d.ts +0 -49
- package/dist/lib/chat/sse-handler.js +0 -259
- package/dist/lib/chat/types.d.ts +0 -74
- package/dist/lib/chat/types.js +0 -5
- package/dist/lib/chat/websocket-chat-handler.d.ts +0 -37
- package/dist/lib/chat/websocket-chat-handler.js +0 -262
- package/dist/lib/core/defaults.d.ts +0 -19
- package/dist/lib/core/defaults.js +0 -29
- package/dist/lib/core/evaluation-config.d.ts +0 -29
- package/dist/lib/core/evaluation-config.js +0 -144
- package/dist/lib/factories/compatibility-factory.d.ts +0 -35
- package/dist/lib/factories/compatibility-factory.js +0 -71
- package/dist/lib/factories/provider-generate-factory.d.ts +0 -20
- package/dist/lib/factories/provider-generate-factory.js +0 -93
- package/dist/lib/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/lib/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/lib/mcp/auto-discovery.d.ts +0 -62
- package/dist/lib/mcp/auto-discovery.js +0 -149
- package/dist/lib/mcp/client.d.ts +0 -68
- package/dist/lib/mcp/client.js +0 -248
- package/dist/lib/mcp/config.d.ts +0 -31
- package/dist/lib/mcp/config.js +0 -99
- package/dist/lib/mcp/context-manager.d.ts +0 -171
- package/dist/lib/mcp/context-manager.js +0 -362
- package/dist/lib/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/lib/mcp/contracts/mcp-contract.js +0 -58
- package/dist/lib/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/lib/mcp/core/plugin-manager.js +0 -110
- package/dist/lib/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/lib/mcp/demo/plugin-demo.js +0 -118
- package/dist/lib/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/lib/mcp/dynamic-chain-executor.js +0 -489
- package/dist/lib/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/lib/mcp/dynamic-orchestrator.js +0 -351
- package/dist/lib/mcp/ecosystem.d.ts +0 -75
- package/dist/lib/mcp/ecosystem.js +0 -161
- package/dist/lib/mcp/error-manager.d.ts +0 -254
- package/dist/lib/mcp/error-manager.js +0 -501
- package/dist/lib/mcp/error-recovery.d.ts +0 -159
- package/dist/lib/mcp/error-recovery.js +0 -405
- package/dist/lib/mcp/external-client.d.ts +0 -88
- package/dist/lib/mcp/external-client.js +0 -331
- package/dist/lib/mcp/external-manager.d.ts +0 -112
- package/dist/lib/mcp/external-manager.js +0 -308
- package/dist/lib/mcp/function-calling.d.ts +0 -65
- package/dist/lib/mcp/function-calling.js +0 -642
- package/dist/lib/mcp/health-monitor.d.ts +0 -257
- package/dist/lib/mcp/health-monitor.js +0 -630
- package/dist/lib/mcp/initialize-tools.d.ts +0 -29
- package/dist/lib/mcp/initialize-tools.js +0 -261
- package/dist/lib/mcp/initialize.d.ts +0 -18
- package/dist/lib/mcp/initialize.js +0 -62
- package/dist/lib/mcp/logging.d.ts +0 -38
- package/dist/lib/mcp/logging.js +0 -100
- package/dist/lib/mcp/manager.d.ts +0 -68
- package/dist/lib/mcp/manager.js +0 -176
- package/dist/lib/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/lib/mcp/neurolink-mcp-client.js +0 -462
- package/dist/lib/mcp/orchestrator.d.ts +0 -302
- package/dist/lib/mcp/orchestrator.js +0 -703
- package/dist/lib/mcp/plugin-manager.d.ts +0 -98
- package/dist/lib/mcp/plugin-manager.js +0 -296
- package/dist/lib/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/lib/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/lib/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/lib/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/lib/mcp/security-manager.d.ts +0 -87
- package/dist/lib/mcp/security-manager.js +0 -344
- package/dist/lib/mcp/semaphore-manager.d.ts +0 -137
- package/dist/lib/mcp/semaphore-manager.js +0 -329
- package/dist/lib/mcp/session-manager.d.ts +0 -187
- package/dist/lib/mcp/session-manager.js +0 -400
- package/dist/lib/mcp/session-persistence.d.ts +0 -93
- package/dist/lib/mcp/session-persistence.js +0 -301
- package/dist/lib/mcp/tool-integration.d.ts +0 -58
- package/dist/lib/mcp/tool-integration.js +0 -203
- package/dist/lib/mcp/transport-manager.d.ts +0 -154
- package/dist/lib/mcp/transport-manager.js +0 -334
- package/dist/lib/mcp/unified-mcp.d.ts +0 -133
- package/dist/lib/mcp/unified-mcp.js +0 -251
- package/dist/lib/mcp/unified-registry.d.ts +0 -165
- package/dist/lib/mcp/unified-registry.js +0 -538
- package/dist/lib/providers/analytics-helper.d.ts +0 -38
- package/dist/lib/providers/analytics-helper.js +0 -216
- package/dist/lib/providers/function-calling-provider.d.ts +0 -142
- package/dist/lib/providers/function-calling-provider.js +0 -630
- package/dist/lib/providers/mcp-provider.d.ts +0 -75
- package/dist/lib/providers/mcp-provider.js +0 -283
- package/dist/lib/providers/timeout-wrapper.d.ts +0 -40
- package/dist/lib/providers/timeout-wrapper.js +0 -100
- package/dist/lib/sdk/tool-extension.d.ts +0 -181
- package/dist/lib/sdk/tool-extension.js +0 -284
- package/dist/lib/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/lib/services/streaming/streaming-manager.js +0 -245
- package/dist/lib/services/types.d.ts +0 -156
- package/dist/lib/services/types.js +0 -2
- package/dist/lib/services/websocket/websocket-server.d.ts +0 -34
- package/dist/lib/services/websocket/websocket-server.js +0 -305
- package/dist/lib/utils/provider-validation.d.ts +0 -36
- package/dist/lib/utils/provider-validation.js +0 -625
- package/dist/lib/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/lib/utils/providerUtils-fixed.js +0 -94
- package/dist/lib/utils/streaming-utils.d.ts +0 -79
- package/dist/lib/utils/streaming-utils.js +0 -198
- package/dist/lib/utils/timeout-manager.d.ts +0 -75
- package/dist/lib/utils/timeout-manager.js +0 -244
- package/dist/mcp/adapters/plugin-bridge.d.ts +0 -40
- package/dist/mcp/adapters/plugin-bridge.js +0 -89
- package/dist/mcp/auto-discovery.d.ts +0 -62
- package/dist/mcp/auto-discovery.js +0 -149
- package/dist/mcp/client.d.ts +0 -68
- package/dist/mcp/client.js +0 -248
- package/dist/mcp/config.d.ts +0 -31
- package/dist/mcp/config.js +0 -99
- package/dist/mcp/context-manager.d.ts +0 -171
- package/dist/mcp/context-manager.js +0 -362
- package/dist/mcp/contracts/mcp-contract.d.ts +0 -169
- package/dist/mcp/contracts/mcp-contract.js +0 -58
- package/dist/mcp/core/plugin-manager.d.ts +0 -46
- package/dist/mcp/core/plugin-manager.js +0 -110
- package/dist/mcp/demo/plugin-demo.d.ts +0 -20
- package/dist/mcp/demo/plugin-demo.js +0 -118
- package/dist/mcp/dynamic-chain-executor.d.ts +0 -225
- package/dist/mcp/dynamic-chain-executor.js +0 -489
- package/dist/mcp/dynamic-orchestrator.d.ts +0 -115
- package/dist/mcp/dynamic-orchestrator.js +0 -351
- package/dist/mcp/ecosystem.d.ts +0 -75
- package/dist/mcp/ecosystem.js +0 -162
- package/dist/mcp/error-manager.d.ts +0 -254
- package/dist/mcp/error-manager.js +0 -501
- package/dist/mcp/error-recovery.d.ts +0 -159
- package/dist/mcp/error-recovery.js +0 -405
- package/dist/mcp/external-client.d.ts +0 -88
- package/dist/mcp/external-client.js +0 -331
- package/dist/mcp/external-manager.d.ts +0 -112
- package/dist/mcp/external-manager.js +0 -308
- package/dist/mcp/function-calling.d.ts +0 -65
- package/dist/mcp/function-calling.js +0 -642
- package/dist/mcp/health-monitor.d.ts +0 -257
- package/dist/mcp/health-monitor.js +0 -630
- package/dist/mcp/initialize-tools.d.ts +0 -29
- package/dist/mcp/initialize-tools.js +0 -262
- package/dist/mcp/initialize.d.ts +0 -18
- package/dist/mcp/initialize.js +0 -62
- package/dist/mcp/logging.d.ts +0 -38
- package/dist/mcp/logging.js +0 -100
- package/dist/mcp/manager.d.ts +0 -68
- package/dist/mcp/manager.js +0 -176
- package/dist/mcp/neurolink-mcp-client.d.ts +0 -97
- package/dist/mcp/neurolink-mcp-client.js +0 -462
- package/dist/mcp/orchestrator.d.ts +0 -302
- package/dist/mcp/orchestrator.js +0 -703
- package/dist/mcp/plugin-manager.d.ts +0 -98
- package/dist/mcp/plugin-manager.js +0 -297
- package/dist/mcp/plugins/core/filesystem-mcp.d.ts +0 -36
- package/dist/mcp/plugins/core/filesystem-mcp.js +0 -142
- package/dist/mcp/plugins/core/neurolink-mcp.json +0 -17
- package/dist/mcp/plugins/filesystem-mcp.d.ts +0 -37
- package/dist/mcp/plugins/filesystem-mcp.js +0 -54
- package/dist/mcp/security-manager.d.ts +0 -87
- package/dist/mcp/security-manager.js +0 -344
- package/dist/mcp/semaphore-manager.d.ts +0 -137
- package/dist/mcp/semaphore-manager.js +0 -329
- package/dist/mcp/session-manager.d.ts +0 -187
- package/dist/mcp/session-manager.js +0 -400
- package/dist/mcp/session-persistence.d.ts +0 -93
- package/dist/mcp/session-persistence.js +0 -302
- package/dist/mcp/tool-integration.d.ts +0 -58
- package/dist/mcp/tool-integration.js +0 -203
- package/dist/mcp/transport-manager.d.ts +0 -154
- package/dist/mcp/transport-manager.js +0 -335
- package/dist/mcp/unified-mcp.d.ts +0 -133
- package/dist/mcp/unified-mcp.js +0 -251
- package/dist/mcp/unified-registry.d.ts +0 -165
- package/dist/mcp/unified-registry.js +0 -539
- package/dist/providers/analytics-helper.d.ts +0 -38
- package/dist/providers/analytics-helper.js +0 -216
- package/dist/providers/function-calling-provider.d.ts +0 -142
- package/dist/providers/function-calling-provider.js +0 -630
- package/dist/providers/mcp-provider.d.ts +0 -75
- package/dist/providers/mcp-provider.js +0 -283
- package/dist/providers/timeout-wrapper.d.ts +0 -40
- package/dist/providers/timeout-wrapper.js +0 -100
- package/dist/sdk/tool-extension.d.ts +0 -181
- package/dist/sdk/tool-extension.js +0 -284
- package/dist/services/streaming/streaming-manager.d.ts +0 -29
- package/dist/services/streaming/streaming-manager.js +0 -245
- package/dist/services/types.d.ts +0 -156
- package/dist/services/types.js +0 -2
- package/dist/services/websocket/websocket-server.d.ts +0 -34
- package/dist/services/websocket/websocket-server.js +0 -306
- package/dist/utils/provider-validation.d.ts +0 -36
- package/dist/utils/provider-validation.js +0 -625
- package/dist/utils/providerUtils-fixed.d.ts +0 -8
- package/dist/utils/providerUtils-fixed.js +0 -94
- package/dist/utils/streaming-utils.d.ts +0 -79
- package/dist/utils/streaming-utils.js +0 -198
- package/dist/utils/timeout-manager.d.ts +0 -75
- package/dist/utils/timeout-manager.js +0 -244
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP-Aware AI Provider
|
|
3
|
-
* Integrates MCP tools with AI providers following Lighthouse's pattern
|
|
4
|
-
*/
|
|
5
|
-
import type { AIProvider, TextGenerationOptions } from "../core/types.js";
|
|
6
|
-
import type { Schema } from "ai";
|
|
7
|
-
import type { GenerateResult } from "../types/generate-types.js";
|
|
8
|
-
import type { ZodType, ZodTypeDef } from "zod";
|
|
9
|
-
import type { StreamOptions, StreamResult } from "../types/stream-types.js";
|
|
10
|
-
/**
|
|
11
|
-
* MCP-Aware Provider Configuration
|
|
12
|
-
*/
|
|
13
|
-
export interface MCPProviderConfig {
|
|
14
|
-
baseProvider: AIProvider;
|
|
15
|
-
providerName?: string;
|
|
16
|
-
modelName?: string;
|
|
17
|
-
enableMCP?: boolean;
|
|
18
|
-
sessionId?: string;
|
|
19
|
-
userId?: string;
|
|
20
|
-
organizationId?: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* MCP-Aware AI Provider
|
|
24
|
-
* Wraps any AI provider with MCP tool capabilities
|
|
25
|
-
*/
|
|
26
|
-
export declare class MCPAwareProvider implements AIProvider {
|
|
27
|
-
private baseProvider;
|
|
28
|
-
private config;
|
|
29
|
-
private sessionId;
|
|
30
|
-
private mcpInitialized;
|
|
31
|
-
constructor(config: MCPProviderConfig);
|
|
32
|
-
/**
|
|
33
|
-
* Initialize MCP tools for this session
|
|
34
|
-
*/
|
|
35
|
-
private initializeMCP;
|
|
36
|
-
/**
|
|
37
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
38
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
39
|
-
*/
|
|
40
|
-
stream(optionsOrPrompt: StreamOptions | string, analysisSchema?: unknown): Promise<StreamResult>;
|
|
41
|
-
generate(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
42
|
-
/**
|
|
43
|
-
* Detect if the prompt is requesting tool usage
|
|
44
|
-
*/
|
|
45
|
-
private detectToolRequest;
|
|
46
|
-
/**
|
|
47
|
-
* Get session statistics
|
|
48
|
-
*/
|
|
49
|
-
getSessionStats(): {
|
|
50
|
-
sessionId: string;
|
|
51
|
-
toolCount: number;
|
|
52
|
-
executionCount: number;
|
|
53
|
-
isConnected: boolean;
|
|
54
|
-
uptime: number;
|
|
55
|
-
} | null;
|
|
56
|
-
/**
|
|
57
|
-
* Clean up session
|
|
58
|
-
*/
|
|
59
|
-
cleanup(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Alias for generate() - CLI-SDK consistency
|
|
62
|
-
*/
|
|
63
|
-
/**
|
|
64
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
65
|
-
*/
|
|
66
|
-
gen(optionsOrPrompt: TextGenerationOptions | string, analysisSchema?: ZodType<unknown, ZodTypeDef, unknown> | Schema<unknown>): Promise<GenerateResult>;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Create an MCP-aware provider
|
|
70
|
-
*/
|
|
71
|
-
export declare function createMCPAwareProvider(baseProvider: AIProvider, config?: Partial<MCPProviderConfig>): MCPAwareProvider;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a provider is MCP-aware
|
|
74
|
-
*/
|
|
75
|
-
export declare function isMCPAwareProvider(provider: AIProvider): provider is MCPAwareProvider;
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink MCP-Aware AI Provider
|
|
3
|
-
* Integrates MCP tools with AI providers following Lighthouse's pattern
|
|
4
|
-
*/
|
|
5
|
-
import { getMCPManager } from "../mcp/manager.js";
|
|
6
|
-
import { initializeMCPTools } from "../mcp/initialize-tools.js";
|
|
7
|
-
import { logger } from "../utils/logger.js";
|
|
8
|
-
import { v4 as uuidv4 } from "uuid";
|
|
9
|
-
/**
|
|
10
|
-
* MCP-Aware AI Provider
|
|
11
|
-
* Wraps any AI provider with MCP tool capabilities
|
|
12
|
-
*/
|
|
13
|
-
export class MCPAwareProvider {
|
|
14
|
-
baseProvider;
|
|
15
|
-
config;
|
|
16
|
-
sessionId;
|
|
17
|
-
mcpInitialized = false;
|
|
18
|
-
constructor(config) {
|
|
19
|
-
this.baseProvider = config.baseProvider;
|
|
20
|
-
this.config = config;
|
|
21
|
-
this.sessionId = config.sessionId || uuidv4();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Initialize MCP tools for this session
|
|
25
|
-
*/
|
|
26
|
-
async initializeMCP() {
|
|
27
|
-
if (this.mcpInitialized || this.config.enableMCP === false) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
// Get or create MCP client for this session
|
|
32
|
-
const mcpClient = getMCPManager(this.sessionId, {
|
|
33
|
-
userId: this.config.userId || "anonymous",
|
|
34
|
-
aiProvider: this.config.providerName || "unknown",
|
|
35
|
-
modelId: this.config.modelName,
|
|
36
|
-
});
|
|
37
|
-
// Create execution context
|
|
38
|
-
const context = {
|
|
39
|
-
sessionId: this.sessionId,
|
|
40
|
-
userId: this.config.userId || "anonymous",
|
|
41
|
-
organizationId: this.config.organizationId || "default",
|
|
42
|
-
aiProvider: this.config.providerName || "unknown",
|
|
43
|
-
modelId: this.config.modelName,
|
|
44
|
-
timestamp: Date.now(),
|
|
45
|
-
// Required properties
|
|
46
|
-
secureFS: {
|
|
47
|
-
readFile: async () => {
|
|
48
|
-
throw new Error("secureFS not configured");
|
|
49
|
-
},
|
|
50
|
-
writeFile: async () => {
|
|
51
|
-
throw new Error("secureFS not configured");
|
|
52
|
-
},
|
|
53
|
-
readdir: async () => {
|
|
54
|
-
throw new Error("secureFS not configured");
|
|
55
|
-
},
|
|
56
|
-
stat: async () => {
|
|
57
|
-
throw new Error("secureFS not configured");
|
|
58
|
-
},
|
|
59
|
-
mkdir: async () => {
|
|
60
|
-
throw new Error("secureFS not configured");
|
|
61
|
-
},
|
|
62
|
-
exists: async () => false,
|
|
63
|
-
},
|
|
64
|
-
path: {
|
|
65
|
-
join: (...paths) => {
|
|
66
|
-
const pathModule = require("path");
|
|
67
|
-
return pathModule.join(...paths);
|
|
68
|
-
},
|
|
69
|
-
resolve: (...paths) => {
|
|
70
|
-
const pathModule = require("path");
|
|
71
|
-
return pathModule.resolve(...paths);
|
|
72
|
-
},
|
|
73
|
-
relative: (from, to) => {
|
|
74
|
-
const pathModule = require("path");
|
|
75
|
-
return pathModule.relative(from, to);
|
|
76
|
-
},
|
|
77
|
-
dirname: (pathArg) => {
|
|
78
|
-
const pathModule = require("path");
|
|
79
|
-
return pathModule.dirname(pathArg);
|
|
80
|
-
},
|
|
81
|
-
basename: (pathArg, ext) => {
|
|
82
|
-
const pathModule = require("path");
|
|
83
|
-
return pathModule.basename(pathArg, ext);
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
grantedPermissions: [],
|
|
87
|
-
log: console.log,
|
|
88
|
-
};
|
|
89
|
-
// Initialize all MCP tools
|
|
90
|
-
initializeMCPTools(this.sessionId, mcpClient, context);
|
|
91
|
-
this.mcpInitialized = true;
|
|
92
|
-
const tools = mcpClient.getTools();
|
|
93
|
-
const toolCount = Object.keys(tools).length;
|
|
94
|
-
logger.info(`[MCP Provider] Initialized ${toolCount} tools for session ${this.sessionId}`);
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
logger.error(`[MCP Provider] Failed to initialize MCP for session ${this.sessionId}`, error);
|
|
98
|
-
// Continue without MCP tools if initialization fails
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* PRIMARY METHOD: Stream content using AI (recommended for new code)
|
|
103
|
-
* Future-ready for multi-modal capabilities with current text focus
|
|
104
|
-
*/
|
|
105
|
-
async stream(optionsOrPrompt, analysisSchema) {
|
|
106
|
-
const functionTag = "MCPAwareProvider.stream";
|
|
107
|
-
const startTime = Date.now();
|
|
108
|
-
// Parse parameters - support both string and options object
|
|
109
|
-
const options = typeof optionsOrPrompt === "string"
|
|
110
|
-
? { input: { text: optionsOrPrompt } }
|
|
111
|
-
: optionsOrPrompt;
|
|
112
|
-
// Validate input
|
|
113
|
-
if (!options?.input?.text ||
|
|
114
|
-
typeof options.input.text !== "string" ||
|
|
115
|
-
options.input.text.trim() === "") {
|
|
116
|
-
throw new Error("Stream options must include input.text as a non-empty string");
|
|
117
|
-
}
|
|
118
|
-
// Use base provider's stream implementation
|
|
119
|
-
const baseResult = await this.baseProvider.stream(options);
|
|
120
|
-
if (!baseResult) {
|
|
121
|
-
throw new Error("No stream response received from provider");
|
|
122
|
-
}
|
|
123
|
-
// Return the result with MCP metadata
|
|
124
|
-
return {
|
|
125
|
-
...baseResult,
|
|
126
|
-
provider: "mcp",
|
|
127
|
-
model: options.model || "unknown",
|
|
128
|
-
metadata: {
|
|
129
|
-
streamId: `mcp-${Date.now()}`,
|
|
130
|
-
startTime,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
async generate(optionsOrPrompt, analysisSchema) {
|
|
135
|
-
// Ensure MCP is initialized
|
|
136
|
-
await this.initializeMCP();
|
|
137
|
-
// Parse options
|
|
138
|
-
const options = typeof optionsOrPrompt === "string"
|
|
139
|
-
? { prompt: optionsOrPrompt }
|
|
140
|
-
: optionsOrPrompt;
|
|
141
|
-
// Validate prompt is provided
|
|
142
|
-
if (!options.prompt || options.prompt.trim() === "") {
|
|
143
|
-
throw new Error("MCP Provider requires a valid prompt. Please provide a non-empty prompt string.");
|
|
144
|
-
}
|
|
145
|
-
// Check if prompt requests tool usage
|
|
146
|
-
const needsTools = this.detectToolRequest(options.prompt);
|
|
147
|
-
if (needsTools && this.mcpInitialized) {
|
|
148
|
-
// Get MCP client
|
|
149
|
-
const mcpClient = getMCPManager(this.sessionId);
|
|
150
|
-
// Create enhanced prompt with available tools
|
|
151
|
-
const tools = mcpClient.getTools();
|
|
152
|
-
const toolList = Object.keys(tools)
|
|
153
|
-
.map((name) => {
|
|
154
|
-
const tool = tools[name];
|
|
155
|
-
return `- ${name}: ${tool.description || "No description"}`;
|
|
156
|
-
})
|
|
157
|
-
.join("\n");
|
|
158
|
-
const enhancedPrompt = `${options.prompt}
|
|
159
|
-
|
|
160
|
-
Available tools:
|
|
161
|
-
${toolList}
|
|
162
|
-
|
|
163
|
-
To use a tool, respond with:
|
|
164
|
-
TOOL: <tool_name>
|
|
165
|
-
PARAMS: <json_params>
|
|
166
|
-
|
|
167
|
-
Otherwise, provide a direct response.`;
|
|
168
|
-
// Generate response with enhanced prompt
|
|
169
|
-
const response = await this.baseProvider.generate({
|
|
170
|
-
...options,
|
|
171
|
-
prompt: enhancedPrompt,
|
|
172
|
-
}, analysisSchema);
|
|
173
|
-
if (!response) {
|
|
174
|
-
return {
|
|
175
|
-
content: "No response generated",
|
|
176
|
-
provider: "mcp",
|
|
177
|
-
model: "unknown",
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
// Check if response includes tool invocation
|
|
181
|
-
const toolMatch = response.content.match(/TOOL:\s*(\S+)\s*\nPARAMS:\s*({.*})/s);
|
|
182
|
-
if (toolMatch) {
|
|
183
|
-
const toolName = toolMatch[1];
|
|
184
|
-
const toolParams = JSON.parse(toolMatch[2]);
|
|
185
|
-
// Execute tool
|
|
186
|
-
const toolResult = await mcpClient.executeTool(toolName, toolParams);
|
|
187
|
-
// Generate final response with tool result
|
|
188
|
-
const finalPrompt = `${options.prompt}
|
|
189
|
-
|
|
190
|
-
Tool ${toolName} was executed with result:
|
|
191
|
-
${JSON.stringify(toolResult, null, 2)}
|
|
192
|
-
|
|
193
|
-
Please provide a response based on this information.`;
|
|
194
|
-
const finalResponse = await this.baseProvider.generate({
|
|
195
|
-
...options,
|
|
196
|
-
prompt: finalPrompt,
|
|
197
|
-
}, analysisSchema);
|
|
198
|
-
if (!finalResponse) {
|
|
199
|
-
return {
|
|
200
|
-
content: "Tool execution failed",
|
|
201
|
-
provider: "mcp",
|
|
202
|
-
model: "unknown",
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
// Return response (tool usage is tracked internally)
|
|
206
|
-
return finalResponse;
|
|
207
|
-
}
|
|
208
|
-
return response;
|
|
209
|
-
}
|
|
210
|
-
// Regular generation without tools
|
|
211
|
-
const result = await this.baseProvider.generate(options);
|
|
212
|
-
if (!result) {
|
|
213
|
-
return {
|
|
214
|
-
content: "Base provider returned no result",
|
|
215
|
-
provider: "mcp",
|
|
216
|
-
model: "unknown",
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return result;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Detect if the prompt is requesting tool usage
|
|
223
|
-
*/
|
|
224
|
-
detectToolRequest(prompt) {
|
|
225
|
-
const toolKeywords = [
|
|
226
|
-
"use tool",
|
|
227
|
-
"call tool",
|
|
228
|
-
"execute tool",
|
|
229
|
-
"run tool",
|
|
230
|
-
"invoke tool",
|
|
231
|
-
"what tools",
|
|
232
|
-
"available tools",
|
|
233
|
-
"list tools",
|
|
234
|
-
];
|
|
235
|
-
const lowerPrompt = prompt.toLowerCase();
|
|
236
|
-
return toolKeywords.some((keyword) => lowerPrompt.includes(keyword));
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Get session statistics
|
|
240
|
-
*/
|
|
241
|
-
getSessionStats() {
|
|
242
|
-
if (!this.mcpInitialized) {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
const mcpClient = getMCPManager(this.sessionId);
|
|
246
|
-
return mcpClient.getStats();
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Clean up session
|
|
250
|
-
*/
|
|
251
|
-
async cleanup() {
|
|
252
|
-
if (this.mcpInitialized) {
|
|
253
|
-
const { removeMCPManager } = await import("../mcp/manager.js");
|
|
254
|
-
await removeMCPManager(this.sessionId);
|
|
255
|
-
this.mcpInitialized = false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Alias for generate() - CLI-SDK consistency
|
|
260
|
-
*/
|
|
261
|
-
/**
|
|
262
|
-
* Short alias for generate() - CLI-SDK consistency
|
|
263
|
-
*/
|
|
264
|
-
async gen(optionsOrPrompt, analysisSchema) {
|
|
265
|
-
return this.generate(optionsOrPrompt, analysisSchema);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Create an MCP-aware provider
|
|
270
|
-
*/
|
|
271
|
-
export function createMCPAwareProvider(baseProvider, config) {
|
|
272
|
-
return new MCPAwareProvider({
|
|
273
|
-
baseProvider,
|
|
274
|
-
enableMCP: true,
|
|
275
|
-
...config,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Check if a provider is MCP-aware
|
|
280
|
-
*/
|
|
281
|
-
export function isMCPAwareProvider(provider) {
|
|
282
|
-
return provider instanceof MCPAwareProvider;
|
|
283
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Timeout wrapper for AI provider operations
|
|
3
|
-
*
|
|
4
|
-
* Provides a consistent way to add timeout functionality to any async operation.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Wrap an async operation with a timeout
|
|
8
|
-
* @param promise - The promise to wrap
|
|
9
|
-
* @param timeout - Timeout duration (number in ms or string with unit)
|
|
10
|
-
* @param provider - Provider name for error messages
|
|
11
|
-
* @param operation - Operation type (generate or stream)
|
|
12
|
-
* @returns The result of the promise or throws TimeoutError
|
|
13
|
-
*/
|
|
14
|
-
export declare function withTimeout<T>(promise: Promise<T>, timeout: number | string | undefined, provider: string, operation: "generate" | "stream"): Promise<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Wrap a streaming async generator with timeout
|
|
17
|
-
* @param generator - The async generator to wrap
|
|
18
|
-
* @param timeout - Timeout duration for the entire stream
|
|
19
|
-
* @param provider - Provider name for error messages
|
|
20
|
-
* @returns Wrapped async generator that respects timeout
|
|
21
|
-
*/
|
|
22
|
-
export declare function withStreamingTimeout<T>(generator: AsyncGenerator<T>, timeout: number | string | undefined, provider: string): AsyncGenerator<T>;
|
|
23
|
-
/**
|
|
24
|
-
* Create an abort controller with timeout
|
|
25
|
-
* @param timeout - Timeout duration
|
|
26
|
-
* @param provider - Provider name for error messages
|
|
27
|
-
* @param operation - Operation type
|
|
28
|
-
* @returns AbortController and cleanup function
|
|
29
|
-
*/
|
|
30
|
-
export declare function createTimeoutController(timeout: number | string | undefined, provider: string, operation: "generate" | "stream"): {
|
|
31
|
-
controller: AbortController;
|
|
32
|
-
cleanup: () => void;
|
|
33
|
-
timeoutMs: number;
|
|
34
|
-
} | null;
|
|
35
|
-
/**
|
|
36
|
-
* Merge abort signals (for combining user abort with timeout)
|
|
37
|
-
* @param signals - Array of abort signals to merge
|
|
38
|
-
* @returns Combined abort controller
|
|
39
|
-
*/
|
|
40
|
-
export declare function mergeAbortSignals(signals: (AbortSignal | undefined)[]): AbortController;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Timeout wrapper for AI provider operations
|
|
3
|
-
*
|
|
4
|
-
* Provides a consistent way to add timeout functionality to any async operation.
|
|
5
|
-
*/
|
|
6
|
-
import { parseTimeout, TimeoutError, createTimeoutPromise, } from "../utils/timeout.js";
|
|
7
|
-
/**
|
|
8
|
-
* Wrap an async operation with a timeout
|
|
9
|
-
* @param promise - The promise to wrap
|
|
10
|
-
* @param timeout - Timeout duration (number in ms or string with unit)
|
|
11
|
-
* @param provider - Provider name for error messages
|
|
12
|
-
* @param operation - Operation type (generate or stream)
|
|
13
|
-
* @returns The result of the promise or throws TimeoutError
|
|
14
|
-
*/
|
|
15
|
-
export async function withTimeout(promise, timeout, provider, operation) {
|
|
16
|
-
const timeoutPromise = createTimeoutPromise(timeout, provider, operation);
|
|
17
|
-
if (!timeoutPromise) {
|
|
18
|
-
// No timeout specified, return original promise
|
|
19
|
-
return promise;
|
|
20
|
-
}
|
|
21
|
-
// Race between the actual operation and timeout
|
|
22
|
-
return Promise.race([promise, timeoutPromise]);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Wrap a streaming async generator with timeout
|
|
26
|
-
* @param generator - The async generator to wrap
|
|
27
|
-
* @param timeout - Timeout duration for the entire stream
|
|
28
|
-
* @param provider - Provider name for error messages
|
|
29
|
-
* @returns Wrapped async generator that respects timeout
|
|
30
|
-
*/
|
|
31
|
-
export async function* withStreamingTimeout(generator, timeout, provider) {
|
|
32
|
-
const timeoutMs = parseTimeout(timeout);
|
|
33
|
-
if (!timeoutMs) {
|
|
34
|
-
// No timeout, pass through original generator
|
|
35
|
-
yield* generator;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const startTime = Date.now();
|
|
39
|
-
try {
|
|
40
|
-
for await (const chunk of generator) {
|
|
41
|
-
// Check if we've exceeded the timeout
|
|
42
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
43
|
-
throw new TimeoutError(`${provider} streaming operation timed out after ${timeout}`, timeoutMs, provider, "stream");
|
|
44
|
-
}
|
|
45
|
-
yield chunk;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
// Ensure generator is properly closed
|
|
50
|
-
if (generator.return) {
|
|
51
|
-
await generator.return(undefined);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Create an abort controller with timeout
|
|
57
|
-
* @param timeout - Timeout duration
|
|
58
|
-
* @param provider - Provider name for error messages
|
|
59
|
-
* @param operation - Operation type
|
|
60
|
-
* @returns AbortController and cleanup function
|
|
61
|
-
*/
|
|
62
|
-
export function createTimeoutController(timeout, provider, operation) {
|
|
63
|
-
const timeoutMs = parseTimeout(timeout);
|
|
64
|
-
if (!timeoutMs) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
const controller = new AbortController();
|
|
68
|
-
const timer = setTimeout(() => {
|
|
69
|
-
controller.abort(new TimeoutError(`${provider} ${operation} operation timed out after ${timeout}`, timeoutMs, provider, operation));
|
|
70
|
-
}, timeoutMs);
|
|
71
|
-
// Cleanup function to clear the timer
|
|
72
|
-
const cleanup = () => {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
};
|
|
75
|
-
return { controller, cleanup, timeoutMs };
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Merge abort signals (for combining user abort with timeout)
|
|
79
|
-
* @param signals - Array of abort signals to merge
|
|
80
|
-
* @returns Combined abort controller
|
|
81
|
-
*/
|
|
82
|
-
export function mergeAbortSignals(signals) {
|
|
83
|
-
const controller = new AbortController();
|
|
84
|
-
// Listen to all signals and abort when any fires
|
|
85
|
-
for (const signal of signals) {
|
|
86
|
-
if (signal && !signal.aborted) {
|
|
87
|
-
signal.addEventListener("abort", () => {
|
|
88
|
-
if (!controller.signal.aborted) {
|
|
89
|
-
controller.abort(signal.reason);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
// If any signal is already aborted, abort immediately
|
|
94
|
-
if (signal?.aborted) {
|
|
95
|
-
controller.abort(signal.reason);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return controller;
|
|
100
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NeuroLink SDK Tool Extension System
|
|
3
|
-
* Allows developers to register custom tools that integrate with AI providers
|
|
4
|
-
*/
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
import type { Tool } from "ai";
|
|
7
|
-
import { logger } from "../utils/logger.js";
|
|
8
|
-
/**
|
|
9
|
-
* Custom tool interface for SDK users
|
|
10
|
-
*/
|
|
11
|
-
export interface CustomTool {
|
|
12
|
-
/**
|
|
13
|
-
* Tool description that helps AI understand when to use it
|
|
14
|
-
*/
|
|
15
|
-
description: string;
|
|
16
|
-
/**
|
|
17
|
-
* Parameters schema using Zod or JSON Schema
|
|
18
|
-
*/
|
|
19
|
-
parameters?: z.ZodSchema | Record<string, unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* Tool execution function
|
|
22
|
-
*/
|
|
23
|
-
execute: (args: unknown, context?: ToolContext) => Promise<unknown> | unknown;
|
|
24
|
-
/**
|
|
25
|
-
* Optional metadata
|
|
26
|
-
*/
|
|
27
|
-
category?: string;
|
|
28
|
-
version?: string;
|
|
29
|
-
author?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Optional configuration
|
|
32
|
-
*/
|
|
33
|
-
config?: {
|
|
34
|
-
timeout?: number;
|
|
35
|
-
retries?: number;
|
|
36
|
-
rateLimit?: {
|
|
37
|
-
requests: number;
|
|
38
|
-
window: number;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Context provided to tools during execution
|
|
44
|
-
*/
|
|
45
|
-
export interface ToolContext {
|
|
46
|
-
/**
|
|
47
|
-
* Call another tool
|
|
48
|
-
*/
|
|
49
|
-
callTool: (name: string, args: unknown) => Promise<unknown>;
|
|
50
|
-
/**
|
|
51
|
-
* Current session information
|
|
52
|
-
*/
|
|
53
|
-
session: {
|
|
54
|
-
id: string;
|
|
55
|
-
userId?: string;
|
|
56
|
-
provider?: string;
|
|
57
|
-
model?: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Logger instance
|
|
61
|
-
*/
|
|
62
|
-
logger: typeof logger;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Tool middleware function
|
|
66
|
-
*/
|
|
67
|
-
export type ToolMiddleware = (toolName: string, args: unknown, next: () => Promise<unknown>, context: ToolContext) => Promise<unknown>;
|
|
68
|
-
/**
|
|
69
|
-
* Tool permission configuration
|
|
70
|
-
*/
|
|
71
|
-
export interface ToolPermissions {
|
|
72
|
-
allowlist?: string[];
|
|
73
|
-
denylist?: string[];
|
|
74
|
-
requireApproval?: string[];
|
|
75
|
-
customValidator?: (toolName: string, args: unknown) => boolean | Promise<boolean>;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts a custom tool to Vercel AI SDK format
|
|
79
|
-
*/
|
|
80
|
-
export declare function convertToAISDKTool(name: string, customTool: CustomTool): Tool;
|
|
81
|
-
/**
|
|
82
|
-
* Tool registry for managing custom tools
|
|
83
|
-
*/
|
|
84
|
-
export declare class ToolRegistry {
|
|
85
|
-
private tools;
|
|
86
|
-
private middleware;
|
|
87
|
-
private permissions;
|
|
88
|
-
private rateLimits;
|
|
89
|
-
/**
|
|
90
|
-
* Simple rate limiting check with automatic cleanup
|
|
91
|
-
*/
|
|
92
|
-
private checkRateLimit;
|
|
93
|
-
/**
|
|
94
|
-
* Register a custom tool
|
|
95
|
-
*/
|
|
96
|
-
register(name: string, tool: CustomTool): void;
|
|
97
|
-
/**
|
|
98
|
-
* Register multiple tools at once
|
|
99
|
-
*/
|
|
100
|
-
registerMany(tools: Record<string, CustomTool>): void;
|
|
101
|
-
/**
|
|
102
|
-
* Unregister a tool
|
|
103
|
-
*/
|
|
104
|
-
unregister(name: string): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Get a tool by name
|
|
107
|
-
*/
|
|
108
|
-
get(name: string): CustomTool | undefined;
|
|
109
|
-
/**
|
|
110
|
-
* Get all registered tools
|
|
111
|
-
*/
|
|
112
|
-
getAll(): Map<string, CustomTool>;
|
|
113
|
-
/**
|
|
114
|
-
* Convert all tools to AI SDK format
|
|
115
|
-
*/
|
|
116
|
-
toAISDKTools(): Record<string, Tool>;
|
|
117
|
-
/**
|
|
118
|
-
* Add middleware
|
|
119
|
-
*/
|
|
120
|
-
use(middleware: ToolMiddleware): void;
|
|
121
|
-
/**
|
|
122
|
-
* Set permissions
|
|
123
|
-
*/
|
|
124
|
-
setPermissions(permissions: ToolPermissions): void;
|
|
125
|
-
/**
|
|
126
|
-
* Check if a tool is allowed
|
|
127
|
-
*/
|
|
128
|
-
private isToolAllowed;
|
|
129
|
-
/**
|
|
130
|
-
* Execute a tool with middleware
|
|
131
|
-
*/
|
|
132
|
-
execute(name: string, args: unknown, context: ToolContext): Promise<unknown>;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Create a simple tool helper
|
|
136
|
-
*/
|
|
137
|
-
export declare function createTool(config: CustomTool): CustomTool;
|
|
138
|
-
/**
|
|
139
|
-
* Create an async tool helper
|
|
140
|
-
*/
|
|
141
|
-
export declare function createAsyncTool(config: Omit<CustomTool, "execute"> & {
|
|
142
|
-
execute: (args: unknown, context?: ToolContext) => Promise<unknown>;
|
|
143
|
-
}): CustomTool;
|
|
144
|
-
/**
|
|
145
|
-
* Create a batch tool that processes multiple items
|
|
146
|
-
*/
|
|
147
|
-
export declare function createBatchTool<T, R>(config: Omit<CustomTool, "execute" | "parameters"> & {
|
|
148
|
-
parameters: z.ZodSchema<{
|
|
149
|
-
items: T[];
|
|
150
|
-
}>;
|
|
151
|
-
processItem: (item: T, context?: ToolContext) => Promise<R> | R;
|
|
152
|
-
batchSize?: number;
|
|
153
|
-
}): CustomTool;
|
|
154
|
-
/**
|
|
155
|
-
* Tool testing utilities
|
|
156
|
-
*/
|
|
157
|
-
export declare const TestUtils: {
|
|
158
|
-
/**
|
|
159
|
-
* Create a mock tool context
|
|
160
|
-
*/
|
|
161
|
-
mockContext(overrides?: Partial<ToolContext>): ToolContext;
|
|
162
|
-
/**
|
|
163
|
-
* Test a tool with mock data
|
|
164
|
-
*/
|
|
165
|
-
testTool(tool: CustomTool, testCases: Array<{
|
|
166
|
-
input: unknown;
|
|
167
|
-
expected?: unknown;
|
|
168
|
-
}>): Promise<({
|
|
169
|
-
input: unknown;
|
|
170
|
-
output: unknown;
|
|
171
|
-
success: boolean;
|
|
172
|
-
matches: boolean | undefined;
|
|
173
|
-
error?: undefined;
|
|
174
|
-
} | {
|
|
175
|
-
input: unknown;
|
|
176
|
-
error: string;
|
|
177
|
-
success: boolean;
|
|
178
|
-
output?: undefined;
|
|
179
|
-
matches?: undefined;
|
|
180
|
-
})[]>;
|
|
181
|
-
};
|