@smythos/sre 1.7.20 → 1.7.41
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/dist/index.js +134 -89
- package/dist/index.js.map +1 -1
- package/dist/types/Components/AgentPlugin.class.d.ts +1 -1
- package/dist/types/Components/DataSourceIndexer.class.d.ts +4 -12
- package/dist/types/Components/GenAILLM.class.d.ts +5 -5
- package/dist/types/Components/RAG/DataSourceCleaner.class.d.ts +4 -4
- package/dist/types/Components/RAG/DataSourceComponent.class.d.ts +5 -1
- package/dist/types/Components/index.d.ts +3 -3
- package/dist/types/config.d.ts +1 -0
- package/dist/types/helpers/Conversation.helper.d.ts +10 -13
- package/dist/types/helpers/TemplateString.helper.d.ts +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/subsystems/IO/VectorDB.service/VectorDBConnector.d.ts +1 -0
- package/dist/types/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.d.ts +1 -0
- package/dist/types/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.d.ts +11 -4
- package/dist/types/subsystems/IO/VectorDB.service/embed/index.d.ts +5 -0
- package/dist/types/subsystems/LLMManager/LLM.helper.d.ts +19 -0
- package/dist/types/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.d.ts +15 -10
- package/dist/types/subsystems/LLMManager/ModelsProvider.service/connectors/JSONModelsProvider.class.d.ts +35 -0
- package/dist/types/subsystems/Security/Account.service/AccountConnector.d.ts +2 -2
- package/dist/types/subsystems/Security/Vault.service/connectors/SecretsManager.class.d.ts +2 -3
- package/dist/types/types/LLM.types.d.ts +23 -0
- package/dist/types/types/VectorDB.types.d.ts +4 -0
- package/dist/types/utils/string.utils.d.ts +1 -0
- package/package.json +3 -3
- package/src/Components/APIEndpoint.class.ts +1 -6
- package/src/Components/AgentPlugin.class.ts +20 -3
- package/src/Components/Classifier.class.ts +79 -16
- package/src/Components/Component.class.ts +14 -1
- package/src/Components/ForEach.class.ts +34 -6
- package/src/Components/GenAILLM.class.ts +75 -34
- package/src/Components/LLMAssistant.class.ts +56 -21
- package/src/Components/RAG/DataSourceCleaner.class.ts +180 -0
- package/src/Components/RAG/DataSourceComponent.class.ts +137 -0
- package/src/Components/RAG/DataSourceIndexer.class.ts +260 -0
- package/src/Components/{DataSourceLookup.class.ts → RAG/DataSourceLookup.class.ts} +96 -3
- package/src/Components/ScrapflyWebScrape.class.ts +7 -0
- package/src/Components/ServerlessCode.class.ts +1 -4
- package/src/Components/index.ts +3 -3
- package/src/config.ts +1 -0
- package/src/helpers/Conversation.helper.ts +112 -26
- package/src/helpers/S3Cache.helper.ts +2 -1
- package/src/helpers/TemplateString.helper.ts +6 -5
- package/src/index.ts +213 -212
- package/src/index.ts.bak +213 -212
- package/src/subsystems/IO/NKV.service/connectors/NKVRedis.class.ts +3 -1
- package/src/subsystems/IO/VectorDB.service/VectorDBConnector.ts +1 -0
- package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +145 -19
- package/src/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.ts +67 -22
- package/src/subsystems/IO/VectorDB.service/embed/GoogleEmbedding.ts +1 -0
- package/src/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.ts +2 -1
- package/src/subsystems/IO/VectorDB.service/embed/index.ts +16 -0
- package/src/subsystems/LLMManager/LLM.helper.ts +25 -0
- package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +1 -1
- package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +35 -10
- package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +12 -4
- package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +4 -4
- package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +192 -139
- package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +17 -5
- package/src/subsystems/LLMManager/LLM.service/connectors/Ollama.class.ts +18 -3
- package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +14 -5
- package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +6 -4
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ChatCompletionsApiInterface.ts +5 -5
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/ResponsesApiInterface.ts +8 -3
- package/src/subsystems/LLMManager/LLM.service/connectors/openai/apiInterfaces/utils.ts +1 -1
- package/src/subsystems/LLMManager/LLM.service/connectors/xAI.class.ts +9 -8
- package/src/subsystems/LLMManager/ModelsProvider.service/connectors/JSONModelsProvider.class.ts +92 -1
- package/src/subsystems/ObservabilityManager/Telemetry.service/connectors/OTel/OTel.class.ts +260 -17
- package/src/subsystems/Security/Account.service/AccountConnector.ts +3 -3
- package/src/subsystems/Security/Vault.service/connectors/SecretsManager.class.ts +8 -63
- package/src/types/LLM.types.ts +24 -0
- package/src/types/VectorDB.types.ts +4 -0
- package/src/utils/array.utils.ts +11 -0
- package/src/utils/base64.utils.ts +1 -1
- package/src/utils/data.utils.ts +6 -4
- package/src/utils/string.utils.ts +3 -192
- package/src/Components/DataSourceCleaner.class.ts +0 -92
- package/src/Components/DataSourceIndexer.class.ts +0 -181
|
@@ -5,7 +5,7 @@ import { IAccessCandidate } from '@sre/types/ACL.types';
|
|
|
5
5
|
import { TelemetryConnector } from '../../TelemetryConnector';
|
|
6
6
|
import { AgentCallLog } from '@sre/types/AgentLogger.types';
|
|
7
7
|
|
|
8
|
-
import { trace, context, SpanStatusCode, Tracer } from '@opentelemetry/api';
|
|
8
|
+
import { trace, context, SpanStatusCode, Tracer, propagation } from '@opentelemetry/api';
|
|
9
9
|
import { Logger as OTelLogger, logs, SeverityNumber } from '@opentelemetry/api-logs';
|
|
10
10
|
import { OTelContextRegistry } from './OTelContextRegistry';
|
|
11
11
|
import { HookService, THook } from '@sre/Core/HookService';
|
|
@@ -20,8 +20,9 @@ import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
|
|
|
20
20
|
import { IAgent } from '@sre/types/Agent.types';
|
|
21
21
|
import { Conversation } from '@sre/helpers/Conversation.helper';
|
|
22
22
|
import { TLLMEvent } from '@sre/types/LLM.types';
|
|
23
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
23
24
|
|
|
24
|
-
const outputLogger = Logger('
|
|
25
|
+
const outputLogger = Logger('OTel');
|
|
25
26
|
|
|
26
27
|
export type OTelLogConfig = {
|
|
27
28
|
endpoint: string;
|
|
@@ -50,7 +51,7 @@ export type OTelLogConfig = {
|
|
|
50
51
|
*/
|
|
51
52
|
redactFields?: string[];
|
|
52
53
|
};
|
|
53
|
-
|
|
54
|
+
const OTEL_DEBUG_LOGS = true;
|
|
54
55
|
export class OTel extends TelemetryConnector {
|
|
55
56
|
public name: string = 'OTel';
|
|
56
57
|
public id: string;
|
|
@@ -61,6 +62,10 @@ export class OTel extends TelemetryConnector {
|
|
|
61
62
|
|
|
62
63
|
constructor(protected _settings: OTelLogConfig) {
|
|
63
64
|
super();
|
|
65
|
+
if (!_settings.endpoint) {
|
|
66
|
+
outputLogger.warn('OTel initialization skipped, endpoint is not set');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
64
69
|
|
|
65
70
|
outputLogger.log(`Initializing Tracer ...`);
|
|
66
71
|
|
|
@@ -208,6 +213,8 @@ export class OTel extends TelemetryConnector {
|
|
|
208
213
|
|
|
209
214
|
const createToolInfoHandler = function (hookContext) {
|
|
210
215
|
return function (toolInfo: any) {
|
|
216
|
+
const accessCandidate = AccessCandidate.agent(hookContext?.agentId);
|
|
217
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createToolInfoHandler started', accessCandidate);
|
|
211
218
|
if (!hookContext.curLLMGenSpan || !hookContext.convSpan) return;
|
|
212
219
|
|
|
213
220
|
const modelId = toolInfo.model;
|
|
@@ -238,6 +245,7 @@ export class OTel extends TelemetryConnector {
|
|
|
238
245
|
|
|
239
246
|
hookContext.curLLMGenSpan.end();
|
|
240
247
|
delete hookContext.curLLMGenSpan;
|
|
248
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createToolInfoHandler completed', accessCandidate);
|
|
241
249
|
};
|
|
242
250
|
};
|
|
243
251
|
|
|
@@ -245,6 +253,8 @@ export class OTel extends TelemetryConnector {
|
|
|
245
253
|
return function (data: any, reqInfo: any) {
|
|
246
254
|
if (!hookContext.convSpan) return;
|
|
247
255
|
if (hookContext.curLLMGenSpan) return;
|
|
256
|
+
const accessCandidate = AccessCandidate.agent(hookContext?.agentId);
|
|
257
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createDataHandler started', reqInfo?.requestId, accessCandidate);
|
|
248
258
|
|
|
249
259
|
const modelId = reqInfo.model;
|
|
250
260
|
const contextWindow = reqInfo.contextWindow;
|
|
@@ -273,6 +283,7 @@ export class OTel extends TelemetryConnector {
|
|
|
273
283
|
attributes: {
|
|
274
284
|
'agent.id': hookContext.agentId,
|
|
275
285
|
'conv.id': hookContext.processId,
|
|
286
|
+
'team.id': hookContext.teamId,
|
|
276
287
|
'llm.model': modelId || 'unknown',
|
|
277
288
|
},
|
|
278
289
|
},
|
|
@@ -285,13 +296,15 @@ export class OTel extends TelemetryConnector {
|
|
|
285
296
|
'context.preview': JSON.stringify(lastContext).substring(0, 200),
|
|
286
297
|
});
|
|
287
298
|
hookContext.curLLMGenSpan = llmGenSpan;
|
|
299
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createDataHandler completed', reqInfo?.requestId, accessCandidate);
|
|
288
300
|
};
|
|
289
301
|
};
|
|
290
302
|
|
|
291
303
|
const createRequestedHandler = function (hookContext) {
|
|
292
304
|
return function (reqInfo: any) {
|
|
293
305
|
if (!hookContext.convSpan) return;
|
|
294
|
-
|
|
306
|
+
const accessCandidate = AccessCandidate.agent(hookContext?.agentId);
|
|
307
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createRequestedHandler started', reqInfo?.requestId, accessCandidate);
|
|
295
308
|
if (!hookContext.latencySpans) hookContext.latencySpans = {};
|
|
296
309
|
const contextWindow = reqInfo.contextWindow;
|
|
297
310
|
|
|
@@ -304,6 +317,7 @@ export class OTel extends TelemetryConnector {
|
|
|
304
317
|
attributes: {
|
|
305
318
|
'agent.id': hookContext.agentId,
|
|
306
319
|
'conv.id': hookContext.processId,
|
|
320
|
+
'team.id': hookContext.teamId,
|
|
307
321
|
'request.id': reqInfo.requestId,
|
|
308
322
|
'llm.model': modelId || 'unknown',
|
|
309
323
|
'metric.type': 'ttfb',
|
|
@@ -317,21 +331,34 @@ export class OTel extends TelemetryConnector {
|
|
|
317
331
|
'context.preview': JSON.stringify(lastContext).substring(0, 200),
|
|
318
332
|
});
|
|
319
333
|
hookContext.latencySpans[reqInfo.requestId] = llmGenLatencySpan;
|
|
334
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('createRequestedHandler completed', reqInfo?.requestId, accessCandidate);
|
|
320
335
|
};
|
|
321
336
|
};
|
|
322
337
|
HookService.register(
|
|
323
338
|
'Conversation.streamPrompt',
|
|
324
339
|
async function (additionalContext, args) {
|
|
325
|
-
const conversation: Conversation = this.instance;
|
|
326
|
-
const processId = conversation.id;
|
|
340
|
+
const conversation: Conversation = this.instance; //this.instance.agentData.teamId // this.instance.agentData.parenparentTeamId //this.instance.agentData.planInfo.properties this.instance.agentData.planInfo.flags
|
|
341
|
+
const processId = conversation.storeId || conversation.id;
|
|
327
342
|
const agentId = conversation.agentId;
|
|
328
343
|
const message = typeof args === 'object' ? args?.message : args || null;
|
|
329
344
|
const hookContext: any = this.context;
|
|
345
|
+
const teamId = conversation.agentData.teamId;
|
|
346
|
+
const orgTier = 'standard';
|
|
347
|
+
const orgSlot = this.instance.agentData?.planInfo?.flags ? `standard/${teamId}` : undefined;
|
|
348
|
+
const agentData = conversation.agentData || {};
|
|
349
|
+
const isDebugSession = agentData.debugSessionEnabled || false;
|
|
350
|
+
const isTestDomain = agentData.usingTestDomain || false;
|
|
351
|
+
const sessionId = processId;
|
|
352
|
+
const workflowId = agentData?.workflowReqId || agentData?.workflowID || agentData?.workflowId || undefined;
|
|
353
|
+
const logTags = agentData?.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
354
|
+
|
|
330
355
|
if (message == null) {
|
|
331
356
|
//this is a conversation step, will be handled by createRequestedHandler
|
|
332
357
|
|
|
333
358
|
return;
|
|
334
359
|
}
|
|
360
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
361
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('Conversation.streamPrompt started', { processId, message }, accessCandidate);
|
|
335
362
|
|
|
336
363
|
const modelId = typeof conversation?.model === 'string' ? conversation?.model : conversation?.model?.modelId;
|
|
337
364
|
|
|
@@ -343,21 +370,44 @@ export class OTel extends TelemetryConnector {
|
|
|
343
370
|
'gen_ai.conversation.id': processId,
|
|
344
371
|
'gen_ai.request.model': modelId || 'unknown',
|
|
345
372
|
////////////////////////////////
|
|
373
|
+
'team.id': teamId,
|
|
374
|
+
'org.tier': orgTier,
|
|
375
|
+
'org.slot': orgSlot,
|
|
346
376
|
'agent.id': agentId,
|
|
347
377
|
'conv.id': processId,
|
|
348
378
|
'llm.model': modelId || 'unknown',
|
|
379
|
+
'agent.debug': isDebugSession,
|
|
380
|
+
'agent.isTest': isTestDomain,
|
|
381
|
+
'session.id': sessionId,
|
|
382
|
+
'workflow.id': workflowId,
|
|
349
383
|
},
|
|
350
384
|
});
|
|
351
385
|
hookContext.convSpan = convSpan;
|
|
386
|
+
hookContext.agentId = agentId;
|
|
387
|
+
hookContext.processId = processId;
|
|
388
|
+
hookContext.teamId = teamId;
|
|
389
|
+
hookContext.orgSlot = orgSlot;
|
|
390
|
+
hookContext.isDebugSession = isDebugSession;
|
|
391
|
+
hookContext.isTestDomain = isTestDomain;
|
|
392
|
+
|
|
393
|
+
// Inject trace context into conversation headers for distributed tracing
|
|
394
|
+
let headers = {};
|
|
395
|
+
const traceContext = trace.setSpan(context.active(), convSpan);
|
|
396
|
+
propagation.inject(traceContext, headers);
|
|
397
|
+
for (let [key, value] of Object.entries(headers)) {
|
|
398
|
+
conversation.headers[key] = value as string;
|
|
399
|
+
}
|
|
400
|
+
if (OTEL_DEBUG_LOGS) {
|
|
401
|
+
outputLogger.debug('Injected trace headers into conversation', { processId, headers });
|
|
402
|
+
}
|
|
352
403
|
|
|
353
404
|
hookContext.dataHandler = createDataHandler(hookContext);
|
|
354
405
|
conversation.on(TLLMEvent.Data, hookContext.dataHandler);
|
|
406
|
+
|
|
355
407
|
hookContext.requestedHandler = createRequestedHandler(hookContext);
|
|
356
408
|
conversation.on(TLLMEvent.Requested, hookContext.requestedHandler);
|
|
357
|
-
hookContext.agentId = agentId;
|
|
358
|
-
hookContext.processId = processId;
|
|
359
|
-
hookContext.toolInfoHandler = createToolInfoHandler(hookContext);
|
|
360
409
|
|
|
410
|
+
hookContext.toolInfoHandler = createToolInfoHandler(hookContext);
|
|
361
411
|
conversation.on(TLLMEvent.ToolInfo, hookContext.toolInfoHandler);
|
|
362
412
|
|
|
363
413
|
// Add start event
|
|
@@ -383,10 +433,19 @@ export class OTel extends TelemetryConnector {
|
|
|
383
433
|
span_id: spanCtx.spanId,
|
|
384
434
|
trace_flags: spanCtx.traceFlags,
|
|
385
435
|
|
|
436
|
+
/////
|
|
437
|
+
'team.id': teamId,
|
|
438
|
+
'org.slot': orgSlot,
|
|
439
|
+
|
|
386
440
|
'agent.id': agentId,
|
|
387
441
|
'conv.id': processId,
|
|
388
442
|
'input.size': JSON.stringify(message || {}).length,
|
|
389
443
|
'input.preview': message.substring(0, 2000),
|
|
444
|
+
'agent.debug': isDebugSession,
|
|
445
|
+
'agent.isTest': isTestDomain,
|
|
446
|
+
'session.id': sessionId,
|
|
447
|
+
'workflow.id': workflowId,
|
|
448
|
+
'log.tags': logTags,
|
|
390
449
|
},
|
|
391
450
|
});
|
|
392
451
|
});
|
|
@@ -398,10 +457,21 @@ export class OTel extends TelemetryConnector {
|
|
|
398
457
|
'Conversation.streamPrompt',
|
|
399
458
|
async function ({ result, args, error }) {
|
|
400
459
|
const conversation: Conversation = this.instance;
|
|
401
|
-
const processId = conversation.id;
|
|
460
|
+
const processId = conversation.storeId || conversation.id;
|
|
402
461
|
const agentId = conversation.agentId;
|
|
403
462
|
const message = typeof args?.[0] === 'object' ? args?.[0]?.message : args?.[0] || null;
|
|
404
463
|
const hookContext: any = this.context;
|
|
464
|
+
const teamId = conversation.agentData.teamId;
|
|
465
|
+
const orgTier = 'standard';
|
|
466
|
+
const orgSlot = this.instance.agentData?.planInfo?.flags ? `standard/${teamId}` : undefined;
|
|
467
|
+
|
|
468
|
+
const isDebugSession = hookContext.isDebugSession || conversation.agentData?.debugSessionEnabled || false;
|
|
469
|
+
const isTestDomain = hookContext.isTestDomain || conversation.agentData?.usingTestDomain || false;
|
|
470
|
+
const agentData = conversation.agentData || {};
|
|
471
|
+
const sessionId = processId;
|
|
472
|
+
const workflowId = agentData?.workflowReqId || agentData?.workflowID || agentData?.workflowId || undefined;
|
|
473
|
+
const logTags = agentData?.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
474
|
+
|
|
405
475
|
if (message == null) {
|
|
406
476
|
return;
|
|
407
477
|
}
|
|
@@ -409,6 +479,9 @@ export class OTel extends TelemetryConnector {
|
|
|
409
479
|
const ctx = OTelContextRegistry.get(agentId, processId);
|
|
410
480
|
if (!ctx) return;
|
|
411
481
|
|
|
482
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
483
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('Conversation.streamPrompt completed', { processId }, accessCandidate);
|
|
484
|
+
|
|
412
485
|
if (hookContext.curLLMGenSpan) {
|
|
413
486
|
hookContext.curLLMGenSpan.addEvent('llm.gen.content', {
|
|
414
487
|
'content.size': JSON.stringify(result || {}).length,
|
|
@@ -435,6 +508,14 @@ export class OTel extends TelemetryConnector {
|
|
|
435
508
|
'conv.id': processId,
|
|
436
509
|
'output.size': JSON.stringify(result || {}).length,
|
|
437
510
|
'output.preview': result.substring(0, 2000),
|
|
511
|
+
'team.id': teamId,
|
|
512
|
+
'org.tier': orgTier,
|
|
513
|
+
'org.slot': orgSlot,
|
|
514
|
+
'agent.debug': isDebugSession,
|
|
515
|
+
'agent.isTest': isTestDomain,
|
|
516
|
+
'session.id': sessionId,
|
|
517
|
+
'workflow.id': workflowId,
|
|
518
|
+
'log.tags': logTags,
|
|
438
519
|
},
|
|
439
520
|
});
|
|
440
521
|
});
|
|
@@ -456,11 +537,24 @@ export class OTel extends TelemetryConnector {
|
|
|
456
537
|
const conversationId = agent.conversationId || agent.agentRequest?.header('X-CONVERSATION-ID');
|
|
457
538
|
const processId = agentProcessId.split(':').shift();
|
|
458
539
|
|
|
540
|
+
const orgTier = 'standard';
|
|
541
|
+
const orgSlot = agent.data.planInfo?.flags ? `standard/${agent.data.teamId}` : undefined;
|
|
459
542
|
const agentId = agent.id;
|
|
460
543
|
const agentRequest = agent.agentRequest;
|
|
461
544
|
const teamId = agent.teamId;
|
|
462
545
|
const _hookContext: any = this.context;
|
|
463
546
|
|
|
547
|
+
const sessionId = agent.callerSessionId || undefined;
|
|
548
|
+
const workflowId = agent.agentRuntime?.workflowReqId || undefined;
|
|
549
|
+
|
|
550
|
+
const isDebugSession = agent.debugSessionEnabled || agent.agentRuntime?.debug || false;
|
|
551
|
+
const logTags = agent.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
552
|
+
const isTestDomain = agent.usingTestDomain || false;
|
|
553
|
+
const domain = agent.domain || undefined;
|
|
554
|
+
|
|
555
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
556
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('SREAgent.process started', { processId, agentProcessId, endpointPath }, accessCandidate);
|
|
557
|
+
|
|
464
558
|
const body = oTelInstance.prepareComponentData(agentRequest.body || {});
|
|
465
559
|
const query = oTelInstance.prepareComponentData(agentRequest.query || {});
|
|
466
560
|
const headers = oTelInstance.prepareComponentData(agentRequest.headers || {});
|
|
@@ -469,22 +563,50 @@ export class OTel extends TelemetryConnector {
|
|
|
469
563
|
const input = { body, query, headers, processInput: agentInput };
|
|
470
564
|
|
|
471
565
|
let convSpan;
|
|
472
|
-
|
|
566
|
+
let parentContext = context.active();
|
|
567
|
+
|
|
568
|
+
//try reading ctx from local registry (local execution)
|
|
569
|
+
let ctx = OTelContextRegistry.get(agentId, processId) || OTelContextRegistry.get(agentId, conversationId);
|
|
473
570
|
|
|
474
571
|
if (ctx) {
|
|
475
572
|
convSpan = ctx.rootSpan;
|
|
476
573
|
_hookContext.otelSpan = convSpan;
|
|
574
|
+
parentContext = trace.setSpan(context.active(), convSpan);
|
|
575
|
+
} else {
|
|
576
|
+
// No local context found - try extracting from headers (remote execution)
|
|
577
|
+
const extractedContext = propagation.extract(context.active(), agentRequest.headers);
|
|
578
|
+
const extractedSpan = trace.getSpan(extractedContext);
|
|
579
|
+
|
|
580
|
+
if (extractedSpan) {
|
|
581
|
+
// Successfully extracted parent span from headers
|
|
582
|
+
parentContext = extractedContext;
|
|
583
|
+
if (OTEL_DEBUG_LOGS) {
|
|
584
|
+
outputLogger.debug('SREAgent.process extracted remote parent context from headers', {
|
|
585
|
+
processId,
|
|
586
|
+
traceId: extractedSpan.spanContext().traceId,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
}
|
|
477
590
|
}
|
|
591
|
+
|
|
478
592
|
const agentSpan = tracer.startSpan(
|
|
479
593
|
'Agent.Skill',
|
|
480
594
|
{
|
|
481
595
|
attributes: {
|
|
482
596
|
'agent.id': agentId,
|
|
483
597
|
'team.id': teamId,
|
|
598
|
+
'conv.id': conversationId,
|
|
484
599
|
'process.id': agentProcessId,
|
|
600
|
+
'org.slot': orgSlot,
|
|
601
|
+
'org.tier': orgTier,
|
|
602
|
+
'session.id': sessionId,
|
|
603
|
+
'workflow.id': workflowId,
|
|
604
|
+
'agent.debug': isDebugSession,
|
|
605
|
+
'agent.isTest': isTestDomain,
|
|
606
|
+
'agent.domain': domain,
|
|
485
607
|
},
|
|
486
608
|
},
|
|
487
|
-
|
|
609
|
+
parentContext
|
|
488
610
|
);
|
|
489
611
|
|
|
490
612
|
// Add start event
|
|
@@ -510,12 +632,22 @@ export class OTel extends TelemetryConnector {
|
|
|
510
632
|
trace_id: spanCtx.traceId,
|
|
511
633
|
span_id: spanCtx.spanId,
|
|
512
634
|
trace_flags: spanCtx.traceFlags,
|
|
513
|
-
agentId,
|
|
514
|
-
|
|
635
|
+
'agent.id': agentId,
|
|
636
|
+
'process.id': agentProcessId,
|
|
515
637
|
input: agentInput,
|
|
516
638
|
body,
|
|
517
639
|
query,
|
|
518
640
|
headers,
|
|
641
|
+
'team.id': teamId,
|
|
642
|
+
'org.slot': orgSlot,
|
|
643
|
+
'org.tier': orgTier,
|
|
644
|
+
'conv.id': conversationId,
|
|
645
|
+
'session.id': sessionId,
|
|
646
|
+
'workflow.id': workflowId,
|
|
647
|
+
'log.tags': logTags,
|
|
648
|
+
'agent.debug': isDebugSession,
|
|
649
|
+
'agent.isTest': isTestDomain,
|
|
650
|
+
'agent.domain': domain,
|
|
519
651
|
},
|
|
520
652
|
} as any);
|
|
521
653
|
});
|
|
@@ -528,8 +660,20 @@ export class OTel extends TelemetryConnector {
|
|
|
528
660
|
async function ({ result, error }) {
|
|
529
661
|
const agent = this.instance;
|
|
530
662
|
const agentProcessId = agent.agentRuntime.processID; // nested process has a subID that needs to be removed
|
|
663
|
+
const conversationId = agent.conversationId || agent.agentRequest?.header('X-CONVERSATION-ID');
|
|
531
664
|
const agentId = agent.id;
|
|
532
665
|
const _hookContext: any = this.context;
|
|
666
|
+
const teamId = agent.teamId;
|
|
667
|
+
const orgTier = 'standard';
|
|
668
|
+
const orgSlot = agent.data.planInfo?.flags ? `standard/${agent.data.teamId}` : undefined;
|
|
669
|
+
|
|
670
|
+
const sessionId = agent.callerSessionId || undefined;
|
|
671
|
+
const workflowId = agent.agentRuntime?.workflowReqId || undefined;
|
|
672
|
+
|
|
673
|
+
const isDebugSession = agent.debugSessionEnabled || agent.agentRuntime?.debug || false;
|
|
674
|
+
const logTags = agent.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
675
|
+
const isTestDomain = agent.usingTestDomain || false;
|
|
676
|
+
const domain = agent.domain || undefined;
|
|
533
677
|
|
|
534
678
|
const ctx = OTelContextRegistry.get(agentId, agentProcessId);
|
|
535
679
|
if (!ctx) return;
|
|
@@ -537,6 +681,9 @@ export class OTel extends TelemetryConnector {
|
|
|
537
681
|
|
|
538
682
|
if (!agentSpan) return;
|
|
539
683
|
|
|
684
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
685
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('SREAgent.process completed', { agentProcessId }, accessCandidate);
|
|
686
|
+
|
|
540
687
|
if (error) {
|
|
541
688
|
agentSpan.recordException(error);
|
|
542
689
|
agentSpan.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
@@ -561,11 +708,21 @@ export class OTel extends TelemetryConnector {
|
|
|
561
708
|
trace_id: spanCtx.traceId,
|
|
562
709
|
span_id: spanCtx.spanId,
|
|
563
710
|
trace_flags: spanCtx.traceFlags,
|
|
564
|
-
agentId,
|
|
565
|
-
|
|
711
|
+
'agent.id': agentId,
|
|
712
|
+
'process.id': agentProcessId,
|
|
566
713
|
hasError: !!error,
|
|
567
714
|
'error.message': error?.message,
|
|
568
715
|
'error.stack': error?.stack,
|
|
716
|
+
'team.id': teamId,
|
|
717
|
+
'org.slot': orgSlot,
|
|
718
|
+
'org.tier': orgTier,
|
|
719
|
+
'conv.id': conversationId,
|
|
720
|
+
'session.id': sessionId,
|
|
721
|
+
'workflow.id': workflowId,
|
|
722
|
+
'log.tags': logTags,
|
|
723
|
+
'agent.debug': isDebugSession,
|
|
724
|
+
'agent.isTest': isTestDomain,
|
|
725
|
+
'agent.domain': domain,
|
|
569
726
|
};
|
|
570
727
|
|
|
571
728
|
// Only include output if formatOutputForLog returns a value
|
|
@@ -603,6 +760,28 @@ export class OTel extends TelemetryConnector {
|
|
|
603
760
|
const componentType = settings.name;
|
|
604
761
|
const componentName = settings.displayName || settings.name;
|
|
605
762
|
const eventId = settings.eventId; // specific event id attached to this component execution
|
|
763
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
764
|
+
const teamId = agent.teamId;
|
|
765
|
+
const orgTier = 'standard';
|
|
766
|
+
const orgSlot = agent.data.planInfo?.flags ? `standard/${agent.data.teamId}` : undefined;
|
|
767
|
+
|
|
768
|
+
const componentData = agent.agentRuntime?.getComponentData?.(componentId);
|
|
769
|
+
const sourceId = componentData?.sourceId || 'AGENT';
|
|
770
|
+
const sourceComponentData = sourceId !== 'AGENT' ? agent.components?.[sourceId] : null;
|
|
771
|
+
const sourceName = sourceComponentData?.displayName || sourceComponentData?.name || sourceId;
|
|
772
|
+
|
|
773
|
+
const sessionId = agent.callerSessionId || undefined;
|
|
774
|
+
const workflowId = agent.agentRuntime?.workflowReqId || undefined;
|
|
775
|
+
const workflowStep = agent.agentRuntime?.curStep || undefined;
|
|
776
|
+
|
|
777
|
+
const isDebugSession = agent.debugSessionEnabled || agent.agentRuntime?.debug || false;
|
|
778
|
+
const logTags = agent.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
779
|
+
const isTestDomain = agent.usingTestDomain || false;
|
|
780
|
+
|
|
781
|
+
const inputAction = input?.__action || undefined;
|
|
782
|
+
const inputStatus = input?.__status || undefined;
|
|
783
|
+
|
|
784
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('Component.process started', { componentId, sourceId }, accessCandidate);
|
|
606
785
|
|
|
607
786
|
const ctx = OTelContextRegistry.get(agentId, processId);
|
|
608
787
|
const parentSpan = ctx?.rootSpan;
|
|
@@ -619,13 +798,23 @@ export class OTel extends TelemetryConnector {
|
|
|
619
798
|
'cmp.id': componentId,
|
|
620
799
|
'cmp.type': componentType,
|
|
621
800
|
'cmp.name': componentName,
|
|
801
|
+
'team.id': teamId,
|
|
802
|
+
'org.tier': orgTier,
|
|
803
|
+
'org.slot': orgSlot,
|
|
804
|
+
'source.id': sourceId,
|
|
805
|
+
'source.name': sourceName,
|
|
806
|
+
'session.id': sessionId,
|
|
807
|
+
'workflow.id': workflowId,
|
|
808
|
+
'workflow.step': workflowStep,
|
|
809
|
+
'agent.debug': isDebugSession,
|
|
810
|
+
'agent.isTest': isTestDomain,
|
|
622
811
|
...compSettingsData,
|
|
623
812
|
},
|
|
624
813
|
},
|
|
625
814
|
parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined
|
|
626
815
|
);
|
|
627
816
|
|
|
628
|
-
// Add event: Component started
|
|
817
|
+
// Add event: Component started - includes input.action and input.status for workflow tracking
|
|
629
818
|
const inputStr = JSON.stringify(input || {});
|
|
630
819
|
|
|
631
820
|
const compInputData = oTelInstance.prepareComponentData(input || {});
|
|
@@ -633,6 +822,8 @@ export class OTel extends TelemetryConnector {
|
|
|
633
822
|
'event.id': eventId,
|
|
634
823
|
'cmp.input.size': JSON.stringify(input || {}).length,
|
|
635
824
|
'cmp.input': JSON.stringify(compInputData),
|
|
825
|
+
'input.action': inputAction,
|
|
826
|
+
'input.status': inputStatus,
|
|
636
827
|
});
|
|
637
828
|
|
|
638
829
|
// Emit structured log with full details
|
|
@@ -650,6 +841,17 @@ export class OTel extends TelemetryConnector {
|
|
|
650
841
|
'cmp.type': componentType,
|
|
651
842
|
'cmp.name': componentName,
|
|
652
843
|
'cmp.input': input,
|
|
844
|
+
'team.id': teamId,
|
|
845
|
+
'org.slot': orgSlot,
|
|
846
|
+
'org.tier': orgTier,
|
|
847
|
+
'source.id': sourceId,
|
|
848
|
+
'source.name': sourceName,
|
|
849
|
+
'session.id': sessionId,
|
|
850
|
+
'workflow.id': workflowId,
|
|
851
|
+
'workflow.step': workflowStep,
|
|
852
|
+
'log.tags': logTags,
|
|
853
|
+
'agent.debug': isDebugSession,
|
|
854
|
+
'agent.isTest': isTestDomain,
|
|
653
855
|
},
|
|
654
856
|
});
|
|
655
857
|
});
|
|
@@ -676,6 +878,25 @@ export class OTel extends TelemetryConnector {
|
|
|
676
878
|
const componentId = settings.id || 'unknown';
|
|
677
879
|
const componentType = settings.name;
|
|
678
880
|
const componentName = settings.displayName || settings.name;
|
|
881
|
+
const teamId = agent.teamId;
|
|
882
|
+
const orgTier = 'standard';
|
|
883
|
+
const orgSlot = agent.data.planInfo?.flags ? `standard/${agent.data.teamId}` : undefined;
|
|
884
|
+
|
|
885
|
+
const componentData = agent.agentRuntime?.getComponentData?.(componentId);
|
|
886
|
+
const sourceId = componentData?.sourceId || 'AGENT';
|
|
887
|
+
const sourceComponentData = sourceId !== 'AGENT' ? agent.components?.[sourceId] : null;
|
|
888
|
+
const sourceName = sourceComponentData?.displayName || sourceComponentData?.name || sourceId;
|
|
889
|
+
|
|
890
|
+
const sessionId = agent.callerSessionId || undefined;
|
|
891
|
+
const workflowId = agent.agentRuntime?.workflowReqId || undefined;
|
|
892
|
+
const workflowStep = agent.agentRuntime?.curStep || undefined;
|
|
893
|
+
|
|
894
|
+
const isDebugSession = agent.debugSessionEnabled || agent.agentRuntime?.debug || false;
|
|
895
|
+
const logTags = agent.sessionTag || (isDebugSession ? 'DEBUG' : undefined);
|
|
896
|
+
const isTestDomain = agent.usingTestDomain || false;
|
|
897
|
+
|
|
898
|
+
const accessCandidate = AccessCandidate.agent(agentId);
|
|
899
|
+
if (OTEL_DEBUG_LOGS) outputLogger.debug('Component.process completed', { componentId }, accessCandidate);
|
|
679
900
|
|
|
680
901
|
if (error) {
|
|
681
902
|
// Capture error details
|
|
@@ -710,6 +931,17 @@ export class OTel extends TelemetryConnector {
|
|
|
710
931
|
'error.type': error.name,
|
|
711
932
|
'error.message': error.message,
|
|
712
933
|
'error.stack': error.stack, // ← Full stack in logs
|
|
934
|
+
'team.id': teamId,
|
|
935
|
+
'org.slot': orgSlot,
|
|
936
|
+
'org.tier': orgTier,
|
|
937
|
+
'source.id': sourceId,
|
|
938
|
+
'source.name': sourceName,
|
|
939
|
+
'session.id': sessionId,
|
|
940
|
+
'workflow.id': workflowId,
|
|
941
|
+
'workflow.step': workflowStep,
|
|
942
|
+
'log.tags': logTags,
|
|
943
|
+
'agent.debug': isDebugSession,
|
|
944
|
+
'agent.isTest': isTestDomain,
|
|
713
945
|
},
|
|
714
946
|
});
|
|
715
947
|
});
|
|
@@ -739,6 +971,17 @@ export class OTel extends TelemetryConnector {
|
|
|
739
971
|
'process.id': processId,
|
|
740
972
|
'event.id': eventId,
|
|
741
973
|
'cmp.output': result,
|
|
974
|
+
'team.id': teamId,
|
|
975
|
+
'org.slot': orgSlot,
|
|
976
|
+
'org.tier': orgTier,
|
|
977
|
+
'source.id': sourceId,
|
|
978
|
+
'source.name': sourceName,
|
|
979
|
+
'session.id': sessionId,
|
|
980
|
+
'workflow.id': workflowId,
|
|
981
|
+
'workflow.step': workflowStep,
|
|
982
|
+
'log.tags': logTags,
|
|
983
|
+
'agent.debug': isDebugSession,
|
|
984
|
+
'agent.isTest': isTestDomain,
|
|
742
985
|
};
|
|
743
986
|
|
|
744
987
|
// Only include output if formatOutputForLog returns a value
|
|
@@ -10,7 +10,7 @@ export interface ISmythAccountRequest {
|
|
|
10
10
|
getCandidateTeam(): Promise<string | undefined>;
|
|
11
11
|
getAllTeamSettings(): Promise<KeyValueObject>;
|
|
12
12
|
getAllUserSettings(): Promise<KeyValueObject>;
|
|
13
|
-
getTeamSetting(settingKey: string): Promise<string>;
|
|
13
|
+
getTeamSetting(settingKey: string, group?: string): Promise<string>;
|
|
14
14
|
getUserSetting(settingKey: string): Promise<string>;
|
|
15
15
|
getAgentSetting(settingKey: string): Promise<string>;
|
|
16
16
|
getTeam(): Promise<string>;
|
|
@@ -25,7 +25,7 @@ export abstract class AccountConnector extends Connector {
|
|
|
25
25
|
getAllUserSettings: async () => this.getAllUserSettings(candidate.readRequest, candidate.id),
|
|
26
26
|
getUserSetting: async (settingKey: string) => this.getUserSetting(candidate.readRequest, candidate.id, settingKey),
|
|
27
27
|
getAllTeamSettings: async () => this.getAllTeamSettings(candidate.readRequest, candidate.id),
|
|
28
|
-
getTeamSetting: async (settingKey: string) => this.getTeamSetting(candidate.readRequest, candidate.id, settingKey),
|
|
28
|
+
getTeamSetting: async (settingKey: string, group?: string) => this.getTeamSetting(candidate.readRequest, candidate.id, settingKey, group),
|
|
29
29
|
isTeamMember: async (teamId: string) => this.isTeamMember(teamId, candidate),
|
|
30
30
|
getCandidateTeam: async () => this.getCandidateTeam(candidate),
|
|
31
31
|
getTeam: async () => this.getCandidateTeam(candidate),
|
|
@@ -38,7 +38,7 @@ export abstract class AccountConnector extends Connector {
|
|
|
38
38
|
public abstract getCandidateTeam(candidate: IAccessCandidate): Promise<string | undefined>;
|
|
39
39
|
public abstract getAllTeamSettings(acRequest: AccessRequest, teamId: string): Promise<KeyValueObject>;
|
|
40
40
|
public abstract getAllUserSettings(acRequest: AccessRequest, accountId: string): Promise<KeyValueObject>;
|
|
41
|
-
public abstract getTeamSetting(acRequest: AccessRequest, teamId: string, settingKey: string): Promise<string>;
|
|
41
|
+
public abstract getTeamSetting(acRequest: AccessRequest, teamId: string, settingKey: string, group?: string): Promise<string>;
|
|
42
42
|
public abstract getUserSetting(acRequest: AccessRequest, accountId: string, settingKey: string): Promise<string>;
|
|
43
43
|
public abstract getAgentSetting(acRequest: AccessRequest, agentId: string, settingKey: string): Promise<string>;
|
|
44
44
|
}
|