@smythos/sre 1.5.64 → 1.5.66

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.
@@ -1,19 +1,14 @@
1
1
  import { Component } from './Component.class';
2
2
  import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import Joi from 'joi';
3
4
  export declare class FTimestamp extends Component {
5
+ protected configSchema: Joi.ObjectSchema<any>;
4
6
  constructor();
5
7
  init(): void;
6
8
  process(input: any, config: any, agent: Agent): Promise<{
7
- Timestamp: number;
9
+ Timestamp: string | number;
8
10
  _error: any;
9
11
  _debug: string;
10
12
  _debug_time: number;
11
- hash?: undefined;
12
- } | {
13
- hash: any;
14
- _error: any;
15
- _debug: string;
16
- _debug_time: number;
17
- Timestamp?: undefined;
18
13
  }>;
19
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smythos/sre",
3
- "version": "1.5.64",
3
+ "version": "1.5.66",
4
4
  "description": "Smyth Runtime Environment",
5
5
  "author": "Alaa-eddine KADDOURI",
6
6
  "license": "MIT",
@@ -116,7 +116,8 @@ export class Component {
116
116
  }
117
117
  async postProcess(output, config, agent: Agent): Promise<any> {
118
118
  if (output?.result) {
119
- delete output?.result?._debug;
119
+ if (!agent.agentRuntime?.debug) delete output?.result?._debug;
120
+
120
121
  if (!output?.result?._error) delete output?.result?._error;
121
122
  }
122
123
  return output;
@@ -1,25 +1,66 @@
1
1
  import { Component } from './Component.class';
2
2
  import { IAgent as Agent } from '@sre/types/Agent.types';
3
+ import Joi from 'joi';
4
+ import dayjs from 'dayjs';
3
5
 
4
6
  export class FTimestamp extends Component {
7
+ protected configSchema = Joi.object({
8
+ format: Joi.alternatives()
9
+ .try(Joi.string().valid('unix', 'iso', 'timestamp'), Joi.string().pattern(/^[YMDHhmsSSZzAa\s\-\/:,\.]*$/, 'custom dayjs format'))
10
+ .default('unix')
11
+ .allow(null)
12
+ .label('Timestamp Format')
13
+ .messages({
14
+ 'string.pattern.name': 'Invalid format string: {#value}',
15
+ }),
16
+ });
17
+
5
18
  constructor() {
6
19
  super();
7
20
  }
8
21
  init() {}
9
22
  async process(input, config, agent: Agent) {
10
23
  await super.process(input, config, agent);
24
+
11
25
  const logger = this.createComponentLogger(agent, config);
26
+
27
+ const validationResult = await this.validateConfig(config);
28
+ if (validationResult._error) {
29
+ return {
30
+ Timestamp: undefined,
31
+ _error: validationResult._error,
32
+ _debug: logger.output,
33
+ _debug_time: logger.elapsedTime,
34
+ };
35
+ }
12
36
  try {
13
37
  const _error = undefined;
14
- const format = config.data.format; //TODO set timestamp format
15
- const Timestamp = Date.now();
16
- logger.debug(`Timestamp : ${Timestamp}`);
38
+ const format = config.data.format || 'unix';
39
+ const now = dayjs();
40
+
41
+ let Timestamp: number | string;
42
+
43
+ switch (format) {
44
+ case 'unix':
45
+ case 'timestamp':
46
+ Timestamp = Date.now();
47
+ logger.debug(`Unix timestamp: ${Timestamp}`);
48
+ break;
49
+ case 'iso':
50
+ Timestamp = now.toISOString();
51
+ logger.debug(`ISO timestamp: ${Timestamp}`);
52
+ break;
53
+ default:
54
+ Timestamp = now.format(format);
55
+ logger.debug(`Custom formatted timestamp (${format}): ${Timestamp}`);
56
+ break;
57
+ }
17
58
 
18
59
  return { Timestamp, _error, _debug: logger.output, _debug_time: logger.elapsedTime };
19
60
  } catch (err: any) {
20
61
  const _error = err?.response?.data || err?.message || err.toString();
21
- logger.error(` Error processing data \n${_error}\n`);
22
- return { hash: undefined, _error, _debug: logger.output, _debug_time: logger.elapsedTime };
62
+ logger.error(` Error processing timestamp \n${_error}\n`);
63
+ return { Timestamp: undefined, _error, _debug: logger.output, _debug_time: logger.elapsedTime };
23
64
  }
24
65
  }
25
66
  }
@@ -14,9 +14,9 @@ export class MCPClient extends Component {
14
14
  model: Joi.string().optional(),
15
15
  openAiModel: Joi.string().optional(), // for backward compatibility
16
16
  mcpUrl: Joi.string().max(2048).uri().required().description('URL of the MCP'),
17
- descForModel: Joi.string().max(5000).required().allow('').label('Description for Model'),
17
+ descForModel: Joi.string().max(5000).allow('').label('Description for Model'),
18
18
  name: Joi.string().max(500).required().allow(''),
19
- desc: Joi.string().max(5000).required().allow('').label('Description'),
19
+ desc: Joi.string().max(5000).allow('').label('Description'),
20
20
  logoUrl: Joi.string().max(8192).allow(''),
21
21
  id: Joi.string().max(200),
22
22
  version: Joi.string().max(100).allow(''),
@@ -70,7 +70,7 @@ export class MCPClient extends Component {
70
70
  ],
71
71
  paths: {},
72
72
  },
73
- { agentId: agent?.id },
73
+ { agentId: agent?.id }
74
74
  );
75
75
 
76
76
  for (const tool of toolsData.tools) {
@@ -107,32 +107,31 @@ export class MCPClient extends Component {
107
107
  }
108
108
  private async connectMCP(mcpUrl: string) {
109
109
  const client = new Client({ name: 'auto-client', version: '1.0.0' });
110
-
110
+
111
111
  // 1) Try Streamable HTTP first
112
112
  try {
113
- const st = new StreamableHTTPClientTransport(new URL(mcpUrl));
114
- await client.connect(st);
115
- console.debug('Connected to MCP using Streamable HTTP');
116
- return { client, transport: 'streamable' as const };
113
+ const st = new StreamableHTTPClientTransport(new URL(mcpUrl));
114
+ await client.connect(st);
115
+ console.debug('Connected to MCP using Streamable HTTP');
116
+ return { client, transport: 'streamable' as const };
117
117
  } catch (e: any) {
118
- console.debug('Failed to connect to MCP using Streamable HTTP, falling back to SSE');
119
- // 2) If clearly unsupported, fall back to SSE
120
- const msg = String(e?.message || e);
121
- const isUnsupported =
122
- /404|405|ENOTFOUND|ECONNREFUSED|CORS/i.test(msg);
123
-
124
- // 406 means wrong/missing Accept for Streamable → retry Streamable with proper header
125
- const isAcceptProblem = /406|Not Acceptable|text\/event-stream/i.test(msg);
126
- if (isAcceptProblem) {
127
- throw new Error('Server is Streamable; include Accept: application/json, text/event-stream');
128
- }
129
-
130
- if (!isUnsupported) throw e;
131
-
132
- // SSE fallback
133
- const sse = new SSEClientTransport(new URL(mcpUrl));
134
- await client.connect(sse);
135
- return { client, transport: 'sse' as const };
118
+ console.debug('Failed to connect to MCP using Streamable HTTP, falling back to SSE');
119
+ // 2) If clearly unsupported, fall back to SSE
120
+ const msg = String(e?.message || e);
121
+ const isUnsupported = /404|405|ENOTFOUND|ECONNREFUSED|CORS/i.test(msg);
122
+
123
+ // 406 means wrong/missing Accept for Streamable → retry Streamable with proper header
124
+ const isAcceptProblem = /406|Not Acceptable|text\/event-stream/i.test(msg);
125
+ if (isAcceptProblem) {
126
+ throw new Error('Server is Streamable; include Accept: application/json, text/event-stream');
127
+ }
128
+
129
+ if (!isUnsupported) throw e;
130
+
131
+ // SSE fallback
132
+ const sse = new SSEClientTransport(new URL(mcpUrl));
133
+ await client.connect(sse);
134
+ return { client, transport: 'sse' as const };
136
135
  }
137
- }
136
+ }
138
137
  }