Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions src/lib/core/baseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { MiddlewareFactory } from "../middleware/factory.js";
import type { MiddlewareFactoryOptions } from "../types/middlewareTypes.js";
import type { StreamOptions, StreamResult } from "../types/streamTypes.js";
import type { JsonValue, JsonObject, UnknownRecord } from "../types/common.js";
import type { ToolResult, ToolArgs } from "../types/tools.js";
import type { TextContent, ImageContent } from "../types/content.js";
import type { ToolArgs, ToolCallObject, ToolResult } from "../types/tools.js";
import type { MultimodalInput } from "../types/content.js";
import { logger } from "../utils/logger.js";
import { DEFAULT_MAX_STEPS, STEP_LIMITS } from "../core/constants.js";
import { directAgentTools } from "../agent/directTools.js";
Expand Down Expand Up @@ -50,33 +50,6 @@ import {
} from "./evaluationProviders.js";
import { modelConfig } from "./modelConfiguration.js";

// Provider types moved to ../types/providers.js

/**
* Multimodal input type for options that may contain images, CSV files, PDF files, or content arrays
*/
type MultimodalInput = {
text: string;
images?: Array<Buffer | string>;
content?: Array<TextContent | ImageContent>;
csvFiles?: Array<Buffer | string>;
pdfFiles?: Array<Buffer | string>;
files?: Array<Buffer | string>;
};

/**
* Tool call object interface for type-safe access to tool call properties
*/
interface ToolCallObject extends UnknownRecord {
toolName?: string;
name?: string;
toolCallId?: string;
id?: string;
args?: UnknownRecord;
arguments?: UnknownRecord;
parameters?: UnknownRecord;
}

/**
* Abstract base class for all AI providers
* Tools are integrated as first-class citizens - always available by default
Expand Down
6 changes: 1 addition & 5 deletions src/lib/core/conversationMemoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import type {
ConversationMemoryConfig,
RedisStorageConfig,
} from "../types/conversation.js";
import type { StorageType } from "../types/common.js";
import { ConversationMemoryManager } from "./conversationMemoryManager.js";
import { RedisConversationMemoryManager } from "./redisConversationMemoryManager.js";
import { logger } from "../utils/logger.js";

/**
* Configuration for memory storage type
*/
export type StorageType = "memory" | "redis";

/**
* Creates a conversation memory manager based on configuration
*/
Expand Down
21 changes: 1 addition & 20 deletions src/lib/core/redisConversationMemoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
RedisConversationObject,
} from "../types/conversation.js";
import { ConversationMemoryError } from "../types/conversation.js";
import type { PendingToolExecution } from "../types/tools.js";
import {
DEFAULT_MAX_SESSIONS,
MESSAGES_PER_TURN,
Expand All @@ -33,26 +34,6 @@ import {
* Redis-based implementation of the ConversationMemoryManager
* Uses the same interface but stores data in Redis
*/
/**
* Temporary storage for tool execution data to avoid race conditions
*/
interface PendingToolExecution {
toolCalls: Array<{
toolCallId?: string;
toolName?: string;
args?: Record<string, unknown>;
timestamp?: Date; // Individual timestamp for each tool call
[key: string]: unknown;
}>;
toolResults: Array<{
toolCallId?: string;
result?: unknown;
error?: string;
timestamp?: Date; // Individual timestamp for each tool result
[key: string]: unknown;
}>;
timestamp: number; // Overall timestamp for the execution batch
}

export class RedisConversationMemoryManager {
public config: ConversationMemoryConfig;
Expand Down
11 changes: 5 additions & 6 deletions src/lib/neurolink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ import type {
MCPServerCategory,
} from "./types/mcpTypes.js";
import type { ToolInfo } from "./types/tools.js";
import type {
NeuroLinkEvents,
TypedEventEmitter,
ToolExecutionContext,
ToolExecutionSummary,
} from "./types/common.js";
import type { NeuroLinkEvents, TypedEventEmitter } from "./types/common.js";
import {
createCustomToolServerInfo,
detectCategory,
} from "./utils/mcpDefaults.js";
import type {
ToolExecutionContext,
ToolExecutionSummary,
} from "./types/tools.js";
import type { JsonValue, JsonObject, UnknownRecord } from "./types/common.js";
import type {
ToolExecutionResult,
Expand Down
83 changes: 19 additions & 64 deletions src/lib/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export type UnknownRecord = Record<string, unknown>;
*/
export type UnknownArray = unknown[];

/**
* Storage type for conversation memory factory
*/
export type StorageType = "memory" | "redis";

/**
* JSON-serializable value type
*/
Expand All @@ -28,37 +33,37 @@ export type JsonValue =
| JsonObject
| JsonArray;

export interface JsonObject {
export type JsonObject = {
[key: string]: JsonValue;
}
};

export interface JsonArray extends Array<JsonValue> {}
export type JsonArray = JsonValue[];

/**
* Type-safe error handling
*/
export interface ErrorInfo {
export type ErrorInfo = {
message: string;
code?: string | number;
stack?: string;
cause?: unknown;
}
};

/**
* Generic success/error result type
*/
export interface Result<T = unknown, E = ErrorInfo> {
export type Result<T = unknown, E = ErrorInfo> = {
success: boolean;
data?: T;
error?: E;
}
};

/**
* Function parameter type for dynamic functions
*/
export interface FunctionParameters {
export type FunctionParameters = {
[key: string]: unknown;
}
};

/**
* Generic async function type
Expand Down Expand Up @@ -135,58 +140,21 @@ export function toErrorInfo(error: unknown): ErrorInfo {
};
}

/**
* NeuroLink Native Event System Types
*/

/**
* Tool execution event for real-time streaming
*/
export interface ToolExecutionEvent {
type: "tool:start" | "tool:end";
tool: string;
input?: unknown;
result?: unknown;
error?: string;
timestamp: number;
duration?: number;
executionId: string;
}

/**
* Tool execution summary for completed executions
*/
export interface ToolExecutionSummary {
tool: string;
startTime: number;
endTime: number;
duration: number;
success: boolean;
result?: unknown;
error?: string;
executionId: string;
metadata?: {
serverId?: string;
toolCategory?: "direct" | "custom" | "mcp";
isExternal?: boolean;
};
}

/**
* Stream event types for real-time communication
*/
export interface StreamEvent {
export type StreamEvent = {
type: "stream:chunk" | "stream:complete" | "stream:error";
content?: string;
metadata?: JsonObject;
timestamp: number;
}
};

/**
* Enhanced NeuroLink event types
* Flexible interface to support both typed and legacy event patterns
* Flexible type to support both typed and legacy event patterns
*/
export interface NeuroLinkEvents {
export type NeuroLinkEvents = {
// Core tool events
"tool:start": unknown;
"tool:end": unknown;
Expand Down Expand Up @@ -227,7 +195,7 @@ export interface NeuroLinkEvents {

// Allow any additional event for flexibility
[key: string]: unknown;
}
};

/**
* TypeScript utility for typed EventEmitter
Expand All @@ -249,16 +217,3 @@ export interface TypedEventEmitter<TEvents extends Record<string, unknown>> {
event: K,
): Array<(...args: unknown[]) => void>;
}

/**
* Tool execution context for tracking
*/
export interface ToolExecutionContext {
executionId: string;
tool: string;
startTime: number;
endTime?: number;
result?: unknown;
error?: string;
metadata?: JsonObject;
}
32 changes: 22 additions & 10 deletions src/lib/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,50 +68,62 @@ export type Content = TextContent | ImageContent | CSVContent | PDFContent;
/**
* Vision capability information for providers
*/
export interface VisionCapability {
export type VisionCapability = {
provider: string;
supportedModels: string[];
maxImageSize?: number; // in bytes
supportedFormats: string[];
maxImagesPerRequest?: number;
}
};

/**
* Provider-specific image format requirements
*/
export interface ProviderImageFormat {
export type ProviderImageFormat = {
provider: string;
format: "data_uri" | "base64" | "inline_data" | "source";
requiresPrefix?: boolean;
mimeTypeField?: string;
dataField?: string;
}
};

/**
* Image processing result
*/
export interface ProcessedImage {
export type ProcessedImage = {
data: string;
mediaType: string;
size: number;
format: "data_uri" | "base64" | "inline_data" | "source";
}
};

/**
* Multimodal message structure for provider adapters
*/
export interface MultimodalMessage {
export type MultimodalMessage = {
role: "user" | "assistant" | "system";
content: Content[];
}
};

/**
* Multimodal input type for options that may contain images or content arrays
*/
export type MultimodalInput = {
text: string;
images?: Array<Buffer | string>;
content?: Array<TextContent | ImageContent>;
csvFiles?: Array<Buffer | string>;
pdfFiles?: Array<Buffer | string>;
files?: Array<Buffer | string>;
};

/**
* Provider-specific multimodal payload
*/
export interface ProviderMultimodalPayload {
export type ProviderMultimodalPayload = {
provider: string;
model: string;
messages?: MultimodalMessage[];
contents?: unknown[]; // Google AI format
[key: string]: unknown; // Allow provider-specific fields
}
};
Loading
Loading