@struct-ai/sdk 0.1.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 (228) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +168 -0
  3. package/dist/commonjs/content-capture.d.ts +10 -0
  4. package/dist/commonjs/content-capture.js +23 -0
  5. package/dist/commonjs/context.d.ts +30 -0
  6. package/dist/commonjs/context.js +94 -0
  7. package/dist/commonjs/core.d.ts +120 -0
  8. package/dist/commonjs/core.js +408 -0
  9. package/dist/commonjs/events.d.ts +12 -0
  10. package/dist/commonjs/events.js +103 -0
  11. package/dist/commonjs/index.d.ts +6 -0
  12. package/dist/commonjs/index.js +10 -0
  13. package/dist/commonjs/integrations/anthropic-content.d.ts +24 -0
  14. package/dist/commonjs/integrations/anthropic-content.js +178 -0
  15. package/dist/commonjs/integrations/anthropic.d.ts +34 -0
  16. package/dist/commonjs/integrations/anthropic.js +377 -0
  17. package/dist/commonjs/integrations/index.d.ts +5 -0
  18. package/dist/commonjs/integrations/index.js +47 -0
  19. package/dist/commonjs/integrations/langchain-callback.d.ts +134 -0
  20. package/dist/commonjs/integrations/langchain-callback.js +723 -0
  21. package/dist/commonjs/integrations/langchain-content.d.ts +35 -0
  22. package/dist/commonjs/integrations/langchain-content.js +307 -0
  23. package/dist/commonjs/integrations/langchain.d.ts +11 -0
  24. package/dist/commonjs/integrations/langchain.js +100 -0
  25. package/dist/commonjs/package.json +3 -0
  26. package/dist/commonjs/semconv.d.ts +54 -0
  27. package/dist/commonjs/semconv.js +74 -0
  28. package/dist/commonjs/truncation.d.ts +10 -0
  29. package/dist/commonjs/truncation.js +103 -0
  30. package/dist/esm/content-capture.d.ts +10 -0
  31. package/dist/esm/content-capture.js +17 -0
  32. package/dist/esm/context.d.ts +30 -0
  33. package/dist/esm/context.js +80 -0
  34. package/dist/esm/core.d.ts +120 -0
  35. package/dist/esm/core.js +403 -0
  36. package/dist/esm/events.d.ts +12 -0
  37. package/dist/esm/events.js +99 -0
  38. package/dist/esm/index.d.ts +6 -0
  39. package/dist/esm/index.js +5 -0
  40. package/dist/esm/integrations/anthropic-content.d.ts +24 -0
  41. package/dist/esm/integrations/anthropic-content.js +168 -0
  42. package/dist/esm/integrations/anthropic.d.ts +34 -0
  43. package/dist/esm/integrations/anthropic.js +370 -0
  44. package/dist/esm/integrations/index.d.ts +5 -0
  45. package/dist/esm/integrations/index.js +42 -0
  46. package/dist/esm/integrations/langchain-callback.d.ts +134 -0
  47. package/dist/esm/integrations/langchain-callback.js +719 -0
  48. package/dist/esm/integrations/langchain-content.d.ts +35 -0
  49. package/dist/esm/integrations/langchain-content.js +294 -0
  50. package/dist/esm/integrations/langchain.d.ts +11 -0
  51. package/dist/esm/integrations/langchain.js +95 -0
  52. package/dist/esm/package.json +3 -0
  53. package/dist/esm/semconv.d.ts +54 -0
  54. package/dist/esm/semconv.js +71 -0
  55. package/dist/esm/truncation.d.ts +10 -0
  56. package/dist/esm/truncation.js +96 -0
  57. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/content-capture.d.ts +10 -0
  58. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/context.d.ts +30 -0
  59. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/core.d.ts +120 -0
  60. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/events.d.ts +12 -0
  61. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/index.d.ts +6 -0
  62. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic-content.d.ts +24 -0
  63. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/anthropic.d.ts +34 -0
  64. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/index.d.ts +5 -0
  65. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-callback.d.ts +134 -0
  66. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain-content.d.ts +35 -0
  67. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/integrations/langchain.d.ts +11 -0
  68. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +3 -0
  69. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/semconv.d.ts +54 -0
  70. package/dist/node_modules/@struct-ai/sdk/dist/commonjs/truncation.d.ts +10 -0
  71. package/dist/node_modules/@struct-ai/sdk/dist/esm/content-capture.d.ts +10 -0
  72. package/dist/node_modules/@struct-ai/sdk/dist/esm/context.d.ts +30 -0
  73. package/dist/node_modules/@struct-ai/sdk/dist/esm/core.d.ts +120 -0
  74. package/dist/node_modules/@struct-ai/sdk/dist/esm/events.d.ts +12 -0
  75. package/dist/node_modules/@struct-ai/sdk/dist/esm/index.d.ts +6 -0
  76. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic-content.d.ts +24 -0
  77. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/anthropic.d.ts +34 -0
  78. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/index.d.ts +5 -0
  79. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-callback.d.ts +134 -0
  80. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain-content.d.ts +35 -0
  81. package/dist/node_modules/@struct-ai/sdk/dist/esm/integrations/langchain.d.ts +11 -0
  82. package/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +3 -0
  83. package/dist/node_modules/@struct-ai/sdk/dist/esm/semconv.d.ts +54 -0
  84. package/dist/node_modules/@struct-ai/sdk/dist/esm/truncation.d.ts +10 -0
  85. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/commonjs/package.json +3 -0
  86. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/esm/package.json +3 -0
  87. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +100 -0
  88. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +103 -0
  89. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +118 -0
  90. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +916 -0
  91. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +188 -0
  92. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +96 -0
  93. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +91 -0
  94. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +96 -0
  95. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +108 -0
  96. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +105 -0
  97. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +100 -0
  98. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +109 -0
  99. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +100 -0
  100. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +76 -0
  101. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +140 -0
  102. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +89 -0
  103. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +81 -0
  104. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +120 -0
  105. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +239 -0
  106. package/dist/node_modules/@struct-ai/sdk/dist/node_modules/@struct-ai/sdk/package.json +100 -0
  107. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/core.d.ts +244 -0
  108. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/error.d.ts +54 -0
  109. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/index.d.ts +188 -0
  110. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/package.json +103 -0
  111. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/pagination.d.ts +26 -0
  112. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/resource.d.ts +6 -0
  113. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/streaming.d.ts +41 -0
  114. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/uploads.d.ts +75 -0
  115. package/dist/node_modules/@struct-ai/sdk/node_modules/@anthropic-ai/sdk/version.d.ts +2 -0
  116. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/experimental.d.ts +1 -0
  117. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/index.d.ts +1 -0
  118. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/anthropic/package.json +118 -0
  119. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/agents.d.ts +1 -0
  120. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/caches.d.ts +1 -0
  121. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/chat_history.d.ts +1 -0
  122. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/context.d.ts +1 -0
  123. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/documents.d.ts +1 -0
  124. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/embeddings.d.ts +1 -0
  125. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/example_selectors.d.ts +1 -0
  126. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/index.d.ts +1 -0
  127. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/indexing.d.ts +1 -0
  128. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/load.d.ts +1 -0
  129. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/memory.d.ts +1 -0
  130. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/messages.d.ts +1 -0
  131. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/output_parsers.d.ts +1 -0
  132. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/outputs.d.ts +1 -0
  133. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/package.json +916 -0
  134. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompt_values.d.ts +1 -0
  135. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/prompts.d.ts +1 -0
  136. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/retrievers.d.ts +1 -0
  137. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/runnables.d.ts +1 -0
  138. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/singletons.d.ts +1 -0
  139. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/stores.d.ts +1 -0
  140. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/structured_query.d.ts +1 -0
  141. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/tools.d.ts +1 -0
  142. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/core/vectorstores.d.ts +1 -0
  143. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/index.d.ts +1 -0
  144. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/package.json +188 -0
  145. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/prebuilt.d.ts +1 -0
  146. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/pregel.d.ts +1 -0
  147. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/remote.d.ts +1 -0
  148. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/web.d.ts +1 -0
  149. package/dist/node_modules/@struct-ai/sdk/node_modules/@langchain/langgraph/zod.d.ts +1 -0
  150. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api/package.json +96 -0
  151. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/api-logs/package.json +91 -0
  152. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/core/package.json +96 -0
  153. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-logs-otlp-proto/package.json +108 -0
  154. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/exporter-trace-otlp-proto/package.json +105 -0
  155. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/resources/package.json +100 -0
  156. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-logs/package.json +109 -0
  157. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-base/package.json +100 -0
  158. package/dist/node_modules/@struct-ai/sdk/node_modules/@opentelemetry/sdk-trace-node/package.json +76 -0
  159. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/assert.d.ts +1062 -0
  160. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/async_hooks.d.ts +605 -0
  161. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  162. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/buffer.d.ts +1936 -0
  163. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/child_process.d.ts +1475 -0
  164. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/cluster.d.ts +577 -0
  165. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/console.d.ts +452 -0
  166. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/constants.d.ts +21 -0
  167. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/crypto.d.ts +4590 -0
  168. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dgram.d.ts +597 -0
  169. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  170. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/dns.d.ts +871 -0
  171. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/domain.d.ts +170 -0
  172. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/events.d.ts +977 -0
  173. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/fs.d.ts +4375 -0
  174. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.d.ts +172 -0
  175. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  176. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http.d.ts +2049 -0
  177. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/http2.d.ts +2631 -0
  178. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/https.d.ts +578 -0
  179. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/index.d.ts +93 -0
  180. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  181. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/module.d.ts +539 -0
  182. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/net.d.ts +1031 -0
  183. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/os.d.ts +506 -0
  184. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/package.json +140 -0
  185. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/path.d.ts +200 -0
  186. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/perf_hooks.d.ts +961 -0
  187. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/process.d.ts +1961 -0
  188. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/punycode.d.ts +117 -0
  189. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/querystring.d.ts +152 -0
  190. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/readline.d.ts +589 -0
  191. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/repl.d.ts +430 -0
  192. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/sea.d.ts +153 -0
  193. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/stream.d.ts +1698 -0
  194. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/string_decoder.d.ts +67 -0
  195. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/test.d.ts +1787 -0
  196. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/timers.d.ts +286 -0
  197. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tls.d.ts +1259 -0
  198. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/trace_events.d.ts +197 -0
  199. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/tty.d.ts +208 -0
  200. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/url.d.ts +964 -0
  201. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/util.d.ts +2331 -0
  202. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/v8.d.ts +809 -0
  203. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/vm.d.ts +1001 -0
  204. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/wasi.d.ts +181 -0
  205. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/worker_threads.d.ts +715 -0
  206. package/dist/node_modules/@struct-ai/sdk/node_modules/@types/node/zlib.d.ts +598 -0
  207. package/dist/node_modules/@struct-ai/sdk/node_modules/nock/package.json +89 -0
  208. package/dist/node_modules/@struct-ai/sdk/node_modules/tshy/package.json +81 -0
  209. package/dist/node_modules/@struct-ai/sdk/node_modules/typescript/package.json +120 -0
  210. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/config.d.ts +3 -0
  211. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/coverage.d.ts +1 -0
  212. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/environments.d.ts +1 -0
  213. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/globals.d.ts +22 -0
  214. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/import-meta.d.ts +5 -0
  215. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/importMeta.d.ts +4 -0
  216. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/jsdom.d.ts +6 -0
  217. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/mocker.d.ts +1 -0
  218. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/node.d.ts +1 -0
  219. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-runtime-types.d.ts +6 -0
  220. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/optional-types.d.ts +7 -0
  221. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/package.json +239 -0
  222. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/reporters.d.ts +1 -0
  223. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/runners.d.ts +1 -0
  224. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/snapshot.d.ts +1 -0
  225. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/suite.d.ts +1 -0
  226. package/dist/node_modules/@struct-ai/sdk/node_modules/vitest/worker.d.ts +1 -0
  227. package/dist/node_modules/@struct-ai/sdk/package.json +100 -0
  228. package/package.json +100 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Struct
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # @struct-ai/sdk
2
+
3
+ Struct agent observability SDK for TypeScript/Node.js. Auto-instruments AI agent
4
+ frameworks — the Anthropic SDK and LangChain.js — and emits OpenTelemetry
5
+ traces + logs to [struct.ai](https://struct.ai) with zero config.
6
+
7
+ This is the TypeScript port of [`struct-sdk`](https://pypi.org/project/struct-sdk/)
8
+ (Python). Span names, attribute keys, and log event shapes are identical across
9
+ the two SDKs so the server processes both uniformly.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @struct-ai/sdk
15
+ # optional — the SDK auto-instruments these if present
16
+ npm install @anthropic-ai/sdk @langchain/core @langchain/langgraph
17
+ ```
18
+
19
+ Requires Node 18+.
20
+
21
+ ## Quickstart
22
+
23
+ ```ts
24
+ import { struct } from "@struct-ai/sdk";
25
+ // Initialize once, as early as possible in your process
26
+ struct.init({
27
+ ingestKey: process.env.STRUCT_INGEST_KEY!,
28
+ serviceName: "my-agent",
29
+ environment: "production",
30
+ });
31
+
32
+ // Use your agent code as normal — spans + log events are emitted automatically.
33
+ import Anthropic from "@anthropic-ai/sdk";
34
+ const client = new Anthropic();
35
+
36
+ await struct.agent({ name: "checkout" }, async () => {
37
+ const msg = await client.messages.create({
38
+ model: "claude-3-5-sonnet-20241022",
39
+ max_tokens: 1024,
40
+ messages: [{ role: "user", content: "plan my checkout flow" }],
41
+ });
42
+
43
+ // tool_call_id is auto-filled from the preceding Anthropic response
44
+ await struct.tool({ name: "search" }, async () => {
45
+ return await search(msg);
46
+ });
47
+ });
48
+ ```
49
+
50
+ ## What gets instrumented
51
+
52
+ | Library | Hook | Span type | Notes |
53
+ |---|---|---|---|
54
+ | `@anthropic-ai/sdk` | `Messages.prototype.create`, `.stream` | `chat {model}` | Cache-token accounting, streaming with tool-use reconstruction |
55
+ | `@anthropic-ai/bedrock-sdk`, `@anthropic-ai/vertex-sdk` | `Messages.prototype.*` | `chat {model}` | Best-effort, if installed |
56
+ | `@langchain/core` `BaseChatModel` | `.invoke`, `.stream` | `chat {model}` | Skipped when a provider-direct instrumentor is active (e.g. ChatAnthropic + Anthropic patch → single span) |
57
+ | `@langchain/core` `StructuredTool` | `.invoke` | `execute_tool {name}` | Extracts `tool_call_id` from LangChain ToolCall input or pending queue |
58
+ | `@langchain/core` `BaseRetriever` | `.invoke` | `retrieval {name}` | |
59
+ | `@langchain/langgraph` `Pregel` | `.invoke`, `.stream` | `invoke_agent {name}` | Covers `createReactAgent`, custom graphs. `thread_id` → `gen_ai.conversation.id` |
60
+
61
+ ## Content capture
62
+
63
+ The SDK supports four capture modes controlling how prompt/response content is emitted.
64
+
65
+ ```ts
66
+ import { struct, ContentCaptureMode } from "@struct-ai/sdk";
67
+ struct.init({
68
+ ingestKey: ...,
69
+ contentCapture: ContentCaptureMode.EventOnly, // default
70
+ // or ContentCaptureMode.None, SpanOnly, SpanAndEvent
71
+ });
72
+ ```
73
+
74
+ - **`EventOnly`** (default): per-message content lands on OTel log records
75
+ (`gen_ai.{user,assistant,system,tool}.message`, `gen_ai.choice`). Spans carry
76
+ metadata only.
77
+ - **`SpanOnly`**: content on span attributes (`gen_ai.input.messages`,
78
+ `gen_ai.output.messages`).
79
+ - **`SpanAndEvent`**: both.
80
+ - **`None`**: no content captured. Token counts, tool call IDs, finish reasons,
81
+ and other metadata still flow.
82
+
83
+ Set `captureContent: false` for the legacy bool API (equivalent to
84
+ `ContentCaptureMode.None`).
85
+
86
+ ## Manual scopes
87
+
88
+ `struct.agent()` and `struct.tool()` create `invoke_agent` and `execute_tool`
89
+ spans. These are optional — LangChain's Pregel patch creates agent spans
90
+ automatically when your graph has a `thread_id` in the config.
91
+
92
+ ```ts
93
+ await struct.agent(
94
+ { name: "onboarding", sessionId: conversationId, metadata: { tenant: "acme" } },
95
+ async () => {
96
+ await struct.tool({ name: "fetch-profile" }, async () => {
97
+ return fetchProfile();
98
+ });
99
+ }
100
+ );
101
+ ```
102
+
103
+ Nested agents set `struct.agent.parent_session_id` on the inner span, linking
104
+ subagents back to the parent.
105
+
106
+ ## Semantic conventions
107
+
108
+ Emits attributes per the OTel GenAI semantic conventions:
109
+
110
+ - `gen_ai.operation.name` — `chat`, `execute_tool`, `invoke_agent`, `retrieval`
111
+ - `gen_ai.provider.name` — `anthropic`, `openai`, `langchain`, `struct`, …
112
+ - `gen_ai.request.{model, max_tokens, temperature, top_p, top_k, stop_sequences}`
113
+ - `gen_ai.response.{model, id, finish_reasons}`
114
+ - `gen_ai.usage.{input_tokens, output_tokens, cache_read.input_tokens, cache_creation.input_tokens}`
115
+ - `gen_ai.conversation.id`
116
+ - `gen_ai.tool.{name, call.id, call.arguments, call.result}`
117
+ - `error.type` + `StatusCode.ERROR` on failures
118
+
119
+ Note: `gen_ai.usage.input_tokens` for Anthropic is the TRUE total — we add back
120
+ `cache_read_input_tokens + cache_creation_input_tokens` (which Anthropic's raw
121
+ response excludes). Matches the Python SDK.
122
+
123
+ ## Troubleshooting
124
+
125
+ - **Spans missing after instrumenting:** Import `@struct-ai/sdk` (or `struct.init()`)
126
+ *before* the instrumented libraries, so their class prototypes are patched
127
+ before any instance is constructed. In most Node setups this is automatic, but
128
+ some bundlers tree-shake aggressively.
129
+ - **No logs appearing:** `LogRecord`s only emit when `sdk.emitEvents` is true
130
+ (`EventOnly` or `SpanAndEvent` capture mode, which is the default). If you set
131
+ `captureContent: false` you disable them.
132
+ - **Duplicate chat spans:** The LangChain integration suppresses its own chat
133
+ span when a provider-direct patch is active (e.g. ChatAnthropic calls through
134
+ to `@anthropic-ai/sdk`, which emits its own `chat` span). If you see doubles,
135
+ confirm both integrations are auto-instrumenting (check `struct.initialized`).
136
+ - **Subagent in a different trace / missing from parent's "Subagents" list:**
137
+ If you invoke a nested agent (`subagent.invoke(...)`) from inside a tool body,
138
+ define the outer tool with `tool(func, { name, description, schema })` from
139
+ `@langchain/core/tools` — not `new DynamicTool({...})`. The `tool()` factory
140
+ wraps your function in `AsyncLocalStorageProviderSingleton.runWithConfig(...)`,
141
+ which is what lets the nested invoke inherit the tool's callback chain and
142
+ share the parent's trace_id. `DynamicTool` skips that wrap, so the subagent
143
+ starts a new trace and parent↔subagent linkage breaks. The `struct.agent.parent_session_id`
144
+ attribute is still set, so "Spawned by" on the child side still renders —
145
+ but the parent's forward link to the subagent won't appear.
146
+
147
+ ## Parity with the Python SDK
148
+
149
+ Span names, attribute keys, and log event shapes match `struct-sdk-python`
150
+ byte-for-byte. Running the same agent logic in both SDKs against the same
151
+ tenant produces structurally identical traces in the Struct UI.
152
+
153
+ One deliberate divergence: the TS SDK finalizes streaming chat spans via the
154
+ `finalMessage` event, closing a known gap in the Python SDK where
155
+ `messages.stream()` didn't populate the pending-tool-call queue.
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ pnpm install
161
+ pnpm -F @struct-ai/sdk typecheck
162
+ pnpm -F @struct-ai/sdk test
163
+ pnpm -F @struct-ai/sdk build
164
+ ```
165
+
166
+ ## License
167
+
168
+ Apache-2.0
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentCaptureMode = void 0;
4
+ exports.emitEventsFor = emitEventsFor;
5
+ exports.emitSpanContentFor = emitSpanContentFor;
6
+ exports.captureContentFor = captureContentFor;
7
+ var ContentCaptureMode;
8
+ (function (ContentCaptureMode) {
9
+ ContentCaptureMode["None"] = "none";
10
+ ContentCaptureMode["EventOnly"] = "event_only";
11
+ ContentCaptureMode["SpanOnly"] = "span_only";
12
+ ContentCaptureMode["SpanAndEvent"] = "span_and_event";
13
+ })(ContentCaptureMode || (exports.ContentCaptureMode = ContentCaptureMode = {}));
14
+ function emitEventsFor(mode) {
15
+ return mode === ContentCaptureMode.EventOnly || mode === ContentCaptureMode.SpanAndEvent;
16
+ }
17
+ function emitSpanContentFor(mode) {
18
+ return mode === ContentCaptureMode.SpanOnly || mode === ContentCaptureMode.SpanAndEvent;
19
+ }
20
+ function captureContentFor(mode) {
21
+ return mode !== ContentCaptureMode.None;
22
+ }
23
+ //# sourceMappingURL=content-capture.js.map
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStore = getStore;
4
+ exports.getSessionId = getSessionId;
5
+ exports.getConversationId = getConversationId;
6
+ exports.getAgentSpan = getAgentSpan;
7
+ exports.getPendingToolCalls = getPendingToolCalls;
8
+ exports.runWithContext = runWithContext;
9
+ exports.ensurePendingToolCallsSlot = ensurePendingToolCallsSlot;
10
+ exports.popPendingToolCallId = popPendingToolCallId;
11
+ exports.pushPendingToolCalls = pushPendingToolCalls;
12
+ exports.snapshotStore = snapshotStore;
13
+ exports.runWithStore = runWithStore;
14
+ exports.runInFreshContext = runInFreshContext;
15
+ const node_async_hooks_1 = require("node:async_hooks");
16
+ const als = new node_async_hooks_1.AsyncLocalStorage();
17
+ function getStore() {
18
+ return als.getStore();
19
+ }
20
+ function getSessionId() {
21
+ return als.getStore()?.sessionId;
22
+ }
23
+ function getConversationId() {
24
+ return als.getStore()?.conversationId;
25
+ }
26
+ function getAgentSpan() {
27
+ return als.getStore()?.agentSpan;
28
+ }
29
+ function getPendingToolCalls() {
30
+ return als.getStore()?.pendingToolCalls;
31
+ }
32
+ function runWithContext(patch, fn) {
33
+ const current = als.getStore() ?? {};
34
+ const next = { ...current, ...patch };
35
+ return als.run(next, fn);
36
+ }
37
+ function ensurePendingToolCallsSlot() {
38
+ const store = als.getStore();
39
+ if (store) {
40
+ if (!store.pendingToolCalls) {
41
+ store.pendingToolCalls = {};
42
+ }
43
+ return store.pendingToolCalls;
44
+ }
45
+ // No active store — nothing to attach to. Caller is expected to handle this.
46
+ return {};
47
+ }
48
+ /**
49
+ * Pop the first pending tool_use id matching `name`, or undefined.
50
+ * FIFO semantics match Python struct-sdk-python.
51
+ */
52
+ function popPendingToolCallId(name) {
53
+ const pending = getPendingToolCalls();
54
+ if (!pending)
55
+ return undefined;
56
+ const ids = pending[name];
57
+ if (!ids || ids.length === 0)
58
+ return undefined;
59
+ return ids.shift();
60
+ }
61
+ /**
62
+ * Push (name, id) pairs into the active pending-tool-calls slot.
63
+ * Initializes a transient dict if no active agent scope.
64
+ */
65
+ function pushPendingToolCalls(pairs) {
66
+ if (pairs.length === 0)
67
+ return;
68
+ const store = als.getStore();
69
+ if (!store)
70
+ return;
71
+ if (!store.pendingToolCalls) {
72
+ store.pendingToolCalls = {};
73
+ }
74
+ for (const [name, id] of pairs) {
75
+ if (!store.pendingToolCalls[name])
76
+ store.pendingToolCalls[name] = [];
77
+ store.pendingToolCalls[name].push(id);
78
+ }
79
+ }
80
+ /** Snapshot the store for wrapping async iterators. */
81
+ function snapshotStore() {
82
+ const store = als.getStore();
83
+ return store ? { ...store } : undefined;
84
+ }
85
+ function runWithStore(store, fn) {
86
+ if (!store)
87
+ return fn();
88
+ return als.run(store, fn);
89
+ }
90
+ /** Test-only: run `fn` inside a completely fresh context (no parent store). */
91
+ function runInFreshContext(fn) {
92
+ return als.run({}, fn);
93
+ }
94
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,120 @@
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