@introspection-sdk/introspection-node 0.19.1 → 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 +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -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 -266
- 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/vercel.ts
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converter for Vercel AI SDK telemetry spans → Gen AI semantic conventions.
|
|
3
|
-
*
|
|
4
|
-
* The Vercel AI SDK emits spans with `ai.*` attributes when
|
|
5
|
-
* `experimental_telemetry: { isEnabled: true }` is set on streamText/generateText.
|
|
6
|
-
* This converter translates those to `gen_ai.*` so the Introspection frontend
|
|
7
|
-
* can render them in the conversation view.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { Attributes } from "@opentelemetry/api";
|
|
11
|
-
|
|
12
|
-
interface VercelMessage {
|
|
13
|
-
role: string;
|
|
14
|
-
content?: string | VercelContentPart[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface VercelContentPart {
|
|
18
|
-
type: string;
|
|
19
|
-
text?: string;
|
|
20
|
-
content?: string;
|
|
21
|
-
toolName?: string;
|
|
22
|
-
name?: string;
|
|
23
|
-
toolCallId?: string;
|
|
24
|
-
id?: string;
|
|
25
|
-
// AI SDK v6 uses `input` for tool-call args; older versions used `args`.
|
|
26
|
-
args?: string | Record<string, unknown>;
|
|
27
|
-
input?: string | Record<string, unknown>;
|
|
28
|
-
// tool-result payload. AI SDK v6 emits `{ output: { type: "text", value } }`
|
|
29
|
-
// for text results; older shapes used `result`.
|
|
30
|
-
output?: { type?: string; value?: unknown } | unknown;
|
|
31
|
-
result?: unknown;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface VercelTool {
|
|
35
|
-
type?: string;
|
|
36
|
-
name?: string;
|
|
37
|
-
description?: string;
|
|
38
|
-
inputSchema?: Record<string, unknown>;
|
|
39
|
-
parameters?: Record<string, unknown>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface GenAIPart {
|
|
43
|
-
type: string;
|
|
44
|
-
content?: string;
|
|
45
|
-
name?: string;
|
|
46
|
-
id?: string;
|
|
47
|
-
arguments?: string;
|
|
48
|
-
// tool_call_response payload — kept separate from `content` so downstream
|
|
49
|
-
// consumers (and brightstaff signal detectors) can distinguish tool
|
|
50
|
-
// results from plain text.
|
|
51
|
-
response?: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
interface GenAIMessage {
|
|
55
|
-
role: string;
|
|
56
|
-
parts: GenAIPart[];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Check if a span is a Vercel AI SDK span worth converting.
|
|
60
|
-
* Only converts child "do*" spans (doStream, doGenerate) which have
|
|
61
|
-
* the actual prompt/response data with proper message windows.
|
|
62
|
-
* Parent wrapper spans (ai.streamText, ai.generateText) are skipped
|
|
63
|
-
* to avoid duplicate conversation steps without user messages. */
|
|
64
|
-
export function isVercelAISpan(attrs: Attributes): boolean {
|
|
65
|
-
const operationId = attrs["ai.operationId"];
|
|
66
|
-
return typeof operationId === "string" && operationId.includes(".do");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Convert Vercel AI SDK `ai.*` attributes to `gen_ai.*` semconv attributes.
|
|
71
|
-
* Returns only the gen_ai attributes to merge — does NOT remove originals.
|
|
72
|
-
*/
|
|
73
|
-
export function convertVercelAIToGenAI(
|
|
74
|
-
attrs: Attributes,
|
|
75
|
-
): Record<string, unknown> {
|
|
76
|
-
const result: Record<string, unknown> = {};
|
|
77
|
-
|
|
78
|
-
// gen_ai.operation.name
|
|
79
|
-
result["gen_ai.operation.name"] = "chat";
|
|
80
|
-
|
|
81
|
-
// gen_ai.usage.cache_read.input_tokens from ai.usage.cachedInputTokens
|
|
82
|
-
const cachedInput = attrs["ai.usage.cachedInputTokens"];
|
|
83
|
-
if (typeof cachedInput === "number") {
|
|
84
|
-
result["gen_ai.usage.cache_read.input_tokens"] = cachedInput;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// gen_ai.conversation.id from telemetry metadata (set by app)
|
|
88
|
-
const metadataConvId = attrs["ai.telemetry.metadata.gen_ai.conversation.id"];
|
|
89
|
-
if (typeof metadataConvId === "string") {
|
|
90
|
-
result["gen_ai.conversation.id"] = metadataConvId;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// gen_ai.request.model and gen_ai.provider.name from ai.model.*
|
|
94
|
-
const modelId = attrs["ai.model.id"];
|
|
95
|
-
if (typeof modelId === "string" && !attrs["gen_ai.request.model"]) {
|
|
96
|
-
result["gen_ai.request.model"] = modelId;
|
|
97
|
-
}
|
|
98
|
-
const modelProvider = attrs["ai.model.provider"];
|
|
99
|
-
if (typeof modelProvider === "string" && !attrs["gen_ai.provider.name"]) {
|
|
100
|
-
result["gen_ai.provider.name"] = modelProvider;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Vercel AI SDK stores prompt data in two formats:
|
|
104
|
-
// - Child spans (doStream): flat keys like ai.prompt.messages, ai.prompt.toolChoice
|
|
105
|
-
// - Parent spans (streamText): single JSON string in ai.prompt
|
|
106
|
-
const promptMessages = attrs["ai.prompt.messages"];
|
|
107
|
-
const promptRaw = attrs["ai.prompt"];
|
|
108
|
-
let parsedMessages: VercelMessage[] | null = null;
|
|
109
|
-
let parsedSystem: string | null = null;
|
|
110
|
-
|
|
111
|
-
if (typeof promptMessages === "string") {
|
|
112
|
-
try {
|
|
113
|
-
const parsed: unknown = JSON.parse(promptMessages);
|
|
114
|
-
if (Array.isArray(parsed)) parsedMessages = parsed as VercelMessage[];
|
|
115
|
-
} catch {
|
|
116
|
-
/* ignore */
|
|
117
|
-
}
|
|
118
|
-
} else if (typeof promptRaw === "string") {
|
|
119
|
-
try {
|
|
120
|
-
const parsed = JSON.parse(promptRaw) as Record<string, unknown>;
|
|
121
|
-
if (Array.isArray(parsed?.messages))
|
|
122
|
-
parsedMessages = parsed.messages as VercelMessage[];
|
|
123
|
-
if (typeof parsed?.system === "string") parsedSystem = parsed.system;
|
|
124
|
-
} catch {
|
|
125
|
-
/* ignore */
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// gen_ai.input.messages — excluding system messages
|
|
130
|
-
const nonSystemMessages = parsedMessages
|
|
131
|
-
? parsedMessages.filter((m) => m.role !== "system")
|
|
132
|
-
: null;
|
|
133
|
-
if (nonSystemMessages && nonSystemMessages.length > 0) {
|
|
134
|
-
const converted = nonSystemMessages.map(convertVercelMessageToGenAI);
|
|
135
|
-
result["gen_ai.input.messages"] = JSON.stringify(converted);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// gen_ai.output.messages — build from ai.response.text + ai.response.reasoning
|
|
139
|
-
const responseText = attrs["ai.response.text"];
|
|
140
|
-
const responseReasoning = attrs["ai.response.reasoning"];
|
|
141
|
-
if (typeof responseText === "string" && responseText) {
|
|
142
|
-
const parts: GenAIPart[] = [];
|
|
143
|
-
if (typeof responseReasoning === "string" && responseReasoning) {
|
|
144
|
-
parts.push({ type: "reasoning", content: responseReasoning });
|
|
145
|
-
}
|
|
146
|
-
parts.push({ type: "text", content: responseText });
|
|
147
|
-
result["gen_ai.output.messages"] = JSON.stringify([
|
|
148
|
-
{ role: "assistant", parts },
|
|
149
|
-
]);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// gen_ai.tool.definitions — parse ai.prompt.tools JSON strings
|
|
153
|
-
const promptTools = attrs["ai.prompt.tools"];
|
|
154
|
-
if (typeof promptTools === "string") {
|
|
155
|
-
try {
|
|
156
|
-
const parsed: unknown = JSON.parse(promptTools);
|
|
157
|
-
if (Array.isArray(parsed)) {
|
|
158
|
-
result["gen_ai.tool.definitions"] = JSON.stringify(
|
|
159
|
-
(parsed as (string | VercelTool)[])
|
|
160
|
-
.map((t) => {
|
|
161
|
-
if (typeof t === "string") {
|
|
162
|
-
try {
|
|
163
|
-
return JSON.parse(t) as VercelTool;
|
|
164
|
-
} catch {
|
|
165
|
-
return { name: t } as VercelTool;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return t;
|
|
169
|
-
})
|
|
170
|
-
.map((t) => ({
|
|
171
|
-
type: t.type || "function",
|
|
172
|
-
name: t.name || "",
|
|
173
|
-
description: t.description || "",
|
|
174
|
-
parameters: t.inputSchema || t.parameters || undefined,
|
|
175
|
-
})),
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
} catch {
|
|
179
|
-
// ignore
|
|
180
|
-
}
|
|
181
|
-
} else if (Array.isArray(promptTools)) {
|
|
182
|
-
const tools = (promptTools as string[]).map((t) => {
|
|
183
|
-
const parsed = (typeof t === "string" ? JSON.parse(t) : t) as VercelTool;
|
|
184
|
-
return {
|
|
185
|
-
type: parsed.type || "function",
|
|
186
|
-
name: parsed.name || "",
|
|
187
|
-
description: parsed.description || "",
|
|
188
|
-
parameters: parsed.inputSchema || parsed.parameters || undefined,
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
result["gen_ai.tool.definitions"] = JSON.stringify(tools);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// gen_ai.agent.name — from telemetry functionId or operation
|
|
195
|
-
const functionId = attrs["ai.telemetry.functionId"];
|
|
196
|
-
if (typeof functionId === "string" && functionId) {
|
|
197
|
-
result["gen_ai.agent.name"] = functionId;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// gen_ai.system_instructions — from parsed system prompt or system role messages
|
|
201
|
-
if (parsedSystem) {
|
|
202
|
-
result["gen_ai.system_instructions"] = JSON.stringify([
|
|
203
|
-
{ type: "text", content: parsedSystem },
|
|
204
|
-
]);
|
|
205
|
-
} else if (parsedMessages) {
|
|
206
|
-
const systemMsgs = parsedMessages.filter((m) => m.role === "system");
|
|
207
|
-
if (systemMsgs.length > 0) {
|
|
208
|
-
result["gen_ai.system_instructions"] = JSON.stringify(
|
|
209
|
-
systemMsgs.map((m) => ({
|
|
210
|
-
type: "text",
|
|
211
|
-
content:
|
|
212
|
-
typeof m.content === "string"
|
|
213
|
-
? m.content
|
|
214
|
-
: JSON.stringify(m.content),
|
|
215
|
-
})),
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function convertVercelMessageToGenAI(msg: VercelMessage): GenAIMessage {
|
|
224
|
-
const role = msg.role || "user";
|
|
225
|
-
|
|
226
|
-
if (role === "system") {
|
|
227
|
-
return {
|
|
228
|
-
role,
|
|
229
|
-
parts: [{ type: "text", content: extractTextContent(msg.content) }],
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return {
|
|
234
|
-
role,
|
|
235
|
-
parts: extractParts(msg.content),
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function extractTextContent(content: VercelMessage["content"]): string {
|
|
240
|
-
if (typeof content === "string") return content;
|
|
241
|
-
if (Array.isArray(content)) {
|
|
242
|
-
return content
|
|
243
|
-
.filter((p) => p.type === "text")
|
|
244
|
-
.map((p) => p.text || p.content || "")
|
|
245
|
-
.join("");
|
|
246
|
-
}
|
|
247
|
-
return String(content || "");
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function extractParts(content: VercelMessage["content"]): GenAIPart[] {
|
|
251
|
-
if (typeof content === "string") {
|
|
252
|
-
return [{ type: "text", content }];
|
|
253
|
-
}
|
|
254
|
-
if (Array.isArray(content)) {
|
|
255
|
-
return content.map((part) => {
|
|
256
|
-
if (part.type === "text") {
|
|
257
|
-
return { type: "text", content: part.text || part.content || "" };
|
|
258
|
-
}
|
|
259
|
-
if (part.type === "tool-call" || part.type === "tool_call") {
|
|
260
|
-
// AI SDK v6 emits `input`; older versions emitted `args`.
|
|
261
|
-
const rawArgs = part.input ?? part.args;
|
|
262
|
-
return {
|
|
263
|
-
type: "tool_call",
|
|
264
|
-
name: part.toolName || part.name || "",
|
|
265
|
-
id: part.toolCallId || part.id || "",
|
|
266
|
-
arguments:
|
|
267
|
-
typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs),
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
if (part.type === "tool-result" || part.type === "tool_result") {
|
|
271
|
-
// AI SDK v6 wraps text outputs in `{ output: { type: "text", value } }`.
|
|
272
|
-
// Older shapes used `result`. Unwrap to the raw string when we can so
|
|
273
|
-
// brightstaff's execution.failure.* / environment.exhaustion.* regex
|
|
274
|
-
// detectors see the error text directly — otherwise downstream
|
|
275
|
-
// consumers get a JSON-stringified blob and the canonical
|
|
276
|
-
// `tool_call_response` shape is lost.
|
|
277
|
-
const rawOutput =
|
|
278
|
-
part.result !== undefined ? part.result : (part.output as unknown);
|
|
279
|
-
let response: string;
|
|
280
|
-
if (typeof rawOutput === "string") {
|
|
281
|
-
response = rawOutput;
|
|
282
|
-
} else if (
|
|
283
|
-
rawOutput &&
|
|
284
|
-
typeof rawOutput === "object" &&
|
|
285
|
-
"value" in (rawOutput as Record<string, unknown>)
|
|
286
|
-
) {
|
|
287
|
-
const value = (rawOutput as Record<string, unknown>).value;
|
|
288
|
-
response = typeof value === "string" ? value : JSON.stringify(value);
|
|
289
|
-
} else {
|
|
290
|
-
response = JSON.stringify(rawOutput);
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
type: "tool_call_response",
|
|
294
|
-
id: part.toolCallId || part.id || "",
|
|
295
|
-
response,
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
return { type: "text", content: JSON.stringify(part) };
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
return [{ type: "text", content: String(content || "") }];
|
|
302
|
-
}
|
package/src/dev-target.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Development-target resolution — which `introspection dev` server this
|
|
3
|
-
* process's tasks should reach.
|
|
4
|
-
*
|
|
5
|
-
* Two developers can run `introspection dev` against one shared Runtime. A
|
|
6
|
-
* task created by a shared application credential carries no developer, so the
|
|
7
|
-
* platform cannot tell their machines apart; the caller names one instead.
|
|
8
|
-
* `introspection dev` prints the value to set:
|
|
9
|
-
*
|
|
10
|
-
* ```
|
|
11
|
-
* serving as: roland
|
|
12
|
-
* for your app: INTROSPECTION_DEV_TARGET=roland
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* Carried as a header rather than on the runner's `caller` payload: `caller`
|
|
16
|
-
* is descriptive metadata the platform never acts on, and a target is a
|
|
17
|
-
* per-request selector the platform does act on. Keeping them apart is what
|
|
18
|
-
* lets `caller` stay a free-form bag, and it is the only transport that
|
|
19
|
-
* reaches a bare `POST /v1/tasks` with a dev API key, whose JWT is minted from
|
|
20
|
-
* the key row with no per-request input path.
|
|
21
|
-
*
|
|
22
|
-
* Deliberately env-only, with no `os.userInfo()` fallback. Defaulting to the
|
|
23
|
-
* local username would be zero-config on a laptop and wrong everywhere else: a
|
|
24
|
-
* process running in a shared development deployment under an account like
|
|
25
|
-
* `node` would silently name a machine nobody is serving and fail closed,
|
|
26
|
-
* where today it reaches the one connected dev server. The CLI defaults to the
|
|
27
|
-
* username because it is naming *itself* and always runs on the developer's
|
|
28
|
-
* machine; this names *someone else's* machine and can run anywhere.
|
|
29
|
-
*
|
|
30
|
-
* Inert outside development: the Data Plane consults a target only on the
|
|
31
|
-
* development pin path, so a stray value in staging or production is ignored.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/** Header carrying the target on requests that have no runner to ride. */
|
|
35
|
-
export const DEV_TARGET_HEADER = "x-introspection-dev-target";
|
|
36
|
-
|
|
37
|
-
/** The env var `introspection dev` prints and both the CLI and SDK read. */
|
|
38
|
-
export const DEV_TARGET_ENV = "INTROSPECTION_DEV_TARGET";
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Percent-encode to RFC 3986, so the three SDKs put identical bytes on the
|
|
42
|
-
* wire for the same target.
|
|
43
|
-
*
|
|
44
|
-
* `encodeURIComponent` leaves `!'()*` alone where Python's `quote(safe="")`
|
|
45
|
-
* and the Rust client encode them. The Data Plane decodes before it
|
|
46
|
-
* normalizes, so either form routes — but a header that differs by which
|
|
47
|
-
* client sent it is a debugging trap for no benefit.
|
|
48
|
-
*/
|
|
49
|
-
function encodeTarget(value: string): string {
|
|
50
|
-
return encodeURIComponent(value).replace(
|
|
51
|
-
/[!'()*]/g,
|
|
52
|
-
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The development target for this process, or `undefined` when unset.
|
|
58
|
-
*
|
|
59
|
-
* Percent-encoded, because the value becomes an HTTP header and a header is
|
|
60
|
-
* bytes: a login name like `andré` is not transmissible as-is, and a runtime
|
|
61
|
-
* that lets it through sends latin-1 bytes the server would read back as a
|
|
62
|
-
* different string. Encoding here is lossless and costs nothing for the
|
|
63
|
-
* ordinary ASCII name, which encodes to itself.
|
|
64
|
-
*
|
|
65
|
-
* Safe to send encoded because the Data Plane decodes before it normalizes,
|
|
66
|
-
* so `andré` and `andr%C3%A9` land on the same target as the `--as andré`
|
|
67
|
-
* the CLI advertises over protobuf, where no encoding is needed.
|
|
68
|
-
*
|
|
69
|
-
* Read through `globalThis.process` so the module stays importable from
|
|
70
|
-
* non-Node runtimes that share this package's build.
|
|
71
|
-
*/
|
|
72
|
-
export function resolveDevTarget(): string | undefined {
|
|
73
|
-
const env = (
|
|
74
|
-
globalThis as { process?: { env?: Record<string, string | undefined> } }
|
|
75
|
-
).process?.env;
|
|
76
|
-
const raw = env?.[DEV_TARGET_ENV];
|
|
77
|
-
const trimmed = raw?.trim();
|
|
78
|
-
return trimmed ? encodeTarget(trimmed) : undefined;
|
|
79
|
-
}
|
package/src/http.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BaseHttpClient } from "@introspection-sdk/http";
|
|
2
|
-
|
|
3
|
-
export interface ResolvedApiConfig {
|
|
4
|
-
/**
|
|
5
|
-
* Base URL the client will prepend to every request path. For the
|
|
6
|
-
* IntrospectionClient this is the CP API host; for a Runner it is the
|
|
7
|
-
* `deployment.endpoint` returned by CP.
|
|
8
|
-
*/
|
|
9
|
-
apiUrl: string;
|
|
10
|
-
/** Bearer token. Customer API key for CP, runner JWT for DP. */
|
|
11
|
-
token: string;
|
|
12
|
-
additionalHeaders?: Record<string, string>;
|
|
13
|
-
fetch?: typeof fetch;
|
|
14
|
-
/**
|
|
15
|
-
* Automatic retries on a `429 Too Many Requests` for unary requests
|
|
16
|
-
* (honouring `Retry-After`). `0` disables. Defaults to the shared client
|
|
17
|
-
* default. Streaming has its own resume budget.
|
|
18
|
-
*/
|
|
19
|
-
maxRetries?: number;
|
|
20
|
-
/** Base step (ms) of the capped-exponential `429` retry backoff. */
|
|
21
|
-
retryBaseMs?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Bearer-token HTTP client used by both the CP-bound IntrospectionClient
|
|
26
|
-
* and each DP-bound Runner. The request/response machinery lives in the
|
|
27
|
-
* shared {@link BaseHttpClient}; this only pins the auth strategy —
|
|
28
|
-
* `Authorization: Bearer <token>` on every request, no cookie credentials.
|
|
29
|
-
*/
|
|
30
|
-
export class HttpClient extends BaseHttpClient {
|
|
31
|
-
constructor(cfg: ResolvedApiConfig) {
|
|
32
|
-
super({
|
|
33
|
-
apiUrl: cfg.apiUrl,
|
|
34
|
-
additionalHeaders: cfg.additionalHeaders,
|
|
35
|
-
fetch: cfg.fetch,
|
|
36
|
-
maxRetries: cfg.maxRetries,
|
|
37
|
-
retryBaseMs: cfg.retryBaseMs,
|
|
38
|
-
transport: {
|
|
39
|
-
authHeaders: () => ({ Authorization: `Bearer ${cfg.token}` }),
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Root entry point — REST-only surface.
|
|
3
|
-
*
|
|
4
|
-
* Exports `IntrospectionClient` (REST), Runner / RuntimeHandle /
|
|
5
|
-
* ExperimentHandle, REST wire types, and HTTP helpers. None of these
|
|
6
|
-
* touch the OpenTelemetry SDK.
|
|
7
|
-
*
|
|
8
|
-
* For the OTel surface (logs, span processors, instrumentors) import
|
|
9
|
-
* from `@introspection-sdk/introspection-node/otel`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// REST client.
|
|
13
|
-
export { IntrospectionClient } from "./client.js";
|
|
14
|
-
|
|
15
|
-
// Machine / federated / hosted-login OAuth token helpers.
|
|
16
|
-
export {
|
|
17
|
-
serviceAccountToken,
|
|
18
|
-
tokenExchange,
|
|
19
|
-
authorizationCodeToken,
|
|
20
|
-
} from "./auth.js";
|
|
21
|
-
export type {
|
|
22
|
-
ServiceAccountTokenParams,
|
|
23
|
-
ServiceAccountToken,
|
|
24
|
-
TokenExchangeParams,
|
|
25
|
-
AuthorizationCodeParams,
|
|
26
|
-
OAuthToken,
|
|
27
|
-
} from "./auth.js";
|
|
28
|
-
|
|
29
|
-
// Configuration / event types shared with the OTel surface.
|
|
30
|
-
export type {
|
|
31
|
-
AdvancedOptions,
|
|
32
|
-
IntrospectionClientOptions,
|
|
33
|
-
FeedbackOptions,
|
|
34
|
-
UserTraits,
|
|
35
|
-
} from "./types.js";
|
|
36
|
-
|
|
37
|
-
// Runner-bound REST namespaces (runner.tasks, runner.files,
|
|
38
|
-
// runner.conversations) + HTTP.
|
|
39
|
-
export {
|
|
40
|
-
ConversationItemsApi,
|
|
41
|
-
ConversationsApi,
|
|
42
|
-
EventsApi,
|
|
43
|
-
FileVersionsApi,
|
|
44
|
-
FilesApi,
|
|
45
|
-
MetricsApi,
|
|
46
|
-
RunHandle,
|
|
47
|
-
SharesApi,
|
|
48
|
-
TaskRunsApi,
|
|
49
|
-
TasksApi,
|
|
50
|
-
} from "@introspection-sdk/http";
|
|
51
|
-
export { streamResumable } from "@introspection-sdk/http";
|
|
52
|
-
export { ArrowPages } from "@introspection-sdk/http";
|
|
53
|
-
export type {
|
|
54
|
-
EventArrowParams,
|
|
55
|
-
FileUploadBody,
|
|
56
|
-
ListReadParams,
|
|
57
|
-
StartParams,
|
|
58
|
-
StreamOptions,
|
|
59
|
-
} from "@introspection-sdk/http";
|
|
60
|
-
export { HttpClient } from "./http.js";
|
|
61
|
-
export type { ResolvedApiConfig } from "./http.js";
|
|
62
|
-
export { EventType } from "@introspection-sdk/types";
|
|
63
|
-
|
|
64
|
-
// Runner + CP resources.
|
|
65
|
-
export { Runner } from "./runner.js";
|
|
66
|
-
export type { RunnerSource } from "./runner.js";
|
|
67
|
-
export {
|
|
68
|
-
RuntimesApi,
|
|
69
|
-
RuntimeHandle,
|
|
70
|
-
attachRuntimes,
|
|
71
|
-
isUuid,
|
|
72
|
-
} from "./resources/runtimes.js";
|
|
73
|
-
export type { RuntimeHandleFactory } from "./resources/runtimes.js";
|
|
74
|
-
export {
|
|
75
|
-
ExperimentsApi,
|
|
76
|
-
ExperimentHandle,
|
|
77
|
-
attachExperiments,
|
|
78
|
-
} from "./resources/experiments.js";
|
|
79
|
-
export type { ExperimentHandleFactory } from "./resources/experiments.js";
|
|
80
|
-
export { RecipesApi, attachRecipes } from "./resources/recipes.js";
|
|
81
|
-
|
|
82
|
-
// REST API wire types
|
|
83
|
-
export type {
|
|
84
|
-
AGUIEvent,
|
|
85
|
-
BaseEvent,
|
|
86
|
-
Interrupt,
|
|
87
|
-
Message,
|
|
88
|
-
ResumeEntry,
|
|
89
|
-
RunAgentInput,
|
|
90
|
-
Paginated,
|
|
91
|
-
ListParams,
|
|
92
|
-
Task,
|
|
93
|
-
TaskCreateParams,
|
|
94
|
-
TaskUpdateParams,
|
|
95
|
-
TaskListParams,
|
|
96
|
-
TaskMode,
|
|
97
|
-
TaskStatus,
|
|
98
|
-
TaskRunKind,
|
|
99
|
-
TaskPrompt,
|
|
100
|
-
TaskRun,
|
|
101
|
-
TaskRunCreateParams,
|
|
102
|
-
TaskRunResumeParams,
|
|
103
|
-
TaskRunResponse,
|
|
104
|
-
TaskCreateResponse,
|
|
105
|
-
TaskFileRef,
|
|
106
|
-
TaskCancelResponse,
|
|
107
|
-
TaskCancelOptions,
|
|
108
|
-
AgentInfo,
|
|
109
|
-
File,
|
|
110
|
-
FileType,
|
|
111
|
-
FileListParams,
|
|
112
|
-
FileUpdateParams,
|
|
113
|
-
FileCreateTextParams,
|
|
114
|
-
Runtime,
|
|
115
|
-
RuntimeListParams,
|
|
116
|
-
Experiment,
|
|
117
|
-
ExperimentCreate,
|
|
118
|
-
ExperimentUpdate,
|
|
119
|
-
ExperimentListParams,
|
|
120
|
-
ExperimentStatus,
|
|
121
|
-
ExperimentGoal,
|
|
122
|
-
ExperimentGoalComponent,
|
|
123
|
-
ExperimentGoalDirection,
|
|
124
|
-
ExperimentGoalGuard,
|
|
125
|
-
JudgeGoalComponent,
|
|
126
|
-
TelemetryGoalComponent,
|
|
127
|
-
ExperimentArm,
|
|
128
|
-
Recipe,
|
|
129
|
-
RecipeCreate,
|
|
130
|
-
RecipeUpdate,
|
|
131
|
-
RecipeListParams,
|
|
132
|
-
RunnerSpec,
|
|
133
|
-
RunnerDeployment,
|
|
134
|
-
RunnerContext,
|
|
135
|
-
RunnerRecipeSummary,
|
|
136
|
-
RunnerIdentity,
|
|
137
|
-
RunRequest,
|
|
138
|
-
RunCaller,
|
|
139
|
-
RunCallerLibrary,
|
|
140
|
-
RunCallerPage,
|
|
141
|
-
RunIdentityInput,
|
|
142
|
-
GenAiSpan,
|
|
143
|
-
GenAiSpanList,
|
|
144
|
-
GenAiSpanAttributes,
|
|
145
|
-
GenAiSpanStatus,
|
|
146
|
-
IntrospectionSpanAttributes,
|
|
147
|
-
IntrospectionConversation,
|
|
148
|
-
SpanAttributes,
|
|
149
|
-
SpanResource,
|
|
150
|
-
ConversationItemInclude,
|
|
151
|
-
ConversationSortField,
|
|
152
|
-
ConversationListParams,
|
|
153
|
-
ConversationItemListParams,
|
|
154
|
-
ConversationsMethod,
|
|
155
|
-
SpanEvent,
|
|
156
|
-
SpanKind,
|
|
157
|
-
SpanStatus,
|
|
158
|
-
ReadFormat,
|
|
159
|
-
ReadWindowParams,
|
|
160
|
-
IntrospectionEventName,
|
|
161
|
-
IntrospectionEventEnvelope,
|
|
162
|
-
ObservationPayload,
|
|
163
|
-
PatternPayload,
|
|
164
|
-
PatternAssignmentPayload,
|
|
165
|
-
ClusteringRunPayload,
|
|
166
|
-
FeedbackPayload,
|
|
167
|
-
JudgementPayload,
|
|
168
|
-
ObservationEvent,
|
|
169
|
-
PatternEvent,
|
|
170
|
-
PatternAssignmentEvent,
|
|
171
|
-
ClusteringRunEvent,
|
|
172
|
-
FeedbackEvent,
|
|
173
|
-
JudgementEvent,
|
|
174
|
-
Event,
|
|
175
|
-
UnknownEvent,
|
|
176
|
-
EventForName,
|
|
177
|
-
EventSortField,
|
|
178
|
-
EventListParams,
|
|
179
|
-
MetricView,
|
|
180
|
-
MetricAggregation,
|
|
181
|
-
MetricFilterOperator,
|
|
182
|
-
MetricInterval,
|
|
183
|
-
MetricSpec,
|
|
184
|
-
MetricDimension,
|
|
185
|
-
MetricFilter,
|
|
186
|
-
MetricTimeDimension,
|
|
187
|
-
MetricOrderBy,
|
|
188
|
-
MetricHaving,
|
|
189
|
-
MetricQueryConfig,
|
|
190
|
-
MetricQueryRequest,
|
|
191
|
-
MetricDimensionValue,
|
|
192
|
-
MetricResultValue,
|
|
193
|
-
MetricResultRow,
|
|
194
|
-
MetricEffectiveWindow,
|
|
195
|
-
MetricQueryMeta,
|
|
196
|
-
MetricQueryResponse,
|
|
197
|
-
} from "@introspection-sdk/types";
|
|
198
|
-
export {
|
|
199
|
-
ConversationsMethods,
|
|
200
|
-
IntrospectionEventNames,
|
|
201
|
-
genAiConversationId,
|
|
202
|
-
genAiInputMessages,
|
|
203
|
-
genAiOutputMessages,
|
|
204
|
-
isKnownEvent,
|
|
205
|
-
} from "@introspection-sdk/types";
|
|
206
|
-
export {
|
|
207
|
-
IntrospectionAPIError,
|
|
208
|
-
AuthenticationError,
|
|
209
|
-
InsufficientScopeError,
|
|
210
|
-
RunnerExpiredError,
|
|
211
|
-
NotFoundError,
|
|
212
|
-
ConflictError,
|
|
213
|
-
ValidationError,
|
|
214
|
-
RateLimitError,
|
|
215
|
-
SandboxUnavailableError,
|
|
216
|
-
StreamError,
|
|
217
|
-
NetworkError,
|
|
218
|
-
apiErrorFromResponse,
|
|
219
|
-
} from "@introspection-sdk/types";
|
|
220
|
-
|
|
221
|
-
// GenAI types (shared, no OTel SDK imports).
|
|
222
|
-
export type {
|
|
223
|
-
GenAiAttributes,
|
|
224
|
-
InputMessage,
|
|
225
|
-
OutputMessage,
|
|
226
|
-
SystemInstruction,
|
|
227
|
-
ToolDefinition,
|
|
228
|
-
TextPart,
|
|
229
|
-
ToolCallRequestPart,
|
|
230
|
-
ToolCallResponsePart,
|
|
231
|
-
CompactionPart,
|
|
232
|
-
MediaUrlPart,
|
|
233
|
-
BinaryDataPart,
|
|
234
|
-
MessagePart,
|
|
235
|
-
} from "@introspection-sdk/types";
|
|
236
|
-
export { toAttributes } from "@introspection-sdk/types";
|
|
237
|
-
|
|
238
|
-
// OpenAI converter exports (pure functions, no OTel SDK imports).
|
|
239
|
-
export {
|
|
240
|
-
convertResponsesInputsToSemconv,
|
|
241
|
-
convertResponsesOutputsToSemconv,
|
|
242
|
-
convertResponsesToolsToSemconv,
|
|
243
|
-
convertResponsesInstructionsToSemconv,
|
|
244
|
-
} from "./converters/openai.js";
|
|
245
|
-
export type {
|
|
246
|
-
ResponseInputItem,
|
|
247
|
-
ResponseOutputItem,
|
|
248
|
-
ResponseTool,
|
|
249
|
-
ResponseUsage,
|
|
250
|
-
Response as OpenAIResponse,
|
|
251
|
-
} from "./converters/openai.js";
|
|
252
|
-
|
|
253
|
-
// Gemini converters (pure functions, no OTel SDK imports).
|
|
254
|
-
export {
|
|
255
|
-
convertGeminiContentsToInputMessages,
|
|
256
|
-
convertGeminiCandidatesToOutputMessages,
|
|
257
|
-
convertGeminiSystemInstructionToSemconv,
|
|
258
|
-
convertGeminiToolsToToolDefinitions,
|
|
259
|
-
} from "./converters/gemini.js";
|
|
260
|
-
export type {
|
|
261
|
-
GeminiCandidate,
|
|
262
|
-
GeminiContent,
|
|
263
|
-
GeminiFunctionDeclaration,
|
|
264
|
-
GeminiPart,
|
|
265
|
-
GeminiTool,
|
|
266
|
-
} from "./converters/gemini.js";
|