@smythos/sre 1.5.0
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/README.md +135 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Components/APICall/APICall.class.d.ts +34 -0
- package/dist/types/Components/APICall/AccessTokenManager.d.ts +17 -0
- package/dist/types/Components/APICall/ArrayBufferResponse.helper.d.ts +3 -0
- package/dist/types/Components/APICall/OAuth.helper.d.ts +10 -0
- package/dist/types/Components/APICall/mimeTypeCategories.d.ts +6 -0
- package/dist/types/Components/APICall/parseData.d.ts +5 -0
- package/dist/types/Components/APICall/parseHeaders.d.ts +3 -0
- package/dist/types/Components/APICall/parseProxy.d.ts +4 -0
- package/dist/types/Components/APICall/parseUrl.d.ts +7 -0
- package/dist/types/Components/APIEndpoint.class.d.ts +16 -0
- package/dist/types/Components/APIOutput.class.d.ts +15 -0
- package/dist/types/Components/AgentPlugin.class.d.ts +16 -0
- package/dist/types/Components/Async.class.d.ts +17 -0
- package/dist/types/Components/Await.class.d.ts +22 -0
- package/dist/types/Components/Classifier.class.d.ts +33 -0
- package/dist/types/Components/Component.class.d.ts +35 -0
- package/dist/types/Components/ComponentHost.class.d.ts +12 -0
- package/dist/types/Components/DataSourceCleaner.class.d.ts +19 -0
- package/dist/types/Components/DataSourceIndexer.class.d.ts +25 -0
- package/dist/types/Components/DataSourceLookup.class.d.ts +17 -0
- package/dist/types/Components/FEncDec.class.d.ts +17 -0
- package/dist/types/Components/FHash.class.d.ts +17 -0
- package/dist/types/Components/FSign.class.d.ts +18 -0
- package/dist/types/Components/FSleep.class.d.ts +19 -0
- package/dist/types/Components/FTimestamp.class.d.ts +19 -0
- package/dist/types/Components/FileStore.class.d.ts +11 -0
- package/dist/types/Components/ForEach.class.d.ts +16 -0
- package/dist/types/Components/GPTPlugin.class.d.ts +17 -0
- package/dist/types/Components/GenAILLM.class.d.ts +130 -0
- package/dist/types/Components/HuggingFace.class.d.ts +17 -0
- package/dist/types/Components/Image/imageSettings.config.d.ts +21 -0
- package/dist/types/Components/ImageGenerator.class.d.ts +17 -0
- package/dist/types/Components/JSONFilter.class.d.ts +13 -0
- package/dist/types/Components/LLMAssistant.class.d.ts +19 -0
- package/dist/types/Components/LogicAND.class.d.ts +7 -0
- package/dist/types/Components/LogicAtLeast.class.d.ts +9 -0
- package/dist/types/Components/LogicAtMost.class.d.ts +9 -0
- package/dist/types/Components/LogicOR.class.d.ts +7 -0
- package/dist/types/Components/LogicXOR.class.d.ts +7 -0
- package/dist/types/Components/MCPClient.class.d.ts +17 -0
- package/dist/types/Components/PromptGenerator.class.d.ts +19 -0
- package/dist/types/Components/ScrapflyWebScrape.class.d.ts +30 -0
- package/dist/types/Components/TavilyWebSearch.class.d.ts +31 -0
- package/dist/types/Components/index.d.ts +74 -0
- package/dist/types/Core/AgentProcess.helper.d.ts +36 -0
- package/dist/types/Core/Connector.class.d.ts +34 -0
- package/dist/types/Core/ConnectorsService.d.ts +64 -0
- package/dist/types/Core/DummyConnector.d.ts +4 -0
- package/dist/types/Core/HookService.d.ts +27 -0
- package/dist/types/Core/SmythRuntime.class.d.ts +28 -0
- package/dist/types/Core/SystemEvents.d.ts +12 -0
- package/dist/types/Core/boot.d.ts +1 -0
- package/dist/types/config.d.ts +11 -0
- package/dist/types/constants.d.ts +79 -0
- package/dist/types/helpers/BinaryInput.helper.d.ts +33 -0
- package/dist/types/helpers/Conversation.helper.d.ts +85 -0
- package/dist/types/helpers/JsonContent.helper.d.ts +16 -0
- package/dist/types/helpers/LocalCache.helper.d.ts +14 -0
- package/dist/types/helpers/Log.helper.d.ts +22 -0
- package/dist/types/helpers/OpenApiParser.helper.d.ts +10 -0
- package/dist/types/helpers/S3Cache.helper.d.ts +9 -0
- package/dist/types/helpers/SmythURI.helper.d.ts +3 -0
- package/dist/types/helpers/TemplateString.helper.d.ts +71 -0
- package/dist/types/helpers/TypeChecker.helper.d.ts +10 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/subsystems/AgentManager/Agent.class.d.ts +78 -0
- package/dist/types/subsystems/AgentManager/Agent.helper.d.ts +1 -0
- package/dist/types/subsystems/AgentManager/AgentData.service/AgentDataConnector.d.ts +33 -0
- package/dist/types/subsystems/AgentManager/AgentData.service/connectors/CLIAgentDataConnector.class.d.ts +20 -0
- package/dist/types/subsystems/AgentManager/AgentData.service/connectors/LocalAgentDataConnector.class.d.ts +48 -0
- package/dist/types/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.d.ts +19 -0
- package/dist/types/subsystems/AgentManager/AgentData.service/index.d.ts +4 -0
- package/dist/types/subsystems/AgentManager/AgentLogger.class.d.ts +11 -0
- package/dist/types/subsystems/AgentManager/AgentRequest.class.d.ts +15 -0
- package/dist/types/subsystems/AgentManager/AgentRuntime.class.d.ts +91 -0
- package/dist/types/subsystems/AgentManager/AgentSSE.class.d.ts +40 -0
- package/dist/types/subsystems/AgentManager/AgentSettings.class.d.ts +12 -0
- package/dist/types/subsystems/AgentManager/Component.service/ComponentConnector.d.ts +17 -0
- package/dist/types/subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class.d.ts +14 -0
- package/dist/types/subsystems/AgentManager/Component.service/index.d.ts +4 -0
- package/dist/types/subsystems/AgentManager/EmbodimentSettings.class.d.ts +8 -0
- package/dist/types/subsystems/AgentManager/ForkedAgent.class.d.ts +15 -0
- package/dist/types/subsystems/AgentManager/OSResourceMonitor.d.ts +2 -0
- package/dist/types/subsystems/ComputeManager/Code.service/CodeConnector.d.ts +58 -0
- package/dist/types/subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class.d.ts +15 -0
- package/dist/types/subsystems/ComputeManager/Code.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/CLI.service/CLIConnector.d.ts +21 -0
- package/dist/types/subsystems/IO/CLI.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/Log.service/LogConnector.d.ts +17 -0
- package/dist/types/subsystems/IO/Log.service/connectors/ConsoleLog.class.d.ts +12 -0
- package/dist/types/subsystems/IO/Log.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/NKV.service/NKVConnector.d.ts +33 -0
- package/dist/types/subsystems/IO/NKV.service/connectors/NKVRAM.class.d.ts +43 -0
- package/dist/types/subsystems/IO/NKV.service/connectors/NKVRedis.class.d.ts +27 -0
- package/dist/types/subsystems/IO/NKV.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/Router.service/RouterConnector.d.ts +11 -0
- package/dist/types/subsystems/IO/Router.service/connectors/ExpressRouter.class.d.ts +21 -0
- package/dist/types/subsystems/IO/Router.service/connectors/NullRouter.class.d.ts +12 -0
- package/dist/types/subsystems/IO/Router.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/Storage.service/SmythFS.class.d.ts +49 -0
- package/dist/types/subsystems/IO/Storage.service/StorageConnector.d.ts +30 -0
- package/dist/types/subsystems/IO/Storage.service/connectors/LocalStorage.class.d.ts +58 -0
- package/dist/types/subsystems/IO/Storage.service/connectors/S3Storage.class.d.ts +53 -0
- package/dist/types/subsystems/IO/Storage.service/index.d.ts +4 -0
- package/dist/types/subsystems/IO/VectorDB.service/VectorDBConnector.d.ts +41 -0
- package/dist/types/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.d.ts +49 -0
- package/dist/types/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.d.ts +50 -0
- package/dist/types/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.d.ts +52 -0
- package/dist/types/subsystems/IO/VectorDB.service/embed/BaseEmbedding.d.ts +53 -0
- package/dist/types/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.d.ts +16 -0
- package/dist/types/subsystems/IO/VectorDB.service/embed/index.d.ts +16 -0
- package/dist/types/subsystems/IO/VectorDB.service/index.d.ts +4 -0
- package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +125 -0
- package/dist/types/subsystems/LLMManager/LLM.inference.d.ts +36 -0
- package/dist/types/subsystems/LLMManager/LLM.service/LLMConnector.d.ts +62 -0
- package/dist/types/subsystems/LLMManager/LLM.service/LLMCredentials.helper.d.ts +3 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.d.ts +68 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.d.ts +46 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Echo.class.d.ts +18 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +57 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Groq.class.d.ts +55 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.d.ts +92 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +86 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.d.ts +38 -0
- package/dist/types/subsystems/LLMManager/LLM.service/index.d.ts +5 -0
- package/dist/types/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.d.ts +36 -0
- package/dist/types/subsystems/LLMManager/ModelsProvider.service/connectors/SmythModelsProvider.class.d.ts +39 -0
- package/dist/types/subsystems/LLMManager/ModelsProvider.service/index.d.ts +4 -0
- package/dist/types/subsystems/LLMManager/custom-models.d.ts +785 -0
- package/dist/types/subsystems/LLMManager/models.d.ts +2629 -0
- package/dist/types/subsystems/LLMManager/paramMappings.d.ts +69 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/CacheConnector.d.ts +41 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/connectors/LocalStorageCache.class.d.ts +33 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/connectors/RAMCache.class.d.ts +31 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.d.ts +33 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/connectors/S3Cache.class.d.ts +38 -0
- package/dist/types/subsystems/MemoryManager/Cache.service/index.d.ts +4 -0
- package/dist/types/subsystems/MemoryManager/LLMCache.d.ts +27 -0
- package/dist/types/subsystems/MemoryManager/LLMContext.d.ts +25 -0
- package/dist/types/subsystems/MemoryManager/RuntimeContext.d.ts +50 -0
- package/dist/types/subsystems/Security/AccessControl/ACL.class.d.ts +29 -0
- package/dist/types/subsystems/Security/AccessControl/AccessCandidate.class.d.ts +21 -0
- package/dist/types/subsystems/Security/AccessControl/AccessRequest.class.d.ts +13 -0
- package/dist/types/subsystems/Security/Account.service/AccountConnector.d.ts +27 -0
- package/dist/types/subsystems/Security/Account.service/connectors/AWSAccount.class.d.ts +19 -0
- package/dist/types/subsystems/Security/Account.service/connectors/DummyAccount.class.d.ts +19 -0
- package/dist/types/subsystems/Security/Account.service/connectors/JSONFileAccount.class.d.ts +25 -0
- package/dist/types/subsystems/Security/Account.service/index.d.ts +4 -0
- package/dist/types/subsystems/Security/Credentials.helper.d.ts +16 -0
- package/dist/types/subsystems/Security/ManagedVault.service/ManagedVaultConnector.d.ts +23 -0
- package/dist/types/subsystems/Security/ManagedVault.service/connectors/NullManagedVault.class.d.ts +14 -0
- package/dist/types/subsystems/Security/ManagedVault.service/connectors/SecretManagerManagedVault.d.ts +22 -0
- package/dist/types/subsystems/Security/ManagedVault.service/index.d.ts +4 -0
- package/dist/types/subsystems/Security/SecureConnector.class.d.ts +13 -0
- package/dist/types/subsystems/Security/Vault.service/Vault.helper.d.ts +5 -0
- package/dist/types/subsystems/Security/Vault.service/VaultConnector.d.ts +17 -0
- package/dist/types/subsystems/Security/Vault.service/connectors/HashicorpVault.class.d.ts +13 -0
- package/dist/types/subsystems/Security/Vault.service/connectors/JSONFileVault.class.d.ts +23 -0
- package/dist/types/subsystems/Security/Vault.service/connectors/NullVault.class.d.ts +16 -0
- package/dist/types/subsystems/Security/Vault.service/connectors/SecretsManager.class.d.ts +20 -0
- package/dist/types/subsystems/Security/Vault.service/index.d.ts +4 -0
- package/dist/types/types/ACL.types.d.ts +83 -0
- package/dist/types/types/AWS.types.d.ts +7 -0
- package/dist/types/types/Agent.types.d.ts +52 -0
- package/dist/types/types/AgentLogger.types.d.ts +16 -0
- package/dist/types/types/Cache.types.d.ts +1 -0
- package/dist/types/types/Common.types.d.ts +3 -0
- package/dist/types/types/LLM.types.d.ts +365 -0
- package/dist/types/types/Redis.types.d.ts +6 -0
- package/dist/types/types/SRE.types.d.ts +60 -0
- package/dist/types/types/Security.types.d.ts +16 -0
- package/dist/types/types/Storage.types.d.ts +3 -0
- package/dist/types/types/VectorDB.types.d.ts +66 -0
- package/dist/types/utils/base64.utils.d.ts +86 -0
- package/dist/types/utils/cli.utils.d.ts +20 -0
- package/dist/types/utils/data.utils.d.ts +17 -0
- package/dist/types/utils/date-time.utils.d.ts +3 -0
- package/dist/types/utils/general.utils.d.ts +75 -0
- package/dist/types/utils/index.d.ts +9 -0
- package/dist/types/utils/numbers.utils.d.ts +2 -0
- package/dist/types/utils/oauth.utils.d.ts +7 -0
- package/dist/types/utils/string.utils.d.ts +28 -0
- package/dist/types/utils/url.utils.d.ts +1 -0
- package/dist/types/utils/validation.utils.d.ts +25 -0
- package/package.json +117 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { StorageConnector } from '@sre/IO/Storage.service/StorageConnector';
|
|
2
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
3
|
+
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
4
|
+
import { StorageData, StorageMetadata } from '@sre/types/Storage.types';
|
|
5
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
6
|
+
export type LocalStorageConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* The folder to use for the local storage.
|
|
9
|
+
*
|
|
10
|
+
* If not provided, the default folder will be used.
|
|
11
|
+
* The default folder is ~/.smyth/storage
|
|
12
|
+
*/
|
|
13
|
+
folder?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class LocalStorage extends StorageConnector {
|
|
16
|
+
protected _settings?: LocalStorageConfig;
|
|
17
|
+
name: string;
|
|
18
|
+
private folder;
|
|
19
|
+
private storagePrefix;
|
|
20
|
+
private metadataPrefix;
|
|
21
|
+
private isInitialized;
|
|
22
|
+
constructor(_settings?: LocalStorageConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Reads an object from the local storage.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} resourceId - The key of the object to be read.
|
|
27
|
+
* @returns {Promise<any>} - A promise that resolves with the object data.
|
|
28
|
+
*/
|
|
29
|
+
read(acRequest: AccessRequest, resourceId: string): Promise<string>;
|
|
30
|
+
getMetadata(acRequest: AccessRequest, resourceId: string): Promise<StorageMetadata | undefined>;
|
|
31
|
+
setMetadata(acRequest: AccessRequest, resourceId: string, metadata: StorageMetadata): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Writes an object to the local storage.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} resourceId - The key of the object to be written.
|
|
36
|
+
* @param {any} value - The value of the object to be written.
|
|
37
|
+
* @param {Metadata} metadata - Optional metadata to be associated with the object.
|
|
38
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been written.
|
|
39
|
+
*/
|
|
40
|
+
write(acRequest: AccessRequest, resourceId: string, value: StorageData, acl?: IACL, metadata?: StorageMetadata): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes an object from the local storage.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} resourceId - The key of the object to be deleted.
|
|
45
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been deleted.
|
|
46
|
+
*/
|
|
47
|
+
delete(acRequest: AccessRequest, resourceId: string): Promise<void>;
|
|
48
|
+
exists(acRequest: AccessRequest, resourceId: string): Promise<boolean>;
|
|
49
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
50
|
+
getACL(acRequest: AccessRequest, resourceId: string): Promise<ACL | undefined>;
|
|
51
|
+
setACL(acRequest: AccessRequest, resourceId: string, acl: IACL): Promise<void>;
|
|
52
|
+
expire(acRequest: AccessRequest, resourceId: string, ttl: number): Promise<void>;
|
|
53
|
+
private initialize;
|
|
54
|
+
private getStorageFilePath;
|
|
55
|
+
private getMetadataFilePath;
|
|
56
|
+
private serializeMetadata;
|
|
57
|
+
private deserializeMetadata;
|
|
58
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StorageConnector } from '@sre/IO/Storage.service/StorageConnector';
|
|
2
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
3
|
+
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
4
|
+
import { AWSRegionConfig, AWSCredentials } from '@sre/types/AWS.types';
|
|
5
|
+
import { StorageData, StorageMetadata } from '@sre/types/Storage.types';
|
|
6
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
7
|
+
export type S3Config = AWSCredentials & AWSRegionConfig & {
|
|
8
|
+
bucket: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class S3Storage extends StorageConnector {
|
|
11
|
+
protected _settings: S3Config;
|
|
12
|
+
name: string;
|
|
13
|
+
private client;
|
|
14
|
+
private bucket;
|
|
15
|
+
private isInitialized;
|
|
16
|
+
constructor(_settings: S3Config);
|
|
17
|
+
private initialize;
|
|
18
|
+
/**
|
|
19
|
+
* Reads an object from the S3 bucket.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} resourceId - The key of the object to be read.
|
|
22
|
+
* @returns {Promise<any>} - A promise that resolves with the object data.
|
|
23
|
+
*/
|
|
24
|
+
read(acRequest: AccessRequest, resourceId: string): Promise<Buffer<ArrayBufferLike>>;
|
|
25
|
+
getMetadata(acRequest: AccessRequest, resourceId: string): Promise<StorageMetadata | undefined>;
|
|
26
|
+
setMetadata(acRequest: AccessRequest, resourceId: string, metadata: StorageMetadata): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Writes an object to the S3 bucket.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} resourceId - The key of the object to be written.
|
|
31
|
+
* @param {any} value - The value of the object to be written.
|
|
32
|
+
* @param {Metadata} metadata - Optional metadata to be associated with the object.
|
|
33
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been written.
|
|
34
|
+
*/
|
|
35
|
+
write(acRequest: AccessRequest, resourceId: string, value: StorageData, acl?: IACL, metadata?: StorageMetadata): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Deletes an object from the S3 bucket.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} resourceId - The key of the object to be deleted.
|
|
40
|
+
* @returns {Promise<void>} - A promise that resolves when the object has been deleted.
|
|
41
|
+
*/
|
|
42
|
+
delete(acRequest: AccessRequest, resourceId: string): Promise<void>;
|
|
43
|
+
exists(acRequest: AccessRequest, resourceId: string): Promise<boolean>;
|
|
44
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
45
|
+
getACL(acRequest: AccessRequest, resourceId: string): Promise<ACL | undefined>;
|
|
46
|
+
setACL(acRequest: AccessRequest, resourceId: string, acl: IACL): Promise<void>;
|
|
47
|
+
expire(acRequest: AccessRequest, resourceId: string, ttl: number): Promise<void>;
|
|
48
|
+
private migrateMetadata;
|
|
49
|
+
private serializeS3Metadata;
|
|
50
|
+
private deserializeS3Metadata;
|
|
51
|
+
private getS3Metadata;
|
|
52
|
+
private setS3Metadata;
|
|
53
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
3
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
4
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
5
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
6
|
+
import { DatasourceDto, IStorageVectorDataSource, IVectorDataSourceDto, QueryOptions, VectorsResultData } from '@sre/types/VectorDB.types';
|
|
7
|
+
export type DeleteFilterOptions = {
|
|
8
|
+
datasourceId?: string;
|
|
9
|
+
};
|
|
10
|
+
export type DeleteTarget = string | string[] | DeleteFilterOptions;
|
|
11
|
+
export interface IVectorDBRequest {
|
|
12
|
+
search(namespace: string, query: string | number[], options?: QueryOptions): Promise<VectorsResultData>;
|
|
13
|
+
createDatasource(namespace: string, datasource: DatasourceDto): Promise<IStorageVectorDataSource>;
|
|
14
|
+
deleteDatasource(namespace: string, datasourceId: string): Promise<void>;
|
|
15
|
+
listDatasources(namespace: string): Promise<IStorageVectorDataSource[]>;
|
|
16
|
+
getDatasource(namespace: string, datasourceId: string): Promise<IStorageVectorDataSource>;
|
|
17
|
+
createNamespace(namespace: string, metadata?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
21
|
+
namespaceExists(namespace: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export declare abstract class VectorDBConnector extends SecureConnector<IVectorDBRequest> {
|
|
24
|
+
protected readonly USER_METADATA_KEY = "user_metadata";
|
|
25
|
+
abstract id: string;
|
|
26
|
+
abstract getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
27
|
+
requester(candidate: AccessCandidate): IVectorDBRequest;
|
|
28
|
+
protected abstract search(acRequest: AccessRequest, namespace: string, query: string | number[], options: QueryOptions): Promise<VectorsResultData>;
|
|
29
|
+
protected abstract insert(acRequest: AccessRequest, namespace: string, source: IVectorDataSourceDto | IVectorDataSourceDto[]): Promise<string[]>;
|
|
30
|
+
protected abstract delete(acRequest: AccessRequest, namespace: string, deleteTarget: DeleteTarget): Promise<void>;
|
|
31
|
+
protected abstract createDatasource(acRequest: AccessRequest, namespace: string, datasource: DatasourceDto): Promise<IStorageVectorDataSource>;
|
|
32
|
+
protected abstract deleteDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<void>;
|
|
33
|
+
protected abstract listDatasources(acRequest: AccessRequest, namespace: string): Promise<IStorageVectorDataSource[]>;
|
|
34
|
+
protected abstract getDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<IStorageVectorDataSource | undefined>;
|
|
35
|
+
protected abstract createNamespace(acRequest: AccessRequest, namespace: string, metadata?: {
|
|
36
|
+
[key: string]: any;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
protected abstract deleteNamespace(acRequest: AccessRequest, namespace: string): Promise<void>;
|
|
39
|
+
protected abstract namespaceExists(acRequest: AccessRequest, namespace: string): Promise<boolean>;
|
|
40
|
+
constructNsName(candidate: AccessCandidate, name: string): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
3
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
4
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
5
|
+
import { DeleteTarget, VectorDBConnector } from '../VectorDBConnector';
|
|
6
|
+
import { DatasourceDto, IStorageVectorDataSource, IVectorDataSourceDto, QueryOptions, VectorsResultData } from '@sre/types/VectorDB.types';
|
|
7
|
+
import { BaseEmbedding, TEmbeddings } from '../embed/BaseEmbedding';
|
|
8
|
+
export type IMilvusCredentials = {
|
|
9
|
+
address: string;
|
|
10
|
+
token: string;
|
|
11
|
+
} | {
|
|
12
|
+
address: string;
|
|
13
|
+
user: string;
|
|
14
|
+
password: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
};
|
|
17
|
+
export type MilvusConfig = {
|
|
18
|
+
credentials: IMilvusCredentials;
|
|
19
|
+
embeddings: TEmbeddings;
|
|
20
|
+
};
|
|
21
|
+
export declare class MilvusVectorDB extends VectorDBConnector {
|
|
22
|
+
protected _settings: MilvusConfig;
|
|
23
|
+
name: string;
|
|
24
|
+
id: string;
|
|
25
|
+
private client;
|
|
26
|
+
private cache;
|
|
27
|
+
private accountConnector;
|
|
28
|
+
embedder: BaseEmbedding;
|
|
29
|
+
private SCHEMA_DEFINITION;
|
|
30
|
+
private INDEX_PARAMS;
|
|
31
|
+
constructor(_settings: MilvusConfig);
|
|
32
|
+
protected createNamespace(acRequest: AccessRequest, namespace: string, metadata?: {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
protected namespaceExists(acRequest: AccessRequest, namespace: string): Promise<boolean>;
|
|
36
|
+
protected deleteNamespace(acRequest: AccessRequest, namespace: string): Promise<void>;
|
|
37
|
+
protected search(acRequest: AccessRequest, namespace: string, query: string | number[], options?: QueryOptions): Promise<VectorsResultData>;
|
|
38
|
+
protected insert(acRequest: AccessRequest, namespace: string, sourceWrapper: IVectorDataSourceDto | IVectorDataSourceDto[]): Promise<string[]>;
|
|
39
|
+
protected delete(acRequest: AccessRequest, namespace: string, deleteTarget: DeleteTarget): Promise<void>;
|
|
40
|
+
protected createDatasource(acRequest: AccessRequest, namespace: string, datasource: DatasourceDto): Promise<IStorageVectorDataSource>;
|
|
41
|
+
protected deleteDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<void>;
|
|
42
|
+
protected listDatasources(acRequest: AccessRequest, namespace: string): Promise<IStorageVectorDataSource[]>;
|
|
43
|
+
protected getDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<IStorageVectorDataSource | undefined>;
|
|
44
|
+
private setACL;
|
|
45
|
+
private getACL;
|
|
46
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
47
|
+
private deleteACL;
|
|
48
|
+
constructNsName(candidate: AccessCandidate, name: string): string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
3
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
4
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
5
|
+
import { VectorDBConnector } from '../VectorDBConnector';
|
|
6
|
+
import { DatasourceDto, IStorageVectorDataSource, IVectorDataSourceDto, QueryOptions, VectorsResultData } from '@sre/types/VectorDB.types';
|
|
7
|
+
import { BaseEmbedding, TEmbeddings } from '../embed/BaseEmbedding';
|
|
8
|
+
export type PineconeConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* The Pinecone API key
|
|
11
|
+
*/
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/**
|
|
14
|
+
* The Pinecone index name
|
|
15
|
+
*/
|
|
16
|
+
indexName: string;
|
|
17
|
+
/**
|
|
18
|
+
* The embeddings model to use
|
|
19
|
+
*/
|
|
20
|
+
embeddings: TEmbeddings;
|
|
21
|
+
};
|
|
22
|
+
export declare class PineconeVectorDB extends VectorDBConnector {
|
|
23
|
+
protected _settings: PineconeConfig;
|
|
24
|
+
name: string;
|
|
25
|
+
id: string;
|
|
26
|
+
private client;
|
|
27
|
+
private indexName;
|
|
28
|
+
private cache;
|
|
29
|
+
private accountConnector;
|
|
30
|
+
private nkvConnector;
|
|
31
|
+
embedder: BaseEmbedding;
|
|
32
|
+
constructor(_settings: PineconeConfig);
|
|
33
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
34
|
+
protected createNamespace(acRequest: AccessRequest, namespace: string, metadata?: {
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
protected namespaceExists(acRequest: AccessRequest, namespace: string): Promise<boolean>;
|
|
38
|
+
protected deleteNamespace(acRequest: AccessRequest, namespace: string): Promise<void>;
|
|
39
|
+
protected search(acRequest: AccessRequest, namespace: string, query: string | number[], options?: QueryOptions): Promise<VectorsResultData>;
|
|
40
|
+
protected insert(acRequest: AccessRequest, namespace: string, sourceWrapper: IVectorDataSourceDto | IVectorDataSourceDto[]): Promise<string[]>;
|
|
41
|
+
protected delete(acRequest: AccessRequest, namespace: string, id: string | string[]): Promise<void>;
|
|
42
|
+
protected createDatasource(acRequest: AccessRequest, namespace: string, datasource: DatasourceDto): Promise<IStorageVectorDataSource>;
|
|
43
|
+
protected deleteDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<void>;
|
|
44
|
+
protected listDatasources(acRequest: AccessRequest, namespace: string): Promise<IStorageVectorDataSource[]>;
|
|
45
|
+
protected getDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<IStorageVectorDataSource>;
|
|
46
|
+
private setACL;
|
|
47
|
+
private getACL;
|
|
48
|
+
private deleteACL;
|
|
49
|
+
constructNsName(candidate: AccessCandidate, name: string): string;
|
|
50
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
3
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
4
|
+
import { VectorDBConnector } from '../VectorDBConnector';
|
|
5
|
+
import { DatasourceDto, IStorageVectorDataSource, IStorageVectorNamespace, IVectorDataSourceDto, QueryOptions, VectorsResultData } from '@sre/types/VectorDB.types';
|
|
6
|
+
import { BaseEmbedding, TEmbeddings } from '../embed/BaseEmbedding';
|
|
7
|
+
export type RAMVectorDBConfig = {
|
|
8
|
+
embeddings: TEmbeddings;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* RAM Vector Database - stores everything in memory
|
|
12
|
+
* Data structure:
|
|
13
|
+
* - vectors: namespace -> VectorData[]
|
|
14
|
+
* - namespaces: namespace -> IStorageVectorNamespace
|
|
15
|
+
* - datasources: namespace -> datasourceId -> IStorageVectorDataSource
|
|
16
|
+
* - acls: resourceId -> IACL
|
|
17
|
+
*/
|
|
18
|
+
export declare class RAMVectorDB extends VectorDBConnector {
|
|
19
|
+
protected _settings: RAMVectorDBConfig;
|
|
20
|
+
name: string;
|
|
21
|
+
id: string;
|
|
22
|
+
private accountConnector;
|
|
23
|
+
private vectors;
|
|
24
|
+
private namespaces;
|
|
25
|
+
private datasources;
|
|
26
|
+
private acls;
|
|
27
|
+
embedder: BaseEmbedding;
|
|
28
|
+
constructor(_settings: RAMVectorDBConfig);
|
|
29
|
+
getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
30
|
+
protected createNamespace(acRequest: AccessRequest, namespace: string, metadata?: {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
protected namespaceExists(acRequest: AccessRequest, namespace: string): Promise<boolean>;
|
|
34
|
+
protected getNamespace(acRequest: AccessRequest, namespace: string): Promise<IStorageVectorNamespace>;
|
|
35
|
+
protected listNamespaces(acRequest: AccessRequest): Promise<IStorageVectorNamespace[]>;
|
|
36
|
+
protected deleteNamespace(acRequest: AccessRequest, namespace: string): Promise<void>;
|
|
37
|
+
protected search(acRequest: AccessRequest, namespace: string, query: string | number[], options?: QueryOptions): Promise<VectorsResultData>;
|
|
38
|
+
protected insert(acRequest: AccessRequest, namespace: string, sourceWrapper: IVectorDataSourceDto | IVectorDataSourceDto[]): Promise<string[]>;
|
|
39
|
+
protected delete(acRequest: AccessRequest, namespace: string, id: string | string[]): Promise<void>;
|
|
40
|
+
protected createDatasource(acRequest: AccessRequest, namespace: string, datasource: DatasourceDto): Promise<IStorageVectorDataSource>;
|
|
41
|
+
protected deleteDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<void>;
|
|
42
|
+
protected listDatasources(acRequest: AccessRequest, namespace: string): Promise<IStorageVectorDataSource[]>;
|
|
43
|
+
protected getDatasource(acRequest: AccessRequest, namespace: string, datasourceId: string): Promise<IStorageVectorDataSource>;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate cosine similarity between two vectors
|
|
46
|
+
*/
|
|
47
|
+
private cosineSimilarity;
|
|
48
|
+
/**
|
|
49
|
+
* Split text into chunks with overlap
|
|
50
|
+
*/
|
|
51
|
+
private splitTextIntoChunks;
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IVectorDataSourceDto, Source } from '@sre/types/VectorDB.types';
|
|
2
|
+
import { SupportedProviders, SupportedModels } from './index';
|
|
3
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
4
|
+
export type TEmbeddings = {
|
|
5
|
+
provider: SupportedProviders;
|
|
6
|
+
model: SupportedModels[SupportedProviders];
|
|
7
|
+
dimensions?: number;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
chunkSize?: number;
|
|
10
|
+
stripNewLines?: boolean;
|
|
11
|
+
maxConcurrency?: number;
|
|
12
|
+
credentials?: {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type SupportedSources = 'text' | 'vector' | 'url';
|
|
17
|
+
export declare abstract class BaseEmbedding {
|
|
18
|
+
model: string;
|
|
19
|
+
modelName: string;
|
|
20
|
+
chunkSize: number;
|
|
21
|
+
stripNewLines: boolean;
|
|
22
|
+
dimensions?: number;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
maxConcurrency?: number;
|
|
25
|
+
constructor(fields?: Partial<TEmbeddings>);
|
|
26
|
+
/**
|
|
27
|
+
* Embed multiple texts and return their vector representations
|
|
28
|
+
*/
|
|
29
|
+
abstract embedTexts(texts: string[], candidate: AccessCandidate): Promise<number[][]>;
|
|
30
|
+
/**
|
|
31
|
+
* Embed a single text and return its vector representation
|
|
32
|
+
*/
|
|
33
|
+
abstract embedText(text: string, candidate: AccessCandidate): Promise<number[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Utility method to chunk arrays into smaller batches
|
|
36
|
+
*/
|
|
37
|
+
protected chunkArr<T>(arr: T[], sizePerChunk: number): T[][];
|
|
38
|
+
/**
|
|
39
|
+
* Utility method to process multiple texts based on stripNewLines setting
|
|
40
|
+
*/
|
|
41
|
+
protected processTexts(texts: string[]): string[];
|
|
42
|
+
detectSourceType(source: Source): SupportedSources | 'unknown';
|
|
43
|
+
transformSource(source: IVectorDataSourceDto[], sourceType: SupportedSources, candidate: AccessCandidate): IVectorDataSourceDto[] | Promise<{
|
|
44
|
+
source: number[];
|
|
45
|
+
metadata: {
|
|
46
|
+
text: string;
|
|
47
|
+
user?: string;
|
|
48
|
+
};
|
|
49
|
+
id: string;
|
|
50
|
+
}[]>;
|
|
51
|
+
get dummyVector(): number[];
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import OpenAI, { type ClientOptions, OpenAI as OpenAIClient } from 'openai';
|
|
2
|
+
import { BaseEmbedding, TEmbeddings } from './BaseEmbedding';
|
|
3
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
4
|
+
export declare class OpenAIEmbeds extends BaseEmbedding {
|
|
5
|
+
private settings?;
|
|
6
|
+
protected client: OpenAIClient;
|
|
7
|
+
protected clientConfig: ClientOptions;
|
|
8
|
+
static models: string[];
|
|
9
|
+
canSpecifyDimensions: boolean;
|
|
10
|
+
constructor(settings?: Partial<TEmbeddings>);
|
|
11
|
+
embedTexts(texts: string[], candidate: AccessCandidate): Promise<number[][]>;
|
|
12
|
+
embedText(text: string, candidate: AccessCandidate): Promise<number[]>;
|
|
13
|
+
protected embed(request: OpenAIClient.EmbeddingCreateParams, candidate: AccessCandidate): Promise<OpenAI.Embeddings.CreateEmbeddingResponse & {
|
|
14
|
+
_request_id?: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpenAIEmbeds } from './OpenAIEmbedding';
|
|
2
|
+
import { TEmbeddings } from './BaseEmbedding';
|
|
3
|
+
declare const supportedProviders: {
|
|
4
|
+
readonly OpenAI: {
|
|
5
|
+
readonly embedder: typeof OpenAIEmbeds;
|
|
6
|
+
readonly models: string[];
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export type SupportedProviders = keyof typeof supportedProviders;
|
|
10
|
+
export type SupportedModels = {
|
|
11
|
+
[K in SupportedProviders]: (typeof supportedProviders)[K]['models'][number];
|
|
12
|
+
};
|
|
13
|
+
export declare class EmbeddingsFactory {
|
|
14
|
+
static create(provider: SupportedProviders, config: TEmbeddings): OpenAIEmbeds;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type TLLMMessageBlock } from '@sre/types/LLM.types';
|
|
2
|
+
export declare class LLMHelper {
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the given array of messages contains a system message.
|
|
5
|
+
*
|
|
6
|
+
* @param {any} messages - The array of messages to check.
|
|
7
|
+
* @returns {boolean} True if a system message is found, false otherwise.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const messages = [
|
|
11
|
+
* { role: 'user', content: 'Hello' },
|
|
12
|
+
* { role: 'system', content: 'You are a helpful assistant' }
|
|
13
|
+
* ];
|
|
14
|
+
* const hasSystem = LLMHelper.hasSystemMessage(messages);
|
|
15
|
+
* console.log(hasSystem); // true
|
|
16
|
+
*/
|
|
17
|
+
static hasSystemMessage(messages: any): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Separates system messages from other messages in an array of LLM message blocks.
|
|
20
|
+
*
|
|
21
|
+
* @param {TLLMMessageBlock[]} messages - The array of message blocks to process.
|
|
22
|
+
* @returns {Object} An object containing the system message (if any) and an array of other messages.
|
|
23
|
+
* @property {TLLMMessageBlock | {}} systemMessage - The first system message found, or an empty object if none.
|
|
24
|
+
* @property {TLLMMessageBlock[]} otherMessages - An array of all non-system messages.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const messages = [
|
|
28
|
+
* { role: 'system', content: 'You are a helpful assistant' },
|
|
29
|
+
* { role: 'user', content: 'Hello' },
|
|
30
|
+
* { role: 'assistant', content: 'Hi there!' }
|
|
31
|
+
* ];
|
|
32
|
+
* const { systemMessage, otherMessages } = LLMHelper.separateSystemMessages(messages);
|
|
33
|
+
* console.log(systemMessage); // { role: 'system', content: 'You are a helpful assistant' }
|
|
34
|
+
* console.log(otherMessages); // [{ role: 'user', content: 'Hello' }, { role: 'assistant', content: 'Hi there!' }]
|
|
35
|
+
*/
|
|
36
|
+
static separateSystemMessages(messages: TLLMMessageBlock[]): {
|
|
37
|
+
systemMessage: TLLMMessageBlock | {};
|
|
38
|
+
otherMessages: TLLMMessageBlock[];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Counts the total number of tokens in a vision prompt, including both text and image tokens.
|
|
42
|
+
*
|
|
43
|
+
* @param {any} prompt - The vision prompt object containing text and image items.
|
|
44
|
+
* @returns {Promise<number>} A promise that resolves to the total number of tokens in the prompt.
|
|
45
|
+
*
|
|
46
|
+
* @description
|
|
47
|
+
* This method processes a vision prompt by:
|
|
48
|
+
* 1. Counting tokens in the text portion of the prompt.
|
|
49
|
+
* 2. Calculating tokens for each image in the prompt based on its dimensions.
|
|
50
|
+
* 3. Summing up text and image tokens to get the total token count.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const prompt = [
|
|
54
|
+
* { type: 'text', text: 'Describe this image:' },
|
|
55
|
+
* { type: 'image_url', image_url: { url: 'https://example.com/image.jpg' } }
|
|
56
|
+
* ];
|
|
57
|
+
* const tokenCount = await countVisionPromptTokens(prompt);
|
|
58
|
+
* console.log(tokenCount); // e.g., 150
|
|
59
|
+
*/
|
|
60
|
+
static countVisionPromptTokens(prompt: any): Promise<number>;
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves the dimensions (width and height) of an image from a given URL or base64 encoded string.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} imageUrl - The URL or base64 encoded string of the image.
|
|
65
|
+
* @returns {Promise<{ width: number; height: number }>} A promise that resolves to an object containing the width and height of the image.
|
|
66
|
+
* @throws {Error} If the provided imageUrl is invalid or if there's an error retrieving the image dimensions.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Using a URL
|
|
70
|
+
* const dimensions = await getImageDimensions('https://example.com/image.jpg');
|
|
71
|
+
* console.log(dimensions); // { width: 800, height: 600 }
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Using a base64 encoded string
|
|
75
|
+
* const dimensions = await getImageDimensions('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==');
|
|
76
|
+
* console.log(dimensions); // { width: 1, height: 1 }
|
|
77
|
+
*/
|
|
78
|
+
static getImageDimensions(imageUrl: string): Promise<{
|
|
79
|
+
width: number;
|
|
80
|
+
height: number;
|
|
81
|
+
}>;
|
|
82
|
+
/**
|
|
83
|
+
* Calculates the number of tokens required to process an image based on its dimensions and detail mode.
|
|
84
|
+
*
|
|
85
|
+
* @param {number} width - The width of the image in pixels.
|
|
86
|
+
* @param {number} height - The height of the image in pixels.
|
|
87
|
+
* @param {string} detailMode - The detail mode for processing the image. Defaults to 'auto'.
|
|
88
|
+
* @returns {number} The number of tokens required to process the image.
|
|
89
|
+
*
|
|
90
|
+
* @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.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* const tokenCount = countImageTokens(1024, 768);
|
|
103
|
+
* console.log(tokenCount); // Outputs the calculated token count
|
|
104
|
+
*/
|
|
105
|
+
static countImageTokens(width: number, height: number, detailMode?: string): number;
|
|
106
|
+
/**
|
|
107
|
+
* Removes duplicate user messages from the beginning and end of the messages array.
|
|
108
|
+
*
|
|
109
|
+
* This method checks if there are two consecutive user messages at the start or end of the array
|
|
110
|
+
*
|
|
111
|
+
* @param {Array<{ role: string; content: string }>} messages - The array of message objects to process.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const messages = [
|
|
115
|
+
* { role: 'user', content: 'Hello' },
|
|
116
|
+
* { role: 'user', content: 'Hello' },
|
|
117
|
+
* { role: 'assistant', content: 'Hi there!' }
|
|
118
|
+
* ];
|
|
119
|
+
* LLMHelper.removeDuplicateUserMessages(messages);
|
|
120
|
+
* console.log(messages); // [{ role: 'user', content: 'Hello' }, { role: 'assistant', content: 'Hi there!' }]
|
|
121
|
+
*
|
|
122
|
+
* @returns {TLLMMessageBlock[]} The modified array of message objects.
|
|
123
|
+
*/
|
|
124
|
+
static removeDuplicateUserMessages(messages: TLLMMessageBlock[]): TLLMMessageBlock[];
|
|
125
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
2
|
+
import { LLMConnector } from './LLM.service/LLMConnector';
|
|
3
|
+
import { TLLMModel } from '@sre/types/LLM.types';
|
|
4
|
+
import { IAgent } from '@sre/types/Agent.types';
|
|
5
|
+
import { TLLMParams } from '@sre/types/LLM.types';
|
|
6
|
+
type TPromptParams = {
|
|
7
|
+
query?: string;
|
|
8
|
+
contextWindow?: any[];
|
|
9
|
+
files?: any[];
|
|
10
|
+
params: TLLMParams;
|
|
11
|
+
};
|
|
12
|
+
export declare class LLMInference {
|
|
13
|
+
private model;
|
|
14
|
+
private llmConnector;
|
|
15
|
+
private modelProviderReq;
|
|
16
|
+
teamId?: string;
|
|
17
|
+
static getInstance(model: string | TLLMModel, candidate: AccessCandidate): Promise<LLMInference>;
|
|
18
|
+
static user(candidate: AccessCandidate): any;
|
|
19
|
+
get connector(): LLMConnector;
|
|
20
|
+
prompt({ query, contextWindow, files, params }: TPromptParams): Promise<any>;
|
|
21
|
+
promptStream({ query, contextWindow, files, params }: TPromptParams): Promise<any>;
|
|
22
|
+
imageGenRequest({ query, files, params }: TPromptParams): Promise<any>;
|
|
23
|
+
imageEditRequest({ query, files, params }: TPromptParams): Promise<any>;
|
|
24
|
+
streamRequest(params: any, agent: string | IAgent): Promise<any>;
|
|
25
|
+
multimodalStreamRequest(params: any, fileSources: any, agent: string | IAgent): Promise<any>;
|
|
26
|
+
multimodalStreamRequestLegacy(prompt: any, files: string[], config: any, agent: string | IAgent): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the context window for the given messages
|
|
29
|
+
* @param _messages - The messages to get the context window for (the messages are in smythos generic format)
|
|
30
|
+
* @param maxTokens - The maximum number of tokens to use for the context window
|
|
31
|
+
* @param maxOutputTokens - The maximum number of tokens to use for the output
|
|
32
|
+
* @returns The context window for the given messages
|
|
33
|
+
*/
|
|
34
|
+
getContextWindow(systemPrompt: string, _messages: any[], maxTokens: number, maxOutputTokens?: number): Promise<any[]>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Connector } from '@sre/Core/Connector.class';
|
|
2
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
3
|
+
import { TLLMConnectorParams, TLLMMessageBlock, TLLMToolResultMessageBlock, ToolData, APIKeySource, ILLMRequestFuncParams, TLLMChatResponse, TLLMRequestBody } from '@sre/types/LLM.types';
|
|
4
|
+
import EventEmitter from 'events';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
export interface ILLMConnectorRequest {
|
|
7
|
+
request(params: TLLMConnectorParams): Promise<TLLMChatResponse>;
|
|
8
|
+
streamRequest(params: TLLMConnectorParams): Promise<EventEmitter>;
|
|
9
|
+
imageGenRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
|
|
10
|
+
imageEditRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export declare class LLMStream extends Readable {
|
|
13
|
+
private dataQueue;
|
|
14
|
+
private toolsData;
|
|
15
|
+
private hasData;
|
|
16
|
+
isReading: boolean;
|
|
17
|
+
constructor(options?: any);
|
|
18
|
+
_read(size: any): void;
|
|
19
|
+
enqueueData(data: any): void;
|
|
20
|
+
endStream(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare abstract class LLMConnector extends Connector {
|
|
23
|
+
abstract name: string;
|
|
24
|
+
protected abstract request({ acRequest, body, context }: ILLMRequestFuncParams): Promise<TLLMChatResponse>;
|
|
25
|
+
protected abstract streamRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
|
|
26
|
+
protected abstract webSearchRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<EventEmitter>;
|
|
27
|
+
protected abstract reqBodyAdapter(params: TLLMConnectorParams): Promise<TLLMRequestBody>;
|
|
28
|
+
protected abstract reportUsage(usage: any, metadata: {
|
|
29
|
+
modelEntryName: string;
|
|
30
|
+
keySource: APIKeySource;
|
|
31
|
+
agentId: string;
|
|
32
|
+
teamId: string;
|
|
33
|
+
}): any;
|
|
34
|
+
protected imageGenRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
|
|
35
|
+
protected imageEditRequest({ acRequest, body, context }: ILLMRequestFuncParams): Promise<any>;
|
|
36
|
+
private vaultConnector;
|
|
37
|
+
requester(candidate: AccessCandidate): ILLMConnectorRequest;
|
|
38
|
+
enhancePrompt(prompt: string, config: any): string;
|
|
39
|
+
postProcess(response: string): any;
|
|
40
|
+
formatToolsConfig({ type, toolDefinitions, toolChoice }: {
|
|
41
|
+
type?: string;
|
|
42
|
+
toolDefinitions: any;
|
|
43
|
+
toolChoice?: string;
|
|
44
|
+
}): void;
|
|
45
|
+
transformToolMessageBlocks({ messageBlock, toolsData, }: {
|
|
46
|
+
messageBlock: TLLMMessageBlock;
|
|
47
|
+
toolsData: ToolData[];
|
|
48
|
+
}): TLLMToolResultMessageBlock[];
|
|
49
|
+
getConsistentMessages(messages: TLLMMessageBlock[]): TLLMMessageBlock[];
|
|
50
|
+
private prepareParams;
|
|
51
|
+
private formatParamValues;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the team ID associated with the given access candidate
|
|
54
|
+
* @param candidate - The access candidate whose team ID needs to be retrieved
|
|
55
|
+
* @returns Promise<string> - The unique identifier of the team associated with the candidate
|
|
56
|
+
* @throws {Error} If the Account Connector service is unavailable or cannot be accessed
|
|
57
|
+
* @throws {Error} If the candidate's team cannot be retrieved
|
|
58
|
+
* @private
|
|
59
|
+
* @remarks This method is used internally to determine the team context for custom LLM operations
|
|
60
|
+
*/
|
|
61
|
+
private getTeamId;
|
|
62
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
2
|
+
import { TCustomLLMModel, TLLMModel } from '@sre/types/LLM.types';
|
|
3
|
+
export declare function getLLMCredentials(candidate: AccessCandidate, modelInfo: TLLMModel | TCustomLLMModel): Promise<any>;
|