@smythos/sre 1.6.13 → 1.7.1

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 (83) hide show
  1. package/CHANGELOG +15 -0
  2. package/dist/index.js +52 -46
  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/Conversation.helper.d.ts +2 -0
  14. package/dist/types/helpers/Crypto.helper.d.ts +8 -0
  15. package/dist/types/index.d.ts +13 -0
  16. package/dist/types/subsystems/AgentManager/Agent.class.d.ts +4 -2
  17. package/dist/types/subsystems/AgentManager/AgentData.service/AgentDataConnector.d.ts +13 -0
  18. package/dist/types/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.d.ts +1 -4
  19. package/dist/types/subsystems/AgentManager/Scheduler.service/Job.class.d.ts +29 -6
  20. package/dist/types/subsystems/AgentManager/Scheduler.service/SchedulerConnector.d.ts +11 -3
  21. package/dist/types/subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class.d.ts +31 -7
  22. package/dist/types/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.d.ts +2 -5
  23. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.d.ts +3 -6
  24. package/dist/types/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.d.ts +7 -0
  25. package/dist/types/subsystems/LLMManager/LLM.service/connectors/xAI.class.d.ts +2 -5
  26. package/dist/types/types/Agent.types.d.ts +1 -0
  27. package/dist/types/types/LLM.types.d.ts +2 -5
  28. package/dist/types/types/SRE.types.d.ts +4 -1
  29. package/package.json +6 -2
  30. package/src/Components/APICall/OAuth.helper.ts +30 -35
  31. package/src/Components/APIEndpoint.class.ts +25 -6
  32. package/src/Components/Component.class.ts +11 -0
  33. package/src/Components/Triggers/Gmail.trigger.ts +282 -0
  34. package/src/Components/Triggers/JobScheduler.trigger.ts +45 -0
  35. package/src/Components/Triggers/README.md +3 -0
  36. package/src/Components/Triggers/Trigger.class.ts +101 -0
  37. package/src/Components/Triggers/WhatsApp.trigger.ts +219 -0
  38. package/src/Components/index.ts +8 -0
  39. package/src/Core/AgentProcess.helper.ts +4 -6
  40. package/src/Core/Connector.class.ts +11 -3
  41. package/src/Core/ConnectorsService.ts +5 -0
  42. package/src/Core/ExternalEventsReceiver.ts +317 -0
  43. package/src/Core/HookService.ts +20 -6
  44. package/src/Core/SmythRuntime.class.ts +7 -0
  45. package/src/Core/SystemEvents.ts +17 -0
  46. package/src/Core/boot.ts +2 -0
  47. package/src/helpers/Conversation.helper.ts +35 -11
  48. package/src/helpers/Crypto.helper.ts +28 -0
  49. package/src/helpers/Sysconfig.helper.ts +50 -14
  50. package/src/index.ts +13 -0
  51. package/src/index.ts.bak +13 -0
  52. package/src/subsystems/AGENTS.md +594 -0
  53. package/src/subsystems/AgentManager/Agent.class.ts +71 -21
  54. package/src/subsystems/AgentManager/AgentData.service/AgentDataConnector.ts +24 -1
  55. package/src/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.ts +2 -2
  56. package/src/subsystems/AgentManager/AgentRuntime.class.ts +34 -5
  57. package/src/subsystems/AgentManager/Scheduler.service/Job.class.ts +414 -0
  58. package/src/subsystems/AgentManager/Scheduler.service/Schedule.class.ts +200 -0
  59. package/src/subsystems/AgentManager/Scheduler.service/SchedulerConnector.ts +200 -0
  60. package/src/subsystems/AgentManager/Scheduler.service/connectors/LocalScheduler.class.ts +767 -0
  61. package/src/subsystems/AgentManager/Scheduler.service/index.ts +11 -0
  62. package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +1 -1
  63. package/src/subsystems/LLMManager/LLM.service/LLMCredentials.helper.ts +61 -2
  64. package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +3 -0
  65. package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +3 -1
  66. package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +5 -1
  67. package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +247 -56
  68. package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +3 -0
  69. package/src/subsystems/LLMManager/LLM.service/connectors/Ollama.class.ts +28 -21
  70. package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +3 -0
  71. package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +121 -33
  72. package/src/subsystems/LLMManager/LLM.service/connectors/openai/OpenAIConnector.class.ts +38 -27
  73. package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +115 -18
  74. package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +3 -0
  75. package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +1 -6
  76. package/src/subsystems/MemoryManager/LLMContext.ts +3 -8
  77. package/src/subsystems/MemoryManager/RuntimeContext.ts +10 -9
  78. package/src/subsystems/Security/Credentials/Credentials.class.ts +1 -0
  79. package/src/subsystems/Security/Credentials/ManagedOAuth2Credentials.class.ts +106 -0
  80. package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +2 -2
  81. package/src/types/Agent.types.ts +1 -0
  82. package/src/types/LLM.types.ts +2 -2
  83. package/src/types/SRE.types.ts +3 -0
@@ -25,7 +25,7 @@ export class LLMContext {
25
25
  public contextLength: number;
26
26
 
27
27
  private _messages: any[] = [];
28
- public get messages() {
28
+ public get messages() {
29
29
  return this._messages;
30
30
  }
31
31
 
@@ -36,16 +36,11 @@ export class LLMContext {
36
36
  *
37
37
  * @param source a messages[] object, or smyth file system uri (smythfs://...)
38
38
  */
39
- constructor(
40
- private llmInference,
41
- _systemPrompt: string = '',
42
- llmContextStore?: ILLMContextStore,
43
- ) {
39
+ constructor(private llmInference, _systemPrompt: string = '', llmContextStore?: ILLMContextStore) {
44
40
  this._llmCache = new LLMCache(AccessCandidate.team(this.llmInference.teamId));
45
41
  //this._systemPrompt = _systemPrompt;
46
42
  this.systemPrompt = _systemPrompt;
47
43
 
48
-
49
44
  if (llmContextStore) {
50
45
  this._llmContextStore = llmContextStore;
51
46
  this._llmContextStore.load().then((messages) => {
@@ -57,7 +52,7 @@ export class LLMContext {
57
52
 
58
53
  private push(...message: any[]) {
59
54
  this._messages.push(...message);
60
-
55
+
61
56
  if (this._llmContextStore) {
62
57
  this._llmContextStore.save(this._messages);
63
58
  }
@@ -92,11 +92,11 @@ export class RuntimeContext extends EventEmitter {
92
92
  private initRuntimeContext() {
93
93
  if (this._runtimeFileReady) return;
94
94
 
95
- const endpointDBGCall = this.runtime.xDebugId?.startsWith('dbg-'); //weak check for debug session, we need to improve this
95
+ //const endpointDBGCall = this.runtime.xDebugId?.startsWith('dbg-'); //weak check for debug session, we need to improve this
96
96
  console.debug('Init Agent Context', this.ctxFile, AccessCandidate.agent(this.runtime.agent.id));
97
97
  const agent = this.runtime.agent;
98
- let method = (agent.agentRequest.method || 'POST').toUpperCase();
99
- const endpoint = agent.endpoints?.[agent.agentRequest.path]?.[method];
98
+ //let method = (agent.agentRequest.method || 'POST').toUpperCase();
99
+ //const endpoint = agent.endpoints?.[agent.agentRequest.path]?.[method];
100
100
 
101
101
  let ctxData: any = {};
102
102
 
@@ -115,12 +115,13 @@ export class RuntimeContext extends EventEmitter {
115
115
  ctx: { active: false, name: ctxData.components[cptId].name },
116
116
  };
117
117
 
118
- const cpt = ctxData.components[cptId];
119
- //if this debug session was initiated from an endpoint, we mark the endpoint component as active
120
- if (endpoint && endpoint.id != undefined && cpt.id == endpoint.id && endpointDBGCall) {
121
- //cpt.dbg.active = true;
122
- cpt.ctx.active = true;
123
- }
118
+ // //TODO : the endpoint initialization logic should be moved to the AgentRuntime class
119
+ // const cpt = ctxData.components[cptId];
120
+ // //if this debug session was initiated from an endpoint, we mark the endpoint component as active
121
+ // if (endpoint && endpoint.id != undefined && cpt.id == endpoint.id && endpointDBGCall) {
122
+ // //cpt.dbg.active = true;
123
+ // cpt.ctx.active = true;
124
+ // }
124
125
  }
125
126
 
126
127
  await this._cacheConnector
@@ -0,0 +1 @@
1
+ export class Credentials {}
@@ -0,0 +1,106 @@
1
+ import { ConnectorService } from '@sre/Core/ConnectorsService';
2
+ import { Credentials } from './Credentials.class';
3
+ import { AccessCandidate } from '../AccessControl/AccessCandidate.class';
4
+
5
+ export class ManagedOAuth2Credentials extends Credentials {
6
+ #accessToken: string;
7
+ #refreshToken: string;
8
+ #expiresIn: number;
9
+ #scope: string;
10
+ #tokenUrl: string;
11
+ #service: string;
12
+ #clientId: string;
13
+ #clientSecret: string;
14
+
15
+ public get accessToken(): string {
16
+ return this.#accessToken;
17
+ }
18
+ public get refreshToken(): string {
19
+ return this.#refreshToken;
20
+ }
21
+ public get expiresIn(): number {
22
+ return this.#expiresIn;
23
+ }
24
+ public get scope(): string {
25
+ return this.#scope;
26
+ }
27
+ public get tokenUrl(): string {
28
+ return this.#tokenUrl;
29
+ }
30
+ public get service(): string {
31
+ return this.#service;
32
+ }
33
+
34
+ private constructor(data: any) {
35
+ super();
36
+ this.parseData(data);
37
+ }
38
+
39
+ static async load(keyId: string, candidate: AccessCandidate): Promise<ManagedOAuth2Credentials> {
40
+ const managedVault = ConnectorService.getManagedVaultConnector();
41
+ const result = await managedVault.requester(candidate).get(keyId);
42
+ const data = typeof result === 'object' ? result : JSON.parse(result || '{}');
43
+
44
+ return new ManagedOAuth2Credentials(data);
45
+ }
46
+
47
+ private parseData(data: any) {
48
+ //SRE v1.0 format
49
+
50
+ //SRE v1.5.0+ format
51
+ if (!data.auth_data || !data.auth_settings) throw new Error('oAuth2Manager:Invalid data format');
52
+
53
+ this.#accessToken = data.auth_data.primary;
54
+ this.#refreshToken = data.auth_data.secondary;
55
+ this.#expiresIn = data.auth_data.expires_in;
56
+ this.#scope = data.auth_settings.scope;
57
+ this.#tokenUrl = data.auth_settings.tokenURL;
58
+ this.#service = data.auth_settings.service;
59
+ this.#clientId = data.auth_settings.clientID;
60
+ this.#clientSecret = data.auth_settings.clientSecret;
61
+ }
62
+
63
+ /**
64
+ * Get a fresh access token using the refresh token
65
+ */
66
+ public async refreshAccessToken() {
67
+ console.log('Refreshing access token...');
68
+
69
+ const tokenUrl = this.#tokenUrl;
70
+ const body = new URLSearchParams({
71
+ client_id: this.#clientId,
72
+ client_secret: this.#clientSecret,
73
+ refresh_token: this.#refreshToken,
74
+ grant_type: 'refresh_token',
75
+ });
76
+
77
+ try {
78
+ const res = await fetch(tokenUrl, {
79
+ method: 'POST',
80
+ headers: {
81
+ 'Content-Type': 'application/x-www-form-urlencoded',
82
+ },
83
+ body: body.toString(),
84
+ });
85
+
86
+ const text = await res.text();
87
+ let json: any;
88
+ try {
89
+ json = JSON.parse(text);
90
+ } catch {
91
+ throw new Error(`Invalid JSON response: ${text}`);
92
+ }
93
+
94
+ if (!res.ok) {
95
+ const errorMsg = json.error_description || json.error?.message || json.error || text;
96
+ throw new Error(`HTTP ${res.status}: ${errorMsg}`);
97
+ }
98
+
99
+ this.#accessToken = json.access_token;
100
+ this.#expiresIn = Date.now() + json.expires_in * 1000;
101
+ return this.#accessToken;
102
+ } catch (error: any) {
103
+ throw new Error(`Failed to refresh access token: ${error.message}`);
104
+ }
105
+ }
106
+ }
@@ -51,12 +51,12 @@ export class JSONFileVault extends VaultConnector {
51
51
  const relativeSearchLocations = ['vault.json', 'vault/vault.json', '.sre/vault.json'];
52
52
  found = findValidResourcePath(relativeSearchLocations, (dir, success, nextDir) => {
53
53
  if (!success) {
54
- logger.warn('Vault file not found in:', nextDir);
54
+ logger.warn('Vault file not found in:', dir);
55
55
  }
56
56
  });
57
57
 
58
58
  if (found) {
59
- logger.warn('Using alternative vault file found in : ', found);
59
+ logger.warn('Found a Vault file in : ', found, ' I will use this one.');
60
60
  return found;
61
61
  }
62
62
 
@@ -29,6 +29,7 @@ export interface IAgent {
29
29
  sessionTag: any;
30
30
  callerSessionId: any;
31
31
  apiBasePath: any;
32
+ triggerBasePath: any;
32
33
  agentRuntime: AgentRuntime | any;
33
34
  usingTestDomain: any;
34
35
  domain: any;
@@ -387,8 +387,8 @@ export type TLLMMessageBlock = {
387
387
  | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam>;
388
388
  parts?: {
389
389
  text?: string;
390
- functionCall?: { name: string; args: string };
391
- functionResponse?: { name: string; response: { name: string; content: string } };
390
+ functionCall?: { name: string; args: string | Record<string, any> };
391
+ functionResponse?: { name: string; response: any };
392
392
  }[]; // for Google Vertex AI
393
393
  tool_calls?: ToolData[];
394
394
  };
@@ -13,6 +13,7 @@ import { LogService } from '@sre/IO/Log.service';
13
13
  import { ComponentService } from '@sre/AgentManager/Component.service';
14
14
  import { ModelsProviderService } from '@sre/LLMManager/ModelsProvider.service';
15
15
  import { CodeService } from '@sre/ComputeManager/Code.service';
16
+ import { SchedulerService } from '@sre/AgentManager/Scheduler.service';
16
17
 
17
18
  export type TServiceRegistry = {
18
19
  Storage?: StorageService;
@@ -30,6 +31,7 @@ export type TServiceRegistry = {
30
31
  Component?: ComponentService;
31
32
  ModelsProvider?: ModelsProviderService;
32
33
  Code?: CodeService;
34
+ Scheduler?: SchedulerService;
33
35
  };
34
36
 
35
37
  export enum TConnectorService {
@@ -48,6 +50,7 @@ export enum TConnectorService {
48
50
  Component = 'Component',
49
51
  ModelsProvider = 'ModelsProvider',
50
52
  Code = 'Code',
53
+ Scheduler = 'Scheduler',
51
54
  }
52
55
 
53
56
  export type SREConnectorConfig = {