langsmith 0.3.62-rc.2 → 0.3.63
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.
- package/dist/client.cjs +627 -424
- package/dist/client.d.ts +7 -1
- package/dist/client.js +626 -423
- package/dist/evaluation/evaluate_comparative.cjs +1 -0
- package/dist/evaluation/evaluate_comparative.d.ts +1 -0
- package/dist/evaluation/evaluate_comparative.js +1 -0
- package/dist/experimental/vercel/index.cjs +120 -21
- package/dist/experimental/vercel/index.d.ts +211 -1
- package/dist/experimental/vercel/index.js +119 -21
- package/dist/experimental/vercel/middleware.cjs +17 -8
- package/dist/experimental/vercel/middleware.d.ts +19 -2
- package/dist/experimental/vercel/middleware.js +17 -8
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/langchain.cjs +4 -0
- package/dist/langchain.d.ts +1 -0
- package/dist/langchain.js +4 -0
- package/dist/run_trees.cjs +17 -5
- package/dist/run_trees.d.ts +3 -1
- package/dist/run_trees.js +17 -5
- package/dist/singletons/fetch.cjs +5 -1
- package/dist/singletons/fetch.d.ts +1 -0
- package/dist/singletons/fetch.js +3 -0
- package/dist/traceable.cjs +24 -11
- package/dist/traceable.js +24 -11
- package/dist/utils/async_caller.cjs +15 -35
- package/dist/utils/async_caller.d.ts +0 -2
- package/dist/utils/async_caller.js +15 -35
- package/dist/utils/error.cjs +4 -4
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/error.js +4 -4
- package/package.json +2 -2
package/dist/singletons/fetch.js
CHANGED
|
@@ -14,6 +14,9 @@ const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("ls:fetch_implementation")
|
|
|
14
14
|
export const overrideFetchImplementation = (fetch) => {
|
|
15
15
|
globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
|
|
16
16
|
};
|
|
17
|
+
export const clearFetchImplementation = () => {
|
|
18
|
+
delete globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY];
|
|
19
|
+
};
|
|
17
20
|
export const _globalFetchImplementationIsNodeFetch = () => {
|
|
18
21
|
const fetchImpl = globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY];
|
|
19
22
|
if (!fetchImpl)
|
package/dist/traceable.cjs
CHANGED
|
@@ -122,7 +122,7 @@ function validateExtractedUsageMetadata(data) {
|
|
|
122
122
|
return data;
|
|
123
123
|
}
|
|
124
124
|
async function handleEnd(params) {
|
|
125
|
-
const { runTree, on_end, postRunPromise } = params;
|
|
125
|
+
const { runTree, on_end, postRunPromise, excludeInputs } = params;
|
|
126
126
|
const onEnd = on_end;
|
|
127
127
|
if (onEnd) {
|
|
128
128
|
if (!runTree) {
|
|
@@ -133,7 +133,9 @@ async function handleEnd(params) {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
await postRunPromise;
|
|
136
|
-
await runTree?.patchRun(
|
|
136
|
+
await runTree?.patchRun({
|
|
137
|
+
excludeInputs,
|
|
138
|
+
});
|
|
137
139
|
}
|
|
138
140
|
const _populateUsageMetadata = (processedOutputs, runTree) => {
|
|
139
141
|
if (runTree !== undefined) {
|
|
@@ -160,7 +162,7 @@ function isAsyncFn(fn) {
|
|
|
160
162
|
}
|
|
161
163
|
// Note: This mutates the run tree
|
|
162
164
|
async function handleRunOutputs(params) {
|
|
163
|
-
const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise } = params;
|
|
165
|
+
const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise, excludeInputs, } = params;
|
|
164
166
|
let outputs;
|
|
165
167
|
if ((0, asserts_js_1.isKVMap)(rawOutputs)) {
|
|
166
168
|
outputs = { ...rawOutputs };
|
|
@@ -183,7 +185,7 @@ async function handleRunOutputs(params) {
|
|
|
183
185
|
await runTree?.end(outputs);
|
|
184
186
|
})
|
|
185
187
|
.finally(async () => {
|
|
186
|
-
await handleEnd({ runTree, postRunPromise, on_end });
|
|
188
|
+
await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
|
|
187
189
|
});
|
|
188
190
|
return;
|
|
189
191
|
}
|
|
@@ -193,7 +195,7 @@ async function handleRunOutputs(params) {
|
|
|
193
195
|
}
|
|
194
196
|
_populateUsageMetadata(outputs, runTree);
|
|
195
197
|
await runTree?.end(outputs);
|
|
196
|
-
await handleEnd({ runTree, postRunPromise, on_end });
|
|
198
|
+
await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
|
|
197
199
|
return;
|
|
198
200
|
}
|
|
199
201
|
const handleRunAttachments = (rawInputs, extractAttachments) => {
|
|
@@ -283,11 +285,11 @@ const convertSerializableArg = (arg) => {
|
|
|
283
285
|
});
|
|
284
286
|
const pipeThrough = arg.pipeThrough(transform);
|
|
285
287
|
Object.assign(pipeThrough, { toJSON: () => proxyState });
|
|
286
|
-
return pipeThrough;
|
|
288
|
+
return { converted: pipeThrough, deferredInput: true };
|
|
287
289
|
}
|
|
288
290
|
if ((0, asserts_js_1.isAsyncIterable)(arg)) {
|
|
289
291
|
const proxyState = { current: [] };
|
|
290
|
-
|
|
292
|
+
const converted = new Proxy(arg, {
|
|
291
293
|
get(target, prop, receiver) {
|
|
292
294
|
if (prop === Symbol.asyncIterator) {
|
|
293
295
|
return () => {
|
|
@@ -327,10 +329,11 @@ const convertSerializableArg = (arg) => {
|
|
|
327
329
|
return Reflect.get(target, prop, receiver);
|
|
328
330
|
},
|
|
329
331
|
});
|
|
332
|
+
return { converted, deferredInput: true };
|
|
330
333
|
}
|
|
331
334
|
if (!Array.isArray(arg) && (0, asserts_js_1.isIteratorLike)(arg)) {
|
|
332
335
|
const proxyState = [];
|
|
333
|
-
|
|
336
|
+
const converted = new Proxy(arg, {
|
|
334
337
|
get(target, prop, receiver) {
|
|
335
338
|
if (prop === "next" || prop === "return" || prop === "throw") {
|
|
336
339
|
const bound = arg[prop]?.bind(arg);
|
|
@@ -354,11 +357,12 @@ const convertSerializableArg = (arg) => {
|
|
|
354
357
|
return Reflect.get(target, prop, receiver);
|
|
355
358
|
},
|
|
356
359
|
});
|
|
360
|
+
return { converted, deferredInput: true };
|
|
357
361
|
}
|
|
358
362
|
if ((0, asserts_js_1.isThenable)(arg)) {
|
|
359
|
-
return getSerializablePromise(arg);
|
|
363
|
+
return { converted: getSerializablePromise(arg), deferredInput: true };
|
|
360
364
|
}
|
|
361
|
-
return arg;
|
|
365
|
+
return { converted: arg, deferredInput: false };
|
|
362
366
|
};
|
|
363
367
|
/**
|
|
364
368
|
* Higher-order function that takes function as input and returns a
|
|
@@ -429,8 +433,11 @@ function traceable(wrappedFunc, config) {
|
|
|
429
433
|
const asyncLocalStorage = traceable_js_1.AsyncLocalStorageProviderSingleton.getInstance();
|
|
430
434
|
// TODO: deal with possible nested promises and async iterables
|
|
431
435
|
const processedArgs = args;
|
|
436
|
+
let deferredInput = false;
|
|
432
437
|
for (let i = 0; i < processedArgs.length; i++) {
|
|
433
|
-
|
|
438
|
+
const { converted, deferredInput: argDefersInput } = convertSerializableArg(processedArgs[i]);
|
|
439
|
+
processedArgs[i] = converted;
|
|
440
|
+
deferredInput = deferredInput || argDefersInput;
|
|
434
441
|
}
|
|
435
442
|
const [currentContext, rawInputs] = (() => {
|
|
436
443
|
const [firstArg, ...restArgs] = processedArgs;
|
|
@@ -520,6 +527,7 @@ function traceable(wrappedFunc, config) {
|
|
|
520
527
|
processOutputsFn,
|
|
521
528
|
on_end: config?.on_end,
|
|
522
529
|
postRunPromise,
|
|
530
|
+
excludeInputs: !deferredInput,
|
|
523
531
|
});
|
|
524
532
|
controller.close();
|
|
525
533
|
break;
|
|
@@ -544,6 +552,7 @@ function traceable(wrappedFunc, config) {
|
|
|
544
552
|
processOutputsFn,
|
|
545
553
|
on_end: config?.on_end,
|
|
546
554
|
postRunPromise,
|
|
555
|
+
excludeInputs: !deferredInput,
|
|
547
556
|
});
|
|
548
557
|
return reader.cancel(reason);
|
|
549
558
|
},
|
|
@@ -587,6 +596,7 @@ function traceable(wrappedFunc, config) {
|
|
|
587
596
|
processOutputsFn,
|
|
588
597
|
on_end: config?.on_end,
|
|
589
598
|
postRunPromise,
|
|
599
|
+
excludeInputs: !deferredInput,
|
|
590
600
|
});
|
|
591
601
|
}
|
|
592
602
|
}
|
|
@@ -664,6 +674,7 @@ function traceable(wrappedFunc, config) {
|
|
|
664
674
|
processOutputsFn,
|
|
665
675
|
on_end: config?.on_end,
|
|
666
676
|
postRunPromise,
|
|
677
|
+
excludeInputs: !deferredInput,
|
|
667
678
|
});
|
|
668
679
|
}
|
|
669
680
|
catch (e) {
|
|
@@ -684,6 +695,7 @@ function traceable(wrappedFunc, config) {
|
|
|
684
695
|
processOutputsFn,
|
|
685
696
|
on_end: config?.on_end,
|
|
686
697
|
postRunPromise,
|
|
698
|
+
excludeInputs: !deferredInput,
|
|
687
699
|
});
|
|
688
700
|
}
|
|
689
701
|
finally {
|
|
@@ -696,6 +708,7 @@ function traceable(wrappedFunc, config) {
|
|
|
696
708
|
runTree: currentRunTree,
|
|
697
709
|
postRunPromise,
|
|
698
710
|
on_end: config?.on_end,
|
|
711
|
+
excludeInputs: !deferredInput,
|
|
699
712
|
});
|
|
700
713
|
throw error;
|
|
701
714
|
})
|
package/dist/traceable.js
CHANGED
|
@@ -118,7 +118,7 @@ function validateExtractedUsageMetadata(data) {
|
|
|
118
118
|
return data;
|
|
119
119
|
}
|
|
120
120
|
async function handleEnd(params) {
|
|
121
|
-
const { runTree, on_end, postRunPromise } = params;
|
|
121
|
+
const { runTree, on_end, postRunPromise, excludeInputs } = params;
|
|
122
122
|
const onEnd = on_end;
|
|
123
123
|
if (onEnd) {
|
|
124
124
|
if (!runTree) {
|
|
@@ -129,7 +129,9 @@ async function handleEnd(params) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
await postRunPromise;
|
|
132
|
-
await runTree?.patchRun(
|
|
132
|
+
await runTree?.patchRun({
|
|
133
|
+
excludeInputs,
|
|
134
|
+
});
|
|
133
135
|
}
|
|
134
136
|
const _populateUsageMetadata = (processedOutputs, runTree) => {
|
|
135
137
|
if (runTree !== undefined) {
|
|
@@ -156,7 +158,7 @@ function isAsyncFn(fn) {
|
|
|
156
158
|
}
|
|
157
159
|
// Note: This mutates the run tree
|
|
158
160
|
async function handleRunOutputs(params) {
|
|
159
|
-
const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise } = params;
|
|
161
|
+
const { runTree, rawOutputs, processOutputsFn, on_end, postRunPromise, excludeInputs, } = params;
|
|
160
162
|
let outputs;
|
|
161
163
|
if (isKVMap(rawOutputs)) {
|
|
162
164
|
outputs = { ...rawOutputs };
|
|
@@ -179,7 +181,7 @@ async function handleRunOutputs(params) {
|
|
|
179
181
|
await runTree?.end(outputs);
|
|
180
182
|
})
|
|
181
183
|
.finally(async () => {
|
|
182
|
-
await handleEnd({ runTree, postRunPromise, on_end });
|
|
184
|
+
await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
|
|
183
185
|
});
|
|
184
186
|
return;
|
|
185
187
|
}
|
|
@@ -189,7 +191,7 @@ async function handleRunOutputs(params) {
|
|
|
189
191
|
}
|
|
190
192
|
_populateUsageMetadata(outputs, runTree);
|
|
191
193
|
await runTree?.end(outputs);
|
|
192
|
-
await handleEnd({ runTree, postRunPromise, on_end });
|
|
194
|
+
await handleEnd({ runTree, postRunPromise, on_end, excludeInputs });
|
|
193
195
|
return;
|
|
194
196
|
}
|
|
195
197
|
const handleRunAttachments = (rawInputs, extractAttachments) => {
|
|
@@ -279,11 +281,11 @@ const convertSerializableArg = (arg) => {
|
|
|
279
281
|
});
|
|
280
282
|
const pipeThrough = arg.pipeThrough(transform);
|
|
281
283
|
Object.assign(pipeThrough, { toJSON: () => proxyState });
|
|
282
|
-
return pipeThrough;
|
|
284
|
+
return { converted: pipeThrough, deferredInput: true };
|
|
283
285
|
}
|
|
284
286
|
if (isAsyncIterable(arg)) {
|
|
285
287
|
const proxyState = { current: [] };
|
|
286
|
-
|
|
288
|
+
const converted = new Proxy(arg, {
|
|
287
289
|
get(target, prop, receiver) {
|
|
288
290
|
if (prop === Symbol.asyncIterator) {
|
|
289
291
|
return () => {
|
|
@@ -323,10 +325,11 @@ const convertSerializableArg = (arg) => {
|
|
|
323
325
|
return Reflect.get(target, prop, receiver);
|
|
324
326
|
},
|
|
325
327
|
});
|
|
328
|
+
return { converted, deferredInput: true };
|
|
326
329
|
}
|
|
327
330
|
if (!Array.isArray(arg) && isIteratorLike(arg)) {
|
|
328
331
|
const proxyState = [];
|
|
329
|
-
|
|
332
|
+
const converted = new Proxy(arg, {
|
|
330
333
|
get(target, prop, receiver) {
|
|
331
334
|
if (prop === "next" || prop === "return" || prop === "throw") {
|
|
332
335
|
const bound = arg[prop]?.bind(arg);
|
|
@@ -350,11 +353,12 @@ const convertSerializableArg = (arg) => {
|
|
|
350
353
|
return Reflect.get(target, prop, receiver);
|
|
351
354
|
},
|
|
352
355
|
});
|
|
356
|
+
return { converted, deferredInput: true };
|
|
353
357
|
}
|
|
354
358
|
if (isThenable(arg)) {
|
|
355
|
-
return getSerializablePromise(arg);
|
|
359
|
+
return { converted: getSerializablePromise(arg), deferredInput: true };
|
|
356
360
|
}
|
|
357
|
-
return arg;
|
|
361
|
+
return { converted: arg, deferredInput: false };
|
|
358
362
|
};
|
|
359
363
|
/**
|
|
360
364
|
* Higher-order function that takes function as input and returns a
|
|
@@ -425,8 +429,11 @@ export function traceable(wrappedFunc, config) {
|
|
|
425
429
|
const asyncLocalStorage = AsyncLocalStorageProviderSingleton.getInstance();
|
|
426
430
|
// TODO: deal with possible nested promises and async iterables
|
|
427
431
|
const processedArgs = args;
|
|
432
|
+
let deferredInput = false;
|
|
428
433
|
for (let i = 0; i < processedArgs.length; i++) {
|
|
429
|
-
|
|
434
|
+
const { converted, deferredInput: argDefersInput } = convertSerializableArg(processedArgs[i]);
|
|
435
|
+
processedArgs[i] = converted;
|
|
436
|
+
deferredInput = deferredInput || argDefersInput;
|
|
430
437
|
}
|
|
431
438
|
const [currentContext, rawInputs] = (() => {
|
|
432
439
|
const [firstArg, ...restArgs] = processedArgs;
|
|
@@ -516,6 +523,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
516
523
|
processOutputsFn,
|
|
517
524
|
on_end: config?.on_end,
|
|
518
525
|
postRunPromise,
|
|
526
|
+
excludeInputs: !deferredInput,
|
|
519
527
|
});
|
|
520
528
|
controller.close();
|
|
521
529
|
break;
|
|
@@ -540,6 +548,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
540
548
|
processOutputsFn,
|
|
541
549
|
on_end: config?.on_end,
|
|
542
550
|
postRunPromise,
|
|
551
|
+
excludeInputs: !deferredInput,
|
|
543
552
|
});
|
|
544
553
|
return reader.cancel(reason);
|
|
545
554
|
},
|
|
@@ -583,6 +592,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
583
592
|
processOutputsFn,
|
|
584
593
|
on_end: config?.on_end,
|
|
585
594
|
postRunPromise,
|
|
595
|
+
excludeInputs: !deferredInput,
|
|
586
596
|
});
|
|
587
597
|
}
|
|
588
598
|
}
|
|
@@ -660,6 +670,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
660
670
|
processOutputsFn,
|
|
661
671
|
on_end: config?.on_end,
|
|
662
672
|
postRunPromise,
|
|
673
|
+
excludeInputs: !deferredInput,
|
|
663
674
|
});
|
|
664
675
|
}
|
|
665
676
|
catch (e) {
|
|
@@ -680,6 +691,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
680
691
|
processOutputsFn,
|
|
681
692
|
on_end: config?.on_end,
|
|
682
693
|
postRunPromise,
|
|
694
|
+
excludeInputs: !deferredInput,
|
|
683
695
|
});
|
|
684
696
|
}
|
|
685
697
|
finally {
|
|
@@ -692,6 +704,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
692
704
|
runTree: currentRunTree,
|
|
693
705
|
postRunPromise,
|
|
694
706
|
on_end: config?.on_end,
|
|
707
|
+
excludeInputs: !deferredInput,
|
|
695
708
|
});
|
|
696
709
|
throw error;
|
|
697
710
|
})
|
|
@@ -6,19 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.AsyncCaller = void 0;
|
|
7
7
|
const p_retry_1 = __importDefault(require("p-retry"));
|
|
8
8
|
const p_queue_1 = __importDefault(require("p-queue"));
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
405, // Method Not Allowed
|
|
16
|
-
406, // Not Acceptable
|
|
17
|
-
407, // Proxy Authentication Required
|
|
18
|
-
408, // Request Timeout
|
|
19
|
-
];
|
|
20
|
-
const STATUS_IGNORE = [
|
|
21
|
-
409, // Conflict
|
|
9
|
+
const STATUS_RETRYABLE = [
|
|
10
|
+
429, // Too Many Requests
|
|
11
|
+
500, // Internal Server Error
|
|
12
|
+
502, // Bad Gateway
|
|
13
|
+
503, // Service Unavailable
|
|
14
|
+
504, // Gateway Timeout
|
|
22
15
|
];
|
|
23
16
|
/**
|
|
24
17
|
* A class that can be used to make async calls with concurrency and retry logic.
|
|
@@ -59,15 +52,8 @@ class AsyncCaller {
|
|
|
59
52
|
writable: true,
|
|
60
53
|
value: void 0
|
|
61
54
|
});
|
|
62
|
-
Object.defineProperty(this, "debug", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
55
|
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
69
56
|
this.maxRetries = params.maxRetries ?? 6;
|
|
70
|
-
this.debug = params.debug;
|
|
71
57
|
if ("default" in p_queue_1.default) {
|
|
72
58
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
59
|
this.queue = new p_queue_1.default.default({
|
|
@@ -92,6 +78,7 @@ class AsyncCaller {
|
|
|
92
78
|
throw new Error(error);
|
|
93
79
|
}
|
|
94
80
|
}), {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
82
|
async onFailedAttempt(error) {
|
|
96
83
|
if (error.message.startsWith("Cancel") ||
|
|
97
84
|
error.message.startsWith("TimeoutError") ||
|
|
@@ -99,27 +86,23 @@ class AsyncCaller {
|
|
|
99
86
|
error.message.startsWith("AbortError")) {
|
|
100
87
|
throw error;
|
|
101
88
|
}
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
89
|
if (error?.code === "ECONNABORTED") {
|
|
104
90
|
throw error;
|
|
105
91
|
}
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
92
|
const response = error?.response;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
else if (STATUS_IGNORE.includes(+status)) {
|
|
93
|
+
if (onFailedResponseHook) {
|
|
94
|
+
const handled = await onFailedResponseHook(response);
|
|
95
|
+
if (handled) {
|
|
114
96
|
return;
|
|
115
97
|
}
|
|
116
|
-
|
|
117
|
-
|
|
98
|
+
}
|
|
99
|
+
const status = response?.status ?? error?.status;
|
|
100
|
+
if (status) {
|
|
101
|
+
if (!STATUS_RETRYABLE.includes(+status)) {
|
|
102
|
+
throw error;
|
|
118
103
|
}
|
|
119
104
|
}
|
|
120
105
|
},
|
|
121
|
-
// If needed we can change some of the defaults here,
|
|
122
|
-
// but they're quite sensible.
|
|
123
106
|
retries: this.maxRetries,
|
|
124
107
|
randomize: true,
|
|
125
108
|
}), { throwOnTimeout: true });
|
|
@@ -140,8 +123,5 @@ class AsyncCaller {
|
|
|
140
123
|
}
|
|
141
124
|
return this.call(callable, ...args);
|
|
142
125
|
}
|
|
143
|
-
fetch(...args) {
|
|
144
|
-
return this.call(() => (0, fetch_js_1._getFetchImplementation)(this.debug)(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
145
|
-
}
|
|
146
126
|
}
|
|
147
127
|
exports.AsyncCaller = AsyncCaller;
|
|
@@ -34,10 +34,8 @@ export declare class AsyncCaller {
|
|
|
34
34
|
protected maxRetries: AsyncCallerParams["maxRetries"];
|
|
35
35
|
queue: typeof import("p-queue")["default"]["prototype"];
|
|
36
36
|
private onFailedResponseHook?;
|
|
37
|
-
private debug?;
|
|
38
37
|
constructor(params: AsyncCallerParams);
|
|
39
38
|
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
40
39
|
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
41
|
-
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
42
40
|
}
|
|
43
41
|
export {};
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import pRetry from "p-retry";
|
|
2
2
|
import PQueueMod from "p-queue";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
405, // Method Not Allowed
|
|
10
|
-
406, // Not Acceptable
|
|
11
|
-
407, // Proxy Authentication Required
|
|
12
|
-
408, // Request Timeout
|
|
13
|
-
];
|
|
14
|
-
const STATUS_IGNORE = [
|
|
15
|
-
409, // Conflict
|
|
3
|
+
const STATUS_RETRYABLE = [
|
|
4
|
+
429, // Too Many Requests
|
|
5
|
+
500, // Internal Server Error
|
|
6
|
+
502, // Bad Gateway
|
|
7
|
+
503, // Service Unavailable
|
|
8
|
+
504, // Gateway Timeout
|
|
16
9
|
];
|
|
17
10
|
/**
|
|
18
11
|
* A class that can be used to make async calls with concurrency and retry logic.
|
|
@@ -53,15 +46,8 @@ export class AsyncCaller {
|
|
|
53
46
|
writable: true,
|
|
54
47
|
value: void 0
|
|
55
48
|
});
|
|
56
|
-
Object.defineProperty(this, "debug", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
49
|
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
63
50
|
this.maxRetries = params.maxRetries ?? 6;
|
|
64
|
-
this.debug = params.debug;
|
|
65
51
|
if ("default" in PQueueMod) {
|
|
66
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
53
|
this.queue = new PQueueMod.default({
|
|
@@ -86,6 +72,7 @@ export class AsyncCaller {
|
|
|
86
72
|
throw new Error(error);
|
|
87
73
|
}
|
|
88
74
|
}), {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
76
|
async onFailedAttempt(error) {
|
|
90
77
|
if (error.message.startsWith("Cancel") ||
|
|
91
78
|
error.message.startsWith("TimeoutError") ||
|
|
@@ -93,27 +80,23 @@ export class AsyncCaller {
|
|
|
93
80
|
error.message.startsWith("AbortError")) {
|
|
94
81
|
throw error;
|
|
95
82
|
}
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
83
|
if (error?.code === "ECONNABORTED") {
|
|
98
84
|
throw error;
|
|
99
85
|
}
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
86
|
const response = error?.response;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
else if (STATUS_IGNORE.includes(+status)) {
|
|
87
|
+
if (onFailedResponseHook) {
|
|
88
|
+
const handled = await onFailedResponseHook(response);
|
|
89
|
+
if (handled) {
|
|
108
90
|
return;
|
|
109
91
|
}
|
|
110
|
-
|
|
111
|
-
|
|
92
|
+
}
|
|
93
|
+
const status = response?.status ?? error?.status;
|
|
94
|
+
if (status) {
|
|
95
|
+
if (!STATUS_RETRYABLE.includes(+status)) {
|
|
96
|
+
throw error;
|
|
112
97
|
}
|
|
113
98
|
}
|
|
114
99
|
},
|
|
115
|
-
// If needed we can change some of the defaults here,
|
|
116
|
-
// but they're quite sensible.
|
|
117
100
|
retries: this.maxRetries,
|
|
118
101
|
randomize: true,
|
|
119
102
|
}), { throwOnTimeout: true });
|
|
@@ -134,7 +117,4 @@ export class AsyncCaller {
|
|
|
134
117
|
}
|
|
135
118
|
return this.call(callable, ...args);
|
|
136
119
|
}
|
|
137
|
-
fetch(...args) {
|
|
138
|
-
return this.call(() => _getFetchImplementation(this.debug)(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
139
|
-
}
|
|
140
120
|
}
|
package/dist/utils/error.cjs
CHANGED
|
@@ -78,12 +78,12 @@ exports.LangSmithConflictError = LangSmithConflictError;
|
|
|
78
78
|
* @throws {LangSmithConflictError} When the response status is 409
|
|
79
79
|
* @throws {Error} For all other non-ok responses
|
|
80
80
|
*/
|
|
81
|
-
async function raiseForStatus(response, context,
|
|
82
|
-
// consume the response body to release the connection
|
|
83
|
-
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
81
|
+
async function raiseForStatus(response, context, consumeOnSuccess) {
|
|
84
82
|
let errorBody;
|
|
85
83
|
if (response.ok) {
|
|
86
|
-
|
|
84
|
+
// consume the response body to release the connection
|
|
85
|
+
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
86
|
+
if (consumeOnSuccess) {
|
|
87
87
|
errorBody = await response.text();
|
|
88
88
|
}
|
|
89
89
|
return;
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class LangSmithConflictError extends Error {
|
|
|
42
42
|
* @throws {LangSmithConflictError} When the response status is 409
|
|
43
43
|
* @throws {Error} For all other non-ok responses
|
|
44
44
|
*/
|
|
45
|
-
export declare function raiseForStatus(response: Response, context: string,
|
|
45
|
+
export declare function raiseForStatus(response: Response, context: string, consumeOnSuccess?: boolean): Promise<void>;
|
|
46
46
|
export declare class ConflictingEndpointsError extends Error {
|
|
47
47
|
readonly code = "ERR_CONFLICTING_ENDPOINTS";
|
|
48
48
|
constructor();
|
package/dist/utils/error.js
CHANGED
|
@@ -71,12 +71,12 @@ export class LangSmithConflictError extends Error {
|
|
|
71
71
|
* @throws {LangSmithConflictError} When the response status is 409
|
|
72
72
|
* @throws {Error} For all other non-ok responses
|
|
73
73
|
*/
|
|
74
|
-
export async function raiseForStatus(response, context,
|
|
75
|
-
// consume the response body to release the connection
|
|
76
|
-
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
74
|
+
export async function raiseForStatus(response, context, consumeOnSuccess) {
|
|
77
75
|
let errorBody;
|
|
78
76
|
if (response.ok) {
|
|
79
|
-
|
|
77
|
+
// consume the response body to release the connection
|
|
78
|
+
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
79
|
+
if (consumeOnSuccess) {
|
|
80
80
|
errorBody = await response.text();
|
|
81
81
|
}
|
|
82
82
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langsmith",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.63",
|
|
4
4
|
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
|
|
5
5
|
"packageManager": "yarn@1.22.19",
|
|
6
6
|
"files": [
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"@faker-js/faker": "^8.4.1",
|
|
155
155
|
"@jest/globals": "^29.5.0",
|
|
156
156
|
"@jest/reporters": "^29.7.0",
|
|
157
|
-
"@langchain/core": "^0.3.
|
|
157
|
+
"@langchain/core": "^0.3.72",
|
|
158
158
|
"@langchain/langgraph": "^0.3.6",
|
|
159
159
|
"@langchain/openai": "^0.5.16",
|
|
160
160
|
"@opentelemetry/api": "^1.9.0",
|