@juspay/neurolink 7.14.1 → 7.14.3
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 +12 -0
- package/dist/cli/commands/config.d.ts +66 -66
- package/dist/core/baseProvider.d.ts +12 -7
- package/dist/core/baseProvider.js +118 -125
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/constants.js +6 -0
- package/dist/core/dynamicModels.d.ts +4 -4
- package/dist/core/factory.d.ts +2 -4
- package/dist/core/types.d.ts +8 -22
- package/dist/index.d.ts +19 -4
- package/dist/index.js +21 -0
- package/dist/lib/core/baseProvider.d.ts +12 -7
- package/dist/lib/core/baseProvider.js +118 -125
- package/dist/lib/core/constants.d.ts +5 -0
- package/dist/lib/core/constants.js +6 -0
- package/dist/lib/core/dynamicModels.d.ts +8 -8
- package/dist/lib/core/factory.d.ts +2 -4
- package/dist/lib/core/types.d.ts +8 -22
- package/dist/lib/index.d.ts +19 -4
- package/dist/lib/index.js +21 -0
- package/dist/lib/mcp/contracts/mcpContract.d.ts +6 -19
- package/dist/lib/mcp/externalServerManager.d.ts +2 -4
- package/dist/lib/mcp/externalServerManager.js +7 -8
- package/dist/lib/mcp/factory.d.ts +61 -7
- package/dist/lib/mcp/factory.js +36 -23
- package/dist/lib/mcp/mcpClientFactory.d.ts +2 -1
- package/dist/lib/mcp/mcpClientFactory.js +73 -26
- package/dist/lib/mcp/registry.d.ts +1 -1
- package/dist/lib/mcp/toolDiscoveryService.d.ts +1 -1
- package/dist/lib/mcp/toolDiscoveryService.js +50 -19
- package/dist/lib/mcp/toolRegistry.d.ts +23 -1
- package/dist/lib/mcp/toolRegistry.js +108 -17
- package/dist/lib/models/modelResolver.js +2 -1
- package/dist/lib/neurolink.d.ts +12 -8
- package/dist/lib/neurolink.js +130 -134
- package/dist/lib/providers/amazonBedrock.d.ts +2 -2
- package/dist/lib/providers/anthropic.d.ts +3 -3
- package/dist/lib/providers/googleAiStudio.d.ts +2 -2
- package/dist/lib/providers/mistral.d.ts +3 -3
- package/dist/lib/providers/ollama.d.ts +2 -2
- package/dist/lib/providers/openAI.d.ts +3 -3
- package/dist/lib/providers/openaiCompatible.d.ts +2 -2
- package/dist/lib/providers/sagemaker/client.d.ts +2 -5
- package/dist/lib/providers/sagemaker/language-model.d.ts +4 -6
- package/dist/lib/providers/sagemaker/parsers.js +5 -4
- package/dist/lib/sdk/toolRegistration.d.ts +6 -6
- package/dist/lib/sdk/toolRegistration.js +17 -56
- package/dist/lib/types/generateTypes.d.ts +9 -9
- package/dist/lib/types/streamTypes.d.ts +4 -4
- package/dist/lib/types/tools.d.ts +15 -7
- package/dist/lib/types/typeAliases.d.ts +412 -0
- package/dist/lib/types/typeAliases.js +48 -0
- package/dist/lib/utils/factoryProcessing.d.ts +2 -1
- package/dist/lib/utils/factoryProcessing.js +4 -3
- package/dist/lib/utils/parameterValidation.d.ts +97 -0
- package/dist/lib/utils/parameterValidation.js +452 -0
- package/dist/lib/utils/transformationUtils.d.ts +204 -0
- package/dist/lib/utils/transformationUtils.js +334 -0
- package/dist/lib/utils/typeUtils.d.ts +77 -0
- package/dist/lib/utils/typeUtils.js +97 -0
- package/dist/mcp/contracts/mcpContract.d.ts +6 -19
- package/dist/mcp/externalServerManager.d.ts +2 -4
- package/dist/mcp/externalServerManager.js +7 -8
- package/dist/mcp/factory.d.ts +61 -7
- package/dist/mcp/factory.js +36 -23
- package/dist/mcp/mcpClientFactory.d.ts +2 -1
- package/dist/mcp/mcpClientFactory.js +73 -26
- package/dist/mcp/registry.d.ts +1 -1
- package/dist/mcp/toolDiscoveryService.d.ts +1 -1
- package/dist/mcp/toolDiscoveryService.js +50 -19
- package/dist/mcp/toolRegistry.d.ts +23 -1
- package/dist/mcp/toolRegistry.js +108 -17
- package/dist/models/modelResolver.js +2 -1
- package/dist/neurolink.d.ts +12 -8
- package/dist/neurolink.js +130 -134
- package/dist/providers/amazonBedrock.d.ts +2 -2
- package/dist/providers/anthropic.d.ts +3 -3
- package/dist/providers/googleAiStudio.d.ts +2 -2
- package/dist/providers/mistral.d.ts +3 -3
- package/dist/providers/ollama.d.ts +2 -2
- package/dist/providers/openAI.d.ts +3 -3
- package/dist/providers/openaiCompatible.d.ts +2 -2
- package/dist/providers/sagemaker/client.d.ts +2 -5
- package/dist/providers/sagemaker/language-model.d.ts +4 -6
- package/dist/providers/sagemaker/parsers.js +5 -4
- package/dist/sdk/toolRegistration.d.ts +6 -6
- package/dist/sdk/toolRegistration.js +17 -56
- package/dist/types/generateTypes.d.ts +9 -9
- package/dist/types/streamTypes.d.ts +4 -4
- package/dist/types/tools.d.ts +15 -7
- package/dist/types/typeAliases.d.ts +412 -0
- package/dist/types/typeAliases.js +48 -0
- package/dist/utils/factoryProcessing.d.ts +2 -1
- package/dist/utils/factoryProcessing.js +4 -3
- package/dist/utils/parameterValidation.d.ts +97 -0
- package/dist/utils/parameterValidation.js +452 -0
- package/dist/utils/transformationUtils.d.ts +204 -0
- package/dist/utils/transformationUtils.js +334 -0
- package/dist/utils/typeUtils.d.ts +77 -0
- package/dist/utils/typeUtils.js +97 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { type LanguageModelV1 } from "ai";
|
|
2
|
+
import type { ValidationSchema } from "../types/typeAliases.js";
|
|
3
3
|
import { AIProviderName } from "../core/types.js";
|
|
4
4
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
5
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
@@ -23,6 +23,6 @@ export declare class OpenAIProvider extends BaseProvider {
|
|
|
23
23
|
* For details on the changes and migration steps, refer to the BaseProvider documentation
|
|
24
24
|
* and the migration guide in the project repository.
|
|
25
25
|
*/
|
|
26
|
-
protected executeStream(options: StreamOptions, analysisSchema?:
|
|
26
|
+
protected executeStream(options: StreamOptions, analysisSchema?: ValidationSchema): Promise<StreamResult>;
|
|
27
27
|
}
|
|
28
28
|
export default OpenAIProvider;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ZodType, ZodTypeDef } from "zod";
|
|
2
1
|
import { type Schema, type LanguageModelV1 } from "ai";
|
|
2
|
+
import type { ZodUnknownSchema } from "../types/typeAliases.js";
|
|
3
3
|
import type { AIProviderName } from "../core/types.js";
|
|
4
4
|
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
|
|
5
5
|
import { BaseProvider } from "../core/baseProvider.js";
|
|
@@ -29,7 +29,7 @@ export declare class OpenAICompatibleProvider extends BaseProvider {
|
|
|
29
29
|
* Provider-specific streaming implementation
|
|
30
30
|
* Note: This is only used when tools are disabled
|
|
31
31
|
*/
|
|
32
|
-
protected executeStream(options: StreamOptions, analysisSchema?:
|
|
32
|
+
protected executeStream(options: StreamOptions, analysisSchema?: ZodUnknownSchema | Schema<unknown>): Promise<StreamResult>;
|
|
33
33
|
/**
|
|
34
34
|
* Get available models from OpenAI Compatible endpoint
|
|
35
35
|
*
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* with enhanced error handling, retry logic, and NeuroLink-specific features.
|
|
6
6
|
*/
|
|
7
7
|
import type { SageMakerConfig, InvokeEndpointParams, InvokeEndpointResponse } from "./types.js";
|
|
8
|
+
import type { ConnectionResult } from "../../types/typeAliases.js";
|
|
8
9
|
/**
|
|
9
10
|
* Enhanced SageMaker Runtime client with retry logic and error handling
|
|
10
11
|
*/
|
|
@@ -149,8 +150,4 @@ export declare function createSageMakerRuntimeClient(config: SageMakerConfig): S
|
|
|
149
150
|
* @param endpointName - Endpoint to test
|
|
150
151
|
* @returns Promise resolving to connectivity test result
|
|
151
152
|
*/
|
|
152
|
-
export declare function testSageMakerConnectivity(config: SageMakerConfig, endpointName: string): Promise<
|
|
153
|
-
connected: boolean;
|
|
154
|
-
latency?: number;
|
|
155
|
-
error?: string;
|
|
156
|
-
}>;
|
|
153
|
+
export declare function testSageMakerConnectivity(config: SageMakerConfig, endpointName: string): Promise<ConnectionResult>;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { LanguageModelV1, LanguageModelV1CallOptions, LanguageModelV1StreamPart } from "ai";
|
|
8
8
|
import type { SageMakerConfig, SageMakerModelConfig } from "./types.js";
|
|
9
|
+
import type { ConnectivityResult } from "../../types/typeAliases.js";
|
|
9
10
|
/**
|
|
10
11
|
* SageMaker Language Model implementing LanguageModelV1 interface
|
|
11
12
|
*/
|
|
@@ -125,16 +126,13 @@ export declare class SageMakerLanguageModel implements LanguageModelV1 {
|
|
|
125
126
|
provider: string;
|
|
126
127
|
specificationVersion: string;
|
|
127
128
|
endpointName: string;
|
|
128
|
-
modelType: "
|
|
129
|
+
modelType: "mistral" | "huggingface" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
|
|
129
130
|
region: string;
|
|
130
131
|
};
|
|
131
132
|
/**
|
|
132
133
|
* Test basic connectivity to the SageMaker endpoint
|
|
133
134
|
*/
|
|
134
|
-
testConnectivity(): Promise<
|
|
135
|
-
success: boolean;
|
|
136
|
-
error?: string;
|
|
137
|
-
}>;
|
|
135
|
+
testConnectivity(): Promise<ConnectivityResult>;
|
|
138
136
|
/**
|
|
139
137
|
* Batch inference support (Phase 4)
|
|
140
138
|
* Process multiple prompts in a single request for efficiency
|
|
@@ -175,7 +173,7 @@ export declare class SageMakerLanguageModel implements LanguageModelV1 {
|
|
|
175
173
|
provider: string;
|
|
176
174
|
specificationVersion: string;
|
|
177
175
|
endpointName: string;
|
|
178
|
-
modelType: "
|
|
176
|
+
modelType: "mistral" | "huggingface" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
|
|
179
177
|
region: string;
|
|
180
178
|
};
|
|
181
179
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This module provides protocol-specific parsers for different streaming
|
|
5
5
|
* formats used by SageMaker endpoints (HuggingFace, LLaMA, custom models).
|
|
6
6
|
*/
|
|
7
|
+
import { isNonNullObject } from "../../utils/typeUtils.js";
|
|
7
8
|
import { createStructuredOutputParser, isStructuredContent, } from "./structured-parser.js";
|
|
8
9
|
import { SageMakerError } from "./errors.js";
|
|
9
10
|
import { logger } from "../../utils/logger.js";
|
|
@@ -229,7 +230,7 @@ export class HuggingFaceStreamParser extends BaseStreamingParser {
|
|
|
229
230
|
}
|
|
230
231
|
// Parse JSON data
|
|
231
232
|
const parsed = this.parseJSON(data);
|
|
232
|
-
if (parsed &&
|
|
233
|
+
if (parsed && isNonNullObject(parsed)) {
|
|
233
234
|
const chunk = this.parseHuggingFaceChunk(parsed);
|
|
234
235
|
if (chunk) {
|
|
235
236
|
chunks.push(chunk);
|
|
@@ -310,7 +311,7 @@ export class LlamaStreamParser extends BaseStreamingParser {
|
|
|
310
311
|
}
|
|
311
312
|
// Parse each line as JSON
|
|
312
313
|
const parsed = this.parseJSON(trimmed);
|
|
313
|
-
if (parsed &&
|
|
314
|
+
if (parsed && isNonNullObject(parsed)) {
|
|
314
315
|
const chunk = this.parseLlamaChunk(parsed);
|
|
315
316
|
if (chunk) {
|
|
316
317
|
chunks.push(chunk);
|
|
@@ -512,7 +513,7 @@ export class CustomStreamParser extends BaseStreamingParser {
|
|
|
512
513
|
const line = this.buffer.substring(startIndex, newlineIndex);
|
|
513
514
|
if (line.trim()) {
|
|
514
515
|
const parsed = this.parseJSON(line.trim());
|
|
515
|
-
if (parsed &&
|
|
516
|
+
if (parsed && isNonNullObject(parsed)) {
|
|
516
517
|
const chunk = this.parseCustomChunk(parsed);
|
|
517
518
|
if (chunk) {
|
|
518
519
|
chunks.push(chunk);
|
|
@@ -605,7 +606,7 @@ function formatErrorMessage(error) {
|
|
|
605
606
|
* Handles both string and object error formats consistently
|
|
606
607
|
*/
|
|
607
608
|
function extractApiErrorMessage(errorData) {
|
|
608
|
-
if (
|
|
609
|
+
if (isNonNullObject(errorData)) {
|
|
609
610
|
return errorData.message || String(errorData);
|
|
610
611
|
}
|
|
611
612
|
return String(errorData);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { logger } from "../utils/logger.js";
|
|
7
7
|
import type { MCPServerInfo, MCPServerCategory } from "../types/mcpTypes.js";
|
|
8
|
-
import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool } from "../types/tools.js";
|
|
8
|
+
import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool, ZodUnknownSchema } from "../types/tools.js";
|
|
9
9
|
import type { JsonValue } from "../types/common.js";
|
|
10
10
|
/**
|
|
11
11
|
* Enhanced validation configuration
|
|
@@ -39,7 +39,7 @@ export interface ToolContext extends CoreToolContext {
|
|
|
39
39
|
/**
|
|
40
40
|
* Call another tool
|
|
41
41
|
*/
|
|
42
|
-
callTool?: (name: string,
|
|
42
|
+
callTool?: (name: string, params: ToolArgs) => Promise<ToolResult>;
|
|
43
43
|
/**
|
|
44
44
|
* Logger instance
|
|
45
45
|
*/
|
|
@@ -57,11 +57,11 @@ export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> extends Omit<
|
|
|
57
57
|
/**
|
|
58
58
|
* Parameters schema using Zod (optional)
|
|
59
59
|
*/
|
|
60
|
-
parameters?:
|
|
60
|
+
parameters?: ZodUnknownSchema;
|
|
61
61
|
/**
|
|
62
62
|
* Tool execution function
|
|
63
63
|
*/
|
|
64
|
-
execute: (
|
|
64
|
+
execute: (params: TArgs, context?: ToolContext) => Promise<TResult>;
|
|
65
65
|
/**
|
|
66
66
|
* Optional metadata
|
|
67
67
|
*/
|
|
@@ -99,9 +99,9 @@ export declare function createValidatedTool(name: string, config: SimpleTool, op
|
|
|
99
99
|
/**
|
|
100
100
|
* Helper to create a tool with typed parameters
|
|
101
101
|
*/
|
|
102
|
-
export declare function createTypedTool<TParams extends
|
|
102
|
+
export declare function createTypedTool<TParams extends ZodUnknownSchema>(config: Omit<SimpleTool, "execute"> & {
|
|
103
103
|
parameters: TParams;
|
|
104
|
-
execute: (
|
|
104
|
+
execute: (params: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue;
|
|
105
105
|
}): SimpleTool;
|
|
106
106
|
/**
|
|
107
107
|
* Validate tool configuration with detailed error messages
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
6
|
import { createMCPServerInfo } from "../utils/mcpDefaults.js";
|
|
7
|
+
import { validateToolName, validateToolDescription, } from "../utils/parameterValidation.js";
|
|
7
8
|
/**
|
|
8
9
|
* Configuration constants for tool validation
|
|
9
10
|
*/
|
|
@@ -153,39 +154,15 @@ export function createTypedTool(config) {
|
|
|
153
154
|
return config;
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
156
|
-
* Enhanced tool name validation
|
|
157
|
+
* Enhanced tool name validation using centralized utilities
|
|
157
158
|
*/
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
throw
|
|
159
|
+
function validateToolNameLegacy(name) {
|
|
160
|
+
const error = validateToolName(name);
|
|
161
|
+
if (error) {
|
|
162
|
+
throw error;
|
|
162
163
|
}
|
|
164
|
+
// Additional legacy-specific validations
|
|
163
165
|
const trimmedName = name.trim();
|
|
164
|
-
// Length validation
|
|
165
|
-
if (trimmedName.length < VALIDATION_CONFIG.NAME_MIN_LENGTH) {
|
|
166
|
-
throw new Error(`Tool name too short: '${name}' (${trimmedName.length} chars). ` +
|
|
167
|
-
`Minimum length: ${VALIDATION_CONFIG.NAME_MIN_LENGTH} characters. ` +
|
|
168
|
-
`Example: 'get_data', 'send_email'`);
|
|
169
|
-
}
|
|
170
|
-
// Only check name length if limit is greater than 0 (0 means unlimited)
|
|
171
|
-
if (VALIDATION_CONFIG.NAME_MAX_LENGTH > 0 &&
|
|
172
|
-
trimmedName.length > VALIDATION_CONFIG.NAME_MAX_LENGTH) {
|
|
173
|
-
throw new Error(`Tool name too long: '${name}' (${trimmedName.length} chars). ` +
|
|
174
|
-
`Maximum length: ${VALIDATION_CONFIG.NAME_MAX_LENGTH} characters. ` +
|
|
175
|
-
`Consider shortening: '${trimmedName.substring(0, 20)}...'`);
|
|
176
|
-
}
|
|
177
|
-
// Format validation (alphanumeric, hyphens, underscores only)
|
|
178
|
-
const validNamePattern = /^[a-zA-Z0-9_-]+$/;
|
|
179
|
-
if (!validNamePattern.test(trimmedName)) {
|
|
180
|
-
throw new Error(`Invalid tool name format: '${name}'. Tool names must contain only alphanumeric characters, hyphens, and underscores. ` +
|
|
181
|
-
`Examples: 'calculate-tax', 'get_weather', 'sendEmail123'`);
|
|
182
|
-
}
|
|
183
|
-
// Reserved name validation
|
|
184
|
-
if (VALIDATION_CONFIG.RESERVED_NAMES.has(trimmedName.toLowerCase())) {
|
|
185
|
-
throw new Error(`Tool name '${name}' is reserved and cannot be used. ` +
|
|
186
|
-
`Reserved names include: ${Array.from(VALIDATION_CONFIG.RESERVED_NAMES).slice(0, 5).join(", ")}... ` +
|
|
187
|
-
`Try variations like: '${trimmedName}_tool', 'custom_${trimmedName}', '${trimmedName}_helper'`);
|
|
188
|
-
}
|
|
189
166
|
// Naming convention suggestions using pre-compiled patterns for performance
|
|
190
167
|
const hasGoodPattern = VALIDATION_CONFIG.COMPILED_PATTERN_REGEXES.some((patternRegex) => {
|
|
191
168
|
return patternRegex.test(trimmedName);
|
|
@@ -196,31 +173,15 @@ function validateToolName(name) {
|
|
|
196
173
|
}
|
|
197
174
|
}
|
|
198
175
|
/**
|
|
199
|
-
* Enhanced description validation
|
|
176
|
+
* Enhanced description validation using centralized utilities
|
|
200
177
|
*/
|
|
201
|
-
function
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
throw new Error(`Tool '${name}' must have a non-empty description string. ` +
|
|
206
|
-
`Example: { description: "Calculates mathematical expressions", execute: async (params) => {...} }`);
|
|
178
|
+
function validateToolDescriptionLegacy(name, description) {
|
|
179
|
+
const error = validateToolDescription(description);
|
|
180
|
+
if (error) {
|
|
181
|
+
throw new Error(`Tool '${name}': ${error.message}`);
|
|
207
182
|
}
|
|
183
|
+
// Additional legacy-specific validations
|
|
208
184
|
const trimmedDescription = description.trim();
|
|
209
|
-
// Length validation
|
|
210
|
-
if (trimmedDescription.length < VALIDATION_CONFIG.DESCRIPTION_MIN_LENGTH) {
|
|
211
|
-
throw new Error(`Tool '${name}' description too short: ${trimmedDescription.length} characters. ` +
|
|
212
|
-
`Minimum length: ${VALIDATION_CONFIG.DESCRIPTION_MIN_LENGTH} characters. ` +
|
|
213
|
-
`The description should clearly explain what the tool does and when to use it. ` +
|
|
214
|
-
`Example: "Fetches current weather data for a specified location using coordinates or city name"`);
|
|
215
|
-
}
|
|
216
|
-
// Only check description length if limit is greater than 0 (0 means unlimited)
|
|
217
|
-
if (VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH > 0 &&
|
|
218
|
-
trimmedDescription.length > VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH) {
|
|
219
|
-
throw new Error(`Tool '${name}' description too long: ${trimmedDescription.length} characters. ` +
|
|
220
|
-
`Maximum length: ${VALIDATION_CONFIG.DESCRIPTION_MAX_LENGTH} characters. ` +
|
|
221
|
-
`Current description: "${trimmedDescription.substring(0, 50)}..." ` +
|
|
222
|
-
`Try to be more concise while keeping the essential information.`);
|
|
223
|
-
}
|
|
224
185
|
// Quality suggestions
|
|
225
186
|
const hasActionWord = /^(get|fetch|calculate|send|create|update|delete|validate|process|generate|parse|convert)/i.test(trimmedDescription);
|
|
226
187
|
if (!hasActionWord) {
|
|
@@ -231,15 +192,15 @@ function validateToolDescription(name, description) {
|
|
|
231
192
|
* Validate tool configuration with detailed error messages
|
|
232
193
|
*/
|
|
233
194
|
export function validateTool(name, tool) {
|
|
234
|
-
// Enhanced tool name validation
|
|
235
|
-
|
|
195
|
+
// Enhanced tool name validation using centralized utilities
|
|
196
|
+
validateToolNameLegacy(name);
|
|
236
197
|
// Validate tool object
|
|
237
198
|
if (!tool || typeof tool !== "object") {
|
|
238
199
|
throw new Error(`Tool '${name}' must be an object with description and execute properties. Received: ${typeof tool}. ` +
|
|
239
200
|
`Expected format: { description: "Tool description", execute: async (params) => { ... } }`);
|
|
240
201
|
}
|
|
241
|
-
// Enhanced description validation
|
|
242
|
-
|
|
202
|
+
// Enhanced description validation using centralized utilities
|
|
203
|
+
validateToolDescriptionLegacy(name, tool.description);
|
|
243
204
|
// Validate execute function with signature guidance
|
|
244
205
|
if (typeof tool.execute !== "function") {
|
|
245
206
|
throw new Error(`Tool '${name}' must have an execute function. ` +
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Tool } from "ai";
|
|
2
|
+
import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
|
|
3
3
|
import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Generate function options interface - Primary method for content generation
|
|
@@ -17,13 +17,13 @@ export interface GenerateOptions {
|
|
|
17
17
|
temperature?: number;
|
|
18
18
|
maxTokens?: number;
|
|
19
19
|
systemPrompt?: string;
|
|
20
|
-
schema?:
|
|
20
|
+
schema?: ValidationSchema;
|
|
21
21
|
tools?: Record<string, Tool>;
|
|
22
22
|
timeout?: number | string;
|
|
23
23
|
disableTools?: boolean;
|
|
24
24
|
enableEvaluation?: boolean;
|
|
25
25
|
enableAnalytics?: boolean;
|
|
26
|
-
context?:
|
|
26
|
+
context?: StandardRecord;
|
|
27
27
|
evaluationDomain?: string;
|
|
28
28
|
toolUsageContext?: string;
|
|
29
29
|
conversationHistory?: Array<{
|
|
@@ -32,7 +32,7 @@ export interface GenerateOptions {
|
|
|
32
32
|
}>;
|
|
33
33
|
factoryConfig?: {
|
|
34
34
|
domainType?: string;
|
|
35
|
-
domainConfig?:
|
|
35
|
+
domainConfig?: StandardRecord;
|
|
36
36
|
enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
|
|
37
37
|
preserveLegacyFields?: boolean;
|
|
38
38
|
validateDomainData?: boolean;
|
|
@@ -65,20 +65,20 @@ export interface GenerateResult {
|
|
|
65
65
|
toolCalls?: Array<{
|
|
66
66
|
toolCallId: string;
|
|
67
67
|
toolName: string;
|
|
68
|
-
args:
|
|
68
|
+
args: StandardRecord;
|
|
69
69
|
}>;
|
|
70
70
|
toolResults?: unknown[];
|
|
71
71
|
toolsUsed?: string[];
|
|
72
72
|
toolExecutions?: Array<{
|
|
73
73
|
name: string;
|
|
74
|
-
input:
|
|
74
|
+
input: StandardRecord;
|
|
75
75
|
output: unknown;
|
|
76
76
|
}>;
|
|
77
77
|
enhancedWithTools?: boolean;
|
|
78
78
|
availableTools?: Array<{
|
|
79
79
|
name: string;
|
|
80
80
|
description: string;
|
|
81
|
-
parameters:
|
|
81
|
+
parameters: StandardRecord;
|
|
82
82
|
}>;
|
|
83
83
|
analytics?: AnalyticsData;
|
|
84
84
|
evaluation?: EvaluationData;
|
|
@@ -87,7 +87,7 @@ export interface GenerateResult {
|
|
|
87
87
|
enhancementType?: string;
|
|
88
88
|
domainType?: string;
|
|
89
89
|
processingTime?: number;
|
|
90
|
-
configurationUsed?:
|
|
90
|
+
configurationUsed?: StandardRecord;
|
|
91
91
|
migrationPerformed?: boolean;
|
|
92
92
|
legacyFieldsPreserved?: boolean;
|
|
93
93
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Tool } from "ai";
|
|
2
|
+
import type { ValidationSchema, StandardRecord } from "./typeAliases.js";
|
|
3
3
|
import type { AIProviderName, AnalyticsData, EvaluationData } from "../core/types.js";
|
|
4
4
|
import type { UnknownRecord, JsonValue } from "./common.js";
|
|
5
5
|
import type { ChatMessage } from "./conversationTypes.js";
|
|
@@ -80,7 +80,7 @@ export interface StreamOptions {
|
|
|
80
80
|
temperature?: number;
|
|
81
81
|
maxTokens?: number;
|
|
82
82
|
systemPrompt?: string;
|
|
83
|
-
schema?:
|
|
83
|
+
schema?: ValidationSchema;
|
|
84
84
|
tools?: Record<string, Tool>;
|
|
85
85
|
timeout?: number | string;
|
|
86
86
|
disableTools?: boolean;
|
|
@@ -96,7 +96,7 @@ export interface StreamOptions {
|
|
|
96
96
|
}>;
|
|
97
97
|
factoryConfig?: {
|
|
98
98
|
domainType?: string;
|
|
99
|
-
domainConfig?:
|
|
99
|
+
domainConfig?: StandardRecord;
|
|
100
100
|
enhancementType?: "domain-configuration" | "streaming-optimization" | "mcp-integration" | "legacy-migration" | "context-conversion";
|
|
101
101
|
preserveLegacyFields?: boolean;
|
|
102
102
|
validateDomainData?: boolean;
|
|
@@ -4,10 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import type { Result, JsonValue, ErrorInfo } from "./common.js";
|
|
7
|
+
/**
|
|
8
|
+
* Commonly used Zod schema type aliases for cleaner type declarations
|
|
9
|
+
*/
|
|
10
|
+
import type { ZodUnknownSchema } from "./typeAliases.js";
|
|
11
|
+
export type { ZodUnknownSchema } from "./typeAliases.js";
|
|
12
|
+
export type ZodAnySchema = z.ZodSchema<unknown>;
|
|
13
|
+
export type ZodObjectSchema = z.ZodObject<z.ZodRawShape>;
|
|
14
|
+
export type ZodStringSchema = z.ZodString;
|
|
7
15
|
/**
|
|
8
16
|
* Tool parameter schema types
|
|
9
17
|
*/
|
|
10
|
-
export type ToolParameterSchema =
|
|
18
|
+
export type ToolParameterSchema = ZodUnknownSchema | Record<string, JsonValue>;
|
|
11
19
|
/**
|
|
12
20
|
* Standard tool input parameters
|
|
13
21
|
*/
|
|
@@ -78,16 +86,16 @@ export interface ToolDefinition<TArgs = ToolArgs, TResult = JsonValue> {
|
|
|
78
86
|
description: string;
|
|
79
87
|
parameters?: ToolParameterSchema;
|
|
80
88
|
metadata?: ToolMetadata;
|
|
81
|
-
execute: (
|
|
89
|
+
execute: (params: TArgs, context?: ToolContext) => Promise<ToolResult<TResult>> | ToolResult<TResult>;
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
92
|
* Simple tool interface (for SDK)
|
|
85
93
|
*/
|
|
86
94
|
export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> {
|
|
87
95
|
description: string;
|
|
88
|
-
parameters?:
|
|
96
|
+
parameters?: ZodUnknownSchema;
|
|
89
97
|
metadata?: ToolMetadata;
|
|
90
|
-
execute: (
|
|
98
|
+
execute: (params: TArgs, context?: ToolContext) => Promise<TResult>;
|
|
91
99
|
}
|
|
92
100
|
/**
|
|
93
101
|
* Tool registry entry
|
|
@@ -105,7 +113,7 @@ export interface ToolRegistryEntry {
|
|
|
105
113
|
*/
|
|
106
114
|
export interface ToolExecution {
|
|
107
115
|
toolName: string;
|
|
108
|
-
|
|
116
|
+
params: ToolArgs;
|
|
109
117
|
result: ToolResult;
|
|
110
118
|
executionTime: number;
|
|
111
119
|
timestamp: number;
|
|
@@ -124,7 +132,7 @@ export interface AvailableTool {
|
|
|
124
132
|
* Tool validation options
|
|
125
133
|
*/
|
|
126
134
|
export interface ToolValidationOptions {
|
|
127
|
-
customValidator?: (toolName: string,
|
|
135
|
+
customValidator?: (toolName: string, params: ToolArgs) => boolean | Promise<boolean>;
|
|
128
136
|
validateSchema?: boolean;
|
|
129
137
|
allowUnknownProperties?: boolean;
|
|
130
138
|
}
|
|
@@ -143,7 +151,7 @@ export interface AiSdkToolCall {
|
|
|
143
151
|
type: "tool-call";
|
|
144
152
|
toolCallId: string;
|
|
145
153
|
toolName: string;
|
|
146
|
-
|
|
154
|
+
params: ToolArgs;
|
|
147
155
|
}
|
|
148
156
|
/**
|
|
149
157
|
* Tool call result (for AI SDK integration)
|