@agentmark-ai/shared-utils 0.7.0 → 0.8.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 +40 -6
- package/dist/index.d.ts +40 -6
- package/dist/index.js +216 -101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -175,6 +175,23 @@ interface ToolCall {
|
|
|
175
175
|
result?: string;
|
|
176
176
|
providerMetadata?: Record<string, any>;
|
|
177
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* A single document returned by a retriever / vector-store search, normalized
|
|
180
|
+
* from instrumentation that carries documents per-index (OpenInference's
|
|
181
|
+
* flattened `retrieval.documents.{i}.document.*`) or per-event (OpenLLMetry's
|
|
182
|
+
* `db.query.result` span events). Stored under a span's `outputObject` as
|
|
183
|
+
* `{ documents: RetrievalDocument[] }` so the UI can render a ranked panel
|
|
184
|
+
* (relevance score / distance, content, metadata) instead of a single blob.
|
|
185
|
+
*/
|
|
186
|
+
interface RetrievalDocument {
|
|
187
|
+
id?: string;
|
|
188
|
+
content?: string;
|
|
189
|
+
/** Relevance/similarity score (higher = more relevant). */
|
|
190
|
+
score?: number;
|
|
191
|
+
/** Vector distance (lower = closer). Some stores report this instead of a score. */
|
|
192
|
+
distance?: number;
|
|
193
|
+
metadata?: Record<string, any>;
|
|
194
|
+
}
|
|
178
195
|
interface OtelScope {
|
|
179
196
|
name?: string;
|
|
180
197
|
version?: string;
|
|
@@ -537,6 +554,17 @@ declare function messagesToPlainText(messages: Message[] | undefined): string |
|
|
|
537
554
|
/** Valid semantic kind values. */
|
|
538
555
|
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
539
556
|
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
557
|
+
/**
|
|
558
|
+
* True when a span looks like a vector-store query: a recognized vector-DB
|
|
559
|
+
* `db.system`, any `db.vector.query.*` attribute, or `db.query.result` /
|
|
560
|
+
* `db.search.result` events. Distinguishes a vector search from a plain SQL
|
|
561
|
+
* query (which carries none of these). Shared by the semantic-kind resolver
|
|
562
|
+
* (→ classifies as "retrieval") and the dispatching transformer (→ routes to
|
|
563
|
+
* the OpenLLMetry extractor so the result events become documents).
|
|
564
|
+
*/
|
|
565
|
+
declare function hasVectorStoreSignature(attributes: Record<string, any>, events?: ReadonlyArray<{
|
|
566
|
+
name: string;
|
|
567
|
+
}>): boolean;
|
|
540
568
|
/**
|
|
541
569
|
* Resolve the semantic kind of a span using a 9-level priority chain.
|
|
542
570
|
*
|
|
@@ -660,6 +688,8 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
|
|
|
660
688
|
* @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
|
|
661
689
|
*/
|
|
662
690
|
|
|
691
|
+
/** Join document contents into a readable, searchable text output. */
|
|
692
|
+
declare function retrievalDocumentsToText(documents: RetrievalDocument[]): string | undefined;
|
|
663
693
|
declare class OpenInferenceTransformer implements ScopeTransformer {
|
|
664
694
|
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
665
695
|
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
@@ -710,11 +740,15 @@ declare class DispatchingTransformer implements ScopeTransformer {
|
|
|
710
740
|
private readonly openInference;
|
|
711
741
|
private readonly openLLMetry;
|
|
712
742
|
private readonly otelGenAi;
|
|
713
|
-
/** Choose the extractor for a span from its attribute signature.
|
|
714
|
-
* is checked before OpenLLMetry because its markers (`llm.*`,
|
|
715
|
-
* `openinference.span.kind`) are more specific
|
|
716
|
-
*
|
|
717
|
-
|
|
743
|
+
/** Choose the extractor for a span from its attribute/event signature.
|
|
744
|
+
* OpenInference is checked before OpenLLMetry because its markers (`llm.*`,
|
|
745
|
+
* `openinference.span.kind`) are more specific. Vector-store query spans
|
|
746
|
+
* route to the OpenLLMetry extractor — they may carry no `traceloop.*`
|
|
747
|
+
* marker (a bare Pinecone span is just `db.system` + `db.query.result`
|
|
748
|
+
* events), so without this they'd fall through to the OTel-GenAI catch-all
|
|
749
|
+
* and their result documents would be dropped. The bare OTel GenAI
|
|
750
|
+
* transformer is the final catch-all. */
|
|
751
|
+
select(attributes: Record<string, any>, span?: OtelSpan): ScopeTransformer;
|
|
718
752
|
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
719
753
|
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
720
754
|
}
|
|
@@ -727,4 +761,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
727
761
|
*/
|
|
728
762
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
729
763
|
|
|
730
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, 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, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
|
764
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, 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 RetrievalDocument, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, hasVectorStoreSignature, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, retrievalDocumentsToText, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -175,6 +175,23 @@ interface ToolCall {
|
|
|
175
175
|
result?: string;
|
|
176
176
|
providerMetadata?: Record<string, any>;
|
|
177
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* A single document returned by a retriever / vector-store search, normalized
|
|
180
|
+
* from instrumentation that carries documents per-index (OpenInference's
|
|
181
|
+
* flattened `retrieval.documents.{i}.document.*`) or per-event (OpenLLMetry's
|
|
182
|
+
* `db.query.result` span events). Stored under a span's `outputObject` as
|
|
183
|
+
* `{ documents: RetrievalDocument[] }` so the UI can render a ranked panel
|
|
184
|
+
* (relevance score / distance, content, metadata) instead of a single blob.
|
|
185
|
+
*/
|
|
186
|
+
interface RetrievalDocument {
|
|
187
|
+
id?: string;
|
|
188
|
+
content?: string;
|
|
189
|
+
/** Relevance/similarity score (higher = more relevant). */
|
|
190
|
+
score?: number;
|
|
191
|
+
/** Vector distance (lower = closer). Some stores report this instead of a score. */
|
|
192
|
+
distance?: number;
|
|
193
|
+
metadata?: Record<string, any>;
|
|
194
|
+
}
|
|
178
195
|
interface OtelScope {
|
|
179
196
|
name?: string;
|
|
180
197
|
version?: string;
|
|
@@ -537,6 +554,17 @@ declare function messagesToPlainText(messages: Message[] | undefined): string |
|
|
|
537
554
|
/** Valid semantic kind values. */
|
|
538
555
|
declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
539
556
|
type SemanticKind = typeof SEMANTIC_KINDS[number];
|
|
557
|
+
/**
|
|
558
|
+
* True when a span looks like a vector-store query: a recognized vector-DB
|
|
559
|
+
* `db.system`, any `db.vector.query.*` attribute, or `db.query.result` /
|
|
560
|
+
* `db.search.result` events. Distinguishes a vector search from a plain SQL
|
|
561
|
+
* query (which carries none of these). Shared by the semantic-kind resolver
|
|
562
|
+
* (→ classifies as "retrieval") and the dispatching transformer (→ routes to
|
|
563
|
+
* the OpenLLMetry extractor so the result events become documents).
|
|
564
|
+
*/
|
|
565
|
+
declare function hasVectorStoreSignature(attributes: Record<string, any>, events?: ReadonlyArray<{
|
|
566
|
+
name: string;
|
|
567
|
+
}>): boolean;
|
|
540
568
|
/**
|
|
541
569
|
* Resolve the semantic kind of a span using a 9-level priority chain.
|
|
542
570
|
*
|
|
@@ -660,6 +688,8 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
|
|
|
660
688
|
* @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
|
|
661
689
|
*/
|
|
662
690
|
|
|
691
|
+
/** Join document contents into a readable, searchable text output. */
|
|
692
|
+
declare function retrievalDocumentsToText(documents: RetrievalDocument[]): string | undefined;
|
|
663
693
|
declare class OpenInferenceTransformer implements ScopeTransformer {
|
|
664
694
|
classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
665
695
|
transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
@@ -710,11 +740,15 @@ declare class DispatchingTransformer implements ScopeTransformer {
|
|
|
710
740
|
private readonly openInference;
|
|
711
741
|
private readonly openLLMetry;
|
|
712
742
|
private readonly otelGenAi;
|
|
713
|
-
/** Choose the extractor for a span from its attribute signature.
|
|
714
|
-
* is checked before OpenLLMetry because its markers (`llm.*`,
|
|
715
|
-
* `openinference.span.kind`) are more specific
|
|
716
|
-
*
|
|
717
|
-
|
|
743
|
+
/** Choose the extractor for a span from its attribute/event signature.
|
|
744
|
+
* OpenInference is checked before OpenLLMetry because its markers (`llm.*`,
|
|
745
|
+
* `openinference.span.kind`) are more specific. Vector-store query spans
|
|
746
|
+
* route to the OpenLLMetry extractor — they may carry no `traceloop.*`
|
|
747
|
+
* marker (a bare Pinecone span is just `db.system` + `db.query.result`
|
|
748
|
+
* events), so without this they'd fall through to the OTel-GenAI catch-all
|
|
749
|
+
* and their result documents would be dropped. The bare OTel GenAI
|
|
750
|
+
* transformer is the final catch-all. */
|
|
751
|
+
select(attributes: Record<string, any>, span?: OtelSpan): ScopeTransformer;
|
|
718
752
|
classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
|
|
719
753
|
transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
|
|
720
754
|
}
|
|
@@ -727,4 +761,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
|
|
|
727
761
|
*/
|
|
728
762
|
declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
|
|
729
763
|
|
|
730
|
-
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, 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, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, toFrontMatter, typeClassifier, verifySignature };
|
|
764
|
+
export { AGENTMARK_SCOPE_NAME, AgentMarkTransformer, type AgentmarkConfig, type AgentmarkModelConfig, type AgentmarkModelSchema, type AgentmarkModelSettingsConfig, type AgentmarkModelSettingsSchema, AiSdkTransformer, type AiSdkVersion, type AttributeExtractor, AgentMarkTransformer as ClaudeAgentTransformer, DispatchingTransformer, type GenerateTypesLanguage, type IndexedMessageConfig, MastraTransformer, type McpServerConfig, type McpServers, type McpStdioServerConfig, type McpUrlServerConfig, type Message, type ModelSettingsTypeAspectRatio, type ModelSettingsTypeImageSize, type ModelSettingsTypeSelect, type ModelSettingsTypeSlider, type NormalizedSpan, OpenInferenceTransformer, OpenLLMetryTransformer, 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 RetrievalDocument, SEMANTIC_KINDS, type ScopeTransformer, type SemanticKind, SpanType, type StandardMessageContent, type StandardTextContent, type StandardToolCallContent, type StandardToolResultContent, type ToolCall, TransformerRegistry, TypeClassifier, collectIndices, convertOtlpAttributes, createSignature, detectVersion, extractCustomMetadata, extractIndexedToolCalls, extractReasoningFromProviderMetadata, extractResourceScopeSpan, fetchPromptsFrontmatter, findPromptFiles, generateTypeDefinitions, generateUnique8CharString, hasVectorStoreSignature, messagesToPlainText, normalizeOtlpSpans, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, parseIndexedMessages, parseMetadata, parseTokens, registry, resolveSemanticKind, retrievalDocumentsToText, toFrontMatter, typeClassifier, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ __export(index_exports, {
|
|
|
56
56
|
findPromptFiles: () => findPromptFiles,
|
|
57
57
|
generateTypeDefinitions: () => generateTypeDefinitions,
|
|
58
58
|
generateUnique8CharString: () => generateUnique8CharString,
|
|
59
|
+
hasVectorStoreSignature: () => hasVectorStoreSignature,
|
|
59
60
|
messagesToPlainText: () => messagesToPlainText,
|
|
60
61
|
normalizeOtlpSpans: () => normalizeOtlpSpans,
|
|
61
62
|
normalizeOtlpStatusCode: () => normalizeOtlpStatusCode,
|
|
@@ -66,6 +67,7 @@ __export(index_exports, {
|
|
|
66
67
|
parseTokens: () => parseTokens,
|
|
67
68
|
registry: () => registry,
|
|
68
69
|
resolveSemanticKind: () => resolveSemanticKind,
|
|
70
|
+
retrievalDocumentsToText: () => retrievalDocumentsToText,
|
|
69
71
|
toFrontMatter: () => toFrontMatter,
|
|
70
72
|
typeClassifier: () => typeClassifier,
|
|
71
73
|
verifySignature: () => verifySignature
|
|
@@ -2441,13 +2443,38 @@ function extractGenericOutput(attributes) {
|
|
|
2441
2443
|
}
|
|
2442
2444
|
return { output: String(value) };
|
|
2443
2445
|
}
|
|
2446
|
+
function parseDocumentMetadata(raw) {
|
|
2447
|
+
let parsed = raw;
|
|
2448
|
+
if (typeof raw === "string") {
|
|
2449
|
+
try {
|
|
2450
|
+
parsed = JSON.parse(raw);
|
|
2451
|
+
} catch {
|
|
2452
|
+
return void 0;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
2456
|
+
return void 0;
|
|
2457
|
+
}
|
|
2444
2458
|
function extractRetrievalDocuments(attributes) {
|
|
2445
2459
|
const docs = [];
|
|
2446
2460
|
for (const i of collectIndices(attributes, RETRIEVAL_PREFIX)) {
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2461
|
+
const base = `${RETRIEVAL_PREFIX}.${i}.document`;
|
|
2462
|
+
const doc = {};
|
|
2463
|
+
const id = attributes[`${base}.id`];
|
|
2464
|
+
if (id !== void 0 && id !== null && String(id).length > 0) doc.id = String(id);
|
|
2465
|
+
const content = attributes[`${base}.content`];
|
|
2466
|
+
if (typeof content === "string" && content.length > 0) doc.content = content;
|
|
2467
|
+
const score = toNumber(attributes[`${base}.score`]);
|
|
2468
|
+
if (score !== void 0) doc.score = score;
|
|
2469
|
+
const metadata = parseDocumentMetadata(attributes[`${base}.metadata`]);
|
|
2470
|
+
if (metadata !== void 0) doc.metadata = metadata;
|
|
2471
|
+
if (Object.keys(doc).length > 0) docs.push(doc);
|
|
2472
|
+
}
|
|
2473
|
+
return docs;
|
|
2474
|
+
}
|
|
2475
|
+
function retrievalDocumentsToText(documents) {
|
|
2476
|
+
const text = documents.map((d) => d.content).filter((c) => typeof c === "string" && c.length > 0).join("\n\n");
|
|
2477
|
+
return text.length > 0 ? text : void 0;
|
|
2451
2478
|
}
|
|
2452
2479
|
var OpenInferenceTransformer = class {
|
|
2453
2480
|
classify(_span, attributes) {
|
|
@@ -2491,9 +2518,13 @@ var OpenInferenceTransformer = class {
|
|
|
2491
2518
|
} else {
|
|
2492
2519
|
Object.assign(result, extractGenericOutput(attributes));
|
|
2493
2520
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
if (
|
|
2521
|
+
const documents = extractRetrievalDocuments(attributes);
|
|
2522
|
+
if (documents.length > 0) {
|
|
2523
|
+
if (result.outputObject === void 0) result.outputObject = { documents };
|
|
2524
|
+
if (result.output === void 0) {
|
|
2525
|
+
const text = retrievalDocumentsToText(documents);
|
|
2526
|
+
if (text) result.output = text;
|
|
2527
|
+
}
|
|
2497
2528
|
}
|
|
2498
2529
|
const toolName = attributes[Attrs2.TOOL_NAME];
|
|
2499
2530
|
if (typeof toolName === "string" && toolName.length > 0) result.name = toolName;
|
|
@@ -2595,6 +2626,51 @@ function extractFromEvents(events, attrKey) {
|
|
|
2595
2626
|
}
|
|
2596
2627
|
return void 0;
|
|
2597
2628
|
}
|
|
2629
|
+
function parseResultMetadata(raw) {
|
|
2630
|
+
let parsed = raw;
|
|
2631
|
+
if (typeof raw === "string") {
|
|
2632
|
+
try {
|
|
2633
|
+
parsed = JSON.parse(raw);
|
|
2634
|
+
} catch {
|
|
2635
|
+
return void 0;
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
2639
|
+
return void 0;
|
|
2640
|
+
}
|
|
2641
|
+
var VECTOR_RESULT_EVENT_NAMES = /* @__PURE__ */ new Set(["db.query.result", "db.search.result"]);
|
|
2642
|
+
function extractVectorResultDocuments(events) {
|
|
2643
|
+
var _a, _b;
|
|
2644
|
+
if (!events) return [];
|
|
2645
|
+
const docs = [];
|
|
2646
|
+
for (const event of events) {
|
|
2647
|
+
if (!VECTOR_RESULT_EVENT_NAMES.has(event.name)) continue;
|
|
2648
|
+
const a = (_a = event.attributes) != null ? _a : {};
|
|
2649
|
+
const get = (field) => {
|
|
2650
|
+
var _a2;
|
|
2651
|
+
return (_a2 = a[`db.query.result.${field}`]) != null ? _a2 : a[`db.search.result.${field}`];
|
|
2652
|
+
};
|
|
2653
|
+
const doc = {};
|
|
2654
|
+
const id = get("id");
|
|
2655
|
+
if (id !== void 0 && id !== null && String(id).length > 0) doc.id = String(id);
|
|
2656
|
+
const content = get("document");
|
|
2657
|
+
if (typeof content === "string" && content.length > 0) doc.content = content;
|
|
2658
|
+
const score = toNumber(get("score"));
|
|
2659
|
+
if (score !== void 0) doc.score = score;
|
|
2660
|
+
const distance = toNumber(get("distance"));
|
|
2661
|
+
if (distance !== void 0) doc.distance = distance;
|
|
2662
|
+
let metadata = parseResultMetadata(get("metadata"));
|
|
2663
|
+
if (metadata === void 0) {
|
|
2664
|
+
const entity = get("entity");
|
|
2665
|
+
if (entity !== void 0 && entity !== null && String(entity).length > 0) {
|
|
2666
|
+
metadata = (_b = parseResultMetadata(entity)) != null ? _b : { entity: String(entity) };
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
if (metadata !== void 0) doc.metadata = metadata;
|
|
2670
|
+
if (Object.keys(doc).length > 0) docs.push(doc);
|
|
2671
|
+
}
|
|
2672
|
+
return docs;
|
|
2673
|
+
}
|
|
2598
2674
|
function extractFinishReason(attributes) {
|
|
2599
2675
|
const direct = attributes[Attrs3.RESPONSE_FINISH_REASON];
|
|
2600
2676
|
if (direct !== void 0) {
|
|
@@ -2664,6 +2740,16 @@ var OpenLLMetryTransformer = class {
|
|
|
2664
2740
|
if (eventCompletion) result.output = eventCompletion;
|
|
2665
2741
|
}
|
|
2666
2742
|
}
|
|
2743
|
+
if (result.outputObject === void 0) {
|
|
2744
|
+
const documents = extractVectorResultDocuments(span.events);
|
|
2745
|
+
if (documents.length > 0) {
|
|
2746
|
+
result.outputObject = { documents };
|
|
2747
|
+
if (result.output === void 0) {
|
|
2748
|
+
const text = documents.map((d) => d.content).filter((c) => typeof c === "string" && c.length > 0).join("\n\n");
|
|
2749
|
+
if (text) result.output = text;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2667
2753
|
const entityName = attributes[Attrs3.ENTITY_NAME];
|
|
2668
2754
|
if (typeof entityName === "string" && entityName.length > 0) result.traceName = entityName;
|
|
2669
2755
|
const metadata = {};
|
|
@@ -2683,6 +2769,115 @@ var OpenLLMetryTransformer = class {
|
|
|
2683
2769
|
}
|
|
2684
2770
|
};
|
|
2685
2771
|
|
|
2772
|
+
// src/normalizer/resolvers/semantic-kind-resolver.ts
|
|
2773
|
+
var SEMANTIC_KINDS = ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
2774
|
+
var VALID_KINDS = new Set(SEMANTIC_KINDS);
|
|
2775
|
+
var OPENINFERENCE_MAP = {
|
|
2776
|
+
"CHAIN": "function",
|
|
2777
|
+
"LLM": "llm",
|
|
2778
|
+
"TOOL": "tool",
|
|
2779
|
+
"AGENT": "agent",
|
|
2780
|
+
"RETRIEVER": "retrieval",
|
|
2781
|
+
"EMBEDDING": "embedding",
|
|
2782
|
+
"GUARDRAIL": "guardrail",
|
|
2783
|
+
"RERANKER": "retrieval"
|
|
2784
|
+
};
|
|
2785
|
+
var VECTOR_DB_SYSTEMS = /* @__PURE__ */ new Set([
|
|
2786
|
+
"pinecone",
|
|
2787
|
+
"qdrant",
|
|
2788
|
+
"weaviate",
|
|
2789
|
+
"milvus",
|
|
2790
|
+
"chroma",
|
|
2791
|
+
"chromadb",
|
|
2792
|
+
"marqo",
|
|
2793
|
+
"lancedb"
|
|
2794
|
+
]);
|
|
2795
|
+
var VECTOR_RESULT_EVENT_NAMES2 = /* @__PURE__ */ new Set(["db.query.result", "db.search.result"]);
|
|
2796
|
+
function hasVectorStoreSignature(attributes, events) {
|
|
2797
|
+
var _a;
|
|
2798
|
+
const dbSystem = (_a = attributes["db.system"]) != null ? _a : attributes["db.system.name"];
|
|
2799
|
+
if (typeof dbSystem === "string" && VECTOR_DB_SYSTEMS.has(dbSystem.toLowerCase())) return true;
|
|
2800
|
+
if (Object.keys(attributes).some((k) => k.startsWith("db.vector.query."))) return true;
|
|
2801
|
+
if (events == null ? void 0 : events.some((e) => VECTOR_RESULT_EVENT_NAMES2.has(e.name))) return true;
|
|
2802
|
+
return false;
|
|
2803
|
+
}
|
|
2804
|
+
var FRAMEWORK_MAPPINGS = [
|
|
2805
|
+
{
|
|
2806
|
+
key: "ai.operationId",
|
|
2807
|
+
// Vercel AI SDK
|
|
2808
|
+
// The AI SDK emits ai.operationId WITH the "ai." prefix (e.g.
|
|
2809
|
+
// "ai.generateText"); accept both prefixed and unprefixed so generation
|
|
2810
|
+
// wrappers resolve to "llm" instead of falling through to "function".
|
|
2811
|
+
map: {
|
|
2812
|
+
"embed": "embedding",
|
|
2813
|
+
"ai.embed": "embedding",
|
|
2814
|
+
"generateText": "llm",
|
|
2815
|
+
"ai.generateText": "llm",
|
|
2816
|
+
"streamText": "llm",
|
|
2817
|
+
"ai.streamText": "llm",
|
|
2818
|
+
"generateObject": "llm",
|
|
2819
|
+
"ai.generateObject": "llm",
|
|
2820
|
+
"streamObject": "llm",
|
|
2821
|
+
"ai.streamObject": "llm"
|
|
2822
|
+
}
|
|
2823
|
+
},
|
|
2824
|
+
{
|
|
2825
|
+
key: "traceloop.span.kind",
|
|
2826
|
+
// Traceloop / OpenLLMetry
|
|
2827
|
+
map: { "LLM": "llm", "TOOL": "tool", "AGENT": "agent", "WORKFLOW": "function", "TASK": "function" }
|
|
2828
|
+
},
|
|
2829
|
+
{
|
|
2830
|
+
key: "langchain.run_type",
|
|
2831
|
+
// LangChain via OTLP
|
|
2832
|
+
map: { "llm": "llm", "chat_model": "llm", "retriever": "retrieval", "tool": "tool", "chain": "function", "embedding": "embedding" }
|
|
2833
|
+
},
|
|
2834
|
+
{
|
|
2835
|
+
key: "genkit:type",
|
|
2836
|
+
// Firebase Genkit
|
|
2837
|
+
map: { "model": "llm", "tool": "tool", "flow": "function", "retriever": "retrieval", "embedder": "embedding" }
|
|
2838
|
+
}
|
|
2839
|
+
];
|
|
2840
|
+
function resolveSemanticKind(normalized, allAttributes) {
|
|
2841
|
+
if (normalized.semanticKind && VALID_KINDS.has(normalized.semanticKind)) {
|
|
2842
|
+
return normalized.semanticKind;
|
|
2843
|
+
}
|
|
2844
|
+
const oiKind = allAttributes["openinference.span.kind"];
|
|
2845
|
+
if (oiKind) {
|
|
2846
|
+
const mapped = OPENINFERENCE_MAP[String(oiKind).toUpperCase()];
|
|
2847
|
+
if (mapped) return mapped;
|
|
2848
|
+
}
|
|
2849
|
+
for (const { key, map } of FRAMEWORK_MAPPINGS) {
|
|
2850
|
+
const val = allAttributes[key];
|
|
2851
|
+
if (val) {
|
|
2852
|
+
const mapped = map[String(val)];
|
|
2853
|
+
if (mapped) return mapped;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
if (hasVectorStoreSignature(allAttributes, normalized.events)) {
|
|
2857
|
+
return "retrieval";
|
|
2858
|
+
}
|
|
2859
|
+
const opName = allAttributes["gen_ai.operation.name"];
|
|
2860
|
+
if (opName) {
|
|
2861
|
+
const op = String(opName).toLowerCase();
|
|
2862
|
+
if (op === "chat" || op === "text_completion" || op === "generate_content") return "llm";
|
|
2863
|
+
if (op === "embeddings") return "embedding";
|
|
2864
|
+
}
|
|
2865
|
+
if (normalized.type === "GENERATION" /* GENERATION */) {
|
|
2866
|
+
return "llm";
|
|
2867
|
+
}
|
|
2868
|
+
if (normalized.model) {
|
|
2869
|
+
return "llm";
|
|
2870
|
+
}
|
|
2871
|
+
if (normalized.toolCalls && normalized.toolCalls.length > 0) {
|
|
2872
|
+
return "tool";
|
|
2873
|
+
}
|
|
2874
|
+
const name = (normalized.name || "").toLowerCase();
|
|
2875
|
+
if (/retriev|search|rag/i.test(name)) return "retrieval";
|
|
2876
|
+
if (/embed/i.test(name)) return "embedding";
|
|
2877
|
+
if (/guard|safety/i.test(name)) return "guardrail";
|
|
2878
|
+
return "function";
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2686
2881
|
// src/normalizer/transformers/dispatching/index.ts
|
|
2687
2882
|
var OPENINFERENCE_INDEXED = /^llm\.(input_messages|output_messages|token_count)\./;
|
|
2688
2883
|
var OPENLLMETRY_INDEXED = /^gen_ai\.(prompt|completion)\.\d+\./;
|
|
@@ -2707,20 +2902,25 @@ var DispatchingTransformer = class {
|
|
|
2707
2902
|
this.openLLMetry = new OpenLLMetryTransformer();
|
|
2708
2903
|
this.otelGenAi = new OtelGenAiTransformer();
|
|
2709
2904
|
}
|
|
2710
|
-
/** Choose the extractor for a span from its attribute signature.
|
|
2711
|
-
* is checked before OpenLLMetry because its markers (`llm.*`,
|
|
2712
|
-
* `openinference.span.kind`) are more specific
|
|
2713
|
-
*
|
|
2714
|
-
|
|
2905
|
+
/** Choose the extractor for a span from its attribute/event signature.
|
|
2906
|
+
* OpenInference is checked before OpenLLMetry because its markers (`llm.*`,
|
|
2907
|
+
* `openinference.span.kind`) are more specific. Vector-store query spans
|
|
2908
|
+
* route to the OpenLLMetry extractor — they may carry no `traceloop.*`
|
|
2909
|
+
* marker (a bare Pinecone span is just `db.system` + `db.query.result`
|
|
2910
|
+
* events), so without this they'd fall through to the OTel-GenAI catch-all
|
|
2911
|
+
* and their result documents would be dropped. The bare OTel GenAI
|
|
2912
|
+
* transformer is the final catch-all. */
|
|
2913
|
+
select(attributes, span) {
|
|
2715
2914
|
if (isOpenInference(attributes)) return this.openInference;
|
|
2716
2915
|
if (isOpenLLMetry(attributes)) return this.openLLMetry;
|
|
2916
|
+
if (hasVectorStoreSignature(attributes, span == null ? void 0 : span.events)) return this.openLLMetry;
|
|
2717
2917
|
return this.otelGenAi;
|
|
2718
2918
|
}
|
|
2719
2919
|
classify(span, attributes) {
|
|
2720
|
-
return this.select(attributes).classify(span, attributes);
|
|
2920
|
+
return this.select(attributes, span).classify(span, attributes);
|
|
2721
2921
|
}
|
|
2722
2922
|
transform(span, attributes) {
|
|
2723
|
-
return this.select(attributes).transform(span, attributes);
|
|
2923
|
+
return this.select(attributes, span).transform(span, attributes);
|
|
2724
2924
|
}
|
|
2725
2925
|
};
|
|
2726
2926
|
|
|
@@ -2804,93 +3004,6 @@ function extractResourceScopeSpan(resourceSpans) {
|
|
|
2804
3004
|
return result;
|
|
2805
3005
|
}
|
|
2806
3006
|
|
|
2807
|
-
// src/normalizer/resolvers/semantic-kind-resolver.ts
|
|
2808
|
-
var SEMANTIC_KINDS = ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
|
|
2809
|
-
var VALID_KINDS = new Set(SEMANTIC_KINDS);
|
|
2810
|
-
var OPENINFERENCE_MAP = {
|
|
2811
|
-
"CHAIN": "function",
|
|
2812
|
-
"LLM": "llm",
|
|
2813
|
-
"TOOL": "tool",
|
|
2814
|
-
"AGENT": "agent",
|
|
2815
|
-
"RETRIEVER": "retrieval",
|
|
2816
|
-
"EMBEDDING": "embedding",
|
|
2817
|
-
"GUARDRAIL": "guardrail",
|
|
2818
|
-
"RERANKER": "retrieval"
|
|
2819
|
-
};
|
|
2820
|
-
var FRAMEWORK_MAPPINGS = [
|
|
2821
|
-
{
|
|
2822
|
-
key: "ai.operationId",
|
|
2823
|
-
// Vercel AI SDK
|
|
2824
|
-
// The AI SDK emits ai.operationId WITH the "ai." prefix (e.g.
|
|
2825
|
-
// "ai.generateText"); accept both prefixed and unprefixed so generation
|
|
2826
|
-
// wrappers resolve to "llm" instead of falling through to "function".
|
|
2827
|
-
map: {
|
|
2828
|
-
"embed": "embedding",
|
|
2829
|
-
"ai.embed": "embedding",
|
|
2830
|
-
"generateText": "llm",
|
|
2831
|
-
"ai.generateText": "llm",
|
|
2832
|
-
"streamText": "llm",
|
|
2833
|
-
"ai.streamText": "llm",
|
|
2834
|
-
"generateObject": "llm",
|
|
2835
|
-
"ai.generateObject": "llm",
|
|
2836
|
-
"streamObject": "llm",
|
|
2837
|
-
"ai.streamObject": "llm"
|
|
2838
|
-
}
|
|
2839
|
-
},
|
|
2840
|
-
{
|
|
2841
|
-
key: "traceloop.span.kind",
|
|
2842
|
-
// Traceloop / OpenLLMetry
|
|
2843
|
-
map: { "LLM": "llm", "TOOL": "tool", "AGENT": "agent", "WORKFLOW": "function", "TASK": "function" }
|
|
2844
|
-
},
|
|
2845
|
-
{
|
|
2846
|
-
key: "langchain.run_type",
|
|
2847
|
-
// LangChain via OTLP
|
|
2848
|
-
map: { "llm": "llm", "chat_model": "llm", "retriever": "retrieval", "tool": "tool", "chain": "function", "embedding": "embedding" }
|
|
2849
|
-
},
|
|
2850
|
-
{
|
|
2851
|
-
key: "genkit:type",
|
|
2852
|
-
// Firebase Genkit
|
|
2853
|
-
map: { "model": "llm", "tool": "tool", "flow": "function", "retriever": "retrieval", "embedder": "embedding" }
|
|
2854
|
-
}
|
|
2855
|
-
];
|
|
2856
|
-
function resolveSemanticKind(normalized, allAttributes) {
|
|
2857
|
-
if (normalized.semanticKind && VALID_KINDS.has(normalized.semanticKind)) {
|
|
2858
|
-
return normalized.semanticKind;
|
|
2859
|
-
}
|
|
2860
|
-
const oiKind = allAttributes["openinference.span.kind"];
|
|
2861
|
-
if (oiKind) {
|
|
2862
|
-
const mapped = OPENINFERENCE_MAP[String(oiKind).toUpperCase()];
|
|
2863
|
-
if (mapped) return mapped;
|
|
2864
|
-
}
|
|
2865
|
-
for (const { key, map } of FRAMEWORK_MAPPINGS) {
|
|
2866
|
-
const val = allAttributes[key];
|
|
2867
|
-
if (val) {
|
|
2868
|
-
const mapped = map[String(val)];
|
|
2869
|
-
if (mapped) return mapped;
|
|
2870
|
-
}
|
|
2871
|
-
}
|
|
2872
|
-
const opName = allAttributes["gen_ai.operation.name"];
|
|
2873
|
-
if (opName) {
|
|
2874
|
-
const op = String(opName).toLowerCase();
|
|
2875
|
-
if (op === "chat" || op === "text_completion" || op === "generate_content") return "llm";
|
|
2876
|
-
if (op === "embeddings") return "embedding";
|
|
2877
|
-
}
|
|
2878
|
-
if (normalized.type === "GENERATION" /* GENERATION */) {
|
|
2879
|
-
return "llm";
|
|
2880
|
-
}
|
|
2881
|
-
if (normalized.model) {
|
|
2882
|
-
return "llm";
|
|
2883
|
-
}
|
|
2884
|
-
if (normalized.toolCalls && normalized.toolCalls.length > 0) {
|
|
2885
|
-
return "tool";
|
|
2886
|
-
}
|
|
2887
|
-
const name = (normalized.name || "").toLowerCase();
|
|
2888
|
-
if (/retriev|search|rag/i.test(name)) return "retrieval";
|
|
2889
|
-
if (/embed/i.test(name)) return "embedding";
|
|
2890
|
-
if (/guard|safety/i.test(name)) return "guardrail";
|
|
2891
|
-
return "function";
|
|
2892
|
-
}
|
|
2893
|
-
|
|
2894
3007
|
// src/normalizer/type-classifier.ts
|
|
2895
3008
|
var TypeClassifier = class {
|
|
2896
3009
|
classify(span, attributes) {
|
|
@@ -3059,6 +3172,7 @@ function deriveTraceIO(spans) {
|
|
|
3059
3172
|
findPromptFiles,
|
|
3060
3173
|
generateTypeDefinitions,
|
|
3061
3174
|
generateUnique8CharString,
|
|
3175
|
+
hasVectorStoreSignature,
|
|
3062
3176
|
messagesToPlainText,
|
|
3063
3177
|
normalizeOtlpSpans,
|
|
3064
3178
|
normalizeOtlpStatusCode,
|
|
@@ -3069,6 +3183,7 @@ function deriveTraceIO(spans) {
|
|
|
3069
3183
|
parseTokens,
|
|
3070
3184
|
registry,
|
|
3071
3185
|
resolveSemanticKind,
|
|
3186
|
+
retrievalDocumentsToText,
|
|
3072
3187
|
toFrontMatter,
|
|
3073
3188
|
typeClassifier,
|
|
3074
3189
|
verifySignature
|