@agentmark-ai/shared-utils 0.6.1 → 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 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;
@@ -448,9 +465,106 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
448
465
  */
449
466
  declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
450
467
 
468
+ /**
469
+ * Shared parser for the "flattened indexed message" attribute shape used by
470
+ * both OpenInference and OpenLLMetry/Traceloop. Neither emits a single JSON
471
+ * messages array (the way OTel GenAI v1.37+ does with `gen_ai.input.messages`);
472
+ * instead they explode each message into one attribute per field, indexed by
473
+ * position:
474
+ *
475
+ * OpenInference:
476
+ * llm.input_messages.0.message.role = "user"
477
+ * llm.input_messages.0.message.content = "hello"
478
+ * llm.output_messages.0.message.tool_calls.0.tool_call.function.name = "search"
479
+ * llm.output_messages.0.message.tool_calls.0.tool_call.function.arguments = "{...}"
480
+ *
481
+ * OpenLLMetry / Traceloop:
482
+ * gen_ai.prompt.0.role = "user"
483
+ * gen_ai.prompt.0.content = "hello"
484
+ * gen_ai.completion.0.tool_calls.0.name = "search"
485
+ * gen_ai.completion.0.tool_calls.0.arguments = "{...}"
486
+ *
487
+ * The two differ only in path fragments (a `message.` infix, a `tool_call.`
488
+ * infix, `function.name` vs `name`), so one config-driven parser serves both.
489
+ */
490
+ interface IndexedMessageConfig {
491
+ /** Attribute prefix that precedes the integer index, e.g. "llm.input_messages". */
492
+ prefix: string;
493
+ /** Path fragment between the index and the per-message fields. OpenInference uses
494
+ * "message." (so keys read `…0.message.role`); OpenLLMetry uses "" (`…0.role`). */
495
+ messageInfix: string;
496
+ /** Field name for the role. Default "role". */
497
+ roleKey?: string;
498
+ /** Field name for scalar text content. Default "content". */
499
+ contentKey?: string;
500
+ /** Multi-part content list field (OpenInference `contents`), read when the scalar
501
+ * content field is absent. Each part lives at
502
+ * `${base}${contentsKey}.${j}.${contentsPartInfix}text`. Omit to disable. */
503
+ contentsKey?: string;
504
+ /** Path fragment after the contents index, e.g. "message_content." for OpenInference. */
505
+ contentsPartInfix?: string;
506
+ /** Tool-call sub-shape. Omit if the source never carries tool calls. */
507
+ toolCalls?: {
508
+ /** Array field name under a message, e.g. "tool_calls". */
509
+ arrayKey: string;
510
+ /** Fragment between the tool-call index and its fields. OpenInference uses
511
+ * "tool_call." ; OpenLLMetry uses "". */
512
+ infix: string;
513
+ /** Relative key to the call id, e.g. "id". */
514
+ idKey: string;
515
+ /** Relative key to the tool name. OpenInference "function.name"; OpenLLMetry "name". */
516
+ nameKey: string;
517
+ /** Relative key to the JSON-string arguments. OpenInference "function.arguments";
518
+ * OpenLLMetry "arguments". */
519
+ argsKey: string;
520
+ };
521
+ }
522
+ /**
523
+ * Collect the distinct, ascending integer indices that appear immediately after
524
+ * `prefix.` across the attribute keys. Tolerant of gaps and arbitrary key order
525
+ * (a span may emit message 2 before message 0); we never assume a dense 0..n.
526
+ * Exported so transformers can reuse it for non-message indexed groups
527
+ * (e.g. OpenInference `retrieval.documents.{i}.*`).
528
+ */
529
+ declare function collectIndices(attributes: Record<string, any>, prefix: string): number[];
530
+ /**
531
+ * Parse the flattened indexed messages under `config.prefix` into normalized
532
+ * Messages. A message that carries tool calls gets an array content of a text
533
+ * part (when present) followed by `tool-call` parts, so conversation history is
534
+ * preserved with full fidelity; a text-only message gets a plain string content.
535
+ * Returns `undefined` when no messages are present (lets callers fall through to
536
+ * other extraction paths).
537
+ */
538
+ declare function parseIndexedMessages(attributes: Record<string, any>, config: IndexedMessageConfig): Message[] | undefined;
539
+ /**
540
+ * Flatten every tool call across the indexed messages under `config.prefix` into
541
+ * a span-level ToolCall[]. Used for the response side, where OpenInference and
542
+ * OpenLLMetry place the assistant's tool calls inside `output_messages` /
543
+ * `gen_ai.completion` and AgentMark surfaces them as `span.toolCalls`.
544
+ */
545
+ declare function extractIndexedToolCalls(attributes: Record<string, any>, config: IndexedMessageConfig): ToolCall[] | undefined;
546
+ /**
547
+ * Collapse normalized messages into a single plain-text string (text parts only,
548
+ * newline-joined). Tool-call parts are intentionally dropped — they travel
549
+ * separately via `extractIndexedToolCalls`. Returns `undefined` when there is no
550
+ * text to show.
551
+ */
552
+ declare function messagesToPlainText(messages: Message[] | undefined): string | undefined;
553
+
451
554
  /** Valid semantic kind values. */
452
555
  declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
453
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;
454
568
  /**
455
569
  * Resolve the semantic kind of a span using a 9-level priority chain.
456
570
  *
@@ -557,6 +671,88 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
557
671
  static readonly SCOPE_NAME = "pydantic-ai";
558
672
  }
559
673
 
674
+ /**
675
+ * Transformer for the OpenInference semantic conventions — the instrumentation
676
+ * standard maintained by Arize and used by ~30 auto-instrumentors (LangChain,
677
+ * LlamaIndex, OpenAI Agents SDK, CrewAI, DSPy, Haystack, smolagents, Bedrock,
678
+ * Anthropic, Google ADK, Instructor, MCP, Guardrails, …). Those instrumentors
679
+ * each set their own OTel scope name, so this transformer is reached via the
680
+ * attribute-signature dispatcher rather than a scope registration (see the
681
+ * DispatchingTransformer).
682
+ *
683
+ * Span *classification* (openinference.span.kind → SpanKind) is already handled
684
+ * by resolveSemanticKind; this transformer fills the gap that left the IO,
685
+ * model, and token fields empty, because the default OTel-GenAI transformer only
686
+ * reads `gen_ai.*` keys and OpenInference uses an entirely different shape.
687
+ *
688
+ * @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
689
+ */
690
+
691
+ /** Join document contents into a readable, searchable text output. */
692
+ declare function retrievalDocumentsToText(documents: RetrievalDocument[]): string | undefined;
693
+ declare class OpenInferenceTransformer implements ScopeTransformer {
694
+ classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
695
+ transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
696
+ }
697
+
698
+ /**
699
+ * Transformer for the OpenLLMetry / Traceloop conventions (which OpenLIT also
700
+ * largely follows). These instrumentors back the AutoGen, Semantic Kernel, and
701
+ * Agno integrations, among others. Like OpenInference, each emits its own OTel
702
+ * scope name, so this transformer is reached via the attribute-signature
703
+ * dispatcher rather than a scope registration.
704
+ *
705
+ * Tokens and model already partly resolve through the default OTel-GenAI
706
+ * transformer's legacy `gen_ai.usage.prompt_tokens` fallbacks; the gap this
707
+ * closes is the IO, which OpenLLMetry flattens into indexed
708
+ * `gen_ai.prompt.{i}.*` / `gen_ai.completion.{i}.*` attributes (and, for
709
+ * workflow/task spans, `traceloop.entity.input/output`) rather than the
710
+ * `gen_ai.input.messages` JSON array the default transformer expects.
711
+ *
712
+ * @see https://www.traceloop.com/docs/openllmetry/privacy/traces
713
+ */
714
+
715
+ declare class OpenLLMetryTransformer implements ScopeTransformer {
716
+ classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
717
+ transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
718
+ }
719
+
720
+ /**
721
+ * Default transformer that routes a span to the right extractor by sniffing its
722
+ * attribute signature, instead of by OTel scope name.
723
+ *
724
+ * The registry dispatches scope → transformer by exact match, which works for
725
+ * SDKs that emit one stable scope (Vercel AI SDK = "ai", Mastra =
726
+ * "default-tracer", …). But the OpenInference and OpenLLMetry ecosystems each
727
+ * span dozens of instrumentor scope names
728
+ * (`openinference.instrumentation.langchain`,
729
+ * `@arizeai/openinference-instrumentation-openai`, `opentelemetry.instrumentation.openai`, …),
730
+ * so per-scope registration doesn't scale. This transformer is registered as the
731
+ * registry *default* (replacing the bare OTel-GenAI default) and picks the
732
+ * extractor from unambiguous attribute markers, falling back to the OTel GenAI
733
+ * semantic conventions when nothing framework-specific is present.
734
+ *
735
+ * classify() and transform() must agree on the chosen extractor, so both call
736
+ * the single `select()` method.
737
+ */
738
+
739
+ declare class DispatchingTransformer implements ScopeTransformer {
740
+ private readonly openInference;
741
+ private readonly openLLMetry;
742
+ private readonly otelGenAi;
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;
752
+ classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
753
+ transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
754
+ }
755
+
560
756
  declare function normalizeOtlpStatusCode(raw: string | number | undefined | null): string;
561
757
  declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
562
758
  /**
@@ -565,4 +761,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
565
761
  */
566
762
  declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
567
763
 
568
- 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, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, 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;
@@ -448,9 +465,106 @@ declare function extractCustomMetadata(attributes: Record<string, any>, prefix?:
448
465
  */
449
466
  declare function parseAgentMarkAttributes(attributes: Record<string, any>, prefix?: string): Partial<NormalizedSpan>;
450
467
 
468
+ /**
469
+ * Shared parser for the "flattened indexed message" attribute shape used by
470
+ * both OpenInference and OpenLLMetry/Traceloop. Neither emits a single JSON
471
+ * messages array (the way OTel GenAI v1.37+ does with `gen_ai.input.messages`);
472
+ * instead they explode each message into one attribute per field, indexed by
473
+ * position:
474
+ *
475
+ * OpenInference:
476
+ * llm.input_messages.0.message.role = "user"
477
+ * llm.input_messages.0.message.content = "hello"
478
+ * llm.output_messages.0.message.tool_calls.0.tool_call.function.name = "search"
479
+ * llm.output_messages.0.message.tool_calls.0.tool_call.function.arguments = "{...}"
480
+ *
481
+ * OpenLLMetry / Traceloop:
482
+ * gen_ai.prompt.0.role = "user"
483
+ * gen_ai.prompt.0.content = "hello"
484
+ * gen_ai.completion.0.tool_calls.0.name = "search"
485
+ * gen_ai.completion.0.tool_calls.0.arguments = "{...}"
486
+ *
487
+ * The two differ only in path fragments (a `message.` infix, a `tool_call.`
488
+ * infix, `function.name` vs `name`), so one config-driven parser serves both.
489
+ */
490
+ interface IndexedMessageConfig {
491
+ /** Attribute prefix that precedes the integer index, e.g. "llm.input_messages". */
492
+ prefix: string;
493
+ /** Path fragment between the index and the per-message fields. OpenInference uses
494
+ * "message." (so keys read `…0.message.role`); OpenLLMetry uses "" (`…0.role`). */
495
+ messageInfix: string;
496
+ /** Field name for the role. Default "role". */
497
+ roleKey?: string;
498
+ /** Field name for scalar text content. Default "content". */
499
+ contentKey?: string;
500
+ /** Multi-part content list field (OpenInference `contents`), read when the scalar
501
+ * content field is absent. Each part lives at
502
+ * `${base}${contentsKey}.${j}.${contentsPartInfix}text`. Omit to disable. */
503
+ contentsKey?: string;
504
+ /** Path fragment after the contents index, e.g. "message_content." for OpenInference. */
505
+ contentsPartInfix?: string;
506
+ /** Tool-call sub-shape. Omit if the source never carries tool calls. */
507
+ toolCalls?: {
508
+ /** Array field name under a message, e.g. "tool_calls". */
509
+ arrayKey: string;
510
+ /** Fragment between the tool-call index and its fields. OpenInference uses
511
+ * "tool_call." ; OpenLLMetry uses "". */
512
+ infix: string;
513
+ /** Relative key to the call id, e.g. "id". */
514
+ idKey: string;
515
+ /** Relative key to the tool name. OpenInference "function.name"; OpenLLMetry "name". */
516
+ nameKey: string;
517
+ /** Relative key to the JSON-string arguments. OpenInference "function.arguments";
518
+ * OpenLLMetry "arguments". */
519
+ argsKey: string;
520
+ };
521
+ }
522
+ /**
523
+ * Collect the distinct, ascending integer indices that appear immediately after
524
+ * `prefix.` across the attribute keys. Tolerant of gaps and arbitrary key order
525
+ * (a span may emit message 2 before message 0); we never assume a dense 0..n.
526
+ * Exported so transformers can reuse it for non-message indexed groups
527
+ * (e.g. OpenInference `retrieval.documents.{i}.*`).
528
+ */
529
+ declare function collectIndices(attributes: Record<string, any>, prefix: string): number[];
530
+ /**
531
+ * Parse the flattened indexed messages under `config.prefix` into normalized
532
+ * Messages. A message that carries tool calls gets an array content of a text
533
+ * part (when present) followed by `tool-call` parts, so conversation history is
534
+ * preserved with full fidelity; a text-only message gets a plain string content.
535
+ * Returns `undefined` when no messages are present (lets callers fall through to
536
+ * other extraction paths).
537
+ */
538
+ declare function parseIndexedMessages(attributes: Record<string, any>, config: IndexedMessageConfig): Message[] | undefined;
539
+ /**
540
+ * Flatten every tool call across the indexed messages under `config.prefix` into
541
+ * a span-level ToolCall[]. Used for the response side, where OpenInference and
542
+ * OpenLLMetry place the assistant's tool calls inside `output_messages` /
543
+ * `gen_ai.completion` and AgentMark surfaces them as `span.toolCalls`.
544
+ */
545
+ declare function extractIndexedToolCalls(attributes: Record<string, any>, config: IndexedMessageConfig): ToolCall[] | undefined;
546
+ /**
547
+ * Collapse normalized messages into a single plain-text string (text parts only,
548
+ * newline-joined). Tool-call parts are intentionally dropped — they travel
549
+ * separately via `extractIndexedToolCalls`. Returns `undefined` when there is no
550
+ * text to show.
551
+ */
552
+ declare function messagesToPlainText(messages: Message[] | undefined): string | undefined;
553
+
451
554
  /** Valid semantic kind values. */
452
555
  declare const SEMANTIC_KINDS: readonly ["function", "llm", "tool", "agent", "retrieval", "embedding", "guardrail"];
453
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;
454
568
  /**
455
569
  * Resolve the semantic kind of a span using a 9-level priority chain.
456
570
  *
@@ -557,6 +671,88 @@ declare class OtelGenAiTransformer implements ScopeTransformer {
557
671
  static readonly SCOPE_NAME = "pydantic-ai";
558
672
  }
559
673
 
674
+ /**
675
+ * Transformer for the OpenInference semantic conventions — the instrumentation
676
+ * standard maintained by Arize and used by ~30 auto-instrumentors (LangChain,
677
+ * LlamaIndex, OpenAI Agents SDK, CrewAI, DSPy, Haystack, smolagents, Bedrock,
678
+ * Anthropic, Google ADK, Instructor, MCP, Guardrails, …). Those instrumentors
679
+ * each set their own OTel scope name, so this transformer is reached via the
680
+ * attribute-signature dispatcher rather than a scope registration (see the
681
+ * DispatchingTransformer).
682
+ *
683
+ * Span *classification* (openinference.span.kind → SpanKind) is already handled
684
+ * by resolveSemanticKind; this transformer fills the gap that left the IO,
685
+ * model, and token fields empty, because the default OTel-GenAI transformer only
686
+ * reads `gen_ai.*` keys and OpenInference uses an entirely different shape.
687
+ *
688
+ * @see https://github.com/Arize-ai/openinference/blob/main/spec/semantic_conventions.md
689
+ */
690
+
691
+ /** Join document contents into a readable, searchable text output. */
692
+ declare function retrievalDocumentsToText(documents: RetrievalDocument[]): string | undefined;
693
+ declare class OpenInferenceTransformer implements ScopeTransformer {
694
+ classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
695
+ transform(_span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
696
+ }
697
+
698
+ /**
699
+ * Transformer for the OpenLLMetry / Traceloop conventions (which OpenLIT also
700
+ * largely follows). These instrumentors back the AutoGen, Semantic Kernel, and
701
+ * Agno integrations, among others. Like OpenInference, each emits its own OTel
702
+ * scope name, so this transformer is reached via the attribute-signature
703
+ * dispatcher rather than a scope registration.
704
+ *
705
+ * Tokens and model already partly resolve through the default OTel-GenAI
706
+ * transformer's legacy `gen_ai.usage.prompt_tokens` fallbacks; the gap this
707
+ * closes is the IO, which OpenLLMetry flattens into indexed
708
+ * `gen_ai.prompt.{i}.*` / `gen_ai.completion.{i}.*` attributes (and, for
709
+ * workflow/task spans, `traceloop.entity.input/output`) rather than the
710
+ * `gen_ai.input.messages` JSON array the default transformer expects.
711
+ *
712
+ * @see https://www.traceloop.com/docs/openllmetry/privacy/traces
713
+ */
714
+
715
+ declare class OpenLLMetryTransformer implements ScopeTransformer {
716
+ classify(_span: OtelSpan, attributes: Record<string, any>): SpanType;
717
+ transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
718
+ }
719
+
720
+ /**
721
+ * Default transformer that routes a span to the right extractor by sniffing its
722
+ * attribute signature, instead of by OTel scope name.
723
+ *
724
+ * The registry dispatches scope → transformer by exact match, which works for
725
+ * SDKs that emit one stable scope (Vercel AI SDK = "ai", Mastra =
726
+ * "default-tracer", …). But the OpenInference and OpenLLMetry ecosystems each
727
+ * span dozens of instrumentor scope names
728
+ * (`openinference.instrumentation.langchain`,
729
+ * `@arizeai/openinference-instrumentation-openai`, `opentelemetry.instrumentation.openai`, …),
730
+ * so per-scope registration doesn't scale. This transformer is registered as the
731
+ * registry *default* (replacing the bare OTel-GenAI default) and picks the
732
+ * extractor from unambiguous attribute markers, falling back to the OTel GenAI
733
+ * semantic conventions when nothing framework-specific is present.
734
+ *
735
+ * classify() and transform() must agree on the chosen extractor, so both call
736
+ * the single `select()` method.
737
+ */
738
+
739
+ declare class DispatchingTransformer implements ScopeTransformer {
740
+ private readonly openInference;
741
+ private readonly openLLMetry;
742
+ private readonly otelGenAi;
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;
752
+ classify(span: OtelSpan, attributes: Record<string, any>): SpanType;
753
+ transform(span: OtelSpan, attributes: Record<string, any>): Partial<NormalizedSpan>;
754
+ }
755
+
560
756
  declare function normalizeOtlpStatusCode(raw: string | number | undefined | null): string;
561
757
  declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: OtelSpan): NormalizedSpan;
562
758
  /**
@@ -565,4 +761,4 @@ declare function normalizeSpan(resource: OtelResource, scope: OtelScope, span: O
565
761
  */
566
762
  declare function normalizeOtlpSpans(resourceSpans: OtlpResourceSpans[]): NormalizedSpan[];
567
763
 
568
- 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, normalizeOtlpStatusCode, normalizeSpan, parseAgentMarkAttributes, 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 };