@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.
Files changed (82) hide show
  1. package/dist/index.js +65 -45
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/Components/ECMASandbox.class.d.ts +14 -0
  4. package/dist/types/Components/MemoryDeleteKeyVal.class.d.ts +19 -0
  5. package/dist/types/Components/MemoryReadKeyVal.class.d.ts +17 -0
  6. package/dist/types/Components/MemoryWriteKeyVal.class.d.ts +17 -0
  7. package/dist/types/Components/MemoryWriteObject.class.d.ts +19 -0
  8. package/dist/types/Components/index.d.ts +10 -0
  9. package/dist/types/Core/ConnectorsService.d.ts +2 -1
  10. package/dist/types/helpers/ECMASandbox.helper.d.ts +3 -0
  11. package/dist/types/helpers/Log.helper.d.ts +1 -1
  12. package/dist/types/index.d.ts +8 -1
  13. package/dist/types/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.d.ts +19 -0
  14. package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +21 -10
  15. package/dist/types/subsystems/LLMManager/LLM.service/LLMConnector.d.ts +5 -5
  16. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.d.ts +2 -3
  17. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.d.ts +2 -3
  18. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Echo.class.d.ts +2 -3
  19. package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +2 -3
  20. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Groq.class.d.ts +2 -3
  21. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +3 -4
  22. package/dist/types/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.d.ts +19 -14
  23. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +95 -0
  24. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.d.ts +87 -0
  25. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.d.ts +85 -0
  26. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.d.ts +49 -0
  27. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +146 -0
  28. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.d.ts +10 -0
  29. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.d.ts +4 -0
  30. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/types.d.ts +38 -0
  31. package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +1 -2
  32. package/dist/types/subsystems/Security/Vault.service/connectors/JSONFileVault.class.d.ts +5 -0
  33. package/dist/types/types/LLM.types.d.ts +82 -37
  34. package/dist/types/utils/data.utils.d.ts +2 -1
  35. package/package.json +4 -3
  36. package/src/Components/APICall/APICall.class.ts +2 -1
  37. package/src/Components/Component.class.ts +1 -1
  38. package/src/Components/ECMASandbox.class.ts +71 -0
  39. package/src/Components/GenAILLM.class.ts +1 -1
  40. package/src/Components/MemoryDeleteKeyVal.class.ts +70 -0
  41. package/src/Components/MemoryReadKeyVal.class.ts +66 -0
  42. package/src/Components/MemoryWriteKeyVal.class.ts +62 -0
  43. package/src/Components/MemoryWriteObject.class.ts +97 -0
  44. package/src/Components/index.ts +10 -0
  45. package/src/Core/ConnectorsService.ts +3 -3
  46. package/src/helpers/Conversation.helper.ts +11 -3
  47. package/src/helpers/ECMASandbox.helper.ts +54 -0
  48. package/src/helpers/Log.helper.ts +57 -17
  49. package/src/index.ts +192 -185
  50. package/src/index.ts.bak +192 -185
  51. package/src/subsystems/AgentManager/Agent.class.ts +11 -6
  52. package/src/subsystems/AgentManager/AgentRuntime.class.ts +13 -13
  53. package/src/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.ts +131 -0
  54. package/src/subsystems/ComputeManager/Code.service/index.ts +2 -0
  55. package/src/subsystems/LLMManager/LLM.helper.ts +57 -27
  56. package/src/subsystems/LLMManager/LLM.inference.ts +4 -0
  57. package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +125 -28
  58. package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +18 -17
  59. package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +2 -7
  60. package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +2 -6
  61. package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +26 -17
  62. package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +2 -7
  63. package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +2 -7
  64. package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +314 -84
  65. package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +455 -0
  66. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +528 -0
  67. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.ts +100 -0
  68. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.ts +81 -0
  69. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +853 -0
  70. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.ts +37 -0
  71. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.ts +4 -0
  72. package/src/subsystems/LLMManager/LLM.service/connectors/openai/types.ts +37 -0
  73. package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +0 -5
  74. package/src/subsystems/LLMManager/LLM.service/index.ts +1 -1
  75. package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +2 -2
  76. package/src/subsystems/LLMManager/models.ts +1 -1
  77. package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +18 -0
  78. package/src/subsystems/MemoryManager/RuntimeContext.ts +33 -16
  79. package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +68 -42
  80. package/src/types/LLM.types.ts +91 -43
  81. package/src/utils/data.utils.ts +3 -2
  82. 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
+ }
@@ -0,0 +1,19 @@
1
+ import Joi from 'joi';
2
+ import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import { Component } from './Component.class';
4
+ export declare class MemoryDeleteKeyVal extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
6
+ constructor();
7
+ init(): void;
8
+ process(input: any, config: any, agent: Agent): Promise<{
9
+ Key: string;
10
+ deleted: boolean;
11
+ _debug: string;
12
+ _error?: undefined;
13
+ } | {
14
+ _error: any;
15
+ _debug: string;
16
+ Key?: undefined;
17
+ deleted?: undefined;
18
+ }>;
19
+ }
@@ -0,0 +1,17 @@
1
+ import Joi from 'joi';
2
+ import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import { Component } from './Component.class';
4
+ export declare class MemoryReadKeyVal extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
6
+ constructor();
7
+ init(): void;
8
+ process(input: any, config: any, agent: Agent): Promise<{
9
+ Value: any;
10
+ _debug: string;
11
+ _error?: undefined;
12
+ } | {
13
+ _error: any;
14
+ _debug: string;
15
+ Value?: undefined;
16
+ }>;
17
+ }
@@ -0,0 +1,17 @@
1
+ import Joi from 'joi';
2
+ import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import { Component } from './Component.class';
4
+ export declare class MemoryWriteKeyVal extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
6
+ constructor();
7
+ init(): void;
8
+ process(input: any, config: any, agent: Agent): Promise<{
9
+ Key: string;
10
+ _debug: string;
11
+ _error?: undefined;
12
+ } | {
13
+ _error: any;
14
+ _debug: string;
15
+ Key?: undefined;
16
+ }>;
17
+ }
@@ -0,0 +1,19 @@
1
+ import Joi from 'joi';
2
+ import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import { Component } from './Component.class';
4
+ export declare class MemoryWriteObject extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
6
+ constructor();
7
+ init(): void;
8
+ process(input: any, config: any, agent: Agent): Promise<{
9
+ Keys: string[];
10
+ Count: number;
11
+ _debug: string;
12
+ _error?: undefined;
13
+ } | {
14
+ _error: any;
15
+ _debug: string;
16
+ Keys?: undefined;
17
+ Count?: undefined;
18
+ }>;
19
+ }
@@ -37,6 +37,11 @@ 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';
41
+ import { MemoryWriteKeyVal } from './MemoryWriteKeyVal.class';
42
+ import { MemoryReadKeyVal } from './MemoryReadKeyVal.class';
43
+ import { MemoryDeleteKeyVal } from './MemoryDeleteKeyVal.class';
44
+ import { MemoryWriteObject } from './MemoryWriteObject.class';
40
45
  export declare const ComponentInstances: {
41
46
  Component: Component;
42
47
  Note: Component;
@@ -81,4 +86,9 @@ export declare const ComponentInstances: {
81
86
  ImageGenerator: ImageGenerator;
82
87
  MCPClient: MCPClient;
83
88
  OpenAPI: OpenAPI;
89
+ ECMASandbox: ECMASandbox;
90
+ MemoryWriteKeyVal: MemoryWriteKeyVal;
91
+ MemoryReadKeyVal: MemoryReadKeyVal;
92
+ MemoryDeleteKeyVal: MemoryDeleteKeyVal;
93
+ MemoryWriteObject: MemoryWriteObject;
84
94
  };
@@ -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;
@@ -32,6 +32,10 @@ export * from './Components/LogicAtMost.class';
32
32
  export * from './Components/LogicOR.class';
33
33
  export * from './Components/LogicXOR.class';
34
34
  export * from './Components/MCPClient.class';
35
+ export * from './Components/MemoryDeleteKeyVal.class';
36
+ export * from './Components/MemoryReadKeyVal.class';
37
+ export * from './Components/MemoryWriteKeyVal.class';
38
+ export * from './Components/MemoryWriteObject.class';
35
39
  export * from './Components/MultimodalLLM.class';
36
40
  export * from './Components/PromptGenerator.class';
37
41
  export * from './Components/ScrapflyWebScrape.class';
@@ -50,6 +54,7 @@ export * from './Core/SystemEvents';
50
54
  export * from './helpers/AWSLambdaCode.helper';
51
55
  export * from './helpers/BinaryInput.helper';
52
56
  export * from './helpers/Conversation.helper';
57
+ export * from './helpers/ECMASandbox.helper';
53
58
  export * from './helpers/JsonContent.helper';
54
59
  export * from './helpers/LocalCache.helper';
55
60
  export * from './helpers/Log.helper';
@@ -162,7 +167,6 @@ export * from './subsystems/LLMManager/LLM.service/connectors/Bedrock.class';
162
167
  export * from './subsystems/LLMManager/LLM.service/connectors/Echo.class';
163
168
  export * from './subsystems/LLMManager/LLM.service/connectors/GoogleAI.class';
164
169
  export * from './subsystems/LLMManager/LLM.service/connectors/Groq.class';
165
- export * from './subsystems/LLMManager/LLM.service/connectors/OpenAI.class';
166
170
  export * from './subsystems/LLMManager/LLM.service/connectors/Perplexity.class';
167
171
  export * from './subsystems/LLMManager/LLM.service/connectors/VertexAI.class';
168
172
  export * from './subsystems/LLMManager/LLM.service/connectors/xAI.class';
@@ -180,3 +184,6 @@ export * from './subsystems/Security/Vault.service/connectors/HashicorpVault.cla
180
184
  export * from './subsystems/Security/Vault.service/connectors/JSONFileVault.class';
181
185
  export * from './subsystems/Security/Vault.service/connectors/NullVault.class';
182
186
  export * from './subsystems/Security/Vault.service/connectors/SecretsManager.class';
187
+ export * from './subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class';
188
+ export * from './subsystems/LLMManager/LLM.service/connectors/openai/types';
189
+ 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,17 +1,14 @@
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, TLLMChatResponse } 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
- protected request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
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<TGoogleAIRequestBody>;
12
- protected reportUsage(usage: UsageMetadata & {
13
- cachedContentTokenCount?: number;
14
- }, metadata: {
10
+ protected reqBodyAdapter(params: TLLMPreparedParams): Promise<TGoogleAIRequestBody>;
11
+ protected reportUsage(usage: UsageMetadata, metadata: {
15
12
  modelEntryName: string;
16
13
  keySource: APIKeySource;
17
14
  agentId: string;
@@ -26,13 +23,21 @@ export declare class VertexAIConnector extends LLMConnector {
26
23
  agentId: string;
27
24
  teamId: string;
28
25
  };
29
- formatToolsConfig({ type, toolDefinitions, toolChoice }: {
30
- type?: string;
26
+ private prepareMessages;
27
+ private processFiles;
28
+ private convertMessagesToVertexAIFormat;
29
+ private formatToolsForVertexAI;
30
+ formatToolsConfig({ toolDefinitions, toolChoice }: {
31
31
  toolDefinitions: any;
32
32
  toolChoice?: string;
33
- }): void;
34
- getConsistentMessages(messages: any): {
35
- role: import("@sre/types/LLM.types").TLLMMessageRole;
36
- parts: any[];
37
- }[];
33
+ }): {
34
+ tools: any;
35
+ toolChoice: {
36
+ type: string;
37
+ };
38
+ };
39
+ transformToolMessageBlocks({ messageBlock, toolsData, }: {
40
+ messageBlock: TLLMMessageBlock;
41
+ toolsData: ToolData[];
42
+ }): TLLMToolResultMessageBlock[];
38
43
  }
@@ -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
+ }