langsmith 0.3.16 → 0.3.18
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/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +18 -3
- package/dist/run_trees.js +18 -3
- package/dist/utils/jestlike/globals.d.ts +1 -0
- package/dist/utils/jestlike/index.cjs +49 -42
- package/dist/utils/jestlike/index.js +49 -42
- package/package.json +1 -1
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.18";
|
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.18";
|
package/dist/index.js
CHANGED
package/dist/run_trees.cjs
CHANGED
|
@@ -56,7 +56,7 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
|
56
56
|
* Baggage header information
|
|
57
57
|
*/
|
|
58
58
|
class Baggage {
|
|
59
|
-
constructor(metadata, tags) {
|
|
59
|
+
constructor(metadata, tags, project_name) {
|
|
60
60
|
Object.defineProperty(this, "metadata", {
|
|
61
61
|
enumerable: true,
|
|
62
62
|
configurable: true,
|
|
@@ -69,13 +69,21 @@ class Baggage {
|
|
|
69
69
|
writable: true,
|
|
70
70
|
value: void 0
|
|
71
71
|
});
|
|
72
|
+
Object.defineProperty(this, "project_name", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
72
78
|
this.metadata = metadata;
|
|
73
79
|
this.tags = tags;
|
|
80
|
+
this.project_name = project_name;
|
|
74
81
|
}
|
|
75
82
|
static fromHeader(value) {
|
|
76
83
|
const items = value.split(",");
|
|
77
84
|
let metadata = {};
|
|
78
85
|
let tags = [];
|
|
86
|
+
let project_name;
|
|
79
87
|
for (const item of items) {
|
|
80
88
|
const [key, uriValue] = item.split("=");
|
|
81
89
|
const value = decodeURIComponent(uriValue);
|
|
@@ -85,8 +93,11 @@ class Baggage {
|
|
|
85
93
|
else if (key === "langsmith-tags") {
|
|
86
94
|
tags = value.split(",");
|
|
87
95
|
}
|
|
96
|
+
else if (key === "langsmith-project") {
|
|
97
|
+
project_name = value;
|
|
98
|
+
}
|
|
88
99
|
}
|
|
89
|
-
return new Baggage(metadata, tags);
|
|
100
|
+
return new Baggage(metadata, tags, project_name);
|
|
90
101
|
}
|
|
91
102
|
toHeader() {
|
|
92
103
|
const items = [];
|
|
@@ -96,6 +107,9 @@ class Baggage {
|
|
|
96
107
|
if (this.tags && this.tags.length > 0) {
|
|
97
108
|
items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
|
|
98
109
|
}
|
|
110
|
+
if (this.project_name) {
|
|
111
|
+
items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
|
|
112
|
+
}
|
|
99
113
|
return items.join(",");
|
|
100
114
|
}
|
|
101
115
|
}
|
|
@@ -542,13 +556,14 @@ class RunTree {
|
|
|
542
556
|
const baggage = Baggage.fromHeader(rawHeaders["baggage"]);
|
|
543
557
|
config.metadata = baggage.metadata;
|
|
544
558
|
config.tags = baggage.tags;
|
|
559
|
+
config.project_name = baggage.project_name;
|
|
545
560
|
}
|
|
546
561
|
return new RunTree(config);
|
|
547
562
|
}
|
|
548
563
|
toHeaders(headers) {
|
|
549
564
|
const result = {
|
|
550
565
|
"langsmith-trace": this.dotted_order,
|
|
551
|
-
baggage: new Baggage(this.extra?.metadata, this.tags).toHeader(),
|
|
566
|
+
baggage: new Baggage(this.extra?.metadata, this.tags, this.project_name).toHeader(),
|
|
552
567
|
};
|
|
553
568
|
if (headers) {
|
|
554
569
|
for (const [key, value] of Object.entries(result)) {
|
package/dist/run_trees.js
CHANGED
|
@@ -17,7 +17,7 @@ export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
|
17
17
|
* Baggage header information
|
|
18
18
|
*/
|
|
19
19
|
class Baggage {
|
|
20
|
-
constructor(metadata, tags) {
|
|
20
|
+
constructor(metadata, tags, project_name) {
|
|
21
21
|
Object.defineProperty(this, "metadata", {
|
|
22
22
|
enumerable: true,
|
|
23
23
|
configurable: true,
|
|
@@ -30,13 +30,21 @@ class Baggage {
|
|
|
30
30
|
writable: true,
|
|
31
31
|
value: void 0
|
|
32
32
|
});
|
|
33
|
+
Object.defineProperty(this, "project_name", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
33
39
|
this.metadata = metadata;
|
|
34
40
|
this.tags = tags;
|
|
41
|
+
this.project_name = project_name;
|
|
35
42
|
}
|
|
36
43
|
static fromHeader(value) {
|
|
37
44
|
const items = value.split(",");
|
|
38
45
|
let metadata = {};
|
|
39
46
|
let tags = [];
|
|
47
|
+
let project_name;
|
|
40
48
|
for (const item of items) {
|
|
41
49
|
const [key, uriValue] = item.split("=");
|
|
42
50
|
const value = decodeURIComponent(uriValue);
|
|
@@ -46,8 +54,11 @@ class Baggage {
|
|
|
46
54
|
else if (key === "langsmith-tags") {
|
|
47
55
|
tags = value.split(",");
|
|
48
56
|
}
|
|
57
|
+
else if (key === "langsmith-project") {
|
|
58
|
+
project_name = value;
|
|
59
|
+
}
|
|
49
60
|
}
|
|
50
|
-
return new Baggage(metadata, tags);
|
|
61
|
+
return new Baggage(metadata, tags, project_name);
|
|
51
62
|
}
|
|
52
63
|
toHeader() {
|
|
53
64
|
const items = [];
|
|
@@ -57,6 +68,9 @@ class Baggage {
|
|
|
57
68
|
if (this.tags && this.tags.length > 0) {
|
|
58
69
|
items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
|
|
59
70
|
}
|
|
71
|
+
if (this.project_name) {
|
|
72
|
+
items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
|
|
73
|
+
}
|
|
60
74
|
return items.join(",");
|
|
61
75
|
}
|
|
62
76
|
}
|
|
@@ -503,13 +517,14 @@ export class RunTree {
|
|
|
503
517
|
const baggage = Baggage.fromHeader(rawHeaders["baggage"]);
|
|
504
518
|
config.metadata = baggage.metadata;
|
|
505
519
|
config.tags = baggage.tags;
|
|
520
|
+
config.project_name = baggage.project_name;
|
|
506
521
|
}
|
|
507
522
|
return new RunTree(config);
|
|
508
523
|
}
|
|
509
524
|
toHeaders(headers) {
|
|
510
525
|
const result = {
|
|
511
526
|
"langsmith-trace": this.dotted_order,
|
|
512
|
-
baggage: new Baggage(this.extra?.metadata, this.tags).toHeader(),
|
|
527
|
+
baggage: new Baggage(this.extra?.metadata, this.tags, this.project_name).toHeader(),
|
|
513
528
|
};
|
|
514
529
|
if (headers) {
|
|
515
530
|
for (const [key, value] of Object.entries(result)) {
|
|
@@ -18,6 +18,7 @@ export type TestWrapperAsyncLocalStorageData = {
|
|
|
18
18
|
client: Client;
|
|
19
19
|
suiteUuid: string;
|
|
20
20
|
suiteName: string;
|
|
21
|
+
testRootRunTree?: RunTree;
|
|
21
22
|
};
|
|
22
23
|
export declare const testWrapperAsyncLocalStorageInstance: AsyncLocalStorage<TestWrapperAsyncLocalStorageData>;
|
|
23
24
|
export declare function trackingEnabled(context: TestWrapperAsyncLocalStorageData): boolean;
|
|
@@ -79,7 +79,7 @@ function logFeedback(feedback, config) {
|
|
|
79
79
|
exampleId: context.currentExample.id,
|
|
80
80
|
feedback: feedback,
|
|
81
81
|
context,
|
|
82
|
-
runTree:
|
|
82
|
+
runTree: context.testRootRunTree,
|
|
83
83
|
client: context.client,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -399,52 +399,59 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
|
|
|
399
399
|
};
|
|
400
400
|
let exampleId;
|
|
401
401
|
const runTestFn = async () => {
|
|
402
|
-
|
|
402
|
+
let testContext = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
|
|
403
403
|
if (testContext === undefined) {
|
|
404
404
|
throw new Error("Could not identify test context. Please contact us for help.");
|
|
405
405
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
406
|
+
return globals_js_1.testWrapperAsyncLocalStorageInstance.run({
|
|
407
|
+
...testContext,
|
|
408
|
+
testRootRunTree: (0, globals_js_1.trackingEnabled)(testContext)
|
|
409
|
+
? (0, traceable_js_1.getCurrentRunTree)()
|
|
410
|
+
: undefined,
|
|
411
|
+
}, async () => {
|
|
412
|
+
testContext = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
|
|
413
|
+
if (testContext === undefined) {
|
|
414
|
+
throw new Error("Could not identify test context after setting test root run tree. Please contact us for help.");
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
const res = await testFn({
|
|
418
|
+
...rest,
|
|
419
|
+
inputs: testInput,
|
|
420
|
+
referenceOutputs: testOutput,
|
|
421
|
+
});
|
|
422
|
+
(0, globals_js_1._logTestFeedback)({
|
|
423
|
+
exampleId,
|
|
424
|
+
feedback: { key: "pass", score: true },
|
|
425
|
+
context: testContext,
|
|
426
|
+
runTree: testContext.testRootRunTree,
|
|
427
|
+
client: testContext.client,
|
|
428
|
+
});
|
|
429
|
+
if (res != null) {
|
|
430
|
+
if (loggedOutput !== undefined) {
|
|
431
|
+
console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
|
|
432
|
+
}
|
|
433
|
+
loggedOutput =
|
|
434
|
+
typeof res === "object"
|
|
435
|
+
? res
|
|
436
|
+
: { result: res };
|
|
424
437
|
}
|
|
425
|
-
loggedOutput
|
|
426
|
-
typeof res === "object"
|
|
427
|
-
? res
|
|
428
|
-
: { result: res };
|
|
438
|
+
return loggedOutput;
|
|
429
439
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
langsmithFriendlyError.rawJestError = rawError;
|
|
446
|
-
throw langsmithFriendlyError;
|
|
447
|
-
}
|
|
440
|
+
catch (e) {
|
|
441
|
+
(0, globals_js_1._logTestFeedback)({
|
|
442
|
+
exampleId,
|
|
443
|
+
feedback: { key: "pass", score: false },
|
|
444
|
+
context: testContext,
|
|
445
|
+
runTree: testContext.testRootRunTree,
|
|
446
|
+
client: testContext.client,
|
|
447
|
+
});
|
|
448
|
+
const rawError = e;
|
|
449
|
+
const strippedErrorMessage = e.message.replace(constants_js_1.STRIP_ANSI_REGEX, "");
|
|
450
|
+
const langsmithFriendlyError = new Error(strippedErrorMessage);
|
|
451
|
+
langsmithFriendlyError.rawJestError = rawError;
|
|
452
|
+
throw langsmithFriendlyError;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
448
455
|
};
|
|
449
456
|
try {
|
|
450
457
|
if ((0, globals_js_1.trackingEnabled)(context)) {
|
|
@@ -32,7 +32,7 @@ export function logFeedback(feedback, config) {
|
|
|
32
32
|
exampleId: context.currentExample.id,
|
|
33
33
|
feedback: feedback,
|
|
34
34
|
context,
|
|
35
|
-
runTree:
|
|
35
|
+
runTree: context.testRootRunTree,
|
|
36
36
|
client: context.client,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
@@ -352,52 +352,59 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
|
|
|
352
352
|
};
|
|
353
353
|
let exampleId;
|
|
354
354
|
const runTestFn = async () => {
|
|
355
|
-
|
|
355
|
+
let testContext = testWrapperAsyncLocalStorageInstance.getStore();
|
|
356
356
|
if (testContext === undefined) {
|
|
357
357
|
throw new Error("Could not identify test context. Please contact us for help.");
|
|
358
358
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
359
|
+
return testWrapperAsyncLocalStorageInstance.run({
|
|
360
|
+
...testContext,
|
|
361
|
+
testRootRunTree: trackingEnabled(testContext)
|
|
362
|
+
? getCurrentRunTree()
|
|
363
|
+
: undefined,
|
|
364
|
+
}, async () => {
|
|
365
|
+
testContext = testWrapperAsyncLocalStorageInstance.getStore();
|
|
366
|
+
if (testContext === undefined) {
|
|
367
|
+
throw new Error("Could not identify test context after setting test root run tree. Please contact us for help.");
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const res = await testFn({
|
|
371
|
+
...rest,
|
|
372
|
+
inputs: testInput,
|
|
373
|
+
referenceOutputs: testOutput,
|
|
374
|
+
});
|
|
375
|
+
_logTestFeedback({
|
|
376
|
+
exampleId,
|
|
377
|
+
feedback: { key: "pass", score: true },
|
|
378
|
+
context: testContext,
|
|
379
|
+
runTree: testContext.testRootRunTree,
|
|
380
|
+
client: testContext.client,
|
|
381
|
+
});
|
|
382
|
+
if (res != null) {
|
|
383
|
+
if (loggedOutput !== undefined) {
|
|
384
|
+
console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
|
|
385
|
+
}
|
|
386
|
+
loggedOutput =
|
|
387
|
+
typeof res === "object"
|
|
388
|
+
? res
|
|
389
|
+
: { result: res };
|
|
377
390
|
}
|
|
378
|
-
loggedOutput
|
|
379
|
-
typeof res === "object"
|
|
380
|
-
? res
|
|
381
|
-
: { result: res };
|
|
391
|
+
return loggedOutput;
|
|
382
392
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
langsmithFriendlyError.rawJestError = rawError;
|
|
399
|
-
throw langsmithFriendlyError;
|
|
400
|
-
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
_logTestFeedback({
|
|
395
|
+
exampleId,
|
|
396
|
+
feedback: { key: "pass", score: false },
|
|
397
|
+
context: testContext,
|
|
398
|
+
runTree: testContext.testRootRunTree,
|
|
399
|
+
client: testContext.client,
|
|
400
|
+
});
|
|
401
|
+
const rawError = e;
|
|
402
|
+
const strippedErrorMessage = e.message.replace(STRIP_ANSI_REGEX, "");
|
|
403
|
+
const langsmithFriendlyError = new Error(strippedErrorMessage);
|
|
404
|
+
langsmithFriendlyError.rawJestError = rawError;
|
|
405
|
+
throw langsmithFriendlyError;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
401
408
|
};
|
|
402
409
|
try {
|
|
403
410
|
if (trackingEnabled(context)) {
|