@smythos/sre 1.5.37 → 1.5.39

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.
Files changed (71) hide show
  1. package/dist/index.js +62 -44
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/Components/ECMASandbox.class.d.ts +14 -0
  4. package/dist/types/Components/index.d.ts +2 -0
  5. package/dist/types/Core/ConnectorsService.d.ts +2 -1
  6. package/dist/types/helpers/ECMASandbox.helper.d.ts +3 -0
  7. package/dist/types/helpers/Log.helper.d.ts +1 -1
  8. package/dist/types/index.d.ts +4 -1
  9. package/dist/types/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.d.ts +19 -0
  10. package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +21 -10
  11. package/dist/types/subsystems/LLMManager/LLM.service/LLMConnector.d.ts +5 -5
  12. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.d.ts +2 -3
  13. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.d.ts +2 -3
  14. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Echo.class.d.ts +2 -3
  15. package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +2 -3
  16. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Groq.class.d.ts +2 -3
  17. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +3 -4
  18. package/dist/types/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.d.ts +15 -7
  19. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +95 -0
  20. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.d.ts +87 -0
  21. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.d.ts +85 -0
  22. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.d.ts +49 -0
  23. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +146 -0
  24. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.d.ts +10 -0
  25. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.d.ts +4 -0
  26. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/types.d.ts +38 -0
  27. package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +1 -2
  28. package/dist/types/subsystems/Security/Vault.service/connectors/JSONFileVault.class.d.ts +5 -0
  29. package/dist/types/types/LLM.types.d.ts +82 -37
  30. package/dist/types/utils/data.utils.d.ts +2 -1
  31. package/package.json +4 -3
  32. package/src/Components/APICall/APICall.class.ts +2 -1
  33. package/src/Components/Component.class.ts +1 -1
  34. package/src/Components/ECMASandbox.class.ts +71 -0
  35. package/src/Components/GenAILLM.class.ts +1 -1
  36. package/src/Components/index.ts +2 -0
  37. package/src/Core/ConnectorsService.ts +3 -3
  38. package/src/helpers/ECMASandbox.helper.ts +54 -0
  39. package/src/helpers/Log.helper.ts +57 -17
  40. package/src/index.ts +188 -185
  41. package/src/index.ts.bak +188 -185
  42. package/src/subsystems/AgentManager/Agent.class.ts +11 -6
  43. package/src/subsystems/AgentManager/AgentRuntime.class.ts +13 -13
  44. package/src/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.ts +131 -0
  45. package/src/subsystems/ComputeManager/Code.service/index.ts +2 -0
  46. package/src/subsystems/LLMManager/LLM.helper.ts +57 -27
  47. package/src/subsystems/LLMManager/LLM.inference.ts +4 -0
  48. package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +123 -28
  49. package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +13 -14
  50. package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +2 -7
  51. package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +2 -6
  52. package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +8 -14
  53. package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +2 -7
  54. package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +2 -7
  55. package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +121 -9
  56. package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +455 -0
  57. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +528 -0
  58. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.ts +100 -0
  59. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.ts +81 -0
  60. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +853 -0
  61. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.ts +37 -0
  62. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.ts +4 -0
  63. package/src/subsystems/LLMManager/LLM.service/connectors/openai/types.ts +37 -0
  64. package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +0 -5
  65. package/src/subsystems/LLMManager/LLM.service/index.ts +1 -1
  66. package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +18 -0
  67. package/src/subsystems/MemoryManager/RuntimeContext.ts +33 -16
  68. package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +68 -42
  69. package/src/types/LLM.types.ts +91 -43
  70. package/src/utils/data.utils.ts +3 -2
  71. package/src/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.ts +0 -848
@@ -0,0 +1,14 @@
1
+ import { IAgent as Agent } from '@sre/types/Agent.types';
2
+ import { Component } from './Component.class';
3
+ import Joi from 'joi';
4
+ export declare class ECMASandbox extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
6
+ constructor();
7
+ init(): void;
8
+ process(input: any, config: any, agent: Agent): Promise<{
9
+ Output: any;
10
+ _error: any;
11
+ _debug: string;
12
+ }>;
13
+ private generateInputVarCode;
14
+ }
@@ -37,6 +37,7 @@ import { ServerlessCode } from './ServerlessCode.class';
37
37
  import { ImageGenerator } from './ImageGenerator.class';
38
38
  import { MCPClient } from './MCPClient.class';
39
39
  import { OpenAPI } from './OpenAPI.class';
40
+ import { ECMASandbox } from './ECMASandbox.class';
40
41
  export declare const ComponentInstances: {
41
42
  Component: Component;
42
43
  Note: Component;
@@ -81,4 +82,5 @@ export declare const ComponentInstances: {
81
82
  ImageGenerator: ImageGenerator;
82
83
  MCPClient: MCPClient;
83
84
  OpenAPI: OpenAPI;
85
+ ECMASandbox: ECMASandbox;
84
86
  };
@@ -14,6 +14,7 @@ import { ManagedVaultConnector } from '@sre/Security/ManagedVault.service/Manage
14
14
  import { LogConnector } from '@sre/IO/Log.service/LogConnector';
15
15
  import { ComponentConnector } from '@sre/AgentManager/Component.service/ComponentConnector';
16
16
  import { ModelsProviderConnector } from '@sre/LLMManager/ModelsProvider.service/ModelsProviderConnector';
17
+ import { CodeConnector } from '@sre/ComputeManager/Code.service/CodeConnector';
17
18
  export declare class ConnectorService {
18
19
  static Connectors: {};
19
20
  static ConnectorInstances: any;
@@ -56,7 +57,7 @@ export declare class ConnectorService {
56
57
  static getModelsProviderConnector(name?: string): ModelsProviderConnector;
57
58
  static hasInstance(connectorType: TConnectorService, connectorName?: string): any;
58
59
  static getRouterConnector(name?: string): RouterConnector;
59
- static getCodeConnector(name?: string): RouterConnector;
60
+ static getCodeConnector(name?: string): CodeConnector;
60
61
  }
61
62
  export declare abstract class ConnectorServiceProvider {
62
63
  abstract register(): any;
@@ -0,0 +1,3 @@
1
+ import 'ses';
2
+ export declare function runJs(code: string): any;
3
+ export declare function generateExecutableCode(code: string, parameters: string[], inputs: Record<string, any>): string;
@@ -19,4 +19,4 @@ export declare class LogHelper extends EventEmitter {
19
19
  error(...args: any[]): void;
20
20
  close(): void;
21
21
  }
22
- export declare function Logger(module: string, withMemoryStore?: boolean): LogHelper;
22
+ export declare function Logger(module: string | any, withMemoryStore?: boolean): LogHelper;
@@ -50,6 +50,7 @@ export * from './Core/SystemEvents';
50
50
  export * from './helpers/AWSLambdaCode.helper';
51
51
  export * from './helpers/BinaryInput.helper';
52
52
  export * from './helpers/Conversation.helper';
53
+ export * from './helpers/ECMASandbox.helper';
53
54
  export * from './helpers/JsonContent.helper';
54
55
  export * from './helpers/LocalCache.helper';
55
56
  export * from './helpers/Log.helper';
@@ -162,7 +163,6 @@ export * from './subsystems/LLMManager/LLM.service/connectors/Bedrock.class';
162
163
  export * from './subsystems/LLMManager/LLM.service/connectors/Echo.class';
163
164
  export * from './subsystems/LLMManager/LLM.service/connectors/GoogleAI.class';
164
165
  export * from './subsystems/LLMManager/LLM.service/connectors/Groq.class';
165
- export * from './subsystems/LLMManager/LLM.service/connectors/OpenAI.class';
166
166
  export * from './subsystems/LLMManager/LLM.service/connectors/Perplexity.class';
167
167
  export * from './subsystems/LLMManager/LLM.service/connectors/VertexAI.class';
168
168
  export * from './subsystems/LLMManager/LLM.service/connectors/xAI.class';
@@ -180,3 +180,6 @@ export * from './subsystems/Security/Vault.service/connectors/HashicorpVault.cla
180
180
  export * from './subsystems/Security/Vault.service/connectors/JSONFileVault.class';
181
181
  export * from './subsystems/Security/Vault.service/connectors/NullVault.class';
182
182
  export * from './subsystems/Security/Vault.service/connectors/SecretsManager.class';
183
+ export * from './subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class';
184
+ export * from './subsystems/LLMManager/LLM.service/connectors/openai/types';
185
+ export * from './subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants';
@@ -0,0 +1,19 @@
1
+ import { IAccessCandidate } from '@sre/types/ACL.types';
2
+ import { ACL } from '@sre/Security/AccessControl/ACL.class';
3
+ import { CodeConfig, CodePreparationResult, CodeConnector, CodeInput, CodeDeployment, CodeExecutionResult } from '../CodeConnector';
4
+ import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
5
+ export declare class ECMASandbox extends CodeConnector {
6
+ name: string;
7
+ private sandboxUrl;
8
+ constructor(config: {
9
+ sandboxUrl: string;
10
+ });
11
+ prepare(acRequest: AccessRequest, codeUID: string, input: CodeInput, config: CodeConfig): Promise<CodePreparationResult>;
12
+ deploy(acRequest: AccessRequest, codeUID: string, input: CodeInput, config: CodeConfig): Promise<CodeDeployment>;
13
+ execute(acRequest: AccessRequest, codeUID: string, inputs: Record<string, any>, config: CodeConfig): Promise<CodeExecutionResult>;
14
+ executeDeployment(acRequest: AccessRequest, codeUID: string, deploymentId: string, inputs: Record<string, any>, config: CodeConfig): Promise<CodeExecutionResult>;
15
+ listDeployments(acRequest: AccessRequest, codeUID: string, config: CodeConfig): Promise<CodeDeployment[]>;
16
+ getDeployment(acRequest: AccessRequest, codeUID: string, deploymentId: string, config: CodeConfig): Promise<CodeDeployment | null>;
17
+ deleteDeployment(acRequest: AccessRequest, codeUID: string, deploymentId: string): Promise<void>;
18
+ getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
19
+ }
@@ -49,13 +49,24 @@ export declare class LLMHelper {
49
49
  * 2. Calculating tokens for each image in the prompt based on its dimensions.
50
50
  * 3. Summing up text and image tokens to get the total token count.
51
51
  *
52
+ * IMPORTANT: This returns the base token calculation for rate limiting and quota management.
53
+ * The actual tokens charged by OpenAI may differ significantly:
54
+ * - GPT-4o: Uses base calculation (matches this result)
55
+ * - GPT-4o-mini: Intentionally inflates image tokens by ~33x (e.g., 431 → 14,180 tokens)
56
+ * - GPT-4.1 series: Uses different patch-based calculations with various multipliers
57
+ *
58
+ * For consistent user limits regardless of model choice, use this base calculation.
59
+ * For billing estimates, refer to OpenAI's pricing calculator or API response.
60
+ *
61
+ * @see https://platform.openai.com/docs/guides/images-vision?api-mode=responses#calculating-costs
62
+ *
52
63
  * @example
53
64
  * const prompt = [
54
65
  * { type: 'text', text: 'Describe this image:' },
55
66
  * { type: 'image_url', image_url: { url: 'https://example.com/image.jpg' } }
56
67
  * ];
57
68
  * const tokenCount = await countVisionPromptTokens(prompt);
58
- * console.log(tokenCount); // e.g., 150
69
+ * console.log(tokenCount); // e.g., 150 (base calculation for rate limiting)
59
70
  */
60
71
  static countVisionPromptTokens(prompt: any): Promise<number>;
61
72
  /**
@@ -88,15 +99,15 @@ export declare class LLMHelper {
88
99
  * @returns {number} The number of tokens required to process the image.
89
100
  *
90
101
  * @description
91
- * This method estimates the token count for image processing based on the image dimensions and detail mode.
92
- * It uses a tiling approach to calculate the token count, scaling the image if necessary.
93
- *
94
- * - If detailMode is 'low', it returns a fixed token count of 85.
95
- * - For other modes, it calculates based on the image dimensions:
96
- * - Scales down images larger than 2048 pixels in any dimension.
97
- * - Adjusts the scaled dimension to fit within a 768x1024 aspect ratio.
98
- * - Calculates the number of 512x512 tiles needed to cover the image.
99
- * - Returns the total token count based on the number of tiles.
102
+ * This method calculates the token count for image processing based on OpenAI's official documentation:
103
+ *
104
+ * For 'low' detail mode: Returns 85 tokens regardless of image size.
105
+ *
106
+ * For 'high' detail mode (default):
107
+ * 1. Scale image to fit within 2048x2048 square (maintaining aspect ratio)
108
+ * 2. Scale image so shortest side is 768px (if both dimensions > 768px)
109
+ * 3. Calculate number of 512x512 tiles needed
110
+ * 4. Return 85 + (170 * number_of_tiles)
100
111
  *
101
112
  * @example
102
113
  * const tokenCount = countImageTokens(1024, 768);
@@ -1,6 +1,6 @@
1
1
  import { Connector } from '@sre/Core/Connector.class';
2
2
  import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
3
- import { TLLMConnectorParams, TLLMMessageBlock, TLLMToolResultMessageBlock, ToolData, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMRequestBody } from '@sre/types/LLM.types';
3
+ import type { TLLMConnectorParams, TLLMMessageBlock, TLLMToolResultMessageBlock, ToolData, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMRequestBody } from '@sre/types/LLM.types';
4
4
  import EventEmitter from 'events';
5
5
  import { Readable } from 'stream';
6
6
  export interface ILLMConnectorRequest {
@@ -11,8 +11,6 @@ export interface ILLMConnectorRequest {
11
11
  }
12
12
  export declare class LLMStream extends Readable {
13
13
  private dataQueue;
14
- private toolsData;
15
- private hasData;
16
14
  isReading: boolean;
17
15
  constructor(options?: any);
18
16
  _read(size: any): void;
@@ -23,7 +21,6 @@ export declare abstract class LLMConnector extends Connector {
23
21
  abstract name: string;
24
22
  protected abstract request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
25
23
  protected abstract streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
26
- protected abstract webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
27
24
  protected abstract reqBodyAdapter(params: TLLMConnectorParams): Promise<TLLMRequestBody>;
28
25
  protected abstract reportUsage(usage: any, metadata: {
29
26
  modelEntryName: string;
@@ -37,10 +34,11 @@ export declare abstract class LLMConnector extends Connector {
37
34
  requester(candidate: AccessCandidate): ILLMConnectorRequest;
38
35
  enhancePrompt(prompt: string, config: any): string;
39
36
  postProcess(response: string): any;
40
- formatToolsConfig({ type, toolDefinitions, toolChoice }: {
37
+ formatToolsConfig({ type, toolDefinitions, toolChoice, modelInfo }: {
41
38
  type?: string;
42
39
  toolDefinitions: any;
43
40
  toolChoice?: string;
41
+ modelInfo?: any;
44
42
  }): void;
45
43
  transformToolMessageBlocks({ messageBlock, toolsData, }: {
46
44
  messageBlock: TLLMMessageBlock;
@@ -48,6 +46,8 @@ export declare abstract class LLMConnector extends Connector {
48
46
  }): TLLMToolResultMessageBlock[];
49
47
  getConsistentMessages(messages: TLLMMessageBlock[]): TLLMMessageBlock[];
50
48
  private prepareParams;
49
+ private prepareOpenAIToolsInfo;
50
+ private prepareXAIToolsInfo;
51
51
  private formatParamValues;
52
52
  /**
53
53
  * Retrieves the team ID associated with the given access candidate
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { TLLMParams, ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TAnthropicRequestBody } from '@sre/types/LLM.types';
3
+ import { ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TAnthropicRequestBody, TLLMPreparedParams } from '@sre/types/LLM.types';
4
4
  import { LLMConnector } from '../LLMConnector';
5
5
  export declare class AnthropicConnector extends LLMConnector {
6
6
  name: string;
@@ -8,8 +8,7 @@ export declare class AnthropicConnector extends LLMConnector {
8
8
  private getClient;
9
9
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
10
10
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
11
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
12
- protected reqBodyAdapter(params: TLLMParams): Promise<TAnthropicRequestBody>;
11
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<TAnthropicRequestBody>;
13
12
  protected reportUsage(usage: Anthropic.Messages.Usage & {
14
13
  cache_creation_input_tokens?: number;
15
14
  cache_read_input_tokens?: number;
@@ -1,14 +1,13 @@
1
1
  import { ConverseCommandInput, TokenUsage } from '@aws-sdk/client-bedrock-runtime';
2
2
  import EventEmitter from 'events';
3
- import { TLLMParams, ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse } from '@sre/types/LLM.types';
3
+ import { ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMPreparedParams } from '@sre/types/LLM.types';
4
4
  import { LLMConnector } from '../LLMConnector';
5
5
  export declare class BedrockConnector extends LLMConnector {
6
6
  name: string;
7
7
  private getClient;
8
8
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
9
9
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
10
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
11
- protected reqBodyAdapter(params: TLLMParams): Promise<ConverseCommandInput>;
10
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<ConverseCommandInput>;
12
11
  protected reportUsage(usage: TokenUsage & {
13
12
  cacheReadInputTokenCount: number;
14
13
  cacheWriteInputTokenCount: number;
@@ -1,12 +1,11 @@
1
1
  import { LLMConnector } from '../LLMConnector';
2
2
  import EventEmitter from 'events';
3
- import { APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMParams } from '@sre/types/LLM.types';
3
+ import { APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMPreparedParams } from '@sre/types/LLM.types';
4
4
  export declare class EchoConnector extends LLMConnector {
5
5
  name: string;
6
6
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
7
7
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
8
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
9
- protected reqBodyAdapter(params: TLLMParams): Promise<any>;
8
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<any>;
10
9
  enhancePrompt(prompt: string, config: any): string;
11
10
  postProcess(response: any): any;
12
11
  protected reportUsage(usage: any, metadata: {
@@ -1,6 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import { UsageMetadata } from '@google/generative-ai';
3
- import { TLLMMessageBlock, ToolData, TLLMToolResultMessageBlock, APIKeySource, TLLMParams, ILLMRequestFuncParams, TLLMChatResponse, TGoogleAIRequestBody } from '@sre/types/LLM.types';
3
+ import { TLLMMessageBlock, ToolData, TLLMToolResultMessageBlock, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TGoogleAIRequestBody, TLLMPreparedParams } from '@sre/types/LLM.types';
4
4
  import { LLMConnector } from '../LLMConnector';
5
5
  type UsageMetadataWithThoughtsToken = UsageMetadata & {
6
6
  thoughtsTokenCount: number;
@@ -11,10 +11,9 @@ export declare class GoogleAIConnector extends LLMConnector {
11
11
  private getClient;
12
12
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
13
13
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
14
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
15
14
  protected imageGenRequest({ body, context }: ILLMRequestFuncParams): Promise<any>;
16
15
  protected imageEditRequest({ body, context }: ILLMRequestFuncParams): Promise<any>;
17
- protected reqBodyAdapter(params: TLLMParams): Promise<TGoogleAIRequestBody>;
16
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<TGoogleAIRequestBody>;
18
17
  protected reportUsage(usage: UsageMetadataWithThoughtsToken, metadata: {
19
18
  modelEntryName: string;
20
19
  keySource: APIKeySource;
@@ -1,6 +1,6 @@
1
1
  import Groq from 'groq-sdk';
2
2
  import EventEmitter from 'events';
3
- import { TLLMMessageBlock, ToolData, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMParams, TLLMToolResultMessageBlock } from '@sre/types/LLM.types';
3
+ import { TLLMMessageBlock, ToolData, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMPreparedParams, TLLMToolResultMessageBlock } from '@sre/types/LLM.types';
4
4
  import { LLMConnector } from '../LLMConnector';
5
5
  type ChatCompletionCreateParams = {
6
6
  model: string;
@@ -18,8 +18,7 @@ export declare class GroqConnector extends LLMConnector {
18
18
  private getClient;
19
19
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
20
20
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
21
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
22
- protected reqBodyAdapter(params: TLLMParams): Promise<ChatCompletionCreateParams>;
21
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<ChatCompletionCreateParams>;
23
22
  protected reportUsage(usage: Groq.Completions.CompletionUsage & {
24
23
  prompt_tokens_details?: {
25
24
  cached_tokens?: number;
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'events';
2
- import { TLLMParams, ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, TLLMMessageRole, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse } from '@sre/types/LLM.types';
2
+ import { ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, TLLMMessageRole, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMPreparedParams } from '@sre/types/LLM.types';
3
3
  import { LLMConnector } from '../LLMConnector';
4
4
  type ChatCompletionParams = {
5
5
  model: string;
@@ -28,8 +28,7 @@ export declare class PerplexityConnector extends LLMConnector {
28
28
  private getClient;
29
29
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
30
30
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
31
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
32
- protected reqBodyAdapter(params: TLLMParams): Promise<ChatCompletionParams>;
31
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<ChatCompletionParams>;
33
32
  protected reportUsage(usage: TUsage, metadata: {
34
33
  modelEntryName: string;
35
34
  keySource: APIKeySource;
@@ -65,7 +64,7 @@ export declare class PerplexityConnector extends LLMConnector {
65
64
  role: TLLMMessageRole;
66
65
  content?: string | {
67
66
  text: string;
68
- }[] | 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>;
67
+ }[] | 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>;
69
68
  parts?: {
70
69
  text?: string;
71
70
  functionCall?: {
@@ -1,14 +1,13 @@
1
1
  import { type UsageMetadata } from '@google-cloud/vertexai';
2
2
  import EventEmitter from 'events';
3
- import { TLLMParams, APIKeySource, ILLMRequestFuncParams, TGoogleAIRequestBody } from '@sre/types/LLM.types';
3
+ import { APIKeySource, ILLMRequestFuncParams, TGoogleAIRequestBody, TLLMPreparedParams, TLLMMessageBlock, ToolData, TLLMToolResultMessageBlock, TLLMMessageRole } from '@sre/types/LLM.types';
4
4
  import { LLMConnector } from '../LLMConnector';
5
5
  export declare class VertexAIConnector extends LLMConnector {
6
6
  name: string;
7
7
  private getClient;
8
8
  protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
9
9
  protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
10
- protected webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
11
- protected reqBodyAdapter(params: TLLMParams): Promise<TGoogleAIRequestBody>;
10
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<TGoogleAIRequestBody>;
12
11
  protected reportUsage(usage: UsageMetadata & {
13
12
  cachedContentTokenCount?: number;
14
13
  }, metadata: {
@@ -26,13 +25,22 @@ export declare class VertexAIConnector extends LLMConnector {
26
25
  agentId: string;
27
26
  teamId: string;
28
27
  };
29
- formatToolsConfig({ type, toolDefinitions, toolChoice }: {
30
- type?: string;
28
+ private sanitizeFunctionName;
29
+ formatToolsConfig({ toolDefinitions, toolChoice }: {
31
30
  toolDefinitions: any;
32
31
  toolChoice?: string;
33
- }): void;
32
+ }): {
33
+ tools: any;
34
+ toolChoice: {
35
+ type: string;
36
+ };
37
+ };
38
+ transformToolMessageBlocks({ messageBlock, toolsData, }: {
39
+ messageBlock: TLLMMessageBlock;
40
+ toolsData: ToolData[];
41
+ }): TLLMToolResultMessageBlock[];
34
42
  getConsistentMessages(messages: any): {
35
- role: import("@sre/types/LLM.types").TLLMMessageRole;
43
+ role: TLLMMessageRole;
36
44
  parts: any[];
37
45
  }[];
38
46
  }
@@ -0,0 +1,95 @@
1
+ import EventEmitter from 'events';
2
+ import OpenAI from 'openai';
3
+ import { ToolData, TLLMMessageBlock, TLLMToolResultMessageBlock, TLLMMessageRole, APIKeySource, ILLMRequestFuncParams, TOpenAIRequestBody, TLLMChatResponse, ILLMRequestContext, TLLMPreparedParams } from '@sre/types/LLM.types';
4
+ import { LLMConnector } from '../../LLMConnector';
5
+ export declare class OpenAIConnector extends LLMConnector {
6
+ name: string;
7
+ private interfaceFactory;
8
+ constructor();
9
+ /**
10
+ * Get the appropriate API interface for the given interface type and context
11
+ */
12
+ private getApiInterface;
13
+ /**
14
+ * Determine the appropriate interface type based on context and capabilities
15
+ */
16
+ private getInterfaceType;
17
+ protected getClient(params: ILLMRequestContext): Promise<OpenAI>;
18
+ protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
19
+ protected streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
20
+ protected imageGenRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<OpenAI.ImagesResponse>;
21
+ protected imageEditRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<OpenAI.ImagesResponse>;
22
+ formatToolsConfig({ type, toolDefinitions, toolChoice, modelInfo }: {
23
+ type?: string;
24
+ toolDefinitions: any;
25
+ toolChoice?: string;
26
+ modelInfo?: any;
27
+ }): {
28
+ tools: any[];
29
+ tool_choice: string;
30
+ } | {
31
+ tools?: undefined;
32
+ tool_choice?: undefined;
33
+ };
34
+ transformToolMessageBlocks({ messageBlock, toolsData, }: {
35
+ messageBlock: TLLMMessageBlock;
36
+ toolsData: ToolData[];
37
+ }): TLLMToolResultMessageBlock[];
38
+ getConsistentMessages(messages: any): {
39
+ role: TLLMMessageRole;
40
+ content?: string | {
41
+ text: string;
42
+ }[] | 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>;
43
+ parts?: {
44
+ text?: string;
45
+ functionCall?: {
46
+ name: string;
47
+ args: string;
48
+ };
49
+ functionResponse?: {
50
+ name: string;
51
+ response: {
52
+ name: string;
53
+ content: string;
54
+ };
55
+ };
56
+ }[];
57
+ tool_calls?: ToolData[];
58
+ }[];
59
+ private validateTokenLimit;
60
+ private getProvider;
61
+ /**
62
+ * Prepare request body for OpenAI Responses API
63
+ * Uses MessageTransformer and ToolsTransformer for clean interface transformations
64
+ */
65
+ private prepareImageGenerationBody;
66
+ private prepareImageEditBody;
67
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<TOpenAIRequestBody>;
68
+ private prepareRequestBody;
69
+ protected reportUsage(usage: OpenAI.Completions.CompletionUsage & {
70
+ input_tokens?: number;
71
+ output_tokens?: number;
72
+ input_tokens_details?: {
73
+ cached_tokens?: number;
74
+ };
75
+ prompt_tokens_details?: {
76
+ cached_tokens?: number;
77
+ };
78
+ cost?: number;
79
+ }, metadata: {
80
+ modelEntryName: string;
81
+ keySource: APIKeySource;
82
+ agentId: string;
83
+ teamId: string;
84
+ }): {
85
+ sourceId: string;
86
+ input_tokens: number;
87
+ output_tokens: number;
88
+ input_tokens_cache_write: number;
89
+ input_tokens_cache_read: number;
90
+ cost: number;
91
+ keySource: APIKeySource;
92
+ agentId: string;
93
+ teamId: string;
94
+ };
95
+ }
@@ -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
+ }