braintrust 3.24.0 → 3.25.0
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/dev/dist/index.d.mts +5 -0
- package/dev/dist/index.d.ts +5 -0
- package/dev/dist/index.js +2614 -1567
- package/dev/dist/index.mjs +2037 -990
- package/dist/apply-auto-instrumentation.js +200 -199
- package/dist/apply-auto-instrumentation.mjs +8 -7
- package/dist/auto-instrumentations/bundler/esbuild.cjs +596 -462
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +596 -462
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +596 -462
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +596 -462
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +596 -462
- package/dist/auto-instrumentations/bundler/webpack.cjs +596 -462
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-BURMPO7L.mjs → chunk-7P6563SW.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-F43DNLPD.mjs → chunk-CZ24KNHT.mjs} +569 -442
- package/dist/auto-instrumentations/{chunk-GSZHTAQW.mjs → chunk-JPVCUKTY.mjs} +30 -21
- package/dist/auto-instrumentations/hook.mjs +648 -476
- package/dist/auto-instrumentations/index.cjs +568 -442
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/browser.d.mts +7 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +2022 -971
- package/dist/browser.mjs +2022 -971
- package/dist/{chunk-XE5FS7QY.mjs → chunk-2SANLSWX.mjs} +1375 -597
- package/dist/{chunk-7F6GCRHH.mjs → chunk-ABR2QWDP.mjs} +702 -456
- package/dist/{chunk-SU6EHKJV.js → chunk-GSIDVFE6.js} +2176 -1398
- package/dist/{chunk-7AUY2XWX.js → chunk-P25IOOU4.js} +704 -458
- package/dist/cli.js +2005 -958
- package/dist/edge-light.js +2022 -971
- package/dist/edge-light.mjs +2022 -971
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +447 -402
- package/dist/index.mjs +72 -27
- package/dist/instrumentation/index.d.mts +5 -0
- package/dist/instrumentation/index.d.ts +5 -0
- package/dist/instrumentation/index.js +1990 -981
- package/dist/instrumentation/index.mjs +1990 -981
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.js +2022 -971
- package/dist/workerd.mjs +2022 -971
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -139,8 +139,9 @@ import {
|
|
|
139
139
|
wrapMastraAgent,
|
|
140
140
|
wrapTraced,
|
|
141
141
|
zodToJsonSchema
|
|
142
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-2SANLSWX.mjs";
|
|
143
143
|
import {
|
|
144
|
+
INSTRUMENTATION_NAMES,
|
|
144
145
|
__export,
|
|
145
146
|
aiSDKChannels,
|
|
146
147
|
anthropicChannels,
|
|
@@ -163,8 +164,9 @@ import {
|
|
|
163
164
|
openRouterAgentChannels,
|
|
164
165
|
openRouterChannels,
|
|
165
166
|
piCodingAgentChannels,
|
|
166
|
-
strandsAgentSDKChannels
|
|
167
|
-
|
|
167
|
+
strandsAgentSDKChannels,
|
|
168
|
+
withSpanInstrumentationName
|
|
169
|
+
} from "./chunk-ABR2QWDP.mjs";
|
|
168
170
|
|
|
169
171
|
// src/exports.ts
|
|
170
172
|
var exports_exports = {};
|
|
@@ -941,6 +943,12 @@ var wrapAgentClass = (AgentClass, options = {}) => {
|
|
|
941
943
|
const original = Reflect.get(instanceTarget, prop, instanceTarget);
|
|
942
944
|
if (harnessAgent && typeof original === "function") {
|
|
943
945
|
switch (prop) {
|
|
946
|
+
case "createSession":
|
|
947
|
+
return wrapHarnessAgentCreateSession(
|
|
948
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
949
|
+
original,
|
|
950
|
+
harnessAgent
|
|
951
|
+
);
|
|
944
952
|
case "generate":
|
|
945
953
|
return wrapHarnessAgentGenerate(
|
|
946
954
|
original,
|
|
@@ -990,6 +998,19 @@ var wrapAgentClass = (AgentClass, options = {}) => {
|
|
|
990
998
|
}
|
|
991
999
|
});
|
|
992
1000
|
};
|
|
1001
|
+
var wrapHarnessAgentCreateSession = (createSession, instance) => {
|
|
1002
|
+
const wrapper = function(params) {
|
|
1003
|
+
return harnessAgentChannels.createSession.tracePromise(
|
|
1004
|
+
() => params === void 0 ? createSession.call(instance) : createSession.call(instance, params),
|
|
1005
|
+
createAISDKChannelContext(params ?? {}, { self: instance })
|
|
1006
|
+
);
|
|
1007
|
+
};
|
|
1008
|
+
Object.defineProperty(wrapper, "name", {
|
|
1009
|
+
value: "HarnessAgent.createSession",
|
|
1010
|
+
writable: false
|
|
1011
|
+
});
|
|
1012
|
+
return wrapper;
|
|
1013
|
+
};
|
|
993
1014
|
var wrapHarnessAgentGenerate = (generate, instance, channel, name, options) => makeGenerateTextWrapper(
|
|
994
1015
|
channel,
|
|
995
1016
|
name,
|
|
@@ -1259,12 +1280,17 @@ var BraintrustLanguageModelWrapper = class {
|
|
|
1259
1280
|
// For the first cut, do not support custom span_info arguments. We can
|
|
1260
1281
|
// propagate those via async local storage
|
|
1261
1282
|
async doGenerate(options) {
|
|
1262
|
-
const span = startSpan(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1283
|
+
const span = startSpan(
|
|
1284
|
+
withSpanInstrumentationName(
|
|
1285
|
+
{
|
|
1286
|
+
name: "Chat Completion",
|
|
1287
|
+
spanAttributes: {
|
|
1288
|
+
type: "llm"
|
|
1289
|
+
}
|
|
1290
|
+
},
|
|
1291
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
1292
|
+
)
|
|
1293
|
+
);
|
|
1268
1294
|
const { prompt, mode, ...rest } = options;
|
|
1269
1295
|
const startTime = getCurrentUnixTimestamp();
|
|
1270
1296
|
try {
|
|
@@ -1295,12 +1321,17 @@ var BraintrustLanguageModelWrapper = class {
|
|
|
1295
1321
|
async doStream(options) {
|
|
1296
1322
|
const { prompt, mode, ...rest } = options;
|
|
1297
1323
|
const startTime = getCurrentUnixTimestamp();
|
|
1298
|
-
const span = startSpan(
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1324
|
+
const span = startSpan(
|
|
1325
|
+
withSpanInstrumentationName(
|
|
1326
|
+
{
|
|
1327
|
+
name: "Chat Completion",
|
|
1328
|
+
spanAttributes: {
|
|
1329
|
+
type: "llm"
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
INSTRUMENTATION_NAMES.AI_SDK
|
|
1333
|
+
)
|
|
1334
|
+
);
|
|
1304
1335
|
span.log({
|
|
1305
1336
|
input: postProcessPrompt(prompt),
|
|
1306
1337
|
metadata: {
|
|
@@ -1655,7 +1686,9 @@ function BraintrustMiddleware(config = {}) {
|
|
|
1655
1686
|
}
|
|
1656
1687
|
}
|
|
1657
1688
|
};
|
|
1658
|
-
const span = startSpan(
|
|
1689
|
+
const span = startSpan(
|
|
1690
|
+
withSpanInstrumentationName(spanArgs, INSTRUMENTATION_NAMES.AI_SDK)
|
|
1691
|
+
);
|
|
1659
1692
|
try {
|
|
1660
1693
|
const result = await doGenerate();
|
|
1661
1694
|
const metadata = {};
|
|
@@ -1717,7 +1750,9 @@ function BraintrustMiddleware(config = {}) {
|
|
|
1717
1750
|
}
|
|
1718
1751
|
}
|
|
1719
1752
|
};
|
|
1720
|
-
const span = startSpan(
|
|
1753
|
+
const span = startSpan(
|
|
1754
|
+
withSpanInstrumentationName(spanArgs, INSTRUMENTATION_NAMES.AI_SDK)
|
|
1755
|
+
);
|
|
1721
1756
|
try {
|
|
1722
1757
|
const { stream, ...rest } = await doStream();
|
|
1723
1758
|
const textChunks = [];
|
|
@@ -1924,7 +1959,12 @@ var EveBridge = class {
|
|
|
1924
1959
|
};
|
|
1925
1960
|
const span = withCurrent(
|
|
1926
1961
|
NOOP_SPAN,
|
|
1927
|
-
() => _internalStartSpanWithInitialMerge(
|
|
1962
|
+
() => _internalStartSpanWithInitialMerge(
|
|
1963
|
+
withSpanInstrumentationName(
|
|
1964
|
+
{ ...args, startTime },
|
|
1965
|
+
INSTRUMENTATION_NAMES.EVE
|
|
1966
|
+
)
|
|
1967
|
+
)
|
|
1928
1968
|
);
|
|
1929
1969
|
if (typeof rowId !== "string") {
|
|
1930
1970
|
return span;
|
|
@@ -8836,26 +8876,30 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
8836
8876
|
}
|
|
8837
8877
|
}
|
|
8838
8878
|
})();
|
|
8879
|
+
let timeoutId;
|
|
8880
|
+
let abortHandler;
|
|
8881
|
+
const cleanupCancellation = () => {
|
|
8882
|
+
if (timeoutId !== void 0) {
|
|
8883
|
+
clearTimeout(timeoutId);
|
|
8884
|
+
timeoutId = void 0;
|
|
8885
|
+
}
|
|
8886
|
+
if (abortHandler && evaluator.signal) {
|
|
8887
|
+
evaluator.signal.removeEventListener("abort", abortHandler);
|
|
8888
|
+
abortHandler = void 0;
|
|
8889
|
+
}
|
|
8890
|
+
};
|
|
8839
8891
|
const cancel = async () => {
|
|
8840
8892
|
await new Promise((_, reject2) => {
|
|
8841
8893
|
if (cancelled) {
|
|
8842
8894
|
reject2(new InternalAbortError("Evaluator already cancelled"));
|
|
8843
8895
|
return;
|
|
8844
8896
|
}
|
|
8845
|
-
let timeoutId;
|
|
8846
|
-
let abortHandler;
|
|
8847
8897
|
const rejectOnce = (error) => {
|
|
8848
8898
|
if (cancelled) {
|
|
8849
8899
|
return;
|
|
8850
8900
|
}
|
|
8851
8901
|
cancelled = true;
|
|
8852
|
-
|
|
8853
|
-
clearTimeout(timeoutId);
|
|
8854
|
-
timeoutId = void 0;
|
|
8855
|
-
}
|
|
8856
|
-
if (abortHandler && evaluator.signal) {
|
|
8857
|
-
evaluator.signal.removeEventListener("abort", abortHandler);
|
|
8858
|
-
}
|
|
8902
|
+
cleanupCancellation();
|
|
8859
8903
|
reject2(error);
|
|
8860
8904
|
};
|
|
8861
8905
|
if (evaluator.timeout) {
|
|
@@ -8895,6 +8939,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
8895
8939
|
}
|
|
8896
8940
|
throw e;
|
|
8897
8941
|
} finally {
|
|
8942
|
+
cleanupCancellation();
|
|
8898
8943
|
if (!collectResults) {
|
|
8899
8944
|
collectedResults.length = 0;
|
|
8900
8945
|
}
|
|
@@ -7942,7 +7942,12 @@ declare class BraintrustState {
|
|
|
7942
7942
|
private _contextManager;
|
|
7943
7943
|
private _otelFlushCallback;
|
|
7944
7944
|
spanOriginEnvironment: SpanOriginEnvironment | undefined;
|
|
7945
|
+
private traceContextSigningSecret;
|
|
7945
7946
|
constructor(loginParams: LoginOptions);
|
|
7947
|
+
/** @internal */
|
|
7948
|
+
_internalSetTraceContextSigningSecret(secret: string | undefined): void;
|
|
7949
|
+
/** @internal */
|
|
7950
|
+
_internalGetTraceContextSigningSecret(): string | undefined;
|
|
7946
7951
|
resetLoginInfo(): void;
|
|
7947
7952
|
resetIdGenState(): void;
|
|
7948
7953
|
[RESET_CONTEXT_MANAGER_STATE](): void;
|
|
@@ -7942,7 +7942,12 @@ declare class BraintrustState {
|
|
|
7942
7942
|
private _contextManager;
|
|
7943
7943
|
private _otelFlushCallback;
|
|
7944
7944
|
spanOriginEnvironment: SpanOriginEnvironment | undefined;
|
|
7945
|
+
private traceContextSigningSecret;
|
|
7945
7946
|
constructor(loginParams: LoginOptions);
|
|
7947
|
+
/** @internal */
|
|
7948
|
+
_internalSetTraceContextSigningSecret(secret: string | undefined): void;
|
|
7949
|
+
/** @internal */
|
|
7950
|
+
_internalGetTraceContextSigningSecret(): string | undefined;
|
|
7946
7951
|
resetLoginInfo(): void;
|
|
7947
7952
|
resetIdGenState(): void;
|
|
7948
7953
|
[RESET_CONTEXT_MANAGER_STATE](): void;
|