langsmith 0.5.22 → 0.5.24

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 (95) hide show
  1. package/dist/client.cjs +365 -19
  2. package/dist/client.d.ts +116 -1
  3. package/dist/client.js +369 -23
  4. package/dist/evaluation/_runner.cjs +4 -7
  5. package/dist/evaluation/_runner.js +2 -5
  6. package/dist/evaluation/evaluate_comparative.cjs +10 -10
  7. package/dist/evaluation/evaluate_comparative.js +1 -1
  8. package/dist/evaluation/evaluator.cjs +2 -2
  9. package/dist/evaluation/evaluator.js +1 -1
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/run_trees.cjs +8 -7
  14. package/dist/run_trees.d.ts +7 -0
  15. package/dist/run_trees.js +7 -6
  16. package/dist/schemas.d.ts +54 -0
  17. package/dist/singletons/otel.cjs +3 -2
  18. package/dist/singletons/otel.js +4 -3
  19. package/dist/traceable.cjs +1 -2
  20. package/dist/traceable.js +1 -2
  21. package/dist/utils/_uuid.cjs +2 -2
  22. package/dist/utils/_uuid.js +1 -1
  23. package/dist/utils/env.cjs +33 -0
  24. package/dist/utils/env.d.ts +9 -0
  25. package/dist/utils/env.js +32 -0
  26. package/dist/utils/error.cjs +7 -0
  27. package/dist/utils/error.d.ts +1 -0
  28. package/dist/utils/error.js +6 -0
  29. package/dist/utils/fast-safe-stringify/index.cjs +203 -0
  30. package/dist/utils/fast-safe-stringify/index.d.ts +46 -0
  31. package/dist/utils/fast-safe-stringify/index.js +202 -0
  32. package/dist/utils/jestlike/index.cjs +5 -5
  33. package/dist/utils/jestlike/index.js +1 -1
  34. package/dist/utils/jestlike/vendor/evaluatedBy.cjs +3 -3
  35. package/dist/utils/jestlike/vendor/evaluatedBy.js +1 -1
  36. package/dist/utils/prompts.cjs +7 -2
  37. package/dist/utils/prompts.d.ts +6 -1
  38. package/dist/utils/prompts.js +6 -1
  39. package/dist/utils/serialize_worker.cjs +389 -0
  40. package/dist/utils/serialize_worker.d.ts +67 -0
  41. package/dist/utils/serialize_worker.js +383 -0
  42. package/dist/utils/uuid/src/index.cjs +24 -0
  43. package/dist/utils/uuid/src/index.d.ts +10 -0
  44. package/dist/utils/uuid/src/index.js +9 -0
  45. package/dist/utils/uuid/src/max.cjs +3 -0
  46. package/dist/utils/uuid/src/max.d.ts +2 -0
  47. package/dist/utils/uuid/src/max.js +1 -0
  48. package/dist/utils/uuid/src/nil.cjs +3 -0
  49. package/dist/utils/uuid/src/nil.d.ts +2 -0
  50. package/dist/utils/uuid/src/nil.js +1 -0
  51. package/dist/utils/uuid/src/parse.cjs +23 -0
  52. package/dist/utils/uuid/src/parse.d.ts +3 -0
  53. package/dist/utils/uuid/src/parse.js +18 -0
  54. package/dist/utils/uuid/src/regex.cjs +3 -0
  55. package/dist/utils/uuid/src/regex.d.ts +2 -0
  56. package/dist/utils/uuid/src/regex.js +1 -0
  57. package/dist/utils/uuid/src/rng.cjs +10 -0
  58. package/dist/utils/uuid/src/rng.d.ts +1 -0
  59. package/dist/utils/uuid/src/rng.js +7 -0
  60. package/dist/utils/uuid/src/sha1.cjs +75 -0
  61. package/dist/utils/uuid/src/sha1.d.ts +2 -0
  62. package/dist/utils/uuid/src/sha1.js +73 -0
  63. package/dist/utils/uuid/src/stringify.cjs +55 -0
  64. package/dist/utils/uuid/src/stringify.d.ts +3 -0
  65. package/dist/utils/uuid/src/stringify.js +49 -0
  66. package/dist/utils/uuid/src/types.cjs +2 -0
  67. package/dist/utils/uuid/src/types.d.ts +22 -0
  68. package/dist/utils/uuid/src/types.js +1 -0
  69. package/dist/utils/uuid/src/v35.cjs +52 -0
  70. package/dist/utils/uuid/src/v35.d.ts +7 -0
  71. package/dist/utils/uuid/src/v35.js +44 -0
  72. package/dist/utils/uuid/src/v4.cjs +40 -0
  73. package/dist/utils/uuid/src/v4.d.ts +4 -0
  74. package/dist/utils/uuid/src/v4.js +35 -0
  75. package/dist/utils/uuid/src/v5.cjs +50 -0
  76. package/dist/utils/uuid/src/v5.d.ts +9 -0
  77. package/dist/utils/uuid/src/v5.js +9 -0
  78. package/dist/utils/uuid/src/v7.cjs +88 -0
  79. package/dist/utils/uuid/src/v7.d.ts +9 -0
  80. package/dist/utils/uuid/src/v7.js +82 -0
  81. package/dist/utils/uuid/src/validate.cjs +10 -0
  82. package/dist/utils/uuid/src/validate.d.ts +2 -0
  83. package/dist/utils/uuid/src/validate.js +5 -0
  84. package/dist/utils/uuid/src/version.cjs +13 -0
  85. package/dist/utils/uuid/src/version.d.ts +2 -0
  86. package/dist/utils/uuid/src/version.js +8 -0
  87. package/dist/utils/worker_threads.browser.cjs +16 -0
  88. package/dist/utils/worker_threads.browser.d.ts +14 -0
  89. package/dist/utils/worker_threads.browser.js +13 -0
  90. package/dist/utils/worker_threads.cjs +16 -0
  91. package/dist/utils/worker_threads.d.ts +13 -0
  92. package/dist/utils/worker_threads.js +13 -0
  93. package/dist/uuid.cjs +2 -2
  94. package/dist/uuid.js +1 -1
  95. package/package.json +7 -5
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateSerializedSize = estimateSerializedSize;
3
4
  exports.serialize = serialize;
4
5
  /* eslint-disable */
5
6
  // @ts-nocheck
@@ -60,6 +61,208 @@ function createDefaultReplacer(userReplacer) {
60
61
  return serializeWellKnownTypes(val);
61
62
  };
62
63
  }
64
+ function estimateSerializedSize(value) {
65
+ try {
66
+ // Ancestor set for cycle detection. An object is only treated as
67
+ // circular if it appears on the current recursion path, not merely
68
+ // if it has been seen before elsewhere in the graph.
69
+ const ancestors = new Set();
70
+ let maxStringLen = 0;
71
+ // In Node / Bun, Buffer.byteLength is a fast native way to get UTF-8
72
+ // byte length without allocating an encoded copy. In other runtimes
73
+ // we fall back to code-unit length (a small under-estimate for
74
+ // non-ASCII text, which is acceptable for soft limits).
75
+ const byteLen = typeof Buffer !== "undefined" && typeof Buffer.byteLength === "function"
76
+ ? (s) => Buffer.byteLength(s, "utf8")
77
+ : (s) => s.length;
78
+ function estimateString(s) {
79
+ // +2 for the surrounding quotes. Escape expansion is not counted.
80
+ const n = byteLen(s);
81
+ if (n > maxStringLen)
82
+ maxStringLen = n;
83
+ return n + 2;
84
+ }
85
+ // Size of a byte sequence when rendered as a JSON array of decimal
86
+ // numbers: "[b0,b1,b2,...]". Each byte averages ~3.5 chars (value 0-9
87
+ // => 1 char, 10-99 => 2 chars, 100-255 => 3 chars; weighted mean over
88
+ // a uniform distribution is ~2.81, plus one comma per element except
89
+ // the last). Round up to 4 bytes/element for a small safety margin.
90
+ function estimateByteArrayJson(byteLength) {
91
+ if (byteLength === 0)
92
+ return 2; // "[]"
93
+ return 2 + byteLength * 4;
94
+ }
95
+ // Returns true for values that JSON.stringify drops when they appear
96
+ // as an object property (as opposed to an array element, where they
97
+ // become "null").
98
+ function isDropped(v) {
99
+ return (v === undefined || typeof v === "function" || typeof v === "symbol");
100
+ }
101
+ // In arrays, undefined / function / symbol become "null" (4 bytes).
102
+ function estimateInArray(v) {
103
+ if (v === undefined || typeof v === "function" || typeof v === "symbol") {
104
+ return 4;
105
+ }
106
+ return estimate(v);
107
+ }
108
+ function estimate(val) {
109
+ if (val === null)
110
+ return 4; // "null"
111
+ if (val === undefined)
112
+ return 0; // top-level or property context; array handled separately
113
+ const t = typeof val;
114
+ if (t === "boolean")
115
+ return 5; // "true" / "false" upper bound
116
+ if (t === "number") {
117
+ if (!Number.isFinite(val))
118
+ return 4; // "null"
119
+ // Convert to string to get exact length. This is cheap for numbers
120
+ // (V8 caches small-number strings) and makes the estimate far
121
+ // tighter for common cases like integer arrays.
122
+ return val.toString().length;
123
+ }
124
+ if (t === "bigint") {
125
+ // Our replacer renders BigInt via .toString(), then JSON.stringify
126
+ // quotes it.
127
+ return val.toString().length + 2;
128
+ }
129
+ if (t === "string")
130
+ return estimateString(val);
131
+ if (t === "function" || t === "symbol")
132
+ return 0;
133
+ // Objects from here on.
134
+ const obj = val;
135
+ // Well-known types handled by our replacer.
136
+ if (obj instanceof Date)
137
+ return 26; // "2024-01-01T00:00:00.000Z"
138
+ if (obj instanceof RegExp)
139
+ return byteLen(obj.toString()) + 2;
140
+ if (obj instanceof Error) {
141
+ const name = obj.name ?? "";
142
+ const message = obj.message ?? "";
143
+ // {"name":"...","message":"..."}
144
+ return 22 + byteLen(name) + byteLen(message);
145
+ }
146
+ // Binary data types. These commonly appear in LLM payloads (images,
147
+ // audio) and their JSON representations vary widely.
148
+ if (typeof Buffer !== "undefined" && obj instanceof Buffer) {
149
+ // { "type": "Buffer", "data": [0, 1, 2, ...] }
150
+ return 28 + estimateByteArrayJson(obj.byteLength);
151
+ }
152
+ if (ArrayBuffer.isView(obj)) {
153
+ if (obj instanceof DataView) {
154
+ // DataView has no enumerable own properties; serializes as "{}".
155
+ return 2;
156
+ }
157
+ // Typed arrays serialize as {"0":v0,"1":v1,...} (keyed objects),
158
+ // which is much larger than a plain array would be. Per element
159
+ // cost: digits for index + digits for value + ":" + "," + quotes.
160
+ const len = obj.length ?? 0;
161
+ const isFloat = obj instanceof Float32Array || obj instanceof Float64Array;
162
+ // Index digits grow with len; worst-case per element:
163
+ // "NNN":V, where NNN = log10(len) digits and V depends on type.
164
+ // Loose but safe bounds: integer views ~12 chars/element, float
165
+ // views ~30 chars/element (Float32 ToString can be up to ~17 chars).
166
+ const perElement = isFloat ? 30 : 12;
167
+ return 2 + len * perElement;
168
+ }
169
+ if (obj instanceof ArrayBuffer) {
170
+ // Plain ArrayBuffer has no enumerable properties; serializes as "{}".
171
+ return 2;
172
+ }
173
+ if (ancestors.has(obj)) {
174
+ // Cycle: our decirc fallback replaces with { result: "[Circular]" }.
175
+ return 24;
176
+ }
177
+ // Custom toJSON (Decimal.js, Moment, Luxon, Mongoose docs, etc.).
178
+ // This runs after explicit built-in / binary cases above so known
179
+ // types (for example Buffer) use their dedicated fast-path sizing
180
+ // logic instead of duck-typing through toJSON().
181
+ if (typeof obj.toJSON === "function") {
182
+ let projected;
183
+ try {
184
+ projected = obj.toJSON("");
185
+ }
186
+ catch {
187
+ // If toJSON throws, JSON.stringify would also throw and our
188
+ // serializer would emit "[Unserializable]" (~16 bytes).
189
+ return 16;
190
+ }
191
+ ancestors.add(obj);
192
+ const size = estimate(projected);
193
+ ancestors.delete(obj);
194
+ return size;
195
+ }
196
+ ancestors.add(obj);
197
+ let size;
198
+ if (Array.isArray(obj)) {
199
+ size = 2; // []
200
+ const len = obj.length;
201
+ for (let i = 0; i < len; i++) {
202
+ size += estimateInArray(obj[i]);
203
+ if (i < len - 1)
204
+ size += 1; // comma
205
+ }
206
+ }
207
+ else if (obj instanceof Map) {
208
+ // Rendered as { k: v, ... } via Object.fromEntries.
209
+ size = 2;
210
+ let emitted = 0;
211
+ for (const [k, v] of obj) {
212
+ if (isDropped(v))
213
+ continue;
214
+ if (emitted > 0)
215
+ size += 1; // comma
216
+ const keyStr = typeof k === "string" ? k : String(k);
217
+ size += byteLen(keyStr) + 3; // "key":
218
+ size += estimate(v);
219
+ emitted++;
220
+ }
221
+ }
222
+ else if (obj instanceof Set) {
223
+ // Rendered as [v, ...] via Array.from.
224
+ size = 2;
225
+ let emitted = 0;
226
+ for (const v of obj) {
227
+ if (emitted > 0)
228
+ size += 1; // comma
229
+ size += estimateInArray(v);
230
+ emitted++;
231
+ }
232
+ }
233
+ else {
234
+ size = 2; // {}
235
+ let emitted = 0;
236
+ // Object.keys only returns own enumerable string keys, matching
237
+ // JSON.stringify.
238
+ const keys = Object.keys(obj);
239
+ for (let i = 0; i < keys.length; i++) {
240
+ const key = keys[i];
241
+ const v = obj[key];
242
+ if (isDropped(v))
243
+ continue;
244
+ if (emitted > 0)
245
+ size += 1; // comma
246
+ size += byteLen(key) + 3; // "key":
247
+ size += estimate(v);
248
+ emitted++;
249
+ }
250
+ }
251
+ ancestors.delete(obj);
252
+ return size;
253
+ }
254
+ const size = estimate(value);
255
+ return { size, maxStringLen };
256
+ }
257
+ catch {
258
+ // If the estimator itself hits an unexpected edge case, fall back to the
259
+ // exact serialized size. This preserves correctness of queue-size
260
+ // accounting at the cost of a slower hot path for that one payload.
261
+ // We cannot cheaply recover maxStringLen here, so report 0: the worker
262
+ // gate will then fall back to sync serialization, which is safe.
263
+ return { size: serialize(value).length, maxStringLen: 0 };
264
+ }
265
+ }
63
266
  // Regular stringify
64
267
  function serialize(obj, errorContext, replacer, spacer, options) {
65
268
  try {
@@ -1 +1,47 @@
1
+ /**
2
+ * Estimate the serialized JSON byte size of a value without actually
3
+ * serializing it. Used on hot paths (enqueuing runs for batched tracing)
4
+ * where the exact serialized size is not required -- only a reasonable
5
+ * approximation for soft memory accounting.
6
+ *
7
+ * Walks the object graph in O(n) without allocating a JSON string,
8
+ * avoiding the event-loop blocking that JSON.stringify causes on large
9
+ * payloads.
10
+ *
11
+ * Accuracy notes (all estimates are approximate, never exact):
12
+ * - Strings: UTF-8 byte length via Buffer.byteLength when available,
13
+ * falling back to code-unit length for non-Node environments. Does
14
+ * not account for escape expansion (\", \\, control chars, surrogate
15
+ * escapes) which is usually a small fraction of total size.
16
+ * - Binary data (Buffer / typed arrays / ArrayBuffer / DataView): sized
17
+ * from their JSON.stringify representations where practical
18
+ * ({ type: "Buffer", data: [...] } for Buffer, keyed objects for typed
19
+ * arrays). DataView and ArrayBuffer themselves have no enumerable own
20
+ * properties and serialize as "{}". Each byte contributes ~3.5
21
+ * characters on average in Buffer's decimal-array representation
22
+ * (digit(s) + comma).
23
+ * - Other objects with toJSON(): we invoke toJSON() once and estimate
24
+ * the result. This matches JSON.stringify semantics for libraries
25
+ * like Decimal.js, Moment, Luxon, Mongoose documents, etc.
26
+ * - Cycles: detected via an ancestor-path set that is pushed/popped
27
+ * during recursion. This matches JSON.stringify semantics --
28
+ * repeated references that are *not* on the current ancestor chain
29
+ * (shared subobjects) are counted every time they appear, because
30
+ * JSON.stringify will serialize them every time.
31
+ * - No depth limit (JSON.stringify has none either).
32
+ */
33
+ export interface EstimatedSize {
34
+ /** Approximate serialized JSON byte size. */
35
+ size: number;
36
+ /**
37
+ * Length (in UTF-8 bytes) of the longest single string value encountered
38
+ * anywhere in the payload graph. Callers can use this as a shape-aware
39
+ * dispatch signal -- for example, to decide whether to offload serialize
40
+ * to a worker thread (which only pays off when a payload contains one
41
+ * or more large strings, since V8 shares string storage across isolates
42
+ * via refcount).
43
+ */
44
+ maxStringLen: number;
45
+ }
46
+ export declare function estimateSerializedSize(value: unknown): EstimatedSize;
1
47
  export declare function serialize(obj: any, errorContext?: any, replacer?: any, spacer?: any, options?: any): Uint8Array<ArrayBuffer>;
@@ -57,6 +57,208 @@ function createDefaultReplacer(userReplacer) {
57
57
  return serializeWellKnownTypes(val);
58
58
  };
59
59
  }
60
+ export function estimateSerializedSize(value) {
61
+ try {
62
+ // Ancestor set for cycle detection. An object is only treated as
63
+ // circular if it appears on the current recursion path, not merely
64
+ // if it has been seen before elsewhere in the graph.
65
+ const ancestors = new Set();
66
+ let maxStringLen = 0;
67
+ // In Node / Bun, Buffer.byteLength is a fast native way to get UTF-8
68
+ // byte length without allocating an encoded copy. In other runtimes
69
+ // we fall back to code-unit length (a small under-estimate for
70
+ // non-ASCII text, which is acceptable for soft limits).
71
+ const byteLen = typeof Buffer !== "undefined" && typeof Buffer.byteLength === "function"
72
+ ? (s) => Buffer.byteLength(s, "utf8")
73
+ : (s) => s.length;
74
+ function estimateString(s) {
75
+ // +2 for the surrounding quotes. Escape expansion is not counted.
76
+ const n = byteLen(s);
77
+ if (n > maxStringLen)
78
+ maxStringLen = n;
79
+ return n + 2;
80
+ }
81
+ // Size of a byte sequence when rendered as a JSON array of decimal
82
+ // numbers: "[b0,b1,b2,...]". Each byte averages ~3.5 chars (value 0-9
83
+ // => 1 char, 10-99 => 2 chars, 100-255 => 3 chars; weighted mean over
84
+ // a uniform distribution is ~2.81, plus one comma per element except
85
+ // the last). Round up to 4 bytes/element for a small safety margin.
86
+ function estimateByteArrayJson(byteLength) {
87
+ if (byteLength === 0)
88
+ return 2; // "[]"
89
+ return 2 + byteLength * 4;
90
+ }
91
+ // Returns true for values that JSON.stringify drops when they appear
92
+ // as an object property (as opposed to an array element, where they
93
+ // become "null").
94
+ function isDropped(v) {
95
+ return (v === undefined || typeof v === "function" || typeof v === "symbol");
96
+ }
97
+ // In arrays, undefined / function / symbol become "null" (4 bytes).
98
+ function estimateInArray(v) {
99
+ if (v === undefined || typeof v === "function" || typeof v === "symbol") {
100
+ return 4;
101
+ }
102
+ return estimate(v);
103
+ }
104
+ function estimate(val) {
105
+ if (val === null)
106
+ return 4; // "null"
107
+ if (val === undefined)
108
+ return 0; // top-level or property context; array handled separately
109
+ const t = typeof val;
110
+ if (t === "boolean")
111
+ return 5; // "true" / "false" upper bound
112
+ if (t === "number") {
113
+ if (!Number.isFinite(val))
114
+ return 4; // "null"
115
+ // Convert to string to get exact length. This is cheap for numbers
116
+ // (V8 caches small-number strings) and makes the estimate far
117
+ // tighter for common cases like integer arrays.
118
+ return val.toString().length;
119
+ }
120
+ if (t === "bigint") {
121
+ // Our replacer renders BigInt via .toString(), then JSON.stringify
122
+ // quotes it.
123
+ return val.toString().length + 2;
124
+ }
125
+ if (t === "string")
126
+ return estimateString(val);
127
+ if (t === "function" || t === "symbol")
128
+ return 0;
129
+ // Objects from here on.
130
+ const obj = val;
131
+ // Well-known types handled by our replacer.
132
+ if (obj instanceof Date)
133
+ return 26; // "2024-01-01T00:00:00.000Z"
134
+ if (obj instanceof RegExp)
135
+ return byteLen(obj.toString()) + 2;
136
+ if (obj instanceof Error) {
137
+ const name = obj.name ?? "";
138
+ const message = obj.message ?? "";
139
+ // {"name":"...","message":"..."}
140
+ return 22 + byteLen(name) + byteLen(message);
141
+ }
142
+ // Binary data types. These commonly appear in LLM payloads (images,
143
+ // audio) and their JSON representations vary widely.
144
+ if (typeof Buffer !== "undefined" && obj instanceof Buffer) {
145
+ // { "type": "Buffer", "data": [0, 1, 2, ...] }
146
+ return 28 + estimateByteArrayJson(obj.byteLength);
147
+ }
148
+ if (ArrayBuffer.isView(obj)) {
149
+ if (obj instanceof DataView) {
150
+ // DataView has no enumerable own properties; serializes as "{}".
151
+ return 2;
152
+ }
153
+ // Typed arrays serialize as {"0":v0,"1":v1,...} (keyed objects),
154
+ // which is much larger than a plain array would be. Per element
155
+ // cost: digits for index + digits for value + ":" + "," + quotes.
156
+ const len = obj.length ?? 0;
157
+ const isFloat = obj instanceof Float32Array || obj instanceof Float64Array;
158
+ // Index digits grow with len; worst-case per element:
159
+ // "NNN":V, where NNN = log10(len) digits and V depends on type.
160
+ // Loose but safe bounds: integer views ~12 chars/element, float
161
+ // views ~30 chars/element (Float32 ToString can be up to ~17 chars).
162
+ const perElement = isFloat ? 30 : 12;
163
+ return 2 + len * perElement;
164
+ }
165
+ if (obj instanceof ArrayBuffer) {
166
+ // Plain ArrayBuffer has no enumerable properties; serializes as "{}".
167
+ return 2;
168
+ }
169
+ if (ancestors.has(obj)) {
170
+ // Cycle: our decirc fallback replaces with { result: "[Circular]" }.
171
+ return 24;
172
+ }
173
+ // Custom toJSON (Decimal.js, Moment, Luxon, Mongoose docs, etc.).
174
+ // This runs after explicit built-in / binary cases above so known
175
+ // types (for example Buffer) use their dedicated fast-path sizing
176
+ // logic instead of duck-typing through toJSON().
177
+ if (typeof obj.toJSON === "function") {
178
+ let projected;
179
+ try {
180
+ projected = obj.toJSON("");
181
+ }
182
+ catch {
183
+ // If toJSON throws, JSON.stringify would also throw and our
184
+ // serializer would emit "[Unserializable]" (~16 bytes).
185
+ return 16;
186
+ }
187
+ ancestors.add(obj);
188
+ const size = estimate(projected);
189
+ ancestors.delete(obj);
190
+ return size;
191
+ }
192
+ ancestors.add(obj);
193
+ let size;
194
+ if (Array.isArray(obj)) {
195
+ size = 2; // []
196
+ const len = obj.length;
197
+ for (let i = 0; i < len; i++) {
198
+ size += estimateInArray(obj[i]);
199
+ if (i < len - 1)
200
+ size += 1; // comma
201
+ }
202
+ }
203
+ else if (obj instanceof Map) {
204
+ // Rendered as { k: v, ... } via Object.fromEntries.
205
+ size = 2;
206
+ let emitted = 0;
207
+ for (const [k, v] of obj) {
208
+ if (isDropped(v))
209
+ continue;
210
+ if (emitted > 0)
211
+ size += 1; // comma
212
+ const keyStr = typeof k === "string" ? k : String(k);
213
+ size += byteLen(keyStr) + 3; // "key":
214
+ size += estimate(v);
215
+ emitted++;
216
+ }
217
+ }
218
+ else if (obj instanceof Set) {
219
+ // Rendered as [v, ...] via Array.from.
220
+ size = 2;
221
+ let emitted = 0;
222
+ for (const v of obj) {
223
+ if (emitted > 0)
224
+ size += 1; // comma
225
+ size += estimateInArray(v);
226
+ emitted++;
227
+ }
228
+ }
229
+ else {
230
+ size = 2; // {}
231
+ let emitted = 0;
232
+ // Object.keys only returns own enumerable string keys, matching
233
+ // JSON.stringify.
234
+ const keys = Object.keys(obj);
235
+ for (let i = 0; i < keys.length; i++) {
236
+ const key = keys[i];
237
+ const v = obj[key];
238
+ if (isDropped(v))
239
+ continue;
240
+ if (emitted > 0)
241
+ size += 1; // comma
242
+ size += byteLen(key) + 3; // "key":
243
+ size += estimate(v);
244
+ emitted++;
245
+ }
246
+ }
247
+ ancestors.delete(obj);
248
+ return size;
249
+ }
250
+ const size = estimate(value);
251
+ return { size, maxStringLen };
252
+ }
253
+ catch {
254
+ // If the estimator itself hits an unexpected edge case, fall back to the
255
+ // exact serialized size. This preserves correctness of queue-size
256
+ // accounting at the cost of a slower hot path for that one payload.
257
+ // We cannot cheaply recover maxStringLen here, so report 0: the worker
258
+ // gate will then fall back to sync serialization, which is safe.
259
+ return { size: serialize(value).length, maxStringLen: 0 };
260
+ }
261
+ }
60
262
  // Regular stringify
61
263
  export function serialize(obj, errorContext, replacer, spacer, options) {
62
264
  try {
@@ -48,7 +48,7 @@ exports._objectHash = _objectHash;
48
48
  exports.generateWrapperFromJestlikeMethods = generateWrapperFromJestlikeMethods;
49
49
  exports.isInTestContext = isInTestContext;
50
50
  const crypto_1 = __importDefault(require("crypto"));
51
- const uuid_1 = require("uuid");
51
+ const index_js_1 = require("../uuid/src/index.cjs");
52
52
  const os = __importStar(require("node:os"));
53
53
  const path = __importStar(require("node:path"));
54
54
  const fs = __importStar(require("node:fs/promises"));
@@ -137,7 +137,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
137
137
  catch (e) {
138
138
  // Naming collision
139
139
  if (e?.name === "LangSmithConflictError") {
140
- const ent = (0, uuid_1.v4)().slice(0, 6);
140
+ const ent = (0, index_js_1.v4)().slice(0, 6);
141
141
  experimentName = `${experimentName}-${ent}`;
142
142
  }
143
143
  else {
@@ -158,7 +158,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
158
158
  inputsHash: _objectHash(inputs),
159
159
  outputsHash: _objectHash(outputs ?? {}),
160
160
  });
161
- return (0, uuid_1.v5)(identifier, constants_js_1.UUID5_NAMESPACE);
161
+ return (0, index_js_1.v5)(identifier, constants_js_1.UUID5_NAMESPACE);
162
162
  }
163
163
  async function syncExample(params) {
164
164
  const { client, exampleId, inputs, outputs, metadata, split, createdAt, datasetId, } = params;
@@ -268,7 +268,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
268
268
  });
269
269
  return method(suiteName, () => {
270
270
  const startTime = new Date();
271
- const suiteUuid = (0, uuid_1.v4)();
271
+ const suiteUuid = (0, index_js_1.v4)();
272
272
  const environment = experimentConfig?.metadata?.ENVIRONMENT ??
273
273
  (0, env_js_1.getEnvironmentVariable)("ENVIRONMENT");
274
274
  const nodeEnv = experimentConfig?.metadata?.NODE_ENV ??
@@ -418,7 +418,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
418
418
  }
419
419
  const totalRuns = config?.repetitions ?? 1;
420
420
  for (let i = 0; i < totalRuns; i += 1) {
421
- const testUuid = (0, uuid_1.v4)().replace(/-/g, "").slice(0, 13);
421
+ const testUuid = (0, index_js_1.v4)().replace(/-/g, "").slice(0, 13);
422
422
  // Jest will not group tests under the same "describe" group if you await the test and
423
423
  // total runs is greater than 1.
424
424
  const resultsPath = path.join(os.tmpdir(), "langsmith_test_results", `${testUuid}.json`);
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
  import crypto from "crypto";
4
- import { v4, v5 } from "uuid";
4
+ import { v4, v5 } from "../uuid/src/index.js";
5
5
  import * as os from "node:os";
6
6
  import * as path from "node:path";
7
7
  import * as fs from "node:fs/promises";
@@ -4,7 +4,7 @@ exports.wrapEvaluator = wrapEvaluator;
4
4
  exports.evaluatedBy = evaluatedBy;
5
5
  const traceable_js_1 = require("../../../traceable.cjs");
6
6
  const globals_js_1 = require("../globals.cjs");
7
- const uuid_1 = require("uuid");
7
+ const index_js_1 = require("../../uuid/src/index.cjs");
8
8
  function isEvaluationResult(x) {
9
9
  return (x != null &&
10
10
  typeof x === "object" &&
@@ -22,7 +22,7 @@ function wrapEvaluator(evaluator) {
22
22
  `See this page for more information: https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest`,
23
23
  ].join("\n"));
24
24
  }
25
- let evalRunId = config?.runId ?? config?.id ?? (0, uuid_1.v7)();
25
+ let evalRunId = config?.runId ?? config?.id ?? (0, index_js_1.v7)();
26
26
  let evalResult;
27
27
  if ((0, globals_js_1.trackingEnabled)(context)) {
28
28
  const wrappedEvaluator = (0, traceable_js_1.traceable)(async (_runTree, params) => {
@@ -83,7 +83,7 @@ async function evaluatedBy(outputs, evaluator) {
83
83
  ].join("\n"));
84
84
  }
85
85
  const wrappedEvaluator = wrapEvaluator(evaluator);
86
- const evalRunId = (0, uuid_1.v7)();
86
+ const evalRunId = (0, index_js_1.v7)();
87
87
  const evalResult = await wrappedEvaluator({
88
88
  inputs: context.currentExample?.inputs ?? {},
89
89
  referenceOutputs: context?.currentExample?.outputs ?? {},
@@ -1,6 +1,6 @@
1
1
  import { ROOT, traceable } from "../../../traceable.js";
2
2
  import { testWrapperAsyncLocalStorageInstance, _logTestFeedback, trackingEnabled, } from "../globals.js";
3
- import { v7 } from "uuid";
3
+ import { v7 } from "../../uuid/src/index.js";
4
4
  function isEvaluationResult(x) {
5
5
  return (x != null &&
6
6
  typeof x === "object" &&
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePromptIdentifier = parsePromptIdentifier;
3
+ exports.parseHubIdentifier = parseHubIdentifier;
4
4
  const error_js_1 = require("./error.cjs");
5
- function parsePromptIdentifier(identifier) {
5
+ /**
6
+ * Parse a hub repo identifier (owner/name:hash, name, etc.).
7
+ *
8
+ * Prompts, agents, and skills share the same identifier grammar on Hub.
9
+ */
10
+ function parseHubIdentifier(identifier) {
6
11
  if (!identifier ||
7
12
  identifier.split("/").length > 2 ||
8
13
  identifier.startsWith("/") ||
@@ -1 +1,6 @@
1
- export declare function parsePromptIdentifier(identifier: string): [string, string, string];
1
+ /**
2
+ * Parse a hub repo identifier (owner/name:hash, name, etc.).
3
+ *
4
+ * Prompts, agents, and skills share the same identifier grammar on Hub.
5
+ */
6
+ export declare function parseHubIdentifier(identifier: string): [string, string, string];
@@ -1,5 +1,10 @@
1
1
  import { getInvalidPromptIdentifierMsg } from "./error.js";
2
- export function parsePromptIdentifier(identifier) {
2
+ /**
3
+ * Parse a hub repo identifier (owner/name:hash, name, etc.).
4
+ *
5
+ * Prompts, agents, and skills share the same identifier grammar on Hub.
6
+ */
7
+ export function parseHubIdentifier(identifier) {
3
8
  if (!identifier ||
4
9
  identifier.split("/").length > 2 ||
5
10
  identifier.startsWith("/") ||