@introspection-sdk/introspection-node 0.20.0 → 0.21.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/README.md +28 -8
- package/dist/auth.d.ts +1 -1
- package/dist/client.d.ts +4 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +16 -7
- package/dist/client.js.map +1 -1
- package/dist/dev-target.js +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/otel/index.d.ts +1 -14
- package/dist/otel/index.d.ts.map +1 -1
- package/dist/otel/index.js +10 -18
- package/dist/otel/index.js.map +1 -1
- package/dist/otel/init.d.ts +19 -21
- package/dist/otel/init.d.ts.map +1 -1
- package/dist/otel/init.js +62 -48
- package/dist/otel/init.js.map +1 -1
- package/dist/otel/integrations/base.d.ts +17 -37
- package/dist/otel/integrations/base.d.ts.map +1 -1
- package/dist/otel/integrations/base.js +6 -13
- package/dist/otel/integrations/base.js.map +1 -1
- package/dist/otel/integrations/index.d.ts +3 -4
- package/dist/otel/integrations/index.d.ts.map +1 -1
- package/dist/otel/integrations/index.js +6 -25
- package/dist/otel/integrations/index.js.map +1 -1
- package/dist/otel/integrations/pi.d.ts.map +1 -1
- package/dist/otel/integrations/pi.js +9 -1
- package/dist/otel/integrations/pi.js.map +1 -1
- package/dist/otel/logs.d.ts +41 -8
- package/dist/otel/logs.d.ts.map +1 -1
- package/dist/otel/logs.js +95 -66
- package/dist/otel/logs.js.map +1 -1
- package/dist/otel/pi.d.ts +18 -5
- package/dist/otel/pi.d.ts.map +1 -1
- package/dist/otel/pi.js +38 -9
- package/dist/otel/pi.js.map +1 -1
- package/dist/otel/register.d.ts +2 -2
- package/dist/otel/register.d.ts.map +1 -1
- package/dist/otel/register.js +7 -9
- package/dist/otel/register.js.map +1 -1
- package/dist/otel/setup.d.ts +2 -2
- package/dist/otel/setup.d.ts.map +1 -1
- package/dist/otel/setup.js +16 -6
- package/dist/otel/setup.js.map +1 -1
- package/dist/otel/span-processor.d.ts +18 -5
- package/dist/otel/span-processor.d.ts.map +1 -1
- package/dist/otel/span-processor.js +50 -65
- package/dist/otel/span-processor.js.map +1 -1
- package/dist/resources/experiments.d.ts +10 -5
- package/dist/resources/experiments.d.ts.map +1 -1
- package/dist/resources/experiments.js +9 -25
- package/dist/resources/experiments.js.map +1 -1
- package/dist/resources/recipes.d.ts +6 -6
- package/dist/resources/recipes.d.ts.map +1 -1
- package/dist/resources/recipes.js +5 -23
- package/dist/resources/recipes.js.map +1 -1
- package/dist/resources/runtimes.d.ts +2 -2
- package/dist/resources/runtimes.d.ts.map +1 -1
- package/dist/resources/runtimes.js +2 -2
- package/dist/resources/runtimes.js.map +1 -1
- package/dist/runner.d.ts +8 -4
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +26 -18
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +45 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +61 -2
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +18 -60
- package/.turbo/turbo-build.log +0 -4
- package/dist/converters/claude.d.ts +0 -150
- package/dist/converters/claude.d.ts.map +0 -1
- package/dist/converters/claude.js +0 -211
- package/dist/converters/claude.js.map +0 -1
- package/dist/converters/gemini.d.ts +0 -90
- package/dist/converters/gemini.d.ts.map +0 -1
- package/dist/converters/gemini.js +0 -171
- package/dist/converters/gemini.js.map +0 -1
- package/dist/converters/index.d.ts +0 -9
- package/dist/converters/index.d.ts.map +0 -1
- package/dist/converters/index.js +0 -9
- package/dist/converters/index.js.map +0 -1
- package/dist/converters/openai.d.ts +0 -51
- package/dist/converters/openai.d.ts.map +0 -1
- package/dist/converters/openai.js +0 -269
- package/dist/converters/openai.js.map +0 -1
- package/dist/converters/openinference.d.ts +0 -107
- package/dist/converters/openinference.d.ts.map +0 -1
- package/dist/converters/openinference.js +0 -553
- package/dist/converters/openinference.js.map +0 -1
- package/dist/converters/vercel.d.ts +0 -21
- package/dist/converters/vercel.d.ts.map +0 -1
- package/dist/converters/vercel.js +0 -236
- package/dist/converters/vercel.js.map +0 -1
- package/dist/otel/anthropic.d.ts +0 -63
- package/dist/otel/anthropic.d.ts.map +0 -1
- package/dist/otel/anthropic.js +0 -475
- package/dist/otel/anthropic.js.map +0 -1
- package/dist/otel/claude-hooks.d.ts +0 -346
- package/dist/otel/claude-hooks.d.ts.map +0 -1
- package/dist/otel/claude-hooks.js +0 -647
- package/dist/otel/claude-hooks.js.map +0 -1
- package/dist/otel/claude-wrapper.d.ts +0 -93
- package/dist/otel/claude-wrapper.d.ts.map +0 -1
- package/dist/otel/claude-wrapper.js +0 -155
- package/dist/otel/claude-wrapper.js.map +0 -1
- package/dist/otel/gemini.d.ts +0 -56
- package/dist/otel/gemini.d.ts.map +0 -1
- package/dist/otel/gemini.js +0 -350
- package/dist/otel/gemini.js.map +0 -1
- package/dist/otel/integrations/anthropic.d.ts +0 -10
- package/dist/otel/integrations/anthropic.d.ts.map +0 -1
- package/dist/otel/integrations/anthropic.js +0 -26
- package/dist/otel/integrations/anthropic.js.map +0 -1
- package/dist/otel/integrations/claude-agent.d.ts +0 -12
- package/dist/otel/integrations/claude-agent.d.ts.map +0 -1
- package/dist/otel/integrations/claude-agent.js +0 -28
- package/dist/otel/integrations/claude-agent.js.map +0 -1
- package/dist/otel/integrations/gemini.d.ts +0 -11
- package/dist/otel/integrations/gemini.d.ts.map +0 -1
- package/dist/otel/integrations/gemini.js +0 -23
- package/dist/otel/integrations/gemini.js.map +0 -1
- package/dist/otel/integrations/langchain.d.ts +0 -15
- package/dist/otel/integrations/langchain.d.ts.map +0 -1
- package/dist/otel/integrations/langchain.js +0 -43
- package/dist/otel/integrations/langchain.js.map +0 -1
- package/dist/otel/integrations/mastra.d.ts +0 -14
- package/dist/otel/integrations/mastra.d.ts.map +0 -1
- package/dist/otel/integrations/mastra.js +0 -31
- package/dist/otel/integrations/mastra.js.map +0 -1
- package/dist/otel/integrations/openai-agents.d.ts +0 -11
- package/dist/otel/integrations/openai-agents.d.ts.map +0 -1
- package/dist/otel/integrations/openai-agents.js +0 -30
- package/dist/otel/integrations/openai-agents.js.map +0 -1
- package/dist/otel/integrations/vercel.d.ts +0 -14
- package/dist/otel/integrations/vercel.d.ts.map +0 -1
- package/dist/otel/integrations/vercel.js +0 -20
- package/dist/otel/integrations/vercel.js.map +0 -1
- package/dist/otel/langchain-handler.d.ts +0 -112
- package/dist/otel/langchain-handler.d.ts.map +0 -1
- package/dist/otel/langchain-handler.js +0 -561
- package/dist/otel/langchain-handler.js.map +0 -1
- package/dist/otel/mastra-exporter.d.ts +0 -87
- package/dist/otel/mastra-exporter.d.ts.map +0 -1
- package/dist/otel/mastra-exporter.js +0 -530
- package/dist/otel/mastra-exporter.js.map +0 -1
- package/dist/otel/openai.d.ts +0 -20
- package/dist/otel/openai.d.ts.map +0 -1
- package/dist/otel/openai.js +0 -55
- package/dist/otel/openai.js.map +0 -1
- package/dist/otel/tracing-processor.d.ts +0 -139
- package/dist/otel/tracing-processor.d.ts.map +0 -1
- package/dist/otel/tracing-processor.js +0 -434
- package/dist/otel/tracing-processor.js.map +0 -1
- package/eslint.config.mjs +0 -4
- package/src/auth.ts +0 -236
- package/src/client.ts +0 -163
- package/src/converters/claude.ts +0 -343
- package/src/converters/gemini.ts +0 -243
- package/src/converters/index.ts +0 -50
- package/src/converters/openai.ts +0 -300
- package/src/converters/openinference.ts +0 -665
- package/src/converters/vercel.ts +0 -302
- package/src/dev-target.ts +0 -79
- package/src/http.ts +0 -43
- package/src/index.ts +0 -277
- package/src/otel/anthropic.ts +0 -619
- package/src/otel/claude-hooks.ts +0 -1116
- package/src/otel/claude-wrapper.ts +0 -239
- package/src/otel/gemini.ts +0 -483
- package/src/otel/index.ts +0 -128
- package/src/otel/init.ts +0 -411
- package/src/otel/integrations/anthropic.ts +0 -36
- package/src/otel/integrations/base.ts +0 -158
- package/src/otel/integrations/claude-agent.ts +0 -36
- package/src/otel/integrations/gemini.ts +0 -30
- package/src/otel/integrations/index.ts +0 -152
- package/src/otel/integrations/langchain.ts +0 -60
- package/src/otel/integrations/mastra.ts +0 -48
- package/src/otel/integrations/openai-agents.ts +0 -47
- package/src/otel/integrations/pi.ts +0 -28
- package/src/otel/integrations/vercel.ts +0 -26
- package/src/otel/langchain-handler.ts +0 -804
- package/src/otel/logs.ts +0 -395
- package/src/otel/mastra-exporter.ts +0 -714
- package/src/otel/openai.ts +0 -93
- package/src/otel/pi.ts +0 -94
- package/src/otel/register.ts +0 -50
- package/src/otel/setup.ts +0 -215
- package/src/otel/span-processor.ts +0 -512
- package/src/otel/tracing-processor.ts +0 -637
- package/src/pagination.ts +0 -10
- package/src/proxy-from-env.d.ts +0 -7
- package/src/resources/experiments.ts +0 -176
- package/src/resources/recipes.ts +0 -74
- package/src/resources/runtimes.ts +0 -31
- package/src/runner.ts +0 -213
- package/src/types.ts +0 -13
- package/src/utils.ts +0 -95
- package/src/version.ts +0 -2
- package/tsconfig.json +0 -8
package/src/converters/openai.ts
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
import type { Responses } from "openai/resources/responses/responses";
|
|
10
|
-
import type {
|
|
11
|
-
InputMessage,
|
|
12
|
-
OutputMessage,
|
|
13
|
-
MessagePart,
|
|
14
|
-
ReasoningPart,
|
|
15
|
-
ToolDefinition,
|
|
16
|
-
SystemInstruction,
|
|
17
|
-
} from "@introspection-sdk/types";
|
|
18
|
-
|
|
19
|
-
/** Re-export OpenAI types used by callers (e.g. tracing-processor). */
|
|
20
|
-
export type ResponseInputItem = Responses.ResponseInputItem;
|
|
21
|
-
export type ResponseOutputItem = Responses.ResponseOutputItem;
|
|
22
|
-
export type ResponseTool = Responses.Tool;
|
|
23
|
-
export type ResponseUsage = Responses.ResponseUsage;
|
|
24
|
-
export type Response = Responses.Response;
|
|
25
|
-
|
|
26
|
-
/** Safely access a property from a union type by going through `unknown`. */
|
|
27
|
-
function asRecord(value: unknown): Record<string, unknown> {
|
|
28
|
-
return value as Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Extract text content from a message content field (string or array of content parts).
|
|
33
|
-
*/
|
|
34
|
-
function extractContentParts(content: unknown): MessagePart[] {
|
|
35
|
-
const parts: MessagePart[] = [];
|
|
36
|
-
if (typeof content === "string") {
|
|
37
|
-
parts.push({ type: "text", content });
|
|
38
|
-
} else if (Array.isArray(content)) {
|
|
39
|
-
for (const item of content) {
|
|
40
|
-
const rec = asRecord(item);
|
|
41
|
-
if (rec.type === "output_text") {
|
|
42
|
-
parts.push({
|
|
43
|
-
type: "text",
|
|
44
|
-
content: (rec.text as string) || "",
|
|
45
|
-
});
|
|
46
|
-
} else if (typeof item === "object" && item !== null) {
|
|
47
|
-
parts.push(item as unknown as MessagePart);
|
|
48
|
-
} else {
|
|
49
|
-
parts.push({ type: "text", content: String(item) });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return parts;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Convert OpenAI Responses API inputs to OTel Gen AI Semantic Convention format.
|
|
58
|
-
*
|
|
59
|
-
* Handles `message`, `function_call`, and `function_call_output` input types.
|
|
60
|
-
* System instructions are returned separately so callers can set
|
|
61
|
-
* `gen_ai.system_instructions` independently from `gen_ai.input.messages`.
|
|
62
|
-
*
|
|
63
|
-
* @param inputs - Input items array from the Responses API request body.
|
|
64
|
-
* @param instructions - Optional system instructions / system prompt string.
|
|
65
|
-
* @returns A `[inputMessages, systemInstructions]` tuple of {@link InputMessage} arrays.
|
|
66
|
-
*/
|
|
67
|
-
export function convertResponsesInputsToSemconv(
|
|
68
|
-
inputs: ResponseInputItem[] | undefined,
|
|
69
|
-
instructions: string | undefined,
|
|
70
|
-
): [InputMessage[], InputMessage[]] {
|
|
71
|
-
const inputMessages: InputMessage[] = [];
|
|
72
|
-
const systemInstructions: InputMessage[] = [];
|
|
73
|
-
|
|
74
|
-
if (instructions) {
|
|
75
|
-
systemInstructions.push({
|
|
76
|
-
role: "system",
|
|
77
|
-
parts: [{ type: "text", content: instructions }],
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (inputs) {
|
|
82
|
-
for (const inp of inputs) {
|
|
83
|
-
const item = asRecord(inp);
|
|
84
|
-
const role = (item.role as string) || "user";
|
|
85
|
-
const typ = item.type as string | undefined;
|
|
86
|
-
const content = item.content;
|
|
87
|
-
|
|
88
|
-
if ((typ === undefined || typ === "message") && content) {
|
|
89
|
-
const parts = extractContentParts(content);
|
|
90
|
-
inputMessages.push({ role: role as InputMessage["role"], parts });
|
|
91
|
-
} else if (typ === "function_call") {
|
|
92
|
-
inputMessages.push({
|
|
93
|
-
role: "assistant",
|
|
94
|
-
parts: [
|
|
95
|
-
{
|
|
96
|
-
type: "tool_call",
|
|
97
|
-
id: item.call_id as string | undefined,
|
|
98
|
-
name: item.name as string,
|
|
99
|
-
arguments: item.arguments,
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
});
|
|
103
|
-
} else if (typ === "function_call_output") {
|
|
104
|
-
const msg: InputMessage = {
|
|
105
|
-
role: "tool",
|
|
106
|
-
parts: [
|
|
107
|
-
{
|
|
108
|
-
type: "tool_call_response",
|
|
109
|
-
id: item.call_id as string | undefined,
|
|
110
|
-
response: item.output,
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
};
|
|
114
|
-
if (item.name) {
|
|
115
|
-
msg.name = item.name as string;
|
|
116
|
-
}
|
|
117
|
-
inputMessages.push(msg);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return [inputMessages, systemInstructions];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Convert OpenAI Responses API outputs to OTel Gen AI Semantic Convention format.
|
|
127
|
-
*
|
|
128
|
-
* Maps `message` and `function_call` output types to {@link OutputMessage} objects.
|
|
129
|
-
*
|
|
130
|
-
* @param outputs - Output items array from the Responses API response body.
|
|
131
|
-
* @returns An array of {@link OutputMessage} objects in semconv format.
|
|
132
|
-
*/
|
|
133
|
-
export function convertResponsesOutputsToSemconv(
|
|
134
|
-
outputs: ResponseOutputItem[],
|
|
135
|
-
): OutputMessage[] {
|
|
136
|
-
// Reasoning and web_search_call parts are collected as prefixes and merged
|
|
137
|
-
// into the next message's parts array, matching the format the frontend expects
|
|
138
|
-
// (thinking + text in the same message).
|
|
139
|
-
const prefixParts: MessagePart[] = [];
|
|
140
|
-
const outputMessages: OutputMessage[] = [];
|
|
141
|
-
let pendingWebSearchId: string | undefined;
|
|
142
|
-
|
|
143
|
-
for (const out of outputs) {
|
|
144
|
-
const item = asRecord(out);
|
|
145
|
-
const typ = item.type as string | undefined;
|
|
146
|
-
const content = item.content;
|
|
147
|
-
|
|
148
|
-
if (typ === "mcp_call") {
|
|
149
|
-
const name = (item.name as string) || "mcp_tool";
|
|
150
|
-
const server = (item.server_label as string) || "";
|
|
151
|
-
const toolName = server ? `${server}/${name}` : name;
|
|
152
|
-
const args = item.arguments as string | undefined;
|
|
153
|
-
const output = item.output as string | undefined;
|
|
154
|
-
const error = item.error as string | undefined;
|
|
155
|
-
prefixParts.push({
|
|
156
|
-
type: "tool_call",
|
|
157
|
-
id: item.id as string | undefined,
|
|
158
|
-
name: toolName,
|
|
159
|
-
arguments: args,
|
|
160
|
-
});
|
|
161
|
-
prefixParts.push({
|
|
162
|
-
type: "tool_call_response",
|
|
163
|
-
id: item.id as string | undefined,
|
|
164
|
-
response: error || output || "",
|
|
165
|
-
});
|
|
166
|
-
} else if (typ === "mcp_list_tools") {
|
|
167
|
-
// Skip — tool discovery metadata, not a user-facing message
|
|
168
|
-
} else if (typ === "reasoning") {
|
|
169
|
-
const summary = item.summary as
|
|
170
|
-
Array<Record<string, unknown>> | undefined;
|
|
171
|
-
const texts = (summary ?? [])
|
|
172
|
-
.map((s) => (s.text as string) || "")
|
|
173
|
-
.filter(Boolean);
|
|
174
|
-
const content = texts.length > 0 ? texts.join("\n") : undefined;
|
|
175
|
-
const signature =
|
|
176
|
-
(item.encrypted_content as string | undefined) || undefined;
|
|
177
|
-
const thinkingPart: ReasoningPart = {
|
|
178
|
-
type: "reasoning",
|
|
179
|
-
content: content ?? "[redacted]",
|
|
180
|
-
signature,
|
|
181
|
-
provider_name: "openai",
|
|
182
|
-
};
|
|
183
|
-
prefixParts.push(thinkingPart);
|
|
184
|
-
} else if (typ === "web_search_call") {
|
|
185
|
-
const action = item.action as Record<string, unknown> | undefined;
|
|
186
|
-
const query = action?.query as string | undefined;
|
|
187
|
-
prefixParts.push({
|
|
188
|
-
type: "tool_call",
|
|
189
|
-
id: item.id as string | undefined,
|
|
190
|
-
name: "web_search",
|
|
191
|
-
arguments: query ? JSON.stringify({ query }) : undefined,
|
|
192
|
-
});
|
|
193
|
-
pendingWebSearchId = item.id as string | undefined;
|
|
194
|
-
} else if ((typ === undefined || typ === "message") && content) {
|
|
195
|
-
// Extract search result citations from annotations if this follows a web search
|
|
196
|
-
if (pendingWebSearchId) {
|
|
197
|
-
const contentItems = Array.isArray(content) ? content : [];
|
|
198
|
-
const citations: string[] = [];
|
|
199
|
-
for (const ci of contentItems) {
|
|
200
|
-
const rec = asRecord(ci);
|
|
201
|
-
const anns = rec.annotations as
|
|
202
|
-
Array<Record<string, unknown>> | undefined;
|
|
203
|
-
if (anns) {
|
|
204
|
-
for (const ann of anns) {
|
|
205
|
-
if (ann.title && ann.url) {
|
|
206
|
-
citations.push(`${ann.title}: ${ann.url}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
prefixParts.push({
|
|
212
|
-
type: "tool_call_response",
|
|
213
|
-
id: pendingWebSearchId,
|
|
214
|
-
response:
|
|
215
|
-
citations.length > 0 ? citations.join("\n") : "search completed",
|
|
216
|
-
});
|
|
217
|
-
pendingWebSearchId = undefined;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const parts = extractContentParts(content);
|
|
221
|
-
const status = item.status as string | undefined;
|
|
222
|
-
const finishReason = status === "completed" ? "stop" : undefined;
|
|
223
|
-
outputMessages.push({
|
|
224
|
-
role: "assistant",
|
|
225
|
-
parts: [...prefixParts, ...parts],
|
|
226
|
-
finish_reason: finishReason,
|
|
227
|
-
});
|
|
228
|
-
prefixParts.length = 0;
|
|
229
|
-
} else if (typ === "function_call") {
|
|
230
|
-
outputMessages.push({
|
|
231
|
-
role: "assistant",
|
|
232
|
-
finish_reason: "tool-calls",
|
|
233
|
-
parts: [
|
|
234
|
-
{
|
|
235
|
-
type: "tool_call",
|
|
236
|
-
id: item.call_id as string | undefined,
|
|
237
|
-
name: item.name as string,
|
|
238
|
-
arguments: item.arguments,
|
|
239
|
-
},
|
|
240
|
-
],
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Leftover prefix parts with no message to attach to
|
|
246
|
-
if (prefixParts.length > 0) {
|
|
247
|
-
outputMessages.push({ role: "assistant", parts: [...prefixParts] });
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return outputMessages;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Convert OpenAI Responses API tool definitions to GenAI ToolDefinition format.
|
|
255
|
-
*
|
|
256
|
-
* @param tools - The tools array from the Response object.
|
|
257
|
-
* @returns An array of {@link ToolDefinition} objects.
|
|
258
|
-
*/
|
|
259
|
-
export function convertResponsesToolsToSemconv(
|
|
260
|
-
tools: ResponseTool[],
|
|
261
|
-
): ToolDefinition[] {
|
|
262
|
-
const toolDefs: ToolDefinition[] = [];
|
|
263
|
-
for (const tool of tools) {
|
|
264
|
-
if (tool.type === "function") {
|
|
265
|
-
const toolDef: ToolDefinition = { type: "function", name: tool.name };
|
|
266
|
-
if (tool.description) toolDef.description = tool.description;
|
|
267
|
-
if (tool.parameters)
|
|
268
|
-
toolDef.parameters = tool.parameters as Record<string, unknown>;
|
|
269
|
-
toolDefs.push(toolDef);
|
|
270
|
-
} else {
|
|
271
|
-
// For non-function tools (web_search, file_search, etc.)
|
|
272
|
-
toolDefs.push({ type: tool.type, name: tool.type });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return toolDefs;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Convert OpenAI Response instructions to GenAI SystemInstruction format.
|
|
280
|
-
*
|
|
281
|
-
* @param instructions - The instructions field from the Response object.
|
|
282
|
-
* @returns An array of {@link SystemInstruction} objects, or undefined if no instructions.
|
|
283
|
-
*/
|
|
284
|
-
export function convertResponsesInstructionsToSemconv(
|
|
285
|
-
instructions: string | ResponseInputItem[] | null | undefined,
|
|
286
|
-
): SystemInstruction[] | undefined {
|
|
287
|
-
if (!instructions) return undefined;
|
|
288
|
-
if (typeof instructions === "string") {
|
|
289
|
-
return [{ type: "text", content: instructions }];
|
|
290
|
-
}
|
|
291
|
-
// Array of ResponseInputItem used as instructions
|
|
292
|
-
const result: SystemInstruction[] = [];
|
|
293
|
-
for (const item of instructions) {
|
|
294
|
-
const rec = asRecord(item);
|
|
295
|
-
if (typeof rec.content === "string") {
|
|
296
|
-
result.push({ type: "text", content: rec.content });
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return result.length > 0 ? result : undefined;
|
|
300
|
-
}
|