braintrust 1.0.2 → 1.0.3
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 +30 -25
- package/dev/dist/index.d.ts +30 -25
- package/dev/dist/index.js +336 -325
- package/dev/dist/index.mjs +259 -248
- package/dist/browser.d.mts +2313 -322
- package/dist/browser.d.ts +2313 -322
- package/dist/browser.js +2819 -198
- package/dist/browser.mjs +2681 -60
- package/dist/cli.js +358 -160
- package/dist/index.d.mts +254 -284
- package/dist/index.d.ts +254 -284
- package/dist/index.js +484 -470
- package/dist/index.mjs +335 -321
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19;var __defProp = Object.defineProperty;
|
|
2
2
|
var __export = (target, all) => {
|
|
3
3
|
for (var name in all)
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,7 +32,9 @@ var iso = {
|
|
|
32
32
|
getCallerLocation: () => void 0,
|
|
33
33
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
34
34
|
processOn: (_0, _1) => {
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
|
|
37
|
+
writeln: (text) => console.log(text)
|
|
36
38
|
};
|
|
37
39
|
var isomorph_default = iso;
|
|
38
40
|
|
|
@@ -125,7 +127,7 @@ async function getPastNAncestors(n = 1e3, remote = void 0) {
|
|
|
125
127
|
return [];
|
|
126
128
|
}
|
|
127
129
|
const commits = await git.log({ from: ancestor, to: "HEAD", maxCount: n });
|
|
128
|
-
return commits.all.map((c) => c.hash);
|
|
130
|
+
return commits.all.slice(0, n).map((c) => c.hash);
|
|
129
131
|
}
|
|
130
132
|
async function attempt(fn) {
|
|
131
133
|
try {
|
|
@@ -964,11 +966,11 @@ function mergeDictsWithPaths({
|
|
|
964
966
|
function mergeDictsWithPathsHelper({
|
|
965
967
|
mergeInto,
|
|
966
968
|
mergeFrom,
|
|
967
|
-
path:
|
|
969
|
+
path: path2,
|
|
968
970
|
mergePaths
|
|
969
971
|
}) {
|
|
970
972
|
Object.entries(mergeFrom).forEach(([k, mergeFromV]) => {
|
|
971
|
-
const fullPath =
|
|
973
|
+
const fullPath = path2.concat([k]);
|
|
972
974
|
const fullPathSerialized = JSON.stringify(fullPath);
|
|
973
975
|
const mergeIntoV = recordFind(mergeInto, k);
|
|
974
976
|
if (isObject(mergeIntoV) && isObject(mergeFromV) && !mergePaths.has(fullPathSerialized)) {
|
|
@@ -999,9 +1001,9 @@ function mapAt(m, k) {
|
|
|
999
1001
|
function recordFind(m, k) {
|
|
1000
1002
|
return m[k];
|
|
1001
1003
|
}
|
|
1002
|
-
function getObjValueByPath(row,
|
|
1004
|
+
function getObjValueByPath(row, path2) {
|
|
1003
1005
|
let curr = row;
|
|
1004
|
-
for (const p of
|
|
1006
|
+
for (const p of path2) {
|
|
1005
1007
|
if (!isObjectOrArray(curr)) {
|
|
1006
1008
|
return null;
|
|
1007
1009
|
}
|
|
@@ -1276,6 +1278,93 @@ function _urljoin(...parts) {
|
|
|
1276
1278
|
(x, i) => x.replace(/^\//, "").replace(i < parts.length - 1 ? /\/$/ : "", "")
|
|
1277
1279
|
).filter((x) => x.trim() !== "").join("/");
|
|
1278
1280
|
}
|
|
1281
|
+
function slugify(text, options) {
|
|
1282
|
+
if (typeof text !== "string") {
|
|
1283
|
+
throw new Error("slugify: string argument expected");
|
|
1284
|
+
}
|
|
1285
|
+
const charMap = {
|
|
1286
|
+
// Currency and symbols
|
|
1287
|
+
$: "dollar",
|
|
1288
|
+
"%": "percent",
|
|
1289
|
+
"&": "and",
|
|
1290
|
+
// Latin characters
|
|
1291
|
+
\u00C0: "A",
|
|
1292
|
+
\u00C1: "A",
|
|
1293
|
+
\u00C2: "A",
|
|
1294
|
+
\u00C3: "A",
|
|
1295
|
+
\u00C4: "A",
|
|
1296
|
+
\u00C5: "A",
|
|
1297
|
+
\u00C6: "AE",
|
|
1298
|
+
\u00C7: "C",
|
|
1299
|
+
\u00C8: "E",
|
|
1300
|
+
\u00C9: "E",
|
|
1301
|
+
\u00CA: "E",
|
|
1302
|
+
\u00CB: "E",
|
|
1303
|
+
\u00CC: "I",
|
|
1304
|
+
\u00CD: "I",
|
|
1305
|
+
\u00CE: "I",
|
|
1306
|
+
\u00CF: "I",
|
|
1307
|
+
\u00D1: "N",
|
|
1308
|
+
\u00D2: "O",
|
|
1309
|
+
\u00D3: "O",
|
|
1310
|
+
\u00D4: "O",
|
|
1311
|
+
\u00D5: "O",
|
|
1312
|
+
\u00D6: "O",
|
|
1313
|
+
\u00D8: "O",
|
|
1314
|
+
\u00D9: "U",
|
|
1315
|
+
\u00DA: "U",
|
|
1316
|
+
\u00DB: "U",
|
|
1317
|
+
\u00DC: "U",
|
|
1318
|
+
\u00DD: "Y",
|
|
1319
|
+
\u00E0: "a",
|
|
1320
|
+
\u00E1: "a",
|
|
1321
|
+
\u00E2: "a",
|
|
1322
|
+
\u00E3: "a",
|
|
1323
|
+
\u00E4: "a",
|
|
1324
|
+
\u00E5: "a",
|
|
1325
|
+
\u00E6: "ae",
|
|
1326
|
+
\u00E7: "c",
|
|
1327
|
+
\u00E8: "e",
|
|
1328
|
+
\u00E9: "e",
|
|
1329
|
+
\u00EA: "e",
|
|
1330
|
+
\u00EB: "e",
|
|
1331
|
+
\u00EC: "i",
|
|
1332
|
+
\u00ED: "i",
|
|
1333
|
+
\u00EE: "i",
|
|
1334
|
+
\u00EF: "i",
|
|
1335
|
+
\u00F1: "n",
|
|
1336
|
+
\u00F2: "o",
|
|
1337
|
+
\u00F3: "o",
|
|
1338
|
+
\u00F4: "o",
|
|
1339
|
+
\u00F5: "o",
|
|
1340
|
+
\u00F6: "o",
|
|
1341
|
+
\u00F8: "o",
|
|
1342
|
+
\u00F9: "u",
|
|
1343
|
+
\u00FA: "u",
|
|
1344
|
+
\u00FB: "u",
|
|
1345
|
+
\u00FC: "u",
|
|
1346
|
+
\u00FD: "y",
|
|
1347
|
+
\u00FF: "y"
|
|
1348
|
+
};
|
|
1349
|
+
const replacement = "-";
|
|
1350
|
+
const trim = _optionalChain([options, 'optionalAccess', _21 => _21.trim]) !== false;
|
|
1351
|
+
let slug = text.normalize().split("").reduce((result, ch) => {
|
|
1352
|
+
const mapped = charMap[ch] || ch;
|
|
1353
|
+
const appendChar = mapped === replacement ? " " : mapped;
|
|
1354
|
+
return result + appendChar.replace(/[^\w\s$*_+~.()'"!\-:@]+/g, "");
|
|
1355
|
+
}, "");
|
|
1356
|
+
if (_optionalChain([options, 'optionalAccess', _22 => _22.strict])) {
|
|
1357
|
+
slug = slug.replace(/[^A-Za-z0-9\s]/g, "");
|
|
1358
|
+
}
|
|
1359
|
+
if (trim) {
|
|
1360
|
+
slug = slug.trim();
|
|
1361
|
+
}
|
|
1362
|
+
slug = slug.replace(/\s+/g, replacement);
|
|
1363
|
+
if (_optionalChain([options, 'optionalAccess', _23 => _23.lower])) {
|
|
1364
|
+
slug = slug.toLowerCase();
|
|
1365
|
+
}
|
|
1366
|
+
return slug;
|
|
1367
|
+
}
|
|
1279
1368
|
|
|
1280
1369
|
// util/span_identifier_v4.ts
|
|
1281
1370
|
|
|
@@ -2916,9 +3005,9 @@ var BraintrustStream = class _BraintrustStream {
|
|
|
2916
3005
|
reader.releaseLock();
|
|
2917
3006
|
return { done: true, value: void 0 };
|
|
2918
3007
|
},
|
|
2919
|
-
async throw(
|
|
3008
|
+
async throw(error) {
|
|
2920
3009
|
reader.releaseLock();
|
|
2921
|
-
throw
|
|
3010
|
+
throw error;
|
|
2922
3011
|
}
|
|
2923
3012
|
};
|
|
2924
3013
|
}
|
|
@@ -3232,10 +3321,10 @@ var DiskCache = class {
|
|
|
3232
3321
|
return;
|
|
3233
3322
|
}
|
|
3234
3323
|
const stats = await Promise.all(
|
|
3235
|
-
paths.map(async (
|
|
3236
|
-
const stat2 = await isomorph_default.stat(
|
|
3324
|
+
paths.map(async (path2) => {
|
|
3325
|
+
const stat2 = await isomorph_default.stat(path2);
|
|
3237
3326
|
return {
|
|
3238
|
-
path:
|
|
3327
|
+
path: path2,
|
|
3239
3328
|
mtime: stat2.mtime.getTime()
|
|
3240
3329
|
};
|
|
3241
3330
|
})
|
|
@@ -3376,7 +3465,7 @@ function runCatchFinally(f, catchF, finallyF) {
|
|
|
3376
3465
|
function getCurrentUnixTimestamp() {
|
|
3377
3466
|
return (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
3378
3467
|
}
|
|
3379
|
-
function
|
|
3468
|
+
function isEmpty2(a) {
|
|
3380
3469
|
return a === void 0 || a === null;
|
|
3381
3470
|
}
|
|
3382
3471
|
var LazyValue = (_class2 = class {
|
|
@@ -3513,8 +3602,8 @@ var MaskingError = class {
|
|
|
3513
3602
|
function applyMaskingToField(maskingFunction, data, fieldName) {
|
|
3514
3603
|
try {
|
|
3515
3604
|
return maskingFunction(data);
|
|
3516
|
-
} catch (
|
|
3517
|
-
const errorType =
|
|
3605
|
+
} catch (error) {
|
|
3606
|
+
const errorType = error instanceof Error ? error.constructor.name : "Error";
|
|
3518
3607
|
if (fieldName === "scores" || fieldName === "metrics") {
|
|
3519
3608
|
return new MaskingError(fieldName, errorType);
|
|
3520
3609
|
}
|
|
@@ -3583,7 +3672,7 @@ var NoopSpan = (_class4 = class {
|
|
|
3583
3672
|
return this;
|
|
3584
3673
|
}
|
|
3585
3674
|
end(args) {
|
|
3586
|
-
return _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
3675
|
+
return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _24 => _24.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
3587
3676
|
}
|
|
3588
3677
|
async export() {
|
|
3589
3678
|
return "";
|
|
@@ -3788,8 +3877,8 @@ var BraintrustState = (_class5 = class _BraintrustState {
|
|
|
3788
3877
|
setFetch(fetch2) {
|
|
3789
3878
|
this.loginParams.fetch = fetch2;
|
|
3790
3879
|
this.fetch = fetch2;
|
|
3791
|
-
_optionalChain([this, 'access',
|
|
3792
|
-
_optionalChain([this, 'access',
|
|
3880
|
+
_optionalChain([this, 'access', _25 => _25._apiConn, 'optionalAccess', _26 => _26.setFetch, 'call', _27 => _27(fetch2)]);
|
|
3881
|
+
_optionalChain([this, 'access', _28 => _28._appConn, 'optionalAccess', _29 => _29.setFetch, 'call', _30 => _30(fetch2)]);
|
|
3793
3882
|
}
|
|
3794
3883
|
setMaskingFunction(maskingFunction) {
|
|
3795
3884
|
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
@@ -3801,7 +3890,7 @@ var BraintrustState = (_class5 = class _BraintrustState {
|
|
|
3801
3890
|
const newState = await loginToState({
|
|
3802
3891
|
...this.loginParams,
|
|
3803
3892
|
...Object.fromEntries(
|
|
3804
|
-
Object.entries(loginParams).filter(([k, v]) => !
|
|
3893
|
+
Object.entries(loginParams).filter(([k, v]) => !isEmpty2(v))
|
|
3805
3894
|
)
|
|
3806
3895
|
});
|
|
3807
3896
|
this.copyLoginInfo(newState);
|
|
@@ -3901,7 +3990,7 @@ function useTestBackgroundLogger() {
|
|
|
3901
3990
|
return logger;
|
|
3902
3991
|
}
|
|
3903
3992
|
function clearTestBackgroundLogger() {
|
|
3904
|
-
_optionalChain([_internalGetGlobalState, 'call',
|
|
3993
|
+
_optionalChain([_internalGetGlobalState, 'call', _31 => _31(), 'optionalAccess', _32 => _32.setOverrideBgLogger, 'call', _33 => _33(null)]);
|
|
3905
3994
|
}
|
|
3906
3995
|
function initTestExperiment(experimentName, projectName) {
|
|
3907
3996
|
setInitialTestState();
|
|
@@ -3990,9 +4079,9 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
3990
4079
|
this.headers["Authorization"] = `Bearer ${this.token}`;
|
|
3991
4080
|
}
|
|
3992
4081
|
}
|
|
3993
|
-
async get(
|
|
4082
|
+
async get(path2, params = void 0, config) {
|
|
3994
4083
|
const { headers, ...rest } = config || {};
|
|
3995
|
-
const url = new URL(_urljoin(this.base_url,
|
|
4084
|
+
const url = new URL(_urljoin(this.base_url, path2));
|
|
3996
4085
|
url.search = new URLSearchParams(
|
|
3997
4086
|
params ? Object.entries(params).filter(([_, v]) => v !== void 0).flatMap(
|
|
3998
4087
|
([k, v]) => v !== void 0 ? typeof v === "string" ? [[k, v]] : v.map((x) => [k, x]) : []
|
|
@@ -4013,13 +4102,13 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
4013
4102
|
})
|
|
4014
4103
|
);
|
|
4015
4104
|
}
|
|
4016
|
-
async post(
|
|
4105
|
+
async post(path2, params, config) {
|
|
4017
4106
|
const { headers, ...rest } = config || {};
|
|
4018
4107
|
const this_fetch = this.fetch;
|
|
4019
4108
|
const this_base_url = this.base_url;
|
|
4020
4109
|
const this_headers = this.headers;
|
|
4021
4110
|
return await checkResponse(
|
|
4022
|
-
await this_fetch(_urljoin(this_base_url,
|
|
4111
|
+
await this_fetch(_urljoin(this_base_url, path2), {
|
|
4023
4112
|
method: "POST",
|
|
4024
4113
|
headers: {
|
|
4025
4114
|
Accept: "application/json",
|
|
@@ -4171,12 +4260,12 @@ var Attachment = class extends BaseAttachment {
|
|
|
4171
4260
|
signedUrl: _v3.z.string().url(),
|
|
4172
4261
|
headers: _v3.z.record(_v3.z.string())
|
|
4173
4262
|
}).parse(await metadataResponse.json()));
|
|
4174
|
-
} catch (
|
|
4175
|
-
if (
|
|
4176
|
-
const errorStr = JSON.stringify(
|
|
4263
|
+
} catch (error) {
|
|
4264
|
+
if (error instanceof _v3.ZodError) {
|
|
4265
|
+
const errorStr = JSON.stringify(error.flatten());
|
|
4177
4266
|
throw new Error(`Invalid response from API server: ${errorStr}`);
|
|
4178
4267
|
}
|
|
4179
|
-
throw
|
|
4268
|
+
throw error;
|
|
4180
4269
|
}
|
|
4181
4270
|
addAzureBlobHeaders(headers, signedUrl);
|
|
4182
4271
|
let objectStoreResponse;
|
|
@@ -4188,13 +4277,13 @@ var Attachment = class extends BaseAttachment {
|
|
|
4188
4277
|
body: data
|
|
4189
4278
|
})
|
|
4190
4279
|
);
|
|
4191
|
-
} catch (
|
|
4192
|
-
if (
|
|
4280
|
+
} catch (error) {
|
|
4281
|
+
if (error instanceof FailedHTTPResponse) {
|
|
4193
4282
|
throw new Error(
|
|
4194
|
-
`Failed to upload attachment to object store: ${
|
|
4283
|
+
`Failed to upload attachment to object store: ${error.status} ${error.text} ${error.data}`
|
|
4195
4284
|
);
|
|
4196
4285
|
}
|
|
4197
|
-
throw
|
|
4286
|
+
throw error;
|
|
4198
4287
|
}
|
|
4199
4288
|
return { signedUrl, metadataResponse, objectStoreResponse };
|
|
4200
4289
|
};
|
|
@@ -4206,9 +4295,9 @@ var Attachment = class extends BaseAttachment {
|
|
|
4206
4295
|
const orgId = _nullishCoalesce(state.orgId, () => ( ""));
|
|
4207
4296
|
try {
|
|
4208
4297
|
await doUpload(conn, orgId);
|
|
4209
|
-
} catch (
|
|
4298
|
+
} catch (error) {
|
|
4210
4299
|
status.upload_status = "error";
|
|
4211
|
-
status.error_message =
|
|
4300
|
+
status.error_message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
4212
4301
|
}
|
|
4213
4302
|
const requestParams = {
|
|
4214
4303
|
key: this.reference.key,
|
|
@@ -4407,8 +4496,8 @@ var ReadonlyAttachment = class {
|
|
|
4407
4496
|
}
|
|
4408
4497
|
const objResponse = await fetch(downloadUrl);
|
|
4409
4498
|
if (objResponse.status !== 200) {
|
|
4410
|
-
const
|
|
4411
|
-
throw new Error(`Couldn't download attachment: ${
|
|
4499
|
+
const error = await objResponse.text();
|
|
4500
|
+
throw new Error(`Couldn't download attachment: ${error}`);
|
|
4412
4501
|
}
|
|
4413
4502
|
return await objResponse.blob();
|
|
4414
4503
|
};
|
|
@@ -4466,7 +4555,7 @@ function logFeedbackImpl(state, parentObjectType, parentObjectId, {
|
|
|
4466
4555
|
if (!VALID_SOURCES.includes(source)) {
|
|
4467
4556
|
throw new Error(`source must be one of ${VALID_SOURCES}`);
|
|
4468
4557
|
}
|
|
4469
|
-
if (
|
|
4558
|
+
if (isEmpty2(scores) && isEmpty2(expected) && isEmpty2(tags) && isEmpty2(comment)) {
|
|
4470
4559
|
throw new Error(
|
|
4471
4560
|
"At least one of scores, expected, tags, or comment must be specified"
|
|
4472
4561
|
);
|
|
@@ -4479,7 +4568,7 @@ function logFeedbackImpl(state, parentObjectType, parentObjectId, {
|
|
|
4479
4568
|
});
|
|
4480
4569
|
let { metadata, ...updateEvent } = deepCopyEvent(validatedEvent);
|
|
4481
4570
|
updateEvent = Object.fromEntries(
|
|
4482
|
-
Object.entries(updateEvent).filter(([_, v]) => !
|
|
4571
|
+
Object.entries(updateEvent).filter(([_, v]) => !isEmpty2(v))
|
|
4483
4572
|
);
|
|
4484
4573
|
const parentIds = async () => new SpanComponentsV3({
|
|
4485
4574
|
object_type: parentObjectType,
|
|
@@ -4498,7 +4587,7 @@ function logFeedbackImpl(state, parentObjectType, parentObjectId, {
|
|
|
4498
4587
|
});
|
|
4499
4588
|
state.bgLogger().log([record]);
|
|
4500
4589
|
}
|
|
4501
|
-
if (!
|
|
4590
|
+
if (!isEmpty2(comment)) {
|
|
4502
4591
|
const record = new LazyValue(async () => {
|
|
4503
4592
|
return {
|
|
4504
4593
|
id: _uuid.v4.call(void 0, ),
|
|
@@ -4612,9 +4701,9 @@ async function permalink(slug, opts) {
|
|
|
4612
4701
|
if (slug === "") {
|
|
4613
4702
|
return NOOP_SPAN_PERMALINK;
|
|
4614
4703
|
}
|
|
4615
|
-
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
4704
|
+
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _34 => _34.state]), () => ( _globalState));
|
|
4616
4705
|
const getOrgName = async () => {
|
|
4617
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
4706
|
+
if (_optionalChain([opts, 'optionalAccess', _35 => _35.orgName])) {
|
|
4618
4707
|
return opts.orgName;
|
|
4619
4708
|
}
|
|
4620
4709
|
await state.login({});
|
|
@@ -4624,7 +4713,7 @@ async function permalink(slug, opts) {
|
|
|
4624
4713
|
return state.orgName;
|
|
4625
4714
|
};
|
|
4626
4715
|
const getAppUrl = async () => {
|
|
4627
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
4716
|
+
if (_optionalChain([opts, 'optionalAccess', _36 => _36.appUrl])) {
|
|
4628
4717
|
return opts.appUrl;
|
|
4629
4718
|
}
|
|
4630
4719
|
await state.login({});
|
|
@@ -4757,7 +4846,7 @@ var Logger = (_class6 = class {
|
|
|
4757
4846
|
* @returns The `id` of the logged event.
|
|
4758
4847
|
*/
|
|
4759
4848
|
log(event, options) {
|
|
4760
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
4849
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _37 => _37.allowConcurrentWithSpans])) {
|
|
4761
4850
|
throw new Error(
|
|
4762
4851
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
|
|
4763
4852
|
);
|
|
@@ -4825,12 +4914,12 @@ var Logger = (_class6 = class {
|
|
|
4825
4914
|
state: this.state,
|
|
4826
4915
|
...startSpanParentArgs({
|
|
4827
4916
|
state: this.state,
|
|
4828
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
4917
|
+
parent: _optionalChain([args, 'optionalAccess', _38 => _38.parent]),
|
|
4829
4918
|
parentObjectType: this.parentObjectType(),
|
|
4830
4919
|
parentObjectId: this.lazyId,
|
|
4831
4920
|
parentComputeObjectMetadataArgs: this.computeMetadataArgs,
|
|
4832
|
-
parentSpanIds: _optionalChain([args, 'optionalAccess',
|
|
4833
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
4921
|
+
parentSpanIds: _optionalChain([args, 'optionalAccess', _39 => _39.parentSpanIds]),
|
|
4922
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _40 => _40.propagatedEvent])
|
|
4834
4923
|
}),
|
|
4835
4924
|
defaultRootType: "task" /* TASK */
|
|
4836
4925
|
});
|
|
@@ -5075,7 +5164,7 @@ var HTTPBackgroundLogger = (_class8 = class _HTTPBackgroundLogger {
|
|
|
5075
5164
|
this.queue.clear();
|
|
5076
5165
|
return;
|
|
5077
5166
|
}
|
|
5078
|
-
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
5167
|
+
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _41 => _41.batchSize]), () => ( this.defaultBatchSize));
|
|
5079
5168
|
const wrappedItems = this.queue.drain();
|
|
5080
5169
|
if (wrappedItems.length === 0) {
|
|
5081
5170
|
return;
|
|
@@ -5135,8 +5224,8 @@ var HTTPBackgroundLogger = (_class8 = class _HTTPBackgroundLogger {
|
|
|
5135
5224
|
if (result.upload_status === "error") {
|
|
5136
5225
|
throw new Error(result.error_message);
|
|
5137
5226
|
}
|
|
5138
|
-
} catch (
|
|
5139
|
-
attachmentErrors.push(
|
|
5227
|
+
} catch (error) {
|
|
5228
|
+
attachmentErrors.push(error);
|
|
5140
5229
|
}
|
|
5141
5230
|
}
|
|
5142
5231
|
if (attachmentErrors.length === 1) {
|
|
@@ -5219,22 +5308,22 @@ var HTTPBackgroundLogger = (_class8 = class _HTTPBackgroundLogger {
|
|
|
5219
5308
|
}
|
|
5220
5309
|
for (let i = 0; i < this.numTries; i++) {
|
|
5221
5310
|
const startTime = now();
|
|
5222
|
-
let
|
|
5311
|
+
let error = void 0;
|
|
5223
5312
|
try {
|
|
5224
5313
|
await conn.post_json("logs3", dataStr);
|
|
5225
5314
|
} catch (e) {
|
|
5226
|
-
|
|
5315
|
+
error = e;
|
|
5227
5316
|
}
|
|
5228
|
-
if (
|
|
5317
|
+
if (error === void 0) {
|
|
5229
5318
|
return;
|
|
5230
5319
|
}
|
|
5231
5320
|
const isRetrying = i + 1 < this.numTries;
|
|
5232
5321
|
const retryingText = isRetrying ? "" : " Retrying";
|
|
5233
5322
|
const errorText = (() => {
|
|
5234
|
-
if (
|
|
5235
|
-
return `${
|
|
5323
|
+
if (error instanceof FailedHTTPResponse) {
|
|
5324
|
+
return `${error.status} (${error.text}): ${error.data}`;
|
|
5236
5325
|
} else {
|
|
5237
|
-
return `${
|
|
5326
|
+
return `${error}`;
|
|
5238
5327
|
}
|
|
5239
5328
|
})();
|
|
5240
5329
|
const errMsg = `log request failed. Elapsed time: ${(now() - startTime) / 1e3} seconds. Payload size: ${dataStr.length}.${retryingText}
|
|
@@ -5340,10 +5429,10 @@ Error: ${errorText}`;
|
|
|
5340
5429
|
} catch (err) {
|
|
5341
5430
|
if (err instanceof AggregateError) {
|
|
5342
5431
|
for (const e of err.errors) {
|
|
5343
|
-
_optionalChain([this, 'access',
|
|
5432
|
+
_optionalChain([this, 'access', _42 => _42.onFlushError, 'optionalCall', _43 => _43(e)]);
|
|
5344
5433
|
}
|
|
5345
5434
|
} else {
|
|
5346
|
-
_optionalChain([this, 'access',
|
|
5435
|
+
_optionalChain([this, 'access', _44 => _44.onFlushError, 'optionalCall', _45 => _45(err)]);
|
|
5347
5436
|
}
|
|
5348
5437
|
this.activeFlushError = err;
|
|
5349
5438
|
} finally {
|
|
@@ -5410,7 +5499,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
5410
5499
|
const state = _nullishCoalesce(stateArg, () => ( _globalState));
|
|
5411
5500
|
state.enforceQueueSizeLimit(false);
|
|
5412
5501
|
if (open) {
|
|
5413
|
-
if (
|
|
5502
|
+
if (isEmpty2(experiment)) {
|
|
5414
5503
|
throw new Error(`Cannot open an experiment without specifying its name`);
|
|
5415
5504
|
}
|
|
5416
5505
|
const lazyMetadata2 = new LazyValue(
|
|
@@ -5649,7 +5738,7 @@ async function computeLoggerMetadata(state, {
|
|
|
5649
5738
|
}) {
|
|
5650
5739
|
await state.login({});
|
|
5651
5740
|
const org_id = state.orgId;
|
|
5652
|
-
if (
|
|
5741
|
+
if (isEmpty2(project_id)) {
|
|
5653
5742
|
const response = await state.appConn().post_json("api/project/register", {
|
|
5654
5743
|
project_name: project_name || GLOBAL_PROJECT,
|
|
5655
5744
|
org_id
|
|
@@ -5662,7 +5751,7 @@ async function computeLoggerMetadata(state, {
|
|
|
5662
5751
|
fullInfo: response.project
|
|
5663
5752
|
}
|
|
5664
5753
|
};
|
|
5665
|
-
} else if (
|
|
5754
|
+
} else if (isEmpty2(project_name)) {
|
|
5666
5755
|
const response = await state.appConn().get_json("api/project", {
|
|
5667
5756
|
id: project_id
|
|
5668
5757
|
});
|
|
@@ -5743,9 +5832,9 @@ async function loadPrompt({
|
|
|
5743
5832
|
);
|
|
5744
5833
|
}
|
|
5745
5834
|
if (id) {
|
|
5746
|
-
} else if (
|
|
5835
|
+
} else if (isEmpty2(projectName) && isEmpty2(projectId)) {
|
|
5747
5836
|
throw new Error("Must specify either projectName or projectId");
|
|
5748
|
-
} else if (
|
|
5837
|
+
} else if (isEmpty2(slug)) {
|
|
5749
5838
|
throw new Error("Must specify slug");
|
|
5750
5839
|
}
|
|
5751
5840
|
const state = _nullishCoalesce(stateArg, () => ( _globalState));
|
|
@@ -5847,7 +5936,7 @@ async function login(options = {}) {
|
|
|
5847
5936
|
const { forceLogin = false } = options || {};
|
|
5848
5937
|
if (_globalState.loggedIn && !forceLogin) {
|
|
5849
5938
|
let checkUpdatedParam2 = function(varname, arg, orig) {
|
|
5850
|
-
if (!
|
|
5939
|
+
if (!isEmpty2(arg) && !isEmpty2(orig) && arg !== orig) {
|
|
5851
5940
|
throw new Error(
|
|
5852
5941
|
`Re-logging in with different ${varname} (${arg}) than original (${orig}). To force re-login, pass \`forceLogin: true\``
|
|
5853
5942
|
);
|
|
@@ -5956,24 +6045,24 @@ async function summarize(options = {}) {
|
|
|
5956
6045
|
return await e.summarize(options);
|
|
5957
6046
|
}
|
|
5958
6047
|
function currentExperiment(options) {
|
|
5959
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6048
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.state]), () => ( _globalState));
|
|
5960
6049
|
return state.currentExperiment;
|
|
5961
6050
|
}
|
|
5962
6051
|
function currentLogger(options) {
|
|
5963
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
5964
|
-
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess',
|
|
6052
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _47 => _47.state]), () => ( _globalState));
|
|
6053
|
+
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _48 => _48.asyncFlush]));
|
|
5965
6054
|
}
|
|
5966
6055
|
function currentSpan(options) {
|
|
5967
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6056
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _49 => _49.state]), () => ( _globalState));
|
|
5968
6057
|
return _nullishCoalesce(state.contextManager.getCurrentSpan(), () => ( NOOP_SPAN));
|
|
5969
6058
|
}
|
|
5970
6059
|
function getSpanParentObject(options) {
|
|
5971
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6060
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _50 => _50.state]), () => ( _globalState));
|
|
5972
6061
|
const parentSpan = currentSpan({ state });
|
|
5973
6062
|
if (!Object.is(parentSpan, NOOP_SPAN)) {
|
|
5974
6063
|
return parentSpan;
|
|
5975
6064
|
}
|
|
5976
|
-
const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6065
|
+
const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.parent]), () => ( state.currentParent.getStore()));
|
|
5977
6066
|
if (parentStr) return getSpanComponentsClass().fromStr(parentStr);
|
|
5978
6067
|
const experiment = currentExperiment();
|
|
5979
6068
|
if (experiment) {
|
|
@@ -5985,14 +6074,14 @@ function getSpanParentObject(options) {
|
|
|
5985
6074
|
}
|
|
5986
6075
|
return NOOP_SPAN;
|
|
5987
6076
|
}
|
|
5988
|
-
function logError(span,
|
|
6077
|
+
function logError(span, error) {
|
|
5989
6078
|
let errorMessage = "<error>";
|
|
5990
6079
|
let stackTrace = "";
|
|
5991
|
-
if (
|
|
5992
|
-
errorMessage =
|
|
5993
|
-
stackTrace =
|
|
6080
|
+
if (error instanceof Error) {
|
|
6081
|
+
errorMessage = error.message;
|
|
6082
|
+
stackTrace = error.stack || "";
|
|
5994
6083
|
} else {
|
|
5995
|
-
errorMessage = String(
|
|
6084
|
+
errorMessage = String(error);
|
|
5996
6085
|
}
|
|
5997
6086
|
span.log({ error: `${errorMessage}
|
|
5998
6087
|
|
|
@@ -6002,7 +6091,7 @@ function traced(callback, args) {
|
|
|
6002
6091
|
const { span, isSyncFlushLogger } = startSpanAndIsLogger(args);
|
|
6003
6092
|
const ret = runCatchFinally(
|
|
6004
6093
|
() => {
|
|
6005
|
-
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
6094
|
+
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _52 => _52.setCurrent]), () => ( true))) {
|
|
6006
6095
|
return withCurrent(span, callback);
|
|
6007
6096
|
} else {
|
|
6008
6097
|
return callback(span);
|
|
@@ -6014,7 +6103,7 @@ function traced(callback, args) {
|
|
|
6014
6103
|
},
|
|
6015
6104
|
() => span.end()
|
|
6016
6105
|
);
|
|
6017
|
-
if (_optionalChain([args, 'optionalAccess',
|
|
6106
|
+
if (_optionalChain([args, 'optionalAccess', _53 => _53.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _54 => _54.asyncFlush])) {
|
|
6018
6107
|
return ret;
|
|
6019
6108
|
} else {
|
|
6020
6109
|
return (async () => {
|
|
@@ -6061,12 +6150,12 @@ function wrapTracedSyncGenerator(fn, spanArgs, noTraceIO) {
|
|
|
6061
6150
|
if (!truncated) {
|
|
6062
6151
|
span.log({ output: collected });
|
|
6063
6152
|
}
|
|
6064
|
-
} catch (
|
|
6065
|
-
logError(span,
|
|
6153
|
+
} catch (error) {
|
|
6154
|
+
logError(span, error);
|
|
6066
6155
|
if (!truncated && collected.length > 0) {
|
|
6067
6156
|
span.log({ output: collected });
|
|
6068
6157
|
}
|
|
6069
|
-
throw
|
|
6158
|
+
throw error;
|
|
6070
6159
|
}
|
|
6071
6160
|
} else {
|
|
6072
6161
|
const gen = generatorWithCurrent(span, fn.apply(this, fnArgs));
|
|
@@ -6110,12 +6199,12 @@ function wrapTracedAsyncGenerator(fn, spanArgs, noTraceIO) {
|
|
|
6110
6199
|
if (!truncated) {
|
|
6111
6200
|
span.log({ output: collected });
|
|
6112
6201
|
}
|
|
6113
|
-
} catch (
|
|
6114
|
-
logError(span,
|
|
6202
|
+
} catch (error) {
|
|
6203
|
+
logError(span, error);
|
|
6115
6204
|
if (!truncated && collected.length > 0) {
|
|
6116
6205
|
span.log({ output: collected });
|
|
6117
6206
|
}
|
|
6118
|
-
throw
|
|
6207
|
+
throw error;
|
|
6119
6208
|
}
|
|
6120
6209
|
} else {
|
|
6121
6210
|
const gen = asyncGeneratorWithCurrent(span, fn.apply(this, fnArgs));
|
|
@@ -6138,14 +6227,14 @@ function wrapTraced(fn, args) {
|
|
|
6138
6227
|
};
|
|
6139
6228
|
const hasExplicitInput = args && args.event && "input" in args.event && args.event.input !== void 0;
|
|
6140
6229
|
const hasExplicitOutput = args && args.event && args.event.output !== void 0;
|
|
6141
|
-
const noTraceIO = _optionalChain([args, 'optionalAccess',
|
|
6230
|
+
const noTraceIO = _optionalChain([args, 'optionalAccess', _55 => _55.noTraceIO]) || hasExplicitInput || hasExplicitOutput;
|
|
6142
6231
|
if (isGeneratorFunction(fn)) {
|
|
6143
6232
|
return wrapTracedSyncGenerator(fn, spanArgs, !!noTraceIO);
|
|
6144
6233
|
}
|
|
6145
6234
|
if (isAsyncGeneratorFunction(fn)) {
|
|
6146
6235
|
return wrapTracedAsyncGenerator(fn, spanArgs, !!noTraceIO);
|
|
6147
6236
|
}
|
|
6148
|
-
if (_optionalChain([args, 'optionalAccess',
|
|
6237
|
+
if (_optionalChain([args, 'optionalAccess', _56 => _56.asyncFlush])) {
|
|
6149
6238
|
return ((...fnArgs) => traced((span) => {
|
|
6150
6239
|
if (!hasExplicitInput) {
|
|
6151
6240
|
span.log({ input: fnArgs });
|
|
@@ -6183,17 +6272,17 @@ function startSpan(args) {
|
|
|
6183
6272
|
return startSpanAndIsLogger(args).span;
|
|
6184
6273
|
}
|
|
6185
6274
|
async function flush(options) {
|
|
6186
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6275
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _57 => _57.state]), () => ( _globalState));
|
|
6187
6276
|
return await state.bgLogger().flush();
|
|
6188
6277
|
}
|
|
6189
6278
|
function setFetch(fetch2) {
|
|
6190
6279
|
_globalState.setFetch(fetch2);
|
|
6191
6280
|
}
|
|
6192
6281
|
function startSpanAndIsLogger(args) {
|
|
6193
|
-
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
6282
|
+
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _58 => _58.state]), () => ( _globalState));
|
|
6194
6283
|
const parentObject = getSpanParentObject({
|
|
6195
|
-
asyncFlush: _optionalChain([args, 'optionalAccess',
|
|
6196
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
6284
|
+
asyncFlush: _optionalChain([args, 'optionalAccess', _59 => _59.asyncFlush]),
|
|
6285
|
+
parent: _optionalChain([args, 'optionalAccess', _60 => _60.parent]),
|
|
6197
6286
|
state
|
|
6198
6287
|
});
|
|
6199
6288
|
if (parentObject instanceof SpanComponentsV3 || parentObject instanceof SpanComponentsV4) {
|
|
@@ -6210,14 +6299,14 @@ function startSpanAndIsLogger(args) {
|
|
|
6210
6299
|
),
|
|
6211
6300
|
parentComputeObjectMetadataArgs: _nullishCoalesce(parentObject.data.compute_object_metadata_args, () => ( void 0)),
|
|
6212
6301
|
parentSpanIds,
|
|
6213
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
6302
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _61 => _61.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
6214
6303
|
(_nullishCoalesce(parentObject.data.propagated_event, () => ( void 0)))))
|
|
6215
6304
|
});
|
|
6216
6305
|
return {
|
|
6217
6306
|
span,
|
|
6218
6307
|
isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
|
|
6219
6308
|
// behavior, and therefore propagate along whatever we get from the arguments
|
|
6220
|
-
_optionalChain([args, 'optionalAccess',
|
|
6309
|
+
_optionalChain([args, 'optionalAccess', _62 => _62.asyncFlush]) === false
|
|
6221
6310
|
};
|
|
6222
6311
|
} else {
|
|
6223
6312
|
const span = parentObject.startSpan(args);
|
|
@@ -6409,10 +6498,10 @@ function extractAttachments(event, attachments) {
|
|
|
6409
6498
|
event[key] = value.reference;
|
|
6410
6499
|
continue;
|
|
6411
6500
|
}
|
|
6412
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
6501
|
+
if (_optionalChain([value, 'optionalAccess', _63 => _63.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
|
|
6413
6502
|
continue;
|
|
6414
6503
|
}
|
|
6415
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
6504
|
+
if (_optionalChain([value, 'optionalAccess', _64 => _64.reference, 'optionalAccess', _65 => _65.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _66 => _66.uploader])) {
|
|
6416
6505
|
const attachment = new Attachment({
|
|
6417
6506
|
data: value.dataDebugString,
|
|
6418
6507
|
filename: value.reference.filename,
|
|
@@ -6456,15 +6545,15 @@ async function resolveAttachmentsToBase64(event, state) {
|
|
|
6456
6545
|
return event;
|
|
6457
6546
|
}
|
|
6458
6547
|
function validateAndSanitizeExperimentLogFullArgs(event, hasDataset) {
|
|
6459
|
-
if ("input" in event && !
|
|
6548
|
+
if ("input" in event && !isEmpty2(event.input) && "inputs" in event && !isEmpty2(event.inputs) || !("input" in event) && !("inputs" in event)) {
|
|
6460
6549
|
throw new Error(
|
|
6461
6550
|
"Exactly one of input or inputs (deprecated) must be specified. Prefer input."
|
|
6462
6551
|
);
|
|
6463
6552
|
}
|
|
6464
|
-
if (
|
|
6553
|
+
if (isEmpty2(event.output)) {
|
|
6465
6554
|
throw new Error("output must be specified");
|
|
6466
6555
|
}
|
|
6467
|
-
if (
|
|
6556
|
+
if (isEmpty2(event.scores)) {
|
|
6468
6557
|
throw new Error("scores must be specified");
|
|
6469
6558
|
}
|
|
6470
6559
|
if (hasDataset && event.datasetRecordId === void 0) {
|
|
@@ -6563,7 +6652,7 @@ var ObjectFetcher = (_class9 = class {
|
|
|
6563
6652
|
}
|
|
6564
6653
|
return;
|
|
6565
6654
|
}
|
|
6566
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
6655
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _67 => _67.batchSize]))) {
|
|
6567
6656
|
yield record;
|
|
6568
6657
|
}
|
|
6569
6658
|
}
|
|
@@ -6573,7 +6662,7 @@ var ObjectFetcher = (_class9 = class {
|
|
|
6573
6662
|
async fetchedData(options) {
|
|
6574
6663
|
if (this._fetchedData === void 0) {
|
|
6575
6664
|
const data = [];
|
|
6576
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
6665
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _68 => _68.batchSize]))) {
|
|
6577
6666
|
data.push(record);
|
|
6578
6667
|
}
|
|
6579
6668
|
this._fetchedData = data;
|
|
@@ -6668,7 +6757,7 @@ var Experiment2 = (_class10 = class extends ObjectFetcher {
|
|
|
6668
6757
|
* @returns The `id` of the logged event.
|
|
6669
6758
|
*/
|
|
6670
6759
|
log(event, options) {
|
|
6671
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
6760
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _69 => _69.allowConcurrentWithSpans])) {
|
|
6672
6761
|
throw new Error(
|
|
6673
6762
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
|
|
6674
6763
|
);
|
|
@@ -6721,12 +6810,12 @@ var Experiment2 = (_class10 = class extends ObjectFetcher {
|
|
|
6721
6810
|
state: this.state,
|
|
6722
6811
|
...startSpanParentArgs({
|
|
6723
6812
|
state: this.state,
|
|
6724
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
6813
|
+
parent: _optionalChain([args, 'optionalAccess', _70 => _70.parent]),
|
|
6725
6814
|
parentObjectType: this.parentObjectType(),
|
|
6726
6815
|
parentObjectId: this.lazyId,
|
|
6727
6816
|
parentComputeObjectMetadataArgs: void 0,
|
|
6728
6817
|
parentSpanIds: void 0,
|
|
6729
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
6818
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _71 => _71.propagatedEvent])
|
|
6730
6819
|
}),
|
|
6731
6820
|
defaultRootType: "eval" /* EVAL */
|
|
6732
6821
|
});
|
|
@@ -7064,10 +7153,10 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7064
7153
|
...serializableInternalData,
|
|
7065
7154
|
[IS_MERGE_FIELD]: this.isMerge
|
|
7066
7155
|
});
|
|
7067
|
-
if (_optionalChain([partialRecord, 'access',
|
|
7068
|
-
this.loggedEndTime = _optionalChain([partialRecord, 'access',
|
|
7156
|
+
if (_optionalChain([partialRecord, 'access', _72 => _72.metrics, 'optionalAccess', _73 => _73.end])) {
|
|
7157
|
+
this.loggedEndTime = _optionalChain([partialRecord, 'access', _74 => _74.metrics, 'optionalAccess', _75 => _75.end]);
|
|
7069
7158
|
}
|
|
7070
|
-
if ((_nullishCoalesce(partialRecord.tags, () => ( []))).length > 0 && _optionalChain([this, 'access',
|
|
7159
|
+
if ((_nullishCoalesce(partialRecord.tags, () => ( []))).length > 0 && _optionalChain([this, 'access', _76 => _76._spanParents, 'optionalAccess', _77 => _77.length])) {
|
|
7071
7160
|
throw new Error("Tags can only be logged to the root span");
|
|
7072
7161
|
}
|
|
7073
7162
|
const computeRecord = async () => ({
|
|
@@ -7112,18 +7201,18 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7112
7201
|
);
|
|
7113
7202
|
}
|
|
7114
7203
|
startSpan(args) {
|
|
7115
|
-
const parentSpanIds = _optionalChain([args, 'optionalAccess',
|
|
7204
|
+
const parentSpanIds = _optionalChain([args, 'optionalAccess', _78 => _78.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
|
|
7116
7205
|
return new _SpanImpl({
|
|
7117
7206
|
state: this._state,
|
|
7118
7207
|
...args,
|
|
7119
7208
|
...startSpanParentArgs({
|
|
7120
7209
|
state: this._state,
|
|
7121
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
7210
|
+
parent: _optionalChain([args, 'optionalAccess', _79 => _79.parent]),
|
|
7122
7211
|
parentObjectType: this.parentObjectType,
|
|
7123
7212
|
parentObjectId: this.parentObjectId,
|
|
7124
7213
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
7125
7214
|
parentSpanIds,
|
|
7126
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7215
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _80 => _80.propagatedEvent]), () => ( this.propagatedEvent))
|
|
7127
7216
|
})
|
|
7128
7217
|
});
|
|
7129
7218
|
}
|
|
@@ -7137,12 +7226,12 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7137
7226
|
...args,
|
|
7138
7227
|
...startSpanParentArgs({
|
|
7139
7228
|
state: this._state,
|
|
7140
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
7229
|
+
parent: _optionalChain([args, 'optionalAccess', _81 => _81.parent]),
|
|
7141
7230
|
parentObjectType: this.parentObjectType,
|
|
7142
7231
|
parentObjectId: this.parentObjectId,
|
|
7143
7232
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
7144
7233
|
parentSpanIds,
|
|
7145
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7234
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _82 => _82.propagatedEvent]), () => ( this.propagatedEvent))
|
|
7146
7235
|
}),
|
|
7147
7236
|
spanId
|
|
7148
7237
|
});
|
|
@@ -7151,7 +7240,7 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7151
7240
|
let endTime;
|
|
7152
7241
|
let internalData = {};
|
|
7153
7242
|
if (!this.loggedEndTime) {
|
|
7154
|
-
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7243
|
+
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _83 => _83.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
7155
7244
|
internalData = { metrics: { end: endTime } };
|
|
7156
7245
|
} else {
|
|
7157
7246
|
endTime = this.loggedEndTime;
|
|
@@ -7194,8 +7283,8 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7194
7283
|
const args = this.parentComputeObjectMetadataArgs;
|
|
7195
7284
|
switch (this.parentObjectType) {
|
|
7196
7285
|
case 2 /* PROJECT_LOGS */: {
|
|
7197
|
-
const projectID = _optionalChain([args, 'optionalAccess',
|
|
7198
|
-
const projectName = _optionalChain([args, 'optionalAccess',
|
|
7286
|
+
const projectID = _optionalChain([args, 'optionalAccess', _84 => _84.project_id]) || this.parentObjectId.getSync().value;
|
|
7287
|
+
const projectName = _optionalChain([args, 'optionalAccess', _85 => _85.project_name]);
|
|
7199
7288
|
if (projectID) {
|
|
7200
7289
|
return `${baseUrl}/object?object_type=project_logs&object_id=${projectID}&id=${this._id}`;
|
|
7201
7290
|
} else if (projectName) {
|
|
@@ -7205,7 +7294,7 @@ var SpanImpl = (_class11 = class _SpanImpl {
|
|
|
7205
7294
|
}
|
|
7206
7295
|
}
|
|
7207
7296
|
case 1 /* EXPERIMENT */: {
|
|
7208
|
-
const expID = _optionalChain([args, 'optionalAccess',
|
|
7297
|
+
const expID = _optionalChain([args, 'optionalAccess', _86 => _86.experiment_id]) || _optionalChain([this, 'access', _87 => _87.parentObjectId, 'optionalAccess', _88 => _88.getSync, 'call', _89 => _89(), 'optionalAccess', _90 => _90.value]);
|
|
7209
7298
|
if (!expID) {
|
|
7210
7299
|
return getErrPermlink("provide-experiment-id");
|
|
7211
7300
|
} else {
|
|
@@ -7524,7 +7613,7 @@ function renderMessage(render, message) {
|
|
|
7524
7613
|
return {
|
|
7525
7614
|
...message,
|
|
7526
7615
|
..."content" in message ? {
|
|
7527
|
-
content:
|
|
7616
|
+
content: isEmpty2(message.content) ? void 0 : typeof message.content === "string" ? render(message.content) : message.content.map((c) => {
|
|
7528
7617
|
switch (c.type) {
|
|
7529
7618
|
case "text":
|
|
7530
7619
|
return { ...c, text: render(c.text) };
|
|
@@ -7561,7 +7650,7 @@ function renderMessage(render, message) {
|
|
|
7561
7650
|
})
|
|
7562
7651
|
} : {},
|
|
7563
7652
|
..."tool_calls" in message ? {
|
|
7564
|
-
tool_calls:
|
|
7653
|
+
tool_calls: isEmpty2(message.tool_calls) ? void 0 : message.tool_calls.map((t) => {
|
|
7565
7654
|
return {
|
|
7566
7655
|
type: t.type,
|
|
7567
7656
|
id: render(t.id),
|
|
@@ -7661,13 +7750,13 @@ var Prompt2 = (_class13 = class _Prompt {
|
|
|
7661
7750
|
return "slug" in this.metadata ? this.metadata.slug : this.metadata.id;
|
|
7662
7751
|
}
|
|
7663
7752
|
get prompt() {
|
|
7664
|
-
return _optionalChain([this, 'access',
|
|
7753
|
+
return _optionalChain([this, 'access', _91 => _91.getParsedPromptData, 'call', _92 => _92(), 'optionalAccess', _93 => _93.prompt]);
|
|
7665
7754
|
}
|
|
7666
7755
|
get version() {
|
|
7667
7756
|
return this.metadata[TRANSACTION_ID_FIELD];
|
|
7668
7757
|
}
|
|
7669
7758
|
get options() {
|
|
7670
|
-
return _optionalChain([this, 'access',
|
|
7759
|
+
return _optionalChain([this, 'access', _94 => _94.getParsedPromptData, 'call', _95 => _95(), 'optionalAccess', _96 => _96.options]) || {};
|
|
7671
7760
|
}
|
|
7672
7761
|
get promptData() {
|
|
7673
7762
|
return this.getParsedPromptData();
|
|
@@ -7710,11 +7799,11 @@ var Prompt2 = (_class13 = class _Prompt {
|
|
|
7710
7799
|
([k, _v]) => !BRAINTRUST_PARAMS.includes(k)
|
|
7711
7800
|
)
|
|
7712
7801
|
),
|
|
7713
|
-
...!
|
|
7802
|
+
...!isEmpty2(this.options.model) ? {
|
|
7714
7803
|
model: this.options.model
|
|
7715
7804
|
} : {}
|
|
7716
7805
|
};
|
|
7717
|
-
if (!("model" in params) ||
|
|
7806
|
+
if (!("model" in params) || isEmpty2(params.model)) {
|
|
7718
7807
|
throw new Error(
|
|
7719
7808
|
"No model specified. Either specify it in the prompt or as a default"
|
|
7720
7809
|
);
|
|
@@ -7818,7 +7907,7 @@ var Prompt2 = (_class13 = class _Prompt {
|
|
|
7818
7907
|
return {
|
|
7819
7908
|
type: "chat",
|
|
7820
7909
|
messages,
|
|
7821
|
-
..._optionalChain([prompt, 'access',
|
|
7910
|
+
..._optionalChain([prompt, 'access', _97 => _97.tools, 'optionalAccess', _98 => _98.trim, 'call', _99 => _99()]) ? {
|
|
7822
7911
|
tools: render(prompt.tools)
|
|
7823
7912
|
} : void 0
|
|
7824
7913
|
};
|
|
@@ -7928,9 +8017,9 @@ async function getPromptVersions(projectId, promptId) {
|
|
|
7928
8017
|
);
|
|
7929
8018
|
}
|
|
7930
8019
|
const result = await response.json();
|
|
7931
|
-
return _optionalChain([result, 'access',
|
|
7932
|
-
(entry) => ["upsert", "merge"].includes(_optionalChain([entry, 'access',
|
|
7933
|
-
), 'access',
|
|
8020
|
+
return _optionalChain([result, 'access', _100 => _100.data, 'optionalAccess', _101 => _101.filter, 'call', _102 => _102(
|
|
8021
|
+
(entry) => ["upsert", "merge"].includes(_optionalChain([entry, 'access', _103 => _103.audit_data, 'optionalAccess', _104 => _104.action]))
|
|
8022
|
+
), 'access', _105 => _105.map, 'call', _106 => _106((entry) => prettifyXact(entry._xact_id))]) || [];
|
|
7934
8023
|
}
|
|
7935
8024
|
function resetIdGenStateForTests() {
|
|
7936
8025
|
const state = _internalGetGlobalState();
|
|
@@ -7964,6 +8053,8 @@ function configureNode() {
|
|
|
7964
8053
|
isomorph_default.processOn = (event, handler) => {
|
|
7965
8054
|
process.on(event, handler);
|
|
7966
8055
|
};
|
|
8056
|
+
isomorph_default.basename = path.basename;
|
|
8057
|
+
isomorph_default.writeln = (text) => process.stdout.write(text + "\n");
|
|
7967
8058
|
isomorph_default.pathJoin = path.join;
|
|
7968
8059
|
isomorph_default.pathDirname = path.dirname;
|
|
7969
8060
|
isomorph_default.mkdir = fs.mkdir;
|
|
@@ -7981,10 +8072,11 @@ function configureNode() {
|
|
|
7981
8072
|
_internalSetInitialState();
|
|
7982
8073
|
}
|
|
7983
8074
|
|
|
7984
|
-
// src/exports
|
|
7985
|
-
var
|
|
7986
|
-
__export(
|
|
8075
|
+
// src/exports.ts
|
|
8076
|
+
var exports_exports = {};
|
|
8077
|
+
__export(exports_exports, {
|
|
7987
8078
|
Attachment: () => Attachment,
|
|
8079
|
+
AttachmentReference: () => AttachmentReference,
|
|
7988
8080
|
BaseAttachment: () => BaseAttachment,
|
|
7989
8081
|
BaseExperiment: () => BaseExperiment,
|
|
7990
8082
|
BraintrustMiddleware: () => BraintrustMiddleware,
|
|
@@ -8036,6 +8128,8 @@ __export(exports_node_exports, {
|
|
|
8036
8128
|
defaultErrorScoreHandler: () => defaultErrorScoreHandler,
|
|
8037
8129
|
deserializePlainStringAsJSON: () => deserializePlainStringAsJSON,
|
|
8038
8130
|
devNullWritableStream: () => devNullWritableStream,
|
|
8131
|
+
evaluatorDefinitionSchema: () => evaluatorDefinitionSchema,
|
|
8132
|
+
evaluatorDefinitionsSchema: () => evaluatorDefinitionsSchema,
|
|
8039
8133
|
flush: () => flush,
|
|
8040
8134
|
getContextManager: () => getContextManager,
|
|
8041
8135
|
getIdGenerator: () => getIdGenerator,
|
|
@@ -8227,7 +8321,7 @@ function parseSpanFromResponseCreateParams(params) {
|
|
|
8227
8321
|
}
|
|
8228
8322
|
function parseEventFromResponseCreateResult(result) {
|
|
8229
8323
|
const data = {};
|
|
8230
|
-
if (_optionalChain([result, 'optionalAccess',
|
|
8324
|
+
if (_optionalChain([result, 'optionalAccess', _107 => _107.output]) !== void 0) {
|
|
8231
8325
|
data.output = processImagesInOutput(result.output);
|
|
8232
8326
|
}
|
|
8233
8327
|
if (result) {
|
|
@@ -8236,7 +8330,7 @@ function parseEventFromResponseCreateResult(result) {
|
|
|
8236
8330
|
data.metadata = metadata;
|
|
8237
8331
|
}
|
|
8238
8332
|
}
|
|
8239
|
-
data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
8333
|
+
data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _108 => _108.usage]));
|
|
8240
8334
|
return data;
|
|
8241
8335
|
}
|
|
8242
8336
|
function processImagesInOutput(output) {
|
|
@@ -8290,7 +8384,7 @@ function parseSpanFromResponseParseParams(params) {
|
|
|
8290
8384
|
}
|
|
8291
8385
|
function parseEventFromResponseParseResult(result) {
|
|
8292
8386
|
const data = {};
|
|
8293
|
-
if (_optionalChain([result, 'optionalAccess',
|
|
8387
|
+
if (_optionalChain([result, 'optionalAccess', _109 => _109.output]) !== void 0) {
|
|
8294
8388
|
data.output = processImagesInOutput(result.output);
|
|
8295
8389
|
}
|
|
8296
8390
|
if (result) {
|
|
@@ -8299,7 +8393,7 @@ function parseEventFromResponseParseResult(result) {
|
|
|
8299
8393
|
data.metadata = metadata;
|
|
8300
8394
|
}
|
|
8301
8395
|
}
|
|
8302
|
-
data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
8396
|
+
data.metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _110 => _110.usage]));
|
|
8303
8397
|
return data;
|
|
8304
8398
|
}
|
|
8305
8399
|
function traceResponseCreateStream(stream, timedSpan) {
|
|
@@ -8316,7 +8410,7 @@ function traceResponseCreateStream(stream, timedSpan) {
|
|
|
8316
8410
|
return result;
|
|
8317
8411
|
}
|
|
8318
8412
|
const item = result.value;
|
|
8319
|
-
if (!item || !_optionalChain([item, 'optionalAccess',
|
|
8413
|
+
if (!item || !_optionalChain([item, 'optionalAccess', _111 => _111.type]) || !_optionalChain([item, 'optionalAccess', _112 => _112.response])) {
|
|
8320
8414
|
return result;
|
|
8321
8415
|
}
|
|
8322
8416
|
const event = parseLogFromItem(item);
|
|
@@ -8327,14 +8421,14 @@ function traceResponseCreateStream(stream, timedSpan) {
|
|
|
8327
8421
|
};
|
|
8328
8422
|
}
|
|
8329
8423
|
function parseLogFromItem(item) {
|
|
8330
|
-
if (!item || !_optionalChain([item, 'optionalAccess',
|
|
8424
|
+
if (!item || !_optionalChain([item, 'optionalAccess', _113 => _113.type]) || !_optionalChain([item, 'optionalAccess', _114 => _114.response])) {
|
|
8331
8425
|
return {};
|
|
8332
8426
|
}
|
|
8333
8427
|
const response = item.response;
|
|
8334
8428
|
switch (item.type) {
|
|
8335
8429
|
case "response.completed":
|
|
8336
8430
|
const data = {};
|
|
8337
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
8431
|
+
if (_optionalChain([response, 'optionalAccess', _115 => _115.output]) !== void 0) {
|
|
8338
8432
|
data.output = processImagesInOutput(response.output);
|
|
8339
8433
|
}
|
|
8340
8434
|
if (response) {
|
|
@@ -8343,7 +8437,7 @@ function parseLogFromItem(item) {
|
|
|
8343
8437
|
data.metadata = metadata;
|
|
8344
8438
|
}
|
|
8345
8439
|
}
|
|
8346
|
-
data.metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess',
|
|
8440
|
+
data.metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _116 => _116.usage]));
|
|
8347
8441
|
return data;
|
|
8348
8442
|
default:
|
|
8349
8443
|
return {};
|
|
@@ -8540,8 +8634,8 @@ function wrapOpenAIv4(openai) {
|
|
|
8540
8634
|
const embeddingProxy = createEndpointProxy(openai.embeddings, wrapEmbeddings);
|
|
8541
8635
|
const moderationProxy = createEndpointProxy(openai.moderations, wrapModerations);
|
|
8542
8636
|
let betaProxy2;
|
|
8543
|
-
if (_optionalChain([openai, 'access',
|
|
8544
|
-
const betaChatCompletionProxy = new Proxy(_optionalChain([openai, 'optionalAccess',
|
|
8637
|
+
if (_optionalChain([openai, 'access', _117 => _117.beta, 'optionalAccess', _118 => _118.chat, 'optionalAccess', _119 => _119.completions, 'optionalAccess', _120 => _120.stream])) {
|
|
8638
|
+
const betaChatCompletionProxy = new Proxy(_optionalChain([openai, 'optionalAccess', _121 => _121.beta, 'optionalAccess', _122 => _122.chat, 'access', _123 => _123.completions]), {
|
|
8545
8639
|
get(target, name, receiver) {
|
|
8546
8640
|
const baseVal = Reflect.get(target, name, receiver);
|
|
8547
8641
|
if (name === "parse") {
|
|
@@ -8589,7 +8683,7 @@ function wrapOpenAIv4(openai) {
|
|
|
8589
8683
|
});
|
|
8590
8684
|
}
|
|
8591
8685
|
function logCompletionResponse(startTime, response, span) {
|
|
8592
|
-
const metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess',
|
|
8686
|
+
const metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _124 => _124.usage]));
|
|
8593
8687
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
8594
8688
|
span.log({
|
|
8595
8689
|
output: response.choices,
|
|
@@ -8662,13 +8756,13 @@ function wrapBetaChatCompletionStream(completion) {
|
|
|
8662
8756
|
var LEGACY_CACHED_HEADER = "x-cached";
|
|
8663
8757
|
var X_CACHED_HEADER = "x-bt-cached";
|
|
8664
8758
|
function parseCachedHeader(value) {
|
|
8665
|
-
return
|
|
8759
|
+
return isEmpty2(value) ? void 0 : ["true", "hit"].includes(value.toLowerCase()) ? 1 : 0;
|
|
8666
8760
|
}
|
|
8667
8761
|
function logHeaders(response, span) {
|
|
8668
8762
|
const cachedHeader = response.headers.get(X_CACHED_HEADER);
|
|
8669
|
-
if (
|
|
8763
|
+
if (isEmpty2(cachedHeader)) {
|
|
8670
8764
|
const legacyCacheHeader = response.headers.get(LEGACY_CACHED_HEADER);
|
|
8671
|
-
if (!
|
|
8765
|
+
if (!isEmpty2(legacyCacheHeader)) {
|
|
8672
8766
|
span.log({
|
|
8673
8767
|
metrics: {
|
|
8674
8768
|
cached: parseCachedHeader(legacyCacheHeader)
|
|
@@ -8819,7 +8913,7 @@ function parseChatCompletionParams(params) {
|
|
|
8819
8913
|
function processEmbeddingResponse(result, span) {
|
|
8820
8914
|
span.log({
|
|
8821
8915
|
output: { embedding_length: result.data[0].embedding.length },
|
|
8822
|
-
metrics: parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
8916
|
+
metrics: parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _125 => _125.usage]))
|
|
8823
8917
|
});
|
|
8824
8918
|
}
|
|
8825
8919
|
function processModerationResponse(result, span) {
|
|
@@ -8849,10 +8943,10 @@ function postprocessStreamingResults(allResults) {
|
|
|
8849
8943
|
if (result.usage) {
|
|
8850
8944
|
metrics = {
|
|
8851
8945
|
...metrics,
|
|
8852
|
-
...parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
8946
|
+
...parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _126 => _126.usage]))
|
|
8853
8947
|
};
|
|
8854
8948
|
}
|
|
8855
|
-
const delta = _optionalChain([result, 'access',
|
|
8949
|
+
const delta = _optionalChain([result, 'access', _127 => _127.choices, 'optionalAccess', _128 => _128[0], 'optionalAccess', _129 => _129.delta]);
|
|
8856
8950
|
if (!delta) {
|
|
8857
8951
|
continue;
|
|
8858
8952
|
}
|
|
@@ -8984,7 +9078,7 @@ function convertDataToBlob(data, mediaType) {
|
|
|
8984
9078
|
} else if (typeof Buffer !== "undefined" && data instanceof Buffer) {
|
|
8985
9079
|
return new Blob([data], { type: mediaType });
|
|
8986
9080
|
}
|
|
8987
|
-
} catch (
|
|
9081
|
+
} catch (error) {
|
|
8988
9082
|
return null;
|
|
8989
9083
|
}
|
|
8990
9084
|
return null;
|
|
@@ -9178,7 +9272,7 @@ var resolveModel = (model, ai) => {
|
|
|
9178
9272
|
if (typeof model !== "string") {
|
|
9179
9273
|
return model;
|
|
9180
9274
|
}
|
|
9181
|
-
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([ai, 'optionalAccess',
|
|
9275
|
+
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([ai, 'optionalAccess', _130 => _130.gateway]))), () => ( null));
|
|
9182
9276
|
if (provider && typeof provider.languageModel === "function") {
|
|
9183
9277
|
return provider.languageModel(model);
|
|
9184
9278
|
}
|
|
@@ -9193,7 +9287,7 @@ var wrapModel = (model, ai) => {
|
|
|
9193
9287
|
return resolvedModel;
|
|
9194
9288
|
}
|
|
9195
9289
|
const originalDoGenerate = resolvedModel.doGenerate.bind(resolvedModel);
|
|
9196
|
-
const originalDoStream = _optionalChain([resolvedModel, 'access',
|
|
9290
|
+
const originalDoStream = _optionalChain([resolvedModel, 'access', _131 => _131.doStream, 'optionalAccess', _132 => _132.bind, 'call', _133 => _133(resolvedModel)]);
|
|
9197
9291
|
const wrappedDoGenerate = async (options) => {
|
|
9198
9292
|
return traced(
|
|
9199
9293
|
async (span) => {
|
|
@@ -9276,9 +9370,9 @@ var wrapModel = (model, ai) => {
|
|
|
9276
9370
|
case "raw":
|
|
9277
9371
|
if (chunk.rawValue) {
|
|
9278
9372
|
const rawVal = chunk.rawValue;
|
|
9279
|
-
if (_optionalChain([rawVal, 'access',
|
|
9373
|
+
if (_optionalChain([rawVal, 'access', _134 => _134.delta, 'optionalAccess', _135 => _135.content])) {
|
|
9280
9374
|
text += rawVal.delta.content;
|
|
9281
|
-
} else if (_optionalChain([rawVal, 'access',
|
|
9375
|
+
} else if (_optionalChain([rawVal, 'access', _136 => _136.choices, 'optionalAccess', _137 => _137[0], 'optionalAccess', _138 => _138.delta, 'optionalAccess', _139 => _139.content])) {
|
|
9282
9376
|
text += rawVal.choices[0].delta.content;
|
|
9283
9377
|
} else if (typeof rawVal.text === "string") {
|
|
9284
9378
|
text += rawVal.text;
|
|
@@ -9400,10 +9494,10 @@ var makeStreamTextWrapper = (name, options, streamText, aiSDK) => {
|
|
|
9400
9494
|
}
|
|
9401
9495
|
});
|
|
9402
9496
|
}
|
|
9403
|
-
_optionalChain([params, 'access',
|
|
9497
|
+
_optionalChain([params, 'access', _140 => _140.onChunk, 'optionalCall', _141 => _141(chunk)]);
|
|
9404
9498
|
},
|
|
9405
9499
|
onFinish: async (event) => {
|
|
9406
|
-
_optionalChain([params, 'access',
|
|
9500
|
+
_optionalChain([params, 'access', _142 => _142.onFinish, 'optionalCall', _143 => _143(event)]);
|
|
9407
9501
|
span.log({
|
|
9408
9502
|
output: await processOutput(event, options.denyOutputPaths),
|
|
9409
9503
|
metrics: extractTokenMetrics(event)
|
|
@@ -9411,7 +9505,7 @@ var makeStreamTextWrapper = (name, options, streamText, aiSDK) => {
|
|
|
9411
9505
|
span.end();
|
|
9412
9506
|
},
|
|
9413
9507
|
onError: async (err) => {
|
|
9414
|
-
_optionalChain([params, 'access',
|
|
9508
|
+
_optionalChain([params, 'access', _144 => _144.onError, 'optionalCall', _145 => _145(err)]);
|
|
9415
9509
|
span.log({
|
|
9416
9510
|
error: serializeError(err)
|
|
9417
9511
|
});
|
|
@@ -9448,12 +9542,12 @@ var makeStreamTextWrapper = (name, options, streamText, aiSDK) => {
|
|
|
9448
9542
|
});
|
|
9449
9543
|
}
|
|
9450
9544
|
return result;
|
|
9451
|
-
} catch (
|
|
9545
|
+
} catch (error) {
|
|
9452
9546
|
span.log({
|
|
9453
|
-
error: serializeError(
|
|
9547
|
+
error: serializeError(error)
|
|
9454
9548
|
});
|
|
9455
9549
|
span.end();
|
|
9456
|
-
throw
|
|
9550
|
+
throw error;
|
|
9457
9551
|
}
|
|
9458
9552
|
};
|
|
9459
9553
|
Object.defineProperty(wrapper, "name", { value: name, writable: false });
|
|
@@ -9498,10 +9592,10 @@ var wrapStreamObject = (streamObject, options = {}, aiSDK) => {
|
|
|
9498
9592
|
}
|
|
9499
9593
|
});
|
|
9500
9594
|
}
|
|
9501
|
-
_optionalChain([params, 'access',
|
|
9595
|
+
_optionalChain([params, 'access', _146 => _146.onChunk, 'optionalCall', _147 => _147(chunk)]);
|
|
9502
9596
|
},
|
|
9503
9597
|
onFinish: async (event) => {
|
|
9504
|
-
_optionalChain([params, 'access',
|
|
9598
|
+
_optionalChain([params, 'access', _148 => _148.onFinish, 'optionalCall', _149 => _149(event)]);
|
|
9505
9599
|
span.log({
|
|
9506
9600
|
output: await processOutput(event, options.denyOutputPaths),
|
|
9507
9601
|
metrics: extractTokenMetrics(event)
|
|
@@ -9509,7 +9603,7 @@ var wrapStreamObject = (streamObject, options = {}, aiSDK) => {
|
|
|
9509
9603
|
span.end();
|
|
9510
9604
|
},
|
|
9511
9605
|
onError: async (err) => {
|
|
9512
|
-
_optionalChain([params, 'access',
|
|
9606
|
+
_optionalChain([params, 'access', _150 => _150.onError, 'optionalCall', _151 => _151(err)]);
|
|
9513
9607
|
span.log({
|
|
9514
9608
|
error: serializeError(err)
|
|
9515
9609
|
});
|
|
@@ -9546,12 +9640,12 @@ var wrapStreamObject = (streamObject, options = {}, aiSDK) => {
|
|
|
9546
9640
|
});
|
|
9547
9641
|
}
|
|
9548
9642
|
return result;
|
|
9549
|
-
} catch (
|
|
9643
|
+
} catch (error) {
|
|
9550
9644
|
span.log({
|
|
9551
|
-
error: serializeError(
|
|
9645
|
+
error: serializeError(error)
|
|
9552
9646
|
});
|
|
9553
9647
|
span.end();
|
|
9554
|
-
throw
|
|
9648
|
+
throw error;
|
|
9555
9649
|
}
|
|
9556
9650
|
};
|
|
9557
9651
|
};
|
|
@@ -9633,20 +9727,20 @@ var wrapToolExecute = (tool, name) => {
|
|
|
9633
9727
|
}
|
|
9634
9728
|
return tool;
|
|
9635
9729
|
};
|
|
9636
|
-
var serializeError = (
|
|
9637
|
-
if (
|
|
9638
|
-
return
|
|
9730
|
+
var serializeError = (error) => {
|
|
9731
|
+
if (error instanceof Error) {
|
|
9732
|
+
return error;
|
|
9639
9733
|
}
|
|
9640
|
-
if (typeof
|
|
9734
|
+
if (typeof error === "object" && error !== null) {
|
|
9641
9735
|
try {
|
|
9642
|
-
return JSON.stringify(
|
|
9736
|
+
return JSON.stringify(error);
|
|
9643
9737
|
} catch (e9) {
|
|
9644
9738
|
}
|
|
9645
9739
|
}
|
|
9646
|
-
return String(
|
|
9740
|
+
return String(error);
|
|
9647
9741
|
};
|
|
9648
9742
|
var serializeModel = (model) => {
|
|
9649
|
-
return typeof model === "string" ? model : _optionalChain([model, 'optionalAccess',
|
|
9743
|
+
return typeof model === "string" ? model : _optionalChain([model, 'optionalAccess', _152 => _152.modelId]);
|
|
9650
9744
|
};
|
|
9651
9745
|
var isZodSchema = (value) => {
|
|
9652
9746
|
return value != null && typeof value === "object" && "_def" in value && typeof value._def === "object";
|
|
@@ -9784,8 +9878,8 @@ var processContentPart = (part) => {
|
|
|
9784
9878
|
}
|
|
9785
9879
|
}
|
|
9786
9880
|
}
|
|
9787
|
-
} catch (
|
|
9788
|
-
console.warn("Error processing content part:",
|
|
9881
|
+
} catch (error) {
|
|
9882
|
+
console.warn("Error processing content part:", error);
|
|
9789
9883
|
}
|
|
9790
9884
|
return part;
|
|
9791
9885
|
};
|
|
@@ -9793,7 +9887,7 @@ var convertImageToAttachment = (image, explicitMimeType) => {
|
|
|
9793
9887
|
try {
|
|
9794
9888
|
if (typeof image === "string" && image.startsWith("data:")) {
|
|
9795
9889
|
const [mimeTypeSection, base64Data] = image.split(",");
|
|
9796
|
-
const mimeType = _optionalChain([mimeTypeSection, 'access',
|
|
9890
|
+
const mimeType = _optionalChain([mimeTypeSection, 'access', _153 => _153.match, 'call', _154 => _154(/data:(.*?);/), 'optionalAccess', _155 => _155[1]]);
|
|
9797
9891
|
if (mimeType && base64Data) {
|
|
9798
9892
|
const blob = convertDataToBlob(base64Data, mimeType);
|
|
9799
9893
|
if (blob) {
|
|
@@ -9831,8 +9925,8 @@ var convertImageToAttachment = (image, explicitMimeType) => {
|
|
|
9831
9925
|
if (image instanceof Attachment) {
|
|
9832
9926
|
return image;
|
|
9833
9927
|
}
|
|
9834
|
-
} catch (
|
|
9835
|
-
console.warn("Error converting image to attachment:",
|
|
9928
|
+
} catch (error) {
|
|
9929
|
+
console.warn("Error converting image to attachment:", error);
|
|
9836
9930
|
}
|
|
9837
9931
|
return null;
|
|
9838
9932
|
};
|
|
@@ -9861,8 +9955,8 @@ var convertDataToAttachment = (data, mimeType, filename) => {
|
|
|
9861
9955
|
contentType: mimeType
|
|
9862
9956
|
});
|
|
9863
9957
|
}
|
|
9864
|
-
} catch (
|
|
9865
|
-
console.warn("Error converting data to attachment:",
|
|
9958
|
+
} catch (error) {
|
|
9959
|
+
console.warn("Error converting data to attachment:", error);
|
|
9866
9960
|
}
|
|
9867
9961
|
return null;
|
|
9868
9962
|
};
|
|
@@ -9899,8 +9993,8 @@ var processOutput = async (output, denyOutputPaths) => {
|
|
|
9899
9993
|
var processOutputAttachments = async (output) => {
|
|
9900
9994
|
try {
|
|
9901
9995
|
return await doProcessOutputAttachments(output);
|
|
9902
|
-
} catch (
|
|
9903
|
-
console.error("Error processing output attachments:",
|
|
9996
|
+
} catch (error) {
|
|
9997
|
+
console.error("Error processing output attachments:", error);
|
|
9904
9998
|
return output;
|
|
9905
9999
|
}
|
|
9906
10000
|
};
|
|
@@ -9945,14 +10039,14 @@ var convertFileToAttachment = (file, index) => {
|
|
|
9945
10039
|
filename,
|
|
9946
10040
|
contentType: mediaType
|
|
9947
10041
|
});
|
|
9948
|
-
} catch (
|
|
9949
|
-
console.warn(`Error processing file at index ${index}:`,
|
|
10042
|
+
} catch (error) {
|
|
10043
|
+
console.warn(`Error processing file at index ${index}:`, error);
|
|
9950
10044
|
return file;
|
|
9951
10045
|
}
|
|
9952
10046
|
};
|
|
9953
10047
|
function extractTokenMetrics(result) {
|
|
9954
10048
|
const metrics = {};
|
|
9955
|
-
const usage = _optionalChain([result, 'optionalAccess',
|
|
10049
|
+
const usage = _optionalChain([result, 'optionalAccess', _156 => _156.usage]);
|
|
9956
10050
|
if (!usage) {
|
|
9957
10051
|
return metrics;
|
|
9958
10052
|
}
|
|
@@ -10002,11 +10096,11 @@ function extractTokenMetrics(result) {
|
|
|
10002
10096
|
var deepCopy = (obj) => {
|
|
10003
10097
|
return JSON.parse(JSON.stringify(obj));
|
|
10004
10098
|
};
|
|
10005
|
-
var parsePath = (
|
|
10099
|
+
var parsePath = (path2) => {
|
|
10006
10100
|
const keys = [];
|
|
10007
10101
|
let current = "";
|
|
10008
|
-
for (let i = 0; i <
|
|
10009
|
-
const char =
|
|
10102
|
+
for (let i = 0; i < path2.length; i++) {
|
|
10103
|
+
const char = path2[i];
|
|
10010
10104
|
if (char === ".") {
|
|
10011
10105
|
if (current) {
|
|
10012
10106
|
keys.push(current);
|
|
@@ -10019,8 +10113,8 @@ var parsePath = (path3) => {
|
|
|
10019
10113
|
}
|
|
10020
10114
|
let bracketContent = "";
|
|
10021
10115
|
i++;
|
|
10022
|
-
while (i <
|
|
10023
|
-
bracketContent +=
|
|
10116
|
+
while (i < path2.length && path2[i] !== "]") {
|
|
10117
|
+
bracketContent += path2[i];
|
|
10024
10118
|
i++;
|
|
10025
10119
|
}
|
|
10026
10120
|
if (bracketContent === "") {
|
|
@@ -10062,8 +10156,8 @@ var omitAtPath = (obj, keys) => {
|
|
|
10062
10156
|
};
|
|
10063
10157
|
var omit = (obj, paths) => {
|
|
10064
10158
|
const result = deepCopy(obj);
|
|
10065
|
-
for (const
|
|
10066
|
-
const keys = parsePath(
|
|
10159
|
+
for (const path2 of paths) {
|
|
10160
|
+
const keys = parsePath(path2);
|
|
10067
10161
|
omitAtPath(result, keys);
|
|
10068
10162
|
}
|
|
10069
10163
|
return result;
|
|
@@ -10072,7 +10166,7 @@ var omit = (obj, paths) => {
|
|
|
10072
10166
|
// src/wrappers/ai-sdk/deprecated/wrapAISDKModel.ts
|
|
10073
10167
|
function wrapAISDKModel(model) {
|
|
10074
10168
|
const m = model;
|
|
10075
|
-
if (_optionalChain([m, 'optionalAccess',
|
|
10169
|
+
if (_optionalChain([m, 'optionalAccess', _157 => _157.specificationVersion]) === "v1" && typeof _optionalChain([m, 'optionalAccess', _158 => _158.provider]) === "string" && typeof _optionalChain([m, 'optionalAccess', _159 => _159.modelId]) === "string") {
|
|
10076
10170
|
return new BraintrustLanguageModelWrapper(m);
|
|
10077
10171
|
} else {
|
|
10078
10172
|
console.warn("Unsupported AI SDK model. Not wrapping.");
|
|
@@ -10128,11 +10222,11 @@ var BraintrustLanguageModelWrapper = class {
|
|
|
10128
10222
|
output: postProcessOutput(ret.text, ret.toolCalls, ret.finishReason),
|
|
10129
10223
|
metrics: {
|
|
10130
10224
|
time_to_first_token: getCurrentUnixTimestamp() - startTime,
|
|
10131
|
-
tokens: !
|
|
10132
|
-
prompt_tokens: _optionalChain([ret, 'access',
|
|
10133
|
-
completion_tokens: _optionalChain([ret, 'access',
|
|
10225
|
+
tokens: !isEmpty2(ret.usage) ? ret.usage.promptTokens + ret.usage.completionTokens : void 0,
|
|
10226
|
+
prompt_tokens: _optionalChain([ret, 'access', _160 => _160.usage, 'optionalAccess', _161 => _161.promptTokens]),
|
|
10227
|
+
completion_tokens: _optionalChain([ret, 'access', _162 => _162.usage, 'optionalAccess', _163 => _163.completionTokens]),
|
|
10134
10228
|
cached: parseCachedHeader(
|
|
10135
|
-
_nullishCoalesce(_optionalChain([ret, 'access',
|
|
10229
|
+
_nullishCoalesce(_optionalChain([ret, 'access', _164 => _164.rawResponse, 'optionalAccess', _165 => _165.headers, 'optionalAccess', _166 => _166[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _167 => _167.rawResponse, 'optionalAccess', _168 => _168.headers, 'optionalAccess', _169 => _169[LEGACY_CACHED_HEADER]])))
|
|
10136
10230
|
)
|
|
10137
10231
|
}
|
|
10138
10232
|
});
|
|
@@ -10223,11 +10317,11 @@ var BraintrustLanguageModelWrapper = class {
|
|
|
10223
10317
|
),
|
|
10224
10318
|
metrics: {
|
|
10225
10319
|
time_to_first_token,
|
|
10226
|
-
tokens: !
|
|
10227
|
-
prompt_tokens: _optionalChain([usage, 'optionalAccess',
|
|
10228
|
-
completion_tokens: _optionalChain([usage, 'optionalAccess',
|
|
10320
|
+
tokens: !isEmpty2(usage) ? usage.promptTokens + usage.completionTokens : void 0,
|
|
10321
|
+
prompt_tokens: _optionalChain([usage, 'optionalAccess', _170 => _170.promptTokens]),
|
|
10322
|
+
completion_tokens: _optionalChain([usage, 'optionalAccess', _171 => _171.completionTokens]),
|
|
10229
10323
|
cached: parseCachedHeader(
|
|
10230
|
-
_nullishCoalesce(_optionalChain([ret, 'access',
|
|
10324
|
+
_nullishCoalesce(_optionalChain([ret, 'access', _172 => _172.rawResponse, 'optionalAccess', _173 => _173.headers, 'optionalAccess', _174 => _174[X_CACHED_HEADER]]), () => ( _optionalChain([ret, 'access', _175 => _175.rawResponse, 'optionalAccess', _176 => _176.headers, 'optionalAccess', _177 => _177[LEGACY_CACHED_HEADER]])))
|
|
10231
10325
|
)
|
|
10232
10326
|
}
|
|
10233
10327
|
});
|
|
@@ -10271,7 +10365,7 @@ function postProcessPrompt(prompt) {
|
|
|
10271
10365
|
return [
|
|
10272
10366
|
{
|
|
10273
10367
|
role: "assistant",
|
|
10274
|
-
content: _optionalChain([textPart, 'optionalAccess',
|
|
10368
|
+
content: _optionalChain([textPart, 'optionalAccess', _178 => _178.text]),
|
|
10275
10369
|
...toolCallParts.length > 0 ? {
|
|
10276
10370
|
tool_calls: toolCallParts.map((part) => ({
|
|
10277
10371
|
id: part.toolCallId,
|
|
@@ -10364,23 +10458,23 @@ function extractAnthropicCacheTokens(cacheReadTokens = 0, cacheCreationTokens =
|
|
|
10364
10458
|
|
|
10365
10459
|
// src/wrappers/ai-sdk/deprecated/BraintrustMiddleware.ts
|
|
10366
10460
|
function detectProviderFromResult(result) {
|
|
10367
|
-
if (!_optionalChain([result, 'optionalAccess',
|
|
10461
|
+
if (!_optionalChain([result, 'optionalAccess', _179 => _179.providerMetadata])) {
|
|
10368
10462
|
return void 0;
|
|
10369
10463
|
}
|
|
10370
10464
|
const keys = Object.keys(result.providerMetadata);
|
|
10371
|
-
return _optionalChain([keys, 'optionalAccess',
|
|
10465
|
+
return _optionalChain([keys, 'optionalAccess', _180 => _180.at, 'call', _181 => _181(0)]);
|
|
10372
10466
|
}
|
|
10373
10467
|
function extractModelFromResult(result) {
|
|
10374
|
-
if (_optionalChain([result, 'optionalAccess',
|
|
10468
|
+
if (_optionalChain([result, 'optionalAccess', _182 => _182.response, 'optionalAccess', _183 => _183.modelId])) {
|
|
10375
10469
|
return result.response.modelId;
|
|
10376
10470
|
}
|
|
10377
|
-
if (_optionalChain([result, 'optionalAccess',
|
|
10471
|
+
if (_optionalChain([result, 'optionalAccess', _184 => _184.request, 'optionalAccess', _185 => _185.body, 'optionalAccess', _186 => _186.model])) {
|
|
10378
10472
|
return result.request.body.model;
|
|
10379
10473
|
}
|
|
10380
10474
|
return void 0;
|
|
10381
10475
|
}
|
|
10382
10476
|
function extractModelFromWrapGenerateCallback(model) {
|
|
10383
|
-
return _optionalChain([model, 'optionalAccess',
|
|
10477
|
+
return _optionalChain([model, 'optionalAccess', _187 => _187.modelId]);
|
|
10384
10478
|
}
|
|
10385
10479
|
function camelToSnake(str) {
|
|
10386
10480
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -10425,7 +10519,7 @@ function normalizeUsageMetrics(usage, provider, providerMetadata) {
|
|
|
10425
10519
|
metrics.prompt_cached_tokens = cachedInputTokens;
|
|
10426
10520
|
}
|
|
10427
10521
|
if (provider === "anthropic") {
|
|
10428
|
-
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess',
|
|
10522
|
+
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess', _188 => _188.anthropic]);
|
|
10429
10523
|
if (anthropicMetadata) {
|
|
10430
10524
|
const cacheReadTokens = getNumberProperty(anthropicMetadata.usage, "cache_read_input_tokens") || 0;
|
|
10431
10525
|
const cacheCreationTokens = getNumberProperty(
|
|
@@ -10451,7 +10545,7 @@ function buildAssistantOutputWithToolCalls(result, toolCalls) {
|
|
|
10451
10545
|
{
|
|
10452
10546
|
index: 0,
|
|
10453
10547
|
logprobs: null,
|
|
10454
|
-
finish_reason: _nullishCoalesce(normalizeFinishReason(_optionalChain([result, 'optionalAccess',
|
|
10548
|
+
finish_reason: _nullishCoalesce(normalizeFinishReason(_optionalChain([result, 'optionalAccess', _189 => _189.finishReason])), () => ( (toolCalls.length ? "tool_calls" : void 0))),
|
|
10455
10549
|
message: {
|
|
10456
10550
|
role: "assistant",
|
|
10457
10551
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
@@ -10464,7 +10558,7 @@ function extractToolCallsFromSteps(steps) {
|
|
|
10464
10558
|
if (!Array.isArray(steps)) return toolCalls;
|
|
10465
10559
|
let idx = 0;
|
|
10466
10560
|
for (const step of steps) {
|
|
10467
|
-
const blocks = _optionalChain([step, 'optionalAccess',
|
|
10561
|
+
const blocks = _optionalChain([step, 'optionalAccess', _190 => _190.content]);
|
|
10468
10562
|
if (!Array.isArray(blocks)) continue;
|
|
10469
10563
|
for (const block of blocks) {
|
|
10470
10564
|
if (block && typeof block === "object" && block.type === "tool-call") {
|
|
@@ -10487,7 +10581,7 @@ function extractToolCallsFromBlocks(blocks) {
|
|
|
10487
10581
|
return extractToolCallsFromSteps([{ content: blocks }]);
|
|
10488
10582
|
}
|
|
10489
10583
|
function extractInput(params) {
|
|
10490
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([params, 'optionalAccess',
|
|
10584
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([params, 'optionalAccess', _191 => _191.prompt]), () => ( _optionalChain([params, 'optionalAccess', _192 => _192.messages]))), () => ( _optionalChain([params, 'optionalAccess', _193 => _193.system])));
|
|
10491
10585
|
}
|
|
10492
10586
|
var V2_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
|
|
10493
10587
|
"prompt",
|
|
@@ -10511,16 +10605,16 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10511
10605
|
const rawInput = extractInput(params);
|
|
10512
10606
|
const processedInput = processInputAttachments(rawInput);
|
|
10513
10607
|
const spanArgs = {
|
|
10514
|
-
name: _optionalChain([config, 'access',
|
|
10608
|
+
name: _optionalChain([config, 'access', _194 => _194.spanInfo, 'optionalAccess', _195 => _195.name]) || "ai-sdk.doGenerate",
|
|
10515
10609
|
spanAttributes: {
|
|
10516
10610
|
type: "llm" /* LLM */,
|
|
10517
|
-
..._optionalChain([config, 'access',
|
|
10611
|
+
..._optionalChain([config, 'access', _196 => _196.spanInfo, 'optionalAccess', _197 => _197.spanAttributes]) || {}
|
|
10518
10612
|
},
|
|
10519
10613
|
event: {
|
|
10520
10614
|
input: processedInput,
|
|
10521
10615
|
metadata: {
|
|
10522
10616
|
...extractModelParameters(params, V2_EXCLUDE_KEYS),
|
|
10523
|
-
..._optionalChain([config, 'access',
|
|
10617
|
+
..._optionalChain([config, 'access', _198 => _198.spanInfo, 'optionalAccess', _199 => _199.metadata]) || {}
|
|
10524
10618
|
}
|
|
10525
10619
|
}
|
|
10526
10620
|
};
|
|
@@ -10546,12 +10640,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10546
10640
|
metadata.model = modelId;
|
|
10547
10641
|
}
|
|
10548
10642
|
}
|
|
10549
|
-
let toolCalls = extractToolCallsFromSteps(_optionalChain([result, 'optionalAccess',
|
|
10643
|
+
let toolCalls = extractToolCallsFromSteps(_optionalChain([result, 'optionalAccess', _200 => _200.steps]));
|
|
10550
10644
|
if (!toolCalls || toolCalls.length === 0) {
|
|
10551
|
-
toolCalls = extractToolCallsFromBlocks(_optionalChain([result, 'optionalAccess',
|
|
10645
|
+
toolCalls = extractToolCallsFromBlocks(_optionalChain([result, 'optionalAccess', _201 => _201.content]));
|
|
10552
10646
|
}
|
|
10553
10647
|
span.log({
|
|
10554
|
-
output: toolCalls.length > 0 ? buildAssistantOutputWithToolCalls(result, toolCalls) : _optionalChain([result, 'optionalAccess',
|
|
10648
|
+
output: toolCalls.length > 0 ? buildAssistantOutputWithToolCalls(result, toolCalls) : _optionalChain([result, 'optionalAccess', _202 => _202.content]),
|
|
10555
10649
|
metadata,
|
|
10556
10650
|
metrics: normalizeUsageMetrics(
|
|
10557
10651
|
result.usage,
|
|
@@ -10560,11 +10654,11 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10560
10654
|
)
|
|
10561
10655
|
});
|
|
10562
10656
|
return result;
|
|
10563
|
-
} catch (
|
|
10657
|
+
} catch (error) {
|
|
10564
10658
|
span.log({
|
|
10565
|
-
error:
|
|
10659
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10566
10660
|
});
|
|
10567
|
-
throw
|
|
10661
|
+
throw error;
|
|
10568
10662
|
} finally {
|
|
10569
10663
|
span.end();
|
|
10570
10664
|
}
|
|
@@ -10573,16 +10667,16 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10573
10667
|
const rawInput = extractInput(params);
|
|
10574
10668
|
const processedInput = processInputAttachments(rawInput);
|
|
10575
10669
|
const spanArgs = {
|
|
10576
|
-
name: _optionalChain([config, 'access',
|
|
10670
|
+
name: _optionalChain([config, 'access', _203 => _203.spanInfo, 'optionalAccess', _204 => _204.name]) || "ai-sdk.doStream",
|
|
10577
10671
|
spanAttributes: {
|
|
10578
10672
|
type: "llm" /* LLM */,
|
|
10579
|
-
..._optionalChain([config, 'access',
|
|
10673
|
+
..._optionalChain([config, 'access', _205 => _205.spanInfo, 'optionalAccess', _206 => _206.spanAttributes]) || {}
|
|
10580
10674
|
},
|
|
10581
10675
|
event: {
|
|
10582
10676
|
input: processedInput,
|
|
10583
10677
|
metadata: {
|
|
10584
10678
|
...extractModelParameters(params, V2_EXCLUDE_KEYS),
|
|
10585
|
-
..._optionalChain([config, 'access',
|
|
10679
|
+
..._optionalChain([config, 'access', _207 => _207.spanInfo, 'optionalAccess', _208 => _208.metadata]) || {}
|
|
10586
10680
|
}
|
|
10587
10681
|
}
|
|
10588
10682
|
};
|
|
@@ -10609,12 +10703,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10609
10703
|
providerMetadata = chunk.providerMetadata || {};
|
|
10610
10704
|
}
|
|
10611
10705
|
controller.enqueue(chunk);
|
|
10612
|
-
} catch (
|
|
10706
|
+
} catch (error) {
|
|
10613
10707
|
span.log({
|
|
10614
|
-
error:
|
|
10708
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10615
10709
|
});
|
|
10616
10710
|
span.end();
|
|
10617
|
-
controller.error(
|
|
10711
|
+
controller.error(error);
|
|
10618
10712
|
}
|
|
10619
10713
|
},
|
|
10620
10714
|
flush() {
|
|
@@ -10660,12 +10754,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10660
10754
|
)
|
|
10661
10755
|
});
|
|
10662
10756
|
span.end();
|
|
10663
|
-
} catch (
|
|
10757
|
+
} catch (error) {
|
|
10664
10758
|
span.log({
|
|
10665
|
-
error:
|
|
10759
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10666
10760
|
});
|
|
10667
10761
|
span.end();
|
|
10668
|
-
throw
|
|
10762
|
+
throw error;
|
|
10669
10763
|
}
|
|
10670
10764
|
}
|
|
10671
10765
|
});
|
|
@@ -10673,12 +10767,12 @@ function BraintrustMiddleware(config = {}) {
|
|
|
10673
10767
|
stream: stream.pipeThrough(transformStream),
|
|
10674
10768
|
...rest
|
|
10675
10769
|
};
|
|
10676
|
-
} catch (
|
|
10770
|
+
} catch (error) {
|
|
10677
10771
|
span.log({
|
|
10678
|
-
error:
|
|
10772
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10679
10773
|
});
|
|
10680
10774
|
span.end();
|
|
10681
|
-
throw
|
|
10775
|
+
throw error;
|
|
10682
10776
|
}
|
|
10683
10777
|
}
|
|
10684
10778
|
};
|
|
@@ -10786,8 +10880,8 @@ function apiPromiseProxy2(apiPromise, span, onThen) {
|
|
|
10786
10880
|
try {
|
|
10787
10881
|
const processed = onThen(result);
|
|
10788
10882
|
return onFulfilled ? onFulfilled(processed) : processed;
|
|
10789
|
-
} catch (
|
|
10790
|
-
return onRejected ? onRejected(
|
|
10883
|
+
} catch (error) {
|
|
10884
|
+
return onRejected ? onRejected(error) : Promise.reject(error);
|
|
10791
10885
|
}
|
|
10792
10886
|
},
|
|
10793
10887
|
onRejected
|
|
@@ -10854,9 +10948,9 @@ function streamNextProxy(stream, sspan) {
|
|
|
10854
10948
|
return result;
|
|
10855
10949
|
}
|
|
10856
10950
|
const item = result.value;
|
|
10857
|
-
switch (_optionalChain([item, 'optionalAccess',
|
|
10951
|
+
switch (_optionalChain([item, 'optionalAccess', _209 => _209.type])) {
|
|
10858
10952
|
case "message_start":
|
|
10859
|
-
const msg = _optionalChain([item, 'optionalAccess',
|
|
10953
|
+
const msg = _optionalChain([item, 'optionalAccess', _210 => _210.message]);
|
|
10860
10954
|
if (msg) {
|
|
10861
10955
|
const event = parseEventFromMessage(msg);
|
|
10862
10956
|
totals = { ...totals, ...event.metrics };
|
|
@@ -10869,20 +10963,20 @@ function streamNextProxy(stream, sspan) {
|
|
|
10869
10963
|
}
|
|
10870
10964
|
break;
|
|
10871
10965
|
case "content_block_delta":
|
|
10872
|
-
if (_optionalChain([item, 'access',
|
|
10873
|
-
const text = _optionalChain([item, 'optionalAccess',
|
|
10966
|
+
if (_optionalChain([item, 'access', _211 => _211.delta, 'optionalAccess', _212 => _212.type]) === "text_delta") {
|
|
10967
|
+
const text = _optionalChain([item, 'optionalAccess', _213 => _213.delta, 'optionalAccess', _214 => _214.text]);
|
|
10874
10968
|
if (text) {
|
|
10875
10969
|
deltas.push(text);
|
|
10876
10970
|
}
|
|
10877
10971
|
}
|
|
10878
10972
|
break;
|
|
10879
10973
|
case "message_delta":
|
|
10880
|
-
const usage = _optionalChain([item, 'optionalAccess',
|
|
10974
|
+
const usage = _optionalChain([item, 'optionalAccess', _215 => _215.usage]);
|
|
10881
10975
|
if (usage) {
|
|
10882
10976
|
const metrics = parseMetricsFromUsage2(usage);
|
|
10883
10977
|
totals = { ...totals, ...metrics };
|
|
10884
10978
|
}
|
|
10885
|
-
const delta = _optionalChain([item, 'optionalAccess',
|
|
10979
|
+
const delta = _optionalChain([item, 'optionalAccess', _216 => _216.delta]);
|
|
10886
10980
|
if (delta) {
|
|
10887
10981
|
metadata = { ...metadata, ...delta };
|
|
10888
10982
|
}
|
|
@@ -10895,7 +10989,7 @@ function streamNextProxy(stream, sspan) {
|
|
|
10895
10989
|
}
|
|
10896
10990
|
function parseEventFromMessage(message) {
|
|
10897
10991
|
const output = message ? { role: message.role, content: message.content } : null;
|
|
10898
|
-
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess',
|
|
10992
|
+
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess', _217 => _217.usage]));
|
|
10899
10993
|
const metas = ["stop_reason", "stop_sequence"];
|
|
10900
10994
|
const metadata = {};
|
|
10901
10995
|
for (const m of metas) {
|
|
@@ -11042,7 +11136,7 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
11042
11136
|
finalResults.push(finalMessageContent);
|
|
11043
11137
|
}
|
|
11044
11138
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
11045
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
11139
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _218 => _218.message, 'optionalAccess', _219 => _219.usage])) {
|
|
11046
11140
|
const outputTokens = getNumberProperty2(lastMessage.message.usage, "output_tokens") || 0;
|
|
11047
11141
|
accumulatedOutputTokens += outputTokens;
|
|
11048
11142
|
}
|
|
@@ -11057,20 +11151,20 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
11057
11151
|
);
|
|
11058
11152
|
for await (const message of generator) {
|
|
11059
11153
|
const currentTime = getCurrentUnixTimestamp();
|
|
11060
|
-
const messageId = _optionalChain([message, 'access',
|
|
11154
|
+
const messageId = _optionalChain([message, 'access', _220 => _220.message, 'optionalAccess', _221 => _221.id]);
|
|
11061
11155
|
if (messageId && messageId !== currentMessageId) {
|
|
11062
11156
|
await createLLMSpan();
|
|
11063
11157
|
currentMessageId = messageId;
|
|
11064
11158
|
currentMessageStartTime = currentTime;
|
|
11065
11159
|
}
|
|
11066
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
11160
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _222 => _222.message, 'optionalAccess', _223 => _223.usage])) {
|
|
11067
11161
|
currentMessages.push(message);
|
|
11068
11162
|
}
|
|
11069
11163
|
if (message.type === "result" && message.usage) {
|
|
11070
11164
|
finalUsageMetrics = _extractUsageFromMessage(message);
|
|
11071
11165
|
if (currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
11072
11166
|
const lastMessage = currentMessages[currentMessages.length - 1];
|
|
11073
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
11167
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _224 => _224.message, 'optionalAccess', _225 => _225.usage])) {
|
|
11074
11168
|
const adjustedTokens = finalUsageMetrics.completion_tokens - accumulatedOutputTokens;
|
|
11075
11169
|
if (adjustedTokens >= 0) {
|
|
11076
11170
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -11096,11 +11190,11 @@ function wrapClaudeAgentQuery(queryFn, defaultThis) {
|
|
|
11096
11190
|
span.log({
|
|
11097
11191
|
output: finalResults.length > 0 ? finalResults[finalResults.length - 1] : void 0
|
|
11098
11192
|
});
|
|
11099
|
-
} catch (
|
|
11193
|
+
} catch (error) {
|
|
11100
11194
|
span.log({
|
|
11101
|
-
error:
|
|
11195
|
+
error: error instanceof Error ? error.message : String(error)
|
|
11102
11196
|
});
|
|
11103
|
-
throw
|
|
11197
|
+
throw error;
|
|
11104
11198
|
} finally {
|
|
11105
11199
|
span.end();
|
|
11106
11200
|
}
|
|
@@ -11151,7 +11245,7 @@ function _extractUsageFromMessage(message) {
|
|
|
11151
11245
|
const metrics = {};
|
|
11152
11246
|
let usage;
|
|
11153
11247
|
if (message.type === "assistant") {
|
|
11154
|
-
usage = _optionalChain([message, 'access',
|
|
11248
|
+
usage = _optionalChain([message, 'access', _226 => _226.message, 'optionalAccess', _227 => _227.usage]);
|
|
11155
11249
|
} else if (message.type === "result") {
|
|
11156
11250
|
usage = message.usage;
|
|
11157
11251
|
}
|
|
@@ -11183,14 +11277,14 @@ function _extractUsageFromMessage(message) {
|
|
|
11183
11277
|
async function _createLLMSpanForMessages(messages, prompt, conversationHistory, options, startTime, parentSpan) {
|
|
11184
11278
|
if (messages.length === 0) return void 0;
|
|
11185
11279
|
const lastMessage = messages[messages.length - 1];
|
|
11186
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
11280
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _228 => _228.message, 'optionalAccess', _229 => _229.usage])) {
|
|
11187
11281
|
return void 0;
|
|
11188
11282
|
}
|
|
11189
11283
|
const model = lastMessage.message.model || options.model;
|
|
11190
11284
|
const usage = _extractUsageFromMessage(lastMessage);
|
|
11191
11285
|
const input = _buildLLMInput(prompt, conversationHistory);
|
|
11192
11286
|
const outputs = messages.map(
|
|
11193
|
-
(m) => _optionalChain([m, 'access',
|
|
11287
|
+
(m) => _optionalChain([m, 'access', _230 => _230.message, 'optionalAccess', _231 => _231.content]) && _optionalChain([m, 'access', _232 => _232.message, 'optionalAccess', _233 => _233.role]) ? { content: m.message.content, role: m.message.role } : void 0
|
|
11194
11288
|
).filter((c) => c !== void 0);
|
|
11195
11289
|
await traced(
|
|
11196
11290
|
(llmSpan) => {
|
|
@@ -11210,7 +11304,7 @@ async function _createLLMSpanForMessages(messages, prompt, conversationHistory,
|
|
|
11210
11304
|
parent: parentSpan
|
|
11211
11305
|
}
|
|
11212
11306
|
);
|
|
11213
|
-
return _optionalChain([lastMessage, 'access',
|
|
11307
|
+
return _optionalChain([lastMessage, 'access', _234 => _234.message, 'optionalAccess', _235 => _235.content]) && _optionalChain([lastMessage, 'access', _236 => _236.message, 'optionalAccess', _237 => _237.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
|
|
11214
11308
|
}
|
|
11215
11309
|
function wrapClaudeAgentSDK(sdk) {
|
|
11216
11310
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -11335,11 +11429,11 @@ function wrapGenerateContent(original) {
|
|
|
11335
11429
|
metrics: cleanMetrics(metrics)
|
|
11336
11430
|
});
|
|
11337
11431
|
return result;
|
|
11338
|
-
} catch (
|
|
11432
|
+
} catch (error) {
|
|
11339
11433
|
span.log({
|
|
11340
|
-
error:
|
|
11434
|
+
error: error instanceof Error ? error.message : String(error)
|
|
11341
11435
|
});
|
|
11342
|
-
throw
|
|
11436
|
+
throw error;
|
|
11343
11437
|
}
|
|
11344
11438
|
},
|
|
11345
11439
|
{
|
|
@@ -11416,14 +11510,14 @@ function asyncGeneratorProxy(generator, input, metadata) {
|
|
|
11416
11510
|
span.end();
|
|
11417
11511
|
}
|
|
11418
11512
|
return result;
|
|
11419
|
-
} catch (
|
|
11513
|
+
} catch (error) {
|
|
11420
11514
|
if (span) {
|
|
11421
11515
|
span.log({
|
|
11422
|
-
error:
|
|
11516
|
+
error: error instanceof Error ? error.message : String(error)
|
|
11423
11517
|
});
|
|
11424
11518
|
span.end();
|
|
11425
11519
|
}
|
|
11426
|
-
throw
|
|
11520
|
+
throw error;
|
|
11427
11521
|
}
|
|
11428
11522
|
};
|
|
11429
11523
|
}
|
|
@@ -11500,7 +11594,7 @@ function serializePart(part) {
|
|
|
11500
11594
|
return part;
|
|
11501
11595
|
}
|
|
11502
11596
|
function serializeTools(params) {
|
|
11503
|
-
if (!_optionalChain([params, 'access',
|
|
11597
|
+
if (!_optionalChain([params, 'access', _238 => _238.config, 'optionalAccess', _239 => _239.tools])) {
|
|
11504
11598
|
return null;
|
|
11505
11599
|
}
|
|
11506
11600
|
try {
|
|
@@ -11583,7 +11677,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
11583
11677
|
}
|
|
11584
11678
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
11585
11679
|
for (const candidate of chunk.candidates) {
|
|
11586
|
-
if (_optionalChain([candidate, 'access',
|
|
11680
|
+
if (_optionalChain([candidate, 'access', _240 => _240.content, 'optionalAccess', _241 => _241.parts])) {
|
|
11587
11681
|
for (const part of candidate.content.parts) {
|
|
11588
11682
|
if (part.text !== void 0) {
|
|
11589
11683
|
if (part.thought) {
|
|
@@ -11614,7 +11708,7 @@ function aggregateGenerateContentChunks(chunks, start, firstTokenTime) {
|
|
|
11614
11708
|
parts.push({ text });
|
|
11615
11709
|
}
|
|
11616
11710
|
parts.push(...otherParts);
|
|
11617
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
11711
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _242 => _242.candidates])) {
|
|
11618
11712
|
const candidates = [];
|
|
11619
11713
|
for (const candidate of lastResponse.candidates) {
|
|
11620
11714
|
const candidateDict = {
|
|
@@ -11949,9 +12043,9 @@ function escapePath(parts) {
|
|
|
11949
12043
|
return part;
|
|
11950
12044
|
}).join(".");
|
|
11951
12045
|
}
|
|
11952
|
-
function unescapePath(
|
|
12046
|
+
function unescapePath(path2) {
|
|
11953
12047
|
const regex = /"((?:\\["\\]|[^"\\])*)"|([^\.]+)/g;
|
|
11954
|
-
const matches =
|
|
12048
|
+
const matches = path2.match(regex);
|
|
11955
12049
|
return matches ? matches.map((match) => {
|
|
11956
12050
|
if (match.startsWith('"')) {
|
|
11957
12051
|
return match.slice(1, -1).replace(/\\(["\\])/g, "$1");
|
|
@@ -12017,9 +12111,9 @@ function handlePromise(promise, callback) {
|
|
|
12017
12111
|
invokeCallback(callback, err && (err instanceof Error || err.message) ? err : new Error(err));
|
|
12018
12112
|
});
|
|
12019
12113
|
}
|
|
12020
|
-
function invokeCallback(callback,
|
|
12114
|
+
function invokeCallback(callback, error, value) {
|
|
12021
12115
|
try {
|
|
12022
|
-
callback(
|
|
12116
|
+
callback(error, value);
|
|
12023
12117
|
} catch (err) {
|
|
12024
12118
|
setImmediate$1((e) => {
|
|
12025
12119
|
throw e;
|
|
@@ -12941,7 +13035,7 @@ function sortBy(coll, iteratee, callback) {
|
|
|
12941
13035
|
}
|
|
12942
13036
|
var sortBy$1 = awaitify(sortBy, 3);
|
|
12943
13037
|
function tryEach(tasks, callback) {
|
|
12944
|
-
var
|
|
13038
|
+
var error = null;
|
|
12945
13039
|
var result;
|
|
12946
13040
|
return eachSeries$1(tasks, (task, taskCb) => {
|
|
12947
13041
|
wrapAsync(task)((err, ...args) => {
|
|
@@ -12951,10 +13045,10 @@ function tryEach(tasks, callback) {
|
|
|
12951
13045
|
} else {
|
|
12952
13046
|
result = args;
|
|
12953
13047
|
}
|
|
12954
|
-
|
|
13048
|
+
error = err;
|
|
12955
13049
|
taskCb(err ? null : {});
|
|
12956
13050
|
});
|
|
12957
|
-
}, () => callback(
|
|
13051
|
+
}, () => callback(error, result));
|
|
12958
13052
|
}
|
|
12959
13053
|
var tryEach$1 = awaitify(tryEach);
|
|
12960
13054
|
function whilst(test, iteratee, callback) {
|
|
@@ -12997,78 +13091,40 @@ function waterfall(tasks, callback) {
|
|
|
12997
13091
|
}
|
|
12998
13092
|
var waterfall$1 = awaitify(waterfall);
|
|
12999
13093
|
|
|
13000
|
-
// src/
|
|
13001
|
-
var
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
var _pluralize = require('pluralize'); var _pluralize2 = _interopRequireDefault(_pluralize);
|
|
13005
|
-
var _clitable3 = require('cli-table3'); var _clitable32 = _interopRequireDefault(_clitable3);
|
|
13006
|
-
|
|
13007
|
-
// src/progress.ts
|
|
13008
|
-
|
|
13009
|
-
var _cliprogress = require('cli-progress'); var cliProgress = _interopRequireWildcard(_cliprogress);
|
|
13010
|
-
var MAX_NAME_LENGTH = 40;
|
|
13011
|
-
function fitNameToSpaces(name, length) {
|
|
13012
|
-
const padded = name.padEnd(length);
|
|
13013
|
-
if (padded.length <= length) {
|
|
13014
|
-
return padded;
|
|
13015
|
-
}
|
|
13016
|
-
return padded.substring(0, length - 3) + "...";
|
|
13017
|
-
}
|
|
13018
|
-
var BarProgressReporter = (_class16 = class {
|
|
13019
|
-
|
|
13020
|
-
__init52() {this.bars = {}}
|
|
13021
|
-
constructor() {;_class16.prototype.__init52.call(this);
|
|
13022
|
-
this.multiBar = new cliProgress.MultiBar(
|
|
13023
|
-
{
|
|
13024
|
-
// clearOnComplete: true,
|
|
13025
|
-
format: `${_chalk2.default.blueBright("{bar}")} ${_chalk2.default.blue("{evaluator}")} {percentage}% ${_chalk2.default.gray("{value}/{total} {eta_formatted}")}`,
|
|
13026
|
-
// autopadding: true,
|
|
13027
|
-
hideCursor: true,
|
|
13028
|
-
barsize: 10
|
|
13029
|
-
},
|
|
13030
|
-
cliProgress.Presets.shades_grey
|
|
13031
|
-
);
|
|
13032
|
-
}
|
|
13033
|
-
start(name, total) {
|
|
13034
|
-
const bar = this.multiBar.create(total, 0);
|
|
13035
|
-
this.bars[name] = bar;
|
|
13094
|
+
// src/reporters/progress.ts
|
|
13095
|
+
var SimpleProgressReporter = class {
|
|
13096
|
+
start(name, _total) {
|
|
13097
|
+
console.log(`Running evaluator ${name}`);
|
|
13036
13098
|
}
|
|
13037
13099
|
stop() {
|
|
13038
|
-
this.multiBar.stop();
|
|
13039
13100
|
}
|
|
13040
|
-
increment(
|
|
13041
|
-
this.bars[name].increment({
|
|
13042
|
-
evaluator: fitNameToSpaces(name, MAX_NAME_LENGTH)
|
|
13043
|
-
});
|
|
13101
|
+
increment(_name) {
|
|
13044
13102
|
}
|
|
13045
|
-
setTotal(
|
|
13046
|
-
this.bars[name].setTotal(total);
|
|
13103
|
+
setTotal(_name, _total) {
|
|
13047
13104
|
}
|
|
13048
|
-
}
|
|
13105
|
+
};
|
|
13049
13106
|
|
|
13050
13107
|
// src/eval-parameters.ts
|
|
13051
13108
|
|
|
13052
13109
|
|
|
13053
13110
|
// src/framework2.ts
|
|
13054
13111
|
|
|
13055
|
-
var
|
|
13056
|
-
|
|
13112
|
+
var currentFilename = typeof __filename !== "undefined" ? __filename : "unknown";
|
|
13057
13113
|
var ProjectBuilder = class {
|
|
13058
13114
|
create(opts) {
|
|
13059
13115
|
return new Project2(opts);
|
|
13060
13116
|
}
|
|
13061
13117
|
};
|
|
13062
13118
|
var projects = new ProjectBuilder();
|
|
13063
|
-
var Project2 = (
|
|
13119
|
+
var Project2 = (_class16 = class {
|
|
13064
13120
|
|
|
13065
13121
|
|
|
13066
13122
|
|
|
13067
13123
|
|
|
13068
13124
|
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
constructor(args) {;
|
|
13125
|
+
__init52() {this._publishableCodeFunctions = []}
|
|
13126
|
+
__init53() {this._publishablePrompts = []}
|
|
13127
|
+
constructor(args) {;_class16.prototype.__init52.call(this);_class16.prototype.__init53.call(this);
|
|
13072
13128
|
_initializeSpanContext();
|
|
13073
13129
|
this.name = "name" in args ? args.name : void 0;
|
|
13074
13130
|
this.id = "id" in args ? args.id : void 0;
|
|
@@ -13111,12 +13167,12 @@ var Project2 = (_class17 = class {
|
|
|
13111
13167
|
functions: functionDefinitions
|
|
13112
13168
|
});
|
|
13113
13169
|
}
|
|
13114
|
-
},
|
|
13115
|
-
var ToolBuilder = (
|
|
13116
|
-
constructor(project) {;
|
|
13170
|
+
}, _class16);
|
|
13171
|
+
var ToolBuilder = (_class17 = class {
|
|
13172
|
+
constructor(project) {;_class17.prototype.__init54.call(this);
|
|
13117
13173
|
this.project = project;
|
|
13118
13174
|
}
|
|
13119
|
-
|
|
13175
|
+
__init54() {this.taskCounter = 0}
|
|
13120
13176
|
// This type definition is just a catch all so that the implementation can be
|
|
13121
13177
|
// less specific than the two more specific declarations above.
|
|
13122
13178
|
create(opts) {
|
|
@@ -13125,12 +13181,12 @@ var ToolBuilder = (_class18 = class {
|
|
|
13125
13181
|
const { handler, name, slug, parameters, returns, ...rest } = opts;
|
|
13126
13182
|
let resolvedName = _nullishCoalesce(name, () => ( handler.name));
|
|
13127
13183
|
if (resolvedName.trim().length === 0) {
|
|
13128
|
-
resolvedName = `Tool ${
|
|
13184
|
+
resolvedName = `Tool ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
|
|
13129
13185
|
}
|
|
13130
13186
|
const tool = new CodeFunction(this.project, {
|
|
13131
13187
|
handler,
|
|
13132
13188
|
name: resolvedName,
|
|
13133
|
-
slug: _nullishCoalesce(slug, () => (
|
|
13189
|
+
slug: _nullishCoalesce(slug, () => ( slugify(resolvedName, { lower: true, strict: true }))),
|
|
13134
13190
|
type: "tool",
|
|
13135
13191
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
13136
13192
|
parameters,
|
|
@@ -13141,12 +13197,12 @@ var ToolBuilder = (_class18 = class {
|
|
|
13141
13197
|
this.project.addCodeFunction(tool);
|
|
13142
13198
|
return tool;
|
|
13143
13199
|
}
|
|
13144
|
-
},
|
|
13145
|
-
var ScorerBuilder = (
|
|
13146
|
-
constructor(project) {;
|
|
13200
|
+
}, _class17);
|
|
13201
|
+
var ScorerBuilder = (_class18 = class {
|
|
13202
|
+
constructor(project) {;_class18.prototype.__init55.call(this);
|
|
13147
13203
|
this.project = project;
|
|
13148
13204
|
}
|
|
13149
|
-
|
|
13205
|
+
__init55() {this.taskCounter = 0}
|
|
13150
13206
|
create(opts) {
|
|
13151
13207
|
this.taskCounter++;
|
|
13152
13208
|
let resolvedName = opts.name;
|
|
@@ -13154,9 +13210,9 @@ var ScorerBuilder = (_class19 = class {
|
|
|
13154
13210
|
resolvedName = opts.handler.name;
|
|
13155
13211
|
}
|
|
13156
13212
|
if (!resolvedName || resolvedName.trim().length === 0) {
|
|
13157
|
-
resolvedName = `Scorer ${
|
|
13213
|
+
resolvedName = `Scorer ${isomorph_default.basename(currentFilename)} ${this.taskCounter}`;
|
|
13158
13214
|
}
|
|
13159
|
-
const slug = _nullishCoalesce(opts.slug, () => (
|
|
13215
|
+
const slug = _nullishCoalesce(opts.slug, () => ( slugify(resolvedName, { lower: true, strict: true })));
|
|
13160
13216
|
if ("handler" in opts) {
|
|
13161
13217
|
const scorer = new CodeFunction(this.project, {
|
|
13162
13218
|
...opts,
|
|
@@ -13199,7 +13255,7 @@ var ScorerBuilder = (_class19 = class {
|
|
|
13199
13255
|
this.project.addPrompt(codePrompt);
|
|
13200
13256
|
}
|
|
13201
13257
|
}
|
|
13202
|
-
},
|
|
13258
|
+
}, _class18);
|
|
13203
13259
|
var CodeFunction = class {
|
|
13204
13260
|
constructor(project, opts) {
|
|
13205
13261
|
this.project = project;
|
|
@@ -13327,7 +13383,7 @@ var PromptBuilder = class {
|
|
|
13327
13383
|
rawTools.push(tool);
|
|
13328
13384
|
}
|
|
13329
13385
|
}
|
|
13330
|
-
const slug = _nullishCoalesce(opts.slug, () => (
|
|
13386
|
+
const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
|
|
13331
13387
|
const promptData = promptDefinitionToPromptData(opts, rawTools);
|
|
13332
13388
|
const promptRow = {
|
|
13333
13389
|
id: opts.id,
|
|
@@ -13368,9 +13424,9 @@ function promptDefinitionToPromptData(promptDefinition, rawTools) {
|
|
|
13368
13424
|
}
|
|
13369
13425
|
};
|
|
13370
13426
|
}
|
|
13371
|
-
var ProjectNameIdMap = (
|
|
13372
|
-
|
|
13373
|
-
|
|
13427
|
+
var ProjectNameIdMap = (_class19 = class {constructor() { _class19.prototype.__init56.call(this);_class19.prototype.__init57.call(this); }
|
|
13428
|
+
__init56() {this.nameToId = {}}
|
|
13429
|
+
__init57() {this.idToName = {}}
|
|
13374
13430
|
async getId(projectName) {
|
|
13375
13431
|
if (!(projectName in this.nameToId)) {
|
|
13376
13432
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
|
|
@@ -13403,7 +13459,7 @@ var ProjectNameIdMap = (_class20 = class {constructor() { _class20.prototype.__i
|
|
|
13403
13459
|
}
|
|
13404
13460
|
return this.getId(project.name);
|
|
13405
13461
|
}
|
|
13406
|
-
},
|
|
13462
|
+
}, _class19);
|
|
13407
13463
|
|
|
13408
13464
|
// src/eval-parameters.ts
|
|
13409
13465
|
var evalParametersSchema = _v3.z.record(
|
|
@@ -13455,8 +13511,11 @@ var EvalResultWithSummary = class {
|
|
|
13455
13511
|
this.summary = summary;
|
|
13456
13512
|
this.results = results;
|
|
13457
13513
|
}
|
|
13514
|
+
/**
|
|
13515
|
+
* @deprecated Use `summary` instead.
|
|
13516
|
+
*/
|
|
13458
13517
|
toString() {
|
|
13459
|
-
return
|
|
13518
|
+
return JSON.stringify(this.summary);
|
|
13460
13519
|
}
|
|
13461
13520
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
13462
13521
|
return `EvalResultWithSummary(summary="...", results=[...])`;
|
|
@@ -13509,7 +13568,7 @@ function _initializeSpanContext() {
|
|
|
13509
13568
|
globalThis._spanContext = { currentSpan, withCurrent, startSpan, NOOP_SPAN };
|
|
13510
13569
|
}
|
|
13511
13570
|
async function Eval(name, evaluator, reporterOrOpts) {
|
|
13512
|
-
const options =
|
|
13571
|
+
const options = isEmpty2(reporterOrOpts) ? {} : typeof reporterOrOpts === "string" ? { reporter: reporterOrOpts } : "name" in reporterOrOpts ? { reporter: reporterOrOpts } : reporterOrOpts;
|
|
13513
13572
|
let evalName = makeEvalName(name, evaluator.experimentName);
|
|
13514
13573
|
if (globalThis._evals.evaluators[evalName]) {
|
|
13515
13574
|
evalName = `${evalName}_${Object.keys(_evals).length}`;
|
|
@@ -13535,7 +13594,7 @@ async function Eval(name, evaluator, reporterOrOpts) {
|
|
|
13535
13594
|
[]
|
|
13536
13595
|
);
|
|
13537
13596
|
}
|
|
13538
|
-
const progressReporter = _nullishCoalesce(options.progress, () => ( new
|
|
13597
|
+
const progressReporter = _nullishCoalesce(options.progress, () => ( new SimpleProgressReporter()));
|
|
13539
13598
|
const shouldCollectResults = _nullishCoalesce(options.returnResults, () => ( true));
|
|
13540
13599
|
if (typeof options.reporter === "string") {
|
|
13541
13600
|
throw new Error(
|
|
@@ -13635,8 +13694,8 @@ function serializeJSONWithPlainString(v) {
|
|
|
13635
13694
|
}
|
|
13636
13695
|
}
|
|
13637
13696
|
function evaluateFilter(object, filter2) {
|
|
13638
|
-
const { path:
|
|
13639
|
-
const key =
|
|
13697
|
+
const { path: path2, pattern } = filter2;
|
|
13698
|
+
const key = path2.reduce(
|
|
13640
13699
|
(acc, p) => typeof acc === "object" && acc !== null ? (
|
|
13641
13700
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
13642
13701
|
acc[p]
|
|
@@ -13687,7 +13746,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13687
13746
|
);
|
|
13688
13747
|
}
|
|
13689
13748
|
let name = dataResult.name;
|
|
13690
|
-
if (
|
|
13749
|
+
if (isEmpty2(name)) {
|
|
13691
13750
|
const baseExperiment = await experiment.fetchBaseExperiment();
|
|
13692
13751
|
if (!baseExperiment) {
|
|
13693
13752
|
throw new Error("BaseExperiment() failed to fetch base experiment");
|
|
@@ -13756,7 +13815,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13756
13815
|
};
|
|
13757
13816
|
const expected = "expected" in datum ? datum.expected : void 0;
|
|
13758
13817
|
let output = void 0;
|
|
13759
|
-
let
|
|
13818
|
+
let error = void 0;
|
|
13760
13819
|
let tags = [..._nullishCoalesce(datum.tags, () => ( []))];
|
|
13761
13820
|
const scores = {};
|
|
13762
13821
|
const scorerNames = evaluator.scores.map(scorerName);
|
|
@@ -13772,10 +13831,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13772
13831
|
span,
|
|
13773
13832
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
13774
13833
|
reportProgress: (event) => {
|
|
13775
|
-
_optionalChain([stream, 'optionalCall',
|
|
13834
|
+
_optionalChain([stream, 'optionalCall', _243 => _243({
|
|
13776
13835
|
...event,
|
|
13777
13836
|
id: rootSpan.id,
|
|
13778
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
13837
|
+
origin: _optionalChain([baseEvent, 'access', _244 => _244.event, 'optionalAccess', _245 => _245.origin]),
|
|
13779
13838
|
name: evaluator.evalName,
|
|
13780
13839
|
object_type: "task"
|
|
13781
13840
|
})]);
|
|
@@ -13820,7 +13879,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13820
13879
|
}
|
|
13821
13880
|
if (Array.isArray(scoreValue)) {
|
|
13822
13881
|
for (const s of scoreValue) {
|
|
13823
|
-
if (!(typeof s === "object" && !
|
|
13882
|
+
if (!(typeof s === "object" && !isEmpty2(s))) {
|
|
13824
13883
|
throw new Error(
|
|
13825
13884
|
`When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(
|
|
13826
13885
|
s
|
|
@@ -13829,7 +13888,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13829
13888
|
}
|
|
13830
13889
|
}
|
|
13831
13890
|
}
|
|
13832
|
-
const results2 = Array.isArray(scoreValue) ? scoreValue : typeof scoreValue === "object" && !
|
|
13891
|
+
const results2 = Array.isArray(scoreValue) ? scoreValue : typeof scoreValue === "object" && !isEmpty2(scoreValue) ? [scoreValue] : [
|
|
13833
13892
|
{
|
|
13834
13893
|
name: scorerNames[score_idx],
|
|
13835
13894
|
score: scoreValue
|
|
@@ -13887,9 +13946,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13887
13946
|
unhandledScores = null;
|
|
13888
13947
|
if (failingScorersAndResults.length) {
|
|
13889
13948
|
const scorerErrors = Object.fromEntries(
|
|
13890
|
-
failingScorersAndResults.map(({ name, error:
|
|
13949
|
+
failingScorersAndResults.map(({ name, error: error2 }) => [
|
|
13891
13950
|
name,
|
|
13892
|
-
|
|
13951
|
+
error2 instanceof Error ? error2.stack : `${error2}`
|
|
13893
13952
|
])
|
|
13894
13953
|
);
|
|
13895
13954
|
metadata["scorer_errors"] = scorerErrors;
|
|
@@ -13906,7 +13965,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13906
13965
|
}
|
|
13907
13966
|
} catch (e) {
|
|
13908
13967
|
logError(rootSpan, e);
|
|
13909
|
-
|
|
13968
|
+
error = e;
|
|
13910
13969
|
} finally {
|
|
13911
13970
|
progressReporter.increment(evaluator.evalName);
|
|
13912
13971
|
}
|
|
@@ -13929,8 +13988,8 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13929
13988
|
tags: tags.length ? tags : void 0,
|
|
13930
13989
|
metadata,
|
|
13931
13990
|
scores: mergedScores,
|
|
13932
|
-
error
|
|
13933
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
13991
|
+
error,
|
|
13992
|
+
origin: _optionalChain([baseEvent, 'access', _246 => _246.event, 'optionalAccess', _247 => _247.origin])
|
|
13934
13993
|
});
|
|
13935
13994
|
}
|
|
13936
13995
|
};
|
|
@@ -13963,7 +14022,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13963
14022
|
break;
|
|
13964
14023
|
}
|
|
13965
14024
|
scheduledTrials++;
|
|
13966
|
-
_optionalChain([progressReporter, 'access',
|
|
14025
|
+
_optionalChain([progressReporter, 'access', _248 => _248.setTotal, 'optionalCall', _249 => _249(evaluator.evalName, scheduledTrials)]);
|
|
13967
14026
|
q.push({ datum, trialIndex });
|
|
13968
14027
|
}
|
|
13969
14028
|
}
|
|
@@ -13976,7 +14035,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13976
14035
|
}
|
|
13977
14036
|
let timeoutId;
|
|
13978
14037
|
let abortHandler;
|
|
13979
|
-
const rejectOnce = (
|
|
14038
|
+
const rejectOnce = (error) => {
|
|
13980
14039
|
if (cancelled) {
|
|
13981
14040
|
return;
|
|
13982
14041
|
}
|
|
@@ -13988,7 +14047,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
13988
14047
|
if (abortHandler && evaluator.signal) {
|
|
13989
14048
|
evaluator.signal.removeEventListener("abort", abortHandler);
|
|
13990
14049
|
}
|
|
13991
|
-
reject2(
|
|
14050
|
+
reject2(error);
|
|
13992
14051
|
};
|
|
13993
14052
|
if (evaluator.timeout) {
|
|
13994
14053
|
timeoutId = setTimeout(() => {
|
|
@@ -14015,7 +14074,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
14015
14074
|
} catch (e) {
|
|
14016
14075
|
q.kill();
|
|
14017
14076
|
if (e instanceof InternalAbortError) {
|
|
14018
|
-
if (
|
|
14077
|
+
if (isomorph_default.getEnv("BRAINTRUST_VERBOSE")) {
|
|
14019
14078
|
console.warn("Evaluator cancelled:", e.message);
|
|
14020
14079
|
}
|
|
14021
14080
|
}
|
|
@@ -14035,8 +14094,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
14035
14094
|
collectResults ? collectedResults : []
|
|
14036
14095
|
);
|
|
14037
14096
|
}
|
|
14038
|
-
var
|
|
14039
|
-
var warning = _chalk2.default.yellow;
|
|
14097
|
+
var warning = (text) => `Warning: ${text}`;
|
|
14040
14098
|
function logError2(e, verbose) {
|
|
14041
14099
|
if (!verbose) {
|
|
14042
14100
|
console.error(`${e}`);
|
|
@@ -14085,11 +14143,7 @@ function reportFailures(evaluator, failingResults, { verbose, jsonl }) {
|
|
|
14085
14143
|
if (failingResults.length > 0) {
|
|
14086
14144
|
console.error(
|
|
14087
14145
|
warning(
|
|
14088
|
-
`Evaluator ${evaluator.evalName} failed with ${
|
|
14089
|
-
"error",
|
|
14090
|
-
failingResults.length,
|
|
14091
|
-
true
|
|
14092
|
-
)}. This evaluation ("${evaluator.evalName}") will not be fully logged.`
|
|
14146
|
+
`Evaluator ${evaluator.evalName} failed with ${failingResults.length} error${failingResults.length === 1 ? "" : "s"}. This evaluation ("${evaluator.evalName}") will not be fully logged.`
|
|
14093
14147
|
)
|
|
14094
14148
|
);
|
|
14095
14149
|
if (jsonl) {
|
|
@@ -14121,124 +14175,84 @@ var defaultReporter = {
|
|
|
14121
14175
|
if (failingResults.length > 0) {
|
|
14122
14176
|
reportFailures(evaluator, failingResults, { verbose, jsonl });
|
|
14123
14177
|
}
|
|
14124
|
-
|
|
14125
|
-
|
|
14126
|
-
|
|
14127
|
-
|
|
14178
|
+
if (jsonl) {
|
|
14179
|
+
isomorph_default.writeln(JSON.stringify(summary));
|
|
14180
|
+
} else {
|
|
14181
|
+
isomorph_default.writeln("Experiment summary");
|
|
14182
|
+
isomorph_default.writeln("==================");
|
|
14183
|
+
if (summary.comparisonExperimentName) {
|
|
14184
|
+
isomorph_default.writeln(
|
|
14185
|
+
`${summary.comparisonExperimentName} (baseline) <- ${summary.experimentName} (comparison)`
|
|
14186
|
+
);
|
|
14187
|
+
isomorph_default.writeln("");
|
|
14188
|
+
}
|
|
14189
|
+
const hasScores = Object.keys(summary.scores).length > 0;
|
|
14190
|
+
const hasMetrics = Object.keys(_nullishCoalesce(summary.metrics, () => ( {}))).length > 0;
|
|
14191
|
+
const hasComparison = !!summary.comparisonExperimentName;
|
|
14192
|
+
if (hasScores || hasMetrics) {
|
|
14193
|
+
if (hasComparison) {
|
|
14194
|
+
isomorph_default.writeln(
|
|
14195
|
+
"Name Value Change Improvements Regressions"
|
|
14196
|
+
);
|
|
14197
|
+
isomorph_default.writeln(
|
|
14198
|
+
"----------------------------------------------------------------"
|
|
14199
|
+
);
|
|
14200
|
+
}
|
|
14201
|
+
for (const score of Object.values(summary.scores)) {
|
|
14202
|
+
const scorePercent = (score.score * 100).toFixed(2);
|
|
14203
|
+
const scoreValue = `${scorePercent}%`;
|
|
14204
|
+
if (hasComparison) {
|
|
14205
|
+
let diffString = "-";
|
|
14206
|
+
if (!isEmpty2(score.diff)) {
|
|
14207
|
+
const diffPercent = (score.diff * 100).toFixed(2);
|
|
14208
|
+
const diffSign = score.diff > 0 ? "+" : "";
|
|
14209
|
+
diffString = `${diffSign}${diffPercent}%`;
|
|
14210
|
+
}
|
|
14211
|
+
const improvements = score.improvements > 0 ? score.improvements.toString() : "-";
|
|
14212
|
+
const regressions = score.regressions > 0 ? score.regressions.toString() : "-";
|
|
14213
|
+
isomorph_default.writeln(
|
|
14214
|
+
`${score.name.padEnd(18)} ${scoreValue.padStart(10)} ${diffString.padStart(10)} ${improvements.padStart(12)} ${regressions.padStart(11)}`
|
|
14215
|
+
);
|
|
14216
|
+
} else {
|
|
14217
|
+
isomorph_default.writeln(`${score.name.padEnd(20)} ${scoreValue.padStart(15)}`);
|
|
14218
|
+
}
|
|
14219
|
+
}
|
|
14220
|
+
for (const metric of Object.values(_nullishCoalesce(summary.metrics, () => ( {})))) {
|
|
14221
|
+
const fractionDigits = Number.isInteger(metric.metric) ? 0 : 2;
|
|
14222
|
+
const formattedValue = metric.metric.toFixed(fractionDigits);
|
|
14223
|
+
const metricValue = metric.unit === "$" ? `${metric.unit}${formattedValue}` : `${formattedValue}${metric.unit}`;
|
|
14224
|
+
if (hasComparison) {
|
|
14225
|
+
let diffString = "-";
|
|
14226
|
+
if (!isEmpty2(metric.diff)) {
|
|
14227
|
+
const diffPercent = (metric.diff * 100).toFixed(2);
|
|
14228
|
+
const diffSign = metric.diff > 0 ? "+" : "";
|
|
14229
|
+
diffString = `${diffSign}${diffPercent}%`;
|
|
14230
|
+
}
|
|
14231
|
+
const improvements = metric.improvements > 0 ? metric.improvements.toString() : "-";
|
|
14232
|
+
const regressions = metric.regressions > 0 ? metric.regressions.toString() : "-";
|
|
14233
|
+
isomorph_default.writeln(
|
|
14234
|
+
`${metric.name.padEnd(18)} ${metricValue.padStart(10)} ${diffString.padStart(10)} ${improvements.padStart(12)} ${regressions.padStart(11)}`
|
|
14235
|
+
);
|
|
14236
|
+
} else {
|
|
14237
|
+
isomorph_default.writeln(
|
|
14238
|
+
`${metric.name.padEnd(20)} ${metricValue.padStart(15)}`
|
|
14239
|
+
);
|
|
14240
|
+
}
|
|
14241
|
+
}
|
|
14242
|
+
}
|
|
14243
|
+
if (summary.experimentUrl) {
|
|
14244
|
+
isomorph_default.writeln("");
|
|
14245
|
+
isomorph_default.writeln(`View results for ${summary.experimentName}`);
|
|
14246
|
+
isomorph_default.writeln(`See results at ${summary.experimentUrl}`);
|
|
14247
|
+
}
|
|
14248
|
+
}
|
|
14249
|
+
isomorph_default.writeln("");
|
|
14128
14250
|
return failingResults.length === 0;
|
|
14129
14251
|
},
|
|
14130
14252
|
async reportRun(evalReports) {
|
|
14131
14253
|
return evalReports.every((r) => r);
|
|
14132
14254
|
}
|
|
14133
14255
|
};
|
|
14134
|
-
function formatExperimentSummary(summary) {
|
|
14135
|
-
let comparisonLine = "";
|
|
14136
|
-
if (summary.comparisonExperimentName) {
|
|
14137
|
-
comparisonLine = `${summary.comparisonExperimentName} ${_chalk2.default.gray("(baseline)")} \u2190 ${summary.experimentName} ${_chalk2.default.gray("(comparison)")}
|
|
14138
|
-
|
|
14139
|
-
`;
|
|
14140
|
-
}
|
|
14141
|
-
const tableParts = [];
|
|
14142
|
-
const hasScores = Object.keys(summary.scores).length > 0;
|
|
14143
|
-
const hasMetrics = Object.keys(_nullishCoalesce(summary.metrics, () => ( {}))).length > 0;
|
|
14144
|
-
const hasComparison = !!summary.comparisonExperimentName;
|
|
14145
|
-
if (hasScores || hasMetrics) {
|
|
14146
|
-
const headers = [_chalk2.default.gray("Name"), _chalk2.default.gray("Value")];
|
|
14147
|
-
if (hasComparison) {
|
|
14148
|
-
headers.push(
|
|
14149
|
-
_chalk2.default.gray("Change"),
|
|
14150
|
-
_chalk2.default.gray("Improvements"),
|
|
14151
|
-
_chalk2.default.gray("Regressions")
|
|
14152
|
-
);
|
|
14153
|
-
}
|
|
14154
|
-
const combinedTable = new (0, _clitable32.default)({
|
|
14155
|
-
head: hasComparison ? headers : [],
|
|
14156
|
-
style: { head: [], "padding-left": 0, "padding-right": 0, border: [] },
|
|
14157
|
-
chars: {
|
|
14158
|
-
top: "",
|
|
14159
|
-
"top-mid": "",
|
|
14160
|
-
"top-left": "",
|
|
14161
|
-
"top-right": "",
|
|
14162
|
-
bottom: "",
|
|
14163
|
-
"bottom-mid": "",
|
|
14164
|
-
"bottom-left": "",
|
|
14165
|
-
"bottom-right": "",
|
|
14166
|
-
left: "",
|
|
14167
|
-
"left-mid": "",
|
|
14168
|
-
mid: "",
|
|
14169
|
-
"mid-mid": "",
|
|
14170
|
-
right: "",
|
|
14171
|
-
"right-mid": "",
|
|
14172
|
-
middle: " "
|
|
14173
|
-
},
|
|
14174
|
-
colWidths: hasComparison ? [18, 10, 10, 13, 12] : [20, 15],
|
|
14175
|
-
colAligns: hasComparison ? ["left", "right", "right", "right", "right"] : ["left", "right"],
|
|
14176
|
-
wordWrap: false
|
|
14177
|
-
});
|
|
14178
|
-
const scoreValues = Object.values(summary.scores);
|
|
14179
|
-
for (let i = 0; i < scoreValues.length; i++) {
|
|
14180
|
-
const score = scoreValues[i];
|
|
14181
|
-
const scorePercent = (score.score * 100).toFixed(2);
|
|
14182
|
-
const scoreValue = _chalk2.default.white(`${scorePercent}%`);
|
|
14183
|
-
let diffString = "";
|
|
14184
|
-
if (!isEmpty(score.diff)) {
|
|
14185
|
-
const diffPercent = (score.diff * 100).toFixed(2);
|
|
14186
|
-
const diffSign = score.diff > 0 ? "+" : "";
|
|
14187
|
-
const diffColor = score.diff > 0 ? _chalk2.default.green : _chalk2.default.red;
|
|
14188
|
-
diffString = diffColor(`${diffSign}${diffPercent}%`);
|
|
14189
|
-
} else {
|
|
14190
|
-
diffString = _chalk2.default.gray("-");
|
|
14191
|
-
}
|
|
14192
|
-
const improvements = score.improvements > 0 ? _chalk2.default.dim.green(score.improvements) : _chalk2.default.gray("-");
|
|
14193
|
-
const regressions = score.regressions > 0 ? _chalk2.default.dim.red(score.regressions) : _chalk2.default.gray("-");
|
|
14194
|
-
const row = [`${_chalk2.default.blue("\u25EF")} ${score.name}`, scoreValue];
|
|
14195
|
-
if (hasComparison) {
|
|
14196
|
-
row.push(diffString, improvements, regressions);
|
|
14197
|
-
}
|
|
14198
|
-
combinedTable.push(row);
|
|
14199
|
-
}
|
|
14200
|
-
const metricValues = Object.values(_nullishCoalesce(summary.metrics, () => ( {})));
|
|
14201
|
-
for (let i = 0; i < metricValues.length; i++) {
|
|
14202
|
-
const metric = metricValues[i];
|
|
14203
|
-
const fractionDigits = Number.isInteger(metric.metric) ? 0 : 2;
|
|
14204
|
-
const formattedValue = metric.metric.toFixed(fractionDigits);
|
|
14205
|
-
const metricValue = _chalk2.default.white(
|
|
14206
|
-
metric.unit === "$" ? `${metric.unit}${formattedValue}` : `${formattedValue}${metric.unit}`
|
|
14207
|
-
);
|
|
14208
|
-
let diffString = "";
|
|
14209
|
-
if (!isEmpty(metric.diff)) {
|
|
14210
|
-
const diffPercent = (metric.diff * 100).toFixed(2);
|
|
14211
|
-
const diffSign = metric.diff > 0 ? "+" : "";
|
|
14212
|
-
const diffColor = metric.diff > 0 ? _chalk2.default.green : _chalk2.default.red;
|
|
14213
|
-
diffString = diffColor(`${diffSign}${diffPercent}%`);
|
|
14214
|
-
} else {
|
|
14215
|
-
diffString = _chalk2.default.gray("-");
|
|
14216
|
-
}
|
|
14217
|
-
const improvements = metric.improvements > 0 ? _chalk2.default.dim.green(metric.improvements) : _chalk2.default.gray("-");
|
|
14218
|
-
const regressions = metric.regressions > 0 ? _chalk2.default.dim.red(metric.regressions) : _chalk2.default.gray("-");
|
|
14219
|
-
const row = [`${_chalk2.default.magenta("\u25EF")} ${metric.name}`, metricValue];
|
|
14220
|
-
if (hasComparison) {
|
|
14221
|
-
row.push(diffString, improvements, regressions);
|
|
14222
|
-
}
|
|
14223
|
-
combinedTable.push(row);
|
|
14224
|
-
}
|
|
14225
|
-
tableParts.push(combinedTable.toString());
|
|
14226
|
-
}
|
|
14227
|
-
const content = [comparisonLine, ...tableParts].filter(Boolean).join("\n");
|
|
14228
|
-
const footer = summary.experimentUrl ? _termilink.terminalLink.call(void 0,
|
|
14229
|
-
`View results for ${summary.experimentName}`,
|
|
14230
|
-
summary.experimentUrl,
|
|
14231
|
-
{ fallback: () => `See results at ${summary.experimentUrl}` }
|
|
14232
|
-
) : "";
|
|
14233
|
-
const boxContent = [content, footer].filter(Boolean).join("\n\n");
|
|
14234
|
-
return "\n" + _boxen2.default.call(void 0, boxContent, {
|
|
14235
|
-
title: _chalk2.default.gray("Experiment summary"),
|
|
14236
|
-
titleAlignment: "left",
|
|
14237
|
-
padding: 0.5,
|
|
14238
|
-
borderColor: "gray",
|
|
14239
|
-
borderStyle: "round"
|
|
14240
|
-
});
|
|
14241
|
-
}
|
|
14242
14256
|
|
|
14243
14257
|
// dev/types.ts
|
|
14244
14258
|
|
|
@@ -14284,7 +14298,6 @@ var evaluatorDefinitionsSchema = _v3.z.record(
|
|
|
14284
14298
|
|
|
14285
14299
|
// src/index.ts
|
|
14286
14300
|
configureNode();
|
|
14287
|
-
var index_default = exports_node_exports;
|
|
14288
14301
|
|
|
14289
14302
|
|
|
14290
14303
|
|
|
@@ -14393,4 +14406,5 @@ var index_default = exports_node_exports;
|
|
|
14393
14406
|
|
|
14394
14407
|
|
|
14395
14408
|
|
|
14396
|
-
|
|
14409
|
+
|
|
14410
|
+
exports.Attachment = Attachment; exports.AttachmentReference = AttachmentReference; exports.BaseAttachment = BaseAttachment; exports.BaseExperiment = BaseExperiment; exports.BraintrustMiddleware = BraintrustMiddleware; exports.BraintrustState = BraintrustState; exports.BraintrustStream = BraintrustStream; exports.CodeFunction = CodeFunction; exports.CodePrompt = CodePrompt; exports.ContextManager = ContextManager; exports.DEFAULT_FETCH_BATCH_SIZE = DEFAULT_FETCH_BATCH_SIZE; exports.Dataset = Dataset2; exports.ERR_PERMALINK = ERR_PERMALINK; exports.Eval = Eval; exports.EvalResultWithSummary = EvalResultWithSummary; exports.Experiment = Experiment2; exports.ExternalAttachment = ExternalAttachment; exports.FailedHTTPResponse = FailedHTTPResponse; exports.IDGenerator = IDGenerator; exports.JSONAttachment = JSONAttachment; exports.LEGACY_CACHED_HEADER = LEGACY_CACHED_HEADER; exports.LazyValue = LazyValue; exports.Logger = Logger; exports.LoginInvalidOrgError = LoginInvalidOrgError; exports.NOOP_SPAN = NOOP_SPAN; exports.NOOP_SPAN_PERMALINK = NOOP_SPAN_PERMALINK; exports.NoopSpan = NoopSpan; exports.Project = Project2; exports.ProjectNameIdMap = ProjectNameIdMap; exports.Prompt = Prompt2; exports.PromptBuilder = PromptBuilder; exports.ReadonlyAttachment = ReadonlyAttachment; exports.ReadonlyExperiment = ReadonlyExperiment; exports.Reporter = Reporter; exports.ScorerBuilder = ScorerBuilder; exports.SpanImpl = SpanImpl; exports.TestBackgroundLogger = TestBackgroundLogger; exports.ToolBuilder = ToolBuilder; exports.UUIDGenerator = UUIDGenerator; exports.X_CACHED_HEADER = X_CACHED_HEADER; exports._exportsForTestingOnly = _exportsForTestingOnly; exports._internalGetGlobalState = _internalGetGlobalState; exports._internalSetInitialState = _internalSetInitialState; exports.braintrustStreamChunkSchema = braintrustStreamChunkSchema; exports.buildLocalSummary = buildLocalSummary; exports.createFinalValuePassThroughStream = createFinalValuePassThroughStream; exports.currentExperiment = currentExperiment; exports.currentLogger = currentLogger; exports.currentSpan = currentSpan; exports.deepCopyEvent = deepCopyEvent; exports.default = exports_exports; exports.defaultErrorScoreHandler = defaultErrorScoreHandler; exports.deserializePlainStringAsJSON = deserializePlainStringAsJSON; exports.devNullWritableStream = devNullWritableStream; exports.evaluatorDefinitionSchema = evaluatorDefinitionSchema; exports.evaluatorDefinitionsSchema = evaluatorDefinitionsSchema; exports.flush = flush; exports.getContextManager = getContextManager; exports.getIdGenerator = getIdGenerator; exports.getPromptVersions = getPromptVersions; exports.getSpanParentObject = getSpanParentObject; exports.graph = graph_framework_exports; exports.init = init; exports.initDataset = initDataset; exports.initExperiment = initExperiment; exports.initFunction = initFunction; exports.initLogger = initLogger; exports.invoke = invoke; exports.loadPrompt = loadPrompt; exports.log = log; exports.logError = logError; exports.login = login; exports.loginToState = loginToState; exports.newId = newId; exports.parseCachedHeader = parseCachedHeader; exports.permalink = permalink; exports.projects = projects; exports.promptContentsSchema = promptContentsSchema; exports.promptDefinitionSchema = promptDefinitionSchema; exports.promptDefinitionToPromptData = promptDefinitionToPromptData; exports.promptDefinitionWithToolsSchema = promptDefinitionWithToolsSchema; exports.renderMessage = renderMessage; exports.renderPromptParams = renderPromptParams; exports.reportFailures = reportFailures; exports.runEvaluator = runEvaluator; exports.setFetch = setFetch; exports.setMaskingFunction = setMaskingFunction; exports.spanComponentsToObjectId = spanComponentsToObjectId; exports.startSpan = startSpan; exports.summarize = summarize; exports.toolFunctionDefinitionSchema = ToolFunctionDefinition; exports.traceable = traceable; exports.traced = traced; exports.updateSpan = updateSpan; exports.withCurrent = withCurrent; exports.withDataset = withDataset; exports.withExperiment = withExperiment; exports.withLogger = withLogger; exports.withParent = withParent; exports.wrapAISDK = wrapAISDK; exports.wrapAISDKModel = wrapAISDKModel; exports.wrapAnthropic = wrapAnthropic; exports.wrapClaudeAgentSDK = wrapClaudeAgentSDK; exports.wrapGoogleGenAI = wrapGoogleGenAI; exports.wrapMastraAgent = wrapMastraAgent; exports.wrapOpenAI = wrapOpenAI; exports.wrapOpenAIv4 = wrapOpenAIv4; exports.wrapTraced = wrapTraced;
|