@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,52 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { EmbodimentSettings } from './EmbodimentSettings.class';
|
|
3
|
+
|
|
4
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
5
|
+
const console = Logger('AgentSettings');
|
|
6
|
+
|
|
7
|
+
export class AgentSettings {
|
|
8
|
+
private _settings: any;
|
|
9
|
+
public embodiments?: EmbodimentSettings;
|
|
10
|
+
private _ready = false;
|
|
11
|
+
|
|
12
|
+
constructor(agentId?) {
|
|
13
|
+
if (agentId) {
|
|
14
|
+
this.init(agentId);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async init(agentId) {
|
|
19
|
+
// Set embodiments before _settings allow us to use it immediately; otherwise, we need to wait both AgentSettings instance and EmbodimentSettings instance to be ready
|
|
20
|
+
this.embodiments = new EmbodimentSettings(agentId);
|
|
21
|
+
|
|
22
|
+
const agentDataConnector = ConnectorService.getAgentDataConnector();
|
|
23
|
+
this._settings = (await agentDataConnector.getAgentSettings(agentId).catch((e) => {})) || {};
|
|
24
|
+
this._ready = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public ready(maxWait = 10000) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const interval = setInterval(() => {
|
|
30
|
+
if (this._ready) {
|
|
31
|
+
clearInterval(interval);
|
|
32
|
+
resolve(true);
|
|
33
|
+
}
|
|
34
|
+
maxWait -= 100;
|
|
35
|
+
}, 100);
|
|
36
|
+
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
clearInterval(interval);
|
|
39
|
+
reject(false);
|
|
40
|
+
}, maxWait);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
public get(key: string) {
|
|
44
|
+
return this._settings?.[key] || '';
|
|
45
|
+
}
|
|
46
|
+
public set(key: string, value: any) {
|
|
47
|
+
this._settings[key] = value;
|
|
48
|
+
}
|
|
49
|
+
public has(key: string) {
|
|
50
|
+
return this._settings[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
3
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
4
|
+
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
5
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
6
|
+
|
|
7
|
+
export interface IComponentRequest {
|
|
8
|
+
register(componentName: string, componentInstance: any): Promise<void>;
|
|
9
|
+
get(componentName: string): Promise<any>;
|
|
10
|
+
getAll(): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export abstract class ComponentConnector extends SecureConnector {
|
|
14
|
+
public abstract getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
15
|
+
protected abstract register(acRequest: AccessRequest, componentName: string, componentInstance: any): Promise<void>;
|
|
16
|
+
protected abstract get(acRequest: AccessRequest, componentName: string): Promise<any>;
|
|
17
|
+
protected abstract getAll(acRequest: AccessRequest): Promise<any>;
|
|
18
|
+
|
|
19
|
+
public requester(candidate: AccessCandidate): IComponentRequest {
|
|
20
|
+
return {
|
|
21
|
+
register: async (componentName: string, componentInstance: any) => {
|
|
22
|
+
return await this.register(candidate.readRequest, componentName, componentInstance);
|
|
23
|
+
},
|
|
24
|
+
get: async (componentName: string) => {
|
|
25
|
+
return await this.get(candidate.readRequest, componentName);
|
|
26
|
+
},
|
|
27
|
+
getAll: async () => {
|
|
28
|
+
return await this.getAll(candidate.readRequest);
|
|
29
|
+
},
|
|
30
|
+
} as IComponentRequest;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
|
|
4
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
5
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
6
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
7
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
8
|
+
|
|
9
|
+
import { ComponentConnector } from '../ComponentConnector';
|
|
10
|
+
import { ComponentInstances } from '@sre/Components/index';
|
|
11
|
+
|
|
12
|
+
const console = Logger('LocalComponentConnector');
|
|
13
|
+
|
|
14
|
+
//TODO : future : Candidate specific components access : we can rely on the ACL to isolate the components per user/agent/team
|
|
15
|
+
export class LocalComponentConnector extends ComponentConnector {
|
|
16
|
+
public name: string = 'LocalComponentConnector';
|
|
17
|
+
private components: any = {};
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
this.init();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async init() {
|
|
26
|
+
for (const component in ComponentInstances) {
|
|
27
|
+
this.components[component] = ComponentInstances[component];
|
|
28
|
+
}
|
|
29
|
+
console.debug('Registering Components :', Object.keys(this.components).join(', '));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@SecureConnector.AccessControl
|
|
33
|
+
protected async register(acRequest: AccessRequest, componentName: string, componentInstance: any) {
|
|
34
|
+
this.components[componentName] = componentInstance;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@SecureConnector.AccessControl
|
|
38
|
+
protected async get(acRequest: AccessRequest, componentName: string) {
|
|
39
|
+
return this.components[componentName];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@SecureConnector.AccessControl
|
|
43
|
+
protected async getAll(acRequest: AccessRequest) {
|
|
44
|
+
return this.components;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
48
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
49
|
+
|
|
50
|
+
const teamId = await accountConnector.getCandidateTeam(candidate);
|
|
51
|
+
|
|
52
|
+
const acl = new ACL();
|
|
53
|
+
|
|
54
|
+
//Grant read access by default
|
|
55
|
+
acl.addAccess(TAccessRole.Team, teamId, TAccessLevel.Read).addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
56
|
+
|
|
57
|
+
return acl;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//==[ SRE: Component ]======================
|
|
2
|
+
|
|
3
|
+
import { ConnectorService, ConnectorServiceProvider } from '@sre/Core/ConnectorsService';
|
|
4
|
+
import { TConnectorService } from '@sre/types/SRE.types';
|
|
5
|
+
import { LocalComponentConnector } from './connectors/LocalComponentConnector.class';
|
|
6
|
+
|
|
7
|
+
export class ComponentService extends ConnectorServiceProvider {
|
|
8
|
+
public register() {
|
|
9
|
+
ConnectorService.register(TConnectorService.Component, 'LocalComponent', LocalComponentConnector);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
2
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
3
|
+
const console = Logger('EmbodimentSettings');
|
|
4
|
+
|
|
5
|
+
export class EmbodimentSettings {
|
|
6
|
+
private _embodiments: any;
|
|
7
|
+
private _ready = false;
|
|
8
|
+
|
|
9
|
+
constructor(agentId) {
|
|
10
|
+
this.init(agentId);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async init(agentId) {
|
|
14
|
+
const agentDataConnector = ConnectorService.getAgentDataConnector();
|
|
15
|
+
this._embodiments = await agentDataConnector.getAgentEmbodiments(agentId).catch((error) => []);
|
|
16
|
+
this._ready = true;
|
|
17
|
+
}
|
|
18
|
+
public ready(maxWait = 10000) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const interval = setInterval(() => {
|
|
21
|
+
if (this._ready) {
|
|
22
|
+
clearInterval(interval);
|
|
23
|
+
resolve(true);
|
|
24
|
+
}
|
|
25
|
+
maxWait -= 100;
|
|
26
|
+
}, 100);
|
|
27
|
+
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
clearInterval(interval);
|
|
30
|
+
reject(false);
|
|
31
|
+
}, maxWait);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public get(embodimentType: string, key?: string) {
|
|
36
|
+
if (!this._embodiments) return undefined;
|
|
37
|
+
const _embodiment = this._embodiments.find((embodiment: any) => embodiment.type?.toLowerCase() === embodimentType.toLowerCase());
|
|
38
|
+
|
|
39
|
+
if (!_embodiment) {
|
|
40
|
+
//console.error(`Error: No ${embodimentType} embodiment found for agent`);
|
|
41
|
+
}
|
|
42
|
+
if (key) {
|
|
43
|
+
return _embodiment?.properties?.[key];
|
|
44
|
+
}
|
|
45
|
+
return _embodiment?.properties;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { IAgent } from '@sre/types/Agent.types';
|
|
2
|
+
import { Agent } from './Agent.class';
|
|
3
|
+
import { AgentRequest } from './AgentRequest.class';
|
|
4
|
+
|
|
5
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
6
|
+
import { uid } from '@sre/utils';
|
|
7
|
+
const console = Logger('ForkedAgent');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This class creates a forked agent from a parent agent branch, it allows running a sub-branch of the parent agent asynchrounously by providing a separate agent context
|
|
11
|
+
* We use composition instead of inheritance to avoid circular dependencies between Agent and ForkedAgent
|
|
12
|
+
*/
|
|
13
|
+
export class ForkedAgent {
|
|
14
|
+
public agent: IAgent;
|
|
15
|
+
public get agentRequest() {
|
|
16
|
+
return this.agent.agentRequest;
|
|
17
|
+
}
|
|
18
|
+
public get components() {
|
|
19
|
+
return this.agent.components;
|
|
20
|
+
}
|
|
21
|
+
public get agentRuntime() {
|
|
22
|
+
return this.agent.agentRuntime;
|
|
23
|
+
}
|
|
24
|
+
public get jobID() {
|
|
25
|
+
return this.agent.jobID;
|
|
26
|
+
}
|
|
27
|
+
constructor(
|
|
28
|
+
private parent: IAgent,
|
|
29
|
+
componentId: string, //the component to fork from
|
|
30
|
+
) {
|
|
31
|
+
const data: any = fork(this.parent.data, componentId);
|
|
32
|
+
data.variables = JSON.parse(JSON.stringify(this.parent?.data?.variables || {})); //copy parent Agent variables to forked agent
|
|
33
|
+
data.teamId = this.parent.teamId;
|
|
34
|
+
//TODO : we need to create a default APIEndpoint bound to the root component if root component is not an APIEndpoint
|
|
35
|
+
const content = { name: this.parent.name, data, teamId: this.parent.teamId, debugSessionEnabled: false, version: this.parent.version };
|
|
36
|
+
|
|
37
|
+
const agentRequest = new AgentRequest(this.parent.agentRequest.req);
|
|
38
|
+
agentRequest.headers = []; //clear all headers from parent agent to conflict with child agent
|
|
39
|
+
|
|
40
|
+
this.agent = new Agent(this.parent.id, content, this.parent.agentSettings, agentRequest);
|
|
41
|
+
const JobID = componentId + '-' + uid();
|
|
42
|
+
this.agent.jobID = JobID;
|
|
43
|
+
//since the jobID was updated we need to create a different runtime
|
|
44
|
+
//FIXME : we need to find a way to avoid creating default runtime for forked agents, then replace it
|
|
45
|
+
//this.agent.agentRuntime = new AgentRuntime(this.agent);
|
|
46
|
+
|
|
47
|
+
//super(parent.id, content, agentRequest);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
process(path: string, input: any) {
|
|
51
|
+
return this.agent.process(path, input);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Helper function to clone a component and update its ID
|
|
56
|
+
function cloneComponent(component) {
|
|
57
|
+
const newComponent = JSON.parse(JSON.stringify(component));
|
|
58
|
+
newComponent.id = component.id;
|
|
59
|
+
return newComponent;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Helper function to recursively clone components and their connections
|
|
63
|
+
function cloneRecursively(componentData, currentID, newIDMap, clonedComponents, clonedConnections) {
|
|
64
|
+
const componentToClone = componentData.components.find((c) => c.id === currentID);
|
|
65
|
+
if (!componentToClone) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const clonedComponent = cloneComponent(componentToClone);
|
|
70
|
+
newIDMap[currentID] = clonedComponent.id; // Map old ID to new ID
|
|
71
|
+
clonedComponents.push(clonedComponent);
|
|
72
|
+
|
|
73
|
+
// Find all outgoing connections for the current component
|
|
74
|
+
const outgoingConnections = componentData.connections.filter((conn) => conn.sourceId === currentID);
|
|
75
|
+
outgoingConnections.forEach((conn) => {
|
|
76
|
+
// Clone the connection and update the IDs
|
|
77
|
+
const clonedConnection = JSON.parse(JSON.stringify(conn));
|
|
78
|
+
clonedConnection.sourceId = clonedComponent.id;
|
|
79
|
+
if (!newIDMap[conn.targetId]) {
|
|
80
|
+
// Recursively clone the connected component if it hasn't been cloned yet
|
|
81
|
+
cloneRecursively(componentData, conn.targetId, newIDMap, clonedComponents, clonedConnections);
|
|
82
|
+
}
|
|
83
|
+
clonedConnection.targetId = newIDMap[conn.targetId];
|
|
84
|
+
clonedConnections.push(clonedConnection);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function fork(componentData, componentID) {
|
|
89
|
+
const clonedComponents: any[] = [];
|
|
90
|
+
const clonedConnections: any[] = [];
|
|
91
|
+
const newIDMap = {}; // Map to keep track of old to new ID mappings
|
|
92
|
+
|
|
93
|
+
// Start the cloning process from the specified component ID
|
|
94
|
+
cloneRecursively(componentData, componentID, newIDMap, clonedComponents, clonedConnections);
|
|
95
|
+
|
|
96
|
+
const rootComponentData = clonedComponents.find((e) => e.id == componentID);
|
|
97
|
+
if (rootComponentData) {
|
|
98
|
+
if (rootComponentData.name !== 'APIEndpoint') {
|
|
99
|
+
const APIEndpointData: any = {
|
|
100
|
+
id: `${componentID}_ENDPOINT`,
|
|
101
|
+
name: 'APIEndpoint',
|
|
102
|
+
outputs: [
|
|
103
|
+
{ name: 'headers', index: 0, default: true },
|
|
104
|
+
{ name: 'body', index: 1, default: true },
|
|
105
|
+
{ name: 'query', index: 2, default: true },
|
|
106
|
+
],
|
|
107
|
+
inputs: [],
|
|
108
|
+
data: { endpoint: componentID, description: '', method: 'POST' },
|
|
109
|
+
displayName: 'APIEndpoint',
|
|
110
|
+
title: 'APIEndpoint',
|
|
111
|
+
description: '',
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//APIEndpointData.inputs = JSON.parse(JSON.stringify(rootComponentData.inputs));
|
|
115
|
+
clonedComponents.push(APIEndpointData);
|
|
116
|
+
|
|
117
|
+
//find all previously connected forked inputs
|
|
118
|
+
const incomingConnections = componentData.connections.filter((conn) => conn.targetId === componentID);
|
|
119
|
+
// //deduplicate connections by targetId
|
|
120
|
+
// const uniqueIncomingConnections = incomingConnections.filter(
|
|
121
|
+
// (conn, index, self) => index === self.findIndex((t) => t.targetId === conn.targetId && t.sourceIndex === conn.sourceIndex && t.targetIndex === conn.targetIndex),
|
|
122
|
+
// );
|
|
123
|
+
|
|
124
|
+
let i = 3;
|
|
125
|
+
for (let con of incomingConnections) {
|
|
126
|
+
const input = rootComponentData.inputs.find((e) => e.index == con.targetIndex);
|
|
127
|
+
const epInput = JSON.parse(JSON.stringify(input));
|
|
128
|
+
APIEndpointData.inputs.push(epInput);
|
|
129
|
+
|
|
130
|
+
const epOutput = {
|
|
131
|
+
name: input.name,
|
|
132
|
+
expression: `body.${input.name}`,
|
|
133
|
+
optional: false,
|
|
134
|
+
index: i++,
|
|
135
|
+
default: false,
|
|
136
|
+
};
|
|
137
|
+
APIEndpointData.outputs.push(epOutput);
|
|
138
|
+
|
|
139
|
+
clonedConnections.push({
|
|
140
|
+
sourceId: APIEndpointData.id,
|
|
141
|
+
targetId: rootComponentData.id,
|
|
142
|
+
sourceIndex: epOutput.index,
|
|
143
|
+
targetIndex: input.index,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Return the cloned sub-workflow
|
|
149
|
+
return {
|
|
150
|
+
components: clonedComponents,
|
|
151
|
+
connections: clonedConnections,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import process from 'process';
|
|
3
|
+
|
|
4
|
+
const OSResourceMonitor: any = {
|
|
5
|
+
mem: getMemoryUsage(),
|
|
6
|
+
//processMemory: getProcessMemoryUsage(),
|
|
7
|
+
cpu: getCpuUsage(),
|
|
8
|
+
//processCpu: getProcessCpuUsage(),
|
|
9
|
+
};
|
|
10
|
+
export { OSResourceMonitor };
|
|
11
|
+
|
|
12
|
+
function getCpuUsage() {
|
|
13
|
+
const cpus = os.cpus();
|
|
14
|
+
let user = 0;
|
|
15
|
+
let nice = 0;
|
|
16
|
+
let sys = 0;
|
|
17
|
+
let idle = 0;
|
|
18
|
+
let irq = 0;
|
|
19
|
+
let total = 0;
|
|
20
|
+
|
|
21
|
+
for (let cpu of cpus) {
|
|
22
|
+
user += cpu.times.user;
|
|
23
|
+
nice += cpu.times.nice;
|
|
24
|
+
sys += cpu.times.sys;
|
|
25
|
+
idle += cpu.times.idle;
|
|
26
|
+
irq += cpu.times.irq;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
total = user + nice + sys + idle + irq;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
user: (user / total) * 100,
|
|
33
|
+
sys: (sys / total) * 100,
|
|
34
|
+
idle: (idle / total) * 100,
|
|
35
|
+
load: 100 - (idle / total) * 100,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getMemoryUsage() {
|
|
40
|
+
const totalMemory = os.totalmem();
|
|
41
|
+
const freeMemory = os.freemem();
|
|
42
|
+
const usedMemory = totalMemory - freeMemory;
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
totalMemory: (totalMemory / 1024 ** 3).toFixed(2) + ' GB',
|
|
46
|
+
freeMemory: (freeMemory / 1024 ** 3).toFixed(2) + ' GB',
|
|
47
|
+
usedMemory: (usedMemory / 1024 ** 3).toFixed(2) + ' GB',
|
|
48
|
+
memoryUsagePercentage: ((usedMemory / totalMemory) * 100).toFixed(2),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getProcessMemoryUsage() {
|
|
53
|
+
const memoryUsage = process.memoryUsage();
|
|
54
|
+
return {
|
|
55
|
+
total: memoryUsage.rss,
|
|
56
|
+
heapTotal: (memoryUsage.heapTotal / 1024 ** 2).toFixed(2) + ' MB',
|
|
57
|
+
heapUsed: (memoryUsage.heapUsed / 1024 ** 2).toFixed(2) + ' MB',
|
|
58
|
+
external: (memoryUsage.external / 1024 ** 2).toFixed(2) + ' MB',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getProcessCpuUsage() {
|
|
63
|
+
const cpuUsage = process.cpuUsage();
|
|
64
|
+
return {
|
|
65
|
+
user: cpuUsage.user,
|
|
66
|
+
system: cpuUsage.system,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function logSystemUsage() {
|
|
71
|
+
OSResourceMonitor.mem = getMemoryUsage();
|
|
72
|
+
OSResourceMonitor.cpu = getCpuUsage();
|
|
73
|
+
//OSResourceMonitor.processMemory = getProcessMemoryUsage();
|
|
74
|
+
//OSResourceMonitor.processCpu = getProcessCpuUsage();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//setInterval(logSystemUsage, 5000); // update every 5 seconds
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
2
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
3
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
4
|
+
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
5
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
6
|
+
|
|
7
|
+
export interface CodeInput {
|
|
8
|
+
code: string; // Main code to execute
|
|
9
|
+
dependencies?: string; // Dependencies/imports/packages
|
|
10
|
+
files?: Record<string, string>; // Additional files (filename -> content)
|
|
11
|
+
inputs?: Record<string, any>; // Runtime input parameters
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CodeConfig {
|
|
15
|
+
runtime: string; // 'nodejs', 'python', 'java', etc.
|
|
16
|
+
timeout?: number; // Execution timeout in milliseconds
|
|
17
|
+
memoryLimit?: number; // Memory allocation in MB
|
|
18
|
+
environment?: Record<string, string>; // Environment variables
|
|
19
|
+
|
|
20
|
+
// Platform-specific settings
|
|
21
|
+
platformConfig?: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CodeExecutionResult {
|
|
25
|
+
output: any; // The execution result/return value
|
|
26
|
+
executionTime: number; // Execution time in milliseconds
|
|
27
|
+
logs?: string[]; // Execution logs
|
|
28
|
+
errors?: string[]; // Error messages
|
|
29
|
+
success: boolean; // Whether execution succeeded
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CodePreparationResult {
|
|
33
|
+
prepared: boolean; // Whether preparation succeeded
|
|
34
|
+
errors?: string[]; // Preparation errors
|
|
35
|
+
warnings?: string[]; // Preparation warnings
|
|
36
|
+
metadata?: Record<string, any>; // Platform-specific preparation data
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CodeDeployment {
|
|
40
|
+
id: string; // Deployment identifier
|
|
41
|
+
status: 'deploying' | 'ready' | 'failed';
|
|
42
|
+
runtime: string;
|
|
43
|
+
createdAt: Date;
|
|
44
|
+
lastUsed?: Date;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ICodeRequest {
|
|
48
|
+
// Core workflow
|
|
49
|
+
prepare(input: CodeInput, config: CodeConfig): Promise<CodePreparationResult>;
|
|
50
|
+
deploy(deploymentId: string, input: CodeInput, config: CodeConfig): Promise<CodeDeployment>;
|
|
51
|
+
execute(input: CodeInput, config: CodeConfig): Promise<CodeExecutionResult>;
|
|
52
|
+
|
|
53
|
+
// Execute with existing deployment (for platforms that support it)
|
|
54
|
+
executeDeployment(deploymentId: string, inputs: Record<string, any>): Promise<CodeExecutionResult>;
|
|
55
|
+
|
|
56
|
+
// Deployment management
|
|
57
|
+
listDeployments(): Promise<CodeDeployment[]>;
|
|
58
|
+
getDeployment(deploymentId: string): Promise<CodeDeployment | null>;
|
|
59
|
+
deleteDeployment(deploymentId: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export abstract class CodeConnector extends SecureConnector {
|
|
63
|
+
public abstract getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
64
|
+
|
|
65
|
+
// Abstract methods that concrete connectors must implement
|
|
66
|
+
protected abstract prepare(acRequest: AccessRequest, input: CodeInput, config: CodeConfig): Promise<CodePreparationResult>;
|
|
67
|
+
protected abstract deploy(acRequest: AccessRequest, deploymentId: string, input: CodeInput, config: CodeConfig): Promise<CodeDeployment>;
|
|
68
|
+
protected abstract execute(acRequest: AccessRequest, input: CodeInput, config: CodeConfig): Promise<CodeExecutionResult>;
|
|
69
|
+
protected abstract executeDeployment(acRequest: AccessRequest, deploymentId: string, inputs: Record<string, any>): Promise<CodeExecutionResult>;
|
|
70
|
+
protected abstract listDeployments(acRequest: AccessRequest): Promise<CodeDeployment[]>;
|
|
71
|
+
protected abstract getDeployment(acRequest: AccessRequest, deploymentId: string): Promise<CodeDeployment | null>;
|
|
72
|
+
protected abstract deleteDeployment(acRequest: AccessRequest, deploymentId: string): Promise<void>;
|
|
73
|
+
|
|
74
|
+
public requester(candidate: AccessCandidate): ICodeRequest {
|
|
75
|
+
return {
|
|
76
|
+
prepare: async (input: CodeInput, config: CodeConfig) => {
|
|
77
|
+
return await this.prepare(candidate.readRequest, input, config);
|
|
78
|
+
},
|
|
79
|
+
deploy: async (deploymentId: string, input: CodeInput, config: CodeConfig) => {
|
|
80
|
+
return await this.deploy(candidate.writeRequest, deploymentId, input, config);
|
|
81
|
+
},
|
|
82
|
+
execute: async (input: CodeInput, config: CodeConfig) => {
|
|
83
|
+
return await this.execute(candidate.readRequest, input, config);
|
|
84
|
+
},
|
|
85
|
+
executeDeployment: async (deploymentId: string, inputs: Record<string, any>) => {
|
|
86
|
+
return await this.executeDeployment(candidate.readRequest, deploymentId, inputs);
|
|
87
|
+
},
|
|
88
|
+
listDeployments: async () => {
|
|
89
|
+
return await this.listDeployments(candidate.readRequest);
|
|
90
|
+
},
|
|
91
|
+
getDeployment: async (deploymentId: string) => {
|
|
92
|
+
return await this.getDeployment(candidate.readRequest, deploymentId);
|
|
93
|
+
},
|
|
94
|
+
deleteDeployment: async (deploymentId: string) => {
|
|
95
|
+
await this.deleteDeployment(candidate.writeRequest, deploymentId);
|
|
96
|
+
},
|
|
97
|
+
} as ICodeRequest;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { IAccessCandidate, TAccessLevel } 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
|
+
|
|
6
|
+
export class AWSLambdaCode extends CodeConnector {
|
|
7
|
+
public name = 'AWSLambdaCode';
|
|
8
|
+
|
|
9
|
+
public async prepare(acRequest: AccessRequest, input: CodeInput, config: CodeConfig): Promise<CodePreparationResult> {
|
|
10
|
+
return {
|
|
11
|
+
prepared: true,
|
|
12
|
+
errors: [],
|
|
13
|
+
warnings: [],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async deploy(acRequest: AccessRequest, deploymentId: string, input: CodeInput, config: CodeConfig): Promise<CodeDeployment> {
|
|
18
|
+
return {
|
|
19
|
+
id: deploymentId,
|
|
20
|
+
runtime: config.runtime,
|
|
21
|
+
createdAt: new Date(),
|
|
22
|
+
status: 'deploying',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async execute(acRequest: AccessRequest, input: CodeInput, config: CodeConfig): Promise<CodeExecutionResult> {
|
|
27
|
+
return {
|
|
28
|
+
output: {},
|
|
29
|
+
executionTime: 0,
|
|
30
|
+
success: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async executeDeployment(acRequest: AccessRequest, deploymentId: string, inputs: Record<string, any>): Promise<CodeExecutionResult> {
|
|
35
|
+
return {
|
|
36
|
+
output: {},
|
|
37
|
+
executionTime: 0,
|
|
38
|
+
success: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async listDeployments(acRequest: AccessRequest): Promise<CodeDeployment[]> {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async getDeployment(acRequest: AccessRequest, deploymentId: string): Promise<CodeDeployment | null> {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async deleteDeployment(acRequest: AccessRequest, deploymentId: string): Promise<void> {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL> {
|
|
55
|
+
const acl = new ACL();
|
|
56
|
+
|
|
57
|
+
//give Read access everytime
|
|
58
|
+
//FIXME: !!!!!! IMPORTANT !!!!!! this implementation have to be changed in order to reflect the security model of AWS Lambda
|
|
59
|
+
acl.addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
60
|
+
|
|
61
|
+
return acl;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//==[ SRE: Storage ]======================
|
|
2
|
+
|
|
3
|
+
import { ConnectorService, ConnectorServiceProvider } from '@sre/Core/ConnectorsService';
|
|
4
|
+
import { TConnectorService } from '@sre/types/SRE.types';
|
|
5
|
+
import { AWSLambdaCode } from './connectors/AWSLambdaCode.class';
|
|
6
|
+
|
|
7
|
+
export class CodeService extends ConnectorServiceProvider {
|
|
8
|
+
public register() {
|
|
9
|
+
ConnectorService.register(TConnectorService.Code, 'AWSLambda', AWSLambdaCode);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Connector } from '@sre/Core/Connector.class';
|
|
2
|
+
import { getMainArgs, parseCLIArgs } from '@sre/utils/cli.utils';
|
|
3
|
+
|
|
4
|
+
export class CLIConnector extends Connector {
|
|
5
|
+
public name = 'CLI';
|
|
6
|
+
public params: any;
|
|
7
|
+
constructor(protected _settings?: any) {
|
|
8
|
+
super(_settings);
|
|
9
|
+
this.params = this.parse(process.argv);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parses the command line arguments, and returns the parsed arguments object
|
|
14
|
+
* if args is provided, it will only parse the provided args
|
|
15
|
+
* @param argv The command line arguments, usually process.argv
|
|
16
|
+
* @param args The arguments to parse
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
public parse(argv: string[], args?: string | string[]) {
|
|
20
|
+
let _keys = args;
|
|
21
|
+
if (_keys && !Array.isArray(_keys)) _keys = [_keys];
|
|
22
|
+
|
|
23
|
+
const argsList = _keys || getMainArgs(argv);
|
|
24
|
+
const params = parseCLIArgs(argsList, argv);
|
|
25
|
+
|
|
26
|
+
return params;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the parsed arguments as an object
|
|
31
|
+
* @param args The arguments to get
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
public get(args: string | string[]) {
|
|
35
|
+
let _keys = args;
|
|
36
|
+
if (!Array.isArray(_keys)) _keys = [_keys];
|
|
37
|
+
|
|
38
|
+
const result = {};
|
|
39
|
+
_keys.forEach((key) => {
|
|
40
|
+
if (this.params[key]) {
|
|
41
|
+
result[key] = this.params[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConnectorService, ConnectorServiceProvider } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { TConnectorService } from '@sre/types/SRE.types';
|
|
3
|
+
import { CLIConnector } from './CLIConnector';
|
|
4
|
+
|
|
5
|
+
export class CLIService extends ConnectorServiceProvider {
|
|
6
|
+
public register() {
|
|
7
|
+
ConnectorService.register(TConnectorService.CLI, 'CLI', CLIConnector);
|
|
8
|
+
}
|
|
9
|
+
}
|