@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
package/src/client.ts CHANGED
@@ -1,515 +1,118 @@
1
1
  /**
2
- * Introspection Client for Node.js
3
- * Provides an API for tracking events and feedback using OTLP Logs.
2
+ * Introspection REST Client for Node.js
4
3
  *
5
- * Identity and gen_ai context are automatically extracted from OpenTelemetry
6
- * baggage.
4
+ * Exposes the Control Plane REST surface for managing runtimes and
5
+ * experiments. Calling `client.runtimes(name).run()` or
6
+ * `client.experiments(id).run()` returns a {@link Runner} bound to a Data
7
+ * Plane sandbox.
8
+ *
9
+ * This class is **REST-only** and does not depend on the OpenTelemetry
10
+ * SDK. For event tracking, feedback, identify, and baggage context
11
+ * helpers, use {@link IntrospectionLogs} from
12
+ * `@introspection-sdk/introspection-node/otel`.
7
13
  */
8
14
 
9
- import { SeverityNumber, type LogAttributes } from "@opentelemetry/api-logs";
10
- import {
11
- LoggerProvider,
12
- BatchLogRecordProcessor,
13
- } from "@opentelemetry/sdk-logs";
14
- import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto";
15
+ import type { AdvancedOptions } from "@introspection-sdk/types";
16
+ import { logger as sdkLogger } from "./utils.js";
17
+ import type { IntrospectionClientOptions } from "./types.js";
18
+ import { HttpClient } from "./http.js";
15
19
  import {
16
- resourceFromAttributes,
17
- defaultResource,
18
- } from "@opentelemetry/resources";
19
- import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
20
- import { propagation, context } from "@opentelemetry/api";
21
- import { logger as sdkLogger, withOtlpHttpsProxy } from "./utils.js";
22
- import { VERSION } from "./version.js";
20
+ attachRuntimes,
21
+ type RuntimeHandleFactory,
22
+ type RuntimesApi,
23
+ } from "./resources/runtimes.js";
23
24
  import {
24
- generateEventId,
25
- type IntrospectionClientOptions,
26
- type FeedbackOptions,
27
- type UserTraits,
28
- type GenAiContext,
29
- type IdentityContext,
30
- } from "./types.js";
25
+ attachExperiments,
26
+ type ExperimentHandleFactory,
27
+ type ExperimentsApi,
28
+ } from "./resources/experiments.js";
29
+ import { attachRecipes, type RecipesApi } from "./resources/recipes.js";
31
30
 
32
31
  /**
33
- * Introspection client for tracking events and feedback using OTLP Logs.
32
+ * Introspection REST client.
34
33
  *
35
34
  * @example
36
35
  * ```typescript
37
36
  * const client = new IntrospectionClient({
38
37
  * token: process.env.INTROSPECTION_TOKEN,
38
+ * projectId: "proj_…",
39
39
  * });
40
40
  *
41
- * client.identify("user_123", { email: "user@example.com" });
42
- * client.feedback("thumbs_up", { comments: "Great response!" });
41
+ * // Open a runner from a runtime, then drive it.
42
+ * const runner = await client.runtimes("customer-agent").run({
43
+ * identity: { user_id: "u_42" },
44
+ * });
45
+ * const run = await runner.tasks.create({ prompt: "Summarize this repo" });
46
+ * for await (const ev of run.stream()) console.log(ev);
43
47
  *
48
+ * await runner.close();
44
49
  * await client.shutdown();
45
50
  * ```
46
51
  */
47
52
  export class IntrospectionClient {
48
- private loggerProvider: LoggerProvider;
49
- private otelLogger: ReturnType<LoggerProvider["getLogger"]>;
50
- private userId: string | undefined;
51
- private anonymousId: string | undefined;
52
- private traits: Record<string, unknown> = {};
53
-
54
- constructor(options: IntrospectionClientOptions = {}) {
55
- const token = options.token || process.env.INTROSPECTION_TOKEN || "";
56
- const serviceName =
57
- options.serviceName ||
58
- process.env.INTROSPECTION_SERVICE_NAME ||
59
- "introspection-client";
60
- const advanced = options.advanced || {};
61
- const baseUrl =
62
- advanced.baseUrl ||
63
- process.env.INTROSPECTION_BASE_URL ||
64
- "https://otel.introspection.dev";
65
-
66
- if (!token) {
67
- sdkLogger.warn(
68
- "IntrospectionClient: No token provided. Events will not be sent.",
69
- );
70
- }
71
-
72
- // Construct endpoint URL for logs
73
- let endpoint: string;
74
- if (baseUrl.endsWith("/v1/logs")) {
75
- endpoint = baseUrl;
76
- } else {
77
- endpoint = `${baseUrl.replace(/\/$/, "")}/v1/logs`;
78
- }
79
-
80
- // Build headers
81
- const headers: Record<string, string> = {
82
- Authorization: `Bearer ${token}`,
83
- };
84
- if (advanced.additionalHeaders) {
85
- Object.assign(headers, advanced.additionalHeaders);
86
- }
87
-
88
- // Create OTLP log exporter
89
- const exporter = new OTLPLogExporter(
90
- withOtlpHttpsProxy({
91
- url: endpoint,
92
- headers,
93
- }),
94
- );
95
-
96
- // Create batch processor
97
- const processor = new BatchLogRecordProcessor(exporter, {
98
- maxQueueSize: advanced.maxBatchSize ?? 100,
99
- scheduledDelayMillis: advanced.flushInterval ?? 5000,
100
- });
101
-
102
- // Get default resource and merge with our service name
103
- const baseResource = defaultResource();
104
- const introspectionResource = resourceFromAttributes({
105
- [ATTR_SERVICE_NAME]: serviceName,
106
- });
107
- const resource = baseResource.merge(introspectionResource);
108
-
109
- // Create logger provider
110
- this.loggerProvider = new LoggerProvider({
111
- resource,
112
- processors: [processor],
113
- });
114
-
115
- this.otelLogger = this.loggerProvider.getLogger(
116
- "@introspection-sdk/introspection-node",
117
- VERSION,
118
- );
119
-
120
- sdkLogger.info(
121
- `IntrospectionClient initialized: service=${serviceName}, endpoint=${endpoint}`,
122
- );
123
- }
124
-
125
- /** Get gen_ai context from baggage */
126
- private getGenAiFromContext(): GenAiContext {
127
- const baggage = propagation.getBaggage(context.active());
128
- return {
129
- conversationId: baggage?.getEntry("gen_ai.conversation.id")?.value,
130
- previousResponseId: baggage?.getEntry(
131
- "gen_ai.request.previous_response_id",
132
- )?.value,
133
- agentName: baggage?.getEntry("gen_ai.agent.name")?.value,
134
- agentId: baggage?.getEntry("gen_ai.agent.id")?.value,
135
- };
136
- }
137
-
138
- /** Get identity from baggage or client instance */
139
- private getIdentityFromContext(): IdentityContext {
140
- const baggage = propagation.getBaggage(context.active());
141
- return {
142
- userId: baggage?.getEntry("identity.user_id")?.value || this.userId,
143
- anonymousId:
144
- baggage?.getEntry("identity.anonymous_id")?.value || this.anonymousId,
145
- };
146
- }
147
-
148
- /**
149
- * Get current timestamp as OpenTelemetry HrTime.
150
- * Uses process.hrtime.bigint() for nanosecond precision in Node.js.
151
- */
152
- private getTimestamp(): [number, number] {
153
- const hrTimeNs = process.hrtime.bigint();
154
- const epochNs = BigInt(Date.now()) * BigInt(1_000_000);
155
- const offsetNs = hrTimeNs - process.hrtime.bigint() + epochNs;
156
- const seconds = Number(offsetNs / BigInt(1_000_000_000));
157
- const nanos = Number(offsetNs % BigInt(1_000_000_000));
158
- return [seconds, nanos];
159
- }
53
+ /** @internal — HTTP client pointed at the CP API with the customer key. */
54
+ readonly cpHttp: HttpClient;
55
+ /** @internal — passed through to Runner so it can build its own DP HTTP client. */
56
+ readonly advancedOptions: AdvancedOptions;
57
+ readonly projectId: string | undefined;
160
58
 
161
59
  /**
162
- * Build log record attributes.
60
+ * CRUD on `/v1/runtimes` and the `(idOrName) => RuntimeHandle` factory.
61
+ * Call as `client.runtimes("customer-agent").run()` or
62
+ * `client.runtimes.list({ project_id })`.
163
63
  */
164
- private buildAttributes(
165
- eventName: string,
166
- options: {
167
- properties?: Record<string, unknown>;
168
- traits?: Record<string, unknown>;
169
- conversationId?: string;
170
- previousResponseId?: string;
171
- eventId?: string;
172
- } = {},
173
- ): LogAttributes {
174
- const { properties, traits, conversationId, previousResponseId, eventId } =
175
- options;
176
-
177
- // Core fields
178
- const attributes: LogAttributes = {
179
- "event.name": eventName,
180
- "event.id": eventId || generateEventId(),
181
- };
182
-
183
- // Identity
184
- const identity = this.getIdentityFromContext();
185
- if (identity.userId) {
186
- attributes["identity.user.id"] = identity.userId;
187
- }
188
- if (identity.anonymousId) {
189
- attributes["identity.anonymous.id"] = identity.anonymousId;
190
- }
191
-
192
- // Gen AI context (explicit params override baggage)
193
- const genAi = this.getGenAiFromContext();
194
- const finalConversationId = conversationId || genAi.conversationId;
195
- const finalPreviousResponseId =
196
- previousResponseId || genAi.previousResponseId;
197
-
198
- if (finalConversationId) {
199
- attributes["gen_ai.conversation.id"] = finalConversationId;
200
- }
201
- if (finalPreviousResponseId) {
202
- attributes["gen_ai.request.previous_response_id"] =
203
- finalPreviousResponseId;
204
- }
205
- if (genAi.agentName) {
206
- attributes["gen_ai.agent.name"] = genAi.agentName;
207
- }
208
- if (genAi.agentId) {
209
- attributes["gen_ai.agent.id"] = genAi.agentId;
210
- }
211
-
212
- // Flatten properties with "properties." prefix
213
- if (properties) {
214
- for (const [key, value] of Object.entries(properties)) {
215
- if (value != null) {
216
- const attrKey = `properties.${key}`;
217
- if (typeof value === "object") {
218
- attributes[attrKey] = JSON.stringify(value);
219
- } else if (
220
- typeof value === "string" ||
221
- typeof value === "number" ||
222
- typeof value === "boolean"
223
- ) {
224
- attributes[attrKey] = value;
225
- }
226
- }
227
- }
228
- }
229
-
230
- // Flatten traits with "context.traits." prefix
231
- if (traits) {
232
- for (const [key, value] of Object.entries(traits)) {
233
- if (value != null) {
234
- const attrKey = `context.traits.${key}`;
235
- if (typeof value === "object") {
236
- attributes[attrKey] = JSON.stringify(value);
237
- } else if (
238
- typeof value === "string" ||
239
- typeof value === "number" ||
240
- typeof value === "boolean"
241
- ) {
242
- attributes[attrKey] = value;
243
- }
244
- }
245
- }
246
- }
247
-
248
- return attributes;
249
- }
64
+ readonly runtimes: RuntimesApi & RuntimeHandleFactory;
250
65
 
251
66
  /**
252
- * Track a custom event.
253
- *
254
- * @param eventName - A descriptive name for the event (e.g. `"page_view"`).
255
- * @param properties - Arbitrary key/value pairs attached to the event.
256
- * @param options - Optional overrides such as a custom `eventId`.
67
+ * CRUD on `/v1/experiments` and the `(id) => ExperimentHandle` factory.
257
68
  */
258
- track(
259
- eventName: string,
260
- properties?: Record<string, unknown>,
261
- options?: { eventId?: string },
262
- ): void {
263
- const attributes = this.buildAttributes(eventName, {
264
- properties,
265
- eventId: options?.eventId,
266
- });
267
-
268
- this.otelLogger.emit({
269
- timestamp: this.getTimestamp(),
270
- context: context.active(),
271
- severityNumber: SeverityNumber.INFO,
272
- severityText: "INFO",
273
- attributes,
274
- });
275
-
276
- sdkLogger.debug(`Tracked: ${eventName}`);
277
- }
69
+ readonly experiments: ExperimentsApi & ExperimentHandleFactory;
278
70
 
279
71
  /**
280
- * Track feedback on a message or response.
281
- *
282
- * @param name - Feedback type (e.g. `"thumbs_up"`, `"thumbs_down"`).
283
- * @param options - Additional feedback context such as comments or conversation ID.
72
+ * CRUD on `/v1/recipes`. Recipes are immutable build artefacts
73
+ * (repository + git ref + commit sha) referenced by runtimes and
74
+ * experiment arms.
284
75
  */
285
- feedback(name: string, options: FeedbackOptions = {}): void {
286
- const { comments, conversationId, previousResponseId, eventId, ...extra } =
287
- options;
76
+ readonly recipes: RecipesApi;
288
77
 
289
- const properties: Record<string, unknown> = { name, ...extra };
290
- if (comments) {
291
- properties.comments = comments;
292
- }
293
-
294
- const attributes = this.buildAttributes("introspection.feedback", {
295
- properties,
296
- conversationId: conversationId as string | undefined,
297
- previousResponseId: previousResponseId as string | undefined,
298
- eventId: eventId as string | undefined,
299
- });
300
-
301
- this.otelLogger.emit({
302
- timestamp: this.getTimestamp(),
303
- context: context.active(),
304
- severityNumber: SeverityNumber.INFO,
305
- severityText: "INFO",
306
- attributes,
307
- });
308
-
309
- sdkLogger.debug(`Feedback: ${name}`);
310
- }
78
+ constructor(options: IntrospectionClientOptions = {}) {
79
+ const token = options.token || process.env.INTROSPECTION_TOKEN || "";
80
+ const advanced = options.advanced || {};
81
+ this.advancedOptions = advanced;
82
+ this.projectId =
83
+ options.projectId || process.env.INTROSPECTION_PROJECT_ID || undefined;
84
+ const baseApiUrl =
85
+ advanced.baseApiUrl ||
86
+ process.env.INTROSPECTION_BASE_API_URL ||
87
+ "https://api.introspection.dev";
311
88
 
312
- /**
313
- * Identify a user and associate traits with them.
314
- *
315
- * @param userId - Unique identifier for the user.
316
- * @param traits - Key/value user properties (e.g. `{ email: "…" }`).
317
- * @param anonymousId - Optional anonymous identifier to link pre-auth sessions.
318
- * @param eventId - Optional custom event ID override.
319
- */
320
- identify(
321
- userId: string,
322
- traits?: UserTraits,
323
- anonymousId?: string,
324
- eventId?: string,
325
- ): void {
326
- this.userId = userId;
327
- if (anonymousId) {
328
- this.anonymousId = anonymousId;
329
- }
330
- if (traits) {
331
- this.traits = { ...this.traits, ...traits };
89
+ if (!token) {
90
+ sdkLogger.warn(
91
+ "IntrospectionClient: No token provided. REST calls will fail.",
92
+ );
332
93
  }
333
94
 
334
- const attributes = this.buildAttributes("identify", { traits, eventId });
335
-
336
- this.otelLogger.emit({
337
- timestamp: this.getTimestamp(),
338
- context: context.active(),
339
- severityNumber: SeverityNumber.INFO,
340
- severityText: "INFO",
341
- attributes,
95
+ // CP HTTP client — talks to the customer-facing API with the customer
96
+ // API key. Runners get their own HttpClient instances pointed at the
97
+ // `deployment.endpoint` returned by `/v1/runtimes/{id}/run`.
98
+ this.cpHttp = new HttpClient({
99
+ apiUrl: baseApiUrl,
100
+ token,
101
+ additionalHeaders: advanced.additionalHeaders,
102
+ fetch: advanced.fetch,
342
103
  });
343
104
 
344
- sdkLogger.debug(`Identified: ${userId}`);
345
- }
346
-
347
- /**
348
- * Create an OTel context with the given baggage values set.
349
- *
350
- * @param values - Key/value pairs to store in OTel baggage.
351
- * @returns A new context containing the baggage entries.
352
- */
353
- createBaggageContext(values: Record<string, string>) {
354
- const ctx = context.active();
355
- let bag = propagation.getBaggage(ctx) || propagation.createBaggage();
356
-
357
- for (const [key, value] of Object.entries(values)) {
358
- bag = bag.setEntry(key, { value });
359
- }
105
+ this.runtimes = attachRuntimes(this, this.cpHttp);
106
+ this.experiments = attachExperiments(this, this.cpHttp);
107
+ this.recipes = attachRecipes(this.cpHttp);
360
108
 
361
- return propagation.setBaggage(ctx, bag);
362
- }
363
-
364
- /**
365
- * Set multiple baggage values and run a callback within that context.
366
- *
367
- * @param values - Key/value pairs to store in OTel baggage.
368
- * @param callback - Function to execute with the baggage context active.
369
- * @returns The value returned by `callback`.
370
- */
371
- async withBaggage<T>(
372
- values: Record<string, string>,
373
- callback: () => T | Promise<T>,
374
- ): Promise<T> {
375
- const ctx = this.createBaggageContext(values);
376
- return await context.with(ctx, callback);
377
- }
378
-
379
- /**
380
- * Set `gen_ai.agent.name` (and optionally `gen_ai.agent.id`) baggage and run
381
- * a callback within that context.
382
- *
383
- * @param agentName - The agent name to propagate.
384
- * @param agentId - Optional agent identifier.
385
- * @param callback - Function to execute with the agent baggage active.
386
- * @returns The value returned by `callback`.
387
- */
388
- async withAgent<T>(
389
- agentName: string,
390
- agentId: string | undefined,
391
- callback: () => T | Promise<T>,
392
- ): Promise<T> {
393
- const values: Record<string, string> = { "gen_ai.agent.name": agentName };
394
- if (agentId) {
395
- values["gen_ai.agent.id"] = agentId;
396
- }
397
- return await context.with(this.createBaggageContext(values), callback);
398
- }
399
-
400
- /**
401
- * Set conversation-related baggage (`gen_ai.conversation.id`,
402
- * `gen_ai.request.previous_response_id`) and run a callback within that
403
- * context.
404
- *
405
- * @param conversationId - The conversation identifier.
406
- * @param previousResponseId - The ID of the previous response in the conversation.
407
- * @param callback - Function to execute with the conversation baggage active.
408
- * @returns The value returned by `callback`.
409
- */
410
- async withConversation<T>(
411
- conversationId: string | undefined,
412
- previousResponseId: string | undefined,
413
- callback: () => T | Promise<T>,
414
- ): Promise<T> {
415
- const values: Record<string, string> = {};
416
- if (conversationId) {
417
- values["gen_ai.conversation.id"] = conversationId;
418
- }
419
- if (previousResponseId) {
420
- values["gen_ai.request.previous_response_id"] = previousResponseId;
421
- }
422
- return await context.with(this.createBaggageContext(values), callback);
109
+ sdkLogger.info(`IntrospectionClient initialized: api=${baseApiUrl}`);
423
110
  }
424
111
 
425
- /**
426
- * Set the user ID on this client instance.
427
- *
428
- * @param userId - Unique identifier for the user.
429
- */
430
- setUserId(userId: string): void {
431
- this.userId = userId;
432
- }
433
-
434
- /**
435
- * Set the anonymous ID on this client instance.
436
- *
437
- * @param anonymousId - Anonymous identifier used before authentication.
438
- */
439
- setAnonymousId(anonymousId: string): void {
440
- this.anonymousId = anonymousId;
441
- }
442
-
443
- /**
444
- * Set `identity.user_id` baggage and run a callback within that context.
445
- *
446
- * @param userId - The user identifier to propagate.
447
- * @param callback - Function to execute with the user-ID baggage active.
448
- * @returns The value returned by `callback`.
449
- */
450
- async withUserId<T>(
451
- userId: string,
452
- callback: () => T | Promise<T>,
453
- ): Promise<T> {
454
- return await context.with(
455
- this.createBaggageContext({ "identity.user_id": userId }),
456
- callback,
457
- );
458
- }
459
-
460
- /**
461
- * Set `identity.anonymous_id` baggage and run a callback within that context.
462
- *
463
- * @param anonymousId - The anonymous identifier to propagate.
464
- * @param callback - Function to execute with the anonymous-ID baggage active.
465
- * @returns The value returned by `callback`.
466
- */
467
- async withAnonymousId<T>(
468
- anonymousId: string,
469
- callback: () => T | Promise<T>,
470
- ): Promise<T> {
471
- return await context.with(
472
- this.createBaggageContext({ "identity.anonymous_id": anonymousId }),
473
- callback,
474
- );
475
- }
476
-
477
- /**
478
- * Get the current anonymous ID stored on this client instance.
479
- *
480
- * @returns The anonymous ID, or `undefined` if not set.
481
- */
482
- getAnonymousId(): string | undefined {
483
- return this.anonymousId;
484
- }
485
-
486
- /**
487
- * Reset all client-side state (user ID, anonymous ID, and traits).
488
- */
489
- reset(): void {
490
- this.userId = undefined;
491
- this.anonymousId = undefined;
492
- this.traits = {};
493
- sdkLogger.debug("Client state reset");
494
- }
495
-
496
- /**
497
- * Flush all queued log records to the backend.
498
- *
499
- * @returns A promise that resolves once the flush completes.
500
- */
501
- async flush(): Promise<void> {
502
- await this.loggerProvider.forceFlush();
503
- sdkLogger.debug("Flushed pending log records");
504
- }
505
-
506
- /**
507
- * Shut down the client, flushing all pending log records.
508
- *
509
- * @returns A promise that resolves once shutdown is complete.
510
- */
112
+ /** Close the underlying HTTP client. */
511
113
  async shutdown(): Promise<void> {
512
- await this.loggerProvider.shutdown();
114
+ // HttpClient has no persistent connections to close, but reserved
115
+ // for future use (e.g. agent keep-alive pools).
513
116
  sdkLogger.debug("IntrospectionClient shutdown complete");
514
117
  }
515
118
  }
@@ -228,6 +228,10 @@ export interface ClaudeSessionData {
228
228
  toolNames?: string[];
229
229
  /** System instructions / system prompt */
230
230
  systemInstructions?: string;
231
+ /** Tokens read from the LLM prompt cache */
232
+ cacheReadInputTokens?: number;
233
+ /** Tokens written to the LLM prompt cache */
234
+ cacheCreationInputTokens?: number;
231
235
  }
232
236
 
233
237
  /**
@@ -280,6 +284,12 @@ export function convertClaudeSessionToGenAI(
280
284
  if (data.outputTokens !== undefined) {
281
285
  result.outputTokens = data.outputTokens;
282
286
  }
287
+ if (data.cacheReadInputTokens !== undefined) {
288
+ result.cacheReadInputTokens = data.cacheReadInputTokens;
289
+ }
290
+ if (data.cacheCreationInputTokens !== undefined) {
291
+ result.cacheCreationInputTokens = data.cacheCreationInputTokens;
292
+ }
283
293
 
284
294
  // Set response ID
285
295
  if (data.responseId) {