UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

120 lines (119 loc) 3.82 kB
/** * Utility class for span creation and serialization * Handles conversion between NeuroLink's span format and platform-specific formats */ import { type LangfuseSpan, type LangSmithRun, type OtelSpan, type SpanAttributes, type SpanData, SpanStatus, SpanType } from "../../types/index.js"; /** * Utility class for span creation and serialization */ export declare class SpanSerializer { /** * Create a new span with generated IDs. * * When `traceId` / `parentSpanId` are omitted, the method automatically * attempts to inherit them from the active OTel context so that Pipeline B * spans land inside the same Langfuse trace as Pipeline A spans (fix A5). */ static createSpan(type: SpanType, name: string, attributes?: Partial<SpanAttributes>, parentSpanId?: string, traceId?: string): SpanData; /** * End a span with status */ static endSpan(span: SpanData, status?: SpanStatus, statusMessage?: string): SpanData; /** * Add event to span */ static addEvent(span: SpanData, name: string, attributes?: Record<string, unknown>): SpanData; /** * Update span attributes */ static updateAttributes(span: SpanData, attributes: Partial<SpanAttributes>): SpanData; /** * Serialize span to JSON for export */ static toJSON(span: SpanData): string; /** * Instance method to serialize a span object to JSON string * @param span - The span data to serialize (can be partial span data) * @returns JSON string representation of the span */ serialize(span: Partial<SpanData> | Record<string, unknown>): string; /** * Instance method to deserialize a JSON string to span data * @param json - The JSON string to parse * @returns Parsed span data */ deserialize(json: string): SpanData; /** * Parse span from JSON */ static fromJSON(json: string): SpanData; /** * Serialize span for Langfuse format */ static toLangfuseFormat(span: SpanData): LangfuseSpan; /** * Serialize span for LangSmith format */ static toLangSmithFormat(span: SpanData): LangSmithRun; /** * Serialize span for OpenTelemetry format */ static toOtelFormat(span: SpanData): OtelSpan; /** * Convert value to OTel attribute value format */ private static toOtelAttributeValue; /** * Map NeuroLink span type to LangSmith run type */ private static mapSpanTypeToLangSmithRunType; /** * Extract tags from span attributes for LangSmith */ private static extractTags; /** * Create a generation span with AI-specific attributes */ static createGenerationSpan(params: { provider: string; model: string; name?: string; parentSpanId?: string; traceId?: string; temperature?: number; maxTokens?: number; input?: unknown; userId?: string; sessionId?: string; }): SpanData; /** * Create a tool call span */ static createToolCallSpan(params: { toolName: string; server?: string; input?: unknown; parentSpanId?: string; traceId?: string; }): SpanData; /** * Enrich span with token usage */ static enrichWithTokenUsage(span: SpanData, usage: { promptTokens?: number; completionTokens?: number; totalTokens?: number; cacheCreationTokens?: number; cacheReadTokens?: number; reasoningTokens?: number; }): SpanData; /** * Enrich span with cost information */ static enrichWithCost(span: SpanData, cost: { inputCost?: number; outputCost?: number; totalCost: number; currency?: string; }): SpanData; }