@agentmark-ai/shared-utils 0.3.1 → 0.3.2
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 +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +87 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -219,6 +219,7 @@ interface NormalizedSpan {
|
|
|
219
219
|
duration: number;
|
|
220
220
|
name: string;
|
|
221
221
|
kind: string;
|
|
222
|
+
semanticKind?: string;
|
|
222
223
|
serviceName?: string;
|
|
223
224
|
statusCode: string;
|
|
224
225
|
statusMessage?: string;
|
|
@@ -443,6 +444,27 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
|
|
|
443
444
|
*/
|
|
444
445
|
declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
|
|
445
446
|
|
|
447
|
+
/** Valid semantic kind values. */
|
|
448
|
+
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
449
|
+
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
450
|
+
/**
|
|
451
|
+
* Resolve the semantic kind of a span using an 8-level priority chain.
|
|
452
|
+
*
|
|
453
|
+
* Priority:
|
|
454
|
+
* 1. normalized.semanticKind (from agentmark.span.kind attribute) — if valid
|
|
455
|
+
* 2. openinference.span.kind attribute
|
|
456
|
+
* 3. Framework-specific attributes (Vercel AI SDK, Traceloop, LangChain, Genkit)
|
|
457
|
+
* 4. gen_ai.operation.name → llm/embedding
|
|
458
|
+
* 5. Type = GENERATION → llm
|
|
459
|
+
* 6. Has non-empty ToolCalls → tool
|
|
460
|
+
* 7. Name-based heuristics
|
|
461
|
+
* 8. Default → function
|
|
462
|
+
*/
|
|
463
|
+
declare function resolveSemanticKind(normalized: Partial<NormalizedSpan> & {
|
|
464
|
+
type: SpanType;
|
|
465
|
+
name: string;
|
|
466
|
+
}, allAttributes: Record<string, any>): SemanticKind;
|
|
467
|
+
|
|
446
468
|
declare class AiSdkTransformer implements ScopeTransformer {
|
|
447
469
|
private strategies;
|
|
448
470
|
constructor();
|
|
@@ -536,4 +558,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
536
558
|
*/
|
|
537
559
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
538
560
|
|
|
539
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, 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 };
|
|
561
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, 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, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, 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, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -219,6 +219,7 @@ interface NormalizedSpan {
|
|
|
219
219
|
duration: number;
|
|
220
220
|
name: string;
|
|
221
221
|
kind: string;
|
|
222
|
+
semanticKind?: string;
|
|
222
223
|
serviceName?: string;
|
|
223
224
|
statusCode: string;
|
|
224
225
|
statusMessage?: string;
|
|
@@ -443,6 +444,27 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
|
|
|
443
444
|
*/
|
|
444
445
|
declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
|
|
445
446
|
|
|
447
|
+
/** Valid semantic kind values. */
|
|
448
|
+
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
449
|
+
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
450
|
+
/**
|
|
451
|
+
* Resolve the semantic kind of a span using an 8-level priority chain.
|
|
452
|
+
*
|
|
453
|
+
* Priority:
|
|
454
|
+
* 1. normalized.semanticKind (from agentmark.span.kind attribute) — if valid
|
|
455
|
+
* 2. openinference.span.kind attribute
|
|
456
|
+
* 3. Framework-specific attributes (Vercel AI SDK, Traceloop, LangChain, Genkit)
|
|
457
|
+
* 4. gen_ai.operation.name → llm/embedding
|
|
458
|
+
* 5. Type = GENERATION → llm
|
|
459
|
+
* 6. Has non-empty ToolCalls → tool
|
|
460
|
+
* 7. Name-based heuristics
|
|
461
|
+
* 8. Default → function
|
|
462
|
+
*/
|
|
463
|
+
declare function resolveSemanticKind(normalized: Partial<NormalizedSpan> & {
|
|
464
|
+
type: SpanType;
|
|
465
|
+
name: string;
|
|
466
|
+
}, allAttributes: Record<string, any>): SemanticKind;
|
|
467
|
+
|
|
446
468
|
declare class AiSdkTransformer implements ScopeTransformer {
|
|
447
469
|
private strategies;
|
|
448
470
|
constructor();
|
|
@@ -536,4 +558,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
536
558
|
*/
|
|
537
559
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
538
560
|
|
|
539
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, 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 };
|
|
561
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, type GenerateTypesLanguage, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, type OtelEvent, OtelGenAiTransformer, 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, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, 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, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
ClaudeAgentTransformer: () => AgentMarkTransformer,
|
|
37
37
|
MastraTransformer: () => MastraTransformer,
|
|
38
38
|
OtelGenAiTransformer: () => OtelGenAiTransformer,
|
|
39
|
+
SEMANTIC_KINDS: () => SEMANTIC_KINDS,
|
|
39
40
|
SpanType: () => SpanType,
|
|
40
41
|
TransformerRegistry: () => TransformerRegistry,
|
|
41
42
|
TypeClassifier: () => TypeClassifier,
|
|
@@ -55,6 +56,7 @@ __export(index_exports, {
|
|
|
55
56
|
parseMetadata: () => parseMetadata,
|
|
56
57
|
parseTokens: () => parseTokens,
|
|
57
58
|
registry: () => registry,
|
|
59
|
+
resolveSemanticKind: () => resolveSemanticKind,
|
|
58
60
|
toFrontMatter: () => toFrontMatter,
|
|
59
61
|
typeClassifier: () => typeClassifier,
|
|
60
62
|
verifySignature: () => verifySignature
|
|
@@ -889,8 +891,7 @@ var KNOWN_METADATA_FIELDS = /* @__PURE__ */ new Set([
|
|
|
889
891
|
"dataset_expected_output",
|
|
890
892
|
"dataset_input",
|
|
891
893
|
"prompt_name",
|
|
892
|
-
"props"
|
|
893
|
-
"commit_sha"
|
|
894
|
+
"props"
|
|
894
895
|
]);
|
|
895
896
|
function parseMetadata(attributes, prefix = "agentmark.metadata.") {
|
|
896
897
|
const result = {};
|
|
@@ -1675,7 +1676,7 @@ function parseAgentMarkAttributes(attributes, prefix = "agentmark.") {
|
|
|
1675
1676
|
if (get("trace_name")) result.traceName = String(get("trace_name"));
|
|
1676
1677
|
if (get("prompt_name")) result.promptName = String(get("prompt_name"));
|
|
1677
1678
|
if (get("props")) result.props = String(get("props"));
|
|
1678
|
-
if (get("span.kind")) result.
|
|
1679
|
+
if (get("span.kind")) result.semanticKind = String(get("span.kind"));
|
|
1679
1680
|
if (get("dataset_run_id")) result.datasetRunId = String(get("dataset_run_id"));
|
|
1680
1681
|
if (get("dataset_run_name")) result.datasetRunName = String(get("dataset_run_name"));
|
|
1681
1682
|
if (get("dataset_item_name")) result.datasetItemName = String(get("dataset_item_name"));
|
|
@@ -1745,6 +1746,9 @@ var AgentMarkTransformer = class {
|
|
|
1745
1746
|
if (operationName === OperationNames.CHAT || operationName === OperationNames.TEXT_COMPLETION) {
|
|
1746
1747
|
return "GENERATION" /* GENERATION */;
|
|
1747
1748
|
}
|
|
1749
|
+
if (operationName === OperationNames.EMBEDDINGS) {
|
|
1750
|
+
return "GENERATION" /* GENERATION */;
|
|
1751
|
+
}
|
|
1748
1752
|
if (span.name === SpanNames.CHAT || span.name.startsWith(SpanNames.CHAT + " ")) {
|
|
1749
1753
|
return "GENERATION" /* GENERATION */;
|
|
1750
1754
|
}
|
|
@@ -2167,6 +2171,83 @@ function extractResourceScopeSpan(resourceSpans) {
|
|
|
2167
2171
|
return result;
|
|
2168
2172
|
}
|
|
2169
2173
|
|
|
2174
|
+
// src/normalizer/resolvers/semantic-kind-resolver.ts
|
|
2175
|
+
var SEMANTIC_KINDS = ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
2176
|
+
var VALID_KINDS = new Set(SEMANTIC_KINDS);
|
|
2177
|
+
var OPENINFERENCE_MAP = {
|
|
2178
|
+
"CHAIN": "function",
|
|
2179
|
+
"LLM": "llm",
|
|
2180
|
+
"TOOL": "tool",
|
|
2181
|
+
"AGENT": "agent",
|
|
2182
|
+
"RETRIEVER": "retrieval",
|
|
2183
|
+
"EMBEDDING": "embedding",
|
|
2184
|
+
"GUARDRAIL": "guardrail",
|
|
2185
|
+
"RERANKER": "retrieval"
|
|
2186
|
+
};
|
|
2187
|
+
var FRAMEWORK_MAPPINGS = [
|
|
2188
|
+
{
|
|
2189
|
+
key: "ai.operationId",
|
|
2190
|
+
// Vercel AI SDK
|
|
2191
|
+
map: {
|
|
2192
|
+
"embed": "embedding",
|
|
2193
|
+
"ai.embed": "embedding",
|
|
2194
|
+
"generateText": "llm",
|
|
2195
|
+
"streamText": "llm",
|
|
2196
|
+
"generateObject": "llm",
|
|
2197
|
+
"streamObject": "llm"
|
|
2198
|
+
}
|
|
2199
|
+
},
|
|
2200
|
+
{
|
|
2201
|
+
key: "traceloop.span.kind",
|
|
2202
|
+
// Traceloop / OpenLLMetry
|
|
2203
|
+
map: { "LLM": "llm", "TOOL": "tool", "AGENT": "agent", "WORKFLOW": "function", "TASK": "function" }
|
|
2204
|
+
},
|
|
2205
|
+
{
|
|
2206
|
+
key: "langchain.run_type",
|
|
2207
|
+
// LangChain via OTLP
|
|
2208
|
+
map: { "llm": "llm", "chat_model": "llm", "retriever": "retrieval", "tool": "tool", "chain": "function", "embedding": "embedding" }
|
|
2209
|
+
},
|
|
2210
|
+
{
|
|
2211
|
+
key: "genkit:type",
|
|
2212
|
+
// Firebase Genkit
|
|
2213
|
+
map: { "model": "llm", "tool": "tool", "flow": "function", "retriever": "retrieval", "embedder": "embedding" }
|
|
2214
|
+
}
|
|
2215
|
+
];
|
|
2216
|
+
function resolveSemanticKind(normalized, allAttributes) {
|
|
2217
|
+
if (normalized.semanticKind && VALID_KINDS.has(normalized.semanticKind)) {
|
|
2218
|
+
return normalized.semanticKind;
|
|
2219
|
+
}
|
|
2220
|
+
const oiKind = allAttributes["openinference.span.kind"];
|
|
2221
|
+
if (oiKind) {
|
|
2222
|
+
const mapped = OPENINFERENCE_MAP[String(oiKind).toUpperCase()];
|
|
2223
|
+
if (mapped) return mapped;
|
|
2224
|
+
}
|
|
2225
|
+
for (const { key, map } of FRAMEWORK_MAPPINGS) {
|
|
2226
|
+
const val = allAttributes[key];
|
|
2227
|
+
if (val) {
|
|
2228
|
+
const mapped = map[String(val)];
|
|
2229
|
+
if (mapped) return mapped;
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
const opName = allAttributes["gen_ai.operation.name"];
|
|
2233
|
+
if (opName) {
|
|
2234
|
+
const op = String(opName).toLowerCase();
|
|
2235
|
+
if (op === "chat" || op === "text_completion" || op === "generate_content") return "llm";
|
|
2236
|
+
if (op === "embeddings") return "embedding";
|
|
2237
|
+
}
|
|
2238
|
+
if (normalized.type === "GENERATION" /* GENERATION */) {
|
|
2239
|
+
return "llm";
|
|
2240
|
+
}
|
|
2241
|
+
if (normalized.toolCalls && normalized.toolCalls.length > 0) {
|
|
2242
|
+
return "tool";
|
|
2243
|
+
}
|
|
2244
|
+
const name = (normalized.name || "").toLowerCase();
|
|
2245
|
+
if (/retriev|search|rag/i.test(name)) return "retrieval";
|
|
2246
|
+
if (/embed/i.test(name)) return "embedding";
|
|
2247
|
+
if (/guard|safety/i.test(name)) return "guardrail";
|
|
2248
|
+
return "function";
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2170
2251
|
// src/normalizer/type-classifier.ts
|
|
2171
2252
|
var TypeClassifier = class {
|
|
2172
2253
|
classify(span, attributes) {
|
|
@@ -2245,6 +2326,7 @@ function normalizeSpan(resource, scope, span) {
|
|
|
2245
2326
|
}
|
|
2246
2327
|
const agentMarkAttributes = parseAgentMarkAttributes(allAttributes);
|
|
2247
2328
|
Object.assign(normalized, agentMarkAttributes);
|
|
2329
|
+
normalized.semanticKind = resolveSemanticKind(normalized, allAttributes);
|
|
2248
2330
|
return normalized;
|
|
2249
2331
|
}
|
|
2250
2332
|
function normalizeOtlpSpans(resourceSpans) {
|
|
@@ -2265,6 +2347,7 @@ function normalizeOtlpSpans(resourceSpans) {
|
|
|
2265
2347
|
ClaudeAgentTransformer,
|
|
2266
2348
|
MastraTransformer,
|
|
2267
2349
|
OtelGenAiTransformer,
|
|
2350
|
+
SEMANTIC_KINDS,
|
|
2268
2351
|
SpanType,
|
|
2269
2352
|
TransformerRegistry,
|
|
2270
2353
|
TypeClassifier,
|
|
@@ -2284,6 +2367,7 @@ function normalizeOtlpSpans(resourceSpans) {
|
|
|
2284
2367
|
parseMetadata,
|
|
2285
2368
|
parseTokens,
|
|
2286
2369
|
registry,
|
|
2370
|
+
resolveSemanticKind,
|
|
2287
2371
|
toFrontMatter,
|
|
2288
2372
|
typeClassifier,
|
|
2289
2373
|
verifySignature
|