langsmith 0.3.4 → 0.3.5
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 +13 -13
- package/dist/client.js +14 -14
- package/dist/evaluation/_runner.cjs +0 -1
- package/dist/evaluation/_runner.js +0 -1
- 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 +14 -9
- package/dist/utils/fast-safe-stringify/index.d.ts +1 -1
- package/dist/utils/fast-safe-stringify/index.js +12 -7
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -127,7 +127,7 @@ class AutoBatchQueue {
|
|
|
127
127
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
128
128
|
itemPromiseResolve = resolve;
|
|
129
129
|
});
|
|
130
|
-
const size = (0, index_js_2.
|
|
130
|
+
const size = (0, index_js_2.serialize)(item.item).length;
|
|
131
131
|
this.items.push({
|
|
132
132
|
action: item.action,
|
|
133
133
|
payload: item.item,
|
|
@@ -683,7 +683,7 @@ class Client {
|
|
|
683
683
|
const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs`, {
|
|
684
684
|
method: "POST",
|
|
685
685
|
headers,
|
|
686
|
-
body: (0, index_js_2.
|
|
686
|
+
body: (0, index_js_2.serialize)(mergedRunCreateParam),
|
|
687
687
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
688
688
|
...this.fetchOptions,
|
|
689
689
|
});
|
|
@@ -743,7 +743,7 @@ class Client {
|
|
|
743
743
|
}
|
|
744
744
|
}
|
|
745
745
|
if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
|
|
746
|
-
await this._postBatchIngestRuns((0, index_js_2.
|
|
746
|
+
await this._postBatchIngestRuns((0, index_js_2.serialize)(batchChunks));
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
async _postBatchIngestRuns(body) {
|
|
@@ -838,7 +838,7 @@ class Client {
|
|
|
838
838
|
const { inputs, outputs, events, attachments, ...payload } = originalPayload;
|
|
839
839
|
const fields = { inputs, outputs, events };
|
|
840
840
|
// encode the main run payload
|
|
841
|
-
const stringifiedPayload = (0, index_js_2.
|
|
841
|
+
const stringifiedPayload = (0, index_js_2.serialize)(payload);
|
|
842
842
|
accumulatedParts.push({
|
|
843
843
|
name: `${method}.${payload.id}`,
|
|
844
844
|
payload: new Blob([stringifiedPayload], {
|
|
@@ -850,7 +850,7 @@ class Client {
|
|
|
850
850
|
if (value === undefined) {
|
|
851
851
|
continue;
|
|
852
852
|
}
|
|
853
|
-
const stringifiedValue = (0, index_js_2.
|
|
853
|
+
const stringifiedValue = (0, index_js_2.serialize)(value);
|
|
854
854
|
accumulatedParts.push({
|
|
855
855
|
name: `${method}.${payload.id}.${key}`,
|
|
856
856
|
payload: new Blob([stringifiedValue], {
|
|
@@ -966,7 +966,7 @@ class Client {
|
|
|
966
966
|
const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}`, {
|
|
967
967
|
method: "PATCH",
|
|
968
968
|
headers,
|
|
969
|
-
body: (0, index_js_2.
|
|
969
|
+
body: (0, index_js_2.serialize)(run),
|
|
970
970
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
971
971
|
...this.fetchOptions,
|
|
972
972
|
});
|
|
@@ -2853,14 +2853,14 @@ class Client {
|
|
|
2853
2853
|
...(example.split && { split: example.split }),
|
|
2854
2854
|
};
|
|
2855
2855
|
// Add main example data
|
|
2856
|
-
const stringifiedExample = (0, index_js_2.
|
|
2856
|
+
const stringifiedExample = (0, index_js_2.serialize)(exampleBody);
|
|
2857
2857
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
2858
2858
|
type: "application/json",
|
|
2859
2859
|
});
|
|
2860
2860
|
formData.append(exampleId, exampleBlob);
|
|
2861
2861
|
// Add inputs
|
|
2862
2862
|
if (example.inputs) {
|
|
2863
|
-
const stringifiedInputs = (0, index_js_2.
|
|
2863
|
+
const stringifiedInputs = (0, index_js_2.serialize)(example.inputs);
|
|
2864
2864
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
2865
2865
|
type: "application/json",
|
|
2866
2866
|
});
|
|
@@ -2868,7 +2868,7 @@ class Client {
|
|
|
2868
2868
|
}
|
|
2869
2869
|
// Add outputs if present
|
|
2870
2870
|
if (example.outputs) {
|
|
2871
|
-
const stringifiedOutputs = (0, index_js_2.
|
|
2871
|
+
const stringifiedOutputs = (0, index_js_2.serialize)(example.outputs);
|
|
2872
2872
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
2873
2873
|
type: "application/json",
|
|
2874
2874
|
});
|
|
@@ -2893,7 +2893,7 @@ class Client {
|
|
|
2893
2893
|
}
|
|
2894
2894
|
}
|
|
2895
2895
|
if (example.attachments_operations) {
|
|
2896
|
-
const stringifiedAttachmentsOperations = (0, index_js_2.
|
|
2896
|
+
const stringifiedAttachmentsOperations = (0, index_js_2.serialize)(example.attachments_operations);
|
|
2897
2897
|
const attachmentsOperationsBlob = new Blob([stringifiedAttachmentsOperations], {
|
|
2898
2898
|
type: "application/json",
|
|
2899
2899
|
});
|
|
@@ -2927,20 +2927,20 @@ class Client {
|
|
|
2927
2927
|
...(example.split && { split: example.split }),
|
|
2928
2928
|
};
|
|
2929
2929
|
// Add main example data
|
|
2930
|
-
const stringifiedExample = (0, index_js_2.
|
|
2930
|
+
const stringifiedExample = (0, index_js_2.serialize)(exampleBody);
|
|
2931
2931
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
2932
2932
|
type: "application/json",
|
|
2933
2933
|
});
|
|
2934
2934
|
formData.append(exampleId, exampleBlob);
|
|
2935
2935
|
// Add inputs
|
|
2936
|
-
const stringifiedInputs = (0, index_js_2.
|
|
2936
|
+
const stringifiedInputs = (0, index_js_2.serialize)(example.inputs);
|
|
2937
2937
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
2938
2938
|
type: "application/json",
|
|
2939
2939
|
});
|
|
2940
2940
|
formData.append(`${exampleId}.inputs`, inputsBlob);
|
|
2941
2941
|
// Add outputs if present
|
|
2942
2942
|
if (example.outputs) {
|
|
2943
|
-
const stringifiedOutputs = (0, index_js_2.
|
|
2943
|
+
const stringifiedOutputs = (0, index_js_2.serialize)(example.outputs);
|
|
2944
2944
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
2945
2945
|
type: "application/json",
|
|
2946
2946
|
});
|
package/dist/client.js
CHANGED
|
@@ -8,7 +8,7 @@ import { warnOnce } from "./utils/warn.js";
|
|
|
8
8
|
import { parsePromptIdentifier } from "./utils/prompts.js";
|
|
9
9
|
import { raiseForStatus } from "./utils/error.js";
|
|
10
10
|
import { _getFetchImplementation } from "./singletons/fetch.js";
|
|
11
|
-
import {
|
|
11
|
+
import { serialize as serializePayloadForTracing } from "./utils/fast-safe-stringify/index.js";
|
|
12
12
|
export function mergeRuntimeEnvIntoRunCreate(run) {
|
|
13
13
|
const runtimeEnv = getRuntimeEnvironment();
|
|
14
14
|
const envVars = getLangChainEnvVarsMetadata();
|
|
@@ -100,7 +100,7 @@ export class AutoBatchQueue {
|
|
|
100
100
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
101
101
|
itemPromiseResolve = resolve;
|
|
102
102
|
});
|
|
103
|
-
const size =
|
|
103
|
+
const size = serializePayloadForTracing(item.item).length;
|
|
104
104
|
this.items.push({
|
|
105
105
|
action: item.action,
|
|
106
106
|
payload: item.item,
|
|
@@ -655,7 +655,7 @@ export class Client {
|
|
|
655
655
|
const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs`, {
|
|
656
656
|
method: "POST",
|
|
657
657
|
headers,
|
|
658
|
-
body:
|
|
658
|
+
body: serializePayloadForTracing(mergedRunCreateParam),
|
|
659
659
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
660
660
|
...this.fetchOptions,
|
|
661
661
|
});
|
|
@@ -715,7 +715,7 @@ export class Client {
|
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
717
|
if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
|
|
718
|
-
await this._postBatchIngestRuns(
|
|
718
|
+
await this._postBatchIngestRuns(serializePayloadForTracing(batchChunks));
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
async _postBatchIngestRuns(body) {
|
|
@@ -810,7 +810,7 @@ export class Client {
|
|
|
810
810
|
const { inputs, outputs, events, attachments, ...payload } = originalPayload;
|
|
811
811
|
const fields = { inputs, outputs, events };
|
|
812
812
|
// encode the main run payload
|
|
813
|
-
const stringifiedPayload =
|
|
813
|
+
const stringifiedPayload = serializePayloadForTracing(payload);
|
|
814
814
|
accumulatedParts.push({
|
|
815
815
|
name: `${method}.${payload.id}`,
|
|
816
816
|
payload: new Blob([stringifiedPayload], {
|
|
@@ -822,7 +822,7 @@ export class Client {
|
|
|
822
822
|
if (value === undefined) {
|
|
823
823
|
continue;
|
|
824
824
|
}
|
|
825
|
-
const stringifiedValue =
|
|
825
|
+
const stringifiedValue = serializePayloadForTracing(value);
|
|
826
826
|
accumulatedParts.push({
|
|
827
827
|
name: `${method}.${payload.id}.${key}`,
|
|
828
828
|
payload: new Blob([stringifiedValue], {
|
|
@@ -938,7 +938,7 @@ export class Client {
|
|
|
938
938
|
const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/${runId}`, {
|
|
939
939
|
method: "PATCH",
|
|
940
940
|
headers,
|
|
941
|
-
body:
|
|
941
|
+
body: serializePayloadForTracing(run),
|
|
942
942
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
943
943
|
...this.fetchOptions,
|
|
944
944
|
});
|
|
@@ -2825,14 +2825,14 @@ export class Client {
|
|
|
2825
2825
|
...(example.split && { split: example.split }),
|
|
2826
2826
|
};
|
|
2827
2827
|
// Add main example data
|
|
2828
|
-
const stringifiedExample =
|
|
2828
|
+
const stringifiedExample = serializePayloadForTracing(exampleBody);
|
|
2829
2829
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
2830
2830
|
type: "application/json",
|
|
2831
2831
|
});
|
|
2832
2832
|
formData.append(exampleId, exampleBlob);
|
|
2833
2833
|
// Add inputs
|
|
2834
2834
|
if (example.inputs) {
|
|
2835
|
-
const stringifiedInputs =
|
|
2835
|
+
const stringifiedInputs = serializePayloadForTracing(example.inputs);
|
|
2836
2836
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
2837
2837
|
type: "application/json",
|
|
2838
2838
|
});
|
|
@@ -2840,7 +2840,7 @@ export class Client {
|
|
|
2840
2840
|
}
|
|
2841
2841
|
// Add outputs if present
|
|
2842
2842
|
if (example.outputs) {
|
|
2843
|
-
const stringifiedOutputs =
|
|
2843
|
+
const stringifiedOutputs = serializePayloadForTracing(example.outputs);
|
|
2844
2844
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
2845
2845
|
type: "application/json",
|
|
2846
2846
|
});
|
|
@@ -2865,7 +2865,7 @@ export class Client {
|
|
|
2865
2865
|
}
|
|
2866
2866
|
}
|
|
2867
2867
|
if (example.attachments_operations) {
|
|
2868
|
-
const stringifiedAttachmentsOperations =
|
|
2868
|
+
const stringifiedAttachmentsOperations = serializePayloadForTracing(example.attachments_operations);
|
|
2869
2869
|
const attachmentsOperationsBlob = new Blob([stringifiedAttachmentsOperations], {
|
|
2870
2870
|
type: "application/json",
|
|
2871
2871
|
});
|
|
@@ -2899,20 +2899,20 @@ export class Client {
|
|
|
2899
2899
|
...(example.split && { split: example.split }),
|
|
2900
2900
|
};
|
|
2901
2901
|
// Add main example data
|
|
2902
|
-
const stringifiedExample =
|
|
2902
|
+
const stringifiedExample = serializePayloadForTracing(exampleBody);
|
|
2903
2903
|
const exampleBlob = new Blob([stringifiedExample], {
|
|
2904
2904
|
type: "application/json",
|
|
2905
2905
|
});
|
|
2906
2906
|
formData.append(exampleId, exampleBlob);
|
|
2907
2907
|
// Add inputs
|
|
2908
|
-
const stringifiedInputs =
|
|
2908
|
+
const stringifiedInputs = serializePayloadForTracing(example.inputs);
|
|
2909
2909
|
const inputsBlob = new Blob([stringifiedInputs], {
|
|
2910
2910
|
type: "application/json",
|
|
2911
2911
|
});
|
|
2912
2912
|
formData.append(`${exampleId}.inputs`, inputsBlob);
|
|
2913
2913
|
// Add outputs if present
|
|
2914
2914
|
if (example.outputs) {
|
|
2915
|
-
const stringifiedOutputs =
|
|
2915
|
+
const stringifiedOutputs = serializePayloadForTracing(example.outputs);
|
|
2916
2916
|
const outputsBlob = new Blob([stringifiedOutputs], {
|
|
2917
2917
|
type: "application/json",
|
|
2918
2918
|
});
|
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.3.
|
|
11
|
+
exports.__version__ = "0.3.5";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Client, type ClientConfig, type LangSmithTracingClientInterface, } from
|
|
|
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.3.
|
|
5
|
+
export declare const __version__ = "0.3.5";
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.serialize = void 0;
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
// @ts-nocheck
|
|
6
6
|
var LIMIT_REPLACE_NODE = "[...]";
|
|
7
7
|
var CIRCULAR_REPLACE_NODE = { result: "[Circular]" };
|
|
8
8
|
var arr = [];
|
|
9
9
|
var replacerStack = [];
|
|
10
|
+
const encoder = new TextEncoder();
|
|
10
11
|
function defaultOptions() {
|
|
11
12
|
return {
|
|
12
13
|
depthLimit: Number.MAX_SAFE_INTEGER,
|
|
13
14
|
edgesLimit: Number.MAX_SAFE_INTEGER,
|
|
14
15
|
};
|
|
15
16
|
}
|
|
17
|
+
function encodeString(str) {
|
|
18
|
+
return encoder.encode(str);
|
|
19
|
+
}
|
|
16
20
|
// Regular stringify
|
|
17
|
-
function
|
|
21
|
+
function serialize(obj, replacer, spacer, options) {
|
|
18
22
|
try {
|
|
19
|
-
|
|
23
|
+
const str = JSON.stringify(obj, replacer, spacer);
|
|
24
|
+
return encodeString(str);
|
|
20
25
|
}
|
|
21
26
|
catch (e) {
|
|
22
27
|
// Fall back to more complex stringify if circular reference
|
|
23
28
|
if (!e.message?.includes("Converting circular structure to JSON")) {
|
|
24
29
|
console.warn("[WARNING]: LangSmith received unserializable value.");
|
|
25
|
-
return "[Unserializable]";
|
|
30
|
+
return encodeString("[Unserializable]");
|
|
26
31
|
}
|
|
27
32
|
console.warn("[WARNING]: LangSmith received circular JSON. This will decrease tracer performance.");
|
|
28
33
|
if (typeof options === "undefined") {
|
|
29
34
|
options = defaultOptions();
|
|
30
35
|
}
|
|
31
36
|
decirc(obj, "", 0, [], undefined, 0, options);
|
|
32
|
-
|
|
37
|
+
let res;
|
|
33
38
|
try {
|
|
34
39
|
if (replacerStack.length === 0) {
|
|
35
40
|
res = JSON.stringify(obj, replacer, spacer);
|
|
@@ -39,11 +44,11 @@ function stringify(obj, replacer, spacer, options) {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
catch (_) {
|
|
42
|
-
return
|
|
47
|
+
return encodeString("[unable to serialize, circular reference is too complex to analyze]");
|
|
43
48
|
}
|
|
44
49
|
finally {
|
|
45
50
|
while (arr.length !== 0) {
|
|
46
|
-
|
|
51
|
+
const part = arr.pop();
|
|
47
52
|
if (part.length === 4) {
|
|
48
53
|
Object.defineProperty(part[0], part[1], part[3]);
|
|
49
54
|
}
|
|
@@ -52,10 +57,10 @@ function stringify(obj, replacer, spacer, options) {
|
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
|
-
return res;
|
|
60
|
+
return encodeString(res);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
exports.
|
|
63
|
+
exports.serialize = serialize;
|
|
59
64
|
function setReplace(replace, val, k, parent) {
|
|
60
65
|
var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|
|
61
66
|
if (propertyDescriptor.get !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function serialize(obj: any, replacer?: any, spacer?: any, options?: any): Uint8Array;
|
|
@@ -4,29 +4,34 @@ var LIMIT_REPLACE_NODE = "[...]";
|
|
|
4
4
|
var CIRCULAR_REPLACE_NODE = { result: "[Circular]" };
|
|
5
5
|
var arr = [];
|
|
6
6
|
var replacerStack = [];
|
|
7
|
+
const encoder = new TextEncoder();
|
|
7
8
|
function defaultOptions() {
|
|
8
9
|
return {
|
|
9
10
|
depthLimit: Number.MAX_SAFE_INTEGER,
|
|
10
11
|
edgesLimit: Number.MAX_SAFE_INTEGER,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
function encodeString(str) {
|
|
15
|
+
return encoder.encode(str);
|
|
16
|
+
}
|
|
13
17
|
// Regular stringify
|
|
14
|
-
export function
|
|
18
|
+
export function serialize(obj, replacer, spacer, options) {
|
|
15
19
|
try {
|
|
16
|
-
|
|
20
|
+
const str = JSON.stringify(obj, replacer, spacer);
|
|
21
|
+
return encodeString(str);
|
|
17
22
|
}
|
|
18
23
|
catch (e) {
|
|
19
24
|
// Fall back to more complex stringify if circular reference
|
|
20
25
|
if (!e.message?.includes("Converting circular structure to JSON")) {
|
|
21
26
|
console.warn("[WARNING]: LangSmith received unserializable value.");
|
|
22
|
-
return "[Unserializable]";
|
|
27
|
+
return encodeString("[Unserializable]");
|
|
23
28
|
}
|
|
24
29
|
console.warn("[WARNING]: LangSmith received circular JSON. This will decrease tracer performance.");
|
|
25
30
|
if (typeof options === "undefined") {
|
|
26
31
|
options = defaultOptions();
|
|
27
32
|
}
|
|
28
33
|
decirc(obj, "", 0, [], undefined, 0, options);
|
|
29
|
-
|
|
34
|
+
let res;
|
|
30
35
|
try {
|
|
31
36
|
if (replacerStack.length === 0) {
|
|
32
37
|
res = JSON.stringify(obj, replacer, spacer);
|
|
@@ -36,11 +41,11 @@ export function stringify(obj, replacer, spacer, options) {
|
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
catch (_) {
|
|
39
|
-
return
|
|
44
|
+
return encodeString("[unable to serialize, circular reference is too complex to analyze]");
|
|
40
45
|
}
|
|
41
46
|
finally {
|
|
42
47
|
while (arr.length !== 0) {
|
|
43
|
-
|
|
48
|
+
const part = arr.pop();
|
|
44
49
|
if (part.length === 4) {
|
|
45
50
|
Object.defineProperty(part[0], part[1], part[3]);
|
|
46
51
|
}
|
|
@@ -49,7 +54,7 @@ export function stringify(obj, replacer, spacer, options) {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
return res;
|
|
57
|
+
return encodeString(res);
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
function setReplace(replace, val, k, parent) {
|