@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.mjs
CHANGED
|
@@ -826,8 +826,7 @@ var KNOWN_METADATA_FIELDS = /* @__PURE__ */ new Set([
|
|
|
826
826
|
"dataset_expected_output",
|
|
827
827
|
"dataset_input",
|
|
828
828
|
"prompt_name",
|
|
829
|
-
"props"
|
|
830
|
-
"commit_sha"
|
|
829
|
+
"props"
|
|
831
830
|
]);
|
|
832
831
|
function parseMetadata(attributes, prefix = "agentmark.metadata.") {
|
|
833
832
|
const result = {};
|
|
@@ -1612,7 +1611,7 @@ function parseAgentMarkAttributes(attributes, prefix = "agentmark.") {
|
|
|
1612
1611
|
if (get("trace_name")) result.traceName = String(get("trace_name"));
|
|
1613
1612
|
if (get("prompt_name")) result.promptName = String(get("prompt_name"));
|
|
1614
1613
|
if (get("props")) result.props = String(get("props"));
|
|
1615
|
-
if (get("span.kind")) result.
|
|
1614
|
+
if (get("span.kind")) result.semanticKind = String(get("span.kind"));
|
|
1616
1615
|
if (get("dataset_run_id")) result.datasetRunId = String(get("dataset_run_id"));
|
|
1617
1616
|
if (get("dataset_run_name")) result.datasetRunName = String(get("dataset_run_name"));
|
|
1618
1617
|
if (get("dataset_item_name")) result.datasetItemName = String(get("dataset_item_name"));
|
|
@@ -1682,6 +1681,9 @@ var AgentMarkTransformer = class {
|
|
|
1682
1681
|
if (operationName === OperationNames.CHAT || operationName === OperationNames.TEXT_COMPLETION) {
|
|
1683
1682
|
return "GENERATION" /* GENERATION */;
|
|
1684
1683
|
}
|
|
1684
|
+
if (operationName === OperationNames.EMBEDDINGS) {
|
|
1685
|
+
return "GENERATION" /* GENERATION */;
|
|
1686
|
+
}
|
|
1685
1687
|
if (span.name === SpanNames.CHAT || span.name.startsWith(SpanNames.CHAT + " ")) {
|
|
1686
1688
|
return "GENERATION" /* GENERATION */;
|
|
1687
1689
|
}
|
|
@@ -2104,6 +2106,83 @@ function extractResourceScopeSpan(resourceSpans) {
|
|
|
2104
2106
|
return result;
|
|
2105
2107
|
}
|
|
2106
2108
|
|
|
2109
|
+
// src/normalizer/resolvers/semantic-kind-resolver.ts
|
|
2110
|
+
var SEMANTIC_KINDS = ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
2111
|
+
var VALID_KINDS = new Set(SEMANTIC_KINDS);
|
|
2112
|
+
var OPENINFERENCE_MAP = {
|
|
2113
|
+
"CHAIN": "function",
|
|
2114
|
+
"LLM": "llm",
|
|
2115
|
+
"TOOL": "tool",
|
|
2116
|
+
"AGENT": "agent",
|
|
2117
|
+
"RETRIEVER": "retrieval",
|
|
2118
|
+
"EMBEDDING": "embedding",
|
|
2119
|
+
"GUARDRAIL": "guardrail",
|
|
2120
|
+
"RERANKER": "retrieval"
|
|
2121
|
+
};
|
|
2122
|
+
var FRAMEWORK_MAPPINGS = [
|
|
2123
|
+
{
|
|
2124
|
+
key: "ai.operationId",
|
|
2125
|
+
// Vercel AI SDK
|
|
2126
|
+
map: {
|
|
2127
|
+
"embed": "embedding",
|
|
2128
|
+
"ai.embed": "embedding",
|
|
2129
|
+
"generateText": "llm",
|
|
2130
|
+
"streamText": "llm",
|
|
2131
|
+
"generateObject": "llm",
|
|
2132
|
+
"streamObject": "llm"
|
|
2133
|
+
}
|
|
2134
|
+
},
|
|
2135
|
+
{
|
|
2136
|
+
key: "traceloop.span.kind",
|
|
2137
|
+
// Traceloop / OpenLLMetry
|
|
2138
|
+
map: { "LLM": "llm", "TOOL": "tool", "AGENT": "agent", "WORKFLOW": "function", "TASK": "function" }
|
|
2139
|
+
},
|
|
2140
|
+
{
|
|
2141
|
+
key: "langchain.run_type",
|
|
2142
|
+
// LangChain via OTLP
|
|
2143
|
+
map: { "llm": "llm", "chat_model": "llm", "retriever": "retrieval", "tool": "tool", "chain": "function", "embedding": "embedding" }
|
|
2144
|
+
},
|
|
2145
|
+
{
|
|
2146
|
+
key: "genkit:type",
|
|
2147
|
+
// Firebase Genkit
|
|
2148
|
+
map: { "model": "llm", "tool": "tool", "flow": "function", "retriever": "retrieval", "embedder": "embedding" }
|
|
2149
|
+
}
|
|
2150
|
+
];
|
|
2151
|
+
function resolveSemanticKind(normalized, allAttributes) {
|
|
2152
|
+
if (normalized.semanticKind && VALID_KINDS.has(normalized.semanticKind)) {
|
|
2153
|
+
return normalized.semanticKind;
|
|
2154
|
+
}
|
|
2155
|
+
const oiKind = allAttributes["openinference.span.kind"];
|
|
2156
|
+
if (oiKind) {
|
|
2157
|
+
const mapped = OPENINFERENCE_MAP[String(oiKind).toUpperCase()];
|
|
2158
|
+
if (mapped) return mapped;
|
|
2159
|
+
}
|
|
2160
|
+
for (const { key, map } of FRAMEWORK_MAPPINGS) {
|
|
2161
|
+
const val = allAttributes[key];
|
|
2162
|
+
if (val) {
|
|
2163
|
+
const mapped = map[String(val)];
|
|
2164
|
+
if (mapped) return mapped;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
const opName = allAttributes["gen_ai.operation.name"];
|
|
2168
|
+
if (opName) {
|
|
2169
|
+
const op = String(opName).toLowerCase();
|
|
2170
|
+
if (op === "chat" || op === "text_completion" || op === "generate_content") return "llm";
|
|
2171
|
+
if (op === "embeddings") return "embedding";
|
|
2172
|
+
}
|
|
2173
|
+
if (normalized.type === "GENERATION" /* GENERATION */) {
|
|
2174
|
+
return "llm";
|
|
2175
|
+
}
|
|
2176
|
+
if (normalized.toolCalls && normalized.toolCalls.length > 0) {
|
|
2177
|
+
return "tool";
|
|
2178
|
+
}
|
|
2179
|
+
const name = (normalized.name || "").toLowerCase();
|
|
2180
|
+
if (/retriev|search|rag/i.test(name)) return "retrieval";
|
|
2181
|
+
if (/embed/i.test(name)) return "embedding";
|
|
2182
|
+
if (/guard|safety/i.test(name)) return "guardrail";
|
|
2183
|
+
return "function";
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2107
2186
|
// src/normalizer/type-classifier.ts
|
|
2108
2187
|
var TypeClassifier = class {
|
|
2109
2188
|
classify(span, attributes) {
|
|
@@ -2182,6 +2261,7 @@ function normalizeSpan(resource, scope, span) {
|
|
|
2182
2261
|
}
|
|
2183
2262
|
const agentMarkAttributes = parseAgentMarkAttributes(allAttributes);
|
|
2184
2263
|
Object.assign(normalized, agentMarkAttributes);
|
|
2264
|
+
normalized.semanticKind = resolveSemanticKind(normalized, allAttributes);
|
|
2185
2265
|
return normalized;
|
|
2186
2266
|
}
|
|
2187
2267
|
function normalizeOtlpSpans(resourceSpans) {
|
|
@@ -2201,6 +2281,7 @@ export {
|
|
|
2201
2281
|
AgentMarkTransformer as ClaudeAgentTransformer,
|
|
2202
2282
|
MastraTransformer,
|
|
2203
2283
|
OtelGenAiTransformer,
|
|
2284
|
+
SEMANTIC_KINDS,
|
|
2204
2285
|
SpanType,
|
|
2205
2286
|
TransformerRegistry,
|
|
2206
2287
|
TypeClassifier,
|
|
@@ -2220,6 +2301,7 @@ export {
|
|
|
2220
2301
|
parseMetadata,
|
|
2221
2302
|
parseTokens,
|
|
2222
2303
|
registry,
|
|
2304
|
+
resolveSemanticKind,
|
|
2223
2305
|
toFrontMatter,
|
|
2224
2306
|
typeClassifier,
|
|
2225
2307
|
verifySignature
|