@smythos/sre 1.6.14 → 1.7.5

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 (115) hide show
  1. package/CHANGELOG +15 -0
  2. package/dist/index.js +66 -58
  3. package/dist/index.js.map +1 -1
  4. package/dist/types/Components/APIEndpoint.class.d.ts +2 -8
  5. package/dist/types/Components/Component.class.d.ts +9 -0
  6. package/dist/types/Components/Triggers/Gmail.trigger.d.ts +0 -17
  7. package/dist/types/Components/Triggers/JobScheduler.trigger.d.ts +10 -0
  8. package/dist/types/Components/Triggers/Trigger.class.d.ts +11 -0
  9. package/dist/types/Components/index.d.ts +6 -0
  10. package/dist/types/Core/Connector.class.d.ts +1 -0
  11. package/dist/types/Core/ConnectorsService.d.ts +2 -0
  12. package/dist/types/Core/HookService.d.ts +1 -1
  13. package/dist/types/helpers/BinaryInput.helper.d.ts +1 -1
  14. package/dist/types/helpers/Conversation.helper.d.ts +2 -0
  15. package/dist/types/helpers/Crypto.helper.d.ts +8 -0
  16. package/dist/types/helpers/LocalCache.helper.d.ts +18 -0
  17. package/dist/types/helpers/TemplateString.helper.d.ts +2 -1
  18. package/dist/types/index.d.ts +13 -0
  19. package/dist/types/subsystems/AgentManager/Agent.class.d.ts +4 -2
  20. package/dist/types/subsystems/AgentManager/AgentData.service/AgentDataConnector.d.ts +13 -0
  21. package/dist/types/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.d.ts +1 -4
  22. package/dist/types/subsystems/AgentManager/Scheduler.service/Job.class.d.ts +29 -6
  23. package/dist/types/subsystems/AgentManager/Scheduler.service/SchedulerConnector.d.ts +11 -3
  24. package/dist/types/subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class.d.ts +31 -7
  25. package/dist/types/subsystems/IO/VectorDB.service/VectorDBConnector.d.ts +4 -4
  26. package/dist/types/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.d.ts +2 -2
  27. package/dist/types/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.d.ts +2 -2
  28. package/dist/types/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.d.ts +2 -2
  29. package/dist/types/subsystems/IO/VectorDB.service/embed/BaseEmbedding.d.ts +16 -9
  30. package/dist/types/subsystems/IO/VectorDB.service/embed/index.d.ts +4 -1
  31. package/dist/types/subsystems/LLMManager/LLM.inference.d.ts +36 -2
  32. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +2 -5
  33. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +3 -6
  34. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +7 -0
  35. package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +2 -5
  36. package/dist/types/types/Agent.types.d.ts +1 -0
  37. package/dist/types/types/LLM.types.d.ts +56 -36
  38. package/dist/types/types/SRE.types.d.ts +4 -1
  39. package/dist/types/types/VectorDB.types.d.ts +6 -3
  40. package/dist/types/utils/string.utils.d.ts +0 -4
  41. package/package.json +6 -2
  42. package/src/Components/APICall/OAuth.helper.ts +30 -35
  43. package/src/Components/APIEndpoint.class.ts +25 -6
  44. package/src/Components/Classifier.class.ts +8 -2
  45. package/src/Components/Component.class.ts +11 -0
  46. package/src/Components/GenAILLM.class.ts +11 -7
  47. package/src/Components/LLMAssistant.class.ts +12 -3
  48. package/src/Components/ScrapflyWebScrape.class.ts +8 -1
  49. package/src/Components/TavilyWebSearch.class.ts +4 -1
  50. package/src/Components/Triggers/Gmail.trigger.ts +282 -0
  51. package/src/Components/Triggers/JobScheduler.trigger.ts +45 -0
  52. package/src/Components/Triggers/README.md +3 -0
  53. package/src/Components/Triggers/Trigger.class.ts +101 -0
  54. package/src/Components/Triggers/WhatsApp.trigger.ts +219 -0
  55. package/src/Components/index.ts +8 -0
  56. package/src/Core/AgentProcess.helper.ts +4 -6
  57. package/src/Core/Connector.class.ts +11 -3
  58. package/src/Core/ConnectorsService.ts +5 -0
  59. package/src/Core/ExternalEventsReceiver.ts +317 -0
  60. package/src/Core/HookService.ts +20 -6
  61. package/src/Core/SmythRuntime.class.ts +20 -2
  62. package/src/Core/SystemEvents.ts +17 -0
  63. package/src/Core/boot.ts +2 -0
  64. package/src/helpers/BinaryInput.helper.ts +8 -8
  65. package/src/helpers/Conversation.helper.ts +46 -12
  66. package/src/helpers/Crypto.helper.ts +28 -0
  67. package/src/helpers/LocalCache.helper.ts +18 -0
  68. package/src/helpers/TemplateString.helper.ts +20 -9
  69. package/src/index.ts +13 -0
  70. package/src/index.ts.bak +13 -0
  71. package/src/subsystems/AGENTS.md +594 -0
  72. package/src/subsystems/AgentManager/Agent.class.ts +73 -21
  73. package/src/subsystems/AgentManager/AgentData.service/AgentDataConnector.ts +30 -6
  74. package/src/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.ts +2 -2
  75. package/src/subsystems/AgentManager/AgentLogger.class.ts +1 -1
  76. package/src/subsystems/AgentManager/AgentRuntime.class.ts +34 -5
  77. package/src/subsystems/AgentManager/Scheduler.service/Job.class.ts +414 -0
  78. package/src/subsystems/AgentManager/Scheduler.service/Schedule.class.ts +200 -0
  79. package/src/subsystems/AgentManager/Scheduler.service/SchedulerConnector.ts +200 -0
  80. package/src/subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class.ts +767 -0
  81. package/src/subsystems/AgentManager/Scheduler.service/index.ts +11 -0
  82. package/src/subsystems/IO/VectorDB.service/VectorDBConnector.ts +15 -4
  83. package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +32 -11
  84. package/src/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.ts +27 -10
  85. package/src/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.ts +25 -9
  86. package/src/subsystems/IO/VectorDB.service/embed/BaseEmbedding.ts +182 -12
  87. package/src/subsystems/IO/VectorDB.service/embed/GoogleEmbedding.ts +1 -1
  88. package/src/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.ts +1 -1
  89. package/src/subsystems/IO/VectorDB.service/embed/index.ts +12 -2
  90. package/src/subsystems/LLMManager/LLM.inference.ts +76 -17
  91. package/src/subsystems/LLMManager/LLM.service/LLMCredentials.helper.ts +61 -2
  92. package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +3 -0
  93. package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +3 -1
  94. package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +5 -1
  95. package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +247 -56
  96. package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +3 -0
  97. package/src/subsystems/LLMManager/LLM.service/connectors/Ollama.class.ts +28 -21
  98. package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +3 -0
  99. package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +121 -33
  100. package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +38 -27
  101. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +3 -2
  102. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +117 -20
  103. package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +3 -0
  104. package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +3 -8
  105. package/src/subsystems/LLMManager/ModelsProvider.service/connectors/JSONModelsProvider.class.ts +4 -1
  106. package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +12 -0
  107. package/src/subsystems/MemoryManager/LLMContext.ts +3 -8
  108. package/src/subsystems/MemoryManager/RuntimeContext.ts +10 -9
  109. package/src/subsystems/Security/Credentials/Credentials.class.ts +1 -0
  110. package/src/subsystems/Security/Credentials/ManagedOAuth2Credentials.class.ts +106 -0
  111. package/src/types/Agent.types.ts +1 -0
  112. package/src/types/LLM.types.ts +68 -40
  113. package/src/types/SRE.types.ts +3 -0
  114. package/src/types/VectorDB.types.ts +7 -3
  115. package/src/utils/string.utils.ts +193 -191
@@ -3,6 +3,13 @@ interface CacheItem<T> {
3
3
  expiry: number;
4
4
  }
5
5
 
6
+ /**
7
+ * A local cache helper used to cache data, functions or object instances
8
+ * This is useful when you need to cache an object and refresh the cache if the object is accessed within a certain time period
9
+ *
10
+ * @template K - The type of the key
11
+ * @template V - The type of the value
12
+ */
6
13
  export class LocalCache<K, V> {
7
14
  private cache: Map<K, V>;
8
15
  private expiryMap: Map<K, number>;
@@ -48,6 +55,12 @@ export class LocalCache<K, V> {
48
55
  timeout.unref(); //unblock the event loop
49
56
  }
50
57
 
58
+ /**
59
+ * Get the value from the cache, and update the TTL if provided
60
+ * @param key - The key to get the value from the cache
61
+ * @param ttlMs - The TTL in milliseconds
62
+ * @returns The value from the cache
63
+ */
51
64
  get(key: K, ttlMs?: number): V | undefined {
52
65
  if (!this.has(key)) {
53
66
  return undefined;
@@ -60,6 +73,11 @@ export class LocalCache<K, V> {
60
73
  return value;
61
74
  }
62
75
 
76
+ /**
77
+ * Check if the key exists in the cache
78
+ * @param key - The key to check if it exists in the cache
79
+ * @returns True if the key exists in the cache, false otherwise
80
+ */
63
81
  has(key: K): boolean {
64
82
  if (!this.cache.has(key)) {
65
83
  return false;
@@ -101,19 +101,30 @@ export class TemplateStringHelper {
101
101
  /**
102
102
  * Parses a template string by replacing the placeholders with the values from the provided data object
103
103
  * unmatched placeholders will be left as is
104
+ * Recursively resolves nested template variables until no more variables are found
104
105
  */
105
- public parse(data: Record<string, string>, regex: TemplateStringMatch = Match.default) {
106
+ public parse(data: Record<string, string>, regex: TemplateStringMatch = Match.default, maxDepth: number = 5) {
106
107
  if (typeof this._current !== 'string' || typeof data !== 'object') return this;
107
- this._current = this._current.replace(regex, (match, token) => {
108
- let val = data?.[token] ?? match; // Use nullish coalescing to preserve falsy values (0, '', false)
109
108
 
110
- //if no exact match, try to parse the token as a JSON expression
111
- if (!data?.[token]) {
112
- val = JSONExpression(data, token) || `{{${token}}}`; //if no match, use the token as is
113
- }
109
+ // Keep parsing until no more template variables are resolved or max depth is reached
110
+ // this is useful for chained template variables : e.g {{defaultVar}} => "text {{nestedVar}} more text" ==> "text value of nestedVar more text"
111
+ for (let i = 0; i < maxDepth; i++) {
112
+ const previous = this._current;
114
113
 
115
- return typeof val === 'object' ? JSON.stringify(val) : escapeJsonField(val);
116
- });
114
+ this._current = this._current.replace(regex, (match, token) => {
115
+ let val = data?.[token] ?? match; // Use nullish coalescing to preserve falsy values (0, '', false)
116
+
117
+ //if no exact match, try to parse the token as a JSON expression
118
+ if (!data?.[token]) {
119
+ val = JSONExpression(data, token) || `{{${token}}}`; //if no match, use the token as is
120
+ }
121
+
122
+ return typeof val === 'object' ? JSON.stringify(val) : escapeJsonField(val);
123
+ });
124
+
125
+ // Break early if no changes were made : we parsed all the template variables
126
+ if (previous === this._current) break;
127
+ }
117
128
 
118
129
  return this;
119
130
  }
package/src/index.ts CHANGED
@@ -54,12 +54,14 @@ export * from './Core/boot';
54
54
  export * from './Core/Connector.class';
55
55
  export * from './Core/ConnectorsService';
56
56
  export * from './Core/DummyConnector';
57
+ export * from './Core/ExternalEventsReceiver';
57
58
  export * from './Core/HookService';
58
59
  export * from './Core/SmythRuntime.class';
59
60
  export * from './Core/SystemEvents';
60
61
  export * from './helpers/AWSLambdaCode.helper';
61
62
  export * from './helpers/BinaryInput.helper';
62
63
  export * from './helpers/Conversation.helper';
64
+ export * from './helpers/Crypto.helper';
63
65
  export * from './helpers/ECMASandbox.helper';
64
66
  export * from './helpers/JsonContent.helper';
65
67
  export * from './helpers/LocalCache.helper';
@@ -92,6 +94,10 @@ export * from './Components/APICall/parseHeaders';
92
94
  export * from './Components/APICall/parseProxy';
93
95
  export * from './Components/APICall/parseUrl';
94
96
  export * from './Components/Image/imageSettings.config';
97
+ export * from './Components/Triggers/Gmail.trigger';
98
+ export * from './Components/Triggers/JobScheduler.trigger';
99
+ export * from './Components/Triggers/Trigger.class';
100
+ export * from './Components/Triggers/WhatsApp.trigger';
95
101
  export * from './subsystems/AgentManager/Agent.class';
96
102
  export * from './subsystems/AgentManager/Agent.helper';
97
103
  export * from './subsystems/AgentManager/AgentLogger.class';
@@ -116,6 +122,10 @@ export * from './subsystems/AgentManager/AgentData.service/AgentDataConnector';
116
122
  export * from './subsystems/AgentManager/AgentData.service/index';
117
123
  export * from './subsystems/AgentManager/Component.service/ComponentConnector';
118
124
  export * from './subsystems/AgentManager/Component.service/index';
125
+ export * from './subsystems/AgentManager/Scheduler.service/index';
126
+ export * from './subsystems/AgentManager/Scheduler.service/Job.class';
127
+ export * from './subsystems/AgentManager/Scheduler.service/Schedule.class';
128
+ export * from './subsystems/AgentManager/Scheduler.service/SchedulerConnector';
119
129
  export * from './subsystems/ComputeManager/Code.service/CodeConnector';
120
130
  export * from './subsystems/ComputeManager/Code.service/index';
121
131
  export * from './subsystems/IO/CLI.service/CLIConnector';
@@ -144,6 +154,8 @@ export * from './subsystems/Security/AccessControl/AccessRequest.class';
144
154
  export * from './subsystems/Security/AccessControl/ACL.class';
145
155
  export * from './subsystems/Security/Account.service/AccountConnector';
146
156
  export * from './subsystems/Security/Account.service/index';
157
+ export * from './subsystems/Security/Credentials/Credentials.class';
158
+ export * from './subsystems/Security/Credentials/ManagedOAuth2Credentials.class';
147
159
  export * from './subsystems/Security/ManagedVault.service/index';
148
160
  export * from './subsystems/Security/ManagedVault.service/ManagedVaultConnector';
149
161
  export * from './subsystems/Security/Vault.service/index';
@@ -153,6 +165,7 @@ export * from './subsystems/AgentManager/AgentData.service/connectors/CLIAgentDa
153
165
  export * from './subsystems/AgentManager/AgentData.service/connectors/LocalAgentDataConnector.class';
154
166
  export * from './subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class';
155
167
  export * from './subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class';
168
+ export * from './subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class';
156
169
  export * from './subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class';
157
170
  export * from './subsystems/IO/Log.service/connectors/ConsoleLog.class';
158
171
  export * from './subsystems/IO/NKV.service/connectors/NKVLocalStorage.class';
package/src/index.ts.bak CHANGED
@@ -54,12 +54,14 @@ export * from './Core/boot';
54
54
  export * from './Core/Connector.class';
55
55
  export * from './Core/ConnectorsService';
56
56
  export * from './Core/DummyConnector';
57
+ export * from './Core/ExternalEventsReceiver';
57
58
  export * from './Core/HookService';
58
59
  export * from './Core/SmythRuntime.class';
59
60
  export * from './Core/SystemEvents';
60
61
  export * from './helpers/AWSLambdaCode.helper';
61
62
  export * from './helpers/BinaryInput.helper';
62
63
  export * from './helpers/Conversation.helper';
64
+ export * from './helpers/Crypto.helper';
63
65
  export * from './helpers/ECMASandbox.helper';
64
66
  export * from './helpers/JsonContent.helper';
65
67
  export * from './helpers/LocalCache.helper';
@@ -92,6 +94,10 @@ export * from './Components/APICall/parseHeaders';
92
94
  export * from './Components/APICall/parseProxy';
93
95
  export * from './Components/APICall/parseUrl';
94
96
  export * from './Components/Image/imageSettings.config';
97
+ export * from './Components/Triggers/Gmail.trigger';
98
+ export * from './Components/Triggers/JobScheduler.trigger';
99
+ export * from './Components/Triggers/Trigger.class';
100
+ export * from './Components/Triggers/WhatsApp.trigger';
95
101
  export * from './subsystems/AgentManager/Agent.class';
96
102
  export * from './subsystems/AgentManager/Agent.helper';
97
103
  export * from './subsystems/AgentManager/AgentLogger.class';
@@ -116,6 +122,10 @@ export * from './subsystems/AgentManager/AgentData.service/AgentDataConnector';
116
122
  export * from './subsystems/AgentManager/AgentData.service/index';
117
123
  export * from './subsystems/AgentManager/Component.service/ComponentConnector';
118
124
  export * from './subsystems/AgentManager/Component.service/index';
125
+ export * from './subsystems/AgentManager/Scheduler.service/index';
126
+ export * from './subsystems/AgentManager/Scheduler.service/Job.class';
127
+ export * from './subsystems/AgentManager/Scheduler.service/Schedule.class';
128
+ export * from './subsystems/AgentManager/Scheduler.service/SchedulerConnector';
119
129
  export * from './subsystems/ComputeManager/Code.service/CodeConnector';
120
130
  export * from './subsystems/ComputeManager/Code.service/index';
121
131
  export * from './subsystems/IO/CLI.service/CLIConnector';
@@ -144,6 +154,8 @@ export * from './subsystems/Security/AccessControl/AccessRequest.class';
144
154
  export * from './subsystems/Security/AccessControl/ACL.class';
145
155
  export * from './subsystems/Security/Account.service/AccountConnector';
146
156
  export * from './subsystems/Security/Account.service/index';
157
+ export * from './subsystems/Security/Credentials/Credentials.class';
158
+ export * from './subsystems/Security/Credentials/ManagedOAuth2Credentials.class';
147
159
  export * from './subsystems/Security/ManagedVault.service/index';
148
160
  export * from './subsystems/Security/ManagedVault.service/ManagedVaultConnector';
149
161
  export * from './subsystems/Security/Vault.service/index';
@@ -153,6 +165,7 @@ export * from './subsystems/AgentManager/AgentData.service/connectors/CLIAgentDa
153
165
  export * from './subsystems/AgentManager/AgentData.service/connectors/LocalAgentDataConnector.class';
154
166
  export * from './subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class';
155
167
  export * from './subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class';
168
+ export * from './subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class';
156
169
  export * from './subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class';
157
170
  export * from './subsystems/IO/Log.service/connectors/ConsoleLog.class';
158
171
  export * from './subsystems/IO/NKV.service/connectors/NKVLocalStorage.class';