langsmith 0.3.49 → 0.3.51
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 +3 -3
- package/dist/client.js +3 -3
- package/dist/experimental/otel/processor.cjs +35 -4
- package/dist/experimental/otel/processor.js +37 -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 +52 -6
- package/dist/run_trees.d.ts +1 -0
- package/dist/run_trees.js +52 -7
- package/dist/utils/vercel.cjs +35 -7
- package/dist/utils/vercel.js +35 -7
- package/package.json +3 -3
package/dist/client.cjs
CHANGED
|
@@ -588,11 +588,11 @@ class Client {
|
|
|
588
588
|
if (patch) {
|
|
589
589
|
const sampled = [];
|
|
590
590
|
for (const run of runs) {
|
|
591
|
-
if (!this.filteredPostUuids.has(run.
|
|
591
|
+
if (!this.filteredPostUuids.has(run.trace_id)) {
|
|
592
592
|
sampled.push(run);
|
|
593
593
|
}
|
|
594
|
-
else {
|
|
595
|
-
this.filteredPostUuids.delete(run.
|
|
594
|
+
else if (run.id === run.trace_id) {
|
|
595
|
+
this.filteredPostUuids.delete(run.trace_id);
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
598
|
return sampled;
|
package/dist/client.js
CHANGED
|
@@ -550,11 +550,11 @@ export class Client {
|
|
|
550
550
|
if (patch) {
|
|
551
551
|
const sampled = [];
|
|
552
552
|
for (const run of runs) {
|
|
553
|
-
if (!this.filteredPostUuids.has(run.
|
|
553
|
+
if (!this.filteredPostUuids.has(run.trace_id)) {
|
|
554
554
|
sampled.push(run);
|
|
555
555
|
}
|
|
556
|
-
else {
|
|
557
|
-
this.filteredPostUuids.delete(run.
|
|
556
|
+
else if (run.id === run.trace_id) {
|
|
557
|
+
this.filteredPostUuids.delete(run.trace_id);
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
return sampled;
|
|
@@ -6,10 +6,24 @@ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
|
6
6
|
const constants_js_1 = require("./constants.cjs");
|
|
7
7
|
const utils_js_1 = require("./utils.cjs");
|
|
8
8
|
const run_trees_js_1 = require("../../run_trees.cjs");
|
|
9
|
+
const NANOSECOND_DIGITS = 9;
|
|
10
|
+
const MICROSECOND_DIGITS = 6;
|
|
9
11
|
function isTraceableSpan(span) {
|
|
10
12
|
return (span.attributes[constants_js_1.LANGSMITH_TRACEABLE] === "true" ||
|
|
11
13
|
typeof span.attributes["ai.operationId"] === "string");
|
|
12
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123Z"
|
|
17
|
+
* @param time
|
|
18
|
+
*/
|
|
19
|
+
function hrTimeToTimeStamp(time) {
|
|
20
|
+
const precision = NANOSECOND_DIGITS;
|
|
21
|
+
const tmp = `${"0".repeat(precision)}${time[1]}Z`;
|
|
22
|
+
const nanoString = tmp.substring(tmp.length - precision - 1);
|
|
23
|
+
const date = new Date(time[0] * 1000).toISOString();
|
|
24
|
+
// We only need 6 digits of precision for the dotted order
|
|
25
|
+
return `${date.replace("000Z", nanoString.slice(0, MICROSECOND_DIGITS))}Z`;
|
|
26
|
+
}
|
|
13
27
|
function getParentSpanId(span) {
|
|
14
28
|
// Backcompat shim to support OTEL 1.x and 2.x
|
|
15
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -39,20 +53,35 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
|
|
|
39
53
|
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
40
54
|
const isTraceable = isTraceableSpan(span);
|
|
41
55
|
const parentSpanId = getParentSpanId(span);
|
|
42
|
-
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
43
|
-
isTraceable,
|
|
44
|
-
parentSpanId,
|
|
45
|
-
};
|
|
46
56
|
let currentCandidateParentSpanId = parentSpanId;
|
|
47
57
|
let traceableParentId;
|
|
58
|
+
let parentDottedOrder;
|
|
59
|
+
// LangSmith uses the first span's id as the trace id, NOT the actual OTEL trace id
|
|
60
|
+
// Default to the current span if no parent information is present
|
|
61
|
+
let lsTraceId = (0, utils_js_1.getUuidFromOtelSpanId)(span.spanContext().spanId);
|
|
48
62
|
while (currentCandidateParentSpanId) {
|
|
49
63
|
const currentSpanInfo = this.traceMap[span.spanContext().traceId].spanInfo[currentCandidateParentSpanId];
|
|
50
64
|
if (currentSpanInfo?.isTraceable) {
|
|
51
65
|
traceableParentId = currentCandidateParentSpanId;
|
|
66
|
+
parentDottedOrder = currentSpanInfo.dottedOrder;
|
|
67
|
+
lsTraceId = currentSpanInfo.lsTraceId;
|
|
52
68
|
break;
|
|
53
69
|
}
|
|
54
70
|
currentCandidateParentSpanId = currentSpanInfo?.parentSpanId;
|
|
55
71
|
}
|
|
72
|
+
const startTimestamp = hrTimeToTimeStamp(span.startTime);
|
|
73
|
+
const spanUuid = (0, utils_js_1.getUuidFromOtelSpanId)(span.spanContext().spanId);
|
|
74
|
+
const dottedOrderComponent = (0, run_trees_js_1.stripNonAlphanumeric)(startTimestamp) + spanUuid;
|
|
75
|
+
const currentDottedOrder = parentDottedOrder
|
|
76
|
+
? `${parentDottedOrder}.${dottedOrderComponent}`
|
|
77
|
+
: dottedOrderComponent;
|
|
78
|
+
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
79
|
+
isTraceable,
|
|
80
|
+
lsTraceId,
|
|
81
|
+
spanId: span.spanContext().spanId,
|
|
82
|
+
parentSpanId,
|
|
83
|
+
dottedOrder: currentDottedOrder,
|
|
84
|
+
};
|
|
56
85
|
if (!traceableParentId) {
|
|
57
86
|
span.attributes[constants_js_1.LANGSMITH_IS_ROOT] = true;
|
|
58
87
|
}
|
|
@@ -60,6 +89,8 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
|
|
|
60
89
|
span.attributes[constants_js_1.LANGSMITH_PARENT_RUN_ID] =
|
|
61
90
|
(0, utils_js_1.getUuidFromOtelSpanId)(traceableParentId);
|
|
62
91
|
}
|
|
92
|
+
span.attributes[constants_js_1.LANGSMITH_DOTTED_ORDER] = currentDottedOrder;
|
|
93
|
+
span.attributes[constants_js_1.LANGSMITH_TRACE_ID] = lsTraceId;
|
|
63
94
|
if (isTraceable) {
|
|
64
95
|
super.onStart(span, parentContext);
|
|
65
96
|
}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { BatchSpanProcessor, } from "@opentelemetry/sdk-trace-base";
|
|
2
|
-
import { LANGSMITH_IS_ROOT, LANGSMITH_PARENT_RUN_ID, LANGSMITH_TRACEABLE, } from "./constants.js";
|
|
2
|
+
import { LANGSMITH_IS_ROOT, LANGSMITH_PARENT_RUN_ID, LANGSMITH_TRACEABLE, LANGSMITH_DOTTED_ORDER, LANGSMITH_TRACE_ID, } from "./constants.js";
|
|
3
3
|
import { getUuidFromOtelSpanId } from "./utils.js";
|
|
4
|
-
import { RunTree } from "../../run_trees.js";
|
|
4
|
+
import { RunTree, stripNonAlphanumeric } from "../../run_trees.js";
|
|
5
|
+
const NANOSECOND_DIGITS = 9;
|
|
6
|
+
const MICROSECOND_DIGITS = 6;
|
|
5
7
|
export function isTraceableSpan(span) {
|
|
6
8
|
return (span.attributes[LANGSMITH_TRACEABLE] === "true" ||
|
|
7
9
|
typeof span.attributes["ai.operationId"] === "string");
|
|
8
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123Z"
|
|
13
|
+
* @param time
|
|
14
|
+
*/
|
|
15
|
+
function hrTimeToTimeStamp(time) {
|
|
16
|
+
const precision = NANOSECOND_DIGITS;
|
|
17
|
+
const tmp = `${"0".repeat(precision)}${time[1]}Z`;
|
|
18
|
+
const nanoString = tmp.substring(tmp.length - precision - 1);
|
|
19
|
+
const date = new Date(time[0] * 1000).toISOString();
|
|
20
|
+
// We only need 6 digits of precision for the dotted order
|
|
21
|
+
return `${date.replace("000Z", nanoString.slice(0, MICROSECOND_DIGITS))}Z`;
|
|
22
|
+
}
|
|
9
23
|
function getParentSpanId(span) {
|
|
10
24
|
// Backcompat shim to support OTEL 1.x and 2.x
|
|
11
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -35,20 +49,35 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
|
35
49
|
this.traceMap[span.spanContext().traceId].spanCount++;
|
|
36
50
|
const isTraceable = isTraceableSpan(span);
|
|
37
51
|
const parentSpanId = getParentSpanId(span);
|
|
38
|
-
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
39
|
-
isTraceable,
|
|
40
|
-
parentSpanId,
|
|
41
|
-
};
|
|
42
52
|
let currentCandidateParentSpanId = parentSpanId;
|
|
43
53
|
let traceableParentId;
|
|
54
|
+
let parentDottedOrder;
|
|
55
|
+
// LangSmith uses the first span's id as the trace id, NOT the actual OTEL trace id
|
|
56
|
+
// Default to the current span if no parent information is present
|
|
57
|
+
let lsTraceId = getUuidFromOtelSpanId(span.spanContext().spanId);
|
|
44
58
|
while (currentCandidateParentSpanId) {
|
|
45
59
|
const currentSpanInfo = this.traceMap[span.spanContext().traceId].spanInfo[currentCandidateParentSpanId];
|
|
46
60
|
if (currentSpanInfo?.isTraceable) {
|
|
47
61
|
traceableParentId = currentCandidateParentSpanId;
|
|
62
|
+
parentDottedOrder = currentSpanInfo.dottedOrder;
|
|
63
|
+
lsTraceId = currentSpanInfo.lsTraceId;
|
|
48
64
|
break;
|
|
49
65
|
}
|
|
50
66
|
currentCandidateParentSpanId = currentSpanInfo?.parentSpanId;
|
|
51
67
|
}
|
|
68
|
+
const startTimestamp = hrTimeToTimeStamp(span.startTime);
|
|
69
|
+
const spanUuid = getUuidFromOtelSpanId(span.spanContext().spanId);
|
|
70
|
+
const dottedOrderComponent = stripNonAlphanumeric(startTimestamp) + spanUuid;
|
|
71
|
+
const currentDottedOrder = parentDottedOrder
|
|
72
|
+
? `${parentDottedOrder}.${dottedOrderComponent}`
|
|
73
|
+
: dottedOrderComponent;
|
|
74
|
+
this.traceMap[span.spanContext().traceId].spanInfo[span.spanContext().spanId] = {
|
|
75
|
+
isTraceable,
|
|
76
|
+
lsTraceId,
|
|
77
|
+
spanId: span.spanContext().spanId,
|
|
78
|
+
parentSpanId,
|
|
79
|
+
dottedOrder: currentDottedOrder,
|
|
80
|
+
};
|
|
52
81
|
if (!traceableParentId) {
|
|
53
82
|
span.attributes[LANGSMITH_IS_ROOT] = true;
|
|
54
83
|
}
|
|
@@ -56,6 +85,8 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
|
|
|
56
85
|
span.attributes[LANGSMITH_PARENT_RUN_ID] =
|
|
57
86
|
getUuidFromOtelSpanId(traceableParentId);
|
|
58
87
|
}
|
|
88
|
+
span.attributes[LANGSMITH_DOTTED_ORDER] = currentDottedOrder;
|
|
89
|
+
span.attributes[LANGSMITH_TRACE_ID] = lsTraceId;
|
|
59
90
|
if (isTraceable) {
|
|
60
91
|
super.onStart(span, parentContext);
|
|
61
92
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
|
|
|
10
10
|
var project_js_1 = require("./utils/project.cjs");
|
|
11
11
|
Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
|
|
12
12
|
// Update using yarn bump-version
|
|
13
|
-
exports.__version__ = "0.3.
|
|
13
|
+
exports.__version__ = "0.3.51";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
|
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
|
-
export declare const __version__ = "0.3.
|
|
6
|
+
export declare const __version__ = "0.3.51";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
|
|
|
3
3
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
// Update using yarn bump-version
|
|
6
|
-
export const __version__ = "0.3.
|
|
6
|
+
export const __version__ = "0.3.51";
|
package/dist/run_trees.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.RunTree = void 0;
|
|
37
|
+
exports.stripNonAlphanumeric = stripNonAlphanumeric;
|
|
37
38
|
exports.convertToDottedOrderFormat = convertToDottedOrderFormat;
|
|
38
39
|
exports.isRunTree = isRunTree;
|
|
39
40
|
exports.isRunnableConfigLike = isRunnableConfigLike;
|
|
@@ -775,17 +776,62 @@ function _getWriteReplicasFromEnv() {
|
|
|
775
776
|
return [];
|
|
776
777
|
try {
|
|
777
778
|
const parsed = JSON.parse(envVar);
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
779
|
+
if (Array.isArray(parsed)) {
|
|
780
|
+
const replicas = [];
|
|
781
|
+
for (const item of parsed) {
|
|
782
|
+
if (typeof item !== "object" || item === null) {
|
|
783
|
+
console.warn(`Invalid item type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
784
|
+
`expected object, got ${typeof item}`);
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
if (typeof item.api_url !== "string") {
|
|
788
|
+
console.warn(`Invalid api_url type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
789
|
+
`expected string, got ${typeof item.api_url}`);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (typeof item.api_key !== "string") {
|
|
793
|
+
console.warn(`Invalid api_key type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
794
|
+
`expected string, got ${typeof item.api_key}`);
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
replicas.push({
|
|
798
|
+
apiUrl: item.api_url.replace(/\/$/, ""),
|
|
799
|
+
apiKey: item.api_key,
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return replicas;
|
|
803
|
+
}
|
|
804
|
+
else if (typeof parsed === "object" && parsed !== null) {
|
|
805
|
+
_checkEndpointEnvUnset(parsed);
|
|
806
|
+
const replicas = [];
|
|
807
|
+
for (const [url, key] of Object.entries(parsed)) {
|
|
808
|
+
const cleanUrl = url.replace(/\/$/, "");
|
|
809
|
+
if (typeof key === "string") {
|
|
810
|
+
replicas.push({
|
|
811
|
+
apiUrl: cleanUrl,
|
|
812
|
+
apiKey: key,
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
console.warn(`Invalid value type in LANGSMITH_RUNS_ENDPOINTS for URL ${url}: ` +
|
|
817
|
+
`expected string, got ${typeof key}`);
|
|
818
|
+
continue;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return replicas;
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of " +
|
|
825
|
+
`objects with api_url and api_key properties, or object mapping url->apiKey, got ${typeof parsed}`);
|
|
826
|
+
return [];
|
|
827
|
+
}
|
|
783
828
|
}
|
|
784
829
|
catch (e) {
|
|
785
830
|
if ((0, error_js_1.isConflictingEndpointsError)(e)) {
|
|
786
831
|
throw e;
|
|
787
832
|
}
|
|
788
|
-
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON
|
|
833
|
+
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of " +
|
|
834
|
+
"objects with api_url and api_key properties, or object mapping url->apiKey");
|
|
789
835
|
return [];
|
|
790
836
|
}
|
|
791
837
|
}
|
package/dist/run_trees.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from "./client.js";
|
|
2
2
|
import { Attachments, BaseRun, KVMap, RunCreate } from "./schemas.js";
|
|
3
|
+
export declare function stripNonAlphanumeric(input: string): string;
|
|
3
4
|
export declare function convertToDottedOrderFormat(epoch: number, runId: string, executionOrder?: number): {
|
|
4
5
|
dottedOrder: string;
|
|
5
6
|
microsecondPrecisionDatestring: string;
|
package/dist/run_trees.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
|
|
|
7
7
|
import { getDefaultProjectName } from "./utils/project.js";
|
|
8
8
|
import { getLangSmithEnvironmentVariable } from "./utils/env.js";
|
|
9
9
|
import { warnOnce } from "./utils/warn.js";
|
|
10
|
-
function stripNonAlphanumeric(input) {
|
|
10
|
+
export function stripNonAlphanumeric(input) {
|
|
11
11
|
return input.replace(/[-:.]/g, "");
|
|
12
12
|
}
|
|
13
13
|
export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
@@ -735,17 +735,62 @@ function _getWriteReplicasFromEnv() {
|
|
|
735
735
|
return [];
|
|
736
736
|
try {
|
|
737
737
|
const parsed = JSON.parse(envVar);
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
738
|
+
if (Array.isArray(parsed)) {
|
|
739
|
+
const replicas = [];
|
|
740
|
+
for (const item of parsed) {
|
|
741
|
+
if (typeof item !== "object" || item === null) {
|
|
742
|
+
console.warn(`Invalid item type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
743
|
+
`expected object, got ${typeof item}`);
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (typeof item.api_url !== "string") {
|
|
747
|
+
console.warn(`Invalid api_url type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
748
|
+
`expected string, got ${typeof item.api_url}`);
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
751
|
+
if (typeof item.api_key !== "string") {
|
|
752
|
+
console.warn(`Invalid api_key type in LANGSMITH_RUNS_ENDPOINTS: ` +
|
|
753
|
+
`expected string, got ${typeof item.api_key}`);
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
replicas.push({
|
|
757
|
+
apiUrl: item.api_url.replace(/\/$/, ""),
|
|
758
|
+
apiKey: item.api_key,
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
return replicas;
|
|
762
|
+
}
|
|
763
|
+
else if (typeof parsed === "object" && parsed !== null) {
|
|
764
|
+
_checkEndpointEnvUnset(parsed);
|
|
765
|
+
const replicas = [];
|
|
766
|
+
for (const [url, key] of Object.entries(parsed)) {
|
|
767
|
+
const cleanUrl = url.replace(/\/$/, "");
|
|
768
|
+
if (typeof key === "string") {
|
|
769
|
+
replicas.push({
|
|
770
|
+
apiUrl: cleanUrl,
|
|
771
|
+
apiKey: key,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
console.warn(`Invalid value type in LANGSMITH_RUNS_ENDPOINTS for URL ${url}: ` +
|
|
776
|
+
`expected string, got ${typeof key}`);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return replicas;
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of " +
|
|
784
|
+
`objects with api_url and api_key properties, or object mapping url->apiKey, got ${typeof parsed}`);
|
|
785
|
+
return [];
|
|
786
|
+
}
|
|
743
787
|
}
|
|
744
788
|
catch (e) {
|
|
745
789
|
if (isConflictingEndpointsError(e)) {
|
|
746
790
|
throw e;
|
|
747
791
|
}
|
|
748
|
-
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON
|
|
792
|
+
console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of " +
|
|
793
|
+
"objects with api_url and api_key properties, or object mapping url->apiKey");
|
|
749
794
|
return [];
|
|
750
795
|
}
|
|
751
796
|
}
|
package/dist/utils/vercel.cjs
CHANGED
|
@@ -6,14 +6,42 @@ function extractInputTokenDetails(providerMetadata, spanAttributes) {
|
|
|
6
6
|
if (providerMetadata.anthropic != null &&
|
|
7
7
|
typeof providerMetadata.anthropic === "object") {
|
|
8
8
|
const anthropic = providerMetadata.anthropic;
|
|
9
|
-
if (anthropic.
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (anthropic.usage != null && typeof anthropic.usage === "object") {
|
|
10
|
+
// Raw usage from Anthropic returned in AI SDK 5
|
|
11
|
+
const usage = anthropic.usage;
|
|
12
|
+
if (usage.cache_creation != null &&
|
|
13
|
+
typeof usage.cache_creation === "object") {
|
|
14
|
+
const cacheCreation = usage.cache_creation;
|
|
15
|
+
if (typeof cacheCreation.ephemeral_5m_input_tokens === "number") {
|
|
16
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
17
|
+
cacheCreation.ephemeral_5m_input_tokens;
|
|
18
|
+
}
|
|
19
|
+
if (typeof cacheCreation.ephemeral_1h_input_tokens === "number") {
|
|
20
|
+
inputTokenDetails.ephemeral_1hr_input_tokens =
|
|
21
|
+
cacheCreation.ephemeral_1h_input_tokens;
|
|
22
|
+
}
|
|
23
|
+
// If cache_creation not returned (no beta header passed),
|
|
24
|
+
// fallback to assuming 5m cache tokens
|
|
25
|
+
}
|
|
26
|
+
else if (typeof usage.cache_creation_input_tokens === "number") {
|
|
27
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
28
|
+
usage.cache_creation_input_tokens;
|
|
29
|
+
}
|
|
30
|
+
if (typeof usage.cache_read_input_tokens === "number") {
|
|
31
|
+
inputTokenDetails.cache_read = usage.cache_read_input_tokens;
|
|
32
|
+
}
|
|
12
33
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
anthropic.
|
|
34
|
+
else {
|
|
35
|
+
// AI SDK 4 fields
|
|
36
|
+
if (anthropic.cacheReadInputTokens != null &&
|
|
37
|
+
typeof anthropic.cacheReadInputTokens === "number") {
|
|
38
|
+
inputTokenDetails.cache_read = anthropic.cacheReadInputTokens;
|
|
39
|
+
}
|
|
40
|
+
if (anthropic.cacheCreationInputTokens != null &&
|
|
41
|
+
typeof anthropic.cacheCreationInputTokens === "number") {
|
|
42
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
43
|
+
anthropic.cacheCreationInputTokens;
|
|
44
|
+
}
|
|
17
45
|
}
|
|
18
46
|
return inputTokenDetails;
|
|
19
47
|
}
|
package/dist/utils/vercel.js
CHANGED
|
@@ -3,14 +3,42 @@ function extractInputTokenDetails(providerMetadata, spanAttributes) {
|
|
|
3
3
|
if (providerMetadata.anthropic != null &&
|
|
4
4
|
typeof providerMetadata.anthropic === "object") {
|
|
5
5
|
const anthropic = providerMetadata.anthropic;
|
|
6
|
-
if (anthropic.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (anthropic.usage != null && typeof anthropic.usage === "object") {
|
|
7
|
+
// Raw usage from Anthropic returned in AI SDK 5
|
|
8
|
+
const usage = anthropic.usage;
|
|
9
|
+
if (usage.cache_creation != null &&
|
|
10
|
+
typeof usage.cache_creation === "object") {
|
|
11
|
+
const cacheCreation = usage.cache_creation;
|
|
12
|
+
if (typeof cacheCreation.ephemeral_5m_input_tokens === "number") {
|
|
13
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
14
|
+
cacheCreation.ephemeral_5m_input_tokens;
|
|
15
|
+
}
|
|
16
|
+
if (typeof cacheCreation.ephemeral_1h_input_tokens === "number") {
|
|
17
|
+
inputTokenDetails.ephemeral_1hr_input_tokens =
|
|
18
|
+
cacheCreation.ephemeral_1h_input_tokens;
|
|
19
|
+
}
|
|
20
|
+
// If cache_creation not returned (no beta header passed),
|
|
21
|
+
// fallback to assuming 5m cache tokens
|
|
22
|
+
}
|
|
23
|
+
else if (typeof usage.cache_creation_input_tokens === "number") {
|
|
24
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
25
|
+
usage.cache_creation_input_tokens;
|
|
26
|
+
}
|
|
27
|
+
if (typeof usage.cache_read_input_tokens === "number") {
|
|
28
|
+
inputTokenDetails.cache_read = usage.cache_read_input_tokens;
|
|
29
|
+
}
|
|
9
30
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
anthropic.
|
|
31
|
+
else {
|
|
32
|
+
// AI SDK 4 fields
|
|
33
|
+
if (anthropic.cacheReadInputTokens != null &&
|
|
34
|
+
typeof anthropic.cacheReadInputTokens === "number") {
|
|
35
|
+
inputTokenDetails.cache_read = anthropic.cacheReadInputTokens;
|
|
36
|
+
}
|
|
37
|
+
if (anthropic.cacheCreationInputTokens != null &&
|
|
38
|
+
typeof anthropic.cacheCreationInputTokens === "number") {
|
|
39
|
+
inputTokenDetails.ephemeral_5m_input_tokens =
|
|
40
|
+
anthropic.cacheCreationInputTokens;
|
|
41
|
+
}
|
|
14
42
|
}
|
|
15
43
|
return inputTokenDetails;
|
|
16
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langsmith",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.51",
|
|
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": [
|
|
@@ -144,8 +144,8 @@
|
|
|
144
144
|
"uuid": "^10.0.0"
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"@ai-sdk/anthropic": "2.0.0-beta.
|
|
148
|
-
"@ai-sdk/openai": "2.0.0-beta.
|
|
147
|
+
"@ai-sdk/anthropic": "2.0.0-beta.12",
|
|
148
|
+
"@ai-sdk/openai": "2.0.0-beta.15",
|
|
149
149
|
"@babel/preset-env": "^7.22.4",
|
|
150
150
|
"@faker-js/faker": "^8.4.1",
|
|
151
151
|
"@jest/globals": "^29.5.0",
|