@introspection-sdk/introspection-node 0.4.2 → 0.4.4
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/.turbo/turbo-build.log +1 -1
- package/dist/client.d.ts +42 -132
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +67 -366
- package/dist/client.js.map +1 -0
- package/dist/converters/claude.d.ts +4 -0
- package/dist/converters/claude.d.ts.map +1 -1
- package/dist/converters/claude.js +7 -0
- package/dist/converters/claude.js.map +1 -0
- package/dist/converters/gemini.d.ts +90 -0
- package/dist/converters/gemini.d.ts.map +1 -0
- package/dist/converters/gemini.js +171 -0
- package/dist/converters/gemini.js.map +1 -0
- package/dist/converters/index.d.ts +1 -1
- package/dist/converters/index.d.ts.map +1 -1
- package/dist/converters/index.js +2 -1
- package/dist/converters/index.js.map +1 -0
- package/dist/converters/openai.js +1 -0
- package/dist/converters/openai.js.map +1 -0
- package/dist/converters/openinference.js +1 -0
- package/dist/converters/openinference.js.map +1 -0
- package/dist/converters/vercel.d.ts.map +1 -1
- package/dist/converters/vercel.js +31 -3
- package/dist/converters/vercel.js.map +1 -0
- package/dist/http.d.ts +36 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +145 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +24 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -32
- package/dist/index.js.map +1 -0
- package/dist/{anthropic.d.ts → otel/anthropic.d.ts} +23 -13
- package/dist/otel/anthropic.d.ts.map +1 -0
- package/dist/{anthropic.js → otel/anthropic.js} +132 -40
- package/dist/otel/anthropic.js.map +1 -0
- package/dist/{claude-hooks.d.ts → otel/claude-hooks.d.ts} +19 -1
- package/dist/otel/claude-hooks.d.ts.map +1 -0
- package/dist/{claude-hooks.js → otel/claude-hooks.js} +94 -20
- package/dist/otel/claude-hooks.js.map +1 -0
- package/dist/otel/claude-wrapper.d.ts.map +1 -0
- package/dist/{claude-wrapper.js → otel/claude-wrapper.js} +2 -1
- package/dist/otel/claude-wrapper.js.map +1 -0
- package/dist/otel/gemini.d.ts +56 -0
- package/dist/otel/gemini.d.ts.map +1 -0
- package/dist/otel/gemini.js +348 -0
- package/dist/otel/gemini.js.map +1 -0
- package/dist/otel/index.d.ts +32 -0
- package/dist/otel/index.d.ts.map +1 -0
- package/dist/otel/index.js +41 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/otel/init.d.ts +126 -0
- package/dist/otel/init.d.ts.map +1 -0
- package/dist/otel/init.js +259 -0
- package/dist/otel/init.js.map +1 -0
- package/dist/otel/integrations/anthropic.d.ts +10 -0
- package/dist/otel/integrations/anthropic.d.ts.map +1 -0
- package/dist/otel/integrations/anthropic.js +22 -0
- package/dist/otel/integrations/anthropic.js.map +1 -0
- package/dist/otel/integrations/base.d.ts +83 -0
- package/dist/otel/integrations/base.d.ts.map +1 -0
- package/dist/otel/integrations/base.js +23 -0
- package/dist/otel/integrations/base.js.map +1 -0
- package/dist/otel/integrations/claude-agent.d.ts +13 -0
- package/dist/otel/integrations/claude-agent.d.ts.map +1 -0
- package/dist/otel/integrations/claude-agent.js +27 -0
- package/dist/otel/integrations/claude-agent.js.map +1 -0
- package/dist/otel/integrations/gemini.d.ts +11 -0
- package/dist/otel/integrations/gemini.d.ts.map +1 -0
- package/dist/otel/integrations/gemini.js +21 -0
- package/dist/otel/integrations/gemini.js.map +1 -0
- package/dist/otel/integrations/index.d.ts +39 -0
- package/dist/otel/integrations/index.d.ts.map +1 -0
- package/dist/otel/integrations/index.js +131 -0
- package/dist/otel/integrations/index.js.map +1 -0
- package/dist/otel/integrations/langchain.d.ts +16 -0
- package/dist/otel/integrations/langchain.d.ts.map +1 -0
- package/dist/otel/integrations/langchain.js +41 -0
- package/dist/otel/integrations/langchain.js.map +1 -0
- package/dist/otel/integrations/mastra.d.ts +14 -0
- package/dist/otel/integrations/mastra.d.ts.map +1 -0
- package/dist/otel/integrations/mastra.js +27 -0
- package/dist/otel/integrations/mastra.js.map +1 -0
- package/dist/otel/integrations/openai-agents.d.ts +11 -0
- package/dist/otel/integrations/openai-agents.d.ts.map +1 -0
- package/dist/otel/integrations/openai-agents.js +25 -0
- package/dist/otel/integrations/openai-agents.js.map +1 -0
- package/dist/otel/integrations/pi.d.ts +12 -0
- package/dist/otel/integrations/pi.d.ts.map +1 -0
- package/dist/otel/integrations/pi.js +20 -0
- package/dist/otel/integrations/pi.js.map +1 -0
- package/dist/otel/integrations/vercel.d.ts +15 -0
- package/dist/otel/integrations/vercel.d.ts.map +1 -0
- package/dist/otel/integrations/vercel.js +20 -0
- package/dist/otel/integrations/vercel.js.map +1 -0
- package/dist/{langchain-handler.d.ts → otel/langchain-handler.d.ts} +10 -1
- package/dist/otel/langchain-handler.d.ts.map +1 -0
- package/dist/{langchain-handler.js → otel/langchain-handler.js} +43 -6
- package/dist/otel/langchain-handler.js.map +1 -0
- package/dist/otel/logs.d.ts +82 -0
- package/dist/otel/logs.d.ts.map +1 -0
- package/dist/otel/logs.js +271 -0
- package/dist/otel/logs.js.map +1 -0
- package/dist/{mastra-exporter.d.ts → otel/mastra-exporter.d.ts} +3 -1
- package/dist/otel/mastra-exporter.d.ts.map +1 -0
- package/dist/{mastra-exporter.js → otel/mastra-exporter.js} +71 -17
- package/dist/otel/mastra-exporter.js.map +1 -0
- package/dist/otel/pi.d.ts +59 -0
- package/dist/otel/pi.d.ts.map +1 -0
- package/dist/otel/pi.js +67 -0
- package/dist/otel/pi.js.map +1 -0
- package/dist/otel/register.d.ts +8 -0
- package/dist/otel/register.d.ts.map +1 -0
- package/dist/otel/register.js +48 -0
- package/dist/otel/register.js.map +1 -0
- package/dist/otel/setup.d.ts +52 -0
- package/dist/otel/setup.d.ts.map +1 -0
- package/dist/otel/setup.js +146 -0
- package/dist/otel/setup.js.map +1 -0
- package/dist/{span-processor.d.ts → otel/span-processor.d.ts} +1 -1
- package/dist/otel/span-processor.d.ts.map +1 -0
- package/dist/{span-processor.js → otel/span-processor.js} +11 -5
- package/dist/otel/span-processor.js.map +1 -0
- package/dist/{tracing-processor.d.ts → otel/tracing-processor.d.ts} +4 -1
- package/dist/otel/tracing-processor.d.ts.map +1 -0
- package/dist/{tracing-processor.js → otel/tracing-processor.js} +64 -14
- package/dist/otel/tracing-processor.js.map +1 -0
- package/dist/resources/experiments.d.ts +31 -0
- package/dist/resources/experiments.d.ts.map +1 -0
- package/dist/resources/experiments.js +133 -0
- package/dist/resources/experiments.js.map +1 -0
- package/dist/resources/recipes.d.ts +22 -0
- package/dist/resources/recipes.d.ts.map +1 -0
- package/dist/resources/recipes.js +61 -0
- package/dist/resources/recipes.js.map +1 -0
- package/dist/resources/runtimes.d.ts +76 -0
- package/dist/resources/runtimes.d.ts.map +1 -0
- package/dist/resources/runtimes.js +179 -0
- package/dist/resources/runtimes.js.map +1 -0
- package/dist/runner-resources/files.d.ts +35 -0
- package/dist/runner-resources/files.d.ts.map +1 -0
- package/dist/runner-resources/files.js +131 -0
- package/dist/runner-resources/files.js.map +1 -0
- package/dist/runner-resources/tasks.d.ts +39 -0
- package/dist/runner-resources/tasks.d.ts.map +1 -0
- package/dist/runner-resources/tasks.js +129 -0
- package/dist/runner-resources/tasks.js.map +1 -0
- package/dist/runner.d.ts +80 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +159 -0
- package/dist/runner.js.map +1 -0
- package/dist/streaming.d.ts +8 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +67 -0
- package/dist/streaming.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -4
- package/dist/utils.js.map +1 -0
- package/dist/version.js +1 -0
- package/dist/version.js.map +1 -0
- package/package.json +91 -22
- package/src/client.ts +76 -473
- package/src/converters/claude.ts +10 -0
- package/src/converters/gemini.ts +243 -0
- package/src/converters/index.ts +13 -7
- package/src/converters/vercel.ts +41 -3
- package/src/http.ts +163 -0
- package/src/index.ts +110 -75
- package/src/{anthropic.ts → otel/anthropic.ts} +206 -54
- package/src/{claude-hooks.ts → otel/claude-hooks.ts} +119 -20
- package/src/{claude-wrapper.ts → otel/claude-wrapper.ts} +1 -1
- package/src/otel/gemini.ts +491 -0
- package/src/otel/index.ts +121 -0
- package/src/otel/init.ts +411 -0
- package/src/otel/integrations/anthropic.ts +26 -0
- package/src/otel/integrations/base.ts +95 -0
- package/src/otel/integrations/claude-agent.ts +32 -0
- package/src/otel/integrations/gemini.ts +25 -0
- package/src/otel/integrations/index.ts +151 -0
- package/src/otel/integrations/langchain.ts +45 -0
- package/src/otel/integrations/mastra.ts +30 -0
- package/src/otel/integrations/openai-agents.ts +31 -0
- package/src/otel/integrations/pi.ts +24 -0
- package/src/otel/integrations/vercel.ts +24 -0
- package/src/{langchain-handler.ts → otel/langchain-handler.ts} +53 -6
- package/src/otel/logs.ts +394 -0
- package/src/{mastra-exporter.ts → otel/mastra-exporter.ts} +83 -22
- package/src/otel/pi.ts +88 -0
- package/src/otel/register.ts +50 -0
- package/src/otel/setup.ts +215 -0
- package/src/{span-processor.ts → otel/span-processor.ts} +11 -6
- package/src/{tracing-processor.ts → otel/tracing-processor.ts} +94 -19
- package/src/resources/experiments.ts +170 -0
- package/src/resources/recipes.ts +73 -0
- package/src/resources/runtimes.ts +231 -0
- package/src/runner-resources/files.ts +163 -0
- package/src/runner-resources/tasks.ts +156 -0
- package/src/runner.ts +194 -0
- package/src/streaming.ts +57 -0
- package/src/utils.ts +12 -5
- package/dist/ai-sdk-integration.d.ts +0 -123
- package/dist/ai-sdk-integration.d.ts.map +0 -1
- package/dist/ai-sdk-integration.js +0 -475
- package/dist/anthropic.d.ts.map +0 -1
- package/dist/claude-hooks.d.ts.map +0 -1
- package/dist/claude-wrapper.d.ts.map +0 -1
- package/dist/converters/ai-sdk.d.ts +0 -65
- package/dist/converters/ai-sdk.d.ts.map +0 -1
- package/dist/converters/ai-sdk.js +0 -261
- package/dist/langchain-handler.d.ts.map +0 -1
- package/dist/mastra-exporter.d.ts.map +0 -1
- package/dist/span-processor.d.ts.map +0 -1
- package/dist/tracing-processor.d.ts.map +0 -1
- package/src/ai-sdk-integration.ts +0 -691
- package/src/converters/ai-sdk.ts +0 -323
- /package/dist/{claude-wrapper.d.ts → otel/claude-wrapper.d.ts} +0 -0
package/src/converters/ai-sdk.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converter for AI SDK event data → Gen AI semantic conventions.
|
|
3
|
-
*
|
|
4
|
-
* Converts typed event objects (messages, tool definitions, step results)
|
|
5
|
-
* from the AI SDK's TelemetryIntegration callbacks into the standardized
|
|
6
|
-
* gen_ai format used by the Introspection backend.
|
|
7
|
-
*
|
|
8
|
-
* Used by {@link IntrospectionAISDKIntegration}.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
InputMessage,
|
|
13
|
-
OutputMessage,
|
|
14
|
-
SystemInstruction,
|
|
15
|
-
ToolDefinition,
|
|
16
|
-
MessagePart,
|
|
17
|
-
} from "@introspection-sdk/types";
|
|
18
|
-
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Local types — minimal shapes matching AI SDK data structures.
|
|
21
|
-
// Defined locally to avoid requiring `ai` as a compile-time dependency.
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
/** A content part within an AI SDK message. */
|
|
25
|
-
interface ContentPart {
|
|
26
|
-
type: string;
|
|
27
|
-
text?: string;
|
|
28
|
-
toolCallId?: string;
|
|
29
|
-
toolName?: string;
|
|
30
|
-
args?: unknown;
|
|
31
|
-
input?: unknown;
|
|
32
|
-
result?: unknown;
|
|
33
|
-
output?: unknown;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
// Public conversion functions
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Convert AI SDK messages (ModelMessage[]) to gen_ai InputMessage[].
|
|
42
|
-
* System messages are excluded — they're handled separately via
|
|
43
|
-
* {@link extractSystemInstructions}.
|
|
44
|
-
*
|
|
45
|
-
* @param messages - Array of AI SDK ModelMessage objects.
|
|
46
|
-
* @returns Array of gen_ai InputMessage objects (without system messages).
|
|
47
|
-
*/
|
|
48
|
-
export function convertMessagesToInputMessages(
|
|
49
|
-
messages: readonly unknown[],
|
|
50
|
-
): InputMessage[] {
|
|
51
|
-
const result: InputMessage[] = [];
|
|
52
|
-
for (const msg of messages) {
|
|
53
|
-
const m = msg as { role?: string; content?: unknown };
|
|
54
|
-
if (!m || !m.role || m.role === "system") continue;
|
|
55
|
-
result.push(convertOneMessage(m));
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Extract gen_ai system instructions from AI SDK's system field and messages.
|
|
62
|
-
*
|
|
63
|
-
* The AI SDK provides system prompts in two places:
|
|
64
|
-
* - The `system` parameter (string, SystemModelMessage, or array)
|
|
65
|
-
* - Messages with role "system"
|
|
66
|
-
*
|
|
67
|
-
* @param system - The AI SDK `system` field.
|
|
68
|
-
* @param messages - The messages array (may contain system-role messages).
|
|
69
|
-
* @returns System instructions in gen_ai format, or undefined if none.
|
|
70
|
-
*/
|
|
71
|
-
export function extractSystemInstructions(
|
|
72
|
-
system: unknown,
|
|
73
|
-
messages: readonly unknown[],
|
|
74
|
-
): SystemInstruction[] | undefined {
|
|
75
|
-
const instructions: SystemInstruction[] = [];
|
|
76
|
-
|
|
77
|
-
// From the `system` field
|
|
78
|
-
if (typeof system === "string" && system) {
|
|
79
|
-
instructions.push({ type: "text", content: system });
|
|
80
|
-
} else if (system && typeof system === "object") {
|
|
81
|
-
if (Array.isArray(system)) {
|
|
82
|
-
for (const s of system) {
|
|
83
|
-
const text = extractTextFromSystemMessage(s);
|
|
84
|
-
if (text) instructions.push({ type: "text", content: text });
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
const text = extractTextFromSystemMessage(system);
|
|
88
|
-
if (text) instructions.push({ type: "text", content: text });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// From system-role messages
|
|
93
|
-
for (const msg of messages) {
|
|
94
|
-
const m = msg as { role?: string; content?: unknown };
|
|
95
|
-
if (m?.role === "system") {
|
|
96
|
-
const content = m.content;
|
|
97
|
-
if (typeof content === "string") {
|
|
98
|
-
instructions.push({ type: "text", content });
|
|
99
|
-
} else if (Array.isArray(content)) {
|
|
100
|
-
const text = (content as ContentPart[])
|
|
101
|
-
.filter((p) => p.type === "text")
|
|
102
|
-
.map((p) => p.text || "")
|
|
103
|
-
.join("");
|
|
104
|
-
if (text) instructions.push({ type: "text", content: text });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return instructions.length > 0 ? instructions : undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Build gen_ai output messages from AI SDK step result data.
|
|
114
|
-
*
|
|
115
|
-
* Combines text, reasoning, and tool call outputs into a single assistant
|
|
116
|
-
* OutputMessage, mirroring the order used by vercel.ts (reasoning → text → tool calls).
|
|
117
|
-
*
|
|
118
|
-
* @param options - Step result fields.
|
|
119
|
-
* @returns Array of gen_ai OutputMessage objects.
|
|
120
|
-
*/
|
|
121
|
-
export function buildOutputMessages(options: {
|
|
122
|
-
text?: string;
|
|
123
|
-
reasoningText?: string;
|
|
124
|
-
reasoning?: readonly { text?: string }[];
|
|
125
|
-
toolCalls?: readonly {
|
|
126
|
-
toolCallId: string;
|
|
127
|
-
toolName: string;
|
|
128
|
-
input: unknown;
|
|
129
|
-
}[];
|
|
130
|
-
finishReason?: string;
|
|
131
|
-
}): OutputMessage[] {
|
|
132
|
-
const parts: MessagePart[] = [];
|
|
133
|
-
|
|
134
|
-
// Reasoning first (mirrors vercel.ts order)
|
|
135
|
-
if (options.reasoningText) {
|
|
136
|
-
parts.push({ type: "thinking", content: options.reasoningText });
|
|
137
|
-
} else if (options.reasoning?.length) {
|
|
138
|
-
for (const r of options.reasoning) {
|
|
139
|
-
if (r.text) parts.push({ type: "thinking", content: r.text });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Text content
|
|
144
|
-
if (options.text) {
|
|
145
|
-
parts.push({ type: "text", content: options.text });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Tool calls
|
|
149
|
-
if (options.toolCalls?.length) {
|
|
150
|
-
for (const tc of options.toolCalls) {
|
|
151
|
-
parts.push({
|
|
152
|
-
type: "tool_call",
|
|
153
|
-
name: tc.toolName,
|
|
154
|
-
id: tc.toolCallId,
|
|
155
|
-
arguments:
|
|
156
|
-
typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input),
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (parts.length === 0) return [];
|
|
162
|
-
|
|
163
|
-
return [
|
|
164
|
-
{
|
|
165
|
-
role: "assistant",
|
|
166
|
-
parts,
|
|
167
|
-
finish_reason: options.finishReason,
|
|
168
|
-
},
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Convert AI SDK ToolSet to gen_ai ToolDefinition[].
|
|
174
|
-
*
|
|
175
|
-
* The AI SDK represents tools as `Record<string, Tool>` where each Tool has
|
|
176
|
-
* description and parameters (usually a Zod schema). We extract what we can
|
|
177
|
-
* without importing Zod.
|
|
178
|
-
*
|
|
179
|
-
* @param tools - AI SDK ToolSet (Record<string, Tool>).
|
|
180
|
-
* @returns Array of gen_ai ToolDefinition objects, or undefined if no tools.
|
|
181
|
-
*/
|
|
182
|
-
export function convertToolsToToolDefinitions(
|
|
183
|
-
tools: unknown,
|
|
184
|
-
): ToolDefinition[] | undefined {
|
|
185
|
-
if (!tools || typeof tools !== "object") return undefined;
|
|
186
|
-
|
|
187
|
-
const defs: ToolDefinition[] = [];
|
|
188
|
-
for (const [name, tool] of Object.entries(tools as Record<string, unknown>)) {
|
|
189
|
-
if (!tool || typeof tool !== "object") continue;
|
|
190
|
-
const t = tool as Record<string, unknown>;
|
|
191
|
-
defs.push({
|
|
192
|
-
name,
|
|
193
|
-
description:
|
|
194
|
-
typeof t.description === "string" ? t.description : undefined,
|
|
195
|
-
parameters: extractToolParameters(t.inputSchema ?? t.parameters),
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return defs.length > 0 ? defs : undefined;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ---------------------------------------------------------------------------
|
|
203
|
-
// Internal helpers
|
|
204
|
-
// ---------------------------------------------------------------------------
|
|
205
|
-
|
|
206
|
-
function convertOneMessage(msg: {
|
|
207
|
-
role?: string;
|
|
208
|
-
content?: unknown;
|
|
209
|
-
}): InputMessage {
|
|
210
|
-
const role = (msg.role || "user") as InputMessage["role"];
|
|
211
|
-
const content = msg.content;
|
|
212
|
-
const parts: MessagePart[] = [];
|
|
213
|
-
|
|
214
|
-
if (typeof content === "string") {
|
|
215
|
-
parts.push({ type: "text", content });
|
|
216
|
-
} else if (Array.isArray(content)) {
|
|
217
|
-
for (const part of content as ContentPart[]) {
|
|
218
|
-
const converted = convertContentPart(part);
|
|
219
|
-
if (converted) parts.push(converted);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return { role, parts };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function convertContentPart(part: ContentPart): MessagePart | null {
|
|
227
|
-
switch (part.type) {
|
|
228
|
-
case "text":
|
|
229
|
-
return { type: "text", content: part.text || "" };
|
|
230
|
-
|
|
231
|
-
case "tool-call": {
|
|
232
|
-
const args = part.args ?? part.input;
|
|
233
|
-
return {
|
|
234
|
-
type: "tool_call",
|
|
235
|
-
name: part.toolName || "",
|
|
236
|
-
id: part.toolCallId || "",
|
|
237
|
-
arguments: typeof args === "string" ? args : JSON.stringify(args ?? {}),
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
case "tool-result": {
|
|
242
|
-
const rawResult = part.result ?? part.output;
|
|
243
|
-
let response: string;
|
|
244
|
-
if (typeof rawResult === "string") {
|
|
245
|
-
response = rawResult;
|
|
246
|
-
} else if (
|
|
247
|
-
rawResult &&
|
|
248
|
-
typeof rawResult === "object" &&
|
|
249
|
-
"value" in (rawResult as Record<string, unknown>)
|
|
250
|
-
) {
|
|
251
|
-
response = JSON.stringify((rawResult as Record<string, unknown>).value);
|
|
252
|
-
} else {
|
|
253
|
-
response = JSON.stringify(rawResult);
|
|
254
|
-
}
|
|
255
|
-
return {
|
|
256
|
-
type: "tool_call_response",
|
|
257
|
-
id: part.toolCallId || "",
|
|
258
|
-
response,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
case "reasoning":
|
|
263
|
-
return { type: "thinking", content: part.text || "" };
|
|
264
|
-
|
|
265
|
-
default:
|
|
266
|
-
// Unknown part type — serialize as text fallback
|
|
267
|
-
return { type: "text", content: JSON.stringify(part) };
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function extractTextFromSystemMessage(msg: unknown): string | null {
|
|
272
|
-
if (typeof msg === "string") return msg;
|
|
273
|
-
if (msg && typeof msg === "object") {
|
|
274
|
-
const m = msg as Record<string, unknown>;
|
|
275
|
-
if (typeof m.content === "string") return m.content;
|
|
276
|
-
if (typeof m.text === "string") return m.text;
|
|
277
|
-
}
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function extractToolParameters(
|
|
282
|
-
parameters: unknown,
|
|
283
|
-
): Record<string, unknown> | undefined {
|
|
284
|
-
if (!parameters || typeof parameters !== "object") return undefined;
|
|
285
|
-
const p = parameters as Record<string, unknown>;
|
|
286
|
-
|
|
287
|
-
// Zod 4 schema — exposes a toJSONSchema() method.
|
|
288
|
-
if (typeof p.toJSONSchema === "function") {
|
|
289
|
-
const jsonSchema = p.toJSONSchema();
|
|
290
|
-
if (jsonSchema && typeof jsonSchema === "object") {
|
|
291
|
-
return jsonSchema as Record<string, unknown>;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// AI SDK v6 tools expose inputSchema instead of parameters. Zod-backed
|
|
296
|
-
// schemas usually carry a JSON Schema factory on this property.
|
|
297
|
-
if (p["~standard"] && typeof p["~standard"] === "object") {
|
|
298
|
-
const standard = p["~standard"] as Record<string, unknown>;
|
|
299
|
-
const standardJsonSchema = standard.jsonSchema;
|
|
300
|
-
if (standardJsonSchema && typeof standardJsonSchema === "object") {
|
|
301
|
-
const input = (standardJsonSchema as Record<string, unknown>).input;
|
|
302
|
-
if (typeof input === "function") {
|
|
303
|
-
const jsonSchema = input();
|
|
304
|
-
if (jsonSchema && typeof jsonSchema === "object") {
|
|
305
|
-
return jsonSchema as Record<string, unknown>;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return standardJsonSchema as Record<string, unknown>;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// jsonSchema() wrapper — has a jsonSchema property
|
|
313
|
-
if (p.jsonSchema && typeof p.jsonSchema === "object") {
|
|
314
|
-
return p.jsonSchema as Record<string, unknown>;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Plain JSON Schema object (has 'type' and 'properties')
|
|
318
|
-
if (p.type === "object" && p.properties) {
|
|
319
|
-
return p as Record<string, unknown>;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return undefined;
|
|
323
|
-
}
|
|
File without changes
|