@struct-ai/sdk 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/README.md +46 -3
  2. package/dist/commonjs/core.d.ts +2 -0
  3. package/dist/commonjs/core.js +53 -7
  4. package/dist/esm/core.d.ts +2 -0
  5. package/dist/esm/core.js +54 -8
  6. package/package.json +21 -21
  7. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/content-capture.d.ts +0 -10
  8. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/context.d.ts +0 -30
  9. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/core.d.ts +0 -120
  10. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/events.d.ts +0 -12
  11. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/index.d.ts +0 -6
  12. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic-content.d.ts +0 -24
  13. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic.d.ts +0 -34
  14. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/index.d.ts +0 -5
  15. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-callback.d.ts +0 -134
  16. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-content.d.ts +0 -35
  17. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain.d.ts +0 -11
  18. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +0 -3
  19. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/semconv.d.ts +0 -54
  20. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/truncation.d.ts +0 -10
  21. package/dist/node_modules/@struct-ai/sdk/dist/esm/content-capture.d.ts +0 -10
  22. package/dist/node_modules/@struct-ai/sdk/dist/esm/context.d.ts +0 -30
  23. package/dist/node_modules/@struct-ai/sdk/dist/esm/core.d.ts +0 -120
  24. package/dist/node_modules/@struct-ai/sdk/dist/esm/events.d.ts +0 -12
  25. package/dist/node_modules/@struct-ai/sdk/dist/esm/index.d.ts +0 -6
  26. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic-content.d.ts +0 -24
  27. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic.d.ts +0 -34
  28. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/index.d.ts +0 -5
  29. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-callback.d.ts +0 -134
  30. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-content.d.ts +0 -35
  31. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain.d.ts +0 -11
  32. package/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +0 -3
  33. package/dist/node_modules/@struct-ai/sdk/dist/esm/semconv.d.ts +0 -54
  34. package/dist/node_modules/@struct-ai/sdk/dist/esm/truncation.d.ts +0 -10
  35. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +0 -3
  36. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +0 -3
  37. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +0 -103
  38. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +0 -103
  39. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +0 -118
  40. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +0 -916
  41. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +0 -188
  42. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/package.json +0 -105
  43. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +0 -96
  44. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +0 -91
  45. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +0 -96
  46. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +0 -108
  47. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +0 -105
  48. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +0 -100
  49. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +0 -109
  50. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +0 -100
  51. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +0 -76
  52. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +0 -140
  53. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +0 -89
  54. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +0 -81
  55. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tsx/package.json +0 -68
  56. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +0 -120
  57. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +0 -239
  58. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/zod/package.json +0 -135
  59. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +0 -103
  60. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/core.d.ts +0 -244
  61. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/error.d.ts +0 -54
  62. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/index.d.ts +0 -188
  63. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +0 -103
  64. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/pagination.d.ts +0 -26
  65. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/resource.d.ts +0 -6
  66. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/streaming.d.ts +0 -41
  67. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/uploads.d.ts +0 -75
  68. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/version.d.ts +0 -2
  69. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/experimental.d.ts +0 -1
  70. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/index.d.ts +0 -1
  71. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +0 -118
  72. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/agents.d.ts +0 -1
  73. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/caches.d.ts +0 -1
  74. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/chat_history.d.ts +0 -1
  75. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/context.d.ts +0 -1
  76. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/documents.d.ts +0 -1
  77. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/embeddings.d.ts +0 -1
  78. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/example_selectors.d.ts +0 -1
  79. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/index.d.ts +0 -1
  80. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/indexing.d.ts +0 -1
  81. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/load.d.ts +0 -1
  82. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/memory.d.ts +0 -1
  83. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/messages.d.ts +0 -1
  84. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/output_parsers.d.ts +0 -1
  85. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/outputs.d.ts +0 -1
  86. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +0 -916
  87. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompt_values.d.ts +0 -1
  88. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompts.d.ts +0 -1
  89. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/retrievers.d.ts +0 -1
  90. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/runnables.d.ts +0 -1
  91. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/singletons.d.ts +0 -1
  92. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/stores.d.ts +0 -1
  93. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/structured_query.d.ts +0 -1
  94. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/tools.d.ts +0 -1
  95. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/vectorstores.d.ts +0 -1
  96. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/index.d.ts +0 -1
  97. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +0 -188
  98. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/prebuilt.d.ts +0 -1
  99. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/pregel.d.ts +0 -1
  100. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/remote.d.ts +0 -1
  101. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/web.d.ts +0 -1
  102. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/zod.d.ts +0 -1
  103. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/index.d.ts +0 -1
  104. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/openai/package.json +0 -105
  105. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +0 -96
  106. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +0 -91
  107. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +0 -96
  108. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +0 -108
  109. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +0 -105
  110. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +0 -100
  111. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +0 -109
  112. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +0 -100
  113. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +0 -76
  114. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/assert.d.ts +0 -1062
  115. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/async_hooks.d.ts +0 -605
  116. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.buffer.d.ts +0 -471
  117. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.d.ts +0 -1936
  118. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/child_process.d.ts +0 -1475
  119. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/cluster.d.ts +0 -577
  120. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/console.d.ts +0 -452
  121. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/constants.d.ts +0 -21
  122. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/crypto.d.ts +0 -4590
  123. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dgram.d.ts +0 -597
  124. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/diagnostics_channel.d.ts +0 -578
  125. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dns.d.ts +0 -871
  126. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/domain.d.ts +0 -170
  127. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/events.d.ts +0 -977
  128. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/fs.d.ts +0 -4375
  129. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.d.ts +0 -172
  130. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.typedarray.d.ts +0 -38
  131. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http.d.ts +0 -2049
  132. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http2.d.ts +0 -2631
  133. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/https.d.ts +0 -578
  134. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/index.d.ts +0 -93
  135. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/inspector.generated.d.ts +0 -3966
  136. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/module.d.ts +0 -539
  137. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/net.d.ts +0 -1031
  138. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/os.d.ts +0 -506
  139. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +0 -140
  140. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/path.d.ts +0 -200
  141. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/perf_hooks.d.ts +0 -961
  142. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/process.d.ts +0 -1961
  143. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/punycode.d.ts +0 -117
  144. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/querystring.d.ts +0 -152
  145. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/readline.d.ts +0 -589
  146. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/repl.d.ts +0 -430
  147. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/sea.d.ts +0 -153
  148. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/stream.d.ts +0 -1698
  149. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/string_decoder.d.ts +0 -67
  150. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/test.d.ts +0 -1787
  151. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/timers.d.ts +0 -286
  152. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tls.d.ts +0 -1259
  153. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/trace_events.d.ts +0 -197
  154. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tty.d.ts +0 -208
  155. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/url.d.ts +0 -964
  156. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/util.d.ts +0 -2331
  157. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/v8.d.ts +0 -809
  158. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/vm.d.ts +0 -1001
  159. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/wasi.d.ts +0 -181
  160. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/worker_threads.d.ts +0 -715
  161. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/zlib.d.ts +0 -598
  162. package/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +0 -89
  163. package/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +0 -81
  164. package/dist/node_modules/@struct-ai/sdk/node_modules/tsx/package.json +0 -68
  165. package/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +0 -120
  166. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/config.d.ts +0 -3
  167. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/coverage.d.ts +0 -1
  168. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/environments.d.ts +0 -1
  169. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/globals.d.ts +0 -22
  170. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/import-meta.d.ts +0 -5
  171. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/importMeta.d.ts +0 -4
  172. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/jsdom.d.ts +0 -6
  173. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/mocker.d.ts +0 -1
  174. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/node.d.ts +0 -1
  175. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-runtime-types.d.ts +0 -6
  176. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-types.d.ts +0 -7
  177. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +0 -239
  178. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/reporters.d.ts +0 -1
  179. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/runners.d.ts +0 -1
  180. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/snapshot.d.ts +0 -1
  181. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/suite.d.ts +0 -1
  182. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/worker.d.ts +0 -1
  183. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/index.d.ts +0 -4
  184. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/locales/package.json +0 -7
  185. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/mini/package.json +0 -7
  186. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/package.json +0 -135
  187. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v3/package.json +0 -7
  188. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/classic/package.json +0 -7
  189. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/core/package.json +0 -7
  190. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/locales/package.json +0 -7
  191. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/mini/package.json +0 -7
  192. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4/package.json +0 -7
  193. package/dist/node_modules/@struct-ai/sdk/node_modules/zod/v4-mini/package.json +0 -7
  194. package/dist/node_modules/@struct-ai/sdk/package.json +0 -103
@@ -1,134 +0,0 @@
1
- import { type Tracer } from "@opentelemetry/api";
2
- import type { Logger } from "@opentelemetry/api-logs";
3
- import { type StructSDK } from "../core.js";
4
- type Serialized = {
5
- lc?: number;
6
- type?: string;
7
- id?: string[];
8
- kwargs?: Record<string, unknown>;
9
- name?: string;
10
- };
11
- type UnknownMessage = unknown;
12
- interface ChatGenerationLike {
13
- text?: string;
14
- message?: UnknownMessage;
15
- generationInfo?: Record<string, unknown>;
16
- }
17
- interface LLMResultLike {
18
- generations: ChatGenerationLike[][];
19
- llmOutput?: Record<string, unknown>;
20
- }
21
- /**
22
- * LangChain CallbackHandler — creates OTel spans from LangChain callbacks.
23
- *
24
- * Parent-child linkage comes from `parentRunId` fields LangChain passes to us,
25
- * NOT from OTel's async context. This survives LangGraph's internal task
26
- * shuffling, which is why the callback API is the industry-standard integration
27
- * point (LangSmith, OpenInference, Traceloop, Langfuse all use it).
28
- *
29
- * thread_id vs gen_ai.conversation.id
30
- * -----------------------------------
31
- * These are distinct concepts and Struct keeps them separate:
32
- *
33
- * - `config.configurable.thread_id` is LangGraph's checkpoint identifier,
34
- * keying a conversation's state in the checkpointer. Multiple turns of
35
- * the same conversation reuse one thread_id so history accumulates.
36
- *
37
- * - `gen_ai.conversation.id` is the OTel GenAI-spec conversation identifier
38
- * and Struct's UI grouping unit — one value = one entry in the sessions
39
- * list. For the top-level agent we auto-derive it from thread_id, so a
40
- * stable thread_id across multi-turn chats collapses into one session.
41
- *
42
- * For SUBAGENTS (an agent invoked from inside another's tool body) we
43
- * deliberately assign a DIFFERENT conversation.id — either from the subagent's
44
- * own thread_id if supplied, or a fresh UUID. The resulting session is
45
- * linked back to the outer agent's session via the
46
- * `struct.agent.parent_session_id` span attribute (what powers "Spawned
47
- * by" / subagent navigation in the UI). Without this split the subagent's
48
- * spans would collapse into the outer session, burying delegation.
49
- *
50
- * LangChain quirk (handled automatically): when `agent.invoke(...)` runs
51
- * nested inside a parent call, LangChain's config-merge inherits the
52
- * parent's `metadata.thread_id` onto the child even if its config provided
53
- * a different one. We detect that by comparing against the nearest agent
54
- * ancestor's session; if they match, treat it as "inherited, not
55
- * user-intended" and assign a fresh UUID to the subagent.
56
- *
57
- * End-user guidance:
58
- * - Use thread_id per conversation; multi-turn chats reuse it.
59
- * - For a subagent call, pass a DIFFERENT thread_id (or omit it and let
60
- * LangGraph generate one). Each subagent then surfaces as its own
61
- * session in the UI, linked back via parent_session_id.
62
- */
63
- export declare class StructCallbackHandler {
64
- private readonly sdk;
65
- private readonly tracer;
66
- private readonly logger;
67
- readonly name = "struct";
68
- readonly lc_namespace: readonly string[];
69
- readonly lc_serializable = false;
70
- readonly awaitHandlers = false;
71
- readonly ignoreLLM = false;
72
- readonly ignoreChain = false;
73
- readonly ignoreAgent = false;
74
- readonly ignoreRetriever = false;
75
- readonly ignoreCustomEvent = true;
76
- /**
77
- * LangChain reads `raiseError` to decide whether a callback throw should
78
- * abort the user's run. We keep this `false` because every callback method
79
- * is wrapped in `safe()` and never throws — but a `true` here would tell
80
- * LangChain to surface our (impossible) throws into the user's call.
81
- * Locked by `test_handler_raiseError_is_false`.
82
- */
83
- readonly raiseError = false;
84
- private readonly runs;
85
- private readonly internalLogger;
86
- constructor(sdk: StructSDK, tracer: Tracer, logger: Logger | undefined);
87
- handleChainStart: (chain: Serialized, inputs: unknown, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string) => void;
88
- handleChainEnd: (_outputs: unknown, runId: string) => void;
89
- handleChainError: (err: Error, runId: string) => void;
90
- handleChatModelStart: (llm: Serialized, messages: UnknownMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
91
- handleLLMStart: (llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
92
- handleLLMEnd: (output: LLMResultLike, runId: string) => void;
93
- handleLLMError: (err: Error, runId: string) => void;
94
- handleToolStart: (tool: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
95
- handleToolEnd: (output: unknown, runId: string) => void;
96
- handleToolError: (err: Error, runId: string) => void;
97
- handleRetrieverStart: (retriever: Serialized, query: string, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
98
- handleRetrieverEnd: (documents: unknown[], runId: string) => void;
99
- handleRetrieverError: (err: Error, runId: string) => void;
100
- private resolveParent;
101
- /**
102
- * Conversation-id resolution for chat/tool/retriever spans — INHERIT from
103
- * the parent agent so everything rolls up under one gen_ai.conversation.id.
104
- */
105
- private resolveSessionId;
106
- /**
107
- * Walk the run tree to find the nearest ``invoke_agent`` ancestor's
108
- * gen_ai.conversation.id.
109
- *
110
- * The immediate ``parentRunId`` might be a tool, LLM, retriever, or a
111
- * filtered RunnableSequence — none of which are agents themselves. We
112
- * populate ``nearestAgentSessionId`` at each run's creation so any
113
- * descendant can read it in O(1).
114
- *
115
- * Used to set ``struct.agent.parent_session_id`` on nested ``invoke_agent``
116
- * spans (our UI's "Spawned by" / "Subagents" linkage).
117
- */
118
- private inheritedAgentSessionId;
119
- /**
120
- * Conversation-id resolution for AGENT spans — each agent invocation gets
121
- * its own gen_ai.conversation.id. We deliberately do NOT inherit from the
122
- * parent run, so subagents surface as separate entries in the sessions
123
- * list. Parent linkage is preserved via `struct.agent.parent_session_id`.
124
- *
125
- * LangChain inherits `metadata.thread_id` from the parent invoke's config
126
- * when a nested invoke runs inside it (even if the child config supplied
127
- * its own). We detect that inheritance by comparing against the parent's
128
- * resolved session and ignore the inherited value.
129
- */
130
- private resolveAgentSessionId;
131
- private propagateUserPrompt;
132
- }
133
- export {};
134
- //# sourceMappingURL=langchain-callback.d.ts.map
@@ -1,35 +0,0 @@
1
- import type { Part } from "./anthropic-content.js";
2
- export declare const PROVIDER_MAP: Record<string, string>;
3
- export declare const MODULE_PROVIDER_MAP: Record<string, string>;
4
- /** Detect LLM provider from a LangChain model instance. */
5
- export declare function detectProvider(model: unknown): string;
6
- /** Probe `modelName`, `model`, `modelId` attrs in order. */
7
- export declare function detectModel(model: unknown): string;
8
- /**
9
- * Extract the messages list from LangChain invoke()'s input argument.
10
- * Handles: BaseMessage[], string, PromptValue (via toChatMessages/toMessages),
11
- * dict with .messages key.
12
- */
13
- export declare function extractInputMessages(input: unknown): unknown[];
14
- /**
15
- * Extract thread_id from LangChain/LangGraph RunnableConfig.
16
- * Signature: (input, config?, ...). Config has shape { configurable: { thread_id: "..." } }.
17
- */
18
- export declare function extractThreadId(args: readonly unknown[], options?: unknown): string | undefined;
19
- /**
20
- * Extract tool_call_id from LangChain ToolCall input.
21
- * LangChain tool invocation input shape: { name, args, id, type: "tool_call" }.
22
- */
23
- export declare function extractToolCallId(args: readonly unknown[]): string | undefined;
24
- /** Convert a LangChain message to (role, parts). Uses ._getType() first, falls back to class name. */
25
- export declare function langchainMessageToRoleAndParts(msg: unknown): {
26
- role: string;
27
- parts: Part[];
28
- };
29
- export declare function langchainToInputMessages(messages: unknown[]): string;
30
- export declare function langchainToOutputMessages(result: unknown): string;
31
- /** Last user message parts for parent invoke_agent span propagation. */
32
- export declare function lastUserMessageParts(messages: unknown[]): Part[] | undefined;
33
- /** Merge a list of LangChain AIMessageChunks into one via .concat(). */
34
- export declare function mergeChunks(chunks: unknown[]): unknown;
35
- //# sourceMappingURL=langchain-content.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { StructSDK } from "../core.js";
2
- import { StructCallbackHandler } from "./langchain-callback.js";
3
- /**
4
- * Export the handler so callers can register it explicitly
5
- * (e.g. `runnable.invoke(x, { callbacks: [struct.langchainHandler] })`)
6
- * when the global monkey-patch isn't an option.
7
- */
8
- export declare function getLangchainHandler(): StructCallbackHandler | undefined;
9
- export declare function patch(sdk: StructSDK): Promise<void>;
10
- export declare function unpatch(): Promise<void>;
11
- //# sourceMappingURL=langchain.d.ts.map
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,54 +0,0 @@
1
- export declare const GEN_AI: {
2
- readonly OPERATION_NAME: "gen_ai.operation.name";
3
- readonly PROVIDER_NAME: "gen_ai.provider.name";
4
- readonly SYSTEM: "gen_ai.system";
5
- readonly AGENT_NAME: "gen_ai.agent.name";
6
- readonly AGENT_ID: "gen_ai.agent.id";
7
- readonly AGENT_VERSION: "gen_ai.agent.version";
8
- readonly CONVERSATION_ID: "gen_ai.conversation.id";
9
- readonly REQUEST_MODEL: "gen_ai.request.model";
10
- readonly REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens";
11
- readonly REQUEST_TEMPERATURE: "gen_ai.request.temperature";
12
- readonly REQUEST_TOP_P: "gen_ai.request.top_p";
13
- readonly REQUEST_TOP_K: "gen_ai.request.top_k";
14
- readonly REQUEST_FREQUENCY_PENALTY: "gen_ai.request.frequency_penalty";
15
- readonly REQUEST_PRESENCE_PENALTY: "gen_ai.request.presence_penalty";
16
- readonly REQUEST_STOP_SEQUENCES: "gen_ai.request.stop_sequences";
17
- readonly RESPONSE_MODEL: "gen_ai.response.model";
18
- readonly RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons";
19
- readonly RESPONSE_ID: "gen_ai.response.id";
20
- readonly USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens";
21
- readonly USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
22
- readonly USAGE_CACHE_READ_INPUT_TOKENS: "gen_ai.usage.cache_read.input_tokens";
23
- readonly USAGE_CACHE_CREATION_INPUT_TOKENS: "gen_ai.usage.cache_creation.input_tokens";
24
- readonly INPUT_MESSAGES: "gen_ai.input.messages";
25
- readonly OUTPUT_MESSAGES: "gen_ai.output.messages";
26
- readonly SYSTEM_INSTRUCTIONS: "gen_ai.system_instructions";
27
- readonly TOOL_DEFINITIONS: "gen_ai.tool.definitions";
28
- readonly TOOL_NAME: "gen_ai.tool.name";
29
- readonly TOOL_CALL_ID: "gen_ai.tool.call.id";
30
- readonly TOOL_CALL_ARGUMENTS: "gen_ai.tool.call.arguments";
31
- readonly TOOL_CALL_RESULT: "gen_ai.tool.call.result";
32
- readonly DATA_SOURCE_ID: "gen_ai.data_source.id";
33
- readonly RETRIEVAL_QUERY_TEXT: "gen_ai.retrieval.query.text";
34
- readonly RETRIEVAL_DOCUMENTS: "gen_ai.retrieval.documents";
35
- readonly MESSAGE_INDEX: "gen_ai.message.index";
36
- };
37
- export declare const STRUCT: {
38
- readonly METADATA_PREFIX: "struct.metadata.";
39
- readonly AGENT_PARENT_SESSION_ID: "struct.agent.parent_session_id";
40
- readonly INPUT_MESSAGE_COUNT: "struct.input.message_count";
41
- };
42
- export declare const EVENT_NAME = "event.name";
43
- export declare const ERROR_TYPE = "error.type";
44
- export declare const EVENT_NAMES: {
45
- readonly USER_MESSAGE: "gen_ai.user.message";
46
- readonly ASSISTANT_MESSAGE: "gen_ai.assistant.message";
47
- readonly SYSTEM_MESSAGE: "gen_ai.system.message";
48
- readonly TOOL_MESSAGE: "gen_ai.tool.message";
49
- readonly CHOICE: "gen_ai.choice";
50
- };
51
- export declare const ROLE_TO_EVENT_NAME: Record<string, string>;
52
- export declare const ANTHROPIC_FINISH_REASON_MAP: Record<string, string>;
53
- export declare const LANGCHAIN_FINISH_REASON_MAP: Record<string, string>;
54
- //# sourceMappingURL=semconv.d.ts.map
@@ -1,10 +0,0 @@
1
- export declare const MAX_CONTENT_SIZE: number;
2
- export declare const MAX_FIELD_SIZE = 16384;
3
- export declare const TRUNCATION_MARKER = "\u2026 [truncated]";
4
- export declare function truncateField<T>(value: T, maxLen?: number): T | string;
5
- type Part = Record<string, unknown>;
6
- export declare function truncateParts(parts: Part[]): Part[];
7
- export declare function truncateAndSerialize(obj: unknown, maxSize?: number): string;
8
- export declare function safeJsonStringify(obj: unknown): string;
9
- export {};
10
- //# sourceMappingURL=truncation.d.ts.map
@@ -1,10 +0,0 @@
1
- export declare enum ContentCaptureMode {
2
- None = "none",
3
- EventOnly = "event_only",
4
- SpanOnly = "span_only",
5
- SpanAndEvent = "span_and_event"
6
- }
7
- export declare function emitEventsFor(mode: ContentCaptureMode): boolean;
8
- export declare function emitSpanContentFor(mode: ContentCaptureMode): boolean;
9
- export declare function captureContentFor(mode: ContentCaptureMode): boolean;
10
- //# sourceMappingURL=content-capture.d.ts.map
@@ -1,30 +0,0 @@
1
- import type { Span } from "@opentelemetry/api";
2
- export interface StructContext {
3
- sessionId?: string;
4
- conversationId?: string;
5
- agentSpan?: Span;
6
- pendingToolCalls?: Record<string, string[]>;
7
- }
8
- export declare function getStore(): StructContext | undefined;
9
- export declare function getSessionId(): string | undefined;
10
- export declare function getConversationId(): string | undefined;
11
- export declare function getAgentSpan(): Span | undefined;
12
- export declare function getPendingToolCalls(): Record<string, string[]> | undefined;
13
- export declare function runWithContext<T>(patch: Partial<StructContext>, fn: () => T): T;
14
- export declare function ensurePendingToolCallsSlot(): Record<string, string[]>;
15
- /**
16
- * Pop the first pending tool_use id matching `name`, or undefined.
17
- * FIFO semantics match Python struct-sdk-python.
18
- */
19
- export declare function popPendingToolCallId(name: string): string | undefined;
20
- /**
21
- * Push (name, id) pairs into the active pending-tool-calls slot.
22
- * Initializes a transient dict if no active agent scope.
23
- */
24
- export declare function pushPendingToolCalls(pairs: readonly [string, string][]): void;
25
- /** Snapshot the store for wrapping async iterators. */
26
- export declare function snapshotStore(): StructContext | undefined;
27
- export declare function runWithStore<T>(store: StructContext | undefined, fn: () => T): T;
28
- /** Test-only: run `fn` inside a completely fresh context (no parent store). */
29
- export declare function runInFreshContext<T>(fn: () => T): T;
30
- //# sourceMappingURL=context.d.ts.map
@@ -1,120 +0,0 @@
1
- import { type Tracer } from "@opentelemetry/api";
2
- import { type Logger } from "@opentelemetry/api-logs";
3
- import { type LogRecordProcessor } from "@opentelemetry/sdk-logs";
4
- import type { SpanProcessor } from "@opentelemetry/sdk-trace-base";
5
- import { ContentCaptureMode } from "./content-capture.js";
6
- export declare const DEFAULT_ENDPOINT = "https://ingest.struct.ai";
7
- export interface InitOptions {
8
- ingestKey: string;
9
- serviceName?: string;
10
- serviceVersion?: string;
11
- environment?: string;
12
- endpoint?: string;
13
- captureContent?: boolean;
14
- contentCapture?: ContentCaptureMode;
15
- /**
16
- * Maximum time `shutdown()` is allowed to spend flushing telemetry providers
17
- * before returning. If the ingest endpoint is dead or slow, shutdown returns
18
- * within this budget rather than hanging the host process exit. Defaults to
19
- * 5000ms. Can be overridden per call via `shutdown(timeoutMs)`.
20
- */
21
- shutdownTimeoutMs?: number;
22
- }
23
- export interface AgentScopeOptions {
24
- name: string;
25
- sessionId?: string;
26
- /**
27
- * Stable identifier for the agent DEFINITION — `gen_ai.agent.id` per the OTel
28
- * GenAI spec. Not the same as sessionId (which identifies a single
29
- * invocation / conversation). Omit if you don't have a stable ID.
30
- */
31
- agentId?: string;
32
- version?: string;
33
- metadata?: Record<string, string>;
34
- }
35
- export interface ToolScopeOptions {
36
- name: string;
37
- toolCallId?: string;
38
- }
39
- export interface InternalLogger {
40
- info(msg: string, ...args: unknown[]): void;
41
- warn(msg: string, ...args: unknown[]): void;
42
- debug(msg: string, ...args: unknown[]): void;
43
- }
44
- /**
45
- * Sites that have already logged a first-failure WARN; subsequent failures at
46
- * the same site log at DEBUG. Mirrors `_first_failure_logged` in the Python
47
- * SDK.
48
- *
49
- * Exported for tests that need to clear the set between runs so log-level
50
- * assertions are deterministic. Internal — not re-exported from `index.ts`,
51
- * so consumers cannot reach it via the package's public API surface.
52
- */
53
- export declare const firstFailureLogged: Set<string>;
54
- /**
55
- * Run `fn`; swallow any exception. The first failure per `site` logs at WARN
56
- * (with the error attached); subsequent failures at the same site log at
57
- * DEBUG. The caller's logger is passed explicitly so this helper stays a free
58
- * module-level function — usable from instrumentation modules that don't
59
- * carry an SDK reference of their own.
60
- *
61
- * Mirrors `_safe(fn, *, site)` in the Python SDK.
62
- */
63
- export declare function safe(fn: () => void, site: string, logger: InternalLogger): void;
64
- export declare class StructSDK {
65
- private _initialized;
66
- private _tracerProvider;
67
- private _loggerProvider;
68
- private _ingestKey;
69
- private _endpoint;
70
- private _contentCapture;
71
- private _shutdownHook;
72
- private _shutdownTimeoutMs;
73
- private _internalLogger;
74
- private _readyPromise;
75
- /** Resolves once auto-instrumentation has attempted to patch every detected library. */
76
- get ready(): Promise<void>;
77
- get initialized(): boolean;
78
- get endpoint(): string;
79
- get ingestKey(): string;
80
- get contentCapture(): ContentCaptureMode;
81
- get captureContent(): boolean;
82
- get emitEvents(): boolean;
83
- get emitSpanContent(): boolean;
84
- init(options: InitOptions): void;
85
- getTracer(name?: string): Tracer;
86
- getLogger(name?: string): Logger;
87
- getInternalLogger(): InternalLogger;
88
- /** Test-only: attach a custom span processor to the internal provider. */
89
- addSpanProcessor(processor: SpanProcessor): void;
90
- /** Test-only: attach a custom log record processor. */
91
- addLogRecordProcessor(processor: LogRecordProcessor): void;
92
- /**
93
- * Shut down the SDK and flush pending telemetry.
94
- *
95
- * Returns within `timeoutMs` (default: SDK init's `shutdownTimeoutMs`,
96
- * fallback 5000ms). If the ingest endpoint is unreachable, in-flight
97
- * telemetry may be dropped — the trade-off vs. blocking process exit.
98
- *
99
- * In serverless / edge runtimes (Lambda, Vercel, etc.), the runtime does
100
- * NOT await our `beforeExit` hook. Call `await struct.shutdown()`
101
- * explicitly before your function returns or before container freeze.
102
- *
103
- * Safe to call multiple times. Safe to call on an SDK that failed to init
104
- * or was never initialized.
105
- *
106
- * @param timeoutMs - Override the configured shutdown timeout for this call.
107
- */
108
- shutdown(timeoutMs?: number): Promise<void>;
109
- /**
110
- * Run `fn` inside an `invoke_agent` span scope.
111
- * Matches Python's _AgentContext behavior.
112
- */
113
- agent<T>(options: AgentScopeOptions, fn: () => Promise<T> | T): Promise<T>;
114
- /**
115
- * Run `fn` inside an `execute_tool` span scope.
116
- * Matches Python's _ToolContext behavior.
117
- */
118
- tool<T>(options: ToolScopeOptions, fn: () => Promise<T> | T): Promise<T>;
119
- }
120
- //# sourceMappingURL=core.d.ts.map
@@ -1,12 +0,0 @@
1
- import { type Logger } from "@opentelemetry/api-logs";
2
- /**
3
- * Emit per-message log events for an Anthropic messages.create() call.
4
- * Port of _emit_message_events from anthropic.py.
5
- */
6
- export declare function emitAnthropicMessageEvents(logger: Logger, messages: unknown, system: unknown): void;
7
- /**
8
- * Emit a gen_ai.choice LogRecord for an Anthropic response.
9
- * Port of _emit_choice_event from anthropic.py.
10
- */
11
- export declare function emitAnthropicChoiceEvent(logger: Logger, contentBlocks: unknown, stopReason: string | null | undefined): void;
12
- //# sourceMappingURL=events.d.ts.map
@@ -1,6 +0,0 @@
1
- import { StructSDK } from "./core.js";
2
- export { ContentCaptureMode } from "./content-capture.js";
3
- export type { AgentScopeOptions, InitOptions, InternalLogger, ToolScopeOptions, } from "./core.js";
4
- export { StructSDK } from "./core.js";
5
- export declare const struct: StructSDK;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,24 +0,0 @@
1
- import { truncateField } from "../truncation.js";
2
- /** Part in the GenAI spec format. */
3
- export type Part = Record<string, unknown>;
4
- /**
5
- * Walk Anthropic response content blocks, return (name, id) pairs for tool_use blocks.
6
- * Port of _iter_tool_uses from anthropic.py.
7
- */
8
- export declare function iterToolUses(blocks: unknown): Array<[string, string]>;
9
- /**
10
- * Convert arbitrary content (string | block[] | unknown) → GenAI parts.
11
- * Port of _content_to_parts from anthropic.py.
12
- */
13
- export declare function contentToParts(content: unknown): Part[];
14
- /** Convert Anthropic message list → GenAI input-messages JSON string. */
15
- export declare function toInputMessages(messages: unknown): string;
16
- /** Convert response content blocks → GenAI output-messages JSON string. */
17
- export declare function toOutputMessages(contentBlocks: unknown, stopReason: string | null | undefined): string;
18
- /** Convert system prompt (string | block[]) → GenAI system_instructions JSON string. */
19
- export declare function toSystemInstructions(system: unknown): string;
20
- export declare function safeJsonForTool(obj: unknown): string;
21
- /** Extract the last user message's parts for parent-span propagation. */
22
- export declare function lastUserMessageParts(messages: unknown): Part[] | undefined;
23
- export { truncateField };
24
- //# sourceMappingURL=anthropic-content.d.ts.map
@@ -1,34 +0,0 @@
1
- import { type Tracer } from "@opentelemetry/api";
2
- import type { Logger } from "@opentelemetry/api-logs";
3
- import { type StructSDK } from "../core.js";
4
- interface PatchContext {
5
- tracer: Tracer;
6
- sdk: StructSDK;
7
- logger: Logger | undefined;
8
- }
9
- interface CreateParams {
10
- model?: string;
11
- max_tokens?: number;
12
- temperature?: number;
13
- top_p?: number;
14
- top_k?: number;
15
- stop_sequences?: string[];
16
- messages?: unknown[];
17
- system?: unknown;
18
- tools?: unknown[];
19
- stream?: boolean;
20
- }
21
- export declare function patch(sdk: StructSDK): Promise<void>;
22
- export declare function unpatch(): Promise<void>;
23
- type CreateMethod = (this: unknown, params: CreateParams, opts?: unknown) => unknown;
24
- type StreamMethod = (this: unknown, params: CreateParams, opts?: unknown) => unknown;
25
- /** @internal */
26
- export type _PatchContextForTest = PatchContext;
27
- /** @internal */
28
- export declare function _wrapCreateForTest(original: CreateMethod): CreateMethod;
29
- /** @internal */
30
- export declare function _wrapStreamForTest(original: StreamMethod): StreamMethod;
31
- /** @internal */
32
- export declare function _setActivePatchCtxForTest(ctx: PatchContext | undefined): void;
33
- export {};
34
- //# sourceMappingURL=anthropic.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { StructSDK } from "../core.js";
2
- export declare const patchedIntegrations: Set<string>;
3
- export declare function resetPatchedIntegrations(): void;
4
- export declare function autoInstrument(sdk: StructSDK): Promise<void>;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,134 +0,0 @@
1
- import { type Tracer } from "@opentelemetry/api";
2
- import type { Logger } from "@opentelemetry/api-logs";
3
- import { type StructSDK } from "../core.js";
4
- type Serialized = {
5
- lc?: number;
6
- type?: string;
7
- id?: string[];
8
- kwargs?: Record<string, unknown>;
9
- name?: string;
10
- };
11
- type UnknownMessage = unknown;
12
- interface ChatGenerationLike {
13
- text?: string;
14
- message?: UnknownMessage;
15
- generationInfo?: Record<string, unknown>;
16
- }
17
- interface LLMResultLike {
18
- generations: ChatGenerationLike[][];
19
- llmOutput?: Record<string, unknown>;
20
- }
21
- /**
22
- * LangChain CallbackHandler — creates OTel spans from LangChain callbacks.
23
- *
24
- * Parent-child linkage comes from `parentRunId` fields LangChain passes to us,
25
- * NOT from OTel's async context. This survives LangGraph's internal task
26
- * shuffling, which is why the callback API is the industry-standard integration
27
- * point (LangSmith, OpenInference, Traceloop, Langfuse all use it).
28
- *
29
- * thread_id vs gen_ai.conversation.id
30
- * -----------------------------------
31
- * These are distinct concepts and Struct keeps them separate:
32
- *
33
- * - `config.configurable.thread_id` is LangGraph's checkpoint identifier,
34
- * keying a conversation's state in the checkpointer. Multiple turns of
35
- * the same conversation reuse one thread_id so history accumulates.
36
- *
37
- * - `gen_ai.conversation.id` is the OTel GenAI-spec conversation identifier
38
- * and Struct's UI grouping unit — one value = one entry in the sessions
39
- * list. For the top-level agent we auto-derive it from thread_id, so a
40
- * stable thread_id across multi-turn chats collapses into one session.
41
- *
42
- * For SUBAGENTS (an agent invoked from inside another's tool body) we
43
- * deliberately assign a DIFFERENT conversation.id — either from the subagent's
44
- * own thread_id if supplied, or a fresh UUID. The resulting session is
45
- * linked back to the outer agent's session via the
46
- * `struct.agent.parent_session_id` span attribute (what powers "Spawned
47
- * by" / subagent navigation in the UI). Without this split the subagent's
48
- * spans would collapse into the outer session, burying delegation.
49
- *
50
- * LangChain quirk (handled automatically): when `agent.invoke(...)` runs
51
- * nested inside a parent call, LangChain's config-merge inherits the
52
- * parent's `metadata.thread_id` onto the child even if its config provided
53
- * a different one. We detect that by comparing against the nearest agent
54
- * ancestor's session; if they match, treat it as "inherited, not
55
- * user-intended" and assign a fresh UUID to the subagent.
56
- *
57
- * End-user guidance:
58
- * - Use thread_id per conversation; multi-turn chats reuse it.
59
- * - For a subagent call, pass a DIFFERENT thread_id (or omit it and let
60
- * LangGraph generate one). Each subagent then surfaces as its own
61
- * session in the UI, linked back via parent_session_id.
62
- */
63
- export declare class StructCallbackHandler {
64
- private readonly sdk;
65
- private readonly tracer;
66
- private readonly logger;
67
- readonly name = "struct";
68
- readonly lc_namespace: readonly string[];
69
- readonly lc_serializable = false;
70
- readonly awaitHandlers = false;
71
- readonly ignoreLLM = false;
72
- readonly ignoreChain = false;
73
- readonly ignoreAgent = false;
74
- readonly ignoreRetriever = false;
75
- readonly ignoreCustomEvent = true;
76
- /**
77
- * LangChain reads `raiseError` to decide whether a callback throw should
78
- * abort the user's run. We keep this `false` because every callback method
79
- * is wrapped in `safe()` and never throws — but a `true` here would tell
80
- * LangChain to surface our (impossible) throws into the user's call.
81
- * Locked by `test_handler_raiseError_is_false`.
82
- */
83
- readonly raiseError = false;
84
- private readonly runs;
85
- private readonly internalLogger;
86
- constructor(sdk: StructSDK, tracer: Tracer, logger: Logger | undefined);
87
- handleChainStart: (chain: Serialized, inputs: unknown, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string) => void;
88
- handleChainEnd: (_outputs: unknown, runId: string) => void;
89
- handleChainError: (err: Error, runId: string) => void;
90
- handleChatModelStart: (llm: Serialized, messages: UnknownMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
91
- handleLLMStart: (llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
92
- handleLLMEnd: (output: LLMResultLike, runId: string) => void;
93
- handleLLMError: (err: Error, runId: string) => void;
94
- handleToolStart: (tool: Serialized, input: string, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
95
- handleToolEnd: (output: unknown, runId: string) => void;
96
- handleToolError: (err: Error, runId: string) => void;
97
- handleRetrieverStart: (retriever: Serialized, query: string, runId: string, parentRunId?: string, _tags?: string[], metadata?: Record<string, unknown>, runName?: string) => void;
98
- handleRetrieverEnd: (documents: unknown[], runId: string) => void;
99
- handleRetrieverError: (err: Error, runId: string) => void;
100
- private resolveParent;
101
- /**
102
- * Conversation-id resolution for chat/tool/retriever spans — INHERIT from
103
- * the parent agent so everything rolls up under one gen_ai.conversation.id.
104
- */
105
- private resolveSessionId;
106
- /**
107
- * Walk the run tree to find the nearest ``invoke_agent`` ancestor's
108
- * gen_ai.conversation.id.
109
- *
110
- * The immediate ``parentRunId`` might be a tool, LLM, retriever, or a
111
- * filtered RunnableSequence — none of which are agents themselves. We
112
- * populate ``nearestAgentSessionId`` at each run's creation so any
113
- * descendant can read it in O(1).
114
- *
115
- * Used to set ``struct.agent.parent_session_id`` on nested ``invoke_agent``
116
- * spans (our UI's "Spawned by" / "Subagents" linkage).
117
- */
118
- private inheritedAgentSessionId;
119
- /**
120
- * Conversation-id resolution for AGENT spans — each agent invocation gets
121
- * its own gen_ai.conversation.id. We deliberately do NOT inherit from the
122
- * parent run, so subagents surface as separate entries in the sessions
123
- * list. Parent linkage is preserved via `struct.agent.parent_session_id`.
124
- *
125
- * LangChain inherits `metadata.thread_id` from the parent invoke's config
126
- * when a nested invoke runs inside it (even if the child config supplied
127
- * its own). We detect that inheritance by comparing against the parent's
128
- * resolved session and ignore the inherited value.
129
- */
130
- private resolveAgentSessionId;
131
- private propagateUserPrompt;
132
- }
133
- export {};
134
- //# sourceMappingURL=langchain-callback.d.ts.map