langchain 1.0.1 → 1.0.2

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