@smythos/sre 1.5.37 → 1.5.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/index.js +65 -45
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/Components/ECMASandbox.class.d.ts +14 -0
  4. package/dist/types/Components/MemoryDeleteKeyVal.class.d.ts +19 -0
  5. package/dist/types/Components/MemoryReadKeyVal.class.d.ts +17 -0
  6. package/dist/types/Components/MemoryWriteKeyVal.class.d.ts +17 -0
  7. package/dist/types/Components/MemoryWriteObject.class.d.ts +19 -0
  8. package/dist/types/Components/index.d.ts +10 -0
  9. package/dist/types/Core/ConnectorsService.d.ts +2 -1
  10. package/dist/types/helpers/ECMASandbox.helper.d.ts +3 -0
  11. package/dist/types/helpers/Log.helper.d.ts +1 -1
  12. package/dist/types/index.d.ts +8 -1
  13. package/dist/types/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.d.ts +19 -0
  14. package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +21 -10
  15. package/dist/types/subsystems/LLMManager/LLM.service/LLMConnector.d.ts +5 -5
  16. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.d.ts +2 -3
  17. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.d.ts +2 -3
  18. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Echo.class.d.ts +2 -3
  19. package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +2 -3
  20. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Groq.class.d.ts +2 -3
  21. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +3 -4
  22. package/dist/types/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.d.ts +19 -14
  23. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +95 -0
  24. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.d.ts +87 -0
  25. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.d.ts +85 -0
  26. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.d.ts +49 -0
  27. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +146 -0
  28. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.d.ts +10 -0
  29. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.d.ts +4 -0
  30. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/types.d.ts +38 -0
  31. package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +1 -2
  32. package/dist/types/subsystems/Security/Vault.service/connectors/JSONFileVault.class.d.ts +5 -0
  33. package/dist/types/types/LLM.types.d.ts +82 -37
  34. package/dist/types/utils/data.utils.d.ts +2 -1
  35. package/package.json +4 -3
  36. package/src/Components/APICall/APICall.class.ts +2 -1
  37. package/src/Components/Component.class.ts +1 -1
  38. package/src/Components/ECMASandbox.class.ts +71 -0
  39. package/src/Components/GenAILLM.class.ts +1 -1
  40. package/src/Components/MemoryDeleteKeyVal.class.ts +70 -0
  41. package/src/Components/MemoryReadKeyVal.class.ts +66 -0
  42. package/src/Components/MemoryWriteKeyVal.class.ts +62 -0
  43. package/src/Components/MemoryWriteObject.class.ts +97 -0
  44. package/src/Components/index.ts +10 -0
  45. package/src/Core/ConnectorsService.ts +3 -3
  46. package/src/helpers/Conversation.helper.ts +11 -3
  47. package/src/helpers/ECMASandbox.helper.ts +54 -0
  48. package/src/helpers/Log.helper.ts +57 -17
  49. package/src/index.ts +192 -185
  50. package/src/index.ts.bak +192 -185
  51. package/src/subsystems/AgentManager/Agent.class.ts +11 -6
  52. package/src/subsystems/AgentManager/AgentRuntime.class.ts +13 -13
  53. package/src/subsystems/ComputeManager/Code.service/connectors/ECMASandbox.class.ts +131 -0
  54. package/src/subsystems/ComputeManager/Code.service/index.ts +2 -0
  55. package/src/subsystems/LLMManager/LLM.helper.ts +57 -27
  56. package/src/subsystems/LLMManager/LLM.inference.ts +4 -0
  57. package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +125 -28
  58. package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +18 -17
  59. package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +2 -7
  60. package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +2 -6
  61. package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +26 -17
  62. package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +2 -7
  63. package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +2 -7
  64. package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +314 -84
  65. package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +455 -0
  66. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +528 -0
  67. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterface.ts +100 -0
  68. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/OpenAIApiInterfaceFactory.ts +81 -0
  69. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +853 -0
  70. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/constants.ts +37 -0
  71. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/index.ts +4 -0
  72. package/src/subsystems/LLMManager/LLM.service/connectors/openai/types.ts +37 -0
  73. package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +0 -5
  74. package/src/subsystems/LLMManager/LLM.service/index.ts +1 -1
  75. package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +2 -2
  76. package/src/subsystems/LLMManager/models.ts +1 -1
  77. package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +18 -0
  78. package/src/subsystems/MemoryManager/RuntimeContext.ts +33 -16
  79. package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +68 -42
  80. package/src/types/LLM.types.ts +91 -43
  81. package/src/utils/data.utils.ts +3 -2
  82. package/src/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.ts +0 -848
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smythos/sre",
3
- "version": "1.5.37",
3
+ "version": "1.5.40",
4
4
  "description": "Smyth Runtime Environment",
5
5
  "author": "Alaa-eddine KADDOURI",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "typescript": "^5.4.5"
43
43
  },
44
44
  "dependencies": {
45
- "@anthropic-ai/sdk": "^0.39.0",
45
+ "@anthropic-ai/sdk": "^0.56.0",
46
46
  "@aws-sdk/client-bedrock-runtime": "^3.826.0",
47
47
  "@aws-sdk/client-iam": "^3.835.0",
48
48
  "@aws-sdk/client-lambda": "^3.835.0",
@@ -50,8 +50,8 @@
50
50
  "@aws-sdk/client-secrets-manager": "^3.826.0",
51
51
  "@faker-js/faker": "^9.8.0",
52
52
  "@google-cloud/vertexai": "^1.7.0",
53
- "@google/generative-ai": "^0.14.1",
54
53
  "@google/genai": "^1.10.0",
54
+ "@google/generative-ai": "^0.14.1",
55
55
  "@huggingface/inference": "^2.8.0",
56
56
  "@modelcontextprotocol/sdk": "^1.10.1",
57
57
  "@pinecone-database/pinecone": "^3.0.0",
@@ -83,6 +83,7 @@
83
83
  "p-limit": "^6.1.0",
84
84
  "qs": "^6.13.0",
85
85
  "readline-sync": "^1.4.10",
86
+ "ses": "^1.14.0",
86
87
  "socks-proxy-agent": "^8.0.4",
87
88
  "winston": "^3.13.0",
88
89
  "winston-transport": "^4.7.0",
@@ -11,6 +11,7 @@ import { parseArrayBufferResponse } from './ArrayBufferResponse.helper';
11
11
  import { extractAdditionalParamsForOAuth1, handleOAuthHeaders as generateOAuthHeaders } from './OAuth.helper';
12
12
  import { SocksProxyAgent } from 'socks-proxy-agent';
13
13
  import { formatDataForDebug } from '@sre/utils/data.utils';
14
+ import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
14
15
 
15
16
  export class APICall extends Component {
16
17
  protected schema = {
@@ -92,7 +93,7 @@ export class APICall extends Component {
92
93
  if (data) {
93
94
  reqConfig.data = data;
94
95
 
95
- dataForDebug = await formatDataForDebug(data);
96
+ dataForDebug = await formatDataForDebug(data, AccessCandidate.agent(agent.id));
96
97
  }
97
98
 
98
99
  reqConfig.headers = (await parseHeaders(input, config, agent)).concat({ ...headers });
@@ -27,7 +27,7 @@ export class Component {
27
27
  init() {}
28
28
 
29
29
  createComponentLogger(agent: Agent, configuration: any) {
30
- const logger = Logger(configuration.name || this.constructor.name, agent?.agentRuntime?.debug);
30
+ const logger = Logger((configuration.name || this.constructor.name) + `,agent<${agent.id}>`, agent?.agentRuntime?.debug);
31
31
 
32
32
  logger.on('logged', (info: { level: string; message: string }) => {
33
33
  if (agent.sse && configuration.eventId) {
@@ -0,0 +1,71 @@
1
+ import { IAgent as Agent } from '@sre/types/Agent.types';
2
+ import { Component } from './Component.class';
3
+ import Joi from 'joi';
4
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
5
+ import { CodeExecutionResult } from '@sre/ComputeManager/Code.service/CodeConnector';
6
+
7
+ export class ECMASandbox extends Component {
8
+ protected configSchema = Joi.object({
9
+ code: Joi.string().max(500000).allow('').label('Code'),
10
+ });
11
+ constructor() {
12
+ super();
13
+ }
14
+ init() {}
15
+ async process(input, config, agent: Agent) {
16
+ await super.process(input, config, agent);
17
+
18
+ const logger = this.createComponentLogger(agent, config);
19
+ try {
20
+ let Output: any = {};
21
+ let _error = undefined;
22
+
23
+ let codeInputs = {};
24
+ for (let fieldName in input) {
25
+ const _type = typeof input[fieldName];
26
+ switch (_type) {
27
+ case 'string':
28
+ const b64encoded = Buffer.from(input[fieldName]).toString('base64');
29
+ codeInputs[fieldName] = `___internal.b64decode('${b64encoded}')`;
30
+ break;
31
+ case 'number':
32
+ case 'boolean':
33
+ codeInputs[fieldName] = input[fieldName];
34
+ break;
35
+ default:
36
+ codeInputs[fieldName] = input[fieldName];
37
+ break;
38
+ }
39
+ }
40
+
41
+ const inputVarsCode = this.generateInputVarCode(codeInputs);
42
+ const code = inputVarsCode + '\n' + config.data.code;
43
+
44
+ logger.debug(`Running code: \n${code}\n`);
45
+
46
+ const ecmaCodeConnector = ConnectorService.getCodeConnector('ECMASandbox');
47
+
48
+ const executionResponse: CodeExecutionResult = await ecmaCodeConnector.agent(agent.id).execute(config.id, { code });
49
+ if (executionResponse.success) {
50
+ Output = executionResponse.output;
51
+ } else {
52
+ Output = undefined;
53
+ _error = executionResponse.errors;
54
+ }
55
+
56
+ return { Output, _error, _debug: logger.output };
57
+ } catch (err: any) {
58
+ const _error = err?.response?.data || err?.message || err.toString();
59
+ logger.error(`Error running code: \n${_error}\n`);
60
+ return { Output: undefined, _error, _debug: logger.output };
61
+ }
62
+ }
63
+
64
+ private generateInputVarCode(input: Record<string, any>) {
65
+ let input_vars = '';
66
+ for (const key in input) {
67
+ input_vars += `var ${key} = ${input[key]};\n`;
68
+ }
69
+ return input_vars;
70
+ }
71
+ }
@@ -390,7 +390,7 @@ export class GenAILLM extends Component {
390
390
  logger.debug(` Prompt\n`, prompt, '\n');
391
391
 
392
392
  if (!isEcho) {
393
- logger.debug(' Files\n', await Promise.all(files.map((file) => formatDataForDebug(file))));
393
+ logger.debug(' Files\n', await Promise.all(files.map((file) => formatDataForDebug(file, AccessCandidate.agent(agent.id)))));
394
394
  }
395
395
 
396
396
  // default to json response format
@@ -0,0 +1,70 @@
1
+ import Joi from 'joi';
2
+
3
+ import { IAgent as Agent } from '@sre/types/Agent.types';
4
+ import { Component } from './Component.class';
5
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
6
+ import { TemplateString } from '@sre/helpers/TemplateString.helper';
7
+ import { ICacheRequest } from '@sre/MemoryManager/Cache.service/CacheConnector';
8
+
9
+ export class MemoryDeleteKeyVal extends Component {
10
+ protected configSchema = Joi.object({
11
+ memoryName: Joi.string().max(255).allow('').label('Memory Name'),
12
+ key: Joi.string().max(255).allow('').label('Key'),
13
+ });
14
+ constructor() {
15
+ super();
16
+ }
17
+ init() {}
18
+ async process(input, config, agent: Agent) {
19
+ await super.process(input, config, agent);
20
+
21
+ const logger = this.createComponentLogger(agent, config);
22
+
23
+ try {
24
+ const cacheConnector = ConnectorService.getCacheConnector();
25
+ const connectorRequester: ICacheRequest = cacheConnector.agent(agent.id);
26
+ const teamId = agent.teamId;
27
+ const agentId = agent.id;
28
+
29
+ const memoryName = config.data.memoryName;
30
+ const key = TemplateString(config.data.key).parse(input).result;
31
+
32
+ const sessionId = agent.sessionId;
33
+ const workflowId = agent.agentRuntime.workflowReqId;
34
+
35
+ logger.debug(`Reading Scope Data for deletion`);
36
+ const scopeKeyId = `${agentId}:${memoryName}:${key}_scope`;
37
+ const scopeStrData = await connectorRequester.get(scopeKeyId);
38
+
39
+ if (!scopeStrData) {
40
+ return { _error: 'key not found', _debug: logger.output };
41
+ }
42
+
43
+ logger.debug(`Checking Scope for deletion`);
44
+ const scopeData = JSON.parse(scopeStrData);
45
+ const scopeKey = scopeData.value;
46
+
47
+ // Validate scope access like in MemoryReadKeyVal
48
+ if (scopeData.scope === 'session' && scopeKey !== sessionId) {
49
+ return { _error: 'key not found', _debug: logger.output };
50
+ }
51
+
52
+ if (scopeData.scope === 'request' && scopeKey !== workflowId) {
53
+ return { _error: 'key not found', _debug: logger.output };
54
+ }
55
+
56
+ logger.debug(`Deleting memory value and scope data`);
57
+
58
+ // Delete the actual value
59
+ const fullKey = `${agentId}:${scopeKey}:${memoryName}:${key}`;
60
+ await connectorRequester.delete(fullKey);
61
+
62
+ // Delete the scope metadata
63
+ await connectorRequester.delete(scopeKeyId);
64
+
65
+ return { Key: key, deleted: true, _debug: logger.output };
66
+ } catch (error: any) {
67
+ return { _error: error.message, _debug: logger.output };
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,66 @@
1
+ import Joi from 'joi';
2
+
3
+ import { IAgent as Agent } from '@sre/types/Agent.types';
4
+ import { Component } from './Component.class';
5
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
6
+ import { TemplateString } from '@sre/helpers/TemplateString.helper';
7
+ import { ICacheRequest } from '@sre/MemoryManager/Cache.service/CacheConnector';
8
+
9
+ const memory = {};
10
+ export class MemoryReadKeyVal extends Component {
11
+ protected configSchema = Joi.object({
12
+ memoryName: Joi.string().max(255).allow('').label('Memory Name'),
13
+ });
14
+ constructor() {
15
+ super();
16
+ }
17
+ init() {}
18
+ async process(input, config, agent: Agent) {
19
+ await super.process(input, config, agent);
20
+
21
+ const logger = this.createComponentLogger(agent, config);
22
+
23
+ try {
24
+ const cacheConnector = ConnectorService.getCacheConnector();
25
+ const connectorRequester: ICacheRequest = cacheConnector.agent(agent.id);
26
+ const teamId = agent.teamId;
27
+ const agentId = agent.id;
28
+
29
+ const memoryName = config.data.memoryName;
30
+
31
+ const key = input.Key;
32
+
33
+ const sessionId = agent.sessionId;
34
+ const workflowId = agent.agentRuntime.workflowReqId;
35
+
36
+ logger.debug(`Reading Scope Data`);
37
+ const scopeKeyId = `${agentId}:${memoryName}:${key}_scope`;
38
+ const scopeStrData = await connectorRequester.get(scopeKeyId);
39
+
40
+ if (!scopeStrData) {
41
+ return { _error: 'key not found', _debug: logger.output };
42
+ }
43
+
44
+ logger.debug(`Checking Scope`);
45
+ const scopeData = JSON.parse(scopeStrData);
46
+ const scopeKey = scopeData.value;
47
+ if (scopeData.scope === 'session' && scopeKey !== sessionId) {
48
+ return { _error: 'key not found', _debug: logger.output };
49
+ }
50
+
51
+ if (scopeData.scope === 'request' && scopeKey !== workflowId) {
52
+ return { _error: 'key not found', _debug: logger.output };
53
+ }
54
+
55
+ logger.debug(`Reading Value`);
56
+
57
+ const fullKey = `${agentId}:${scopeKey}:${memoryName}:${key}`;
58
+
59
+ const value = await connectorRequester.get(fullKey);
60
+
61
+ return { Value: value, _debug: logger.output };
62
+ } catch (error: any) {
63
+ return { _error: error.message, _debug: logger.output };
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,62 @@
1
+ import Joi from 'joi';
2
+
3
+ import { IAgent as Agent } from '@sre/types/Agent.types';
4
+ import { Component } from './Component.class';
5
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
6
+ import { TemplateString } from '@sre/helpers/TemplateString.helper';
7
+ import { ICacheRequest } from '@sre/MemoryManager/Cache.service/CacheConnector';
8
+
9
+ const memory = {};
10
+ export class MemoryWriteKeyVal extends Component {
11
+ protected configSchema = Joi.object({
12
+ memoryName: Joi.string().max(255).allow('').label('Memory Name'),
13
+ key: Joi.string().max(255).allow('').label('Key'),
14
+ value: Joi.string().max(100000).allow('').label('Value'),
15
+ scope: Joi.string().max(20).allow('').label('Scope'),
16
+ ttl: Joi.number().min(300).max(604800).allow('').label('TTL'),
17
+ });
18
+ constructor() {
19
+ super();
20
+ }
21
+ init() {}
22
+ async process(input, config, agent: Agent) {
23
+ await super.process(input, config, agent);
24
+
25
+ const logger = this.createComponentLogger(agent, config);
26
+
27
+ try {
28
+ const cacheConnector = ConnectorService.getCacheConnector();
29
+ const connectorRequester: ICacheRequest = cacheConnector.agent(agent.id);
30
+ const teamId = agent.teamId;
31
+ const agentId = agent.id;
32
+
33
+ const memoryName = config.data.memoryName;
34
+ const key = TemplateString(config.data.key).parse(input).result;
35
+ const value = TemplateString(config.data.value).parse(input).result;
36
+ const scope = config.data.scope;
37
+ const ttl = scope === 'ttl' ? config?.data?.ttl : 3 * 60 * 60; // 3 hours default ttl
38
+
39
+ const sessionId = agent.sessionId;
40
+ const workflowId = agent.agentRuntime.workflowReqId;
41
+
42
+ let scopeKey = '';
43
+ if (scope === 'session') {
44
+ scopeKey = sessionId;
45
+ } else if (scope === 'request') {
46
+ scopeKey = workflowId;
47
+ } else if (scope === 'ttl') {
48
+ scopeKey = 'ttl';
49
+ }
50
+
51
+ const scopeKeyId = `${agentId}:${memoryName}:${key}_scope`;
52
+ await connectorRequester.set(scopeKeyId, JSON.stringify({ scope, value: scopeKey }), null, null, ttl);
53
+
54
+ const fullKey = `${agentId}:${scopeKey}:${memoryName}:${key}`;
55
+ await connectorRequester.set(fullKey, value, null, null, ttl);
56
+
57
+ return { Key: key, _debug: logger.output };
58
+ } catch (error: any) {
59
+ return { _error: error.message, _debug: logger.output };
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,97 @@
1
+ import Joi from 'joi';
2
+
3
+ import { IAgent as Agent } from '@sre/types/Agent.types';
4
+ import { Component } from './Component.class';
5
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
6
+ import { TemplateString } from '@sre/helpers/TemplateString.helper';
7
+ import { ICacheRequest } from '@sre/MemoryManager/Cache.service/CacheConnector';
8
+
9
+ export class MemoryWriteObject extends Component {
10
+ protected configSchema = Joi.object({
11
+ memoryName: Joi.string().max(255).allow('').label('Memory Name'),
12
+ scope: Joi.string().max(20).allow('').label('Scope'),
13
+ ttl: Joi.number().min(300).max(604800).allow('').label('TTL'),
14
+ });
15
+ constructor() {
16
+ super();
17
+ }
18
+ init() {}
19
+ async process(input, config, agent: Agent) {
20
+ await super.process(input, config, agent);
21
+
22
+ const logger = this.createComponentLogger(agent, config);
23
+
24
+ try {
25
+ const cacheConnector = ConnectorService.getCacheConnector();
26
+ const connectorRequester: ICacheRequest = cacheConnector.agent(agent.id);
27
+ const teamId = agent.teamId;
28
+ const agentId = agent.id;
29
+
30
+ const memoryName = config.data.memoryName;
31
+ const dataString = input.Data;
32
+ const scope = config.data.scope;
33
+ const ttl = scope === 'ttl' ? config?.data?.ttl : 3 * 60 * 60; // 3 hours default ttl
34
+
35
+ // Parse the JSON data
36
+ let dataObject;
37
+ try {
38
+ dataObject = JSON.parse(dataString);
39
+ } catch (parseError) {
40
+ return { _error: 'Invalid JSON data provided', _debug: logger.output };
41
+ }
42
+
43
+ // Validate that the parsed data is an object
44
+ if (typeof dataObject !== 'object' || dataObject === null || Array.isArray(dataObject)) {
45
+ return { _error: 'Data must be a valid JSON object', _debug: logger.output };
46
+ }
47
+
48
+ const sessionId = agent.sessionId;
49
+ const workflowId = agent.agentRuntime.workflowReqId;
50
+
51
+ let scopeKey = '';
52
+ if (scope === 'session') {
53
+ scopeKey = sessionId;
54
+ } else if (scope === 'request') {
55
+ scopeKey = workflowId;
56
+ } else if (scope === 'ttl') {
57
+ scopeKey = 'ttl';
58
+ }
59
+
60
+ // Get all keys from the data object
61
+ const keys = Object.keys(dataObject);
62
+ logger.debug(`Writing ${keys.length} key-value pairs to memory`);
63
+
64
+ // Create promises for parallel execution
65
+ const writePromises = keys.map(async (key) => {
66
+ const value = String(dataObject[key]); // Convert value to string
67
+
68
+ // Write scope metadata
69
+ const scopeKeyId = `${agentId}:${memoryName}:${key}_scope`;
70
+ const scopePromise = connectorRequester.set(scopeKeyId, JSON.stringify({ scope, value: scopeKey }), null, null, ttl);
71
+
72
+ // Write actual value
73
+ const fullKey = `${agentId}:${scopeKey}:${memoryName}:${key}`;
74
+ const valuePromise = connectorRequester.set(fullKey, value, null, null, ttl);
75
+
76
+ // Wait for both operations to complete for this key
77
+ await Promise.all([scopePromise, valuePromise]);
78
+
79
+ return { key, success: true };
80
+ });
81
+
82
+ // Execute all write operations in parallel
83
+ const results = await Promise.all(writePromises);
84
+ const successfulKeys = results.filter((result) => result.success).map((result) => result.key);
85
+
86
+ logger.debug(`Successfully wrote ${successfulKeys.length} keys to memory`);
87
+
88
+ return {
89
+ Keys: successfulKeys,
90
+ Count: successfulKeys.length,
91
+ _debug: logger.output,
92
+ };
93
+ } catch (error: any) {
94
+ return { _error: error.message, _debug: logger.output };
95
+ }
96
+ }
97
+ }
@@ -37,6 +37,11 @@ import { ServerlessCode } from './ServerlessCode.class';
37
37
  import { ImageGenerator } from './ImageGenerator.class'; // Legacy
38
38
  import { MCPClient } from './MCPClient.class';
39
39
  import { OpenAPI } from './OpenAPI.class';
40
+ import { ECMASandbox } from './ECMASandbox.class';
41
+ import { MemoryWriteKeyVal } from './MemoryWriteKeyVal.class';
42
+ import { MemoryReadKeyVal } from './MemoryReadKeyVal.class';
43
+ import { MemoryDeleteKeyVal } from './MemoryDeleteKeyVal.class';
44
+ import { MemoryWriteObject } from './MemoryWriteObject.class';
40
45
 
41
46
  const components = {
42
47
  Component: new Component(),
@@ -82,6 +87,11 @@ const components = {
82
87
  ImageGenerator: new ImageGenerator(),
83
88
  MCPClient: new MCPClient(),
84
89
  OpenAPI: new OpenAPI(),
90
+ ECMASandbox: new ECMASandbox(),
91
+ MemoryWriteKeyVal: new MemoryWriteKeyVal(),
92
+ MemoryReadKeyVal: new MemoryReadKeyVal(),
93
+ MemoryDeleteKeyVal: new MemoryDeleteKeyVal(),
94
+ MemoryWriteObject: new MemoryWriteObject(),
85
95
  };
86
96
 
87
97
  export const ComponentInstances = components;
@@ -18,6 +18,7 @@ import { ManagedVaultConnector } from '@sre/Security/ManagedVault.service/Manage
18
18
  import { LogConnector } from '@sre/IO/Log.service/LogConnector';
19
19
  import { ComponentConnector } from '@sre/AgentManager/Component.service/ComponentConnector';
20
20
  import { ModelsProviderConnector } from '@sre/LLMManager/ModelsProvider.service/ModelsProviderConnector';
21
+ import { CodeConnector } from '@sre/ComputeManager/Code.service/CodeConnector';
21
22
  const console = Logger('ConnectorService');
22
23
 
23
24
  let ServiceRegistry: TServiceRegistry = {};
@@ -182,9 +183,8 @@ export class ConnectorService {
182
183
  return ConnectorService.getInstance<RouterConnector>(TConnectorService.Router, name);
183
184
  }
184
185
 
185
-
186
- static getCodeConnector(name?: string): RouterConnector {
187
- return ConnectorService.getInstance<RouterConnector>(TConnectorService.Code, name);
186
+ static getCodeConnector(name?: string): CodeConnector {
187
+ return ConnectorService.getInstance<CodeConnector>(TConnectorService.Code, name);
188
188
  }
189
189
  }
190
190
 
@@ -130,8 +130,14 @@ export class Conversation extends EventEmitter {
130
130
  this._lastError = error;
131
131
  console.warn('Conversation Error: ', error?.message);
132
132
  });
133
- if (_settings?.maxContextSize) this._maxContextSize = _settings.maxContextSize;
134
- if (_settings?.maxOutputTokens) this._maxOutputTokens = _settings.maxOutputTokens;
133
+ this._maxContextSize =
134
+ _settings.maxContextSize || (this._model as TLLMModel).tokens || (this._model as TLLMModel).keyOptions?.tokens || this._maxContextSize;
135
+ this._maxOutputTokens =
136
+ _settings.maxOutputTokens ||
137
+ (this._model as TLLMModel).completionTokens ||
138
+ (this._model as TLLMModel).keyOptions?.completionTokens ||
139
+ this._maxOutputTokens;
140
+
135
141
  if (_settings?.systemPrompt) {
136
142
  this.userDefinedSystemPrompt = _settings.systemPrompt;
137
143
  }
@@ -490,9 +496,11 @@ export class Conversation extends EventEmitter {
490
496
  //this._context.addAssistantMessage(passThroughContent, message_id);
491
497
  llmMessage.content += '\n' + passThroughContent;
492
498
  this._context.addToolMessage(llmMessage, processedToolsData, message_id);
499
+
500
+ //this._context.addAssistantMessage(passThroughContent, message_id, { passthrough: true });
493
501
  //this should not be stored in the persistent conversation store
494
502
  //it's just a workaround to avoid generating more content after passthrough content
495
- this._context.addUserMessage(passThroughtContinueMessage, message_id, { internal: true });
503
+ //this._context.addUserMessage(passThroughtContinueMessage, message_id, { internal: true });
496
504
  //toolHeaders['x-passthrough'] = 'true';
497
505
  }
498
506
 
@@ -0,0 +1,54 @@
1
+ import 'ses';
2
+
3
+
4
+
5
+
6
+ export function runJs(code: string) {
7
+ // Call lockdown to secure the environment
8
+ lockdown();
9
+ try {
10
+ // Endow the compartment with necessary APIs
11
+ const compartment = new Compartment({
12
+ globals: {
13
+ // add necessary globals here
14
+ setTimeout: harden(setTimeout),
15
+ clearTimeout: harden(clearTimeout),
16
+ setInterval: harden(setInterval),
17
+ clearInterval: harden(clearInterval),
18
+ console: harden(console),
19
+ Promise: harden(Promise),
20
+ fetch: harden(fetch),
21
+ },
22
+ __options__: true, // temporary migration affordance
23
+ });
24
+ const result = compartment.evaluate(code);
25
+ return result;
26
+ } catch (error) {
27
+ console.error(error);
28
+ throw error;
29
+ }
30
+
31
+ }
32
+
33
+ function getParametersString(parameters: string[], inputs: Record<string, any>) {
34
+ let params = [];
35
+ for (const parameter of parameters) {
36
+ if (typeof inputs[parameter] === 'string') {
37
+ params.push(`'${inputs[parameter]}'`);
38
+ } else {
39
+ params.push(`${inputs[parameter]}`);
40
+ }
41
+ }
42
+ return params.join(',');
43
+ }
44
+
45
+ export function generateExecutableCode(code: string, parameters: string[], inputs: Record<string, any>) {
46
+ const executableCode = `
47
+ (async () => {
48
+ ${code}
49
+ const result = await main(${getParametersString(parameters, inputs)});
50
+ return result;
51
+ })();
52
+ `
53
+ return executableCode;
54
+ }