@agentmark-ai/shared-utils 0.1.0 → 0.2.0
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.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +219 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +216 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -468,6 +468,44 @@ declare class MastraTransformer implements ScopeTransformer {
|
|
|
468
468
|
private extractStreamResult;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Transformer for AgentMark spans emitted via OTEL.
|
|
473
|
+
* Handles GenAI semantic convention attributes and classifies spans.
|
|
474
|
+
*
|
|
475
|
+
* Classification rules (per OTEL GenAI conventions):
|
|
476
|
+
* - GENERATION: Spans that represent actual LLM API calls (chat, text_completion)
|
|
477
|
+
* - SPAN: All other spans (tool execution, agent invocation, grouping spans)
|
|
478
|
+
*
|
|
479
|
+
* Only spans that send requests to the LLM should be GENERATION type.
|
|
480
|
+
* Wrapper/grouping spans like conversations are regular SPAN type.
|
|
481
|
+
*/
|
|
482
|
+
declare class AgentMarkTransformer implements ScopeTransformer {
|
|
483
|
+
/**
|
|
484
|
+
* Classify the span type based on span name and attributes.
|
|
485
|
+
*
|
|
486
|
+
* GENERATION type (actual LLM calls):
|
|
487
|
+
* - Spans starting with "chat " (OTEL convention)
|
|
488
|
+
* - gen_ai.llm.turn spans (legacy traced module)
|
|
489
|
+
* - gen_ai.session spans (legacy hooks) - these wrap LLM calls
|
|
490
|
+
* - Spans with gen_ai.operation.name = "chat" or "text_completion"
|
|
491
|
+
*
|
|
492
|
+
* SPAN type (everything else):
|
|
493
|
+
* - gen_ai.conversation (grouping span)
|
|
494
|
+
* - execute_tool / gen_ai.tool.call (tool execution)
|
|
495
|
+
* - invoke_agent / gen_ai.subagent (agent invocation)
|
|
496
|
+
*/
|
|
497
|
+
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
498
|
+
/**
|
|
499
|
+
* Transform the span and extract normalized fields from GenAI attributes.
|
|
500
|
+
*/
|
|
501
|
+
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* The scope name used by AgentMark's OTEL tracer.
|
|
505
|
+
* Used by the registry to route spans to this transformer.
|
|
506
|
+
*/
|
|
507
|
+
declare const AGENTMARK_SCOPE_NAME = "agentmark";
|
|
508
|
+
|
|
471
509
|
declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
|
|
472
510
|
/**
|
|
473
511
|
* Normalize spans from raw OTLP resourceSpans structure
|
|
@@ -475,4 +513,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
475
513
|
*/
|
|
476
514
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
477
515
|
|
|
478
|
-
export { type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, type ScopeTransformer, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, toFrontMatter, typeClassifier, verifySignature };
|
|
516
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, type ScopeTransformer, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -468,6 +468,44 @@ declare class MastraTransformer implements ScopeTransformer {
|
|
|
468
468
|
private extractStreamResult;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Transformer for AgentMark spans emitted via OTEL.
|
|
473
|
+
* Handles GenAI semantic convention attributes and classifies spans.
|
|
474
|
+
*
|
|
475
|
+
* Classification rules (per OTEL GenAI conventions):
|
|
476
|
+
* - GENERATION: Spans that represent actual LLM API calls (chat, text_completion)
|
|
477
|
+
* - SPAN: All other spans (tool execution, agent invocation, grouping spans)
|
|
478
|
+
*
|
|
479
|
+
* Only spans that send requests to the LLM should be GENERATION type.
|
|
480
|
+
* Wrapper/grouping spans like conversations are regular SPAN type.
|
|
481
|
+
*/
|
|
482
|
+
declare class AgentMarkTransformer implements ScopeTransformer {
|
|
483
|
+
/**
|
|
484
|
+
* Classify the span type based on span name and attributes.
|
|
485
|
+
*
|
|
486
|
+
* GENERATION type (actual LLM calls):
|
|
487
|
+
* - Spans starting with "chat " (OTEL convention)
|
|
488
|
+
* - gen_ai.llm.turn spans (legacy traced module)
|
|
489
|
+
* - gen_ai.session spans (legacy hooks) - these wrap LLM calls
|
|
490
|
+
* - Spans with gen_ai.operation.name = "chat" or "text_completion"
|
|
491
|
+
*
|
|
492
|
+
* SPAN type (everything else):
|
|
493
|
+
* - gen_ai.conversation (grouping span)
|
|
494
|
+
* - execute_tool / gen_ai.tool.call (tool execution)
|
|
495
|
+
* - invoke_agent / gen_ai.subagent (agent invocation)
|
|
496
|
+
*/
|
|
497
|
+
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
498
|
+
/**
|
|
499
|
+
* Transform the span and extract normalized fields from GenAI attributes.
|
|
500
|
+
*/
|
|
501
|
+
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* The scope name used by AgentMark's OTEL tracer.
|
|
505
|
+
* Used by the registry to route spans to this transformer.
|
|
506
|
+
*/
|
|
507
|
+
declare const AGENTMARK_SCOPE_NAME = "agentmark";
|
|
508
|
+
|
|
471
509
|
declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
|
|
472
510
|
/**
|
|
473
511
|
* Normalize spans from raw OTLP resourceSpans structure
|
|
@@ -475,4 +513,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
475
513
|
*/
|
|
476
514
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
477
515
|
|
|
478
|
-
export { type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, type ScopeTransformer, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, toFrontMatter, typeClassifier, verifySignature };
|
|
516
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, type OtelLink, type OtelResource, type OtelScope, type OtelSpan, type OtlpAttribute, type OtlpAttributeValue, type OtlpEvent, type OtlpLink, type OtlpResource, type OtlpResourceSpans, type OtlpScope, type OtlpScopeSpans, type OtlpSpan, type ScopeTransformer, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, normalizeOtlpSpans, normalizeSpan, parseAgentMarkAttributes, parseMetadata, parseTokens, registry, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
AGENTMARK_SCOPE_NAME: () => AGENTMARK_SCOPE_NAME,
|
|
34
|
+
AgentMarkTransformer: () => AgentMarkTransformer,
|
|
33
35
|
AiSdkTransformer: () => AiSdkTransformer,
|
|
36
|
+
ClaudeAgentTransformer: () => AgentMarkTransformer,
|
|
34
37
|
MastraTransformer: () => MastraTransformer,
|
|
35
38
|
SpanType: () => SpanType,
|
|
36
39
|
TransformerRegistry: () => TransformerRegistry,
|
|
@@ -1333,6 +1336,218 @@ var MastraTransformer = class {
|
|
|
1333
1336
|
}
|
|
1334
1337
|
};
|
|
1335
1338
|
|
|
1339
|
+
// src/normalizer/extractors/agentmark-parser.ts
|
|
1340
|
+
function parseAgentMarkAttributes(attributes, prefix = "agentmark.") {
|
|
1341
|
+
const result = {};
|
|
1342
|
+
const get = (key) => attributes[`${prefix}${key}`];
|
|
1343
|
+
if (get("session_id")) result.sessionId = String(get("session_id"));
|
|
1344
|
+
if (get("session_name")) result.sessionName = String(get("session_name"));
|
|
1345
|
+
if (get("user_id")) result.userId = String(get("user_id"));
|
|
1346
|
+
if (get("trace_name")) result.traceName = String(get("trace_name"));
|
|
1347
|
+
if (get("prompt_name")) result.promptName = String(get("prompt_name"));
|
|
1348
|
+
if (get("props")) result.props = String(get("props"));
|
|
1349
|
+
if (get("dataset_run_id")) result.datasetRunId = String(get("dataset_run_id"));
|
|
1350
|
+
if (get("dataset_run_name")) result.datasetRunName = String(get("dataset_run_name"));
|
|
1351
|
+
if (get("dataset_item_name")) result.datasetItemName = String(get("dataset_item_name"));
|
|
1352
|
+
if (get("dataset_expected_output")) result.datasetExpectedOutput = String(get("dataset_expected_output"));
|
|
1353
|
+
if (get("dataset_path")) result.datasetPath = String(get("dataset_path"));
|
|
1354
|
+
return result;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// src/normalizer/transformers/agentmark/index.ts
|
|
1358
|
+
var GenAIAttributes = {
|
|
1359
|
+
SYSTEM: "gen_ai.system",
|
|
1360
|
+
OPERATION_NAME: "gen_ai.operation.name",
|
|
1361
|
+
REQUEST_MODEL: "gen_ai.request.model",
|
|
1362
|
+
REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens",
|
|
1363
|
+
REQUEST_TEMPERATURE: "gen_ai.request.temperature",
|
|
1364
|
+
REQUEST_INPUT: "gen_ai.request.input",
|
|
1365
|
+
RESPONSE_ID: "gen_ai.response.id",
|
|
1366
|
+
RESPONSE_MODEL: "gen_ai.response.model",
|
|
1367
|
+
RESPONSE_OUTPUT: "gen_ai.response.output",
|
|
1368
|
+
RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons",
|
|
1369
|
+
USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens",
|
|
1370
|
+
USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens",
|
|
1371
|
+
TOOL_NAME: "gen_ai.tool.name",
|
|
1372
|
+
TOOL_CALL_ID: "gen_ai.tool.call.id",
|
|
1373
|
+
TOOL_INPUT: "gen_ai.tool.input",
|
|
1374
|
+
TOOL_OUTPUT: "gen_ai.tool.output"
|
|
1375
|
+
};
|
|
1376
|
+
var SpanNames = {
|
|
1377
|
+
// OTEL GenAI standard operation names (these can be followed by model/tool/agent name)
|
|
1378
|
+
CHAT: "chat",
|
|
1379
|
+
EXECUTE_TOOL: "execute_tool",
|
|
1380
|
+
INVOKE_AGENT: "invoke_agent",
|
|
1381
|
+
// Legacy span names (for backwards compatibility)
|
|
1382
|
+
SESSION: "gen_ai.session",
|
|
1383
|
+
TOOL_CALL: "gen_ai.tool.call",
|
|
1384
|
+
SUBAGENT: "gen_ai.subagent",
|
|
1385
|
+
CONVERSATION: "gen_ai.conversation",
|
|
1386
|
+
LLM_TURN: "gen_ai.llm.turn"
|
|
1387
|
+
};
|
|
1388
|
+
var OperationNames = {
|
|
1389
|
+
CHAT: "chat",
|
|
1390
|
+
EMBEDDINGS: "embeddings",
|
|
1391
|
+
TEXT_COMPLETION: "text_completion",
|
|
1392
|
+
GENERATE_CONTENT: "generate_content",
|
|
1393
|
+
EXECUTE_TOOL: "execute_tool",
|
|
1394
|
+
CREATE_AGENT: "create_agent",
|
|
1395
|
+
INVOKE_AGENT: "invoke_agent"
|
|
1396
|
+
};
|
|
1397
|
+
var AgentMarkTransformer = class {
|
|
1398
|
+
/**
|
|
1399
|
+
* Classify the span type based on span name and attributes.
|
|
1400
|
+
*
|
|
1401
|
+
* GENERATION type (actual LLM calls):
|
|
1402
|
+
* - Spans starting with "chat " (OTEL convention)
|
|
1403
|
+
* - gen_ai.llm.turn spans (legacy traced module)
|
|
1404
|
+
* - gen_ai.session spans (legacy hooks) - these wrap LLM calls
|
|
1405
|
+
* - Spans with gen_ai.operation.name = "chat" or "text_completion"
|
|
1406
|
+
*
|
|
1407
|
+
* SPAN type (everything else):
|
|
1408
|
+
* - gen_ai.conversation (grouping span)
|
|
1409
|
+
* - execute_tool / gen_ai.tool.call (tool execution)
|
|
1410
|
+
* - invoke_agent / gen_ai.subagent (agent invocation)
|
|
1411
|
+
*/
|
|
1412
|
+
classify(span, attributes) {
|
|
1413
|
+
const operationName = attributes[GenAIAttributes.OPERATION_NAME];
|
|
1414
|
+
if (operationName === OperationNames.CHAT || operationName === OperationNames.TEXT_COMPLETION) {
|
|
1415
|
+
return "GENERATION" /* GENERATION */;
|
|
1416
|
+
}
|
|
1417
|
+
if (span.name === SpanNames.CHAT || span.name.startsWith(SpanNames.CHAT + " ")) {
|
|
1418
|
+
return "GENERATION" /* GENERATION */;
|
|
1419
|
+
}
|
|
1420
|
+
if (span.name === SpanNames.LLM_TURN) {
|
|
1421
|
+
return "GENERATION" /* GENERATION */;
|
|
1422
|
+
}
|
|
1423
|
+
if (span.name === SpanNames.SESSION) {
|
|
1424
|
+
return "GENERATION" /* GENERATION */;
|
|
1425
|
+
}
|
|
1426
|
+
if (span.name === SpanNames.EXECUTE_TOOL || span.name.startsWith(SpanNames.EXECUTE_TOOL + " ") || span.name.startsWith(SpanNames.TOOL_CALL)) {
|
|
1427
|
+
return "SPAN" /* SPAN */;
|
|
1428
|
+
}
|
|
1429
|
+
if (span.name === SpanNames.INVOKE_AGENT || span.name.startsWith(SpanNames.INVOKE_AGENT + " ")) {
|
|
1430
|
+
return "SPAN" /* SPAN */;
|
|
1431
|
+
}
|
|
1432
|
+
if (span.name === SpanNames.CONVERSATION || span.name === SpanNames.SUBAGENT) {
|
|
1433
|
+
return "SPAN" /* SPAN */;
|
|
1434
|
+
}
|
|
1435
|
+
if (attributes[GenAIAttributes.SYSTEM] === "anthropic") {
|
|
1436
|
+
if (attributes[GenAIAttributes.USAGE_INPUT_TOKENS] !== void 0 && attributes[GenAIAttributes.RESPONSE_OUTPUT] !== void 0) {
|
|
1437
|
+
return "GENERATION" /* GENERATION */;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
return "SPAN" /* SPAN */;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Transform the span and extract normalized fields from GenAI attributes.
|
|
1444
|
+
*/
|
|
1445
|
+
transform(_span, attributes) {
|
|
1446
|
+
const result = {};
|
|
1447
|
+
const responseModel = attributes[GenAIAttributes.RESPONSE_MODEL];
|
|
1448
|
+
const requestModel = attributes[GenAIAttributes.REQUEST_MODEL];
|
|
1449
|
+
if (responseModel) {
|
|
1450
|
+
result.model = String(responseModel);
|
|
1451
|
+
} else if (requestModel) {
|
|
1452
|
+
result.model = String(requestModel);
|
|
1453
|
+
}
|
|
1454
|
+
const inputTokens = attributes[GenAIAttributes.USAGE_INPUT_TOKENS];
|
|
1455
|
+
const outputTokens = attributes[GenAIAttributes.USAGE_OUTPUT_TOKENS];
|
|
1456
|
+
if (typeof inputTokens === "number") {
|
|
1457
|
+
result.inputTokens = inputTokens;
|
|
1458
|
+
}
|
|
1459
|
+
if (typeof outputTokens === "number") {
|
|
1460
|
+
result.outputTokens = outputTokens;
|
|
1461
|
+
}
|
|
1462
|
+
if (result.inputTokens !== void 0 && result.outputTokens !== void 0) {
|
|
1463
|
+
result.totalTokens = result.inputTokens + result.outputTokens;
|
|
1464
|
+
}
|
|
1465
|
+
const finishReasons = attributes[GenAIAttributes.RESPONSE_FINISH_REASONS];
|
|
1466
|
+
if (finishReasons) {
|
|
1467
|
+
try {
|
|
1468
|
+
const reasons = JSON.parse(finishReasons);
|
|
1469
|
+
if (Array.isArray(reasons) && reasons.length > 0) {
|
|
1470
|
+
result.finishReason = String(reasons[0]);
|
|
1471
|
+
}
|
|
1472
|
+
} catch {
|
|
1473
|
+
result.finishReason = String(finishReasons);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
const maxTokens = attributes[GenAIAttributes.REQUEST_MAX_TOKENS];
|
|
1477
|
+
const temperature = attributes[GenAIAttributes.REQUEST_TEMPERATURE];
|
|
1478
|
+
if (maxTokens !== void 0 || temperature !== void 0) {
|
|
1479
|
+
result.settings = {};
|
|
1480
|
+
if (typeof maxTokens === "number") {
|
|
1481
|
+
result.settings.maxTokens = maxTokens;
|
|
1482
|
+
}
|
|
1483
|
+
if (typeof temperature === "number") {
|
|
1484
|
+
result.settings.temperature = temperature;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const requestInput = attributes[GenAIAttributes.REQUEST_INPUT];
|
|
1488
|
+
if (requestInput && typeof requestInput === "string") {
|
|
1489
|
+
try {
|
|
1490
|
+
const parsed = JSON.parse(requestInput);
|
|
1491
|
+
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
1492
|
+
const isMessagesArray = parsed.every(
|
|
1493
|
+
(item) => item && typeof item === "object" && "role" in item && "content" in item
|
|
1494
|
+
);
|
|
1495
|
+
if (isMessagesArray) {
|
|
1496
|
+
result.input = parsed;
|
|
1497
|
+
} else {
|
|
1498
|
+
result.input = [{ role: "user", content: requestInput }];
|
|
1499
|
+
}
|
|
1500
|
+
} else {
|
|
1501
|
+
result.input = [{ role: "user", content: requestInput }];
|
|
1502
|
+
}
|
|
1503
|
+
} catch {
|
|
1504
|
+
result.input = [{ role: "user", content: requestInput }];
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
const responseOutput = attributes[GenAIAttributes.RESPONSE_OUTPUT];
|
|
1508
|
+
if (responseOutput && typeof responseOutput === "string") {
|
|
1509
|
+
result.output = responseOutput;
|
|
1510
|
+
}
|
|
1511
|
+
const toolName = attributes[GenAIAttributes.TOOL_NAME];
|
|
1512
|
+
const toolCallId = attributes[GenAIAttributes.TOOL_CALL_ID];
|
|
1513
|
+
const toolInput = attributes[GenAIAttributes.TOOL_INPUT];
|
|
1514
|
+
const toolOutput = attributes[GenAIAttributes.TOOL_OUTPUT];
|
|
1515
|
+
if (toolName && typeof toolName === "string") {
|
|
1516
|
+
result.name = toolName;
|
|
1517
|
+
const toolCall = {
|
|
1518
|
+
type: "tool-call",
|
|
1519
|
+
toolCallId: typeof toolCallId === "string" ? toolCallId : "",
|
|
1520
|
+
toolName,
|
|
1521
|
+
args: {}
|
|
1522
|
+
};
|
|
1523
|
+
if (toolInput && typeof toolInput === "string") {
|
|
1524
|
+
try {
|
|
1525
|
+
toolCall.args = JSON.parse(toolInput);
|
|
1526
|
+
} catch {
|
|
1527
|
+
toolCall.args = { raw: toolInput };
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
if (toolOutput && typeof toolOutput === "string") {
|
|
1531
|
+
toolCall.result = toolOutput;
|
|
1532
|
+
}
|
|
1533
|
+
result.toolCalls = [toolCall];
|
|
1534
|
+
}
|
|
1535
|
+
const agentmarkAttrs = parseAgentMarkAttributes(attributes);
|
|
1536
|
+
const metadataAttrs = parseMetadata(attributes, "agentmark.metadata.");
|
|
1537
|
+
const customMetadata = extractCustomMetadata(attributes, "agentmark.metadata.");
|
|
1538
|
+
return {
|
|
1539
|
+
...result,
|
|
1540
|
+
...metadataAttrs,
|
|
1541
|
+
// agentmark.metadata.* values (lower priority)
|
|
1542
|
+
...agentmarkAttrs,
|
|
1543
|
+
// agentmark.* values (higher priority)
|
|
1544
|
+
// Only include metadata field if there are custom metadata keys
|
|
1545
|
+
...Object.keys(customMetadata).length > 0 ? { metadata: customMetadata } : {}
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
var AGENTMARK_SCOPE_NAME = "agentmark";
|
|
1550
|
+
|
|
1336
1551
|
// src/normalizer/converters/otlp-converter.ts
|
|
1337
1552
|
function convertOtlpValue(value) {
|
|
1338
1553
|
var _a;
|
|
@@ -1413,21 +1628,6 @@ function extractResourceScopeSpan(resourceSpans) {
|
|
|
1413
1628
|
return result;
|
|
1414
1629
|
}
|
|
1415
1630
|
|
|
1416
|
-
// src/normalizer/extractors/agentmark-parser.ts
|
|
1417
|
-
function parseAgentMarkAttributes(attributes, prefix = "agentmark.") {
|
|
1418
|
-
const result = {};
|
|
1419
|
-
const get = (key) => attributes[`${prefix}${key}`];
|
|
1420
|
-
if (get("session_id")) result.sessionId = String(get("session_id"));
|
|
1421
|
-
if (get("session_name")) result.sessionName = String(get("session_name"));
|
|
1422
|
-
if (get("user_id")) result.userId = String(get("user_id"));
|
|
1423
|
-
if (get("trace_name")) result.traceName = String(get("trace_name"));
|
|
1424
|
-
if (get("dataset_run_id")) result.datasetRunId = String(get("dataset_run_id"));
|
|
1425
|
-
if (get("dataset_run_name")) result.datasetRunName = String(get("dataset_run_name"));
|
|
1426
|
-
if (get("dataset_item_name")) result.datasetItemName = String(get("dataset_item_name"));
|
|
1427
|
-
if (get("dataset_expected_output")) result.datasetExpectedOutput = String(get("dataset_expected_output"));
|
|
1428
|
-
return result;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
1631
|
// src/normalizer/type-classifier.ts
|
|
1432
1632
|
var TypeClassifier = class {
|
|
1433
1633
|
classify(span, attributes) {
|
|
@@ -1448,6 +1648,7 @@ var typeClassifier = new TypeClassifier();
|
|
|
1448
1648
|
// src/normalizer/index.ts
|
|
1449
1649
|
registry.register("ai", new AiSdkTransformer());
|
|
1450
1650
|
registry.register("default-tracer", new MastraTransformer());
|
|
1651
|
+
registry.register("agentmark", new AgentMarkTransformer());
|
|
1451
1652
|
registry.setDefault(new AiSdkTransformer());
|
|
1452
1653
|
function normalizeSpan(resource, scope, span) {
|
|
1453
1654
|
var _a, _b, _c;
|
|
@@ -1518,7 +1719,10 @@ function normalizeOtlpSpans(resourceSpans) {
|
|
|
1518
1719
|
}
|
|
1519
1720
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1520
1721
|
0 && (module.exports = {
|
|
1722
|
+
AGENTMARK_SCOPE_NAME,
|
|
1723
|
+
AgentMarkTransformer,
|
|
1521
1724
|
AiSdkTransformer,
|
|
1725
|
+
ClaudeAgentTransformer,
|
|
1522
1726
|
MastraTransformer,
|
|
1523
1727
|
SpanType,
|
|
1524
1728
|
TransformerRegistry,
|