@smythos/sre 1.5.1 → 1.5.4
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/LICENSE +18 -0
- package/dist/index.js +22329 -4
- package/dist/index.js.map +1 -1
- package/dist/types/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.d.ts +2 -2
- package/dist/types/subsystems/IO/VectorDB.service/embed/BaseEmbedding.d.ts +11 -7
- package/dist/types/types/VectorDB.types.d.ts +13 -11
- package/package.json +102 -127
- package/src/Components/APICall/APICall.class.ts +155 -0
- package/src/Components/APICall/AccessTokenManager.ts +130 -0
- package/src/Components/APICall/ArrayBufferResponse.helper.ts +58 -0
- package/src/Components/APICall/OAuth.helper.ts +294 -0
- package/src/Components/APICall/mimeTypeCategories.ts +46 -0
- package/src/Components/APICall/parseData.ts +167 -0
- package/src/Components/APICall/parseHeaders.ts +41 -0
- package/src/Components/APICall/parseProxy.ts +68 -0
- package/src/Components/APICall/parseUrl.ts +91 -0
- package/src/Components/APIEndpoint.class.ts +234 -0
- package/src/Components/APIOutput.class.ts +58 -0
- package/src/Components/AgentPlugin.class.ts +102 -0
- package/src/Components/Async.class.ts +155 -0
- package/src/Components/Await.class.ts +90 -0
- package/src/Components/Classifier.class.ts +158 -0
- package/src/Components/Component.class.ts +94 -0
- package/src/Components/ComponentHost.class.ts +38 -0
- package/src/Components/DataSourceCleaner.class.ts +92 -0
- package/src/Components/DataSourceIndexer.class.ts +181 -0
- package/src/Components/DataSourceLookup.class.ts +141 -0
- package/src/Components/FEncDec.class.ts +29 -0
- package/src/Components/FHash.class.ts +33 -0
- package/src/Components/FSign.class.ts +80 -0
- package/src/Components/FSleep.class.ts +25 -0
- package/src/Components/FTimestamp.class.ts +25 -0
- package/src/Components/FileStore.class.ts +75 -0
- package/src/Components/ForEach.class.ts +97 -0
- package/src/Components/GPTPlugin.class.ts +70 -0
- package/src/Components/GenAILLM.class.ts +395 -0
- package/src/Components/HuggingFace.class.ts +314 -0
- package/src/Components/Image/imageSettings.config.ts +70 -0
- package/src/Components/ImageGenerator.class.ts +407 -0
- package/src/Components/JSONFilter.class.ts +54 -0
- package/src/Components/LLMAssistant.class.ts +213 -0
- package/src/Components/LogicAND.class.ts +28 -0
- package/src/Components/LogicAtLeast.class.ts +85 -0
- package/src/Components/LogicAtMost.class.ts +86 -0
- package/src/Components/LogicOR.class.ts +29 -0
- package/src/Components/LogicXOR.class.ts +34 -0
- package/src/Components/MCPClient.class.ts +112 -0
- package/src/Components/PromptGenerator.class.ts +122 -0
- package/src/Components/ScrapflyWebScrape.class.ts +159 -0
- package/src/Components/TavilyWebSearch.class.ts +98 -0
- package/src/Components/index.ts +77 -0
- package/src/Core/AgentProcess.helper.ts +240 -0
- package/src/Core/Connector.class.ts +123 -0
- package/src/Core/ConnectorsService.ts +192 -0
- package/src/Core/DummyConnector.ts +49 -0
- package/src/Core/HookService.ts +105 -0
- package/src/Core/SmythRuntime.class.ts +292 -0
- package/src/Core/SystemEvents.ts +15 -0
- package/src/Core/boot.ts +55 -0
- package/src/config.ts +15 -0
- package/src/constants.ts +125 -0
- package/src/data/hugging-face.params.json +580 -0
- package/src/helpers/BinaryInput.helper.ts +324 -0
- package/src/helpers/Conversation.helper.ts +1094 -0
- package/src/helpers/JsonContent.helper.ts +97 -0
- package/src/helpers/LocalCache.helper.ts +97 -0
- package/src/helpers/Log.helper.ts +234 -0
- package/src/helpers/OpenApiParser.helper.ts +150 -0
- package/src/helpers/S3Cache.helper.ts +129 -0
- package/src/helpers/SmythURI.helper.ts +5 -0
- package/src/helpers/TemplateString.helper.ts +243 -0
- package/src/helpers/TypeChecker.helper.ts +329 -0
- package/src/index.ts +179 -0
- package/src/index.ts.bak +179 -0
- package/src/subsystems/AgentManager/Agent.class.ts +1108 -0
- package/src/subsystems/AgentManager/Agent.helper.ts +3 -0
- package/src/subsystems/AgentManager/AgentData.service/AgentDataConnector.ts +230 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/CLIAgentDataConnector.class.ts +66 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/LocalAgentDataConnector.class.ts +142 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.ts +39 -0
- package/src/subsystems/AgentManager/AgentData.service/index.ts +18 -0
- package/src/subsystems/AgentManager/AgentLogger.class.ts +297 -0
- package/src/subsystems/AgentManager/AgentRequest.class.ts +51 -0
- package/src/subsystems/AgentManager/AgentRuntime.class.ts +559 -0
- package/src/subsystems/AgentManager/AgentSSE.class.ts +101 -0
- package/src/subsystems/AgentManager/AgentSettings.class.ts +52 -0
- package/src/subsystems/AgentManager/Component.service/ComponentConnector.ts +32 -0
- package/src/subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class.ts +59 -0
- package/src/subsystems/AgentManager/Component.service/index.ts +11 -0
- package/src/subsystems/AgentManager/EmbodimentSettings.class.ts +47 -0
- package/src/subsystems/AgentManager/ForkedAgent.class.ts +153 -0
- package/src/subsystems/AgentManager/OSResourceMonitor.ts +77 -0
- package/src/subsystems/ComputeManager/Code.service/CodeConnector.ts +99 -0
- package/src/subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class.ts +63 -0
- package/src/subsystems/ComputeManager/Code.service/index.ts +11 -0
- package/src/subsystems/IO/CLI.service/CLIConnector.ts +47 -0
- package/src/subsystems/IO/CLI.service/index.ts +9 -0
- package/src/subsystems/IO/Log.service/LogConnector.ts +32 -0
- package/src/subsystems/IO/Log.service/connectors/ConsoleLog.class.ts +28 -0
- package/src/subsystems/IO/Log.service/index.ts +13 -0
- package/src/subsystems/IO/NKV.service/NKVConnector.ts +41 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRAM.class.ts +204 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRedis.class.ts +182 -0
- package/src/subsystems/IO/NKV.service/index.ts +12 -0
- package/src/subsystems/IO/Router.service/RouterConnector.ts +21 -0
- package/src/subsystems/IO/Router.service/connectors/ExpressRouter.class.ts +48 -0
- package/src/subsystems/IO/Router.service/connectors/NullRouter.class.ts +40 -0
- package/src/subsystems/IO/Router.service/index.ts +11 -0
- package/src/subsystems/IO/Storage.service/SmythFS.class.ts +472 -0
- package/src/subsystems/IO/Storage.service/StorageConnector.ts +66 -0
- package/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts +305 -0
- package/src/subsystems/IO/Storage.service/connectors/S3Storage.class.ts +418 -0
- package/src/subsystems/IO/Storage.service/index.ts +13 -0
- package/src/subsystems/IO/VectorDB.service/VectorDBConnector.ts +108 -0
- package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +454 -0
- package/src/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.ts +384 -0
- package/src/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.ts +421 -0
- package/src/subsystems/IO/VectorDB.service/embed/BaseEmbedding.ts +107 -0
- package/src/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.ts +109 -0
- package/src/subsystems/IO/VectorDB.service/embed/index.ts +21 -0
- package/src/subsystems/IO/VectorDB.service/index.ts +14 -0
- package/src/subsystems/LLMManager/LLM.helper.ts +221 -0
- package/src/subsystems/LLMManager/LLM.inference.ts +335 -0
- package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +375 -0
- package/src/subsystems/LLMManager/LLM.service/LLMCredentials.helper.ts +145 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +632 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +405 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +81 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +689 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +257 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.ts +848 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +255 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +193 -0
- package/src/subsystems/LLMManager/LLM.service/index.ts +43 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +281 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/connectors/SmythModelsProvider.class.ts +229 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/index.ts +11 -0
- package/src/subsystems/LLMManager/custom-models.ts +854 -0
- package/src/subsystems/LLMManager/models.ts +2539 -0
- package/src/subsystems/LLMManager/paramMappings.ts +69 -0
- package/src/subsystems/MemoryManager/Cache.service/CacheConnector.ts +86 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/LocalStorageCache.class.ts +297 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/RAMCache.class.ts +201 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +252 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/S3Cache.class.ts +373 -0
- package/src/subsystems/MemoryManager/Cache.service/index.ts +15 -0
- package/src/subsystems/MemoryManager/LLMCache.ts +72 -0
- package/src/subsystems/MemoryManager/LLMContext.ts +125 -0
- package/src/subsystems/MemoryManager/RuntimeContext.ts +249 -0
- package/src/subsystems/Security/AccessControl/ACL.class.ts +208 -0
- package/src/subsystems/Security/AccessControl/AccessCandidate.class.ts +76 -0
- package/src/subsystems/Security/AccessControl/AccessRequest.class.ts +52 -0
- package/src/subsystems/Security/Account.service/AccountConnector.ts +41 -0
- package/src/subsystems/Security/Account.service/connectors/AWSAccount.class.ts +76 -0
- package/src/subsystems/Security/Account.service/connectors/DummyAccount.class.ts +130 -0
- package/src/subsystems/Security/Account.service/connectors/JSONFileAccount.class.ts +159 -0
- package/src/subsystems/Security/Account.service/index.ts +14 -0
- package/src/subsystems/Security/Credentials.helper.ts +62 -0
- package/src/subsystems/Security/ManagedVault.service/ManagedVaultConnector.ts +34 -0
- package/src/subsystems/Security/ManagedVault.service/connectors/NullManagedVault.class.ts +57 -0
- package/src/subsystems/Security/ManagedVault.service/connectors/SecretManagerManagedVault.ts +154 -0
- package/src/subsystems/Security/ManagedVault.service/index.ts +12 -0
- package/src/subsystems/Security/SecureConnector.class.ts +110 -0
- package/src/subsystems/Security/Vault.service/Vault.helper.ts +30 -0
- package/src/subsystems/Security/Vault.service/VaultConnector.ts +26 -0
- package/src/subsystems/Security/Vault.service/connectors/HashicorpVault.class.ts +46 -0
- package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +166 -0
- package/src/subsystems/Security/Vault.service/connectors/NullVault.class.ts +54 -0
- package/src/subsystems/Security/Vault.service/connectors/SecretsManager.class.ts +140 -0
- package/src/subsystems/Security/Vault.service/index.ts +12 -0
- package/src/types/ACL.types.ts +104 -0
- package/src/types/AWS.types.ts +9 -0
- package/src/types/Agent.types.ts +61 -0
- package/src/types/AgentLogger.types.ts +17 -0
- package/src/types/Cache.types.ts +1 -0
- package/src/types/Common.types.ts +3 -0
- package/src/types/LLM.types.ts +419 -0
- package/src/types/Redis.types.ts +8 -0
- package/src/types/SRE.types.ts +64 -0
- package/src/types/Security.types.ts +18 -0
- package/src/types/Storage.types.ts +5 -0
- package/src/types/VectorDB.types.ts +86 -0
- package/src/utils/base64.utils.ts +275 -0
- package/src/utils/cli.utils.ts +68 -0
- package/src/utils/data.utils.ts +263 -0
- package/src/utils/date-time.utils.ts +22 -0
- package/src/utils/general.utils.ts +238 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/numbers.utils.ts +13 -0
- package/src/utils/oauth.utils.ts +35 -0
- package/src/utils/string.utils.ts +414 -0
- package/src/utils/url.utils.ts +19 -0
- package/src/utils/validation.utils.ts +74 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
3
|
+
import { FunctionCallingMode, ModelParams, GenerateContentRequest } from '@google/generative-ai';
|
|
4
|
+
|
|
5
|
+
import { BinaryInput } from '@sre/helpers/BinaryInput.helper';
|
|
6
|
+
import { type models } from '@sre/LLMManager/models';
|
|
7
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
8
|
+
import { ConverseCommandInput } from '@aws-sdk/client-bedrock-runtime';
|
|
9
|
+
|
|
10
|
+
export type LLMProvider = Extract<(typeof models)[keyof typeof models], { llm: string }>['llm'] | 'VertexAI' | 'Bedrock';
|
|
11
|
+
export type LLMModel = keyof typeof models;
|
|
12
|
+
export type LLMModelInfo = (typeof models)[LLMModel];
|
|
13
|
+
|
|
14
|
+
// Google Service Account Credentials Interface
|
|
15
|
+
export interface VertexAICredentials {
|
|
16
|
+
type: 'service_account';
|
|
17
|
+
project_id: string;
|
|
18
|
+
private_key_id: string;
|
|
19
|
+
private_key: string;
|
|
20
|
+
client_email: string;
|
|
21
|
+
client_id: string;
|
|
22
|
+
auth_uri: string;
|
|
23
|
+
token_uri: string;
|
|
24
|
+
auth_provider_x509_cert_url: string;
|
|
25
|
+
client_x509_cert_url: string;
|
|
26
|
+
universe_domain?: string; // Optional, defaults to "googleapis.com"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Basic LLM Credentials Interface
|
|
30
|
+
export interface BasicCredentials {
|
|
31
|
+
apiKey: string;
|
|
32
|
+
isUserKey: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// AWS Bedrock Credentials Interface
|
|
36
|
+
export interface BedrockCredentials {
|
|
37
|
+
accessKeyId: string;
|
|
38
|
+
secretAccessKey: string;
|
|
39
|
+
sessionToken?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Union type for all credential types
|
|
43
|
+
export type ILLMConnectorCredentials = BasicCredentials | BedrockCredentials | VertexAICredentials;
|
|
44
|
+
|
|
45
|
+
export type TOpenAIResponseToolChoice = OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceTypes | OpenAI.Responses.ToolChoiceFunction;
|
|
46
|
+
export type TLLMToolChoice = OpenAI.ChatCompletionToolChoiceOption;
|
|
47
|
+
|
|
48
|
+
export type TLLMParams = {
|
|
49
|
+
model: TLLMModel | string;
|
|
50
|
+
modelEntryName?: string; // for usage reporting
|
|
51
|
+
credentials?: ILLMConnectorCredentials;
|
|
52
|
+
|
|
53
|
+
prompt?: string;
|
|
54
|
+
messages?: any[]; // TODO [Forhad]: apply proper typing
|
|
55
|
+
temperature?: number;
|
|
56
|
+
maxTokens?: number;
|
|
57
|
+
stopSequences?: string[];
|
|
58
|
+
topP?: number;
|
|
59
|
+
topK?: number;
|
|
60
|
+
frequencyPenalty?: number;
|
|
61
|
+
presencePenalty?: number;
|
|
62
|
+
responseFormat?: any; // TODO [Forhad]: apply proper typing
|
|
63
|
+
modelInfo?: TCustomLLMModel;
|
|
64
|
+
files?: BinaryInput[];
|
|
65
|
+
toolsConfig?: {
|
|
66
|
+
tools?: OpenAI.ChatCompletionTool[] | OpenAI.Responses.Tool[] | OpenAI.Responses.WebSearchTool[];
|
|
67
|
+
tool_choice?: TLLMToolChoice;
|
|
68
|
+
};
|
|
69
|
+
baseURL?: string;
|
|
70
|
+
|
|
71
|
+
size?: OpenAI.Images.ImageGenerateParams['size'] | OpenAI.Images.ImageEditParams['size']; // for image generation and image editing
|
|
72
|
+
quality?: 'standard' | 'hd'; // for image generation
|
|
73
|
+
n?: number; // for image generation
|
|
74
|
+
style?: 'vivid' | 'natural'; // for image generation
|
|
75
|
+
|
|
76
|
+
cache?: boolean;
|
|
77
|
+
agentId?: string;
|
|
78
|
+
teamId?: string;
|
|
79
|
+
thinking?: {
|
|
80
|
+
// for Anthropic
|
|
81
|
+
type: 'enabled' | 'disabled';
|
|
82
|
+
budget_tokens: number;
|
|
83
|
+
};
|
|
84
|
+
maxThinkingTokens?: number;
|
|
85
|
+
|
|
86
|
+
// #region Search
|
|
87
|
+
useWebSearch?: boolean;
|
|
88
|
+
webSearchContextSize?: 'high' | 'medium' | 'low';
|
|
89
|
+
webSearchCity?: string;
|
|
90
|
+
webSearchCountry?: string;
|
|
91
|
+
webSearchRegion?: string;
|
|
92
|
+
webSearchTimezone?: string;
|
|
93
|
+
// #endregion
|
|
94
|
+
|
|
95
|
+
useReasoning?: boolean;
|
|
96
|
+
|
|
97
|
+
isUserKey?: boolean;
|
|
98
|
+
capabilities?: {
|
|
99
|
+
search?: boolean;
|
|
100
|
+
reasoning?: boolean;
|
|
101
|
+
imageGeneration?: boolean;
|
|
102
|
+
imageEditing?: boolean;
|
|
103
|
+
};
|
|
104
|
+
max_output_tokens?: number;
|
|
105
|
+
|
|
106
|
+
abortSignal?: AbortSignal;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type TLLMParamsV2 = {
|
|
110
|
+
model: string;
|
|
111
|
+
modelEntryName: string;
|
|
112
|
+
messages: any[];
|
|
113
|
+
toolsConfig?: {
|
|
114
|
+
tools?: OpenAI.Responses.Tool[];
|
|
115
|
+
tool_choice?: OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceTypes | OpenAI.Responses.ToolChoiceFunction;
|
|
116
|
+
};
|
|
117
|
+
baseURL?: string;
|
|
118
|
+
stream?: boolean;
|
|
119
|
+
responseFormat?: any;
|
|
120
|
+
credentials?: {
|
|
121
|
+
apiKey?: string;
|
|
122
|
+
isUserKey?: boolean;
|
|
123
|
+
};
|
|
124
|
+
max_output_tokens?: number;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
top_p?: number;
|
|
127
|
+
top_k?: number;
|
|
128
|
+
frequency_penalty?: number;
|
|
129
|
+
presence_penalty?: number;
|
|
130
|
+
teamId?: string;
|
|
131
|
+
files?: BinaryInput[];
|
|
132
|
+
|
|
133
|
+
// #region Search
|
|
134
|
+
useWebSearch?: boolean;
|
|
135
|
+
webSearchContextSize?: 'high' | 'medium' | 'low';
|
|
136
|
+
webSearchCity?: string;
|
|
137
|
+
webSearchCountry?: string;
|
|
138
|
+
webSearchRegion?: string;
|
|
139
|
+
webSearchTimezone?: string;
|
|
140
|
+
// #endregion
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type TLLMConnectorParams = Omit<TLLMParams, 'model'> & {
|
|
144
|
+
//the LLMConnector accepts a model object that we extract the model info from instead of relying on the internal models list
|
|
145
|
+
model: string | TLLMModel | TCustomLLMModel;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type TLLMModelEntry = {
|
|
149
|
+
llm: string;
|
|
150
|
+
tokens?: number;
|
|
151
|
+
completionTokens?: number;
|
|
152
|
+
enabled?: boolean;
|
|
153
|
+
components?: string[];
|
|
154
|
+
alias?: string;
|
|
155
|
+
tags?: string[];
|
|
156
|
+
keyOptions?: {
|
|
157
|
+
tokens: number;
|
|
158
|
+
completionTokens: number;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export enum TLLMCredentials {
|
|
163
|
+
Vault = 'vault',
|
|
164
|
+
Internal = 'internal',
|
|
165
|
+
BedrockVault = 'bedrock_vault',
|
|
166
|
+
VertexAIVault = 'vertexai_vault',
|
|
167
|
+
None = 'none',
|
|
168
|
+
}
|
|
169
|
+
export type TLLMModel = {
|
|
170
|
+
llm?: string;
|
|
171
|
+
isCustomLLM?: boolean;
|
|
172
|
+
modelId?: string;
|
|
173
|
+
tokens?: number;
|
|
174
|
+
completionTokens?: number;
|
|
175
|
+
components?: string[];
|
|
176
|
+
tags?: string[];
|
|
177
|
+
label?: string;
|
|
178
|
+
provider?: LLMProvider;
|
|
179
|
+
features?: string[];
|
|
180
|
+
enabled?: boolean;
|
|
181
|
+
alias?: string;
|
|
182
|
+
baseURL?: string;
|
|
183
|
+
keyOptions?: {
|
|
184
|
+
tokens: number;
|
|
185
|
+
completionTokens: number;
|
|
186
|
+
};
|
|
187
|
+
credentials?: TLLMCredentials;
|
|
188
|
+
|
|
189
|
+
//models can come with predefined params
|
|
190
|
+
//this can also be used to pass a preconfigured model object
|
|
191
|
+
params?: TLLMParams;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
// #region [ Handle extendable LLM Providers ] ================================================
|
|
195
|
+
export const BuiltinLLMProviders = {
|
|
196
|
+
Echo: 'Echo',
|
|
197
|
+
OpenAI: 'OpenAI',
|
|
198
|
+
DeepSeek: 'DeepSeek',
|
|
199
|
+
GoogleAI: 'GoogleAI',
|
|
200
|
+
Anthropic: 'Anthropic',
|
|
201
|
+
Groq: 'Groq',
|
|
202
|
+
TogetherAI: 'TogetherAI',
|
|
203
|
+
Bedrock: 'Bedrock',
|
|
204
|
+
VertexAI: 'VertexAI',
|
|
205
|
+
xAI: 'xAI',
|
|
206
|
+
Perplexity: 'Perplexity',
|
|
207
|
+
} as const;
|
|
208
|
+
// Base provider type
|
|
209
|
+
export type TBuiltinLLMProvider = (typeof BuiltinLLMProviders)[keyof typeof BuiltinLLMProviders];
|
|
210
|
+
|
|
211
|
+
// Extensible interface for custom providers
|
|
212
|
+
export interface ILLMProviders {}
|
|
213
|
+
// Combined provider type that can be extended
|
|
214
|
+
export type TLLMProvider = TBuiltinLLMProvider | keyof ILLMProviders;
|
|
215
|
+
|
|
216
|
+
// For backward compatibility, export the built-in providers as enum-like object
|
|
217
|
+
export const TLLMProvider = BuiltinLLMProviders;
|
|
218
|
+
|
|
219
|
+
// #endregion
|
|
220
|
+
|
|
221
|
+
export type TBedrockSettings = {
|
|
222
|
+
keyIDName: string;
|
|
223
|
+
secretKeyName: string;
|
|
224
|
+
sessionKeyName: string;
|
|
225
|
+
};
|
|
226
|
+
export type TVertexAISettings = {
|
|
227
|
+
projectId: string;
|
|
228
|
+
credentialsName: string;
|
|
229
|
+
jsonCredentialsName: string;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export type TCustomLLMModel = TLLMModel & {
|
|
233
|
+
name: string;
|
|
234
|
+
settings: {
|
|
235
|
+
foundationModel: string;
|
|
236
|
+
customModel: string;
|
|
237
|
+
region: string;
|
|
238
|
+
} & (TBedrockSettings | TVertexAISettings);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
//#region === LLM Tools ===========================
|
|
242
|
+
export type ToolData = {
|
|
243
|
+
index: number;
|
|
244
|
+
id: string;
|
|
245
|
+
type: string;
|
|
246
|
+
name: string;
|
|
247
|
+
arguments: string | Record<string, any>;
|
|
248
|
+
role: 'user' | 'tool' | 'assistant';
|
|
249
|
+
result?: string; // result string from the used tool
|
|
250
|
+
function?: any;
|
|
251
|
+
error?: string; // for Bedrock
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export interface AnthropicToolDefinition {
|
|
255
|
+
name: string;
|
|
256
|
+
description: string;
|
|
257
|
+
input_schema: {
|
|
258
|
+
type: 'object';
|
|
259
|
+
properties: Record<string, unknown>;
|
|
260
|
+
required: string[];
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export type ToolDefinition = OpenAI.ChatCompletionTool | AnthropicToolDefinition;
|
|
264
|
+
export type ToolChoice = OpenAI.ChatCompletionToolChoiceOption | FunctionCallingMode;
|
|
265
|
+
|
|
266
|
+
export interface ToolsConfig {
|
|
267
|
+
tools?: ToolDefinition[];
|
|
268
|
+
tool_choice?: ToolChoice;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
//#endregion
|
|
272
|
+
|
|
273
|
+
export enum TLLMMessageRole {
|
|
274
|
+
User = 'user',
|
|
275
|
+
Assistant = 'assistant',
|
|
276
|
+
System = 'system',
|
|
277
|
+
Model = 'model',
|
|
278
|
+
Tool = 'tool',
|
|
279
|
+
Function = 'function',
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type TLLMMessageBlock = {
|
|
283
|
+
role: TLLMMessageRole;
|
|
284
|
+
content?:
|
|
285
|
+
| string
|
|
286
|
+
| { text: string }[]
|
|
287
|
+
| Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam>;
|
|
288
|
+
parts?: {
|
|
289
|
+
text?: string;
|
|
290
|
+
functionCall?: { name: string; args: string };
|
|
291
|
+
functionResponse?: { name: string; response: { name: string; content: string } };
|
|
292
|
+
}[]; // for Google Vertex AI
|
|
293
|
+
tool_calls?: ToolData[];
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export type TLLMToolResultMessageBlock = TLLMMessageBlock & {
|
|
297
|
+
tool_call_id?: string; // for tool result message block of OpenAI
|
|
298
|
+
name?: string; // for tool result message block of OpenAI
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export type GenerateImageConfig = {
|
|
302
|
+
size?: '256x256' | '512x512' | '1024x1024' | '1792x1024' | '1024x1792';
|
|
303
|
+
quality?: 'standard' | 'hd';
|
|
304
|
+
model: string;
|
|
305
|
+
style?: 'vivid' | 'natural';
|
|
306
|
+
n?: number;
|
|
307
|
+
response_format?: 'url' | 'b64_json';
|
|
308
|
+
prompt?: string;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// ! Deprecated
|
|
312
|
+
export type TLLMInputMessage = {
|
|
313
|
+
role: string;
|
|
314
|
+
content?: string | { text: string }[];
|
|
315
|
+
parts?: { text: string }[]; // * 'part' is for Google Vertex AI
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export interface ILLMContextStore {
|
|
319
|
+
save(messages: any[]): Promise<void>;
|
|
320
|
+
load(count?: number): Promise<any[]>;
|
|
321
|
+
getMessage(message_id: string): Promise<any[]>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export enum APIKeySource {
|
|
325
|
+
Smyth = 'smyth-managed',
|
|
326
|
+
User = 'user-managed',
|
|
327
|
+
Custom = 'custom',
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface SmythLLMUsage {
|
|
331
|
+
sourceId: string;
|
|
332
|
+
input_tokens: number;
|
|
333
|
+
input_tokens_cache_write: number;
|
|
334
|
+
input_tokens_cache_read: number;
|
|
335
|
+
output_tokens: number;
|
|
336
|
+
keySource?: APIKeySource;
|
|
337
|
+
agentId: string;
|
|
338
|
+
teamId: string;
|
|
339
|
+
tier?: string; // for Google AI
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export interface SmythTaskUsage {
|
|
343
|
+
sourceId: string;
|
|
344
|
+
number: number;
|
|
345
|
+
agentId: string;
|
|
346
|
+
teamId: string;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export type TLLMModelsList = {
|
|
350
|
+
[key: string]: TLLMModel | TCustomLLMModel;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export enum TLLMEvent {
|
|
354
|
+
/** Generated response chunks */
|
|
355
|
+
Content = 'content',
|
|
356
|
+
/** Thinking blocks/chunks */
|
|
357
|
+
Thinking = 'thinking',
|
|
358
|
+
/** End of the response */
|
|
359
|
+
End = 'end',
|
|
360
|
+
/** Error */
|
|
361
|
+
Error = 'error',
|
|
362
|
+
/** Tool information : emitted by the LLM determines the next tool call */
|
|
363
|
+
ToolInfo = 'toolInfo',
|
|
364
|
+
/** Tool call : emitted before the tool call */
|
|
365
|
+
ToolCall = 'toolCall',
|
|
366
|
+
/** Tool result : emitted after the tool call */
|
|
367
|
+
ToolResult = 'toolResult',
|
|
368
|
+
/** Tokens usage information */
|
|
369
|
+
Usage = 'usage',
|
|
370
|
+
/** Interrupted : emitted when the response is interrupted before completion */
|
|
371
|
+
Interrupted = 'interrupted',
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface ILLMRequestContext {
|
|
375
|
+
modelEntryName: string;
|
|
376
|
+
agentId: string;
|
|
377
|
+
teamId: string;
|
|
378
|
+
isUserKey: boolean;
|
|
379
|
+
hasFiles?: boolean;
|
|
380
|
+
modelInfo: TCustomLLMModel | TLLMModel;
|
|
381
|
+
credentials: ILLMConnectorCredentials;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Generic interface that can be extended by specific providers
|
|
385
|
+
export interface ILLMRequestFuncParams<TBody = any> {
|
|
386
|
+
acRequest: AccessRequest;
|
|
387
|
+
body: TBody;
|
|
388
|
+
context: ILLMRequestContext;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// For future providers, you can add similar types:
|
|
392
|
+
// export type TAnthropicRequestBody = Anthropic.MessageCreateParams | Anthropic.MessageStreamParams;
|
|
393
|
+
// export type IAnthropicRequestFuncParams = ILLMRequestFuncParams<TAnthropicRequestBody>;
|
|
394
|
+
|
|
395
|
+
export type TLLMChatResponse = {
|
|
396
|
+
content: string;
|
|
397
|
+
finishReason: string;
|
|
398
|
+
thinkingContent?: string;
|
|
399
|
+
usage?: any;
|
|
400
|
+
useTool?: boolean;
|
|
401
|
+
toolsData?: ToolData[];
|
|
402
|
+
message?: OpenAI.ChatCompletionMessageParam | Anthropic.MessageParam;
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
export type TOpenAIRequestBody =
|
|
406
|
+
| OpenAI.ChatCompletionCreateParamsNonStreaming
|
|
407
|
+
| OpenAI.ChatCompletionCreateParamsStreaming
|
|
408
|
+
| OpenAI.ChatCompletionCreateParams
|
|
409
|
+
| OpenAI.Responses.ResponseCreateParams
|
|
410
|
+
| OpenAI.Responses.ResponseCreateParamsNonStreaming
|
|
411
|
+
| OpenAI.Responses.ResponseCreateParamsStreaming
|
|
412
|
+
| OpenAI.Images.ImageGenerateParams
|
|
413
|
+
| OpenAI.Images.ImageEditParams;
|
|
414
|
+
|
|
415
|
+
export type TAnthropicRequestBody = Anthropic.MessageCreateParamsNonStreaming;
|
|
416
|
+
|
|
417
|
+
export type TGoogleAIRequestBody = ModelParams & { messages: string | TLLMMessageBlock[] | GenerateContentRequest };
|
|
418
|
+
|
|
419
|
+
export type TLLMRequestBody = TOpenAIRequestBody | TAnthropicRequestBody | TGoogleAIRequestBody | ConverseCommandInput;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AgentDataService } from '@sre/AgentManager/AgentData.service';
|
|
2
|
+
import { CLIService } from '@sre/IO/CLI.service';
|
|
3
|
+
import { NKVService } from '@sre/IO/NKV.service';
|
|
4
|
+
import { StorageService } from '@sre/IO/Storage.service';
|
|
5
|
+
import { VectorDBService } from '@sre/IO/VectorDB.service';
|
|
6
|
+
import { LLMService } from '@sre/LLMManager/LLM.service';
|
|
7
|
+
import { CacheService } from '@sre/MemoryManager/Cache.service';
|
|
8
|
+
import { AccountService } from '@sre/Security/Account.service';
|
|
9
|
+
import { VaultService } from '@sre/Security/Vault.service';
|
|
10
|
+
import { RouterService } from '@sre/IO/Router.service';
|
|
11
|
+
import { ManagedVaultService } from '@sre/Security/ManagedVault.service';
|
|
12
|
+
import { LogService } from '@sre/IO/Log.service';
|
|
13
|
+
import { ComponentService } from '@sre/AgentManager/Component.service';
|
|
14
|
+
import { ModelsProviderService } from '@sre/LLMManager/ModelsProvider.service';
|
|
15
|
+
import { CodeService } from '@sre/ComputeManager/Code.service';
|
|
16
|
+
|
|
17
|
+
export type TServiceRegistry = {
|
|
18
|
+
Storage?: StorageService;
|
|
19
|
+
VectorDB?: VectorDBService;
|
|
20
|
+
Cache?: CacheService;
|
|
21
|
+
LLM?: LLMService;
|
|
22
|
+
Vault?: VaultService;
|
|
23
|
+
Account?: AccountService;
|
|
24
|
+
AgentData?: AgentDataService;
|
|
25
|
+
CLI?: CLIService;
|
|
26
|
+
NKV?: NKVService;
|
|
27
|
+
Router?: RouterService;
|
|
28
|
+
ManagedVault?: ManagedVaultService;
|
|
29
|
+
Log?: LogService;
|
|
30
|
+
Component?: ComponentService;
|
|
31
|
+
ModelsProvider?: ModelsProviderService;
|
|
32
|
+
Code?: CodeService;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export enum TConnectorService {
|
|
36
|
+
Storage = 'Storage',
|
|
37
|
+
VectorDB = 'VectorDB',
|
|
38
|
+
Cache = 'Cache',
|
|
39
|
+
LLM = 'LLM',
|
|
40
|
+
Vault = 'Vault',
|
|
41
|
+
Account = 'Account',
|
|
42
|
+
AgentData = 'AgentData',
|
|
43
|
+
CLI = 'CLI',
|
|
44
|
+
NKV = 'NKV',
|
|
45
|
+
Router = 'Router',
|
|
46
|
+
ManagedVault = 'ManagedVault',
|
|
47
|
+
Log = 'Log',
|
|
48
|
+
Component = 'Component',
|
|
49
|
+
ModelsProvider = 'ModelsProvider',
|
|
50
|
+
Code = 'Code',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SREConnectorConfig = {
|
|
54
|
+
Connector: string;
|
|
55
|
+
Id?: string;
|
|
56
|
+
Default?: boolean;
|
|
57
|
+
Settings?: {
|
|
58
|
+
[hashedOwnerKey: string]: any;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type SREConfig = {
|
|
63
|
+
[key in TConnectorService]?: SREConnectorConfig[] | SREConnectorConfig | {};
|
|
64
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type OAuthConfig = {
|
|
2
|
+
oAuthAppID: string;
|
|
3
|
+
oAuthAppSecret: string;
|
|
4
|
+
oAuthBaseUrl: string;
|
|
5
|
+
oAuthResource?: string;
|
|
6
|
+
oAuthScope?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type EncryptionSettings = {
|
|
10
|
+
encryption?: {
|
|
11
|
+
key?: string;
|
|
12
|
+
algorithm?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type SmythConfigs = {
|
|
17
|
+
smythAPIBaseUrl: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export type VectorDBMetadata = {
|
|
2
|
+
namespaceId: string;
|
|
3
|
+
datasourceId: string;
|
|
4
|
+
datasourceLabel: string;
|
|
5
|
+
acl: string;
|
|
6
|
+
user_metadata?: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type VectorsResultData = {
|
|
11
|
+
id: string;
|
|
12
|
+
score?: number;
|
|
13
|
+
values: number[];
|
|
14
|
+
text: string;
|
|
15
|
+
metadata?: Record<string, any>;
|
|
16
|
+
}[];
|
|
17
|
+
|
|
18
|
+
export interface NsKnownMetadata {
|
|
19
|
+
isOnCustomStorage?: boolean;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// export interface IDocument<Metadata extends Record<string, any> = Record<string, any>> {
|
|
24
|
+
// text: string;
|
|
25
|
+
// metadata: Metadata;
|
|
26
|
+
// id?: string;
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
export interface QueryOptions {
|
|
30
|
+
topK?: number;
|
|
31
|
+
includeMetadata?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface SourceTypes {
|
|
35
|
+
Vector: number[];
|
|
36
|
+
Text: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Source = SourceTypes[keyof SourceTypes];
|
|
40
|
+
|
|
41
|
+
// export interface IVectorDataSourceDto<T extends Source> {
|
|
42
|
+
// id: string;
|
|
43
|
+
// // source: url | text | document | vector;
|
|
44
|
+
// source: T;
|
|
45
|
+
// metadata?: VectorDBMetadata;
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
export interface IVectorDataSourceDto {
|
|
49
|
+
id: string;
|
|
50
|
+
source: number[] | string;
|
|
51
|
+
metadata?: VectorDBMetadata;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IStorageVectorDataSource {
|
|
55
|
+
namespaceId: string;
|
|
56
|
+
// indexName: string;
|
|
57
|
+
name: string;
|
|
58
|
+
metadata: string;
|
|
59
|
+
text?: string;
|
|
60
|
+
vectorIds: string[];
|
|
61
|
+
id: string;
|
|
62
|
+
candidateId: string;
|
|
63
|
+
candidateRole: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface IStorageVectorNamespace {
|
|
67
|
+
namespace: string;
|
|
68
|
+
displayName: string;
|
|
69
|
+
metadata?: StorageVectorNamespaceMetadata;
|
|
70
|
+
candidateId: string;
|
|
71
|
+
candidateRole: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type StorageVectorNamespaceMetadata = Partial<PineconeNamespaceMetadata> & { isOnCustomStorage?: boolean } & { [key: string]: any };
|
|
75
|
+
export interface PineconeNamespaceMetadata {
|
|
76
|
+
indexName: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface DatasourceDto {
|
|
80
|
+
text: string;
|
|
81
|
+
metadata?: Record<string, string> & { smyth_metadata?: Record<string, string> };
|
|
82
|
+
chunkSize?: number;
|
|
83
|
+
chunkOverlap?: number;
|
|
84
|
+
label?: string;
|
|
85
|
+
id?: string;
|
|
86
|
+
}
|