/** * Converts internal message types to OTel GenAI JSON schema format. * @see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-input-messages.json * @see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-output-messages.json */ /** * Truncate a string to fit within OTel attribute size limits. * Returns the original string if within bounds, otherwise truncates with a suffix. * * @param value The string to truncate. * @param maxLength The maximum length in characters. A value of `0` (the * default) or any non-positive number disables truncation entirely, matching * the OTel spec's `AttributeValueLengthLimit` default of `Infinity` for string * attributes (see https://opentelemetry.io/docs/specs/otel/common/#attribute-limits). * Production call sites should pass `OTelConfig.maxAttributeSizeChars` so * users can configure truncation to match their backend's per-attribute limit. */ export declare function truncateForOTel(value: string, maxLength?: number): string; export interface OTelChatMessage { role: string | undefined; parts: OTelMessagePart[]; } export interface OTelOutputMessage extends OTelChatMessage { finish_reason?: string; } export type OTelMessagePart = { type: 'text'; content: string; } | { type: 'tool_call'; id: string; name: string; arguments: unknown; } | { type: 'tool_call_response'; id: string; response: unknown; } | { type: 'tool_search_output'; id: string; tools?: unknown; status?: string; } | { type: 'reasoning'; content: string; }; export type OTelSystemInstruction = Array<{ type: 'text'; content: string; }>; export interface OTelToolDefinition { type: 'function'; name: string; description?: string; parameters?: unknown; } /** * Convert an array of internal messages to OTel input message format. * Handles OpenAI format (tool_calls, tool_call_id) natively. */ export declare function toInputMessages(messages: ReadonlyArray<{ role?: string; content?: string; tool_calls?: ReadonlyArray<{ id: string; function: { name: string; arguments: string; }; }>; tool_call_id?: string; }>): OTelChatMessage[]; /** * Convert model response choices to OTel output message format. */ export declare function toOutputMessages(choices: ReadonlyArray<{ message?: { role?: string; content?: string; tool_calls?: ReadonlyArray<{ id: string; function: { name: string; arguments: string; }; }>; }; finish_reason?: string; }>): OTelOutputMessage[]; /** * Convert system message text to OTel system instruction format. * Accepts a single string or an array (one block per entry). Returns * `undefined` when no non-empty text is available. */ export declare function toSystemInstructions(systemMessage: string | ReadonlyArray | undefined): OTelSystemInstruction | undefined; /** * Extract plain text from a message-content value (string or array of * content blocks). Returns an empty string when no text can be extracted. */ export declare function extractTextFromContent(content: unknown): string; /** * Collect system-instruction text from a provider request body. Uses * messages-level `system` entries when present, otherwise falls back to * top-level `system` or `instructions`. */ export declare function collectSystemTextsFromRequestBody(requestBody: { readonly messages?: ReadonlyArray<{ role?: unknown; content?: unknown; }>; readonly input?: ReadonlyArray<{ role?: unknown; content?: unknown; }>; readonly system?: unknown; readonly instructions?: unknown; }): string[]; /** * Normalize provider-specific messages (Anthropic content blocks, OpenAI * Chat Completions, OpenAI Responses API) to OTel GenAI semantic * convention format. * * Handles: * - Anthropic content block arrays: tool_use → tool_call, tool_result → tool_call_response, thinking → reasoning * - OpenAI Chat Completions: tool_calls, role=tool with tool_call_id * - OpenAI Responses API items: `type: 'message'` with `input_text` / * `output_text` content blocks; `type: 'function_call'` → * role=assistant + tool_call; `type: 'function_call_output'` → * role=tool + tool_call_response; `type: 'tool_search_output'` → * role=tool_search + tool_search_output; `type: 'reasoning'` → * role=assistant + reasoning part * - Plain string content */ export declare function normalizeProviderMessages(messages: ReadonlyArray>): OTelChatMessage[]; /** * Convert tool definitions to OTel `gen_ai.tool.definitions` format. * * Accepts the variants emitted by the different request bodies/providers: * - OpenAI Chat Completions: `{ type: 'function', function: { name, description, parameters } }` * - OpenAI Responses API: `{ type: 'function', name, description, parameters }` * - Anthropic Messages API: `{ name, description, input_schema }` * - VS Code tool info: `{ name, description, inputSchema }` * * Tools without a name (e.g. OpenAI client-side `tool_search`) are skipped * because OTel `gen_ai.tool.definitions` requires a name per entry. * * @see https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-tool-definitions */ export declare function toToolDefinitions(tools: ReadonlyArray<{ type?: string; name?: string; description?: string; parameters?: unknown; input_schema?: unknown; inputSchema?: unknown; function?: { name?: string; description?: string; parameters?: unknown; }; }> | undefined): OTelToolDefinition[] | undefined; /** * Return the OTel-normalized JSON string for a tools array, memoized so all * telemetry/span sites within (and across consecutive identical rounds of) an * LLM call share a single string instance. Returns `undefined` if no * normalized tools would be emitted. */ export declare function stringifyToolDefinitionsForOTel(tools: Parameters[0]): string | undefined; /** * Return `JSON.stringify(tools)` memoized by array reference, with a * single-slot content intern so consecutive rounds producing identical content * share one string instance. Used for telemetry sinks that consume the raw * tools shape rather than the OTel-normalized one. Mirrors `JSON.stringify` * exactly: returns `'[]'` for an empty array and `undefined` only when * `tools` itself is `undefined`. */ export declare function stringifyToolsRawForTelemetry(tools: ReadonlyArray | undefined): string | undefined; //# sourceMappingURL=messageFormatters.d.ts.map