langsmith 0.7.8 → 0.7.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +161 -15
  2. package/dist/_openapi_client/client.cjs +814 -0
  3. package/dist/_openapi_client/client.d.ts +247 -0
  4. package/dist/_openapi_client/client.js +777 -0
  5. package/dist/_openapi_client/core/api-promise.cjs +100 -0
  6. package/dist/_openapi_client/core/api-promise.d.ts +45 -0
  7. package/dist/_openapi_client/core/api-promise.js +96 -0
  8. package/dist/_openapi_client/core/error.cjs +134 -0
  9. package/dist/_openapi_client/core/error.d.ts +45 -0
  10. package/dist/_openapi_client/core/error.js +118 -0
  11. package/dist/_openapi_client/core/pagination.cjs +374 -0
  12. package/dist/_openapi_client/core/pagination.d.ts +157 -0
  13. package/dist/_openapi_client/core/pagination.js +361 -0
  14. package/dist/_openapi_client/core/resource.cjs +17 -0
  15. package/dist/_openapi_client/core/resource.d.ts +5 -0
  16. package/dist/_openapi_client/core/resource.js +13 -0
  17. package/dist/_openapi_client/core/uploads.cjs +5 -0
  18. package/dist/_openapi_client/core/uploads.d.ts +2 -0
  19. package/dist/_openapi_client/core/uploads.js +1 -0
  20. package/dist/_openapi_client/index.cjs +29 -0
  21. package/dist/_openapi_client/index.d.ts +6 -0
  22. package/dist/_openapi_client/index.js +8 -0
  23. package/dist/_openapi_client/internal/builtin-types.cjs +4 -0
  24. package/dist/_openapi_client/internal/builtin-types.d.ts +72 -0
  25. package/dist/_openapi_client/internal/builtin-types.js +3 -0
  26. package/dist/_openapi_client/internal/detect-platform.cjs +162 -0
  27. package/dist/_openapi_client/internal/detect-platform.d.ts +14 -0
  28. package/dist/_openapi_client/internal/detect-platform.js +157 -0
  29. package/dist/_openapi_client/internal/errors.cjs +41 -0
  30. package/dist/_openapi_client/internal/errors.d.ts +2 -0
  31. package/dist/_openapi_client/internal/errors.js +36 -0
  32. package/dist/_openapi_client/internal/headers.cjs +79 -0
  33. package/dist/_openapi_client/internal/headers.d.ts +18 -0
  34. package/dist/_openapi_client/internal/headers.js +74 -0
  35. package/dist/_openapi_client/internal/parse.cjs +40 -0
  36. package/dist/_openapi_client/internal/parse.d.ts +11 -0
  37. package/dist/_openapi_client/internal/parse.js +37 -0
  38. package/dist/_openapi_client/internal/qs/formats.cjs +12 -0
  39. package/dist/_openapi_client/internal/qs/formats.d.ts +6 -0
  40. package/dist/_openapi_client/internal/qs/formats.js +8 -0
  41. package/dist/_openapi_client/internal/qs/stringify.cjs +277 -0
  42. package/dist/_openapi_client/internal/qs/stringify.d.ts +2 -0
  43. package/dist/_openapi_client/internal/qs/stringify.js +274 -0
  44. package/dist/_openapi_client/internal/qs/types.cjs +2 -0
  45. package/dist/_openapi_client/internal/qs/types.d.ts +56 -0
  46. package/dist/_openapi_client/internal/qs/types.js +1 -0
  47. package/dist/_openapi_client/internal/qs/utils.cjs +230 -0
  48. package/dist/_openapi_client/internal/qs/utils.d.ts +14 -0
  49. package/dist/_openapi_client/internal/qs/utils.js +217 -0
  50. package/dist/_openapi_client/internal/request-options.cjs +14 -0
  51. package/dist/_openapi_client/internal/request-options.d.ts +74 -0
  52. package/dist/_openapi_client/internal/request-options.js +10 -0
  53. package/dist/_openapi_client/internal/shim-types.cjs +4 -0
  54. package/dist/_openapi_client/internal/shim-types.d.ts +16 -0
  55. package/dist/_openapi_client/internal/shim-types.js +3 -0
  56. package/dist/_openapi_client/internal/shims.cjs +92 -0
  57. package/dist/_openapi_client/internal/shims.d.ts +25 -0
  58. package/dist/_openapi_client/internal/shims.js +85 -0
  59. package/dist/_openapi_client/internal/to-file.cjs +91 -0
  60. package/dist/_openapi_client/internal/to-file.d.ts +44 -0
  61. package/dist/_openapi_client/internal/to-file.js +88 -0
  62. package/dist/_openapi_client/internal/types.cjs +4 -0
  63. package/dist/_openapi_client/internal/types.d.ts +35 -0
  64. package/dist/_openapi_client/internal/types.js +3 -0
  65. package/dist/_openapi_client/internal/uploads.cjs +140 -0
  66. package/dist/_openapi_client/internal/uploads.d.ts +41 -0
  67. package/dist/_openapi_client/internal/uploads.js +130 -0
  68. package/dist/_openapi_client/internal/utils/env.cjs +22 -0
  69. package/dist/_openapi_client/internal/utils/env.d.ts +8 -0
  70. package/dist/_openapi_client/internal/utils/env.js +18 -0
  71. package/dist/_openapi_client/internal/utils/log.cjs +88 -0
  72. package/dist/_openapi_client/internal/utils/log.d.ts +36 -0
  73. package/dist/_openapi_client/internal/utils/log.js +82 -0
  74. package/dist/_openapi_client/internal/utils/path.cjs +79 -0
  75. package/dist/_openapi_client/internal/utils/path.d.ts +14 -0
  76. package/dist/_openapi_client/internal/utils/path.js +74 -0
  77. package/dist/_openapi_client/internal/utils/query.cjs +42 -0
  78. package/dist/_openapi_client/internal/utils/query.d.ts +1 -0
  79. package/dist/_openapi_client/internal/utils/query.js +6 -0
  80. package/dist/_openapi_client/internal/utils/sleep.cjs +7 -0
  81. package/dist/_openapi_client/internal/utils/sleep.d.ts +1 -0
  82. package/dist/_openapi_client/internal/utils/sleep.js +3 -0
  83. package/dist/_openapi_client/internal/utils/uuid.cjs +19 -0
  84. package/dist/_openapi_client/internal/utils/uuid.d.ts +4 -0
  85. package/dist/_openapi_client/internal/utils/uuid.js +15 -0
  86. package/dist/_openapi_client/internal/utils/values.cjs +112 -0
  87. package/dist/_openapi_client/internal/utils/values.d.ts +17 -0
  88. package/dist/_openapi_client/internal/utils/values.js +94 -0
  89. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.cjs +138 -0
  90. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +367 -0
  91. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +101 -0
  92. package/dist/_openapi_client/resources/annotation-queues/runs.cjs +46 -0
  93. package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +128 -0
  94. package/dist/_openapi_client/resources/annotation-queues/runs.js +42 -0
  95. package/dist/_openapi_client/resources/commits.cjs +44 -0
  96. package/dist/_openapi_client/resources/commits.d.ts +204 -0
  97. package/dist/_openapi_client/resources/commits.js +40 -0
  98. package/dist/_openapi_client/resources/datasets/comparative.cjs +22 -0
  99. package/dist/_openapi_client/resources/datasets/comparative.d.ts +55 -0
  100. package/dist/_openapi_client/resources/datasets/comparative.js +18 -0
  101. package/dist/_openapi_client/resources/datasets/datasets.cjs +193 -0
  102. package/dist/_openapi_client/resources/datasets/datasets.d.ts +374 -0
  103. package/dist/_openapi_client/resources/datasets/datasets.js +156 -0
  104. package/dist/_openapi_client/resources/datasets/experiments.cjs +16 -0
  105. package/dist/_openapi_client/resources/datasets/experiments.d.ts +23 -0
  106. package/dist/_openapi_client/resources/datasets/experiments.js +12 -0
  107. package/dist/_openapi_client/resources/datasets/group.cjs +17 -0
  108. package/dist/_openapi_client/resources/datasets/group.d.ts +160 -0
  109. package/dist/_openapi_client/resources/datasets/group.js +13 -0
  110. package/dist/_openapi_client/resources/datasets/runs.cjs +29 -0
  111. package/dist/_openapi_client/resources/datasets/runs.d.ts +216 -0
  112. package/dist/_openapi_client/resources/datasets/runs.js +25 -0
  113. package/dist/_openapi_client/resources/datasets/share.cjs +32 -0
  114. package/dist/_openapi_client/resources/datasets/share.d.ts +28 -0
  115. package/dist/_openapi_client/resources/datasets/share.js +28 -0
  116. package/dist/_openapi_client/resources/datasets/splits.cjs +22 -0
  117. package/dist/_openapi_client/resources/datasets/splits.d.ts +30 -0
  118. package/dist/_openapi_client/resources/datasets/splits.js +18 -0
  119. package/dist/_openapi_client/resources/datasets/versions.cjs +23 -0
  120. package/dist/_openapi_client/resources/datasets/versions.d.ts +36 -0
  121. package/dist/_openapi_client/resources/datasets/versions.js +19 -0
  122. package/dist/_openapi_client/resources/evaluators.cjs +15 -0
  123. package/dist/_openapi_client/resources/evaluators.d.ts +125 -0
  124. package/dist/_openapi_client/resources/evaluators.js +11 -0
  125. package/dist/_openapi_client/resources/examples/bulk.cjs +24 -0
  126. package/dist/_openapi_client/resources/examples/bulk.d.ts +78 -0
  127. package/dist/_openapi_client/resources/examples/bulk.js +20 -0
  128. package/dist/_openapi_client/resources/examples/examples.cjs +124 -0
  129. package/dist/_openapi_client/resources/examples/examples.d.ts +182 -0
  130. package/dist/_openapi_client/resources/examples/examples.js +87 -0
  131. package/dist/_openapi_client/resources/examples/validate.cjs +21 -0
  132. package/dist/_openapi_client/resources/examples/validate.d.ts +38 -0
  133. package/dist/_openapi_client/resources/examples/validate.js +17 -0
  134. package/dist/_openapi_client/resources/feedback/configs.cjs +24 -0
  135. package/dist/_openapi_client/resources/feedback/configs.d.ts +18 -0
  136. package/dist/_openapi_client/resources/feedback/configs.js +20 -0
  137. package/dist/_openapi_client/resources/feedback/feedback.cjs +98 -0
  138. package/dist/_openapi_client/resources/feedback/feedback.d.ts +275 -0
  139. package/dist/_openapi_client/resources/feedback/feedback.js +61 -0
  140. package/dist/_openapi_client/resources/feedback/tokens.cjs +35 -0
  141. package/dist/_openapi_client/resources/feedback/tokens.d.ts +130 -0
  142. package/dist/_openapi_client/resources/feedback/tokens.js +31 -0
  143. package/dist/_openapi_client/resources/index.cjs +35 -0
  144. package/dist/_openapi_client/resources/index.d.ts +15 -0
  145. package/dist/_openapi_client/resources/index.js +17 -0
  146. package/dist/_openapi_client/resources/info.cjs +15 -0
  147. package/dist/_openapi_client/resources/info.d.ts +51 -0
  148. package/dist/_openapi_client/resources/info.js +11 -0
  149. package/dist/_openapi_client/resources/online-evaluators.cjs +70 -0
  150. package/dist/_openapi_client/resources/online-evaluators.d.ts +284 -0
  151. package/dist/_openapi_client/resources/online-evaluators.js +66 -0
  152. package/dist/_openapi_client/resources/public/datasets.cjs +47 -0
  153. package/dist/_openapi_client/resources/public/datasets.d.ts +152 -0
  154. package/dist/_openapi_client/resources/public/datasets.js +43 -0
  155. package/dist/_openapi_client/resources/public/public.cjs +62 -0
  156. package/dist/_openapi_client/resources/public/public.d.ts +32 -0
  157. package/dist/_openapi_client/resources/public/public.js +25 -0
  158. package/dist/_openapi_client/resources/repos/directories.cjs +40 -0
  159. package/dist/_openapi_client/resources/repos/directories.d.ts +72 -0
  160. package/dist/_openapi_client/resources/repos/directories.js +36 -0
  161. package/dist/_openapi_client/resources/repos/repos.cjs +93 -0
  162. package/dist/_openapi_client/resources/repos/repos.d.ts +188 -0
  163. package/dist/_openapi_client/resources/repos/repos.js +56 -0
  164. package/dist/_openapi_client/resources/runs/rules.cjs +9 -0
  165. package/dist/_openapi_client/resources/runs/rules.d.ts +3 -0
  166. package/dist/_openapi_client/resources/runs/rules.js +5 -0
  167. package/dist/_openapi_client/resources/runs/runs.cjs +102 -0
  168. package/dist/_openapi_client/resources/runs/runs.d.ts +542 -0
  169. package/dist/_openapi_client/resources/runs/runs.js +65 -0
  170. package/dist/_openapi_client/resources/sandboxes/boxes.cjs +86 -0
  171. package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +1121 -0
  172. package/dist/_openapi_client/resources/sandboxes/boxes.js +82 -0
  173. package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +63 -0
  174. package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +13 -0
  175. package/dist/_openapi_client/resources/sandboxes/sandboxes.js +26 -0
  176. package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +39 -0
  177. package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +130 -0
  178. package/dist/_openapi_client/resources/sandboxes/snapshots.js +35 -0
  179. package/dist/_openapi_client/resources/sessions/insights.cjs +54 -0
  180. package/dist/_openapi_client/resources/sessions/insights.d.ts +246 -0
  181. package/dist/_openapi_client/resources/sessions/insights.js +50 -0
  182. package/dist/_openapi_client/resources/sessions/sessions.cjs +109 -0
  183. package/dist/_openapi_client/resources/sessions/sessions.d.ts +674 -0
  184. package/dist/_openapi_client/resources/sessions/sessions.js +72 -0
  185. package/dist/_openapi_client/resources/settings.cjs +15 -0
  186. package/dist/_openapi_client/resources/settings.d.ts +18 -0
  187. package/dist/_openapi_client/resources/settings.js +11 -0
  188. package/dist/_openapi_client/resources/workspaces.cjs +35 -0
  189. package/dist/_openapi_client/resources/workspaces.d.ts +84 -0
  190. package/dist/_openapi_client/resources/workspaces.js +31 -0
  191. package/dist/_openapi_client/version.cjs +5 -0
  192. package/dist/_openapi_client/version.d.ts +1 -0
  193. package/dist/_openapi_client/version.js +2 -0
  194. package/dist/client.cjs +48 -19
  195. package/dist/client.d.ts +5 -0
  196. package/dist/client.js +29 -0
  197. package/dist/env.cjs +3 -3
  198. package/dist/env.d.ts +1 -1
  199. package/dist/env.js +1 -1
  200. package/dist/experimental/otel/exporter.cjs +1 -1
  201. package/dist/experimental/otel/exporter.js +2 -2
  202. package/dist/experimental/vercel/telemetry.cjs +1 -1
  203. package/dist/experimental/vercel/telemetry.js +2 -2
  204. package/dist/index.cjs +4 -2
  205. package/dist/index.d.ts +2 -1
  206. package/dist/index.js +2 -1
  207. package/dist/run_trees.cjs +1 -1
  208. package/dist/run_trees.js +2 -2
  209. package/dist/sandbox/client.cjs +11 -3
  210. package/dist/sandbox/client.js +11 -3
  211. package/dist/sandbox/index.cjs +8 -2
  212. package/dist/sandbox/index.d.ts +3 -2
  213. package/dist/sandbox/index.js +2 -1
  214. package/dist/sandbox/mounts.cjs +114 -0
  215. package/dist/sandbox/mounts.d.ts +24 -0
  216. package/dist/sandbox/mounts.js +109 -0
  217. package/dist/sandbox/proxy_config.cjs +90 -5
  218. package/dist/sandbox/proxy_config.d.ts +19 -4
  219. package/dist/sandbox/proxy_config.js +86 -4
  220. package/dist/sandbox/types.d.ts +92 -3
  221. package/dist/traceable.cjs +1 -1
  222. package/dist/traceable.js +2 -2
  223. package/dist/utils/guard.cjs +13 -0
  224. package/dist/utils/guard.d.ts +6 -0
  225. package/dist/utils/guard.js +10 -0
  226. package/dist/utils/jestlike/globals.cjs +1 -1
  227. package/dist/utils/jestlike/globals.js +2 -2
  228. package/package.json +2 -2
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This module provides internal shims and utility functions for environments where certain Node.js or global types may not be available.
3
+ *
4
+ * These are used to ensure we can provide a consistent behaviour between different JavaScript environments and good error
5
+ * messages in cases where an environment isn't fully supported.
6
+ */
7
+ import type { Fetch } from './builtin-types.js';
8
+ import type { ReadableStream } from './shim-types.js';
9
+ export declare function getDefaultFetch(): Fetch;
10
+ type ReadableStreamArgs = ConstructorParameters<typeof ReadableStream>;
11
+ export declare function makeReadableStream(...args: ReadableStreamArgs): ReadableStream;
12
+ export declare function ReadableStreamFrom<T>(iterable: Iterable<T> | AsyncIterable<T>): ReadableStream<T>;
13
+ /**
14
+ * Most browsers don't yet have async iterable support for ReadableStream,
15
+ * and Node has a very different way of reading bytes from its "ReadableStream".
16
+ *
17
+ * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
18
+ */
19
+ export declare function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T>;
20
+ /**
21
+ * Cancels a ReadableStream we don't need to consume.
22
+ * See https://undici.nodejs.org/#/?id=garbage-collection
23
+ */
24
+ export declare function CancelReadableStream(stream: any): Promise<void>;
25
+ export {};
@@ -0,0 +1,85 @@
1
+ // @ts-nocheck
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ export function getDefaultFetch() {
4
+ if (typeof fetch !== 'undefined') {
5
+ return fetch;
6
+ }
7
+ throw new Error('`fetch` is not defined as a global; Either pass `fetch` to the client, `new Langsmith({ fetch })` or polyfill the global, `globalThis.fetch = fetch`');
8
+ }
9
+ export function makeReadableStream(...args) {
10
+ const ReadableStream = globalThis.ReadableStream;
11
+ if (typeof ReadableStream === 'undefined') {
12
+ // Note: All of the platforms / runtimes we officially support already define
13
+ // `ReadableStream` as a global, so this should only ever be hit on unsupported runtimes.
14
+ throw new Error('`ReadableStream` is not defined as a global; You will need to polyfill it, `globalThis.ReadableStream = ReadableStream`');
15
+ }
16
+ return new ReadableStream(...args);
17
+ }
18
+ export function ReadableStreamFrom(iterable) {
19
+ let iter = Symbol.asyncIterator in iterable ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
20
+ return makeReadableStream({
21
+ start() { },
22
+ async pull(controller) {
23
+ const { done, value } = await iter.next();
24
+ if (done) {
25
+ controller.close();
26
+ }
27
+ else {
28
+ controller.enqueue(value);
29
+ }
30
+ },
31
+ async cancel() {
32
+ await iter.return?.();
33
+ },
34
+ });
35
+ }
36
+ /**
37
+ * Most browsers don't yet have async iterable support for ReadableStream,
38
+ * and Node has a very different way of reading bytes from its "ReadableStream".
39
+ *
40
+ * This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
41
+ */
42
+ export function ReadableStreamToAsyncIterable(stream) {
43
+ if (stream[Symbol.asyncIterator])
44
+ return stream;
45
+ const reader = stream.getReader();
46
+ return {
47
+ async next() {
48
+ try {
49
+ const result = await reader.read();
50
+ if (result?.done)
51
+ reader.releaseLock(); // release lock when stream becomes closed
52
+ return result;
53
+ }
54
+ catch (e) {
55
+ reader.releaseLock(); // release lock when stream becomes errored
56
+ throw e;
57
+ }
58
+ },
59
+ async return() {
60
+ const cancelPromise = reader.cancel();
61
+ reader.releaseLock();
62
+ await cancelPromise;
63
+ return { done: true, value: undefined };
64
+ },
65
+ [Symbol.asyncIterator]() {
66
+ return this;
67
+ },
68
+ };
69
+ }
70
+ /**
71
+ * Cancels a ReadableStream we don't need to consume.
72
+ * See https://undici.nodejs.org/#/?id=garbage-collection
73
+ */
74
+ export async function CancelReadableStream(stream) {
75
+ if (stream === null || typeof stream !== 'object')
76
+ return;
77
+ if (stream[Symbol.asyncIterator]) {
78
+ await stream[Symbol.asyncIterator]().return?.();
79
+ return;
80
+ }
81
+ const reader = stream.getReader();
82
+ const cancelPromise = reader.cancel();
83
+ reader.releaseLock();
84
+ await cancelPromise;
85
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toFile = toFile;
4
+ // @ts-nocheck
5
+ const uploads_js_1 = require("./uploads.cjs");
6
+ const uploads_js_2 = require("./uploads.cjs");
7
+ /**
8
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
9
+ */
10
+ const isBlobLike = (value) => value != null &&
11
+ typeof value === 'object' &&
12
+ typeof value.size === 'number' &&
13
+ typeof value.type === 'string' &&
14
+ typeof value.text === 'function' &&
15
+ typeof value.slice === 'function' &&
16
+ typeof value.arrayBuffer === 'function';
17
+ /**
18
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
19
+ */
20
+ const isFileLike = (value) => value != null &&
21
+ typeof value === 'object' &&
22
+ typeof value.name === 'string' &&
23
+ typeof value.lastModified === 'number' &&
24
+ isBlobLike(value);
25
+ const isResponseLike = (value) => value != null &&
26
+ typeof value === 'object' &&
27
+ typeof value.url === 'string' &&
28
+ typeof value.blob === 'function';
29
+ /**
30
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
31
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
32
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
33
+ * @param {Object=} options additional properties
34
+ * @param {string=} options.type the MIME type of the content
35
+ * @param {number=} options.lastModified the last modified timestamp
36
+ * @returns a {@link File} with the given properties
37
+ */
38
+ async function toFile(value, name, options) {
39
+ (0, uploads_js_2.checkFileSupport)();
40
+ // If it's a promise, resolve it.
41
+ value = await value;
42
+ // If we've been given a `File` we don't need to do anything
43
+ if (isFileLike(value)) {
44
+ if (value instanceof File) {
45
+ return value;
46
+ }
47
+ return (0, uploads_js_1.makeFile)([await value.arrayBuffer()], value.name);
48
+ }
49
+ if (isResponseLike(value)) {
50
+ const blob = await value.blob();
51
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop();
52
+ return (0, uploads_js_1.makeFile)(await getBytes(blob), name, options);
53
+ }
54
+ const parts = await getBytes(value);
55
+ name ||= (0, uploads_js_1.getName)(value);
56
+ if (!options?.type) {
57
+ const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
58
+ if (typeof type === 'string') {
59
+ options = { ...options, type };
60
+ }
61
+ }
62
+ return (0, uploads_js_1.makeFile)(parts, name, options);
63
+ }
64
+ async function getBytes(value) {
65
+ let parts = [];
66
+ if (typeof value === 'string' ||
67
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
68
+ value instanceof ArrayBuffer) {
69
+ parts.push(value);
70
+ }
71
+ else if (isBlobLike(value)) {
72
+ parts.push(value instanceof Blob ? value : await value.arrayBuffer());
73
+ }
74
+ else if ((0, uploads_js_1.isAsyncIterable)(value) // includes Readable, ReadableStream, etc.
75
+ ) {
76
+ for await (const chunk of value) {
77
+ parts.push(...(await getBytes(chunk))); // TODO, consider validating?
78
+ }
79
+ }
80
+ else {
81
+ const constructor = value?.constructor?.name;
82
+ throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
83
+ }
84
+ return parts;
85
+ }
86
+ function propsForError(value) {
87
+ if (typeof value !== 'object' || value === null)
88
+ return '';
89
+ const props = Object.getOwnPropertyNames(value);
90
+ return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
91
+ }
@@ -0,0 +1,44 @@
1
+ import type { FilePropertyBag } from './builtin-types.js';
2
+ type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
3
+ /**
4
+ * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
5
+ * Don't add arrayBuffer here, node-fetch doesn't have it
6
+ */
7
+ interface BlobLike {
8
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
9
+ readonly size: number;
10
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
11
+ readonly type: string;
12
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
13
+ text(): Promise<string>;
14
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
15
+ slice(start?: number, end?: number): BlobLike;
16
+ }
17
+ /**
18
+ * Intended to match DOM File, node:buffer File, undici File, etc.
19
+ */
20
+ interface FileLike extends BlobLike {
21
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
22
+ readonly lastModified: number;
23
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
24
+ readonly name?: string | undefined;
25
+ }
26
+ /**
27
+ * Intended to match DOM Response, node-fetch Response, undici Response, etc.
28
+ */
29
+ export interface ResponseLike {
30
+ url: string;
31
+ blob(): Promise<BlobLike>;
32
+ }
33
+ export type ToFileInput = FileLike | ResponseLike | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
34
+ /**
35
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
36
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
37
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
38
+ * @param {Object=} options additional properties
39
+ * @param {string=} options.type the MIME type of the content
40
+ * @param {number=} options.lastModified the last modified timestamp
41
+ * @returns a {@link File} with the given properties
42
+ */
43
+ export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<File>;
44
+ export {};
@@ -0,0 +1,88 @@
1
+ // @ts-nocheck
2
+ import { getName, makeFile, isAsyncIterable } from './uploads.js';
3
+ import { checkFileSupport } from './uploads.js';
4
+ /**
5
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
6
+ */
7
+ const isBlobLike = (value) => value != null &&
8
+ typeof value === 'object' &&
9
+ typeof value.size === 'number' &&
10
+ typeof value.type === 'string' &&
11
+ typeof value.text === 'function' &&
12
+ typeof value.slice === 'function' &&
13
+ typeof value.arrayBuffer === 'function';
14
+ /**
15
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
16
+ */
17
+ const isFileLike = (value) => value != null &&
18
+ typeof value === 'object' &&
19
+ typeof value.name === 'string' &&
20
+ typeof value.lastModified === 'number' &&
21
+ isBlobLike(value);
22
+ const isResponseLike = (value) => value != null &&
23
+ typeof value === 'object' &&
24
+ typeof value.url === 'string' &&
25
+ typeof value.blob === 'function';
26
+ /**
27
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
28
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
29
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
30
+ * @param {Object=} options additional properties
31
+ * @param {string=} options.type the MIME type of the content
32
+ * @param {number=} options.lastModified the last modified timestamp
33
+ * @returns a {@link File} with the given properties
34
+ */
35
+ export async function toFile(value, name, options) {
36
+ checkFileSupport();
37
+ // If it's a promise, resolve it.
38
+ value = await value;
39
+ // If we've been given a `File` we don't need to do anything
40
+ if (isFileLike(value)) {
41
+ if (value instanceof File) {
42
+ return value;
43
+ }
44
+ return makeFile([await value.arrayBuffer()], value.name);
45
+ }
46
+ if (isResponseLike(value)) {
47
+ const blob = await value.blob();
48
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop();
49
+ return makeFile(await getBytes(blob), name, options);
50
+ }
51
+ const parts = await getBytes(value);
52
+ name ||= getName(value);
53
+ if (!options?.type) {
54
+ const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
55
+ if (typeof type === 'string') {
56
+ options = { ...options, type };
57
+ }
58
+ }
59
+ return makeFile(parts, name, options);
60
+ }
61
+ async function getBytes(value) {
62
+ let parts = [];
63
+ if (typeof value === 'string' ||
64
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
65
+ value instanceof ArrayBuffer) {
66
+ parts.push(value);
67
+ }
68
+ else if (isBlobLike(value)) {
69
+ parts.push(value instanceof Blob ? value : await value.arrayBuffer());
70
+ }
71
+ else if (isAsyncIterable(value) // includes Readable, ReadableStream, etc.
72
+ ) {
73
+ for await (const chunk of value) {
74
+ parts.push(...(await getBytes(chunk))); // TODO, consider validating?
75
+ }
76
+ }
77
+ else {
78
+ const constructor = value?.constructor?.name;
79
+ throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
80
+ }
81
+ return parts;
82
+ }
83
+ function propsForError(value) {
84
+ if (typeof value !== 'object' || value === null)
85
+ return '';
86
+ const props = Object.getOwnPropertyNames(value);
87
+ return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
88
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ export type PromiseOrValue<T> = T | Promise<T>;
2
+ export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
3
+ export type KeysEnum<T> = {
4
+ [P in keyof Required<T>]: true;
5
+ };
6
+ export type FinalizedRequestInit = RequestInit & {
7
+ headers: Headers;
8
+ };
9
+ type NotAny<T> = [0] extends [1 & T] ? never : T;
10
+ /**
11
+ * Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
12
+ */
13
+ type OverloadedParameters<T> = T extends ({
14
+ (...args: infer A): unknown;
15
+ (...args: infer B): unknown;
16
+ (...args: infer C): unknown;
17
+ (...args: infer D): unknown;
18
+ }) ? A | B | C | D : T extends ({
19
+ (...args: infer A): unknown;
20
+ (...args: infer B): unknown;
21
+ (...args: infer C): unknown;
22
+ }) ? A | B | C : T extends ({
23
+ (...args: infer A): unknown;
24
+ (...args: infer B): unknown;
25
+ }) ? A | B : T extends (...args: infer A) => unknown ? A : never;
26
+ /** @ts-ignore For users who use Deno */ type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
27
+ type RequestInits = NotAny<RequestInit> | NotAny<FetchRequestInit>;
28
+ /**
29
+ * This type contains `RequestInit` options that may be available on the current runtime,
30
+ * including per-platform extensions like `dispatcher`, `agent`, `client`, etc.
31
+ */
32
+ export type MergedRequestInit = RequestInits &
33
+ /** We don't include these in the types as they'll be overridden for every request. */
34
+ Partial<Record<'body' | 'headers' | 'method' | 'signal', never>>;
35
+ export {};
@@ -0,0 +1,3 @@
1
+ // @ts-nocheck
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ export {};
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.isAsyncIterable = exports.checkFileSupport = void 0;
4
+ exports.makeFile = makeFile;
5
+ exports.getName = getName;
6
+ const shims_js_1 = require("./shims.cjs");
7
+ const checkFileSupport = () => {
8
+ if (typeof File === 'undefined') {
9
+ const { process } = globalThis;
10
+ const isOldNode = typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
11
+ throw new Error('`File` is not defined as a global, which is required for file uploads.' +
12
+ (isOldNode ?
13
+ " Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
14
+ : ''));
15
+ }
16
+ };
17
+ exports.checkFileSupport = checkFileSupport;
18
+ /**
19
+ * Construct a `File` instance. This is used to ensure a helpful error is thrown
20
+ * for environments that don't define a global `File` yet.
21
+ */
22
+ function makeFile(fileBits, fileName, options) {
23
+ (0, exports.checkFileSupport)();
24
+ return new File(fileBits, fileName ?? 'unknown_file', options);
25
+ }
26
+ function getName(value) {
27
+ return (((typeof value === 'object' &&
28
+ value !== null &&
29
+ (('name' in value && value.name && String(value.name)) ||
30
+ ('url' in value && value.url && String(value.url)) ||
31
+ ('filename' in value && value.filename && String(value.filename)) ||
32
+ ('path' in value && value.path && String(value.path)))) ||
33
+ '')
34
+ .split(/[\\/]/)
35
+ .pop() || undefined);
36
+ }
37
+ const isAsyncIterable = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
38
+ exports.isAsyncIterable = isAsyncIterable;
39
+ /**
40
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
41
+ * Otherwise returns the request as is.
42
+ */
43
+ const maybeMultipartFormRequestOptions = async (opts, fetch) => {
44
+ if (!hasUploadableValue(opts.body))
45
+ return opts;
46
+ return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
47
+ };
48
+ exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
49
+ const multipartFormRequestOptions = async (opts, fetch) => {
50
+ return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
51
+ };
52
+ exports.multipartFormRequestOptions = multipartFormRequestOptions;
53
+ const supportsFormDataMap = /* @__PURE__ */ new WeakMap();
54
+ /**
55
+ * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
56
+ * properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
57
+ * This function detects if the fetch function provided supports the global FormData object to avoid
58
+ * confusing error messages later on.
59
+ */
60
+ function supportsFormData(fetchObject) {
61
+ const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
62
+ const cached = supportsFormDataMap.get(fetch);
63
+ if (cached)
64
+ return cached;
65
+ const promise = (async () => {
66
+ try {
67
+ const FetchResponse = ('Response' in fetch ?
68
+ fetch.Response
69
+ : (await fetch('data:,')).constructor);
70
+ const data = new FormData();
71
+ if (data.toString() === (await new FetchResponse(data).text())) {
72
+ return false;
73
+ }
74
+ return true;
75
+ }
76
+ catch {
77
+ // avoid false negatives
78
+ return true;
79
+ }
80
+ })();
81
+ supportsFormDataMap.set(fetch, promise);
82
+ return promise;
83
+ }
84
+ const createForm = async (body, fetch) => {
85
+ if (!(await supportsFormData(fetch))) {
86
+ throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
87
+ }
88
+ const form = new FormData();
89
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
90
+ return form;
91
+ };
92
+ exports.createForm = createForm;
93
+ // We check for Blob not File because Bun.File doesn't inherit from File,
94
+ // but they both inherit from Blob and have a `name` property at runtime.
95
+ const isNamedBlob = (value) => value instanceof Blob && 'name' in value;
96
+ const isUploadable = (value) => typeof value === 'object' &&
97
+ value !== null &&
98
+ (value instanceof Response || (0, exports.isAsyncIterable)(value) || isNamedBlob(value));
99
+ const hasUploadableValue = (value) => {
100
+ if (isUploadable(value))
101
+ return true;
102
+ if (Array.isArray(value))
103
+ return value.some(hasUploadableValue);
104
+ if (value && typeof value === 'object') {
105
+ for (const k in value) {
106
+ if (hasUploadableValue(value[k]))
107
+ return true;
108
+ }
109
+ }
110
+ return false;
111
+ };
112
+ const addFormValue = async (form, key, value) => {
113
+ if (value === undefined)
114
+ return;
115
+ if (value == null) {
116
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
117
+ }
118
+ // TODO: make nested formats configurable
119
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
120
+ form.append(key, String(value));
121
+ }
122
+ else if (value instanceof Response) {
123
+ form.append(key, makeFile([await value.blob()], getName(value)));
124
+ }
125
+ else if ((0, exports.isAsyncIterable)(value)) {
126
+ form.append(key, makeFile([await new Response((0, shims_js_1.ReadableStreamFrom)(value)).blob()], getName(value)));
127
+ }
128
+ else if (isNamedBlob(value)) {
129
+ form.append(key, value, getName(value));
130
+ }
131
+ else if (Array.isArray(value)) {
132
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
133
+ }
134
+ else if (typeof value === 'object') {
135
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
136
+ }
137
+ else {
138
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
139
+ }
140
+ };
@@ -0,0 +1,41 @@
1
+ import { type RequestOptions } from './request-options.js';
2
+ import type { FilePropertyBag, Fetch } from './builtin-types.js';
3
+ import type { Langsmith } from '../client.js';
4
+ export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
5
+ type FsReadStream = AsyncIterable<Uint8Array> & {
6
+ path: string | {
7
+ toString(): string;
8
+ };
9
+ };
10
+ interface BunFile extends Blob {
11
+ readonly name?: string | undefined;
12
+ }
13
+ export declare const checkFileSupport: () => void;
14
+ /**
15
+ * Typically, this is a native "File" class.
16
+ *
17
+ * We provide the {@link toFile} utility to convert a variety of objects
18
+ * into the File class.
19
+ *
20
+ * For convenience, you can also pass a fetch Response, or in Node,
21
+ * the result of fs.createReadStream().
22
+ */
23
+ export type Uploadable = File | Response | FsReadStream | BunFile;
24
+ /**
25
+ * Construct a `File` instance. This is used to ensure a helpful error is thrown
26
+ * for environments that don't define a global `File` yet.
27
+ */
28
+ export declare function makeFile(fileBits: BlobPart[], fileName: string | undefined, options?: FilePropertyBag): File;
29
+ export declare function getName(value: any): string | undefined;
30
+ export declare const isAsyncIterable: (value: any) => value is AsyncIterable<any>;
31
+ /**
32
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
33
+ * Otherwise returns the request as is.
34
+ */
35
+ export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Langsmith | Fetch) => Promise<RequestOptions>;
36
+ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
37
+ body: unknown;
38
+ };
39
+ export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Langsmith | Fetch) => Promise<RequestOptions>;
40
+ export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Langsmith | Fetch) => Promise<FormData>;
41
+ export {};