@introspection-sdk/introspection-node 0.20.0 → 0.21.1

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 (211) hide show
  1. package/README.md +28 -8
  2. package/dist/auth.d.ts +1 -1
  3. package/dist/client.d.ts +4 -3
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +16 -7
  6. package/dist/client.js.map +1 -1
  7. package/dist/dev-target.js +1 -1
  8. package/dist/index.d.ts +3 -7
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -6
  11. package/dist/index.js.map +1 -1
  12. package/dist/otel/index.d.ts +1 -14
  13. package/dist/otel/index.d.ts.map +1 -1
  14. package/dist/otel/index.js +10 -18
  15. package/dist/otel/index.js.map +1 -1
  16. package/dist/otel/init.d.ts +19 -21
  17. package/dist/otel/init.d.ts.map +1 -1
  18. package/dist/otel/init.js +62 -48
  19. package/dist/otel/init.js.map +1 -1
  20. package/dist/otel/integrations/base.d.ts +17 -37
  21. package/dist/otel/integrations/base.d.ts.map +1 -1
  22. package/dist/otel/integrations/base.js +6 -13
  23. package/dist/otel/integrations/base.js.map +1 -1
  24. package/dist/otel/integrations/index.d.ts +3 -4
  25. package/dist/otel/integrations/index.d.ts.map +1 -1
  26. package/dist/otel/integrations/index.js +6 -25
  27. package/dist/otel/integrations/index.js.map +1 -1
  28. package/dist/otel/integrations/pi.d.ts.map +1 -1
  29. package/dist/otel/integrations/pi.js +9 -1
  30. package/dist/otel/integrations/pi.js.map +1 -1
  31. package/dist/otel/logs.d.ts +41 -8
  32. package/dist/otel/logs.d.ts.map +1 -1
  33. package/dist/otel/logs.js +95 -66
  34. package/dist/otel/logs.js.map +1 -1
  35. package/dist/otel/pi.d.ts +18 -5
  36. package/dist/otel/pi.d.ts.map +1 -1
  37. package/dist/otel/pi.js +38 -9
  38. package/dist/otel/pi.js.map +1 -1
  39. package/dist/otel/register.d.ts +2 -2
  40. package/dist/otel/register.d.ts.map +1 -1
  41. package/dist/otel/register.js +7 -9
  42. package/dist/otel/register.js.map +1 -1
  43. package/dist/otel/setup.d.ts +2 -2
  44. package/dist/otel/setup.d.ts.map +1 -1
  45. package/dist/otel/setup.js +16 -6
  46. package/dist/otel/setup.js.map +1 -1
  47. package/dist/otel/span-processor.d.ts +18 -5
  48. package/dist/otel/span-processor.d.ts.map +1 -1
  49. package/dist/otel/span-processor.js +50 -65
  50. package/dist/otel/span-processor.js.map +1 -1
  51. package/dist/resources/experiments.d.ts +10 -5
  52. package/dist/resources/experiments.d.ts.map +1 -1
  53. package/dist/resources/experiments.js +9 -25
  54. package/dist/resources/experiments.js.map +1 -1
  55. package/dist/resources/recipes.d.ts +6 -6
  56. package/dist/resources/recipes.d.ts.map +1 -1
  57. package/dist/resources/recipes.js +5 -23
  58. package/dist/resources/recipes.js.map +1 -1
  59. package/dist/resources/runtimes.d.ts +2 -2
  60. package/dist/resources/runtimes.d.ts.map +1 -1
  61. package/dist/resources/runtimes.js +2 -2
  62. package/dist/resources/runtimes.js.map +1 -1
  63. package/dist/runner.d.ts +8 -4
  64. package/dist/runner.d.ts.map +1 -1
  65. package/dist/runner.js +26 -18
  66. package/dist/runner.js.map +1 -1
  67. package/dist/types.d.ts +1 -1
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js +1 -1
  70. package/dist/types.js.map +1 -1
  71. package/dist/utils.d.ts +45 -0
  72. package/dist/utils.d.ts.map +1 -1
  73. package/dist/utils.js +61 -2
  74. package/dist/utils.js.map +1 -1
  75. package/dist/version.d.ts +1 -1
  76. package/dist/version.d.ts.map +1 -1
  77. package/dist/version.js +1 -1
  78. package/dist/version.js.map +1 -1
  79. package/package.json +16 -58
  80. package/.turbo/turbo-build.log +0 -4
  81. package/dist/converters/claude.d.ts +0 -150
  82. package/dist/converters/claude.d.ts.map +0 -1
  83. package/dist/converters/claude.js +0 -211
  84. package/dist/converters/claude.js.map +0 -1
  85. package/dist/converters/gemini.d.ts +0 -90
  86. package/dist/converters/gemini.d.ts.map +0 -1
  87. package/dist/converters/gemini.js +0 -171
  88. package/dist/converters/gemini.js.map +0 -1
  89. package/dist/converters/index.d.ts +0 -9
  90. package/dist/converters/index.d.ts.map +0 -1
  91. package/dist/converters/index.js +0 -9
  92. package/dist/converters/index.js.map +0 -1
  93. package/dist/converters/openai.d.ts +0 -51
  94. package/dist/converters/openai.d.ts.map +0 -1
  95. package/dist/converters/openai.js +0 -269
  96. package/dist/converters/openai.js.map +0 -1
  97. package/dist/converters/openinference.d.ts +0 -107
  98. package/dist/converters/openinference.d.ts.map +0 -1
  99. package/dist/converters/openinference.js +0 -553
  100. package/dist/converters/openinference.js.map +0 -1
  101. package/dist/converters/vercel.d.ts +0 -21
  102. package/dist/converters/vercel.d.ts.map +0 -1
  103. package/dist/converters/vercel.js +0 -236
  104. package/dist/converters/vercel.js.map +0 -1
  105. package/dist/otel/anthropic.d.ts +0 -63
  106. package/dist/otel/anthropic.d.ts.map +0 -1
  107. package/dist/otel/anthropic.js +0 -475
  108. package/dist/otel/anthropic.js.map +0 -1
  109. package/dist/otel/claude-hooks.d.ts +0 -346
  110. package/dist/otel/claude-hooks.d.ts.map +0 -1
  111. package/dist/otel/claude-hooks.js +0 -647
  112. package/dist/otel/claude-hooks.js.map +0 -1
  113. package/dist/otel/claude-wrapper.d.ts +0 -93
  114. package/dist/otel/claude-wrapper.d.ts.map +0 -1
  115. package/dist/otel/claude-wrapper.js +0 -155
  116. package/dist/otel/claude-wrapper.js.map +0 -1
  117. package/dist/otel/gemini.d.ts +0 -56
  118. package/dist/otel/gemini.d.ts.map +0 -1
  119. package/dist/otel/gemini.js +0 -350
  120. package/dist/otel/gemini.js.map +0 -1
  121. package/dist/otel/integrations/anthropic.d.ts +0 -10
  122. package/dist/otel/integrations/anthropic.d.ts.map +0 -1
  123. package/dist/otel/integrations/anthropic.js +0 -26
  124. package/dist/otel/integrations/anthropic.js.map +0 -1
  125. package/dist/otel/integrations/claude-agent.d.ts +0 -12
  126. package/dist/otel/integrations/claude-agent.d.ts.map +0 -1
  127. package/dist/otel/integrations/claude-agent.js +0 -28
  128. package/dist/otel/integrations/claude-agent.js.map +0 -1
  129. package/dist/otel/integrations/gemini.d.ts +0 -11
  130. package/dist/otel/integrations/gemini.d.ts.map +0 -1
  131. package/dist/otel/integrations/gemini.js +0 -23
  132. package/dist/otel/integrations/gemini.js.map +0 -1
  133. package/dist/otel/integrations/langchain.d.ts +0 -15
  134. package/dist/otel/integrations/langchain.d.ts.map +0 -1
  135. package/dist/otel/integrations/langchain.js +0 -43
  136. package/dist/otel/integrations/langchain.js.map +0 -1
  137. package/dist/otel/integrations/mastra.d.ts +0 -14
  138. package/dist/otel/integrations/mastra.d.ts.map +0 -1
  139. package/dist/otel/integrations/mastra.js +0 -31
  140. package/dist/otel/integrations/mastra.js.map +0 -1
  141. package/dist/otel/integrations/openai-agents.d.ts +0 -11
  142. package/dist/otel/integrations/openai-agents.d.ts.map +0 -1
  143. package/dist/otel/integrations/openai-agents.js +0 -30
  144. package/dist/otel/integrations/openai-agents.js.map +0 -1
  145. package/dist/otel/integrations/vercel.d.ts +0 -14
  146. package/dist/otel/integrations/vercel.d.ts.map +0 -1
  147. package/dist/otel/integrations/vercel.js +0 -20
  148. package/dist/otel/integrations/vercel.js.map +0 -1
  149. package/dist/otel/langchain-handler.d.ts +0 -112
  150. package/dist/otel/langchain-handler.d.ts.map +0 -1
  151. package/dist/otel/langchain-handler.js +0 -561
  152. package/dist/otel/langchain-handler.js.map +0 -1
  153. package/dist/otel/mastra-exporter.d.ts +0 -87
  154. package/dist/otel/mastra-exporter.d.ts.map +0 -1
  155. package/dist/otel/mastra-exporter.js +0 -530
  156. package/dist/otel/mastra-exporter.js.map +0 -1
  157. package/dist/otel/openai.d.ts +0 -20
  158. package/dist/otel/openai.d.ts.map +0 -1
  159. package/dist/otel/openai.js +0 -55
  160. package/dist/otel/openai.js.map +0 -1
  161. package/dist/otel/tracing-processor.d.ts +0 -139
  162. package/dist/otel/tracing-processor.d.ts.map +0 -1
  163. package/dist/otel/tracing-processor.js +0 -434
  164. package/dist/otel/tracing-processor.js.map +0 -1
  165. package/eslint.config.mjs +0 -4
  166. package/src/auth.ts +0 -236
  167. package/src/client.ts +0 -163
  168. package/src/converters/claude.ts +0 -343
  169. package/src/converters/gemini.ts +0 -243
  170. package/src/converters/index.ts +0 -50
  171. package/src/converters/openai.ts +0 -300
  172. package/src/converters/openinference.ts +0 -665
  173. package/src/converters/vercel.ts +0 -302
  174. package/src/dev-target.ts +0 -79
  175. package/src/http.ts +0 -43
  176. package/src/index.ts +0 -277
  177. package/src/otel/anthropic.ts +0 -619
  178. package/src/otel/claude-hooks.ts +0 -1116
  179. package/src/otel/claude-wrapper.ts +0 -239
  180. package/src/otel/gemini.ts +0 -483
  181. package/src/otel/index.ts +0 -128
  182. package/src/otel/init.ts +0 -411
  183. package/src/otel/integrations/anthropic.ts +0 -36
  184. package/src/otel/integrations/base.ts +0 -158
  185. package/src/otel/integrations/claude-agent.ts +0 -36
  186. package/src/otel/integrations/gemini.ts +0 -30
  187. package/src/otel/integrations/index.ts +0 -152
  188. package/src/otel/integrations/langchain.ts +0 -60
  189. package/src/otel/integrations/mastra.ts +0 -48
  190. package/src/otel/integrations/openai-agents.ts +0 -47
  191. package/src/otel/integrations/pi.ts +0 -28
  192. package/src/otel/integrations/vercel.ts +0 -26
  193. package/src/otel/langchain-handler.ts +0 -804
  194. package/src/otel/logs.ts +0 -395
  195. package/src/otel/mastra-exporter.ts +0 -714
  196. package/src/otel/openai.ts +0 -93
  197. package/src/otel/pi.ts +0 -94
  198. package/src/otel/register.ts +0 -50
  199. package/src/otel/setup.ts +0 -215
  200. package/src/otel/span-processor.ts +0 -512
  201. package/src/otel/tracing-processor.ts +0 -637
  202. package/src/pagination.ts +0 -10
  203. package/src/proxy-from-env.d.ts +0 -7
  204. package/src/resources/experiments.ts +0 -176
  205. package/src/resources/recipes.ts +0 -74
  206. package/src/resources/runtimes.ts +0 -31
  207. package/src/runner.ts +0 -213
  208. package/src/types.ts +0 -13
  209. package/src/utils.ts +0 -95
  210. package/src/version.ts +0 -2
  211. package/tsconfig.json +0 -8
@@ -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,277 +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 {
53
- TranscriptAccumulator,
54
- foldAgui,
55
- foldSpans,
56
- mergeTranscripts,
57
- } from "@introspection-sdk/http";
58
- export { ArrowPages } from "@introspection-sdk/http";
59
- export type {
60
- EventArrowParams,
61
- FileUploadBody,
62
- ListReadParams,
63
- StartParams,
64
- StreamOptions,
65
- } from "@introspection-sdk/http";
66
- export { HttpClient } from "./http.js";
67
- export type { ResolvedApiConfig } from "./http.js";
68
- export { EventType } from "@introspection-sdk/types";
69
-
70
- // Runner + CP resources.
71
- export { Runner } from "./runner.js";
72
- export type { RunnerSource } from "./runner.js";
73
- export {
74
- RuntimesApi,
75
- RuntimeHandle,
76
- attachRuntimes,
77
- isUuid,
78
- } from "./resources/runtimes.js";
79
- export type { RuntimeHandleFactory } from "./resources/runtimes.js";
80
- export {
81
- ExperimentsApi,
82
- ExperimentHandle,
83
- attachExperiments,
84
- } from "./resources/experiments.js";
85
- export type { ExperimentHandleFactory } from "./resources/experiments.js";
86
- export { RecipesApi, attachRecipes } from "./resources/recipes.js";
87
-
88
- // REST API wire types
89
- export type {
90
- AGUIEvent,
91
- BaseEvent,
92
- Interrupt,
93
- Message,
94
- ResumeEntry,
95
- RunAgentInput,
96
- Paginated,
97
- ListParams,
98
- Task,
99
- TaskCreateParams,
100
- TaskUpdateParams,
101
- TaskListParams,
102
- TaskMode,
103
- TaskStatus,
104
- TaskRunKind,
105
- TaskPrompt,
106
- TaskRun,
107
- TaskRunCreateParams,
108
- TaskRunResumeParams,
109
- TaskRunResponse,
110
- TaskCreateResponse,
111
- TaskFileRef,
112
- TaskCancelResponse,
113
- TaskCancelOptions,
114
- AgentInfo,
115
- File,
116
- FileType,
117
- FileListParams,
118
- FileUpdateParams,
119
- FileCreateTextParams,
120
- Runtime,
121
- RuntimeListParams,
122
- Experiment,
123
- ExperimentCreate,
124
- ExperimentUpdate,
125
- ExperimentListParams,
126
- ExperimentStatus,
127
- ExperimentGoal,
128
- ExperimentGoalComponent,
129
- ExperimentGoalDirection,
130
- ExperimentGoalGuard,
131
- JudgeGoalComponent,
132
- TelemetryGoalComponent,
133
- ExperimentArm,
134
- Recipe,
135
- RecipeCreate,
136
- RecipeUpdate,
137
- RecipeListParams,
138
- RunnerSpec,
139
- RunnerDeployment,
140
- RunnerContext,
141
- RunnerRecipeSummary,
142
- RunnerIdentity,
143
- RunRequest,
144
- RunCaller,
145
- RunCallerLibrary,
146
- RunCallerPage,
147
- RunIdentityInput,
148
- GenAiSpan,
149
- GenAiSpanList,
150
- GenAiSpanAttributes,
151
- GenAiSpanStatus,
152
- Conversation,
153
- ConversationAgent,
154
- ConversationUsage,
155
- ConversationCost,
156
- ConversationMetrics,
157
- IntrospectionSpanAttributes,
158
- IntrospectionConversation,
159
- SpanAttributes,
160
- SpanResource,
161
- ConversationItemInclude,
162
- ConversationSortField,
163
- ConversationListParams,
164
- ConversationItemListParams,
165
- ConversationsMethod,
166
- SpanEvent,
167
- SpanKind,
168
- SpanStatus,
169
- ReadFormat,
170
- ReadWindowParams,
171
- IntrospectionEventName,
172
- IntrospectionEventEnvelope,
173
- ObservationPayload,
174
- PatternPayload,
175
- PatternAssignmentPayload,
176
- ClusteringRunPayload,
177
- FeedbackPayload,
178
- JudgementPayload,
179
- ObservationEvent,
180
- PatternEvent,
181
- PatternAssignmentEvent,
182
- ClusteringRunEvent,
183
- FeedbackEvent,
184
- JudgementEvent,
185
- Event,
186
- UnknownEvent,
187
- EventForName,
188
- EventSortField,
189
- EventListParams,
190
- MetricView,
191
- MetricAggregation,
192
- MetricFilterOperator,
193
- MetricInterval,
194
- MetricSpec,
195
- MetricDimension,
196
- MetricFilter,
197
- MetricTimeDimension,
198
- MetricOrderBy,
199
- MetricHaving,
200
- MetricQueryConfig,
201
- MetricQueryRequest,
202
- MetricDimensionValue,
203
- MetricResultValue,
204
- MetricResultRow,
205
- MetricEffectiveWindow,
206
- MetricQueryMeta,
207
- MetricQueryResponse,
208
- } from "@introspection-sdk/types";
209
- export {
210
- ConversationsMethods,
211
- IntrospectionEventNames,
212
- genAiConversationId,
213
- genAiInputMessages,
214
- genAiOutputMessages,
215
- isKnownEvent,
216
- } from "@introspection-sdk/types";
217
- export {
218
- IntrospectionAPIError,
219
- AuthenticationError,
220
- InsufficientScopeError,
221
- RunnerExpiredError,
222
- NotFoundError,
223
- ConflictError,
224
- ValidationError,
225
- RateLimitError,
226
- SandboxUnavailableError,
227
- StreamError,
228
- NetworkError,
229
- apiErrorFromResponse,
230
- } from "@introspection-sdk/types";
231
-
232
- // GenAI types (shared, no OTel SDK imports).
233
- export type {
234
- GenAiAttributes,
235
- InputMessage,
236
- OutputMessage,
237
- SystemInstruction,
238
- ToolDefinition,
239
- TextPart,
240
- ToolCallRequestPart,
241
- ToolCallResponsePart,
242
- CompactionPart,
243
- MediaUrlPart,
244
- BinaryDataPart,
245
- MessagePart,
246
- } from "@introspection-sdk/types";
247
- export { toAttributes } from "@introspection-sdk/types";
248
-
249
- // OpenAI converter exports (pure functions, no OTel SDK imports).
250
- export {
251
- convertResponsesInputsToSemconv,
252
- convertResponsesOutputsToSemconv,
253
- convertResponsesToolsToSemconv,
254
- convertResponsesInstructionsToSemconv,
255
- } from "./converters/openai.js";
256
- export type {
257
- ResponseInputItem,
258
- ResponseOutputItem,
259
- ResponseTool,
260
- ResponseUsage,
261
- Response as OpenAIResponse,
262
- } from "./converters/openai.js";
263
-
264
- // Gemini converters (pure functions, no OTel SDK imports).
265
- export {
266
- convertGeminiContentsToInputMessages,
267
- convertGeminiCandidatesToOutputMessages,
268
- convertGeminiSystemInstructionToSemconv,
269
- convertGeminiToolsToToolDefinitions,
270
- } from "./converters/gemini.js";
271
- export type {
272
- GeminiCandidate,
273
- GeminiContent,
274
- GeminiFunctionDeclaration,
275
- GeminiPart,
276
- GeminiTool,
277
- } from "./converters/gemini.js";