langsmith 0.1.60 → 0.1.62
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 +44 -6
- package/dist/client.d.ts +25 -1
- package/dist/client.js +44 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +31 -21
- package/dist/run_trees.js +31 -21
- package/dist/traceable.cjs +12 -7
- package/dist/traceable.js +12 -7
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -116,11 +116,15 @@ class Queue {
|
|
|
116
116
|
return this.items.length;
|
|
117
117
|
}
|
|
118
118
|
push(item) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
let itemPromiseResolve;
|
|
120
|
+
const itemPromise = new Promise((resolve) => {
|
|
121
|
+
// Setting itemPromiseResolve is synchronous with promise creation:
|
|
122
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
123
|
+
itemPromiseResolve = resolve;
|
|
124
|
+
});
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
126
|
+
this.items.push([item, itemPromiseResolve, itemPromise]);
|
|
127
|
+
return itemPromise;
|
|
124
128
|
}
|
|
125
129
|
pop(upToN) {
|
|
126
130
|
if (upToN < 1) {
|
|
@@ -270,6 +274,12 @@ class Client {
|
|
|
270
274
|
writable: true,
|
|
271
275
|
value: void 0
|
|
272
276
|
});
|
|
277
|
+
Object.defineProperty(this, "blockOnRootRunFinalization", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
configurable: true,
|
|
280
|
+
writable: true,
|
|
281
|
+
value: true
|
|
282
|
+
});
|
|
273
283
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
274
284
|
this.tracingSampleRate = getTracingSamplingRate();
|
|
275
285
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
@@ -292,6 +302,8 @@ class Client {
|
|
|
292
302
|
this.hideOutputs =
|
|
293
303
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
294
304
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
305
|
+
this.blockOnRootRunFinalization =
|
|
306
|
+
config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
|
|
295
307
|
this.pendingAutoBatchedRunLimit =
|
|
296
308
|
config.pendingAutoBatchedRunLimit ?? this.pendingAutoBatchedRunLimit;
|
|
297
309
|
this.fetchOptions = config.fetchOptions || {};
|
|
@@ -698,7 +710,9 @@ class Client {
|
|
|
698
710
|
if (this.autoBatchTracing &&
|
|
699
711
|
data.trace_id !== undefined &&
|
|
700
712
|
data.dotted_order !== undefined) {
|
|
701
|
-
if (run.end_time !== undefined &&
|
|
713
|
+
if (run.end_time !== undefined &&
|
|
714
|
+
data.parent_run_id === undefined &&
|
|
715
|
+
this.blockOnRootRunFinalization) {
|
|
702
716
|
// Trigger a batch as soon as a root trace ends and block to ensure trace finishes
|
|
703
717
|
// in serverless environments.
|
|
704
718
|
await this.processRunOperation({ action: "update", item: data }, true);
|
|
@@ -2656,5 +2670,29 @@ class Client {
|
|
|
2656
2670
|
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
2657
2671
|
}
|
|
2658
2672
|
}
|
|
2673
|
+
/**
|
|
2674
|
+
* Awaits all pending trace batches. Useful for environments where
|
|
2675
|
+
* you need to be sure that all tracing requests finish before execution ends,
|
|
2676
|
+
* such as serverless environments.
|
|
2677
|
+
*
|
|
2678
|
+
* @example
|
|
2679
|
+
* ```
|
|
2680
|
+
* import { Client } from "langsmith";
|
|
2681
|
+
*
|
|
2682
|
+
* const client = new Client();
|
|
2683
|
+
*
|
|
2684
|
+
* try {
|
|
2685
|
+
* // Tracing happens here
|
|
2686
|
+
* ...
|
|
2687
|
+
* } finally {
|
|
2688
|
+
* await client.awaitPendingTraceBatches();
|
|
2689
|
+
* }
|
|
2690
|
+
* ```
|
|
2691
|
+
*
|
|
2692
|
+
* @returns A promise that resolves once all currently pending traces have sent.
|
|
2693
|
+
*/
|
|
2694
|
+
awaitPendingTraceBatches() {
|
|
2695
|
+
return Promise.all(this.autoBatchQueue.items.map(([, , promise]) => promise));
|
|
2696
|
+
}
|
|
2659
2697
|
}
|
|
2660
2698
|
exports.Client = Client;
|
package/dist/client.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface ClientConfig {
|
|
|
12
12
|
hideOutputs?: boolean | ((outputs: KVMap) => KVMap);
|
|
13
13
|
autoBatchTracing?: boolean;
|
|
14
14
|
pendingAutoBatchedRunLimit?: number;
|
|
15
|
+
blockOnRootRunFinalization?: boolean;
|
|
15
16
|
fetchOptions?: RequestInit;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
@@ -157,7 +158,7 @@ export type CreateExampleOptions = {
|
|
|
157
158
|
sourceRunId?: string;
|
|
158
159
|
};
|
|
159
160
|
export declare class Queue<T> {
|
|
160
|
-
items: [T, () => void][];
|
|
161
|
+
items: [T, () => void, Promise<void>][];
|
|
161
162
|
get size(): number;
|
|
162
163
|
push(item: T): Promise<void>;
|
|
163
164
|
pop(upToN: number): [T[], () => void];
|
|
@@ -185,6 +186,7 @@ export declare class Client {
|
|
|
185
186
|
private serverInfo;
|
|
186
187
|
private fetchOptions;
|
|
187
188
|
private settings;
|
|
189
|
+
private blockOnRootRunFinalization;
|
|
188
190
|
constructor(config?: ClientConfig);
|
|
189
191
|
static getDefaultClientConfig(): {
|
|
190
192
|
apiUrl: string;
|
|
@@ -736,5 +738,27 @@ export declare class Client {
|
|
|
736
738
|
datasetName?: string;
|
|
737
739
|
}): Promise<void>;
|
|
738
740
|
private parseTokenOrUrl;
|
|
741
|
+
/**
|
|
742
|
+
* Awaits all pending trace batches. Useful for environments where
|
|
743
|
+
* you need to be sure that all tracing requests finish before execution ends,
|
|
744
|
+
* such as serverless environments.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```
|
|
748
|
+
* import { Client } from "langsmith";
|
|
749
|
+
*
|
|
750
|
+
* const client = new Client();
|
|
751
|
+
*
|
|
752
|
+
* try {
|
|
753
|
+
* // Tracing happens here
|
|
754
|
+
* ...
|
|
755
|
+
* } finally {
|
|
756
|
+
* await client.awaitPendingTraceBatches();
|
|
757
|
+
* }
|
|
758
|
+
* ```
|
|
759
|
+
*
|
|
760
|
+
* @returns A promise that resolves once all currently pending traces have sent.
|
|
761
|
+
*/
|
|
762
|
+
awaitPendingTraceBatches(): Promise<void[]>;
|
|
739
763
|
}
|
|
740
764
|
export {};
|
package/dist/client.js
CHANGED
|
@@ -90,11 +90,15 @@ export class Queue {
|
|
|
90
90
|
return this.items.length;
|
|
91
91
|
}
|
|
92
92
|
push(item) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
let itemPromiseResolve;
|
|
94
|
+
const itemPromise = new Promise((resolve) => {
|
|
95
|
+
// Setting itemPromiseResolve is synchronous with promise creation:
|
|
96
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
97
|
+
itemPromiseResolve = resolve;
|
|
98
|
+
});
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
100
|
+
this.items.push([item, itemPromiseResolve, itemPromise]);
|
|
101
|
+
return itemPromise;
|
|
98
102
|
}
|
|
99
103
|
pop(upToN) {
|
|
100
104
|
if (upToN < 1) {
|
|
@@ -243,6 +247,12 @@ export class Client {
|
|
|
243
247
|
writable: true,
|
|
244
248
|
value: void 0
|
|
245
249
|
});
|
|
250
|
+
Object.defineProperty(this, "blockOnRootRunFinalization", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
configurable: true,
|
|
253
|
+
writable: true,
|
|
254
|
+
value: true
|
|
255
|
+
});
|
|
246
256
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
247
257
|
this.tracingSampleRate = getTracingSamplingRate();
|
|
248
258
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
@@ -265,6 +275,8 @@ export class Client {
|
|
|
265
275
|
this.hideOutputs =
|
|
266
276
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
267
277
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
278
|
+
this.blockOnRootRunFinalization =
|
|
279
|
+
config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
|
|
268
280
|
this.pendingAutoBatchedRunLimit =
|
|
269
281
|
config.pendingAutoBatchedRunLimit ?? this.pendingAutoBatchedRunLimit;
|
|
270
282
|
this.fetchOptions = config.fetchOptions || {};
|
|
@@ -671,7 +683,9 @@ export class Client {
|
|
|
671
683
|
if (this.autoBatchTracing &&
|
|
672
684
|
data.trace_id !== undefined &&
|
|
673
685
|
data.dotted_order !== undefined) {
|
|
674
|
-
if (run.end_time !== undefined &&
|
|
686
|
+
if (run.end_time !== undefined &&
|
|
687
|
+
data.parent_run_id === undefined &&
|
|
688
|
+
this.blockOnRootRunFinalization) {
|
|
675
689
|
// Trigger a batch as soon as a root trace ends and block to ensure trace finishes
|
|
676
690
|
// in serverless environments.
|
|
677
691
|
await this.processRunOperation({ action: "update", item: data }, true);
|
|
@@ -2629,4 +2643,28 @@ export class Client {
|
|
|
2629
2643
|
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
2630
2644
|
}
|
|
2631
2645
|
}
|
|
2646
|
+
/**
|
|
2647
|
+
* Awaits all pending trace batches. Useful for environments where
|
|
2648
|
+
* you need to be sure that all tracing requests finish before execution ends,
|
|
2649
|
+
* such as serverless environments.
|
|
2650
|
+
*
|
|
2651
|
+
* @example
|
|
2652
|
+
* ```
|
|
2653
|
+
* import { Client } from "langsmith";
|
|
2654
|
+
*
|
|
2655
|
+
* const client = new Client();
|
|
2656
|
+
*
|
|
2657
|
+
* try {
|
|
2658
|
+
* // Tracing happens here
|
|
2659
|
+
* ...
|
|
2660
|
+
* } finally {
|
|
2661
|
+
* await client.awaitPendingTraceBatches();
|
|
2662
|
+
* }
|
|
2663
|
+
* ```
|
|
2664
|
+
*
|
|
2665
|
+
* @returns A promise that resolves once all currently pending traces have sent.
|
|
2666
|
+
*/
|
|
2667
|
+
awaitPendingTraceBatches() {
|
|
2668
|
+
return Promise.all(this.autoBatchQueue.items.map(([, , promise]) => promise));
|
|
2669
|
+
}
|
|
2632
2670
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
|
|
|
8
8
|
var fetch_js_1 = require("./singletons/fetch.cjs");
|
|
9
9
|
Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
|
|
10
10
|
// Update using yarn bump-version
|
|
11
|
-
exports.__version__ = "0.1.
|
|
11
|
+
exports.__version__ = "0.1.62";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Client, type ClientConfig } from "./client.js";
|
|
|
2
2
|
export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
|
-
export declare const __version__ = "0.1.
|
|
5
|
+
export declare const __version__ = "0.1.62";
|
package/dist/index.js
CHANGED
package/dist/run_trees.cjs
CHANGED
|
@@ -364,31 +364,41 @@ class RunTree {
|
|
|
364
364
|
return persistedRun;
|
|
365
365
|
}
|
|
366
366
|
async postRun(excludeChildRuns = true) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
367
|
+
try {
|
|
368
|
+
const runtimeEnv = await (0, env_js_1.getRuntimeEnvironment)();
|
|
369
|
+
const runCreate = await this._convertToCreate(this, runtimeEnv, true);
|
|
370
|
+
await this.client.createRun(runCreate);
|
|
371
|
+
if (!excludeChildRuns) {
|
|
372
|
+
(0, warn_js_1.warnOnce)("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
|
|
373
|
+
for (const childRun of this.child_runs) {
|
|
374
|
+
await childRun.postRun(false);
|
|
375
|
+
}
|
|
374
376
|
}
|
|
375
377
|
}
|
|
378
|
+
catch (error) {
|
|
379
|
+
console.error(`Error in postRun for run ${this.id}:`, error);
|
|
380
|
+
}
|
|
376
381
|
}
|
|
377
382
|
async patchRun() {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
383
|
+
try {
|
|
384
|
+
const runUpdate = {
|
|
385
|
+
end_time: this.end_time,
|
|
386
|
+
error: this.error,
|
|
387
|
+
inputs: this.inputs,
|
|
388
|
+
outputs: this.outputs,
|
|
389
|
+
parent_run_id: this.parent_run?.id,
|
|
390
|
+
reference_example_id: this.reference_example_id,
|
|
391
|
+
extra: this.extra,
|
|
392
|
+
events: this.events,
|
|
393
|
+
dotted_order: this.dotted_order,
|
|
394
|
+
trace_id: this.trace_id,
|
|
395
|
+
tags: this.tags,
|
|
396
|
+
};
|
|
397
|
+
await this.client.updateRun(this.id, runUpdate);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
console.error(`Error in patchRun for run ${this.id}`, error);
|
|
401
|
+
}
|
|
392
402
|
}
|
|
393
403
|
toJSON() {
|
|
394
404
|
return this._convertToCreate(this, undefined, false);
|
package/dist/run_trees.js
CHANGED
|
@@ -337,31 +337,41 @@ export class RunTree {
|
|
|
337
337
|
return persistedRun;
|
|
338
338
|
}
|
|
339
339
|
async postRun(excludeChildRuns = true) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
340
|
+
try {
|
|
341
|
+
const runtimeEnv = await getRuntimeEnvironment();
|
|
342
|
+
const runCreate = await this._convertToCreate(this, runtimeEnv, true);
|
|
343
|
+
await this.client.createRun(runCreate);
|
|
344
|
+
if (!excludeChildRuns) {
|
|
345
|
+
warnOnce("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
|
|
346
|
+
for (const childRun of this.child_runs) {
|
|
347
|
+
await childRun.postRun(false);
|
|
348
|
+
}
|
|
347
349
|
}
|
|
348
350
|
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.error(`Error in postRun for run ${this.id}:`, error);
|
|
353
|
+
}
|
|
349
354
|
}
|
|
350
355
|
async patchRun() {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
356
|
+
try {
|
|
357
|
+
const runUpdate = {
|
|
358
|
+
end_time: this.end_time,
|
|
359
|
+
error: this.error,
|
|
360
|
+
inputs: this.inputs,
|
|
361
|
+
outputs: this.outputs,
|
|
362
|
+
parent_run_id: this.parent_run?.id,
|
|
363
|
+
reference_example_id: this.reference_example_id,
|
|
364
|
+
extra: this.extra,
|
|
365
|
+
events: this.events,
|
|
366
|
+
dotted_order: this.dotted_order,
|
|
367
|
+
trace_id: this.trace_id,
|
|
368
|
+
tags: this.tags,
|
|
369
|
+
};
|
|
370
|
+
await this.client.updateRun(this.id, runUpdate);
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
console.error(`Error in patchRun for run ${this.id}`, error);
|
|
374
|
+
}
|
|
365
375
|
}
|
|
366
376
|
toJSON() {
|
|
367
377
|
return this._convertToCreate(this, undefined, false);
|
package/dist/traceable.cjs
CHANGED
|
@@ -428,13 +428,18 @@ function traceable(wrappedFunc, config) {
|
|
|
428
428
|
}
|
|
429
429
|
if ((0, asserts_js_1.isGenerator)(wrappedFunc) && (0, asserts_js_1.isIteratorLike)(rawOutput)) {
|
|
430
430
|
const chunks = gatherAll(rawOutput);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
431
|
+
try {
|
|
432
|
+
await currentRunTree?.end(handleRunOutputs(await handleChunks(chunks.reduce((memo, { value, done }) => {
|
|
433
|
+
if (!done || typeof value !== "undefined") {
|
|
434
|
+
memo.push(value);
|
|
435
|
+
}
|
|
436
|
+
return memo;
|
|
437
|
+
}, []))));
|
|
438
|
+
await handleEnd();
|
|
439
|
+
}
|
|
440
|
+
catch (e) {
|
|
441
|
+
console.error("Error occurred during handleEnd:", e);
|
|
442
|
+
}
|
|
438
443
|
return (function* () {
|
|
439
444
|
for (const ret of chunks) {
|
|
440
445
|
if (ret.done)
|
package/dist/traceable.js
CHANGED
|
@@ -425,13 +425,18 @@ export function traceable(wrappedFunc, config) {
|
|
|
425
425
|
}
|
|
426
426
|
if (isGenerator(wrappedFunc) && isIteratorLike(rawOutput)) {
|
|
427
427
|
const chunks = gatherAll(rawOutput);
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
428
|
+
try {
|
|
429
|
+
await currentRunTree?.end(handleRunOutputs(await handleChunks(chunks.reduce((memo, { value, done }) => {
|
|
430
|
+
if (!done || typeof value !== "undefined") {
|
|
431
|
+
memo.push(value);
|
|
432
|
+
}
|
|
433
|
+
return memo;
|
|
434
|
+
}, []))));
|
|
435
|
+
await handleEnd();
|
|
436
|
+
}
|
|
437
|
+
catch (e) {
|
|
438
|
+
console.error("Error occurred during handleEnd:", e);
|
|
439
|
+
}
|
|
435
440
|
return (function* () {
|
|
436
441
|
for (const ret of chunks) {
|
|
437
442
|
if (ret.done)
|