@introspection-sdk/introspection-node 0.4.2 → 0.4.3

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 (151) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/.turbo/turbo-lint.log +5 -0
  4. package/dist/client.d.ts +42 -132
  5. package/dist/client.d.ts.map +1 -1
  6. package/dist/client.js +67 -366
  7. package/dist/client.js.map +1 -0
  8. package/dist/converters/claude.d.ts +4 -0
  9. package/dist/converters/claude.d.ts.map +1 -1
  10. package/dist/converters/claude.js +7 -0
  11. package/dist/converters/claude.js.map +1 -0
  12. package/dist/converters/gemini.d.ts +90 -0
  13. package/dist/converters/gemini.d.ts.map +1 -0
  14. package/dist/converters/gemini.js +171 -0
  15. package/dist/converters/gemini.js.map +1 -0
  16. package/dist/converters/index.d.ts +1 -1
  17. package/dist/converters/index.d.ts.map +1 -1
  18. package/dist/converters/index.js +2 -1
  19. package/dist/converters/index.js.map +1 -0
  20. package/dist/converters/openai.js +1 -0
  21. package/dist/converters/openai.js.map +1 -0
  22. package/dist/converters/openclaw.d.ts +16 -0
  23. package/dist/converters/openclaw.d.ts.map +1 -0
  24. package/dist/converters/openclaw.js +49 -0
  25. package/dist/converters/openinference.js +1 -0
  26. package/dist/converters/openinference.js.map +1 -0
  27. package/dist/converters/vercel.d.ts.map +1 -1
  28. package/dist/converters/vercel.js +31 -3
  29. package/dist/converters/vercel.js.map +1 -0
  30. package/dist/http.d.ts +36 -0
  31. package/dist/http.d.ts.map +1 -0
  32. package/dist/http.js +145 -0
  33. package/dist/http.js.map +1 -0
  34. package/dist/index.d.ts +24 -27
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +22 -32
  37. package/dist/index.js.map +1 -0
  38. package/dist/otel/anthropic.d.ts +62 -0
  39. package/dist/otel/anthropic.d.ts.map +1 -0
  40. package/dist/otel/anthropic.js +425 -0
  41. package/dist/otel/anthropic.js.map +1 -0
  42. package/dist/otel/claude-hooks.d.ts +346 -0
  43. package/dist/otel/claude-hooks.d.ts.map +1 -0
  44. package/dist/otel/claude-hooks.js +645 -0
  45. package/dist/otel/claude-hooks.js.map +1 -0
  46. package/dist/otel/claude-wrapper.d.ts +93 -0
  47. package/dist/otel/claude-wrapper.d.ts.map +1 -0
  48. package/dist/otel/claude-wrapper.js +155 -0
  49. package/dist/otel/claude-wrapper.js.map +1 -0
  50. package/dist/otel/gemini.d.ts +48 -0
  51. package/dist/otel/gemini.d.ts.map +1 -0
  52. package/dist/otel/gemini.js +297 -0
  53. package/dist/otel/gemini.js.map +1 -0
  54. package/dist/otel/index.d.ts +27 -0
  55. package/dist/otel/index.d.ts.map +1 -0
  56. package/dist/otel/index.js +33 -0
  57. package/dist/otel/index.js.map +1 -0
  58. package/dist/otel/langchain-handler.d.ts +112 -0
  59. package/dist/otel/langchain-handler.d.ts.map +1 -0
  60. package/dist/otel/langchain-handler.js +555 -0
  61. package/dist/otel/langchain-handler.js.map +1 -0
  62. package/dist/otel/logs.d.ts +82 -0
  63. package/dist/otel/logs.d.ts.map +1 -0
  64. package/dist/otel/logs.js +271 -0
  65. package/dist/otel/logs.js.map +1 -0
  66. package/dist/otel/mastra-exporter.d.ts +87 -0
  67. package/dist/otel/mastra-exporter.d.ts.map +1 -0
  68. package/dist/otel/mastra-exporter.js +525 -0
  69. package/dist/otel/mastra-exporter.js.map +1 -0
  70. package/dist/otel/pi.d.ts +59 -0
  71. package/dist/otel/pi.d.ts.map +1 -0
  72. package/dist/otel/pi.js +67 -0
  73. package/dist/otel/pi.js.map +1 -0
  74. package/dist/otel/setup.d.ts +23 -0
  75. package/dist/otel/setup.d.ts.map +1 -0
  76. package/dist/otel/setup.js +127 -0
  77. package/dist/otel/setup.js.map +1 -0
  78. package/dist/otel/span-processor.d.ts +62 -0
  79. package/dist/otel/span-processor.d.ts.map +1 -0
  80. package/dist/otel/span-processor.js +319 -0
  81. package/dist/otel/span-processor.js.map +1 -0
  82. package/dist/otel/tracing-processor.d.ts +139 -0
  83. package/dist/otel/tracing-processor.d.ts.map +1 -0
  84. package/dist/otel/tracing-processor.js +418 -0
  85. package/dist/otel/tracing-processor.js.map +1 -0
  86. package/dist/resources/experiments.d.ts +31 -0
  87. package/dist/resources/experiments.d.ts.map +1 -0
  88. package/dist/resources/experiments.js +133 -0
  89. package/dist/resources/experiments.js.map +1 -0
  90. package/dist/resources/recipes.d.ts +22 -0
  91. package/dist/resources/recipes.d.ts.map +1 -0
  92. package/dist/resources/recipes.js +61 -0
  93. package/dist/resources/recipes.js.map +1 -0
  94. package/dist/resources/runtimes.d.ts +76 -0
  95. package/dist/resources/runtimes.d.ts.map +1 -0
  96. package/dist/resources/runtimes.js +179 -0
  97. package/dist/resources/runtimes.js.map +1 -0
  98. package/dist/runner-resources/files.d.ts +35 -0
  99. package/dist/runner-resources/files.d.ts.map +1 -0
  100. package/dist/runner-resources/files.js +131 -0
  101. package/dist/runner-resources/files.js.map +1 -0
  102. package/dist/runner-resources/tasks.d.ts +39 -0
  103. package/dist/runner-resources/tasks.d.ts.map +1 -0
  104. package/dist/runner-resources/tasks.js +129 -0
  105. package/dist/runner-resources/tasks.js.map +1 -0
  106. package/dist/runner.d.ts +80 -0
  107. package/dist/runner.d.ts.map +1 -0
  108. package/dist/runner.js +159 -0
  109. package/dist/runner.js.map +1 -0
  110. package/dist/streaming.d.ts +8 -0
  111. package/dist/streaming.d.ts.map +1 -0
  112. package/dist/streaming.js +67 -0
  113. package/dist/streaming.js.map +1 -0
  114. package/dist/types/genai.d.ts +165 -0
  115. package/dist/types/genai.d.ts.map +1 -0
  116. package/dist/types/genai.js +82 -0
  117. package/dist/types.js +1 -0
  118. package/dist/types.js.map +1 -0
  119. package/dist/utils.js +1 -0
  120. package/dist/utils.js.map +1 -0
  121. package/dist/version.js +1 -0
  122. package/dist/version.js.map +1 -0
  123. package/package.json +81 -24
  124. package/src/client.ts +76 -473
  125. package/src/converters/claude.ts +10 -0
  126. package/src/converters/gemini.ts +243 -0
  127. package/src/converters/index.ts +13 -7
  128. package/src/converters/vercel.ts +41 -3
  129. package/src/http.ts +163 -0
  130. package/src/index.ts +110 -75
  131. package/src/{anthropic.ts → otel/anthropic.ts} +95 -8
  132. package/src/{claude-hooks.ts → otel/claude-hooks.ts} +119 -20
  133. package/src/{claude-wrapper.ts → otel/claude-wrapper.ts} +1 -1
  134. package/src/otel/gemini.ts +397 -0
  135. package/src/otel/index.ts +80 -0
  136. package/src/{langchain-handler.ts → otel/langchain-handler.ts} +53 -6
  137. package/src/otel/logs.ts +394 -0
  138. package/src/{mastra-exporter.ts → otel/mastra-exporter.ts} +83 -22
  139. package/src/otel/pi.ts +88 -0
  140. package/src/otel/setup.ts +174 -0
  141. package/src/{span-processor.ts → otel/span-processor.ts} +11 -6
  142. package/src/{tracing-processor.ts → otel/tracing-processor.ts} +94 -19
  143. package/src/resources/experiments.ts +170 -0
  144. package/src/resources/recipes.ts +73 -0
  145. package/src/resources/runtimes.ts +231 -0
  146. package/src/runner-resources/files.ts +163 -0
  147. package/src/runner-resources/tasks.ts +156 -0
  148. package/src/runner.ts +194 -0
  149. package/src/streaming.ts +57 -0
  150. package/src/ai-sdk-integration.ts +0 -691
  151. package/src/converters/ai-sdk.ts +0 -323
@@ -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
- }