braintrust 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/dist/index.d.mts +6 -8
- package/dev/dist/index.d.ts +6 -8
- package/dev/dist/index.js +809 -466
- package/dev/dist/index.mjs +367 -24
- package/dist/apply-auto-instrumentation.js +204 -174
- package/dist/apply-auto-instrumentation.mjs +35 -5
- package/dist/auto-instrumentations/bundler/esbuild.cjs +225 -1
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -1
- package/dist/auto-instrumentations/bundler/next.cjs +225 -1
- package/dist/auto-instrumentations/bundler/next.mjs +3 -2
- package/dist/auto-instrumentations/bundler/rollup.cjs +225 -1
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -1
- package/dist/auto-instrumentations/bundler/vite.cjs +225 -1
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -1
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +8 -0
- package/dist/auto-instrumentations/bundler/webpack.cjs +225 -1
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -2
- package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
- package/dist/auto-instrumentations/{chunk-WFEUJACP.mjs → chunk-OTUQ7KH5.mjs} +1 -1
- package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
- package/dist/auto-instrumentations/{chunk-GJOO4ESL.mjs → chunk-XKAAVWT6.mjs} +23 -1
- package/dist/auto-instrumentations/hook.mjs +7980 -7
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
- package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
- package/dist/browser.d.mts +127 -11
- package/dist/browser.d.ts +127 -11
- package/dist/browser.js +293 -24
- package/dist/browser.mjs +293 -24
- package/dist/{chunk-26JGOELH.js → chunk-NKD77KGB.js} +179 -1
- package/dist/{chunk-75IQCUB2.mjs → chunk-NU2GSPHX.mjs} +179 -1
- package/dist/cli.js +374 -51
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +293 -24
- package/dist/edge-light.mjs +293 -24
- package/dist/index.d.mts +127 -11
- package/dist/index.d.ts +127 -11
- package/dist/index.js +1113 -838
- package/dist/index.mjs +305 -30
- package/dist/instrumentation/index.d.mts +7 -8
- package/dist/instrumentation/index.d.ts +7 -8
- package/dist/instrumentation/index.js +101 -24
- package/dist/instrumentation/index.mjs +101 -24
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +293 -24
- package/dist/workerd.mjs +293 -24
- package/package.json +1 -7
- package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
package/dev/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; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32;// src/node/config.ts
|
|
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 _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32; var _class33;// src/node/config.ts
|
|
2
2
|
var _nodeasync_hooks = require('node:async_hooks');
|
|
3
3
|
var _nodediagnostics_channel = require('node:diagnostics_channel'); var diagnostics_channel = _interopRequireWildcard(_nodediagnostics_channel);
|
|
4
4
|
var _nodepath = require('node:path'); var path = _interopRequireWildcard(_nodepath);
|
|
@@ -4254,6 +4254,76 @@ var LRUCache = class {
|
|
|
4254
4254
|
}
|
|
4255
4255
|
};
|
|
4256
4256
|
|
|
4257
|
+
// src/prompt-cache/cache-config.ts
|
|
4258
|
+
var CACHE_LOCATION_ENV_VAR = "BRAINTRUST_CACHE_LOCATION";
|
|
4259
|
+
var DEFAULT_CACHE_MEMORY_MAX = 1 << 10;
|
|
4260
|
+
var DEFAULT_CACHE_DISK_MAX = 1 << 20;
|
|
4261
|
+
var warnedInvalidCacheModeEnvValue = false;
|
|
4262
|
+
var warnedUnavailableDiskCacheMode = false;
|
|
4263
|
+
function warnInvalidCacheMode(value) {
|
|
4264
|
+
if (warnedInvalidCacheModeEnvValue) {
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
4267
|
+
warnedInvalidCacheModeEnvValue = true;
|
|
4268
|
+
debugLogger.warn(
|
|
4269
|
+
`Invalid ${CACHE_LOCATION_ENV_VAR} value "${value}". Expected "mixed", "memory", "disk", or "none". Falling back to "mixed".`
|
|
4270
|
+
);
|
|
4271
|
+
}
|
|
4272
|
+
function warnUnavailableDiskCache() {
|
|
4273
|
+
if (warnedUnavailableDiskCacheMode) {
|
|
4274
|
+
return;
|
|
4275
|
+
}
|
|
4276
|
+
warnedUnavailableDiskCacheMode = true;
|
|
4277
|
+
debugLogger.warn(
|
|
4278
|
+
`Disk cache is not supported on this platform, so ${CACHE_LOCATION_ENV_VAR}="disk" disables prompt and parameters caching.`
|
|
4279
|
+
);
|
|
4280
|
+
}
|
|
4281
|
+
function parseCacheMode() {
|
|
4282
|
+
const value = isomorph_default.getEnv(CACHE_LOCATION_ENV_VAR);
|
|
4283
|
+
const normalized = _optionalChain([value, 'optionalAccess', _63 => _63.trim, 'call', _64 => _64(), 'access', _65 => _65.toLowerCase, 'call', _66 => _66()]);
|
|
4284
|
+
if (!normalized) {
|
|
4285
|
+
return "mixed";
|
|
4286
|
+
}
|
|
4287
|
+
if (normalized === "mixed" || normalized === "memory" || normalized === "disk" || normalized === "none") {
|
|
4288
|
+
return normalized;
|
|
4289
|
+
}
|
|
4290
|
+
warnInvalidCacheMode(_nullishCoalesce(value, () => ( "")));
|
|
4291
|
+
return "mixed";
|
|
4292
|
+
}
|
|
4293
|
+
function parsePositiveIntegerEnv(envVar, defaultValue) {
|
|
4294
|
+
const value = Number(isomorph_default.getEnv(envVar));
|
|
4295
|
+
return Number.isInteger(value) && value > 0 ? value : defaultValue;
|
|
4296
|
+
}
|
|
4297
|
+
function createCacheLayers({
|
|
4298
|
+
memoryMaxEnvVar,
|
|
4299
|
+
diskCacheDirEnvVar,
|
|
4300
|
+
diskMaxEnvVar,
|
|
4301
|
+
getDefaultDiskCacheDir
|
|
4302
|
+
}) {
|
|
4303
|
+
const mode = parseCacheMode();
|
|
4304
|
+
const memoryCache = mode === "mixed" || mode === "memory" ? new LRUCache({
|
|
4305
|
+
max: parsePositiveIntegerEnv(
|
|
4306
|
+
memoryMaxEnvVar,
|
|
4307
|
+
DEFAULT_CACHE_MEMORY_MAX
|
|
4308
|
+
)
|
|
4309
|
+
}) : void 0;
|
|
4310
|
+
let diskCache;
|
|
4311
|
+
if (mode === "mixed" || mode === "disk") {
|
|
4312
|
+
if (canUseDiskCache()) {
|
|
4313
|
+
diskCache = new DiskCache({
|
|
4314
|
+
cacheDir: _nullishCoalesce(isomorph_default.getEnv(diskCacheDirEnvVar), () => ( getDefaultDiskCacheDir())),
|
|
4315
|
+
max: parsePositiveIntegerEnv(diskMaxEnvVar, DEFAULT_CACHE_DISK_MAX)
|
|
4316
|
+
});
|
|
4317
|
+
} else if (mode === "disk") {
|
|
4318
|
+
warnUnavailableDiskCache();
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
if (diskCache) {
|
|
4322
|
+
return { memoryCache, diskCache };
|
|
4323
|
+
}
|
|
4324
|
+
return { memoryCache };
|
|
4325
|
+
}
|
|
4326
|
+
|
|
4257
4327
|
// src/prompt-cache/prompt-cache.ts
|
|
4258
4328
|
function createCacheKey(key) {
|
|
4259
4329
|
if (key.id) {
|
|
@@ -4281,16 +4351,18 @@ var PromptCache = class {
|
|
|
4281
4351
|
*/
|
|
4282
4352
|
async get(key) {
|
|
4283
4353
|
const cacheKey = createCacheKey(key);
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4354
|
+
if (this.memoryCache) {
|
|
4355
|
+
const memoryPrompt = this.memoryCache.get(cacheKey);
|
|
4356
|
+
if (memoryPrompt !== void 0) {
|
|
4357
|
+
return memoryPrompt;
|
|
4358
|
+
}
|
|
4287
4359
|
}
|
|
4288
4360
|
if (this.diskCache) {
|
|
4289
4361
|
const diskPrompt = await this.diskCache.get(cacheKey);
|
|
4290
4362
|
if (!diskPrompt) {
|
|
4291
4363
|
return void 0;
|
|
4292
4364
|
}
|
|
4293
|
-
this.memoryCache.set(cacheKey, diskPrompt);
|
|
4365
|
+
_optionalChain([this, 'access', _67 => _67.memoryCache, 'optionalAccess', _68 => _68.set, 'call', _69 => _69(cacheKey, diskPrompt)]);
|
|
4294
4366
|
return diskPrompt;
|
|
4295
4367
|
}
|
|
4296
4368
|
return void 0;
|
|
@@ -4305,7 +4377,7 @@ var PromptCache = class {
|
|
|
4305
4377
|
*/
|
|
4306
4378
|
async set(key, value) {
|
|
4307
4379
|
const cacheKey = createCacheKey(key);
|
|
4308
|
-
this.memoryCache.set(cacheKey, value);
|
|
4380
|
+
_optionalChain([this, 'access', _70 => _70.memoryCache, 'optionalAccess', _71 => _71.set, 'call', _72 => _72(cacheKey, value)]);
|
|
4309
4381
|
if (this.diskCache) {
|
|
4310
4382
|
await this.diskCache.set(cacheKey, value);
|
|
4311
4383
|
}
|
|
@@ -4335,23 +4407,25 @@ var ParametersCache = class {
|
|
|
4335
4407
|
}
|
|
4336
4408
|
async get(key) {
|
|
4337
4409
|
const cacheKey = createCacheKey2(key);
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4410
|
+
if (this.memoryCache) {
|
|
4411
|
+
const memoryParams = this.memoryCache.get(cacheKey);
|
|
4412
|
+
if (memoryParams !== void 0) {
|
|
4413
|
+
return memoryParams;
|
|
4414
|
+
}
|
|
4341
4415
|
}
|
|
4342
4416
|
if (this.diskCache) {
|
|
4343
4417
|
const diskParams = await this.diskCache.get(cacheKey);
|
|
4344
4418
|
if (!diskParams) {
|
|
4345
4419
|
return void 0;
|
|
4346
4420
|
}
|
|
4347
|
-
this.memoryCache.set(cacheKey, diskParams);
|
|
4421
|
+
_optionalChain([this, 'access', _73 => _73.memoryCache, 'optionalAccess', _74 => _74.set, 'call', _75 => _75(cacheKey, diskParams)]);
|
|
4348
4422
|
return diskParams;
|
|
4349
4423
|
}
|
|
4350
4424
|
return void 0;
|
|
4351
4425
|
}
|
|
4352
4426
|
async set(key, value) {
|
|
4353
4427
|
const cacheKey = createCacheKey2(key);
|
|
4354
|
-
this.memoryCache.set(cacheKey, value);
|
|
4428
|
+
_optionalChain([this, 'access', _76 => _76.memoryCache, 'optionalAccess', _77 => _77.set, 'call', _78 => _78(cacheKey, value)]);
|
|
4355
4429
|
if (this.diskCache) {
|
|
4356
4430
|
await this.diskCache.set(cacheKey, value);
|
|
4357
4431
|
}
|
|
@@ -4379,7 +4453,7 @@ var SpanCache = (_class6 = class {
|
|
|
4379
4453
|
// Small in-memory index tracking which rootSpanIds have data
|
|
4380
4454
|
__init14() {this.rootSpanIndex = /* @__PURE__ */ new Set()}
|
|
4381
4455
|
constructor(options) {;_class6.prototype.__init8.call(this);_class6.prototype.__init9.call(this);_class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this);_class6.prototype.__init12.call(this);_class6.prototype.__init13.call(this);_class6.prototype.__init14.call(this);_class6.prototype.__init15.call(this);_class6.prototype.__init16.call(this);_class6.prototype.__init17.call(this);
|
|
4382
|
-
this._explicitlyDisabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4456
|
+
this._explicitlyDisabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _79 => _79.disabled]), () => ( false));
|
|
4383
4457
|
}
|
|
4384
4458
|
/**
|
|
4385
4459
|
* Disable the cache at runtime. This is called automatically when
|
|
@@ -4799,7 +4873,7 @@ var NoopSpan = (_class7 = class {
|
|
|
4799
4873
|
return this;
|
|
4800
4874
|
}
|
|
4801
4875
|
end(args) {
|
|
4802
|
-
return _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
4876
|
+
return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _80 => _80.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
4803
4877
|
}
|
|
4804
4878
|
async export() {
|
|
4805
4879
|
return "";
|
|
@@ -4883,21 +4957,22 @@ var BraintrustState = (_class8 = class _BraintrustState {
|
|
|
4883
4957
|
setGlobalDebugLogLevel(void 0);
|
|
4884
4958
|
}
|
|
4885
4959
|
this.resetLoginInfo();
|
|
4886
|
-
const memoryCache =
|
|
4887
|
-
|
|
4960
|
+
const { memoryCache, diskCache } = createCacheLayers({
|
|
4961
|
+
memoryMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_MEMORY_MAX",
|
|
4962
|
+
diskCacheDirEnvVar: "BRAINTRUST_PROMPT_CACHE_DIR",
|
|
4963
|
+
diskMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_DISK_MAX",
|
|
4964
|
+
getDefaultDiskCacheDir: () => `${_nullishCoalesce(isomorph_default.getEnv("HOME"), () => ( isomorph_default.homedir()))}/.braintrust/prompt_cache`
|
|
4888
4965
|
});
|
|
4889
|
-
const diskCache = canUseDiskCache() ? new DiskCache({
|
|
4890
|
-
cacheDir: _nullishCoalesce(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DIR"), () => ( `${_nullishCoalesce(isomorph_default.getEnv("HOME"), () => ( isomorph_default.homedir()))}/.braintrust/prompt_cache`)),
|
|
4891
|
-
max: _nullishCoalesce(Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DISK_MAX")), () => ( 1 << 20))
|
|
4892
|
-
}) : void 0;
|
|
4893
4966
|
this.promptCache = new PromptCache({ memoryCache, diskCache });
|
|
4894
|
-
const
|
|
4895
|
-
|
|
4967
|
+
const {
|
|
4968
|
+
memoryCache: parametersMemoryCache,
|
|
4969
|
+
diskCache: parametersDiskCache
|
|
4970
|
+
} = createCacheLayers({
|
|
4971
|
+
memoryMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX",
|
|
4972
|
+
diskCacheDirEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DIR",
|
|
4973
|
+
diskMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DISK_MAX",
|
|
4974
|
+
getDefaultDiskCacheDir: () => `${_nullishCoalesce(isomorph_default.getEnv("HOME"), () => ( isomorph_default.homedir()))}/.braintrust/parameters_cache`
|
|
4896
4975
|
});
|
|
4897
|
-
const parametersDiskCache = canUseDiskCache() ? new DiskCache({
|
|
4898
|
-
cacheDir: _nullishCoalesce(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DIR"), () => ( `${_nullishCoalesce(isomorph_default.getEnv("HOME"), () => ( isomorph_default.homedir()))}/.braintrust/parameters_cache`)),
|
|
4899
|
-
max: _nullishCoalesce(Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DISK_MAX")), () => ( 1 << 20))
|
|
4900
|
-
}) : void 0;
|
|
4901
4976
|
this.parametersCache = new ParametersCache({
|
|
4902
4977
|
memoryCache: parametersMemoryCache,
|
|
4903
4978
|
diskCache: parametersDiskCache
|
|
@@ -5064,8 +5139,8 @@ var BraintrustState = (_class8 = class _BraintrustState {
|
|
|
5064
5139
|
setFetch(fetch2) {
|
|
5065
5140
|
this.loginParams.fetch = fetch2;
|
|
5066
5141
|
this.fetch = fetch2;
|
|
5067
|
-
_optionalChain([this, 'access',
|
|
5068
|
-
_optionalChain([this, 'access',
|
|
5142
|
+
_optionalChain([this, 'access', _81 => _81._apiConn, 'optionalAccess', _82 => _82.setFetch, 'call', _83 => _83(fetch2)]);
|
|
5143
|
+
_optionalChain([this, 'access', _84 => _84._appConn, 'optionalAccess', _85 => _85.setFetch, 'call', _86 => _86(fetch2)]);
|
|
5069
5144
|
}
|
|
5070
5145
|
setMaskingFunction(maskingFunction) {
|
|
5071
5146
|
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
@@ -5465,7 +5540,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
5465
5540
|
body: data
|
|
5466
5541
|
})
|
|
5467
5542
|
);
|
|
5468
|
-
await _optionalChain([objectStoreResponse, 'access',
|
|
5543
|
+
await _optionalChain([objectStoreResponse, 'access', _87 => _87.body, 'optionalAccess', _88 => _88.cancel, 'call', _89 => _89()]);
|
|
5469
5544
|
} catch (error) {
|
|
5470
5545
|
if (error instanceof FailedHTTPResponse) {
|
|
5471
5546
|
throw new Error(
|
|
@@ -5497,7 +5572,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
5497
5572
|
"/attachment/status",
|
|
5498
5573
|
requestParams
|
|
5499
5574
|
);
|
|
5500
|
-
await _optionalChain([statusResponse, 'access',
|
|
5575
|
+
await _optionalChain([statusResponse, 'access', _90 => _90.body, 'optionalAccess', _91 => _91.cancel, 'call', _92 => _92()]);
|
|
5501
5576
|
if (!statusResponse.ok) {
|
|
5502
5577
|
const errorStr = JSON.stringify(statusResponse);
|
|
5503
5578
|
throw new Error(`Couldn't log attachment status: ${errorStr}`);
|
|
@@ -5776,8 +5851,8 @@ function _getOrgName(orgName) {
|
|
|
5776
5851
|
return orgName || isomorph_default.getEnv("BRAINTRUST_ORG_NAME") || void 0;
|
|
5777
5852
|
}
|
|
5778
5853
|
function _getLinkBaseUrl(state, linkArgs) {
|
|
5779
|
-
const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess',
|
|
5780
|
-
const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess',
|
|
5854
|
+
const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess', _93 => _93.app_url]));
|
|
5855
|
+
const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess', _94 => _94.org_name]));
|
|
5781
5856
|
if (!orgName) {
|
|
5782
5857
|
return null;
|
|
5783
5858
|
}
|
|
@@ -5787,9 +5862,9 @@ async function permalink(slug, opts) {
|
|
|
5787
5862
|
if (slug === "") {
|
|
5788
5863
|
return NOOP_SPAN_PERMALINK;
|
|
5789
5864
|
}
|
|
5790
|
-
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
5865
|
+
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _95 => _95.state]), () => ( _globalState));
|
|
5791
5866
|
const getOrgName = async () => {
|
|
5792
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
5867
|
+
if (_optionalChain([opts, 'optionalAccess', _96 => _96.orgName])) {
|
|
5793
5868
|
return opts.orgName;
|
|
5794
5869
|
}
|
|
5795
5870
|
await state.login({});
|
|
@@ -5799,7 +5874,7 @@ async function permalink(slug, opts) {
|
|
|
5799
5874
|
return state.orgName;
|
|
5800
5875
|
};
|
|
5801
5876
|
const getAppUrl = async () => {
|
|
5802
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
5877
|
+
if (_optionalChain([opts, 'optionalAccess', _97 => _97.appUrl])) {
|
|
5803
5878
|
return opts.appUrl;
|
|
5804
5879
|
}
|
|
5805
5880
|
await state.login({});
|
|
@@ -5921,7 +5996,7 @@ var Logger = (_class9 = class {
|
|
|
5921
5996
|
* @returns The `id` of the logged event.
|
|
5922
5997
|
*/
|
|
5923
5998
|
log(event, options) {
|
|
5924
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
5999
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _98 => _98.allowConcurrentWithSpans])) {
|
|
5925
6000
|
throw new Error(
|
|
5926
6001
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
|
|
5927
6002
|
);
|
|
@@ -5989,12 +6064,12 @@ var Logger = (_class9 = class {
|
|
|
5989
6064
|
state: this.state,
|
|
5990
6065
|
...startSpanParentArgs({
|
|
5991
6066
|
state: this.state,
|
|
5992
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
6067
|
+
parent: _optionalChain([args, 'optionalAccess', _99 => _99.parent]),
|
|
5993
6068
|
parentObjectType: this.parentObjectType(),
|
|
5994
6069
|
parentObjectId: this.lazyId,
|
|
5995
6070
|
parentComputeObjectMetadataArgs: this.computeMetadataArgs,
|
|
5996
|
-
parentSpanIds: _optionalChain([args, 'optionalAccess',
|
|
5997
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
6071
|
+
parentSpanIds: _optionalChain([args, 'optionalAccess', _100 => _100.parentSpanIds]),
|
|
6072
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _101 => _101.propagatedEvent])
|
|
5998
6073
|
}),
|
|
5999
6074
|
defaultRootType: "task" /* TASK */
|
|
6000
6075
|
});
|
|
@@ -6330,7 +6405,7 @@ var HTTPBackgroundLogger = (_class10 = class _HTTPBackgroundLogger {
|
|
|
6330
6405
|
this.queue.clear();
|
|
6331
6406
|
return;
|
|
6332
6407
|
}
|
|
6333
|
-
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
6408
|
+
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _102 => _102.batchSize]), () => ( this.defaultBatchSize));
|
|
6334
6409
|
const wrappedItems = this.queue.drain();
|
|
6335
6410
|
if (wrappedItems.length === 0) {
|
|
6336
6411
|
return;
|
|
@@ -6644,10 +6719,10 @@ Error: ${errorText}`;
|
|
|
6644
6719
|
} catch (err) {
|
|
6645
6720
|
if (err instanceof AggregateError) {
|
|
6646
6721
|
for (const e of err.errors) {
|
|
6647
|
-
_optionalChain([this, 'access',
|
|
6722
|
+
_optionalChain([this, 'access', _103 => _103.onFlushError, 'optionalCall', _104 => _104(e)]);
|
|
6648
6723
|
}
|
|
6649
6724
|
} else {
|
|
6650
|
-
_optionalChain([this, 'access',
|
|
6725
|
+
_optionalChain([this, 'access', _105 => _105.onFlushError, 'optionalCall', _106 => _106(err)]);
|
|
6651
6726
|
}
|
|
6652
6727
|
this.activeFlushError = err;
|
|
6653
6728
|
} finally {
|
|
@@ -6697,7 +6772,7 @@ function getExperimentDatasetFilter({
|
|
|
6697
6772
|
return isObject(datasetFilter) ? datasetFilter : void 0;
|
|
6698
6773
|
}
|
|
6699
6774
|
function getInternalBtqlLimit(internalBtql) {
|
|
6700
|
-
const limit = _optionalChain([internalBtql, 'optionalAccess',
|
|
6775
|
+
const limit = _optionalChain([internalBtql, 'optionalAccess', _107 => _107["limit"]]);
|
|
6701
6776
|
return typeof limit === "number" ? limit : void 0;
|
|
6702
6777
|
}
|
|
6703
6778
|
function init(projectOrOptions, optionalOptions) {
|
|
@@ -7335,24 +7410,24 @@ async function loginToState(options = {}) {
|
|
|
7335
7410
|
return state;
|
|
7336
7411
|
}
|
|
7337
7412
|
function currentExperiment(options) {
|
|
7338
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7413
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _108 => _108.state]), () => ( _globalState));
|
|
7339
7414
|
return state.currentExperiment;
|
|
7340
7415
|
}
|
|
7341
7416
|
function currentLogger(options) {
|
|
7342
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7343
|
-
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess',
|
|
7417
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _109 => _109.state]), () => ( _globalState));
|
|
7418
|
+
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _110 => _110.asyncFlush]));
|
|
7344
7419
|
}
|
|
7345
7420
|
function currentSpan(options) {
|
|
7346
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7421
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _111 => _111.state]), () => ( _globalState));
|
|
7347
7422
|
return _nullishCoalesce(state.contextManager.getCurrentSpan(), () => ( NOOP_SPAN));
|
|
7348
7423
|
}
|
|
7349
7424
|
function getSpanParentObject(options) {
|
|
7350
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7425
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _112 => _112.state]), () => ( _globalState));
|
|
7351
7426
|
const parentSpan = currentSpan({ state });
|
|
7352
7427
|
if (!Object.is(parentSpan, NOOP_SPAN)) {
|
|
7353
7428
|
return parentSpan;
|
|
7354
7429
|
}
|
|
7355
|
-
const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7430
|
+
const parentStr = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _113 => _113.parent]), () => ( state.currentParent.getStore()));
|
|
7356
7431
|
if (parentStr) return getSpanComponentsClass().fromStr(parentStr);
|
|
7357
7432
|
const experiment = currentExperiment();
|
|
7358
7433
|
if (experiment) {
|
|
@@ -7381,7 +7456,7 @@ function traced(callback, args) {
|
|
|
7381
7456
|
const { span, isSyncFlushLogger } = startSpanAndIsLogger(args);
|
|
7382
7457
|
const ret = runCatchFinally(
|
|
7383
7458
|
() => {
|
|
7384
|
-
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7459
|
+
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _114 => _114.setCurrent]), () => ( true))) {
|
|
7385
7460
|
return withCurrent(span, callback);
|
|
7386
7461
|
} else {
|
|
7387
7462
|
return callback(span);
|
|
@@ -7393,7 +7468,7 @@ function traced(callback, args) {
|
|
|
7393
7468
|
},
|
|
7394
7469
|
() => span.end()
|
|
7395
7470
|
);
|
|
7396
|
-
if (_optionalChain([args, 'optionalAccess',
|
|
7471
|
+
if (_optionalChain([args, 'optionalAccess', _115 => _115.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _116 => _116.asyncFlush])) {
|
|
7397
7472
|
return ret;
|
|
7398
7473
|
} else {
|
|
7399
7474
|
return (async () => {
|
|
@@ -7409,14 +7484,14 @@ function startSpan(args) {
|
|
|
7409
7484
|
return startSpanAndIsLogger(args).span;
|
|
7410
7485
|
}
|
|
7411
7486
|
async function flush(options) {
|
|
7412
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7487
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _117 => _117.state]), () => ( _globalState));
|
|
7413
7488
|
return await state.bgLogger().flush();
|
|
7414
7489
|
}
|
|
7415
7490
|
function startSpanAndIsLogger(args) {
|
|
7416
|
-
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7491
|
+
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _118 => _118.state]), () => ( _globalState));
|
|
7417
7492
|
const parentObject = getSpanParentObject({
|
|
7418
|
-
asyncFlush: _optionalChain([args, 'optionalAccess',
|
|
7419
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
7493
|
+
asyncFlush: _optionalChain([args, 'optionalAccess', _119 => _119.asyncFlush]),
|
|
7494
|
+
parent: _optionalChain([args, 'optionalAccess', _120 => _120.parent]),
|
|
7420
7495
|
state
|
|
7421
7496
|
});
|
|
7422
7497
|
if (parentObject instanceof SpanComponentsV3 || parentObject instanceof SpanComponentsV4) {
|
|
@@ -7433,14 +7508,14 @@ function startSpanAndIsLogger(args) {
|
|
|
7433
7508
|
),
|
|
7434
7509
|
parentComputeObjectMetadataArgs: _nullishCoalesce(parentObject.data.compute_object_metadata_args, () => ( void 0)),
|
|
7435
7510
|
parentSpanIds,
|
|
7436
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7511
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _121 => _121.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
7437
7512
|
(_nullishCoalesce(parentObject.data.propagated_event, () => ( void 0)))))
|
|
7438
7513
|
});
|
|
7439
7514
|
return {
|
|
7440
7515
|
span,
|
|
7441
7516
|
isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
|
|
7442
7517
|
// behavior, and therefore propagate along whatever we get from the arguments
|
|
7443
|
-
_optionalChain([args, 'optionalAccess',
|
|
7518
|
+
_optionalChain([args, 'optionalAccess', _122 => _122.asyncFlush]) === false
|
|
7444
7519
|
};
|
|
7445
7520
|
} else {
|
|
7446
7521
|
const span = parentObject.startSpan(args);
|
|
@@ -7607,10 +7682,10 @@ function extractAttachments(event, attachments) {
|
|
|
7607
7682
|
event[key] = value.reference;
|
|
7608
7683
|
continue;
|
|
7609
7684
|
}
|
|
7610
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
7685
|
+
if (_optionalChain([value, 'optionalAccess', _123 => _123.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
|
|
7611
7686
|
continue;
|
|
7612
7687
|
}
|
|
7613
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
7688
|
+
if (_optionalChain([value, 'optionalAccess', _124 => _124.reference, 'optionalAccess', _125 => _125.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _126 => _126.uploader])) {
|
|
7614
7689
|
const attachment = new Attachment({
|
|
7615
7690
|
data: value.dataDebugString,
|
|
7616
7691
|
filename: value.reference.filename,
|
|
@@ -7777,7 +7852,7 @@ var ObjectFetcher = (_class11 = class {
|
|
|
7777
7852
|
}
|
|
7778
7853
|
return;
|
|
7779
7854
|
}
|
|
7780
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
7855
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _127 => _127.batchSize]))) {
|
|
7781
7856
|
yield record;
|
|
7782
7857
|
}
|
|
7783
7858
|
}
|
|
@@ -7787,7 +7862,7 @@ var ObjectFetcher = (_class11 = class {
|
|
|
7787
7862
|
async fetchedData(options) {
|
|
7788
7863
|
if (this._fetchedData === void 0) {
|
|
7789
7864
|
const data = [];
|
|
7790
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
7865
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _128 => _128.batchSize]))) {
|
|
7791
7866
|
data.push(record);
|
|
7792
7867
|
}
|
|
7793
7868
|
this._fetchedData = data;
|
|
@@ -7882,7 +7957,7 @@ var Experiment2 = (_class12 = class extends ObjectFetcher {
|
|
|
7882
7957
|
* @returns The `id` of the logged event.
|
|
7883
7958
|
*/
|
|
7884
7959
|
log(event, options) {
|
|
7885
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
7960
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _129 => _129.allowConcurrentWithSpans])) {
|
|
7886
7961
|
throw new Error(
|
|
7887
7962
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
|
|
7888
7963
|
);
|
|
@@ -7935,12 +8010,12 @@ var Experiment2 = (_class12 = class extends ObjectFetcher {
|
|
|
7935
8010
|
state: this.state,
|
|
7936
8011
|
...startSpanParentArgs({
|
|
7937
8012
|
state: this.state,
|
|
7938
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
8013
|
+
parent: _optionalChain([args, 'optionalAccess', _130 => _130.parent]),
|
|
7939
8014
|
parentObjectType: this.parentObjectType(),
|
|
7940
8015
|
parentObjectId: this.lazyId,
|
|
7941
8016
|
parentComputeObjectMetadataArgs: void 0,
|
|
7942
8017
|
parentSpanIds: void 0,
|
|
7943
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
8018
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _131 => _131.propagatedEvent])
|
|
7944
8019
|
}),
|
|
7945
8020
|
defaultRootType: "eval" /* EVAL */
|
|
7946
8021
|
});
|
|
@@ -8284,7 +8359,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8284
8359
|
...serializableInternalData,
|
|
8285
8360
|
[IS_MERGE_FIELD]: this.isMerge
|
|
8286
8361
|
});
|
|
8287
|
-
if (typeof _optionalChain([partialRecord, 'access',
|
|
8362
|
+
if (typeof _optionalChain([partialRecord, 'access', _132 => _132.metrics, 'optionalAccess', _133 => _133.end]) === "number") {
|
|
8288
8363
|
this.loggedEndTime = partialRecord.metrics.end;
|
|
8289
8364
|
}
|
|
8290
8365
|
if (this.parentObjectType === 1 /* EXPERIMENT */) {
|
|
@@ -8350,18 +8425,18 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8350
8425
|
);
|
|
8351
8426
|
}
|
|
8352
8427
|
startSpan(args) {
|
|
8353
|
-
const parentSpanIds = _optionalChain([args, 'optionalAccess',
|
|
8428
|
+
const parentSpanIds = _optionalChain([args, 'optionalAccess', _134 => _134.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
|
|
8354
8429
|
return new _SpanImpl({
|
|
8355
8430
|
state: this._state,
|
|
8356
8431
|
...args,
|
|
8357
8432
|
...startSpanParentArgs({
|
|
8358
8433
|
state: this._state,
|
|
8359
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
8434
|
+
parent: _optionalChain([args, 'optionalAccess', _135 => _135.parent]),
|
|
8360
8435
|
parentObjectType: this.parentObjectType,
|
|
8361
8436
|
parentObjectId: this.parentObjectId,
|
|
8362
8437
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
8363
8438
|
parentSpanIds,
|
|
8364
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8439
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _136 => _136.propagatedEvent]), () => ( this.propagatedEvent))
|
|
8365
8440
|
})
|
|
8366
8441
|
});
|
|
8367
8442
|
}
|
|
@@ -8375,12 +8450,12 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8375
8450
|
...args,
|
|
8376
8451
|
...startSpanParentArgs({
|
|
8377
8452
|
state: this._state,
|
|
8378
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
8453
|
+
parent: _optionalChain([args, 'optionalAccess', _137 => _137.parent]),
|
|
8379
8454
|
parentObjectType: this.parentObjectType,
|
|
8380
8455
|
parentObjectId: this.parentObjectId,
|
|
8381
8456
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
8382
8457
|
parentSpanIds,
|
|
8383
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8458
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _138 => _138.propagatedEvent]), () => ( this.propagatedEvent))
|
|
8384
8459
|
}),
|
|
8385
8460
|
spanId
|
|
8386
8461
|
});
|
|
@@ -8389,7 +8464,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8389
8464
|
let endTime;
|
|
8390
8465
|
let internalData = {};
|
|
8391
8466
|
if (!this.loggedEndTime) {
|
|
8392
|
-
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8467
|
+
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _139 => _139.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
8393
8468
|
internalData = { metrics: { end: endTime } };
|
|
8394
8469
|
} else {
|
|
8395
8470
|
endTime = this.loggedEndTime;
|
|
@@ -8440,8 +8515,8 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8440
8515
|
const args = this.parentComputeObjectMetadataArgs;
|
|
8441
8516
|
switch (this.parentObjectType) {
|
|
8442
8517
|
case 2 /* PROJECT_LOGS */: {
|
|
8443
|
-
const projectID = _optionalChain([args, 'optionalAccess',
|
|
8444
|
-
const projectName = _optionalChain([args, 'optionalAccess',
|
|
8518
|
+
const projectID = _optionalChain([args, 'optionalAccess', _140 => _140.project_id]) || this.parentObjectId.getSync().value;
|
|
8519
|
+
const projectName = _optionalChain([args, 'optionalAccess', _141 => _141.project_name]);
|
|
8445
8520
|
if (projectID) {
|
|
8446
8521
|
return `${baseUrl}/object?object_type=project_logs&object_id=${projectID}&id=${this._id}`;
|
|
8447
8522
|
} else if (projectName) {
|
|
@@ -8451,7 +8526,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
8451
8526
|
}
|
|
8452
8527
|
}
|
|
8453
8528
|
case 1 /* EXPERIMENT */: {
|
|
8454
|
-
const expID = _optionalChain([args, 'optionalAccess',
|
|
8529
|
+
const expID = _optionalChain([args, 'optionalAccess', _142 => _142.experiment_id]) || _optionalChain([this, 'access', _143 => _143.parentObjectId, 'optionalAccess', _144 => _144.getSync, 'call', _145 => _145(), 'optionalAccess', _146 => _146.value]);
|
|
8455
8530
|
if (!expID) {
|
|
8456
8531
|
return getErrPermlink("provide-experiment-id");
|
|
8457
8532
|
} else {
|
|
@@ -8544,9 +8619,9 @@ var Dataset2 = (_class14 = class extends ObjectFetcher {
|
|
|
8544
8619
|
);_class14.prototype.__init57.call(this);_class14.prototype.__init58.call(this);;
|
|
8545
8620
|
this.state = state;
|
|
8546
8621
|
this.lazyMetadata = lazyMetadata;
|
|
8547
|
-
this.lazyPinnedVersion = _optionalChain([pinState, 'optionalAccess',
|
|
8548
|
-
this.pinnedEnvironment = _optionalChain([pinState, 'optionalAccess',
|
|
8549
|
-
this.pinnedSnapshotName = _optionalChain([pinState, 'optionalAccess',
|
|
8622
|
+
this.lazyPinnedVersion = _optionalChain([pinState, 'optionalAccess', _147 => _147.lazyPinnedVersion]);
|
|
8623
|
+
this.pinnedEnvironment = _optionalChain([pinState, 'optionalAccess', _148 => _148.pinnedEnvironment]);
|
|
8624
|
+
this.pinnedSnapshotName = _optionalChain([pinState, 'optionalAccess', _149 => _149.pinnedSnapshotName]);
|
|
8550
8625
|
}
|
|
8551
8626
|
|
|
8552
8627
|
__init57() {this.__braintrust_dataset_marker = true}
|
|
@@ -9074,16 +9149,16 @@ var Prompt2 = (_class15 = class _Prompt {
|
|
|
9074
9149
|
return "slug" in this.metadata ? this.metadata.slug : this.metadata.id;
|
|
9075
9150
|
}
|
|
9076
9151
|
get prompt() {
|
|
9077
|
-
return _optionalChain([this, 'access',
|
|
9152
|
+
return _optionalChain([this, 'access', _150 => _150.getParsedPromptData, 'call', _151 => _151(), 'optionalAccess', _152 => _152.prompt]);
|
|
9078
9153
|
}
|
|
9079
9154
|
get version() {
|
|
9080
9155
|
return this.metadata[TRANSACTION_ID_FIELD];
|
|
9081
9156
|
}
|
|
9082
9157
|
get options() {
|
|
9083
|
-
return _optionalChain([this, 'access',
|
|
9158
|
+
return _optionalChain([this, 'access', _153 => _153.getParsedPromptData, 'call', _154 => _154(), 'optionalAccess', _155 => _155.options]) || {};
|
|
9084
9159
|
}
|
|
9085
9160
|
get templateFormat() {
|
|
9086
|
-
return _optionalChain([this, 'access',
|
|
9161
|
+
return _optionalChain([this, 'access', _156 => _156.getParsedPromptData, 'call', _157 => _157(), 'optionalAccess', _158 => _158.template_format]);
|
|
9087
9162
|
}
|
|
9088
9163
|
get promptData() {
|
|
9089
9164
|
return this.getParsedPromptData();
|
|
@@ -9245,7 +9320,7 @@ var Prompt2 = (_class15 = class _Prompt {
|
|
|
9245
9320
|
return {
|
|
9246
9321
|
type: "chat",
|
|
9247
9322
|
messages,
|
|
9248
|
-
..._optionalChain([prompt, 'access',
|
|
9323
|
+
..._optionalChain([prompt, 'access', _159 => _159.tools, 'optionalAccess', _160 => _160.trim, 'call', _161 => _161()]) ? {
|
|
9249
9324
|
tools: render(prompt.tools)
|
|
9250
9325
|
} : void 0
|
|
9251
9326
|
};
|
|
@@ -9563,7 +9638,7 @@ function getChannelSpanInfo(event) {
|
|
|
9563
9638
|
if (isObject(event.span_info)) {
|
|
9564
9639
|
return event.span_info;
|
|
9565
9640
|
}
|
|
9566
|
-
const firstArg = _optionalChain([event, 'access',
|
|
9641
|
+
const firstArg = _optionalChain([event, 'access', _162 => _162.arguments, 'optionalAccess', _163 => _163[0]]);
|
|
9567
9642
|
if (hasChannelSpanInfo(firstArg)) {
|
|
9568
9643
|
return firstArg.span_info;
|
|
9569
9644
|
}
|
|
@@ -9574,13 +9649,13 @@ function buildStartSpanArgs(config, event) {
|
|
|
9574
9649
|
const spanAttributes = {
|
|
9575
9650
|
type: config.type
|
|
9576
9651
|
};
|
|
9577
|
-
if (isObject(_optionalChain([spanInfo, 'optionalAccess',
|
|
9652
|
+
if (isObject(_optionalChain([spanInfo, 'optionalAccess', _164 => _164.spanAttributes]))) {
|
|
9578
9653
|
mergeDicts(spanAttributes, spanInfo.spanAttributes);
|
|
9579
9654
|
}
|
|
9580
9655
|
return {
|
|
9581
|
-
name: typeof _optionalChain([spanInfo, 'optionalAccess',
|
|
9656
|
+
name: typeof _optionalChain([spanInfo, 'optionalAccess', _165 => _165.name]) === "string" && spanInfo.name ? spanInfo.name : config.name,
|
|
9582
9657
|
spanAttributes,
|
|
9583
|
-
spanInfoMetadata: isObject(_optionalChain([spanInfo, 'optionalAccess',
|
|
9658
|
+
spanInfoMetadata: isObject(_optionalChain([spanInfo, 'optionalAccess', _166 => _166.metadata])) ? spanInfo.metadata : void 0
|
|
9584
9659
|
};
|
|
9585
9660
|
}
|
|
9586
9661
|
function mergeInputMetadata(metadata, spanInfoMetadata) {
|
|
@@ -9670,7 +9745,7 @@ var BasePlugin = (_class17 = class {constructor() { _class17.prototype.__init62.
|
|
|
9670
9745
|
try {
|
|
9671
9746
|
const output = config.extractOutput(event.result, event);
|
|
9672
9747
|
const metrics = config.extractMetrics(event.result, startTime, event);
|
|
9673
|
-
const metadata = _optionalChain([config, 'access',
|
|
9748
|
+
const metadata = _optionalChain([config, 'access', _167 => _167.extractMetadata, 'optionalCall', _168 => _168(event.result, event)]);
|
|
9674
9749
|
span.log({
|
|
9675
9750
|
output,
|
|
9676
9751
|
...metadata !== void 0 ? { metadata } : {},
|
|
@@ -9990,7 +10065,7 @@ function ensureSpanStateForEvent(states, config, event, channelName) {
|
|
|
9990
10065
|
function bindCurrentSpanStoreToStart(tracingChannel2, states, config, channelName) {
|
|
9991
10066
|
const state = _internalGetGlobalState();
|
|
9992
10067
|
const startChannel = tracingChannel2.start;
|
|
9993
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
10068
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _169 => _169.contextManager]);
|
|
9994
10069
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
9995
10070
|
if (!currentSpanStore || !startChannel) {
|
|
9996
10071
|
return void 0;
|
|
@@ -10078,7 +10153,7 @@ function traceAsyncChannel(channel2, config) {
|
|
|
10078
10153
|
startTime,
|
|
10079
10154
|
asyncEndEvent
|
|
10080
10155
|
);
|
|
10081
|
-
const metadata = _optionalChain([config, 'access',
|
|
10156
|
+
const metadata = _optionalChain([config, 'access', _170 => _170.extractMetadata, 'optionalCall', _171 => _171(
|
|
10082
10157
|
asyncEndEvent.result,
|
|
10083
10158
|
asyncEndEvent
|
|
10084
10159
|
)]);
|
|
@@ -10100,7 +10175,7 @@ function traceAsyncChannel(channel2, config) {
|
|
|
10100
10175
|
};
|
|
10101
10176
|
tracingChannel2.subscribe(handlers);
|
|
10102
10177
|
return () => {
|
|
10103
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
10178
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _172 => _172()]);
|
|
10104
10179
|
tracingChannel2.unsubscribe(handlers);
|
|
10105
10180
|
};
|
|
10106
10181
|
}
|
|
@@ -10206,7 +10281,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
10206
10281
|
});
|
|
10207
10282
|
return;
|
|
10208
10283
|
}
|
|
10209
|
-
if (_optionalChain([config, 'access',
|
|
10284
|
+
if (_optionalChain([config, 'access', _173 => _173.patchResult, 'optionalCall', _174 => _174({
|
|
10210
10285
|
channelName,
|
|
10211
10286
|
endEvent: asyncEndEvent,
|
|
10212
10287
|
result: asyncEndEvent.result,
|
|
@@ -10226,7 +10301,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
10226
10301
|
startTime,
|
|
10227
10302
|
asyncEndEvent
|
|
10228
10303
|
);
|
|
10229
|
-
const metadata = _optionalChain([config, 'access',
|
|
10304
|
+
const metadata = _optionalChain([config, 'access', _175 => _175.extractMetadata, 'optionalCall', _176 => _176(
|
|
10230
10305
|
asyncEndEvent.result,
|
|
10231
10306
|
asyncEndEvent
|
|
10232
10307
|
)]);
|
|
@@ -10259,7 +10334,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
10259
10334
|
};
|
|
10260
10335
|
tracingChannel2.subscribe(handlers);
|
|
10261
10336
|
return () => {
|
|
10262
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
10337
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _177 => _177()]);
|
|
10263
10338
|
tracingChannel2.unsubscribe(handlers);
|
|
10264
10339
|
};
|
|
10265
10340
|
}
|
|
@@ -10294,7 +10369,7 @@ function traceSyncStreamChannel(channel2, config) {
|
|
|
10294
10369
|
...endEvent,
|
|
10295
10370
|
result
|
|
10296
10371
|
};
|
|
10297
|
-
if (_optionalChain([config, 'access',
|
|
10372
|
+
if (_optionalChain([config, 'access', _178 => _178.patchResult, 'optionalCall', _179 => _179({
|
|
10298
10373
|
channelName,
|
|
10299
10374
|
endEvent: resolvedEndEvent,
|
|
10300
10375
|
result,
|
|
@@ -10375,7 +10450,7 @@ function traceSyncStreamChannel(channel2, config) {
|
|
|
10375
10450
|
};
|
|
10376
10451
|
tracingChannel2.subscribe(handlers);
|
|
10377
10452
|
return () => {
|
|
10378
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
10453
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _180 => _180()]);
|
|
10379
10454
|
tracingChannel2.unsubscribe(handlers);
|
|
10380
10455
|
};
|
|
10381
10456
|
}
|
|
@@ -10450,7 +10525,7 @@ function processInputAttachments(input) {
|
|
|
10450
10525
|
let attachmentIndex = 0;
|
|
10451
10526
|
const inferMediaTypeFromDataUrl = (value, fallback2) => {
|
|
10452
10527
|
const mediaTypeMatch = value.match(/^data:([^;]+);/);
|
|
10453
|
-
return _optionalChain([mediaTypeMatch, 'optionalAccess',
|
|
10528
|
+
return _optionalChain([mediaTypeMatch, 'optionalAccess', _181 => _181[1]]) || fallback2;
|
|
10454
10529
|
};
|
|
10455
10530
|
const toAttachment = (value, mediaType, filename) => {
|
|
10456
10531
|
const blob = convertDataToBlob(value, mediaType);
|
|
@@ -10704,11 +10779,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10704
10779
|
};
|
|
10705
10780
|
},
|
|
10706
10781
|
extractOutput: (result) => {
|
|
10707
|
-
return _optionalChain([result, 'optionalAccess',
|
|
10782
|
+
return _optionalChain([result, 'optionalAccess', _182 => _182.choices]);
|
|
10708
10783
|
},
|
|
10709
10784
|
extractMetrics: (result, startTime, endEvent) => {
|
|
10710
10785
|
const metrics = withCachedMetric(
|
|
10711
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10786
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _183 => _183.usage])),
|
|
10712
10787
|
result,
|
|
10713
10788
|
endEvent
|
|
10714
10789
|
);
|
|
@@ -10732,12 +10807,12 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10732
10807
|
};
|
|
10733
10808
|
},
|
|
10734
10809
|
extractOutput: (result) => {
|
|
10735
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
10810
|
+
const embedding = _optionalChain([result, 'optionalAccess', _184 => _184.data, 'optionalAccess', _185 => _185[0], 'optionalAccess', _186 => _186.embedding]);
|
|
10736
10811
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
10737
10812
|
},
|
|
10738
10813
|
extractMetrics: (result, _startTime, endEvent) => {
|
|
10739
10814
|
return withCachedMetric(
|
|
10740
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10815
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _187 => _187.usage])),
|
|
10741
10816
|
result,
|
|
10742
10817
|
endEvent
|
|
10743
10818
|
);
|
|
@@ -10756,11 +10831,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10756
10831
|
};
|
|
10757
10832
|
},
|
|
10758
10833
|
extractOutput: (result) => {
|
|
10759
|
-
return _optionalChain([result, 'optionalAccess',
|
|
10834
|
+
return _optionalChain([result, 'optionalAccess', _188 => _188.choices]);
|
|
10760
10835
|
},
|
|
10761
10836
|
extractMetrics: (result, startTime, endEvent) => {
|
|
10762
10837
|
const metrics = withCachedMetric(
|
|
10763
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10838
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _189 => _189.usage])),
|
|
10764
10839
|
result,
|
|
10765
10840
|
endEvent
|
|
10766
10841
|
);
|
|
@@ -10797,11 +10872,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10797
10872
|
};
|
|
10798
10873
|
},
|
|
10799
10874
|
extractOutput: (result) => {
|
|
10800
|
-
return _optionalChain([result, 'optionalAccess',
|
|
10875
|
+
return _optionalChain([result, 'optionalAccess', _190 => _190.results]);
|
|
10801
10876
|
},
|
|
10802
10877
|
extractMetrics: (result, _startTime, endEvent) => {
|
|
10803
10878
|
return withCachedMetric(
|
|
10804
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10879
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _191 => _191.usage])),
|
|
10805
10880
|
result,
|
|
10806
10881
|
endEvent
|
|
10807
10882
|
);
|
|
@@ -10820,7 +10895,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10820
10895
|
};
|
|
10821
10896
|
},
|
|
10822
10897
|
extractOutput: (result) => {
|
|
10823
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
10898
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _192 => _192.output]));
|
|
10824
10899
|
},
|
|
10825
10900
|
extractMetadata: (result) => {
|
|
10826
10901
|
if (!result) {
|
|
@@ -10831,7 +10906,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10831
10906
|
},
|
|
10832
10907
|
extractMetrics: (result, startTime, endEvent) => {
|
|
10833
10908
|
const metrics = withCachedMetric(
|
|
10834
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10909
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _193 => _193.usage])),
|
|
10835
10910
|
result,
|
|
10836
10911
|
endEvent
|
|
10837
10912
|
);
|
|
@@ -10884,7 +10959,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10884
10959
|
};
|
|
10885
10960
|
},
|
|
10886
10961
|
extractOutput: (result) => {
|
|
10887
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
10962
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _194 => _194.output]));
|
|
10888
10963
|
},
|
|
10889
10964
|
extractMetadata: (result) => {
|
|
10890
10965
|
if (!result) {
|
|
@@ -10895,7 +10970,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10895
10970
|
},
|
|
10896
10971
|
extractMetrics: (result, startTime, endEvent) => {
|
|
10897
10972
|
const metrics = withCachedMetric(
|
|
10898
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
10973
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _195 => _195.usage])),
|
|
10899
10974
|
result,
|
|
10900
10975
|
endEvent
|
|
10901
10976
|
);
|
|
@@ -10919,7 +10994,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10919
10994
|
};
|
|
10920
10995
|
},
|
|
10921
10996
|
extractOutput: (result) => {
|
|
10922
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
10997
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _196 => _196.output]));
|
|
10923
10998
|
},
|
|
10924
10999
|
extractMetadata: (result) => {
|
|
10925
11000
|
if (!result) {
|
|
@@ -10930,7 +11005,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
10930
11005
|
},
|
|
10931
11006
|
extractMetrics: (result, startTime, endEvent) => {
|
|
10932
11007
|
const metrics = withCachedMetric(
|
|
10933
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
11008
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _197 => _197.usage])),
|
|
10934
11009
|
result,
|
|
10935
11010
|
endEvent
|
|
10936
11011
|
);
|
|
@@ -11032,11 +11107,11 @@ function aggregateChatLogprobs(existing, incoming) {
|
|
|
11032
11107
|
return _nullishCoalesce(existing, () => ( null));
|
|
11033
11108
|
}
|
|
11034
11109
|
const aggregated = existing && existing !== null ? { ...existing, ...incoming } : { ...incoming };
|
|
11035
|
-
const content = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess',
|
|
11110
|
+
const content = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess', _198 => _198.content]), incoming.content);
|
|
11036
11111
|
if (content !== void 0) {
|
|
11037
11112
|
aggregated.content = content;
|
|
11038
11113
|
}
|
|
11039
|
-
const refusal = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess',
|
|
11114
|
+
const refusal = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess', _199 => _199.refusal]), incoming.refusal);
|
|
11040
11115
|
if (refusal !== void 0) {
|
|
11041
11116
|
aggregated.refusal = refusal;
|
|
11042
11117
|
}
|
|
@@ -11057,7 +11132,7 @@ function aggregateChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
11057
11132
|
...parseMetricsFromUsage(chunk.usage)
|
|
11058
11133
|
};
|
|
11059
11134
|
}
|
|
11060
|
-
const choice = _optionalChain([chunk, 'access',
|
|
11135
|
+
const choice = _optionalChain([chunk, 'access', _200 => _200.choices, 'optionalAccess', _201 => _201[0]]);
|
|
11061
11136
|
if (!choice) {
|
|
11062
11137
|
continue;
|
|
11063
11138
|
}
|
|
@@ -11127,14 +11202,14 @@ function aggregateResponseStreamEvents(chunks, _streamResult, endEvent) {
|
|
|
11127
11202
|
continue;
|
|
11128
11203
|
}
|
|
11129
11204
|
const response = chunk.response;
|
|
11130
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
11205
|
+
if (_optionalChain([response, 'optionalAccess', _202 => _202.output]) !== void 0) {
|
|
11131
11206
|
output = processImagesInOutput(response.output);
|
|
11132
11207
|
}
|
|
11133
11208
|
const { usage: _usage, output: _output, ...rest } = response || {};
|
|
11134
11209
|
if (Object.keys(rest).length > 0) {
|
|
11135
11210
|
metadata = rest;
|
|
11136
11211
|
}
|
|
11137
|
-
metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess',
|
|
11212
|
+
metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _203 => _203.usage]));
|
|
11138
11213
|
}
|
|
11139
11214
|
return {
|
|
11140
11215
|
output,
|
|
@@ -11309,7 +11384,7 @@ async function handleCodexEvent(state, event) {
|
|
|
11309
11384
|
return;
|
|
11310
11385
|
case "turn.failed":
|
|
11311
11386
|
await finalizeCodexRun(state, {
|
|
11312
|
-
error: _nullishCoalesce(_optionalChain([event, 'access',
|
|
11387
|
+
error: _nullishCoalesce(_optionalChain([event, 'access', _204 => _204.error, 'optionalAccess', _205 => _205.message]), () => ( "Codex turn failed"))
|
|
11313
11388
|
});
|
|
11314
11389
|
return;
|
|
11315
11390
|
case "item.started":
|
|
@@ -11580,7 +11655,7 @@ function mcpToolSpanArgs(parent, baseMetadata, item) {
|
|
|
11580
11655
|
spanAttributes: { type: "tool" /* TOOL */ }
|
|
11581
11656
|
},
|
|
11582
11657
|
end: {
|
|
11583
|
-
..._optionalChain([item, 'access',
|
|
11658
|
+
..._optionalChain([item, 'access', _206 => _206.error, 'optionalAccess', _207 => _207.message]) ? { error: item.error.message } : {},
|
|
11584
11659
|
metadata,
|
|
11585
11660
|
output: item.result
|
|
11586
11661
|
}
|
|
@@ -11642,7 +11717,7 @@ function extractThreadFromEvent(event) {
|
|
|
11642
11717
|
function extractThreadMetadata(thread) {
|
|
11643
11718
|
const threadOptions = extractThreadOptions(thread);
|
|
11644
11719
|
return {
|
|
11645
|
-
..._optionalChain([thread, 'optionalAccess',
|
|
11720
|
+
..._optionalChain([thread, 'optionalAccess', _208 => _208.id]) ? { "openai_codex.thread_id": thread.id } : {},
|
|
11646
11721
|
...extractThreadOptionsMetadata(threadOptions)
|
|
11647
11722
|
};
|
|
11648
11723
|
}
|
|
@@ -11843,7 +11918,7 @@ var AnthropicPlugin = class extends BasePlugin {
|
|
|
11843
11918
|
return message ? { role: message.role, content: message.content } : null;
|
|
11844
11919
|
},
|
|
11845
11920
|
extractMetrics: (message, startTime) => {
|
|
11846
|
-
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess',
|
|
11921
|
+
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess', _209 => _209.usage]));
|
|
11847
11922
|
if (startTime) {
|
|
11848
11923
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
11849
11924
|
}
|
|
@@ -11858,7 +11933,7 @@ var AnthropicPlugin = class extends BasePlugin {
|
|
|
11858
11933
|
const metadata = {};
|
|
11859
11934
|
const metas = ["stop_reason", "stop_sequence"];
|
|
11860
11935
|
for (const m of metas) {
|
|
11861
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
11936
|
+
if (_optionalChain([message, 'optionalAccess', _210 => _210[m]]) !== void 0) {
|
|
11862
11937
|
metadata[m] = message[m];
|
|
11863
11938
|
}
|
|
11864
11939
|
}
|
|
@@ -12008,8 +12083,8 @@ function wrapAnthropicToolRunnerTool(tool, index, state) {
|
|
|
12008
12083
|
Object.getOwnPropertyDescriptors(tool)
|
|
12009
12084
|
);
|
|
12010
12085
|
Object.defineProperty(wrappedTool, "run", {
|
|
12011
|
-
configurable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
12012
|
-
enumerable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
12086
|
+
configurable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _211 => _211.configurable]), () => ( true)),
|
|
12087
|
+
enumerable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _212 => _212.enumerable]), () => ( true)),
|
|
12013
12088
|
value: function braintrustAnthropicToolRunnerRun(...args) {
|
|
12014
12089
|
return state.span.traced(
|
|
12015
12090
|
(span) => {
|
|
@@ -12046,7 +12121,7 @@ function wrapAnthropicToolRunnerTool(tool, index, state) {
|
|
|
12046
12121
|
}
|
|
12047
12122
|
);
|
|
12048
12123
|
},
|
|
12049
|
-
writable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
12124
|
+
writable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _213 => _213.writable]), () => ( true))
|
|
12050
12125
|
});
|
|
12051
12126
|
Object.defineProperty(wrappedTool, ANTHROPIC_TOOL_RUNNER_TOOL_WRAPPED, {
|
|
12052
12127
|
configurable: false,
|
|
@@ -12151,10 +12226,10 @@ async function finalizeAnthropicToolRunner(state, finalMessage) {
|
|
|
12151
12226
|
const metadata = {
|
|
12152
12227
|
anthropic_tool_runner_iterations: state.iterationCount
|
|
12153
12228
|
};
|
|
12154
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
12229
|
+
if (_optionalChain([message, 'optionalAccess', _214 => _214.stop_reason]) !== void 0) {
|
|
12155
12230
|
metadata.stop_reason = message.stop_reason;
|
|
12156
12231
|
}
|
|
12157
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
12232
|
+
if (_optionalChain([message, 'optionalAccess', _215 => _215.stop_sequence]) !== void 0) {
|
|
12158
12233
|
metadata.stop_sequence = message.stop_sequence;
|
|
12159
12234
|
}
|
|
12160
12235
|
state.span.log({
|
|
@@ -12296,13 +12371,13 @@ function aggregateAnthropicStreamChunks(chunks) {
|
|
|
12296
12371
|
let metadata = {};
|
|
12297
12372
|
let role;
|
|
12298
12373
|
for (const event of chunks) {
|
|
12299
|
-
switch (_optionalChain([event, 'optionalAccess',
|
|
12374
|
+
switch (_optionalChain([event, 'optionalAccess', _216 => _216.type])) {
|
|
12300
12375
|
case "message_start":
|
|
12301
|
-
if (_optionalChain([event, 'access',
|
|
12376
|
+
if (_optionalChain([event, 'access', _217 => _217.message, 'optionalAccess', _218 => _218.usage])) {
|
|
12302
12377
|
const initialMetrics = parseMetricsFromUsage2(event.message.usage);
|
|
12303
12378
|
metrics = { ...metrics, ...initialMetrics };
|
|
12304
12379
|
}
|
|
12305
|
-
if (typeof _optionalChain([event, 'access',
|
|
12380
|
+
if (typeof _optionalChain([event, 'access', _219 => _219.message, 'optionalAccess', _220 => _220.role]) === "string") {
|
|
12306
12381
|
role = event.message.role;
|
|
12307
12382
|
}
|
|
12308
12383
|
break;
|
|
@@ -12368,7 +12443,7 @@ function aggregateAnthropicStreamChunks(chunks) {
|
|
|
12368
12443
|
})).filter(({ block }) => block !== void 0).sort((left, right) => left.index - right.index).map(({ block }) => block);
|
|
12369
12444
|
let output = fallbackTextDeltas.join("");
|
|
12370
12445
|
if (orderedContent.length > 0) {
|
|
12371
|
-
if (orderedContent.every(isTextContentBlock) && orderedContent.every((block) => !_optionalChain([block, 'access',
|
|
12446
|
+
if (orderedContent.every(isTextContentBlock) && orderedContent.every((block) => !_optionalChain([block, 'access', _221 => _221.citations, 'optionalAccess', _222 => _222.length]))) {
|
|
12372
12447
|
output = orderedContent.map((block) => block.text).join("");
|
|
12373
12448
|
} else {
|
|
12374
12449
|
output = {
|
|
@@ -12395,7 +12470,7 @@ function finalizeContentBlock(index, contentBlocks, contentBlockDeltas, fallback
|
|
|
12395
12470
|
return;
|
|
12396
12471
|
}
|
|
12397
12472
|
const acc = contentBlockDeltas[index];
|
|
12398
|
-
const text = _nullishCoalesce(_optionalChain([acc, 'optionalAccess',
|
|
12473
|
+
const text = _nullishCoalesce(_optionalChain([acc, 'optionalAccess', _223 => _223.textDeltas, 'access', _224 => _224.join, 'call', _225 => _225("")]), () => ( ""));
|
|
12399
12474
|
if (isToolUseLikeContentBlock(contentBlock)) {
|
|
12400
12475
|
if (!text) {
|
|
12401
12476
|
return;
|
|
@@ -12426,7 +12501,7 @@ function finalizeContentBlock(index, contentBlocks, contentBlockDeltas, fallback
|
|
|
12426
12501
|
return;
|
|
12427
12502
|
}
|
|
12428
12503
|
const updated = { ...contentBlock, text };
|
|
12429
|
-
if (_optionalChain([acc, 'optionalAccess',
|
|
12504
|
+
if (_optionalChain([acc, 'optionalAccess', _226 => _226.citations, 'access', _227 => _227.length])) {
|
|
12430
12505
|
updated.citations = acc.citations;
|
|
12431
12506
|
}
|
|
12432
12507
|
contentBlocks[index] = updated;
|
|
@@ -12931,10 +13006,10 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
12931
13006
|
}
|
|
12932
13007
|
};
|
|
12933
13008
|
function resolveDenyOutputPaths(event, defaultDenyOutputPaths) {
|
|
12934
|
-
if (Array.isArray(_optionalChain([event, 'optionalAccess',
|
|
13009
|
+
if (Array.isArray(_optionalChain([event, 'optionalAccess', _228 => _228.denyOutputPaths]))) {
|
|
12935
13010
|
return event.denyOutputPaths;
|
|
12936
13011
|
}
|
|
12937
|
-
const firstArgument2 = _optionalChain([event, 'optionalAccess',
|
|
13012
|
+
const firstArgument2 = _optionalChain([event, 'optionalAccess', _229 => _229.arguments]) && event.arguments.length > 0 ? event.arguments[0] : void 0;
|
|
12938
13013
|
if (!firstArgument2 || typeof firstArgument2 !== "object") {
|
|
12939
13014
|
return defaultDenyOutputPaths;
|
|
12940
13015
|
}
|
|
@@ -13149,7 +13224,7 @@ var convertImageToAttachment = (image, explicitMimeType) => {
|
|
|
13149
13224
|
try {
|
|
13150
13225
|
if (typeof image === "string" && image.startsWith("data:")) {
|
|
13151
13226
|
const [mimeTypeSection, base64Data] = image.split(",");
|
|
13152
|
-
const mimeType = _optionalChain([mimeTypeSection, 'access',
|
|
13227
|
+
const mimeType = _optionalChain([mimeTypeSection, 'access', _230 => _230.match, 'call', _231 => _231(/data:(.*?);/), 'optionalAccess', _232 => _232[1]]);
|
|
13153
13228
|
if (mimeType && base64Data) {
|
|
13154
13229
|
const blob = convertDataToBlob(base64Data, mimeType);
|
|
13155
13230
|
if (blob) {
|
|
@@ -13279,7 +13354,7 @@ function extractTopLevelAISDKMetrics(result, event, startTime) {
|
|
|
13279
13354
|
return metrics;
|
|
13280
13355
|
}
|
|
13281
13356
|
function hasModelChildTracing(event) {
|
|
13282
|
-
return _optionalChain([event, 'optionalAccess',
|
|
13357
|
+
return _optionalChain([event, 'optionalAccess', _233 => _233.modelWrapped]) === true || _optionalChain([event, 'optionalAccess', _234 => _234.__braintrust_ai_sdk_model_wrapped]) === true;
|
|
13283
13358
|
}
|
|
13284
13359
|
function createAISDKIntegrationMetadata() {
|
|
13285
13360
|
return {
|
|
@@ -13290,7 +13365,7 @@ function createAISDKIntegrationMetadata() {
|
|
|
13290
13365
|
};
|
|
13291
13366
|
}
|
|
13292
13367
|
function resolveModelFromSelf(self) {
|
|
13293
|
-
return self && typeof self === "object" && "model" in self && self.model ? self.model : self && typeof self === "object" && "settings" in self && _optionalChain([self, 'access',
|
|
13368
|
+
return self && typeof self === "object" && "model" in self && self.model ? self.model : self && typeof self === "object" && "settings" in self && _optionalChain([self, 'access', _235 => _235.settings, 'optionalAccess', _236 => _236.model]) ? _optionalChain([self, 'access', _237 => _237.settings, 'optionalAccess', _238 => _238.model]) : void 0;
|
|
13294
13369
|
}
|
|
13295
13370
|
function extractBaseMetadata(model, self) {
|
|
13296
13371
|
const metadata = createAISDKIntegrationMetadata();
|
|
@@ -13417,9 +13492,9 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
13417
13492
|
case "raw":
|
|
13418
13493
|
if (chunk.rawValue) {
|
|
13419
13494
|
const rawVal = chunk.rawValue;
|
|
13420
|
-
if (_optionalChain([rawVal, 'access',
|
|
13495
|
+
if (_optionalChain([rawVal, 'access', _239 => _239.delta, 'optionalAccess', _240 => _240.content])) {
|
|
13421
13496
|
text += rawVal.delta.content;
|
|
13422
|
-
} else if (_optionalChain([rawVal, 'access',
|
|
13497
|
+
} else if (_optionalChain([rawVal, 'access', _241 => _241.choices, 'optionalAccess', _242 => _242[0], 'optionalAccess', _243 => _243.delta, 'optionalAccess', _244 => _244.content])) {
|
|
13423
13498
|
text += rawVal.choices[0].delta.content;
|
|
13424
13499
|
} else if (typeof rawVal.text === "string") {
|
|
13425
13500
|
text += rawVal.text;
|
|
@@ -13573,14 +13648,14 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
13573
13648
|
return {
|
|
13574
13649
|
cleanup: cleanup.length > 0 ? () => {
|
|
13575
13650
|
while (cleanup.length > 0) {
|
|
13576
|
-
_optionalChain([cleanup, 'access',
|
|
13651
|
+
_optionalChain([cleanup, 'access', _245 => _245.pop, 'call', _246 => _246(), 'optionalCall', _247 => _247()]);
|
|
13577
13652
|
}
|
|
13578
13653
|
} : void 0,
|
|
13579
13654
|
modelWrapped
|
|
13580
13655
|
};
|
|
13581
13656
|
}
|
|
13582
13657
|
function finalizeAISDKChildTracing(event) {
|
|
13583
|
-
const cleanup = _optionalChain([event, 'optionalAccess',
|
|
13658
|
+
const cleanup = _optionalChain([event, 'optionalAccess', _248 => _248.__braintrust_ai_sdk_cleanup]);
|
|
13584
13659
|
if (event && typeof cleanup === "function") {
|
|
13585
13660
|
cleanup();
|
|
13586
13661
|
delete event.__braintrust_ai_sdk_cleanup;
|
|
@@ -13793,10 +13868,10 @@ function buildAISDKChildMetadata(model) {
|
|
|
13793
13868
|
function buildResolvedMetadataPayload(result) {
|
|
13794
13869
|
const gatewayInfo = extractGatewayRoutingInfo(result);
|
|
13795
13870
|
const metadata = {};
|
|
13796
|
-
if (_optionalChain([gatewayInfo, 'optionalAccess',
|
|
13871
|
+
if (_optionalChain([gatewayInfo, 'optionalAccess', _249 => _249.provider])) {
|
|
13797
13872
|
metadata.provider = gatewayInfo.provider;
|
|
13798
13873
|
}
|
|
13799
|
-
if (_optionalChain([gatewayInfo, 'optionalAccess',
|
|
13874
|
+
if (_optionalChain([gatewayInfo, 'optionalAccess', _250 => _250.model])) {
|
|
13800
13875
|
metadata.model = gatewayInfo.model;
|
|
13801
13876
|
}
|
|
13802
13877
|
let finishReason;
|
|
@@ -13817,7 +13892,7 @@ function resolveAISDKModel(model, aiSDK) {
|
|
|
13817
13892
|
if (typeof model !== "string") {
|
|
13818
13893
|
return model;
|
|
13819
13894
|
}
|
|
13820
|
-
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([aiSDK, 'optionalAccess',
|
|
13895
|
+
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([aiSDK, 'optionalAccess', _251 => _251.gateway]))), () => ( null));
|
|
13821
13896
|
if (provider && typeof provider.languageModel === "function") {
|
|
13822
13897
|
return provider.languageModel(model);
|
|
13823
13898
|
}
|
|
@@ -13879,8 +13954,8 @@ function processAISDKRerankOutput(output, _denyOutputPaths) {
|
|
|
13879
13954
|
return ranking.slice(0, 100).map((item) => {
|
|
13880
13955
|
const entry = item && typeof item === "object" ? item : void 0;
|
|
13881
13956
|
return {
|
|
13882
|
-
index: typeof _optionalChain([entry, 'optionalAccess',
|
|
13883
|
-
relevance_score: typeof _optionalChain([entry, 'optionalAccess',
|
|
13957
|
+
index: typeof _optionalChain([entry, 'optionalAccess', _252 => _252.originalIndex]) === "number" ? entry.originalIndex : void 0,
|
|
13958
|
+
relevance_score: typeof _optionalChain([entry, 'optionalAccess', _253 => _253.score]) === "number" ? entry.score : void 0
|
|
13884
13959
|
};
|
|
13885
13960
|
});
|
|
13886
13961
|
}
|
|
@@ -13903,7 +13978,7 @@ function extractTokenMetrics(result) {
|
|
|
13903
13978
|
return metrics;
|
|
13904
13979
|
}
|
|
13905
13980
|
const promptTokens = firstNumber2(
|
|
13906
|
-
_optionalChain([usage, 'access',
|
|
13981
|
+
_optionalChain([usage, 'access', _254 => _254.inputTokens, 'optionalAccess', _255 => _255.total]),
|
|
13907
13982
|
usage.inputTokens,
|
|
13908
13983
|
usage.promptTokens,
|
|
13909
13984
|
usage.prompt_tokens
|
|
@@ -13912,7 +13987,7 @@ function extractTokenMetrics(result) {
|
|
|
13912
13987
|
metrics.prompt_tokens = promptTokens;
|
|
13913
13988
|
}
|
|
13914
13989
|
const completionTokens = firstNumber2(
|
|
13915
|
-
_optionalChain([usage, 'access',
|
|
13990
|
+
_optionalChain([usage, 'access', _256 => _256.outputTokens, 'optionalAccess', _257 => _257.total]),
|
|
13916
13991
|
usage.outputTokens,
|
|
13917
13992
|
usage.completionTokens,
|
|
13918
13993
|
usage.completion_tokens
|
|
@@ -13929,8 +14004,8 @@ function extractTokenMetrics(result) {
|
|
|
13929
14004
|
metrics.tokens = totalTokens;
|
|
13930
14005
|
}
|
|
13931
14006
|
const promptCachedTokens = firstNumber2(
|
|
13932
|
-
_optionalChain([usage, 'access',
|
|
13933
|
-
_optionalChain([usage, 'access',
|
|
14007
|
+
_optionalChain([usage, 'access', _258 => _258.inputTokens, 'optionalAccess', _259 => _259.cacheRead]),
|
|
14008
|
+
_optionalChain([usage, 'access', _260 => _260.inputTokenDetails, 'optionalAccess', _261 => _261.cacheReadTokens]),
|
|
13934
14009
|
usage.cachedInputTokens,
|
|
13935
14010
|
usage.promptCachedTokens,
|
|
13936
14011
|
usage.prompt_cached_tokens
|
|
@@ -13939,8 +14014,8 @@ function extractTokenMetrics(result) {
|
|
|
13939
14014
|
metrics.prompt_cached_tokens = promptCachedTokens;
|
|
13940
14015
|
}
|
|
13941
14016
|
const promptCacheCreationTokens = firstNumber2(
|
|
13942
|
-
_optionalChain([usage, 'access',
|
|
13943
|
-
_optionalChain([usage, 'access',
|
|
14017
|
+
_optionalChain([usage, 'access', _262 => _262.inputTokens, 'optionalAccess', _263 => _263.cacheWrite]),
|
|
14018
|
+
_optionalChain([usage, 'access', _264 => _264.inputTokenDetails, 'optionalAccess', _265 => _265.cacheWriteTokens]),
|
|
13944
14019
|
usage.promptCacheCreationTokens,
|
|
13945
14020
|
usage.prompt_cache_creation_tokens,
|
|
13946
14021
|
extractAnthropicCacheCreationTokens(result)
|
|
@@ -13963,7 +14038,7 @@ function extractTokenMetrics(result) {
|
|
|
13963
14038
|
metrics.completion_cached_tokens = completionCachedTokens;
|
|
13964
14039
|
}
|
|
13965
14040
|
const reasoningTokenCount = firstNumber2(
|
|
13966
|
-
_optionalChain([usage, 'access',
|
|
14041
|
+
_optionalChain([usage, 'access', _266 => _266.outputTokens, 'optionalAccess', _267 => _267.reasoning]),
|
|
13967
14042
|
usage.reasoningTokens,
|
|
13968
14043
|
usage.completionReasoningTokens,
|
|
13969
14044
|
usage.completion_reasoning_tokens,
|
|
@@ -13993,13 +14068,13 @@ function extractAnthropicCacheCreationTokens(result) {
|
|
|
13993
14068
|
result,
|
|
13994
14069
|
"providerMetadata"
|
|
13995
14070
|
);
|
|
13996
|
-
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess',
|
|
14071
|
+
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess', _268 => _268.anthropic]);
|
|
13997
14072
|
if (!anthropicMetadata) {
|
|
13998
14073
|
return void 0;
|
|
13999
14074
|
}
|
|
14000
14075
|
return firstNumber2(
|
|
14001
14076
|
anthropicMetadata.cacheCreationInputTokens,
|
|
14002
|
-
_optionalChain([anthropicMetadata, 'access',
|
|
14077
|
+
_optionalChain([anthropicMetadata, 'access', _269 => _269.usage, 'optionalAccess', _270 => _270.cache_creation_input_tokens])
|
|
14003
14078
|
);
|
|
14004
14079
|
}
|
|
14005
14080
|
function safeResultFieldRead(result, field) {
|
|
@@ -14007,7 +14082,7 @@ function safeResultFieldRead(result, field) {
|
|
|
14007
14082
|
}
|
|
14008
14083
|
function safeSerializableFieldRead(obj, field) {
|
|
14009
14084
|
try {
|
|
14010
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
14085
|
+
const value = _optionalChain([obj, 'optionalAccess', _271 => _271[field]]);
|
|
14011
14086
|
if (isPromiseLike(value)) {
|
|
14012
14087
|
void Promise.resolve(value).catch(() => {
|
|
14013
14088
|
});
|
|
@@ -14101,7 +14176,7 @@ function extractSerializableOutputFields(output) {
|
|
|
14101
14176
|
];
|
|
14102
14177
|
for (const name of directFieldNames) {
|
|
14103
14178
|
try {
|
|
14104
|
-
const value = _optionalChain([output, 'optionalAccess',
|
|
14179
|
+
const value = _optionalChain([output, 'optionalAccess', _272 => _272[name]]);
|
|
14105
14180
|
if (isPromiseLike(value)) {
|
|
14106
14181
|
void Promise.resolve(value).catch(() => {
|
|
14107
14182
|
});
|
|
@@ -14134,8 +14209,8 @@ function isSerializableOutputValue(value) {
|
|
|
14134
14209
|
return true;
|
|
14135
14210
|
}
|
|
14136
14211
|
function serializeModelWithProvider(model) {
|
|
14137
|
-
const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess',
|
|
14138
|
-
const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess',
|
|
14212
|
+
const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess', _273 => _273.modelId]);
|
|
14213
|
+
const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess', _274 => _274.provider]) : void 0;
|
|
14139
14214
|
if (!modelId) {
|
|
14140
14215
|
return { model: modelId, provider: explicitProvider };
|
|
14141
14216
|
}
|
|
@@ -14161,7 +14236,7 @@ function parseGatewayModelString(modelString) {
|
|
|
14161
14236
|
function extractGatewayRoutingInfo(result) {
|
|
14162
14237
|
const steps = safeSerializableFieldRead(result, "steps");
|
|
14163
14238
|
if (Array.isArray(steps) && steps.length > 0) {
|
|
14164
|
-
const routing2 = _optionalChain([steps, 'access',
|
|
14239
|
+
const routing2 = _optionalChain([steps, 'access', _275 => _275[0], 'optionalAccess', _276 => _276.providerMetadata, 'optionalAccess', _277 => _277.gateway, 'optionalAccess', _278 => _278.routing]);
|
|
14165
14240
|
if (routing2) {
|
|
14166
14241
|
return {
|
|
14167
14242
|
provider: routing2.resolvedProvider || routing2.finalProvider,
|
|
@@ -14173,7 +14248,7 @@ function extractGatewayRoutingInfo(result) {
|
|
|
14173
14248
|
result,
|
|
14174
14249
|
"providerMetadata"
|
|
14175
14250
|
);
|
|
14176
|
-
const routing = _optionalChain([providerMetadata, 'optionalAccess',
|
|
14251
|
+
const routing = _optionalChain([providerMetadata, 'optionalAccess', _279 => _279.gateway, 'optionalAccess', _280 => _280.routing]);
|
|
14177
14252
|
if (routing) {
|
|
14178
14253
|
return {
|
|
14179
14254
|
provider: routing.resolvedProvider || routing.finalProvider,
|
|
@@ -14188,8 +14263,8 @@ function extractCostFromResult(result) {
|
|
|
14188
14263
|
let totalCost = 0;
|
|
14189
14264
|
let foundCost = false;
|
|
14190
14265
|
for (const step of steps) {
|
|
14191
|
-
const gateway2 = _optionalChain([step, 'optionalAccess',
|
|
14192
|
-
const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess',
|
|
14266
|
+
const gateway2 = _optionalChain([step, 'optionalAccess', _281 => _281.providerMetadata, 'optionalAccess', _282 => _282.gateway]);
|
|
14267
|
+
const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _283 => _283.cost])) || parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _284 => _284.marketCost]));
|
|
14193
14268
|
if (stepCost !== void 0 && stepCost > 0) {
|
|
14194
14269
|
totalCost += stepCost;
|
|
14195
14270
|
foundCost = true;
|
|
@@ -14203,8 +14278,8 @@ function extractCostFromResult(result) {
|
|
|
14203
14278
|
result,
|
|
14204
14279
|
"providerMetadata"
|
|
14205
14280
|
);
|
|
14206
|
-
const gateway = _optionalChain([providerMetadata, 'optionalAccess',
|
|
14207
|
-
const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess',
|
|
14281
|
+
const gateway = _optionalChain([providerMetadata, 'optionalAccess', _285 => _285.gateway]);
|
|
14282
|
+
const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _286 => _286.cost])) || parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _287 => _287.marketCost]));
|
|
14208
14283
|
if (directCost !== void 0 && directCost > 0) {
|
|
14209
14284
|
return directCost;
|
|
14210
14285
|
}
|
|
@@ -14380,7 +14455,7 @@ function setClaudeLocalToolParentResolver(resolver) {
|
|
|
14380
14455
|
context.resolveLocalToolParent = resolver;
|
|
14381
14456
|
}
|
|
14382
14457
|
function getClaudeLocalToolParentResolver() {
|
|
14383
|
-
return _nullishCoalesce(_optionalChain([localToolContextStore, 'access',
|
|
14458
|
+
return _nullishCoalesce(_optionalChain([localToolContextStore, 'access', _288 => _288.getStore, 'call', _289 => _289(), 'optionalAccess', _290 => _290.resolveLocalToolParent]), () => ( fallbackLocalToolParentResolver));
|
|
14384
14459
|
}
|
|
14385
14460
|
function isAsyncIterable3(value) {
|
|
14386
14461
|
return value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
|
|
@@ -14674,10 +14749,10 @@ function upsertSubAgentDetails(detailsByToolUseId, toolUseId, update) {
|
|
|
14674
14749
|
return merged;
|
|
14675
14750
|
}
|
|
14676
14751
|
function formatSubAgentSpanName(details) {
|
|
14677
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
14752
|
+
if (_optionalChain([details, 'optionalAccess', _291 => _291.description])) {
|
|
14678
14753
|
return `Agent: ${details.description}`;
|
|
14679
14754
|
}
|
|
14680
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
14755
|
+
if (_optionalChain([details, 'optionalAccess', _292 => _292.agentType])) {
|
|
14681
14756
|
return `Agent: ${details.agentType}`;
|
|
14682
14757
|
}
|
|
14683
14758
|
return "Agent: sub-agent";
|
|
@@ -14732,7 +14807,7 @@ function extractUsageFromMessage(message) {
|
|
|
14732
14807
|
const metrics = {};
|
|
14733
14808
|
let usage;
|
|
14734
14809
|
if (message.type === "assistant") {
|
|
14735
|
-
usage = _optionalChain([message, 'access',
|
|
14810
|
+
usage = _optionalChain([message, 'access', _293 => _293.message, 'optionalAccess', _294 => _294.usage]);
|
|
14736
14811
|
} else if (message.type === "result") {
|
|
14737
14812
|
usage = message.usage;
|
|
14738
14813
|
}
|
|
@@ -14766,8 +14841,8 @@ function buildLLMInput(prompt, conversationHistory, capturedPromptMessages) {
|
|
|
14766
14841
|
promptMessages.push({ content: prompt, role: "user" });
|
|
14767
14842
|
} else if (capturedPromptMessages && capturedPromptMessages.length > 0) {
|
|
14768
14843
|
for (const msg of capturedPromptMessages) {
|
|
14769
|
-
const role = _optionalChain([msg, 'access',
|
|
14770
|
-
const content = _optionalChain([msg, 'access',
|
|
14844
|
+
const role = _optionalChain([msg, 'access', _295 => _295.message, 'optionalAccess', _296 => _296.role]);
|
|
14845
|
+
const content = _optionalChain([msg, 'access', _297 => _297.message, 'optionalAccess', _298 => _298.content]);
|
|
14771
14846
|
if (role && content !== void 0) {
|
|
14772
14847
|
promptMessages.push({ content, role });
|
|
14773
14848
|
}
|
|
@@ -14784,7 +14859,7 @@ async function createLLMSpanForMessages(messages, prompt, conversationHistory, o
|
|
|
14784
14859
|
return void 0;
|
|
14785
14860
|
}
|
|
14786
14861
|
const lastMessage = messages[messages.length - 1];
|
|
14787
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
14862
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _299 => _299.message, 'optionalAccess', _300 => _300.usage])) {
|
|
14788
14863
|
return void 0;
|
|
14789
14864
|
}
|
|
14790
14865
|
const model = lastMessage.message.model || options.model;
|
|
@@ -14795,7 +14870,7 @@ async function createLLMSpanForMessages(messages, prompt, conversationHistory, o
|
|
|
14795
14870
|
capturedPromptMessages
|
|
14796
14871
|
);
|
|
14797
14872
|
const outputs = messages.map(
|
|
14798
|
-
(m) => _optionalChain([m, 'access',
|
|
14873
|
+
(m) => _optionalChain([m, 'access', _301 => _301.message, 'optionalAccess', _302 => _302.content]) && _optionalChain([m, 'access', _303 => _303.message, 'optionalAccess', _304 => _304.role]) ? { content: m.message.content, role: m.message.role } : void 0
|
|
14799
14874
|
).filter(
|
|
14800
14875
|
(c) => c !== void 0
|
|
14801
14876
|
);
|
|
@@ -14815,7 +14890,7 @@ async function createLLMSpanForMessages(messages, prompt, conversationHistory, o
|
|
|
14815
14890
|
});
|
|
14816
14891
|
const spanExport = await span.export();
|
|
14817
14892
|
await span.end();
|
|
14818
|
-
const finalMessage = _optionalChain([lastMessage, 'access',
|
|
14893
|
+
const finalMessage = _optionalChain([lastMessage, 'access', _305 => _305.message, 'optionalAccess', _306 => _306.content]) && _optionalChain([lastMessage, 'access', _307 => _307.message, 'optionalAccess', _308 => _308.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
|
|
14819
14894
|
return {
|
|
14820
14895
|
finalMessage,
|
|
14821
14896
|
spanExport
|
|
@@ -14952,18 +15027,18 @@ function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers,
|
|
|
14952
15027
|
subAgentDetailsByToolUseId.get(toolUseID)
|
|
14953
15028
|
)
|
|
14954
15029
|
};
|
|
14955
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
15030
|
+
if (_optionalChain([response, 'optionalAccess', _309 => _309.status])) {
|
|
14956
15031
|
metadata["claude_agent_sdk.status"] = response.status;
|
|
14957
15032
|
}
|
|
14958
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
15033
|
+
if (_optionalChain([response, 'optionalAccess', _310 => _310.totalDurationMs])) {
|
|
14959
15034
|
metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
|
|
14960
15035
|
}
|
|
14961
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
15036
|
+
if (_optionalChain([response, 'optionalAccess', _311 => _311.totalToolUseCount]) !== void 0) {
|
|
14962
15037
|
metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
|
|
14963
15038
|
}
|
|
14964
15039
|
subAgentSpan.log({
|
|
14965
15040
|
metadata,
|
|
14966
|
-
output: _optionalChain([response, 'optionalAccess',
|
|
15041
|
+
output: _optionalChain([response, 'optionalAccess', _312 => _312.content])
|
|
14967
15042
|
});
|
|
14968
15043
|
} finally {
|
|
14969
15044
|
subAgentSpan.end();
|
|
@@ -15175,7 +15250,7 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
15175
15250
|
if (state.currentMessages.length === 0) {
|
|
15176
15251
|
return;
|
|
15177
15252
|
}
|
|
15178
|
-
const parentToolUseId = _nullishCoalesce(_optionalChain([state, 'access',
|
|
15253
|
+
const parentToolUseId = _nullishCoalesce(_optionalChain([state, 'access', _313 => _313.currentMessages, 'access', _314 => _314[0], 'optionalAccess', _315 => _315.parent_tool_use_id]), () => ( null));
|
|
15179
15254
|
const parentKey = llmParentKey(parentToolUseId);
|
|
15180
15255
|
let parentSpan = await state.span.export();
|
|
15181
15256
|
if (parentToolUseId) {
|
|
@@ -15210,14 +15285,14 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
15210
15285
|
}
|
|
15211
15286
|
state.activeLlmSpansByParentToolUse.delete(parentKey);
|
|
15212
15287
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
15213
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
15288
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _316 => _316.message, 'optionalAccess', _317 => _317.usage])) {
|
|
15214
15289
|
state.accumulatedOutputTokens += getNumberProperty(lastMessage.message.usage, "output_tokens") || 0;
|
|
15215
15290
|
}
|
|
15216
15291
|
state.currentMessages.length = 0;
|
|
15217
15292
|
}
|
|
15218
15293
|
function maybeTrackToolUseContext(state, message) {
|
|
15219
15294
|
seedTaskToolUseIdMapping(state.taskIdToToolUseId, message);
|
|
15220
|
-
if (message.type !== "assistant" || !Array.isArray(_optionalChain([message, 'access',
|
|
15295
|
+
if (message.type !== "assistant" || !Array.isArray(_optionalChain([message, 'access', _318 => _318.message, 'optionalAccess', _319 => _319.content]))) {
|
|
15221
15296
|
return;
|
|
15222
15297
|
}
|
|
15223
15298
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
@@ -15400,13 +15475,13 @@ async function handleStreamMessage(state, message) {
|
|
|
15400
15475
|
return;
|
|
15401
15476
|
}
|
|
15402
15477
|
await maybeStartSubAgentSpan(state, message);
|
|
15403
|
-
const messageId = _optionalChain([message, 'access',
|
|
15478
|
+
const messageId = _optionalChain([message, 'access', _320 => _320.message, 'optionalAccess', _321 => _321.id]);
|
|
15404
15479
|
if (messageId && messageId !== state.currentMessageId) {
|
|
15405
15480
|
await finalizeCurrentMessageGroup(state);
|
|
15406
15481
|
state.currentMessageId = messageId;
|
|
15407
15482
|
state.currentMessageStartTime = getCurrentUnixTimestamp();
|
|
15408
15483
|
}
|
|
15409
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
15484
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _322 => _322.message, 'optionalAccess', _323 => _323.usage])) {
|
|
15410
15485
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
15411
15486
|
await ensureActiveLlmSpanForParentToolUse(
|
|
15412
15487
|
state.span,
|
|
@@ -15425,7 +15500,7 @@ async function handleStreamMessage(state, message) {
|
|
|
15425
15500
|
const finalUsageMetrics = extractUsageFromMessage(message);
|
|
15426
15501
|
if (state.currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
15427
15502
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
15428
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
15503
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _324 => _324.message, 'optionalAccess', _325 => _325.usage])) {
|
|
15429
15504
|
const adjustedTokens = finalUsageMetrics.completion_tokens - state.accumulatedOutputTokens;
|
|
15430
15505
|
if (adjustedTokens >= 0) {
|
|
15431
15506
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -15530,7 +15605,7 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
15530
15605
|
yield message;
|
|
15531
15606
|
}
|
|
15532
15607
|
} finally {
|
|
15533
|
-
_optionalChain([resolvePromptDone, 'optionalCall',
|
|
15608
|
+
_optionalChain([resolvePromptDone, 'optionalCall', _326 => _326()]);
|
|
15534
15609
|
}
|
|
15535
15610
|
})();
|
|
15536
15611
|
}
|
|
@@ -15565,10 +15640,10 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
15565
15640
|
const skipLocalToolHooks = options[CLAUDE_AGENT_SDK_SKIP_LOCAL_TOOL_HOOKS_OPTION] === true || hasLocalToolHandlers;
|
|
15566
15641
|
const resolveToolUseParentSpan = async (toolUseID, context) => {
|
|
15567
15642
|
const trackedParentToolUseId = toolUseToParent.get(toolUseID);
|
|
15568
|
-
const parentToolUseId = _nullishCoalesce(trackedParentToolUseId, () => ( (_optionalChain([context, 'optionalAccess',
|
|
15643
|
+
const parentToolUseId = _nullishCoalesce(trackedParentToolUseId, () => ( (_optionalChain([context, 'optionalAccess', _327 => _327.agentId]) ? _nullishCoalesce(taskIdToToolUseId.get(context.agentId), () => ( null)) : null)));
|
|
15569
15644
|
const parentKey = llmParentKey(parentToolUseId);
|
|
15570
15645
|
const activeLlmSpan = activeLlmSpansByParentToolUse.get(parentKey);
|
|
15571
|
-
if (_optionalChain([context, 'optionalAccess',
|
|
15646
|
+
if (_optionalChain([context, 'optionalAccess', _328 => _328.preferTaskSiblingParent])) {
|
|
15572
15647
|
if (!activeLlmSpan) {
|
|
15573
15648
|
await ensureActiveLlmSpanForParentToolUse(
|
|
15574
15649
|
span,
|
|
@@ -15813,7 +15888,7 @@ var CursorSDKPlugin = (_class18 = class extends BasePlugin {constructor(...args3
|
|
|
15813
15888
|
...extractRunResultMetadata(event.result)
|
|
15814
15889
|
},
|
|
15815
15890
|
metrics: buildDurationMetrics2(state.startTime),
|
|
15816
|
-
output: _nullishCoalesce(_optionalChain([event, 'access',
|
|
15891
|
+
output: _nullishCoalesce(_optionalChain([event, 'access', _329 => _329.result, 'optionalAccess', _330 => _330.result]), () => ( event.result))
|
|
15817
15892
|
});
|
|
15818
15893
|
} finally {
|
|
15819
15894
|
state.span.end();
|
|
@@ -16134,9 +16209,9 @@ async function handleToolUpdate(state, update) {
|
|
|
16134
16209
|
toolCall
|
|
16135
16210
|
})));
|
|
16136
16211
|
finishToolSpan(toolState, {
|
|
16137
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
16212
|
+
error: _optionalChain([toolCall, 'optionalAccess', _331 => _331.status]) === "error" ? stringifyUnknown(result) : void 0,
|
|
16138
16213
|
metadata: {
|
|
16139
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
16214
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _332 => _332.status]), () => ( "completed"))
|
|
16140
16215
|
},
|
|
16141
16216
|
output: result
|
|
16142
16217
|
});
|
|
@@ -16157,10 +16232,10 @@ async function handleStreamMessage2(state, message) {
|
|
|
16157
16232
|
}
|
|
16158
16233
|
if (message.type === "assistant") {
|
|
16159
16234
|
const assistantMessage = message;
|
|
16160
|
-
for (const block of _nullishCoalesce(_optionalChain([assistantMessage, 'access',
|
|
16161
|
-
if (_optionalChain([block, 'optionalAccess',
|
|
16235
|
+
for (const block of _nullishCoalesce(_optionalChain([assistantMessage, 'access', _333 => _333.message, 'optionalAccess', _334 => _334.content]), () => ( []))) {
|
|
16236
|
+
if (_optionalChain([block, 'optionalAccess', _335 => _335.type]) === "text" && typeof block.text === "string") {
|
|
16162
16237
|
state.streamText.push(block.text);
|
|
16163
|
-
} else if (_optionalChain([block, 'optionalAccess',
|
|
16238
|
+
} else if (_optionalChain([block, 'optionalAccess', _336 => _336.type]) === "tool_use" && block.id) {
|
|
16164
16239
|
state.activeToolSpans.set(
|
|
16165
16240
|
block.id,
|
|
16166
16241
|
await startToolSpan(state, {
|
|
@@ -16229,29 +16304,29 @@ async function handleConversation(state, turns) {
|
|
|
16229
16304
|
state.conversationOutput = turns;
|
|
16230
16305
|
for (const turn of turns) {
|
|
16231
16306
|
if (turn.type === "agentConversationTurn") {
|
|
16232
|
-
for (const step of _nullishCoalesce(_optionalChain([turn, 'access',
|
|
16307
|
+
for (const step of _nullishCoalesce(_optionalChain([turn, 'access', _337 => _337.turn, 'optionalAccess', _338 => _338.steps]), () => ( []))) {
|
|
16233
16308
|
await handleConversationStep(state, step);
|
|
16234
16309
|
}
|
|
16235
16310
|
} else if (turn.type === "shellConversationTurn") {
|
|
16236
|
-
const command = _optionalChain([turn, 'access',
|
|
16311
|
+
const command = _optionalChain([turn, 'access', _339 => _339.turn, 'optionalAccess', _340 => _340.shellCommand, 'optionalAccess', _341 => _341.command]);
|
|
16237
16312
|
if (command) {
|
|
16238
16313
|
const callId = `shell:${state.activeToolSpans.size}:${command}`;
|
|
16239
16314
|
const toolState = await startToolSpan(state, {
|
|
16240
|
-
args: _optionalChain([turn, 'access',
|
|
16315
|
+
args: _optionalChain([turn, 'access', _342 => _342.turn, 'optionalAccess', _343 => _343.shellCommand]),
|
|
16241
16316
|
callId,
|
|
16242
16317
|
name: "shell",
|
|
16243
16318
|
status: "completed"
|
|
16244
16319
|
});
|
|
16245
16320
|
finishToolSpan(toolState, {
|
|
16246
16321
|
metadata: { "cursor_sdk.tool.status": "completed" },
|
|
16247
|
-
output: _optionalChain([turn, 'access',
|
|
16322
|
+
output: _optionalChain([turn, 'access', _344 => _344.turn, 'optionalAccess', _345 => _345.shellOutput])
|
|
16248
16323
|
});
|
|
16249
16324
|
}
|
|
16250
16325
|
}
|
|
16251
16326
|
}
|
|
16252
16327
|
}
|
|
16253
16328
|
async function handleConversationStep(state, step) {
|
|
16254
|
-
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access',
|
|
16329
|
+
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access', _346 => _346.message, 'optionalAccess', _347 => _347.text]) === "string") {
|
|
16255
16330
|
state.conversationText.push(step.message.text);
|
|
16256
16331
|
return;
|
|
16257
16332
|
}
|
|
@@ -16259,18 +16334,18 @@ async function handleConversationStep(state, step) {
|
|
|
16259
16334
|
return;
|
|
16260
16335
|
}
|
|
16261
16336
|
const toolCall = step.message;
|
|
16262
|
-
const callId = typeof _optionalChain([toolCall, 'optionalAccess',
|
|
16337
|
+
const callId = typeof _optionalChain([toolCall, 'optionalAccess', _348 => _348.callId]) === "string" ? toolCall.callId : `conversation-tool:${state.activeToolSpans.size}`;
|
|
16263
16338
|
const toolState = await startToolSpan(state, {
|
|
16264
16339
|
args: extractToolArgs(toolCall),
|
|
16265
16340
|
callId,
|
|
16266
16341
|
name: extractToolName(toolCall),
|
|
16267
|
-
status: _optionalChain([toolCall, 'optionalAccess',
|
|
16342
|
+
status: _optionalChain([toolCall, 'optionalAccess', _349 => _349.status]),
|
|
16268
16343
|
toolCall
|
|
16269
16344
|
});
|
|
16270
16345
|
finishToolSpan(toolState, {
|
|
16271
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
16346
|
+
error: _optionalChain([toolCall, 'optionalAccess', _350 => _350.status]) === "error" ? stringifyUnknown(toolCall.result) : void 0,
|
|
16272
16347
|
metadata: {
|
|
16273
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
16348
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _351 => _351.status]), () => ( "completed"))
|
|
16274
16349
|
},
|
|
16275
16350
|
output: extractToolResult(toolCall)
|
|
16276
16351
|
});
|
|
@@ -16287,7 +16362,7 @@ function handleStepUpdate(state, step) {
|
|
|
16287
16362
|
state.metadata["cursor_sdk.step_types"] = [step.type];
|
|
16288
16363
|
}
|
|
16289
16364
|
}
|
|
16290
|
-
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access',
|
|
16365
|
+
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access', _352 => _352.message, 'optionalAccess', _353 => _353.text]) === "string") {
|
|
16291
16366
|
state.stepText.push(step.message.text);
|
|
16292
16367
|
}
|
|
16293
16368
|
}
|
|
@@ -16298,10 +16373,10 @@ async function startToolSpan(state, args) {
|
|
|
16298
16373
|
"gen_ai.tool.call.id": args.callId,
|
|
16299
16374
|
"gen_ai.tool.name": name
|
|
16300
16375
|
};
|
|
16301
|
-
if (_optionalChain([args, 'access',
|
|
16376
|
+
if (_optionalChain([args, 'access', _354 => _354.truncated, 'optionalAccess', _355 => _355.args]) !== void 0) {
|
|
16302
16377
|
metadata["cursor_sdk.tool.args_truncated"] = args.truncated.args;
|
|
16303
16378
|
}
|
|
16304
|
-
if (_optionalChain([args, 'access',
|
|
16379
|
+
if (_optionalChain([args, 'access', _356 => _356.truncated, 'optionalAccess', _357 => _357.result]) !== void 0) {
|
|
16305
16380
|
metadata["cursor_sdk.tool.result_truncated"] = args.truncated.result;
|
|
16306
16381
|
}
|
|
16307
16382
|
const span = startSpan({
|
|
@@ -16358,7 +16433,7 @@ function finishToolSpan(toolState, result) {
|
|
|
16358
16433
|
}
|
|
16359
16434
|
}
|
|
16360
16435
|
} finally {
|
|
16361
|
-
_optionalChain([toolState, 'access',
|
|
16436
|
+
_optionalChain([toolState, 'access', _358 => _358.subAgentSpan, 'optionalAccess', _359 => _359.end, 'call', _360 => _360()]);
|
|
16362
16437
|
toolState.span.end();
|
|
16363
16438
|
}
|
|
16364
16439
|
}
|
|
@@ -16369,7 +16444,7 @@ async function finalizeCursorRun(state, params = {}) {
|
|
|
16369
16444
|
state.finalized = true;
|
|
16370
16445
|
const error = params.error;
|
|
16371
16446
|
const result = _nullishCoalesce(params.result, () => ( state.lastResult));
|
|
16372
|
-
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(params.output, () => ( _optionalChain([result, 'optionalAccess',
|
|
16447
|
+
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(params.output, () => ( _optionalChain([result, 'optionalAccess', _361 => _361.result]))), () => ( _optionalChain([state, 'access', _362 => _362.run, 'optionalAccess', _363 => _363.result]))), () => ( (state.conversationText.length > 0 ? state.conversationText.join("\n") : void 0))), () => ( state.conversationOutput)), () => ( (state.streamText.length > 0 ? state.streamText.join("") : void 0))), () => ( (state.deltaText.length > 0 ? state.deltaText.join("") : void 0))), () => ( (state.stepText.length > 0 ? state.stepText.join("\n") : void 0))), () => ( (state.taskText.length > 0 ? state.taskText.join("\n") : void 0)));
|
|
16373
16448
|
try {
|
|
16374
16449
|
const metadata = {
|
|
16375
16450
|
...state.metadata,
|
|
@@ -16413,7 +16488,7 @@ function sanitizeUserMessage(message) {
|
|
|
16413
16488
|
}
|
|
16414
16489
|
return {
|
|
16415
16490
|
...message,
|
|
16416
|
-
images: _optionalChain([message, 'access',
|
|
16491
|
+
images: _optionalChain([message, 'access', _364 => _364.images, 'optionalAccess', _365 => _365.map, 'call', _366 => _366((image) => {
|
|
16417
16492
|
const imageRecord = image;
|
|
16418
16493
|
return {
|
|
16419
16494
|
...typeof imageRecord.url === "string" ? { url: imageRecord.url } : {},
|
|
@@ -16439,9 +16514,9 @@ function extractAgentOptionsMetadata(options) {
|
|
|
16439
16514
|
...options.cloud ? {
|
|
16440
16515
|
"cursor_sdk.runtime": "cloud",
|
|
16441
16516
|
"cursor_sdk.cloud.auto_create_pr": options.cloud.autoCreatePR,
|
|
16442
|
-
"cursor_sdk.cloud.env_type": _optionalChain([options, 'access',
|
|
16443
|
-
"cursor_sdk.cloud.env_name": _optionalChain([options, 'access',
|
|
16444
|
-
"cursor_sdk.cloud.repos": _optionalChain([options, 'access',
|
|
16517
|
+
"cursor_sdk.cloud.env_type": _optionalChain([options, 'access', _367 => _367.cloud, 'access', _368 => _368.env, 'optionalAccess', _369 => _369.type]),
|
|
16518
|
+
"cursor_sdk.cloud.env_name": _optionalChain([options, 'access', _370 => _370.cloud, 'access', _371 => _371.env, 'optionalAccess', _372 => _372.name]),
|
|
16519
|
+
"cursor_sdk.cloud.repos": _optionalChain([options, 'access', _373 => _373.cloud, 'access', _374 => _374.repos, 'optionalAccess', _375 => _375.map, 'call', _376 => _376((repo) => repo.url), 'access', _377 => _377.filter, 'call', _378 => _378((url) => typeof url === "string")])
|
|
16445
16520
|
} : {}
|
|
16446
16521
|
};
|
|
16447
16522
|
}
|
|
@@ -16451,7 +16526,7 @@ function extractSendMetadata(options) {
|
|
|
16451
16526
|
}
|
|
16452
16527
|
return {
|
|
16453
16528
|
...extractModelMetadata(options.model),
|
|
16454
|
-
..._optionalChain([options, 'access',
|
|
16529
|
+
..._optionalChain([options, 'access', _379 => _379.local, 'optionalAccess', _380 => _380.force]) !== void 0 ? { "cursor_sdk.local.force": options.local.force } : {}
|
|
16455
16530
|
};
|
|
16456
16531
|
}
|
|
16457
16532
|
function extractAgentMetadata(agent) {
|
|
@@ -16486,7 +16561,7 @@ function extractRunResultMetadata(result) {
|
|
|
16486
16561
|
};
|
|
16487
16562
|
}
|
|
16488
16563
|
function extractGitMetadata(git) {
|
|
16489
|
-
const branches = _optionalChain([git, 'optionalAccess',
|
|
16564
|
+
const branches = _optionalChain([git, 'optionalAccess', _381 => _381.branches]);
|
|
16490
16565
|
if (!branches || branches.length === 0) {
|
|
16491
16566
|
return {};
|
|
16492
16567
|
}
|
|
@@ -16499,7 +16574,7 @@ function extractGitMetadata(git) {
|
|
|
16499
16574
|
};
|
|
16500
16575
|
}
|
|
16501
16576
|
function extractModelMetadata(model) {
|
|
16502
|
-
if (!_optionalChain([model, 'optionalAccess',
|
|
16577
|
+
if (!_optionalChain([model, 'optionalAccess', _382 => _382.id])) {
|
|
16503
16578
|
return {};
|
|
16504
16579
|
}
|
|
16505
16580
|
return {
|
|
@@ -16561,7 +16636,7 @@ function formatSubAgentSpanName2(toolCall, args) {
|
|
|
16561
16636
|
return description ? `Agent: ${description}` : "Agent: sub-agent";
|
|
16562
16637
|
}
|
|
16563
16638
|
function getString(obj, key) {
|
|
16564
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
16639
|
+
const value = _optionalChain([obj, 'optionalAccess', _383 => _383[key]]);
|
|
16565
16640
|
return typeof value === "string" ? value : void 0;
|
|
16566
16641
|
}
|
|
16567
16642
|
function stringifyUnknown(value) {
|
|
@@ -16724,7 +16799,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
16724
16799
|
}
|
|
16725
16800
|
}
|
|
16726
16801
|
onTraceStart(trace) {
|
|
16727
|
-
if (!_optionalChain([trace, 'optionalAccess',
|
|
16802
|
+
if (!_optionalChain([trace, 'optionalAccess', _384 => _384.traceId])) {
|
|
16728
16803
|
return Promise.resolve();
|
|
16729
16804
|
}
|
|
16730
16805
|
if (this.traceOrder.length >= this.maxTraces) {
|
|
@@ -16760,7 +16835,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
16760
16835
|
return Promise.resolve();
|
|
16761
16836
|
}
|
|
16762
16837
|
async onTraceEnd(trace) {
|
|
16763
|
-
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess',
|
|
16838
|
+
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess', _385 => _385.traceId]));
|
|
16764
16839
|
if (!traceData) {
|
|
16765
16840
|
return;
|
|
16766
16841
|
}
|
|
@@ -16780,7 +16855,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
16780
16855
|
}
|
|
16781
16856
|
}
|
|
16782
16857
|
onSpanStart(span) {
|
|
16783
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
16858
|
+
if (!_optionalChain([span, 'optionalAccess', _386 => _386.spanId]) || !span.traceId) {
|
|
16784
16859
|
return Promise.resolve();
|
|
16785
16860
|
}
|
|
16786
16861
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -16799,7 +16874,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
16799
16874
|
return Promise.resolve();
|
|
16800
16875
|
}
|
|
16801
16876
|
onSpanEnd(span) {
|
|
16802
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
16877
|
+
if (!_optionalChain([span, 'optionalAccess', _387 => _387.spanId]) || !span.traceId) {
|
|
16803
16878
|
return Promise.resolve();
|
|
16804
16879
|
}
|
|
16805
16880
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -17169,7 +17244,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
17169
17244
|
};
|
|
17170
17245
|
tracingChannel2.subscribe(handlers);
|
|
17171
17246
|
this.unsubscribers.push(() => {
|
|
17172
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
17247
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _388 => _388()]);
|
|
17173
17248
|
tracingChannel2.unsubscribe(handlers);
|
|
17174
17249
|
});
|
|
17175
17250
|
}
|
|
@@ -17266,7 +17341,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
17266
17341
|
};
|
|
17267
17342
|
tracingChannel2.subscribe(handlers);
|
|
17268
17343
|
this.unsubscribers.push(() => {
|
|
17269
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
17344
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _389 => _389()]);
|
|
17270
17345
|
tracingChannel2.unsubscribe(handlers);
|
|
17271
17346
|
});
|
|
17272
17347
|
}
|
|
@@ -17282,10 +17357,10 @@ function ensureSpanState(states, event, create) {
|
|
|
17282
17357
|
}
|
|
17283
17358
|
function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
17284
17359
|
const state = _internalGetGlobalState();
|
|
17285
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
17360
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _390 => _390.contextManager]);
|
|
17286
17361
|
const startChannel = tracingChannel2.start;
|
|
17287
17362
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
17288
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
17363
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _391 => _391.bindStore]) || !currentSpanStore) {
|
|
17289
17364
|
return void 0;
|
|
17290
17365
|
}
|
|
17291
17366
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -17297,7 +17372,7 @@ function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
|
17297
17372
|
return contextManager.wrapSpanForStore(span);
|
|
17298
17373
|
});
|
|
17299
17374
|
return () => {
|
|
17300
|
-
_optionalChain([startChannel, 'access',
|
|
17375
|
+
_optionalChain([startChannel, 'access', _392 => _392.unbindStore, 'optionalCall', _393 => _393(currentSpanStore)]);
|
|
17301
17376
|
};
|
|
17302
17377
|
}
|
|
17303
17378
|
function logErrorAndEndSpan(states, event) {
|
|
@@ -17532,7 +17607,7 @@ function serializePart(part) {
|
|
|
17532
17607
|
}
|
|
17533
17608
|
function serializeGenerateContentTools(params) {
|
|
17534
17609
|
const config = params.config ? tryToDict(params.config) : null;
|
|
17535
|
-
const tools = _optionalChain([config, 'optionalAccess',
|
|
17610
|
+
const tools = _optionalChain([config, 'optionalAccess', _394 => _394.tools]);
|
|
17536
17611
|
if (!Array.isArray(tools)) {
|
|
17537
17612
|
return null;
|
|
17538
17613
|
}
|
|
@@ -17591,7 +17666,7 @@ function extractGenerateContentMetrics(response, startTime) {
|
|
|
17591
17666
|
metrics.end = end;
|
|
17592
17667
|
metrics.duration = end - startTime;
|
|
17593
17668
|
}
|
|
17594
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
17669
|
+
if (_optionalChain([response, 'optionalAccess', _395 => _395.usageMetadata])) {
|
|
17595
17670
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
17596
17671
|
}
|
|
17597
17672
|
return metrics;
|
|
@@ -17604,7 +17679,7 @@ function extractEmbedContentMetrics(response, startTime) {
|
|
|
17604
17679
|
metrics.end = end;
|
|
17605
17680
|
metrics.duration = end - startTime;
|
|
17606
17681
|
}
|
|
17607
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
17682
|
+
if (_optionalChain([response, 'optionalAccess', _396 => _396.usageMetadata])) {
|
|
17608
17683
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
17609
17684
|
}
|
|
17610
17685
|
const embeddingTokenCount = extractEmbedPromptTokenCount(response);
|
|
@@ -17618,11 +17693,11 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
17618
17693
|
if (!response) {
|
|
17619
17694
|
return void 0;
|
|
17620
17695
|
}
|
|
17621
|
-
const usagePromptTokens = _optionalChain([response, 'access',
|
|
17696
|
+
const usagePromptTokens = _optionalChain([response, 'access', _397 => _397.usageMetadata, 'optionalAccess', _398 => _398.promptTokenCount]);
|
|
17622
17697
|
if (typeof usagePromptTokens === "number" && Number.isFinite(usagePromptTokens)) {
|
|
17623
17698
|
return usagePromptTokens;
|
|
17624
17699
|
}
|
|
17625
|
-
const usageTotalTokens = _optionalChain([response, 'access',
|
|
17700
|
+
const usageTotalTokens = _optionalChain([response, 'access', _399 => _399.usageMetadata, 'optionalAccess', _400 => _400.totalTokenCount]);
|
|
17626
17701
|
if (typeof usageTotalTokens === "number" && Number.isFinite(usageTotalTokens)) {
|
|
17627
17702
|
return usageTotalTokens;
|
|
17628
17703
|
}
|
|
@@ -17633,8 +17708,8 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
17633
17708
|
let total = 0;
|
|
17634
17709
|
let sawAny = false;
|
|
17635
17710
|
for (const embedding of embeddings) {
|
|
17636
|
-
const embeddingStats = tryToDict(_optionalChain([tryToDict, 'call',
|
|
17637
|
-
const tokenCount = _optionalChain([embeddingStats, 'optionalAccess',
|
|
17711
|
+
const embeddingStats = tryToDict(_optionalChain([tryToDict, 'call', _401 => _401(embedding), 'optionalAccess', _402 => _402.statistics]));
|
|
17712
|
+
const tokenCount = _optionalChain([embeddingStats, 'optionalAccess', _403 => _403.tokenCount]);
|
|
17638
17713
|
if (typeof tokenCount === "number" && Number.isFinite(tokenCount)) {
|
|
17639
17714
|
total += tokenCount;
|
|
17640
17715
|
sawAny = true;
|
|
@@ -17650,7 +17725,7 @@ function summarizeEmbedContentOutput(response) {
|
|
|
17650
17725
|
if (embeddings.length === 0) {
|
|
17651
17726
|
return void 0;
|
|
17652
17727
|
}
|
|
17653
|
-
const firstValues = _optionalChain([embeddings, 'access',
|
|
17728
|
+
const firstValues = _optionalChain([embeddings, 'access', _404 => _404[0], 'optionalAccess', _405 => _405.values]);
|
|
17654
17729
|
if (!Array.isArray(firstValues)) {
|
|
17655
17730
|
return void 0;
|
|
17656
17731
|
}
|
|
@@ -17705,7 +17780,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
17705
17780
|
}
|
|
17706
17781
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
17707
17782
|
for (const candidate of chunk.candidates) {
|
|
17708
|
-
if (_optionalChain([candidate, 'access',
|
|
17783
|
+
if (_optionalChain([candidate, 'access', _406 => _406.content, 'optionalAccess', _407 => _407.parts])) {
|
|
17709
17784
|
for (const part of candidate.content.parts) {
|
|
17710
17785
|
if (part.text !== void 0) {
|
|
17711
17786
|
if (part.thought) {
|
|
@@ -17736,7 +17811,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
17736
17811
|
parts.push({ text });
|
|
17737
17812
|
}
|
|
17738
17813
|
parts.push(...otherParts);
|
|
17739
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
17814
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _408 => _408.candidates])) {
|
|
17740
17815
|
const candidates = [];
|
|
17741
17816
|
for (const candidate of lastResponse.candidates) {
|
|
17742
17817
|
const candidateDict = {
|
|
@@ -17793,7 +17868,7 @@ function extractResponseMetadata(response) {
|
|
|
17793
17868
|
if (Array.isArray(responseDict.candidates)) {
|
|
17794
17869
|
for (const candidate of responseDict.candidates) {
|
|
17795
17870
|
const candidateDict = tryToDict(candidate);
|
|
17796
|
-
if (_optionalChain([candidateDict, 'optionalAccess',
|
|
17871
|
+
if (_optionalChain([candidateDict, 'optionalAccess', _409 => _409.groundingMetadata]) !== void 0) {
|
|
17797
17872
|
candidateGroundingMetadata.push(candidateDict.groundingMetadata);
|
|
17798
17873
|
}
|
|
17799
17874
|
}
|
|
@@ -17874,9 +17949,9 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
17874
17949
|
name: "huggingface.chat_completion",
|
|
17875
17950
|
type: "llm" /* LLM */,
|
|
17876
17951
|
extractInput: extractChatInputWithMetadata,
|
|
17877
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
17952
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _410 => _410.choices]),
|
|
17878
17953
|
extractMetadata: (result) => extractResponseMetadata2(result),
|
|
17879
|
-
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
17954
|
+
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _411 => _411.usage]))
|
|
17880
17955
|
}),
|
|
17881
17956
|
traceSyncStreamChannel(huggingFaceChannels.chatCompletionStream, {
|
|
17882
17957
|
name: "huggingface.chat_completion_stream",
|
|
@@ -17894,7 +17969,7 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
17894
17969
|
extractInput: extractTextGenerationInputWithMetadata,
|
|
17895
17970
|
extractOutput: (result) => isObject(result) ? { generated_text: result.generated_text } : result,
|
|
17896
17971
|
extractMetadata: extractTextGenerationMetadata,
|
|
17897
|
-
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
17972
|
+
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _412 => _412.details]), () => ( null)))
|
|
17898
17973
|
}),
|
|
17899
17974
|
traceSyncStreamChannel(huggingFaceChannels.textGenerationStream, {
|
|
17900
17975
|
name: "huggingface.text_generation_stream",
|
|
@@ -18013,7 +18088,7 @@ function extractTextGenerationMetrics(details) {
|
|
|
18013
18088
|
return metrics;
|
|
18014
18089
|
}
|
|
18015
18090
|
function extractTextGenerationMetadata(result) {
|
|
18016
|
-
if (!isObject(_optionalChain([result, 'optionalAccess',
|
|
18091
|
+
if (!isObject(_optionalChain([result, 'optionalAccess', _413 => _413.details]))) {
|
|
18017
18092
|
return void 0;
|
|
18018
18093
|
}
|
|
18019
18094
|
return typeof result.details.finish_reason === "string" ? {
|
|
@@ -18059,7 +18134,7 @@ function patchChatCompletionStream(args) {
|
|
|
18059
18134
|
const lastChunk = chunks.at(-1);
|
|
18060
18135
|
const responseMetadata = extractResponseMetadata2(lastChunk);
|
|
18061
18136
|
const metrics = {
|
|
18062
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
18137
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _414 => _414.usage])),
|
|
18063
18138
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
18064
18139
|
};
|
|
18065
18140
|
span.log({
|
|
@@ -18097,8 +18172,8 @@ function patchTextGenerationStream(args) {
|
|
|
18097
18172
|
output: aggregateTextGenerationStreamChunks(chunks),
|
|
18098
18173
|
...streamMetadata ? { metadata: streamMetadata } : {},
|
|
18099
18174
|
metrics: {
|
|
18100
|
-
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess',
|
|
18101
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
18175
|
+
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess', _415 => _415.details]), () => ( null))),
|
|
18176
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _416 => _416.usage])),
|
|
18102
18177
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
18103
18178
|
}
|
|
18104
18179
|
});
|
|
@@ -18127,14 +18202,14 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
18127
18202
|
}));
|
|
18128
18203
|
const delta = isObject(choice.delta) ? choice.delta : void 0;
|
|
18129
18204
|
const message = isObject(choice.message) ? choice.message : void 0;
|
|
18130
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
18205
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _417 => _417.content]) === "string") {
|
|
18131
18206
|
existing.content += delta.content;
|
|
18132
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
18207
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _418 => _418.content]) === "string") {
|
|
18133
18208
|
existing.content = message.content;
|
|
18134
18209
|
}
|
|
18135
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
18210
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _419 => _419.role]) === "string") {
|
|
18136
18211
|
existing.role = delta.role;
|
|
18137
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
18212
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _420 => _420.role]) === "string") {
|
|
18138
18213
|
existing.role = message.role;
|
|
18139
18214
|
}
|
|
18140
18215
|
if (choice.finish_reason !== void 0) {
|
|
@@ -18162,7 +18237,7 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
18162
18237
|
};
|
|
18163
18238
|
}
|
|
18164
18239
|
function getChatToolCallDeltas(value) {
|
|
18165
|
-
if (!Array.isArray(_optionalChain([value, 'optionalAccess',
|
|
18240
|
+
if (!Array.isArray(_optionalChain([value, 'optionalAccess', _421 => _421.tool_calls]))) {
|
|
18166
18241
|
return void 0;
|
|
18167
18242
|
}
|
|
18168
18243
|
const toolCalls = value.tool_calls.filter((toolCall) => isObject(toolCall));
|
|
@@ -18227,7 +18302,7 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
18227
18302
|
for (const chunk of chunks) {
|
|
18228
18303
|
if (typeof chunk.generated_text === "string") {
|
|
18229
18304
|
generatedText = chunk.generated_text;
|
|
18230
|
-
} else if (typeof _optionalChain([chunk, 'access',
|
|
18305
|
+
} else if (typeof _optionalChain([chunk, 'access', _422 => _422.token, 'optionalAccess', _423 => _423.text]) === "string" && !chunk.token.special) {
|
|
18231
18306
|
generatedText += chunk.token.text;
|
|
18232
18307
|
} else if (Array.isArray(chunk.choices)) {
|
|
18233
18308
|
for (const choice of chunk.choices) {
|
|
@@ -18251,17 +18326,17 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
18251
18326
|
function extractTextGenerationStreamMetadata(chunks) {
|
|
18252
18327
|
for (let index = chunks.length - 1; index >= 0; index--) {
|
|
18253
18328
|
const chunk = chunks[index];
|
|
18254
|
-
if (isObject(_optionalChain([chunk, 'optionalAccess',
|
|
18329
|
+
if (isObject(_optionalChain([chunk, 'optionalAccess', _424 => _424.details])) && typeof chunk.details.finish_reason === "string") {
|
|
18255
18330
|
return {
|
|
18256
18331
|
finish_reason: chunk.details.finish_reason
|
|
18257
18332
|
};
|
|
18258
18333
|
}
|
|
18259
|
-
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess',
|
|
18334
|
+
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess', _425 => _425.choices]))) {
|
|
18260
18335
|
continue;
|
|
18261
18336
|
}
|
|
18262
18337
|
for (let choiceIndex = chunk.choices.length - 1; choiceIndex >= 0; choiceIndex--) {
|
|
18263
18338
|
const choice = chunk.choices[choiceIndex];
|
|
18264
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
18339
|
+
if (_optionalChain([choice, 'optionalAccess', _426 => _426.finish_reason]) !== void 0) {
|
|
18265
18340
|
return { finish_reason: choice.finish_reason };
|
|
18266
18341
|
}
|
|
18267
18342
|
}
|
|
@@ -18337,14 +18412,14 @@ var OpenRouterAgentPlugin = class extends BasePlugin {
|
|
|
18337
18412
|
extractMetadata: (result, event) => {
|
|
18338
18413
|
if (!isObject(result)) {
|
|
18339
18414
|
return {
|
|
18340
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
18341
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
18415
|
+
step: _optionalChain([event, 'optionalAccess', _427 => _427.step]),
|
|
18416
|
+
step_type: _optionalChain([event, 'optionalAccess', _428 => _428.stepType])
|
|
18342
18417
|
};
|
|
18343
18418
|
}
|
|
18344
18419
|
return {
|
|
18345
18420
|
...extractOpenRouterResponseMetadata(result) || {},
|
|
18346
|
-
..._optionalChain([event, 'optionalAccess',
|
|
18347
|
-
..._optionalChain([event, 'optionalAccess',
|
|
18421
|
+
..._optionalChain([event, 'optionalAccess', _429 => _429.step]) !== void 0 ? { step: event.step } : {},
|
|
18422
|
+
..._optionalChain([event, 'optionalAccess', _430 => _430.stepType]) ? { step_type: event.stepType } : {}
|
|
18348
18423
|
};
|
|
18349
18424
|
},
|
|
18350
18425
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage(result.usage) : {}
|
|
@@ -18705,7 +18780,7 @@ function publishToolResult(tracingChannel2, event, result) {
|
|
|
18705
18780
|
}
|
|
18706
18781
|
function getToolCallId(context) {
|
|
18707
18782
|
const toolContext = context;
|
|
18708
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
18783
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _431 => _431.toolCall, 'optionalAccess', _432 => _432.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
18709
18784
|
}
|
|
18710
18785
|
var OPENROUTER_WRAPPED_CALL_MODEL_RESULT = /* @__PURE__ */ Symbol(
|
|
18711
18786
|
"braintrust.openrouter.wrappedCallModelResult"
|
|
@@ -19103,9 +19178,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19103
19178
|
type: "llm" /* LLM */,
|
|
19104
19179
|
extractInput: (args) => {
|
|
19105
19180
|
const request = getOpenRouterRequestArg(args);
|
|
19106
|
-
const chatGenerationParams = isObject(_optionalChain([request, 'optionalAccess',
|
|
19107
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
19108
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
19181
|
+
const chatGenerationParams = isObject(_optionalChain([request, 'optionalAccess', _433 => _433.chatGenerationParams])) ? request.chatGenerationParams : {};
|
|
19182
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _434 => _434.httpReferer]);
|
|
19183
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _435 => _435.xTitle]);
|
|
19109
19184
|
const { messages, ...metadata } = chatGenerationParams;
|
|
19110
19185
|
return {
|
|
19111
19186
|
input: messages,
|
|
@@ -19116,7 +19191,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19116
19191
|
return isObject(result) ? result.choices : void 0;
|
|
19117
19192
|
},
|
|
19118
19193
|
extractMetrics: (result, startTime) => {
|
|
19119
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
19194
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _436 => _436.usage]));
|
|
19120
19195
|
if (startTime) {
|
|
19121
19196
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
19122
19197
|
}
|
|
@@ -19131,9 +19206,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19131
19206
|
type: "llm" /* LLM */,
|
|
19132
19207
|
extractInput: (args) => {
|
|
19133
19208
|
const request = getOpenRouterRequestArg(args);
|
|
19134
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
19135
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
19136
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
19209
|
+
const requestBody = isObject(_optionalChain([request, 'optionalAccess', _437 => _437.requestBody])) ? request.requestBody : {};
|
|
19210
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _438 => _438.httpReferer]);
|
|
19211
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _439 => _439.xTitle]);
|
|
19137
19212
|
const { input, ...metadata } = requestBody;
|
|
19138
19213
|
return {
|
|
19139
19214
|
input,
|
|
@@ -19148,7 +19223,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19148
19223
|
if (!isObject(result)) {
|
|
19149
19224
|
return void 0;
|
|
19150
19225
|
}
|
|
19151
|
-
const embedding = _optionalChain([result, 'access',
|
|
19226
|
+
const embedding = _optionalChain([result, 'access', _440 => _440.data, 'optionalAccess', _441 => _441[0], 'optionalAccess', _442 => _442.embedding]);
|
|
19152
19227
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
19153
19228
|
},
|
|
19154
19229
|
extractMetadata: (result) => {
|
|
@@ -19168,9 +19243,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19168
19243
|
type: "llm" /* LLM */,
|
|
19169
19244
|
extractInput: (args) => {
|
|
19170
19245
|
const request = getOpenRouterRequestArg(args);
|
|
19171
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
19172
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
19173
|
-
const xTitle = _nullishCoalesce(_optionalChain([request, 'optionalAccess',
|
|
19246
|
+
const requestBody = isObject(_optionalChain([request, 'optionalAccess', _443 => _443.requestBody])) ? request.requestBody : {};
|
|
19247
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _444 => _444.httpReferer]);
|
|
19248
|
+
const xTitle = _nullishCoalesce(_optionalChain([request, 'optionalAccess', _445 => _445.xTitle]), () => ( _optionalChain([request, 'optionalAccess', _446 => _446.appTitle])));
|
|
19174
19249
|
const { documents, query, ...metadata } = requestBody;
|
|
19175
19250
|
return {
|
|
19176
19251
|
input: {
|
|
@@ -19196,9 +19271,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19196
19271
|
type: "llm" /* LLM */,
|
|
19197
19272
|
extractInput: (args) => {
|
|
19198
19273
|
const request = getOpenRouterRequestArg(args);
|
|
19199
|
-
const openResponsesRequest = isObject(_optionalChain([request, 'optionalAccess',
|
|
19200
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
19201
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
19274
|
+
const openResponsesRequest = isObject(_optionalChain([request, 'optionalAccess', _447 => _447.openResponsesRequest])) ? request.openResponsesRequest : {};
|
|
19275
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _448 => _448.httpReferer]);
|
|
19276
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _449 => _449.xTitle]);
|
|
19202
19277
|
const { input, ...metadata } = openResponsesRequest;
|
|
19203
19278
|
return {
|
|
19204
19279
|
input,
|
|
@@ -19208,7 +19283,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19208
19283
|
extractOutput: (result) => extractOpenRouterResponseOutput2(result),
|
|
19209
19284
|
extractMetadata: (result) => extractOpenRouterResponseMetadata2(result),
|
|
19210
19285
|
extractMetrics: (result, startTime) => {
|
|
19211
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
19286
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _450 => _450.usage]));
|
|
19212
19287
|
if (startTime) {
|
|
19213
19288
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
19214
19289
|
}
|
|
@@ -19260,14 +19335,14 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
19260
19335
|
extractMetadata: (result, event) => {
|
|
19261
19336
|
if (!isObject(result)) {
|
|
19262
19337
|
return {
|
|
19263
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
19264
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
19338
|
+
step: _optionalChain([event, 'optionalAccess', _451 => _451.step]),
|
|
19339
|
+
step_type: _optionalChain([event, 'optionalAccess', _452 => _452.stepType])
|
|
19265
19340
|
};
|
|
19266
19341
|
}
|
|
19267
19342
|
return {
|
|
19268
19343
|
...extractOpenRouterResponseMetadata2(result) || {},
|
|
19269
|
-
..._optionalChain([event, 'optionalAccess',
|
|
19270
|
-
..._optionalChain([event, 'optionalAccess',
|
|
19344
|
+
..._optionalChain([event, 'optionalAccess', _453 => _453.step]) !== void 0 ? { step: event.step } : {},
|
|
19345
|
+
..._optionalChain([event, 'optionalAccess', _454 => _454.stepType]) ? { step_type: event.stepType } : {}
|
|
19271
19346
|
};
|
|
19272
19347
|
},
|
|
19273
19348
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage2(result.usage) : {}
|
|
@@ -19647,7 +19722,7 @@ function publishToolResult2(tracingChannel2, event, result) {
|
|
|
19647
19722
|
}
|
|
19648
19723
|
function getToolCallId2(context) {
|
|
19649
19724
|
const toolContext = context;
|
|
19650
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
19725
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _455 => _455.toolCall, 'optionalAccess', _456 => _456.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
19651
19726
|
}
|
|
19652
19727
|
function aggregateOpenRouterChatChunks(chunks) {
|
|
19653
19728
|
let role;
|
|
@@ -19663,12 +19738,12 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
19663
19738
|
for (const chunk of chunks) {
|
|
19664
19739
|
metrics = {
|
|
19665
19740
|
...metrics,
|
|
19666
|
-
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess',
|
|
19741
|
+
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess', _457 => _457.usage]))
|
|
19667
19742
|
};
|
|
19668
|
-
const choice = _optionalChain([chunk, 'optionalAccess',
|
|
19669
|
-
const delta = _optionalChain([choice, 'optionalAccess',
|
|
19743
|
+
const choice = _optionalChain([chunk, 'optionalAccess', _458 => _458.choices, 'optionalAccess', _459 => _459[0]]);
|
|
19744
|
+
const delta = _optionalChain([choice, 'optionalAccess', _460 => _460.delta]);
|
|
19670
19745
|
if (!delta) {
|
|
19671
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
19746
|
+
if (_optionalChain([choice, 'optionalAccess', _461 => _461.finish_reason]) !== void 0) {
|
|
19672
19747
|
finishReason = choice.finish_reason;
|
|
19673
19748
|
}
|
|
19674
19749
|
continue;
|
|
@@ -19694,7 +19769,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
19694
19769
|
...delta.reasoning_details
|
|
19695
19770
|
];
|
|
19696
19771
|
}
|
|
19697
|
-
const choiceFinishReason = _nullishCoalesce(_nullishCoalesce(_optionalChain([choice, 'optionalAccess',
|
|
19772
|
+
const choiceFinishReason = _nullishCoalesce(_nullishCoalesce(_optionalChain([choice, 'optionalAccess', _462 => _462.finishReason]), () => ( _optionalChain([choice, 'optionalAccess', _463 => _463.finish_reason]))), () => ( void 0));
|
|
19698
19773
|
const deltaFinishReason = _nullishCoalesce(_nullishCoalesce(delta.finishReason, () => ( delta.finish_reason)), () => ( void 0));
|
|
19699
19774
|
if (choiceFinishReason !== void 0) {
|
|
19700
19775
|
finishReason = choiceFinishReason;
|
|
@@ -19706,11 +19781,11 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
19706
19781
|
continue;
|
|
19707
19782
|
}
|
|
19708
19783
|
for (const toolDelta of toolCallDeltas) {
|
|
19709
|
-
if (!_optionalChain([toolDelta, 'optionalAccess',
|
|
19784
|
+
if (!_optionalChain([toolDelta, 'optionalAccess', _464 => _464.function])) {
|
|
19710
19785
|
continue;
|
|
19711
19786
|
}
|
|
19712
19787
|
const toolIndex = _nullishCoalesce(toolDelta.index, () => ( 0));
|
|
19713
|
-
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess',
|
|
19788
|
+
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess', _465 => _465[toolIndex]]);
|
|
19714
19789
|
if (!existingToolCall || toolDelta.id && existingToolCall.id !== void 0 && existingToolCall.id !== toolDelta.id) {
|
|
19715
19790
|
const nextToolCalls = [...toolCalls || []];
|
|
19716
19791
|
nextToolCalls[toolIndex] = {
|
|
@@ -19760,7 +19835,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
19760
19835
|
function aggregateOpenRouterResponseStreamEvents(chunks) {
|
|
19761
19836
|
let finalResponse;
|
|
19762
19837
|
for (const chunk of chunks) {
|
|
19763
|
-
const response = _optionalChain([chunk, 'optionalAccess',
|
|
19838
|
+
const response = _optionalChain([chunk, 'optionalAccess', _466 => _466.response]);
|
|
19764
19839
|
if (!response) {
|
|
19765
19840
|
continue;
|
|
19766
19841
|
}
|
|
@@ -20190,10 +20265,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20190
20265
|
type: "llm" /* LLM */,
|
|
20191
20266
|
extractInput: extractMessagesInputWithMetadata,
|
|
20192
20267
|
extractOutput: (result) => {
|
|
20193
|
-
return _optionalChain([result, 'optionalAccess',
|
|
20268
|
+
return _optionalChain([result, 'optionalAccess', _467 => _467.choices]);
|
|
20194
20269
|
},
|
|
20195
20270
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20196
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
20271
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _468 => _468.usage]), startTime)
|
|
20197
20272
|
})
|
|
20198
20273
|
);
|
|
20199
20274
|
this.unsubscribers.push(
|
|
@@ -20213,11 +20288,11 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20213
20288
|
type: "llm" /* LLM */,
|
|
20214
20289
|
extractInput: extractEmbeddingInputWithMetadata,
|
|
20215
20290
|
extractOutput: (result) => {
|
|
20216
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
20291
|
+
const embedding = _optionalChain([result, 'optionalAccess', _469 => _469.data, 'optionalAccess', _470 => _470[0], 'optionalAccess', _471 => _471.embedding]);
|
|
20217
20292
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
20218
20293
|
},
|
|
20219
20294
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20220
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
20295
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _472 => _472.usage]))
|
|
20221
20296
|
})
|
|
20222
20297
|
);
|
|
20223
20298
|
this.unsubscribers.push(
|
|
@@ -20227,7 +20302,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20227
20302
|
extractInput: extractClassifierInputWithMetadata,
|
|
20228
20303
|
extractOutput: extractClassifierOutput,
|
|
20229
20304
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20230
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
20305
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _473 => _473.usage]))
|
|
20231
20306
|
})
|
|
20232
20307
|
);
|
|
20233
20308
|
this.unsubscribers.push(
|
|
@@ -20237,7 +20312,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20237
20312
|
extractInput: extractClassifierInputWithMetadata,
|
|
20238
20313
|
extractOutput: extractClassifierOutput,
|
|
20239
20314
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20240
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
20315
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _474 => _474.usage]))
|
|
20241
20316
|
})
|
|
20242
20317
|
);
|
|
20243
20318
|
this.unsubscribers.push(
|
|
@@ -20247,7 +20322,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20247
20322
|
extractInput: extractClassifierInputWithMetadata,
|
|
20248
20323
|
extractOutput: extractClassifierOutput,
|
|
20249
20324
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20250
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
20325
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _475 => _475.usage]))
|
|
20251
20326
|
})
|
|
20252
20327
|
);
|
|
20253
20328
|
this.unsubscribers.push(
|
|
@@ -20257,7 +20332,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20257
20332
|
extractInput: extractClassifierInputWithMetadata,
|
|
20258
20333
|
extractOutput: extractClassifierOutput,
|
|
20259
20334
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20260
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
20335
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _476 => _476.usage]))
|
|
20261
20336
|
})
|
|
20262
20337
|
);
|
|
20263
20338
|
this.unsubscribers.push(
|
|
@@ -20266,10 +20341,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20266
20341
|
type: "llm" /* LLM */,
|
|
20267
20342
|
extractInput: extractPromptInputWithMetadata,
|
|
20268
20343
|
extractOutput: (result) => {
|
|
20269
|
-
return _optionalChain([result, 'optionalAccess',
|
|
20344
|
+
return _optionalChain([result, 'optionalAccess', _477 => _477.choices]);
|
|
20270
20345
|
},
|
|
20271
20346
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20272
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
20347
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _478 => _478.usage]), startTime)
|
|
20273
20348
|
})
|
|
20274
20349
|
);
|
|
20275
20350
|
this.unsubscribers.push(
|
|
@@ -20289,10 +20364,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
20289
20364
|
type: "llm" /* LLM */,
|
|
20290
20365
|
extractInput: extractMessagesInputWithMetadata,
|
|
20291
20366
|
extractOutput: (result) => {
|
|
20292
|
-
return _optionalChain([result, 'optionalAccess',
|
|
20367
|
+
return _optionalChain([result, 'optionalAccess', _479 => _479.choices]);
|
|
20293
20368
|
},
|
|
20294
20369
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
20295
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
20370
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _480 => _480.usage]), startTime)
|
|
20296
20371
|
})
|
|
20297
20372
|
);
|
|
20298
20373
|
this.unsubscribers.push(
|
|
@@ -20547,11 +20622,11 @@ function mergeMistralContentParts(left, right) {
|
|
|
20547
20622
|
const merged = [...(left || []).map((part) => structuredClone(part))];
|
|
20548
20623
|
for (const part of right) {
|
|
20549
20624
|
const lastPart = merged[merged.length - 1];
|
|
20550
|
-
if (part.type === "text" && _optionalChain([lastPart, 'optionalAccess',
|
|
20625
|
+
if (part.type === "text" && _optionalChain([lastPart, 'optionalAccess', _481 => _481.type]) === "text" && typeof lastPart.text === "string" && typeof part.text === "string") {
|
|
20551
20626
|
lastPart.text += part.text;
|
|
20552
20627
|
continue;
|
|
20553
20628
|
}
|
|
20554
|
-
if (part.type === "thinking" && _optionalChain([lastPart, 'optionalAccess',
|
|
20629
|
+
if (part.type === "thinking" && _optionalChain([lastPart, 'optionalAccess', _482 => _482.type]) === "thinking" && Array.isArray(lastPart.thinking) && Array.isArray(part.thinking)) {
|
|
20555
20630
|
lastPart.thinking = mergeMistralTextSegments(
|
|
20556
20631
|
lastPart.thinking,
|
|
20557
20632
|
part.thinking
|
|
@@ -20606,13 +20681,13 @@ function createMergedToolCallDelta(delta) {
|
|
|
20606
20681
|
...delta,
|
|
20607
20682
|
function: {
|
|
20608
20683
|
...delta.function,
|
|
20609
|
-
arguments: typeof _optionalChain([delta, 'access',
|
|
20684
|
+
arguments: typeof _optionalChain([delta, 'access', _483 => _483.function, 'optionalAccess', _484 => _484.arguments]) === "string" ? delta.function.arguments : ""
|
|
20610
20685
|
}
|
|
20611
20686
|
};
|
|
20612
20687
|
}
|
|
20613
20688
|
function mergeToolCallDeltaPair(current, delta) {
|
|
20614
|
-
const currentArguments = typeof _optionalChain([current, 'access',
|
|
20615
|
-
const deltaArguments = typeof _optionalChain([delta, 'access',
|
|
20689
|
+
const currentArguments = typeof _optionalChain([current, 'access', _485 => _485.function, 'optionalAccess', _486 => _486.arguments]) === "string" ? current.function.arguments : "";
|
|
20690
|
+
const deltaArguments = typeof _optionalChain([delta, 'access', _487 => _487.function, 'optionalAccess', _488 => _488.arguments]) === "string" ? delta.function.arguments : "";
|
|
20616
20691
|
return {
|
|
20617
20692
|
...current,
|
|
20618
20693
|
...delta,
|
|
@@ -20715,7 +20790,7 @@ function aggregateMistralStreamChunks(chunks) {
|
|
|
20715
20790
|
let metrics = {};
|
|
20716
20791
|
let metadata;
|
|
20717
20792
|
for (const event of chunks) {
|
|
20718
|
-
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess',
|
|
20793
|
+
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess', _489 => _489.data])) ? event.data : void 0;
|
|
20719
20794
|
if (!chunk) {
|
|
20720
20795
|
continue;
|
|
20721
20796
|
}
|
|
@@ -20906,7 +20981,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
20906
20981
|
};
|
|
20907
20982
|
tracingChannel2.subscribe(handlers);
|
|
20908
20983
|
this.unsubscribers.push(() => {
|
|
20909
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
20984
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _490 => _490()]);
|
|
20910
20985
|
tracingChannel2.unsubscribe(handlers);
|
|
20911
20986
|
});
|
|
20912
20987
|
}
|
|
@@ -21009,7 +21084,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
21009
21084
|
};
|
|
21010
21085
|
tracingChannel2.subscribe(handlers);
|
|
21011
21086
|
this.unsubscribers.push(() => {
|
|
21012
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
21087
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _491 => _491()]);
|
|
21013
21088
|
tracingChannel2.unsubscribe(handlers);
|
|
21014
21089
|
});
|
|
21015
21090
|
}
|
|
@@ -21156,10 +21231,10 @@ function bindAsyncIterableToCurrentSpan(stream, span) {
|
|
|
21156
21231
|
}
|
|
21157
21232
|
function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
21158
21233
|
const state = _internalGetGlobalState();
|
|
21159
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
21234
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _492 => _492.contextManager]);
|
|
21160
21235
|
const startChannel = tracingChannel2.start;
|
|
21161
21236
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
21162
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
21237
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _493 => _493.bindStore]) || !currentSpanStore) {
|
|
21163
21238
|
return void 0;
|
|
21164
21239
|
}
|
|
21165
21240
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -21171,7 +21246,7 @@ function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
|
21171
21246
|
return contextManager.wrapSpanForStore(span);
|
|
21172
21247
|
});
|
|
21173
21248
|
return () => {
|
|
21174
|
-
_optionalChain([startChannel, 'access',
|
|
21249
|
+
_optionalChain([startChannel, 'access', _494 => _494.unbindStore, 'optionalCall', _495 => _495(currentSpanStore)]);
|
|
21175
21250
|
};
|
|
21176
21251
|
}
|
|
21177
21252
|
function extractRunnerContextKey(paramsOrContext) {
|
|
@@ -21184,9 +21259,9 @@ function extractRunnerContextKey(paramsOrContext) {
|
|
|
21184
21259
|
return extractInvocationContextKey(invocationContext);
|
|
21185
21260
|
}
|
|
21186
21261
|
function extractInvocationContextKey(parentContext) {
|
|
21187
|
-
const session = _optionalChain([parentContext, 'optionalAccess',
|
|
21188
|
-
const userId = _optionalChain([session, 'optionalAccess',
|
|
21189
|
-
const sessionId = _optionalChain([session, 'optionalAccess',
|
|
21262
|
+
const session = _optionalChain([parentContext, 'optionalAccess', _496 => _496.session]);
|
|
21263
|
+
const userId = _optionalChain([session, 'optionalAccess', _497 => _497.userId]);
|
|
21264
|
+
const sessionId = _optionalChain([session, 'optionalAccess', _498 => _498.id]);
|
|
21190
21265
|
if (typeof userId !== "string" || typeof sessionId !== "string") {
|
|
21191
21266
|
return void 0;
|
|
21192
21267
|
}
|
|
@@ -21243,27 +21318,27 @@ function extractRunnerMetadata(paramsOrContext) {
|
|
|
21243
21318
|
metadata["google_adk.session_id"] = directSessionId;
|
|
21244
21319
|
}
|
|
21245
21320
|
const session = "session" in paramsOrContext ? paramsOrContext.session : void 0;
|
|
21246
|
-
if (metadata["google_adk.user_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess',
|
|
21321
|
+
if (metadata["google_adk.user_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess', _499 => _499.userId]) === "string") {
|
|
21247
21322
|
metadata["google_adk.user_id"] = session.userId;
|
|
21248
21323
|
}
|
|
21249
|
-
if (metadata["google_adk.session_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess',
|
|
21324
|
+
if (metadata["google_adk.session_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess', _500 => _500.id]) === "string") {
|
|
21250
21325
|
metadata["google_adk.session_id"] = session.id;
|
|
21251
21326
|
}
|
|
21252
21327
|
return metadata;
|
|
21253
21328
|
}
|
|
21254
21329
|
function extractAgentName(agent, parentContext) {
|
|
21255
|
-
if (typeof _optionalChain([agent, 'optionalAccess',
|
|
21330
|
+
if (typeof _optionalChain([agent, 'optionalAccess', _501 => _501.name]) === "string" && agent.name.length > 0) {
|
|
21256
21331
|
return agent.name;
|
|
21257
21332
|
}
|
|
21258
21333
|
if (!parentContext) {
|
|
21259
21334
|
return void 0;
|
|
21260
21335
|
}
|
|
21261
21336
|
const contextAgent = parentContext.agent;
|
|
21262
|
-
return typeof _optionalChain([contextAgent, 'optionalAccess',
|
|
21337
|
+
return typeof _optionalChain([contextAgent, 'optionalAccess', _502 => _502.name]) === "string" && contextAgent.name.length > 0 ? contextAgent.name : void 0;
|
|
21263
21338
|
}
|
|
21264
21339
|
function extractModelName(agent, parentContext) {
|
|
21265
|
-
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess',
|
|
21266
|
-
if (!_optionalChain([modelAgent, 'optionalAccess',
|
|
21340
|
+
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess', _503 => _503.agent])));
|
|
21341
|
+
if (!_optionalChain([modelAgent, 'optionalAccess', _504 => _504.model])) {
|
|
21267
21342
|
return;
|
|
21268
21343
|
}
|
|
21269
21344
|
if (typeof modelAgent.model === "string") {
|
|
@@ -21276,30 +21351,30 @@ function extractModelName(agent, parentContext) {
|
|
|
21276
21351
|
}
|
|
21277
21352
|
function extractToolCallId(req) {
|
|
21278
21353
|
const toolContext = req.toolContext;
|
|
21279
|
-
return _optionalChain([toolContext, 'optionalAccess',
|
|
21354
|
+
return _optionalChain([toolContext, 'optionalAccess', _505 => _505.functionCallId]);
|
|
21280
21355
|
}
|
|
21281
21356
|
function extractToolName2(req, tool) {
|
|
21282
|
-
if (typeof _optionalChain([tool, 'optionalAccess',
|
|
21357
|
+
if (typeof _optionalChain([tool, 'optionalAccess', _506 => _506.name]) === "string" && tool.name.length > 0) {
|
|
21283
21358
|
return tool.name;
|
|
21284
21359
|
}
|
|
21285
21360
|
const toolContext = req.toolContext;
|
|
21286
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
21287
|
-
const invocationTool = _optionalChain([invocationContext, 'optionalAccess',
|
|
21288
|
-
const toolName = _optionalChain([invocationTool, 'optionalAccess',
|
|
21361
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _507 => _507.invocationContext]);
|
|
21362
|
+
const invocationTool = _optionalChain([invocationContext, 'optionalAccess', _508 => _508.tool]);
|
|
21363
|
+
const toolName = _optionalChain([invocationTool, 'optionalAccess', _509 => _509.name]);
|
|
21289
21364
|
return typeof toolName === "string" && toolName.length > 0 ? toolName : void 0;
|
|
21290
21365
|
}
|
|
21291
21366
|
function extractToolAgentName(req) {
|
|
21292
21367
|
const toolContext = req.toolContext;
|
|
21293
|
-
const directName = _optionalChain([toolContext, 'optionalAccess',
|
|
21368
|
+
const directName = _optionalChain([toolContext, 'optionalAccess', _510 => _510.agentName]);
|
|
21294
21369
|
if (typeof directName === "string" && directName.length > 0) {
|
|
21295
21370
|
return directName;
|
|
21296
21371
|
}
|
|
21297
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
21372
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _511 => _511.invocationContext]);
|
|
21298
21373
|
return extractAgentName(void 0, invocationContext);
|
|
21299
21374
|
}
|
|
21300
21375
|
function findToolParentSpan(req, activeAgentSpans, activeRunnerSpans) {
|
|
21301
21376
|
const toolContext = req.toolContext;
|
|
21302
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
21377
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _512 => _512.invocationContext]);
|
|
21303
21378
|
const contextKey = extractInvocationContextKey(invocationContext);
|
|
21304
21379
|
const agentName = extractToolAgentName(req);
|
|
21305
21380
|
if (contextKey && agentName) {
|
|
@@ -21681,7 +21756,7 @@ function extractCohereResponseMetadata(result) {
|
|
|
21681
21756
|
RESPONSE_METADATA_ALLOWLIST2
|
|
21682
21757
|
);
|
|
21683
21758
|
const meta = isObject(result.meta) ? result.meta : void 0;
|
|
21684
|
-
const apiVersion = isObject(_optionalChain([meta, 'optionalAccess',
|
|
21759
|
+
const apiVersion = isObject(_optionalChain([meta, 'optionalAccess', _513 => _513.apiVersion])) && typeof meta.apiVersion.version === "string" && meta.apiVersion.version || isObject(_optionalChain([meta, 'optionalAccess', _514 => _514.api_version])) && typeof meta.api_version.version === "string" && meta.api_version.version;
|
|
21685
21760
|
const metadata = {
|
|
21686
21761
|
...responseMetadata,
|
|
21687
21762
|
...apiVersion ? { api_version: apiVersion } : {}
|
|
@@ -21842,13 +21917,13 @@ function getToolCallIndex2(toolCall, fallbackIndex) {
|
|
|
21842
21917
|
return typeof toolCall.index === "number" && Number.isInteger(toolCall.index) ? toolCall.index : fallbackIndex;
|
|
21843
21918
|
}
|
|
21844
21919
|
function appendToolCallDelta(existing, incoming) {
|
|
21845
|
-
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess',
|
|
21920
|
+
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess', _515 => _515.function])) && typeof existing.function.arguments === "string" ? existing.function.arguments : "";
|
|
21846
21921
|
const incomingArguments = isObject(incoming.function) && typeof incoming.function.arguments === "string" ? incoming.function.arguments : "";
|
|
21847
21922
|
return {
|
|
21848
21923
|
...existing,
|
|
21849
21924
|
...incoming,
|
|
21850
21925
|
function: {
|
|
21851
|
-
...isObject(_optionalChain([existing, 'optionalAccess',
|
|
21926
|
+
...isObject(_optionalChain([existing, 'optionalAccess', _516 => _516.function])) ? existing.function : {},
|
|
21852
21927
|
...isObject(incoming.function) ? incoming.function : {},
|
|
21853
21928
|
...incomingArguments ? { arguments: `${currentArguments}${incomingArguments}` } : {}
|
|
21854
21929
|
}
|
|
@@ -22104,7 +22179,7 @@ function aggregateCohereChatStreamChunks(chunks) {
|
|
|
22104
22179
|
...mergedToolCalls.length > 0 ? { toolCalls: mergedToolCalls } : {}
|
|
22105
22180
|
};
|
|
22106
22181
|
} else if (mergedToolCalls.length > 0 || role || mergedText.length > 0 || aggregatedContentBlocks.length > 0) {
|
|
22107
|
-
const textContent = mergedText.length > 0 ? mergedText : _optionalChain([aggregatedContentBlocks, 'access',
|
|
22182
|
+
const textContent = mergedText.length > 0 ? mergedText : _optionalChain([aggregatedContentBlocks, 'access', _517 => _517[0], 'optionalAccess', _518 => _518.type]) === "text" ? aggregatedContentBlocks[0].text : void 0;
|
|
22108
22183
|
output = {
|
|
22109
22184
|
...role ? { role } : {},
|
|
22110
22185
|
...textContent ? { content: textContent } : {},
|
|
@@ -22153,7 +22228,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
22153
22228
|
metadata: { ...metadata, provider: "groq" }
|
|
22154
22229
|
};
|
|
22155
22230
|
},
|
|
22156
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
22231
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _519 => _519.choices]),
|
|
22157
22232
|
extractMetrics: (result, startTime) => {
|
|
22158
22233
|
const metrics = parseGroqMetrics(result);
|
|
22159
22234
|
if (startTime) {
|
|
@@ -22176,7 +22251,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
22176
22251
|
};
|
|
22177
22252
|
},
|
|
22178
22253
|
extractOutput: (result) => {
|
|
22179
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
22254
|
+
const embedding = _optionalChain([result, 'optionalAccess', _520 => _520.data, 'optionalAccess', _521 => _521[0], 'optionalAccess', _522 => _522.embedding]);
|
|
22180
22255
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
22181
22256
|
},
|
|
22182
22257
|
extractMetrics: (result) => parseGroqMetrics(result)
|
|
@@ -22188,8 +22263,8 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
22188
22263
|
}
|
|
22189
22264
|
};
|
|
22190
22265
|
function parseGroqMetrics(result) {
|
|
22191
|
-
const metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
22192
|
-
const xGroq = _optionalChain([result, 'optionalAccess',
|
|
22266
|
+
const metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _523 => _523.usage]));
|
|
22267
|
+
const xGroq = _optionalChain([result, 'optionalAccess', _524 => _524.x_groq]);
|
|
22193
22268
|
if (!xGroq || typeof xGroq !== "object") {
|
|
22194
22269
|
return metrics;
|
|
22195
22270
|
}
|
|
@@ -22213,7 +22288,7 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
22213
22288
|
);
|
|
22214
22289
|
const reasoning = aggregateGroqReasoning(chunks);
|
|
22215
22290
|
if (reasoning !== void 0) {
|
|
22216
|
-
const message = _optionalChain([aggregated, 'access',
|
|
22291
|
+
const message = _optionalChain([aggregated, 'access', _525 => _525.output, 'access', _526 => _526[0], 'optionalAccess', _527 => _527.message]);
|
|
22217
22292
|
if (message) {
|
|
22218
22293
|
message.reasoning = reasoning;
|
|
22219
22294
|
}
|
|
@@ -22226,8 +22301,8 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
22226
22301
|
function aggregateGroqReasoning(chunks) {
|
|
22227
22302
|
let reasoning = "";
|
|
22228
22303
|
for (const chunk of chunks) {
|
|
22229
|
-
const delta = _optionalChain([chunk, 'access',
|
|
22230
|
-
const deltaReasoning = _optionalChain([delta, 'optionalAccess',
|
|
22304
|
+
const delta = _optionalChain([chunk, 'access', _528 => _528.choices, 'optionalAccess', _529 => _529[0], 'optionalAccess', _530 => _530.delta]);
|
|
22305
|
+
const deltaReasoning = _optionalChain([delta, 'optionalAccess', _531 => _531.reasoning]);
|
|
22231
22306
|
if (typeof deltaReasoning === "string") {
|
|
22232
22307
|
reasoning += deltaReasoning;
|
|
22233
22308
|
}
|
|
@@ -22284,8 +22359,8 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
22284
22359
|
type: "llm" /* LLM */,
|
|
22285
22360
|
extractInput: ([input]) => extractGenerateInput(input),
|
|
22286
22361
|
extractOutput: extractGenerateOutput,
|
|
22287
|
-
extractMetadata: (result, event) => extractGenerateResponseMetadata(result, _optionalChain([event, 'optionalAccess',
|
|
22288
|
-
extractMetrics: (result) => parseGenkitUsageMetrics(_optionalChain([result, 'optionalAccess',
|
|
22362
|
+
extractMetadata: (result, event) => extractGenerateResponseMetadata(result, _optionalChain([event, 'optionalAccess', _532 => _532.arguments, 'optionalAccess', _533 => _533[0]])),
|
|
22363
|
+
extractMetrics: (result) => parseGenkitUsageMetrics(_optionalChain([result, 'optionalAccess', _534 => _534.usage]))
|
|
22289
22364
|
})
|
|
22290
22365
|
);
|
|
22291
22366
|
this.unsubscribers.push(
|
|
@@ -22302,7 +22377,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
22302
22377
|
type: "function" /* FUNCTION */,
|
|
22303
22378
|
extractInput: ([params]) => extractEmbedInput(params),
|
|
22304
22379
|
extractOutput: (result) => summarizeEmbeddingResult(result),
|
|
22305
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
22380
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _535 => _535.arguments, 'optionalAccess', _536 => _536[0]])),
|
|
22306
22381
|
extractMetrics: () => ({})
|
|
22307
22382
|
})
|
|
22308
22383
|
);
|
|
@@ -22312,7 +22387,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
22312
22387
|
type: "function" /* FUNCTION */,
|
|
22313
22388
|
extractInput: ([params]) => extractEmbedManyInput(params),
|
|
22314
22389
|
extractOutput: summarizeEmbeddingResult,
|
|
22315
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
22390
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _537 => _537.arguments, 'optionalAccess', _538 => _538[0]])),
|
|
22316
22391
|
extractMetrics: () => ({})
|
|
22317
22392
|
})
|
|
22318
22393
|
);
|
|
@@ -22363,7 +22438,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
22363
22438
|
};
|
|
22364
22439
|
tracingChannel2.subscribe(handlers);
|
|
22365
22440
|
this.unsubscribers.push(() => {
|
|
22366
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
22441
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _539 => _539()]);
|
|
22367
22442
|
tracingChannel2.unsubscribe(handlers);
|
|
22368
22443
|
});
|
|
22369
22444
|
}
|
|
@@ -22411,7 +22486,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
22411
22486
|
};
|
|
22412
22487
|
tracingChannel2.subscribe(handlers);
|
|
22413
22488
|
this.unsubscribers.push(() => {
|
|
22414
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
22489
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _540 => _540()]);
|
|
22415
22490
|
tracingChannel2.unsubscribe(handlers);
|
|
22416
22491
|
});
|
|
22417
22492
|
}
|
|
@@ -22478,10 +22553,10 @@ function ensureActionSpanState(states, event, create) {
|
|
|
22478
22553
|
}
|
|
22479
22554
|
function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
22480
22555
|
const state = _internalGetGlobalState();
|
|
22481
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
22556
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _541 => _541.contextManager]);
|
|
22482
22557
|
const startChannel = tracingChannel2.start;
|
|
22483
22558
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
22484
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
22559
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _542 => _542.bindStore]) || !currentSpanStore) {
|
|
22485
22560
|
return void 0;
|
|
22486
22561
|
}
|
|
22487
22562
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -22493,7 +22568,7 @@ function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
|
22493
22568
|
return state2 ? contextManager.wrapSpanForStore(state2.span) : currentSpanStore.getStore();
|
|
22494
22569
|
});
|
|
22495
22570
|
return () => {
|
|
22496
|
-
_optionalChain([startChannel, 'access',
|
|
22571
|
+
_optionalChain([startChannel, 'access', _543 => _543.unbindStore, 'optionalCall', _544 => _544(currentSpanStore)]);
|
|
22497
22572
|
};
|
|
22498
22573
|
}
|
|
22499
22574
|
function normalizeInput(input) {
|
|
@@ -22540,25 +22615,25 @@ function extractGenerateOutput(result) {
|
|
|
22540
22615
|
}
|
|
22541
22616
|
function extractGenerateResponseMetadata(result, input) {
|
|
22542
22617
|
const normalized = input ? normalizeInput(input) : void 0;
|
|
22543
|
-
const request = isObject(_optionalChain([result, 'optionalAccess',
|
|
22618
|
+
const request = isObject(_optionalChain([result, 'optionalAccess', _545 => _545.request])) ? _optionalChain([result, 'optionalAccess', _546 => _546.request]) : isObject(normalized) ? normalized : void 0;
|
|
22544
22619
|
return {
|
|
22545
22620
|
...genkitProviderMetadata(),
|
|
22546
22621
|
...pickDefined({
|
|
22547
|
-
model: modelName(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
22548
|
-
finishReason: _optionalChain([result, 'optionalAccess',
|
|
22549
|
-
finishMessage: _optionalChain([result, 'optionalAccess',
|
|
22622
|
+
model: modelName(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _547 => _547.model]), () => ( _optionalChain([request, 'optionalAccess', _548 => _548.model])))),
|
|
22623
|
+
finishReason: _optionalChain([result, 'optionalAccess', _549 => _549.finishReason]),
|
|
22624
|
+
finishMessage: _optionalChain([result, 'optionalAccess', _550 => _550.finishMessage])
|
|
22550
22625
|
})
|
|
22551
22626
|
};
|
|
22552
22627
|
}
|
|
22553
22628
|
function extractEmbedInput(params) {
|
|
22554
22629
|
return {
|
|
22555
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
22630
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _551 => _551.content])),
|
|
22556
22631
|
metadata: extractEmbedMetadata(params)
|
|
22557
22632
|
};
|
|
22558
22633
|
}
|
|
22559
22634
|
function extractEmbedManyInput(params) {
|
|
22560
22635
|
return {
|
|
22561
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
22636
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _552 => _552.content])),
|
|
22562
22637
|
metadata: extractEmbedMetadata(params)
|
|
22563
22638
|
};
|
|
22564
22639
|
}
|
|
@@ -22566,7 +22641,7 @@ function extractEmbedMetadata(params) {
|
|
|
22566
22641
|
return {
|
|
22567
22642
|
...genkitProviderMetadata(),
|
|
22568
22643
|
...pickDefined({
|
|
22569
|
-
model: modelName(_optionalChain([params, 'optionalAccess',
|
|
22644
|
+
model: modelName(_optionalChain([params, 'optionalAccess', _553 => _553.embedder]))
|
|
22570
22645
|
})
|
|
22571
22646
|
};
|
|
22572
22647
|
}
|
|
@@ -22574,7 +22649,7 @@ function summarizeEmbeddingResult(result) {
|
|
|
22574
22649
|
if (Array.isArray(result)) {
|
|
22575
22650
|
return {
|
|
22576
22651
|
embedding_count: result.length,
|
|
22577
|
-
dimensions: Array.isArray(result[0]) || Array.isArray(_optionalChain([result, 'access',
|
|
22652
|
+
dimensions: Array.isArray(result[0]) || Array.isArray(_optionalChain([result, 'access', _554 => _554[0], 'optionalAccess', _555 => _555.embedding])) ? result[0].length || _optionalChain([result, 'access', _556 => _556[0], 'optionalAccess', _557 => _557.embedding, 'optionalAccess', _558 => _558.length]) : void 0
|
|
22578
22653
|
};
|
|
22579
22654
|
}
|
|
22580
22655
|
if (isObject(result) && Array.isArray(result.embeddings)) {
|
|
@@ -22601,7 +22676,7 @@ function patchGenerateStreamResult(result, span, startTime) {
|
|
|
22601
22676
|
finishSpan(async () => {
|
|
22602
22677
|
const streamedText = chunks.map((chunk) => safeGet(chunk, "text")).join("");
|
|
22603
22678
|
const response = await result.response;
|
|
22604
|
-
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess',
|
|
22679
|
+
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess', _559 => _559.usage]));
|
|
22605
22680
|
if (firstChunkTime !== void 0) {
|
|
22606
22681
|
metrics.time_to_first_token = firstChunkTime - startTime;
|
|
22607
22682
|
}
|
|
@@ -22694,22 +22769,22 @@ function extractActionMetadata(self) {
|
|
|
22694
22769
|
}
|
|
22695
22770
|
function extractActionSpanMetadata(args) {
|
|
22696
22771
|
const options = extractRunInNewSpanOptions(args);
|
|
22697
|
-
const labels = isObject(_optionalChain([options, 'optionalAccess',
|
|
22698
|
-
const metadata = isObject(_optionalChain([options, 'optionalAccess',
|
|
22699
|
-
const actionType = stringValue(_optionalChain([labels, 'optionalAccess',
|
|
22700
|
-
const name = stringValue(_optionalChain([metadata, 'optionalAccess',
|
|
22772
|
+
const labels = isObject(_optionalChain([options, 'optionalAccess', _560 => _560.labels])) ? options.labels : void 0;
|
|
22773
|
+
const metadata = isObject(_optionalChain([options, 'optionalAccess', _561 => _561.metadata])) ? options.metadata : void 0;
|
|
22774
|
+
const actionType = stringValue(_optionalChain([labels, 'optionalAccess', _562 => _562["genkit:metadata:subtype"]]));
|
|
22775
|
+
const name = stringValue(_optionalChain([metadata, 'optionalAccess', _563 => _563.name]));
|
|
22701
22776
|
if (!actionType || !name) {
|
|
22702
22777
|
return void 0;
|
|
22703
22778
|
}
|
|
22704
22779
|
return {
|
|
22705
22780
|
actionType,
|
|
22706
|
-
key: stringValue(_optionalChain([labels, 'optionalAccess',
|
|
22781
|
+
key: stringValue(_optionalChain([labels, 'optionalAccess', _564 => _564["genkit:key"]])),
|
|
22707
22782
|
name
|
|
22708
22783
|
};
|
|
22709
22784
|
}
|
|
22710
22785
|
function extractActionSpanInput(args) {
|
|
22711
22786
|
const options = extractRunInNewSpanOptions(args);
|
|
22712
|
-
if (!isObject(_optionalChain([options, 'optionalAccess',
|
|
22787
|
+
if (!isObject(_optionalChain([options, 'optionalAccess', _565 => _565.metadata]))) {
|
|
22713
22788
|
return void 0;
|
|
22714
22789
|
}
|
|
22715
22790
|
return options.metadata.input;
|
|
@@ -22722,7 +22797,7 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
22722
22797
|
if (runStepName) {
|
|
22723
22798
|
return true;
|
|
22724
22799
|
}
|
|
22725
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
22800
|
+
switch (_optionalChain([metadata, 'optionalAccess', _566 => _566.actionType])) {
|
|
22726
22801
|
case "model":
|
|
22727
22802
|
case "background-model":
|
|
22728
22803
|
case "embedder":
|
|
@@ -22732,8 +22807,8 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
22732
22807
|
}
|
|
22733
22808
|
}
|
|
22734
22809
|
function actionSpanName(metadata, runStepName) {
|
|
22735
|
-
const actionType = _optionalChain([metadata, 'optionalAccess',
|
|
22736
|
-
const name = _optionalChain([metadata, 'optionalAccess',
|
|
22810
|
+
const actionType = _optionalChain([metadata, 'optionalAccess', _567 => _567.actionType]);
|
|
22811
|
+
const name = _optionalChain([metadata, 'optionalAccess', _568 => _568.name]);
|
|
22737
22812
|
if (actionType && name) {
|
|
22738
22813
|
return `genkit.${actionType}: ${name}`;
|
|
22739
22814
|
}
|
|
@@ -22746,7 +22821,7 @@ function actionSpanName(metadata, runStepName) {
|
|
|
22746
22821
|
return "genkit.action";
|
|
22747
22822
|
}
|
|
22748
22823
|
function actionSpanType(metadata) {
|
|
22749
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
22824
|
+
switch (_optionalChain([metadata, 'optionalAccess', _569 => _569.actionType])) {
|
|
22750
22825
|
case "tool":
|
|
22751
22826
|
case "tool.v2":
|
|
22752
22827
|
return "tool" /* TOOL */;
|
|
@@ -22761,9 +22836,9 @@ function actionMetadataForLog(metadata, runStepName) {
|
|
|
22761
22836
|
return {
|
|
22762
22837
|
...genkitProviderMetadata(),
|
|
22763
22838
|
...pickDefined({
|
|
22764
|
-
"genkit.action_type": _optionalChain([metadata, 'optionalAccess',
|
|
22765
|
-
"genkit.action_name": _optionalChain([metadata, 'optionalAccess',
|
|
22766
|
-
"genkit.action_key": _optionalChain([metadata, 'optionalAccess',
|
|
22839
|
+
"genkit.action_type": _optionalChain([metadata, 'optionalAccess', _570 => _570.actionType]),
|
|
22840
|
+
"genkit.action_name": _optionalChain([metadata, 'optionalAccess', _571 => _571.name]),
|
|
22841
|
+
"genkit.action_key": _optionalChain([metadata, 'optionalAccess', _572 => _572.key]),
|
|
22767
22842
|
"genkit.run_name": runStepName
|
|
22768
22843
|
})
|
|
22769
22844
|
};
|
|
@@ -23226,10 +23301,10 @@ function injectTracingHooks2(config, state) {
|
|
|
23226
23301
|
const existingHooks = _nullishCoalesce(config.hooks, () => ( {}));
|
|
23227
23302
|
const onSessionEnd = async (input, invocation) => {
|
|
23228
23303
|
try {
|
|
23229
|
-
await _optionalChain([existingHooks, 'access',
|
|
23304
|
+
await _optionalChain([existingHooks, 'access', _573 => _573.onSessionEnd, 'optionalCall', _574 => _574(input, invocation)]);
|
|
23230
23305
|
} finally {
|
|
23231
23306
|
handleSessionEnd(state, input.reason, input.error);
|
|
23232
|
-
_optionalChain([state, 'access',
|
|
23307
|
+
_optionalChain([state, 'access', _575 => _575.unsubscribeEvents, 'optionalCall', _576 => _576()]);
|
|
23233
23308
|
}
|
|
23234
23309
|
};
|
|
23235
23310
|
config.hooks = {
|
|
@@ -23268,7 +23343,7 @@ function makeSessionHandlers(sessionStates, configArgIndex, includeProviderMetad
|
|
|
23268
23343
|
if (config.model) {
|
|
23269
23344
|
metadata["github_copilot.model"] = config.model;
|
|
23270
23345
|
}
|
|
23271
|
-
if (includeProviderMetadata && _optionalChain([config, 'access',
|
|
23346
|
+
if (includeProviderMetadata && _optionalChain([config, 'access', _577 => _577.provider, 'optionalAccess', _578 => _578.type])) {
|
|
23272
23347
|
metadata["github_copilot.provider_type"] = config.provider.type;
|
|
23273
23348
|
}
|
|
23274
23349
|
if (Object.keys(metadata).length > 0) {
|
|
@@ -23570,33 +23645,33 @@ function traceFlueOperation(channel2, args) {
|
|
|
23570
23645
|
const run = () => {
|
|
23571
23646
|
try {
|
|
23572
23647
|
originalResult = args.run();
|
|
23573
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23648
|
+
_optionalChain([tracingChannel2, 'access', _579 => _579.end, 'optionalAccess', _580 => _580.publish, 'call', _581 => _581(context)]);
|
|
23574
23649
|
} catch (error) {
|
|
23575
23650
|
context.error = normalizeError3(error);
|
|
23576
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23577
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23651
|
+
_optionalChain([tracingChannel2, 'access', _582 => _582.error, 'optionalAccess', _583 => _583.publish, 'call', _584 => _584(context)]);
|
|
23652
|
+
_optionalChain([tracingChannel2, 'access', _585 => _585.end, 'optionalAccess', _586 => _586.publish, 'call', _587 => _587(context)]);
|
|
23578
23653
|
throw error;
|
|
23579
23654
|
}
|
|
23580
23655
|
traced2 = Promise.resolve(originalResult).then(
|
|
23581
23656
|
(result) => {
|
|
23582
23657
|
context.result = result;
|
|
23583
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23584
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23658
|
+
_optionalChain([tracingChannel2, 'access', _588 => _588.asyncStart, 'optionalAccess', _589 => _589.publish, 'call', _590 => _590(context)]);
|
|
23659
|
+
_optionalChain([tracingChannel2, 'access', _591 => _591.asyncEnd, 'optionalAccess', _592 => _592.publish, 'call', _593 => _593(context)]);
|
|
23585
23660
|
return result;
|
|
23586
23661
|
},
|
|
23587
23662
|
(error) => {
|
|
23588
23663
|
context.error = normalizeError3(error);
|
|
23589
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23590
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23591
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23664
|
+
_optionalChain([tracingChannel2, 'access', _594 => _594.error, 'optionalAccess', _595 => _595.publish, 'call', _596 => _596(context)]);
|
|
23665
|
+
_optionalChain([tracingChannel2, 'access', _597 => _597.asyncStart, 'optionalAccess', _598 => _598.publish, 'call', _599 => _599(context)]);
|
|
23666
|
+
_optionalChain([tracingChannel2, 'access', _600 => _600.asyncEnd, 'optionalAccess', _601 => _601.publish, 'call', _602 => _602(context)]);
|
|
23592
23667
|
throw error;
|
|
23593
23668
|
}
|
|
23594
23669
|
);
|
|
23595
23670
|
};
|
|
23596
|
-
if (_optionalChain([tracingChannel2, 'access',
|
|
23671
|
+
if (_optionalChain([tracingChannel2, 'access', _603 => _603.start, 'optionalAccess', _604 => _604.runStores])) {
|
|
23597
23672
|
tracingChannel2.start.runStores(context, run);
|
|
23598
23673
|
} else {
|
|
23599
|
-
_optionalChain([tracingChannel2, 'access',
|
|
23674
|
+
_optionalChain([tracingChannel2, 'access', _605 => _605.start, 'optionalAccess', _606 => _606.publish, 'call', _607 => _607(context)]);
|
|
23600
23675
|
run();
|
|
23601
23676
|
}
|
|
23602
23677
|
return { originalResult, traced: traced2 };
|
|
@@ -23743,7 +23818,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
23743
23818
|
};
|
|
23744
23819
|
tracingChannel2.subscribe(handlers);
|
|
23745
23820
|
this.unsubscribers.push(() => {
|
|
23746
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
23821
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _608 => _608()]);
|
|
23747
23822
|
tracingChannel2.unsubscribe(handlers);
|
|
23748
23823
|
});
|
|
23749
23824
|
}
|
|
@@ -23787,7 +23862,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
23787
23862
|
};
|
|
23788
23863
|
tracingChannel2.subscribe(handlers);
|
|
23789
23864
|
this.unsubscribers.push(() => {
|
|
23790
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
23865
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _609 => _609()]);
|
|
23791
23866
|
tracingChannel2.unsubscribe(handlers);
|
|
23792
23867
|
});
|
|
23793
23868
|
}
|
|
@@ -23818,7 +23893,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
23818
23893
|
bindCurrentSpanStoreToOperationStart(tracingChannel2, ensureState2) {
|
|
23819
23894
|
const state = _internalGetGlobalState();
|
|
23820
23895
|
const startChannel = tracingChannel2.start;
|
|
23821
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
23896
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _610 => _610.contextManager]);
|
|
23822
23897
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
23823
23898
|
if (!currentSpanStore || !startChannel) {
|
|
23824
23899
|
return void 0;
|
|
@@ -23875,7 +23950,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
23875
23950
|
};
|
|
23876
23951
|
const metrics = {
|
|
23877
23952
|
...buildDurationMetrics3(state.startTime),
|
|
23878
|
-
...metricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23953
|
+
...metricsFromUsage(_optionalChain([result, 'optionalAccess', _611 => _611.usage]))
|
|
23879
23954
|
};
|
|
23880
23955
|
safeLog3(state.span, {
|
|
23881
23956
|
metadata,
|
|
@@ -24173,7 +24248,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
24173
24248
|
}
|
|
24174
24249
|
handleCompactionStart(event) {
|
|
24175
24250
|
const operationState = this.operationStateForEvent(event);
|
|
24176
|
-
const parent = _nullishCoalesce(_optionalChain([operationState, 'optionalAccess',
|
|
24251
|
+
const parent = _nullishCoalesce(_optionalChain([operationState, 'optionalAccess', _612 => _612.span]), () => ( this.parentSpanForEvent(event)));
|
|
24177
24252
|
const metadata = {
|
|
24178
24253
|
...extractEventMetadata(event),
|
|
24179
24254
|
...event.reason ? { "flue.compaction_reason": event.reason } : {},
|
|
@@ -24291,9 +24366,9 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
24291
24366
|
}
|
|
24292
24367
|
}
|
|
24293
24368
|
if (event.taskId) {
|
|
24294
|
-
return _optionalChain([this, 'access',
|
|
24369
|
+
return _optionalChain([this, 'access', _613 => _613.tasksById, 'access', _614 => _614.get, 'call', _615 => _615(event.taskId), 'optionalAccess', _616 => _616.span]);
|
|
24295
24370
|
}
|
|
24296
|
-
return _optionalChain([this, 'access',
|
|
24371
|
+
return _optionalChain([this, 'access', _617 => _617.operationStateForEvent, 'call', _618 => _618(event), 'optionalAccess', _619 => _619.span]);
|
|
24297
24372
|
}
|
|
24298
24373
|
promotePendingOperationForEvent(event) {
|
|
24299
24374
|
if (!event.operationId) {
|
|
@@ -24324,7 +24399,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
24324
24399
|
activeOperationForEventScope(event) {
|
|
24325
24400
|
for (const scope of operationScopeNames(event)) {
|
|
24326
24401
|
const operations = this.activeOperationsByScope.get(scope);
|
|
24327
|
-
if (_optionalChain([operations, 'optionalAccess',
|
|
24402
|
+
if (_optionalChain([operations, 'optionalAccess', _620 => _620.length])) {
|
|
24328
24403
|
return operations[operations.length - 1];
|
|
24329
24404
|
}
|
|
24330
24405
|
}
|
|
@@ -24343,7 +24418,7 @@ var FluePlugin = (_class22 = class extends BasePlugin {constructor(...args6) { s
|
|
|
24343
24418
|
takePendingOperationForEvent(event) {
|
|
24344
24419
|
const key = operationKey(event.session, event.operationKind);
|
|
24345
24420
|
const queue2 = this.pendingOperationsByKey.get(key);
|
|
24346
|
-
if (_optionalChain([queue2, 'optionalAccess',
|
|
24421
|
+
if (_optionalChain([queue2, 'optionalAccess', _621 => _621.length])) {
|
|
24347
24422
|
return queue2.shift();
|
|
24348
24423
|
}
|
|
24349
24424
|
for (const [candidateKey, candidateQueue] of this.pendingOperationsByKey) {
|
|
@@ -24367,7 +24442,7 @@ function isInstrumentedOperation(operation) {
|
|
|
24367
24442
|
return operation === "prompt" || operation === "skill" || operation === "task" || operation === "compact";
|
|
24368
24443
|
}
|
|
24369
24444
|
function getSessionName(session) {
|
|
24370
|
-
return typeof _optionalChain([session, 'optionalAccess',
|
|
24445
|
+
return typeof _optionalChain([session, 'optionalAccess', _622 => _622.name]) === "string" ? session.name : void 0;
|
|
24371
24446
|
}
|
|
24372
24447
|
function operationKey(sessionName, operation) {
|
|
24373
24448
|
return `${_nullishCoalesce(sessionName, () => ( "unknown"))}::${operation}`;
|
|
@@ -24462,7 +24537,7 @@ function extractOperationInput(operation, args) {
|
|
|
24462
24537
|
return args[0];
|
|
24463
24538
|
case "skill":
|
|
24464
24539
|
return {
|
|
24465
|
-
args: _optionalChain([getOptionObject, 'call',
|
|
24540
|
+
args: _optionalChain([getOptionObject, 'call', _623 => _623(args[1]), 'optionalAccess', _624 => _624.args]),
|
|
24466
24541
|
name: args[0]
|
|
24467
24542
|
};
|
|
24468
24543
|
case "compact":
|
|
@@ -24473,16 +24548,16 @@ function extractOperationInputMetadata(operation, args) {
|
|
|
24473
24548
|
const options = getOptionObject(args[1]);
|
|
24474
24549
|
return {
|
|
24475
24550
|
...operation === "skill" && typeof args[0] === "string" ? { "flue.skill_name": args[0] } : {},
|
|
24476
|
-
..._optionalChain([options, 'optionalAccess',
|
|
24477
|
-
..._optionalChain([options, 'optionalAccess',
|
|
24478
|
-
..._optionalChain([options, 'optionalAccess',
|
|
24479
|
-
...typeof _optionalChain([options, 'optionalAccess',
|
|
24480
|
-
...Array.isArray(_optionalChain([options, 'optionalAccess',
|
|
24551
|
+
..._optionalChain([options, 'optionalAccess', _625 => _625.model]) ? { model: options.model, "flue.model": options.model } : {},
|
|
24552
|
+
..._optionalChain([options, 'optionalAccess', _626 => _626.role]) ? { "flue.role": options.role } : {},
|
|
24553
|
+
..._optionalChain([options, 'optionalAccess', _627 => _627.thinkingLevel]) ? { "flue.thinking_level": options.thinkingLevel } : {},
|
|
24554
|
+
...typeof _optionalChain([options, 'optionalAccess', _628 => _628.cwd]) === "string" ? { "flue.cwd": options.cwd } : {},
|
|
24555
|
+
...Array.isArray(_optionalChain([options, 'optionalAccess', _629 => _629.tools])) ? {
|
|
24481
24556
|
"flue.tools_count": options.tools.length,
|
|
24482
24557
|
tools: summarizeTools(options.tools)
|
|
24483
24558
|
} : {},
|
|
24484
|
-
...Array.isArray(_optionalChain([options, 'optionalAccess',
|
|
24485
|
-
..._optionalChain([options, 'optionalAccess',
|
|
24559
|
+
...Array.isArray(_optionalChain([options, 'optionalAccess', _630 => _630.images])) ? { "flue.images_count": options.images.length } : {},
|
|
24560
|
+
..._optionalChain([options, 'optionalAccess', _631 => _631.result]) || _optionalChain([options, 'optionalAccess', _632 => _632.schema]) ? { "flue.result_schema": true } : {}
|
|
24486
24561
|
};
|
|
24487
24562
|
}
|
|
24488
24563
|
function getOptionObject(value) {
|
|
@@ -24510,7 +24585,7 @@ function summarizeTools(tools) {
|
|
|
24510
24585
|
});
|
|
24511
24586
|
}
|
|
24512
24587
|
function extractPromptResponseMetadata(result) {
|
|
24513
|
-
const modelId = _optionalChain([result, 'optionalAccess',
|
|
24588
|
+
const modelId = _optionalChain([result, 'optionalAccess', _633 => _633.model]) && typeof result.model.id === "string" ? result.model.id : void 0;
|
|
24514
24589
|
return modelId ? {
|
|
24515
24590
|
model: modelId,
|
|
24516
24591
|
"flue.model": modelId
|
|
@@ -24530,12 +24605,12 @@ function extractOperationOutput(result) {
|
|
|
24530
24605
|
}
|
|
24531
24606
|
function metricsFromUsage(usage) {
|
|
24532
24607
|
return {
|
|
24533
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24534
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24535
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24536
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24537
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24538
|
-
...typeof _optionalChain([usage, 'optionalAccess',
|
|
24608
|
+
...typeof _optionalChain([usage, 'optionalAccess', _634 => _634.input]) === "number" ? { prompt_tokens: usage.input } : {},
|
|
24609
|
+
...typeof _optionalChain([usage, 'optionalAccess', _635 => _635.output]) === "number" ? { completion_tokens: usage.output } : {},
|
|
24610
|
+
...typeof _optionalChain([usage, 'optionalAccess', _636 => _636.cacheRead]) === "number" ? { prompt_cached_tokens: usage.cacheRead } : {},
|
|
24611
|
+
...typeof _optionalChain([usage, 'optionalAccess', _637 => _637.cacheWrite]) === "number" ? { prompt_cache_creation_tokens: usage.cacheWrite } : {},
|
|
24612
|
+
...typeof _optionalChain([usage, 'optionalAccess', _638 => _638.totalTokens]) === "number" ? { tokens: usage.totalTokens } : {},
|
|
24613
|
+
...typeof _optionalChain([usage, 'optionalAccess', _639 => _639.cost, 'optionalAccess', _640 => _640.total]) === "number" ? { estimated_cost: usage.cost.total } : {}
|
|
24539
24614
|
};
|
|
24540
24615
|
}
|
|
24541
24616
|
function buildDurationMetrics3(startTime) {
|
|
@@ -24570,7 +24645,7 @@ function toAssistantOutput(text, finishReason, reasoning, toolCalls) {
|
|
|
24570
24645
|
content: text,
|
|
24571
24646
|
...reasoning ? { reasoning } : {},
|
|
24572
24647
|
role: "assistant",
|
|
24573
|
-
..._optionalChain([toolCalls, 'optionalAccess',
|
|
24648
|
+
..._optionalChain([toolCalls, 'optionalAccess', _641 => _641.length]) ? {
|
|
24574
24649
|
tool_calls: toolCalls.map((toolCall) => ({
|
|
24575
24650
|
function: {
|
|
24576
24651
|
arguments: toolCall.args === void 0 ? "{}" : JSON.stringify(toolCall.args),
|
|
@@ -24624,11 +24699,11 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
24624
24699
|
__init82() {this.firstTokenTimes = /* @__PURE__ */ new Map()}
|
|
24625
24700
|
__init83() {this.ttftMs = /* @__PURE__ */ new Map()}
|
|
24626
24701
|
constructor(options) {;_class23.prototype.__init78.call(this);_class23.prototype.__init79.call(this);_class23.prototype.__init80.call(this);_class23.prototype.__init81.call(this);_class23.prototype.__init82.call(this);_class23.prototype.__init83.call(this);
|
|
24627
|
-
this.parent = _optionalChain([options, 'optionalAccess',
|
|
24702
|
+
this.parent = _optionalChain([options, 'optionalAccess', _642 => _642.parent]);
|
|
24628
24703
|
this.options = {
|
|
24629
|
-
debug: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
24630
|
-
excludeMetadataProps: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
24631
|
-
logger: _optionalChain([options, 'optionalAccess',
|
|
24704
|
+
debug: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _643 => _643.debug]), () => ( false)),
|
|
24705
|
+
excludeMetadataProps: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _644 => _644.excludeMetadataProps]), () => ( /^(l[sc]_|langgraph_|__pregel_|checkpoint_ns)/)),
|
|
24706
|
+
logger: _optionalChain([options, 'optionalAccess', _645 => _645.logger])
|
|
24632
24707
|
};
|
|
24633
24708
|
}
|
|
24634
24709
|
startSpan({
|
|
@@ -24642,7 +24717,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
24642
24717
|
if (!parentRunId) {
|
|
24643
24718
|
this.rootRunId = runId;
|
|
24644
24719
|
}
|
|
24645
|
-
const tags = _optionalChain([args, 'access',
|
|
24720
|
+
const tags = _optionalChain([args, 'access', _646 => _646.event, 'optionalAccess', _647 => _647.tags]);
|
|
24646
24721
|
const spanAttributes = args.spanAttributes || {};
|
|
24647
24722
|
spanAttributes.type = args.type || spanAttributes.type || "task";
|
|
24648
24723
|
args.type = spanAttributes.type;
|
|
@@ -24662,7 +24737,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
24662
24737
|
tags: void 0,
|
|
24663
24738
|
metadata: {
|
|
24664
24739
|
...tags ? { tags } : {},
|
|
24665
|
-
..._optionalChain([args, 'access',
|
|
24740
|
+
..._optionalChain([args, 'access', _648 => _648.event, 'optionalAccess', _649 => _649.metadata]),
|
|
24666
24741
|
braintrust: {
|
|
24667
24742
|
integration_name: "langchain-js",
|
|
24668
24743
|
sdk_language: "javascript"
|
|
@@ -24764,7 +24839,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
24764
24839
|
});
|
|
24765
24840
|
}
|
|
24766
24841
|
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, runName) {
|
|
24767
|
-
if (_optionalChain([tags, 'optionalAccess',
|
|
24842
|
+
if (_optionalChain([tags, 'optionalAccess', _650 => _650.includes, 'call', _651 => _651("langsmith:hidden")])) {
|
|
24768
24843
|
this.skippedRuns.add(runId);
|
|
24769
24844
|
return;
|
|
24770
24845
|
}
|
|
@@ -24874,7 +24949,7 @@ function getSerializedName(serialized) {
|
|
|
24874
24949
|
if (typeof serialized.name === "string") {
|
|
24875
24950
|
return serialized.name;
|
|
24876
24951
|
}
|
|
24877
|
-
const lastIdPart = _optionalChain([serialized, 'access',
|
|
24952
|
+
const lastIdPart = _optionalChain([serialized, 'access', _652 => _652.id, 'optionalAccess', _653 => _653.at, 'call', _654 => _654(-1)]);
|
|
24878
24953
|
return typeof lastIdPart === "string" ? lastIdPart : void 0;
|
|
24879
24954
|
}
|
|
24880
24955
|
function cleanObject(obj) {
|
|
@@ -25023,7 +25098,7 @@ function isCallbackManager(value) {
|
|
|
25023
25098
|
return typeof maybeManager.addHandler === "function";
|
|
25024
25099
|
}
|
|
25025
25100
|
function hasBraintrustHandler(manager) {
|
|
25026
|
-
return _nullishCoalesce(_optionalChain([manager, 'access',
|
|
25101
|
+
return _nullishCoalesce(_optionalChain([manager, 'access', _655 => _655.handlers, 'optionalAccess', _656 => _656.some, 'call', _657 => _657((handler) => {
|
|
25027
25102
|
if (typeof handler !== "object" || handler === null) {
|
|
25028
25103
|
return false;
|
|
25029
25104
|
}
|
|
@@ -25087,7 +25162,7 @@ var BraintrustPlugin = (_class25 = class extends BasePlugin {
|
|
|
25087
25162
|
this.config = config;
|
|
25088
25163
|
}
|
|
25089
25164
|
onEnable() {
|
|
25090
|
-
const integrations = this.config.integrations
|
|
25165
|
+
const integrations = _nullishCoalesce(this.config.integrations, () => ( {}));
|
|
25091
25166
|
if (integrations.openai !== false) {
|
|
25092
25167
|
this.openaiPlugin = new OpenAIPlugin();
|
|
25093
25168
|
this.openaiPlugin.enable();
|
|
@@ -25152,7 +25227,7 @@ var BraintrustPlugin = (_class25 = class extends BasePlugin {
|
|
|
25152
25227
|
this.genkitPlugin = new GenkitPlugin();
|
|
25153
25228
|
this.genkitPlugin.enable();
|
|
25154
25229
|
}
|
|
25155
|
-
if (
|
|
25230
|
+
if (integrations.gitHubCopilot !== false) {
|
|
25156
25231
|
this.gitHubCopilotPlugin = new GitHubCopilotPlugin();
|
|
25157
25232
|
this.gitHubCopilotPlugin.enable();
|
|
25158
25233
|
}
|
|
@@ -25265,6 +25340,7 @@ var envIntegrationAliases = {
|
|
|
25265
25340
|
cursorsdk: "cursorSDK",
|
|
25266
25341
|
flue: "flue",
|
|
25267
25342
|
"flue-runtime": "flue",
|
|
25343
|
+
mastra: "mastra",
|
|
25268
25344
|
"openai-agents": "openAIAgents",
|
|
25269
25345
|
openaiagents: "openAIAgents",
|
|
25270
25346
|
"openai-agents-core": "openAIAgents",
|
|
@@ -25307,6 +25383,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
25307
25383
|
cursor: true,
|
|
25308
25384
|
cursorSDK: true,
|
|
25309
25385
|
flue: true,
|
|
25386
|
+
mastra: true,
|
|
25310
25387
|
openAIAgents: true,
|
|
25311
25388
|
openrouter: true,
|
|
25312
25389
|
openrouterAgent: true,
|
|
@@ -25331,6 +25408,9 @@ function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
|
25331
25408
|
}
|
|
25332
25409
|
return { integrations };
|
|
25333
25410
|
}
|
|
25411
|
+
function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
25412
|
+
return names.some((name) => _optionalChain([integrations, 'optionalAccess', _658 => _658[name]]) === false);
|
|
25413
|
+
}
|
|
25334
25414
|
|
|
25335
25415
|
// src/instrumentation/registry.ts
|
|
25336
25416
|
var REGISTRY_STATE_KEY = /* @__PURE__ */ Symbol.for("braintrust.registry");
|
|
@@ -25424,6 +25504,263 @@ var PluginRegistry = (_class26 = class {constructor() { _class26.prototype.__ini
|
|
|
25424
25504
|
}, _class26);
|
|
25425
25505
|
var registry = new PluginRegistry();
|
|
25426
25506
|
|
|
25507
|
+
// src/auto-instrumentations/loader/mastra-observability-patch.ts
|
|
25508
|
+
var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
|
|
25509
|
+
function installMastraExporterFactory(factory) {
|
|
25510
|
+
const globals = globalThis;
|
|
25511
|
+
globals[MASTRA_EXPORTER_FACTORY_GLOBAL] ??= factory;
|
|
25512
|
+
}
|
|
25513
|
+
var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
|
|
25514
|
+
var OBSERVABILITY_APPEND_BODY = `
|
|
25515
|
+
;(function __braintrustWrapObservability() {
|
|
25516
|
+
// Top-level so we can both read and reassign the var binding the original
|
|
25517
|
+
// entry declared.
|
|
25518
|
+
if (typeof Observability === "undefined") return;
|
|
25519
|
+
if (Observability.__braintrustWrapped) return;
|
|
25520
|
+
function __braintrustEnsureExporter(rawConfig) {
|
|
25521
|
+
try {
|
|
25522
|
+
var factory = globalThis[${EXPORTER_FACTORY_KEY}];
|
|
25523
|
+
if (typeof factory !== "function") return rawConfig;
|
|
25524
|
+
var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
|
|
25525
|
+
var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
|
|
25526
|
+
var configsOut = {};
|
|
25527
|
+
var hadEntries = false;
|
|
25528
|
+
if (configsIn) {
|
|
25529
|
+
for (var name in configsIn) {
|
|
25530
|
+
if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
|
|
25531
|
+
hadEntries = true;
|
|
25532
|
+
var inst = configsIn[name] || {};
|
|
25533
|
+
var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
|
|
25534
|
+
var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
|
|
25535
|
+
configsOut[name] = Object.assign({}, inst, {
|
|
25536
|
+
exporters: hasOurs ? existing : existing.concat([factory()]),
|
|
25537
|
+
});
|
|
25538
|
+
}
|
|
25539
|
+
}
|
|
25540
|
+
if (!hadEntries) {
|
|
25541
|
+
configsOut.default = {
|
|
25542
|
+
serviceName: "mastra",
|
|
25543
|
+
exporters: [factory()],
|
|
25544
|
+
};
|
|
25545
|
+
}
|
|
25546
|
+
return Object.assign({}, config, { configs: configsOut });
|
|
25547
|
+
} catch (e) {
|
|
25548
|
+
return rawConfig;
|
|
25549
|
+
}
|
|
25550
|
+
}
|
|
25551
|
+
var __OriginalObservability = Observability;
|
|
25552
|
+
Observability = new Proxy(__OriginalObservability, {
|
|
25553
|
+
construct: function (target, args, newTarget) {
|
|
25554
|
+
var nextArgs = args.slice();
|
|
25555
|
+
nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
|
|
25556
|
+
return Reflect.construct(target, nextArgs, newTarget);
|
|
25557
|
+
},
|
|
25558
|
+
});
|
|
25559
|
+
Observability.__braintrustWrapped = true;
|
|
25560
|
+
if (typeof exports !== "undefined" && exports && typeof exports === "object") {
|
|
25561
|
+
try {
|
|
25562
|
+
Object.defineProperty(exports, "Observability", {
|
|
25563
|
+
enumerable: true,
|
|
25564
|
+
configurable: true,
|
|
25565
|
+
get: function () { return Observability; },
|
|
25566
|
+
});
|
|
25567
|
+
} catch (e) {}
|
|
25568
|
+
}
|
|
25569
|
+
})();
|
|
25570
|
+
`;
|
|
25571
|
+
|
|
25572
|
+
// src/wrappers/mastra.ts
|
|
25573
|
+
var MASTRA_BRAINTRUST_EXPORTER_NAME = "braintrust";
|
|
25574
|
+
var SPAN_TYPE_MAP = {
|
|
25575
|
+
agent_run: "task" /* TASK */,
|
|
25576
|
+
model_generation: "llm" /* LLM */,
|
|
25577
|
+
model_step: "llm" /* LLM */,
|
|
25578
|
+
model_chunk: "llm" /* LLM */,
|
|
25579
|
+
tool_call: "tool" /* TOOL */,
|
|
25580
|
+
mcp_tool_call: "tool" /* TOOL */,
|
|
25581
|
+
workflow_run: "task" /* TASK */,
|
|
25582
|
+
workflow_step: "function" /* FUNCTION */,
|
|
25583
|
+
workflow_conditional: "function" /* FUNCTION */,
|
|
25584
|
+
workflow_conditional_eval: "function" /* FUNCTION */,
|
|
25585
|
+
workflow_parallel: "function" /* FUNCTION */,
|
|
25586
|
+
workflow_loop: "function" /* FUNCTION */,
|
|
25587
|
+
workflow_sleep: "function" /* FUNCTION */,
|
|
25588
|
+
workflow_wait_event: "function" /* FUNCTION */,
|
|
25589
|
+
memory_operation: "function" /* FUNCTION */,
|
|
25590
|
+
workspace_action: "function" /* FUNCTION */,
|
|
25591
|
+
rag_ingestion: "task" /* TASK */,
|
|
25592
|
+
rag_embedding: "llm" /* LLM */,
|
|
25593
|
+
rag_vector_operation: "function" /* FUNCTION */,
|
|
25594
|
+
rag_action: "function" /* FUNCTION */,
|
|
25595
|
+
graph_action: "function" /* FUNCTION */,
|
|
25596
|
+
scorer_run: "score" /* SCORE */,
|
|
25597
|
+
scorer_step: "score" /* SCORE */,
|
|
25598
|
+
processor_run: "function" /* FUNCTION */,
|
|
25599
|
+
generic: "function" /* FUNCTION */
|
|
25600
|
+
};
|
|
25601
|
+
function spanTypeFor(mastraType) {
|
|
25602
|
+
return _nullishCoalesce(SPAN_TYPE_MAP[mastraType], () => ( "function")) /* FUNCTION */;
|
|
25603
|
+
}
|
|
25604
|
+
function epochSeconds(value) {
|
|
25605
|
+
if (value === void 0) return void 0;
|
|
25606
|
+
const ms = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
|
|
25607
|
+
return Number.isFinite(ms) ? ms / 1e3 : void 0;
|
|
25608
|
+
}
|
|
25609
|
+
function modelMetrics(attributes) {
|
|
25610
|
+
if (!isObject(attributes)) return void 0;
|
|
25611
|
+
const usage = isObject(attributes.usage) ? attributes.usage : void 0;
|
|
25612
|
+
if (!usage) return void 0;
|
|
25613
|
+
const out = {};
|
|
25614
|
+
if (typeof usage.inputTokens === "number")
|
|
25615
|
+
out.prompt_tokens = usage.inputTokens;
|
|
25616
|
+
if (typeof usage.outputTokens === "number")
|
|
25617
|
+
out.completion_tokens = usage.outputTokens;
|
|
25618
|
+
if (typeof usage.inputTokens === "number" && typeof usage.outputTokens === "number") {
|
|
25619
|
+
out.tokens = usage.inputTokens + usage.outputTokens;
|
|
25620
|
+
}
|
|
25621
|
+
const inputDetails = isObject(usage.inputDetails) ? usage.inputDetails : void 0;
|
|
25622
|
+
const outputDetails = isObject(usage.outputDetails) ? usage.outputDetails : void 0;
|
|
25623
|
+
if (inputDetails && typeof inputDetails.cacheRead === "number") {
|
|
25624
|
+
out.prompt_cached_tokens = inputDetails.cacheRead;
|
|
25625
|
+
}
|
|
25626
|
+
if (inputDetails && typeof inputDetails.cacheWrite === "number") {
|
|
25627
|
+
out.prompt_cache_creation_tokens = inputDetails.cacheWrite;
|
|
25628
|
+
}
|
|
25629
|
+
if (outputDetails && typeof outputDetails.reasoning === "number") {
|
|
25630
|
+
out.completion_reasoning_tokens = outputDetails.reasoning;
|
|
25631
|
+
}
|
|
25632
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
25633
|
+
}
|
|
25634
|
+
function buildMetadata(exported) {
|
|
25635
|
+
const out = {};
|
|
25636
|
+
if (exported.entityId !== void 0) out.entity_id = exported.entityId;
|
|
25637
|
+
if (exported.entityName !== void 0) out.entity_name = exported.entityName;
|
|
25638
|
+
if (exported.entityType !== void 0) out.entity_type = exported.entityType;
|
|
25639
|
+
if (exported.metadata && isObject(exported.metadata)) {
|
|
25640
|
+
Object.assign(out, exported.metadata);
|
|
25641
|
+
}
|
|
25642
|
+
if (exported.attributes && isObject(exported.attributes)) {
|
|
25643
|
+
for (const [key, value] of Object.entries(exported.attributes)) {
|
|
25644
|
+
if (key === "usage") continue;
|
|
25645
|
+
if (value !== void 0) out[key] = value;
|
|
25646
|
+
}
|
|
25647
|
+
}
|
|
25648
|
+
if (exported.tags && exported.tags.length > 0) {
|
|
25649
|
+
out.tags = exported.tags;
|
|
25650
|
+
}
|
|
25651
|
+
if (exported.requestContext && isObject(exported.requestContext)) {
|
|
25652
|
+
out.request_context = exported.requestContext;
|
|
25653
|
+
}
|
|
25654
|
+
return out;
|
|
25655
|
+
}
|
|
25656
|
+
var BraintrustObservabilityExporter = (_class27 = class {
|
|
25657
|
+
__init107() {this.name = MASTRA_BRAINTRUST_EXPORTER_NAME}
|
|
25658
|
+
__init108() {this.spans = /* @__PURE__ */ new Map()}
|
|
25659
|
+
// Captured at the first SPAN_STARTED event. Mastra's observability bus may
|
|
25660
|
+
// dispatch later events outside the user's AsyncLocalStorage context, where
|
|
25661
|
+
// `currentSpan()` returns NOOP_SPAN — which would make our `startSpan()`
|
|
25662
|
+
// calls go to a no-op logger and silently drop. Anchoring on the parent
|
|
25663
|
+
// we observe while still in-context keeps the whole Mastra subtree under
|
|
25664
|
+
// the user's traced scenario.
|
|
25665
|
+
|
|
25666
|
+
constructor() {;_class27.prototype.__init107.call(this);_class27.prototype.__init108.call(this);
|
|
25667
|
+
_internalSetInitialState();
|
|
25668
|
+
}
|
|
25669
|
+
async exportTracingEvent(event) {
|
|
25670
|
+
const exported = event.exportedSpan;
|
|
25671
|
+
if (exported.isInternal === true) return;
|
|
25672
|
+
try {
|
|
25673
|
+
switch (event.type) {
|
|
25674
|
+
case "span_started":
|
|
25675
|
+
this.onStart(exported);
|
|
25676
|
+
break;
|
|
25677
|
+
case "span_updated":
|
|
25678
|
+
this.onUpdate(exported);
|
|
25679
|
+
break;
|
|
25680
|
+
case "span_ended":
|
|
25681
|
+
this.onEnd(exported);
|
|
25682
|
+
break;
|
|
25683
|
+
}
|
|
25684
|
+
} catch (err) {
|
|
25685
|
+
logExporterError(err);
|
|
25686
|
+
}
|
|
25687
|
+
}
|
|
25688
|
+
async flush() {
|
|
25689
|
+
const state = _internalGetGlobalState();
|
|
25690
|
+
if (state) {
|
|
25691
|
+
await state.bgLogger().flush();
|
|
25692
|
+
}
|
|
25693
|
+
}
|
|
25694
|
+
async shutdown() {
|
|
25695
|
+
await this.flush();
|
|
25696
|
+
this.spans.clear();
|
|
25697
|
+
}
|
|
25698
|
+
onStart(exported) {
|
|
25699
|
+
if (this.spans.has(exported.id)) return;
|
|
25700
|
+
const args = {
|
|
25701
|
+
name: exported.name,
|
|
25702
|
+
spanAttributes: { type: spanTypeFor(exported.type) },
|
|
25703
|
+
startTime: epochSeconds(exported.startTime)
|
|
25704
|
+
};
|
|
25705
|
+
const parentRecord = exported.parentSpanId ? this.spans.get(exported.parentSpanId) : void 0;
|
|
25706
|
+
if (!this.capturedParent) {
|
|
25707
|
+
const probe = currentSpan();
|
|
25708
|
+
if (probe && probe.spanId) {
|
|
25709
|
+
this.capturedParent = probe;
|
|
25710
|
+
}
|
|
25711
|
+
}
|
|
25712
|
+
const span = parentRecord ? parentRecord.span.startSpan(args) : this.capturedParent ? this.capturedParent.startSpan(args) : startSpan(args);
|
|
25713
|
+
const record = { span, hasLoggedInput: false };
|
|
25714
|
+
this.logPayload(record, exported);
|
|
25715
|
+
this.spans.set(exported.id, record);
|
|
25716
|
+
if (exported.isEvent === true) {
|
|
25717
|
+
span.end({ endTime: args.startTime });
|
|
25718
|
+
this.spans.delete(exported.id);
|
|
25719
|
+
}
|
|
25720
|
+
}
|
|
25721
|
+
onUpdate(exported) {
|
|
25722
|
+
const record = this.spans.get(exported.id);
|
|
25723
|
+
if (!record) return;
|
|
25724
|
+
this.logPayload(record, exported);
|
|
25725
|
+
}
|
|
25726
|
+
onEnd(exported) {
|
|
25727
|
+
const record = this.spans.get(exported.id);
|
|
25728
|
+
if (!record) return;
|
|
25729
|
+
this.logPayload(record, exported);
|
|
25730
|
+
if (exported.errorInfo) {
|
|
25731
|
+
record.span.log({
|
|
25732
|
+
error: exported.errorInfo.message || exported.errorInfo.name || "Unknown Mastra error"
|
|
25733
|
+
});
|
|
25734
|
+
}
|
|
25735
|
+
record.span.end({ endTime: epochSeconds(exported.endTime) });
|
|
25736
|
+
this.spans.delete(exported.id);
|
|
25737
|
+
}
|
|
25738
|
+
logPayload(record, exported) {
|
|
25739
|
+
const event = {};
|
|
25740
|
+
if (exported.input !== void 0) {
|
|
25741
|
+
event.input = exported.input;
|
|
25742
|
+
record.hasLoggedInput = true;
|
|
25743
|
+
}
|
|
25744
|
+
if (exported.output !== void 0) {
|
|
25745
|
+
event.output = exported.output;
|
|
25746
|
+
}
|
|
25747
|
+
const metadata = buildMetadata(exported);
|
|
25748
|
+
if (Object.keys(metadata).length > 0) {
|
|
25749
|
+
event.metadata = metadata;
|
|
25750
|
+
}
|
|
25751
|
+
const metrics = modelMetrics(exported.attributes);
|
|
25752
|
+
if (metrics) {
|
|
25753
|
+
event.metrics = metrics;
|
|
25754
|
+
}
|
|
25755
|
+
if (Object.keys(event).length > 0) {
|
|
25756
|
+
record.span.log(event);
|
|
25757
|
+
}
|
|
25758
|
+
}
|
|
25759
|
+
}, _class27);
|
|
25760
|
+
function logExporterError(err) {
|
|
25761
|
+
debugLogger.warn("Mastra exporter failure:", err);
|
|
25762
|
+
}
|
|
25763
|
+
|
|
25427
25764
|
// src/node/config.ts
|
|
25428
25765
|
var BRAINTRUST_ENV_SEARCH_PARENT_LIMIT = 64;
|
|
25429
25766
|
function configureNode() {
|
|
@@ -25432,11 +25769,11 @@ function configureNode() {
|
|
|
25432
25769
|
isomorph_default.getPastNAncestors = getPastNAncestors;
|
|
25433
25770
|
isomorph_default.getEnv = (name) => {
|
|
25434
25771
|
const value = process.env[name];
|
|
25435
|
-
return name === "BRAINTRUST_API_KEY" && !_optionalChain([value, 'optionalAccess',
|
|
25772
|
+
return name === "BRAINTRUST_API_KEY" && !_optionalChain([value, 'optionalAccess', _659 => _659.trim, 'call', _660 => _660()]) ? void 0 : value;
|
|
25436
25773
|
};
|
|
25437
25774
|
isomorph_default.getBraintrustApiKey = async () => {
|
|
25438
25775
|
const value = process.env.BRAINTRUST_API_KEY;
|
|
25439
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
25776
|
+
if (_optionalChain([value, 'optionalAccess', _661 => _661.trim, 'call', _662 => _662()])) {
|
|
25440
25777
|
return value;
|
|
25441
25778
|
}
|
|
25442
25779
|
const envPaths = [];
|
|
@@ -25467,7 +25804,7 @@ function configureNode() {
|
|
|
25467
25804
|
if ("contents" in nearestResult) {
|
|
25468
25805
|
const parsed = dotenv.parse(nearestResult.contents);
|
|
25469
25806
|
const apiKey = parsed.BRAINTRUST_API_KEY;
|
|
25470
|
-
return _optionalChain([apiKey, 'optionalAccess',
|
|
25807
|
+
return _optionalChain([apiKey, 'optionalAccess', _663 => _663.trim, 'call', _664 => _664()]) ? apiKey : void 0;
|
|
25471
25808
|
}
|
|
25472
25809
|
const e = nearestResult.error;
|
|
25473
25810
|
if (typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT") {
|
|
@@ -25509,6 +25846,12 @@ function configureNode() {
|
|
|
25509
25846
|
isomorph_default.gunzip = _nodeutil.promisify.call(void 0, zlib.gunzip);
|
|
25510
25847
|
isomorph_default.hash = (data) => crypto.createHash("sha256").update(data).digest("hex");
|
|
25511
25848
|
_internalSetInitialState();
|
|
25849
|
+
const disabled = readDisabledInstrumentationEnvConfig(
|
|
25850
|
+
isomorph_default.getEnv("BRAINTRUST_DISABLE_INSTRUMENTATION")
|
|
25851
|
+
).integrations;
|
|
25852
|
+
if (!isInstrumentationIntegrationDisabled(disabled, "mastra")) {
|
|
25853
|
+
installMastraExporterFactory(() => new BraintrustObservabilityExporter());
|
|
25854
|
+
}
|
|
25512
25855
|
registry.enable();
|
|
25513
25856
|
}
|
|
25514
25857
|
|
|
@@ -26691,11 +27034,11 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
|
|
|
26691
27034
|
return this._state;
|
|
26692
27035
|
}
|
|
26693
27036
|
};
|
|
26694
|
-
var CachedSpanFetcher = (
|
|
26695
|
-
|
|
26696
|
-
|
|
27037
|
+
var CachedSpanFetcher = (_class28 = class {
|
|
27038
|
+
__init109() {this.spanCache = /* @__PURE__ */ new Map()}
|
|
27039
|
+
__init110() {this.allFetched = false}
|
|
26697
27040
|
|
|
26698
|
-
constructor(objectTypeOrFetchFn, objectId, rootSpanId, getState) {;
|
|
27041
|
+
constructor(objectTypeOrFetchFn, objectId, rootSpanId, getState) {;_class28.prototype.__init109.call(this);_class28.prototype.__init110.call(this);
|
|
26699
27042
|
if (typeof objectTypeOrFetchFn === "function") {
|
|
26700
27043
|
this.fetchFn = (spanType) => objectTypeOrFetchFn(spanType);
|
|
26701
27044
|
} else {
|
|
@@ -26758,7 +27101,7 @@ var CachedSpanFetcher = (_class27 = class {
|
|
|
26758
27101
|
async fetchSpans(spanType) {
|
|
26759
27102
|
const spans = await this.fetchFn(spanType, false);
|
|
26760
27103
|
for (const span of spans) {
|
|
26761
|
-
const type = _nullishCoalesce(_optionalChain([span, 'access',
|
|
27104
|
+
const type = _nullishCoalesce(_optionalChain([span, 'access', _665 => _665.span_attributes, 'optionalAccess', _666 => _666.type]), () => ( ""));
|
|
26762
27105
|
const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
|
|
26763
27106
|
existing.push(span);
|
|
26764
27107
|
this.spanCache.set(type, existing);
|
|
@@ -26775,24 +27118,24 @@ var CachedSpanFetcher = (_class27 = class {
|
|
|
26775
27118
|
}
|
|
26776
27119
|
return result;
|
|
26777
27120
|
}
|
|
26778
|
-
},
|
|
26779
|
-
var LocalTrace = (
|
|
27121
|
+
}, _class28);
|
|
27122
|
+
var LocalTrace = (_class29 = class {
|
|
26780
27123
|
|
|
26781
27124
|
|
|
26782
27125
|
|
|
26783
27126
|
|
|
26784
27127
|
|
|
26785
|
-
|
|
26786
|
-
|
|
27128
|
+
__init111() {this.spansFlushed = false}
|
|
27129
|
+
__init112() {this.spansFlushPromise = null}
|
|
26787
27130
|
|
|
26788
|
-
|
|
27131
|
+
__init113() {this.threadCache = /* @__PURE__ */ new Map()}
|
|
26789
27132
|
constructor({
|
|
26790
27133
|
objectType,
|
|
26791
27134
|
objectId,
|
|
26792
27135
|
rootSpanId,
|
|
26793
27136
|
ensureSpansFlushed,
|
|
26794
27137
|
state
|
|
26795
|
-
}) {;
|
|
27138
|
+
}) {;_class29.prototype.__init111.call(this);_class29.prototype.__init112.call(this);_class29.prototype.__init113.call(this);
|
|
26796
27139
|
this.objectType = objectType;
|
|
26797
27140
|
this.objectId = objectId;
|
|
26798
27141
|
this.rootSpanId = rootSpanId;
|
|
@@ -26841,11 +27184,11 @@ var LocalTrace = (_class28 = class {
|
|
|
26841
27184
|
const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
|
|
26842
27185
|
if (cachedSpans && cachedSpans.length > 0) {
|
|
26843
27186
|
let spans = includeScorers ? cachedSpans : cachedSpans.filter(
|
|
26844
|
-
(span) => _optionalChain([span, 'access',
|
|
27187
|
+
(span) => _optionalChain([span, 'access', _667 => _667.span_attributes, 'optionalAccess', _668 => _668.purpose]) !== "scorer"
|
|
26845
27188
|
);
|
|
26846
27189
|
if (spanType && spanType.length > 0) {
|
|
26847
27190
|
spans = spans.filter(
|
|
26848
|
-
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access',
|
|
27191
|
+
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _669 => _669.span_attributes, 'optionalAccess', _670 => _670.type]), () => ( "")))
|
|
26849
27192
|
);
|
|
26850
27193
|
}
|
|
26851
27194
|
return spans.map((span) => ({
|
|
@@ -26870,7 +27213,7 @@ var LocalTrace = (_class28 = class {
|
|
|
26870
27213
|
* Calls the API with the project_default preprocessor (which falls back to "thread").
|
|
26871
27214
|
*/
|
|
26872
27215
|
async getThread(options) {
|
|
26873
|
-
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
27216
|
+
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _671 => _671.preprocessor]), () => ( "project_default"));
|
|
26874
27217
|
if (!this.threadCache.has(cacheKey)) {
|
|
26875
27218
|
const promise = this.fetchThread(options);
|
|
26876
27219
|
this.threadCache.set(cacheKey, promise);
|
|
@@ -26881,7 +27224,7 @@ var LocalTrace = (_class28 = class {
|
|
|
26881
27224
|
await this.ensureSpansReady();
|
|
26882
27225
|
await this.state.login({});
|
|
26883
27226
|
const result = await invoke({
|
|
26884
|
-
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
27227
|
+
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _672 => _672.preprocessor]), () => ( "project_default")),
|
|
26885
27228
|
functionType: "preprocessor",
|
|
26886
27229
|
input: {
|
|
26887
27230
|
trace_ref: {
|
|
@@ -26912,7 +27255,7 @@ var LocalTrace = (_class28 = class {
|
|
|
26912
27255
|
}
|
|
26913
27256
|
await this.spansFlushPromise;
|
|
26914
27257
|
}
|
|
26915
|
-
},
|
|
27258
|
+
}, _class29);
|
|
26916
27259
|
|
|
26917
27260
|
// src/reporters/progress.ts
|
|
26918
27261
|
var SimpleProgressReporter = class {
|
|
@@ -27057,10 +27400,10 @@ function validateParametersWithJsonSchema(parameters, schema) {
|
|
|
27057
27400
|
const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
|
|
27058
27401
|
const validate = ajv.compile(schema);
|
|
27059
27402
|
if (!validate(parameters)) {
|
|
27060
|
-
const errorMessages = _optionalChain([validate, 'access',
|
|
27403
|
+
const errorMessages = _optionalChain([validate, 'access', _673 => _673.errors, 'optionalAccess', _674 => _674.map, 'call', _675 => _675((err) => {
|
|
27061
27404
|
const path2 = err.instancePath || "root";
|
|
27062
27405
|
return `${path2}: ${err.message}`;
|
|
27063
|
-
}), 'access',
|
|
27406
|
+
}), 'access', _676 => _676.join, 'call', _677 => _677(", ")]);
|
|
27064
27407
|
throw Error(`Invalid parameters: ${errorMessages}`);
|
|
27065
27408
|
}
|
|
27066
27409
|
return rehydrateRemoteParameters(parameters, schema);
|
|
@@ -27400,7 +27743,7 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters, st
|
|
|
27400
27743
|
}
|
|
27401
27744
|
async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
|
|
27402
27745
|
if (enableCache) {
|
|
27403
|
-
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
27746
|
+
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _678 => _678.spanCache, 'optionalAccess', _679 => _679.start, 'call', _680 => _680()]);
|
|
27404
27747
|
}
|
|
27405
27748
|
try {
|
|
27406
27749
|
if (typeof evaluator.data === "string") {
|
|
@@ -27511,7 +27854,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
27511
27854
|
objectType: parentComponents ? spanObjectTypeV3ToTypedString(
|
|
27512
27855
|
parentComponents.data.object_type
|
|
27513
27856
|
) : "experiment",
|
|
27514
|
-
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async
|
|
27857
|
+
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _681 => _681.data, 'access', async _682 => _682.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
|
|
27515
27858
|
rootSpanId: rootSpan.rootSpanId,
|
|
27516
27859
|
ensureSpansFlushed,
|
|
27517
27860
|
state
|
|
@@ -27541,10 +27884,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
27541
27884
|
span,
|
|
27542
27885
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
27543
27886
|
reportProgress: (event) => {
|
|
27544
|
-
_optionalChain([stream, 'optionalCall',
|
|
27887
|
+
_optionalChain([stream, 'optionalCall', _683 => _683({
|
|
27545
27888
|
...event,
|
|
27546
27889
|
id: rootSpan.id,
|
|
27547
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
27890
|
+
origin: _optionalChain([baseEvent, 'access', _684 => _684.event, 'optionalAccess', _685 => _685.origin]),
|
|
27548
27891
|
name: evaluator.evalName,
|
|
27549
27892
|
object_type: "task"
|
|
27550
27893
|
})]);
|
|
@@ -27732,7 +28075,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
27732
28075
|
tags: tags.length ? tags : void 0,
|
|
27733
28076
|
metadata,
|
|
27734
28077
|
error,
|
|
27735
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
28078
|
+
origin: _optionalChain([baseEvent, 'access', _686 => _686.event, 'optionalAccess', _687 => _687.origin])
|
|
27736
28079
|
};
|
|
27737
28080
|
collectedResults.push({
|
|
27738
28081
|
...baseResult,
|
|
@@ -27772,7 +28115,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
27772
28115
|
break;
|
|
27773
28116
|
}
|
|
27774
28117
|
scheduledTrials++;
|
|
27775
|
-
_optionalChain([progressReporter, 'access',
|
|
28118
|
+
_optionalChain([progressReporter, 'access', _688 => _688.setTotal, 'optionalCall', _689 => _689(evaluator.evalName, scheduledTrials)]);
|
|
27776
28119
|
q.pushAsync({ datum, trialIndex }).catch((e) => {
|
|
27777
28120
|
if (queueErrors.length < 5) {
|
|
27778
28121
|
queueErrors.push(e);
|
|
@@ -27857,9 +28200,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
27857
28200
|
);
|
|
27858
28201
|
} finally {
|
|
27859
28202
|
if (enableCache) {
|
|
27860
|
-
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
27861
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
27862
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
28203
|
+
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _690 => _690.spanCache]);
|
|
28204
|
+
_optionalChain([spanCache, 'optionalAccess', _691 => _691.dispose, 'call', _692 => _692()]);
|
|
28205
|
+
_optionalChain([spanCache, 'optionalAccess', _693 => _693.stop, 'call', _694 => _694()]);
|
|
27863
28206
|
}
|
|
27864
28207
|
}
|
|
27865
28208
|
}
|
|
@@ -28099,7 +28442,7 @@ async function cachedLogin(options) {
|
|
|
28099
28442
|
}
|
|
28100
28443
|
function makeCheckAuthorized(allowedOrgName) {
|
|
28101
28444
|
return async (req, _res, next) => {
|
|
28102
|
-
if (!_optionalChain([req, 'access',
|
|
28445
|
+
if (!_optionalChain([req, 'access', _695 => _695.ctx, 'optionalAccess', _696 => _696.token])) {
|
|
28103
28446
|
return next(_httperrors2.default.call(void 0, 401, "Unauthorized"));
|
|
28104
28447
|
}
|
|
28105
28448
|
try {
|
|
@@ -28112,7 +28455,7 @@ function makeCheckAuthorized(allowedOrgName) {
|
|
|
28112
28455
|
return next(_httperrors2.default.call(void 0, 403, errorMessage2));
|
|
28113
28456
|
}
|
|
28114
28457
|
const state = await cachedLogin({
|
|
28115
|
-
apiKey: _optionalChain([req, 'access',
|
|
28458
|
+
apiKey: _optionalChain([req, 'access', _697 => _697.ctx, 'optionalAccess', _698 => _698.token]),
|
|
28116
28459
|
orgName
|
|
28117
28460
|
});
|
|
28118
28461
|
req.ctx.state = state;
|
|
@@ -28304,17 +28647,17 @@ var ProjectBuilder = class {
|
|
|
28304
28647
|
}
|
|
28305
28648
|
};
|
|
28306
28649
|
var projects = new ProjectBuilder();
|
|
28307
|
-
var Project2 = (
|
|
28650
|
+
var Project2 = (_class30 = class {
|
|
28308
28651
|
|
|
28309
28652
|
|
|
28310
28653
|
|
|
28311
28654
|
|
|
28312
28655
|
|
|
28313
28656
|
|
|
28314
|
-
|
|
28315
|
-
|
|
28316
|
-
|
|
28317
|
-
constructor(args) {;
|
|
28657
|
+
__init114() {this._publishableCodeFunctions = []}
|
|
28658
|
+
__init115() {this._publishablePrompts = []}
|
|
28659
|
+
__init116() {this._publishableParameters = []}
|
|
28660
|
+
constructor(args) {;_class30.prototype.__init114.call(this);_class30.prototype.__init115.call(this);_class30.prototype.__init116.call(this);
|
|
28318
28661
|
_initializeSpanContext();
|
|
28319
28662
|
this.name = "name" in args ? args.name : void 0;
|
|
28320
28663
|
this.id = "id" in args ? args.id : void 0;
|
|
@@ -28366,12 +28709,12 @@ var Project2 = (_class29 = class {
|
|
|
28366
28709
|
functions: functionDefinitions
|
|
28367
28710
|
});
|
|
28368
28711
|
}
|
|
28369
|
-
},
|
|
28370
|
-
var ToolBuilder = (
|
|
28371
|
-
constructor(project) {;
|
|
28712
|
+
}, _class30);
|
|
28713
|
+
var ToolBuilder = (_class31 = class {
|
|
28714
|
+
constructor(project) {;_class31.prototype.__init117.call(this);
|
|
28372
28715
|
this.project = project;
|
|
28373
28716
|
}
|
|
28374
|
-
|
|
28717
|
+
__init117() {this.taskCounter = 0}
|
|
28375
28718
|
// This type definition is just a catch all so that the implementation can be
|
|
28376
28719
|
// less specific than the two more specific declarations above.
|
|
28377
28720
|
create(opts) {
|
|
@@ -28396,12 +28739,12 @@ var ToolBuilder = (_class30 = class {
|
|
|
28396
28739
|
this.project.addCodeFunction(tool);
|
|
28397
28740
|
return tool;
|
|
28398
28741
|
}
|
|
28399
|
-
},
|
|
28400
|
-
var ScorerBuilder = (
|
|
28401
|
-
constructor(project) {;
|
|
28742
|
+
}, _class31);
|
|
28743
|
+
var ScorerBuilder = (_class32 = class {
|
|
28744
|
+
constructor(project) {;_class32.prototype.__init118.call(this);
|
|
28402
28745
|
this.project = project;
|
|
28403
28746
|
}
|
|
28404
|
-
|
|
28747
|
+
__init118() {this.taskCounter = 0}
|
|
28405
28748
|
create(opts) {
|
|
28406
28749
|
this.taskCounter++;
|
|
28407
28750
|
let resolvedName = opts.name;
|
|
@@ -28455,7 +28798,7 @@ var ScorerBuilder = (_class31 = class {
|
|
|
28455
28798
|
this.project.addPrompt(codePrompt);
|
|
28456
28799
|
}
|
|
28457
28800
|
}
|
|
28458
|
-
},
|
|
28801
|
+
}, _class32);
|
|
28459
28802
|
var CodeFunction = class {
|
|
28460
28803
|
constructor(project, opts) {
|
|
28461
28804
|
this.project = project;
|
|
@@ -28757,9 +29100,9 @@ function serializeRemoteEvalParametersContainer(parameters) {
|
|
|
28757
29100
|
source: null
|
|
28758
29101
|
};
|
|
28759
29102
|
}
|
|
28760
|
-
var ProjectNameIdMap = (
|
|
28761
|
-
|
|
28762
|
-
|
|
29103
|
+
var ProjectNameIdMap = (_class33 = class {constructor() { _class33.prototype.__init119.call(this);_class33.prototype.__init120.call(this); }
|
|
29104
|
+
__init119() {this.nameToId = {}}
|
|
29105
|
+
__init120() {this.idToName = {}}
|
|
28763
29106
|
async getId(projectName) {
|
|
28764
29107
|
if (!(projectName in this.nameToId)) {
|
|
28765
29108
|
const response = await _internalGetGlobalState().appConn().post_json("api/project/register", {
|
|
@@ -28792,7 +29135,7 @@ var ProjectNameIdMap = (_class32 = class {constructor() { _class32.prototype.__i
|
|
|
28792
29135
|
}
|
|
28793
29136
|
return this.getId(project.name);
|
|
28794
29137
|
}
|
|
28795
|
-
},
|
|
29138
|
+
}, _class33);
|
|
28796
29139
|
|
|
28797
29140
|
// dev/server.ts
|
|
28798
29141
|
function runDevServer(evaluators, opts) {
|
|
@@ -28867,7 +29210,7 @@ function runDevServer(evaluators, opts) {
|
|
|
28867
29210
|
scores,
|
|
28868
29211
|
stream
|
|
28869
29212
|
} = evalBodySchema.parse(req.body);
|
|
28870
|
-
if (!_optionalChain([req, 'access',
|
|
29213
|
+
if (!_optionalChain([req, 'access', _699 => _699.ctx, 'optionalAccess', _700 => _700.state])) {
|
|
28871
29214
|
res.status(500).json({ error: "Braintrust state not initialized in request" });
|
|
28872
29215
|
return;
|
|
28873
29216
|
}
|
|
@@ -28918,12 +29261,12 @@ function runDevServer(evaluators, opts) {
|
|
|
28918
29261
|
...evaluator,
|
|
28919
29262
|
data: evalData.data,
|
|
28920
29263
|
scores: (_nullishCoalesce(evaluator.scores, () => ( []))).concat(
|
|
28921
|
-
_nullishCoalesce(_optionalChain([scores, 'optionalAccess',
|
|
29264
|
+
_nullishCoalesce(_optionalChain([scores, 'optionalAccess', _701 => _701.map, 'call', _702 => _702(
|
|
28922
29265
|
(score) => makeScorer(
|
|
28923
29266
|
state,
|
|
28924
29267
|
score.name,
|
|
28925
29268
|
score.function_id,
|
|
28926
|
-
_optionalChain([req, 'access',
|
|
29269
|
+
_optionalChain([req, 'access', _703 => _703.ctx, 'optionalAccess', _704 => _704.projectId])
|
|
28927
29270
|
)
|
|
28928
29271
|
)]), () => ( []))
|
|
28929
29272
|
),
|