langsmith 0.2.1 → 0.2.2-rc.1
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 +17 -23
- package/dist/client.d.ts +2 -2
- package/dist/client.js +15 -21
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/fast-safe-stringify/index.cjs +29 -20
- package/dist/utils/fast-safe-stringify/index.js +29 -20
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Client = exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = exports.
|
|
26
|
+
exports.Client = exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = exports.AutoBatchQueue = exports.mergeRuntimeEnvIntoRunCreate = void 0;
|
|
27
27
|
const uuid = __importStar(require("uuid"));
|
|
28
28
|
const async_caller_js_1 = require("./utils/async_caller.cjs");
|
|
29
29
|
const messages_js_1 = require("./utils/messages.cjs");
|
|
@@ -102,7 +102,7 @@ const handle429 = async (response) => {
|
|
|
102
102
|
// Fall back to existing status checks
|
|
103
103
|
return false;
|
|
104
104
|
};
|
|
105
|
-
class
|
|
105
|
+
class AutoBatchQueue {
|
|
106
106
|
constructor() {
|
|
107
107
|
Object.defineProperty(this, "items", {
|
|
108
108
|
enumerable: true,
|
|
@@ -169,7 +169,7 @@ class Queue {
|
|
|
169
169
|
];
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
exports.
|
|
172
|
+
exports.AutoBatchQueue = AutoBatchQueue;
|
|
173
173
|
// 20 MB
|
|
174
174
|
exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20_971_520;
|
|
175
175
|
const SERVER_INFO_REQUEST_TIMEOUT = 1000;
|
|
@@ -251,7 +251,7 @@ class Client {
|
|
|
251
251
|
enumerable: true,
|
|
252
252
|
configurable: true,
|
|
253
253
|
writable: true,
|
|
254
|
-
value: new
|
|
254
|
+
value: new AutoBatchQueue()
|
|
255
255
|
});
|
|
256
256
|
Object.defineProperty(this, "autoBatchTimeout", {
|
|
257
257
|
enumerable: true,
|
|
@@ -539,20 +539,17 @@ class Client {
|
|
|
539
539
|
serverInfo.batch_ingest_config?.size_limit_bytes ??
|
|
540
540
|
exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES);
|
|
541
541
|
}
|
|
542
|
-
|
|
543
|
-
const batchSizeLimit = await this._getBatchSizeLimitBytes();
|
|
542
|
+
drainAutoBatchQueue(batchSizeLimit) {
|
|
544
543
|
while (this.autoBatchQueue.items.length > 0) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
await this.processBatch(batch, done);
|
|
544
|
+
const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
|
|
545
|
+
if (!batch.length) {
|
|
546
|
+
done();
|
|
547
|
+
break;
|
|
552
548
|
}
|
|
549
|
+
void this._processBatch(batch, done).catch(console.error);
|
|
553
550
|
}
|
|
554
551
|
}
|
|
555
|
-
async
|
|
552
|
+
async _processBatch(batch, done) {
|
|
556
553
|
if (!batch.length) {
|
|
557
554
|
done();
|
|
558
555
|
return;
|
|
@@ -578,7 +575,7 @@ class Client {
|
|
|
578
575
|
done();
|
|
579
576
|
}
|
|
580
577
|
}
|
|
581
|
-
async processRunOperation(item
|
|
578
|
+
async processRunOperation(item) {
|
|
582
579
|
const oldTimeout = this.autoBatchTimeout;
|
|
583
580
|
clearTimeout(this.autoBatchTimeout);
|
|
584
581
|
this.autoBatchTimeout = undefined;
|
|
@@ -587,16 +584,13 @@ class Client {
|
|
|
587
584
|
}
|
|
588
585
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
589
586
|
const sizeLimitBytes = await this._getBatchSizeLimitBytes();
|
|
590
|
-
if (
|
|
591
|
-
this.
|
|
592
|
-
await this.drainAutoBatchQueue().catch(console.error);
|
|
587
|
+
if (this.autoBatchQueue.sizeBytes > sizeLimitBytes) {
|
|
588
|
+
this.drainAutoBatchQueue(sizeLimitBytes);
|
|
593
589
|
}
|
|
594
590
|
if (this.autoBatchQueue.items.length > 0) {
|
|
595
591
|
this.autoBatchTimeout = setTimeout(() => {
|
|
596
592
|
this.autoBatchTimeout = undefined;
|
|
597
|
-
|
|
598
|
-
// from the outside. So just log instead.
|
|
599
|
-
void this.drainAutoBatchQueue().catch(console.error);
|
|
593
|
+
this.drainAutoBatchQueue(sizeLimitBytes);
|
|
600
594
|
}, oldTimeout
|
|
601
595
|
? this.autoBatchAggregationDelayMs
|
|
602
596
|
: this.autoBatchInitialDelayMs);
|
|
@@ -921,9 +915,9 @@ class Client {
|
|
|
921
915
|
if (run.end_time !== undefined &&
|
|
922
916
|
data.parent_run_id === undefined &&
|
|
923
917
|
this.blockOnRootRunFinalization) {
|
|
924
|
-
// Trigger
|
|
918
|
+
// Trigger batches as soon as a root trace ends and wait to ensure trace finishes
|
|
925
919
|
// in serverless environments.
|
|
926
|
-
await this.processRunOperation({ action: "update", item: data }
|
|
920
|
+
await this.processRunOperation({ action: "update", item: data }).catch(console.error);
|
|
927
921
|
return;
|
|
928
922
|
}
|
|
929
923
|
else {
|
package/dist/client.d.ts
CHANGED
|
@@ -164,7 +164,7 @@ type AutoBatchQueueItem = {
|
|
|
164
164
|
item: RunCreate | RunUpdate;
|
|
165
165
|
};
|
|
166
166
|
export declare function mergeRuntimeEnvIntoRunCreate(run: RunCreate): RunCreate;
|
|
167
|
-
export declare class
|
|
167
|
+
export declare class AutoBatchQueue {
|
|
168
168
|
items: {
|
|
169
169
|
action: "create" | "update";
|
|
170
170
|
payload: RunCreate | RunUpdate;
|
|
@@ -228,7 +228,7 @@ export declare class Client {
|
|
|
228
228
|
private _filterForSampling;
|
|
229
229
|
private _getBatchSizeLimitBytes;
|
|
230
230
|
private drainAutoBatchQueue;
|
|
231
|
-
private
|
|
231
|
+
private _processBatch;
|
|
232
232
|
private processRunOperation;
|
|
233
233
|
protected _getServerInfo(): Promise<any>;
|
|
234
234
|
protected _ensureServerInfo(): Promise<Record<string, any>>;
|
package/dist/client.js
CHANGED
|
@@ -75,7 +75,7 @@ const handle429 = async (response) => {
|
|
|
75
75
|
// Fall back to existing status checks
|
|
76
76
|
return false;
|
|
77
77
|
};
|
|
78
|
-
export class
|
|
78
|
+
export class AutoBatchQueue {
|
|
79
79
|
constructor() {
|
|
80
80
|
Object.defineProperty(this, "items", {
|
|
81
81
|
enumerable: true,
|
|
@@ -223,7 +223,7 @@ export class Client {
|
|
|
223
223
|
enumerable: true,
|
|
224
224
|
configurable: true,
|
|
225
225
|
writable: true,
|
|
226
|
-
value: new
|
|
226
|
+
value: new AutoBatchQueue()
|
|
227
227
|
});
|
|
228
228
|
Object.defineProperty(this, "autoBatchTimeout", {
|
|
229
229
|
enumerable: true,
|
|
@@ -511,20 +511,17 @@ export class Client {
|
|
|
511
511
|
serverInfo.batch_ingest_config?.size_limit_bytes ??
|
|
512
512
|
DEFAULT_BATCH_SIZE_LIMIT_BYTES);
|
|
513
513
|
}
|
|
514
|
-
|
|
515
|
-
const batchSizeLimit = await this._getBatchSizeLimitBytes();
|
|
514
|
+
drainAutoBatchQueue(batchSizeLimit) {
|
|
516
515
|
while (this.autoBatchQueue.items.length > 0) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
await this.processBatch(batch, done);
|
|
516
|
+
const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
|
|
517
|
+
if (!batch.length) {
|
|
518
|
+
done();
|
|
519
|
+
break;
|
|
524
520
|
}
|
|
521
|
+
void this._processBatch(batch, done).catch(console.error);
|
|
525
522
|
}
|
|
526
523
|
}
|
|
527
|
-
async
|
|
524
|
+
async _processBatch(batch, done) {
|
|
528
525
|
if (!batch.length) {
|
|
529
526
|
done();
|
|
530
527
|
return;
|
|
@@ -550,7 +547,7 @@ export class Client {
|
|
|
550
547
|
done();
|
|
551
548
|
}
|
|
552
549
|
}
|
|
553
|
-
async processRunOperation(item
|
|
550
|
+
async processRunOperation(item) {
|
|
554
551
|
const oldTimeout = this.autoBatchTimeout;
|
|
555
552
|
clearTimeout(this.autoBatchTimeout);
|
|
556
553
|
this.autoBatchTimeout = undefined;
|
|
@@ -559,16 +556,13 @@ export class Client {
|
|
|
559
556
|
}
|
|
560
557
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
561
558
|
const sizeLimitBytes = await this._getBatchSizeLimitBytes();
|
|
562
|
-
if (
|
|
563
|
-
this.
|
|
564
|
-
await this.drainAutoBatchQueue().catch(console.error);
|
|
559
|
+
if (this.autoBatchQueue.sizeBytes > sizeLimitBytes) {
|
|
560
|
+
this.drainAutoBatchQueue(sizeLimitBytes);
|
|
565
561
|
}
|
|
566
562
|
if (this.autoBatchQueue.items.length > 0) {
|
|
567
563
|
this.autoBatchTimeout = setTimeout(() => {
|
|
568
564
|
this.autoBatchTimeout = undefined;
|
|
569
|
-
|
|
570
|
-
// from the outside. So just log instead.
|
|
571
|
-
void this.drainAutoBatchQueue().catch(console.error);
|
|
565
|
+
this.drainAutoBatchQueue(sizeLimitBytes);
|
|
572
566
|
}, oldTimeout
|
|
573
567
|
? this.autoBatchAggregationDelayMs
|
|
574
568
|
: this.autoBatchInitialDelayMs);
|
|
@@ -893,9 +887,9 @@ export class Client {
|
|
|
893
887
|
if (run.end_time !== undefined &&
|
|
894
888
|
data.parent_run_id === undefined &&
|
|
895
889
|
this.blockOnRootRunFinalization) {
|
|
896
|
-
// Trigger
|
|
890
|
+
// Trigger batches as soon as a root trace ends and wait to ensure trace finishes
|
|
897
891
|
// in serverless environments.
|
|
898
|
-
await this.processRunOperation({ action: "update", item: data }
|
|
892
|
+
await this.processRunOperation({ action: "update", item: data }).catch(console.error);
|
|
899
893
|
return;
|
|
900
894
|
}
|
|
901
895
|
else {
|
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.2.1";
|
|
11
|
+
exports.__version__ = "0.2.2-rc.1";
|
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.2.1";
|
|
5
|
+
export declare const __version__ = "0.2.2-rc.1";
|
package/dist/index.js
CHANGED
|
@@ -15,34 +15,43 @@ function defaultOptions() {
|
|
|
15
15
|
}
|
|
16
16
|
// Regular stringify
|
|
17
17
|
function stringify(obj, replacer, spacer, options) {
|
|
18
|
-
if (typeof options === "undefined") {
|
|
19
|
-
options = defaultOptions();
|
|
20
|
-
}
|
|
21
|
-
decirc(obj, "", 0, [], undefined, 0, options);
|
|
22
|
-
var res;
|
|
23
18
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return JSON.stringify(obj, replacer, spacer);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
// Fall back to more complex stringify if circular reference
|
|
23
|
+
if (!e.message?.includes("Converting circular structure to JSON")) {
|
|
24
|
+
return "[Unserializable]";
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (typeof options === "undefined") {
|
|
27
|
+
options = defaultOptions();
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
while (arr.length !== 0) {
|
|
36
|
-
var part = arr.pop();
|
|
37
|
-
if (part.length === 4) {
|
|
38
|
-
Object.defineProperty(part[0], part[1], part[3]);
|
|
29
|
+
decirc(obj, "", 0, [], undefined, 0, options);
|
|
30
|
+
var res;
|
|
31
|
+
try {
|
|
32
|
+
if (replacerStack.length === 0) {
|
|
33
|
+
res = JSON.stringify(obj, replacer, spacer);
|
|
39
34
|
}
|
|
40
35
|
else {
|
|
41
|
-
|
|
36
|
+
res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (_) {
|
|
40
|
+
return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
while (arr.length !== 0) {
|
|
44
|
+
var part = arr.pop();
|
|
45
|
+
if (part.length === 4) {
|
|
46
|
+
Object.defineProperty(part[0], part[1], part[3]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
part[0][part[1]] = part[2];
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
}
|
|
53
|
+
return res;
|
|
44
54
|
}
|
|
45
|
-
return res;
|
|
46
55
|
}
|
|
47
56
|
exports.stringify = stringify;
|
|
48
57
|
function setReplace(replace, val, k, parent) {
|
|
@@ -12,34 +12,43 @@ function defaultOptions() {
|
|
|
12
12
|
}
|
|
13
13
|
// Regular stringify
|
|
14
14
|
export function stringify(obj, replacer, spacer, options) {
|
|
15
|
-
if (typeof options === "undefined") {
|
|
16
|
-
options = defaultOptions();
|
|
17
|
-
}
|
|
18
|
-
decirc(obj, "", 0, [], undefined, 0, options);
|
|
19
|
-
var res;
|
|
20
15
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
return JSON.stringify(obj, replacer, spacer);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
// Fall back to more complex stringify if circular reference
|
|
20
|
+
if (!e.message?.includes("Converting circular structure to JSON")) {
|
|
21
|
+
return "[Unserializable]";
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (typeof options === "undefined") {
|
|
24
|
+
options = defaultOptions();
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
while (arr.length !== 0) {
|
|
33
|
-
var part = arr.pop();
|
|
34
|
-
if (part.length === 4) {
|
|
35
|
-
Object.defineProperty(part[0], part[1], part[3]);
|
|
26
|
+
decirc(obj, "", 0, [], undefined, 0, options);
|
|
27
|
+
var res;
|
|
28
|
+
try {
|
|
29
|
+
if (replacerStack.length === 0) {
|
|
30
|
+
res = JSON.stringify(obj, replacer, spacer);
|
|
36
31
|
}
|
|
37
32
|
else {
|
|
38
|
-
|
|
33
|
+
res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (_) {
|
|
37
|
+
return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
while (arr.length !== 0) {
|
|
41
|
+
var part = arr.pop();
|
|
42
|
+
if (part.length === 4) {
|
|
43
|
+
Object.defineProperty(part[0], part[1], part[3]);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
part[0][part[1]] = part[2];
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
49
|
}
|
|
50
|
+
return res;
|
|
41
51
|
}
|
|
42
|
-
return res;
|
|
43
52
|
}
|
|
44
53
|
function setReplace(replace, val, k, parent) {
|
|
45
54
|
var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|