langchain 1.0.3 → 1.0.5

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 (431) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/agents/ReactAgent.cjs +15 -17
  3. package/dist/agents/ReactAgent.cjs.map +1 -1
  4. package/dist/agents/ReactAgent.d.cts +3 -3
  5. package/dist/agents/ReactAgent.d.cts.map +1 -1
  6. package/dist/agents/ReactAgent.d.ts +3 -3
  7. package/dist/agents/ReactAgent.d.ts.map +1 -1
  8. package/dist/agents/ReactAgent.js +15 -17
  9. package/dist/agents/ReactAgent.js.map +1 -1
  10. package/dist/agents/annotation.cjs +6 -4
  11. package/dist/agents/annotation.cjs.map +1 -1
  12. package/dist/agents/annotation.js +7 -5
  13. package/dist/agents/annotation.js.map +1 -1
  14. package/dist/agents/middleware/contextEditing.cjs +302 -33
  15. package/dist/agents/middleware/contextEditing.cjs.map +1 -1
  16. package/dist/agents/middleware/contextEditing.d.cts +125 -41
  17. package/dist/agents/middleware/contextEditing.d.cts.map +1 -1
  18. package/dist/agents/middleware/contextEditing.d.ts +125 -41
  19. package/dist/agents/middleware/contextEditing.d.ts.map +1 -1
  20. package/dist/agents/middleware/contextEditing.js +302 -33
  21. package/dist/agents/middleware/contextEditing.js.map +1 -1
  22. package/dist/agents/middleware/dynamicSystemPrompt.d.cts.map +1 -1
  23. package/dist/agents/middleware/dynamicSystemPrompt.d.ts.map +1 -1
  24. package/dist/agents/middleware/hitl.d.cts.map +1 -1
  25. package/dist/agents/middleware/hitl.d.ts.map +1 -1
  26. package/dist/agents/middleware/index.cjs +2 -0
  27. package/dist/agents/middleware/index.js +2 -0
  28. package/dist/agents/middleware/modelCallLimit.cjs +6 -2
  29. package/dist/agents/middleware/modelCallLimit.cjs.map +1 -1
  30. package/dist/agents/middleware/modelCallLimit.d.cts +8 -8
  31. package/dist/agents/middleware/modelCallLimit.d.cts.map +1 -1
  32. package/dist/agents/middleware/modelCallLimit.d.ts +8 -8
  33. package/dist/agents/middleware/modelCallLimit.d.ts.map +1 -1
  34. package/dist/agents/middleware/modelCallLimit.js +6 -2
  35. package/dist/agents/middleware/modelCallLimit.js.map +1 -1
  36. package/dist/agents/middleware/modelFallback.cjs +2 -2
  37. package/dist/agents/middleware/modelFallback.cjs.map +1 -1
  38. package/dist/agents/middleware/modelFallback.d.cts +2 -2
  39. package/dist/agents/middleware/modelFallback.d.cts.map +1 -1
  40. package/dist/agents/middleware/modelFallback.d.ts +2 -2
  41. package/dist/agents/middleware/modelFallback.d.ts.map +1 -1
  42. package/dist/agents/middleware/modelFallback.js +2 -2
  43. package/dist/agents/middleware/modelFallback.js.map +1 -1
  44. package/dist/agents/middleware/pii.cjs +445 -0
  45. package/dist/agents/middleware/pii.cjs.map +1 -0
  46. package/dist/agents/middleware/pii.d.cts +216 -0
  47. package/dist/agents/middleware/pii.d.cts.map +1 -0
  48. package/dist/agents/middleware/pii.d.ts +216 -0
  49. package/dist/agents/middleware/pii.d.ts.map +1 -0
  50. package/dist/agents/middleware/pii.js +436 -0
  51. package/dist/agents/middleware/pii.js.map +1 -0
  52. package/dist/agents/middleware/piiRedaction.cjs +2 -1
  53. package/dist/agents/middleware/piiRedaction.cjs.map +1 -1
  54. package/dist/agents/middleware/piiRedaction.d.cts +4 -1
  55. package/dist/agents/middleware/piiRedaction.d.cts.map +1 -1
  56. package/dist/agents/middleware/piiRedaction.d.ts +4 -1
  57. package/dist/agents/middleware/piiRedaction.d.ts.map +1 -1
  58. package/dist/agents/middleware/piiRedaction.js +2 -1
  59. package/dist/agents/middleware/piiRedaction.js.map +1 -1
  60. package/dist/agents/middleware/promptCaching.d.cts.map +1 -1
  61. package/dist/agents/middleware/promptCaching.d.ts.map +1 -1
  62. package/dist/agents/middleware/summarization.cjs +263 -52
  63. package/dist/agents/middleware/summarization.cjs.map +1 -1
  64. package/dist/agents/middleware/summarization.d.cts +384 -26
  65. package/dist/agents/middleware/summarization.d.cts.map +1 -1
  66. package/dist/agents/middleware/summarization.d.ts +384 -26
  67. package/dist/agents/middleware/summarization.d.ts.map +1 -1
  68. package/dist/agents/middleware/summarization.js +263 -55
  69. package/dist/agents/middleware/summarization.js.map +1 -1
  70. package/dist/agents/middleware/todoListMiddleware.d.cts.map +1 -1
  71. package/dist/agents/middleware/toolCallLimit.cjs +36 -27
  72. package/dist/agents/middleware/toolCallLimit.cjs.map +1 -1
  73. package/dist/agents/middleware/toolCallLimit.d.cts +3 -1
  74. package/dist/agents/middleware/toolCallLimit.d.cts.map +1 -1
  75. package/dist/agents/middleware/toolCallLimit.d.ts +3 -1
  76. package/dist/agents/middleware/toolCallLimit.d.ts.map +1 -1
  77. package/dist/agents/middleware/toolCallLimit.js +36 -27
  78. package/dist/agents/middleware/toolCallLimit.js.map +1 -1
  79. package/dist/agents/middleware/toolEmulator.cjs +118 -0
  80. package/dist/agents/middleware/toolEmulator.cjs.map +1 -0
  81. package/dist/agents/middleware/toolEmulator.d.cts +76 -0
  82. package/dist/agents/middleware/toolEmulator.d.cts.map +1 -0
  83. package/dist/agents/middleware/toolEmulator.d.ts +76 -0
  84. package/dist/agents/middleware/toolEmulator.d.ts.map +1 -0
  85. package/dist/agents/middleware/toolEmulator.js +117 -0
  86. package/dist/agents/middleware/toolEmulator.js.map +1 -0
  87. package/dist/agents/middleware/utils.cjs +4 -0
  88. package/dist/agents/middleware/utils.cjs.map +1 -1
  89. package/dist/agents/middleware/utils.d.cts.map +1 -1
  90. package/dist/agents/middleware/utils.d.ts.map +1 -1
  91. package/dist/agents/middleware/utils.js +4 -0
  92. package/dist/agents/middleware/utils.js.map +1 -1
  93. package/dist/agents/nodes/AgentNode.cjs +1 -5
  94. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  95. package/dist/agents/nodes/AgentNode.js +2 -6
  96. package/dist/agents/nodes/AgentNode.js.map +1 -1
  97. package/dist/agents/responses.cjs +0 -1
  98. package/dist/agents/responses.js +1 -1
  99. package/dist/agents/runtime.d.cts +5 -5
  100. package/dist/agents/runtime.d.cts.map +1 -1
  101. package/dist/agents/runtime.d.ts +5 -5
  102. package/dist/agents/runtime.d.ts.map +1 -1
  103. package/dist/index.cjs +22 -0
  104. package/dist/index.cjs.map +1 -1
  105. package/dist/index.d.cts +6 -4
  106. package/dist/index.d.ts +6 -4
  107. package/dist/index.js +13 -1
  108. package/dist/index.js.map +1 -1
  109. package/package.json +10 -9
  110. package/dist/agents/middleware/callLimit.cjs +0 -130
  111. package/dist/agents/middleware/callLimit.cjs.map +0 -1
  112. package/dist/agents/middleware/callLimit.d.cts +0 -119
  113. package/dist/agents/middleware/callLimit.d.cts.map +0 -1
  114. package/dist/agents/middleware/callLimit.d.ts +0 -119
  115. package/dist/agents/middleware/callLimit.d.ts.map +0 -1
  116. package/dist/agents/middleware/callLimit.js +0 -129
  117. package/dist/agents/middleware/callLimit.js.map +0 -1
  118. package/dist/agents/middleware/index.d.cts +0 -15
  119. package/dist/agents/middleware/index.d.ts +0 -14
  120. package/dist/agents/tools.d.cts +0 -9
  121. package/dist/agents/tools.d.cts.map +0 -1
  122. package/dist/agents/tools.d.ts +0 -9
  123. package/dist/agents/tools.d.ts.map +0 -1
  124. package/dist/embeddings/cache_backed.cjs +0 -140
  125. package/dist/embeddings/cache_backed.cjs.map +0 -1
  126. package/dist/embeddings/cache_backed.d.cts +0 -107
  127. package/dist/embeddings/cache_backed.d.cts.map +0 -1
  128. package/dist/embeddings/cache_backed.d.ts +0 -107
  129. package/dist/embeddings/cache_backed.d.ts.map +0 -1
  130. package/dist/embeddings/cache_backed.js +0 -134
  131. package/dist/embeddings/cache_backed.js.map +0 -1
  132. package/dist/embeddings/fake.cjs +0 -22
  133. package/dist/embeddings/fake.cjs.map +0 -1
  134. package/dist/embeddings/fake.d.cts +0 -1
  135. package/dist/embeddings/fake.d.ts +0 -1
  136. package/dist/embeddings/fake.js +0 -12
  137. package/dist/embeddings/fake.js.map +0 -1
  138. package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.cjs +0 -248
  139. package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.cjs.map +0 -1
  140. package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js +0 -244
  141. package/dist/node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js.map +0 -1
  142. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.cjs +0 -3096
  143. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.cjs.map +0 -1
  144. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.js +0 -3095
  145. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.js.map +0 -1
  146. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.cjs +0 -12
  147. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.cjs.map +0 -1
  148. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.js +0 -12
  149. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/env.js.map +0 -1
  150. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.cjs +0 -71
  151. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.cjs.map +0 -1
  152. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.js +0 -38
  153. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/constants.js.map +0 -1
  154. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.cjs +0 -221
  155. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.cjs.map +0 -1
  156. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.js +0 -221
  157. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/experimental/otel/translator.js.map +0 -1
  158. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.cjs +0 -11
  159. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.cjs.map +0 -1
  160. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.js +0 -11
  161. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/index.js.map +0 -1
  162. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.cjs +0 -703
  163. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.cjs.map +0 -1
  164. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.js +0 -702
  165. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/run_trees.js.map +0 -1
  166. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.cjs +0 -7
  167. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.cjs.map +0 -1
  168. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.js +0 -6
  169. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/constants.js.map +0 -1
  170. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.cjs +0 -29
  171. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.cjs.map +0 -1
  172. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.js +0 -28
  173. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/fetch.js.map +0 -1
  174. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.cjs +0 -115
  175. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.cjs.map +0 -1
  176. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.js +0 -113
  177. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/singletons/otel.js.map +0 -1
  178. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.cjs +0 -14
  179. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.cjs.map +0 -1
  180. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.js +0 -13
  181. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/_uuid.js.map +0 -1
  182. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.cjs +0 -95
  183. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.cjs.map +0 -1
  184. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.js +0 -95
  185. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/async_caller.js.map +0 -1
  186. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.cjs +0 -136
  187. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.cjs.map +0 -1
  188. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.js +0 -131
  189. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/env.js.map +0 -1
  190. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.cjs +0 -102
  191. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.cjs.map +0 -1
  192. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.js +0 -99
  193. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/error.js.map +0 -1
  194. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.cjs +0 -140
  195. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.cjs.map +0 -1
  196. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js +0 -140
  197. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/fast-safe-stringify/index.js.map +0 -1
  198. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.cjs +0 -18
  199. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.cjs.map +0 -1
  200. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.js +0 -16
  201. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/messages.js.map +0 -1
  202. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.cjs +0 -10
  203. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.cjs.map +0 -1
  204. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.js +0 -10
  205. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/project.js.map +0 -1
  206. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.cjs +0 -30
  207. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.cjs.map +0 -1
  208. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.js +0 -30
  209. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/prompts.js.map +0 -1
  210. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.cjs +0 -13
  211. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.cjs.map +0 -1
  212. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.js +0 -12
  213. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/utils/warn.js.map +0 -1
  214. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/index.cjs +0 -6
  215. package/dist/node_modules/.pnpm/langsmith@0.3.74_@opentelemetry_api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/index.js +0 -6
  216. package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.cjs +0 -27
  217. package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.cjs.map +0 -1
  218. package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js +0 -23
  219. package/dist/node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js.map +0 -1
  220. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.cjs +0 -267
  221. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.cjs.map +0 -1
  222. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js +0 -263
  223. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js.map +0 -1
  224. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.cjs +0 -32
  225. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.cjs.map +0 -1
  226. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js +0 -28
  227. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js.map +0 -1
  228. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.cjs +0 -49
  229. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.cjs.map +0 -1
  230. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js +0 -45
  231. package/dist/node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js.map +0 -1
  232. package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.cjs +0 -83
  233. package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.cjs.map +0 -1
  234. package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js +0 -79
  235. package/dist/node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js.map +0 -1
  236. package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.cjs +0 -52
  237. package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.cjs.map +0 -1
  238. package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js +0 -48
  239. package/dist/node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js.map +0 -1
  240. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.cjs +0 -16
  241. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.cjs.map +0 -1
  242. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js +0 -13
  243. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js.map +0 -1
  244. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.cjs +0 -77
  245. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.cjs.map +0 -1
  246. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js +0 -74
  247. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js.map +0 -1
  248. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.cjs +0 -115
  249. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.cjs.map +0 -1
  250. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js +0 -112
  251. package/dist/node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js.map +0 -1
  252. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.cjs +0 -90
  253. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.cjs.map +0 -1
  254. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.js +0 -86
  255. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/comparator.js.map +0 -1
  256. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.cjs +0 -294
  257. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.cjs.map +0 -1
  258. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.js +0 -290
  259. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/range.js.map +0 -1
  260. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.cjs +0 -191
  261. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.cjs.map +0 -1
  262. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.js +0 -187
  263. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/classes/semver.js.map +0 -1
  264. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.cjs +0 -24
  265. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.cjs.map +0 -1
  266. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js +0 -20
  267. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/clean.js.map +0 -1
  268. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.cjs +0 -51
  269. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.cjs.map +0 -1
  270. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.js +0 -47
  271. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/cmp.js.map +0 -1
  272. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.cjs +0 -48
  273. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.cjs.map +0 -1
  274. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.js +0 -44
  275. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/coerce.js.map +0 -1
  276. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.cjs +0 -25
  277. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.cjs.map +0 -1
  278. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js +0 -21
  279. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js.map +0 -1
  280. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.cjs +0 -21
  281. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.cjs.map +0 -1
  282. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js +0 -17
  283. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js.map +0 -1
  284. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.cjs +0 -21
  285. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.cjs.map +0 -1
  286. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js +0 -17
  287. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js.map +0 -1
  288. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.cjs +0 -43
  289. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.cjs.map +0 -1
  290. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.js +0 -39
  291. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/diff.js.map +0 -1
  292. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.cjs +0 -21
  293. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.cjs.map +0 -1
  294. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js +0 -17
  295. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js.map +0 -1
  296. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.cjs +0 -21
  297. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.cjs.map +0 -1
  298. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js +0 -17
  299. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js.map +0 -1
  300. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.cjs +0 -21
  301. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.cjs.map +0 -1
  302. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js +0 -17
  303. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js.map +0 -1
  304. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.cjs +0 -32
  305. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.cjs.map +0 -1
  306. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.js +0 -28
  307. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/inc.js.map +0 -1
  308. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.cjs +0 -21
  309. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.cjs.map +0 -1
  310. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js +0 -17
  311. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js.map +0 -1
  312. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.cjs +0 -21
  313. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.cjs.map +0 -1
  314. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js +0 -17
  315. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js.map +0 -1
  316. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.cjs +0 -21
  317. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.cjs.map +0 -1
  318. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.js +0 -17
  319. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/major.js.map +0 -1
  320. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.cjs +0 -21
  321. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.cjs.map +0 -1
  322. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.js +0 -17
  323. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/minor.js.map +0 -1
  324. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.cjs +0 -21
  325. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.cjs.map +0 -1
  326. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js +0 -17
  327. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js.map +0 -1
  328. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.cjs +0 -29
  329. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.cjs.map +0 -1
  330. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.js +0 -25
  331. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/parse.js.map +0 -1
  332. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.cjs +0 -21
  333. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.cjs.map +0 -1
  334. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.js +0 -17
  335. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/patch.js.map +0 -1
  336. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.cjs +0 -24
  337. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.cjs.map +0 -1
  338. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.js +0 -20
  339. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/prerelease.js.map +0 -1
  340. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.cjs +0 -21
  341. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.cjs.map +0 -1
  342. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js +0 -17
  343. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js.map +0 -1
  344. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.cjs +0 -21
  345. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.cjs.map +0 -1
  346. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js +0 -17
  347. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js.map +0 -1
  348. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.cjs +0 -28
  349. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.cjs.map +0 -1
  350. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.js +0 -24
  351. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/satisfies.js.map +0 -1
  352. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.cjs +0 -21
  353. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.cjs.map +0 -1
  354. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js +0 -17
  355. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js.map +0 -1
  356. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.cjs +0 -24
  357. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.cjs.map +0 -1
  358. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.js +0 -20
  359. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/valid.js.map +0 -1
  360. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.cjs +0 -146
  361. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.cjs.map +0 -1
  362. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js +0 -142
  363. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/index.js.map +0 -1
  364. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.cjs +0 -41
  365. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.cjs.map +0 -1
  366. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.js +0 -37
  367. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/constants.js.map +0 -1
  368. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.cjs +0 -19
  369. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.cjs.map +0 -1
  370. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.js +0 -15
  371. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/debug.js.map +0 -1
  372. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.cjs +0 -32
  373. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.cjs.map +0 -1
  374. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js +0 -28
  375. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js.map +0 -1
  376. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.cjs +0 -47
  377. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.cjs.map +0 -1
  378. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.js +0 -43
  379. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/lrucache.js.map +0 -1
  380. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.cjs +0 -25
  381. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.cjs.map +0 -1
  382. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.js +0 -21
  383. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/parse-options.js.map +0 -1
  384. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.cjs +0 -94
  385. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.cjs.map +0 -1
  386. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.js +0 -90
  387. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/re.js.map +0 -1
  388. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.cjs +0 -21
  389. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.cjs.map +0 -1
  390. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.js +0 -17
  391. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/gtr.js.map +0 -1
  392. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.cjs +0 -25
  393. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.cjs.map +0 -1
  394. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.js +0 -21
  395. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/intersects.js.map +0 -1
  396. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.cjs +0 -21
  397. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.cjs.map +0 -1
  398. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.js +0 -17
  399. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/ltr.js.map +0 -1
  400. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.cjs +0 -41
  401. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.cjs.map +0 -1
  402. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.js +0 -37
  403. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/max-satisfying.js.map +0 -1
  404. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.cjs +0 -41
  405. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.cjs.map +0 -1
  406. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.js +0 -37
  407. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-satisfying.js.map +0 -1
  408. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.cjs +0 -55
  409. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.cjs.map +0 -1
  410. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.js +0 -51
  411. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/min-version.js.map +0 -1
  412. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.cjs +0 -74
  413. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.cjs.map +0 -1
  414. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.js +0 -70
  415. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/outside.js.map +0 -1
  416. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.cjs +0 -48
  417. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.cjs.map +0 -1
  418. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.js +0 -44
  419. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/simplify.js.map +0 -1
  420. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.cjs +0 -112
  421. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.cjs.map +0 -1
  422. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.js +0 -108
  423. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/subset.js.map +0 -1
  424. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.cjs +0 -21
  425. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.cjs.map +0 -1
  426. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.js +0 -17
  427. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/to-comparators.js.map +0 -1
  428. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.cjs +0 -27
  429. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.cjs.map +0 -1
  430. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.js +0 -23
  431. package/dist/node_modules/.pnpm/semver@7.7.2/node_modules/semver/ranges/valid.js.map +0 -1
@@ -1,3096 +0,0 @@
1
- const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.cjs');
2
- const require_env = require('./utils/env.cjs');
3
- const require_otel = require('./singletons/otel.cjs');
4
- const require_translator = require('./experimental/otel/translator.cjs');
5
- const require_async_caller = require('./utils/async_caller.cjs');
6
- const require_messages = require('./utils/messages.cjs');
7
- const require__uuid = require('./utils/_uuid.cjs');
8
- const require_warn = require('./utils/warn.cjs');
9
- const require_prompts = require('./utils/prompts.cjs');
10
- const require_error = require('./utils/error.cjs');
11
- const require_fetch = require('./singletons/fetch.cjs');
12
- const require_index = require('./utils/fast-safe-stringify/index.cjs');
13
- const require_index$1 = require('./index.cjs');
14
- const uuid = require_rolldown_runtime.__toESM(require("uuid"));
15
-
16
- //#region ../../node_modules/.pnpm/langsmith@0.3.74_@opentelemetry+api@1.9.0_openai@5.12.2_ws@8.18.3_bufferutil@4.0.9_utf-8-validate@6.0.5__zod@3.25.76_/node_modules/langsmith/dist/client.js
17
- function mergeRuntimeEnvIntoRun(run, cachedEnvVars) {
18
- const runtimeEnv = require_env.getRuntimeEnvironment();
19
- const envVars = cachedEnvVars ?? require_env.getLangSmithEnvVarsMetadata();
20
- const extra = run.extra ?? {};
21
- const metadata = extra.metadata;
22
- run.extra = {
23
- ...extra,
24
- runtime: {
25
- ...runtimeEnv,
26
- ...extra?.runtime
27
- },
28
- metadata: {
29
- ...envVars,
30
- ...envVars.revision_id || "revision_id" in run && run.revision_id ? { revision_id: ("revision_id" in run ? run.revision_id : void 0) ?? envVars.revision_id } : {},
31
- ...metadata
32
- }
33
- };
34
- return run;
35
- }
36
- const getTracingSamplingRate = (configRate) => {
37
- const samplingRateStr = configRate?.toString() ?? require_env.getLangSmithEnvironmentVariable("TRACING_SAMPLING_RATE");
38
- if (samplingRateStr === void 0) return void 0;
39
- const samplingRate = parseFloat(samplingRateStr);
40
- if (samplingRate < 0 || samplingRate > 1) throw new Error(`LANGSMITH_TRACING_SAMPLING_RATE must be between 0 and 1 if set. Got: ${samplingRate}`);
41
- return samplingRate;
42
- };
43
- const isLocalhost = (url) => {
44
- const strippedUrl = url.replace("http://", "").replace("https://", "");
45
- const hostname = strippedUrl.split("/")[0].split(":")[0];
46
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
47
- };
48
- async function toArray(iterable) {
49
- const result = [];
50
- for await (const item of iterable) result.push(item);
51
- return result;
52
- }
53
- function trimQuotes(str) {
54
- if (str === void 0) return void 0;
55
- return str.trim().replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
56
- }
57
- const handle429 = async (response) => {
58
- if (response?.status === 429) {
59
- const retryAfter = parseInt(response.headers.get("retry-after") ?? "10", 10) * 1e3;
60
- if (retryAfter > 0) {
61
- await new Promise((resolve) => setTimeout(resolve, retryAfter));
62
- return true;
63
- }
64
- }
65
- return false;
66
- };
67
- function _formatFeedbackScore(score) {
68
- if (typeof score === "number") return Number(score.toFixed(4));
69
- return score;
70
- }
71
- var AutoBatchQueue = class {
72
- constructor() {
73
- Object.defineProperty(this, "items", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: []
78
- });
79
- Object.defineProperty(this, "sizeBytes", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: 0
84
- });
85
- }
86
- peek() {
87
- return this.items[0];
88
- }
89
- push(item) {
90
- let itemPromiseResolve;
91
- const itemPromise = new Promise((resolve) => {
92
- itemPromiseResolve = resolve;
93
- });
94
- const size = require_index.serialize(item.item, `Serializing run with id: ${item.item.id}`).length;
95
- this.items.push({
96
- action: item.action,
97
- payload: item.item,
98
- otelContext: item.otelContext,
99
- apiKey: item.apiKey,
100
- apiUrl: item.apiUrl,
101
- itemPromiseResolve,
102
- itemPromise,
103
- size
104
- });
105
- this.sizeBytes += size;
106
- return itemPromise;
107
- }
108
- pop({ upToSizeBytes, upToSize }) {
109
- if (upToSizeBytes < 1) throw new Error("Number of bytes to pop off may not be less than 1.");
110
- const popped = [];
111
- let poppedSizeBytes = 0;
112
- while (poppedSizeBytes + (this.peek()?.size ?? 0) < upToSizeBytes && this.items.length > 0 && popped.length < upToSize) {
113
- const item = this.items.shift();
114
- if (item) {
115
- popped.push(item);
116
- poppedSizeBytes += item.size;
117
- this.sizeBytes -= item.size;
118
- }
119
- }
120
- if (popped.length === 0 && this.items.length > 0) {
121
- const item = this.items.shift();
122
- popped.push(item);
123
- poppedSizeBytes += item.size;
124
- this.sizeBytes -= item.size;
125
- }
126
- return [popped.map((it) => ({
127
- action: it.action,
128
- item: it.payload,
129
- otelContext: it.otelContext,
130
- apiKey: it.apiKey,
131
- apiUrl: it.apiUrl
132
- })), () => popped.forEach((it) => it.itemPromiseResolve())];
133
- }
134
- };
135
- const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
136
- const SERVER_INFO_REQUEST_TIMEOUT_MS = 1e4;
137
- /** Maximum number of operations to batch in a single request. */
138
- const DEFAULT_BATCH_SIZE_LIMIT = 100;
139
- const DEFAULT_API_URL = "https://api.smith.langchain.com";
140
- var Client = class Client {
141
- get _fetch() {
142
- return this.fetchImplementation || require_fetch._getFetchImplementation(this.debug);
143
- }
144
- constructor(config = {}) {
145
- Object.defineProperty(this, "apiKey", {
146
- enumerable: true,
147
- configurable: true,
148
- writable: true,
149
- value: void 0
150
- });
151
- Object.defineProperty(this, "apiUrl", {
152
- enumerable: true,
153
- configurable: true,
154
- writable: true,
155
- value: void 0
156
- });
157
- Object.defineProperty(this, "webUrl", {
158
- enumerable: true,
159
- configurable: true,
160
- writable: true,
161
- value: void 0
162
- });
163
- Object.defineProperty(this, "workspaceId", {
164
- enumerable: true,
165
- configurable: true,
166
- writable: true,
167
- value: void 0
168
- });
169
- Object.defineProperty(this, "caller", {
170
- enumerable: true,
171
- configurable: true,
172
- writable: true,
173
- value: void 0
174
- });
175
- Object.defineProperty(this, "batchIngestCaller", {
176
- enumerable: true,
177
- configurable: true,
178
- writable: true,
179
- value: void 0
180
- });
181
- Object.defineProperty(this, "timeout_ms", {
182
- enumerable: true,
183
- configurable: true,
184
- writable: true,
185
- value: void 0
186
- });
187
- Object.defineProperty(this, "_tenantId", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: null
192
- });
193
- Object.defineProperty(this, "hideInputs", {
194
- enumerable: true,
195
- configurable: true,
196
- writable: true,
197
- value: void 0
198
- });
199
- Object.defineProperty(this, "hideOutputs", {
200
- enumerable: true,
201
- configurable: true,
202
- writable: true,
203
- value: void 0
204
- });
205
- Object.defineProperty(this, "tracingSampleRate", {
206
- enumerable: true,
207
- configurable: true,
208
- writable: true,
209
- value: void 0
210
- });
211
- Object.defineProperty(this, "filteredPostUuids", {
212
- enumerable: true,
213
- configurable: true,
214
- writable: true,
215
- value: /* @__PURE__ */ new Set()
216
- });
217
- Object.defineProperty(this, "autoBatchTracing", {
218
- enumerable: true,
219
- configurable: true,
220
- writable: true,
221
- value: true
222
- });
223
- Object.defineProperty(this, "autoBatchQueue", {
224
- enumerable: true,
225
- configurable: true,
226
- writable: true,
227
- value: new AutoBatchQueue()
228
- });
229
- Object.defineProperty(this, "autoBatchTimeout", {
230
- enumerable: true,
231
- configurable: true,
232
- writable: true,
233
- value: void 0
234
- });
235
- Object.defineProperty(this, "autoBatchAggregationDelayMs", {
236
- enumerable: true,
237
- configurable: true,
238
- writable: true,
239
- value: 250
240
- });
241
- Object.defineProperty(this, "batchSizeBytesLimit", {
242
- enumerable: true,
243
- configurable: true,
244
- writable: true,
245
- value: void 0
246
- });
247
- Object.defineProperty(this, "batchSizeLimit", {
248
- enumerable: true,
249
- configurable: true,
250
- writable: true,
251
- value: void 0
252
- });
253
- Object.defineProperty(this, "fetchOptions", {
254
- enumerable: true,
255
- configurable: true,
256
- writable: true,
257
- value: void 0
258
- });
259
- Object.defineProperty(this, "settings", {
260
- enumerable: true,
261
- configurable: true,
262
- writable: true,
263
- value: void 0
264
- });
265
- Object.defineProperty(this, "blockOnRootRunFinalization", {
266
- enumerable: true,
267
- configurable: true,
268
- writable: true,
269
- value: require_env.getEnvironmentVariable("LANGSMITH_TRACING_BACKGROUND") === "false"
270
- });
271
- Object.defineProperty(this, "traceBatchConcurrency", {
272
- enumerable: true,
273
- configurable: true,
274
- writable: true,
275
- value: 5
276
- });
277
- Object.defineProperty(this, "_serverInfo", {
278
- enumerable: true,
279
- configurable: true,
280
- writable: true,
281
- value: void 0
282
- });
283
- Object.defineProperty(this, "_getServerInfoPromise", {
284
- enumerable: true,
285
- configurable: true,
286
- writable: true,
287
- value: void 0
288
- });
289
- Object.defineProperty(this, "manualFlushMode", {
290
- enumerable: true,
291
- configurable: true,
292
- writable: true,
293
- value: false
294
- });
295
- Object.defineProperty(this, "langSmithToOTELTranslator", {
296
- enumerable: true,
297
- configurable: true,
298
- writable: true,
299
- value: void 0
300
- });
301
- Object.defineProperty(this, "fetchImplementation", {
302
- enumerable: true,
303
- configurable: true,
304
- writable: true,
305
- value: void 0
306
- });
307
- Object.defineProperty(this, "cachedLSEnvVarsForMetadata", {
308
- enumerable: true,
309
- configurable: true,
310
- writable: true,
311
- value: void 0
312
- });
313
- Object.defineProperty(this, "multipartStreamingDisabled", {
314
- enumerable: true,
315
- configurable: true,
316
- writable: true,
317
- value: false
318
- });
319
- Object.defineProperty(this, "debug", {
320
- enumerable: true,
321
- configurable: true,
322
- writable: true,
323
- value: require_env.getEnvironmentVariable("LANGSMITH_DEBUG") === "true"
324
- });
325
- const defaultConfig = Client.getDefaultClientConfig();
326
- this.tracingSampleRate = getTracingSamplingRate(config.tracingSamplingRate);
327
- this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
328
- if (this.apiUrl.endsWith("/")) this.apiUrl = this.apiUrl.slice(0, -1);
329
- this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
330
- this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
331
- if (this.webUrl?.endsWith("/")) this.webUrl = this.webUrl.slice(0, -1);
332
- this.workspaceId = trimQuotes(config.workspaceId ?? require_env.getLangSmithEnvironmentVariable("WORKSPACE_ID"));
333
- this.timeout_ms = config.timeout_ms ?? 9e4;
334
- this.caller = new require_async_caller.AsyncCaller({
335
- ...config.callerOptions ?? {},
336
- maxRetries: 4,
337
- debug: config.debug ?? this.debug
338
- });
339
- this.traceBatchConcurrency = config.traceBatchConcurrency ?? this.traceBatchConcurrency;
340
- if (this.traceBatchConcurrency < 1) throw new Error("Trace batch concurrency must be positive.");
341
- this.debug = config.debug ?? this.debug;
342
- this.fetchImplementation = config.fetchImplementation;
343
- this.batchIngestCaller = new require_async_caller.AsyncCaller({
344
- maxRetries: 2,
345
- maxConcurrency: this.traceBatchConcurrency,
346
- ...config.callerOptions ?? {},
347
- onFailedResponseHook: handle429,
348
- debug: config.debug ?? this.debug
349
- });
350
- this.hideInputs = config.hideInputs ?? config.anonymizer ?? defaultConfig.hideInputs;
351
- this.hideOutputs = config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
352
- this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
353
- this.blockOnRootRunFinalization = config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
354
- this.batchSizeBytesLimit = config.batchSizeBytesLimit;
355
- this.batchSizeLimit = config.batchSizeLimit;
356
- this.fetchOptions = config.fetchOptions || {};
357
- this.manualFlushMode = config.manualFlushMode ?? this.manualFlushMode;
358
- if (require_env.getOtelEnabled()) this.langSmithToOTELTranslator = new require_translator.LangSmithToOTELTranslator();
359
- this.cachedLSEnvVarsForMetadata = require_env.getLangSmithEnvVarsMetadata();
360
- }
361
- static getDefaultClientConfig() {
362
- const apiKey = require_env.getLangSmithEnvironmentVariable("API_KEY");
363
- const apiUrl = require_env.getLangSmithEnvironmentVariable("ENDPOINT") ?? DEFAULT_API_URL;
364
- const hideInputs = require_env.getLangSmithEnvironmentVariable("HIDE_INPUTS") === "true";
365
- const hideOutputs = require_env.getLangSmithEnvironmentVariable("HIDE_OUTPUTS") === "true";
366
- return {
367
- apiUrl,
368
- apiKey,
369
- webUrl: void 0,
370
- hideInputs,
371
- hideOutputs
372
- };
373
- }
374
- getHostUrl() {
375
- if (this.webUrl) return this.webUrl;
376
- else if (isLocalhost(this.apiUrl)) {
377
- this.webUrl = "http://localhost:3000";
378
- return this.webUrl;
379
- } else if (this.apiUrl.endsWith("/api/v1")) {
380
- this.webUrl = this.apiUrl.replace("/api/v1", "");
381
- return this.webUrl;
382
- } else if (this.apiUrl.includes("/api") && !this.apiUrl.split(".", 1)[0].endsWith("api")) {
383
- this.webUrl = this.apiUrl.replace("/api", "");
384
- return this.webUrl;
385
- } else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
386
- this.webUrl = "https://dev.smith.langchain.com";
387
- return this.webUrl;
388
- } else if (this.apiUrl.split(".", 1)[0].includes("eu")) {
389
- this.webUrl = "https://eu.smith.langchain.com";
390
- return this.webUrl;
391
- } else if (this.apiUrl.split(".", 1)[0].includes("beta")) {
392
- this.webUrl = "https://beta.smith.langchain.com";
393
- return this.webUrl;
394
- } else {
395
- this.webUrl = "https://smith.langchain.com";
396
- return this.webUrl;
397
- }
398
- }
399
- get headers() {
400
- const headers = { "User-Agent": `langsmith-js/${require_index$1.__version__}` };
401
- if (this.apiKey) headers["x-api-key"] = `${this.apiKey}`;
402
- if (this.workspaceId) headers["x-tenant-id"] = this.workspaceId;
403
- return headers;
404
- }
405
- _getPlatformEndpointPath(path) {
406
- const needsV1Prefix = this.apiUrl.slice(-3) !== "/v1" && this.apiUrl.slice(-4) !== "/v1/";
407
- return needsV1Prefix ? `/v1/platform/${path}` : `/platform/${path}`;
408
- }
409
- async processInputs(inputs) {
410
- if (this.hideInputs === false) return inputs;
411
- if (this.hideInputs === true) return {};
412
- if (typeof this.hideInputs === "function") return this.hideInputs(inputs);
413
- return inputs;
414
- }
415
- async processOutputs(outputs) {
416
- if (this.hideOutputs === false) return outputs;
417
- if (this.hideOutputs === true) return {};
418
- if (typeof this.hideOutputs === "function") return this.hideOutputs(outputs);
419
- return outputs;
420
- }
421
- async prepareRunCreateOrUpdateInputs(run) {
422
- const runParams = { ...run };
423
- if (runParams.inputs !== void 0) runParams.inputs = await this.processInputs(runParams.inputs);
424
- if (runParams.outputs !== void 0) runParams.outputs = await this.processOutputs(runParams.outputs);
425
- return runParams;
426
- }
427
- async _getResponse(path, queryParams) {
428
- const paramsString = queryParams?.toString() ?? "";
429
- const url = `${this.apiUrl}${path}?${paramsString}`;
430
- const response = await this.caller.call(async () => {
431
- const res = await this._fetch(url, {
432
- method: "GET",
433
- headers: this.headers,
434
- signal: AbortSignal.timeout(this.timeout_ms),
435
- ...this.fetchOptions
436
- });
437
- await require_error.raiseForStatus(res, `fetch ${path}`);
438
- return res;
439
- });
440
- return response;
441
- }
442
- async _get(path, queryParams) {
443
- const response = await this._getResponse(path, queryParams);
444
- return response.json();
445
- }
446
- async *_getPaginated(path, queryParams = new URLSearchParams(), transform) {
447
- let offset = Number(queryParams.get("offset")) || 0;
448
- const limit = Number(queryParams.get("limit")) || 100;
449
- while (true) {
450
- queryParams.set("offset", String(offset));
451
- queryParams.set("limit", String(limit));
452
- const url = `${this.apiUrl}${path}?${queryParams}`;
453
- const response = await this.caller.call(async () => {
454
- const res = await this._fetch(url, {
455
- method: "GET",
456
- headers: this.headers,
457
- signal: AbortSignal.timeout(this.timeout_ms),
458
- ...this.fetchOptions
459
- });
460
- await require_error.raiseForStatus(res, `fetch ${path}`);
461
- return res;
462
- });
463
- const items = transform ? transform(await response.json()) : await response.json();
464
- if (items.length === 0) break;
465
- yield items;
466
- if (items.length < limit) break;
467
- offset += items.length;
468
- }
469
- }
470
- async *_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
471
- const bodyParams = body ? { ...body } : {};
472
- while (true) {
473
- const body$1 = JSON.stringify(bodyParams);
474
- const response = await this.caller.call(async () => {
475
- const res = await this._fetch(`${this.apiUrl}${path}`, {
476
- method: requestMethod,
477
- headers: {
478
- ...this.headers,
479
- "Content-Type": "application/json"
480
- },
481
- signal: AbortSignal.timeout(this.timeout_ms),
482
- ...this.fetchOptions,
483
- body: body$1
484
- });
485
- await require_error.raiseForStatus(res, `fetch ${path}`);
486
- return res;
487
- });
488
- const responseBody = await response.json();
489
- if (!responseBody) break;
490
- if (!responseBody[dataKey]) break;
491
- yield responseBody[dataKey];
492
- const cursors = responseBody.cursors;
493
- if (!cursors) break;
494
- if (!cursors.next) break;
495
- bodyParams.cursor = cursors.next;
496
- }
497
- }
498
- _shouldSample() {
499
- if (this.tracingSampleRate === void 0) return true;
500
- return Math.random() < this.tracingSampleRate;
501
- }
502
- _filterForSampling(runs, patch = false) {
503
- if (this.tracingSampleRate === void 0) return runs;
504
- if (patch) {
505
- const sampled = [];
506
- for (const run of runs) if (!this.filteredPostUuids.has(run.trace_id)) sampled.push(run);
507
- else if (run.id === run.trace_id) this.filteredPostUuids.delete(run.trace_id);
508
- return sampled;
509
- } else {
510
- const sampled = [];
511
- for (const run of runs) {
512
- const traceId = run.trace_id ?? run.id;
513
- if (this.filteredPostUuids.has(traceId)) continue;
514
- if (run.id === traceId) if (this._shouldSample()) sampled.push(run);
515
- else this.filteredPostUuids.add(traceId);
516
- else sampled.push(run);
517
- }
518
- return sampled;
519
- }
520
- }
521
- async _getBatchSizeLimitBytes() {
522
- const serverInfo = await this._ensureServerInfo();
523
- return this.batchSizeBytesLimit ?? serverInfo.batch_ingest_config?.size_limit_bytes ?? DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES;
524
- }
525
- /**
526
- * Get the maximum number of operations to batch in a single request.
527
- */
528
- async _getBatchSizeLimit() {
529
- const serverInfo = await this._ensureServerInfo();
530
- return this.batchSizeLimit ?? serverInfo.batch_ingest_config?.size_limit ?? DEFAULT_BATCH_SIZE_LIMIT;
531
- }
532
- async _getDatasetExamplesMultiPartSupport() {
533
- const serverInfo = await this._ensureServerInfo();
534
- return serverInfo.instance_flags?.dataset_examples_multipart_enabled ?? false;
535
- }
536
- drainAutoBatchQueue({ batchSizeLimitBytes, batchSizeLimit }) {
537
- const promises = [];
538
- while (this.autoBatchQueue.items.length > 0) {
539
- const [batch, done] = this.autoBatchQueue.pop({
540
- upToSizeBytes: batchSizeLimitBytes,
541
- upToSize: batchSizeLimit
542
- });
543
- if (!batch.length) {
544
- done();
545
- break;
546
- }
547
- const batchesByDestination = batch.reduce((acc, item) => {
548
- const apiUrl = item.apiUrl ?? this.apiUrl;
549
- const apiKey = item.apiKey ?? this.apiKey;
550
- const isDefault = item.apiKey === this.apiKey && item.apiUrl === this.apiUrl;
551
- const batchKey = isDefault ? "default" : `${apiUrl}|${apiKey}`;
552
- if (!acc[batchKey]) acc[batchKey] = [];
553
- acc[batchKey].push(item);
554
- return acc;
555
- }, {});
556
- const batchPromises = [];
557
- for (const [batchKey, batch$1] of Object.entries(batchesByDestination)) {
558
- const batchPromise = this._processBatch(batch$1, {
559
- apiUrl: batchKey === "default" ? void 0 : batchKey.split("|")[0],
560
- apiKey: batchKey === "default" ? void 0 : batchKey.split("|")[1]
561
- });
562
- batchPromises.push(batchPromise);
563
- }
564
- const allBatchesPromise = Promise.all(batchPromises).finally(done);
565
- promises.push(allBatchesPromise);
566
- }
567
- return Promise.all(promises);
568
- }
569
- async _processBatch(batch, options) {
570
- if (!batch.length) return;
571
- try {
572
- if (this.langSmithToOTELTranslator !== void 0) this._sendBatchToOTELTranslator(batch);
573
- else {
574
- const ingestParams = {
575
- runCreates: batch.filter((item) => item.action === "create").map((item) => item.item),
576
- runUpdates: batch.filter((item) => item.action === "update").map((item) => item.item)
577
- };
578
- const serverInfo = await this._ensureServerInfo();
579
- if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
580
- const useGzip = serverInfo?.instance_flags?.gzip_body_enabled;
581
- await this.multipartIngestRuns(ingestParams, {
582
- ...options,
583
- useGzip
584
- });
585
- } else await this.batchIngestRuns(ingestParams, options);
586
- }
587
- } catch (e) {
588
- console.error("Error exporting batch:", e);
589
- }
590
- }
591
- _sendBatchToOTELTranslator(batch) {
592
- if (this.langSmithToOTELTranslator !== void 0) {
593
- const otelContextMap = /* @__PURE__ */ new Map();
594
- const operations = [];
595
- for (const item of batch) if (item.item.id && item.otelContext) {
596
- otelContextMap.set(item.item.id, item.otelContext);
597
- if (item.action === "create") operations.push({
598
- operation: "post",
599
- id: item.item.id,
600
- trace_id: item.item.trace_id ?? item.item.id,
601
- run: item.item
602
- });
603
- else operations.push({
604
- operation: "patch",
605
- id: item.item.id,
606
- trace_id: item.item.trace_id ?? item.item.id,
607
- run: item.item
608
- });
609
- }
610
- this.langSmithToOTELTranslator.exportBatch(operations, otelContextMap);
611
- }
612
- }
613
- async processRunOperation(item) {
614
- clearTimeout(this.autoBatchTimeout);
615
- this.autoBatchTimeout = void 0;
616
- item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata);
617
- const itemPromise = this.autoBatchQueue.push(item);
618
- if (this.manualFlushMode) return itemPromise;
619
- const sizeLimitBytes = await this._getBatchSizeLimitBytes();
620
- const sizeLimit = await this._getBatchSizeLimit();
621
- if (this.autoBatchQueue.sizeBytes > sizeLimitBytes || this.autoBatchQueue.items.length > sizeLimit) this.drainAutoBatchQueue({
622
- batchSizeLimitBytes: sizeLimitBytes,
623
- batchSizeLimit: sizeLimit
624
- });
625
- if (this.autoBatchQueue.items.length > 0) this.autoBatchTimeout = setTimeout(() => {
626
- this.autoBatchTimeout = void 0;
627
- this.drainAutoBatchQueue({
628
- batchSizeLimitBytes: sizeLimitBytes,
629
- batchSizeLimit: sizeLimit
630
- });
631
- }, this.autoBatchAggregationDelayMs);
632
- return itemPromise;
633
- }
634
- async _getServerInfo() {
635
- const response = await this.caller.call(async () => {
636
- const res = await this._fetch(`${this.apiUrl}/info`, {
637
- method: "GET",
638
- headers: { Accept: "application/json" },
639
- signal: AbortSignal.timeout(SERVER_INFO_REQUEST_TIMEOUT_MS),
640
- ...this.fetchOptions
641
- });
642
- await require_error.raiseForStatus(res, "get server info");
643
- return res;
644
- });
645
- const json = await response.json();
646
- if (this.debug) console.log("\n=== LangSmith Server Configuration ===\n" + JSON.stringify(json, null, 2) + "\n");
647
- return json;
648
- }
649
- async _ensureServerInfo() {
650
- if (this._getServerInfoPromise === void 0) this._getServerInfoPromise = (async () => {
651
- if (this._serverInfo === void 0) try {
652
- this._serverInfo = await this._getServerInfo();
653
- } catch (e) {
654
- console.warn(`[LANGSMITH]: Failed to fetch info on supported operations. Falling back to batch operations and default limits. Info: ${e.status ?? "Unspecified status code"} ${e.message}`);
655
- }
656
- return this._serverInfo ?? {};
657
- })();
658
- return this._getServerInfoPromise.then((serverInfo) => {
659
- if (this._serverInfo === void 0) this._getServerInfoPromise = void 0;
660
- return serverInfo;
661
- });
662
- }
663
- async _getSettings() {
664
- if (!this.settings) this.settings = this._get("/settings");
665
- return await this.settings;
666
- }
667
- /**
668
- * Flushes current queued traces.
669
- */
670
- async flush() {
671
- const sizeLimitBytes = await this._getBatchSizeLimitBytes();
672
- const sizeLimit = await this._getBatchSizeLimit();
673
- await this.drainAutoBatchQueue({
674
- batchSizeLimitBytes: sizeLimitBytes,
675
- batchSizeLimit: sizeLimit
676
- });
677
- }
678
- _cloneCurrentOTELContext() {
679
- const otel_trace = require_otel.getOTELTrace();
680
- const otel_context = require_otel.getOTELContext();
681
- if (this.langSmithToOTELTranslator !== void 0) {
682
- const currentSpan = otel_trace.getActiveSpan();
683
- if (currentSpan) return otel_trace.setSpan(otel_context.active(), currentSpan);
684
- }
685
- return void 0;
686
- }
687
- async createRun(run, options) {
688
- if (!this._filterForSampling([run]).length) return;
689
- const headers = {
690
- ...this.headers,
691
- "Content-Type": "application/json"
692
- };
693
- const session_name = run.project_name;
694
- delete run.project_name;
695
- const runCreate = await this.prepareRunCreateOrUpdateInputs({
696
- session_name,
697
- ...run,
698
- start_time: run.start_time ?? Date.now()
699
- });
700
- if (this.autoBatchTracing && runCreate.trace_id !== void 0 && runCreate.dotted_order !== void 0) {
701
- const otelContext = this._cloneCurrentOTELContext();
702
- this.processRunOperation({
703
- action: "create",
704
- item: runCreate,
705
- otelContext,
706
- apiKey: options?.apiKey,
707
- apiUrl: options?.apiUrl
708
- }).catch(console.error);
709
- return;
710
- }
711
- const mergedRunCreateParam = mergeRuntimeEnvIntoRun(runCreate, this.cachedLSEnvVarsForMetadata);
712
- if (options?.apiKey !== void 0) headers["x-api-key"] = options.apiKey;
713
- if (options?.workspaceId !== void 0) headers["x-tenant-id"] = options.workspaceId;
714
- const body = require_index.serialize(mergedRunCreateParam, `Creating run with id: ${mergedRunCreateParam.id}`);
715
- await this.caller.call(async () => {
716
- const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs`, {
717
- method: "POST",
718
- headers,
719
- signal: AbortSignal.timeout(this.timeout_ms),
720
- ...this.fetchOptions,
721
- body
722
- });
723
- await require_error.raiseForStatus(res, "create run", true);
724
- return res;
725
- });
726
- }
727
- /**
728
- * Batch ingest/upsert multiple runs in the Langsmith system.
729
- * @param runs
730
- */
731
- async batchIngestRuns({ runCreates, runUpdates }, options) {
732
- if (runCreates === void 0 && runUpdates === void 0) return;
733
- let preparedCreateParams = await Promise.all(runCreates?.map((create) => this.prepareRunCreateOrUpdateInputs(create)) ?? []);
734
- let preparedUpdateParams = await Promise.all(runUpdates?.map((update) => this.prepareRunCreateOrUpdateInputs(update)) ?? []);
735
- if (preparedCreateParams.length > 0 && preparedUpdateParams.length > 0) {
736
- const createById = preparedCreateParams.reduce((params, run) => {
737
- if (!run.id) return params;
738
- params[run.id] = run;
739
- return params;
740
- }, {});
741
- const standaloneUpdates = [];
742
- for (const updateParam of preparedUpdateParams) if (updateParam.id !== void 0 && createById[updateParam.id]) createById[updateParam.id] = {
743
- ...createById[updateParam.id],
744
- ...updateParam
745
- };
746
- else standaloneUpdates.push(updateParam);
747
- preparedCreateParams = Object.values(createById);
748
- preparedUpdateParams = standaloneUpdates;
749
- }
750
- const rawBatch = {
751
- post: preparedCreateParams,
752
- patch: preparedUpdateParams
753
- };
754
- if (!rawBatch.post.length && !rawBatch.patch.length) return;
755
- const batchChunks = {
756
- post: [],
757
- patch: []
758
- };
759
- for (const k of ["post", "patch"]) {
760
- const key = k;
761
- const batchItems = rawBatch[key].reverse();
762
- let batchItem = batchItems.pop();
763
- while (batchItem !== void 0) {
764
- batchChunks[key].push(batchItem);
765
- batchItem = batchItems.pop();
766
- }
767
- }
768
- if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
769
- const runIds = batchChunks.post.map((item) => item.id).concat(batchChunks.patch.map((item) => item.id)).join(",");
770
- await this._postBatchIngestRuns(require_index.serialize(batchChunks, `Ingesting runs with ids: ${runIds}`), options);
771
- }
772
- }
773
- async _postBatchIngestRuns(body, options) {
774
- const headers = {
775
- ...this.headers,
776
- "Content-Type": "application/json",
777
- Accept: "application/json"
778
- };
779
- if (options?.apiKey !== void 0) headers["x-api-key"] = options.apiKey;
780
- await this.batchIngestCaller.call(async () => {
781
- const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/batch`, {
782
- method: "POST",
783
- headers,
784
- signal: AbortSignal.timeout(this.timeout_ms),
785
- ...this.fetchOptions,
786
- body
787
- });
788
- await require_error.raiseForStatus(res, "batch create run", true);
789
- return res;
790
- });
791
- }
792
- /**
793
- * Batch ingest/upsert multiple runs in the Langsmith system.
794
- * @param runs
795
- */
796
- async multipartIngestRuns({ runCreates, runUpdates }, options) {
797
- if (runCreates === void 0 && runUpdates === void 0) return;
798
- const allAttachments = {};
799
- let preparedCreateParams = [];
800
- for (const create of runCreates ?? []) {
801
- const preparedCreate = await this.prepareRunCreateOrUpdateInputs(create);
802
- if (preparedCreate.id !== void 0 && preparedCreate.attachments !== void 0) allAttachments[preparedCreate.id] = preparedCreate.attachments;
803
- delete preparedCreate.attachments;
804
- preparedCreateParams.push(preparedCreate);
805
- }
806
- let preparedUpdateParams = [];
807
- for (const update of runUpdates ?? []) preparedUpdateParams.push(await this.prepareRunCreateOrUpdateInputs(update));
808
- const invalidRunCreate = preparedCreateParams.find((runCreate) => {
809
- return runCreate.trace_id === void 0 || runCreate.dotted_order === void 0;
810
- });
811
- if (invalidRunCreate !== void 0) throw new Error(`Multipart ingest requires "trace_id" and "dotted_order" to be set when creating a run`);
812
- const invalidRunUpdate = preparedUpdateParams.find((runUpdate) => {
813
- return runUpdate.trace_id === void 0 || runUpdate.dotted_order === void 0;
814
- });
815
- if (invalidRunUpdate !== void 0) throw new Error(`Multipart ingest requires "trace_id" and "dotted_order" to be set when updating a run`);
816
- if (preparedCreateParams.length > 0 && preparedUpdateParams.length > 0) {
817
- const createById = preparedCreateParams.reduce((params, run) => {
818
- if (!run.id) return params;
819
- params[run.id] = run;
820
- return params;
821
- }, {});
822
- const standaloneUpdates = [];
823
- for (const updateParam of preparedUpdateParams) if (updateParam.id !== void 0 && createById[updateParam.id]) createById[updateParam.id] = {
824
- ...createById[updateParam.id],
825
- ...updateParam
826
- };
827
- else standaloneUpdates.push(updateParam);
828
- preparedCreateParams = Object.values(createById);
829
- preparedUpdateParams = standaloneUpdates;
830
- }
831
- if (preparedCreateParams.length === 0 && preparedUpdateParams.length === 0) return;
832
- const accumulatedContext = [];
833
- const accumulatedParts = [];
834
- for (const [method, payloads] of [["post", preparedCreateParams], ["patch", preparedUpdateParams]]) for (const originalPayload of payloads) {
835
- const { inputs, outputs, events, extra, error, serialized, attachments,...payload } = originalPayload;
836
- const fields = {
837
- inputs,
838
- outputs,
839
- events,
840
- extra,
841
- error,
842
- serialized
843
- };
844
- const stringifiedPayload = require_index.serialize(payload, `Serializing for multipart ingestion of run with id: ${payload.id}`);
845
- accumulatedParts.push({
846
- name: `${method}.${payload.id}`,
847
- payload: new Blob([stringifiedPayload], { type: `application/json; length=${stringifiedPayload.length}` })
848
- });
849
- for (const [key, value] of Object.entries(fields)) {
850
- if (value === void 0) continue;
851
- const stringifiedValue = require_index.serialize(value, `Serializing ${key} for multipart ingestion of run with id: ${payload.id}`);
852
- accumulatedParts.push({
853
- name: `${method}.${payload.id}.${key}`,
854
- payload: new Blob([stringifiedValue], { type: `application/json; length=${stringifiedValue.length}` })
855
- });
856
- }
857
- if (payload.id !== void 0) {
858
- const attachments$1 = allAttachments[payload.id];
859
- if (attachments$1) {
860
- delete allAttachments[payload.id];
861
- for (const [name, attachment] of Object.entries(attachments$1)) {
862
- let contentType;
863
- let content;
864
- if (Array.isArray(attachment)) [contentType, content] = attachment;
865
- else {
866
- contentType = attachment.mimeType;
867
- content = attachment.data;
868
- }
869
- if (name.includes(".")) {
870
- console.warn(`Skipping attachment '${name}' for run ${payload.id}: Invalid attachment name. Attachment names must not contain periods ('.'). Please rename the attachment and try again.`);
871
- continue;
872
- }
873
- accumulatedParts.push({
874
- name: `attachment.${payload.id}.${name}`,
875
- payload: new Blob([content], { type: `${contentType}; length=${content.byteLength}` })
876
- });
877
- }
878
- }
879
- }
880
- accumulatedContext.push(`trace=${payload.trace_id},id=${payload.id}`);
881
- }
882
- await this._sendMultipartRequest(accumulatedParts, accumulatedContext.join("; "), options);
883
- }
884
- async _createNodeFetchBody(parts, boundary) {
885
- const chunks = [];
886
- for (const part of parts) {
887
- chunks.push(new Blob([`--${boundary}\r\n`]));
888
- chunks.push(new Blob([`Content-Disposition: form-data; name="${part.name}"\r\n`, `Content-Type: ${part.payload.type}\r\n\r\n`]));
889
- chunks.push(part.payload);
890
- chunks.push(new Blob(["\r\n"]));
891
- }
892
- chunks.push(new Blob([`--${boundary}--\r\n`]));
893
- const body = new Blob(chunks);
894
- const arrayBuffer = await body.arrayBuffer();
895
- return arrayBuffer;
896
- }
897
- async _createMultipartStream(parts, boundary) {
898
- const encoder = new TextEncoder();
899
- const stream = new ReadableStream({ async start(controller) {
900
- const writeChunk = async (chunk) => {
901
- if (typeof chunk === "string") controller.enqueue(encoder.encode(chunk));
902
- else controller.enqueue(chunk);
903
- };
904
- for (const part of parts) {
905
- await writeChunk(`--${boundary}\r\n`);
906
- await writeChunk(`Content-Disposition: form-data; name="${part.name}"\r\n`);
907
- await writeChunk(`Content-Type: ${part.payload.type}\r\n\r\n`);
908
- const payloadStream = part.payload.stream();
909
- const reader = payloadStream.getReader();
910
- try {
911
- let result;
912
- while (!(result = await reader.read()).done) controller.enqueue(result.value);
913
- } finally {
914
- reader.releaseLock();
915
- }
916
- await writeChunk("\r\n");
917
- }
918
- await writeChunk(`--${boundary}--\r\n`);
919
- controller.close();
920
- } });
921
- return stream;
922
- }
923
- async _sendMultipartRequest(parts, context, options) {
924
- const boundary = "----LangSmithFormBoundary" + Math.random().toString(36).slice(2);
925
- const isNodeFetch = require_fetch._globalFetchImplementationIsNodeFetch();
926
- const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
927
- const buildStream = () => this._createMultipartStream(parts, boundary);
928
- const sendWithRetry = async (bodyFactory) => {
929
- return this.batchIngestCaller.call(async () => {
930
- const body = await bodyFactory();
931
- const headers = {
932
- ...this.headers,
933
- "Content-Type": `multipart/form-data; boundary=${boundary}`
934
- };
935
- if (options?.apiKey !== void 0) headers["x-api-key"] = options.apiKey;
936
- let transformedBody = body;
937
- if (options?.useGzip && typeof body === "object" && "pipeThrough" in body) {
938
- transformedBody = body.pipeThrough(new CompressionStream("gzip"));
939
- headers["Content-Encoding"] = "gzip";
940
- }
941
- const response = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
942
- method: "POST",
943
- headers,
944
- body: transformedBody,
945
- duplex: "half",
946
- signal: AbortSignal.timeout(this.timeout_ms),
947
- ...this.fetchOptions
948
- });
949
- await require_error.raiseForStatus(response, `Failed to send multipart request`, true);
950
- return response;
951
- });
952
- };
953
- try {
954
- let res;
955
- let streamedAttempt = false;
956
- if (!isNodeFetch && !this.multipartStreamingDisabled && require_env.getEnv() !== "bun") {
957
- streamedAttempt = true;
958
- res = await sendWithRetry(buildStream);
959
- } else res = await sendWithRetry(buildBuffered);
960
- if ((!this.multipartStreamingDisabled || streamedAttempt) && res.status === 422 && (options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
961
- console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. This usually means the host does not support chunked uploads. Retrying with a buffered upload for operation "${context}".`);
962
- this.multipartStreamingDisabled = true;
963
- res = await sendWithRetry(buildBuffered);
964
- }
965
- } catch (e) {
966
- console.warn(`${e.message.trim()}\n\nContext: ${context}`);
967
- }
968
- }
969
- async updateRun(runId, run, options) {
970
- require__uuid.assertUuid(runId);
971
- if (run.inputs) run.inputs = await this.processInputs(run.inputs);
972
- if (run.outputs) run.outputs = await this.processOutputs(run.outputs);
973
- const data = {
974
- ...run,
975
- id: runId
976
- };
977
- if (!this._filterForSampling([data], true).length) return;
978
- if (this.autoBatchTracing && data.trace_id !== void 0 && data.dotted_order !== void 0) {
979
- const otelContext = this._cloneCurrentOTELContext();
980
- if (run.end_time !== void 0 && data.parent_run_id === void 0 && this.blockOnRootRunFinalization && !this.manualFlushMode) {
981
- await this.processRunOperation({
982
- action: "update",
983
- item: data,
984
- otelContext,
985
- apiKey: options?.apiKey,
986
- apiUrl: options?.apiUrl
987
- }).catch(console.error);
988
- return;
989
- } else this.processRunOperation({
990
- action: "update",
991
- item: data,
992
- otelContext,
993
- apiKey: options?.apiKey,
994
- apiUrl: options?.apiUrl
995
- }).catch(console.error);
996
- return;
997
- }
998
- const headers = {
999
- ...this.headers,
1000
- "Content-Type": "application/json"
1001
- };
1002
- if (options?.apiKey !== void 0) headers["x-api-key"] = options.apiKey;
1003
- if (options?.workspaceId !== void 0) headers["x-tenant-id"] = options.workspaceId;
1004
- const body = require_index.serialize(run, `Serializing payload to update run with id: ${runId}`);
1005
- await this.caller.call(async () => {
1006
- const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
1007
- method: "PATCH",
1008
- headers,
1009
- signal: AbortSignal.timeout(this.timeout_ms),
1010
- ...this.fetchOptions,
1011
- body
1012
- });
1013
- await require_error.raiseForStatus(res, "update run", true);
1014
- return res;
1015
- });
1016
- }
1017
- async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
1018
- require__uuid.assertUuid(runId);
1019
- let run = await this._get(`/runs/${runId}`);
1020
- if (loadChildRuns) run = await this._loadChildRuns(run);
1021
- return run;
1022
- }
1023
- async getRunUrl({ runId, run, projectOpts }) {
1024
- if (run !== void 0) {
1025
- let sessionId;
1026
- if (run.session_id) sessionId = run.session_id;
1027
- else if (projectOpts?.projectName) sessionId = (await this.readProject({ projectName: projectOpts?.projectName })).id;
1028
- else if (projectOpts?.projectId) sessionId = projectOpts?.projectId;
1029
- else {
1030
- const project = await this.readProject({ projectName: require_env.getLangSmithEnvironmentVariable("PROJECT") || "default" });
1031
- sessionId = project.id;
1032
- }
1033
- const tenantId = await this._getTenantId();
1034
- return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
1035
- } else if (runId !== void 0) {
1036
- const run_ = await this.readRun(runId);
1037
- if (!run_.app_path) throw new Error(`Run ${runId} has no app_path`);
1038
- const baseUrl = this.getHostUrl();
1039
- return `${baseUrl}${run_.app_path}`;
1040
- } else throw new Error("Must provide either runId or run");
1041
- }
1042
- async _loadChildRuns(run) {
1043
- const childRuns = await toArray(this.listRuns({
1044
- isRoot: false,
1045
- projectId: run.session_id,
1046
- traceId: run.trace_id
1047
- }));
1048
- const treemap = {};
1049
- const runs = {};
1050
- childRuns.sort((a, b) => (a?.dotted_order ?? "").localeCompare(b?.dotted_order ?? ""));
1051
- for (const childRun of childRuns) {
1052
- if (childRun.parent_run_id === null || childRun.parent_run_id === void 0) throw new Error(`Child run ${childRun.id} has no parent`);
1053
- if (childRun.dotted_order?.startsWith(run.dotted_order ?? "") && childRun.id !== run.id) {
1054
- if (!(childRun.parent_run_id in treemap)) treemap[childRun.parent_run_id] = [];
1055
- treemap[childRun.parent_run_id].push(childRun);
1056
- runs[childRun.id] = childRun;
1057
- }
1058
- }
1059
- run.child_runs = treemap[run.id] || [];
1060
- for (const runId in treemap) if (runId !== run.id) runs[runId].child_runs = treemap[runId];
1061
- return run;
1062
- }
1063
- /**
1064
- * List runs from the LangSmith server.
1065
- * @param projectId - The ID of the project to filter by.
1066
- * @param projectName - The name of the project to filter by.
1067
- * @param parentRunId - The ID of the parent run to filter by.
1068
- * @param traceId - The ID of the trace to filter by.
1069
- * @param referenceExampleId - The ID of the reference example to filter by.
1070
- * @param startTime - The start time to filter by.
1071
- * @param isRoot - Indicates whether to only return root runs.
1072
- * @param runType - The run type to filter by.
1073
- * @param error - Indicates whether to filter by error runs.
1074
- * @param id - The ID of the run to filter by.
1075
- * @param query - The query string to filter by.
1076
- * @param filter - The filter string to apply to the run spans.
1077
- * @param traceFilter - The filter string to apply on the root run of the trace.
1078
- * @param treeFilter - The filter string to apply on other runs in the trace.
1079
- * @param limit - The maximum number of runs to retrieve.
1080
- * @returns {AsyncIterable<Run>} - The runs.
1081
- *
1082
- * @example
1083
- * // List all runs in a project
1084
- * const projectRuns = client.listRuns({ projectName: "<your_project>" });
1085
- *
1086
- * @example
1087
- * // List LLM and Chat runs in the last 24 hours
1088
- * const todaysLLMRuns = client.listRuns({
1089
- * projectName: "<your_project>",
1090
- * start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
1091
- * run_type: "llm",
1092
- * });
1093
- *
1094
- * @example
1095
- * // List traces in a project
1096
- * const rootRuns = client.listRuns({
1097
- * projectName: "<your_project>",
1098
- * execution_order: 1,
1099
- * });
1100
- *
1101
- * @example
1102
- * // List runs without errors
1103
- * const correctRuns = client.listRuns({
1104
- * projectName: "<your_project>",
1105
- * error: false,
1106
- * });
1107
- *
1108
- * @example
1109
- * // List runs by run ID
1110
- * const runIds = [
1111
- * "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
1112
- * "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
1113
- * ];
1114
- * const selectedRuns = client.listRuns({ run_ids: runIds });
1115
- *
1116
- * @example
1117
- * // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
1118
- * const chainRuns = client.listRuns({
1119
- * projectName: "<your_project>",
1120
- * filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
1121
- * });
1122
- *
1123
- * @example
1124
- * // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
1125
- * const goodExtractorRuns = client.listRuns({
1126
- * projectName: "<your_project>",
1127
- * filter: 'eq(name, "extractor")',
1128
- * traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
1129
- * });
1130
- *
1131
- * @example
1132
- * // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
1133
- * const complexRuns = client.listRuns({
1134
- * projectName: "<your_project>",
1135
- * filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
1136
- * });
1137
- *
1138
- * @example
1139
- * // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
1140
- * const taggedRuns = client.listRuns({
1141
- * projectName: "<your_project>",
1142
- * filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
1143
- * });
1144
- */
1145
- async *listRuns(props) {
1146
- const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, isRoot, runType, error, id, query, filter, traceFilter, treeFilter, limit, select, order } = props;
1147
- let projectIds = [];
1148
- if (projectId) projectIds = Array.isArray(projectId) ? projectId : [projectId];
1149
- if (projectName) {
1150
- const projectNames = Array.isArray(projectName) ? projectName : [projectName];
1151
- const projectIds_ = await Promise.all(projectNames.map((name) => this.readProject({ projectName: name }).then((project) => project.id)));
1152
- projectIds.push(...projectIds_);
1153
- }
1154
- const default_select = [
1155
- "app_path",
1156
- "completion_cost",
1157
- "completion_tokens",
1158
- "dotted_order",
1159
- "end_time",
1160
- "error",
1161
- "events",
1162
- "extra",
1163
- "feedback_stats",
1164
- "first_token_time",
1165
- "id",
1166
- "inputs",
1167
- "name",
1168
- "outputs",
1169
- "parent_run_id",
1170
- "parent_run_ids",
1171
- "prompt_cost",
1172
- "prompt_tokens",
1173
- "reference_example_id",
1174
- "run_type",
1175
- "session_id",
1176
- "start_time",
1177
- "status",
1178
- "tags",
1179
- "total_cost",
1180
- "total_tokens",
1181
- "trace_id"
1182
- ];
1183
- const body = {
1184
- session: projectIds.length ? projectIds : null,
1185
- run_type: runType,
1186
- reference_example: referenceExampleId,
1187
- query,
1188
- filter,
1189
- trace_filter: traceFilter,
1190
- tree_filter: treeFilter,
1191
- execution_order: executionOrder,
1192
- parent_run: parentRunId,
1193
- start_time: startTime ? startTime.toISOString() : null,
1194
- error,
1195
- id,
1196
- limit,
1197
- trace: traceId,
1198
- select: select ? select : default_select,
1199
- is_root: isRoot,
1200
- order
1201
- };
1202
- if (body.select.includes("child_run_ids")) require_warn.warnOnce("Deprecated: 'child_run_ids' in the listRuns select parameter is deprecated and will be removed in a future version.");
1203
- let runsYielded = 0;
1204
- for await (const runs of this._getCursorPaginatedList("/runs/query", body)) if (limit) {
1205
- if (runsYielded >= limit) break;
1206
- if (runs.length + runsYielded > limit) {
1207
- const newRuns = runs.slice(0, limit - runsYielded);
1208
- yield* newRuns;
1209
- break;
1210
- }
1211
- runsYielded += runs.length;
1212
- yield* runs;
1213
- } else yield* runs;
1214
- }
1215
- async *listGroupRuns(props) {
1216
- const { projectId, projectName, groupBy, filter, startTime, endTime, limit, offset } = props;
1217
- const sessionId = projectId || (await this.readProject({ projectName })).id;
1218
- const baseBody = {
1219
- session_id: sessionId,
1220
- group_by: groupBy,
1221
- filter,
1222
- start_time: startTime ? startTime.toISOString() : null,
1223
- end_time: endTime ? endTime.toISOString() : null,
1224
- limit: Number(limit) || 100
1225
- };
1226
- let currentOffset = Number(offset) || 0;
1227
- const path = "/runs/group";
1228
- const url = `${this.apiUrl}${path}`;
1229
- while (true) {
1230
- const currentBody = {
1231
- ...baseBody,
1232
- offset: currentOffset
1233
- };
1234
- const filteredPayload = Object.fromEntries(Object.entries(currentBody).filter(([_, value]) => value !== void 0));
1235
- const body = JSON.stringify(filteredPayload);
1236
- const response = await this.caller.call(async () => {
1237
- const res = await this._fetch(url, {
1238
- method: "POST",
1239
- headers: {
1240
- ...this.headers,
1241
- "Content-Type": "application/json"
1242
- },
1243
- signal: AbortSignal.timeout(this.timeout_ms),
1244
- ...this.fetchOptions,
1245
- body
1246
- });
1247
- await require_error.raiseForStatus(res, `Failed to fetch ${path}`);
1248
- return res;
1249
- });
1250
- const items = await response.json();
1251
- const { groups, total } = items;
1252
- if (groups.length === 0) break;
1253
- for (const thread of groups) yield thread;
1254
- currentOffset += groups.length;
1255
- if (currentOffset >= total) break;
1256
- }
1257
- }
1258
- async getRunStats({ id, trace, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType }) {
1259
- let projectIds_ = projectIds || [];
1260
- if (projectNames) projectIds_ = [...projectIds || [], ...await Promise.all(projectNames.map((name) => this.readProject({ projectName: name }).then((project) => project.id)))];
1261
- const payload = {
1262
- id,
1263
- trace,
1264
- parent_run: parentRun,
1265
- run_type: runType,
1266
- session: projectIds_,
1267
- reference_example: referenceExampleIds,
1268
- start_time: startTime,
1269
- end_time: endTime,
1270
- error,
1271
- query,
1272
- filter,
1273
- trace_filter: traceFilter,
1274
- tree_filter: treeFilter,
1275
- is_root: isRoot,
1276
- data_source_type: dataSourceType
1277
- };
1278
- const filteredPayload = Object.fromEntries(Object.entries(payload).filter(([_, value]) => value !== void 0));
1279
- const body = JSON.stringify(filteredPayload);
1280
- const response = await this.caller.call(async () => {
1281
- const res = await this._fetch(`${this.apiUrl}/runs/stats`, {
1282
- method: "POST",
1283
- headers: {
1284
- ...this.headers,
1285
- "Content-Type": "application/json"
1286
- },
1287
- signal: AbortSignal.timeout(this.timeout_ms),
1288
- ...this.fetchOptions,
1289
- body
1290
- });
1291
- await require_error.raiseForStatus(res, "get run stats");
1292
- return res;
1293
- });
1294
- const result = await response.json();
1295
- return result;
1296
- }
1297
- async shareRun(runId, { shareId } = {}) {
1298
- const data = {
1299
- run_id: runId,
1300
- share_token: shareId || uuid.v4()
1301
- };
1302
- require__uuid.assertUuid(runId);
1303
- const body = JSON.stringify(data);
1304
- const response = await this.caller.call(async () => {
1305
- const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1306
- method: "PUT",
1307
- headers: this.headers,
1308
- signal: AbortSignal.timeout(this.timeout_ms),
1309
- ...this.fetchOptions,
1310
- body
1311
- });
1312
- await require_error.raiseForStatus(res, "share run");
1313
- return res;
1314
- });
1315
- const result = await response.json();
1316
- if (result === null || !("share_token" in result)) throw new Error("Invalid response from server");
1317
- return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
1318
- }
1319
- async unshareRun(runId) {
1320
- require__uuid.assertUuid(runId);
1321
- await this.caller.call(async () => {
1322
- const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1323
- method: "DELETE",
1324
- headers: this.headers,
1325
- signal: AbortSignal.timeout(this.timeout_ms),
1326
- ...this.fetchOptions
1327
- });
1328
- await require_error.raiseForStatus(res, "unshare run", true);
1329
- return res;
1330
- });
1331
- }
1332
- async readRunSharedLink(runId) {
1333
- require__uuid.assertUuid(runId);
1334
- const response = await this.caller.call(async () => {
1335
- const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1336
- method: "GET",
1337
- headers: this.headers,
1338
- signal: AbortSignal.timeout(this.timeout_ms),
1339
- ...this.fetchOptions
1340
- });
1341
- await require_error.raiseForStatus(res, "read run shared link");
1342
- return res;
1343
- });
1344
- const result = await response.json();
1345
- if (result === null || !("share_token" in result)) return void 0;
1346
- return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
1347
- }
1348
- async listSharedRuns(shareToken, { runIds } = {}) {
1349
- const queryParams = new URLSearchParams({ share_token: shareToken });
1350
- if (runIds !== void 0) for (const runId of runIds) queryParams.append("id", runId);
1351
- require__uuid.assertUuid(shareToken);
1352
- const response = await this.caller.call(async () => {
1353
- const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1354
- method: "GET",
1355
- headers: this.headers,
1356
- signal: AbortSignal.timeout(this.timeout_ms),
1357
- ...this.fetchOptions
1358
- });
1359
- await require_error.raiseForStatus(res, "list shared runs");
1360
- return res;
1361
- });
1362
- const runs = await response.json();
1363
- return runs;
1364
- }
1365
- async readDatasetSharedSchema(datasetId, datasetName) {
1366
- if (!datasetId && !datasetName) throw new Error("Either datasetId or datasetName must be given");
1367
- if (!datasetId) {
1368
- const dataset = await this.readDataset({ datasetName });
1369
- datasetId = dataset.id;
1370
- }
1371
- require__uuid.assertUuid(datasetId);
1372
- const response = await this.caller.call(async () => {
1373
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1374
- method: "GET",
1375
- headers: this.headers,
1376
- signal: AbortSignal.timeout(this.timeout_ms),
1377
- ...this.fetchOptions
1378
- });
1379
- await require_error.raiseForStatus(res, "read dataset shared schema");
1380
- return res;
1381
- });
1382
- const shareSchema = await response.json();
1383
- shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
1384
- return shareSchema;
1385
- }
1386
- async shareDataset(datasetId, datasetName) {
1387
- if (!datasetId && !datasetName) throw new Error("Either datasetId or datasetName must be given");
1388
- if (!datasetId) {
1389
- const dataset = await this.readDataset({ datasetName });
1390
- datasetId = dataset.id;
1391
- }
1392
- const data = { dataset_id: datasetId };
1393
- require__uuid.assertUuid(datasetId);
1394
- const body = JSON.stringify(data);
1395
- const response = await this.caller.call(async () => {
1396
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1397
- method: "PUT",
1398
- headers: this.headers,
1399
- signal: AbortSignal.timeout(this.timeout_ms),
1400
- ...this.fetchOptions,
1401
- body
1402
- });
1403
- await require_error.raiseForStatus(res, "share dataset");
1404
- return res;
1405
- });
1406
- const shareSchema = await response.json();
1407
- shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
1408
- return shareSchema;
1409
- }
1410
- async unshareDataset(datasetId) {
1411
- require__uuid.assertUuid(datasetId);
1412
- await this.caller.call(async () => {
1413
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1414
- method: "DELETE",
1415
- headers: this.headers,
1416
- signal: AbortSignal.timeout(this.timeout_ms),
1417
- ...this.fetchOptions
1418
- });
1419
- await require_error.raiseForStatus(res, "unshare dataset", true);
1420
- return res;
1421
- });
1422
- }
1423
- async readSharedDataset(shareToken) {
1424
- require__uuid.assertUuid(shareToken);
1425
- const response = await this.caller.call(async () => {
1426
- const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/datasets`, {
1427
- method: "GET",
1428
- headers: this.headers,
1429
- signal: AbortSignal.timeout(this.timeout_ms),
1430
- ...this.fetchOptions
1431
- });
1432
- await require_error.raiseForStatus(res, "read shared dataset");
1433
- return res;
1434
- });
1435
- const dataset = await response.json();
1436
- return dataset;
1437
- }
1438
- /**
1439
- * Get shared examples.
1440
- *
1441
- * @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
1442
- * @param {Object} [options] Additional options for listing the examples.
1443
- * @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
1444
- * @returns {Promise<Example[]>} The shared examples.
1445
- */
1446
- async listSharedExamples(shareToken, options) {
1447
- const params = {};
1448
- if (options?.exampleIds) params.id = options.exampleIds;
1449
- const urlParams = new URLSearchParams();
1450
- Object.entries(params).forEach(([key, value]) => {
1451
- if (Array.isArray(value)) value.forEach((v) => urlParams.append(key, v));
1452
- else urlParams.append(key, value);
1453
- });
1454
- const response = await this.caller.call(async () => {
1455
- const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1456
- method: "GET",
1457
- headers: this.headers,
1458
- signal: AbortSignal.timeout(this.timeout_ms),
1459
- ...this.fetchOptions
1460
- });
1461
- await require_error.raiseForStatus(res, "list shared examples");
1462
- return res;
1463
- });
1464
- const result = await response.json();
1465
- if (!response.ok) {
1466
- if ("detail" in result) throw new Error(`Failed to list shared examples.\nStatus: ${response.status}\nMessage: ${Array.isArray(result.detail) ? result.detail.join("\n") : "Unspecified error"}`);
1467
- throw new Error(`Failed to list shared examples: ${response.status} ${response.statusText}`);
1468
- }
1469
- return result.map((example) => ({
1470
- ...example,
1471
- _hostUrl: this.getHostUrl()
1472
- }));
1473
- }
1474
- async createProject({ projectName, description = null, metadata = null, upsert = false, projectExtra = null, referenceDatasetId = null }) {
1475
- const upsert_ = upsert ? `?upsert=true` : "";
1476
- const endpoint = `${this.apiUrl}/sessions${upsert_}`;
1477
- const extra = projectExtra || {};
1478
- if (metadata) extra["metadata"] = metadata;
1479
- const body = {
1480
- name: projectName,
1481
- extra,
1482
- description
1483
- };
1484
- if (referenceDatasetId !== null) body["reference_dataset_id"] = referenceDatasetId;
1485
- const serializedBody = JSON.stringify(body);
1486
- const response = await this.caller.call(async () => {
1487
- const res = await this._fetch(endpoint, {
1488
- method: "POST",
1489
- headers: {
1490
- ...this.headers,
1491
- "Content-Type": "application/json"
1492
- },
1493
- signal: AbortSignal.timeout(this.timeout_ms),
1494
- ...this.fetchOptions,
1495
- body: serializedBody
1496
- });
1497
- await require_error.raiseForStatus(res, "create project");
1498
- return res;
1499
- });
1500
- const result = await response.json();
1501
- return result;
1502
- }
1503
- async updateProject(projectId, { name = null, description = null, metadata = null, projectExtra = null, endTime = null }) {
1504
- const endpoint = `${this.apiUrl}/sessions/${projectId}`;
1505
- let extra = projectExtra;
1506
- if (metadata) extra = {
1507
- ...extra || {},
1508
- metadata
1509
- };
1510
- const body = JSON.stringify({
1511
- name,
1512
- extra,
1513
- description,
1514
- end_time: endTime ? new Date(endTime).toISOString() : null
1515
- });
1516
- const response = await this.caller.call(async () => {
1517
- const res = await this._fetch(endpoint, {
1518
- method: "PATCH",
1519
- headers: {
1520
- ...this.headers,
1521
- "Content-Type": "application/json"
1522
- },
1523
- signal: AbortSignal.timeout(this.timeout_ms),
1524
- ...this.fetchOptions,
1525
- body
1526
- });
1527
- await require_error.raiseForStatus(res, "update project");
1528
- return res;
1529
- });
1530
- const result = await response.json();
1531
- return result;
1532
- }
1533
- async hasProject({ projectId, projectName }) {
1534
- let path = "/sessions";
1535
- const params = new URLSearchParams();
1536
- if (projectId !== void 0 && projectName !== void 0) throw new Error("Must provide either projectName or projectId, not both");
1537
- else if (projectId !== void 0) {
1538
- require__uuid.assertUuid(projectId);
1539
- path += `/${projectId}`;
1540
- } else if (projectName !== void 0) params.append("name", projectName);
1541
- else throw new Error("Must provide projectName or projectId");
1542
- const response = await this.caller.call(async () => {
1543
- const res = await this._fetch(`${this.apiUrl}${path}?${params}`, {
1544
- method: "GET",
1545
- headers: this.headers,
1546
- signal: AbortSignal.timeout(this.timeout_ms),
1547
- ...this.fetchOptions
1548
- });
1549
- await require_error.raiseForStatus(res, "has project");
1550
- return res;
1551
- });
1552
- try {
1553
- const result = await response.json();
1554
- if (!response.ok) return false;
1555
- if (Array.isArray(result)) return result.length > 0;
1556
- return true;
1557
- } catch (e) {
1558
- return false;
1559
- }
1560
- }
1561
- async readProject({ projectId, projectName, includeStats }) {
1562
- let path = "/sessions";
1563
- const params = new URLSearchParams();
1564
- if (projectId !== void 0 && projectName !== void 0) throw new Error("Must provide either projectName or projectId, not both");
1565
- else if (projectId !== void 0) {
1566
- require__uuid.assertUuid(projectId);
1567
- path += `/${projectId}`;
1568
- } else if (projectName !== void 0) params.append("name", projectName);
1569
- else throw new Error("Must provide projectName or projectId");
1570
- if (includeStats !== void 0) params.append("include_stats", includeStats.toString());
1571
- const response = await this._get(path, params);
1572
- let result;
1573
- if (Array.isArray(response)) {
1574
- if (response.length === 0) throw new Error(`Project[id=${projectId}, name=${projectName}] not found`);
1575
- result = response[0];
1576
- } else result = response;
1577
- return result;
1578
- }
1579
- async getProjectUrl({ projectId, projectName }) {
1580
- if (projectId === void 0 && projectName === void 0) throw new Error("Must provide either projectName or projectId");
1581
- const project = await this.readProject({
1582
- projectId,
1583
- projectName
1584
- });
1585
- const tenantId = await this._getTenantId();
1586
- return `${this.getHostUrl()}/o/${tenantId}/projects/p/${project.id}`;
1587
- }
1588
- async getDatasetUrl({ datasetId, datasetName }) {
1589
- if (datasetId === void 0 && datasetName === void 0) throw new Error("Must provide either datasetName or datasetId");
1590
- const dataset = await this.readDataset({
1591
- datasetId,
1592
- datasetName
1593
- });
1594
- const tenantId = await this._getTenantId();
1595
- return `${this.getHostUrl()}/o/${tenantId}/datasets/${dataset.id}`;
1596
- }
1597
- async _getTenantId() {
1598
- if (this._tenantId !== null) return this._tenantId;
1599
- const queryParams = new URLSearchParams({ limit: "1" });
1600
- for await (const projects of this._getPaginated("/sessions", queryParams)) {
1601
- this._tenantId = projects[0].tenant_id;
1602
- return projects[0].tenant_id;
1603
- }
1604
- throw new Error("No projects found to resolve tenant.");
1605
- }
1606
- async *listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, includeStats, datasetVersion, referenceFree, metadata } = {}) {
1607
- const params = new URLSearchParams();
1608
- if (projectIds !== void 0) for (const projectId of projectIds) params.append("id", projectId);
1609
- if (name !== void 0) params.append("name", name);
1610
- if (nameContains !== void 0) params.append("name_contains", nameContains);
1611
- if (referenceDatasetId !== void 0) params.append("reference_dataset", referenceDatasetId);
1612
- else if (referenceDatasetName !== void 0) {
1613
- const dataset = await this.readDataset({ datasetName: referenceDatasetName });
1614
- params.append("reference_dataset", dataset.id);
1615
- }
1616
- if (includeStats !== void 0) params.append("include_stats", includeStats.toString());
1617
- if (datasetVersion !== void 0) params.append("dataset_version", datasetVersion);
1618
- if (referenceFree !== void 0) params.append("reference_free", referenceFree.toString());
1619
- if (metadata !== void 0) params.append("metadata", JSON.stringify(metadata));
1620
- for await (const projects of this._getPaginated("/sessions", params)) yield* projects;
1621
- }
1622
- async deleteProject({ projectId, projectName }) {
1623
- let projectId_;
1624
- if (projectId === void 0 && projectName === void 0) throw new Error("Must provide projectName or projectId");
1625
- else if (projectId !== void 0 && projectName !== void 0) throw new Error("Must provide either projectName or projectId, not both");
1626
- else if (projectId === void 0) projectId_ = (await this.readProject({ projectName })).id;
1627
- else projectId_ = projectId;
1628
- require__uuid.assertUuid(projectId_);
1629
- await this.caller.call(async () => {
1630
- const res = await this._fetch(`${this.apiUrl}/sessions/${projectId_}`, {
1631
- method: "DELETE",
1632
- headers: this.headers,
1633
- signal: AbortSignal.timeout(this.timeout_ms),
1634
- ...this.fetchOptions
1635
- });
1636
- await require_error.raiseForStatus(res, `delete session ${projectId_} (${projectName})`, true);
1637
- return res;
1638
- });
1639
- }
1640
- async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name }) {
1641
- const url = `${this.apiUrl}/datasets/upload`;
1642
- const formData = new FormData();
1643
- formData.append("file", csvFile, fileName);
1644
- inputKeys.forEach((key) => {
1645
- formData.append("input_keys", key);
1646
- });
1647
- outputKeys.forEach((key) => {
1648
- formData.append("output_keys", key);
1649
- });
1650
- if (description) formData.append("description", description);
1651
- if (dataType) formData.append("data_type", dataType);
1652
- if (name) formData.append("name", name);
1653
- const response = await this.caller.call(async () => {
1654
- const res = await this._fetch(url, {
1655
- method: "POST",
1656
- headers: this.headers,
1657
- signal: AbortSignal.timeout(this.timeout_ms),
1658
- ...this.fetchOptions,
1659
- body: formData
1660
- });
1661
- await require_error.raiseForStatus(res, "upload CSV");
1662
- return res;
1663
- });
1664
- const result = await response.json();
1665
- return result;
1666
- }
1667
- async createDataset(name, { description, dataType, inputsSchema, outputsSchema, metadata } = {}) {
1668
- const body = {
1669
- name,
1670
- description,
1671
- extra: metadata ? { metadata } : void 0
1672
- };
1673
- if (dataType) body.data_type = dataType;
1674
- if (inputsSchema) body.inputs_schema_definition = inputsSchema;
1675
- if (outputsSchema) body.outputs_schema_definition = outputsSchema;
1676
- const serializedBody = JSON.stringify(body);
1677
- const response = await this.caller.call(async () => {
1678
- const res = await this._fetch(`${this.apiUrl}/datasets`, {
1679
- method: "POST",
1680
- headers: {
1681
- ...this.headers,
1682
- "Content-Type": "application/json"
1683
- },
1684
- signal: AbortSignal.timeout(this.timeout_ms),
1685
- ...this.fetchOptions,
1686
- body: serializedBody
1687
- });
1688
- await require_error.raiseForStatus(res, "create dataset");
1689
- return res;
1690
- });
1691
- const result = await response.json();
1692
- return result;
1693
- }
1694
- async readDataset({ datasetId, datasetName }) {
1695
- let path = "/datasets";
1696
- const params = new URLSearchParams({ limit: "1" });
1697
- if (datasetId && datasetName) throw new Error("Must provide either datasetName or datasetId, not both");
1698
- else if (datasetId) {
1699
- require__uuid.assertUuid(datasetId);
1700
- path += `/${datasetId}`;
1701
- } else if (datasetName) params.append("name", datasetName);
1702
- else throw new Error("Must provide datasetName or datasetId");
1703
- const response = await this._get(path, params);
1704
- let result;
1705
- if (Array.isArray(response)) {
1706
- if (response.length === 0) throw new Error(`Dataset[id=${datasetId}, name=${datasetName}] not found`);
1707
- result = response[0];
1708
- } else result = response;
1709
- return result;
1710
- }
1711
- async hasDataset({ datasetId, datasetName }) {
1712
- try {
1713
- await this.readDataset({
1714
- datasetId,
1715
- datasetName
1716
- });
1717
- return true;
1718
- } catch (e) {
1719
- if (e instanceof Error && e.message.toLocaleLowerCase().includes("not found")) return false;
1720
- throw e;
1721
- }
1722
- }
1723
- async diffDatasetVersions({ datasetId, datasetName, fromVersion, toVersion }) {
1724
- let datasetId_ = datasetId;
1725
- if (datasetId_ === void 0 && datasetName === void 0) throw new Error("Must provide either datasetName or datasetId");
1726
- else if (datasetId_ !== void 0 && datasetName !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
1727
- else if (datasetId_ === void 0) {
1728
- const dataset = await this.readDataset({ datasetName });
1729
- datasetId_ = dataset.id;
1730
- }
1731
- const urlParams = new URLSearchParams({
1732
- from_version: typeof fromVersion === "string" ? fromVersion : fromVersion.toISOString(),
1733
- to_version: typeof toVersion === "string" ? toVersion : toVersion.toISOString()
1734
- });
1735
- const response = await this._get(`/datasets/${datasetId_}/versions/diff`, urlParams);
1736
- return response;
1737
- }
1738
- async readDatasetOpenaiFinetuning({ datasetId, datasetName }) {
1739
- const path = "/datasets";
1740
- if (datasetId !== void 0) {} else if (datasetName !== void 0) datasetId = (await this.readDataset({ datasetName })).id;
1741
- else throw new Error("Must provide either datasetName or datasetId");
1742
- const response = await this._getResponse(`${path}/${datasetId}/openai_ft`);
1743
- const datasetText = await response.text();
1744
- const dataset = datasetText.trim().split("\n").map((line) => JSON.parse(line));
1745
- return dataset;
1746
- }
1747
- async *listDatasets({ limit = 100, offset = 0, datasetIds, datasetName, datasetNameContains, metadata } = {}) {
1748
- const path = "/datasets";
1749
- const params = new URLSearchParams({
1750
- limit: limit.toString(),
1751
- offset: offset.toString()
1752
- });
1753
- if (datasetIds !== void 0) for (const id_ of datasetIds) params.append("id", id_);
1754
- if (datasetName !== void 0) params.append("name", datasetName);
1755
- if (datasetNameContains !== void 0) params.append("name_contains", datasetNameContains);
1756
- if (metadata !== void 0) params.append("metadata", JSON.stringify(metadata));
1757
- for await (const datasets of this._getPaginated(path, params)) yield* datasets;
1758
- }
1759
- /**
1760
- * Update a dataset
1761
- * @param props The dataset details to update
1762
- * @returns The updated dataset
1763
- */
1764
- async updateDataset(props) {
1765
- const { datasetId, datasetName,...update } = props;
1766
- if (!datasetId && !datasetName) throw new Error("Must provide either datasetName or datasetId");
1767
- const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
1768
- require__uuid.assertUuid(_datasetId);
1769
- const body = JSON.stringify(update);
1770
- const response = await this.caller.call(async () => {
1771
- const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}`, {
1772
- method: "PATCH",
1773
- headers: {
1774
- ...this.headers,
1775
- "Content-Type": "application/json"
1776
- },
1777
- signal: AbortSignal.timeout(this.timeout_ms),
1778
- ...this.fetchOptions,
1779
- body
1780
- });
1781
- await require_error.raiseForStatus(res, "update dataset");
1782
- return res;
1783
- });
1784
- return await response.json();
1785
- }
1786
- /**
1787
- * Updates a tag on a dataset.
1788
- *
1789
- * If the tag is already assigned to a different version of this dataset,
1790
- * the tag will be moved to the new version. The as_of parameter is used to
1791
- * determine which version of the dataset to apply the new tags to.
1792
- *
1793
- * It must be an exact version of the dataset to succeed. You can
1794
- * use the "readDatasetVersion" method to find the exact version
1795
- * to apply the tags to.
1796
- * @param params.datasetId The ID of the dataset to update. Must be provided if "datasetName" is not provided.
1797
- * @param params.datasetName The name of the dataset to update. Must be provided if "datasetId" is not provided.
1798
- * @param params.asOf The timestamp of the dataset to apply the new tags to.
1799
- * @param params.tag The new tag to apply to the dataset.
1800
- */
1801
- async updateDatasetTag(props) {
1802
- const { datasetId, datasetName, asOf, tag } = props;
1803
- if (!datasetId && !datasetName) throw new Error("Must provide either datasetName or datasetId");
1804
- const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
1805
- require__uuid.assertUuid(_datasetId);
1806
- const body = JSON.stringify({
1807
- as_of: typeof asOf === "string" ? asOf : asOf.toISOString(),
1808
- tag
1809
- });
1810
- await this.caller.call(async () => {
1811
- const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}/tags`, {
1812
- method: "PUT",
1813
- headers: {
1814
- ...this.headers,
1815
- "Content-Type": "application/json"
1816
- },
1817
- signal: AbortSignal.timeout(this.timeout_ms),
1818
- ...this.fetchOptions,
1819
- body
1820
- });
1821
- await require_error.raiseForStatus(res, "update dataset tags", true);
1822
- return res;
1823
- });
1824
- }
1825
- async deleteDataset({ datasetId, datasetName }) {
1826
- let path = "/datasets";
1827
- let datasetId_ = datasetId;
1828
- if (datasetId !== void 0 && datasetName !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
1829
- else if (datasetName !== void 0) {
1830
- const dataset = await this.readDataset({ datasetName });
1831
- datasetId_ = dataset.id;
1832
- }
1833
- if (datasetId_ !== void 0) {
1834
- require__uuid.assertUuid(datasetId_);
1835
- path += `/${datasetId_}`;
1836
- } else throw new Error("Must provide datasetName or datasetId");
1837
- await this.caller.call(async () => {
1838
- const res = await this._fetch(this.apiUrl + path, {
1839
- method: "DELETE",
1840
- headers: this.headers,
1841
- signal: AbortSignal.timeout(this.timeout_ms),
1842
- ...this.fetchOptions
1843
- });
1844
- await require_error.raiseForStatus(res, `delete ${path}`, true);
1845
- return res;
1846
- });
1847
- }
1848
- async indexDataset({ datasetId, datasetName, tag }) {
1849
- let datasetId_ = datasetId;
1850
- if (!datasetId_ && !datasetName) throw new Error("Must provide either datasetName or datasetId");
1851
- else if (datasetId_ && datasetName) throw new Error("Must provide either datasetName or datasetId, not both");
1852
- else if (!datasetId_) {
1853
- const dataset = await this.readDataset({ datasetName });
1854
- datasetId_ = dataset.id;
1855
- }
1856
- require__uuid.assertUuid(datasetId_);
1857
- const data = { tag };
1858
- const body = JSON.stringify(data);
1859
- const response = await this.caller.call(async () => {
1860
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/index`, {
1861
- method: "POST",
1862
- headers: {
1863
- ...this.headers,
1864
- "Content-Type": "application/json"
1865
- },
1866
- signal: AbortSignal.timeout(this.timeout_ms),
1867
- ...this.fetchOptions,
1868
- body
1869
- });
1870
- await require_error.raiseForStatus(res, "index dataset");
1871
- return res;
1872
- });
1873
- await response.json();
1874
- }
1875
- /**
1876
- * Lets you run a similarity search query on a dataset.
1877
- *
1878
- * Requires the dataset to be indexed. Please see the `indexDataset` method to set up indexing.
1879
- *
1880
- * @param inputs The input on which to run the similarity search. Must have the
1881
- * same schema as the dataset.
1882
- *
1883
- * @param datasetId The dataset to search for similar examples.
1884
- *
1885
- * @param limit The maximum number of examples to return. Will return the top `limit` most
1886
- * similar examples in order of most similar to least similar. If no similar
1887
- * examples are found, random examples will be returned.
1888
- *
1889
- * @param filter A filter string to apply to the search. Only examples will be returned that
1890
- * match the filter string. Some examples of filters
1891
- *
1892
- * - eq(metadata.mykey, "value")
1893
- * - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value"))
1894
- * - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue"))
1895
- *
1896
- * @returns A list of similar examples.
1897
- *
1898
- *
1899
- * @example
1900
- * dataset_id = "123e4567-e89b-12d3-a456-426614174000"
1901
- * inputs = {"text": "How many people live in Berlin?"}
1902
- * limit = 5
1903
- * examples = await client.similarExamples(inputs, dataset_id, limit)
1904
- */
1905
- async similarExamples(inputs, datasetId, limit, { filter } = {}) {
1906
- const data = {
1907
- limit,
1908
- inputs
1909
- };
1910
- if (filter !== void 0) data["filter"] = filter;
1911
- require__uuid.assertUuid(datasetId);
1912
- const body = JSON.stringify(data);
1913
- const response = await this.caller.call(async () => {
1914
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/search`, {
1915
- headers: {
1916
- ...this.headers,
1917
- "Content-Type": "application/json"
1918
- },
1919
- signal: AbortSignal.timeout(this.timeout_ms),
1920
- ...this.fetchOptions,
1921
- method: "POST",
1922
- body
1923
- });
1924
- await require_error.raiseForStatus(res, "fetch similar examples");
1925
- return res;
1926
- });
1927
- const result = await response.json();
1928
- return result["examples"];
1929
- }
1930
- async createExample(inputsOrUpdate, outputs, options) {
1931
- if (isExampleCreate(inputsOrUpdate)) {
1932
- if (outputs !== void 0 || options !== void 0) throw new Error("Cannot provide outputs or options when using ExampleCreate object");
1933
- }
1934
- let datasetId_ = outputs ? options?.datasetId : inputsOrUpdate.dataset_id;
1935
- const datasetName_ = outputs ? options?.datasetName : inputsOrUpdate.dataset_name;
1936
- if (datasetId_ === void 0 && datasetName_ === void 0) throw new Error("Must provide either datasetName or datasetId");
1937
- else if (datasetId_ !== void 0 && datasetName_ !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
1938
- else if (datasetId_ === void 0) {
1939
- const dataset = await this.readDataset({ datasetName: datasetName_ });
1940
- datasetId_ = dataset.id;
1941
- }
1942
- const createdAt_ = (outputs ? options?.createdAt : inputsOrUpdate.created_at) || /* @__PURE__ */ new Date();
1943
- let data;
1944
- if (!isExampleCreate(inputsOrUpdate)) data = {
1945
- inputs: inputsOrUpdate,
1946
- outputs,
1947
- created_at: createdAt_?.toISOString(),
1948
- id: options?.exampleId,
1949
- metadata: options?.metadata,
1950
- split: options?.split,
1951
- source_run_id: options?.sourceRunId,
1952
- use_source_run_io: options?.useSourceRunIO,
1953
- use_source_run_attachments: options?.useSourceRunAttachments,
1954
- attachments: options?.attachments
1955
- };
1956
- else data = inputsOrUpdate;
1957
- const response = await this._uploadExamplesMultipart(datasetId_, [data]);
1958
- const example = await this.readExample(response.example_ids?.[0] ?? uuid.v4());
1959
- return example;
1960
- }
1961
- async createExamples(propsOrUploads) {
1962
- if (Array.isArray(propsOrUploads)) {
1963
- if (propsOrUploads.length === 0) return [];
1964
- const uploads = propsOrUploads;
1965
- let datasetId_$1 = uploads[0].dataset_id;
1966
- const datasetName_$1 = uploads[0].dataset_name;
1967
- if (datasetId_$1 === void 0 && datasetName_$1 === void 0) throw new Error("Must provide either datasetName or datasetId");
1968
- else if (datasetId_$1 !== void 0 && datasetName_$1 !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
1969
- else if (datasetId_$1 === void 0) {
1970
- const dataset = await this.readDataset({ datasetName: datasetName_$1 });
1971
- datasetId_$1 = dataset.id;
1972
- }
1973
- const response$1 = await this._uploadExamplesMultipart(datasetId_$1, uploads);
1974
- const examples$1 = await Promise.all(response$1.example_ids.map((id) => this.readExample(id)));
1975
- return examples$1;
1976
- }
1977
- const { inputs, outputs, metadata, splits, sourceRunIds, useSourceRunIOs, useSourceRunAttachments, attachments, exampleIds, datasetId, datasetName } = propsOrUploads;
1978
- if (inputs === void 0) throw new Error("Must provide inputs when using legacy parameters");
1979
- let datasetId_ = datasetId;
1980
- const datasetName_ = datasetName;
1981
- if (datasetId_ === void 0 && datasetName_ === void 0) throw new Error("Must provide either datasetName or datasetId");
1982
- else if (datasetId_ !== void 0 && datasetName_ !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
1983
- else if (datasetId_ === void 0) {
1984
- const dataset = await this.readDataset({ datasetName: datasetName_ });
1985
- datasetId_ = dataset.id;
1986
- }
1987
- const formattedExamples = inputs.map((input, idx) => {
1988
- return {
1989
- dataset_id: datasetId_,
1990
- inputs: input,
1991
- outputs: outputs?.[idx],
1992
- metadata: metadata?.[idx],
1993
- split: splits?.[idx],
1994
- id: exampleIds?.[idx],
1995
- attachments: attachments?.[idx],
1996
- source_run_id: sourceRunIds?.[idx],
1997
- use_source_run_io: useSourceRunIOs?.[idx],
1998
- use_source_run_attachments: useSourceRunAttachments?.[idx]
1999
- };
2000
- });
2001
- const response = await this._uploadExamplesMultipart(datasetId_, formattedExamples);
2002
- const examples = await Promise.all(response.example_ids.map((id) => this.readExample(id)));
2003
- return examples;
2004
- }
2005
- async createLLMExample(input, generation, options) {
2006
- return this.createExample({ input }, { output: generation }, options);
2007
- }
2008
- async createChatExample(input, generations, options) {
2009
- const finalInput = input.map((message) => {
2010
- if (require_messages.isLangChainMessage(message)) return require_messages.convertLangChainMessageToExample(message);
2011
- return message;
2012
- });
2013
- const finalOutput = require_messages.isLangChainMessage(generations) ? require_messages.convertLangChainMessageToExample(generations) : generations;
2014
- return this.createExample({ input: finalInput }, { output: finalOutput }, options);
2015
- }
2016
- async readExample(exampleId) {
2017
- require__uuid.assertUuid(exampleId);
2018
- const path = `/examples/${exampleId}`;
2019
- const rawExample = await this._get(path);
2020
- const { attachment_urls,...rest } = rawExample;
2021
- const example = rest;
2022
- if (attachment_urls) example.attachments = Object.entries(attachment_urls).reduce((acc, [key, value]) => {
2023
- acc[key.slice(11)] = {
2024
- presigned_url: value.presigned_url,
2025
- mime_type: value.mime_type
2026
- };
2027
- return acc;
2028
- }, {});
2029
- return example;
2030
- }
2031
- async *listExamples({ datasetId, datasetName, exampleIds, asOf, splits, inlineS3Urls, metadata, limit, offset, filter, includeAttachments } = {}) {
2032
- let datasetId_;
2033
- if (datasetId !== void 0 && datasetName !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
2034
- else if (datasetId !== void 0) datasetId_ = datasetId;
2035
- else if (datasetName !== void 0) {
2036
- const dataset = await this.readDataset({ datasetName });
2037
- datasetId_ = dataset.id;
2038
- } else throw new Error("Must provide a datasetName or datasetId");
2039
- const params = new URLSearchParams({ dataset: datasetId_ });
2040
- const dataset_version = asOf ? typeof asOf === "string" ? asOf : asOf?.toISOString() : void 0;
2041
- if (dataset_version) params.append("as_of", dataset_version);
2042
- const inlineS3Urls_ = inlineS3Urls ?? true;
2043
- params.append("inline_s3_urls", inlineS3Urls_.toString());
2044
- if (exampleIds !== void 0) for (const id_ of exampleIds) params.append("id", id_);
2045
- if (splits !== void 0) for (const split of splits) params.append("splits", split);
2046
- if (metadata !== void 0) {
2047
- const serializedMetadata = JSON.stringify(metadata);
2048
- params.append("metadata", serializedMetadata);
2049
- }
2050
- if (limit !== void 0) params.append("limit", limit.toString());
2051
- if (offset !== void 0) params.append("offset", offset.toString());
2052
- if (filter !== void 0) params.append("filter", filter);
2053
- if (includeAttachments === true) [
2054
- "attachment_urls",
2055
- "outputs",
2056
- "metadata"
2057
- ].forEach((field) => params.append("select", field));
2058
- let i = 0;
2059
- for await (const rawExamples of this._getPaginated("/examples", params)) {
2060
- for (const rawExample of rawExamples) {
2061
- const { attachment_urls,...rest } = rawExample;
2062
- const example = rest;
2063
- if (attachment_urls) example.attachments = Object.entries(attachment_urls).reduce((acc, [key, value]) => {
2064
- acc[key.slice(11)] = {
2065
- presigned_url: value.presigned_url,
2066
- mime_type: value.mime_type || void 0
2067
- };
2068
- return acc;
2069
- }, {});
2070
- yield example;
2071
- i++;
2072
- }
2073
- if (limit !== void 0 && i >= limit) break;
2074
- }
2075
- }
2076
- async deleteExample(exampleId) {
2077
- require__uuid.assertUuid(exampleId);
2078
- const path = `/examples/${exampleId}`;
2079
- await this.caller.call(async () => {
2080
- const res = await this._fetch(this.apiUrl + path, {
2081
- method: "DELETE",
2082
- headers: this.headers,
2083
- signal: AbortSignal.timeout(this.timeout_ms),
2084
- ...this.fetchOptions
2085
- });
2086
- await require_error.raiseForStatus(res, `delete ${path}`, true);
2087
- return res;
2088
- });
2089
- }
2090
- async updateExample(exampleIdOrUpdate, update) {
2091
- let exampleId;
2092
- if (update) exampleId = exampleIdOrUpdate;
2093
- else exampleId = exampleIdOrUpdate.id;
2094
- require__uuid.assertUuid(exampleId);
2095
- let updateToUse;
2096
- if (update) updateToUse = {
2097
- id: exampleId,
2098
- ...update
2099
- };
2100
- else updateToUse = exampleIdOrUpdate;
2101
- let datasetId;
2102
- if (updateToUse.dataset_id !== void 0) datasetId = updateToUse.dataset_id;
2103
- else {
2104
- const example = await this.readExample(exampleId);
2105
- datasetId = example.dataset_id;
2106
- }
2107
- return this._updateExamplesMultipart(datasetId, [updateToUse]);
2108
- }
2109
- async updateExamples(update) {
2110
- let datasetId;
2111
- if (update[0].dataset_id === void 0) {
2112
- const example = await this.readExample(update[0].id);
2113
- datasetId = example.dataset_id;
2114
- } else datasetId = update[0].dataset_id;
2115
- return this._updateExamplesMultipart(datasetId, update);
2116
- }
2117
- /**
2118
- * Get dataset version by closest date or exact tag.
2119
- *
2120
- * Use this to resolve the nearest version to a given timestamp or for a given tag.
2121
- *
2122
- * @param options The options for getting the dataset version
2123
- * @param options.datasetId The ID of the dataset
2124
- * @param options.datasetName The name of the dataset
2125
- * @param options.asOf The timestamp of the dataset to retrieve
2126
- * @param options.tag The tag of the dataset to retrieve
2127
- * @returns The dataset version
2128
- */
2129
- async readDatasetVersion({ datasetId, datasetName, asOf, tag }) {
2130
- let resolvedDatasetId;
2131
- if (!datasetId) {
2132
- const dataset = await this.readDataset({ datasetName });
2133
- resolvedDatasetId = dataset.id;
2134
- } else resolvedDatasetId = datasetId;
2135
- require__uuid.assertUuid(resolvedDatasetId);
2136
- if (asOf && tag || !asOf && !tag) throw new Error("Exactly one of asOf and tag must be specified.");
2137
- const params = new URLSearchParams();
2138
- if (asOf !== void 0) params.append("as_of", typeof asOf === "string" ? asOf : asOf.toISOString());
2139
- if (tag !== void 0) params.append("tag", tag);
2140
- const response = await this.caller.call(async () => {
2141
- const res = await this._fetch(`${this.apiUrl}/datasets/${resolvedDatasetId}/version?${params.toString()}`, {
2142
- method: "GET",
2143
- headers: { ...this.headers },
2144
- signal: AbortSignal.timeout(this.timeout_ms),
2145
- ...this.fetchOptions
2146
- });
2147
- await require_error.raiseForStatus(res, "read dataset version");
2148
- return res;
2149
- });
2150
- return await response.json();
2151
- }
2152
- async listDatasetSplits({ datasetId, datasetName, asOf }) {
2153
- let datasetId_;
2154
- if (datasetId === void 0 && datasetName === void 0) throw new Error("Must provide dataset name or ID");
2155
- else if (datasetId !== void 0 && datasetName !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
2156
- else if (datasetId === void 0) {
2157
- const dataset = await this.readDataset({ datasetName });
2158
- datasetId_ = dataset.id;
2159
- } else datasetId_ = datasetId;
2160
- require__uuid.assertUuid(datasetId_);
2161
- const params = new URLSearchParams();
2162
- const dataset_version = asOf ? typeof asOf === "string" ? asOf : asOf?.toISOString() : void 0;
2163
- if (dataset_version) params.append("as_of", dataset_version);
2164
- const response = await this._get(`/datasets/${datasetId_}/splits`, params);
2165
- return response;
2166
- }
2167
- async updateDatasetSplits({ datasetId, datasetName, splitName, exampleIds, remove = false }) {
2168
- let datasetId_;
2169
- if (datasetId === void 0 && datasetName === void 0) throw new Error("Must provide dataset name or ID");
2170
- else if (datasetId !== void 0 && datasetName !== void 0) throw new Error("Must provide either datasetName or datasetId, not both");
2171
- else if (datasetId === void 0) {
2172
- const dataset = await this.readDataset({ datasetName });
2173
- datasetId_ = dataset.id;
2174
- } else datasetId_ = datasetId;
2175
- require__uuid.assertUuid(datasetId_);
2176
- const data = {
2177
- split_name: splitName,
2178
- examples: exampleIds.map((id) => {
2179
- require__uuid.assertUuid(id);
2180
- return id;
2181
- }),
2182
- remove
2183
- };
2184
- const body = JSON.stringify(data);
2185
- await this.caller.call(async () => {
2186
- const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/splits`, {
2187
- method: "PUT",
2188
- headers: {
2189
- ...this.headers,
2190
- "Content-Type": "application/json"
2191
- },
2192
- signal: AbortSignal.timeout(this.timeout_ms),
2193
- ...this.fetchOptions,
2194
- body
2195
- });
2196
- await require_error.raiseForStatus(res, "update dataset splits", true);
2197
- return res;
2198
- });
2199
- }
2200
- /**
2201
- * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
2202
- */
2203
- async evaluateRun(run, evaluator, { sourceInfo, loadChildRuns, referenceExample } = { loadChildRuns: false }) {
2204
- require_warn.warnOnce("This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.");
2205
- let run_;
2206
- if (typeof run === "string") run_ = await this.readRun(run, { loadChildRuns });
2207
- else if (typeof run === "object" && "id" in run) run_ = run;
2208
- else throw new Error(`Invalid run type: ${typeof run}`);
2209
- if (run_.reference_example_id !== null && run_.reference_example_id !== void 0) referenceExample = await this.readExample(run_.reference_example_id);
2210
- const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
2211
- const [_, feedbacks] = await this._logEvaluationFeedback(feedbackResult, run_, sourceInfo);
2212
- return feedbacks[0];
2213
- }
2214
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId }) {
2215
- if (!runId && !projectId) throw new Error("One of runId or projectId must be provided");
2216
- if (runId && projectId) throw new Error("Only one of runId or projectId can be provided");
2217
- const feedback_source = {
2218
- type: feedbackSourceType ?? "api",
2219
- metadata: sourceInfo ?? {}
2220
- };
2221
- if (sourceRunId !== void 0 && feedback_source?.metadata !== void 0 && !feedback_source.metadata["__run"]) feedback_source.metadata["__run"] = { run_id: sourceRunId };
2222
- if (feedback_source?.metadata !== void 0 && feedback_source.metadata["__run"]?.run_id !== void 0) require__uuid.assertUuid(feedback_source.metadata["__run"].run_id);
2223
- const feedback = {
2224
- id: feedbackId ?? uuid.v4(),
2225
- run_id: runId,
2226
- key,
2227
- score: _formatFeedbackScore(score),
2228
- value,
2229
- correction,
2230
- comment,
2231
- feedback_source,
2232
- comparative_experiment_id: comparativeExperimentId,
2233
- feedbackConfig,
2234
- session_id: projectId
2235
- };
2236
- const body = JSON.stringify(feedback);
2237
- const url = `${this.apiUrl}/feedback`;
2238
- await this.caller.call(async () => {
2239
- const res = await this._fetch(url, {
2240
- method: "POST",
2241
- headers: {
2242
- ...this.headers,
2243
- "Content-Type": "application/json"
2244
- },
2245
- signal: AbortSignal.timeout(this.timeout_ms),
2246
- ...this.fetchOptions,
2247
- body
2248
- });
2249
- await require_error.raiseForStatus(res, "create feedback", true);
2250
- return res;
2251
- });
2252
- return feedback;
2253
- }
2254
- async updateFeedback(feedbackId, { score, value, correction, comment }) {
2255
- const feedbackUpdate = {};
2256
- if (score !== void 0 && score !== null) feedbackUpdate["score"] = _formatFeedbackScore(score);
2257
- if (value !== void 0 && value !== null) feedbackUpdate["value"] = value;
2258
- if (correction !== void 0 && correction !== null) feedbackUpdate["correction"] = correction;
2259
- if (comment !== void 0 && comment !== null) feedbackUpdate["comment"] = comment;
2260
- require__uuid.assertUuid(feedbackId);
2261
- const body = JSON.stringify(feedbackUpdate);
2262
- await this.caller.call(async () => {
2263
- const res = await this._fetch(`${this.apiUrl}/feedback/${feedbackId}`, {
2264
- method: "PATCH",
2265
- headers: {
2266
- ...this.headers,
2267
- "Content-Type": "application/json"
2268
- },
2269
- signal: AbortSignal.timeout(this.timeout_ms),
2270
- ...this.fetchOptions,
2271
- body
2272
- });
2273
- await require_error.raiseForStatus(res, "update feedback", true);
2274
- return res;
2275
- });
2276
- }
2277
- async readFeedback(feedbackId) {
2278
- require__uuid.assertUuid(feedbackId);
2279
- const path = `/feedback/${feedbackId}`;
2280
- const response = await this._get(path);
2281
- return response;
2282
- }
2283
- async deleteFeedback(feedbackId) {
2284
- require__uuid.assertUuid(feedbackId);
2285
- const path = `/feedback/${feedbackId}`;
2286
- await this.caller.call(async () => {
2287
- const res = await this._fetch(this.apiUrl + path, {
2288
- method: "DELETE",
2289
- headers: this.headers,
2290
- signal: AbortSignal.timeout(this.timeout_ms),
2291
- ...this.fetchOptions
2292
- });
2293
- await require_error.raiseForStatus(res, `delete ${path}`, true);
2294
- return res;
2295
- });
2296
- }
2297
- async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes } = {}) {
2298
- const queryParams = new URLSearchParams();
2299
- if (runIds) for (const runId of runIds) {
2300
- require__uuid.assertUuid(runId);
2301
- queryParams.append("run", runId);
2302
- }
2303
- if (feedbackKeys) for (const key of feedbackKeys) queryParams.append("key", key);
2304
- if (feedbackSourceTypes) for (const type of feedbackSourceTypes) queryParams.append("source", type);
2305
- for await (const feedbacks of this._getPaginated("/feedback", queryParams)) yield* feedbacks;
2306
- }
2307
- /**
2308
- * Creates a presigned feedback token and URL.
2309
- *
2310
- * The token can be used to authorize feedback metrics without
2311
- * needing an API key. This is useful for giving browser-based
2312
- * applications the ability to submit feedback without needing
2313
- * to expose an API key.
2314
- *
2315
- * @param runId The ID of the run.
2316
- * @param feedbackKey The feedback key.
2317
- * @param options Additional options for the token.
2318
- * @param options.expiration The expiration time for the token.
2319
- *
2320
- * @returns A promise that resolves to a FeedbackIngestToken.
2321
- */
2322
- async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig } = {}) {
2323
- const body = {
2324
- run_id: runId,
2325
- feedback_key: feedbackKey,
2326
- feedback_config: feedbackConfig
2327
- };
2328
- if (expiration) {
2329
- if (typeof expiration === "string") body["expires_at"] = expiration;
2330
- else if (expiration?.hours || expiration?.minutes || expiration?.days) body["expires_in"] = expiration;
2331
- } else body["expires_in"] = { hours: 3 };
2332
- const serializedBody = JSON.stringify(body);
2333
- const response = await this.caller.call(async () => {
2334
- const res = await this._fetch(`${this.apiUrl}/feedback/tokens`, {
2335
- method: "POST",
2336
- headers: {
2337
- ...this.headers,
2338
- "Content-Type": "application/json"
2339
- },
2340
- signal: AbortSignal.timeout(this.timeout_ms),
2341
- ...this.fetchOptions,
2342
- body: serializedBody
2343
- });
2344
- await require_error.raiseForStatus(res, "create presigned feedback token");
2345
- return res;
2346
- });
2347
- return await response.json();
2348
- }
2349
- async createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id }) {
2350
- if (experimentIds.length === 0) throw new Error("At least one experiment is required");
2351
- if (!referenceDatasetId) referenceDatasetId = (await this.readProject({ projectId: experimentIds[0] })).reference_dataset_id;
2352
- if (!referenceDatasetId == null) throw new Error("A reference dataset is required");
2353
- const body = {
2354
- id,
2355
- name,
2356
- experiment_ids: experimentIds,
2357
- reference_dataset_id: referenceDatasetId,
2358
- description,
2359
- created_at: (createdAt ?? /* @__PURE__ */ new Date())?.toISOString(),
2360
- extra: {}
2361
- };
2362
- if (metadata) body.extra["metadata"] = metadata;
2363
- const serializedBody = JSON.stringify(body);
2364
- const response = await this.caller.call(async () => {
2365
- const res = await this._fetch(`${this.apiUrl}/datasets/comparative`, {
2366
- method: "POST",
2367
- headers: {
2368
- ...this.headers,
2369
- "Content-Type": "application/json"
2370
- },
2371
- signal: AbortSignal.timeout(this.timeout_ms),
2372
- ...this.fetchOptions,
2373
- body: serializedBody
2374
- });
2375
- await require_error.raiseForStatus(res, "create comparative experiment");
2376
- return res;
2377
- });
2378
- return response.json();
2379
- }
2380
- /**
2381
- * Retrieves a list of presigned feedback tokens for a given run ID.
2382
- * @param runId The ID of the run.
2383
- * @returns An async iterable of FeedbackIngestToken objects.
2384
- */
2385
- async *listPresignedFeedbackTokens(runId) {
2386
- require__uuid.assertUuid(runId);
2387
- const params = new URLSearchParams({ run_id: runId });
2388
- for await (const tokens of this._getPaginated("/feedback/tokens", params)) yield* tokens;
2389
- }
2390
- _selectEvalResults(results) {
2391
- let results_;
2392
- if ("results" in results) results_ = results.results;
2393
- else if (Array.isArray(results)) results_ = results;
2394
- else results_ = [results];
2395
- return results_;
2396
- }
2397
- async _logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
2398
- const evalResults = this._selectEvalResults(evaluatorResponse);
2399
- const feedbacks = [];
2400
- for (const res of evalResults) {
2401
- let sourceInfo_ = sourceInfo || {};
2402
- if (res.evaluatorInfo) sourceInfo_ = {
2403
- ...res.evaluatorInfo,
2404
- ...sourceInfo_
2405
- };
2406
- let runId_ = null;
2407
- if (res.targetRunId) runId_ = res.targetRunId;
2408
- else if (run) runId_ = run.id;
2409
- feedbacks.push(await this.createFeedback(runId_, res.key, {
2410
- score: res.score,
2411
- value: res.value,
2412
- comment: res.comment,
2413
- correction: res.correction,
2414
- sourceInfo: sourceInfo_,
2415
- sourceRunId: res.sourceRunId,
2416
- feedbackConfig: res.feedbackConfig,
2417
- feedbackSourceType: "model"
2418
- }));
2419
- }
2420
- return [evalResults, feedbacks];
2421
- }
2422
- async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
2423
- const [results] = await this._logEvaluationFeedback(evaluatorResponse, run, sourceInfo);
2424
- return results;
2425
- }
2426
- /**
2427
- * API for managing annotation queues
2428
- */
2429
- /**
2430
- * List the annotation queues on the LangSmith API.
2431
- * @param options - The options for listing annotation queues
2432
- * @param options.queueIds - The IDs of the queues to filter by
2433
- * @param options.name - The name of the queue to filter by
2434
- * @param options.nameContains - The substring that the queue name should contain
2435
- * @param options.limit - The maximum number of queues to return
2436
- * @returns An iterator of AnnotationQueue objects
2437
- */
2438
- async *listAnnotationQueues(options = {}) {
2439
- const { queueIds, name, nameContains, limit } = options;
2440
- const params = new URLSearchParams();
2441
- if (queueIds) queueIds.forEach((id, i) => {
2442
- require__uuid.assertUuid(id, `queueIds[${i}]`);
2443
- params.append("ids", id);
2444
- });
2445
- if (name) params.append("name", name);
2446
- if (nameContains) params.append("name_contains", nameContains);
2447
- params.append("limit", (limit !== void 0 ? Math.min(limit, 100) : 100).toString());
2448
- let count = 0;
2449
- for await (const queues of this._getPaginated("/annotation-queues", params)) {
2450
- yield* queues;
2451
- count++;
2452
- if (limit !== void 0 && count >= limit) break;
2453
- }
2454
- }
2455
- /**
2456
- * Create an annotation queue on the LangSmith API.
2457
- * @param options - The options for creating an annotation queue
2458
- * @param options.name - The name of the annotation queue
2459
- * @param options.description - The description of the annotation queue
2460
- * @param options.queueId - The ID of the annotation queue
2461
- * @returns The created AnnotationQueue object
2462
- */
2463
- async createAnnotationQueue(options) {
2464
- const { name, description, queueId, rubricInstructions } = options;
2465
- const body = {
2466
- name,
2467
- description,
2468
- id: queueId || uuid.v4(),
2469
- rubric_instructions: rubricInstructions
2470
- };
2471
- const serializedBody = JSON.stringify(Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== void 0)));
2472
- const response = await this.caller.call(async () => {
2473
- const res = await this._fetch(`${this.apiUrl}/annotation-queues`, {
2474
- method: "POST",
2475
- headers: {
2476
- ...this.headers,
2477
- "Content-Type": "application/json"
2478
- },
2479
- signal: AbortSignal.timeout(this.timeout_ms),
2480
- ...this.fetchOptions,
2481
- body: serializedBody
2482
- });
2483
- await require_error.raiseForStatus(res, "create annotation queue");
2484
- return res;
2485
- });
2486
- return response.json();
2487
- }
2488
- /**
2489
- * Read an annotation queue with the specified queue ID.
2490
- * @param queueId - The ID of the annotation queue to read
2491
- * @returns The AnnotationQueueWithDetails object
2492
- */
2493
- async readAnnotationQueue(queueId) {
2494
- const response = await this.caller.call(async () => {
2495
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}`, {
2496
- method: "GET",
2497
- headers: this.headers,
2498
- signal: AbortSignal.timeout(this.timeout_ms),
2499
- ...this.fetchOptions
2500
- });
2501
- await require_error.raiseForStatus(res, "read annotation queue");
2502
- return res;
2503
- });
2504
- return response.json();
2505
- }
2506
- /**
2507
- * Update an annotation queue with the specified queue ID.
2508
- * @param queueId - The ID of the annotation queue to update
2509
- * @param options - The options for updating the annotation queue
2510
- * @param options.name - The new name for the annotation queue
2511
- * @param options.description - The new description for the annotation queue
2512
- */
2513
- async updateAnnotationQueue(queueId, options) {
2514
- const { name, description, rubricInstructions } = options;
2515
- const body = JSON.stringify({
2516
- name,
2517
- description,
2518
- rubric_instructions: rubricInstructions
2519
- });
2520
- await this.caller.call(async () => {
2521
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}`, {
2522
- method: "PATCH",
2523
- headers: {
2524
- ...this.headers,
2525
- "Content-Type": "application/json"
2526
- },
2527
- signal: AbortSignal.timeout(this.timeout_ms),
2528
- ...this.fetchOptions,
2529
- body
2530
- });
2531
- await require_error.raiseForStatus(res, "update annotation queue", true);
2532
- return res;
2533
- });
2534
- }
2535
- /**
2536
- * Delete an annotation queue with the specified queue ID.
2537
- * @param queueId - The ID of the annotation queue to delete
2538
- */
2539
- async deleteAnnotationQueue(queueId) {
2540
- await this.caller.call(async () => {
2541
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}`, {
2542
- method: "DELETE",
2543
- headers: {
2544
- ...this.headers,
2545
- Accept: "application/json"
2546
- },
2547
- signal: AbortSignal.timeout(this.timeout_ms),
2548
- ...this.fetchOptions
2549
- });
2550
- await require_error.raiseForStatus(res, "delete annotation queue", true);
2551
- return res;
2552
- });
2553
- }
2554
- /**
2555
- * Add runs to an annotation queue with the specified queue ID.
2556
- * @param queueId - The ID of the annotation queue
2557
- * @param runIds - The IDs of the runs to be added to the annotation queue
2558
- */
2559
- async addRunsToAnnotationQueue(queueId, runIds) {
2560
- const body = JSON.stringify(runIds.map((id, i) => require__uuid.assertUuid(id, `runIds[${i}]`).toString()));
2561
- await this.caller.call(async () => {
2562
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}/runs`, {
2563
- method: "POST",
2564
- headers: {
2565
- ...this.headers,
2566
- "Content-Type": "application/json"
2567
- },
2568
- signal: AbortSignal.timeout(this.timeout_ms),
2569
- ...this.fetchOptions,
2570
- body
2571
- });
2572
- await require_error.raiseForStatus(res, "add runs to annotation queue", true);
2573
- return res;
2574
- });
2575
- }
2576
- /**
2577
- * Get a run from an annotation queue at the specified index.
2578
- * @param queueId - The ID of the annotation queue
2579
- * @param index - The index of the run to retrieve
2580
- * @returns A Promise that resolves to a RunWithAnnotationQueueInfo object
2581
- * @throws {Error} If the run is not found at the given index or for other API-related errors
2582
- */
2583
- async getRunFromAnnotationQueue(queueId, index) {
2584
- const baseUrl = `/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}/run`;
2585
- const response = await this.caller.call(async () => {
2586
- const res = await this._fetch(`${this.apiUrl}${baseUrl}/${index}`, {
2587
- method: "GET",
2588
- headers: this.headers,
2589
- signal: AbortSignal.timeout(this.timeout_ms),
2590
- ...this.fetchOptions
2591
- });
2592
- await require_error.raiseForStatus(res, "get run from annotation queue");
2593
- return res;
2594
- });
2595
- return response.json();
2596
- }
2597
- /**
2598
- * Delete a run from an an annotation queue.
2599
- * @param queueId - The ID of the annotation queue to delete the run from
2600
- * @param queueRunId - The ID of the run to delete from the annotation queue
2601
- */
2602
- async deleteRunFromAnnotationQueue(queueId, queueRunId) {
2603
- await this.caller.call(async () => {
2604
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}/runs/${require__uuid.assertUuid(queueRunId, "queueRunId")}`, {
2605
- method: "DELETE",
2606
- headers: {
2607
- ...this.headers,
2608
- Accept: "application/json"
2609
- },
2610
- signal: AbortSignal.timeout(this.timeout_ms),
2611
- ...this.fetchOptions
2612
- });
2613
- await require_error.raiseForStatus(res, "delete run from annotation queue", true);
2614
- return res;
2615
- });
2616
- }
2617
- /**
2618
- * Get the size of an annotation queue.
2619
- * @param queueId - The ID of the annotation queue
2620
- */
2621
- async getSizeFromAnnotationQueue(queueId) {
2622
- const response = await this.caller.call(async () => {
2623
- const res = await this._fetch(`${this.apiUrl}/annotation-queues/${require__uuid.assertUuid(queueId, "queueId")}/size`, {
2624
- method: "GET",
2625
- headers: this.headers,
2626
- signal: AbortSignal.timeout(this.timeout_ms),
2627
- ...this.fetchOptions
2628
- });
2629
- await require_error.raiseForStatus(res, "get size from annotation queue");
2630
- return res;
2631
- });
2632
- return response.json();
2633
- }
2634
- async _currentTenantIsOwner(owner) {
2635
- const settings = await this._getSettings();
2636
- return owner == "-" || settings.tenant_handle === owner;
2637
- }
2638
- async _ownerConflictError(action, owner) {
2639
- const settings = await this._getSettings();
2640
- return /* @__PURE__ */ new Error(`Cannot ${action} for another tenant.\n
2641
- Current tenant: ${settings.tenant_handle}\n
2642
- Requested tenant: ${owner}`);
2643
- }
2644
- async _getLatestCommitHash(promptOwnerAndName) {
2645
- const response = await this.caller.call(async () => {
2646
- const res = await this._fetch(`${this.apiUrl}/commits/${promptOwnerAndName}/?limit=1&offset=0`, {
2647
- method: "GET",
2648
- headers: this.headers,
2649
- signal: AbortSignal.timeout(this.timeout_ms),
2650
- ...this.fetchOptions
2651
- });
2652
- await require_error.raiseForStatus(res, "get latest commit hash");
2653
- return res;
2654
- });
2655
- const json = await response.json();
2656
- if (json.commits.length === 0) return void 0;
2657
- return json.commits[0].commit_hash;
2658
- }
2659
- async _likeOrUnlikePrompt(promptIdentifier, like) {
2660
- const [owner, promptName, _] = require_prompts.parsePromptIdentifier(promptIdentifier);
2661
- const body = JSON.stringify({ like });
2662
- const response = await this.caller.call(async () => {
2663
- const res = await this._fetch(`${this.apiUrl}/likes/${owner}/${promptName}`, {
2664
- method: "POST",
2665
- headers: {
2666
- ...this.headers,
2667
- "Content-Type": "application/json"
2668
- },
2669
- signal: AbortSignal.timeout(this.timeout_ms),
2670
- ...this.fetchOptions,
2671
- body
2672
- });
2673
- await require_error.raiseForStatus(res, `${like ? "like" : "unlike"} prompt`);
2674
- return res;
2675
- });
2676
- return response.json();
2677
- }
2678
- async _getPromptUrl(promptIdentifier) {
2679
- const [owner, promptName, commitHash] = require_prompts.parsePromptIdentifier(promptIdentifier);
2680
- if (!await this._currentTenantIsOwner(owner)) if (commitHash !== "latest") return `${this.getHostUrl()}/hub/${owner}/${promptName}/${commitHash.substring(0, 8)}`;
2681
- else return `${this.getHostUrl()}/hub/${owner}/${promptName}`;
2682
- else {
2683
- const settings = await this._getSettings();
2684
- if (commitHash !== "latest") return `${this.getHostUrl()}/prompts/${promptName}/${commitHash.substring(0, 8)}?organizationId=${settings.id}`;
2685
- else return `${this.getHostUrl()}/prompts/${promptName}?organizationId=${settings.id}`;
2686
- }
2687
- }
2688
- async promptExists(promptIdentifier) {
2689
- const prompt = await this.getPrompt(promptIdentifier);
2690
- return !!prompt;
2691
- }
2692
- async likePrompt(promptIdentifier) {
2693
- return this._likeOrUnlikePrompt(promptIdentifier, true);
2694
- }
2695
- async unlikePrompt(promptIdentifier) {
2696
- return this._likeOrUnlikePrompt(promptIdentifier, false);
2697
- }
2698
- async *listCommits(promptOwnerAndName) {
2699
- for await (const commits of this._getPaginated(`/commits/${promptOwnerAndName}/`, new URLSearchParams(), (res) => res.commits)) yield* commits;
2700
- }
2701
- async *listPrompts(options) {
2702
- const params = new URLSearchParams();
2703
- params.append("sort_field", options?.sortField ?? "updated_at");
2704
- params.append("sort_direction", "desc");
2705
- params.append("is_archived", (!!options?.isArchived).toString());
2706
- if (options?.isPublic !== void 0) params.append("is_public", options.isPublic.toString());
2707
- if (options?.query) params.append("query", options.query);
2708
- for await (const prompts of this._getPaginated("/repos", params, (res) => res.repos)) yield* prompts;
2709
- }
2710
- async getPrompt(promptIdentifier) {
2711
- const [owner, promptName, _] = require_prompts.parsePromptIdentifier(promptIdentifier);
2712
- const response = await this.caller.call(async () => {
2713
- const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
2714
- method: "GET",
2715
- headers: this.headers,
2716
- signal: AbortSignal.timeout(this.timeout_ms),
2717
- ...this.fetchOptions
2718
- });
2719
- if (res?.status === 404) return null;
2720
- await require_error.raiseForStatus(res, "get prompt");
2721
- return res;
2722
- });
2723
- const result = await response?.json();
2724
- if (result?.repo) return result.repo;
2725
- else return null;
2726
- }
2727
- async createPrompt(promptIdentifier, options) {
2728
- const settings = await this._getSettings();
2729
- if (options?.isPublic && !settings.tenant_handle) throw new Error(`Cannot create a public prompt without first\n
2730
- creating a LangChain Hub handle.
2731
- You can add a handle by creating a public prompt at:\n
2732
- https://smith.langchain.com/prompts`);
2733
- const [owner, promptName, _] = require_prompts.parsePromptIdentifier(promptIdentifier);
2734
- if (!await this._currentTenantIsOwner(owner)) throw await this._ownerConflictError("create a prompt", owner);
2735
- const data = {
2736
- repo_handle: promptName,
2737
- ...options?.description && { description: options.description },
2738
- ...options?.readme && { readme: options.readme },
2739
- ...options?.tags && { tags: options.tags },
2740
- is_public: !!options?.isPublic
2741
- };
2742
- const body = JSON.stringify(data);
2743
- const response = await this.caller.call(async () => {
2744
- const res = await this._fetch(`${this.apiUrl}/repos/`, {
2745
- method: "POST",
2746
- headers: {
2747
- ...this.headers,
2748
- "Content-Type": "application/json"
2749
- },
2750
- signal: AbortSignal.timeout(this.timeout_ms),
2751
- ...this.fetchOptions,
2752
- body
2753
- });
2754
- await require_error.raiseForStatus(res, "create prompt");
2755
- return res;
2756
- });
2757
- const { repo } = await response.json();
2758
- return repo;
2759
- }
2760
- async createCommit(promptIdentifier, object, options) {
2761
- if (!await this.promptExists(promptIdentifier)) throw new Error("Prompt does not exist, you must create it first.");
2762
- const [owner, promptName, _] = require_prompts.parsePromptIdentifier(promptIdentifier);
2763
- const resolvedParentCommitHash = options?.parentCommitHash === "latest" || !options?.parentCommitHash ? await this._getLatestCommitHash(`${owner}/${promptName}`) : options?.parentCommitHash;
2764
- const payload = {
2765
- manifest: JSON.parse(JSON.stringify(object)),
2766
- parent_commit: resolvedParentCommitHash
2767
- };
2768
- const body = JSON.stringify(payload);
2769
- const response = await this.caller.call(async () => {
2770
- const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}`, {
2771
- method: "POST",
2772
- headers: {
2773
- ...this.headers,
2774
- "Content-Type": "application/json"
2775
- },
2776
- signal: AbortSignal.timeout(this.timeout_ms),
2777
- ...this.fetchOptions,
2778
- body
2779
- });
2780
- await require_error.raiseForStatus(res, "create commit");
2781
- return res;
2782
- });
2783
- const result = await response.json();
2784
- return this._getPromptUrl(`${owner}/${promptName}${result.commit_hash ? `:${result.commit_hash}` : ""}`);
2785
- }
2786
- /**
2787
- * Update examples with attachments using multipart form data.
2788
- * @param updates List of ExampleUpdateWithAttachments objects to upsert
2789
- * @returns Promise with the update response
2790
- */
2791
- async updateExamplesMultipart(datasetId, updates = []) {
2792
- return this._updateExamplesMultipart(datasetId, updates);
2793
- }
2794
- async _updateExamplesMultipart(datasetId, updates = []) {
2795
- if (!await this._getDatasetExamplesMultiPartSupport()) throw new Error("Your LangSmith deployment does not allow using the multipart examples endpoint, please upgrade your deployment to the latest version.");
2796
- const formData = new FormData();
2797
- for (const example of updates) {
2798
- const exampleId = example.id;
2799
- const exampleBody = {
2800
- ...example.metadata && { metadata: example.metadata },
2801
- ...example.split && { split: example.split }
2802
- };
2803
- const stringifiedExample = require_index.serialize(exampleBody, `Serializing body for example with id: ${exampleId}`);
2804
- const exampleBlob = new Blob([stringifiedExample], { type: "application/json" });
2805
- formData.append(exampleId, exampleBlob);
2806
- if (example.inputs) {
2807
- const stringifiedInputs = require_index.serialize(example.inputs, `Serializing inputs for example with id: ${exampleId}`);
2808
- const inputsBlob = new Blob([stringifiedInputs], { type: "application/json" });
2809
- formData.append(`${exampleId}.inputs`, inputsBlob);
2810
- }
2811
- if (example.outputs) {
2812
- const stringifiedOutputs = require_index.serialize(example.outputs, `Serializing outputs whle updating example with id: ${exampleId}`);
2813
- const outputsBlob = new Blob([stringifiedOutputs], { type: "application/json" });
2814
- formData.append(`${exampleId}.outputs`, outputsBlob);
2815
- }
2816
- if (example.attachments) for (const [name, attachment] of Object.entries(example.attachments)) {
2817
- let mimeType;
2818
- let data;
2819
- if (Array.isArray(attachment)) [mimeType, data] = attachment;
2820
- else {
2821
- mimeType = attachment.mimeType;
2822
- data = attachment.data;
2823
- }
2824
- const attachmentBlob = new Blob([data], { type: `${mimeType}; length=${data.byteLength}` });
2825
- formData.append(`${exampleId}.attachment.${name}`, attachmentBlob);
2826
- }
2827
- if (example.attachments_operations) {
2828
- const stringifiedAttachmentsOperations = require_index.serialize(example.attachments_operations, `Serializing attachments while updating example with id: ${exampleId}`);
2829
- const attachmentsOperationsBlob = new Blob([stringifiedAttachmentsOperations], { type: "application/json" });
2830
- formData.append(`${exampleId}.attachments_operations`, attachmentsOperationsBlob);
2831
- }
2832
- }
2833
- const datasetIdToUse = datasetId ?? updates[0]?.dataset_id;
2834
- const response = await this.caller.call(async () => {
2835
- const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetIdToUse}/examples`)}`, {
2836
- method: "PATCH",
2837
- headers: this.headers,
2838
- signal: AbortSignal.timeout(this.timeout_ms),
2839
- ...this.fetchOptions,
2840
- body: formData
2841
- });
2842
- await require_error.raiseForStatus(res, "update examples");
2843
- return res;
2844
- });
2845
- return response.json();
2846
- }
2847
- /**
2848
- * Upload examples with attachments using multipart form data.
2849
- * @param uploads List of ExampleUploadWithAttachments objects to upload
2850
- * @returns Promise with the upload response
2851
- * @deprecated This method is deprecated and will be removed in future LangSmith versions, please use `createExamples` instead
2852
- */
2853
- async uploadExamplesMultipart(datasetId, uploads = []) {
2854
- return this._uploadExamplesMultipart(datasetId, uploads);
2855
- }
2856
- async _uploadExamplesMultipart(datasetId, uploads = []) {
2857
- if (!await this._getDatasetExamplesMultiPartSupport()) throw new Error("Your LangSmith deployment does not allow using the multipart examples endpoint, please upgrade your deployment to the latest version.");
2858
- const formData = new FormData();
2859
- for (const example of uploads) {
2860
- const exampleId = (example.id ?? uuid.v4()).toString();
2861
- const exampleBody = {
2862
- created_at: example.created_at,
2863
- ...example.metadata && { metadata: example.metadata },
2864
- ...example.split && { split: example.split },
2865
- ...example.source_run_id && { source_run_id: example.source_run_id },
2866
- ...example.use_source_run_io && { use_source_run_io: example.use_source_run_io },
2867
- ...example.use_source_run_attachments && { use_source_run_attachments: example.use_source_run_attachments }
2868
- };
2869
- const stringifiedExample = require_index.serialize(exampleBody, `Serializing body for uploaded example with id: ${exampleId}`);
2870
- const exampleBlob = new Blob([stringifiedExample], { type: "application/json" });
2871
- formData.append(exampleId, exampleBlob);
2872
- if (example.inputs) {
2873
- const stringifiedInputs = require_index.serialize(example.inputs, `Serializing inputs for uploaded example with id: ${exampleId}`);
2874
- const inputsBlob = new Blob([stringifiedInputs], { type: "application/json" });
2875
- formData.append(`${exampleId}.inputs`, inputsBlob);
2876
- }
2877
- if (example.outputs) {
2878
- const stringifiedOutputs = require_index.serialize(example.outputs, `Serializing outputs for uploaded example with id: ${exampleId}`);
2879
- const outputsBlob = new Blob([stringifiedOutputs], { type: "application/json" });
2880
- formData.append(`${exampleId}.outputs`, outputsBlob);
2881
- }
2882
- if (example.attachments) for (const [name, attachment] of Object.entries(example.attachments)) {
2883
- let mimeType;
2884
- let data;
2885
- if (Array.isArray(attachment)) [mimeType, data] = attachment;
2886
- else {
2887
- mimeType = attachment.mimeType;
2888
- data = attachment.data;
2889
- }
2890
- const attachmentBlob = new Blob([data], { type: `${mimeType}; length=${data.byteLength}` });
2891
- formData.append(`${exampleId}.attachment.${name}`, attachmentBlob);
2892
- }
2893
- }
2894
- const response = await this.caller.call(async () => {
2895
- const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetId}/examples`)}`, {
2896
- method: "POST",
2897
- headers: this.headers,
2898
- signal: AbortSignal.timeout(this.timeout_ms),
2899
- ...this.fetchOptions,
2900
- body: formData
2901
- });
2902
- await require_error.raiseForStatus(res, "upload examples");
2903
- return res;
2904
- });
2905
- return response.json();
2906
- }
2907
- async updatePrompt(promptIdentifier, options) {
2908
- if (!await this.promptExists(promptIdentifier)) throw new Error("Prompt does not exist, you must create it first.");
2909
- const [owner, promptName] = require_prompts.parsePromptIdentifier(promptIdentifier);
2910
- if (!await this._currentTenantIsOwner(owner)) throw await this._ownerConflictError("update a prompt", owner);
2911
- const payload = {};
2912
- if (options?.description !== void 0) payload.description = options.description;
2913
- if (options?.readme !== void 0) payload.readme = options.readme;
2914
- if (options?.tags !== void 0) payload.tags = options.tags;
2915
- if (options?.isPublic !== void 0) payload.is_public = options.isPublic;
2916
- if (options?.isArchived !== void 0) payload.is_archived = options.isArchived;
2917
- if (Object.keys(payload).length === 0) throw new Error("No valid update options provided");
2918
- const body = JSON.stringify(payload);
2919
- const response = await this.caller.call(async () => {
2920
- const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
2921
- method: "PATCH",
2922
- headers: {
2923
- ...this.headers,
2924
- "Content-Type": "application/json"
2925
- },
2926
- signal: AbortSignal.timeout(this.timeout_ms),
2927
- ...this.fetchOptions,
2928
- body
2929
- });
2930
- await require_error.raiseForStatus(res, "update prompt");
2931
- return res;
2932
- });
2933
- return response.json();
2934
- }
2935
- async deletePrompt(promptIdentifier) {
2936
- if (!await this.promptExists(promptIdentifier)) throw new Error("Prompt does not exist, you must create it first.");
2937
- const [owner, promptName, _] = require_prompts.parsePromptIdentifier(promptIdentifier);
2938
- if (!await this._currentTenantIsOwner(owner)) throw await this._ownerConflictError("delete a prompt", owner);
2939
- const response = await this.caller.call(async () => {
2940
- const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
2941
- method: "DELETE",
2942
- headers: this.headers,
2943
- signal: AbortSignal.timeout(this.timeout_ms),
2944
- ...this.fetchOptions
2945
- });
2946
- await require_error.raiseForStatus(res, "delete prompt");
2947
- return res;
2948
- });
2949
- return response.json();
2950
- }
2951
- async pullPromptCommit(promptIdentifier, options) {
2952
- const [owner, promptName, commitHash] = require_prompts.parsePromptIdentifier(promptIdentifier);
2953
- const response = await this.caller.call(async () => {
2954
- const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
2955
- method: "GET",
2956
- headers: this.headers,
2957
- signal: AbortSignal.timeout(this.timeout_ms),
2958
- ...this.fetchOptions
2959
- });
2960
- await require_error.raiseForStatus(res, "pull prompt commit");
2961
- return res;
2962
- });
2963
- const result = await response.json();
2964
- return {
2965
- owner,
2966
- repo: promptName,
2967
- commit_hash: result.commit_hash,
2968
- manifest: result.manifest,
2969
- examples: result.examples
2970
- };
2971
- }
2972
- /**
2973
- * This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
2974
- * Using this method directly returns the JSON string of the prompt rather than a LangChain object.
2975
- * @private
2976
- */
2977
- async _pullPrompt(promptIdentifier, options) {
2978
- const promptObject = await this.pullPromptCommit(promptIdentifier, { includeModel: options?.includeModel });
2979
- const prompt = JSON.stringify(promptObject.manifest);
2980
- return prompt;
2981
- }
2982
- async pushPrompt(promptIdentifier, options) {
2983
- if (await this.promptExists(promptIdentifier)) {
2984
- if (options && Object.keys(options).some((key) => key !== "object")) await this.updatePrompt(promptIdentifier, {
2985
- description: options?.description,
2986
- readme: options?.readme,
2987
- tags: options?.tags,
2988
- isPublic: options?.isPublic
2989
- });
2990
- } else await this.createPrompt(promptIdentifier, {
2991
- description: options?.description,
2992
- readme: options?.readme,
2993
- tags: options?.tags,
2994
- isPublic: options?.isPublic
2995
- });
2996
- if (!options?.object) return await this._getPromptUrl(promptIdentifier);
2997
- const url = await this.createCommit(promptIdentifier, options?.object, { parentCommitHash: options?.parentCommitHash });
2998
- return url;
2999
- }
3000
- /**
3001
- * Clone a public dataset to your own langsmith tenant.
3002
- * This operation is idempotent. If you already have a dataset with the given name,
3003
- * this function will do nothing.
3004
-
3005
- * @param {string} tokenOrUrl The token of the public dataset to clone.
3006
- * @param {Object} [options] Additional options for cloning the dataset.
3007
- * @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
3008
- * @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
3009
- * @returns {Promise<void>}
3010
- */
3011
- async clonePublicDataset(tokenOrUrl, options = {}) {
3012
- const { sourceApiUrl = this.apiUrl, datasetName } = options;
3013
- const [parsedApiUrl, tokenUuid] = this.parseTokenOrUrl(tokenOrUrl, sourceApiUrl);
3014
- const sourceClient = new Client({
3015
- apiUrl: parsedApiUrl,
3016
- apiKey: "placeholder"
3017
- });
3018
- const ds = await sourceClient.readSharedDataset(tokenUuid);
3019
- const finalDatasetName = datasetName || ds.name;
3020
- try {
3021
- if (await this.hasDataset({ datasetId: finalDatasetName })) {
3022
- console.log(`Dataset ${finalDatasetName} already exists in your tenant. Skipping.`);
3023
- return;
3024
- }
3025
- } catch (_) {}
3026
- const examples = await sourceClient.listSharedExamples(tokenUuid);
3027
- const dataset = await this.createDataset(finalDatasetName, {
3028
- description: ds.description,
3029
- dataType: ds.data_type || "kv",
3030
- inputsSchema: ds.inputs_schema_definition ?? void 0,
3031
- outputsSchema: ds.outputs_schema_definition ?? void 0
3032
- });
3033
- try {
3034
- await this.createExamples({
3035
- inputs: examples.map((e) => e.inputs),
3036
- outputs: examples.flatMap((e) => e.outputs ? [e.outputs] : []),
3037
- datasetId: dataset.id
3038
- });
3039
- } catch (e) {
3040
- console.error(`An error occurred while creating dataset ${finalDatasetName}. You should delete it manually.`);
3041
- throw e;
3042
- }
3043
- }
3044
- parseTokenOrUrl(urlOrToken, apiUrl, numParts = 2, kind = "dataset") {
3045
- try {
3046
- require__uuid.assertUuid(urlOrToken);
3047
- return [apiUrl, urlOrToken];
3048
- } catch (_) {}
3049
- try {
3050
- const parsedUrl = new URL(urlOrToken);
3051
- const pathParts = parsedUrl.pathname.split("/").filter((part) => part !== "");
3052
- if (pathParts.length >= numParts) {
3053
- const tokenUuid = pathParts[pathParts.length - numParts];
3054
- return [apiUrl, tokenUuid];
3055
- } else throw new Error(`Invalid public ${kind} URL: ${urlOrToken}`);
3056
- } catch (error) {
3057
- throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
3058
- }
3059
- }
3060
- /**
3061
- * Awaits all pending trace batches. Useful for environments where
3062
- * you need to be sure that all tracing requests finish before execution ends,
3063
- * such as serverless environments.
3064
- *
3065
- * @example
3066
- * ```
3067
- * import { Client } from "langsmith";
3068
- *
3069
- * const client = new Client();
3070
- *
3071
- * try {
3072
- * // Tracing happens here
3073
- * ...
3074
- * } finally {
3075
- * await client.awaitPendingTraceBatches();
3076
- * }
3077
- * ```
3078
- *
3079
- * @returns A promise that resolves once all currently pending traces have sent.
3080
- */
3081
- async awaitPendingTraceBatches() {
3082
- if (this.manualFlushMode) {
3083
- console.warn("[WARNING]: When tracing in manual flush mode, you must call `await client.flush()` manually to submit trace batches.");
3084
- return Promise.resolve();
3085
- }
3086
- await Promise.all([...this.autoBatchQueue.items.map(({ itemPromise }) => itemPromise), this.batchIngestCaller.queue.onIdle()]);
3087
- if (this.langSmithToOTELTranslator !== void 0) await require_otel.getDefaultOTLPTracerComponents()?.DEFAULT_LANGSMITH_SPAN_PROCESSOR?.forceFlush();
3088
- }
3089
- };
3090
- function isExampleCreate(input) {
3091
- return "dataset_id" in input || "dataset_name" in input;
3092
- }
3093
-
3094
- //#endregion
3095
- exports.Client = Client;
3096
- //# sourceMappingURL=client.cjs.map