@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/dist/index.d.ts CHANGED
@@ -1,38 +1,35 @@
1
- import { IntrospectionSpanProcessor } from "./span-processor.js";
2
- import type { IntrospectionSpanProcessorOptions } from "./span-processor.js";
3
1
  /**
4
- * Factory that creates an {@link IntrospectionSpanProcessor}.
2
+ * Root entry point — REST-only surface.
5
3
  *
6
- * Provided as the default export for convenient use with logfire's
7
- * `additionalSpanProcessors` option.
4
+ * Exports `IntrospectionClient` (REST), Runner / RuntimeHandle /
5
+ * ExperimentHandle, REST wire types, and HTTP helpers. None of these
6
+ * touch the OpenTelemetry SDK.
8
7
  *
9
- * @param options - Optional processor configuration (token, serviceName, etc.).
10
- * @returns A ready-to-use {@link IntrospectionSpanProcessor}.
11
- *
12
- * @example
13
- * ```ts
14
- * import introspectionSpanProcessor from "@introspection-sdk/introspection-node";
15
- *
16
- * logfire.configure({ additionalSpanProcessors: [introspectionSpanProcessor()] });
17
- * ```
8
+ * For the OTel surface (logs, span processors, instrumentors) import
9
+ * from `@introspection-sdk/introspection-node/otel`.
18
10
  */
19
- export default function introspectionSpanProcessor(options?: IntrospectionSpanProcessorOptions): IntrospectionSpanProcessor;
20
- export { IntrospectionSpanProcessor } from "./span-processor.js";
21
- export type { IntrospectionSpanProcessorOptions } from "./span-processor.js";
22
11
  export { IntrospectionClient } from "./client.js";
23
12
  export type { AdvancedOptions, IntrospectionClientOptions, FeedbackOptions, UserTraits, } from "./types.js";
24
- export { IntrospectionTracingProcessor } from "./tracing-processor.js";
25
- export type { IntrospectionTracingProcessorOptions, TracingProcessorAdvancedOptions, } from "./tracing-processor.js";
26
- export { IntrospectionClaudeHooks } from "./claude-hooks.js";
27
- export type { IntrospectionClaudeHooksOptions, ClaudeHooksAdvancedOptions, ClaudeHooksConfig, ClaudeHookCallbackMatcher, ClaudeHookEvent, ClaudeHookInput, ClaudeHookOutput, ClaudeHookCallback, ClaudeUsage, ClaudeModelUsage, ClaudeResultMessage, ClaudeAssistantMessage, ClaudeSDKMessage, } from "./claude-hooks.js";
28
- export { withIntrospection } from "./claude-wrapper.js";
29
- export type { WithIntrospectionOptions, InstrumentedClaudeAgentSDK, ClaudeAgentSDKModule, } from "./claude-wrapper.js";
13
+ export { TasksApi, TaskRunsApi, RunHandle } from "./runner-resources/tasks.js";
14
+ export type { StartParams } from "./runner-resources/tasks.js";
15
+ export { FilesApi, FileVersionsApi } from "./runner-resources/files.js";
16
+ export type { FileUploadBody } from "./runner-resources/files.js";
17
+ export { HttpClient } from "./http.js";
18
+ export type { ResolvedApiConfig } from "./http.js";
19
+ export { parseSse } from "./streaming.js";
20
+ export { Runner } from "./runner.js";
21
+ export type { RunnerSource } from "./runner.js";
22
+ export { RuntimesApi, RuntimeHandle, attachRuntimes, isUuid, } from "./resources/runtimes.js";
23
+ export type { RuntimeHandleFactory } from "./resources/runtimes.js";
24
+ export { ExperimentsApi, ExperimentHandle, attachExperiments, } from "./resources/experiments.js";
25
+ export type { ExperimentHandleFactory } from "./resources/experiments.js";
26
+ export { RecipesApi, attachRecipes } from "./resources/recipes.js";
27
+ export type { Paginated, ListParams, Task, TaskCreateParams, TaskUpdateParams, TaskListParams, TaskMode, TaskStatus, TaskPrompt, TaskRun, TaskRunCreateParams, TaskRunResponse, TaskCreateResponse, TaskCancelResponse, AgentInfo, File, FileType, FileListParams, FileUpdateParams, FileCreateTextParams, SseEvent, Runtime, RuntimeCreate, RuntimeUpdate, RuntimeListParams, Experiment, ExperimentCreate, ExperimentUpdate, ExperimentListParams, ExperimentStatus, ExperimentEndParams, Arm, Recipe, RecipeCreate, RecipeUpdate, RecipeListParams, RunnerSpec, RunnerDeployment, RunnerContext, RunnerRecipeSummary, RunnerIdentity, RunRequest, RunCaller, RunCallerLibrary, RunCallerPage, RunIdentityInput, } from "@introspection-sdk/types";
28
+ export { IntrospectionAPIError, AuthenticationError, InsufficientScopeError, RunnerExpiredError, NotFoundError, ConflictError, ValidationError, RateLimitError, SandboxUnavailableError, StreamError, NetworkError, apiErrorFromResponse, } from "@introspection-sdk/types";
30
29
  export type { GenAiAttributes, InputMessage, OutputMessage, SystemInstruction, ToolDefinition, TextPart, ToolCallRequestPart, ToolCallResponsePart, MessagePart, } from "@introspection-sdk/types";
31
30
  export { toAttributes } from "@introspection-sdk/types";
32
31
  export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, } from "./converters/openai.js";
33
32
  export type { ResponseInputItem, ResponseOutputItem, ResponseTool, ResponseUsage, Response as OpenAIResponse, } from "./converters/openai.js";
34
- export { IntrospectionAISDKIntegration } from "./ai-sdk-integration.js";
35
- export type { IntrospectionAISDKIntegrationOptions, AISDKIntegrationAdvancedOptions, } from "./ai-sdk-integration.js";
36
- export { addOpenInferenceAttributes, OpenInferenceSpanExporter, } from "./converters/openinference.js";
37
- export { AnthropicInstrumentor, tracedMessagesCreate, REDACTED_THINKING_CONTENT, } from "./anthropic.js";
33
+ export { convertGeminiContentsToInputMessages, convertGeminiCandidatesToOutputMessages, convertGeminiSystemInstructionToSemconv, convertGeminiToolsToToolDefinitions, } from "./converters/gemini.js";
34
+ export type { GeminiCandidate, GeminiContent, GeminiFunctionDeclaration, GeminiPart, GeminiTool, } from "./converters/gemini.js";
38
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAE7E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CAChD,OAAO,CAAC,EAAE,iCAAiC,GAC1C,0BAA0B,CAE5B;AAGD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EAAE,iCAAiC,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,YAAY,EACV,eAAe,EACf,0BAA0B,EAC1B,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,YAAY,EACV,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,YAAY,EACV,+BAA+B,EAC/B,0BAA0B,EAC1B,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAG7B,YAAY,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,QAAQ,IAAI,cAAc,GAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AACxE,YAAY,EACV,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
package/dist/index.js CHANGED
@@ -1,39 +1,29 @@
1
- import { IntrospectionSpanProcessor } from "./span-processor.js";
2
1
  /**
3
- * Factory that creates an {@link IntrospectionSpanProcessor}.
2
+ * Root entry point — REST-only surface.
4
3
  *
5
- * Provided as the default export for convenient use with logfire's
6
- * `additionalSpanProcessors` option.
4
+ * Exports `IntrospectionClient` (REST), Runner / RuntimeHandle /
5
+ * ExperimentHandle, REST wire types, and HTTP helpers. None of these
6
+ * touch the OpenTelemetry SDK.
7
7
  *
8
- * @param options - Optional processor configuration (token, serviceName, etc.).
9
- * @returns A ready-to-use {@link IntrospectionSpanProcessor}.
10
- *
11
- * @example
12
- * ```ts
13
- * import introspectionSpanProcessor from "@introspection-sdk/introspection-node";
14
- *
15
- * logfire.configure({ additionalSpanProcessors: [introspectionSpanProcessor()] });
16
- * ```
8
+ * For the OTel surface (logs, span processors, instrumentors) import
9
+ * from `@introspection-sdk/introspection-node/otel`.
17
10
  */
18
- export default function introspectionSpanProcessor(options) {
19
- return new IntrospectionSpanProcessor(options);
20
- }
21
- // Span processor exports (for OpenTelemetry integration)
22
- export { IntrospectionSpanProcessor } from "./span-processor.js";
23
- // Client exports
11
+ // REST client.
24
12
  export { IntrospectionClient } from "./client.js";
25
- // Tracing processor exports (for OpenAI Agents SDK integration)
26
- export { IntrospectionTracingProcessor } from "./tracing-processor.js";
27
- // Claude Agent SDK hooks exports
28
- export { IntrospectionClaudeHooks } from "./claude-hooks.js";
29
- // Claude Agent SDK wrapper exports
30
- export { withIntrospection } from "./claude-wrapper.js";
13
+ // Runner-bound REST namespaces (runner.tasks, runner.files) + HTTP/SSE.
14
+ export { TasksApi, TaskRunsApi, RunHandle } from "./runner-resources/tasks.js";
15
+ export { FilesApi, FileVersionsApi } from "./runner-resources/files.js";
16
+ export { HttpClient } from "./http.js";
17
+ export { parseSse } from "./streaming.js";
18
+ // Runner + CP resources.
19
+ export { Runner } from "./runner.js";
20
+ export { RuntimesApi, RuntimeHandle, attachRuntimes, isUuid, } from "./resources/runtimes.js";
21
+ export { ExperimentsApi, ExperimentHandle, attachExperiments, } from "./resources/experiments.js";
22
+ export { RecipesApi, attachRecipes } from "./resources/recipes.js";
23
+ export { IntrospectionAPIError, AuthenticationError, InsufficientScopeError, RunnerExpiredError, NotFoundError, ConflictError, ValidationError, RateLimitError, SandboxUnavailableError, StreamError, NetworkError, apiErrorFromResponse, } from "@introspection-sdk/types";
31
24
  export { toAttributes } from "@introspection-sdk/types";
32
- // OpenAI converter exports
25
+ // OpenAI converter exports (pure functions, no OTel SDK imports).
33
26
  export { convertResponsesInputsToSemconv, convertResponsesOutputsToSemconv, convertResponsesToolsToSemconv, convertResponsesInstructionsToSemconv, } from "./converters/openai.js";
34
- // AI SDK integration exports (for Vercel AI SDK)
35
- export { IntrospectionAISDKIntegration } from "./ai-sdk-integration.js";
36
- // OpenInference converter exports
37
- export { addOpenInferenceAttributes, OpenInferenceSpanExporter, } from "./converters/openinference.js";
38
- // Anthropic instrumentor exports
39
- export { AnthropicInstrumentor, tracedMessagesCreate, REDACTED_THINKING_CONTENT, } from "./anthropic.js";
27
+ // Gemini converters (pure functions, no OTel SDK imports).
28
+ export { convertGeminiContentsToInputMessages, convertGeminiCandidatesToOutputMessages, convertGeminiSystemInstructionToSemconv, convertGeminiToolsToToolDefinitions, } from "./converters/gemini.js";
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAe;AACf,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUlD,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,yBAAyB;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,WAAW,EACX,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAmDnE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,YAAY,EACZ,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAclC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,kEAAkE;AAClE,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,8BAA8B,EAC9B,qCAAqC,GACtC,MAAM,wBAAwB,CAAC;AAShC,2DAA2D;AAC3D,OAAO,EACL,oCAAoC,EACpC,uCAAuC,EACvC,uCAAuC,EACvC,mCAAmC,GACpC,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Lightweight Anthropic instrumentor for Introspection SDK.
3
+ *
4
+ * Captures the full Anthropic response including thinking blocks (extended
5
+ * thinking) with signatures, which third-party instrumentors drop.
6
+ *
7
+ * Supports both non-streaming (`messages.create`) and streaming
8
+ * (`messages.create({ stream: true })`) calls.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { AnthropicInstrumentor } from "@introspection-sdk/introspection-node";
13
+ *
14
+ * const instrumentor = new AnthropicInstrumentor();
15
+ * instrumentor.instrument({ tracerProvider: provider });
16
+ * // All client.messages.create calls are now traced
17
+ * ```
18
+ */
19
+ import type { Tracer } from "@opentelemetry/api";
20
+ import type { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
21
+ /** Sentinel value for redacted thinking blocks — content was encrypted by safety systems. */
22
+ export declare const REDACTED_THINKING_CONTENT = "[redacted]";
23
+ /**
24
+ * Traced wrapper around `client.messages.create(kwargs)`.
25
+ * Creates a gen_ai span with full Anthropic response including thinking blocks.
26
+ */
27
+ export declare function tracedMessagesCreate(tracer: Tracer, client: {
28
+ messages: {
29
+ create: (...args: unknown[]) => Promise<unknown>;
30
+ };
31
+ }, kwargs: Record<string, unknown>, conversationId?: string): Promise<unknown>;
32
+ /**
33
+ * Auto-instrumentor that patches `Anthropic.messages.create` to add tracing.
34
+ *
35
+ * Captures all content blocks including thinking (extended thinking) with
36
+ * signatures. Supports both non-streaming and streaming calls.
37
+ */
38
+ /**
39
+ * Auto-instrumentor that wraps an Anthropic client instance to add tracing.
40
+ *
41
+ * Captures all content blocks including thinking (extended thinking) with
42
+ * signatures. Supports both non-streaming and streaming calls.
43
+ */
44
+ export declare class AnthropicInstrumentor {
45
+ private tracer;
46
+ private patchedClients;
47
+ private conversationId;
48
+ instrument(opts: {
49
+ tracerProvider?: BasicTracerProvider;
50
+ /** The Anthropic client instance to instrument. */
51
+ client: any;
52
+ /**
53
+ * Conversation ID shared across all spans produced by this instrumentor.
54
+ * Enables the Introspection processor to reliably link multi-turn API calls
55
+ * into a single conversation without relying on history-hash matching.
56
+ * Defaults to a random UUID generated at instrument() time.
57
+ */
58
+ conversationId?: string;
59
+ }): void;
60
+ uninstrument(): void;
61
+ }
62
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/otel/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgBH,OAAO,KAAK,EAAE,MAAM,EAAQ,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAMzE,6FAA6F;AAC7F,eAAO,MAAM,yBAAyB,eAAe,CAAC;AAiWtD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE;IAAE,QAAQ,EAAE;QAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;KAAE,CAAA;CAAE,EAC1E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAuBlB;AAED;;;;;GAKG;AACH;;;;;GAKG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAuB;IAErC,OAAO,CAAC,cAAc,CAAmD;IACzE,OAAO,CAAC,cAAc,CAAqB;IAE3C,UAAU,CAAC,IAAI,EAAE;QACf,cAAc,CAAC,EAAE,mBAAmB,CAAC;QACrC,mDAAmD;QAEnD,MAAM,EAAE,GAAG,CAAC;QACZ;;;;;WAKG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,IAAI;IAsFR,YAAY,IAAI,IAAI;CAOrB"}
@@ -0,0 +1,425 @@
1
+ /**
2
+ * Lightweight Anthropic instrumentor for Introspection SDK.
3
+ *
4
+ * Captures the full Anthropic response including thinking blocks (extended
5
+ * thinking) with signatures, which third-party instrumentors drop.
6
+ *
7
+ * Supports both non-streaming (`messages.create`) and streaming
8
+ * (`messages.create({ stream: true })`) calls.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { AnthropicInstrumentor } from "@introspection-sdk/introspection-node";
13
+ *
14
+ * const instrumentor = new AnthropicInstrumentor();
15
+ * instrumentor.instrument({ tracerProvider: provider });
16
+ * // All client.messages.create calls are now traced
17
+ * ```
18
+ */
19
+ import { trace, context as otelContext, propagation, SpanKind, SpanStatusCode, } from "@opentelemetry/api";
20
+ // ---------------------------------------------------------------------------
21
+ // Converters
22
+ // ---------------------------------------------------------------------------
23
+ /** Sentinel value for redacted thinking blocks — content was encrypted by safety systems. */
24
+ export const REDACTED_THINKING_CONTENT = "[redacted]";
25
+ function blockToParts(block) {
26
+ const bt = block.type || "";
27
+ if (bt === "text") {
28
+ return [{ type: "text", content: block.text || "" }];
29
+ }
30
+ if (bt === "thinking") {
31
+ const part = {
32
+ type: "thinking",
33
+ content: block.thinking || undefined,
34
+ signature: block.signature || undefined,
35
+ provider_name: "anthropic",
36
+ };
37
+ return [part];
38
+ }
39
+ if (bt === "redacted_thinking") {
40
+ return [
41
+ {
42
+ type: "thinking",
43
+ content: REDACTED_THINKING_CONTENT,
44
+ signature: block.data || undefined,
45
+ provider_name: "anthropic",
46
+ },
47
+ ];
48
+ }
49
+ if (bt === "tool_use") {
50
+ return [
51
+ {
52
+ type: "tool_call",
53
+ id: block.id || "",
54
+ name: block.name || "",
55
+ arguments: block.input,
56
+ },
57
+ ];
58
+ }
59
+ if (bt === "tool_result") {
60
+ return [
61
+ {
62
+ type: "tool_call_response",
63
+ id: block.tool_use_id || "",
64
+ response: block.content != null ? String(block.content) : "",
65
+ },
66
+ ];
67
+ }
68
+ return [];
69
+ }
70
+ function convertAnthropicInput(messages) {
71
+ const result = [];
72
+ for (const msg of messages) {
73
+ const role = msg.role || "user";
74
+ const content = msg.content;
75
+ if (typeof content === "string") {
76
+ result.push({
77
+ role: role,
78
+ parts: [{ type: "text", content }],
79
+ });
80
+ }
81
+ else if (Array.isArray(content)) {
82
+ const parts = [];
83
+ for (const block of content) {
84
+ const rec = typeof block === "object" && block !== null
85
+ ? block
86
+ : { type: "text", text: String(block) };
87
+ parts.push(...blockToParts(rec));
88
+ }
89
+ if (parts.length > 0) {
90
+ result.push({ role: role, parts });
91
+ }
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ function convertAnthropicOutput(content) {
97
+ const parts = [];
98
+ let hasToolCalls = false;
99
+ for (const block of content) {
100
+ const newParts = blockToParts(block);
101
+ for (const p of newParts) {
102
+ if (p.type === "tool_call")
103
+ hasToolCalls = true;
104
+ }
105
+ parts.push(...newParts);
106
+ }
107
+ if (parts.length === 0)
108
+ return [];
109
+ return [
110
+ {
111
+ role: "assistant",
112
+ parts,
113
+ finish_reason: hasToolCalls ? "tool-calls" : "stop",
114
+ },
115
+ ];
116
+ }
117
+ // ---------------------------------------------------------------------------
118
+ // Span helpers
119
+ // ---------------------------------------------------------------------------
120
+ function serializeMessages(msgs) {
121
+ return JSON.stringify(msgs.map((m) => {
122
+ const obj = { role: m.role, parts: m.parts };
123
+ if ("finish_reason" in m && m.finish_reason) {
124
+ obj.finish_reason = m.finish_reason;
125
+ }
126
+ return obj;
127
+ }));
128
+ }
129
+ function startSpan(tracer, model, conversationId) {
130
+ const span = tracer.startSpan("chat", {
131
+ kind: SpanKind.CLIENT,
132
+ attributes: {
133
+ "gen_ai.system": "anthropic",
134
+ "gen_ai.provider.name": "anthropic",
135
+ "gen_ai.operation.name": "chat",
136
+ "gen_ai.request.model": model,
137
+ "openinference.span.kind": "LLM",
138
+ ...(conversationId
139
+ ? { "gen_ai.conversation.id": conversationId }
140
+ : undefined),
141
+ },
142
+ });
143
+ return { span, token: null };
144
+ }
145
+ function setRequestAttrs(span, kwargs) {
146
+ const messages = kwargs.messages || [];
147
+ const inputMsgs = convertAnthropicInput(messages);
148
+ if (inputMsgs.length > 0) {
149
+ span.setAttribute("gen_ai.input.messages", serializeMessages(inputMsgs));
150
+ }
151
+ const system = kwargs.system;
152
+ if (system) {
153
+ let sysVal;
154
+ if (typeof system === "string") {
155
+ sysVal = JSON.stringify([{ type: "text", content: system }]);
156
+ }
157
+ else if (Array.isArray(system)) {
158
+ // Anthropic block format: [{type:"text", text:"...", cache_control:{...}}]
159
+ // Normalize to gen_ai format: [{type:"text", content:"..."}]
160
+ sysVal = JSON.stringify(system.map((block) => ({
161
+ type: "text",
162
+ content: typeof block.text === "string"
163
+ ? block.text
164
+ : typeof block.content === "string"
165
+ ? block.content
166
+ : "",
167
+ })));
168
+ }
169
+ else {
170
+ sysVal = JSON.stringify(system);
171
+ }
172
+ span.setAttribute("gen_ai.system_instructions", sysVal);
173
+ }
174
+ const tools = kwargs.tools;
175
+ if (tools && tools.length > 0) {
176
+ const defs = tools.map((t) => ({
177
+ name: t.name || "",
178
+ description: t.description,
179
+ parameters: t.input_schema,
180
+ }));
181
+ span.setAttribute("gen_ai.tool.definitions", JSON.stringify(defs));
182
+ }
183
+ }
184
+ function setResponseAttrs(span, response) {
185
+ const content = response.content;
186
+ if (content) {
187
+ const outputMsgs = convertAnthropicOutput(content);
188
+ if (outputMsgs.length > 0) {
189
+ span.setAttribute("gen_ai.output.messages", serializeMessages(outputMsgs));
190
+ }
191
+ }
192
+ if (response.id)
193
+ span.setAttribute("gen_ai.response.id", String(response.id));
194
+ if (response.model)
195
+ span.setAttribute("gen_ai.response.model", String(response.model));
196
+ const usage = response.usage;
197
+ if (usage) {
198
+ if (usage.input_tokens != null)
199
+ span.setAttribute("gen_ai.usage.input_tokens", usage.input_tokens);
200
+ if (usage.output_tokens != null)
201
+ span.setAttribute("gen_ai.usage.output_tokens", usage.output_tokens);
202
+ if (usage.cache_read_input_tokens != null)
203
+ span.setAttribute("gen_ai.usage.cache_read.input_tokens", usage.cache_read_input_tokens);
204
+ if (usage.cache_creation_input_tokens != null)
205
+ span.setAttribute("gen_ai.usage.cache_creation.input_tokens", usage.cache_creation_input_tokens);
206
+ }
207
+ span.setStatus({ code: SpanStatusCode.OK });
208
+ }
209
+ class TracedStream {
210
+ inner;
211
+ span;
212
+ blocks = [];
213
+ currentBlock = null;
214
+ responseId = null;
215
+ responseModel = null;
216
+ inputTokens = 0;
217
+ outputTokens = 0;
218
+ cacheReadInputTokens = 0;
219
+ cacheCreationInputTokens = 0;
220
+ finalized = false;
221
+ constructor(inner, span) {
222
+ this.inner = inner;
223
+ this.span = span;
224
+ }
225
+ async *[Symbol.asyncIterator]() {
226
+ try {
227
+ for await (const event of this.inner) {
228
+ this.processEvent(event);
229
+ yield event;
230
+ }
231
+ }
232
+ finally {
233
+ this.finalize();
234
+ }
235
+ }
236
+ processEvent(event) {
237
+ if (event.type === "message_start" && event.message) {
238
+ this.responseId = event.message.id || null;
239
+ this.responseModel = event.message.model || null;
240
+ const usage = event.message.usage;
241
+ if (usage) {
242
+ this.inputTokens = usage.input_tokens || 0;
243
+ this.cacheReadInputTokens = usage.cache_read_input_tokens || 0;
244
+ this.cacheCreationInputTokens = usage.cache_creation_input_tokens || 0;
245
+ }
246
+ }
247
+ else if (event.type === "content_block_start" && event.content_block) {
248
+ const bt = event.content_block.type || "";
249
+ this.currentBlock = { type: bt };
250
+ if (bt === "thinking") {
251
+ this.currentBlock.thinking = "";
252
+ this.currentBlock.signature = "";
253
+ }
254
+ else if (bt === "text") {
255
+ this.currentBlock.text = "";
256
+ }
257
+ }
258
+ else if (event.type === "content_block_delta" && event.delta) {
259
+ if (!this.currentBlock)
260
+ return;
261
+ const dt = event.delta.type || "";
262
+ if (dt === "thinking_delta") {
263
+ this.currentBlock.thinking =
264
+ (this.currentBlock.thinking || "") +
265
+ (event.delta.thinking || "");
266
+ }
267
+ else if (dt === "text_delta") {
268
+ this.currentBlock.text =
269
+ (this.currentBlock.text || "") +
270
+ (event.delta.text || "");
271
+ }
272
+ else if (dt === "signature_delta") {
273
+ this.currentBlock.signature =
274
+ (this.currentBlock.signature || "") +
275
+ (event.delta.signature || "");
276
+ }
277
+ }
278
+ else if (event.type === "content_block_stop") {
279
+ if (this.currentBlock) {
280
+ this.blocks.push(this.currentBlock);
281
+ this.currentBlock = null;
282
+ }
283
+ }
284
+ else if (event.type === "message_delta") {
285
+ const usage = event.usage;
286
+ if (usage)
287
+ this.outputTokens = usage.output_tokens || 0;
288
+ }
289
+ }
290
+ finalize() {
291
+ if (this.finalized)
292
+ return;
293
+ this.finalized = true;
294
+ if (this.blocks.length > 0) {
295
+ const outputMsgs = convertAnthropicOutput(this.blocks);
296
+ if (outputMsgs.length > 0) {
297
+ this.span.setAttribute("gen_ai.output.messages", serializeMessages(outputMsgs));
298
+ }
299
+ }
300
+ if (this.responseId)
301
+ this.span.setAttribute("gen_ai.response.id", this.responseId);
302
+ if (this.responseModel)
303
+ this.span.setAttribute("gen_ai.response.model", this.responseModel);
304
+ if (this.inputTokens)
305
+ this.span.setAttribute("gen_ai.usage.input_tokens", this.inputTokens);
306
+ if (this.outputTokens)
307
+ this.span.setAttribute("gen_ai.usage.output_tokens", this.outputTokens);
308
+ if (this.cacheReadInputTokens)
309
+ this.span.setAttribute("gen_ai.usage.cache_read.input_tokens", this.cacheReadInputTokens);
310
+ if (this.cacheCreationInputTokens)
311
+ this.span.setAttribute("gen_ai.usage.cache_creation.input_tokens", this.cacheCreationInputTokens);
312
+ this.span.setStatus({ code: SpanStatusCode.OK });
313
+ this.span.end();
314
+ }
315
+ }
316
+ // ---------------------------------------------------------------------------
317
+ // Public API
318
+ // ---------------------------------------------------------------------------
319
+ /**
320
+ * Traced wrapper around `client.messages.create(kwargs)`.
321
+ * Creates a gen_ai span with full Anthropic response including thinking blocks.
322
+ */
323
+ export async function tracedMessagesCreate(tracer, client, kwargs, conversationId) {
324
+ const { span } = startSpan(tracer, kwargs.model || "unknown", conversationId);
325
+ try {
326
+ setRequestAttrs(span, kwargs);
327
+ const response = (await client.messages.create(kwargs));
328
+ setResponseAttrs(span, response);
329
+ return response;
330
+ }
331
+ catch (e) {
332
+ span.setStatus({
333
+ code: SpanStatusCode.ERROR,
334
+ message: String(e),
335
+ });
336
+ throw e;
337
+ }
338
+ finally {
339
+ span.end();
340
+ }
341
+ }
342
+ /**
343
+ * Auto-instrumentor that patches `Anthropic.messages.create` to add tracing.
344
+ *
345
+ * Captures all content blocks including thinking (extended thinking) with
346
+ * signatures. Supports both non-streaming and streaming calls.
347
+ */
348
+ /**
349
+ * Auto-instrumentor that wraps an Anthropic client instance to add tracing.
350
+ *
351
+ * Captures all content blocks including thinking (extended thinking) with
352
+ * signatures. Supports both non-streaming and streaming calls.
353
+ */
354
+ export class AnthropicInstrumentor {
355
+ tracer = null;
356
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
357
+ patchedClients = [];
358
+ conversationId;
359
+ instrument(opts) {
360
+ const { client } = opts;
361
+ if (!client?.messages?.create) {
362
+ throw new Error("Invalid client — pass an Anthropic client instance (new Anthropic())");
363
+ }
364
+ this.conversationId = opts.conversationId ?? crypto.randomUUID();
365
+ const provider = opts.tracerProvider ?? trace.getTracerProvider();
366
+ this.tracer = provider.getTracer("introspection-anthropic");
367
+ const origCreate = client.messages.create.bind(client.messages);
368
+ this.patchedClients.push({ client, originalCreate: origCreate });
369
+ const tracer = this.tracer;
370
+ const defaultConversationId = this.conversationId;
371
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
372
+ client.messages.create = function (...args) {
373
+ const kwargs = args[0];
374
+ const isStream = kwargs?.stream === true;
375
+ // Baggage on the active context overrides the conversation ID bound
376
+ // at instrument() time, so callers can wrap a request in
377
+ // IntrospectionClient.withConversation() to scope a single call to a
378
+ // distinct conversation without re-instrumenting the client.
379
+ const baggage = propagation.getBaggage(otelContext.active());
380
+ const baggageConvId = baggage?.getEntry("gen_ai.conversation.id")?.value;
381
+ const baggageAgentName = baggage?.getEntry("gen_ai.agent.name")?.value;
382
+ const baggageAgentId = baggage?.getEntry("gen_ai.agent.id")?.value;
383
+ const { span } = startSpan(tracer, kwargs?.model || "unknown", baggageConvId ?? defaultConversationId);
384
+ if (baggageAgentName) {
385
+ span.setAttribute("gen_ai.agent.name", baggageAgentName);
386
+ }
387
+ if (baggageAgentId) {
388
+ span.setAttribute("gen_ai.agent.id", baggageAgentId);
389
+ }
390
+ setRequestAttrs(span, kwargs || {});
391
+ if (isStream) {
392
+ const streamPromise = origCreate(...args);
393
+ return streamPromise.then((stream) => new TracedStream(stream, span), (err) => {
394
+ span.setStatus({
395
+ code: SpanStatusCode.ERROR,
396
+ message: String(err),
397
+ });
398
+ span.end();
399
+ throw err;
400
+ });
401
+ }
402
+ const resultPromise = origCreate(...args);
403
+ return resultPromise.then((response) => {
404
+ setResponseAttrs(span, response);
405
+ span.end();
406
+ return response;
407
+ }, (err) => {
408
+ span.setStatus({
409
+ code: SpanStatusCode.ERROR,
410
+ message: String(err),
411
+ });
412
+ span.end();
413
+ throw err;
414
+ });
415
+ };
416
+ }
417
+ uninstrument() {
418
+ for (const { client, originalCreate } of this.patchedClients) {
419
+ client.messages.create = originalCreate;
420
+ }
421
+ this.patchedClients = [];
422
+ this.tracer = null;
423
+ }
424
+ }
425
+ //# sourceMappingURL=anthropic.js.map