@smythos/sre 1.5.37 → 1.5.40
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/dist/index.js +65 -45
- package/dist/index.js.map +1 -1
- package/dist/types/Components/ECMASandbox.class.d.ts +14 -0
- package/dist/types/Components/MemoryDeleteKeyVal.class.d.ts +19 -0
- package/dist/types/Components/MemoryReadKeyVal.class.d.ts +17 -0
- package/dist/types/Components/MemoryWriteKeyVal.class.d.ts +17 -0
- package/dist/types/Components/MemoryWriteObject.class.d.ts +19 -0
- package/dist/types/Components/index.d.ts +10 -0
- package/dist/types/Core/ConnectorsService.d.ts +2 -1
- package/dist/types/helpers/ECMASandbox.helper.d.ts +3 -0
- package/dist/types/helpers/Log.helper.d.ts +1 -1
- package/dist/types/index.d.ts +8 -1
- package/dist/types/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.d.ts +19 -0
- package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +21 -10
- package/dist/types/subsystems/LLMManager/LLM.service/LLMConnector.d.ts +5 -5
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.d.ts +2 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.d.ts +2 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Echo.class.d.ts +2 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +2 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Groq.class.d.ts +2 -3
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +3 -4
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.d.ts +19 -14
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +95 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.d.ts +87 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.d.ts +85 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.d.ts +49 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +146 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.d.ts +10 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.d.ts +4 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/types.d.ts +38 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +1 -2
- package/dist/types/subsystems/Security/Vault.service/connectors/JSONFileVault.class.d.ts +5 -0
- package/dist/types/types/LLM.types.d.ts +82 -37
- package/dist/types/utils/data.utils.d.ts +2 -1
- package/package.json +4 -3
- package/src/Components/APICall/APICall.class.ts +2 -1
- package/src/Components/Component.class.ts +1 -1
- package/src/Components/ECMASandbox.class.ts +71 -0
- package/src/Components/GenAILLM.class.ts +1 -1
- package/src/Components/MemoryDeleteKeyVal.class.ts +70 -0
- package/src/Components/MemoryReadKeyVal.class.ts +66 -0
- package/src/Components/MemoryWriteKeyVal.class.ts +62 -0
- package/src/Components/MemoryWriteObject.class.ts +97 -0
- package/src/Components/index.ts +10 -0
- package/src/Core/ConnectorsService.ts +3 -3
- package/src/helpers/Conversation.helper.ts +11 -3
- package/src/helpers/ECMASandbox.helper.ts +54 -0
- package/src/helpers/Log.helper.ts +57 -17
- package/src/index.ts +192 -185
- package/src/index.ts.bak +192 -185
- package/src/subsystems/AgentManager/Agent.class.ts +11 -6
- package/src/subsystems/AgentManager/AgentRuntime.class.ts +13 -13
- package/src/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.ts +131 -0
- package/src/subsystems/ComputeManager/Code.service/index.ts +2 -0
- package/src/subsystems/LLMManager/LLM.helper.ts +57 -27
- package/src/subsystems/LLMManager/LLM.inference.ts +4 -0
- package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +125 -28
- package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +18 -17
- package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +2 -7
- package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +2 -6
- package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +26 -17
- package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +2 -7
- package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +2 -7
- package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +314 -84
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +455 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +528 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.ts +100 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.ts +81 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +853 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.ts +37 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.ts +4 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/types.ts +37 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +0 -5
- package/src/subsystems/LLMManager/LLM.service/index.ts +1 -1
- package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +2 -2
- package/src/subsystems/LLMManager/models.ts +1 -1
- package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +18 -0
- package/src/subsystems/MemoryManager/RuntimeContext.ts +33 -16
- package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +68 -42
- package/src/types/LLM.types.ts +91 -43
- package/src/utils/data.utils.ts +3 -2
- package/src/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.ts +0 -848
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import { BinaryInput } from '@sre/helpers/BinaryInput.helper';
|
|
4
|
+
import { TLLMParams, TLLMPreparedParams, ILLMRequestContext } from '@sre/types/LLM.types';
|
|
5
|
+
import { OpenAIApiInterface, ToolConfig } from './OpenAIApiInterface';
|
|
6
|
+
import { HandlerDependencies } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* OpenAI Chat Completions API interface implementation
|
|
9
|
+
* Handles all Chat Completions API-specific logic including:
|
|
10
|
+
* - Stream creation and handling
|
|
11
|
+
* - Request body preparation
|
|
12
|
+
* - Tool and message transformations
|
|
13
|
+
* - File attachment handling
|
|
14
|
+
*/
|
|
15
|
+
export declare class ChatCompletionsApiInterface extends OpenAIApiInterface {
|
|
16
|
+
private deps;
|
|
17
|
+
private validImageMimeTypes;
|
|
18
|
+
private validDocumentMimeTypes;
|
|
19
|
+
constructor(context: ILLMRequestContext, deps: HandlerDependencies);
|
|
20
|
+
createRequest(body: OpenAI.ChatCompletionCreateParams, context: ILLMRequestContext): Promise<OpenAI.ChatCompletion>;
|
|
21
|
+
createStream(body: OpenAI.ChatCompletionCreateParams, context: ILLMRequestContext): Promise<AsyncIterable<OpenAI.ChatCompletionChunk>>;
|
|
22
|
+
handleStream(stream: AsyncIterable<OpenAI.ChatCompletionChunk>, context: ILLMRequestContext): EventEmitter;
|
|
23
|
+
prepareRequestBody(params: TLLMPreparedParams): Promise<OpenAI.ChatCompletionCreateParams>;
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to check if a tool is an OpenAI tool definition
|
|
26
|
+
*/
|
|
27
|
+
private isOpenAIToolDefinition;
|
|
28
|
+
/**
|
|
29
|
+
* Transform OpenAI tool definitions to ChatCompletionTool format
|
|
30
|
+
*/
|
|
31
|
+
transformToolsConfig(config: ToolConfig): OpenAI.ChatCompletionTool[];
|
|
32
|
+
handleFileAttachments(files: BinaryInput[], agentId: string, messages: OpenAI.ChatCompletionMessageParam[]): Promise<OpenAI.ChatCompletionMessageParam[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Process the chat completions API stream format
|
|
35
|
+
*/
|
|
36
|
+
private processStream;
|
|
37
|
+
/**
|
|
38
|
+
* Extract and format tool calls from the accumulated data
|
|
39
|
+
*/
|
|
40
|
+
private extractToolCalls;
|
|
41
|
+
/**
|
|
42
|
+
* Report usage statistics
|
|
43
|
+
*/
|
|
44
|
+
private reportUsageStatistics;
|
|
45
|
+
/**
|
|
46
|
+
* Emit final events
|
|
47
|
+
*/
|
|
48
|
+
private emitFinalEvents;
|
|
49
|
+
/**
|
|
50
|
+
* Build usage context parameters from request context
|
|
51
|
+
*/
|
|
52
|
+
private buildUsageContext;
|
|
53
|
+
/**
|
|
54
|
+
* Get valid image files based on supported MIME types
|
|
55
|
+
*/
|
|
56
|
+
private getValidImageFiles;
|
|
57
|
+
/**
|
|
58
|
+
* Get valid document files based on supported MIME types
|
|
59
|
+
*/
|
|
60
|
+
private getValidDocumentFiles;
|
|
61
|
+
/**
|
|
62
|
+
* Upload files to storage
|
|
63
|
+
*/
|
|
64
|
+
private uploadFiles;
|
|
65
|
+
/**
|
|
66
|
+
* Process image files with Chat Completions specific formatting
|
|
67
|
+
*/
|
|
68
|
+
private processImageData;
|
|
69
|
+
/**
|
|
70
|
+
* Process document files with Chat Completions specific formatting
|
|
71
|
+
*/
|
|
72
|
+
private processDocumentData;
|
|
73
|
+
/**
|
|
74
|
+
* Validate file size before processing
|
|
75
|
+
*/
|
|
76
|
+
private validateFileSize;
|
|
77
|
+
getInterfaceName(): string;
|
|
78
|
+
validateParameters(params: TLLMParams): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Convert system messages to user messages for models that don't support system messages
|
|
81
|
+
*/
|
|
82
|
+
private convertSystemMessagesToUserMessages;
|
|
83
|
+
/**
|
|
84
|
+
* Prepare messages for Chat Completions API
|
|
85
|
+
*/
|
|
86
|
+
private prepareMessages;
|
|
87
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { BinaryInput } from '@sre/helpers/BinaryInput.helper';
|
|
3
|
+
import { TLLMParams, ILLMRequestContext, TLLMToolChoice, OpenAIToolDefinition, LegacyToolDefinition, LLMModelInfo } from '@sre/types/LLM.types';
|
|
4
|
+
import { HandlerDependencies } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* OpenAI-specific tool configuration interface
|
|
7
|
+
* Only deals with OpenAI tool definitions for clean separation
|
|
8
|
+
*/
|
|
9
|
+
export interface ToolConfig {
|
|
10
|
+
type?: string;
|
|
11
|
+
toolDefinitions: (OpenAIToolDefinition | LegacyToolDefinition)[];
|
|
12
|
+
toolChoice?: TLLMToolChoice;
|
|
13
|
+
modelInfo?: LLMModelInfo | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base class for OpenAI API interfaces
|
|
17
|
+
* Defines the contract that all OpenAI API implementations must follow
|
|
18
|
+
*
|
|
19
|
+
* This follows the Strategy pattern - each API interface (responses, chat.completions)
|
|
20
|
+
* implements this interface with its own specific behavior
|
|
21
|
+
*/
|
|
22
|
+
export declare abstract class OpenAIApiInterface {
|
|
23
|
+
protected context: ILLMRequestContext;
|
|
24
|
+
constructor(context: ILLMRequestContext);
|
|
25
|
+
/**
|
|
26
|
+
* Create a regular (non-streaming) request for this API interface
|
|
27
|
+
* @param body - The request body prepared for this API
|
|
28
|
+
* @param context - The request context
|
|
29
|
+
*/
|
|
30
|
+
abstract createRequest(body: any, context: ILLMRequestContext): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a stream for this API interface
|
|
33
|
+
* @param body - The request body prepared for this API
|
|
34
|
+
* @param context - The request context
|
|
35
|
+
*/
|
|
36
|
+
abstract createStream(body: any, context: ILLMRequestContext): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Handle the stream response from this API interface
|
|
39
|
+
* @param stream - The stream returned from createStream
|
|
40
|
+
* @param context - The request context
|
|
41
|
+
*/
|
|
42
|
+
abstract handleStream(stream: any, context: ILLMRequestContext): EventEmitter;
|
|
43
|
+
/**
|
|
44
|
+
* Prepare the request body for this API interface
|
|
45
|
+
* @param params - The LLM parameters
|
|
46
|
+
*/
|
|
47
|
+
abstract prepareRequestBody(params: TLLMParams): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Transform tools configuration for this API interface
|
|
50
|
+
* @param config - The tool configuration
|
|
51
|
+
*/
|
|
52
|
+
abstract transformToolsConfig(config: ToolConfig): any[];
|
|
53
|
+
/**
|
|
54
|
+
* Handle file attachments for this API interface
|
|
55
|
+
* @param files - The files to attach
|
|
56
|
+
* @param agentId - The agent ID
|
|
57
|
+
* @param messages - The messages to attach files to
|
|
58
|
+
*/
|
|
59
|
+
abstract handleFileAttachments(files: BinaryInput[], agentId: string, messages: any[]): Promise<any[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the API interface name
|
|
62
|
+
*/
|
|
63
|
+
abstract getInterfaceName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Validate if this interface supports the given parameters
|
|
66
|
+
* @param params - The parameters to validate
|
|
67
|
+
*/
|
|
68
|
+
abstract validateParameters(params: TLLMParams): boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Factory interface for creating OpenAI API interfaces
|
|
72
|
+
*/
|
|
73
|
+
export interface OpenAIApiInterfaceFactory {
|
|
74
|
+
/**
|
|
75
|
+
* Create an API interface instance for the specified type
|
|
76
|
+
* @param interfaceType - The type of interface to create
|
|
77
|
+
* @param context - The context for the interface
|
|
78
|
+
* @param deps - The handler dependencies for the interface
|
|
79
|
+
*/
|
|
80
|
+
createInterface(interfaceType: string, context: ILLMRequestContext, deps: HandlerDependencies): OpenAIApiInterface;
|
|
81
|
+
/**
|
|
82
|
+
* Get supported interface types
|
|
83
|
+
*/
|
|
84
|
+
getSupportedInterfaces(): string[];
|
|
85
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OpenAIApiInterface, OpenAIApiInterfaceFactory as IOpenAIApiInterfaceFactory } from './OpenAIApiInterface';
|
|
2
|
+
import { HandlerDependencies } from '../types';
|
|
3
|
+
import { ILLMRequestContext } from '@sre/types/LLM.types';
|
|
4
|
+
/**
|
|
5
|
+
* Factory for creating OpenAI API interfaces
|
|
6
|
+
* Implements the Factory pattern to provide clean abstraction for different OpenAI API types
|
|
7
|
+
* Each API interface now handles its own streaming functionality
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const factory = new OpenAIApiInterfaceFactory();
|
|
12
|
+
* const apiInterface = factory.createInterface('responses', context, deps);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class OpenAIApiInterfaceFactory implements IOpenAIApiInterfaceFactory {
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Create an API interface instance for the specified type
|
|
19
|
+
* @param interfaceType - The type of interface to create ('responses', 'chat.completions')
|
|
20
|
+
* @param context - The context for the interface
|
|
21
|
+
* @param deps - The handler dependencies for the interface
|
|
22
|
+
* @returns The appropriate OpenAI API interface instance
|
|
23
|
+
*/
|
|
24
|
+
createInterface(interfaceType: string, context: ILLMRequestContext, deps: HandlerDependencies): OpenAIApiInterface;
|
|
25
|
+
/**
|
|
26
|
+
* Get list of supported interface types
|
|
27
|
+
* @returns Array of supported interface type strings
|
|
28
|
+
*/
|
|
29
|
+
getSupportedInterfaces(): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Check if an interface type is supported
|
|
32
|
+
* @param interfaceType - The interface type to check
|
|
33
|
+
* @returns True if supported, false otherwise
|
|
34
|
+
*/
|
|
35
|
+
isInterfaceSupported(interfaceType: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get the default interface type
|
|
38
|
+
* @returns The default interface type string
|
|
39
|
+
*/
|
|
40
|
+
getDefaultInterfaceType(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get interface type based on model information
|
|
43
|
+
* @param modelInfo - Model information object
|
|
44
|
+
* @returns The appropriate interface type for the model
|
|
45
|
+
*/
|
|
46
|
+
getInterfaceTypeFromModelInfo(modelInfo?: {
|
|
47
|
+
interface?: string;
|
|
48
|
+
} | unknown): string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import type { Stream } from 'openai/streaming';
|
|
4
|
+
import { BinaryInput } from '@sre/helpers/BinaryInput.helper';
|
|
5
|
+
import { TLLMParams, TLLMPreparedParams, ILLMRequestContext } from '@sre/types/LLM.types';
|
|
6
|
+
import { OpenAIApiInterface, ToolConfig } from './OpenAIApiInterface';
|
|
7
|
+
import { HandlerDependencies } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* OpenAI Responses API interface implementation
|
|
10
|
+
* Handles all Responses API-specific logic including:
|
|
11
|
+
* - Stream creation and handling
|
|
12
|
+
* - Request body preparation
|
|
13
|
+
* - Tool and message transformations
|
|
14
|
+
* - File attachment handling
|
|
15
|
+
*/
|
|
16
|
+
export declare class ResponsesApiInterface extends OpenAIApiInterface {
|
|
17
|
+
private deps;
|
|
18
|
+
private validImageMimeTypes;
|
|
19
|
+
private validDocumentMimeTypes;
|
|
20
|
+
constructor(context: ILLMRequestContext, deps: HandlerDependencies);
|
|
21
|
+
createRequest(body: OpenAI.Responses.ResponseCreateParams, context: ILLMRequestContext): Promise<OpenAI.Responses.Response>;
|
|
22
|
+
createStream(body: OpenAI.Responses.ResponseCreateParams, context: ILLMRequestContext): Promise<Stream<OpenAI.Responses.ResponseStreamEvent>>;
|
|
23
|
+
handleStream(stream: Stream<OpenAI.Responses.ResponseStreamEvent>, context: ILLMRequestContext): EventEmitter;
|
|
24
|
+
/**
|
|
25
|
+
* Process the responses API stream format
|
|
26
|
+
*/
|
|
27
|
+
private processStream;
|
|
28
|
+
/**
|
|
29
|
+
* Extract and format tool calls from the accumulated data
|
|
30
|
+
*/
|
|
31
|
+
private extractToolCalls;
|
|
32
|
+
/**
|
|
33
|
+
* Report usage statistics
|
|
34
|
+
*/
|
|
35
|
+
private reportUsageStatistics;
|
|
36
|
+
/**
|
|
37
|
+
* Emit final events
|
|
38
|
+
*/
|
|
39
|
+
private emitFinalEvents;
|
|
40
|
+
/**
|
|
41
|
+
* Build usage context parameters from request context
|
|
42
|
+
*/
|
|
43
|
+
private buildUsageContext;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate search tool usage with cost
|
|
46
|
+
*/
|
|
47
|
+
private calculateSearchToolUsage;
|
|
48
|
+
prepareRequestBody(params: TLLMPreparedParams): Promise<OpenAI.Responses.ResponseCreateParams>;
|
|
49
|
+
/**
|
|
50
|
+
* Type guard to check if a tool is an OpenAI tool definition
|
|
51
|
+
*/
|
|
52
|
+
private isOpenAIToolDefinition;
|
|
53
|
+
/**
|
|
54
|
+
* Transform OpenAI tool definitions to Responses.Tool format
|
|
55
|
+
*/
|
|
56
|
+
transformToolsConfig(config: ToolConfig): OpenAI.Responses.Tool[];
|
|
57
|
+
/**
|
|
58
|
+
* Transform assistant message block with tool calls for Responses API
|
|
59
|
+
*/
|
|
60
|
+
private transformAssistantMessageBlock;
|
|
61
|
+
/**
|
|
62
|
+
* Transform individual tool calls to ensure proper formatting
|
|
63
|
+
*/
|
|
64
|
+
private transformToolCalls;
|
|
65
|
+
/**
|
|
66
|
+
* Transform tool results with comprehensive error handling and type support
|
|
67
|
+
*/
|
|
68
|
+
private transformToolResults;
|
|
69
|
+
/**
|
|
70
|
+
* Create a tool result message for the Responses API format
|
|
71
|
+
*/
|
|
72
|
+
private createToolResultMessage;
|
|
73
|
+
/**
|
|
74
|
+
* Format tool result content based on type and handle special cases
|
|
75
|
+
*/
|
|
76
|
+
private formatToolResult;
|
|
77
|
+
/**
|
|
78
|
+
* Format tool error messages with context
|
|
79
|
+
*/
|
|
80
|
+
private formatToolError;
|
|
81
|
+
/**
|
|
82
|
+
* Normalize content to string format for Responses API
|
|
83
|
+
*/
|
|
84
|
+
private normalizeContent;
|
|
85
|
+
/**
|
|
86
|
+
* Normalize tool arguments to string format for Responses API
|
|
87
|
+
*/
|
|
88
|
+
private normalizeToolArguments;
|
|
89
|
+
/**
|
|
90
|
+
* Validate if tool data is complete and valid for transformation
|
|
91
|
+
*/
|
|
92
|
+
private isValidToolData;
|
|
93
|
+
/**
|
|
94
|
+
* Check if the tool is a web search tool based on type or name
|
|
95
|
+
*/
|
|
96
|
+
private isWebSearchTool;
|
|
97
|
+
/**
|
|
98
|
+
* Format web search results with better structure
|
|
99
|
+
*/
|
|
100
|
+
private formatWebSearchResult;
|
|
101
|
+
handleFileAttachments(files: BinaryInput[], agentId: string, messages: any[]): Promise<any[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Get valid image files based on supported MIME types
|
|
104
|
+
*/
|
|
105
|
+
private getValidImageFiles;
|
|
106
|
+
/**
|
|
107
|
+
* Get valid document files based on supported MIME types
|
|
108
|
+
*/
|
|
109
|
+
private getValidDocumentFiles;
|
|
110
|
+
/**
|
|
111
|
+
* Upload files to storage
|
|
112
|
+
*/
|
|
113
|
+
private uploadFiles;
|
|
114
|
+
/**
|
|
115
|
+
* Process image files with Responses API specific formatting
|
|
116
|
+
*/
|
|
117
|
+
private processImageData;
|
|
118
|
+
/**
|
|
119
|
+
* Process document files with Responses API specific formatting
|
|
120
|
+
*/
|
|
121
|
+
private processDocumentData;
|
|
122
|
+
/**
|
|
123
|
+
* Validate file size before processing
|
|
124
|
+
*/
|
|
125
|
+
private validateFileSize;
|
|
126
|
+
getInterfaceName(): string;
|
|
127
|
+
validateParameters(params: TLLMParams): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Prepare input messages for Responses API
|
|
130
|
+
*/
|
|
131
|
+
private prepareInputMessages;
|
|
132
|
+
/**
|
|
133
|
+
* Prepare tools for request
|
|
134
|
+
*/
|
|
135
|
+
private prepareFunctionTools;
|
|
136
|
+
/**
|
|
137
|
+
* Get web search tool configuration for OpenAI Responses API
|
|
138
|
+
* According to OpenAI documentation: https://platform.openai.com/docs/api-reference/responses/create
|
|
139
|
+
*/
|
|
140
|
+
private prepareWebSearchTool;
|
|
141
|
+
private applyToolMessageTransformation;
|
|
142
|
+
/**
|
|
143
|
+
* Get search tool cost for a specific model and context size
|
|
144
|
+
*/
|
|
145
|
+
private getSearchToolCost;
|
|
146
|
+
}
|
package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SearchToolCostConfig } from '../types';
|
|
2
|
+
export declare const MODELS_WITHOUT_TEMPERATURE_SUPPORT: string[];
|
|
3
|
+
export declare const MODELS_WITHOUT_PRESENCE_PENALTY_SUPPORT: string[];
|
|
4
|
+
export declare const MODELS_WITHOUT_JSON_RESPONSE_SUPPORT: string[];
|
|
5
|
+
export declare const MODELS_WITHOUT_SYSTEM_MESSAGE_SUPPORT: string[];
|
|
6
|
+
/**
|
|
7
|
+
* Search tool cost configuration
|
|
8
|
+
* Costs are in dollars per 1000 requests
|
|
9
|
+
*/
|
|
10
|
+
export declare const SEARCH_TOOL_COSTS: SearchToolCostConfig;
|
package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { OpenAIApiInterface, ToolConfig } from './OpenAIApiInterface';
|
|
2
|
+
export { ResponsesApiInterface } from './ResponsesApiInterface';
|
|
3
|
+
export { ChatCompletionsApiInterface } from './ChatCompletionsApiInterface';
|
|
4
|
+
export { OpenAIApiInterfaceFactory } from './OpenAIApiInterfaceFactory';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import { ILLMRequestContext, APIKeySource } from '@sre/types/LLM.types';
|
|
4
|
+
export declare enum TToolType {
|
|
5
|
+
WebSearch = "web_search_preview"
|
|
6
|
+
}
|
|
7
|
+
export interface IResponseHandler {
|
|
8
|
+
createStream(body: Record<string, unknown>, context: ILLMRequestContext): Promise<unknown>;
|
|
9
|
+
handleStream(stream: unknown, context: ILLMRequestContext): EventEmitter;
|
|
10
|
+
}
|
|
11
|
+
export type HandlerDependencies = {
|
|
12
|
+
getClient: (context: ILLMRequestContext) => Promise<OpenAI>;
|
|
13
|
+
reportUsage: (usage: OpenAI.Completions.CompletionUsage & {
|
|
14
|
+
input_tokens?: number;
|
|
15
|
+
output_tokens?: number;
|
|
16
|
+
input_tokens_details?: {
|
|
17
|
+
cached_tokens?: number;
|
|
18
|
+
};
|
|
19
|
+
prompt_tokens_details?: {
|
|
20
|
+
cached_tokens?: number;
|
|
21
|
+
};
|
|
22
|
+
cost?: number;
|
|
23
|
+
}, metadata: {
|
|
24
|
+
modelEntryName: string;
|
|
25
|
+
keySource: APIKeySource;
|
|
26
|
+
agentId: string;
|
|
27
|
+
teamId: string;
|
|
28
|
+
}) => any;
|
|
29
|
+
};
|
|
30
|
+
export interface CostConfig {
|
|
31
|
+
[modelName: string]: {
|
|
32
|
+
[contextSize: string]: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface SearchToolCostConfig {
|
|
36
|
+
normalModels: CostConfig;
|
|
37
|
+
miniModels: CostConfig;
|
|
38
|
+
}
|
|
@@ -63,7 +63,6 @@ export declare class xAIConnector extends LLMConnector {
|
|
|
63
63
|
private getClient;
|
|
64
64
|
protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
|
|
65
65
|
protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
|
|
66
|
-
protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
|
|
67
66
|
protected reqBodyAdapter(params: TLLMParams): Promise<ChatCompletionParams>;
|
|
68
67
|
protected reportUsage(usage: TUsage, metadata: {
|
|
69
68
|
modelEntryName: string;
|
|
@@ -100,7 +99,7 @@ export declare class xAIConnector extends LLMConnector {
|
|
|
100
99
|
role: TLLMMessageRole;
|
|
101
100
|
content?: string | {
|
|
102
101
|
text: string;
|
|
103
|
-
}[] | Array<import("@anthropic-ai/sdk/resources").TextBlockParam | import("@anthropic-ai/sdk/resources").ImageBlockParam | import("@anthropic-ai/sdk/resources").ToolUseBlockParam | import("@anthropic-ai/sdk/resources").ToolResultBlockParam>;
|
|
102
|
+
}[] | Array<import("@anthropic-ai/sdk/resources/messages").TextBlockParam | import("@anthropic-ai/sdk/resources/messages").ImageBlockParam | import("@anthropic-ai/sdk/resources/messages").ToolUseBlockParam | import("@anthropic-ai/sdk/resources/messages").ToolResultBlockParam>;
|
|
104
103
|
parts?: {
|
|
105
104
|
text?: string;
|
|
106
105
|
functionCall?: {
|
|
@@ -13,6 +13,8 @@ export declare class JSONFileVault extends VaultConnector {
|
|
|
13
13
|
private vaultData;
|
|
14
14
|
private index;
|
|
15
15
|
private shared;
|
|
16
|
+
private vaultFile;
|
|
17
|
+
private watcher;
|
|
16
18
|
constructor(_settings: JSONFileVaultConfig);
|
|
17
19
|
private findVaultFile;
|
|
18
20
|
private getMasterKeyInteractive;
|
|
@@ -27,4 +29,7 @@ export declare class JSONFileVault extends VaultConnector {
|
|
|
27
29
|
protected exists(acRequest: AccessRequest, keyId: string): Promise<boolean>;
|
|
28
30
|
protected listKeys(acRequest: AccessRequest): Promise<string[]>;
|
|
29
31
|
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
32
|
+
private fetchVaultData;
|
|
33
|
+
private initFileWatcher;
|
|
34
|
+
stop(): Promise<void>;
|
|
30
35
|
}
|
|
@@ -35,10 +35,43 @@ export interface BedrockCredentials {
|
|
|
35
35
|
export type ILLMConnectorCredentials = BasicCredentials | BedrockCredentials | VertexAICredentials;
|
|
36
36
|
export type TOpenAIResponseToolChoice = OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceTypes | OpenAI.Responses.ToolChoiceFunction;
|
|
37
37
|
export type TLLMToolChoice = OpenAI.ChatCompletionToolChoiceOption;
|
|
38
|
+
export type TOpenAIToolsInfo = {
|
|
39
|
+
webSearch: {
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
contextSize: TSearchContextSize;
|
|
42
|
+
city?: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
region?: string;
|
|
45
|
+
timezone?: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type TxAIToolsInfo = {
|
|
49
|
+
search: {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
mode?: 'auto' | 'on' | 'off';
|
|
52
|
+
returnCitations?: boolean;
|
|
53
|
+
maxResults?: number;
|
|
54
|
+
dataSources?: string[];
|
|
55
|
+
country?: string;
|
|
56
|
+
excludedWebsites?: string[];
|
|
57
|
+
allowedWebsites?: string[];
|
|
58
|
+
includedXHandles?: string[];
|
|
59
|
+
excludedXHandles?: string[];
|
|
60
|
+
postFavoriteCount?: number;
|
|
61
|
+
postViewCount?: number;
|
|
62
|
+
rssLinks?: string;
|
|
63
|
+
safeSearch?: boolean;
|
|
64
|
+
fromDate?: string;
|
|
65
|
+
toDate?: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type TToolsInfo = {
|
|
69
|
+
openai: TOpenAIToolsInfo;
|
|
70
|
+
xai: TxAIToolsInfo;
|
|
71
|
+
};
|
|
72
|
+
export type TSearchContextSize = 'low' | 'medium' | 'high';
|
|
38
73
|
export type TLLMParams = {
|
|
39
74
|
model: TLLMModel | string;
|
|
40
|
-
modelEntryName?: string;
|
|
41
|
-
credentials?: ILLMConnectorCredentials;
|
|
42
75
|
prompt?: string;
|
|
43
76
|
messages?: any[];
|
|
44
77
|
temperature?: number;
|
|
@@ -69,7 +102,7 @@ export type TLLMParams = {
|
|
|
69
102
|
};
|
|
70
103
|
maxThinkingTokens?: number;
|
|
71
104
|
useWebSearch?: boolean;
|
|
72
|
-
webSearchContextSize?:
|
|
105
|
+
webSearchContextSize?: TSearchContextSize;
|
|
73
106
|
webSearchCity?: string;
|
|
74
107
|
webSearchCountry?: string;
|
|
75
108
|
webSearchRegion?: string;
|
|
@@ -91,6 +124,13 @@ export type TLLMParams = {
|
|
|
91
124
|
fromDate?: string;
|
|
92
125
|
toDate?: string;
|
|
93
126
|
useReasoning?: boolean;
|
|
127
|
+
max_output_tokens?: number;
|
|
128
|
+
abortSignal?: AbortSignal;
|
|
129
|
+
};
|
|
130
|
+
export type TLLMPreparedParams = TLLMParams & {
|
|
131
|
+
body: any;
|
|
132
|
+
modelEntryName?: string;
|
|
133
|
+
credentials?: ILLMConnectorCredentials;
|
|
94
134
|
isUserKey?: boolean;
|
|
95
135
|
capabilities?: {
|
|
96
136
|
search?: boolean;
|
|
@@ -98,38 +138,7 @@ export type TLLMParams = {
|
|
|
98
138
|
imageGeneration?: boolean;
|
|
99
139
|
imageEditing?: boolean;
|
|
100
140
|
};
|
|
101
|
-
|
|
102
|
-
abortSignal?: AbortSignal;
|
|
103
|
-
};
|
|
104
|
-
export type TLLMParamsV2 = {
|
|
105
|
-
model: string;
|
|
106
|
-
modelEntryName: string;
|
|
107
|
-
messages: any[];
|
|
108
|
-
toolsConfig?: {
|
|
109
|
-
tools?: OpenAI.Responses.Tool[];
|
|
110
|
-
tool_choice?: OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceTypes | OpenAI.Responses.ToolChoiceFunction;
|
|
111
|
-
};
|
|
112
|
-
baseURL?: string;
|
|
113
|
-
stream?: boolean;
|
|
114
|
-
responseFormat?: any;
|
|
115
|
-
credentials?: {
|
|
116
|
-
apiKey?: string;
|
|
117
|
-
isUserKey?: boolean;
|
|
118
|
-
};
|
|
119
|
-
max_output_tokens?: number;
|
|
120
|
-
temperature?: number;
|
|
121
|
-
top_p?: number;
|
|
122
|
-
top_k?: number;
|
|
123
|
-
frequency_penalty?: number;
|
|
124
|
-
presence_penalty?: number;
|
|
125
|
-
teamId?: string;
|
|
126
|
-
files?: BinaryInput[];
|
|
127
|
-
useWebSearch?: boolean;
|
|
128
|
-
webSearchContextSize?: 'high' | 'medium' | 'low';
|
|
129
|
-
webSearchCity?: string;
|
|
130
|
-
webSearchCountry?: string;
|
|
131
|
-
webSearchRegion?: string;
|
|
132
|
-
webSearchTimezone?: string;
|
|
141
|
+
toolsInfo?: TToolsInfo;
|
|
133
142
|
};
|
|
134
143
|
export type TLLMConnectorParams = Omit<TLLMParams, 'model'> & {
|
|
135
144
|
model: string | TLLMModel | TCustomLLMModel;
|
|
@@ -174,6 +183,12 @@ export type TLLMModel = {
|
|
|
174
183
|
};
|
|
175
184
|
credentials?: TLLMCredentials;
|
|
176
185
|
params?: TLLMParams;
|
|
186
|
+
/**
|
|
187
|
+
* Specifies the API interface type to use for this model
|
|
188
|
+
* Examples: 'chat.completions', 'responses'
|
|
189
|
+
* This determines which OpenAI API endpoint and interface implementation to use
|
|
190
|
+
*/
|
|
191
|
+
interface?: 'chat.completions' | 'responses';
|
|
177
192
|
};
|
|
178
193
|
export declare const BuiltinLLMProviders: {
|
|
179
194
|
readonly Echo: "Echo";
|
|
@@ -214,6 +229,7 @@ export type TVertexAISettings = {
|
|
|
214
229
|
projectId: string;
|
|
215
230
|
credentialsName: string;
|
|
216
231
|
jsonCredentialsName: string;
|
|
232
|
+
apiEndpoint?: string;
|
|
217
233
|
};
|
|
218
234
|
export type TCustomLLMModel = TLLMModel & {
|
|
219
235
|
name: string;
|
|
@@ -234,16 +250,44 @@ export type ToolData = {
|
|
|
234
250
|
function?: any;
|
|
235
251
|
error?: string;
|
|
236
252
|
};
|
|
237
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Base tool definition interface - only truly common properties
|
|
255
|
+
* All provider-specific tool definitions extend from this
|
|
256
|
+
*/
|
|
257
|
+
export interface ToolDefinition {
|
|
238
258
|
name: string;
|
|
239
259
|
description: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* OpenAI-specific tool definition
|
|
263
|
+
* Extends base with OpenAI's parameter format
|
|
264
|
+
*/
|
|
265
|
+
export interface OpenAIToolDefinition extends ToolDefinition {
|
|
266
|
+
parameters: {
|
|
267
|
+
type: 'object';
|
|
268
|
+
properties: Record<string, unknown>;
|
|
269
|
+
required?: string[];
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Anthropic-specific tool definition
|
|
274
|
+
* Extends base with Anthropic's input_schema format
|
|
275
|
+
*/
|
|
276
|
+
export interface AnthropicToolDefinition extends ToolDefinition {
|
|
240
277
|
input_schema: {
|
|
241
278
|
type: 'object';
|
|
242
279
|
properties: Record<string, unknown>;
|
|
243
280
|
required: string[];
|
|
244
281
|
};
|
|
245
282
|
}
|
|
246
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Legacy tool definition for backward compatibility
|
|
285
|
+
* @deprecated Use provider-specific definitions instead
|
|
286
|
+
*/
|
|
287
|
+
export interface LegacyToolDefinition extends ToolDefinition {
|
|
288
|
+
properties?: Record<string, unknown>;
|
|
289
|
+
requiredFields?: string[];
|
|
290
|
+
}
|
|
247
291
|
export type ToolChoice = OpenAI.ChatCompletionToolChoiceOption | FunctionCallingMode;
|
|
248
292
|
export interface ToolsConfig {
|
|
249
293
|
tools?: ToolDefinition[];
|
|
@@ -358,6 +402,7 @@ export interface ILLMRequestContext {
|
|
|
358
402
|
hasFiles?: boolean;
|
|
359
403
|
modelInfo: TCustomLLMModel | TLLMModel;
|
|
360
404
|
credentials: ILLMConnectorCredentials;
|
|
405
|
+
toolsInfo?: TToolsInfo;
|
|
361
406
|
}
|
|
362
407
|
export interface ILLMRequestFuncParams<TBody = any> {
|
|
363
408
|
acRequest: AccessRequest;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
2
|
import { BinaryInput } from '@sre/helpers/BinaryInput.helper';
|
|
3
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
3
4
|
export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
|
|
4
5
|
export declare function dataToBuffer(data: any): Buffer | null;
|
|
5
6
|
export declare const getSizeFromBinary: (data: any) => number;
|
|
@@ -14,5 +15,5 @@ export declare const isSmythFileObject: (data: any) => boolean;
|
|
|
14
15
|
export declare const isBufferObject: (data: Record<string, any>) => boolean;
|
|
15
16
|
export declare const isBase64Object: (data: Record<string, any>) => boolean;
|
|
16
17
|
export declare function getMimeType(data: any): Promise<string>;
|
|
17
|
-
export declare function formatDataForDebug(data: any): Promise<any>;
|
|
18
|
+
export declare function formatDataForDebug(data: any, candidate: IAccessCandidate): Promise<any>;
|
|
18
19
|
export declare function normalizeImageInput(inputImage: string | BinaryInput): Promise<string>;
|