langsmith 0.1.54 → 0.1.55-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 CHANGED
@@ -33,8 +33,8 @@ const _uuid_js_1 = require("./utils/_uuid.cjs");
33
33
  const warn_js_1 = require("./utils/warn.cjs");
34
34
  const prompts_js_1 = require("./utils/prompts.cjs");
35
35
  const error_js_1 = require("./utils/error.cjs");
36
- const serde_js_1 = require("./utils/serde.cjs");
37
36
  const fetch_js_1 = require("./singletons/fetch.cjs");
37
+ const index_js_2 = require("./utils/fast-safe-stringify/index.cjs");
38
38
  async function mergeRuntimeEnvIntoRunCreates(runs) {
39
39
  const runtimeEnv = await (0, env_js_1.getRuntimeEnvironment)();
40
40
  const envVars = (0, env_js_1.getLangChainEnvVarsMetadata)();
@@ -570,7 +570,7 @@ class Client {
570
570
  const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs`, {
571
571
  method: "POST",
572
572
  headers,
573
- body: (0, serde_js_1.stringifyForTracing)(mergedRunCreateParams[0]),
573
+ body: (0, index_js_2.stringify)(mergedRunCreateParams[0]),
574
574
  signal: AbortSignal.timeout(this.timeout_ms),
575
575
  ...this.fetchOptions,
576
576
  });
@@ -644,10 +644,10 @@ class Client {
644
644
  const batchItems = rawBatch[key].reverse();
645
645
  let batchItem = batchItems.pop();
646
646
  while (batchItem !== undefined) {
647
- const stringifiedBatchItem = (0, serde_js_1.stringifyForTracing)(batchItem);
647
+ const stringifiedBatchItem = (0, index_js_2.stringify)(batchItem);
648
648
  if (currentBatchSizeBytes > 0 &&
649
649
  currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
650
- await this._postBatchIngestRuns((0, serde_js_1.stringifyForTracing)(batchChunks));
650
+ await this._postBatchIngestRuns((0, index_js_2.stringify)(batchChunks));
651
651
  currentBatchSizeBytes = 0;
652
652
  batchChunks.post = [];
653
653
  batchChunks.patch = [];
@@ -658,7 +658,7 @@ class Client {
658
658
  }
659
659
  }
660
660
  if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
661
- await this._postBatchIngestRuns((0, serde_js_1.stringifyForTracing)(batchChunks));
661
+ await this._postBatchIngestRuns((0, index_js_2.stringify)(batchChunks));
662
662
  }
663
663
  }
664
664
  async _postBatchIngestRuns(body) {
@@ -707,7 +707,7 @@ class Client {
707
707
  const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}`, {
708
708
  method: "PATCH",
709
709
  headers,
710
- body: (0, serde_js_1.stringifyForTracing)(run),
710
+ body: (0, index_js_2.stringify)(run),
711
711
  signal: AbortSignal.timeout(this.timeout_ms),
712
712
  ...this.fetchOptions,
713
713
  });
package/dist/client.js CHANGED
@@ -7,8 +7,8 @@ import { assertUuid } from "./utils/_uuid.js";
7
7
  import { warnOnce } from "./utils/warn.js";
8
8
  import { isVersionGreaterOrEqual, parsePromptIdentifier, } from "./utils/prompts.js";
9
9
  import { raiseForStatus } from "./utils/error.js";
10
- import { stringifyForTracing } from "./utils/serde.js";
11
10
  import { _getFetchImplementation } from "./singletons/fetch.js";
11
+ import { stringify as stringifyForTracing } from "./utils/fast-safe-stringify/index.js";
12
12
  async function mergeRuntimeEnvIntoRunCreates(runs) {
13
13
  const runtimeEnv = await getRuntimeEnvironment();
14
14
  const envVars = getLangChainEnvVarsMetadata();
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.54";
11
+ exports.__version__ = "0.1.55-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.1.54";
5
+ export declare const __version__ = "0.1.55-rc.1";
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ export { Client } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  // Update using yarn bump-version
5
- export const __version__ = "0.1.54";
5
+ export const __version__ = "0.1.55-rc.1";
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringify = void 0;
4
+ /* eslint-disable */
5
+ // @ts-nocheck
6
+ var LIMIT_REPLACE_NODE = "[...]";
7
+ var CIRCULAR_REPLACE_NODE = { result: "[Circular]" };
8
+ var arr = [];
9
+ var replacerStack = [];
10
+ function defaultOptions() {
11
+ return {
12
+ depthLimit: Number.MAX_SAFE_INTEGER,
13
+ edgesLimit: Number.MAX_SAFE_INTEGER,
14
+ };
15
+ }
16
+ // Regular stringify
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
+ try {
24
+ if (replacerStack.length === 0) {
25
+ res = JSON.stringify(obj, replacer, spacer);
26
+ }
27
+ else {
28
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
29
+ }
30
+ }
31
+ catch (_) {
32
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
33
+ }
34
+ finally {
35
+ while (arr.length !== 0) {
36
+ var part = arr.pop();
37
+ if (part.length === 4) {
38
+ Object.defineProperty(part[0], part[1], part[3]);
39
+ }
40
+ else {
41
+ part[0][part[1]] = part[2];
42
+ }
43
+ }
44
+ }
45
+ return res;
46
+ }
47
+ exports.stringify = stringify;
48
+ function setReplace(replace, val, k, parent) {
49
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
50
+ if (propertyDescriptor.get !== undefined) {
51
+ if (propertyDescriptor.configurable) {
52
+ Object.defineProperty(parent, k, { value: replace });
53
+ arr.push([parent, k, val, propertyDescriptor]);
54
+ }
55
+ else {
56
+ replacerStack.push([val, k, replace]);
57
+ }
58
+ }
59
+ else {
60
+ parent[k] = replace;
61
+ arr.push([parent, k, val]);
62
+ }
63
+ }
64
+ function decirc(val, k, edgeIndex, stack, parent, depth, options) {
65
+ depth += 1;
66
+ var i;
67
+ if (typeof val === "object" && val !== null) {
68
+ for (i = 0; i < stack.length; i++) {
69
+ if (stack[i] === val) {
70
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
71
+ return;
72
+ }
73
+ }
74
+ if (typeof options.depthLimit !== "undefined" &&
75
+ depth > options.depthLimit) {
76
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
77
+ return;
78
+ }
79
+ if (typeof options.edgesLimit !== "undefined" &&
80
+ edgeIndex + 1 > options.edgesLimit) {
81
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
82
+ return;
83
+ }
84
+ stack.push(val);
85
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
86
+ if (Array.isArray(val)) {
87
+ for (i = 0; i < val.length; i++) {
88
+ decirc(val[i], i, i, stack, val, depth, options);
89
+ }
90
+ }
91
+ else {
92
+ var keys = Object.keys(val);
93
+ for (i = 0; i < keys.length; i++) {
94
+ var key = keys[i];
95
+ decirc(val[key], key, i, stack, val, depth, options);
96
+ }
97
+ }
98
+ stack.pop();
99
+ }
100
+ }
101
+ // Stable-stringify
102
+ function compareFunction(a, b) {
103
+ if (a < b) {
104
+ return -1;
105
+ }
106
+ if (a > b) {
107
+ return 1;
108
+ }
109
+ return 0;
110
+ }
111
+ function deterministicStringify(obj, replacer, spacer, options) {
112
+ if (typeof options === "undefined") {
113
+ options = defaultOptions();
114
+ }
115
+ var tmp = deterministicDecirc(obj, "", 0, [], undefined, 0, options) || obj;
116
+ var res;
117
+ try {
118
+ if (replacerStack.length === 0) {
119
+ res = JSON.stringify(tmp, replacer, spacer);
120
+ }
121
+ else {
122
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
123
+ }
124
+ }
125
+ catch (_) {
126
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
127
+ }
128
+ finally {
129
+ // Ensure that we restore the object as it was.
130
+ while (arr.length !== 0) {
131
+ var part = arr.pop();
132
+ if (part.length === 4) {
133
+ Object.defineProperty(part[0], part[1], part[3]);
134
+ }
135
+ else {
136
+ part[0][part[1]] = part[2];
137
+ }
138
+ }
139
+ }
140
+ return res;
141
+ }
142
+ function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
143
+ depth += 1;
144
+ var i;
145
+ if (typeof val === "object" && val !== null) {
146
+ for (i = 0; i < stack.length; i++) {
147
+ if (stack[i] === val) {
148
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
149
+ return;
150
+ }
151
+ }
152
+ try {
153
+ if (typeof val.toJSON === "function") {
154
+ return;
155
+ }
156
+ }
157
+ catch (_) {
158
+ return;
159
+ }
160
+ if (typeof options.depthLimit !== "undefined" &&
161
+ depth > options.depthLimit) {
162
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
163
+ return;
164
+ }
165
+ if (typeof options.edgesLimit !== "undefined" &&
166
+ edgeIndex + 1 > options.edgesLimit) {
167
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
168
+ return;
169
+ }
170
+ stack.push(val);
171
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
172
+ if (Array.isArray(val)) {
173
+ for (i = 0; i < val.length; i++) {
174
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
175
+ }
176
+ }
177
+ else {
178
+ // Create a temporary object in the required way
179
+ var tmp = {};
180
+ var keys = Object.keys(val).sort(compareFunction);
181
+ for (i = 0; i < keys.length; i++) {
182
+ var key = keys[i];
183
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
184
+ tmp[key] = val[key];
185
+ }
186
+ if (typeof parent !== "undefined") {
187
+ arr.push([parent, k, val]);
188
+ parent[k] = tmp;
189
+ }
190
+ else {
191
+ return tmp;
192
+ }
193
+ }
194
+ stack.pop();
195
+ }
196
+ }
197
+ // wraps replacer function to handle values we couldn't replace
198
+ // and mark them as replaced value
199
+ function replaceGetterValues(replacer) {
200
+ replacer =
201
+ typeof replacer !== "undefined"
202
+ ? replacer
203
+ : function (k, v) {
204
+ return v;
205
+ };
206
+ return function (key, val) {
207
+ if (replacerStack.length > 0) {
208
+ for (var i = 0; i < replacerStack.length; i++) {
209
+ var part = replacerStack[i];
210
+ if (part[1] === key && part[0] === val) {
211
+ val = part[2];
212
+ replacerStack.splice(i, 1);
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ return replacer.call(this, key, val);
218
+ };
219
+ }
@@ -0,0 +1 @@
1
+ export declare function stringify(obj: any, replacer?: any, spacer?: any, options?: any): string;
@@ -0,0 +1,215 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ var LIMIT_REPLACE_NODE = "[...]";
4
+ var CIRCULAR_REPLACE_NODE = { result: "[Circular]" };
5
+ var arr = [];
6
+ var replacerStack = [];
7
+ function defaultOptions() {
8
+ return {
9
+ depthLimit: Number.MAX_SAFE_INTEGER,
10
+ edgesLimit: Number.MAX_SAFE_INTEGER,
11
+ };
12
+ }
13
+ // Regular stringify
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
+ try {
21
+ if (replacerStack.length === 0) {
22
+ res = JSON.stringify(obj, replacer, spacer);
23
+ }
24
+ else {
25
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
26
+ }
27
+ }
28
+ catch (_) {
29
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
30
+ }
31
+ finally {
32
+ while (arr.length !== 0) {
33
+ var part = arr.pop();
34
+ if (part.length === 4) {
35
+ Object.defineProperty(part[0], part[1], part[3]);
36
+ }
37
+ else {
38
+ part[0][part[1]] = part[2];
39
+ }
40
+ }
41
+ }
42
+ return res;
43
+ }
44
+ function setReplace(replace, val, k, parent) {
45
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
46
+ if (propertyDescriptor.get !== undefined) {
47
+ if (propertyDescriptor.configurable) {
48
+ Object.defineProperty(parent, k, { value: replace });
49
+ arr.push([parent, k, val, propertyDescriptor]);
50
+ }
51
+ else {
52
+ replacerStack.push([val, k, replace]);
53
+ }
54
+ }
55
+ else {
56
+ parent[k] = replace;
57
+ arr.push([parent, k, val]);
58
+ }
59
+ }
60
+ function decirc(val, k, edgeIndex, stack, parent, depth, options) {
61
+ depth += 1;
62
+ var i;
63
+ if (typeof val === "object" && val !== null) {
64
+ for (i = 0; i < stack.length; i++) {
65
+ if (stack[i] === val) {
66
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
67
+ return;
68
+ }
69
+ }
70
+ if (typeof options.depthLimit !== "undefined" &&
71
+ depth > options.depthLimit) {
72
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
73
+ return;
74
+ }
75
+ if (typeof options.edgesLimit !== "undefined" &&
76
+ edgeIndex + 1 > options.edgesLimit) {
77
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
78
+ return;
79
+ }
80
+ stack.push(val);
81
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
82
+ if (Array.isArray(val)) {
83
+ for (i = 0; i < val.length; i++) {
84
+ decirc(val[i], i, i, stack, val, depth, options);
85
+ }
86
+ }
87
+ else {
88
+ var keys = Object.keys(val);
89
+ for (i = 0; i < keys.length; i++) {
90
+ var key = keys[i];
91
+ decirc(val[key], key, i, stack, val, depth, options);
92
+ }
93
+ }
94
+ stack.pop();
95
+ }
96
+ }
97
+ // Stable-stringify
98
+ function compareFunction(a, b) {
99
+ if (a < b) {
100
+ return -1;
101
+ }
102
+ if (a > b) {
103
+ return 1;
104
+ }
105
+ return 0;
106
+ }
107
+ function deterministicStringify(obj, replacer, spacer, options) {
108
+ if (typeof options === "undefined") {
109
+ options = defaultOptions();
110
+ }
111
+ var tmp = deterministicDecirc(obj, "", 0, [], undefined, 0, options) || obj;
112
+ var res;
113
+ try {
114
+ if (replacerStack.length === 0) {
115
+ res = JSON.stringify(tmp, replacer, spacer);
116
+ }
117
+ else {
118
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
119
+ }
120
+ }
121
+ catch (_) {
122
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
123
+ }
124
+ finally {
125
+ // Ensure that we restore the object as it was.
126
+ while (arr.length !== 0) {
127
+ var part = arr.pop();
128
+ if (part.length === 4) {
129
+ Object.defineProperty(part[0], part[1], part[3]);
130
+ }
131
+ else {
132
+ part[0][part[1]] = part[2];
133
+ }
134
+ }
135
+ }
136
+ return res;
137
+ }
138
+ function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
139
+ depth += 1;
140
+ var i;
141
+ if (typeof val === "object" && val !== null) {
142
+ for (i = 0; i < stack.length; i++) {
143
+ if (stack[i] === val) {
144
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
145
+ return;
146
+ }
147
+ }
148
+ try {
149
+ if (typeof val.toJSON === "function") {
150
+ return;
151
+ }
152
+ }
153
+ catch (_) {
154
+ return;
155
+ }
156
+ if (typeof options.depthLimit !== "undefined" &&
157
+ depth > options.depthLimit) {
158
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
159
+ return;
160
+ }
161
+ if (typeof options.edgesLimit !== "undefined" &&
162
+ edgeIndex + 1 > options.edgesLimit) {
163
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
164
+ return;
165
+ }
166
+ stack.push(val);
167
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
168
+ if (Array.isArray(val)) {
169
+ for (i = 0; i < val.length; i++) {
170
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
171
+ }
172
+ }
173
+ else {
174
+ // Create a temporary object in the required way
175
+ var tmp = {};
176
+ var keys = Object.keys(val).sort(compareFunction);
177
+ for (i = 0; i < keys.length; i++) {
178
+ var key = keys[i];
179
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
180
+ tmp[key] = val[key];
181
+ }
182
+ if (typeof parent !== "undefined") {
183
+ arr.push([parent, k, val]);
184
+ parent[k] = tmp;
185
+ }
186
+ else {
187
+ return tmp;
188
+ }
189
+ }
190
+ stack.pop();
191
+ }
192
+ }
193
+ // wraps replacer function to handle values we couldn't replace
194
+ // and mark them as replaced value
195
+ function replaceGetterValues(replacer) {
196
+ replacer =
197
+ typeof replacer !== "undefined"
198
+ ? replacer
199
+ : function (k, v) {
200
+ return v;
201
+ };
202
+ return function (key, val) {
203
+ if (replacerStack.length > 0) {
204
+ for (var i = 0; i < replacerStack.length; i++) {
205
+ var part = replacerStack[i];
206
+ if (part[1] === key && part[0] === val) {
207
+ val = part[2];
208
+ replacerStack.splice(i, 1);
209
+ break;
210
+ }
211
+ }
212
+ }
213
+ return replacer.call(this, key, val);
214
+ };
215
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.54",
3
+ "version": "0.1.55-rc.1",
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": [
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringifyForTracing = exports.CIRCULAR_VALUE_REPLACEMENT_STRING = void 0;
4
- exports.CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
5
- /**
6
- * JSON.stringify version that handles circular references by replacing them
7
- * with an object marking them as such ({ result: "[Circular]" }).
8
- */
9
- const stringifyForTracing = (value) => {
10
- const seen = new WeakSet();
11
- const serializer = (_, value) => {
12
- if (typeof value === "object" && value !== null) {
13
- if (seen.has(value)) {
14
- return {
15
- result: exports.CIRCULAR_VALUE_REPLACEMENT_STRING,
16
- };
17
- }
18
- seen.add(value);
19
- }
20
- return value;
21
- };
22
- return JSON.stringify(value, serializer);
23
- };
24
- exports.stringifyForTracing = stringifyForTracing;
@@ -1,6 +0,0 @@
1
- export declare const CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
2
- /**
3
- * JSON.stringify version that handles circular references by replacing them
4
- * with an object marking them as such ({ result: "[Circular]" }).
5
- */
6
- export declare const stringifyForTracing: (value: any) => string;
@@ -1,20 +0,0 @@
1
- export const CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
2
- /**
3
- * JSON.stringify version that handles circular references by replacing them
4
- * with an object marking them as such ({ result: "[Circular]" }).
5
- */
6
- export const stringifyForTracing = (value) => {
7
- const seen = new WeakSet();
8
- const serializer = (_, value) => {
9
- if (typeof value === "object" && value !== null) {
10
- if (seen.has(value)) {
11
- return {
12
- result: CIRCULAR_VALUE_REPLACEMENT_STRING,
13
- };
14
- }
15
- seen.add(value);
16
- }
17
- return value;
18
- };
19
- return JSON.stringify(value, serializer);
20
- };