braintrust 3.23.1 → 3.24.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 -0
- package/dev/dist/index.d.ts +6 -0
- package/dev/dist/index.js +902 -586
- package/dev/dist/index.mjs +320 -4
- package/dist/apply-auto-instrumentation.js +211 -189
- package/dist/apply-auto-instrumentation.mjs +23 -1
- package/dist/auto-instrumentations/bundler/esbuild.cjs +40 -0
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +40 -0
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +40 -0
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +40 -0
- package/dist/auto-instrumentations/bundler/vite.d.mts +1 -1
- package/dist/auto-instrumentations/bundler/vite.d.ts +1 -1
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +40 -0
- package/dist/auto-instrumentations/bundler/webpack.cjs +40 -0
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-KIMLYPRW.mjs → chunk-BURMPO7L.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-YXLNSAMJ.mjs → chunk-F43DNLPD.mjs} +40 -0
- package/dist/auto-instrumentations/{chunk-EXY7QCJD.mjs → chunk-GSZHTAQW.mjs} +1 -1
- package/dist/auto-instrumentations/hook.mjs +150 -1
- package/dist/auto-instrumentations/index.cjs +40 -0
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/browser.d.mts +131 -9
- package/dist/browser.d.ts +131 -9
- package/dist/browser.js +703 -65
- package/dist/browser.mjs +703 -65
- package/dist/{chunk-CDIKAHDZ.js → chunk-7AUY2XWX.js} +21 -1
- package/dist/{chunk-36IPYKMG.mjs → chunk-7F6GCRHH.mjs} +20 -0
- package/dist/{chunk-B6ZQIAK3.js → chunk-SU6EHKJV.js} +1085 -799
- package/dist/{chunk-RBXD2KYN.mjs → chunk-XE5FS7QY.mjs} +291 -5
- package/dist/cli.js +328 -8
- package/dist/edge-light.js +703 -65
- package/dist/edge-light.mjs +703 -65
- package/dist/index.d.mts +131 -9
- package/dist/index.d.ts +131 -9
- package/dist/index.js +891 -532
- package/dist/index.mjs +423 -64
- package/dist/instrumentation/index.d.mts +130 -9
- package/dist/instrumentation/index.d.ts +130 -9
- package/dist/instrumentation/index.js +601 -65
- package/dist/instrumentation/index.mjs +601 -65
- package/dist/vitest-evals-reporter.js +17 -16
- package/dist/vitest-evals-reporter.mjs +3 -2
- package/dist/workerd.js +703 -65
- package/dist/workerd.mjs +703 -65
- package/package.json +3 -3
- package/util/dist/index.js +4 -0
- package/util/dist/index.mjs +4 -0
package/dev/dist/index.js
CHANGED
|
@@ -115,6 +115,7 @@ var DefaultChannel = (_class = class {
|
|
|
115
115
|
constructor(name) {;_class.prototype.__init.call(this);
|
|
116
116
|
this.name = name;
|
|
117
117
|
}
|
|
118
|
+
|
|
118
119
|
__init() {this.hasSubscribers = false}
|
|
119
120
|
subscribe(_subscription) {
|
|
120
121
|
}
|
|
@@ -1381,6 +1382,7 @@ var SpanComponentsV3 = class _SpanComponentsV3 {
|
|
|
1381
1382
|
constructor(data) {
|
|
1382
1383
|
this.data = data;
|
|
1383
1384
|
}
|
|
1385
|
+
|
|
1384
1386
|
toStr() {
|
|
1385
1387
|
const jsonObj = {
|
|
1386
1388
|
compute_object_metadata_args: this.data.compute_object_metadata_args || void 0,
|
|
@@ -1892,6 +1894,7 @@ var SpanComponentsV4 = class _SpanComponentsV4 {
|
|
|
1892
1894
|
constructor(data) {
|
|
1893
1895
|
this.data = data;
|
|
1894
1896
|
}
|
|
1897
|
+
|
|
1895
1898
|
toStr() {
|
|
1896
1899
|
const jsonObj = {
|
|
1897
1900
|
compute_object_metadata_args: this.data.compute_object_metadata_args || void 0,
|
|
@@ -5138,6 +5141,97 @@ var SpanCache = (_class6 = class {
|
|
|
5138
5141
|
}
|
|
5139
5142
|
}, _class6);
|
|
5140
5143
|
|
|
5144
|
+
// src/span-origin.ts
|
|
5145
|
+
var SDK_VERSION = true ? "3.24.0" : "0.0.0";
|
|
5146
|
+
function detectSpanOriginEnvironment(explicit) {
|
|
5147
|
+
if (explicit) return explicit;
|
|
5148
|
+
const envType = isomorph_default.getEnv("BRAINTRUST_ENVIRONMENT_TYPE");
|
|
5149
|
+
const envName = isomorph_default.getEnv("BRAINTRUST_ENVIRONMENT_NAME");
|
|
5150
|
+
if (envType || envName) {
|
|
5151
|
+
return {
|
|
5152
|
+
...envType ? { type: envType } : {},
|
|
5153
|
+
...envName ? { name: envName } : {}
|
|
5154
|
+
};
|
|
5155
|
+
}
|
|
5156
|
+
const ci = firstPresent([
|
|
5157
|
+
["GITHUB_ACTIONS", "github_actions"],
|
|
5158
|
+
["GITLAB_CI", "gitlab_ci"],
|
|
5159
|
+
["CIRCLECI", "circleci"],
|
|
5160
|
+
["BUILDKITE", "buildkite"],
|
|
5161
|
+
["JENKINS_URL", "jenkins"],
|
|
5162
|
+
["JENKINS_HOME", "jenkins"],
|
|
5163
|
+
["TF_BUILD", "azure_pipelines"],
|
|
5164
|
+
["TEAMCITY_VERSION", "teamcity"],
|
|
5165
|
+
["TRAVIS", "travis"],
|
|
5166
|
+
["BITBUCKET_BUILD_NUMBER", "bitbucket"]
|
|
5167
|
+
]);
|
|
5168
|
+
if (ci) return { type: "ci", name: ci };
|
|
5169
|
+
if (isomorph_default.getEnv("CI")) return { type: "ci", name: "ci" };
|
|
5170
|
+
const earlyServer = firstPresent([
|
|
5171
|
+
["VERCEL", "vercel"],
|
|
5172
|
+
["NETLIFY", "netlify"]
|
|
5173
|
+
]);
|
|
5174
|
+
if (earlyServer) return { type: "server", name: earlyServer };
|
|
5175
|
+
if (isomorph_default.getEnv("ECS_CONTAINER_METADATA_URI") || isomorph_default.getEnv("ECS_CONTAINER_METADATA_URI_V4")) {
|
|
5176
|
+
return { type: "server", name: "ecs" };
|
|
5177
|
+
}
|
|
5178
|
+
const awsExecutionEnv = isomorph_default.getEnv("AWS_EXECUTION_ENV");
|
|
5179
|
+
if (_optionalChain([awsExecutionEnv, 'optionalAccess', _80 => _80.startsWith, 'call', _81 => _81("AWS_ECS_")])) {
|
|
5180
|
+
return { type: "server", name: "ecs" };
|
|
5181
|
+
}
|
|
5182
|
+
if (_optionalChain([awsExecutionEnv, 'optionalAccess', _82 => _82.startsWith, 'call', _83 => _83("AWS_Lambda_")])) {
|
|
5183
|
+
return { type: "server", name: "aws_lambda" };
|
|
5184
|
+
}
|
|
5185
|
+
if (isomorph_default.getEnv("AWS_LAMBDA_FUNCTION_NAME")) {
|
|
5186
|
+
return { type: "server", name: "aws_lambda" };
|
|
5187
|
+
}
|
|
5188
|
+
const server = firstPresent([
|
|
5189
|
+
["K_SERVICE", "cloud_run"],
|
|
5190
|
+
["FUNCTION_TARGET", "gcp_functions"],
|
|
5191
|
+
["KUBERNETES_SERVICE_HOST", "kubernetes"],
|
|
5192
|
+
["DYNO", "heroku"],
|
|
5193
|
+
["FLY_APP_NAME", "fly"],
|
|
5194
|
+
["RAILWAY_ENVIRONMENT", "railway"],
|
|
5195
|
+
["RENDER_SERVICE_NAME", "render"]
|
|
5196
|
+
]);
|
|
5197
|
+
if (server) return { type: "server", name: server };
|
|
5198
|
+
return deploymentModeEnvironment("NODE_ENV", isomorph_default.getEnv("NODE_ENV"));
|
|
5199
|
+
}
|
|
5200
|
+
function makeSpanOrigin(instrumentationName, environment) {
|
|
5201
|
+
return {
|
|
5202
|
+
name: "braintrust.sdk.javascript",
|
|
5203
|
+
version: SDK_VERSION,
|
|
5204
|
+
instrumentation: { name: instrumentationName },
|
|
5205
|
+
...environment ? { environment } : {}
|
|
5206
|
+
};
|
|
5207
|
+
}
|
|
5208
|
+
function mergeSpanOriginContext(context, instrumentationName, environment) {
|
|
5209
|
+
const next = { ..._nullishCoalesce(context, () => ( {})) };
|
|
5210
|
+
const current = isObject2(next.span_origin) ? { ...next.span_origin } : {};
|
|
5211
|
+
next.span_origin = {
|
|
5212
|
+
...makeSpanOrigin(instrumentationName, environment),
|
|
5213
|
+
...current
|
|
5214
|
+
};
|
|
5215
|
+
return next;
|
|
5216
|
+
}
|
|
5217
|
+
function firstPresent(entries) {
|
|
5218
|
+
return _optionalChain([entries, 'access', _84 => _84.find, 'call', _85 => _85(([key]) => Boolean(isomorph_default.getEnv(key))), 'optionalAccess', _86 => _86[1]]);
|
|
5219
|
+
}
|
|
5220
|
+
function deploymentModeEnvironment(_key, value) {
|
|
5221
|
+
if (!value) return void 0;
|
|
5222
|
+
const normalized = value.toLowerCase();
|
|
5223
|
+
if (normalized === "production" || normalized === "staging") {
|
|
5224
|
+
return { type: "server", name: normalized };
|
|
5225
|
+
}
|
|
5226
|
+
if (normalized === "development" || normalized === "local") {
|
|
5227
|
+
return { type: "local", name: normalized };
|
|
5228
|
+
}
|
|
5229
|
+
return { name: value };
|
|
5230
|
+
}
|
|
5231
|
+
function isObject2(value) {
|
|
5232
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5141
5235
|
// src/logger.ts
|
|
5142
5236
|
var BRAINTRUST_ATTACHMENT = BraintrustAttachmentReference.shape.type.value;
|
|
5143
5237
|
var EXTERNAL_ATTACHMENT = ExternalAttachmentReference.shape.type.value;
|
|
@@ -5186,6 +5280,7 @@ var LoginInvalidOrgError = class extends Error {
|
|
|
5186
5280
|
super(message);
|
|
5187
5281
|
this.message = message;
|
|
5188
5282
|
}
|
|
5283
|
+
|
|
5189
5284
|
};
|
|
5190
5285
|
var REDACTION_FIELDS = [
|
|
5191
5286
|
"input",
|
|
@@ -5201,6 +5296,8 @@ var MaskingError = class {
|
|
|
5201
5296
|
this.fieldName = fieldName;
|
|
5202
5297
|
this.errorType = errorType;
|
|
5203
5298
|
}
|
|
5299
|
+
|
|
5300
|
+
|
|
5204
5301
|
get errorMsg() {
|
|
5205
5302
|
return `ERROR: Failed to mask field '${this.fieldName}' - ${this.errorType}`;
|
|
5206
5303
|
}
|
|
@@ -5298,7 +5395,7 @@ var NoopSpan = (_class7 = class {
|
|
|
5298
5395
|
return this;
|
|
5299
5396
|
}
|
|
5300
5397
|
end(args) {
|
|
5301
|
-
return _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
5398
|
+
return _nullishCoalesce(_optionalChain([args, 'optionalAccess', _87 => _87.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
5302
5399
|
}
|
|
5303
5400
|
async export() {
|
|
5304
5401
|
return "";
|
|
@@ -5410,9 +5507,11 @@ var BraintrustState = (_class8 = class _BraintrustState {
|
|
|
5410
5507
|
diskCache: parametersDiskCache
|
|
5411
5508
|
});
|
|
5412
5509
|
this.spanCache = new SpanCache({ disabled: loginParams.disableSpanCache });
|
|
5510
|
+
this.spanOriginEnvironment = detectSpanOriginEnvironment();
|
|
5413
5511
|
}
|
|
5414
5512
|
|
|
5415
5513
|
|
|
5514
|
+
|
|
5416
5515
|
// Note: the value of IsAsyncFlush doesn't really matter here, since we
|
|
5417
5516
|
// (safely) dynamically cast it whenever retrieving the logger.
|
|
5418
5517
|
|
|
@@ -5445,6 +5544,7 @@ var BraintrustState = (_class8 = class _BraintrustState {
|
|
|
5445
5544
|
__init33() {this._idGenerator = null}
|
|
5446
5545
|
__init34() {this._contextManager = null}
|
|
5447
5546
|
__init35() {this._otelFlushCallback = null}
|
|
5547
|
+
|
|
5448
5548
|
resetLoginInfo() {
|
|
5449
5549
|
this.appUrl = null;
|
|
5450
5550
|
this.appPublicUrl = null;
|
|
@@ -5571,8 +5671,8 @@ var BraintrustState = (_class8 = class _BraintrustState {
|
|
|
5571
5671
|
setFetch(fetch2) {
|
|
5572
5672
|
this.loginParams.fetch = fetch2;
|
|
5573
5673
|
this.fetch = fetch2;
|
|
5574
|
-
_optionalChain([this, 'access',
|
|
5575
|
-
_optionalChain([this, 'access',
|
|
5674
|
+
_optionalChain([this, 'access', _88 => _88._apiConn, 'optionalAccess', _89 => _89.setFetch, 'call', _90 => _90(fetch2)]);
|
|
5675
|
+
_optionalChain([this, 'access', _91 => _91._appConn, 'optionalAccess', _92 => _92.setFetch, 'call', _93 => _93(fetch2)]);
|
|
5576
5676
|
}
|
|
5577
5677
|
setMaskingFunction(maskingFunction) {
|
|
5578
5678
|
this.bgLogger().setMaskingFunction(maskingFunction);
|
|
@@ -5816,7 +5916,7 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
5816
5916
|
})
|
|
5817
5917
|
);
|
|
5818
5918
|
} catch (error) {
|
|
5819
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
5919
|
+
if (_optionalChain([config, 'optionalAccess', _94 => _94.signal, 'optionalAccess', _95 => _95.aborted])) {
|
|
5820
5920
|
throw getAbortReason(config.signal);
|
|
5821
5921
|
}
|
|
5822
5922
|
if (i === tries - 1 || !isRetryableHTTPError(error)) {
|
|
@@ -5829,7 +5929,7 @@ var HTTPConnection = class _HTTPConnection {
|
|
|
5829
5929
|
debugLogger.info(
|
|
5830
5930
|
`Sleeping for ${sleepTimeMs}ms before retrying API request`
|
|
5831
5931
|
);
|
|
5832
|
-
await waitForRetry(sleepTimeMs, _optionalChain([config, 'optionalAccess',
|
|
5932
|
+
await waitForRetry(sleepTimeMs, _optionalChain([config, 'optionalAccess', _96 => _96.signal]));
|
|
5833
5933
|
}
|
|
5834
5934
|
}
|
|
5835
5935
|
throw new Error("Unexpected retry state");
|
|
@@ -5996,7 +6096,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
5996
6096
|
body: data
|
|
5997
6097
|
})
|
|
5998
6098
|
);
|
|
5999
|
-
await _optionalChain([objectStoreResponse, 'access',
|
|
6099
|
+
await _optionalChain([objectStoreResponse, 'access', _97 => _97.body, 'optionalAccess', _98 => _98.cancel, 'call', _99 => _99()]);
|
|
6000
6100
|
} catch (error) {
|
|
6001
6101
|
if (error instanceof FailedHTTPResponse) {
|
|
6002
6102
|
throw new Error(
|
|
@@ -6028,7 +6128,7 @@ var Attachment = class extends BaseAttachment {
|
|
|
6028
6128
|
"/attachment/status",
|
|
6029
6129
|
requestParams
|
|
6030
6130
|
);
|
|
6031
|
-
await _optionalChain([statusResponse, 'access',
|
|
6131
|
+
await _optionalChain([statusResponse, 'access', _100 => _100.body, 'optionalAccess', _101 => _101.cancel, 'call', _102 => _102()]);
|
|
6032
6132
|
if (!statusResponse.ok) {
|
|
6033
6133
|
const errorStr = JSON.stringify(statusResponse);
|
|
6034
6134
|
throw new Error(`Couldn't log attachment status: ${errorStr}`);
|
|
@@ -6307,8 +6407,8 @@ function _getOrgName(orgName) {
|
|
|
6307
6407
|
return orgName || isomorph_default.getEnv("BRAINTRUST_ORG_NAME") || void 0;
|
|
6308
6408
|
}
|
|
6309
6409
|
function _getLinkBaseUrl(state, linkArgs) {
|
|
6310
|
-
const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess',
|
|
6311
|
-
const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess',
|
|
6410
|
+
const appUrl = _getAppUrl(state.appUrl || _optionalChain([linkArgs, 'optionalAccess', _103 => _103.app_url]));
|
|
6411
|
+
const orgName = _getOrgName(state.orgName || _optionalChain([linkArgs, 'optionalAccess', _104 => _104.org_name]));
|
|
6312
6412
|
if (!orgName) {
|
|
6313
6413
|
return null;
|
|
6314
6414
|
}
|
|
@@ -6318,9 +6418,9 @@ async function permalink(slug, opts) {
|
|
|
6318
6418
|
if (slug === "") {
|
|
6319
6419
|
return NOOP_SPAN_PERMALINK;
|
|
6320
6420
|
}
|
|
6321
|
-
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
6421
|
+
const state = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _105 => _105.state]), () => ( _globalState));
|
|
6322
6422
|
const getOrgName = async () => {
|
|
6323
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
6423
|
+
if (_optionalChain([opts, 'optionalAccess', _106 => _106.orgName])) {
|
|
6324
6424
|
return opts.orgName;
|
|
6325
6425
|
}
|
|
6326
6426
|
await state.login({});
|
|
@@ -6330,7 +6430,7 @@ async function permalink(slug, opts) {
|
|
|
6330
6430
|
return state.orgName;
|
|
6331
6431
|
};
|
|
6332
6432
|
const getAppUrl = async () => {
|
|
6333
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
6433
|
+
if (_optionalChain([opts, 'optionalAccess', _107 => _107.appUrl])) {
|
|
6334
6434
|
return opts.appUrl;
|
|
6335
6435
|
}
|
|
6336
6436
|
await state.login({});
|
|
@@ -6464,7 +6564,7 @@ var Logger = (_class9 = class {
|
|
|
6464
6564
|
* @returns The `id` of the logged event.
|
|
6465
6565
|
*/
|
|
6466
6566
|
log(event, options) {
|
|
6467
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
6567
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _108 => _108.allowConcurrentWithSpans])) {
|
|
6468
6568
|
throw new Error(
|
|
6469
6569
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `logger.traced` and then log with `span.log`"
|
|
6470
6570
|
);
|
|
@@ -6532,12 +6632,12 @@ var Logger = (_class9 = class {
|
|
|
6532
6632
|
state: this.state,
|
|
6533
6633
|
...startSpanParentArgs({
|
|
6534
6634
|
state: this.state,
|
|
6535
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
6635
|
+
parent: _optionalChain([args, 'optionalAccess', _109 => _109.parent]),
|
|
6536
6636
|
parentObjectType: this.parentObjectType(),
|
|
6537
6637
|
parentObjectId: this.lazyId,
|
|
6538
6638
|
parentComputeObjectMetadataArgs: this.computeMetadataArgs,
|
|
6539
|
-
parentSpanIds: _optionalChain([args, 'optionalAccess',
|
|
6540
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
6639
|
+
parentSpanIds: _optionalChain([args, 'optionalAccess', _110 => _110.parentSpanIds]),
|
|
6640
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _111 => _111.propagatedEvent])
|
|
6541
6641
|
}),
|
|
6542
6642
|
defaultRootType: "task" /* TASK */
|
|
6543
6643
|
});
|
|
@@ -6611,11 +6711,11 @@ var Logger = (_class9 = class {
|
|
|
6611
6711
|
* undefined when it cannot be determined synchronously.
|
|
6612
6712
|
*/
|
|
6613
6713
|
_getOtelParent() {
|
|
6614
|
-
const id = _optionalChain([this, 'access',
|
|
6714
|
+
const id = _optionalChain([this, 'access', _112 => _112.computeMetadataArgs, 'optionalAccess', _113 => _113.project_id]) || this.lazyId.getSync().value;
|
|
6615
6715
|
if (id) {
|
|
6616
6716
|
return `project_id:${id}`;
|
|
6617
6717
|
}
|
|
6618
|
-
const name = _optionalChain([this, 'access',
|
|
6718
|
+
const name = _optionalChain([this, 'access', _114 => _114.computeMetadataArgs, 'optionalAccess', _115 => _115.project_name]);
|
|
6619
6719
|
if (name) {
|
|
6620
6720
|
return `project_name:${name}`;
|
|
6621
6721
|
}
|
|
@@ -6928,7 +7028,7 @@ var HTTPBackgroundLogger = (_class10 = class _HTTPBackgroundLogger {
|
|
|
6928
7028
|
this.queue.clear();
|
|
6929
7029
|
return;
|
|
6930
7030
|
}
|
|
6931
|
-
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
7031
|
+
const batchSize = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _116 => _116.batchSize]), () => ( this.defaultBatchSize));
|
|
6932
7032
|
const wrappedItems = this.queue.drain();
|
|
6933
7033
|
if (wrappedItems.length === 0) {
|
|
6934
7034
|
return;
|
|
@@ -7242,10 +7342,10 @@ Error: ${errorText}`;
|
|
|
7242
7342
|
} catch (err) {
|
|
7243
7343
|
if (err instanceof AggregateError) {
|
|
7244
7344
|
for (const e of err.errors) {
|
|
7245
|
-
_optionalChain([this, 'access',
|
|
7345
|
+
_optionalChain([this, 'access', _117 => _117.onFlushError, 'optionalCall', _118 => _118(e)]);
|
|
7246
7346
|
}
|
|
7247
7347
|
} else {
|
|
7248
|
-
_optionalChain([this, 'access',
|
|
7348
|
+
_optionalChain([this, 'access', _119 => _119.onFlushError, 'optionalCall', _120 => _120(err)]);
|
|
7249
7349
|
}
|
|
7250
7350
|
this.activeFlushError = err;
|
|
7251
7351
|
} finally {
|
|
@@ -7295,7 +7395,7 @@ function getExperimentDatasetFilter({
|
|
|
7295
7395
|
return isObject(datasetFilter) ? datasetFilter : void 0;
|
|
7296
7396
|
}
|
|
7297
7397
|
function getInternalBtqlLimit(internalBtql) {
|
|
7298
|
-
const limit = _optionalChain([internalBtql, 'optionalAccess',
|
|
7398
|
+
const limit = _optionalChain([internalBtql, 'optionalAccess', _121 => _121["limit"]]);
|
|
7299
7399
|
return typeof limit === "number" ? limit : void 0;
|
|
7300
7400
|
}
|
|
7301
7401
|
function init(projectOrOptions, optionalOptions) {
|
|
@@ -7798,6 +7898,7 @@ function initLogger(options = {}) {
|
|
|
7798
7898
|
orgName,
|
|
7799
7899
|
forceLogin,
|
|
7800
7900
|
debugLogLevel,
|
|
7901
|
+
environment,
|
|
7801
7902
|
fetch: fetch2,
|
|
7802
7903
|
state: stateArg
|
|
7803
7904
|
} = options || {};
|
|
@@ -7814,6 +7915,7 @@ function initLogger(options = {}) {
|
|
|
7814
7915
|
};
|
|
7815
7916
|
const state = _nullishCoalesce(stateArg, () => ( _globalState));
|
|
7816
7917
|
state.setDebugLogLevel(debugLogLevel);
|
|
7918
|
+
state.spanOriginEnvironment = detectSpanOriginEnvironment(environment);
|
|
7817
7919
|
state.enforceQueueSizeLimit(true);
|
|
7818
7920
|
const lazyMetadata = new LazyValue(
|
|
7819
7921
|
async () => {
|
|
@@ -7935,24 +8037,24 @@ async function loginToState(options = {}) {
|
|
|
7935
8037
|
return state;
|
|
7936
8038
|
}
|
|
7937
8039
|
function currentExperiment(options) {
|
|
7938
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8040
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _122 => _122.state]), () => ( _globalState));
|
|
7939
8041
|
return state.currentExperiment;
|
|
7940
8042
|
}
|
|
7941
8043
|
function currentLogger(options) {
|
|
7942
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
7943
|
-
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess',
|
|
8044
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _123 => _123.state]), () => ( _globalState));
|
|
8045
|
+
return castLogger(state.currentLogger, _optionalChain([options, 'optionalAccess', _124 => _124.asyncFlush]));
|
|
7944
8046
|
}
|
|
7945
8047
|
function currentSpan(options) {
|
|
7946
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8048
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _125 => _125.state]), () => ( _globalState));
|
|
7947
8049
|
return _nullishCoalesce(state.contextManager.getCurrentSpan(), () => ( NOOP_SPAN));
|
|
7948
8050
|
}
|
|
7949
8051
|
function getSpanParentObjectAndPropagatedState(options) {
|
|
7950
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8052
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _126 => _126.state]), () => ( _globalState));
|
|
7951
8053
|
const parentSpan = currentSpan({ state });
|
|
7952
8054
|
if (!Object.is(parentSpan, NOOP_SPAN)) {
|
|
7953
8055
|
return { parentObject: parentSpan, propagatedState: void 0 };
|
|
7954
8056
|
}
|
|
7955
|
-
const parent = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8057
|
+
const parent = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.parent]), () => ( state.currentParent.getStore()));
|
|
7956
8058
|
const { parentSlug, propagatedState } = normalizeParent(parent, state);
|
|
7957
8059
|
if (parentSlug) {
|
|
7958
8060
|
return {
|
|
@@ -8123,13 +8225,13 @@ function deleteHeader(carrier, name) {
|
|
|
8123
8225
|
}
|
|
8124
8226
|
}
|
|
8125
8227
|
function _injectIntoCarrier(carrier, args) {
|
|
8126
|
-
const traceFlags = _optionalChain([args, 'access',
|
|
8228
|
+
const traceFlags = _optionalChain([args, 'access', _128 => _128.propagatedState, 'optionalAccess', _129 => _129.traceFlags]);
|
|
8127
8229
|
const traceparent = traceFlags ? formatTraceparent(args.traceId, args.spanId, traceFlags) : formatTraceparent(args.traceId, args.spanId);
|
|
8128
8230
|
if (traceparent === void 0) {
|
|
8129
8231
|
return;
|
|
8130
8232
|
}
|
|
8131
8233
|
setHeader(carrier, TRACEPARENT_HEADER, traceparent);
|
|
8132
|
-
const tracestate = _optionalChain([args, 'access',
|
|
8234
|
+
const tracestate = _optionalChain([args, 'access', _130 => _130.propagatedState, 'optionalAccess', _131 => _131.tracestate]);
|
|
8133
8235
|
if (tracestate) {
|
|
8134
8236
|
setHeader(carrier, TRACESTATE_HEADER, tracestate);
|
|
8135
8237
|
}
|
|
@@ -8214,7 +8316,7 @@ function traced(callback, args) {
|
|
|
8214
8316
|
const { span, isSyncFlushLogger } = startSpanAndIsLogger(args);
|
|
8215
8317
|
const ret = runCatchFinally(
|
|
8216
8318
|
() => {
|
|
8217
|
-
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8319
|
+
if (_nullishCoalesce(_optionalChain([args, 'optionalAccess', _132 => _132.setCurrent]), () => ( true))) {
|
|
8218
8320
|
return withCurrent(span, callback);
|
|
8219
8321
|
} else {
|
|
8220
8322
|
return callback(span);
|
|
@@ -8226,7 +8328,7 @@ function traced(callback, args) {
|
|
|
8226
8328
|
},
|
|
8227
8329
|
() => span.end()
|
|
8228
8330
|
);
|
|
8229
|
-
if (_optionalChain([args, 'optionalAccess',
|
|
8331
|
+
if (_optionalChain([args, 'optionalAccess', _133 => _133.asyncFlush]) === void 0 || _optionalChain([args, 'optionalAccess', _134 => _134.asyncFlush])) {
|
|
8230
8332
|
return ret;
|
|
8231
8333
|
} else {
|
|
8232
8334
|
return (async () => {
|
|
@@ -8242,14 +8344,14 @@ function startSpan(args) {
|
|
|
8242
8344
|
return startSpanAndIsLogger(args).span;
|
|
8243
8345
|
}
|
|
8244
8346
|
async function flush(options) {
|
|
8245
|
-
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
8347
|
+
const state = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _135 => _135.state]), () => ( _globalState));
|
|
8246
8348
|
return await state.bgLogger().flush();
|
|
8247
8349
|
}
|
|
8248
8350
|
function startSpanAndIsLogger(args) {
|
|
8249
|
-
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8351
|
+
const state = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _136 => _136.state]), () => ( _globalState));
|
|
8250
8352
|
const { parentObject, propagatedState } = getSpanParentObjectAndPropagatedState({
|
|
8251
|
-
asyncFlush: _optionalChain([args, 'optionalAccess',
|
|
8252
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
8353
|
+
asyncFlush: _optionalChain([args, 'optionalAccess', _137 => _137.asyncFlush]),
|
|
8354
|
+
parent: _optionalChain([args, 'optionalAccess', _138 => _138.parent]),
|
|
8253
8355
|
state
|
|
8254
8356
|
});
|
|
8255
8357
|
if (parentObject instanceof SpanComponentsV3 || parentObject instanceof SpanComponentsV4) {
|
|
@@ -8270,7 +8372,7 @@ function startSpanAndIsLogger(args) {
|
|
|
8270
8372
|
),
|
|
8271
8373
|
parentComputeObjectMetadataArgs: _nullishCoalesce(parentObject.data.compute_object_metadata_args, () => ( void 0)),
|
|
8272
8374
|
parentSpanIds,
|
|
8273
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
8375
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _139 => _139.propagatedEvent]), () => ( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
8274
8376
|
(_nullishCoalesce(parentObject.data.propagated_event, () => ( void 0))))),
|
|
8275
8377
|
propagatedState
|
|
8276
8378
|
});
|
|
@@ -8278,7 +8380,7 @@ function startSpanAndIsLogger(args) {
|
|
|
8278
8380
|
span,
|
|
8279
8381
|
isSyncFlushLogger: parentObject.data.object_type === 2 /* PROJECT_LOGS */ && // Since there's no parent logger here, we're free to choose the async flush
|
|
8280
8382
|
// behavior, and therefore propagate along whatever we get from the arguments
|
|
8281
|
-
_optionalChain([args, 'optionalAccess',
|
|
8383
|
+
_optionalChain([args, 'optionalAccess', _140 => _140.asyncFlush]) === false
|
|
8282
8384
|
};
|
|
8283
8385
|
} else {
|
|
8284
8386
|
const span = parentObject.startSpan(args);
|
|
@@ -8445,10 +8547,10 @@ function extractAttachments(event, attachments) {
|
|
|
8445
8547
|
event[key] = value.reference;
|
|
8446
8548
|
continue;
|
|
8447
8549
|
}
|
|
8448
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
8550
|
+
if (_optionalChain([value, 'optionalAccess', _141 => _141.type]) === BRAINTRUST_ATTACHMENT && value.key && !value.uploader) {
|
|
8449
8551
|
continue;
|
|
8450
8552
|
}
|
|
8451
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
8553
|
+
if (_optionalChain([value, 'optionalAccess', _142 => _142.reference, 'optionalAccess', _143 => _143.type]) === BRAINTRUST_ATTACHMENT && _optionalChain([value, 'optionalAccess', _144 => _144.uploader])) {
|
|
8452
8554
|
const attachment = new Attachment({
|
|
8453
8555
|
data: value.dataDebugString,
|
|
8454
8556
|
filename: value.reference.filename,
|
|
@@ -8522,6 +8624,11 @@ var ObjectFetcher = (_class11 = class {
|
|
|
8522
8624
|
this._internal_btql = _internal_btql;
|
|
8523
8625
|
this._internalBrainstoreRealtime = _internalBrainstoreRealtime;
|
|
8524
8626
|
}
|
|
8627
|
+
|
|
8628
|
+
|
|
8629
|
+
|
|
8630
|
+
|
|
8631
|
+
|
|
8525
8632
|
__init54() {this._fetchedData = void 0}
|
|
8526
8633
|
get id() {
|
|
8527
8634
|
throw new Error("ObjectFetcher subclasses must have an 'id' attribute");
|
|
@@ -8617,7 +8724,7 @@ var ObjectFetcher = (_class11 = class {
|
|
|
8617
8724
|
}
|
|
8618
8725
|
return;
|
|
8619
8726
|
}
|
|
8620
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
8727
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _145 => _145.batchSize]))) {
|
|
8621
8728
|
yield record;
|
|
8622
8729
|
}
|
|
8623
8730
|
}
|
|
@@ -8627,7 +8734,7 @@ var ObjectFetcher = (_class11 = class {
|
|
|
8627
8734
|
async fetchedData(options) {
|
|
8628
8735
|
if (this._fetchedData === void 0) {
|
|
8629
8736
|
const data = [];
|
|
8630
|
-
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess',
|
|
8737
|
+
for await (const record of this.fetchRecordsFromApi(_optionalChain([options, 'optionalAccess', _146 => _146.batchSize]))) {
|
|
8631
8738
|
data.push(record);
|
|
8632
8739
|
}
|
|
8633
8740
|
this._fetchedData = data;
|
|
@@ -8726,7 +8833,7 @@ var Experiment2 = (_class12 = class extends ObjectFetcher {
|
|
|
8726
8833
|
* @returns The `id` of the logged event.
|
|
8727
8834
|
*/
|
|
8728
8835
|
log(event, options) {
|
|
8729
|
-
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess',
|
|
8836
|
+
if (this.calledStartSpan && !_optionalChain([options, 'optionalAccess', _147 => _147.allowConcurrentWithSpans])) {
|
|
8730
8837
|
throw new Error(
|
|
8731
8838
|
"Cannot run toplevel `log` method while using spans. To log to the span, call `experiment.traced` and then log with `span.log`"
|
|
8732
8839
|
);
|
|
@@ -8779,12 +8886,12 @@ var Experiment2 = (_class12 = class extends ObjectFetcher {
|
|
|
8779
8886
|
state: this.state,
|
|
8780
8887
|
...startSpanParentArgs({
|
|
8781
8888
|
state: this.state,
|
|
8782
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
8889
|
+
parent: _optionalChain([args, 'optionalAccess', _148 => _148.parent]),
|
|
8783
8890
|
parentObjectType: this.parentObjectType(),
|
|
8784
8891
|
parentObjectId: this.lazyId,
|
|
8785
8892
|
parentComputeObjectMetadataArgs: void 0,
|
|
8786
8893
|
parentSpanIds: void 0,
|
|
8787
|
-
propagatedEvent: _optionalChain([args, 'optionalAccess',
|
|
8894
|
+
propagatedEvent: _optionalChain([args, 'optionalAccess', _149 => _149.propagatedEvent])
|
|
8788
8895
|
}),
|
|
8789
8896
|
defaultRootType: "eval" /* EVAL */
|
|
8790
8897
|
});
|
|
@@ -8960,6 +9067,8 @@ var ReadonlyExperiment = class extends ObjectFetcher {
|
|
|
8960
9067
|
this.state = state;
|
|
8961
9068
|
this.lazyMetadata = lazyMetadata;
|
|
8962
9069
|
}
|
|
9070
|
+
|
|
9071
|
+
|
|
8963
9072
|
get id() {
|
|
8964
9073
|
return (async () => {
|
|
8965
9074
|
return (await this.lazyMetadata.get()).experiment.id;
|
|
@@ -9082,7 +9191,11 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9082
9191
|
metrics: {
|
|
9083
9192
|
start: _nullishCoalesce(args.startTime, () => ( getCurrentUnixTimestamp()))
|
|
9084
9193
|
},
|
|
9085
|
-
context:
|
|
9194
|
+
context: mergeSpanOriginContext(
|
|
9195
|
+
{ ...callerLocation },
|
|
9196
|
+
"braintrust-js-logger",
|
|
9197
|
+
this._state.spanOriginEnvironment
|
|
9198
|
+
),
|
|
9086
9199
|
span_attributes: {
|
|
9087
9200
|
name,
|
|
9088
9201
|
type,
|
|
@@ -9153,7 +9266,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9153
9266
|
...serializableInternalData,
|
|
9154
9267
|
[IS_MERGE_FIELD]: this.isMerge
|
|
9155
9268
|
});
|
|
9156
|
-
if (typeof _optionalChain([partialRecord, 'access',
|
|
9269
|
+
if (typeof _optionalChain([partialRecord, 'access', _150 => _150.metrics, 'optionalAccess', _151 => _151.end]) === "number") {
|
|
9157
9270
|
this.loggedEndTime = partialRecord.metrics.end;
|
|
9158
9271
|
}
|
|
9159
9272
|
if (this.parentObjectType === 1 /* EXPERIMENT */) {
|
|
@@ -9219,18 +9332,18 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9219
9332
|
);
|
|
9220
9333
|
}
|
|
9221
9334
|
startSpan(args) {
|
|
9222
|
-
const parentSpanIds = _optionalChain([args, 'optionalAccess',
|
|
9335
|
+
const parentSpanIds = _optionalChain([args, 'optionalAccess', _152 => _152.parent]) ? void 0 : { spanId: this._spanId, rootSpanId: this._rootSpanId };
|
|
9223
9336
|
return new _SpanImpl({
|
|
9224
9337
|
state: this._state,
|
|
9225
9338
|
...args,
|
|
9226
9339
|
...startSpanParentArgs({
|
|
9227
9340
|
state: this._state,
|
|
9228
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
9341
|
+
parent: _optionalChain([args, 'optionalAccess', _153 => _153.parent]),
|
|
9229
9342
|
parentObjectType: this.parentObjectType,
|
|
9230
9343
|
parentObjectId: this.parentObjectId,
|
|
9231
9344
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
9232
9345
|
parentSpanIds,
|
|
9233
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
9346
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _154 => _154.propagatedEvent]), () => ( this.propagatedEvent)),
|
|
9234
9347
|
propagatedState: this._propagatedState
|
|
9235
9348
|
})
|
|
9236
9349
|
});
|
|
@@ -9245,12 +9358,12 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9245
9358
|
...args,
|
|
9246
9359
|
...startSpanParentArgs({
|
|
9247
9360
|
state: this._state,
|
|
9248
|
-
parent: _optionalChain([args, 'optionalAccess',
|
|
9361
|
+
parent: _optionalChain([args, 'optionalAccess', _155 => _155.parent]),
|
|
9249
9362
|
parentObjectType: this.parentObjectType,
|
|
9250
9363
|
parentObjectId: this.parentObjectId,
|
|
9251
9364
|
parentComputeObjectMetadataArgs: this.parentComputeObjectMetadataArgs,
|
|
9252
9365
|
parentSpanIds,
|
|
9253
|
-
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
9366
|
+
propagatedEvent: _nullishCoalesce(_optionalChain([args, 'optionalAccess', _156 => _156.propagatedEvent]), () => ( this.propagatedEvent)),
|
|
9254
9367
|
propagatedState: this._propagatedState
|
|
9255
9368
|
}),
|
|
9256
9369
|
spanId
|
|
@@ -9260,7 +9373,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9260
9373
|
let endTime;
|
|
9261
9374
|
let internalData = {};
|
|
9262
9375
|
if (!this.loggedEndTime) {
|
|
9263
|
-
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess',
|
|
9376
|
+
endTime = _nullishCoalesce(_optionalChain([args, 'optionalAccess', _157 => _157.endTime]), () => ( getCurrentUnixTimestamp()));
|
|
9264
9377
|
internalData = { metrics: { end: endTime } };
|
|
9265
9378
|
} else {
|
|
9266
9379
|
endTime = this.loggedEndTime;
|
|
@@ -9286,15 +9399,15 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9286
9399
|
*/
|
|
9287
9400
|
_getOtelParent() {
|
|
9288
9401
|
if (this.parentObjectType === 2 /* PROJECT_LOGS */) {
|
|
9289
|
-
const id = _optionalChain([this, 'access',
|
|
9290
|
-
const name = _optionalChain([this, 'access',
|
|
9402
|
+
const id = _optionalChain([this, 'access', _158 => _158.parentComputeObjectMetadataArgs, 'optionalAccess', _159 => _159.project_id]) || this.parentObjectId.getSync().value;
|
|
9403
|
+
const name = _optionalChain([this, 'access', _160 => _160.parentComputeObjectMetadataArgs, 'optionalAccess', _161 => _161.project_name]);
|
|
9291
9404
|
if (id) {
|
|
9292
9405
|
return `project_id:${id}`;
|
|
9293
9406
|
} else if (name) {
|
|
9294
9407
|
return `project_name:${name}`;
|
|
9295
9408
|
}
|
|
9296
9409
|
} else if (this.parentObjectType === 1 /* EXPERIMENT */) {
|
|
9297
|
-
const id = _optionalChain([this, 'access',
|
|
9410
|
+
const id = _optionalChain([this, 'access', _162 => _162.parentComputeObjectMetadataArgs, 'optionalAccess', _163 => _163.experiment_id]) || this.parentObjectId.getSync().value;
|
|
9298
9411
|
if (id) {
|
|
9299
9412
|
return `experiment_id:${id}`;
|
|
9300
9413
|
}
|
|
@@ -9307,7 +9420,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9307
9420
|
_injectIntoCarrier(resolvedCarrier, {
|
|
9308
9421
|
traceId: this._rootSpanId,
|
|
9309
9422
|
spanId: this._spanId,
|
|
9310
|
-
braintrustParent: _nullishCoalesce(this._getOtelParent(), () => ( _optionalChain([this, 'access',
|
|
9423
|
+
braintrustParent: _nullishCoalesce(this._getOtelParent(), () => ( _optionalChain([this, 'access', _164 => _164._propagatedState, 'optionalAccess', _165 => _165.braintrustParent]))),
|
|
9311
9424
|
propagatedState: this._propagatedState
|
|
9312
9425
|
});
|
|
9313
9426
|
} catch (e) {
|
|
@@ -9347,8 +9460,8 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9347
9460
|
const args = this.parentComputeObjectMetadataArgs;
|
|
9348
9461
|
switch (this.parentObjectType) {
|
|
9349
9462
|
case 2 /* PROJECT_LOGS */: {
|
|
9350
|
-
const projectID = _optionalChain([args, 'optionalAccess',
|
|
9351
|
-
const projectName = _optionalChain([args, 'optionalAccess',
|
|
9463
|
+
const projectID = _optionalChain([args, 'optionalAccess', _166 => _166.project_id]) || this.parentObjectId.getSync().value;
|
|
9464
|
+
const projectName = _optionalChain([args, 'optionalAccess', _167 => _167.project_name]);
|
|
9352
9465
|
if (projectID) {
|
|
9353
9466
|
return `${baseUrl}/object?object_type=project_logs&object_id=${projectID}&id=${this._id}`;
|
|
9354
9467
|
} else if (projectName) {
|
|
@@ -9358,7 +9471,7 @@ var SpanImpl = (_class13 = class _SpanImpl {
|
|
|
9358
9471
|
}
|
|
9359
9472
|
}
|
|
9360
9473
|
case 1 /* EXPERIMENT */: {
|
|
9361
|
-
const expID = _optionalChain([args, 'optionalAccess',
|
|
9474
|
+
const expID = _optionalChain([args, 'optionalAccess', _168 => _168.experiment_id]) || _optionalChain([this, 'access', _169 => _169.parentObjectId, 'optionalAccess', _170 => _170.getSync, 'call', _171 => _171(), 'optionalAccess', _172 => _172.value]);
|
|
9362
9475
|
if (!expID) {
|
|
9363
9476
|
return getErrPermlink("provide-experiment-id");
|
|
9364
9477
|
} else {
|
|
@@ -9452,11 +9565,12 @@ var Dataset2 = (_class14 = class extends ObjectFetcher {
|
|
|
9452
9565
|
this.state = state;
|
|
9453
9566
|
void this.__braintrust_dataset_marker;
|
|
9454
9567
|
this.lazyMetadata = lazyMetadata;
|
|
9455
|
-
this.lazyPinnedVersion = _optionalChain([pinState, 'optionalAccess',
|
|
9456
|
-
this.pinnedEnvironment = _optionalChain([pinState, 'optionalAccess',
|
|
9457
|
-
this.pinnedSnapshotName = _optionalChain([pinState, 'optionalAccess',
|
|
9568
|
+
this.lazyPinnedVersion = _optionalChain([pinState, 'optionalAccess', _173 => _173.lazyPinnedVersion]);
|
|
9569
|
+
this.pinnedEnvironment = _optionalChain([pinState, 'optionalAccess', _174 => _174.pinnedEnvironment]);
|
|
9570
|
+
this.pinnedSnapshotName = _optionalChain([pinState, 'optionalAccess', _175 => _175.pinnedSnapshotName]);
|
|
9458
9571
|
}
|
|
9459
9572
|
|
|
9573
|
+
|
|
9460
9574
|
__init57() {this.__braintrust_dataset_marker = true}
|
|
9461
9575
|
__init58() {this.newRecords = 0}
|
|
9462
9576
|
|
|
@@ -9968,6 +10082,9 @@ var Prompt2 = (_class15 = class _Prompt {
|
|
|
9968
10082
|
void this.__braintrust_prompt_marker;
|
|
9969
10083
|
}
|
|
9970
10084
|
|
|
10085
|
+
|
|
10086
|
+
|
|
10087
|
+
|
|
9971
10088
|
__init59() {this.hasParsedPromptData = false}
|
|
9972
10089
|
__init60() {this.__braintrust_prompt_marker = true}
|
|
9973
10090
|
get id() {
|
|
@@ -9983,16 +10100,16 @@ var Prompt2 = (_class15 = class _Prompt {
|
|
|
9983
10100
|
return "slug" in this.metadata ? this.metadata.slug : this.metadata.id;
|
|
9984
10101
|
}
|
|
9985
10102
|
get prompt() {
|
|
9986
|
-
return _optionalChain([this, 'access',
|
|
10103
|
+
return _optionalChain([this, 'access', _176 => _176.getParsedPromptData, 'call', _177 => _177(), 'optionalAccess', _178 => _178.prompt]);
|
|
9987
10104
|
}
|
|
9988
10105
|
get version() {
|
|
9989
10106
|
return this.metadata[TRANSACTION_ID_FIELD];
|
|
9990
10107
|
}
|
|
9991
10108
|
get options() {
|
|
9992
|
-
return _optionalChain([this, 'access',
|
|
10109
|
+
return _optionalChain([this, 'access', _179 => _179.getParsedPromptData, 'call', _180 => _180(), 'optionalAccess', _181 => _181.options]) || {};
|
|
9993
10110
|
}
|
|
9994
10111
|
get templateFormat() {
|
|
9995
|
-
return _optionalChain([this, 'access',
|
|
10112
|
+
return _optionalChain([this, 'access', _182 => _182.getParsedPromptData, 'call', _183 => _183(), 'optionalAccess', _184 => _184.template_format]);
|
|
9996
10113
|
}
|
|
9997
10114
|
get promptData() {
|
|
9998
10115
|
return this.getParsedPromptData();
|
|
@@ -10154,7 +10271,7 @@ var Prompt2 = (_class15 = class _Prompt {
|
|
|
10154
10271
|
return {
|
|
10155
10272
|
type: "chat",
|
|
10156
10273
|
messages,
|
|
10157
|
-
..._optionalChain([prompt, 'access',
|
|
10274
|
+
..._optionalChain([prompt, 'access', _185 => _185.tools, 'optionalAccess', _186 => _186.trim, 'call', _187 => _187()]) ? {
|
|
10158
10275
|
tools: render(prompt.tools)
|
|
10159
10276
|
} : void 0
|
|
10160
10277
|
};
|
|
@@ -10204,6 +10321,7 @@ var RemoteEvalParameters = (_class16 = class {
|
|
|
10204
10321
|
this.metadata = metadata;
|
|
10205
10322
|
void this.__braintrust_parameters_marker;
|
|
10206
10323
|
}
|
|
10324
|
+
|
|
10207
10325
|
__init61() {this.__braintrust_parameters_marker = true}
|
|
10208
10326
|
get id() {
|
|
10209
10327
|
return this.metadata.id;
|
|
@@ -10482,7 +10600,7 @@ function getChannelSpanInfo(event) {
|
|
|
10482
10600
|
if (isObject(event.span_info)) {
|
|
10483
10601
|
return event.span_info;
|
|
10484
10602
|
}
|
|
10485
|
-
const firstArg = _optionalChain([event, 'access',
|
|
10603
|
+
const firstArg = _optionalChain([event, 'access', _188 => _188.arguments, 'optionalAccess', _189 => _189[0]]);
|
|
10486
10604
|
if (hasChannelSpanInfo(firstArg)) {
|
|
10487
10605
|
return firstArg.span_info;
|
|
10488
10606
|
}
|
|
@@ -10493,13 +10611,13 @@ function buildStartSpanArgs(config, event) {
|
|
|
10493
10611
|
const spanAttributes = {
|
|
10494
10612
|
type: config.type
|
|
10495
10613
|
};
|
|
10496
|
-
if (isObject(_optionalChain([spanInfo, 'optionalAccess',
|
|
10614
|
+
if (isObject(_optionalChain([spanInfo, 'optionalAccess', _190 => _190.spanAttributes]))) {
|
|
10497
10615
|
mergeDicts(spanAttributes, spanInfo.spanAttributes);
|
|
10498
10616
|
}
|
|
10499
10617
|
return {
|
|
10500
|
-
name: typeof _optionalChain([spanInfo, 'optionalAccess',
|
|
10618
|
+
name: typeof _optionalChain([spanInfo, 'optionalAccess', _191 => _191.name]) === "string" && spanInfo.name ? spanInfo.name : resolveConfigName(config.name, event),
|
|
10501
10619
|
spanAttributes,
|
|
10502
|
-
spanInfoMetadata: isObject(_optionalChain([spanInfo, 'optionalAccess',
|
|
10620
|
+
spanInfoMetadata: isObject(_optionalChain([spanInfo, 'optionalAccess', _192 => _192.metadata])) ? spanInfo.metadata : void 0
|
|
10503
10621
|
};
|
|
10504
10622
|
}
|
|
10505
10623
|
function resolveConfigName(name, event) {
|
|
@@ -10601,7 +10719,7 @@ var BasePlugin = (_class17 = class {constructor() { _class17.prototype.__init62.
|
|
|
10601
10719
|
try {
|
|
10602
10720
|
const output = config.extractOutput(event.result, event);
|
|
10603
10721
|
const metrics = config.extractMetrics(event.result, startTime, event);
|
|
10604
|
-
const metadata = _optionalChain([config, 'access',
|
|
10722
|
+
const metadata = _optionalChain([config, 'access', _193 => _193.extractMetadata, 'optionalCall', _194 => _194(event.result, event)]);
|
|
10605
10723
|
span.log({
|
|
10606
10724
|
output,
|
|
10607
10725
|
...metadata !== void 0 ? { metadata } : {},
|
|
@@ -10900,11 +11018,11 @@ function suppressionStore() {
|
|
|
10900
11018
|
return autoInstrumentationSuppressionStore;
|
|
10901
11019
|
}
|
|
10902
11020
|
function currentFrames() {
|
|
10903
|
-
return _nullishCoalesce(_optionalChain([suppressionStore, 'call',
|
|
11021
|
+
return _nullishCoalesce(_optionalChain([suppressionStore, 'call', _195 => _195(), 'access', _196 => _196.getStore, 'call', _197 => _197(), 'optionalAccess', _198 => _198.frames]), () => ( []));
|
|
10904
11022
|
}
|
|
10905
11023
|
function isAutoInstrumentationSuppressed() {
|
|
10906
11024
|
const frames = currentFrames();
|
|
10907
|
-
return _optionalChain([frames, 'access',
|
|
11025
|
+
return _optionalChain([frames, 'access', _199 => _199[frames.length - 1], 'optionalAccess', _200 => _200.mode]) === "suppress";
|
|
10908
11026
|
}
|
|
10909
11027
|
function runWithAutoInstrumentationSuppressed(callback) {
|
|
10910
11028
|
const frame = {
|
|
@@ -11016,7 +11134,7 @@ function ensureSpanStateForEvent(states, config, event, channelName) {
|
|
|
11016
11134
|
function bindCurrentSpanStoreToStart(tracingChannel2, states, config, channelName) {
|
|
11017
11135
|
const state = _internalGetGlobalState();
|
|
11018
11136
|
const startChannel = tracingChannel2.start;
|
|
11019
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
11137
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _201 => _201.contextManager]);
|
|
11020
11138
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
11021
11139
|
if (!currentSpanStore || !startChannel) {
|
|
11022
11140
|
return void 0;
|
|
@@ -11129,7 +11247,7 @@ function traceAsyncChannel(channel2, config) {
|
|
|
11129
11247
|
startTime,
|
|
11130
11248
|
asyncEndEvent
|
|
11131
11249
|
);
|
|
11132
|
-
const metadata = _optionalChain([config, 'access',
|
|
11250
|
+
const metadata = _optionalChain([config, 'access', _202 => _202.extractMetadata, 'optionalCall', _203 => _203(
|
|
11133
11251
|
asyncEndEvent.result,
|
|
11134
11252
|
asyncEndEvent
|
|
11135
11253
|
)]);
|
|
@@ -11151,7 +11269,7 @@ function traceAsyncChannel(channel2, config) {
|
|
|
11151
11269
|
};
|
|
11152
11270
|
tracingChannel2.subscribe(handlers);
|
|
11153
11271
|
return () => {
|
|
11154
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
11272
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _204 => _204()]);
|
|
11155
11273
|
tracingChannel2.unsubscribe(handlers);
|
|
11156
11274
|
};
|
|
11157
11275
|
}
|
|
@@ -11268,7 +11386,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
11268
11386
|
});
|
|
11269
11387
|
return;
|
|
11270
11388
|
}
|
|
11271
|
-
if (_optionalChain([config, 'access',
|
|
11389
|
+
if (_optionalChain([config, 'access', _205 => _205.patchResult, 'optionalCall', _206 => _206({
|
|
11272
11390
|
channelName,
|
|
11273
11391
|
endEvent: asyncEndEvent,
|
|
11274
11392
|
result: asyncEndEvent.result,
|
|
@@ -11288,7 +11406,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
11288
11406
|
startTime,
|
|
11289
11407
|
asyncEndEvent
|
|
11290
11408
|
);
|
|
11291
|
-
const metadata = _optionalChain([config, 'access',
|
|
11409
|
+
const metadata = _optionalChain([config, 'access', _207 => _207.extractMetadata, 'optionalCall', _208 => _208(
|
|
11292
11410
|
asyncEndEvent.result,
|
|
11293
11411
|
asyncEndEvent
|
|
11294
11412
|
)]);
|
|
@@ -11332,7 +11450,7 @@ function traceStreamingChannel(channel2, config) {
|
|
|
11332
11450
|
};
|
|
11333
11451
|
tracingChannel2.subscribe(handlers);
|
|
11334
11452
|
return () => {
|
|
11335
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
11453
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _209 => _209()]);
|
|
11336
11454
|
tracingChannel2.unsubscribe(handlers);
|
|
11337
11455
|
};
|
|
11338
11456
|
}
|
|
@@ -11370,7 +11488,7 @@ function traceSyncStreamChannel(channel2, config) {
|
|
|
11370
11488
|
...endEvent,
|
|
11371
11489
|
result
|
|
11372
11490
|
};
|
|
11373
|
-
if (_optionalChain([config, 'access',
|
|
11491
|
+
if (_optionalChain([config, 'access', _210 => _210.patchResult, 'optionalCall', _211 => _211({
|
|
11374
11492
|
channelName,
|
|
11375
11493
|
endEvent: resolvedEndEvent,
|
|
11376
11494
|
result,
|
|
@@ -11454,7 +11572,7 @@ function traceSyncStreamChannel(channel2, config) {
|
|
|
11454
11572
|
};
|
|
11455
11573
|
tracingChannel2.subscribe(handlers);
|
|
11456
11574
|
return () => {
|
|
11457
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
11575
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _212 => _212()]);
|
|
11458
11576
|
tracingChannel2.unsubscribe(handlers);
|
|
11459
11577
|
};
|
|
11460
11578
|
}
|
|
@@ -11529,7 +11647,7 @@ function processInputAttachments(input) {
|
|
|
11529
11647
|
let attachmentIndex = 0;
|
|
11530
11648
|
const inferMediaTypeFromDataUrl = (value, fallback2) => {
|
|
11531
11649
|
const mediaTypeMatch = value.match(/^data:([^;]+);/);
|
|
11532
|
-
return _optionalChain([mediaTypeMatch, 'optionalAccess',
|
|
11650
|
+
return _optionalChain([mediaTypeMatch, 'optionalAccess', _213 => _213[1]]) || fallback2;
|
|
11533
11651
|
};
|
|
11534
11652
|
const toAttachment = (value, mediaType, filename) => {
|
|
11535
11653
|
const blob = convertDataToBlob(value, mediaType);
|
|
@@ -11783,11 +11901,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11783
11901
|
};
|
|
11784
11902
|
},
|
|
11785
11903
|
extractOutput: (result) => {
|
|
11786
|
-
return _optionalChain([result, 'optionalAccess',
|
|
11904
|
+
return _optionalChain([result, 'optionalAccess', _214 => _214.choices]);
|
|
11787
11905
|
},
|
|
11788
11906
|
extractMetrics: (result, startTime, endEvent) => {
|
|
11789
11907
|
const metrics = withCachedMetric(
|
|
11790
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
11908
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _215 => _215.usage])),
|
|
11791
11909
|
result,
|
|
11792
11910
|
endEvent
|
|
11793
11911
|
);
|
|
@@ -11811,12 +11929,12 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11811
11929
|
};
|
|
11812
11930
|
},
|
|
11813
11931
|
extractOutput: (result) => {
|
|
11814
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
11932
|
+
const embedding = _optionalChain([result, 'optionalAccess', _216 => _216.data, 'optionalAccess', _217 => _217[0], 'optionalAccess', _218 => _218.embedding]);
|
|
11815
11933
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
11816
11934
|
},
|
|
11817
11935
|
extractMetrics: (result, _startTime, endEvent) => {
|
|
11818
11936
|
return withCachedMetric(
|
|
11819
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
11937
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _219 => _219.usage])),
|
|
11820
11938
|
result,
|
|
11821
11939
|
endEvent
|
|
11822
11940
|
);
|
|
@@ -11835,11 +11953,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11835
11953
|
};
|
|
11836
11954
|
},
|
|
11837
11955
|
extractOutput: (result) => {
|
|
11838
|
-
return _optionalChain([result, 'optionalAccess',
|
|
11956
|
+
return _optionalChain([result, 'optionalAccess', _220 => _220.choices]);
|
|
11839
11957
|
},
|
|
11840
11958
|
extractMetrics: (result, startTime, endEvent) => {
|
|
11841
11959
|
const metrics = withCachedMetric(
|
|
11842
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
11960
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _221 => _221.usage])),
|
|
11843
11961
|
result,
|
|
11844
11962
|
endEvent
|
|
11845
11963
|
);
|
|
@@ -11876,11 +11994,11 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11876
11994
|
};
|
|
11877
11995
|
},
|
|
11878
11996
|
extractOutput: (result) => {
|
|
11879
|
-
return _optionalChain([result, 'optionalAccess',
|
|
11997
|
+
return _optionalChain([result, 'optionalAccess', _222 => _222.results]);
|
|
11880
11998
|
},
|
|
11881
11999
|
extractMetrics: (result, _startTime, endEvent) => {
|
|
11882
12000
|
return withCachedMetric(
|
|
11883
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
12001
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _223 => _223.usage])),
|
|
11884
12002
|
result,
|
|
11885
12003
|
endEvent
|
|
11886
12004
|
);
|
|
@@ -11899,7 +12017,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11899
12017
|
};
|
|
11900
12018
|
},
|
|
11901
12019
|
extractOutput: (result) => {
|
|
11902
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
12020
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _224 => _224.output]));
|
|
11903
12021
|
},
|
|
11904
12022
|
extractMetadata: (result) => {
|
|
11905
12023
|
if (!result) {
|
|
@@ -11910,7 +12028,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11910
12028
|
},
|
|
11911
12029
|
extractMetrics: (result, startTime, endEvent) => {
|
|
11912
12030
|
const metrics = withCachedMetric(
|
|
11913
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
12031
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _225 => _225.usage])),
|
|
11914
12032
|
result,
|
|
11915
12033
|
endEvent
|
|
11916
12034
|
);
|
|
@@ -11963,7 +12081,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11963
12081
|
};
|
|
11964
12082
|
},
|
|
11965
12083
|
extractOutput: (result) => {
|
|
11966
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
12084
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _226 => _226.output]));
|
|
11967
12085
|
},
|
|
11968
12086
|
extractMetadata: (result) => {
|
|
11969
12087
|
if (!result) {
|
|
@@ -11974,7 +12092,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11974
12092
|
},
|
|
11975
12093
|
extractMetrics: (result, startTime, endEvent) => {
|
|
11976
12094
|
const metrics = withCachedMetric(
|
|
11977
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
12095
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _227 => _227.usage])),
|
|
11978
12096
|
result,
|
|
11979
12097
|
endEvent
|
|
11980
12098
|
);
|
|
@@ -11998,7 +12116,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
11998
12116
|
};
|
|
11999
12117
|
},
|
|
12000
12118
|
extractOutput: (result) => {
|
|
12001
|
-
return processImagesInOutput(_optionalChain([result, 'optionalAccess',
|
|
12119
|
+
return processImagesInOutput(_optionalChain([result, 'optionalAccess', _228 => _228.output]));
|
|
12002
12120
|
},
|
|
12003
12121
|
extractMetadata: (result) => {
|
|
12004
12122
|
if (!result) {
|
|
@@ -12009,7 +12127,7 @@ var OpenAIPlugin = class extends BasePlugin {
|
|
|
12009
12127
|
},
|
|
12010
12128
|
extractMetrics: (result, startTime, endEvent) => {
|
|
12011
12129
|
const metrics = withCachedMetric(
|
|
12012
|
-
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
12130
|
+
parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _229 => _229.usage])),
|
|
12013
12131
|
result,
|
|
12014
12132
|
endEvent
|
|
12015
12133
|
);
|
|
@@ -12111,11 +12229,11 @@ function aggregateChatLogprobs(existing, incoming) {
|
|
|
12111
12229
|
return _nullishCoalesce(existing, () => ( null));
|
|
12112
12230
|
}
|
|
12113
12231
|
const aggregated = existing && existing !== null ? { ...existing, ...incoming } : { ...incoming };
|
|
12114
|
-
const content = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess',
|
|
12232
|
+
const content = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess', _230 => _230.content]), incoming.content);
|
|
12115
12233
|
if (content !== void 0) {
|
|
12116
12234
|
aggregated.content = content;
|
|
12117
12235
|
}
|
|
12118
|
-
const refusal = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess',
|
|
12236
|
+
const refusal = mergeLogprobTokens(_optionalChain([existing, 'optionalAccess', _231 => _231.refusal]), incoming.refusal);
|
|
12119
12237
|
if (refusal !== void 0) {
|
|
12120
12238
|
aggregated.refusal = refusal;
|
|
12121
12239
|
}
|
|
@@ -12136,7 +12254,7 @@ function aggregateChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
12136
12254
|
...parseMetricsFromUsage(chunk.usage)
|
|
12137
12255
|
};
|
|
12138
12256
|
}
|
|
12139
|
-
const choice = _optionalChain([chunk, 'access',
|
|
12257
|
+
const choice = _optionalChain([chunk, 'access', _232 => _232.choices, 'optionalAccess', _233 => _233[0]]);
|
|
12140
12258
|
if (!choice) {
|
|
12141
12259
|
continue;
|
|
12142
12260
|
}
|
|
@@ -12206,14 +12324,14 @@ function aggregateResponseStreamEvents(chunks, _streamResult, endEvent) {
|
|
|
12206
12324
|
continue;
|
|
12207
12325
|
}
|
|
12208
12326
|
const response = chunk.response;
|
|
12209
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
12327
|
+
if (_optionalChain([response, 'optionalAccess', _234 => _234.output]) !== void 0) {
|
|
12210
12328
|
output = processImagesInOutput(response.output);
|
|
12211
12329
|
}
|
|
12212
12330
|
const { usage: _usage, output: _output, ...rest } = response || {};
|
|
12213
12331
|
if (Object.keys(rest).length > 0) {
|
|
12214
12332
|
metadata = rest;
|
|
12215
12333
|
}
|
|
12216
|
-
metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess',
|
|
12334
|
+
metrics = parseMetricsFromUsage(_optionalChain([response, 'optionalAccess', _235 => _235.usage]));
|
|
12217
12335
|
}
|
|
12218
12336
|
return {
|
|
12219
12337
|
output,
|
|
@@ -12388,7 +12506,7 @@ async function handleCodexEvent(state, event) {
|
|
|
12388
12506
|
return;
|
|
12389
12507
|
case "turn.failed":
|
|
12390
12508
|
await finalizeCodexRun(state, {
|
|
12391
|
-
error: _nullishCoalesce(_optionalChain([event, 'access',
|
|
12509
|
+
error: _nullishCoalesce(_optionalChain([event, 'access', _236 => _236.error, 'optionalAccess', _237 => _237.message]), () => ( "Codex turn failed"))
|
|
12392
12510
|
});
|
|
12393
12511
|
return;
|
|
12394
12512
|
case "item.started":
|
|
@@ -12659,7 +12777,7 @@ function mcpToolSpanArgs(parent, baseMetadata, item) {
|
|
|
12659
12777
|
spanAttributes: { type: "tool" /* TOOL */ }
|
|
12660
12778
|
},
|
|
12661
12779
|
end: {
|
|
12662
|
-
..._optionalChain([item, 'access',
|
|
12780
|
+
..._optionalChain([item, 'access', _238 => _238.error, 'optionalAccess', _239 => _239.message]) ? { error: item.error.message } : {},
|
|
12663
12781
|
metadata,
|
|
12664
12782
|
output: item.result
|
|
12665
12783
|
}
|
|
@@ -12721,7 +12839,7 @@ function extractThreadFromEvent(event) {
|
|
|
12721
12839
|
function extractThreadMetadata(thread) {
|
|
12722
12840
|
const threadOptions = extractThreadOptions(thread);
|
|
12723
12841
|
return {
|
|
12724
|
-
..._optionalChain([thread, 'optionalAccess',
|
|
12842
|
+
..._optionalChain([thread, 'optionalAccess', _240 => _240.id]) ? { "openai_codex.thread_id": thread.id } : {},
|
|
12725
12843
|
...extractThreadOptionsMetadata(threadOptions)
|
|
12726
12844
|
};
|
|
12727
12845
|
}
|
|
@@ -12922,7 +13040,7 @@ var AnthropicPlugin = class extends BasePlugin {
|
|
|
12922
13040
|
return message ? { role: message.role, content: message.content } : null;
|
|
12923
13041
|
},
|
|
12924
13042
|
extractMetrics: (message, startTime) => {
|
|
12925
|
-
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess',
|
|
13043
|
+
const metrics = parseMetricsFromUsage2(_optionalChain([message, 'optionalAccess', _241 => _241.usage]));
|
|
12926
13044
|
if (startTime) {
|
|
12927
13045
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
12928
13046
|
}
|
|
@@ -12937,7 +13055,7 @@ var AnthropicPlugin = class extends BasePlugin {
|
|
|
12937
13055
|
const metadata = {};
|
|
12938
13056
|
const metas = ["stop_reason", "stop_sequence"];
|
|
12939
13057
|
for (const m of metas) {
|
|
12940
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
13058
|
+
if (_optionalChain([message, 'optionalAccess', _242 => _242[m]]) !== void 0) {
|
|
12941
13059
|
metadata[m] = message[m];
|
|
12942
13060
|
}
|
|
12943
13061
|
}
|
|
@@ -13087,8 +13205,8 @@ function wrapAnthropicToolRunnerTool(tool, index, state) {
|
|
|
13087
13205
|
Object.getOwnPropertyDescriptors(tool)
|
|
13088
13206
|
);
|
|
13089
13207
|
Object.defineProperty(wrappedTool, "run", {
|
|
13090
|
-
configurable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
13091
|
-
enumerable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
13208
|
+
configurable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _243 => _243.configurable]), () => ( true)),
|
|
13209
|
+
enumerable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _244 => _244.enumerable]), () => ( true)),
|
|
13092
13210
|
value: function braintrustAnthropicToolRunnerRun(...args) {
|
|
13093
13211
|
return state.span.traced(
|
|
13094
13212
|
(span) => {
|
|
@@ -13125,7 +13243,7 @@ function wrapAnthropicToolRunnerTool(tool, index, state) {
|
|
|
13125
13243
|
}
|
|
13126
13244
|
);
|
|
13127
13245
|
},
|
|
13128
|
-
writable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess',
|
|
13246
|
+
writable: _nullishCoalesce(_optionalChain([runDescriptor, 'optionalAccess', _245 => _245.writable]), () => ( true))
|
|
13129
13247
|
});
|
|
13130
13248
|
Object.defineProperty(wrappedTool, ANTHROPIC_TOOL_RUNNER_TOOL_WRAPPED, {
|
|
13131
13249
|
configurable: false,
|
|
@@ -13230,10 +13348,10 @@ async function finalizeAnthropicToolRunner(state, finalMessage) {
|
|
|
13230
13348
|
const metadata = {
|
|
13231
13349
|
anthropic_tool_runner_iterations: state.iterationCount
|
|
13232
13350
|
};
|
|
13233
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
13351
|
+
if (_optionalChain([message, 'optionalAccess', _246 => _246.stop_reason]) !== void 0) {
|
|
13234
13352
|
metadata.stop_reason = message.stop_reason;
|
|
13235
13353
|
}
|
|
13236
|
-
if (_optionalChain([message, 'optionalAccess',
|
|
13354
|
+
if (_optionalChain([message, 'optionalAccess', _247 => _247.stop_sequence]) !== void 0) {
|
|
13237
13355
|
metadata.stop_sequence = message.stop_sequence;
|
|
13238
13356
|
}
|
|
13239
13357
|
state.span.log({
|
|
@@ -13375,13 +13493,13 @@ function aggregateAnthropicStreamChunks(chunks) {
|
|
|
13375
13493
|
let metadata = {};
|
|
13376
13494
|
let role;
|
|
13377
13495
|
for (const event of chunks) {
|
|
13378
|
-
switch (_optionalChain([event, 'optionalAccess',
|
|
13496
|
+
switch (_optionalChain([event, 'optionalAccess', _248 => _248.type])) {
|
|
13379
13497
|
case "message_start":
|
|
13380
|
-
if (_optionalChain([event, 'access',
|
|
13498
|
+
if (_optionalChain([event, 'access', _249 => _249.message, 'optionalAccess', _250 => _250.usage])) {
|
|
13381
13499
|
const initialMetrics = parseMetricsFromUsage2(event.message.usage);
|
|
13382
13500
|
metrics = { ...metrics, ...initialMetrics };
|
|
13383
13501
|
}
|
|
13384
|
-
if (typeof _optionalChain([event, 'access',
|
|
13502
|
+
if (typeof _optionalChain([event, 'access', _251 => _251.message, 'optionalAccess', _252 => _252.role]) === "string") {
|
|
13385
13503
|
role = event.message.role;
|
|
13386
13504
|
}
|
|
13387
13505
|
break;
|
|
@@ -13447,7 +13565,7 @@ function aggregateAnthropicStreamChunks(chunks) {
|
|
|
13447
13565
|
})).filter(({ block }) => block !== void 0).sort((left, right) => left.index - right.index).map(({ block }) => block);
|
|
13448
13566
|
let output = fallbackTextDeltas.join("");
|
|
13449
13567
|
if (orderedContent.length > 0) {
|
|
13450
|
-
if (orderedContent.every(isTextContentBlock) && orderedContent.every((block) => !_optionalChain([block, 'access',
|
|
13568
|
+
if (orderedContent.every(isTextContentBlock) && orderedContent.every((block) => !_optionalChain([block, 'access', _253 => _253.citations, 'optionalAccess', _254 => _254.length]))) {
|
|
13451
13569
|
output = orderedContent.map((block) => block.text).join("");
|
|
13452
13570
|
} else {
|
|
13453
13571
|
output = {
|
|
@@ -13474,7 +13592,7 @@ function finalizeContentBlock(index, contentBlocks, contentBlockDeltas, fallback
|
|
|
13474
13592
|
return;
|
|
13475
13593
|
}
|
|
13476
13594
|
const acc = contentBlockDeltas[index];
|
|
13477
|
-
const text = _nullishCoalesce(_optionalChain([acc, 'optionalAccess',
|
|
13595
|
+
const text = _nullishCoalesce(_optionalChain([acc, 'optionalAccess', _255 => _255.textDeltas, 'access', _256 => _256.join, 'call', _257 => _257("")]), () => ( ""));
|
|
13478
13596
|
if (isToolUseLikeContentBlock(contentBlock)) {
|
|
13479
13597
|
if (!text) {
|
|
13480
13598
|
return;
|
|
@@ -13505,7 +13623,7 @@ function finalizeContentBlock(index, contentBlocks, contentBlockDeltas, fallback
|
|
|
13505
13623
|
return;
|
|
13506
13624
|
}
|
|
13507
13625
|
const updated = { ...contentBlock, text };
|
|
13508
|
-
if (_optionalChain([acc, 'optionalAccess',
|
|
13626
|
+
if (_optionalChain([acc, 'optionalAccess', _258 => _258.citations, 'access', _259 => _259.length])) {
|
|
13509
13627
|
updated.citations = acc.citations;
|
|
13510
13628
|
}
|
|
13511
13629
|
contentBlocks[index] = updated;
|
|
@@ -13707,7 +13825,7 @@ function unregisterWorkflowAgentWrapperSpan(span) {
|
|
|
13707
13825
|
}
|
|
13708
13826
|
}
|
|
13709
13827
|
function currentWorkflowAgentWrapperSpan() {
|
|
13710
|
-
const parentSpanIds = _nullishCoalesce(_optionalChain([_internalGetGlobalState, 'call',
|
|
13828
|
+
const parentSpanIds = _nullishCoalesce(_optionalChain([_internalGetGlobalState, 'call', _260 => _260(), 'access', _261 => _261.contextManager, 'access', _262 => _262.getParentSpanIds, 'call', _263 => _263(), 'optionalAccess', _264 => _264.spanParents]), () => ( []));
|
|
13711
13829
|
for (const parentSpanId of parentSpanIds) {
|
|
13712
13830
|
const span = workflowAgentWrapperSpans.get(parentSpanId);
|
|
13713
13831
|
if (span) {
|
|
@@ -13736,7 +13854,7 @@ function braintrustAISDKTelemetry() {
|
|
|
13736
13854
|
}
|
|
13737
13855
|
};
|
|
13738
13856
|
const startChildSpan = (operationKey, name, type, event) => {
|
|
13739
|
-
const parent = _optionalChain([operations, 'access',
|
|
13857
|
+
const parent = _optionalChain([operations, 'access', _265 => _265.get, 'call', _266 => _266(operationKey), 'optionalAccess', _267 => _267.span]);
|
|
13740
13858
|
const spanArgs = {
|
|
13741
13859
|
name,
|
|
13742
13860
|
spanAttributes: { type },
|
|
@@ -13803,9 +13921,9 @@ function braintrustAISDKTelemetry() {
|
|
|
13803
13921
|
return keys[0];
|
|
13804
13922
|
}
|
|
13805
13923
|
const wrapperSpan = currentWorkflowAgentWrapperSpan();
|
|
13806
|
-
if (_optionalChain([wrapperSpan, 'optionalAccess',
|
|
13924
|
+
if (_optionalChain([wrapperSpan, 'optionalAccess', _268 => _268.spanId])) {
|
|
13807
13925
|
const key = keys.find(
|
|
13808
|
-
(candidate) => _optionalChain([operations, 'access',
|
|
13926
|
+
(candidate) => _optionalChain([operations, 'access', _269 => _269.get, 'call', _270 => _270(candidate), 'optionalAccess', _271 => _271.span, 'access', _272 => _272.spanId]) === wrapperSpan.spanId
|
|
13809
13927
|
);
|
|
13810
13928
|
if (key) {
|
|
13811
13929
|
return key;
|
|
@@ -13844,7 +13962,7 @@ function braintrustAISDKTelemetry() {
|
|
|
13844
13962
|
return workflowOperationKey;
|
|
13845
13963
|
}
|
|
13846
13964
|
const wrapperSpan = currentWorkflowAgentWrapperSpan();
|
|
13847
|
-
if (_optionalChain([wrapperSpan, 'optionalAccess',
|
|
13965
|
+
if (_optionalChain([wrapperSpan, 'optionalAccess', _273 => _273.spanId])) {
|
|
13848
13966
|
for (const [operationKey, state] of operations) {
|
|
13849
13967
|
if (state.operationName === "WorkflowAgent.stream" && state.span.spanId === wrapperSpan.spanId) {
|
|
13850
13968
|
return operationKey;
|
|
@@ -13852,7 +13970,7 @@ function braintrustAISDKTelemetry() {
|
|
|
13852
13970
|
}
|
|
13853
13971
|
}
|
|
13854
13972
|
const workflowAgentKeys = operationKeysByCallId.get("workflow-agent");
|
|
13855
|
-
if (_optionalChain([workflowAgentKeys, 'optionalAccess',
|
|
13973
|
+
if (_optionalChain([workflowAgentKeys, 'optionalAccess', _274 => _274.length]) === 1) {
|
|
13856
13974
|
return workflowAgentKeys[0];
|
|
13857
13975
|
}
|
|
13858
13976
|
if (operations.size === 1) {
|
|
@@ -13918,7 +14036,7 @@ function braintrustAISDKTelemetry() {
|
|
|
13918
14036
|
}
|
|
13919
14037
|
return new Error("AI SDK operation aborted");
|
|
13920
14038
|
};
|
|
13921
|
-
const shouldSkipTelemetryChildren = (state) => _optionalChain([state, 'optionalAccess',
|
|
14039
|
+
const shouldSkipTelemetryChildren = (state) => _optionalChain([state, 'optionalAccess', _275 => _275.operationName]) === "WorkflowAgent.stream" && !state.ownsSpan;
|
|
13922
14040
|
const onObjectStepEnd = (event) => {
|
|
13923
14041
|
runSafely("onObjectStepEnd", () => {
|
|
13924
14042
|
const operationKey = operationKeyFromEvent(event);
|
|
@@ -13971,7 +14089,7 @@ function braintrustAISDKTelemetry() {
|
|
|
13971
14089
|
return;
|
|
13972
14090
|
}
|
|
13973
14091
|
const result = {
|
|
13974
|
-
ranking: _optionalChain([event, 'access',
|
|
14092
|
+
ranking: _optionalChain([event, 'access', _276 => _276.ranking, 'optionalAccess', _277 => _277.map, 'call', _278 => _278((entry) => ({
|
|
13975
14093
|
originalIndex: entry.index,
|
|
13976
14094
|
score: entry.relevanceScore
|
|
13977
14095
|
}))])
|
|
@@ -14083,11 +14201,11 @@ function braintrustAISDKTelemetry() {
|
|
|
14083
14201
|
if (shouldSkipTelemetryChildren(state)) {
|
|
14084
14202
|
return;
|
|
14085
14203
|
}
|
|
14086
|
-
const operationName = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
14204
|
+
const operationName = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _279 => _279.operationName]), () => ( "generateText"));
|
|
14087
14205
|
const callInput = operationInput(event, operationName);
|
|
14088
14206
|
const workflowAgent = operationName === "WorkflowAgent.stream";
|
|
14089
14207
|
const processedInput = shouldRecordInputs(event) && workflowAgent ? processAISDKWorkflowAgentModelCallInput(callInput).input : shouldRecordInputs(event) ? processAISDKCallInput(callInput).input : void 0;
|
|
14090
|
-
if (workflowAgent && _optionalChain([state, 'optionalAccess',
|
|
14208
|
+
if (workflowAgent && _optionalChain([state, 'optionalAccess', _280 => _280.ownsSpan]) && !state.loggedInput && hasPromptLikeInput(processedInput)) {
|
|
14091
14209
|
state.span.log({
|
|
14092
14210
|
input: processedInput,
|
|
14093
14211
|
metadata: {
|
|
@@ -14135,8 +14253,8 @@ function braintrustAISDKTelemetry() {
|
|
|
14135
14253
|
if (!span) {
|
|
14136
14254
|
return;
|
|
14137
14255
|
}
|
|
14138
|
-
const timeToFirstOutputMs = _optionalChain([safePerformance, 'call',
|
|
14139
|
-
if (_optionalChain([state, 'optionalAccess',
|
|
14256
|
+
const timeToFirstOutputMs = _optionalChain([safePerformance, 'call', _281 => _281(event), 'optionalAccess', _282 => _282.timeToFirstOutputMs]);
|
|
14257
|
+
if (_optionalChain([state, 'optionalAccess', _283 => _283.operationName]) === "streamText" && state.firstChunkTime === void 0 && typeof timeToFirstOutputMs === "number") {
|
|
14140
14258
|
state.firstChunkTime = state.startTime + timeToFirstOutputMs / 1e3;
|
|
14141
14259
|
}
|
|
14142
14260
|
const result = {
|
|
@@ -14166,7 +14284,7 @@ function braintrustAISDKTelemetry() {
|
|
|
14166
14284
|
}
|
|
14167
14285
|
const span = startChildSpan(
|
|
14168
14286
|
_nullishCoalesce(operationKey, () => ( event.callId)),
|
|
14169
|
-
_optionalChain([state, 'optionalAccess',
|
|
14287
|
+
_optionalChain([state, 'optionalAccess', _284 => _284.operationName]) === "streamObject" ? "doStream" : "doGenerate",
|
|
14170
14288
|
"llm" /* LLM */,
|
|
14171
14289
|
{
|
|
14172
14290
|
...shouldRecordInputs(event) ? {
|
|
@@ -14189,7 +14307,7 @@ function braintrustAISDKTelemetry() {
|
|
|
14189
14307
|
return;
|
|
14190
14308
|
}
|
|
14191
14309
|
for (const [embedCallId, embedState] of embedSpans) {
|
|
14192
|
-
if (embedState.operationKey === operationKey && (_optionalChain([state, 'optionalAccess',
|
|
14310
|
+
if (embedState.operationKey === operationKey && (_optionalChain([state, 'optionalAccess', _285 => _285.operationName]) === "embed" || embedState.values === event.values)) {
|
|
14193
14311
|
embedState.span.end();
|
|
14194
14312
|
embedSpans.delete(embedCallId);
|
|
14195
14313
|
}
|
|
@@ -14284,8 +14402,8 @@ function braintrustAISDKTelemetry() {
|
|
|
14284
14402
|
}
|
|
14285
14403
|
const toolOutput = event.toolOutput;
|
|
14286
14404
|
const workflowToolError = event.success === false && "error" in event ? event.error : void 0;
|
|
14287
|
-
if (_optionalChain([toolOutput, 'optionalAccess',
|
|
14288
|
-
const error = _nullishCoalesce(_optionalChain([toolOutput, 'optionalAccess',
|
|
14405
|
+
if (_optionalChain([toolOutput, 'optionalAccess', _286 => _286.type]) === "tool-error" || workflowToolError !== void 0) {
|
|
14406
|
+
const error = _nullishCoalesce(_optionalChain([toolOutput, 'optionalAccess', _287 => _287.error]), () => ( workflowToolError));
|
|
14289
14407
|
state.span.log({
|
|
14290
14408
|
error: error instanceof Error ? error.message : String(error),
|
|
14291
14409
|
metrics: typeof event.durationMs === "number" ? { duration_ms: event.durationMs } : {}
|
|
@@ -14303,7 +14421,7 @@ function braintrustAISDKTelemetry() {
|
|
|
14303
14421
|
},
|
|
14304
14422
|
onChunk(event) {
|
|
14305
14423
|
runSafely("onChunk", () => {
|
|
14306
|
-
const callId = _optionalChain([event, 'access',
|
|
14424
|
+
const callId = _optionalChain([event, 'access', _288 => _288.chunk, 'optionalAccess', _289 => _289.callId]);
|
|
14307
14425
|
if (!callId) {
|
|
14308
14426
|
return;
|
|
14309
14427
|
}
|
|
@@ -14371,7 +14489,7 @@ function operationNameFromId(operationId) {
|
|
|
14371
14489
|
if (operationId === "ai.workflowAgent.stream") {
|
|
14372
14490
|
return "WorkflowAgent.stream";
|
|
14373
14491
|
}
|
|
14374
|
-
return _optionalChain([operationId, 'optionalAccess',
|
|
14492
|
+
return _optionalChain([operationId, 'optionalAccess', _290 => _290.startsWith, 'call', _291 => _291("ai.")]) ? operationId.slice("ai.".length) : operationId || "ai-sdk";
|
|
14375
14493
|
}
|
|
14376
14494
|
function modelFromEvent(event) {
|
|
14377
14495
|
return event.modelId ? {
|
|
@@ -14441,7 +14559,7 @@ function operationInput(event, operationName) {
|
|
|
14441
14559
|
}
|
|
14442
14560
|
function shiftModelSpan(modelSpans, callId) {
|
|
14443
14561
|
const spans = modelSpans.get(callId);
|
|
14444
|
-
const span = _optionalChain([spans, 'optionalAccess',
|
|
14562
|
+
const span = _optionalChain([spans, 'optionalAccess', _292 => _292.shift, 'call', _293 => _293()]);
|
|
14445
14563
|
if (spans && spans.length === 0) {
|
|
14446
14564
|
modelSpans.delete(callId);
|
|
14447
14565
|
}
|
|
@@ -14475,7 +14593,7 @@ function extractTimeToFirstToken(result, state) {
|
|
|
14475
14593
|
...Array.isArray(result.steps) ? (_nullishCoalesce(result.steps, () => ( []))).map(safePerformance) : []
|
|
14476
14594
|
];
|
|
14477
14595
|
for (const performance of performanceCandidates) {
|
|
14478
|
-
const timeToFirstOutputMs = _optionalChain([performance, 'optionalAccess',
|
|
14596
|
+
const timeToFirstOutputMs = _optionalChain([performance, 'optionalAccess', _294 => _294.timeToFirstOutputMs]);
|
|
14479
14597
|
if (typeof timeToFirstOutputMs === "number") {
|
|
14480
14598
|
return timeToFirstOutputMs / 1e3;
|
|
14481
14599
|
}
|
|
@@ -14574,6 +14692,24 @@ var aiSDKChannels = defineChannels("ai", {
|
|
|
14574
14692
|
kind: "sync-stream"
|
|
14575
14693
|
})
|
|
14576
14694
|
});
|
|
14695
|
+
var harnessAgentChannels = defineChannels("@ai-sdk/harness", {
|
|
14696
|
+
generate: channel({
|
|
14697
|
+
channelName: "HarnessAgent.generate",
|
|
14698
|
+
kind: "async"
|
|
14699
|
+
}),
|
|
14700
|
+
stream: channel({
|
|
14701
|
+
channelName: "HarnessAgent.stream",
|
|
14702
|
+
kind: "async"
|
|
14703
|
+
}),
|
|
14704
|
+
continueGenerate: channel({
|
|
14705
|
+
channelName: "HarnessAgent.continueGenerate",
|
|
14706
|
+
kind: "async"
|
|
14707
|
+
}),
|
|
14708
|
+
continueStream: channel({
|
|
14709
|
+
channelName: "HarnessAgent.continueStream",
|
|
14710
|
+
kind: "async"
|
|
14711
|
+
})
|
|
14712
|
+
});
|
|
14577
14713
|
|
|
14578
14714
|
// src/instrumentation/plugins/ai-sdk-plugin.ts
|
|
14579
14715
|
var DEFAULT_DENY_OUTPUT_PATHS = [
|
|
@@ -14842,6 +14978,84 @@ var AISDKPlugin = class extends BasePlugin {
|
|
|
14842
14978
|
})
|
|
14843
14979
|
})
|
|
14844
14980
|
);
|
|
14981
|
+
this.unsubscribers.push(
|
|
14982
|
+
traceStreamingChannel(harnessAgentChannels.generate, {
|
|
14983
|
+
name: "HarnessAgent.generate",
|
|
14984
|
+
type: "task" /* TASK */,
|
|
14985
|
+
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
14986
|
+
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
14987
|
+
result,
|
|
14988
|
+
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
14989
|
+
),
|
|
14990
|
+
extractMetrics: (result) => extractTokenMetrics(result),
|
|
14991
|
+
aggregateChunks: aggregateAISDKChunks
|
|
14992
|
+
})
|
|
14993
|
+
);
|
|
14994
|
+
this.unsubscribers.push(
|
|
14995
|
+
traceStreamingChannel(harnessAgentChannels.stream, {
|
|
14996
|
+
name: "HarnessAgent.stream",
|
|
14997
|
+
type: "task" /* TASK */,
|
|
14998
|
+
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
14999
|
+
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
15000
|
+
result,
|
|
15001
|
+
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
15002
|
+
),
|
|
15003
|
+
extractMetrics: (result, startTime) => ({
|
|
15004
|
+
...extractTokenMetrics(result),
|
|
15005
|
+
...startTime === void 0 ? {} : {
|
|
15006
|
+
time_to_first_token: getCurrentUnixTimestamp() - startTime
|
|
15007
|
+
}
|
|
15008
|
+
}),
|
|
15009
|
+
aggregateChunks: aggregateAISDKChunks,
|
|
15010
|
+
patchResult: ({ endEvent, result, span, startTime }) => patchAISDKStreamingResult({
|
|
15011
|
+
defaultDenyOutputPaths: denyOutputPaths,
|
|
15012
|
+
endEvent,
|
|
15013
|
+
result,
|
|
15014
|
+
resolvePromiseUsage: true,
|
|
15015
|
+
span,
|
|
15016
|
+
startTime
|
|
15017
|
+
})
|
|
15018
|
+
})
|
|
15019
|
+
);
|
|
15020
|
+
this.unsubscribers.push(
|
|
15021
|
+
traceStreamingChannel(harnessAgentChannels.continueGenerate, {
|
|
15022
|
+
name: "HarnessAgent.continueGenerate",
|
|
15023
|
+
type: "task" /* TASK */,
|
|
15024
|
+
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
15025
|
+
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
15026
|
+
result,
|
|
15027
|
+
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
15028
|
+
),
|
|
15029
|
+
extractMetrics: (result) => extractTokenMetrics(result),
|
|
15030
|
+
aggregateChunks: aggregateAISDKChunks
|
|
15031
|
+
})
|
|
15032
|
+
);
|
|
15033
|
+
this.unsubscribers.push(
|
|
15034
|
+
traceStreamingChannel(harnessAgentChannels.continueStream, {
|
|
15035
|
+
name: "HarnessAgent.continueStream",
|
|
15036
|
+
type: "task" /* TASK */,
|
|
15037
|
+
extractInput: ([params], event) => prepareAISDKHarnessAgentInput(params, event.self),
|
|
15038
|
+
extractOutput: (result, endEvent) => processAISDKOutput(
|
|
15039
|
+
result,
|
|
15040
|
+
resolveDenyOutputPaths(endEvent, denyOutputPaths)
|
|
15041
|
+
),
|
|
15042
|
+
extractMetrics: (result, startTime) => ({
|
|
15043
|
+
...extractTokenMetrics(result),
|
|
15044
|
+
...startTime === void 0 ? {} : {
|
|
15045
|
+
time_to_first_token: getCurrentUnixTimestamp() - startTime
|
|
15046
|
+
}
|
|
15047
|
+
}),
|
|
15048
|
+
aggregateChunks: aggregateAISDKChunks,
|
|
15049
|
+
patchResult: ({ endEvent, result, span, startTime }) => patchAISDKStreamingResult({
|
|
15050
|
+
defaultDenyOutputPaths: denyOutputPaths,
|
|
15051
|
+
endEvent,
|
|
15052
|
+
result,
|
|
15053
|
+
resolvePromiseUsage: true,
|
|
15054
|
+
span,
|
|
15055
|
+
startTime
|
|
15056
|
+
})
|
|
15057
|
+
})
|
|
15058
|
+
);
|
|
14845
15059
|
this.unsubscribers.push(
|
|
14846
15060
|
traceStreamingChannel(aiSDKChannels.toolLoopAgentGenerate, {
|
|
14847
15061
|
name: "ToolLoopAgent.generate",
|
|
@@ -14925,8 +15139,8 @@ function subscribeToAISDKV7TelemetryDispatcher() {
|
|
|
14925
15139
|
const telemetry = braintrustAISDKTelemetry();
|
|
14926
15140
|
const handlers = {
|
|
14927
15141
|
end: (event) => {
|
|
14928
|
-
const telemetryOptions = _optionalChain([event, 'access',
|
|
14929
|
-
if (_optionalChain([telemetryOptions, 'optionalAccess',
|
|
15142
|
+
const telemetryOptions = _optionalChain([event, 'access', _295 => _295.arguments, 'optionalAccess', _296 => _296[0], 'optionalAccess', _297 => _297.telemetry]);
|
|
15143
|
+
if (_optionalChain([telemetryOptions, 'optionalAccess', _298 => _298.isEnabled]) === false) {
|
|
14930
15144
|
return;
|
|
14931
15145
|
}
|
|
14932
15146
|
patchAISDKV7TelemetryDispatcher(
|
|
@@ -14952,13 +15166,13 @@ function patchAISDKV7TelemetryDispatcher(dispatcher, telemetry, telemetryOptions
|
|
|
14952
15166
|
dispatcherRecord[AUTO_PATCHED_V7_TELEMETRY_DISPATCHER] = true;
|
|
14953
15167
|
let operationKey;
|
|
14954
15168
|
const telemetryEventFields = {};
|
|
14955
|
-
if (typeof _optionalChain([telemetryOptions, 'optionalAccess',
|
|
15169
|
+
if (typeof _optionalChain([telemetryOptions, 'optionalAccess', _299 => _299.recordInputs]) === "boolean") {
|
|
14956
15170
|
telemetryEventFields.recordInputs = telemetryOptions.recordInputs;
|
|
14957
15171
|
}
|
|
14958
|
-
if (typeof _optionalChain([telemetryOptions, 'optionalAccess',
|
|
15172
|
+
if (typeof _optionalChain([telemetryOptions, 'optionalAccess', _300 => _300.recordOutputs]) === "boolean") {
|
|
14959
15173
|
telemetryEventFields.recordOutputs = telemetryOptions.recordOutputs;
|
|
14960
15174
|
}
|
|
14961
|
-
if (typeof _optionalChain([telemetryOptions, 'optionalAccess',
|
|
15175
|
+
if (typeof _optionalChain([telemetryOptions, 'optionalAccess', _301 => _301.functionId]) === "string") {
|
|
14962
15176
|
telemetryEventFields.functionId = telemetryOptions.functionId;
|
|
14963
15177
|
}
|
|
14964
15178
|
const eventWithOperationKey = (event) => {
|
|
@@ -15031,10 +15245,10 @@ function patchAISDKV7TelemetryDispatcher(dispatcher, telemetry, telemetryOptions
|
|
|
15031
15245
|
});
|
|
15032
15246
|
}
|
|
15033
15247
|
function resolveDenyOutputPaths(event, defaultDenyOutputPaths) {
|
|
15034
|
-
if (Array.isArray(_optionalChain([event, 'optionalAccess',
|
|
15248
|
+
if (Array.isArray(_optionalChain([event, 'optionalAccess', _302 => _302.denyOutputPaths]))) {
|
|
15035
15249
|
return event.denyOutputPaths;
|
|
15036
15250
|
}
|
|
15037
|
-
const firstArgument2 = _optionalChain([event, 'optionalAccess',
|
|
15251
|
+
const firstArgument2 = _optionalChain([event, 'optionalAccess', _303 => _303.arguments]) && event.arguments.length > 0 ? event.arguments[0] : void 0;
|
|
15038
15252
|
if (!firstArgument2 || typeof firstArgument2 !== "object") {
|
|
15039
15253
|
return defaultDenyOutputPaths;
|
|
15040
15254
|
}
|
|
@@ -15251,7 +15465,7 @@ var convertImageToAttachment = (image, explicitMimeType) => {
|
|
|
15251
15465
|
try {
|
|
15252
15466
|
if (typeof image === "string" && image.startsWith("data:")) {
|
|
15253
15467
|
const [mimeTypeSection, base64Data] = image.split(",");
|
|
15254
|
-
const mimeType = _optionalChain([mimeTypeSection, 'access',
|
|
15468
|
+
const mimeType = _optionalChain([mimeTypeSection, 'access', _304 => _304.match, 'call', _305 => _305(/data:(.*?);/), 'optionalAccess', _306 => _306[1]]);
|
|
15255
15469
|
if (mimeType && base64Data) {
|
|
15256
15470
|
const blob = convertDataToBlob(base64Data, mimeType);
|
|
15257
15471
|
if (blob) {
|
|
@@ -15372,6 +15586,45 @@ function prepareAISDKCallInput(params, event, span, defaultDenyOutputPaths, chil
|
|
|
15372
15586
|
metadata
|
|
15373
15587
|
};
|
|
15374
15588
|
}
|
|
15589
|
+
function prepareAISDKHarnessAgentInput(params, self) {
|
|
15590
|
+
if (isObject(self)) {
|
|
15591
|
+
try {
|
|
15592
|
+
if (isObject(self.settings)) {
|
|
15593
|
+
const settings = self.settings;
|
|
15594
|
+
if (settings.telemetry === void 0) {
|
|
15595
|
+
Reflect.set(self, "settings", { ...settings, telemetry: {} });
|
|
15596
|
+
}
|
|
15597
|
+
}
|
|
15598
|
+
} catch (e45) {
|
|
15599
|
+
}
|
|
15600
|
+
}
|
|
15601
|
+
const selectedInput = {};
|
|
15602
|
+
if (params.prompt !== void 0) {
|
|
15603
|
+
selectedInput.prompt = params.prompt;
|
|
15604
|
+
}
|
|
15605
|
+
if (params.messages !== void 0) {
|
|
15606
|
+
selectedInput.messages = params.messages;
|
|
15607
|
+
}
|
|
15608
|
+
if (params.toolApprovalContinuations !== void 0) {
|
|
15609
|
+
selectedInput.toolApprovalContinuations = params.toolApprovalContinuations;
|
|
15610
|
+
}
|
|
15611
|
+
const metadata = extractMetadataFromCallParams({}, self);
|
|
15612
|
+
if (isObject(params.session) && typeof params.session.sessionId === "string") {
|
|
15613
|
+
metadata.sessionId = params.session.sessionId;
|
|
15614
|
+
}
|
|
15615
|
+
if (isObject(self)) {
|
|
15616
|
+
if (typeof self.harnessId === "string") {
|
|
15617
|
+
metadata.harnessId = self.harnessId;
|
|
15618
|
+
}
|
|
15619
|
+
if (typeof self.permissionMode === "string") {
|
|
15620
|
+
metadata.permissionMode = self.permissionMode;
|
|
15621
|
+
}
|
|
15622
|
+
}
|
|
15623
|
+
return {
|
|
15624
|
+
input: processAISDKCallInput(selectedInput).input,
|
|
15625
|
+
metadata
|
|
15626
|
+
};
|
|
15627
|
+
}
|
|
15375
15628
|
function prepareAISDKWorkflowAgentStreamInput(params, event, span, defaultDenyOutputPaths) {
|
|
15376
15629
|
registerWorkflowAgentWrapperSpan(span);
|
|
15377
15630
|
const { input } = processAISDKWorkflowAgentCallInput(params);
|
|
@@ -15417,7 +15670,7 @@ function extractTopLevelAISDKMetrics(result, event, startTime) {
|
|
|
15417
15670
|
return metrics;
|
|
15418
15671
|
}
|
|
15419
15672
|
function hasModelChildTracing(event) {
|
|
15420
|
-
return _optionalChain([event, 'optionalAccess',
|
|
15673
|
+
return _optionalChain([event, 'optionalAccess', _307 => _307.modelWrapped]) === true || _optionalChain([event, 'optionalAccess', _308 => _308.__braintrust_ai_sdk_model_wrapped]) === true;
|
|
15421
15674
|
}
|
|
15422
15675
|
function serializeToolExecutionInput(args) {
|
|
15423
15676
|
return args.length > 0 ? args[0] : args;
|
|
@@ -15431,14 +15684,14 @@ function createAISDKIntegrationMetadata() {
|
|
|
15431
15684
|
};
|
|
15432
15685
|
}
|
|
15433
15686
|
function resolveModelFromSelf(self) {
|
|
15434
|
-
return self && typeof self === "object" && "model" in self && self.model ? self.model : self && typeof self === "object" && "settings" in self && _optionalChain([self, 'access',
|
|
15687
|
+
return self && typeof self === "object" && "model" in self && self.model ? self.model : self && typeof self === "object" && "settings" in self && _optionalChain([self, 'access', _309 => _309.settings, 'optionalAccess', _310 => _310.model]) ? _optionalChain([self, 'access', _311 => _311.settings, 'optionalAccess', _312 => _312.model]) : void 0;
|
|
15435
15688
|
}
|
|
15436
15689
|
function resolveToolsFromSelf(self) {
|
|
15437
15690
|
if (!self || typeof self !== "object") {
|
|
15438
15691
|
return void 0;
|
|
15439
15692
|
}
|
|
15440
15693
|
const selfRecord = self;
|
|
15441
|
-
return _nullishCoalesce(selfRecord.tools, () => ( _optionalChain([selfRecord, 'access',
|
|
15694
|
+
return _nullishCoalesce(selfRecord.tools, () => ( _optionalChain([selfRecord, 'access', _313 => _313.settings, 'optionalAccess', _314 => _314.tools])));
|
|
15442
15695
|
}
|
|
15443
15696
|
function extractBaseMetadata(model, self) {
|
|
15444
15697
|
const metadata = createAISDKIntegrationMetadata();
|
|
@@ -15643,7 +15896,7 @@ function activeAISDKChildPatchEntry(entries) {
|
|
|
15643
15896
|
if (activeSpanId) {
|
|
15644
15897
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
15645
15898
|
const entry = entries[index];
|
|
15646
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
15899
|
+
if (_optionalChain([entry, 'optionalAccess', _315 => _315.activeSpanIds, 'access', _316 => _316.has, 'call', _317 => _317(activeSpanId)])) {
|
|
15647
15900
|
return entry;
|
|
15648
15901
|
}
|
|
15649
15902
|
}
|
|
@@ -15651,13 +15904,13 @@ function activeAISDKChildPatchEntry(entries) {
|
|
|
15651
15904
|
const activeParentSpanIds = _nullishCoalesce(activeSpan.spanParents, () => ( []));
|
|
15652
15905
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
15653
15906
|
const entry = entries[index];
|
|
15654
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
15907
|
+
if (_optionalChain([entry, 'optionalAccess', _318 => _318.parentSpan, 'access', _319 => _319.spanId]) && activeParentSpanIds.includes(entry.parentSpan.spanId)) {
|
|
15655
15908
|
return entry;
|
|
15656
15909
|
}
|
|
15657
15910
|
}
|
|
15658
15911
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
15659
15912
|
const entry = entries[index];
|
|
15660
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
15913
|
+
if (_optionalChain([entry, 'optionalAccess', _320 => _320.parentSpan, 'access', _321 => _321.spanId]) === activeSpanId) {
|
|
15661
15914
|
return entry;
|
|
15662
15915
|
}
|
|
15663
15916
|
}
|
|
@@ -15670,7 +15923,7 @@ function attachNestedAISDKChildPatchEntry(entries, nestedSpan, cleanup) {
|
|
|
15670
15923
|
}
|
|
15671
15924
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
15672
15925
|
const entry = entries[index];
|
|
15673
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
15926
|
+
if (_optionalChain([entry, 'optionalAccess', _322 => _322.parentSpan, 'access', _323 => _323.spanId]) === activeSpanId || _optionalChain([entry, 'optionalAccess', _324 => _324.activeSpanIds, 'access', _325 => _325.has, 'call', _326 => _326(activeSpanId)])) {
|
|
15674
15927
|
entry.activeSpanIds.add(nestedSpan.spanId);
|
|
15675
15928
|
cleanup.push(() => {
|
|
15676
15929
|
entry.activeSpanIds.delete(nestedSpan.spanId);
|
|
@@ -15687,7 +15940,7 @@ function shadowActiveAISDKChildPatchEntry(entries, entry, nestedSpan, cleanup) {
|
|
|
15687
15940
|
}
|
|
15688
15941
|
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
15689
15942
|
const existingEntry = entries[index];
|
|
15690
|
-
if (_optionalChain([existingEntry, 'optionalAccess',
|
|
15943
|
+
if (_optionalChain([existingEntry, 'optionalAccess', _327 => _327.parentSpan, 'access', _328 => _328.spanId]) === activeSpanId || _optionalChain([existingEntry, 'optionalAccess', _329 => _329.activeSpanIds, 'access', _330 => _330.has, 'call', _331 => _331(activeSpanId)])) {
|
|
15691
15944
|
entry.activeSpanIds.add(activeSpanId);
|
|
15692
15945
|
cleanup.push(() => {
|
|
15693
15946
|
entry.activeSpanIds.delete(activeSpanId);
|
|
@@ -15929,9 +16182,9 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
15929
16182
|
case "raw":
|
|
15930
16183
|
if (chunk.rawValue) {
|
|
15931
16184
|
const rawVal = chunk.rawValue;
|
|
15932
|
-
if (_optionalChain([rawVal, 'access',
|
|
16185
|
+
if (_optionalChain([rawVal, 'access', _332 => _332.delta, 'optionalAccess', _333 => _333.content])) {
|
|
15933
16186
|
text += rawVal.delta.content;
|
|
15934
|
-
} else if (_optionalChain([rawVal, 'access',
|
|
16187
|
+
} else if (_optionalChain([rawVal, 'access', _334 => _334.choices, 'optionalAccess', _335 => _335[0], 'optionalAccess', _336 => _336.delta, 'optionalAccess', _337 => _337.content])) {
|
|
15935
16188
|
text += rawVal.choices[0].delta.content;
|
|
15936
16189
|
} else if (typeof rawVal.text === "string") {
|
|
15937
16190
|
text += rawVal.text;
|
|
@@ -16128,14 +16381,14 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
|
|
|
16128
16381
|
return {
|
|
16129
16382
|
cleanup: cleanup.length > 0 ? () => {
|
|
16130
16383
|
while (cleanup.length > 0) {
|
|
16131
|
-
_optionalChain([cleanup, 'access',
|
|
16384
|
+
_optionalChain([cleanup, 'access', _338 => _338.pop, 'call', _339 => _339(), 'optionalCall', _340 => _340()]);
|
|
16132
16385
|
}
|
|
16133
16386
|
} : void 0,
|
|
16134
16387
|
modelWrapped
|
|
16135
16388
|
};
|
|
16136
16389
|
}
|
|
16137
16390
|
function finalizeAISDKChildTracing(event) {
|
|
16138
|
-
const cleanup = _optionalChain([event, 'optionalAccess',
|
|
16391
|
+
const cleanup = _optionalChain([event, 'optionalAccess', _341 => _341.__braintrust_ai_sdk_cleanup]);
|
|
16139
16392
|
if (event && typeof cleanup === "function") {
|
|
16140
16393
|
cleanup();
|
|
16141
16394
|
delete event.__braintrust_ai_sdk_cleanup;
|
|
@@ -16219,6 +16472,7 @@ function patchAISDKStreamingResult(args) {
|
|
|
16219
16472
|
endEvent,
|
|
16220
16473
|
onComplete,
|
|
16221
16474
|
result,
|
|
16475
|
+
resolvePromiseUsage,
|
|
16222
16476
|
span,
|
|
16223
16477
|
startTime
|
|
16224
16478
|
} = args;
|
|
@@ -16235,7 +16489,7 @@ function patchAISDKStreamingResult(args) {
|
|
|
16235
16489
|
finalized = true;
|
|
16236
16490
|
finalizeAISDKChildTracing(endEvent);
|
|
16237
16491
|
span.end();
|
|
16238
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
16492
|
+
_optionalChain([onComplete, 'optionalCall', _342 => _342()]);
|
|
16239
16493
|
};
|
|
16240
16494
|
let outputLogged = false;
|
|
16241
16495
|
const logStreamingOutput = async (firstChunkTime) => {
|
|
@@ -16245,6 +16499,22 @@ function patchAISDKStreamingResult(args) {
|
|
|
16245
16499
|
outputLogged = true;
|
|
16246
16500
|
try {
|
|
16247
16501
|
const metrics = extractTopLevelAISDKMetrics(result, endEvent);
|
|
16502
|
+
if (resolvePromiseUsage) {
|
|
16503
|
+
try {
|
|
16504
|
+
const resultRecord2 = result;
|
|
16505
|
+
const pendingUsage = _nullishCoalesce(resultRecord2.totalUsage, () => ( resultRecord2.usage));
|
|
16506
|
+
if (isPromiseLike(pendingUsage)) {
|
|
16507
|
+
const usage = await Promise.resolve(pendingUsage);
|
|
16508
|
+
if (isObject(usage)) {
|
|
16509
|
+
Object.assign(
|
|
16510
|
+
metrics,
|
|
16511
|
+
extractTokenMetrics({ usage })
|
|
16512
|
+
);
|
|
16513
|
+
}
|
|
16514
|
+
}
|
|
16515
|
+
} catch (e46) {
|
|
16516
|
+
}
|
|
16517
|
+
}
|
|
16248
16518
|
if (metrics.time_to_first_token === void 0 && firstChunkTime !== void 0) {
|
|
16249
16519
|
metrics.time_to_first_token = firstChunkTime - startTime;
|
|
16250
16520
|
}
|
|
@@ -16313,7 +16583,7 @@ function patchAISDKStreamingResult(args) {
|
|
|
16313
16583
|
writable: descriptor.writable
|
|
16314
16584
|
});
|
|
16315
16585
|
return true;
|
|
16316
|
-
} catch (
|
|
16586
|
+
} catch (e47) {
|
|
16317
16587
|
return false;
|
|
16318
16588
|
}
|
|
16319
16589
|
}
|
|
@@ -16337,7 +16607,7 @@ function patchAISDKStreamingResult(args) {
|
|
|
16337
16607
|
} : {}
|
|
16338
16608
|
});
|
|
16339
16609
|
return true;
|
|
16340
|
-
} catch (
|
|
16610
|
+
} catch (e48) {
|
|
16341
16611
|
return false;
|
|
16342
16612
|
}
|
|
16343
16613
|
};
|
|
@@ -16424,7 +16694,7 @@ function attachKnownResultPromiseHandlers(result) {
|
|
|
16424
16694
|
void Promise.resolve(value).catch(() => {
|
|
16425
16695
|
});
|
|
16426
16696
|
}
|
|
16427
|
-
} catch (
|
|
16697
|
+
} catch (e49) {
|
|
16428
16698
|
}
|
|
16429
16699
|
}
|
|
16430
16700
|
}
|
|
@@ -16459,8 +16729,8 @@ function createPatchedReadableStream(stream, hooks) {
|
|
|
16459
16729
|
if (!completed) {
|
|
16460
16730
|
completed = true;
|
|
16461
16731
|
try {
|
|
16462
|
-
await _optionalChain([hooks, 'access',
|
|
16463
|
-
} catch (
|
|
16732
|
+
await _optionalChain([hooks, 'access', _343 => _343.onCancel, 'optionalCall', _344 => _344()]);
|
|
16733
|
+
} catch (e50) {
|
|
16464
16734
|
}
|
|
16465
16735
|
}
|
|
16466
16736
|
if (reader) {
|
|
@@ -16491,8 +16761,8 @@ function createPatchedAsyncIterable(stream, hooks) {
|
|
|
16491
16761
|
} finally {
|
|
16492
16762
|
if (!completed) {
|
|
16493
16763
|
try {
|
|
16494
|
-
await _optionalChain([hooks, 'access',
|
|
16495
|
-
} catch (
|
|
16764
|
+
await _optionalChain([hooks, 'access', _345 => _345.onCancel, 'optionalCall', _346 => _346()]);
|
|
16765
|
+
} catch (e51) {
|
|
16496
16766
|
}
|
|
16497
16767
|
}
|
|
16498
16768
|
}
|
|
@@ -16513,7 +16783,7 @@ async function processAISDKStreamingOutput(result, denyOutputPaths) {
|
|
|
16513
16783
|
outputRecord.text = resolvedText;
|
|
16514
16784
|
}
|
|
16515
16785
|
}
|
|
16516
|
-
} catch (
|
|
16786
|
+
} catch (e52) {
|
|
16517
16787
|
}
|
|
16518
16788
|
try {
|
|
16519
16789
|
if ("object" in result) {
|
|
@@ -16522,7 +16792,7 @@ async function processAISDKStreamingOutput(result, denyOutputPaths) {
|
|
|
16522
16792
|
outputRecord.object = resolvedObject;
|
|
16523
16793
|
}
|
|
16524
16794
|
}
|
|
16525
|
-
} catch (
|
|
16795
|
+
} catch (e53) {
|
|
16526
16796
|
}
|
|
16527
16797
|
try {
|
|
16528
16798
|
if ("finishReason" in result) {
|
|
@@ -16531,7 +16801,7 @@ async function processAISDKStreamingOutput(result, denyOutputPaths) {
|
|
|
16531
16801
|
outputRecord.finishReason = resolvedFinishReason;
|
|
16532
16802
|
}
|
|
16533
16803
|
}
|
|
16534
|
-
} catch (
|
|
16804
|
+
} catch (e54) {
|
|
16535
16805
|
}
|
|
16536
16806
|
return outputRecord;
|
|
16537
16807
|
}
|
|
@@ -16549,16 +16819,16 @@ function buildAISDKChildMetadata(model) {
|
|
|
16549
16819
|
function buildResolvedMetadataPayload(result) {
|
|
16550
16820
|
const gatewayInfo = extractGatewayRoutingInfo(result);
|
|
16551
16821
|
const metadata = {};
|
|
16552
|
-
if (_optionalChain([gatewayInfo, 'optionalAccess',
|
|
16822
|
+
if (_optionalChain([gatewayInfo, 'optionalAccess', _347 => _347.provider])) {
|
|
16553
16823
|
metadata.provider = gatewayInfo.provider;
|
|
16554
16824
|
}
|
|
16555
|
-
if (_optionalChain([gatewayInfo, 'optionalAccess',
|
|
16825
|
+
if (_optionalChain([gatewayInfo, 'optionalAccess', _348 => _348.model])) {
|
|
16556
16826
|
metadata.model = gatewayInfo.model;
|
|
16557
16827
|
}
|
|
16558
16828
|
let finishReason;
|
|
16559
16829
|
try {
|
|
16560
16830
|
finishReason = result.finishReason;
|
|
16561
|
-
} catch (
|
|
16831
|
+
} catch (e55) {
|
|
16562
16832
|
finishReason = void 0;
|
|
16563
16833
|
}
|
|
16564
16834
|
if (isPromiseLike(finishReason)) {
|
|
@@ -16607,7 +16877,7 @@ function resolveAISDKModel(model, aiSDK) {
|
|
|
16607
16877
|
if (typeof model !== "string") {
|
|
16608
16878
|
return model;
|
|
16609
16879
|
}
|
|
16610
|
-
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([aiSDK, 'optionalAccess',
|
|
16880
|
+
const provider = _nullishCoalesce(_nullishCoalesce(globalThis.AI_SDK_DEFAULT_PROVIDER, () => ( _optionalChain([aiSDK, 'optionalAccess', _349 => _349.gateway]))), () => ( null));
|
|
16611
16881
|
if (provider && typeof provider.languageModel === "function") {
|
|
16612
16882
|
return provider.languageModel(model);
|
|
16613
16883
|
}
|
|
@@ -16707,8 +16977,8 @@ function processAISDKRerankOutput(output, _denyOutputPaths) {
|
|
|
16707
16977
|
return ranking.slice(0, 100).map((item) => {
|
|
16708
16978
|
const entry = item && typeof item === "object" ? item : void 0;
|
|
16709
16979
|
return {
|
|
16710
|
-
index: typeof _optionalChain([entry, 'optionalAccess',
|
|
16711
|
-
relevance_score: typeof _optionalChain([entry, 'optionalAccess',
|
|
16980
|
+
index: typeof _optionalChain([entry, 'optionalAccess', _350 => _350.originalIndex]) === "number" ? entry.originalIndex : void 0,
|
|
16981
|
+
relevance_score: typeof _optionalChain([entry, 'optionalAccess', _351 => _351.score]) === "number" ? entry.score : void 0
|
|
16712
16982
|
};
|
|
16713
16983
|
});
|
|
16714
16984
|
}
|
|
@@ -16731,7 +17001,7 @@ function extractTokenMetrics(result) {
|
|
|
16731
17001
|
return metrics;
|
|
16732
17002
|
}
|
|
16733
17003
|
const promptTokens = firstNumber2(
|
|
16734
|
-
_optionalChain([usage, 'access',
|
|
17004
|
+
_optionalChain([usage, 'access', _352 => _352.inputTokens, 'optionalAccess', _353 => _353.total]),
|
|
16735
17005
|
usage.inputTokens,
|
|
16736
17006
|
usage.promptTokens,
|
|
16737
17007
|
usage.prompt_tokens
|
|
@@ -16740,7 +17010,7 @@ function extractTokenMetrics(result) {
|
|
|
16740
17010
|
metrics.prompt_tokens = promptTokens;
|
|
16741
17011
|
}
|
|
16742
17012
|
const completionTokens = firstNumber2(
|
|
16743
|
-
_optionalChain([usage, 'access',
|
|
17013
|
+
_optionalChain([usage, 'access', _354 => _354.outputTokens, 'optionalAccess', _355 => _355.total]),
|
|
16744
17014
|
usage.outputTokens,
|
|
16745
17015
|
usage.completionTokens,
|
|
16746
17016
|
usage.completion_tokens
|
|
@@ -16759,8 +17029,8 @@ function extractTokenMetrics(result) {
|
|
|
16759
17029
|
metrics.tokens = promptTokens + completionTokens;
|
|
16760
17030
|
}
|
|
16761
17031
|
const promptCachedTokens = firstNumber2(
|
|
16762
|
-
_optionalChain([usage, 'access',
|
|
16763
|
-
_optionalChain([usage, 'access',
|
|
17032
|
+
_optionalChain([usage, 'access', _356 => _356.inputTokens, 'optionalAccess', _357 => _357.cacheRead]),
|
|
17033
|
+
_optionalChain([usage, 'access', _358 => _358.inputTokenDetails, 'optionalAccess', _359 => _359.cacheReadTokens]),
|
|
16764
17034
|
usage.cachedInputTokens,
|
|
16765
17035
|
usage.promptCachedTokens,
|
|
16766
17036
|
usage.prompt_cached_tokens
|
|
@@ -16769,8 +17039,8 @@ function extractTokenMetrics(result) {
|
|
|
16769
17039
|
metrics.prompt_cached_tokens = promptCachedTokens;
|
|
16770
17040
|
}
|
|
16771
17041
|
const promptCacheCreationTokens = firstNumber2(
|
|
16772
|
-
_optionalChain([usage, 'access',
|
|
16773
|
-
_optionalChain([usage, 'access',
|
|
17042
|
+
_optionalChain([usage, 'access', _360 => _360.inputTokens, 'optionalAccess', _361 => _361.cacheWrite]),
|
|
17043
|
+
_optionalChain([usage, 'access', _362 => _362.inputTokenDetails, 'optionalAccess', _363 => _363.cacheWriteTokens]),
|
|
16774
17044
|
usage.promptCacheCreationTokens,
|
|
16775
17045
|
usage.prompt_cache_creation_tokens,
|
|
16776
17046
|
extractAnthropicCacheCreationTokens(result)
|
|
@@ -16793,7 +17063,7 @@ function extractTokenMetrics(result) {
|
|
|
16793
17063
|
metrics.completion_cached_tokens = completionCachedTokens;
|
|
16794
17064
|
}
|
|
16795
17065
|
const reasoningTokenCount = firstNumber2(
|
|
16796
|
-
_optionalChain([usage, 'access',
|
|
17066
|
+
_optionalChain([usage, 'access', _364 => _364.outputTokens, 'optionalAccess', _365 => _365.reasoning]),
|
|
16797
17067
|
usage.reasoningTokens,
|
|
16798
17068
|
usage.completionReasoningTokens,
|
|
16799
17069
|
usage.completion_reasoning_tokens,
|
|
@@ -16823,13 +17093,13 @@ function extractAnthropicCacheCreationTokens(result) {
|
|
|
16823
17093
|
result,
|
|
16824
17094
|
"providerMetadata"
|
|
16825
17095
|
);
|
|
16826
|
-
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess',
|
|
17096
|
+
const anthropicMetadata = _optionalChain([providerMetadata, 'optionalAccess', _366 => _366.anthropic]);
|
|
16827
17097
|
if (!anthropicMetadata) {
|
|
16828
17098
|
return void 0;
|
|
16829
17099
|
}
|
|
16830
17100
|
return firstNumber2(
|
|
16831
17101
|
anthropicMetadata.cacheCreationInputTokens,
|
|
16832
|
-
_optionalChain([anthropicMetadata, 'access',
|
|
17102
|
+
_optionalChain([anthropicMetadata, 'access', _367 => _367.usage, 'optionalAccess', _368 => _368.cache_creation_input_tokens])
|
|
16833
17103
|
);
|
|
16834
17104
|
}
|
|
16835
17105
|
function safeResultFieldRead(result, field) {
|
|
@@ -16837,14 +17107,14 @@ function safeResultFieldRead(result, field) {
|
|
|
16837
17107
|
}
|
|
16838
17108
|
function safeSerializableFieldRead(obj, field) {
|
|
16839
17109
|
try {
|
|
16840
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
17110
|
+
const value = _optionalChain([obj, 'optionalAccess', _369 => _369[field]]);
|
|
16841
17111
|
if (isPromiseLike(value)) {
|
|
16842
17112
|
void Promise.resolve(value).catch(() => {
|
|
16843
17113
|
});
|
|
16844
17114
|
return void 0;
|
|
16845
17115
|
}
|
|
16846
17116
|
return value;
|
|
16847
|
-
} catch (
|
|
17117
|
+
} catch (e56) {
|
|
16848
17118
|
return void 0;
|
|
16849
17119
|
}
|
|
16850
17120
|
}
|
|
@@ -16914,7 +17184,7 @@ function extractGetterValues(obj) {
|
|
|
16914
17184
|
if (isSerializableOutputValue(value)) {
|
|
16915
17185
|
getterValues[name] = value;
|
|
16916
17186
|
}
|
|
16917
|
-
} catch (
|
|
17187
|
+
} catch (e57) {
|
|
16918
17188
|
}
|
|
16919
17189
|
}
|
|
16920
17190
|
return getterValues;
|
|
@@ -16935,7 +17205,7 @@ function extractSerializableOutputFields(output) {
|
|
|
16935
17205
|
];
|
|
16936
17206
|
for (const name of directFieldNames) {
|
|
16937
17207
|
try {
|
|
16938
|
-
const value = _optionalChain([output, 'optionalAccess',
|
|
17208
|
+
const value = _optionalChain([output, 'optionalAccess', _370 => _370[name]]);
|
|
16939
17209
|
if (isPromiseLike(value)) {
|
|
16940
17210
|
void Promise.resolve(value).catch(() => {
|
|
16941
17211
|
});
|
|
@@ -16944,7 +17214,7 @@ function extractSerializableOutputFields(output) {
|
|
|
16944
17214
|
if (isSerializableOutputValue(value)) {
|
|
16945
17215
|
serialized[name] = value;
|
|
16946
17216
|
}
|
|
16947
|
-
} catch (
|
|
17217
|
+
} catch (e58) {
|
|
16948
17218
|
}
|
|
16949
17219
|
}
|
|
16950
17220
|
return {
|
|
@@ -16968,8 +17238,8 @@ function isSerializableOutputValue(value) {
|
|
|
16968
17238
|
return true;
|
|
16969
17239
|
}
|
|
16970
17240
|
function serializeModelWithProvider(model) {
|
|
16971
|
-
const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess',
|
|
16972
|
-
const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess',
|
|
17241
|
+
const modelId = typeof model === "string" ? model : _optionalChain([model, 'optionalAccess', _371 => _371.modelId]);
|
|
17242
|
+
const explicitProvider = typeof model === "object" ? _optionalChain([model, 'optionalAccess', _372 => _372.provider]) : void 0;
|
|
16973
17243
|
if (!modelId) {
|
|
16974
17244
|
return { model: modelId, provider: explicitProvider };
|
|
16975
17245
|
}
|
|
@@ -16995,7 +17265,7 @@ function parseGatewayModelString(modelString) {
|
|
|
16995
17265
|
function extractGatewayRoutingInfo(result) {
|
|
16996
17266
|
const steps = safeSerializableFieldRead(result, "steps");
|
|
16997
17267
|
if (Array.isArray(steps) && steps.length > 0) {
|
|
16998
|
-
const routing2 = _optionalChain([steps, 'access',
|
|
17268
|
+
const routing2 = _optionalChain([steps, 'access', _373 => _373[0], 'optionalAccess', _374 => _374.providerMetadata, 'optionalAccess', _375 => _375.gateway, 'optionalAccess', _376 => _376.routing]);
|
|
16999
17269
|
if (routing2) {
|
|
17000
17270
|
return {
|
|
17001
17271
|
provider: routing2.resolvedProvider || routing2.finalProvider,
|
|
@@ -17007,7 +17277,7 @@ function extractGatewayRoutingInfo(result) {
|
|
|
17007
17277
|
result,
|
|
17008
17278
|
"providerMetadata"
|
|
17009
17279
|
);
|
|
17010
|
-
const routing = _optionalChain([providerMetadata, 'optionalAccess',
|
|
17280
|
+
const routing = _optionalChain([providerMetadata, 'optionalAccess', _377 => _377.gateway, 'optionalAccess', _378 => _378.routing]);
|
|
17011
17281
|
if (routing) {
|
|
17012
17282
|
return {
|
|
17013
17283
|
provider: routing.resolvedProvider || routing.finalProvider,
|
|
@@ -17022,8 +17292,8 @@ function extractCostFromResult(result) {
|
|
|
17022
17292
|
let totalCost = 0;
|
|
17023
17293
|
let foundCost = false;
|
|
17024
17294
|
for (const step of steps) {
|
|
17025
|
-
const gateway2 = _optionalChain([step, 'optionalAccess',
|
|
17026
|
-
const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess',
|
|
17295
|
+
const gateway2 = _optionalChain([step, 'optionalAccess', _379 => _379.providerMetadata, 'optionalAccess', _380 => _380.gateway]);
|
|
17296
|
+
const stepCost = parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _381 => _381.cost])) || parseGatewayCost(_optionalChain([gateway2, 'optionalAccess', _382 => _382.marketCost]));
|
|
17027
17297
|
if (stepCost !== void 0 && stepCost > 0) {
|
|
17028
17298
|
totalCost += stepCost;
|
|
17029
17299
|
foundCost = true;
|
|
@@ -17037,8 +17307,8 @@ function extractCostFromResult(result) {
|
|
|
17037
17307
|
result,
|
|
17038
17308
|
"providerMetadata"
|
|
17039
17309
|
);
|
|
17040
|
-
const gateway = _optionalChain([providerMetadata, 'optionalAccess',
|
|
17041
|
-
const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess',
|
|
17310
|
+
const gateway = _optionalChain([providerMetadata, 'optionalAccess', _383 => _383.gateway]);
|
|
17311
|
+
const directCost = parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _384 => _384.cost])) || parseGatewayCost(_optionalChain([gateway, 'optionalAccess', _385 => _385.marketCost]));
|
|
17042
17312
|
if (directCost !== void 0 && directCost > 0) {
|
|
17043
17313
|
return directCost;
|
|
17044
17314
|
}
|
|
@@ -17221,7 +17491,7 @@ function setClaudeLocalToolParentResolver(resolver) {
|
|
|
17221
17491
|
context.resolveLocalToolParent = resolver;
|
|
17222
17492
|
}
|
|
17223
17493
|
function getClaudeLocalToolParentResolver() {
|
|
17224
|
-
return _nullishCoalesce(_optionalChain([localToolContextStore, 'access',
|
|
17494
|
+
return _nullishCoalesce(_optionalChain([localToolContextStore, 'access', _386 => _386.getStore, 'call', _387 => _387(), 'optionalAccess', _388 => _388.resolveLocalToolParent]), () => ( fallbackLocalToolParentResolver));
|
|
17225
17495
|
}
|
|
17226
17496
|
function isAsyncIterable3(value) {
|
|
17227
17497
|
return value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
|
|
@@ -17512,10 +17782,10 @@ function upsertSubAgentDetails(detailsByToolUseId, toolUseId, update) {
|
|
|
17512
17782
|
return merged;
|
|
17513
17783
|
}
|
|
17514
17784
|
function formatSubAgentSpanName(details) {
|
|
17515
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
17785
|
+
if (_optionalChain([details, 'optionalAccess', _389 => _389.description])) {
|
|
17516
17786
|
return `Agent: ${details.description}`;
|
|
17517
17787
|
}
|
|
17518
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
17788
|
+
if (_optionalChain([details, 'optionalAccess', _390 => _390.agentType])) {
|
|
17519
17789
|
return `Agent: ${details.agentType}`;
|
|
17520
17790
|
}
|
|
17521
17791
|
return "Agent: sub-agent";
|
|
@@ -17570,7 +17840,7 @@ function extractUsageFromMessage(message) {
|
|
|
17570
17840
|
const metrics = {};
|
|
17571
17841
|
let usage;
|
|
17572
17842
|
if (message.type === "assistant") {
|
|
17573
|
-
usage = _optionalChain([message, 'access',
|
|
17843
|
+
usage = _optionalChain([message, 'access', _391 => _391.message, 'optionalAccess', _392 => _392.usage]);
|
|
17574
17844
|
} else if (message.type === "result") {
|
|
17575
17845
|
usage = message.usage;
|
|
17576
17846
|
}
|
|
@@ -17603,15 +17873,15 @@ function buildLLMInput(promptMessages, conversationHistory) {
|
|
|
17603
17873
|
return inputParts.length > 0 ? inputParts : void 0;
|
|
17604
17874
|
}
|
|
17605
17875
|
function conversationMessageFromSDKMessage(message) {
|
|
17606
|
-
const role = _optionalChain([message, 'access',
|
|
17607
|
-
const content = _optionalChain([message, 'access',
|
|
17876
|
+
const role = _optionalChain([message, 'access', _393 => _393.message, 'optionalAccess', _394 => _394.role]);
|
|
17877
|
+
const content = _optionalChain([message, 'access', _395 => _395.message, 'optionalAccess', _396 => _396.content]);
|
|
17608
17878
|
if (role && content !== void 0) {
|
|
17609
17879
|
return { content, role };
|
|
17610
17880
|
}
|
|
17611
17881
|
return void 0;
|
|
17612
17882
|
}
|
|
17613
17883
|
function messageContentHasBlockType(message, blockType) {
|
|
17614
|
-
const content = _optionalChain([message, 'access',
|
|
17884
|
+
const content = _optionalChain([message, 'access', _397 => _397.message, 'optionalAccess', _398 => _398.content]);
|
|
17615
17885
|
return Array.isArray(content) && content.some(
|
|
17616
17886
|
(block) => typeof block === "object" && block !== null && "type" in block && block.type === blockType
|
|
17617
17887
|
);
|
|
@@ -17635,14 +17905,14 @@ async function createLLMSpanForMessages(messages, promptMessages, conversationHi
|
|
|
17635
17905
|
return void 0;
|
|
17636
17906
|
}
|
|
17637
17907
|
const lastMessage = messages[messages.length - 1];
|
|
17638
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
17908
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _399 => _399.message, 'optionalAccess', _400 => _400.usage])) {
|
|
17639
17909
|
return void 0;
|
|
17640
17910
|
}
|
|
17641
17911
|
const model = lastMessage.message.model || options.model;
|
|
17642
17912
|
const usage = extractUsageFromMessage(lastMessage);
|
|
17643
17913
|
const input = buildLLMInput(promptMessages, conversationHistory);
|
|
17644
17914
|
const outputs = messages.map(
|
|
17645
|
-
(m) => _optionalChain([m, 'access',
|
|
17915
|
+
(m) => _optionalChain([m, 'access', _401 => _401.message, 'optionalAccess', _402 => _402.content]) && _optionalChain([m, 'access', _403 => _403.message, 'optionalAccess', _404 => _404.role]) ? { content: m.message.content, role: m.message.role } : void 0
|
|
17646
17916
|
).filter(
|
|
17647
17917
|
(c) => c !== void 0
|
|
17648
17918
|
);
|
|
@@ -17662,7 +17932,7 @@ async function createLLMSpanForMessages(messages, promptMessages, conversationHi
|
|
|
17662
17932
|
});
|
|
17663
17933
|
const spanExport = await span.export();
|
|
17664
17934
|
await span.end();
|
|
17665
|
-
const finalMessage = _optionalChain([lastMessage, 'access',
|
|
17935
|
+
const finalMessage = _optionalChain([lastMessage, 'access', _405 => _405.message, 'optionalAccess', _406 => _406.content]) && _optionalChain([lastMessage, 'access', _407 => _407.message, 'optionalAccess', _408 => _408.role]) ? { content: lastMessage.message.content, role: lastMessage.message.role } : void 0;
|
|
17666
17936
|
return {
|
|
17667
17937
|
finalMessage,
|
|
17668
17938
|
spanExport
|
|
@@ -17798,18 +18068,18 @@ function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers,
|
|
|
17798
18068
|
subAgentDetailsByToolUseId.get(toolUseID)
|
|
17799
18069
|
)
|
|
17800
18070
|
};
|
|
17801
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18071
|
+
if (_optionalChain([response, 'optionalAccess', _409 => _409.status])) {
|
|
17802
18072
|
metadata["claude_agent_sdk.status"] = response.status;
|
|
17803
18073
|
}
|
|
17804
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18074
|
+
if (_optionalChain([response, 'optionalAccess', _410 => _410.totalDurationMs])) {
|
|
17805
18075
|
metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
|
|
17806
18076
|
}
|
|
17807
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18077
|
+
if (_optionalChain([response, 'optionalAccess', _411 => _411.totalToolUseCount]) !== void 0) {
|
|
17808
18078
|
metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
|
|
17809
18079
|
}
|
|
17810
18080
|
subAgentSpan.log({
|
|
17811
18081
|
metadata,
|
|
17812
|
-
output: _optionalChain([response, 'optionalAccess',
|
|
18082
|
+
output: _optionalChain([response, 'optionalAccess', _412 => _412.content])
|
|
17813
18083
|
});
|
|
17814
18084
|
} finally {
|
|
17815
18085
|
subAgentSpan.end();
|
|
@@ -18041,7 +18311,7 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
18041
18311
|
if (state.currentMessages.length === 0) {
|
|
18042
18312
|
return;
|
|
18043
18313
|
}
|
|
18044
|
-
const parentToolUseId = _nullishCoalesce(_optionalChain([state, 'access',
|
|
18314
|
+
const parentToolUseId = _nullishCoalesce(_optionalChain([state, 'access', _413 => _413.currentMessages, 'access', _414 => _414[0], 'optionalAccess', _415 => _415.parent_tool_use_id]), () => ( null));
|
|
18045
18315
|
const parentKey = llmParentKey(parentToolUseId);
|
|
18046
18316
|
const conversationHistory = getConversationHistory(state, parentKey);
|
|
18047
18317
|
const promptMessages = parentToolUseId ? _nullishCoalesce(state.promptMessagesByParentKey.get(parentKey), () => ( [])) : buildRootPromptMessages(
|
|
@@ -18081,14 +18351,14 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
18081
18351
|
}
|
|
18082
18352
|
state.activeLlmSpansByParentToolUse.delete(parentKey);
|
|
18083
18353
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
18084
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
18354
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _416 => _416.message, 'optionalAccess', _417 => _417.usage])) {
|
|
18085
18355
|
state.accumulatedOutputTokens += getNumberProperty(lastMessage.message.usage, "output_tokens") || 0;
|
|
18086
18356
|
}
|
|
18087
18357
|
state.currentMessages.length = 0;
|
|
18088
18358
|
}
|
|
18089
18359
|
function maybeTrackToolUseContext(state, message) {
|
|
18090
18360
|
seedTaskToolUseIdMapping(state.taskIdToToolUseId, message);
|
|
18091
|
-
if (message.type !== "assistant" || !Array.isArray(_optionalChain([message, 'access',
|
|
18361
|
+
if (message.type !== "assistant" || !Array.isArray(_optionalChain([message, 'access', _418 => _418.message, 'optionalAccess', _419 => _419.content]))) {
|
|
18092
18362
|
return;
|
|
18093
18363
|
}
|
|
18094
18364
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
@@ -18291,7 +18561,7 @@ async function handleStreamMessage(state, message) {
|
|
|
18291
18561
|
const messageParentToolUseId = message.parent_tool_use_id;
|
|
18292
18562
|
if (messageParentToolUseId && message.type === "user") {
|
|
18293
18563
|
const conversationMessage = conversationMessageFromSDKMessage(message);
|
|
18294
|
-
if (_optionalChain([conversationMessage, 'optionalAccess',
|
|
18564
|
+
if (_optionalChain([conversationMessage, 'optionalAccess', _420 => _420.role]) === "user") {
|
|
18295
18565
|
await finalizeCurrentMessageGroup(state);
|
|
18296
18566
|
const parentKey = llmParentKey(messageParentToolUseId);
|
|
18297
18567
|
const conversationHistory = getConversationHistory(state, parentKey);
|
|
@@ -18310,13 +18580,13 @@ async function handleStreamMessage(state, message) {
|
|
|
18310
18580
|
return;
|
|
18311
18581
|
}
|
|
18312
18582
|
}
|
|
18313
|
-
const messageId = _optionalChain([message, 'access',
|
|
18583
|
+
const messageId = _optionalChain([message, 'access', _421 => _421.message, 'optionalAccess', _422 => _422.id]);
|
|
18314
18584
|
if (messageId && messageId !== state.currentMessageId) {
|
|
18315
18585
|
await finalizeCurrentMessageGroup(state);
|
|
18316
18586
|
state.currentMessageId = messageId;
|
|
18317
18587
|
state.currentMessageStartTime = getCurrentUnixTimestamp();
|
|
18318
18588
|
}
|
|
18319
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
18589
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _423 => _423.message, 'optionalAccess', _424 => _424.usage])) {
|
|
18320
18590
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
18321
18591
|
await ensureActiveLlmSpanForParentToolUse(
|
|
18322
18592
|
state.span,
|
|
@@ -18335,7 +18605,7 @@ async function handleStreamMessage(state, message) {
|
|
|
18335
18605
|
const finalUsageMetrics = extractUsageFromMessage(message);
|
|
18336
18606
|
if (state.currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
18337
18607
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
18338
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
18608
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _425 => _425.message, 'optionalAccess', _426 => _426.usage])) {
|
|
18339
18609
|
const adjustedTokens = finalUsageMetrics.completion_tokens - state.accumulatedOutputTokens;
|
|
18340
18610
|
if (adjustedTokens >= 0) {
|
|
18341
18611
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -18440,7 +18710,7 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
18440
18710
|
yield message;
|
|
18441
18711
|
}
|
|
18442
18712
|
} finally {
|
|
18443
|
-
_optionalChain([resolvePromptDone, 'optionalCall',
|
|
18713
|
+
_optionalChain([resolvePromptDone, 'optionalCall', _427 => _427()]);
|
|
18444
18714
|
}
|
|
18445
18715
|
})();
|
|
18446
18716
|
}
|
|
@@ -18478,7 +18748,7 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
18478
18748
|
const skipLocalToolHooks = options[CLAUDE_AGENT_SDK_SKIP_LOCAL_TOOL_HOOKS_OPTION] === true || hasLocalToolHandlers;
|
|
18479
18749
|
const resolveToolUseParentSpan = async (toolUseID, context) => {
|
|
18480
18750
|
const trackedParentToolUseId = toolUseToParent.get(toolUseID);
|
|
18481
|
-
const parentToolUseId = _nullishCoalesce(trackedParentToolUseId, () => ( (_optionalChain([context, 'optionalAccess',
|
|
18751
|
+
const parentToolUseId = _nullishCoalesce(trackedParentToolUseId, () => ( (_optionalChain([context, 'optionalAccess', _428 => _428.agentId]) ? _nullishCoalesce(taskIdToToolUseId.get(context.agentId), () => ( null)) : null)));
|
|
18482
18752
|
const parentKey = llmParentKey(parentToolUseId);
|
|
18483
18753
|
const activeLlmSpan = activeLlmSpansByParentToolUse.get(parentKey);
|
|
18484
18754
|
const latestLlmParent = parentToolUseId ? latestLlmParentBySubAgentToolUse.get(parentToolUseId) : latestRootLlmParentRef.value;
|
|
@@ -18707,7 +18977,7 @@ var CursorSDKPlugin = (_class18 = class extends BasePlugin {constructor(...args3
|
|
|
18707
18977
|
...extractRunResultMetadata(event.result)
|
|
18708
18978
|
},
|
|
18709
18979
|
metrics: buildDurationMetrics2(state.startTime),
|
|
18710
|
-
output: _nullishCoalesce(_optionalChain([event, 'access',
|
|
18980
|
+
output: _nullishCoalesce(_optionalChain([event, 'access', _429 => _429.result, 'optionalAccess', _430 => _430.result]), () => ( event.result))
|
|
18711
18981
|
});
|
|
18712
18982
|
} finally {
|
|
18713
18983
|
state.span.end();
|
|
@@ -18841,7 +19111,7 @@ function patchCursorAgentInPlace(agent) {
|
|
|
18841
19111
|
},
|
|
18842
19112
|
writable: true
|
|
18843
19113
|
});
|
|
18844
|
-
} catch (
|
|
19114
|
+
} catch (e59) {
|
|
18845
19115
|
}
|
|
18846
19116
|
}
|
|
18847
19117
|
function wrapSendOptionsCallbacks(options, state) {
|
|
@@ -18935,7 +19205,7 @@ function patchCursorRun(run, state) {
|
|
|
18935
19205
|
writable: true
|
|
18936
19206
|
});
|
|
18937
19207
|
}
|
|
18938
|
-
} catch (
|
|
19208
|
+
} catch (e60) {
|
|
18939
19209
|
void finalizeCursorRun(state, { output: run });
|
|
18940
19210
|
}
|
|
18941
19211
|
}
|
|
@@ -19028,9 +19298,9 @@ async function handleToolUpdate(state, update) {
|
|
|
19028
19298
|
toolCall
|
|
19029
19299
|
})));
|
|
19030
19300
|
finishToolSpan(toolState, {
|
|
19031
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
19301
|
+
error: _optionalChain([toolCall, 'optionalAccess', _431 => _431.status]) === "error" ? toLoggedError(result) : void 0,
|
|
19032
19302
|
metadata: {
|
|
19033
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
19303
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _432 => _432.status]), () => ( "completed"))
|
|
19034
19304
|
},
|
|
19035
19305
|
output: result
|
|
19036
19306
|
});
|
|
@@ -19051,10 +19321,10 @@ async function handleStreamMessage2(state, message) {
|
|
|
19051
19321
|
}
|
|
19052
19322
|
if (message.type === "assistant") {
|
|
19053
19323
|
const assistantMessage = message;
|
|
19054
|
-
for (const block of _nullishCoalesce(_optionalChain([assistantMessage, 'access',
|
|
19055
|
-
if (_optionalChain([block, 'optionalAccess',
|
|
19324
|
+
for (const block of _nullishCoalesce(_optionalChain([assistantMessage, 'access', _433 => _433.message, 'optionalAccess', _434 => _434.content]), () => ( []))) {
|
|
19325
|
+
if (_optionalChain([block, 'optionalAccess', _435 => _435.type]) === "text" && typeof block.text === "string") {
|
|
19056
19326
|
state.streamText.push(block.text);
|
|
19057
|
-
} else if (_optionalChain([block, 'optionalAccess',
|
|
19327
|
+
} else if (_optionalChain([block, 'optionalAccess', _436 => _436.type]) === "tool_use" && block.id) {
|
|
19058
19328
|
state.activeToolSpans.set(
|
|
19059
19329
|
block.id,
|
|
19060
19330
|
await startToolSpan(state, {
|
|
@@ -19123,29 +19393,29 @@ async function handleConversation(state, turns) {
|
|
|
19123
19393
|
state.conversationOutput = turns;
|
|
19124
19394
|
for (const turn of turns) {
|
|
19125
19395
|
if (turn.type === "agentConversationTurn") {
|
|
19126
|
-
for (const step of _nullishCoalesce(_optionalChain([turn, 'access',
|
|
19396
|
+
for (const step of _nullishCoalesce(_optionalChain([turn, 'access', _437 => _437.turn, 'optionalAccess', _438 => _438.steps]), () => ( []))) {
|
|
19127
19397
|
await handleConversationStep(state, step);
|
|
19128
19398
|
}
|
|
19129
19399
|
} else if (turn.type === "shellConversationTurn") {
|
|
19130
|
-
const command = _optionalChain([turn, 'access',
|
|
19400
|
+
const command = _optionalChain([turn, 'access', _439 => _439.turn, 'optionalAccess', _440 => _440.shellCommand, 'optionalAccess', _441 => _441.command]);
|
|
19131
19401
|
if (command) {
|
|
19132
19402
|
const callId = `shell:${state.activeToolSpans.size}:${command}`;
|
|
19133
19403
|
const toolState = await startToolSpan(state, {
|
|
19134
|
-
args: _optionalChain([turn, 'access',
|
|
19404
|
+
args: _optionalChain([turn, 'access', _442 => _442.turn, 'optionalAccess', _443 => _443.shellCommand]),
|
|
19135
19405
|
callId,
|
|
19136
19406
|
name: "shell",
|
|
19137
19407
|
status: "completed"
|
|
19138
19408
|
});
|
|
19139
19409
|
finishToolSpan(toolState, {
|
|
19140
19410
|
metadata: { "cursor_sdk.tool.status": "completed" },
|
|
19141
|
-
output: _optionalChain([turn, 'access',
|
|
19411
|
+
output: _optionalChain([turn, 'access', _444 => _444.turn, 'optionalAccess', _445 => _445.shellOutput])
|
|
19142
19412
|
});
|
|
19143
19413
|
}
|
|
19144
19414
|
}
|
|
19145
19415
|
}
|
|
19146
19416
|
}
|
|
19147
19417
|
async function handleConversationStep(state, step) {
|
|
19148
|
-
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access',
|
|
19418
|
+
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access', _446 => _446.message, 'optionalAccess', _447 => _447.text]) === "string") {
|
|
19149
19419
|
state.conversationText.push(step.message.text);
|
|
19150
19420
|
return;
|
|
19151
19421
|
}
|
|
@@ -19153,18 +19423,18 @@ async function handleConversationStep(state, step) {
|
|
|
19153
19423
|
return;
|
|
19154
19424
|
}
|
|
19155
19425
|
const toolCall = step.message;
|
|
19156
|
-
const callId = typeof _optionalChain([toolCall, 'optionalAccess',
|
|
19426
|
+
const callId = typeof _optionalChain([toolCall, 'optionalAccess', _448 => _448.callId]) === "string" ? toolCall.callId : `conversation-tool:${state.activeToolSpans.size}`;
|
|
19157
19427
|
const toolState = await startToolSpan(state, {
|
|
19158
19428
|
args: extractToolArgs(toolCall),
|
|
19159
19429
|
callId,
|
|
19160
19430
|
name: extractToolName(toolCall),
|
|
19161
|
-
status: _optionalChain([toolCall, 'optionalAccess',
|
|
19431
|
+
status: _optionalChain([toolCall, 'optionalAccess', _449 => _449.status]),
|
|
19162
19432
|
toolCall
|
|
19163
19433
|
});
|
|
19164
19434
|
finishToolSpan(toolState, {
|
|
19165
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
19435
|
+
error: _optionalChain([toolCall, 'optionalAccess', _450 => _450.status]) === "error" ? toLoggedError(toolCall.result) : void 0,
|
|
19166
19436
|
metadata: {
|
|
19167
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
19437
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _451 => _451.status]), () => ( "completed"))
|
|
19168
19438
|
},
|
|
19169
19439
|
output: extractToolResult(toolCall)
|
|
19170
19440
|
});
|
|
@@ -19181,7 +19451,7 @@ function handleStepUpdate(state, step) {
|
|
|
19181
19451
|
state.metadata["cursor_sdk.step_types"] = [step.type];
|
|
19182
19452
|
}
|
|
19183
19453
|
}
|
|
19184
|
-
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access',
|
|
19454
|
+
if (step.type === "assistantMessage" && typeof _optionalChain([step, 'access', _452 => _452.message, 'optionalAccess', _453 => _453.text]) === "string") {
|
|
19185
19455
|
state.stepText.push(step.message.text);
|
|
19186
19456
|
}
|
|
19187
19457
|
}
|
|
@@ -19192,10 +19462,10 @@ async function startToolSpan(state, args) {
|
|
|
19192
19462
|
"gen_ai.tool.call.id": args.callId,
|
|
19193
19463
|
"gen_ai.tool.name": name
|
|
19194
19464
|
};
|
|
19195
|
-
if (_optionalChain([args, 'access',
|
|
19465
|
+
if (_optionalChain([args, 'access', _454 => _454.truncated, 'optionalAccess', _455 => _455.args]) !== void 0) {
|
|
19196
19466
|
metadata["cursor_sdk.tool.args_truncated"] = args.truncated.args;
|
|
19197
19467
|
}
|
|
19198
|
-
if (_optionalChain([args, 'access',
|
|
19468
|
+
if (_optionalChain([args, 'access', _456 => _456.truncated, 'optionalAccess', _457 => _457.result]) !== void 0) {
|
|
19199
19469
|
metadata["cursor_sdk.tool.result_truncated"] = args.truncated.result;
|
|
19200
19470
|
}
|
|
19201
19471
|
const span = startSpan({
|
|
@@ -19252,7 +19522,7 @@ function finishToolSpan(toolState, result) {
|
|
|
19252
19522
|
}
|
|
19253
19523
|
}
|
|
19254
19524
|
} finally {
|
|
19255
|
-
_optionalChain([toolState, 'access',
|
|
19525
|
+
_optionalChain([toolState, 'access', _458 => _458.subAgentSpan, 'optionalAccess', _459 => _459.end, 'call', _460 => _460()]);
|
|
19256
19526
|
toolState.span.end();
|
|
19257
19527
|
}
|
|
19258
19528
|
}
|
|
@@ -19263,7 +19533,7 @@ async function finalizeCursorRun(state, params = {}) {
|
|
|
19263
19533
|
state.finalized = true;
|
|
19264
19534
|
const error = params.error;
|
|
19265
19535
|
const result = _nullishCoalesce(params.result, () => ( state.lastResult));
|
|
19266
|
-
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(params.output, () => ( _optionalChain([result, 'optionalAccess',
|
|
19536
|
+
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(params.output, () => ( _optionalChain([result, 'optionalAccess', _461 => _461.result]))), () => ( _optionalChain([state, 'access', _462 => _462.run, 'optionalAccess', _463 => _463.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)));
|
|
19267
19537
|
try {
|
|
19268
19538
|
const metadata = {
|
|
19269
19539
|
...state.metadata,
|
|
@@ -19307,7 +19577,7 @@ function sanitizeUserMessage(message) {
|
|
|
19307
19577
|
}
|
|
19308
19578
|
return {
|
|
19309
19579
|
...message,
|
|
19310
|
-
images: _optionalChain([message, 'access',
|
|
19580
|
+
images: _optionalChain([message, 'access', _464 => _464.images, 'optionalAccess', _465 => _465.map, 'call', _466 => _466((image) => {
|
|
19311
19581
|
const imageRecord = image;
|
|
19312
19582
|
return {
|
|
19313
19583
|
...typeof imageRecord.url === "string" ? { url: imageRecord.url } : {},
|
|
@@ -19333,9 +19603,9 @@ function extractAgentOptionsMetadata(options) {
|
|
|
19333
19603
|
...options.cloud ? {
|
|
19334
19604
|
"cursor_sdk.runtime": "cloud",
|
|
19335
19605
|
"cursor_sdk.cloud.auto_create_pr": options.cloud.autoCreatePR,
|
|
19336
|
-
"cursor_sdk.cloud.env_type": _optionalChain([options, 'access',
|
|
19337
|
-
"cursor_sdk.cloud.env_name": _optionalChain([options, 'access',
|
|
19338
|
-
"cursor_sdk.cloud.repos": _optionalChain([options, 'access',
|
|
19606
|
+
"cursor_sdk.cloud.env_type": _optionalChain([options, 'access', _467 => _467.cloud, 'access', _468 => _468.env, 'optionalAccess', _469 => _469.type]),
|
|
19607
|
+
"cursor_sdk.cloud.env_name": _optionalChain([options, 'access', _470 => _470.cloud, 'access', _471 => _471.env, 'optionalAccess', _472 => _472.name]),
|
|
19608
|
+
"cursor_sdk.cloud.repos": _optionalChain([options, 'access', _473 => _473.cloud, 'access', _474 => _474.repos, 'optionalAccess', _475 => _475.map, 'call', _476 => _476((repo) => repo.url), 'access', _477 => _477.filter, 'call', _478 => _478((url) => typeof url === "string")])
|
|
19339
19609
|
} : {}
|
|
19340
19610
|
};
|
|
19341
19611
|
}
|
|
@@ -19345,7 +19615,7 @@ function extractSendMetadata(options) {
|
|
|
19345
19615
|
}
|
|
19346
19616
|
return {
|
|
19347
19617
|
...extractModelMetadata(options.model),
|
|
19348
|
-
..._optionalChain([options, 'access',
|
|
19618
|
+
..._optionalChain([options, 'access', _479 => _479.local, 'optionalAccess', _480 => _480.force]) !== void 0 ? { "cursor_sdk.local.force": options.local.force } : {}
|
|
19349
19619
|
};
|
|
19350
19620
|
}
|
|
19351
19621
|
function extractAgentMetadata(agent) {
|
|
@@ -19380,7 +19650,7 @@ function extractRunResultMetadata(result) {
|
|
|
19380
19650
|
};
|
|
19381
19651
|
}
|
|
19382
19652
|
function extractGitMetadata(git) {
|
|
19383
|
-
const branches = _optionalChain([git, 'optionalAccess',
|
|
19653
|
+
const branches = _optionalChain([git, 'optionalAccess', _481 => _481.branches]);
|
|
19384
19654
|
if (!branches || branches.length === 0) {
|
|
19385
19655
|
return {};
|
|
19386
19656
|
}
|
|
@@ -19393,7 +19663,7 @@ function extractGitMetadata(git) {
|
|
|
19393
19663
|
};
|
|
19394
19664
|
}
|
|
19395
19665
|
function extractModelMetadata(model) {
|
|
19396
|
-
if (!_optionalChain([model, 'optionalAccess',
|
|
19666
|
+
if (!_optionalChain([model, 'optionalAccess', _482 => _482.id])) {
|
|
19397
19667
|
return {};
|
|
19398
19668
|
}
|
|
19399
19669
|
return {
|
|
@@ -19455,7 +19725,7 @@ function formatSubAgentSpanName2(toolCall, args) {
|
|
|
19455
19725
|
return description ? `Agent: ${description}` : "Agent: sub-agent";
|
|
19456
19726
|
}
|
|
19457
19727
|
function getString(obj, key) {
|
|
19458
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
19728
|
+
const value = _optionalChain([obj, 'optionalAccess', _483 => _483[key]]);
|
|
19459
19729
|
return typeof value === "string" ? value : void 0;
|
|
19460
19730
|
}
|
|
19461
19731
|
function safeLog2(span, event) {
|
|
@@ -19605,7 +19875,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19605
19875
|
}
|
|
19606
19876
|
}
|
|
19607
19877
|
onTraceStart(trace) {
|
|
19608
|
-
if (!_optionalChain([trace, 'optionalAccess',
|
|
19878
|
+
if (!_optionalChain([trace, 'optionalAccess', _484 => _484.traceId])) {
|
|
19609
19879
|
return Promise.resolve();
|
|
19610
19880
|
}
|
|
19611
19881
|
if (this.traceOrder.length >= this.maxTraces) {
|
|
@@ -19641,7 +19911,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19641
19911
|
return Promise.resolve();
|
|
19642
19912
|
}
|
|
19643
19913
|
async onTraceEnd(trace) {
|
|
19644
|
-
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess',
|
|
19914
|
+
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess', _485 => _485.traceId]));
|
|
19645
19915
|
if (!traceData) {
|
|
19646
19916
|
return;
|
|
19647
19917
|
}
|
|
@@ -19661,7 +19931,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19661
19931
|
}
|
|
19662
19932
|
}
|
|
19663
19933
|
onSpanStart(span) {
|
|
19664
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
19934
|
+
if (!_optionalChain([span, 'optionalAccess', _486 => _486.spanId]) || !span.traceId) {
|
|
19665
19935
|
return Promise.resolve();
|
|
19666
19936
|
}
|
|
19667
19937
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -19680,7 +19950,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19680
19950
|
return Promise.resolve();
|
|
19681
19951
|
}
|
|
19682
19952
|
onSpanEnd(span) {
|
|
19683
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
19953
|
+
if (!_optionalChain([span, 'optionalAccess', _487 => _487.spanId]) || !span.traceId) {
|
|
19684
19954
|
return Promise.resolve();
|
|
19685
19955
|
}
|
|
19686
19956
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -20055,7 +20325,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20055
20325
|
};
|
|
20056
20326
|
tracingChannel2.subscribe(handlers);
|
|
20057
20327
|
this.unsubscribers.push(() => {
|
|
20058
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
20328
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _488 => _488()]);
|
|
20059
20329
|
tracingChannel2.unsubscribe(handlers);
|
|
20060
20330
|
});
|
|
20061
20331
|
}
|
|
@@ -20152,7 +20422,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20152
20422
|
};
|
|
20153
20423
|
tracingChannel2.subscribe(handlers);
|
|
20154
20424
|
this.unsubscribers.push(() => {
|
|
20155
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
20425
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _489 => _489()]);
|
|
20156
20426
|
tracingChannel2.unsubscribe(handlers);
|
|
20157
20427
|
});
|
|
20158
20428
|
}
|
|
@@ -20178,7 +20448,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20178
20448
|
}
|
|
20179
20449
|
};
|
|
20180
20450
|
function isBackgroundInteractionCreate(params) {
|
|
20181
|
-
return _optionalChain([tryToDict, 'call',
|
|
20451
|
+
return _optionalChain([tryToDict, 'call', _490 => _490(params), 'optionalAccess', _491 => _491.background]) === true;
|
|
20182
20452
|
}
|
|
20183
20453
|
function ensureSpanState(states, event, create) {
|
|
20184
20454
|
const existing = states.get(event);
|
|
@@ -20191,10 +20461,10 @@ function ensureSpanState(states, event, create) {
|
|
|
20191
20461
|
}
|
|
20192
20462
|
function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
20193
20463
|
const state = _internalGetGlobalState();
|
|
20194
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
20464
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _492 => _492.contextManager]);
|
|
20195
20465
|
const startChannel = tracingChannel2.start;
|
|
20196
20466
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
20197
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
20467
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _493 => _493.bindStore]) || !currentSpanStore) {
|
|
20198
20468
|
return void 0;
|
|
20199
20469
|
}
|
|
20200
20470
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -20206,7 +20476,7 @@ function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
|
20206
20476
|
return contextManager.wrapSpanForStore(span);
|
|
20207
20477
|
});
|
|
20208
20478
|
return () => {
|
|
20209
|
-
_optionalChain([startChannel, 'access',
|
|
20479
|
+
_optionalChain([startChannel, 'access', _494 => _494.unbindStore, 'optionalCall', _495 => _495(currentSpanStore)]);
|
|
20210
20480
|
};
|
|
20211
20481
|
}
|
|
20212
20482
|
function logErrorAndEndSpan(states, event) {
|
|
@@ -20535,7 +20805,7 @@ function createAttachmentFromInlineData(data, mimeType) {
|
|
|
20535
20805
|
}
|
|
20536
20806
|
function serializeGenerateContentTools(params) {
|
|
20537
20807
|
const config = params.config ? tryToDict(params.config) : null;
|
|
20538
|
-
const tools = _optionalChain([config, 'optionalAccess',
|
|
20808
|
+
const tools = _optionalChain([config, 'optionalAccess', _496 => _496.tools]);
|
|
20539
20809
|
if (!Array.isArray(tools)) {
|
|
20540
20810
|
return null;
|
|
20541
20811
|
}
|
|
@@ -20548,7 +20818,7 @@ function serializeGenerateContentTools(params) {
|
|
|
20548
20818
|
}
|
|
20549
20819
|
}
|
|
20550
20820
|
return serializedTools.length > 0 ? serializedTools : null;
|
|
20551
|
-
} catch (
|
|
20821
|
+
} catch (e61) {
|
|
20552
20822
|
return null;
|
|
20553
20823
|
}
|
|
20554
20824
|
}
|
|
@@ -20594,7 +20864,7 @@ function extractGenerateContentMetrics(response, startTime) {
|
|
|
20594
20864
|
metrics.end = end;
|
|
20595
20865
|
metrics.duration = end - startTime;
|
|
20596
20866
|
}
|
|
20597
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20867
|
+
if (_optionalChain([response, 'optionalAccess', _497 => _497.usageMetadata])) {
|
|
20598
20868
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
20599
20869
|
}
|
|
20600
20870
|
return metrics;
|
|
@@ -20607,7 +20877,7 @@ function extractEmbedContentMetrics(response, startTime) {
|
|
|
20607
20877
|
metrics.end = end;
|
|
20608
20878
|
metrics.duration = end - startTime;
|
|
20609
20879
|
}
|
|
20610
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20880
|
+
if (_optionalChain([response, 'optionalAccess', _498 => _498.usageMetadata])) {
|
|
20611
20881
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
20612
20882
|
}
|
|
20613
20883
|
const embeddingTokenCount = extractEmbedPromptTokenCount(response);
|
|
@@ -20625,7 +20895,7 @@ function extractInteractionMetrics(response, startTime) {
|
|
|
20625
20895
|
metrics.end = end;
|
|
20626
20896
|
metrics.duration = end - startTime;
|
|
20627
20897
|
}
|
|
20628
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20898
|
+
if (_optionalChain([response, 'optionalAccess', _499 => _499.usage])) {
|
|
20629
20899
|
populateInteractionUsageMetrics(metrics, response.usage);
|
|
20630
20900
|
}
|
|
20631
20901
|
return metrics;
|
|
@@ -20648,11 +20918,11 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
20648
20918
|
if (!response) {
|
|
20649
20919
|
return void 0;
|
|
20650
20920
|
}
|
|
20651
|
-
const usagePromptTokens = _optionalChain([response, 'access',
|
|
20921
|
+
const usagePromptTokens = _optionalChain([response, 'access', _500 => _500.usageMetadata, 'optionalAccess', _501 => _501.promptTokenCount]);
|
|
20652
20922
|
if (typeof usagePromptTokens === "number" && Number.isFinite(usagePromptTokens)) {
|
|
20653
20923
|
return usagePromptTokens;
|
|
20654
20924
|
}
|
|
20655
|
-
const usageTotalTokens = _optionalChain([response, 'access',
|
|
20925
|
+
const usageTotalTokens = _optionalChain([response, 'access', _502 => _502.usageMetadata, 'optionalAccess', _503 => _503.totalTokenCount]);
|
|
20656
20926
|
if (typeof usageTotalTokens === "number" && Number.isFinite(usageTotalTokens)) {
|
|
20657
20927
|
return usageTotalTokens;
|
|
20658
20928
|
}
|
|
@@ -20663,8 +20933,8 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
20663
20933
|
let total = 0;
|
|
20664
20934
|
let sawAny = false;
|
|
20665
20935
|
for (const embedding of embeddings) {
|
|
20666
|
-
const embeddingStats = tryToDict(_optionalChain([tryToDict, 'call',
|
|
20667
|
-
const tokenCount = _optionalChain([embeddingStats, 'optionalAccess',
|
|
20936
|
+
const embeddingStats = tryToDict(_optionalChain([tryToDict, 'call', _504 => _504(embedding), 'optionalAccess', _505 => _505.statistics]));
|
|
20937
|
+
const tokenCount = _optionalChain([embeddingStats, 'optionalAccess', _506 => _506.tokenCount]);
|
|
20668
20938
|
if (typeof tokenCount === "number" && Number.isFinite(tokenCount)) {
|
|
20669
20939
|
total += tokenCount;
|
|
20670
20940
|
sawAny = true;
|
|
@@ -20680,7 +20950,7 @@ function summarizeEmbedContentOutput(response) {
|
|
|
20680
20950
|
if (embeddings.length === 0) {
|
|
20681
20951
|
return void 0;
|
|
20682
20952
|
}
|
|
20683
|
-
const firstValues = _optionalChain([embeddings, 'access',
|
|
20953
|
+
const firstValues = _optionalChain([embeddings, 'access', _507 => _507[0], 'optionalAccess', _508 => _508.values]);
|
|
20684
20954
|
if (!Array.isArray(firstValues)) {
|
|
20685
20955
|
return void 0;
|
|
20686
20956
|
}
|
|
@@ -20752,7 +21022,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
20752
21022
|
}
|
|
20753
21023
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
20754
21024
|
for (const candidate of chunk.candidates) {
|
|
20755
|
-
if (_optionalChain([candidate, 'access',
|
|
21025
|
+
if (_optionalChain([candidate, 'access', _509 => _509.content, 'optionalAccess', _510 => _510.parts])) {
|
|
20756
21026
|
for (const part of candidate.content.parts) {
|
|
20757
21027
|
if (part.text !== void 0) {
|
|
20758
21028
|
if (part.thought) {
|
|
@@ -20783,7 +21053,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
20783
21053
|
parts.push({ text });
|
|
20784
21054
|
}
|
|
20785
21055
|
parts.push(...otherParts);
|
|
20786
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
21056
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _511 => _511.candidates])) {
|
|
20787
21057
|
const candidates = [];
|
|
20788
21058
|
for (const candidate of lastResponse.candidates) {
|
|
20789
21059
|
const candidateDict = {
|
|
@@ -20905,16 +21175,16 @@ function aggregateInteractionEvents(chunks, startTime) {
|
|
|
20905
21175
|
}
|
|
20906
21176
|
function extractInteractionUsageFromEvent(event) {
|
|
20907
21177
|
const metadata = tryToDict(event.metadata);
|
|
20908
|
-
const metadataUsage = tryToDict(_optionalChain([metadata, 'optionalAccess',
|
|
21178
|
+
const metadataUsage = tryToDict(_optionalChain([metadata, 'optionalAccess', _512 => _512.usage]));
|
|
20909
21179
|
if (metadataUsage) {
|
|
20910
21180
|
return metadataUsage;
|
|
20911
21181
|
}
|
|
20912
|
-
const metadataTotalUsage = tryToDict(_optionalChain([metadata, 'optionalAccess',
|
|
21182
|
+
const metadataTotalUsage = tryToDict(_optionalChain([metadata, 'optionalAccess', _513 => _513.total_usage]));
|
|
20913
21183
|
if (metadataTotalUsage) {
|
|
20914
21184
|
return metadataTotalUsage;
|
|
20915
21185
|
}
|
|
20916
21186
|
const interaction = tryToDict(event.interaction);
|
|
20917
|
-
const interactionUsage = tryToDict(_optionalChain([interaction, 'optionalAccess',
|
|
21187
|
+
const interactionUsage = tryToDict(_optionalChain([interaction, 'optionalAccess', _514 => _514.usage]));
|
|
20918
21188
|
return interactionUsage ? interactionUsage : void 0;
|
|
20919
21189
|
}
|
|
20920
21190
|
function compactInteractionStep(step) {
|
|
@@ -20980,7 +21250,7 @@ function extractResponseMetadata(response) {
|
|
|
20980
21250
|
if (Array.isArray(responseDict.candidates)) {
|
|
20981
21251
|
for (const candidate of responseDict.candidates) {
|
|
20982
21252
|
const candidateDict = tryToDict(candidate);
|
|
20983
|
-
if (_optionalChain([candidateDict, 'optionalAccess',
|
|
21253
|
+
if (_optionalChain([candidateDict, 'optionalAccess', _515 => _515.groundingMetadata]) !== void 0) {
|
|
20984
21254
|
candidateGroundingMetadata.push(candidateDict.groundingMetadata);
|
|
20985
21255
|
}
|
|
20986
21256
|
}
|
|
@@ -21061,9 +21331,9 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
21061
21331
|
name: "huggingface.chat_completion",
|
|
21062
21332
|
type: "llm" /* LLM */,
|
|
21063
21333
|
extractInput: extractChatInputWithMetadata,
|
|
21064
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
21334
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _516 => _516.choices]),
|
|
21065
21335
|
extractMetadata: (result) => extractResponseMetadata2(result),
|
|
21066
|
-
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
21336
|
+
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _517 => _517.usage]))
|
|
21067
21337
|
}),
|
|
21068
21338
|
traceSyncStreamChannel(huggingFaceChannels.chatCompletionStream, {
|
|
21069
21339
|
name: "huggingface.chat_completion_stream",
|
|
@@ -21081,7 +21351,7 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
21081
21351
|
extractInput: extractTextGenerationInputWithMetadata,
|
|
21082
21352
|
extractOutput: (result) => isObject(result) ? { generated_text: result.generated_text } : result,
|
|
21083
21353
|
extractMetadata: extractTextGenerationMetadata,
|
|
21084
|
-
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
21354
|
+
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _518 => _518.details]), () => ( null)))
|
|
21085
21355
|
}),
|
|
21086
21356
|
traceSyncStreamChannel(huggingFaceChannels.textGenerationStream, {
|
|
21087
21357
|
name: "huggingface.text_generation_stream",
|
|
@@ -21200,7 +21470,7 @@ function extractTextGenerationMetrics(details) {
|
|
|
21200
21470
|
return metrics;
|
|
21201
21471
|
}
|
|
21202
21472
|
function extractTextGenerationMetadata(result) {
|
|
21203
|
-
if (!isObject(_optionalChain([result, 'optionalAccess',
|
|
21473
|
+
if (!isObject(_optionalChain([result, 'optionalAccess', _519 => _519.details]))) {
|
|
21204
21474
|
return void 0;
|
|
21205
21475
|
}
|
|
21206
21476
|
return typeof result.details.finish_reason === "string" ? {
|
|
@@ -21246,7 +21516,7 @@ function patchChatCompletionStream(args) {
|
|
|
21246
21516
|
const lastChunk = chunks.at(-1);
|
|
21247
21517
|
const responseMetadata = extractResponseMetadata2(lastChunk);
|
|
21248
21518
|
const metrics = {
|
|
21249
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
21519
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _520 => _520.usage])),
|
|
21250
21520
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
21251
21521
|
};
|
|
21252
21522
|
span.log({
|
|
@@ -21284,8 +21554,8 @@ function patchTextGenerationStream(args) {
|
|
|
21284
21554
|
output: aggregateTextGenerationStreamChunks(chunks),
|
|
21285
21555
|
...streamMetadata ? { metadata: streamMetadata } : {},
|
|
21286
21556
|
metrics: {
|
|
21287
|
-
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess',
|
|
21288
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
21557
|
+
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess', _521 => _521.details]), () => ( null))),
|
|
21558
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _522 => _522.usage])),
|
|
21289
21559
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
21290
21560
|
}
|
|
21291
21561
|
});
|
|
@@ -21314,14 +21584,14 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
21314
21584
|
}));
|
|
21315
21585
|
const delta = isObject(choice.delta) ? choice.delta : void 0;
|
|
21316
21586
|
const message = isObject(choice.message) ? choice.message : void 0;
|
|
21317
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
21587
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _523 => _523.content]) === "string") {
|
|
21318
21588
|
existing.content += delta.content;
|
|
21319
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
21589
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _524 => _524.content]) === "string") {
|
|
21320
21590
|
existing.content = message.content;
|
|
21321
21591
|
}
|
|
21322
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
21592
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _525 => _525.role]) === "string") {
|
|
21323
21593
|
existing.role = delta.role;
|
|
21324
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
21594
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _526 => _526.role]) === "string") {
|
|
21325
21595
|
existing.role = message.role;
|
|
21326
21596
|
}
|
|
21327
21597
|
if (choice.finish_reason !== void 0) {
|
|
@@ -21349,7 +21619,7 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
21349
21619
|
};
|
|
21350
21620
|
}
|
|
21351
21621
|
function getChatToolCallDeltas(value) {
|
|
21352
|
-
if (!Array.isArray(_optionalChain([value, 'optionalAccess',
|
|
21622
|
+
if (!Array.isArray(_optionalChain([value, 'optionalAccess', _527 => _527.tool_calls]))) {
|
|
21353
21623
|
return void 0;
|
|
21354
21624
|
}
|
|
21355
21625
|
const toolCalls = value.tool_calls.filter((toolCall) => isObject(toolCall));
|
|
@@ -21414,7 +21684,7 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
21414
21684
|
for (const chunk of chunks) {
|
|
21415
21685
|
if (typeof chunk.generated_text === "string") {
|
|
21416
21686
|
generatedText = chunk.generated_text;
|
|
21417
|
-
} else if (typeof _optionalChain([chunk, 'access',
|
|
21687
|
+
} else if (typeof _optionalChain([chunk, 'access', _528 => _528.token, 'optionalAccess', _529 => _529.text]) === "string" && !chunk.token.special) {
|
|
21418
21688
|
generatedText += chunk.token.text;
|
|
21419
21689
|
} else if (Array.isArray(chunk.choices)) {
|
|
21420
21690
|
for (const choice of chunk.choices) {
|
|
@@ -21438,17 +21708,17 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
21438
21708
|
function extractTextGenerationStreamMetadata(chunks) {
|
|
21439
21709
|
for (let index = chunks.length - 1; index >= 0; index--) {
|
|
21440
21710
|
const chunk = chunks[index];
|
|
21441
|
-
if (isObject(_optionalChain([chunk, 'optionalAccess',
|
|
21711
|
+
if (isObject(_optionalChain([chunk, 'optionalAccess', _530 => _530.details])) && typeof chunk.details.finish_reason === "string") {
|
|
21442
21712
|
return {
|
|
21443
21713
|
finish_reason: chunk.details.finish_reason
|
|
21444
21714
|
};
|
|
21445
21715
|
}
|
|
21446
|
-
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess',
|
|
21716
|
+
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess', _531 => _531.choices]))) {
|
|
21447
21717
|
continue;
|
|
21448
21718
|
}
|
|
21449
21719
|
for (let choiceIndex = chunk.choices.length - 1; choiceIndex >= 0; choiceIndex--) {
|
|
21450
21720
|
const choice = chunk.choices[choiceIndex];
|
|
21451
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
21721
|
+
if (_optionalChain([choice, 'optionalAccess', _532 => _532.finish_reason]) !== void 0) {
|
|
21452
21722
|
return { finish_reason: choice.finish_reason };
|
|
21453
21723
|
}
|
|
21454
21724
|
}
|
|
@@ -21524,14 +21794,14 @@ var OpenRouterAgentPlugin = class extends BasePlugin {
|
|
|
21524
21794
|
extractMetadata: (result, event) => {
|
|
21525
21795
|
if (!isObject(result)) {
|
|
21526
21796
|
return {
|
|
21527
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
21528
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
21797
|
+
step: _optionalChain([event, 'optionalAccess', _533 => _533.step]),
|
|
21798
|
+
step_type: _optionalChain([event, 'optionalAccess', _534 => _534.stepType])
|
|
21529
21799
|
};
|
|
21530
21800
|
}
|
|
21531
21801
|
return {
|
|
21532
21802
|
...extractOpenRouterResponseMetadata(result) || {},
|
|
21533
|
-
..._optionalChain([event, 'optionalAccess',
|
|
21534
|
-
..._optionalChain([event, 'optionalAccess',
|
|
21803
|
+
..._optionalChain([event, 'optionalAccess', _535 => _535.step]) !== void 0 ? { step: event.step } : {},
|
|
21804
|
+
..._optionalChain([event, 'optionalAccess', _536 => _536.stepType]) ? { step_type: event.stepType } : {}
|
|
21535
21805
|
};
|
|
21536
21806
|
},
|
|
21537
21807
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage(result.usage) : {}
|
|
@@ -21686,7 +21956,7 @@ function isZodSchema3(value) {
|
|
|
21686
21956
|
function serializeZodSchema3(schema) {
|
|
21687
21957
|
try {
|
|
21688
21958
|
return zodToJsonSchema(schema);
|
|
21689
|
-
} catch (
|
|
21959
|
+
} catch (e62) {
|
|
21690
21960
|
return {
|
|
21691
21961
|
type: "object",
|
|
21692
21962
|
description: "Zod schema (conversion failed)"
|
|
@@ -21892,7 +22162,7 @@ function publishToolResult(tracingChannel2, event, result) {
|
|
|
21892
22162
|
}
|
|
21893
22163
|
function getToolCallId(context) {
|
|
21894
22164
|
const toolContext = context;
|
|
21895
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
22165
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _537 => _537.toolCall, 'optionalAccess', _538 => _538.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
21896
22166
|
}
|
|
21897
22167
|
var OPENROUTER_WRAPPED_CALL_MODEL_RESULT = /* @__PURE__ */ Symbol(
|
|
21898
22168
|
"braintrust.openrouter.wrappedCallModelResult"
|
|
@@ -21983,7 +22253,7 @@ function patchOpenRouterCallModelResult(args) {
|
|
|
21983
22253
|
}
|
|
21984
22254
|
try {
|
|
21985
22255
|
await endSpanWithResult(await originalGetResponse(), fallbackOutput);
|
|
21986
|
-
} catch (
|
|
22256
|
+
} catch (e63) {
|
|
21987
22257
|
await endSpanWithResult(void 0, fallbackOutput);
|
|
21988
22258
|
}
|
|
21989
22259
|
};
|
|
@@ -22288,9 +22558,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22288
22558
|
type: "llm" /* LLM */,
|
|
22289
22559
|
extractInput: (args) => {
|
|
22290
22560
|
const request = getOpenRouterRequestArg(args);
|
|
22291
|
-
const chatGenerationParams = isObject(_optionalChain([request, 'optionalAccess',
|
|
22292
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22293
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
22561
|
+
const chatGenerationParams = isObject(_optionalChain([request, 'optionalAccess', _539 => _539.chatGenerationParams])) ? request.chatGenerationParams : {};
|
|
22562
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _540 => _540.httpReferer]);
|
|
22563
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _541 => _541.xTitle]);
|
|
22294
22564
|
const { messages, ...metadata } = chatGenerationParams;
|
|
22295
22565
|
return {
|
|
22296
22566
|
input: messages,
|
|
@@ -22301,7 +22571,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22301
22571
|
return isObject(result) ? result.choices : void 0;
|
|
22302
22572
|
},
|
|
22303
22573
|
extractMetrics: (result, startTime) => {
|
|
22304
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
22574
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _542 => _542.usage]));
|
|
22305
22575
|
if (startTime) {
|
|
22306
22576
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
22307
22577
|
}
|
|
@@ -22316,9 +22586,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22316
22586
|
type: "llm" /* LLM */,
|
|
22317
22587
|
extractInput: (args) => {
|
|
22318
22588
|
const request = getOpenRouterRequestArg(args);
|
|
22319
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
22320
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22321
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
22589
|
+
const requestBody = isObject(_optionalChain([request, 'optionalAccess', _543 => _543.requestBody])) ? request.requestBody : {};
|
|
22590
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _544 => _544.httpReferer]);
|
|
22591
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _545 => _545.xTitle]);
|
|
22322
22592
|
const { input, ...metadata } = requestBody;
|
|
22323
22593
|
return {
|
|
22324
22594
|
input,
|
|
@@ -22333,7 +22603,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22333
22603
|
if (!isObject(result)) {
|
|
22334
22604
|
return void 0;
|
|
22335
22605
|
}
|
|
22336
|
-
const embedding = _optionalChain([result, 'access',
|
|
22606
|
+
const embedding = _optionalChain([result, 'access', _546 => _546.data, 'optionalAccess', _547 => _547[0], 'optionalAccess', _548 => _548.embedding]);
|
|
22337
22607
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
22338
22608
|
},
|
|
22339
22609
|
extractMetadata: (result) => {
|
|
@@ -22353,9 +22623,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22353
22623
|
type: "llm" /* LLM */,
|
|
22354
22624
|
extractInput: (args) => {
|
|
22355
22625
|
const request = getOpenRouterRequestArg(args);
|
|
22356
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
22357
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22358
|
-
const xTitle = _nullishCoalesce(_optionalChain([request, 'optionalAccess',
|
|
22626
|
+
const requestBody = isObject(_optionalChain([request, 'optionalAccess', _549 => _549.requestBody])) ? request.requestBody : {};
|
|
22627
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _550 => _550.httpReferer]);
|
|
22628
|
+
const xTitle = _nullishCoalesce(_optionalChain([request, 'optionalAccess', _551 => _551.xTitle]), () => ( _optionalChain([request, 'optionalAccess', _552 => _552.appTitle])));
|
|
22359
22629
|
const { documents, query, ...metadata } = requestBody;
|
|
22360
22630
|
return {
|
|
22361
22631
|
input: {
|
|
@@ -22381,9 +22651,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22381
22651
|
type: "llm" /* LLM */,
|
|
22382
22652
|
extractInput: (args) => {
|
|
22383
22653
|
const request = getOpenRouterRequestArg(args);
|
|
22384
|
-
const openResponsesRequest = isObject(_optionalChain([request, 'optionalAccess',
|
|
22385
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22386
|
-
const xTitle = _optionalChain([request, 'optionalAccess',
|
|
22654
|
+
const openResponsesRequest = isObject(_optionalChain([request, 'optionalAccess', _553 => _553.openResponsesRequest])) ? request.openResponsesRequest : {};
|
|
22655
|
+
const httpReferer = _optionalChain([request, 'optionalAccess', _554 => _554.httpReferer]);
|
|
22656
|
+
const xTitle = _optionalChain([request, 'optionalAccess', _555 => _555.xTitle]);
|
|
22387
22657
|
const { input, ...metadata } = openResponsesRequest;
|
|
22388
22658
|
return {
|
|
22389
22659
|
input,
|
|
@@ -22393,7 +22663,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22393
22663
|
extractOutput: (result) => extractOpenRouterResponseOutput2(result),
|
|
22394
22664
|
extractMetadata: (result) => extractOpenRouterResponseMetadata2(result),
|
|
22395
22665
|
extractMetrics: (result, startTime) => {
|
|
22396
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
22666
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _556 => _556.usage]));
|
|
22397
22667
|
if (startTime) {
|
|
22398
22668
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
22399
22669
|
}
|
|
@@ -22445,14 +22715,14 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22445
22715
|
extractMetadata: (result, event) => {
|
|
22446
22716
|
if (!isObject(result)) {
|
|
22447
22717
|
return {
|
|
22448
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
22449
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
22718
|
+
step: _optionalChain([event, 'optionalAccess', _557 => _557.step]),
|
|
22719
|
+
step_type: _optionalChain([event, 'optionalAccess', _558 => _558.stepType])
|
|
22450
22720
|
};
|
|
22451
22721
|
}
|
|
22452
22722
|
return {
|
|
22453
22723
|
...extractOpenRouterResponseMetadata2(result) || {},
|
|
22454
|
-
..._optionalChain([event, 'optionalAccess',
|
|
22455
|
-
..._optionalChain([event, 'optionalAccess',
|
|
22724
|
+
..._optionalChain([event, 'optionalAccess', _559 => _559.step]) !== void 0 ? { step: event.step } : {},
|
|
22725
|
+
..._optionalChain([event, 'optionalAccess', _560 => _560.stepType]) ? { step_type: event.stepType } : {}
|
|
22456
22726
|
};
|
|
22457
22727
|
},
|
|
22458
22728
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage2(result.usage) : {}
|
|
@@ -22611,7 +22881,7 @@ function isZodSchema4(value) {
|
|
|
22611
22881
|
function serializeZodSchema4(schema) {
|
|
22612
22882
|
try {
|
|
22613
22883
|
return zodToJsonSchema(schema);
|
|
22614
|
-
} catch (
|
|
22884
|
+
} catch (e64) {
|
|
22615
22885
|
return {
|
|
22616
22886
|
type: "object",
|
|
22617
22887
|
description: "Zod schema (conversion failed)"
|
|
@@ -22832,7 +23102,7 @@ function publishToolResult2(tracingChannel2, event, result) {
|
|
|
22832
23102
|
}
|
|
22833
23103
|
function getToolCallId2(context) {
|
|
22834
23104
|
const toolContext = context;
|
|
22835
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
23105
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _561 => _561.toolCall, 'optionalAccess', _562 => _562.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
22836
23106
|
}
|
|
22837
23107
|
function aggregateOpenRouterChatChunks(chunks) {
|
|
22838
23108
|
let role;
|
|
@@ -22848,12 +23118,12 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22848
23118
|
for (const chunk of chunks) {
|
|
22849
23119
|
metrics = {
|
|
22850
23120
|
...metrics,
|
|
22851
|
-
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess',
|
|
23121
|
+
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess', _563 => _563.usage]))
|
|
22852
23122
|
};
|
|
22853
|
-
const choice = _optionalChain([chunk, 'optionalAccess',
|
|
22854
|
-
const delta = _optionalChain([choice, 'optionalAccess',
|
|
23123
|
+
const choice = _optionalChain([chunk, 'optionalAccess', _564 => _564.choices, 'optionalAccess', _565 => _565[0]]);
|
|
23124
|
+
const delta = _optionalChain([choice, 'optionalAccess', _566 => _566.delta]);
|
|
22855
23125
|
if (!delta) {
|
|
22856
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
23126
|
+
if (_optionalChain([choice, 'optionalAccess', _567 => _567.finish_reason]) !== void 0) {
|
|
22857
23127
|
finishReason = choice.finish_reason;
|
|
22858
23128
|
}
|
|
22859
23129
|
continue;
|
|
@@ -22879,7 +23149,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22879
23149
|
...delta.reasoning_details
|
|
22880
23150
|
];
|
|
22881
23151
|
}
|
|
22882
|
-
const choiceFinishReason = _nullishCoalesce(_nullishCoalesce(_optionalChain([choice, 'optionalAccess',
|
|
23152
|
+
const choiceFinishReason = _nullishCoalesce(_nullishCoalesce(_optionalChain([choice, 'optionalAccess', _568 => _568.finishReason]), () => ( _optionalChain([choice, 'optionalAccess', _569 => _569.finish_reason]))), () => ( void 0));
|
|
22883
23153
|
const deltaFinishReason = _nullishCoalesce(_nullishCoalesce(delta.finishReason, () => ( delta.finish_reason)), () => ( void 0));
|
|
22884
23154
|
if (choiceFinishReason !== void 0) {
|
|
22885
23155
|
finishReason = choiceFinishReason;
|
|
@@ -22891,11 +23161,11 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22891
23161
|
continue;
|
|
22892
23162
|
}
|
|
22893
23163
|
for (const toolDelta of toolCallDeltas) {
|
|
22894
|
-
if (!_optionalChain([toolDelta, 'optionalAccess',
|
|
23164
|
+
if (!_optionalChain([toolDelta, 'optionalAccess', _570 => _570.function])) {
|
|
22895
23165
|
continue;
|
|
22896
23166
|
}
|
|
22897
23167
|
const toolIndex = _nullishCoalesce(toolDelta.index, () => ( 0));
|
|
22898
|
-
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess',
|
|
23168
|
+
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess', _571 => _571[toolIndex]]);
|
|
22899
23169
|
if (!existingToolCall || toolDelta.id && existingToolCall.id !== void 0 && existingToolCall.id !== toolDelta.id) {
|
|
22900
23170
|
const nextToolCalls = [...toolCalls || []];
|
|
22901
23171
|
nextToolCalls[toolIndex] = {
|
|
@@ -22945,7 +23215,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22945
23215
|
function aggregateOpenRouterResponseStreamEvents(chunks) {
|
|
22946
23216
|
let finalResponse;
|
|
22947
23217
|
for (const chunk of chunks) {
|
|
22948
|
-
const response = _optionalChain([chunk, 'optionalAccess',
|
|
23218
|
+
const response = _optionalChain([chunk, 'optionalAccess', _572 => _572.response]);
|
|
22949
23219
|
if (!response) {
|
|
22950
23220
|
continue;
|
|
22951
23221
|
}
|
|
@@ -23054,7 +23324,7 @@ function patchOpenRouterCallModelResult2(args) {
|
|
|
23054
23324
|
}
|
|
23055
23325
|
try {
|
|
23056
23326
|
await endSpanWithResult(await originalGetResponse(), fallbackOutput);
|
|
23057
|
-
} catch (
|
|
23327
|
+
} catch (e65) {
|
|
23058
23328
|
await endSpanWithResult(void 0, fallbackOutput);
|
|
23059
23329
|
}
|
|
23060
23330
|
};
|
|
@@ -23373,10 +23643,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23373
23643
|
type: "llm" /* LLM */,
|
|
23374
23644
|
extractInput: extractMessagesInputWithMetadata,
|
|
23375
23645
|
extractOutput: (result) => {
|
|
23376
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23646
|
+
return _optionalChain([result, 'optionalAccess', _573 => _573.choices]);
|
|
23377
23647
|
},
|
|
23378
23648
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23379
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23649
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _574 => _574.usage]), startTime)
|
|
23380
23650
|
})
|
|
23381
23651
|
);
|
|
23382
23652
|
this.unsubscribers.push(
|
|
@@ -23396,11 +23666,11 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23396
23666
|
type: "llm" /* LLM */,
|
|
23397
23667
|
extractInput: extractEmbeddingInputWithMetadata,
|
|
23398
23668
|
extractOutput: (result) => {
|
|
23399
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
23669
|
+
const embedding = _optionalChain([result, 'optionalAccess', _575 => _575.data, 'optionalAccess', _576 => _576[0], 'optionalAccess', _577 => _577.embedding]);
|
|
23400
23670
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
23401
23671
|
},
|
|
23402
23672
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23403
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23673
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _578 => _578.usage]))
|
|
23404
23674
|
})
|
|
23405
23675
|
);
|
|
23406
23676
|
this.unsubscribers.push(
|
|
@@ -23410,7 +23680,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23410
23680
|
extractInput: extractClassifierInputWithMetadata,
|
|
23411
23681
|
extractOutput: extractClassifierOutput,
|
|
23412
23682
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23413
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23683
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _579 => _579.usage]))
|
|
23414
23684
|
})
|
|
23415
23685
|
);
|
|
23416
23686
|
this.unsubscribers.push(
|
|
@@ -23420,7 +23690,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23420
23690
|
extractInput: extractClassifierInputWithMetadata,
|
|
23421
23691
|
extractOutput: extractClassifierOutput,
|
|
23422
23692
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23423
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23693
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _580 => _580.usage]))
|
|
23424
23694
|
})
|
|
23425
23695
|
);
|
|
23426
23696
|
this.unsubscribers.push(
|
|
@@ -23430,7 +23700,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23430
23700
|
extractInput: extractClassifierInputWithMetadata,
|
|
23431
23701
|
extractOutput: extractClassifierOutput,
|
|
23432
23702
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23433
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23703
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _581 => _581.usage]))
|
|
23434
23704
|
})
|
|
23435
23705
|
);
|
|
23436
23706
|
this.unsubscribers.push(
|
|
@@ -23440,7 +23710,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23440
23710
|
extractInput: extractClassifierInputWithMetadata,
|
|
23441
23711
|
extractOutput: extractClassifierOutput,
|
|
23442
23712
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23443
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23713
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _582 => _582.usage]))
|
|
23444
23714
|
})
|
|
23445
23715
|
);
|
|
23446
23716
|
this.unsubscribers.push(
|
|
@@ -23449,10 +23719,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23449
23719
|
type: "llm" /* LLM */,
|
|
23450
23720
|
extractInput: extractPromptInputWithMetadata,
|
|
23451
23721
|
extractOutput: (result) => {
|
|
23452
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23722
|
+
return _optionalChain([result, 'optionalAccess', _583 => _583.choices]);
|
|
23453
23723
|
},
|
|
23454
23724
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23455
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23725
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _584 => _584.usage]), startTime)
|
|
23456
23726
|
})
|
|
23457
23727
|
);
|
|
23458
23728
|
this.unsubscribers.push(
|
|
@@ -23472,10 +23742,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23472
23742
|
type: "llm" /* LLM */,
|
|
23473
23743
|
extractInput: extractMessagesInputWithMetadata,
|
|
23474
23744
|
extractOutput: (result) => {
|
|
23475
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23745
|
+
return _optionalChain([result, 'optionalAccess', _585 => _585.choices]);
|
|
23476
23746
|
},
|
|
23477
23747
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23478
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23748
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _586 => _586.usage]), startTime)
|
|
23479
23749
|
})
|
|
23480
23750
|
);
|
|
23481
23751
|
this.unsubscribers.push(
|
|
@@ -23730,11 +24000,11 @@ function mergeMistralContentParts(left, right) {
|
|
|
23730
24000
|
const merged = [...(left || []).map((part) => structuredClone(part))];
|
|
23731
24001
|
for (const part of right) {
|
|
23732
24002
|
const lastPart = merged[merged.length - 1];
|
|
23733
|
-
if (part.type === "text" && _optionalChain([lastPart, 'optionalAccess',
|
|
24003
|
+
if (part.type === "text" && _optionalChain([lastPart, 'optionalAccess', _587 => _587.type]) === "text" && typeof lastPart.text === "string" && typeof part.text === "string") {
|
|
23734
24004
|
lastPart.text += part.text;
|
|
23735
24005
|
continue;
|
|
23736
24006
|
}
|
|
23737
|
-
if (part.type === "thinking" && _optionalChain([lastPart, 'optionalAccess',
|
|
24007
|
+
if (part.type === "thinking" && _optionalChain([lastPart, 'optionalAccess', _588 => _588.type]) === "thinking" && Array.isArray(lastPart.thinking) && Array.isArray(part.thinking)) {
|
|
23738
24008
|
lastPart.thinking = mergeMistralTextSegments(
|
|
23739
24009
|
lastPart.thinking,
|
|
23740
24010
|
part.thinking
|
|
@@ -23789,13 +24059,13 @@ function createMergedToolCallDelta(delta) {
|
|
|
23789
24059
|
...delta,
|
|
23790
24060
|
function: {
|
|
23791
24061
|
...delta.function,
|
|
23792
|
-
arguments: typeof _optionalChain([delta, 'access',
|
|
24062
|
+
arguments: typeof _optionalChain([delta, 'access', _589 => _589.function, 'optionalAccess', _590 => _590.arguments]) === "string" ? delta.function.arguments : ""
|
|
23793
24063
|
}
|
|
23794
24064
|
};
|
|
23795
24065
|
}
|
|
23796
24066
|
function mergeToolCallDeltaPair(current, delta) {
|
|
23797
|
-
const currentArguments = typeof _optionalChain([current, 'access',
|
|
23798
|
-
const deltaArguments = typeof _optionalChain([delta, 'access',
|
|
24067
|
+
const currentArguments = typeof _optionalChain([current, 'access', _591 => _591.function, 'optionalAccess', _592 => _592.arguments]) === "string" ? current.function.arguments : "";
|
|
24068
|
+
const deltaArguments = typeof _optionalChain([delta, 'access', _593 => _593.function, 'optionalAccess', _594 => _594.arguments]) === "string" ? delta.function.arguments : "";
|
|
23799
24069
|
return {
|
|
23800
24070
|
...current,
|
|
23801
24071
|
...delta,
|
|
@@ -23898,7 +24168,7 @@ function aggregateMistralStreamChunks(chunks) {
|
|
|
23898
24168
|
let metrics = {};
|
|
23899
24169
|
let metadata;
|
|
23900
24170
|
for (const event of chunks) {
|
|
23901
|
-
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess',
|
|
24171
|
+
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess', _595 => _595.data])) ? event.data : void 0;
|
|
23902
24172
|
if (!chunk) {
|
|
23903
24173
|
continue;
|
|
23904
24174
|
}
|
|
@@ -24027,7 +24297,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24027
24297
|
input: extractRunnerInput(params),
|
|
24028
24298
|
metadata
|
|
24029
24299
|
});
|
|
24030
|
-
} catch (
|
|
24300
|
+
} catch (e66) {
|
|
24031
24301
|
}
|
|
24032
24302
|
if (contextKey) {
|
|
24033
24303
|
this.activeRunnerSpans.set(contextKey, span);
|
|
@@ -24089,7 +24359,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24089
24359
|
};
|
|
24090
24360
|
tracingChannel2.subscribe(handlers);
|
|
24091
24361
|
this.unsubscribers.push(() => {
|
|
24092
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
24362
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _596 => _596()]);
|
|
24093
24363
|
tracingChannel2.unsubscribe(handlers);
|
|
24094
24364
|
});
|
|
24095
24365
|
}
|
|
@@ -24130,7 +24400,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24130
24400
|
metadata.model = modelName2;
|
|
24131
24401
|
}
|
|
24132
24402
|
span.log({ metadata });
|
|
24133
|
-
} catch (
|
|
24403
|
+
} catch (e67) {
|
|
24134
24404
|
}
|
|
24135
24405
|
if (contextKey && agentName) {
|
|
24136
24406
|
this.activeAgentSpans.set(agentContextKey(contextKey, agentName), span);
|
|
@@ -24192,7 +24462,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24192
24462
|
};
|
|
24193
24463
|
tracingChannel2.subscribe(handlers);
|
|
24194
24464
|
this.unsubscribers.push(() => {
|
|
24195
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
24465
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _597 => _597()]);
|
|
24196
24466
|
tracingChannel2.unsubscribe(handlers);
|
|
24197
24467
|
});
|
|
24198
24468
|
}
|
|
@@ -24301,7 +24571,7 @@ function bindAsyncIterableToCurrentSpan(stream, span) {
|
|
|
24301
24571
|
value: true
|
|
24302
24572
|
});
|
|
24303
24573
|
return stream;
|
|
24304
|
-
} catch (
|
|
24574
|
+
} catch (e68) {
|
|
24305
24575
|
return stream;
|
|
24306
24576
|
}
|
|
24307
24577
|
}
|
|
@@ -24332,17 +24602,17 @@ function bindAsyncIterableToCurrentSpan(stream, span) {
|
|
|
24332
24602
|
}
|
|
24333
24603
|
);
|
|
24334
24604
|
stream[Symbol.asyncIterator] = patchedIteratorFn;
|
|
24335
|
-
} catch (
|
|
24605
|
+
} catch (e69) {
|
|
24336
24606
|
return stream;
|
|
24337
24607
|
}
|
|
24338
24608
|
return stream;
|
|
24339
24609
|
}
|
|
24340
24610
|
function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
24341
24611
|
const state = _internalGetGlobalState();
|
|
24342
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
24612
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _598 => _598.contextManager]);
|
|
24343
24613
|
const startChannel = tracingChannel2.start;
|
|
24344
24614
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
24345
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
24615
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _599 => _599.bindStore]) || !currentSpanStore) {
|
|
24346
24616
|
return void 0;
|
|
24347
24617
|
}
|
|
24348
24618
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -24354,7 +24624,7 @@ function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
|
24354
24624
|
return contextManager.wrapSpanForStore(span);
|
|
24355
24625
|
});
|
|
24356
24626
|
return () => {
|
|
24357
|
-
_optionalChain([startChannel, 'access',
|
|
24627
|
+
_optionalChain([startChannel, 'access', _600 => _600.unbindStore, 'optionalCall', _601 => _601(currentSpanStore)]);
|
|
24358
24628
|
};
|
|
24359
24629
|
}
|
|
24360
24630
|
function extractRunnerContextKey(paramsOrContext) {
|
|
@@ -24367,9 +24637,9 @@ function extractRunnerContextKey(paramsOrContext) {
|
|
|
24367
24637
|
return extractInvocationContextKey(invocationContext);
|
|
24368
24638
|
}
|
|
24369
24639
|
function extractInvocationContextKey(parentContext) {
|
|
24370
|
-
const session = _optionalChain([parentContext, 'optionalAccess',
|
|
24371
|
-
const userId = _optionalChain([session, 'optionalAccess',
|
|
24372
|
-
const sessionId = _optionalChain([session, 'optionalAccess',
|
|
24640
|
+
const session = _optionalChain([parentContext, 'optionalAccess', _602 => _602.session]);
|
|
24641
|
+
const userId = _optionalChain([session, 'optionalAccess', _603 => _603.userId]);
|
|
24642
|
+
const sessionId = _optionalChain([session, 'optionalAccess', _604 => _604.id]);
|
|
24373
24643
|
if (typeof userId !== "string" || typeof sessionId !== "string") {
|
|
24374
24644
|
return void 0;
|
|
24375
24645
|
}
|
|
@@ -24426,27 +24696,27 @@ function extractRunnerMetadata(paramsOrContext) {
|
|
|
24426
24696
|
metadata["google_adk.session_id"] = directSessionId;
|
|
24427
24697
|
}
|
|
24428
24698
|
const session = "session" in paramsOrContext ? paramsOrContext.session : void 0;
|
|
24429
|
-
if (metadata["google_adk.user_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess',
|
|
24699
|
+
if (metadata["google_adk.user_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess', _605 => _605.userId]) === "string") {
|
|
24430
24700
|
metadata["google_adk.user_id"] = session.userId;
|
|
24431
24701
|
}
|
|
24432
|
-
if (metadata["google_adk.session_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess',
|
|
24702
|
+
if (metadata["google_adk.session_id"] === void 0 && typeof _optionalChain([session, 'optionalAccess', _606 => _606.id]) === "string") {
|
|
24433
24703
|
metadata["google_adk.session_id"] = session.id;
|
|
24434
24704
|
}
|
|
24435
24705
|
return metadata;
|
|
24436
24706
|
}
|
|
24437
24707
|
function extractAgentName(agent, parentContext) {
|
|
24438
|
-
if (typeof _optionalChain([agent, 'optionalAccess',
|
|
24708
|
+
if (typeof _optionalChain([agent, 'optionalAccess', _607 => _607.name]) === "string" && agent.name.length > 0) {
|
|
24439
24709
|
return agent.name;
|
|
24440
24710
|
}
|
|
24441
24711
|
if (!parentContext) {
|
|
24442
24712
|
return void 0;
|
|
24443
24713
|
}
|
|
24444
24714
|
const contextAgent = parentContext.agent;
|
|
24445
|
-
return typeof _optionalChain([contextAgent, 'optionalAccess',
|
|
24715
|
+
return typeof _optionalChain([contextAgent, 'optionalAccess', _608 => _608.name]) === "string" && contextAgent.name.length > 0 ? contextAgent.name : void 0;
|
|
24446
24716
|
}
|
|
24447
24717
|
function extractModelName(agent, parentContext) {
|
|
24448
|
-
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess',
|
|
24449
|
-
if (!_optionalChain([modelAgent, 'optionalAccess',
|
|
24718
|
+
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess', _609 => _609.agent])));
|
|
24719
|
+
if (!_optionalChain([modelAgent, 'optionalAccess', _610 => _610.model])) {
|
|
24450
24720
|
return;
|
|
24451
24721
|
}
|
|
24452
24722
|
if (typeof modelAgent.model === "string") {
|
|
@@ -24459,30 +24729,30 @@ function extractModelName(agent, parentContext) {
|
|
|
24459
24729
|
}
|
|
24460
24730
|
function extractToolCallId(req) {
|
|
24461
24731
|
const toolContext = req.toolContext;
|
|
24462
|
-
return _optionalChain([toolContext, 'optionalAccess',
|
|
24732
|
+
return _optionalChain([toolContext, 'optionalAccess', _611 => _611.functionCallId]);
|
|
24463
24733
|
}
|
|
24464
24734
|
function extractToolName2(req, tool) {
|
|
24465
|
-
if (typeof _optionalChain([tool, 'optionalAccess',
|
|
24735
|
+
if (typeof _optionalChain([tool, 'optionalAccess', _612 => _612.name]) === "string" && tool.name.length > 0) {
|
|
24466
24736
|
return tool.name;
|
|
24467
24737
|
}
|
|
24468
24738
|
const toolContext = req.toolContext;
|
|
24469
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24470
|
-
const invocationTool = _optionalChain([invocationContext, 'optionalAccess',
|
|
24471
|
-
const toolName = _optionalChain([invocationTool, 'optionalAccess',
|
|
24739
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _613 => _613.invocationContext]);
|
|
24740
|
+
const invocationTool = _optionalChain([invocationContext, 'optionalAccess', _614 => _614.tool]);
|
|
24741
|
+
const toolName = _optionalChain([invocationTool, 'optionalAccess', _615 => _615.name]);
|
|
24472
24742
|
return typeof toolName === "string" && toolName.length > 0 ? toolName : void 0;
|
|
24473
24743
|
}
|
|
24474
24744
|
function extractToolAgentName(req) {
|
|
24475
24745
|
const toolContext = req.toolContext;
|
|
24476
|
-
const directName = _optionalChain([toolContext, 'optionalAccess',
|
|
24746
|
+
const directName = _optionalChain([toolContext, 'optionalAccess', _616 => _616.agentName]);
|
|
24477
24747
|
if (typeof directName === "string" && directName.length > 0) {
|
|
24478
24748
|
return directName;
|
|
24479
24749
|
}
|
|
24480
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24750
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _617 => _617.invocationContext]);
|
|
24481
24751
|
return extractAgentName(void 0, invocationContext);
|
|
24482
24752
|
}
|
|
24483
24753
|
function findToolParentSpan(req, activeAgentSpans, activeRunnerSpans) {
|
|
24484
24754
|
const toolContext = req.toolContext;
|
|
24485
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24755
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _618 => _618.invocationContext]);
|
|
24486
24756
|
const contextKey = extractInvocationContextKey(invocationContext);
|
|
24487
24757
|
const agentName = extractToolAgentName(req);
|
|
24488
24758
|
if (contextKey && agentName) {
|
|
@@ -24864,7 +25134,7 @@ function extractCohereResponseMetadata(result) {
|
|
|
24864
25134
|
RESPONSE_METADATA_ALLOWLIST2
|
|
24865
25135
|
);
|
|
24866
25136
|
const meta = isObject(result.meta) ? result.meta : void 0;
|
|
24867
|
-
const apiVersion = isObject(_optionalChain([meta, 'optionalAccess',
|
|
25137
|
+
const apiVersion = isObject(_optionalChain([meta, 'optionalAccess', _619 => _619.apiVersion])) && typeof meta.apiVersion.version === "string" && meta.apiVersion.version || isObject(_optionalChain([meta, 'optionalAccess', _620 => _620.api_version])) && typeof meta.api_version.version === "string" && meta.api_version.version;
|
|
24868
25138
|
const metadata = {
|
|
24869
25139
|
...responseMetadata,
|
|
24870
25140
|
...apiVersion ? { api_version: apiVersion } : {}
|
|
@@ -25025,13 +25295,13 @@ function getToolCallIndex2(toolCall, fallbackIndex) {
|
|
|
25025
25295
|
return typeof toolCall.index === "number" && Number.isInteger(toolCall.index) ? toolCall.index : fallbackIndex;
|
|
25026
25296
|
}
|
|
25027
25297
|
function appendToolCallDelta(existing, incoming) {
|
|
25028
|
-
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess',
|
|
25298
|
+
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess', _621 => _621.function])) && typeof existing.function.arguments === "string" ? existing.function.arguments : "";
|
|
25029
25299
|
const incomingArguments = isObject(incoming.function) && typeof incoming.function.arguments === "string" ? incoming.function.arguments : "";
|
|
25030
25300
|
return {
|
|
25031
25301
|
...existing,
|
|
25032
25302
|
...incoming,
|
|
25033
25303
|
function: {
|
|
25034
|
-
...isObject(_optionalChain([existing, 'optionalAccess',
|
|
25304
|
+
...isObject(_optionalChain([existing, 'optionalAccess', _622 => _622.function])) ? existing.function : {},
|
|
25035
25305
|
...isObject(incoming.function) ? incoming.function : {},
|
|
25036
25306
|
...incomingArguments ? { arguments: `${currentArguments}${incomingArguments}` } : {}
|
|
25037
25307
|
}
|
|
@@ -25287,7 +25557,7 @@ function aggregateCohereChatStreamChunks(chunks) {
|
|
|
25287
25557
|
...mergedToolCalls.length > 0 ? { toolCalls: mergedToolCalls } : {}
|
|
25288
25558
|
};
|
|
25289
25559
|
} else if (mergedToolCalls.length > 0 || role || mergedText.length > 0 || aggregatedContentBlocks.length > 0) {
|
|
25290
|
-
const textContent = mergedText.length > 0 ? mergedText : _optionalChain([aggregatedContentBlocks, 'access',
|
|
25560
|
+
const textContent = mergedText.length > 0 ? mergedText : _optionalChain([aggregatedContentBlocks, 'access', _623 => _623[0], 'optionalAccess', _624 => _624.type]) === "text" ? aggregatedContentBlocks[0].text : void 0;
|
|
25291
25561
|
output = {
|
|
25292
25562
|
...role ? { role } : {},
|
|
25293
25563
|
...textContent ? { content: textContent } : {},
|
|
@@ -25336,7 +25606,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25336
25606
|
metadata: { ...metadata, provider: "groq" }
|
|
25337
25607
|
};
|
|
25338
25608
|
},
|
|
25339
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
25609
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _625 => _625.choices]),
|
|
25340
25610
|
extractMetrics: (result, startTime) => {
|
|
25341
25611
|
const metrics = parseGroqMetrics(result);
|
|
25342
25612
|
if (startTime) {
|
|
@@ -25359,7 +25629,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25359
25629
|
};
|
|
25360
25630
|
},
|
|
25361
25631
|
extractOutput: (result) => {
|
|
25362
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
25632
|
+
const embedding = _optionalChain([result, 'optionalAccess', _626 => _626.data, 'optionalAccess', _627 => _627[0], 'optionalAccess', _628 => _628.embedding]);
|
|
25363
25633
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
25364
25634
|
},
|
|
25365
25635
|
extractMetrics: (result) => parseGroqMetrics(result)
|
|
@@ -25371,8 +25641,8 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25371
25641
|
}
|
|
25372
25642
|
};
|
|
25373
25643
|
function parseGroqMetrics(result) {
|
|
25374
|
-
const metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
25375
|
-
const xGroq = _optionalChain([result, 'optionalAccess',
|
|
25644
|
+
const metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _629 => _629.usage]));
|
|
25645
|
+
const xGroq = _optionalChain([result, 'optionalAccess', _630 => _630.x_groq]);
|
|
25376
25646
|
if (!xGroq || typeof xGroq !== "object") {
|
|
25377
25647
|
return metrics;
|
|
25378
25648
|
}
|
|
@@ -25396,7 +25666,7 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
25396
25666
|
);
|
|
25397
25667
|
const reasoning = aggregateGroqReasoning(chunks);
|
|
25398
25668
|
if (reasoning !== void 0) {
|
|
25399
|
-
const message = _optionalChain([aggregated, 'access',
|
|
25669
|
+
const message = _optionalChain([aggregated, 'access', _631 => _631.output, 'access', _632 => _632[0], 'optionalAccess', _633 => _633.message]);
|
|
25400
25670
|
if (message) {
|
|
25401
25671
|
message.reasoning = reasoning;
|
|
25402
25672
|
}
|
|
@@ -25409,8 +25679,8 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
25409
25679
|
function aggregateGroqReasoning(chunks) {
|
|
25410
25680
|
let reasoning = "";
|
|
25411
25681
|
for (const chunk of chunks) {
|
|
25412
|
-
const delta = _optionalChain([chunk, 'access',
|
|
25413
|
-
const deltaReasoning = _optionalChain([delta, 'optionalAccess',
|
|
25682
|
+
const delta = _optionalChain([chunk, 'access', _634 => _634.choices, 'optionalAccess', _635 => _635[0], 'optionalAccess', _636 => _636.delta]);
|
|
25683
|
+
const deltaReasoning = _optionalChain([delta, 'optionalAccess', _637 => _637.reasoning]);
|
|
25414
25684
|
if (typeof deltaReasoning === "string") {
|
|
25415
25685
|
reasoning += deltaReasoning;
|
|
25416
25686
|
}
|
|
@@ -25495,11 +25765,11 @@ function traceBedrockRuntimeClientSendChannel(channel2) {
|
|
|
25495
25765
|
shouldTrace: ([command, optionsOrCb, cb]) => getBedrockRuntimeOperation(command) !== void 0 && typeof optionsOrCb !== "function" && typeof cb !== "function",
|
|
25496
25766
|
type: "llm" /* LLM */,
|
|
25497
25767
|
extractInput: ([command]) => extractBedrockRuntimeInput(command),
|
|
25498
|
-
extractOutput: (result, endEvent) => extractBedrockRuntimeOutput(_optionalChain([endEvent, 'optionalAccess',
|
|
25499
|
-
extractMetadata: (result, endEvent) => extractBedrockRuntimeResponseMetadata(_optionalChain([endEvent, 'optionalAccess',
|
|
25768
|
+
extractOutput: (result, endEvent) => extractBedrockRuntimeOutput(_optionalChain([endEvent, 'optionalAccess', _638 => _638.arguments, 'optionalAccess', _639 => _639[0]]), result),
|
|
25769
|
+
extractMetadata: (result, endEvent) => extractBedrockRuntimeResponseMetadata(_optionalChain([endEvent, 'optionalAccess', _640 => _640.arguments, 'optionalAccess', _641 => _641[0]]), result),
|
|
25500
25770
|
extractMetrics: (result) => extractBedrockRuntimeResponseMetrics(result),
|
|
25501
25771
|
patchResult: ({ endEvent, result, span, startTime }) => patchBedrockRuntimeStreamingResult({
|
|
25502
|
-
command: _optionalChain([endEvent, 'access',
|
|
25772
|
+
command: _optionalChain([endEvent, 'access', _642 => _642.arguments, 'optionalAccess', _643 => _643[0]]),
|
|
25503
25773
|
result,
|
|
25504
25774
|
span,
|
|
25505
25775
|
startTime
|
|
@@ -25520,8 +25790,8 @@ function extractBedrockRuntimeInput(command) {
|
|
|
25520
25790
|
const converseRequest = isObject(request) ? request : void 0;
|
|
25521
25791
|
return {
|
|
25522
25792
|
input: sanitizeBedrockValue({
|
|
25523
|
-
messages: _optionalChain([converseRequest, 'optionalAccess',
|
|
25524
|
-
system: _optionalChain([converseRequest, 'optionalAccess',
|
|
25793
|
+
messages: _optionalChain([converseRequest, 'optionalAccess', _644 => _644.messages]),
|
|
25794
|
+
system: _optionalChain([converseRequest, 'optionalAccess', _645 => _645.system])
|
|
25525
25795
|
}),
|
|
25526
25796
|
metadata
|
|
25527
25797
|
};
|
|
@@ -25529,7 +25799,7 @@ function extractBedrockRuntimeInput(command) {
|
|
|
25529
25799
|
if (operation === "invokeModel" || operation === "invokeModelWithBidirectionalStream" || operation === "invokeModelWithResponseStream") {
|
|
25530
25800
|
const invokeRequest = isObject(request) ? request : void 0;
|
|
25531
25801
|
return {
|
|
25532
|
-
input: _nullishCoalesce(parseJsonBody(_optionalChain([invokeRequest, 'optionalAccess',
|
|
25802
|
+
input: _nullishCoalesce(parseJsonBody(_optionalChain([invokeRequest, 'optionalAccess', _646 => _646.body])), () => ( summarizeBody(_optionalChain([invokeRequest, 'optionalAccess', _647 => _647.body])))),
|
|
25533
25803
|
metadata
|
|
25534
25804
|
};
|
|
25535
25805
|
}
|
|
@@ -25568,12 +25838,12 @@ function extractBedrockRuntimeOutput(command, result) {
|
|
|
25568
25838
|
const operation = getBedrockRuntimeOperation(command);
|
|
25569
25839
|
if (operation === "converse") {
|
|
25570
25840
|
return sanitizeBedrockValue(
|
|
25571
|
-
_optionalChain([result, 'optionalAccess',
|
|
25841
|
+
_optionalChain([result, 'optionalAccess', _648 => _648.output, 'optionalAccess', _649 => _649.message])
|
|
25572
25842
|
);
|
|
25573
25843
|
}
|
|
25574
25844
|
if (operation === "invokeModel") {
|
|
25575
25845
|
const response = isObject(result) ? result : void 0;
|
|
25576
|
-
return _nullishCoalesce(parseJsonBody(_optionalChain([response, 'optionalAccess',
|
|
25846
|
+
return _nullishCoalesce(parseJsonBody(_optionalChain([response, 'optionalAccess', _650 => _650.body])), () => ( summarizeBody(_optionalChain([response, 'optionalAccess', _651 => _651.body]))));
|
|
25577
25847
|
}
|
|
25578
25848
|
return sanitizeBedrockValue(result);
|
|
25579
25849
|
}
|
|
@@ -25610,8 +25880,8 @@ function extractBedrockRuntimeResponseMetrics(result) {
|
|
|
25610
25880
|
if (isObject(parsedBody)) {
|
|
25611
25881
|
const metadata = isObject(parsedBody.metadata) ? parsedBody.metadata : void 0;
|
|
25612
25882
|
const metrics = parseBedrockRuntimeMetrics(
|
|
25613
|
-
_nullishCoalesce(parsedBody.usage, () => ( _optionalChain([metadata, 'optionalAccess',
|
|
25614
|
-
_nullishCoalesce(parsedBody.metrics, () => ( _optionalChain([metadata, 'optionalAccess',
|
|
25883
|
+
_nullishCoalesce(parsedBody.usage, () => ( _optionalChain([metadata, 'optionalAccess', _652 => _652.usage]))),
|
|
25884
|
+
_nullishCoalesce(parsedBody.metrics, () => ( _optionalChain([metadata, 'optionalAccess', _653 => _653.metrics])))
|
|
25615
25885
|
);
|
|
25616
25886
|
if (Object.keys(metrics).length > 0) {
|
|
25617
25887
|
return metrics;
|
|
@@ -25776,42 +26046,42 @@ function aggregateBedrockConverseStreamChunks(chunks) {
|
|
|
25776
26046
|
if (exception) {
|
|
25777
26047
|
return exception;
|
|
25778
26048
|
}
|
|
25779
|
-
if (typeof _optionalChain([chunk, 'access',
|
|
26049
|
+
if (typeof _optionalChain([chunk, 'access', _654 => _654.messageStart, 'optionalAccess', _655 => _655.role]) === "string") {
|
|
25780
26050
|
role = chunk.messageStart.role;
|
|
25781
26051
|
}
|
|
25782
|
-
const startIndex = _optionalChain([chunk, 'access',
|
|
26052
|
+
const startIndex = _optionalChain([chunk, 'access', _656 => _656.contentBlockStart, 'optionalAccess', _657 => _657.contentBlockIndex]);
|
|
25783
26053
|
if (typeof startIndex === "number") {
|
|
25784
26054
|
contentByIndex.set(startIndex, {
|
|
25785
26055
|
..._nullishCoalesce(contentByIndex.get(startIndex), () => ( {})),
|
|
25786
|
-
...sanitizeRecord(_optionalChain([chunk, 'access',
|
|
26056
|
+
...sanitizeRecord(_optionalChain([chunk, 'access', _658 => _658.contentBlockStart, 'optionalAccess', _659 => _659.start]))
|
|
25787
26057
|
});
|
|
25788
26058
|
}
|
|
25789
|
-
const deltaIndex = _optionalChain([chunk, 'access',
|
|
25790
|
-
const delta = _optionalChain([chunk, 'access',
|
|
26059
|
+
const deltaIndex = _optionalChain([chunk, 'access', _660 => _660.contentBlockDelta, 'optionalAccess', _661 => _661.contentBlockIndex]);
|
|
26060
|
+
const delta = _optionalChain([chunk, 'access', _662 => _662.contentBlockDelta, 'optionalAccess', _663 => _663.delta]);
|
|
25791
26061
|
if (typeof deltaIndex === "number" && isObject(delta)) {
|
|
25792
26062
|
const existing = _nullishCoalesce(contentByIndex.get(deltaIndex), () => ( {}));
|
|
25793
26063
|
contentByIndex.set(deltaIndex, mergeContentBlockDelta(existing, delta));
|
|
25794
26064
|
}
|
|
25795
|
-
if (typeof _optionalChain([chunk, 'access',
|
|
26065
|
+
if (typeof _optionalChain([chunk, 'access', _664 => _664.messageStop, 'optionalAccess', _665 => _665.stopReason]) === "string") {
|
|
25796
26066
|
stopReason = chunk.messageStop.stopReason;
|
|
25797
26067
|
}
|
|
25798
|
-
if (_optionalChain([chunk, 'access',
|
|
26068
|
+
if (_optionalChain([chunk, 'access', _666 => _666.messageStop, 'optionalAccess', _667 => _667.additionalModelResponseFields]) !== void 0) {
|
|
25799
26069
|
metadata.additionalModelResponseFields = sanitizeBedrockValue(
|
|
25800
26070
|
chunk.messageStop.additionalModelResponseFields
|
|
25801
26071
|
);
|
|
25802
26072
|
}
|
|
25803
|
-
if (_optionalChain([chunk, 'access',
|
|
26073
|
+
if (_optionalChain([chunk, 'access', _668 => _668.metadata, 'optionalAccess', _669 => _669.usage]) !== void 0) {
|
|
25804
26074
|
usage = chunk.metadata.usage;
|
|
25805
26075
|
}
|
|
25806
|
-
if (_optionalChain([chunk, 'access',
|
|
26076
|
+
if (_optionalChain([chunk, 'access', _670 => _670.metadata, 'optionalAccess', _671 => _671.metrics]) !== void 0) {
|
|
25807
26077
|
responseMetrics = chunk.metadata.metrics;
|
|
25808
26078
|
}
|
|
25809
|
-
if (_optionalChain([chunk, 'access',
|
|
26079
|
+
if (_optionalChain([chunk, 'access', _672 => _672.metadata, 'optionalAccess', _673 => _673.performanceConfig]) !== void 0) {
|
|
25810
26080
|
metadata.performanceConfig = sanitizeBedrockValue(
|
|
25811
26081
|
chunk.metadata.performanceConfig
|
|
25812
26082
|
);
|
|
25813
26083
|
}
|
|
25814
|
-
if (_optionalChain([chunk, 'access',
|
|
26084
|
+
if (_optionalChain([chunk, 'access', _674 => _674.metadata, 'optionalAccess', _675 => _675.serviceTier]) !== void 0) {
|
|
25815
26085
|
metadata.serviceTier = chunk.metadata.serviceTier;
|
|
25816
26086
|
}
|
|
25817
26087
|
}
|
|
@@ -25835,11 +26105,11 @@ function aggregateInvokeModelResponseStreamChunks(chunks) {
|
|
|
25835
26105
|
return exception;
|
|
25836
26106
|
}
|
|
25837
26107
|
}
|
|
25838
|
-
const parsedChunks = chunks.map((chunk) => parseJsonBody(_optionalChain([chunk, 'access',
|
|
26108
|
+
const parsedChunks = chunks.map((chunk) => parseJsonBody(_optionalChain([chunk, 'access', _676 => _676.chunk, 'optionalAccess', _677 => _677.bytes]))).filter((chunk) => chunk !== void 0);
|
|
25839
26109
|
const jsonLikeChunks = parsedChunks.filter(isObject);
|
|
25840
26110
|
const text = parsedChunks.map(extractTextFromJsonLike).join("");
|
|
25841
26111
|
const lastMetadataChunk = jsonLikeChunks.slice().reverse().find((chunk) => isObject(chunk.metadata));
|
|
25842
|
-
const metadata = isObject(_optionalChain([lastMetadataChunk, 'optionalAccess',
|
|
26112
|
+
const metadata = isObject(_optionalChain([lastMetadataChunk, 'optionalAccess', _678 => _678.metadata])) ? sanitizeRecord(lastMetadataChunk.metadata) : void 0;
|
|
25843
26113
|
let usage;
|
|
25844
26114
|
for (const chunk of jsonLikeChunks) {
|
|
25845
26115
|
const message = chunk.message;
|
|
@@ -25960,7 +26230,7 @@ function parseJsonBody(body) {
|
|
|
25960
26230
|
}
|
|
25961
26231
|
try {
|
|
25962
26232
|
return sanitizeBedrockValue(JSON.parse(text));
|
|
25963
|
-
} catch (
|
|
26233
|
+
} catch (e70) {
|
|
25964
26234
|
return void 0;
|
|
25965
26235
|
}
|
|
25966
26236
|
}
|
|
@@ -26113,8 +26383,8 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26113
26383
|
type: "llm" /* LLM */,
|
|
26114
26384
|
extractInput: ([input]) => extractGenerateInput(input),
|
|
26115
26385
|
extractOutput: extractGenerateOutput,
|
|
26116
|
-
extractMetadata: (result, event) => extractGenerateResponseMetadata(result, _optionalChain([event, 'optionalAccess',
|
|
26117
|
-
extractMetrics: (result) => parseGenkitUsageMetrics(_optionalChain([result, 'optionalAccess',
|
|
26386
|
+
extractMetadata: (result, event) => extractGenerateResponseMetadata(result, _optionalChain([event, 'optionalAccess', _679 => _679.arguments, 'optionalAccess', _680 => _680[0]])),
|
|
26387
|
+
extractMetrics: (result) => parseGenkitUsageMetrics(_optionalChain([result, 'optionalAccess', _681 => _681.usage]))
|
|
26118
26388
|
})
|
|
26119
26389
|
);
|
|
26120
26390
|
this.unsubscribers.push(
|
|
@@ -26131,7 +26401,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26131
26401
|
type: "function" /* FUNCTION */,
|
|
26132
26402
|
extractInput: ([params]) => extractEmbedInput(params),
|
|
26133
26403
|
extractOutput: (result) => summarizeEmbeddingResult(result),
|
|
26134
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
26404
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _682 => _682.arguments, 'optionalAccess', _683 => _683[0]])),
|
|
26135
26405
|
extractMetrics: () => ({})
|
|
26136
26406
|
})
|
|
26137
26407
|
);
|
|
@@ -26141,7 +26411,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26141
26411
|
type: "function" /* FUNCTION */,
|
|
26142
26412
|
extractInput: ([params]) => extractEmbedManyInput(params),
|
|
26143
26413
|
extractOutput: summarizeEmbeddingResult,
|
|
26144
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
26414
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _684 => _684.arguments, 'optionalAccess', _685 => _685[0]])),
|
|
26145
26415
|
extractMetrics: () => ({})
|
|
26146
26416
|
})
|
|
26147
26417
|
);
|
|
@@ -26192,7 +26462,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26192
26462
|
};
|
|
26193
26463
|
tracingChannel2.subscribe(handlers);
|
|
26194
26464
|
this.unsubscribers.push(() => {
|
|
26195
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
26465
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _686 => _686()]);
|
|
26196
26466
|
tracingChannel2.unsubscribe(handlers);
|
|
26197
26467
|
});
|
|
26198
26468
|
}
|
|
@@ -26240,7 +26510,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26240
26510
|
};
|
|
26241
26511
|
tracingChannel2.subscribe(handlers);
|
|
26242
26512
|
this.unsubscribers.push(() => {
|
|
26243
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
26513
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _687 => _687()]);
|
|
26244
26514
|
tracingChannel2.unsubscribe(handlers);
|
|
26245
26515
|
});
|
|
26246
26516
|
}
|
|
@@ -26307,10 +26577,10 @@ function ensureActionSpanState(states, event, create) {
|
|
|
26307
26577
|
}
|
|
26308
26578
|
function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
26309
26579
|
const state = _internalGetGlobalState();
|
|
26310
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
26580
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _688 => _688.contextManager]);
|
|
26311
26581
|
const startChannel = tracingChannel2.start;
|
|
26312
26582
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
26313
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
26583
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _689 => _689.bindStore]) || !currentSpanStore) {
|
|
26314
26584
|
return void 0;
|
|
26315
26585
|
}
|
|
26316
26586
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -26322,7 +26592,7 @@ function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
|
26322
26592
|
return state2 ? contextManager.wrapSpanForStore(state2.span) : currentSpanStore.getStore();
|
|
26323
26593
|
});
|
|
26324
26594
|
return () => {
|
|
26325
|
-
_optionalChain([startChannel, 'access',
|
|
26595
|
+
_optionalChain([startChannel, 'access', _690 => _690.unbindStore, 'optionalCall', _691 => _691(currentSpanStore)]);
|
|
26326
26596
|
};
|
|
26327
26597
|
}
|
|
26328
26598
|
function normalizeInput(input) {
|
|
@@ -26369,25 +26639,25 @@ function extractGenerateOutput(result) {
|
|
|
26369
26639
|
}
|
|
26370
26640
|
function extractGenerateResponseMetadata(result, input) {
|
|
26371
26641
|
const normalized = input ? normalizeInput(input) : void 0;
|
|
26372
|
-
const request = isObject(_optionalChain([result, 'optionalAccess',
|
|
26642
|
+
const request = isObject(_optionalChain([result, 'optionalAccess', _692 => _692.request])) ? _optionalChain([result, 'optionalAccess', _693 => _693.request]) : isObject(normalized) ? normalized : void 0;
|
|
26373
26643
|
return {
|
|
26374
26644
|
...genkitProviderMetadata(),
|
|
26375
26645
|
...pickDefined({
|
|
26376
|
-
model: modelName(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
26377
|
-
finishReason: _optionalChain([result, 'optionalAccess',
|
|
26378
|
-
finishMessage: _optionalChain([result, 'optionalAccess',
|
|
26646
|
+
model: modelName(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _694 => _694.model]), () => ( _optionalChain([request, 'optionalAccess', _695 => _695.model])))),
|
|
26647
|
+
finishReason: _optionalChain([result, 'optionalAccess', _696 => _696.finishReason]),
|
|
26648
|
+
finishMessage: _optionalChain([result, 'optionalAccess', _697 => _697.finishMessage])
|
|
26379
26649
|
})
|
|
26380
26650
|
};
|
|
26381
26651
|
}
|
|
26382
26652
|
function extractEmbedInput(params) {
|
|
26383
26653
|
return {
|
|
26384
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
26654
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _698 => _698.content])),
|
|
26385
26655
|
metadata: extractEmbedMetadata(params)
|
|
26386
26656
|
};
|
|
26387
26657
|
}
|
|
26388
26658
|
function extractEmbedManyInput(params) {
|
|
26389
26659
|
return {
|
|
26390
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
26660
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _699 => _699.content])),
|
|
26391
26661
|
metadata: extractEmbedMetadata(params)
|
|
26392
26662
|
};
|
|
26393
26663
|
}
|
|
@@ -26395,7 +26665,7 @@ function extractEmbedMetadata(params) {
|
|
|
26395
26665
|
return {
|
|
26396
26666
|
...genkitProviderMetadata(),
|
|
26397
26667
|
...pickDefined({
|
|
26398
|
-
model: modelName(_optionalChain([params, 'optionalAccess',
|
|
26668
|
+
model: modelName(_optionalChain([params, 'optionalAccess', _700 => _700.embedder]))
|
|
26399
26669
|
})
|
|
26400
26670
|
};
|
|
26401
26671
|
}
|
|
@@ -26403,7 +26673,7 @@ function summarizeEmbeddingResult(result) {
|
|
|
26403
26673
|
if (Array.isArray(result)) {
|
|
26404
26674
|
return {
|
|
26405
26675
|
embedding_count: result.length,
|
|
26406
|
-
dimensions: Array.isArray(result[0]) || Array.isArray(_optionalChain([result, 'access',
|
|
26676
|
+
dimensions: Array.isArray(result[0]) || Array.isArray(_optionalChain([result, 'access', _701 => _701[0], 'optionalAccess', _702 => _702.embedding])) ? result[0].length || _optionalChain([result, 'access', _703 => _703[0], 'optionalAccess', _704 => _704.embedding, 'optionalAccess', _705 => _705.length]) : void 0
|
|
26407
26677
|
};
|
|
26408
26678
|
}
|
|
26409
26679
|
if (isObject(result) && Array.isArray(result.embeddings)) {
|
|
@@ -26430,7 +26700,7 @@ function patchGenerateStreamResult(result, span, startTime) {
|
|
|
26430
26700
|
finishSpan(async () => {
|
|
26431
26701
|
const streamedText = chunks.map((chunk) => safeGet(chunk, "text")).join("");
|
|
26432
26702
|
const response = await result.response;
|
|
26433
|
-
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess',
|
|
26703
|
+
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess', _706 => _706.usage]));
|
|
26434
26704
|
if (firstChunkTime !== void 0) {
|
|
26435
26705
|
metrics.time_to_first_token = firstChunkTime - startTime;
|
|
26436
26706
|
}
|
|
@@ -26523,22 +26793,22 @@ function extractActionMetadata(self) {
|
|
|
26523
26793
|
}
|
|
26524
26794
|
function extractActionSpanMetadata(args) {
|
|
26525
26795
|
const options = extractRunInNewSpanOptions(args);
|
|
26526
|
-
const labels = isObject(_optionalChain([options, 'optionalAccess',
|
|
26527
|
-
const metadata = isObject(_optionalChain([options, 'optionalAccess',
|
|
26528
|
-
const actionType = stringValue(_optionalChain([labels, 'optionalAccess',
|
|
26529
|
-
const name = stringValue(_optionalChain([metadata, 'optionalAccess',
|
|
26796
|
+
const labels = isObject(_optionalChain([options, 'optionalAccess', _707 => _707.labels])) ? options.labels : void 0;
|
|
26797
|
+
const metadata = isObject(_optionalChain([options, 'optionalAccess', _708 => _708.metadata])) ? options.metadata : void 0;
|
|
26798
|
+
const actionType = stringValue(_optionalChain([labels, 'optionalAccess', _709 => _709["genkit:metadata:subtype"]]));
|
|
26799
|
+
const name = stringValue(_optionalChain([metadata, 'optionalAccess', _710 => _710.name]));
|
|
26530
26800
|
if (!actionType || !name) {
|
|
26531
26801
|
return void 0;
|
|
26532
26802
|
}
|
|
26533
26803
|
return {
|
|
26534
26804
|
actionType,
|
|
26535
|
-
key: stringValue(_optionalChain([labels, 'optionalAccess',
|
|
26805
|
+
key: stringValue(_optionalChain([labels, 'optionalAccess', _711 => _711["genkit:key"]])),
|
|
26536
26806
|
name
|
|
26537
26807
|
};
|
|
26538
26808
|
}
|
|
26539
26809
|
function extractActionSpanInput(args) {
|
|
26540
26810
|
const options = extractRunInNewSpanOptions(args);
|
|
26541
|
-
if (!isObject(_optionalChain([options, 'optionalAccess',
|
|
26811
|
+
if (!isObject(_optionalChain([options, 'optionalAccess', _712 => _712.metadata]))) {
|
|
26542
26812
|
return void 0;
|
|
26543
26813
|
}
|
|
26544
26814
|
return options.metadata.input;
|
|
@@ -26551,7 +26821,7 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
26551
26821
|
if (runStepName) {
|
|
26552
26822
|
return true;
|
|
26553
26823
|
}
|
|
26554
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
26824
|
+
switch (_optionalChain([metadata, 'optionalAccess', _713 => _713.actionType])) {
|
|
26555
26825
|
case "model":
|
|
26556
26826
|
case "background-model":
|
|
26557
26827
|
case "embedder":
|
|
@@ -26561,8 +26831,8 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
26561
26831
|
}
|
|
26562
26832
|
}
|
|
26563
26833
|
function actionSpanName(metadata, runStepName) {
|
|
26564
|
-
const actionType = _optionalChain([metadata, 'optionalAccess',
|
|
26565
|
-
const name = _optionalChain([metadata, 'optionalAccess',
|
|
26834
|
+
const actionType = _optionalChain([metadata, 'optionalAccess', _714 => _714.actionType]);
|
|
26835
|
+
const name = _optionalChain([metadata, 'optionalAccess', _715 => _715.name]);
|
|
26566
26836
|
if (actionType && name) {
|
|
26567
26837
|
return `genkit.${actionType}: ${name}`;
|
|
26568
26838
|
}
|
|
@@ -26575,7 +26845,7 @@ function actionSpanName(metadata, runStepName) {
|
|
|
26575
26845
|
return "genkit.action";
|
|
26576
26846
|
}
|
|
26577
26847
|
function actionSpanType(metadata) {
|
|
26578
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
26848
|
+
switch (_optionalChain([metadata, 'optionalAccess', _716 => _716.actionType])) {
|
|
26579
26849
|
case "tool":
|
|
26580
26850
|
case "tool.v2":
|
|
26581
26851
|
return "tool" /* TOOL */;
|
|
@@ -26590,9 +26860,9 @@ function actionMetadataForLog(metadata, runStepName) {
|
|
|
26590
26860
|
return {
|
|
26591
26861
|
...genkitProviderMetadata(),
|
|
26592
26862
|
...pickDefined({
|
|
26593
|
-
"genkit.action_type": _optionalChain([metadata, 'optionalAccess',
|
|
26594
|
-
"genkit.action_name": _optionalChain([metadata, 'optionalAccess',
|
|
26595
|
-
"genkit.action_key": _optionalChain([metadata, 'optionalAccess',
|
|
26863
|
+
"genkit.action_type": _optionalChain([metadata, 'optionalAccess', _717 => _717.actionType]),
|
|
26864
|
+
"genkit.action_name": _optionalChain([metadata, 'optionalAccess', _718 => _718.name]),
|
|
26865
|
+
"genkit.action_key": _optionalChain([metadata, 'optionalAccess', _719 => _719.key]),
|
|
26596
26866
|
"genkit.run_name": runStepName
|
|
26597
26867
|
})
|
|
26598
26868
|
};
|
|
@@ -26612,7 +26882,7 @@ function safeGet(value, key) {
|
|
|
26612
26882
|
}
|
|
26613
26883
|
try {
|
|
26614
26884
|
return value[key];
|
|
26615
|
-
} catch (
|
|
26885
|
+
} catch (e71) {
|
|
26616
26886
|
return void 0;
|
|
26617
26887
|
}
|
|
26618
26888
|
}
|
|
@@ -27052,10 +27322,10 @@ function injectTracingHooks2(config, state) {
|
|
|
27052
27322
|
const existingHooks = _nullishCoalesce(config.hooks, () => ( {}));
|
|
27053
27323
|
const onSessionEnd = async (input, invocation) => {
|
|
27054
27324
|
try {
|
|
27055
|
-
await _optionalChain([existingHooks, 'access',
|
|
27325
|
+
await _optionalChain([existingHooks, 'access', _720 => _720.onSessionEnd, 'optionalCall', _721 => _721(input, invocation)]);
|
|
27056
27326
|
} finally {
|
|
27057
27327
|
handleSessionEnd(state, input.reason, input.error);
|
|
27058
|
-
_optionalChain([state, 'access',
|
|
27328
|
+
_optionalChain([state, 'access', _722 => _722.unsubscribeEvents, 'optionalCall', _723 => _723()]);
|
|
27059
27329
|
}
|
|
27060
27330
|
};
|
|
27061
27331
|
config.hooks = {
|
|
@@ -27094,7 +27364,7 @@ function makeSessionHandlers(sessionStates, configArgIndex, includeProviderMetad
|
|
|
27094
27364
|
if (config.model) {
|
|
27095
27365
|
metadata["github_copilot.model"] = config.model;
|
|
27096
27366
|
}
|
|
27097
|
-
if (includeProviderMetadata && _optionalChain([config, 'access',
|
|
27367
|
+
if (includeProviderMetadata && _optionalChain([config, 'access', _724 => _724.provider, 'optionalAccess', _725 => _725.type])) {
|
|
27098
27368
|
metadata["github_copilot.provider_type"] = config.provider.type;
|
|
27099
27369
|
}
|
|
27100
27370
|
if (Object.keys(metadata).length > 0) {
|
|
@@ -27292,7 +27562,7 @@ function subscribeToFlueContext(value, state) {
|
|
|
27292
27562
|
}
|
|
27293
27563
|
released = true;
|
|
27294
27564
|
try {
|
|
27295
|
-
_optionalChain([unsubscribe, 'optionalCall',
|
|
27565
|
+
_optionalChain([unsubscribe, 'optionalCall', _726 => _726()]);
|
|
27296
27566
|
} catch (error) {
|
|
27297
27567
|
logInstrumentationError3("Flue context unsubscribe", error);
|
|
27298
27568
|
}
|
|
@@ -27324,7 +27594,7 @@ function isAutoContextTerminalEvent(event, ctx) {
|
|
|
27324
27594
|
if (type !== "operation") {
|
|
27325
27595
|
return false;
|
|
27326
27596
|
}
|
|
27327
|
-
return !_optionalChain([ctx, 'optionalAccess',
|
|
27597
|
+
return !_optionalChain([ctx, 'optionalAccess', _727 => _727.runId]) && typeof Reflect.get(event, "runId") !== "string";
|
|
27328
27598
|
}
|
|
27329
27599
|
function isObservableFlueContext(value) {
|
|
27330
27600
|
return isObjectLike(value) && typeof Reflect.get(value, "subscribeEvent") === "function";
|
|
@@ -27392,13 +27662,13 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27392
27662
|
case "workflow":
|
|
27393
27663
|
return this.ensureWorkflowSpanForExecution(operation, executionContext);
|
|
27394
27664
|
case "agent":
|
|
27395
|
-
return _optionalChain([this, 'access',
|
|
27665
|
+
return _optionalChain([this, 'access', _728 => _728.operationsById, 'access', _729 => _729.get, 'call', _730 => _730(operation.operationId), 'optionalAccess', _731 => _731.span]);
|
|
27396
27666
|
case "model":
|
|
27397
|
-
return _optionalChain([this, 'access',
|
|
27667
|
+
return _optionalChain([this, 'access', _732 => _732.turnsByKey, 'access', _733 => _733.get, 'call', _734 => _734(operation.turnId), 'optionalAccess', _735 => _735.span]);
|
|
27398
27668
|
case "tool":
|
|
27399
27669
|
return this.spanForToolExecution(operation, executionContext);
|
|
27400
27670
|
case "task":
|
|
27401
|
-
return _optionalChain([this, 'access',
|
|
27671
|
+
return _optionalChain([this, 'access', _736 => _736.tasksById, 'access', _737 => _737.get, 'call', _738 => _738(operation.taskId), 'optionalAccess', _739 => _739.span]);
|
|
27402
27672
|
default:
|
|
27403
27673
|
return void 0;
|
|
27404
27674
|
}
|
|
@@ -27440,7 +27710,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27440
27710
|
ctx
|
|
27441
27711
|
);
|
|
27442
27712
|
}
|
|
27443
|
-
return _optionalChain([this, 'access',
|
|
27713
|
+
return _optionalChain([this, 'access', _740 => _740.runsById, 'access', _741 => _741.get, 'call', _742 => _742(operation.runId), 'optionalAccess', _743 => _743.span]);
|
|
27444
27714
|
}
|
|
27445
27715
|
spanForToolExecution(operation, executionContext) {
|
|
27446
27716
|
const contextual = this.toolsByKey.get(
|
|
@@ -27511,7 +27781,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27511
27781
|
if (!event.runId) {
|
|
27512
27782
|
return;
|
|
27513
27783
|
}
|
|
27514
|
-
const workflowName = _nullishCoalesce(_nullishCoalesce(event.workflowName, () => ( _optionalChain([event, 'access',
|
|
27784
|
+
const workflowName = _nullishCoalesce(_nullishCoalesce(event.workflowName, () => ( _optionalChain([event, 'access', _744 => _744.owner, 'optionalAccess', _745 => _745.workflowName]))), () => ( (typeof _optionalChain([ctx, 'optionalAccess', _746 => _746.id]) === "string" ? ctx.id : "unknown")));
|
|
27515
27785
|
const input = flueRunInput(event);
|
|
27516
27786
|
const metadata = {
|
|
27517
27787
|
...extractPayloadMetadata(input),
|
|
@@ -27540,7 +27810,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27540
27810
|
if (!event.runId) {
|
|
27541
27811
|
return;
|
|
27542
27812
|
}
|
|
27543
|
-
const workflowName = _nullishCoalesce(event.workflowName, () => ( (typeof _optionalChain([ctx, 'optionalAccess',
|
|
27813
|
+
const workflowName = _nullishCoalesce(event.workflowName, () => ( (typeof _optionalChain([ctx, 'optionalAccess', _747 => _747.id]) === "string" ? ctx.id : "unknown")));
|
|
27544
27814
|
const metadata = {
|
|
27545
27815
|
...extractEventMetadata(event, ctx),
|
|
27546
27816
|
...workflowName ? { "flue.workflow_name": workflowName } : {},
|
|
@@ -27640,8 +27910,8 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27640
27910
|
...provider ? { "flue.provider": provider } : {},
|
|
27641
27911
|
...event.purpose ? { "flue.turn_purpose": event.purpose } : {},
|
|
27642
27912
|
...reasoning ? { reasoning } : {},
|
|
27643
|
-
..._optionalChain([input, 'optionalAccess',
|
|
27644
|
-
..._optionalChain([input, 'optionalAccess',
|
|
27913
|
+
..._optionalChain([input, 'optionalAccess', _748 => _748.systemPrompt]) ? { "flue.system_prompt": input.systemPrompt } : {},
|
|
27914
|
+
..._optionalChain([input, 'optionalAccess', _749 => _749.tools]) ? { tools: input.tools } : {}
|
|
27645
27915
|
};
|
|
27646
27916
|
const parent = this.parentSpanForTurn(event);
|
|
27647
27917
|
const span = startFlueSpan(parent, {
|
|
@@ -27649,11 +27919,11 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27649
27919
|
spanAttributes: { type: "llm" /* LLM */ },
|
|
27650
27920
|
startTime: eventTime(event.timestamp),
|
|
27651
27921
|
event: {
|
|
27652
|
-
input: _optionalChain([input, 'optionalAccess',
|
|
27922
|
+
input: _optionalChain([input, 'optionalAccess', _750 => _750.messages]),
|
|
27653
27923
|
metadata
|
|
27654
27924
|
}
|
|
27655
27925
|
});
|
|
27656
|
-
this.logOperationInput(event.operationId, _nullishCoalesce(_optionalChain([input, 'optionalAccess',
|
|
27926
|
+
this.logOperationInput(event.operationId, _nullishCoalesce(_optionalChain([input, 'optionalAccess', _751 => _751.messages]), () => ( input)));
|
|
27657
27927
|
this.turnsByKey.set(key, { metadata, span });
|
|
27658
27928
|
}
|
|
27659
27929
|
handleTurn(event) {
|
|
@@ -27858,7 +28128,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27858
28128
|
}
|
|
27859
28129
|
}
|
|
27860
28130
|
if (event.runId) {
|
|
27861
|
-
return _optionalChain([this, 'access',
|
|
28131
|
+
return _optionalChain([this, 'access', _752 => _752.runsById, 'access', _753 => _753.get, 'call', _754 => _754(event.runId), 'optionalAccess', _755 => _755.span]);
|
|
27862
28132
|
}
|
|
27863
28133
|
return void 0;
|
|
27864
28134
|
}
|
|
@@ -27876,7 +28146,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27876
28146
|
}
|
|
27877
28147
|
}
|
|
27878
28148
|
if (event.runId) {
|
|
27879
|
-
return _optionalChain([this, 'access',
|
|
28149
|
+
return _optionalChain([this, 'access', _756 => _756.runsById, 'access', _757 => _757.get, 'call', _758 => _758(event.runId), 'optionalAccess', _759 => _759.span]);
|
|
27880
28150
|
}
|
|
27881
28151
|
return void 0;
|
|
27882
28152
|
}
|
|
@@ -28058,8 +28328,8 @@ function extractEventMetadata(event, ctx) {
|
|
|
28058
28328
|
...event.taskId ? { "flue.task_id": event.taskId } : {},
|
|
28059
28329
|
...event.operationId ? { "flue.operation_id": event.operationId } : {},
|
|
28060
28330
|
...event.turnId ? { "flue.turn_id": event.turnId } : {},
|
|
28061
|
-
...typeof _optionalChain([ctx, 'optionalAccess',
|
|
28062
|
-
...typeof _optionalChain([ctx, 'optionalAccess',
|
|
28331
|
+
...typeof _optionalChain([ctx, 'optionalAccess', _760 => _760.id]) === "string" ? { "flue.context_id": ctx.id } : {},
|
|
28332
|
+
...typeof _optionalChain([ctx, 'optionalAccess', _761 => _761.runId]) === "string" ? { "flue.context_run_id": ctx.runId } : {}
|
|
28063
28333
|
};
|
|
28064
28334
|
}
|
|
28065
28335
|
function extractPayloadMetadata(payload) {
|
|
@@ -28076,40 +28346,40 @@ function flueRunInput(event) {
|
|
|
28076
28346
|
return event.input !== void 0 ? event.input : event.payload;
|
|
28077
28347
|
}
|
|
28078
28348
|
function flueTurnRequestInput(event) {
|
|
28079
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28349
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _762 => _762.request, 'optionalAccess', _763 => _763.input]), () => ( event.input));
|
|
28080
28350
|
}
|
|
28081
28351
|
function flueTurnRequestModel(event) {
|
|
28082
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28352
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _764 => _764.request, 'optionalAccess', _765 => _765.model]), () => ( event.model));
|
|
28083
28353
|
}
|
|
28084
28354
|
function flueTurnRequestProvider(event) {
|
|
28085
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access',
|
|
28355
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access', _766 => _766.request, 'optionalAccess', _767 => _767.providerName]), () => ( event.provider)), () => ( _optionalChain([event, 'access', _768 => _768.request, 'optionalAccess', _769 => _769.providerId])));
|
|
28086
28356
|
}
|
|
28087
28357
|
function flueTurnRequestApi(event) {
|
|
28088
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28358
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _770 => _770.request, 'optionalAccess', _771 => _771.api]), () => ( event.api));
|
|
28089
28359
|
}
|
|
28090
28360
|
function flueTurnRequestReasoning(event) {
|
|
28091
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28361
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _772 => _772.request, 'optionalAccess', _773 => _773.reasoning]), () => ( event.reasoning));
|
|
28092
28362
|
}
|
|
28093
28363
|
function flueTurnModel(event) {
|
|
28094
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28364
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _774 => _774.request, 'optionalAccess', _775 => _775.model]), () => ( event.model));
|
|
28095
28365
|
}
|
|
28096
28366
|
function flueTurnProvider(event) {
|
|
28097
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access',
|
|
28367
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access', _776 => _776.request, 'optionalAccess', _777 => _777.providerName]), () => ( event.provider)), () => ( _optionalChain([event, 'access', _778 => _778.request, 'optionalAccess', _779 => _779.providerId])));
|
|
28098
28368
|
}
|
|
28099
28369
|
function flueTurnApi(event) {
|
|
28100
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28370
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _780 => _780.request, 'optionalAccess', _781 => _781.api]), () => ( event.api));
|
|
28101
28371
|
}
|
|
28102
28372
|
function flueTurnUsage(event) {
|
|
28103
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28373
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _782 => _782.response, 'optionalAccess', _783 => _783.usage]), () => ( event.usage));
|
|
28104
28374
|
}
|
|
28105
28375
|
function flueTurnOutput(event) {
|
|
28106
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28376
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _784 => _784.response, 'optionalAccess', _785 => _785.output]), () => ( event.output));
|
|
28107
28377
|
}
|
|
28108
28378
|
function flueTurnStopReason(event) {
|
|
28109
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28379
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _786 => _786.response, 'optionalAccess', _787 => _787.stopReason]), () => ( event.stopReason));
|
|
28110
28380
|
}
|
|
28111
28381
|
function flueTurnError(event) {
|
|
28112
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access',
|
|
28382
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'access', _788 => _788.response, 'optionalAccess', _789 => _789.error]), () => ( _optionalChain([event, 'access', _790 => _790.response, 'optionalAccess', _791 => _791.errorInfo, 'optionalAccess', _792 => _792.message]))), () => ( event.error));
|
|
28113
28383
|
}
|
|
28114
28384
|
function flueToolInput(event) {
|
|
28115
28385
|
if (event.args !== void 0) {
|
|
@@ -28124,7 +28394,7 @@ function flueToolOutput(event) {
|
|
|
28124
28394
|
return event.output !== void 0 ? event.output : event.result;
|
|
28125
28395
|
}
|
|
28126
28396
|
function flueToolError(event) {
|
|
28127
|
-
return _nullishCoalesce(_nullishCoalesce(event.error, () => ( _optionalChain([event, 'access',
|
|
28397
|
+
return _nullishCoalesce(_nullishCoalesce(event.error, () => ( _optionalChain([event, 'access', _793 => _793.errorInfo, 'optionalAccess', _794 => _794.message]))), () => ( flueToolOutput(event)));
|
|
28128
28398
|
}
|
|
28129
28399
|
function operationOutput(event) {
|
|
28130
28400
|
if (event.operationKind === "prompt" || event.operationKind === "skill") {
|
|
@@ -28201,9 +28471,9 @@ function startFlueSpan(parent, args) {
|
|
|
28201
28471
|
}
|
|
28202
28472
|
function runWithCurrentSpanStore(span, next) {
|
|
28203
28473
|
const state = _internalGetGlobalState();
|
|
28204
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
28474
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _795 => _795.contextManager]);
|
|
28205
28475
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
28206
|
-
if (contextManager && typeof _optionalChain([currentSpanStore, 'optionalAccess',
|
|
28476
|
+
if (contextManager && typeof _optionalChain([currentSpanStore, 'optionalAccess', _796 => _796.run]) === "function") {
|
|
28207
28477
|
return currentSpanStore.run(contextManager.wrapSpanForStore(span), next);
|
|
28208
28478
|
}
|
|
28209
28479
|
return withCurrent(span, () => next());
|
|
@@ -28239,11 +28509,11 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28239
28509
|
__init82() {this.firstTokenTimes = /* @__PURE__ */ new Map()}
|
|
28240
28510
|
__init83() {this.ttftMs = /* @__PURE__ */ new Map()}
|
|
28241
28511
|
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);
|
|
28242
|
-
this.parent = _optionalChain([options, 'optionalAccess',
|
|
28512
|
+
this.parent = _optionalChain([options, 'optionalAccess', _797 => _797.parent]);
|
|
28243
28513
|
this.options = {
|
|
28244
|
-
debug: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
28245
|
-
excludeMetadataProps: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
28246
|
-
logger: _optionalChain([options, 'optionalAccess',
|
|
28514
|
+
debug: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _798 => _798.debug]), () => ( false)),
|
|
28515
|
+
excludeMetadataProps: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _799 => _799.excludeMetadataProps]), () => ( /^(l[sc]_|langgraph_|__pregel_|checkpoint_ns)/)),
|
|
28516
|
+
logger: _optionalChain([options, 'optionalAccess', _800 => _800.logger])
|
|
28247
28517
|
};
|
|
28248
28518
|
}
|
|
28249
28519
|
startSpan({
|
|
@@ -28257,7 +28527,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28257
28527
|
if (!parentRunId) {
|
|
28258
28528
|
this.rootRunId = runId;
|
|
28259
28529
|
}
|
|
28260
|
-
const tags = _optionalChain([args, 'access',
|
|
28530
|
+
const tags = _optionalChain([args, 'access', _801 => _801.event, 'optionalAccess', _802 => _802.tags]);
|
|
28261
28531
|
const spanAttributes = args.spanAttributes || {};
|
|
28262
28532
|
spanAttributes.type = args.type || spanAttributes.type || "task";
|
|
28263
28533
|
args.type = spanAttributes.type;
|
|
@@ -28277,7 +28547,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28277
28547
|
tags: void 0,
|
|
28278
28548
|
metadata: {
|
|
28279
28549
|
...tags ? { tags } : {},
|
|
28280
|
-
..._optionalChain([args, 'access',
|
|
28550
|
+
..._optionalChain([args, 'access', _803 => _803.event, 'optionalAccess', _804 => _804.metadata]),
|
|
28281
28551
|
braintrust: {
|
|
28282
28552
|
integration_name: "langchain-js",
|
|
28283
28553
|
sdk_language: "javascript"
|
|
@@ -28379,7 +28649,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28379
28649
|
});
|
|
28380
28650
|
}
|
|
28381
28651
|
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, runName) {
|
|
28382
|
-
if (_optionalChain([tags, 'optionalAccess',
|
|
28652
|
+
if (_optionalChain([tags, 'optionalAccess', _805 => _805.includes, 'call', _806 => _806("langsmith:hidden")])) {
|
|
28383
28653
|
this.skippedRuns.add(runId);
|
|
28384
28654
|
return;
|
|
28385
28655
|
}
|
|
@@ -28489,7 +28759,7 @@ function getSerializedName(serialized) {
|
|
|
28489
28759
|
if (typeof serialized.name === "string") {
|
|
28490
28760
|
return serialized.name;
|
|
28491
28761
|
}
|
|
28492
|
-
const lastIdPart = _optionalChain([serialized, 'access',
|
|
28762
|
+
const lastIdPart = _optionalChain([serialized, 'access', _807 => _807.id, 'optionalAccess', _808 => _808.at, 'call', _809 => _809(-1)]);
|
|
28493
28763
|
return typeof lastIdPart === "string" ? lastIdPart : void 0;
|
|
28494
28764
|
}
|
|
28495
28765
|
function cleanObject(obj) {
|
|
@@ -28502,6 +28772,16 @@ function cleanObject(obj) {
|
|
|
28502
28772
|
})
|
|
28503
28773
|
);
|
|
28504
28774
|
}
|
|
28775
|
+
function normalizeTokenMetrics(obj) {
|
|
28776
|
+
const metrics = cleanObject(obj);
|
|
28777
|
+
if (metrics.total_tokens !== void 0) {
|
|
28778
|
+
metrics.tokens = metrics.total_tokens;
|
|
28779
|
+
} else if (metrics.prompt_tokens !== void 0 && metrics.completion_tokens !== void 0) {
|
|
28780
|
+
metrics.tokens = metrics.prompt_tokens + metrics.completion_tokens;
|
|
28781
|
+
}
|
|
28782
|
+
delete metrics.total_tokens;
|
|
28783
|
+
return metrics;
|
|
28784
|
+
}
|
|
28505
28785
|
function walkGenerations(response) {
|
|
28506
28786
|
const result = [];
|
|
28507
28787
|
const generations = response.generations || [];
|
|
@@ -28548,7 +28828,7 @@ function getMetricsFromResponse(response) {
|
|
|
28548
28828
|
continue;
|
|
28549
28829
|
}
|
|
28550
28830
|
const inputTokenDetails = usageMetadata.input_token_details;
|
|
28551
|
-
return
|
|
28831
|
+
return normalizeTokenMetrics({
|
|
28552
28832
|
total_tokens: usageMetadata.total_tokens,
|
|
28553
28833
|
prompt_tokens: usageMetadata.input_tokens,
|
|
28554
28834
|
completion_tokens: usageMetadata.output_tokens,
|
|
@@ -28558,7 +28838,7 @@ function getMetricsFromResponse(response) {
|
|
|
28558
28838
|
}
|
|
28559
28839
|
const llmOutput = response.llmOutput || {};
|
|
28560
28840
|
const tokenUsage = isRecord(llmOutput.tokenUsage) ? llmOutput.tokenUsage : isRecord(llmOutput.estimatedTokens) ? llmOutput.estimatedTokens : {};
|
|
28561
|
-
return
|
|
28841
|
+
return normalizeTokenMetrics({
|
|
28562
28842
|
total_tokens: tokenUsage.totalTokens,
|
|
28563
28843
|
prompt_tokens: tokenUsage.promptTokens,
|
|
28564
28844
|
completion_tokens: tokenUsage.completionTokens
|
|
@@ -28567,7 +28847,7 @@ function getMetricsFromResponse(response) {
|
|
|
28567
28847
|
function safeJsonParse(input) {
|
|
28568
28848
|
try {
|
|
28569
28849
|
return JSON.parse(input);
|
|
28570
|
-
} catch (
|
|
28850
|
+
} catch (e72) {
|
|
28571
28851
|
return input;
|
|
28572
28852
|
}
|
|
28573
28853
|
}
|
|
@@ -28626,7 +28906,7 @@ var LangChainPlugin = (_class24 = class extends BasePlugin {constructor(...args6
|
|
|
28626
28906
|
try {
|
|
28627
28907
|
result.addHandler(new BraintrustLangChainCallbackHandler(), true);
|
|
28628
28908
|
this.injectedManagers.add(result);
|
|
28629
|
-
} catch (
|
|
28909
|
+
} catch (e73) {
|
|
28630
28910
|
}
|
|
28631
28911
|
}
|
|
28632
28912
|
}, _class24);
|
|
@@ -28638,7 +28918,7 @@ function isCallbackManager(value) {
|
|
|
28638
28918
|
return typeof maybeManager.addHandler === "function";
|
|
28639
28919
|
}
|
|
28640
28920
|
function hasBraintrustHandler(manager) {
|
|
28641
|
-
return _nullishCoalesce(_optionalChain([manager, 'access',
|
|
28921
|
+
return _nullishCoalesce(_optionalChain([manager, 'access', _810 => _810.handlers, 'optionalAccess', _811 => _811.some, 'call', _812 => _812((handler) => {
|
|
28642
28922
|
if (typeof handler !== "object" || handler === null) {
|
|
28643
28923
|
return false;
|
|
28644
28924
|
}
|
|
@@ -28830,7 +29110,7 @@ var LangSmithPlugin = (_class25 = class extends BasePlugin {
|
|
|
28830
29110
|
}
|
|
28831
29111
|
if (this.shouldSkipLangChainRun(run)) {
|
|
28832
29112
|
const active2 = this.activeRuns.get(id);
|
|
28833
|
-
_optionalChain([active2, 'optionalAccess',
|
|
29113
|
+
_optionalChain([active2, 'optionalAccess', _813 => _813.span, 'access', _814 => _814.end, 'call', _815 => _815()]);
|
|
28834
29114
|
this.activeRuns.delete(id);
|
|
28835
29115
|
this.completedRuns.set(id, true);
|
|
28836
29116
|
return;
|
|
@@ -29185,14 +29465,14 @@ var PiCodingAgentPlugin = (_class26 = class extends BasePlugin {constructor(...a
|
|
|
29185
29465
|
};
|
|
29186
29466
|
channel2.subscribe(handlers);
|
|
29187
29467
|
this.unsubscribers.push(() => {
|
|
29188
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
29468
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _816 => _816()]);
|
|
29189
29469
|
channel2.unsubscribe(handlers);
|
|
29190
29470
|
});
|
|
29191
29471
|
}
|
|
29192
29472
|
}, _class26);
|
|
29193
29473
|
function startPiPromptRun(event, onFinalize) {
|
|
29194
29474
|
const session = extractSession(event);
|
|
29195
|
-
const agent = _optionalChain([session, 'optionalAccess',
|
|
29475
|
+
const agent = _optionalChain([session, 'optionalAccess', _817 => _817.agent]);
|
|
29196
29476
|
if (!session || !isPiAgent(agent)) {
|
|
29197
29477
|
return void 0;
|
|
29198
29478
|
}
|
|
@@ -29200,8 +29480,8 @@ function startPiPromptRun(event, onFinalize) {
|
|
|
29200
29480
|
...extractSessionMetadata(session),
|
|
29201
29481
|
...extractPromptOptionsMetadata(event.arguments[1]),
|
|
29202
29482
|
"pi_coding_agent.operation": "AgentSession.prompt",
|
|
29203
|
-
provider: _nullishCoalesce(_nullishCoalesce(_optionalChain([session, 'access',
|
|
29204
|
-
..._optionalChain([session, 'access',
|
|
29483
|
+
provider: _nullishCoalesce(_nullishCoalesce(_optionalChain([session, 'access', _818 => _818.model, 'optionalAccess', _819 => _819.provider]), () => ( _optionalChain([agent, 'access', _820 => _820.state, 'optionalAccess', _821 => _821.model, 'optionalAccess', _822 => _822.provider]))), () => ( "pi")),
|
|
29484
|
+
..._optionalChain([session, 'access', _823 => _823.model, 'optionalAccess', _824 => _824.id]) || _optionalChain([agent, 'access', _825 => _825.state, 'optionalAccess', _826 => _826.model, 'optionalAccess', _827 => _827.id]) ? { model: _nullishCoalesce(_optionalChain([session, 'access', _828 => _828.model, 'optionalAccess', _829 => _829.id]), () => ( _optionalChain([agent, 'access', _830 => _830.state, 'optionalAccess', _831 => _831.model, 'optionalAccess', _832 => _832.id]))) } : {},
|
|
29205
29485
|
...event.moduleVersion ? { "pi_coding_agent.version": event.moduleVersion } : {}
|
|
29206
29486
|
};
|
|
29207
29487
|
const span = startSpan({
|
|
@@ -29220,7 +29500,7 @@ function startPiPromptRun(event, onFinalize) {
|
|
|
29220
29500
|
activeToolSpans: /* @__PURE__ */ new Map(),
|
|
29221
29501
|
agent,
|
|
29222
29502
|
collectedLlmUsageMetrics: false,
|
|
29223
|
-
deferCompletionUntilTurnEnd: _optionalChain([options, 'optionalAccess',
|
|
29503
|
+
deferCompletionUntilTurnEnd: _optionalChain([options, 'optionalAccess', _833 => _833.streamingBehavior]) === "followUp" || _optionalChain([options, 'optionalAccess', _834 => _834.streamingBehavior]) === "steer",
|
|
29224
29504
|
finalized: false,
|
|
29225
29505
|
metadata,
|
|
29226
29506
|
metrics: {},
|
|
@@ -29263,11 +29543,11 @@ function promptContextStore() {
|
|
|
29263
29543
|
return piPromptContextStore;
|
|
29264
29544
|
}
|
|
29265
29545
|
function currentPromptContextFrames() {
|
|
29266
|
-
return _nullishCoalesce(_optionalChain([promptContextStore, 'call',
|
|
29546
|
+
return _nullishCoalesce(_optionalChain([promptContextStore, 'call', _835 => _835(), 'access', _836 => _836.getStore, 'call', _837 => _837(), 'optionalAccess', _838 => _838.frames]), () => ( []));
|
|
29267
29547
|
}
|
|
29268
29548
|
function currentPiPromptState() {
|
|
29269
29549
|
const frames = currentPromptContextFrames();
|
|
29270
|
-
return _optionalChain([frames, 'access',
|
|
29550
|
+
return _optionalChain([frames, 'access', _839 => _839[frames.length - 1], 'optionalAccess', _840 => _840.state]);
|
|
29271
29551
|
}
|
|
29272
29552
|
function enterPiPromptContext(state) {
|
|
29273
29553
|
const frame = {
|
|
@@ -29597,7 +29877,7 @@ function finishPiToolSpan(state, event) {
|
|
|
29597
29877
|
try {
|
|
29598
29878
|
toolState.span.end();
|
|
29599
29879
|
} finally {
|
|
29600
|
-
_optionalChain([toolState, 'access',
|
|
29880
|
+
_optionalChain([toolState, 'access', _841 => _841.restoreAutoInstrumentation, 'optionalCall', _842 => _842()]);
|
|
29601
29881
|
}
|
|
29602
29882
|
}
|
|
29603
29883
|
}
|
|
@@ -29606,10 +29886,10 @@ async function finalizePiPromptRun(state, error) {
|
|
|
29606
29886
|
return;
|
|
29607
29887
|
}
|
|
29608
29888
|
state.finalized = true;
|
|
29609
|
-
_optionalChain([state, 'access',
|
|
29889
|
+
_optionalChain([state, 'access', _843 => _843.onFinalize, 'optionalCall', _844 => _844(state)]);
|
|
29610
29890
|
restorePiStreamFn(state);
|
|
29611
29891
|
try {
|
|
29612
|
-
_optionalChain([state, 'access',
|
|
29892
|
+
_optionalChain([state, 'access', _845 => _845.unsubscribeAgent, 'optionalCall', _846 => _846()]);
|
|
29613
29893
|
} catch (unsubscribeError) {
|
|
29614
29894
|
logInstrumentationError4("Pi Coding Agent unsubscribe", unsubscribeError);
|
|
29615
29895
|
}
|
|
@@ -29617,7 +29897,7 @@ async function finalizePiPromptRun(state, error) {
|
|
|
29617
29897
|
finishOpenToolSpans(state, error);
|
|
29618
29898
|
const metadata = {
|
|
29619
29899
|
...state.metadata,
|
|
29620
|
-
...extractModelMetadata2(_optionalChain([state, 'access',
|
|
29900
|
+
...extractModelMetadata2(_optionalChain([state, 'access', _847 => _847.agent, 'access', _848 => _848.state, 'optionalAccess', _849 => _849.model]))
|
|
29621
29901
|
};
|
|
29622
29902
|
try {
|
|
29623
29903
|
safeLog4(state.span, {
|
|
@@ -29640,7 +29920,7 @@ function restorePiStreamFn(state) {
|
|
|
29640
29920
|
if (patchState.eventPromptState === state) {
|
|
29641
29921
|
patchState.eventPromptState = void 0;
|
|
29642
29922
|
}
|
|
29643
|
-
_optionalChain([state, 'access',
|
|
29923
|
+
_optionalChain([state, 'access', _850 => _850.restorePromptContext, 'optionalCall', _851 => _851()]);
|
|
29644
29924
|
if (patchState.activePromptStates.size > 0) {
|
|
29645
29925
|
return;
|
|
29646
29926
|
}
|
|
@@ -29668,13 +29948,13 @@ function finishPiLlmSpan(promptState, llmState, message, error) {
|
|
|
29668
29948
|
}
|
|
29669
29949
|
llmState.finalized = true;
|
|
29670
29950
|
promptState.activeLlmSpans.delete(llmState);
|
|
29671
|
-
const messageError = _optionalChain([message, 'optionalAccess',
|
|
29951
|
+
const messageError = _optionalChain([message, 'optionalAccess', _852 => _852.stopReason]) === "error" && message.errorMessage;
|
|
29672
29952
|
const metrics = {
|
|
29673
|
-
...extractUsageMetrics2(_optionalChain([message, 'optionalAccess',
|
|
29953
|
+
...extractUsageMetrics2(_optionalChain([message, 'optionalAccess', _853 => _853.usage])),
|
|
29674
29954
|
...cleanMetrics5(llmState.metrics),
|
|
29675
29955
|
...buildDurationMetrics3(llmState.startTime)
|
|
29676
29956
|
};
|
|
29677
|
-
const usageMetrics = extractUsageMetrics2(_optionalChain([message, 'optionalAccess',
|
|
29957
|
+
const usageMetrics = extractUsageMetrics2(_optionalChain([message, 'optionalAccess', _854 => _854.usage]));
|
|
29678
29958
|
if (Object.keys(usageMetrics).length > 0) {
|
|
29679
29959
|
promptState.collectedLlmUsageMetrics = true;
|
|
29680
29960
|
addMetrics(promptState.metrics, usageMetrics);
|
|
@@ -29701,7 +29981,7 @@ function finishOpenToolSpans(state, error) {
|
|
|
29701
29981
|
});
|
|
29702
29982
|
toolState.span.end();
|
|
29703
29983
|
} finally {
|
|
29704
|
-
_optionalChain([toolState, 'access',
|
|
29984
|
+
_optionalChain([toolState, 'access', _855 => _855.restoreAutoInstrumentation, 'optionalCall', _856 => _856()]);
|
|
29705
29985
|
}
|
|
29706
29986
|
}
|
|
29707
29987
|
state.activeToolSpans.clear();
|
|
@@ -29813,7 +30093,7 @@ function normalizeStopReason(reason) {
|
|
|
29813
30093
|
}
|
|
29814
30094
|
}
|
|
29815
30095
|
function extractPromptInput(text, options) {
|
|
29816
|
-
const images = _optionalChain([options, 'optionalAccess',
|
|
30096
|
+
const images = _optionalChain([options, 'optionalAccess', _857 => _857.images]);
|
|
29817
30097
|
if (!images || images.length === 0) {
|
|
29818
30098
|
return text;
|
|
29819
30099
|
}
|
|
@@ -29968,7 +30248,7 @@ function stringifyArguments(value) {
|
|
|
29968
30248
|
}
|
|
29969
30249
|
try {
|
|
29970
30250
|
return JSON.stringify(value);
|
|
29971
|
-
} catch (
|
|
30251
|
+
} catch (e74) {
|
|
29972
30252
|
return stringifyUnknown(value);
|
|
29973
30253
|
}
|
|
29974
30254
|
}
|
|
@@ -29981,7 +30261,7 @@ function stringifyUnknown(value) {
|
|
|
29981
30261
|
}
|
|
29982
30262
|
try {
|
|
29983
30263
|
return JSON.stringify(value);
|
|
29984
|
-
} catch (
|
|
30264
|
+
} catch (e75) {
|
|
29985
30265
|
return String(value);
|
|
29986
30266
|
}
|
|
29987
30267
|
}
|
|
@@ -30079,7 +30359,7 @@ var StrandsAgentSDKPlugin = (_class27 = class extends BasePlugin {constructor(..
|
|
|
30079
30359
|
};
|
|
30080
30360
|
channel2.subscribe(handlers);
|
|
30081
30361
|
this.unsubscribers.push(() => {
|
|
30082
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
30362
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _858 => _858()]);
|
|
30083
30363
|
channel2.unsubscribe(handlers);
|
|
30084
30364
|
});
|
|
30085
30365
|
}
|
|
@@ -30142,14 +30422,14 @@ var StrandsAgentSDKPlugin = (_class27 = class extends BasePlugin {constructor(..
|
|
|
30142
30422
|
};
|
|
30143
30423
|
tracingChannel2.subscribe(handlers);
|
|
30144
30424
|
this.unsubscribers.push(() => {
|
|
30145
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
30425
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _859 => _859()]);
|
|
30146
30426
|
tracingChannel2.unsubscribe(handlers);
|
|
30147
30427
|
});
|
|
30148
30428
|
}
|
|
30149
30429
|
}, _class27);
|
|
30150
30430
|
function startAgentStream(event, activeChildParents) {
|
|
30151
30431
|
const agent = extractAgent(event);
|
|
30152
|
-
const model = _optionalChain([agent, 'optionalAccess',
|
|
30432
|
+
const model = _optionalChain([agent, 'optionalAccess', _860 => _860.model]);
|
|
30153
30433
|
const metadata = {
|
|
30154
30434
|
...extractAgentMetadata2(agent),
|
|
30155
30435
|
...extractModelMetadata3(model),
|
|
@@ -30195,7 +30475,7 @@ function startMultiAgentStream(event, operation, activeChildParents) {
|
|
|
30195
30475
|
const metadata = {
|
|
30196
30476
|
"strands.operation": operation,
|
|
30197
30477
|
provider: "strands",
|
|
30198
|
-
..._optionalChain([orchestrator, 'optionalAccess',
|
|
30478
|
+
..._optionalChain([orchestrator, 'optionalAccess', _861 => _861.id]) ? { "strands.orchestrator.id": orchestrator.id } : {},
|
|
30199
30479
|
...event.moduleVersion ? { "strands_agent_sdk.version": event.moduleVersion } : {}
|
|
30200
30480
|
};
|
|
30201
30481
|
const parentSpan = orchestrator ? getOnlyChildParent(activeChildParents, orchestrator) : void 0;
|
|
@@ -30258,7 +30538,7 @@ function handleAgentStreamEvent(state, event) {
|
|
|
30258
30538
|
},
|
|
30259
30539
|
metrics: {
|
|
30260
30540
|
...buildDurationMetrics4(state.startTime),
|
|
30261
|
-
...parseUsage(_optionalChain([event, 'access',
|
|
30541
|
+
...parseUsage(_optionalChain([event, 'access', _862 => _862.result, 'optionalAccess', _863 => _863.metrics, 'optionalAccess', _864 => _864.accumulatedUsage]))
|
|
30262
30542
|
},
|
|
30263
30543
|
output: extractAgentResultOutput(event.result)
|
|
30264
30544
|
});
|
|
@@ -30294,7 +30574,7 @@ function handleMultiAgentStreamEvent(state, event, activeChildParents) {
|
|
|
30294
30574
|
},
|
|
30295
30575
|
metrics: {
|
|
30296
30576
|
...buildDurationMetrics4(state.startTime),
|
|
30297
|
-
...parseUsage(_optionalChain([event, 'access',
|
|
30577
|
+
...parseUsage(_optionalChain([event, 'access', _865 => _865.result, 'optionalAccess', _866 => _866.usage]))
|
|
30298
30578
|
},
|
|
30299
30579
|
output: extractMultiAgentResultOutput(event.result)
|
|
30300
30580
|
});
|
|
@@ -30310,7 +30590,7 @@ function startModelSpan(state, event) {
|
|
|
30310
30590
|
if (state.activeModel) {
|
|
30311
30591
|
finalizeModelSpan(state);
|
|
30312
30592
|
}
|
|
30313
|
-
const model = _nullishCoalesce(event.model, () => ( _optionalChain([event, 'access',
|
|
30593
|
+
const model = _nullishCoalesce(event.model, () => ( _optionalChain([event, 'access', _867 => _867.agent, 'optionalAccess', _868 => _868.model])));
|
|
30314
30594
|
const metadata = {
|
|
30315
30595
|
...extractModelMetadata3(model),
|
|
30316
30596
|
"strands.operation": "model.stream",
|
|
@@ -30321,7 +30601,7 @@ function startModelSpan(state, event) {
|
|
|
30321
30601
|
state.span,
|
|
30322
30602
|
() => startSpan({
|
|
30323
30603
|
event: {
|
|
30324
|
-
input: Array.isArray(_optionalChain([event, 'access',
|
|
30604
|
+
input: Array.isArray(_optionalChain([event, 'access', _869 => _869.agent, 'optionalAccess', _870 => _870.messages])) ? processStrandsInputAttachments(
|
|
30325
30605
|
event.agent.messages,
|
|
30326
30606
|
state.attachmentCache
|
|
30327
30607
|
) : void 0,
|
|
@@ -30339,7 +30619,7 @@ function startModelSpan(state, event) {
|
|
|
30339
30619
|
};
|
|
30340
30620
|
}
|
|
30341
30621
|
function collectModelStreamMetadata(state, event) {
|
|
30342
|
-
if (!state.activeModel || _optionalChain([event, 'access',
|
|
30622
|
+
if (!state.activeModel || _optionalChain([event, 'access', _871 => _871.event, 'optionalAccess', _872 => _872.type]) !== "modelMetadataEvent") {
|
|
30343
30623
|
return;
|
|
30344
30624
|
}
|
|
30345
30625
|
Object.assign(state.activeModel.metrics, parseUsage(event.event.usage));
|
|
@@ -30356,18 +30636,18 @@ function finalizeModelSpan(state, event) {
|
|
|
30356
30636
|
state.activeModel = void 0;
|
|
30357
30637
|
const metadata = {
|
|
30358
30638
|
...modelState.metadata,
|
|
30359
|
-
..._optionalChain([event, 'optionalAccess',
|
|
30360
|
-
..._optionalChain([event, 'optionalAccess',
|
|
30639
|
+
..._optionalChain([event, 'optionalAccess', _873 => _873.attemptCount]) ? { "strands.model.attempt": event.attemptCount } : {},
|
|
30640
|
+
..._optionalChain([event, 'optionalAccess', _874 => _874.stopData, 'optionalAccess', _875 => _875.stopReason]) ? { "strands.stop_reason": event.stopData.stopReason } : {}
|
|
30361
30641
|
};
|
|
30362
30642
|
const metrics = {
|
|
30363
30643
|
...buildDurationMetrics4(modelState.startTime),
|
|
30364
30644
|
...modelState.metrics
|
|
30365
30645
|
};
|
|
30366
30646
|
safeLog5(modelState.span, {
|
|
30367
|
-
..._optionalChain([event, 'optionalAccess',
|
|
30647
|
+
..._optionalChain([event, 'optionalAccess', _876 => _876.error]) ? { error: toLoggedError(event.error) } : {},
|
|
30368
30648
|
metadata,
|
|
30369
30649
|
metrics: cleanMetrics6(metrics),
|
|
30370
|
-
output: _optionalChain([event, 'optionalAccess',
|
|
30650
|
+
output: _optionalChain([event, 'optionalAccess', _877 => _877.stopData, 'optionalAccess', _878 => _878.message])
|
|
30371
30651
|
});
|
|
30372
30652
|
modelState.span.end();
|
|
30373
30653
|
}
|
|
@@ -30383,9 +30663,9 @@ function startToolSpan2(state, event) {
|
|
|
30383
30663
|
state.span,
|
|
30384
30664
|
() => startSpan({
|
|
30385
30665
|
event: {
|
|
30386
|
-
input: _optionalChain([toolUse, 'optionalAccess',
|
|
30666
|
+
input: _optionalChain([toolUse, 'optionalAccess', _879 => _879.input]),
|
|
30387
30667
|
metadata: {
|
|
30388
|
-
"gen_ai.tool.call.id": _optionalChain([toolUse, 'optionalAccess',
|
|
30668
|
+
"gen_ai.tool.call.id": _optionalChain([toolUse, 'optionalAccess', _880 => _880.toolUseId]),
|
|
30389
30669
|
"gen_ai.tool.name": name,
|
|
30390
30670
|
"strands.operation": "tool.call",
|
|
30391
30671
|
"strands.tool.name": name,
|
|
@@ -30438,8 +30718,8 @@ function finalizeToolSpanState(toolState, data = {}) {
|
|
|
30438
30718
|
safeLog5(toolState.span, {
|
|
30439
30719
|
...data.error ? { error: toLoggedError(data.error) } : {},
|
|
30440
30720
|
metadata: {
|
|
30441
|
-
..._nullishCoalesce(_optionalChain([data, 'access',
|
|
30442
|
-
"gen_ai.tool.call.id": _nullishCoalesce(_optionalChain([data, 'access',
|
|
30721
|
+
..._nullishCoalesce(_optionalChain([data, 'access', _881 => _881.toolUse, 'optionalAccess', _882 => _882.toolUseId]), () => ( _optionalChain([toolState, 'access', _883 => _883.toolUse, 'optionalAccess', _884 => _884.toolUseId]))) ? {
|
|
30722
|
+
"gen_ai.tool.call.id": _nullishCoalesce(_optionalChain([data, 'access', _885 => _885.toolUse, 'optionalAccess', _886 => _886.toolUseId]), () => ( _optionalChain([toolState, 'access', _887 => _887.toolUse, 'optionalAccess', _888 => _888.toolUseId])))
|
|
30443
30723
|
} : {},
|
|
30444
30724
|
...extractToolName3(_nullishCoalesce(data.toolUse, () => ( toolState.toolUse))) ? {
|
|
30445
30725
|
"gen_ai.tool.name": extractToolName3(
|
|
@@ -30459,7 +30739,7 @@ function startNodeSpan(state, event, activeChildParents) {
|
|
|
30459
30739
|
const child = extractNodeChild(node);
|
|
30460
30740
|
const metadata = {
|
|
30461
30741
|
"strands.node.id": nodeId,
|
|
30462
|
-
..._optionalChain([node, 'optionalAccess',
|
|
30742
|
+
..._optionalChain([node, 'optionalAccess', _889 => _889.type]) ? { "strands.node.type": node.type } : {},
|
|
30463
30743
|
"strands.operation": "node.call",
|
|
30464
30744
|
provider: "strands"
|
|
30465
30745
|
};
|
|
@@ -30482,21 +30762,21 @@ function startNodeSpan(state, event, activeChildParents) {
|
|
|
30482
30762
|
}
|
|
30483
30763
|
}
|
|
30484
30764
|
function logNodeResult(state, event) {
|
|
30485
|
-
const nodeId = _nullishCoalesce(_nullishCoalesce(event.nodeId, () => ( _optionalChain([event, 'access',
|
|
30765
|
+
const nodeId = _nullishCoalesce(_nullishCoalesce(event.nodeId, () => ( _optionalChain([event, 'access', _890 => _890.result, 'optionalAccess', _891 => _891.nodeId]))), () => ( "unknown"));
|
|
30486
30766
|
const nodeState = state.activeNodes.get(nodeId);
|
|
30487
30767
|
if (!nodeState) {
|
|
30488
30768
|
return;
|
|
30489
30769
|
}
|
|
30490
30770
|
safeLog5(nodeState.span, {
|
|
30491
|
-
..._optionalChain([event, 'access',
|
|
30771
|
+
..._optionalChain([event, 'access', _892 => _892.result, 'optionalAccess', _893 => _893.error]) ? { error: toLoggedError(event.result.error) } : {},
|
|
30492
30772
|
metadata: {
|
|
30493
30773
|
...event.nodeType ? { "strands.node.type": event.nodeType } : {},
|
|
30494
|
-
..._optionalChain([event, 'access',
|
|
30774
|
+
..._optionalChain([event, 'access', _894 => _894.result, 'optionalAccess', _895 => _895.status]) ? { "strands.node.status": event.result.status } : {}
|
|
30495
30775
|
},
|
|
30496
30776
|
metrics: {
|
|
30497
30777
|
...buildDurationMetrics4(nodeState.startTime),
|
|
30498
|
-
...typeof _optionalChain([event, 'access',
|
|
30499
|
-
...parseUsage(_optionalChain([event, 'access',
|
|
30778
|
+
...typeof _optionalChain([event, 'access', _896 => _896.result, 'optionalAccess', _897 => _897.duration]) === "number" ? { "strands.node.duration_ms": event.result.duration } : {},
|
|
30779
|
+
...parseUsage(_optionalChain([event, 'access', _898 => _898.result, 'optionalAccess', _899 => _899.usage]))
|
|
30500
30780
|
},
|
|
30501
30781
|
output: extractNodeResultOutput(event.result)
|
|
30502
30782
|
});
|
|
@@ -30569,9 +30849,9 @@ function extractOrchestrator(event) {
|
|
|
30569
30849
|
}
|
|
30570
30850
|
function extractAgentMetadata2(agent) {
|
|
30571
30851
|
return {
|
|
30572
|
-
..._optionalChain([agent, 'optionalAccess',
|
|
30573
|
-
..._optionalChain([agent, 'optionalAccess',
|
|
30574
|
-
..._optionalChain([agent, 'optionalAccess',
|
|
30852
|
+
..._optionalChain([agent, 'optionalAccess', _900 => _900.id]) ? { "strands.agent.id": agent.id } : {},
|
|
30853
|
+
..._optionalChain([agent, 'optionalAccess', _901 => _901.name]) ? { "strands.agent.name": agent.name } : {},
|
|
30854
|
+
..._optionalChain([agent, 'optionalAccess', _902 => _902.description]) ? { "strands.agent.description": agent.description } : {}
|
|
30575
30855
|
};
|
|
30576
30856
|
}
|
|
30577
30857
|
function extractModelMetadata3(model) {
|
|
@@ -30579,28 +30859,28 @@ function extractModelMetadata3(model) {
|
|
|
30579
30859
|
const modelName2 = extractModelName2(model);
|
|
30580
30860
|
return {
|
|
30581
30861
|
...modelName2 ? { model: modelName2 } : {},
|
|
30582
|
-
..._optionalChain([config, 'optionalAccess',
|
|
30583
|
-
..._optionalChain([model, 'optionalAccess',
|
|
30862
|
+
..._optionalChain([config, 'optionalAccess', _903 => _903.api]) ? { "strands.model.api": config.api } : {},
|
|
30863
|
+
..._optionalChain([model, 'optionalAccess', _904 => _904.stateful]) !== void 0 ? { "strands.model.stateful": model.stateful } : {}
|
|
30584
30864
|
};
|
|
30585
30865
|
}
|
|
30586
30866
|
function extractAgentResultMetadata(result) {
|
|
30587
30867
|
return {
|
|
30588
|
-
..._optionalChain([result, 'optionalAccess',
|
|
30589
|
-
...typeof _optionalChain([result, 'optionalAccess',
|
|
30590
|
-
...typeof _optionalChain([result, 'optionalAccess',
|
|
30868
|
+
..._optionalChain([result, 'optionalAccess', _905 => _905.stopReason]) ? { "strands.stop_reason": result.stopReason } : {},
|
|
30869
|
+
...typeof _optionalChain([result, 'optionalAccess', _906 => _906.metrics, 'optionalAccess', _907 => _907.latestContextSize]) === "number" ? { "strands.context_size": result.metrics.latestContextSize } : {},
|
|
30870
|
+
...typeof _optionalChain([result, 'optionalAccess', _908 => _908.metrics, 'optionalAccess', _909 => _909.projectedContextSize]) === "number" ? {
|
|
30591
30871
|
"strands.projected_context_size": result.metrics.projectedContextSize
|
|
30592
30872
|
} : {}
|
|
30593
30873
|
};
|
|
30594
30874
|
}
|
|
30595
30875
|
function extractMultiAgentResultMetadata(result) {
|
|
30596
30876
|
return {
|
|
30597
|
-
..._optionalChain([result, 'optionalAccess',
|
|
30598
|
-
...typeof _optionalChain([result, 'optionalAccess',
|
|
30877
|
+
..._optionalChain([result, 'optionalAccess', _910 => _910.status]) ? { "strands.status": result.status } : {},
|
|
30878
|
+
...typeof _optionalChain([result, 'optionalAccess', _911 => _911.duration]) === "number" ? { "strands.duration_ms": result.duration } : {}
|
|
30599
30879
|
};
|
|
30600
30880
|
}
|
|
30601
30881
|
function extractProvider(model) {
|
|
30602
30882
|
const config = getModelConfig(model);
|
|
30603
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30883
|
+
if (typeof _optionalChain([config, 'optionalAccess', _912 => _912.provider]) === "string") {
|
|
30604
30884
|
return config.provider;
|
|
30605
30885
|
}
|
|
30606
30886
|
const constructorName = getConstructorName(model).toLowerCase();
|
|
@@ -30623,13 +30903,13 @@ function extractProvider(model) {
|
|
|
30623
30903
|
}
|
|
30624
30904
|
function extractModelName2(model) {
|
|
30625
30905
|
const config = getModelConfig(model);
|
|
30626
|
-
if (typeof _optionalChain([model, 'optionalAccess',
|
|
30906
|
+
if (typeof _optionalChain([model, 'optionalAccess', _913 => _913.modelId]) === "string") {
|
|
30627
30907
|
return model.modelId;
|
|
30628
30908
|
}
|
|
30629
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30909
|
+
if (typeof _optionalChain([config, 'optionalAccess', _914 => _914.modelId]) === "string") {
|
|
30630
30910
|
return config.modelId;
|
|
30631
30911
|
}
|
|
30632
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30912
|
+
if (typeof _optionalChain([config, 'optionalAccess', _915 => _915.model]) === "string") {
|
|
30633
30913
|
return config.model;
|
|
30634
30914
|
}
|
|
30635
30915
|
return void 0;
|
|
@@ -30646,7 +30926,7 @@ function getModelConfig(model) {
|
|
|
30646
30926
|
}
|
|
30647
30927
|
}
|
|
30648
30928
|
function formatAgentSpanName(agent) {
|
|
30649
|
-
return _optionalChain([agent, 'optionalAccess',
|
|
30929
|
+
return _optionalChain([agent, 'optionalAccess', _916 => _916.name]) ? `Agent: ${agent.name}` : "Strands Agent";
|
|
30650
30930
|
}
|
|
30651
30931
|
function formatModelSpanName(model) {
|
|
30652
30932
|
const modelName2 = extractModelName2(model);
|
|
@@ -30823,7 +31103,7 @@ function createStrandsMediaAttachment(mediaKey, media, cache) {
|
|
|
30823
31103
|
function getOrCreateStrandsAttachment(data, filename, contentType, cache) {
|
|
30824
31104
|
const key = `${contentType}\0${filename}`;
|
|
30825
31105
|
const attachments = typeof data === "string" ? cache.strings.get(data) : isObject(data) ? cache.objects.get(data) : void 0;
|
|
30826
|
-
const cached = _optionalChain([attachments, 'optionalAccess',
|
|
31106
|
+
const cached = _optionalChain([attachments, 'optionalAccess', _917 => _917.get, 'call', _918 => _918(key)]);
|
|
30827
31107
|
if (cached) {
|
|
30828
31108
|
return cached;
|
|
30829
31109
|
}
|
|
@@ -30851,24 +31131,24 @@ function normalizeContentBlocks(blocks) {
|
|
|
30851
31131
|
}
|
|
30852
31132
|
function parseUsage(usage) {
|
|
30853
31133
|
const metrics = {};
|
|
30854
|
-
assignMetric(metrics, "prompt_tokens", _optionalChain([usage, 'optionalAccess',
|
|
30855
|
-
assignMetric(metrics, "completion_tokens", _optionalChain([usage, 'optionalAccess',
|
|
30856
|
-
assignMetric(metrics, "tokens", _optionalChain([usage, 'optionalAccess',
|
|
30857
|
-
assignMetric(metrics, "prompt_cached_tokens", _optionalChain([usage, 'optionalAccess',
|
|
31134
|
+
assignMetric(metrics, "prompt_tokens", _optionalChain([usage, 'optionalAccess', _919 => _919.inputTokens]));
|
|
31135
|
+
assignMetric(metrics, "completion_tokens", _optionalChain([usage, 'optionalAccess', _920 => _920.outputTokens]));
|
|
31136
|
+
assignMetric(metrics, "tokens", _optionalChain([usage, 'optionalAccess', _921 => _921.totalTokens]));
|
|
31137
|
+
assignMetric(metrics, "prompt_cached_tokens", _optionalChain([usage, 'optionalAccess', _922 => _922.cacheReadInputTokens]));
|
|
30858
31138
|
assignMetric(
|
|
30859
31139
|
metrics,
|
|
30860
31140
|
"prompt_cache_creation_tokens",
|
|
30861
|
-
_optionalChain([usage, 'optionalAccess',
|
|
31141
|
+
_optionalChain([usage, 'optionalAccess', _923 => _923.cacheWriteInputTokens])
|
|
30862
31142
|
);
|
|
30863
31143
|
return metrics;
|
|
30864
31144
|
}
|
|
30865
31145
|
function parseModelMetrics(metrics) {
|
|
30866
31146
|
const parsed = {};
|
|
30867
|
-
assignMetric(parsed, "strands.latency_ms", _optionalChain([metrics, 'optionalAccess',
|
|
31147
|
+
assignMetric(parsed, "strands.latency_ms", _optionalChain([metrics, 'optionalAccess', _924 => _924.latencyMs]));
|
|
30868
31148
|
assignMetric(
|
|
30869
31149
|
parsed,
|
|
30870
31150
|
"strands.time_to_first_byte_ms",
|
|
30871
|
-
_optionalChain([metrics, 'optionalAccess',
|
|
31151
|
+
_optionalChain([metrics, 'optionalAccess', _925 => _925.timeToFirstByteMs])
|
|
30872
31152
|
);
|
|
30873
31153
|
return parsed;
|
|
30874
31154
|
}
|
|
@@ -30895,20 +31175,20 @@ function cleanMetrics6(metrics) {
|
|
|
30895
31175
|
return cleaned;
|
|
30896
31176
|
}
|
|
30897
31177
|
function extractToolName3(toolUse, tool) {
|
|
30898
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess',
|
|
31178
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess', _926 => _926.name]), () => ( _optionalChain([tool, 'optionalAccess', _927 => _927.name]))), () => ( "unknown"));
|
|
30899
31179
|
}
|
|
30900
31180
|
function toolKey2(toolUse) {
|
|
30901
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess',
|
|
31181
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess', _928 => _928.toolUseId]), () => ( _optionalChain([toolUse, 'optionalAccess', _929 => _929.name]))), () => ( "unknown"));
|
|
30902
31182
|
}
|
|
30903
31183
|
function findNode(orchestrator, nodeId) {
|
|
30904
31184
|
try {
|
|
30905
|
-
return _optionalChain([orchestrator, 'optionalAccess',
|
|
30906
|
-
} catch (
|
|
31185
|
+
return _optionalChain([orchestrator, 'optionalAccess', _930 => _930.nodes, 'optionalAccess', _931 => _931.get, 'call', _932 => _932(nodeId)]);
|
|
31186
|
+
} catch (e76) {
|
|
30907
31187
|
return void 0;
|
|
30908
31188
|
}
|
|
30909
31189
|
}
|
|
30910
31190
|
function extractNodeChild(node) {
|
|
30911
|
-
const child = _nullishCoalesce(_optionalChain([node, 'optionalAccess',
|
|
31191
|
+
const child = _nullishCoalesce(_optionalChain([node, 'optionalAccess', _933 => _933.agent]), () => ( _optionalChain([node, 'optionalAccess', _934 => _934.orchestrator])));
|
|
30912
31192
|
return isObject(child) ? child : void 0;
|
|
30913
31193
|
}
|
|
30914
31194
|
function pushChildParent(activeChildParents, child, span) {
|
|
@@ -31286,7 +31566,7 @@ function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
|
31286
31566
|
return { integrations };
|
|
31287
31567
|
}
|
|
31288
31568
|
function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
31289
|
-
return names.some((name) => _optionalChain([integrations, 'optionalAccess',
|
|
31569
|
+
return names.some((name) => _optionalChain([integrations, 'optionalAccess', _935 => _935[name]]) === false);
|
|
31290
31570
|
}
|
|
31291
31571
|
|
|
31292
31572
|
// src/instrumentation/registry.ts
|
|
@@ -31668,11 +31948,17 @@ function configureNode() {
|
|
|
31668
31948
|
isomorph_default.getPastNAncestors = getPastNAncestors;
|
|
31669
31949
|
isomorph_default.getEnv = (name) => {
|
|
31670
31950
|
const value = process.env[name];
|
|
31671
|
-
|
|
31951
|
+
if (name === "BRAINTRUST_API_KEY") {
|
|
31952
|
+
return _optionalChain([value, 'optionalAccess', _936 => _936.trim, 'call', _937 => _937()]) ? value : void 0;
|
|
31953
|
+
}
|
|
31954
|
+
if ((name === "BRAINTRUST_ENVIRONMENT_TYPE" || name === "BRAINTRUST_ENVIRONMENT_NAME") && !_optionalChain([value, 'optionalAccess', _938 => _938.trim, 'call', _939 => _939()])) {
|
|
31955
|
+
return getNearestBraintrustEnvValue(name);
|
|
31956
|
+
}
|
|
31957
|
+
return value;
|
|
31672
31958
|
};
|
|
31673
31959
|
isomorph_default.getBraintrustApiKey = async () => {
|
|
31674
31960
|
const value = process.env.BRAINTRUST_API_KEY;
|
|
31675
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
31961
|
+
if (_optionalChain([value, 'optionalAccess', _940 => _940.trim, 'call', _941 => _941()])) {
|
|
31676
31962
|
return value;
|
|
31677
31963
|
}
|
|
31678
31964
|
const envPaths = [];
|
|
@@ -31703,7 +31989,7 @@ function configureNode() {
|
|
|
31703
31989
|
if ("contents" in nearestResult) {
|
|
31704
31990
|
const parsed = dotenv.parse(nearestResult.contents);
|
|
31705
31991
|
const apiKey = parsed.BRAINTRUST_API_KEY;
|
|
31706
|
-
return _optionalChain([apiKey, 'optionalAccess',
|
|
31992
|
+
return _optionalChain([apiKey, 'optionalAccess', _942 => _942.trim, 'call', _943 => _943()]) ? apiKey : void 0;
|
|
31707
31993
|
}
|
|
31708
31994
|
const e = nearestResult.error;
|
|
31709
31995
|
if (typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT") {
|
|
@@ -31753,6 +32039,24 @@ function configureNode() {
|
|
|
31753
32039
|
}
|
|
31754
32040
|
registry.enable();
|
|
31755
32041
|
}
|
|
32042
|
+
function getNearestBraintrustEnvValue(name) {
|
|
32043
|
+
for (let dir2 = process.cwd(), depth = 0; depth <= BRAINTRUST_ENV_SEARCH_PARENT_LIMIT; dir2 = path.dirname(dir2), depth++) {
|
|
32044
|
+
const envPath = path.join(dir2, ".env.braintrust");
|
|
32045
|
+
try {
|
|
32046
|
+
const parsed = dotenv.parse(fsSync.readFileSync(envPath, "utf8"));
|
|
32047
|
+
const value = parsed[name];
|
|
32048
|
+
return _optionalChain([value, 'optionalAccess', _944 => _944.trim, 'call', _945 => _945()]) ? value : void 0;
|
|
32049
|
+
} catch (e) {
|
|
32050
|
+
if (typeof e !== "object" || e === null || !("code" in e) || e.code !== "ENOENT") {
|
|
32051
|
+
return void 0;
|
|
32052
|
+
}
|
|
32053
|
+
}
|
|
32054
|
+
if (path.dirname(dir2) === dir2) {
|
|
32055
|
+
break;
|
|
32056
|
+
}
|
|
32057
|
+
}
|
|
32058
|
+
return void 0;
|
|
32059
|
+
}
|
|
31756
32060
|
|
|
31757
32061
|
// dev/server.ts
|
|
31758
32062
|
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
@@ -32897,6 +33201,10 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
|
|
|
32897
33201
|
this._state = _state;
|
|
32898
33202
|
this.spanTypeFilter = spanTypeFilter;
|
|
32899
33203
|
}
|
|
33204
|
+
|
|
33205
|
+
|
|
33206
|
+
|
|
33207
|
+
|
|
32900
33208
|
static buildFilter(rootSpanId, spanTypeFilter, includeScorers = false) {
|
|
32901
33209
|
const children = [
|
|
32902
33210
|
// Base filter: root_span_id = 'value'
|
|
@@ -33009,7 +33317,7 @@ var CachedSpanFetcher = (_class31 = class {
|
|
|
33009
33317
|
async fetchSpans(spanType) {
|
|
33010
33318
|
const spans = await this.fetchFn(spanType, false);
|
|
33011
33319
|
for (const span of spans) {
|
|
33012
|
-
const type = _nullishCoalesce(_optionalChain([span, 'access',
|
|
33320
|
+
const type = _nullishCoalesce(_optionalChain([span, 'access', _946 => _946.span_attributes, 'optionalAccess', _947 => _947.type]), () => ( ""));
|
|
33013
33321
|
const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
|
|
33014
33322
|
existing.push(span);
|
|
33015
33323
|
this.spanCache.set(type, existing);
|
|
@@ -33092,11 +33400,11 @@ var LocalTrace = (_class32 = class {
|
|
|
33092
33400
|
const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
|
|
33093
33401
|
if (cachedSpans && cachedSpans.length > 0) {
|
|
33094
33402
|
let spans = includeScorers ? cachedSpans : cachedSpans.filter(
|
|
33095
|
-
(span) => _optionalChain([span, 'access',
|
|
33403
|
+
(span) => _optionalChain([span, 'access', _948 => _948.span_attributes, 'optionalAccess', _949 => _949.purpose]) !== "scorer"
|
|
33096
33404
|
);
|
|
33097
33405
|
if (spanType && spanType.length > 0) {
|
|
33098
33406
|
spans = spans.filter(
|
|
33099
|
-
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access',
|
|
33407
|
+
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _950 => _950.span_attributes, 'optionalAccess', _951 => _951.type]), () => ( "")))
|
|
33100
33408
|
);
|
|
33101
33409
|
}
|
|
33102
33410
|
return spans.map((span) => ({
|
|
@@ -33121,7 +33429,7 @@ var LocalTrace = (_class32 = class {
|
|
|
33121
33429
|
* Calls the API with the project_default preprocessor (which falls back to "thread").
|
|
33122
33430
|
*/
|
|
33123
33431
|
async getThread(options) {
|
|
33124
|
-
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
33432
|
+
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _952 => _952.preprocessor]), () => ( "project_default"));
|
|
33125
33433
|
if (!this.threadCache.has(cacheKey)) {
|
|
33126
33434
|
const promise = this.fetchThread(options);
|
|
33127
33435
|
this.threadCache.set(cacheKey, promise);
|
|
@@ -33132,7 +33440,7 @@ var LocalTrace = (_class32 = class {
|
|
|
33132
33440
|
await this.ensureSpansReady();
|
|
33133
33441
|
await this.state.login({});
|
|
33134
33442
|
const result = await invoke({
|
|
33135
|
-
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
33443
|
+
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _953 => _953.preprocessor]), () => ( "project_default")),
|
|
33136
33444
|
functionType: "preprocessor",
|
|
33137
33445
|
input: {
|
|
33138
33446
|
trace_ref: {
|
|
@@ -33308,10 +33616,10 @@ function validateParametersWithJsonSchema(parameters, schema) {
|
|
|
33308
33616
|
const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
|
|
33309
33617
|
const validate = ajv.compile(schema);
|
|
33310
33618
|
if (!validate(parameters)) {
|
|
33311
|
-
const errorMessages = _optionalChain([validate, 'access',
|
|
33619
|
+
const errorMessages = _optionalChain([validate, 'access', _954 => _954.errors, 'optionalAccess', _955 => _955.map, 'call', _956 => _956((err) => {
|
|
33312
33620
|
const path2 = err.instancePath || "root";
|
|
33313
33621
|
return `${path2}: ${err.message}`;
|
|
33314
|
-
}), 'access',
|
|
33622
|
+
}), 'access', _957 => _957.join, 'call', _958 => _958(", ")]);
|
|
33315
33623
|
throw Error(`Invalid parameters: ${errorMessages}`);
|
|
33316
33624
|
}
|
|
33317
33625
|
return rehydrateRemoteParameters(parameters, schema);
|
|
@@ -33344,6 +33652,8 @@ var EvalResultWithSummary = class {
|
|
|
33344
33652
|
this.summary = summary;
|
|
33345
33653
|
this.results = results;
|
|
33346
33654
|
}
|
|
33655
|
+
|
|
33656
|
+
|
|
33347
33657
|
/**
|
|
33348
33658
|
* @deprecated Use `summary` instead.
|
|
33349
33659
|
*/
|
|
@@ -33363,7 +33673,7 @@ var EvalResultWithSummary = class {
|
|
|
33363
33673
|
async function getPersistedBaseExperimentId(experiment) {
|
|
33364
33674
|
try {
|
|
33365
33675
|
return await experiment._getBaseExperimentId();
|
|
33366
|
-
} catch (
|
|
33676
|
+
} catch (e77) {
|
|
33367
33677
|
return void 0;
|
|
33368
33678
|
}
|
|
33369
33679
|
}
|
|
@@ -33658,7 +33968,7 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters, st
|
|
|
33658
33968
|
}
|
|
33659
33969
|
async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
|
|
33660
33970
|
if (enableCache) {
|
|
33661
|
-
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
33971
|
+
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _959 => _959.spanCache, 'optionalAccess', _960 => _960.start, 'call', _961 => _961()]);
|
|
33662
33972
|
}
|
|
33663
33973
|
try {
|
|
33664
33974
|
if (typeof evaluator.data === "string") {
|
|
@@ -33713,7 +34023,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33713
34023
|
const experimentIdPromise = experiment ? (async () => {
|
|
33714
34024
|
try {
|
|
33715
34025
|
return await experiment.id;
|
|
33716
|
-
} catch (
|
|
34026
|
+
} catch (e78) {
|
|
33717
34027
|
return void 0;
|
|
33718
34028
|
}
|
|
33719
34029
|
})() : void 0;
|
|
@@ -33738,7 +34048,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33738
34048
|
_xact_id: datum._xact_id
|
|
33739
34049
|
} : void 0;
|
|
33740
34050
|
const parsedDatumOrigin = ObjectReference.safeParse(datum.origin);
|
|
33741
|
-
const origin = _nullishCoalesce(inlineDatasetOrigin, () => ( (_optionalChain([parsedDatumOrigin, 'optionalAccess',
|
|
34051
|
+
const origin = _nullishCoalesce(inlineDatasetOrigin, () => ( (_optionalChain([parsedDatumOrigin, 'optionalAccess', _962 => _962.success]) ? parsedDatumOrigin.data : void 0)));
|
|
33742
34052
|
const baseEvent = {
|
|
33743
34053
|
name: "eval",
|
|
33744
34054
|
spanAttributes: {
|
|
@@ -33772,7 +34082,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33772
34082
|
objectType: parentComponents ? spanObjectTypeV3ToTypedString(
|
|
33773
34083
|
parentComponents.data.object_type
|
|
33774
34084
|
) : "experiment",
|
|
33775
|
-
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async
|
|
34085
|
+
objectId: await _asyncNullishCoalesce(await _asyncOptionalChain([parentComponents, 'optionalAccess', async _963 => _963.data, 'access', async _964 => _964.object_id]), async () => ( (experimentIdPromise ? await _asyncNullishCoalesce(await experimentIdPromise, async () => ( "")) : ""))),
|
|
33776
34086
|
rootSpanId: rootSpan.rootSpanId,
|
|
33777
34087
|
ensureSpansFlushed,
|
|
33778
34088
|
state
|
|
@@ -33802,10 +34112,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33802
34112
|
span,
|
|
33803
34113
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
33804
34114
|
reportProgress: (event) => {
|
|
33805
|
-
_optionalChain([stream, 'optionalCall',
|
|
34115
|
+
_optionalChain([stream, 'optionalCall', _965 => _965({
|
|
33806
34116
|
...event,
|
|
33807
34117
|
id: rootSpan.id,
|
|
33808
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
34118
|
+
origin: _optionalChain([baseEvent, 'access', _966 => _966.event, 'optionalAccess', _967 => _967.origin]),
|
|
33809
34119
|
name: evaluator.evalName,
|
|
33810
34120
|
object_type: "task"
|
|
33811
34121
|
})]);
|
|
@@ -33993,7 +34303,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33993
34303
|
tags: tags.length ? tags : void 0,
|
|
33994
34304
|
metadata,
|
|
33995
34305
|
error,
|
|
33996
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
34306
|
+
origin: _optionalChain([baseEvent, 'access', _968 => _968.event, 'optionalAccess', _969 => _969.origin])
|
|
33997
34307
|
};
|
|
33998
34308
|
collectedResults.push({
|
|
33999
34309
|
...baseResult,
|
|
@@ -34033,7 +34343,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
34033
34343
|
break;
|
|
34034
34344
|
}
|
|
34035
34345
|
scheduledTrials++;
|
|
34036
|
-
_optionalChain([progressReporter, 'access',
|
|
34346
|
+
_optionalChain([progressReporter, 'access', _970 => _970.setTotal, 'optionalCall', _971 => _971(evaluator.evalName, scheduledTrials)]);
|
|
34037
34347
|
q.pushAsync({ datum, trialIndex }).catch((e) => {
|
|
34038
34348
|
if (queueErrors.length < 5) {
|
|
34039
34349
|
queueErrors.push(e);
|
|
@@ -34120,9 +34430,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
34120
34430
|
);
|
|
34121
34431
|
} finally {
|
|
34122
34432
|
if (enableCache) {
|
|
34123
|
-
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
34124
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
34125
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
34433
|
+
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _972 => _972.spanCache]);
|
|
34434
|
+
_optionalChain([spanCache, 'optionalAccess', _973 => _973.dispose, 'call', _974 => _974()]);
|
|
34435
|
+
_optionalChain([spanCache, 'optionalAccess', _975 => _975.stop, 'call', _976 => _976()]);
|
|
34126
34436
|
}
|
|
34127
34437
|
}
|
|
34128
34438
|
}
|
|
@@ -34362,7 +34672,7 @@ async function cachedLogin(options) {
|
|
|
34362
34672
|
}
|
|
34363
34673
|
function makeCheckAuthorized(allowedOrgName) {
|
|
34364
34674
|
return async (req, _res, next) => {
|
|
34365
|
-
if (!_optionalChain([req, 'access',
|
|
34675
|
+
if (!_optionalChain([req, 'access', _977 => _977.ctx, 'optionalAccess', _978 => _978.token])) {
|
|
34366
34676
|
return next(_httperrors2.default.call(void 0, 401, "Unauthorized"));
|
|
34367
34677
|
}
|
|
34368
34678
|
try {
|
|
@@ -34375,7 +34685,7 @@ function makeCheckAuthorized(allowedOrgName) {
|
|
|
34375
34685
|
return next(_httperrors2.default.call(void 0, 403, errorMessage2));
|
|
34376
34686
|
}
|
|
34377
34687
|
const state = await cachedLogin({
|
|
34378
|
-
apiKey: _optionalChain([req, 'access',
|
|
34688
|
+
apiKey: _optionalChain([req, 'access', _979 => _979.ctx, 'optionalAccess', _980 => _980.token]),
|
|
34379
34689
|
orgName
|
|
34380
34690
|
});
|
|
34381
34691
|
req.ctx.state = state;
|
|
@@ -34636,6 +34946,7 @@ var ToolBuilder = (_class34 = class {
|
|
|
34636
34946
|
constructor(project) {;_class34.prototype.__init125.call(this);
|
|
34637
34947
|
this.project = project;
|
|
34638
34948
|
}
|
|
34949
|
+
|
|
34639
34950
|
__init125() {this.taskCounter = 0}
|
|
34640
34951
|
// This type definition is just a catch all so that the implementation can be
|
|
34641
34952
|
// less specific than the two more specific declarations above.
|
|
@@ -34666,6 +34977,7 @@ var ScorerBuilder = (_class35 = class {
|
|
|
34666
34977
|
constructor(project) {;_class35.prototype.__init126.call(this);
|
|
34667
34978
|
this.project = project;
|
|
34668
34979
|
}
|
|
34980
|
+
|
|
34669
34981
|
__init126() {this.taskCounter = 0}
|
|
34670
34982
|
create(opts) {
|
|
34671
34983
|
this.taskCounter++;
|
|
@@ -34725,6 +35037,7 @@ var ClassifierBuilder = (_class36 = class {
|
|
|
34725
35037
|
constructor(project) {;_class36.prototype.__init127.call(this);
|
|
34726
35038
|
this.project = project;
|
|
34727
35039
|
}
|
|
35040
|
+
|
|
34728
35041
|
__init127() {this.taskCounter = 0}
|
|
34729
35042
|
create(opts) {
|
|
34730
35043
|
this.taskCounter++;
|
|
@@ -34770,6 +35083,7 @@ var CodeFunction = class {
|
|
|
34770
35083
|
|
|
34771
35084
|
|
|
34772
35085
|
|
|
35086
|
+
|
|
34773
35087
|
key() {
|
|
34774
35088
|
return JSON.stringify([
|
|
34775
35089
|
_nullishCoalesce(this.project.id, () => ( "")),
|
|
@@ -34847,6 +35161,7 @@ var PromptBuilder = class {
|
|
|
34847
35161
|
constructor(project) {
|
|
34848
35162
|
this.project = project;
|
|
34849
35163
|
}
|
|
35164
|
+
|
|
34850
35165
|
create(opts) {
|
|
34851
35166
|
const toolFunctions = [];
|
|
34852
35167
|
const rawTools = [];
|
|
@@ -34923,6 +35238,7 @@ var ParametersBuilder = class {
|
|
|
34923
35238
|
constructor(project) {
|
|
34924
35239
|
this.project = project;
|
|
34925
35240
|
}
|
|
35241
|
+
|
|
34926
35242
|
create(opts) {
|
|
34927
35243
|
const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
|
|
34928
35244
|
const codeParameters = new CodeParameters(this.project, {
|
|
@@ -35154,7 +35470,7 @@ function runDevServer(evaluators, opts) {
|
|
|
35154
35470
|
scores,
|
|
35155
35471
|
stream
|
|
35156
35472
|
} = evalBodySchema.parse(req.body);
|
|
35157
|
-
if (!_optionalChain([req, 'access',
|
|
35473
|
+
if (!_optionalChain([req, 'access', _981 => _981.ctx, 'optionalAccess', _982 => _982.state])) {
|
|
35158
35474
|
res.status(500).json({ error: "Braintrust state not initialized in request" });
|
|
35159
35475
|
return;
|
|
35160
35476
|
}
|
|
@@ -35205,12 +35521,12 @@ function runDevServer(evaluators, opts) {
|
|
|
35205
35521
|
...evaluator,
|
|
35206
35522
|
data: evalData.data,
|
|
35207
35523
|
scores: (_nullishCoalesce(evaluator.scores, () => ( []))).concat(
|
|
35208
|
-
_nullishCoalesce(_optionalChain([scores, 'optionalAccess',
|
|
35524
|
+
_nullishCoalesce(_optionalChain([scores, 'optionalAccess', _983 => _983.map, 'call', _984 => _984(
|
|
35209
35525
|
(score) => makeScorer(
|
|
35210
35526
|
state,
|
|
35211
35527
|
score.name,
|
|
35212
35528
|
score.function_id,
|
|
35213
|
-
_optionalChain([req, 'access',
|
|
35529
|
+
_optionalChain([req, 'access', _985 => _985.ctx, 'optionalAccess', _986 => _986.projectId])
|
|
35214
35530
|
)
|
|
35215
35531
|
)]), () => ( []))
|
|
35216
35532
|
),
|