@introspection-sdk/introspection-node 0.4.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.
Files changed (89) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-check-types.log +5 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/dist/ai-sdk-integration.d.ts +123 -0
  5. package/dist/ai-sdk-integration.d.ts.map +1 -0
  6. package/dist/ai-sdk-integration.js +475 -0
  7. package/dist/anthropic.d.ts +54 -0
  8. package/dist/anthropic.d.ts.map +1 -0
  9. package/dist/anthropic.js +375 -0
  10. package/dist/claude-hooks.d.ts +328 -0
  11. package/dist/claude-hooks.d.ts.map +1 -0
  12. package/dist/claude-hooks.js +571 -0
  13. package/dist/claude-wrapper.d.ts +93 -0
  14. package/dist/claude-wrapper.d.ts.map +1 -0
  15. package/dist/claude-wrapper.js +154 -0
  16. package/dist/client.d.ts +157 -0
  17. package/dist/client.d.ts.map +1 -0
  18. package/dist/client.js +394 -0
  19. package/dist/converters/ai-sdk.d.ts +65 -0
  20. package/dist/converters/ai-sdk.d.ts.map +1 -0
  21. package/dist/converters/ai-sdk.js +238 -0
  22. package/dist/converters/claude.d.ts +146 -0
  23. package/dist/converters/claude.d.ts.map +1 -0
  24. package/dist/converters/claude.js +202 -0
  25. package/dist/converters/index.d.ts +9 -0
  26. package/dist/converters/index.d.ts.map +1 -0
  27. package/dist/converters/index.js +8 -0
  28. package/dist/converters/openai.d.ts +51 -0
  29. package/dist/converters/openai.d.ts.map +1 -0
  30. package/dist/converters/openai.js +268 -0
  31. package/dist/converters/openclaw.d.ts +16 -0
  32. package/dist/converters/openclaw.d.ts.map +1 -0
  33. package/dist/converters/openclaw.js +49 -0
  34. package/dist/converters/openinference.d.ts +107 -0
  35. package/dist/converters/openinference.d.ts.map +1 -0
  36. package/dist/converters/openinference.js +552 -0
  37. package/dist/converters/vercel.d.ts +21 -0
  38. package/dist/converters/vercel.d.ts.map +1 -0
  39. package/dist/converters/vercel.js +208 -0
  40. package/dist/index.d.ts +38 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +39 -0
  43. package/dist/langchain-handler.d.ts +101 -0
  44. package/dist/langchain-handler.d.ts.map +1 -0
  45. package/dist/langchain-handler.js +489 -0
  46. package/dist/mastra-exporter.d.ts +85 -0
  47. package/dist/mastra-exporter.d.ts.map +1 -0
  48. package/dist/mastra-exporter.js +471 -0
  49. package/dist/span-processor.d.ts +62 -0
  50. package/dist/span-processor.d.ts.map +1 -0
  51. package/dist/span-processor.js +310 -0
  52. package/dist/tracing-processor.d.ts +136 -0
  53. package/dist/tracing-processor.d.ts.map +1 -0
  54. package/dist/tracing-processor.js +368 -0
  55. package/dist/types/genai.d.ts +165 -0
  56. package/dist/types/genai.d.ts.map +1 -0
  57. package/dist/types/genai.js +82 -0
  58. package/dist/types.d.ts +7 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +1 -0
  61. package/dist/utils.d.ts +19 -0
  62. package/dist/utils.d.ts.map +1 -0
  63. package/dist/utils.js +57 -0
  64. package/dist/version.d.ts +3 -0
  65. package/dist/version.d.ts.map +1 -0
  66. package/dist/version.js +2 -0
  67. package/eslint.config.mjs +4 -0
  68. package/package.json +78 -0
  69. package/src/ai-sdk-integration.ts +689 -0
  70. package/src/anthropic.ts +465 -0
  71. package/src/claude-hooks.ts +1010 -0
  72. package/src/claude-wrapper.ts +240 -0
  73. package/src/client.ts +513 -0
  74. package/src/converters/ai-sdk.ts +298 -0
  75. package/src/converters/claude.ts +334 -0
  76. package/src/converters/index.ts +44 -0
  77. package/src/converters/openai.ts +302 -0
  78. package/src/converters/openinference.ts +673 -0
  79. package/src/converters/vercel.ts +264 -0
  80. package/src/index.ts +121 -0
  81. package/src/langchain-handler.ts +722 -0
  82. package/src/mastra-exporter.ts +650 -0
  83. package/src/span-processor.ts +418 -0
  84. package/src/tracing-processor.ts +548 -0
  85. package/src/types/genai.ts +264 -0
  86. package/src/types.ts +13 -0
  87. package/src/utils.ts +69 -0
  88. package/src/version.ts +2 -0
  89. package/tsconfig.json +8 -0
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Claude Agent SDK format conversion functions for OTel Gen AI Semantic Conventions.
3
+ *
4
+ * These functions convert Claude Agent SDK message formats to the standardized
5
+ * OTel Gen AI Semantic Convention format for gen_ai.input.messages and gen_ai.output.messages.
6
+ */
7
+ import type { InputMessage, OutputMessage, GenAiAttributes } from "../types/genai.js";
8
+ /** A plain-text content block from the Claude API. */
9
+ export interface ClaudeTextBlock {
10
+ type: "text";
11
+ text: string;
12
+ }
13
+ /** A tool-use (function call) content block from the Claude API. */
14
+ export interface ClaudeToolUseBlock {
15
+ type: "tool_use";
16
+ id: string;
17
+ name: string;
18
+ input: unknown;
19
+ }
20
+ /** A tool-result content block returned to the Claude API. */
21
+ export interface ClaudeToolResultBlock {
22
+ type: "tool_result";
23
+ tool_use_id: string;
24
+ content: string | unknown[];
25
+ is_error?: boolean;
26
+ }
27
+ /** Union of all Claude API content block shapes. */
28
+ export type ClaudeContentBlock = ClaudeTextBlock | ClaudeToolUseBlock | ClaudeToolResultBlock | {
29
+ type: string;
30
+ [key: string]: unknown;
31
+ };
32
+ /** A single message in a Claude multi-turn conversation. */
33
+ export interface ClaudeMessage {
34
+ role: "user" | "assistant";
35
+ content: string | ClaudeContentBlock[];
36
+ }
37
+ /** Subset of the Claude Messages API response used for conversion. */
38
+ export interface ClaudeResponse {
39
+ id?: string;
40
+ model?: string;
41
+ content?: ClaudeContentBlock[];
42
+ stop_reason?: string;
43
+ usage?: {
44
+ input_tokens?: number;
45
+ output_tokens?: number;
46
+ };
47
+ }
48
+ /**
49
+ * Convert a user prompt string to OTel Gen AI input message format.
50
+ *
51
+ * @param prompt - The user's text prompt.
52
+ * @returns An array containing a single user-role {@link InputMessage}.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const msgs = convertClaudePromptToInputMessages("Hello, Claude!");
57
+ * // [{ role: "user", parts: [{ type: "text", content: "Hello, Claude!" }] }]
58
+ * ```
59
+ */
60
+ export declare function convertClaudePromptToInputMessages(prompt: string): InputMessage[];
61
+ /**
62
+ * Convert Claude assistant response content to OTel Gen AI output message format.
63
+ *
64
+ * @param content - A plain string or array of {@link ClaudeContentBlock} objects.
65
+ * @param stopReason - Optional stop/finish reason (e.g. `"end_turn"`).
66
+ * @returns An array containing a single assistant-role {@link OutputMessage}.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const msgs = convertClaudeResponseToOutputMessages(response.content, response.stop_reason);
71
+ * span.setAttribute("gen_ai.output.messages", JSON.stringify(msgs));
72
+ * ```
73
+ */
74
+ export declare function convertClaudeResponseToOutputMessages(content: string | ClaudeContentBlock[], stopReason?: string): OutputMessage[];
75
+ /**
76
+ * Convert a Claude multi-turn conversation to OTel Gen AI input message format.
77
+ *
78
+ * @param messages - Array of {@link ClaudeMessage} objects (user + assistant turns).
79
+ * @returns An array of {@link InputMessage} objects preserving turn order.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const msgs = convertClaudeMessagesToInputMessages(conversation);
84
+ * span.setAttribute("gen_ai.input.messages", JSON.stringify(msgs));
85
+ * ```
86
+ */
87
+ export declare function convertClaudeMessagesToInputMessages(messages: ClaudeMessage[]): InputMessage[];
88
+ /**
89
+ * Aggregated session data from the Claude Agent SDK, used as input for
90
+ * the {@link convertClaudeSessionToGenAI} and
91
+ * {@link convertClaudeSessionToOtelAttributes} converters.
92
+ */
93
+ export interface ClaudeSessionData {
94
+ /** Input prompt */
95
+ inputPrompt?: string;
96
+ /** Response content (text extracted from assistant messages) */
97
+ responseContent?: string;
98
+ /** Full response content blocks (if available) */
99
+ responseBlocks?: ClaudeContentBlock[];
100
+ /** Model name */
101
+ model?: string;
102
+ /** Session ID */
103
+ sessionId?: string;
104
+ /** Input token count */
105
+ inputTokens?: number;
106
+ /** Output token count */
107
+ outputTokens?: number;
108
+ /** Cost in USD */
109
+ costUsd?: number;
110
+ /** Stop/finish reason */
111
+ stopReason?: string;
112
+ /** Response ID */
113
+ responseId?: string;
114
+ /** Tool names from init message */
115
+ toolNames?: string[];
116
+ /** System instructions / system prompt */
117
+ systemInstructions?: string;
118
+ }
119
+ /**
120
+ * Convert Claude session data to camelCase {@link GenAiAttributes}.
121
+ *
122
+ * @param data - Aggregated {@link ClaudeSessionData} for one session.
123
+ * @returns A {@link GenAiAttributes} object ready for {@link toAttributes}.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * const genAi = convertClaudeSessionToGenAI({ model: "claude-sonnet-4-20250514", inputTokens: 100 });
128
+ * const otel = toAttributes(genAi);
129
+ * ```
130
+ */
131
+ export declare function convertClaudeSessionToGenAI(data: ClaudeSessionData): GenAiAttributes;
132
+ /**
133
+ * Convert Claude session data directly to OTel span attributes with `gen_ai.*`
134
+ * dot-notation keys, plus Claude-specific keys like `claude.session_id`.
135
+ *
136
+ * @param data - Aggregated {@link ClaudeSessionData} for one session.
137
+ * @returns A flat dictionary suitable for `span.setAttributes()`.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const attrs = convertClaudeSessionToOtelAttributes(sessionData);
142
+ * for (const [k, v] of Object.entries(attrs)) span.setAttribute(k, v);
143
+ * ```
144
+ */
145
+ export declare function convertClaudeSessionToOtelAttributes(data: ClaudeSessionData): Record<string, string | number>;
146
+ //# sourceMappingURL=claude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/converters/claude.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Claude Agent SDK format conversion functions for OTel Gen AI Semantic Conventions.
3
+ *
4
+ * These functions convert Claude Agent SDK message formats to the standardized
5
+ * OTel Gen AI Semantic Convention format for gen_ai.input.messages and gen_ai.output.messages.
6
+ */
7
+ import { toAttributes } from "../types/genai.js";
8
+ /**
9
+ * Convert a user prompt string to OTel Gen AI input message format.
10
+ *
11
+ * @param prompt - The user's text prompt.
12
+ * @returns An array containing a single user-role {@link InputMessage}.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const msgs = convertClaudePromptToInputMessages("Hello, Claude!");
17
+ * // [{ role: "user", parts: [{ type: "text", content: "Hello, Claude!" }] }]
18
+ * ```
19
+ */
20
+ export function convertClaudePromptToInputMessages(prompt) {
21
+ return [
22
+ {
23
+ role: "user",
24
+ parts: [{ type: "text", content: prompt }],
25
+ },
26
+ ];
27
+ }
28
+ /**
29
+ * Convert Claude content blocks to message parts.
30
+ */
31
+ function convertContentBlocksToParts(content) {
32
+ if (typeof content === "string") {
33
+ return [{ type: "text", content }];
34
+ }
35
+ const parts = [];
36
+ for (const block of content) {
37
+ if (block.type === "text" && "text" in block) {
38
+ parts.push({ type: "text", content: block.text });
39
+ }
40
+ else if (block.type === "tool_use" && "name" in block) {
41
+ parts.push({
42
+ type: "tool_call",
43
+ id: block.id,
44
+ name: block.name,
45
+ arguments: block.input,
46
+ });
47
+ }
48
+ else if (block.type === "tool_result" && "tool_use_id" in block) {
49
+ let response = block.content;
50
+ if (typeof response === "string") {
51
+ // Keep as string
52
+ }
53
+ else if (Array.isArray(response)) {
54
+ // Extract text from content array
55
+ response = response
56
+ .filter((item) => typeof item === "object" &&
57
+ item !== null &&
58
+ item.type === "text")
59
+ .map((item) => item.text)
60
+ .join("");
61
+ }
62
+ parts.push({
63
+ type: "tool_call_response",
64
+ id: block.tool_use_id,
65
+ response,
66
+ });
67
+ }
68
+ else if (block.type === "thinking" && "thinking" in block) {
69
+ const thinking = block.thinking;
70
+ const signature = block.signature;
71
+ const thinkingPart = {
72
+ type: "thinking",
73
+ content: thinking || undefined,
74
+ signature: signature || undefined,
75
+ provider_name: "anthropic",
76
+ };
77
+ parts.push(thinkingPart);
78
+ }
79
+ }
80
+ return parts;
81
+ }
82
+ /**
83
+ * Convert Claude assistant response content to OTel Gen AI output message format.
84
+ *
85
+ * @param content - A plain string or array of {@link ClaudeContentBlock} objects.
86
+ * @param stopReason - Optional stop/finish reason (e.g. `"end_turn"`).
87
+ * @returns An array containing a single assistant-role {@link OutputMessage}.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const msgs = convertClaudeResponseToOutputMessages(response.content, response.stop_reason);
92
+ * span.setAttribute("gen_ai.output.messages", JSON.stringify(msgs));
93
+ * ```
94
+ */
95
+ export function convertClaudeResponseToOutputMessages(content, stopReason) {
96
+ const parts = convertContentBlocksToParts(content);
97
+ const message = {
98
+ role: "assistant",
99
+ parts,
100
+ };
101
+ if (stopReason) {
102
+ message.finish_reason = stopReason;
103
+ }
104
+ return [message];
105
+ }
106
+ /**
107
+ * Convert a Claude multi-turn conversation to OTel Gen AI input message format.
108
+ *
109
+ * @param messages - Array of {@link ClaudeMessage} objects (user + assistant turns).
110
+ * @returns An array of {@link InputMessage} objects preserving turn order.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const msgs = convertClaudeMessagesToInputMessages(conversation);
115
+ * span.setAttribute("gen_ai.input.messages", JSON.stringify(msgs));
116
+ * ```
117
+ */
118
+ export function convertClaudeMessagesToInputMessages(messages) {
119
+ return messages.map((msg) => ({
120
+ role: msg.role,
121
+ parts: convertContentBlocksToParts(msg.content),
122
+ }));
123
+ }
124
+ /**
125
+ * Convert Claude session data to camelCase {@link GenAiAttributes}.
126
+ *
127
+ * @param data - Aggregated {@link ClaudeSessionData} for one session.
128
+ * @returns A {@link GenAiAttributes} object ready for {@link toAttributes}.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const genAi = convertClaudeSessionToGenAI({ model: "claude-sonnet-4-20250514", inputTokens: 100 });
133
+ * const otel = toAttributes(genAi);
134
+ * ```
135
+ */
136
+ export function convertClaudeSessionToGenAI(data) {
137
+ const result = {};
138
+ // Set system
139
+ result.system = "anthropic";
140
+ // Set model
141
+ if (data.model) {
142
+ result.requestModel = data.model;
143
+ }
144
+ // Convert input to gen_ai.input.messages format
145
+ if (data.inputPrompt) {
146
+ result.inputMessages = convertClaudePromptToInputMessages(data.inputPrompt);
147
+ }
148
+ // Convert output to gen_ai.output.messages format
149
+ if (data.responseBlocks) {
150
+ result.outputMessages = convertClaudeResponseToOutputMessages(data.responseBlocks, data.stopReason);
151
+ }
152
+ else if (data.responseContent) {
153
+ result.outputMessages = convertClaudeResponseToOutputMessages(data.responseContent, data.stopReason);
154
+ }
155
+ // Set token counts
156
+ if (data.inputTokens !== undefined) {
157
+ result.inputTokens = data.inputTokens;
158
+ }
159
+ if (data.outputTokens !== undefined) {
160
+ result.outputTokens = data.outputTokens;
161
+ }
162
+ // Set response ID
163
+ if (data.responseId) {
164
+ result.responseId = data.responseId;
165
+ }
166
+ // Set tool definitions from tool names
167
+ if (data.toolNames && data.toolNames.length > 0) {
168
+ result.toolDefinitions = data.toolNames.map((name) => ({ name }));
169
+ }
170
+ // Set system instructions
171
+ if (data.systemInstructions) {
172
+ result.systemInstructions = [
173
+ { type: "text", content: data.systemInstructions },
174
+ ];
175
+ }
176
+ return result;
177
+ }
178
+ /**
179
+ * Convert Claude session data directly to OTel span attributes with `gen_ai.*`
180
+ * dot-notation keys, plus Claude-specific keys like `claude.session_id`.
181
+ *
182
+ * @param data - Aggregated {@link ClaudeSessionData} for one session.
183
+ * @returns A flat dictionary suitable for `span.setAttributes()`.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const attrs = convertClaudeSessionToOtelAttributes(sessionData);
188
+ * for (const [k, v] of Object.entries(attrs)) span.setAttribute(k, v);
189
+ * ```
190
+ */
191
+ export function convertClaudeSessionToOtelAttributes(data) {
192
+ const genaiAttrs = convertClaudeSessionToGenAI(data);
193
+ const result = toAttributes(genaiAttrs);
194
+ // Add Claude-specific attributes
195
+ if (data.sessionId) {
196
+ result["claude.session_id"] = data.sessionId;
197
+ }
198
+ if (data.costUsd !== undefined) {
199
+ result["gen_ai.cost.usd"] = data.costUsd;
200
+ }
201
+ return result;
202
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Converters for transforming various API formats to OTel Gen AI Semantic Conventions.
3
+ */
4
+ export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, type ResponseInputItem, type ResponseOutputItem, type ResponseTool, type ResponseUsage, type Response as OpenAIResponse, } from "./openai.js";
5
+ export { isOpenInferenceSpan, convertOpenInferenceToGenAI, replaceOpenInferenceWithGenAI, addOpenInferenceAttributes, OpenInferenceSpanExporter, } from "./openinference.js";
6
+ export { isVercelAISpan, convertVercelAIToGenAI } from "./vercel.js";
7
+ export { convertMessagesToInputMessages as convertAISDKMessagesToInputMessages, extractSystemInstructions as extractAISDKSystemInstructions, buildOutputMessages as buildAISDKOutputMessages, convertToolsToToolDefinitions as convertAISDKToolsToToolDefinitions, } from "./ai-sdk.js";
8
+ export { convertClaudePromptToInputMessages, convertClaudeResponseToOutputMessages, convertClaudeMessagesToInputMessages, convertClaudeSessionToGenAI, convertClaudeSessionToOtelAttributes, type ClaudeContentBlock, type ClaudeMessage, type ClaudeResponse, type ClaudeSessionData, } from "./claude.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/converters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,8BAA8B,EAC9B,qCAAqC,EACrC,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,IAAI,cAAc,GAChC,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EACL,8BAA8B,IAAI,mCAAmC,EACrE,yBAAyB,IAAI,8BAA8B,EAC3D,mBAAmB,IAAI,wBAAwB,EAC/C,6BAA6B,IAAI,kCAAkC,GACpE,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kCAAkC,EAClC,qCAAqC,EACrC,oCAAoC,EACpC,2BAA2B,EAC3B,oCAAoC,EACpC,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converters for transforming various API formats to OTel Gen AI Semantic Conventions.
3
+ */
4
+ export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, } from "./openai.js";
5
+ export { isOpenInferenceSpan, convertOpenInferenceToGenAI, replaceOpenInferenceWithGenAI, addOpenInferenceAttributes, OpenInferenceSpanExporter, } from "./openinference.js";
6
+ export { isVercelAISpan, convertVercelAIToGenAI } from "./vercel.js";
7
+ export { convertMessagesToInputMessages as convertAISDKMessagesToInputMessages, extractSystemInstructions as extractAISDKSystemInstructions, buildOutputMessages as buildAISDKOutputMessages, convertToolsToToolDefinitions as convertAISDKToolsToToolDefinitions, } from "./ai-sdk.js";
8
+ export { convertClaudePromptToInputMessages, convertClaudeResponseToOutputMessages, convertClaudeMessagesToInputMessages, convertClaudeSessionToGenAI, convertClaudeSessionToOtelAttributes, } from "./claude.js";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * OpenAI format conversion functions for OTel Gen AI Semantic Conventions.
3
+ *
4
+ * These functions convert OpenAI API formats (Responses API, Agents SDK) to the
5
+ * standardized OTel Gen AI Semantic Convention format for gen_ai.input.messages
6
+ * and gen_ai.output.messages attributes.
7
+ */
8
+ import type { Responses } from "openai/resources/responses/responses";
9
+ import type { InputMessage, OutputMessage, ToolDefinition, SystemInstruction } from "../types/genai.js";
10
+ /** Re-export OpenAI types used by callers (e.g. tracing-processor). */
11
+ export type ResponseInputItem = Responses.ResponseInputItem;
12
+ export type ResponseOutputItem = Responses.ResponseOutputItem;
13
+ export type ResponseTool = Responses.Tool;
14
+ export type ResponseUsage = Responses.ResponseUsage;
15
+ export type Response = Responses.Response;
16
+ /**
17
+ * Convert OpenAI Responses API inputs to OTel Gen AI Semantic Convention format.
18
+ *
19
+ * Handles `message`, `function_call`, and `function_call_output` input types.
20
+ * System instructions are returned separately so callers can set
21
+ * `gen_ai.system_instructions` independently from `gen_ai.input.messages`.
22
+ *
23
+ * @param inputs - Input items array from the Responses API request body.
24
+ * @param instructions - Optional system instructions / system prompt string.
25
+ * @returns A `[inputMessages, systemInstructions]` tuple of {@link InputMessage} arrays.
26
+ */
27
+ export declare function convertResponsesInputsToSemconv(inputs: ResponseInputItem[] | undefined, instructions: string | undefined): [InputMessage[], InputMessage[]];
28
+ /**
29
+ * Convert OpenAI Responses API outputs to OTel Gen AI Semantic Convention format.
30
+ *
31
+ * Maps `message` and `function_call` output types to {@link OutputMessage} objects.
32
+ *
33
+ * @param outputs - Output items array from the Responses API response body.
34
+ * @returns An array of {@link OutputMessage} objects in semconv format.
35
+ */
36
+ export declare function convertResponsesOutputsToSemconv(outputs: ResponseOutputItem[]): OutputMessage[];
37
+ /**
38
+ * Convert OpenAI Responses API tool definitions to GenAI ToolDefinition format.
39
+ *
40
+ * @param tools - The tools array from the Response object.
41
+ * @returns An array of {@link ToolDefinition} objects.
42
+ */
43
+ export declare function convertResponsesToolsToSemconv(tools: ResponseTool[]): ToolDefinition[];
44
+ /**
45
+ * Convert OpenAI Response instructions to GenAI SystemInstruction format.
46
+ *
47
+ * @param instructions - The instructions field from the Response object.
48
+ * @returns An array of {@link SystemInstruction} objects, or undefined if no instructions.
49
+ */
50
+ export declare function convertResponsesInstructionsToSemconv(instructions: string | ResponseInputItem[] | null | undefined): SystemInstruction[] | undefined;
51
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/converters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAGb,cAAc,EACd,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAE3B,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,CAAC;AAC5D,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC;AAC9D,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC;AAC1C,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;AACpD,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;AAgC1C;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,iBAAiB,EAAE,GAAG,SAAS,EACvC,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,CAqDlC;AAED;;;;;;;GAOG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,kBAAkB,EAAE,GAC5B,aAAa,EAAE,CAsHjB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,YAAY,EAAE,GACpB,cAAc,EAAE,CAelB;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,GAAG,IAAI,GAAG,SAAS,GAC5D,iBAAiB,EAAE,GAAG,SAAS,CAcjC"}