braintrust 3.23.0 → 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 -588
- package/dev/dist/index.mjs +320 -6
- 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 -67
- package/dist/browser.mjs +703 -67
- package/dist/{chunk-CDIKAHDZ.js → chunk-7AUY2XWX.js} +21 -1
- package/dist/{chunk-36IPYKMG.mjs → chunk-7F6GCRHH.mjs} +20 -0
- package/dist/{chunk-FZWPFCVE.js → chunk-SU6EHKJV.js} +1085 -801
- package/dist/{chunk-IXL4PMY4.mjs → chunk-XE5FS7QY.mjs} +291 -7
- package/dist/cli.js +328 -10
- package/dist/edge-light.js +703 -67
- package/dist/edge-light.mjs +703 -67
- 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 -67
- package/dist/instrumentation/index.mjs +601 -67
- package/dist/vitest-evals-reporter.js +17 -16
- package/dist/vitest-evals-reporter.mjs +3 -2
- package/dist/workerd.js +703 -67
- package/dist/workerd.mjs +703 -67
- 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";
|
|
@@ -17475,8 +17745,6 @@ function filterSerializableOptions(options) {
|
|
|
17475
17745
|
"additionalDirectories",
|
|
17476
17746
|
"permissionMode",
|
|
17477
17747
|
"debug",
|
|
17478
|
-
"apiKey",
|
|
17479
|
-
"apiKeySource",
|
|
17480
17748
|
"agentName",
|
|
17481
17749
|
"instructions"
|
|
17482
17750
|
];
|
|
@@ -17514,10 +17782,10 @@ function upsertSubAgentDetails(detailsByToolUseId, toolUseId, update) {
|
|
|
17514
17782
|
return merged;
|
|
17515
17783
|
}
|
|
17516
17784
|
function formatSubAgentSpanName(details) {
|
|
17517
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
17785
|
+
if (_optionalChain([details, 'optionalAccess', _389 => _389.description])) {
|
|
17518
17786
|
return `Agent: ${details.description}`;
|
|
17519
17787
|
}
|
|
17520
|
-
if (_optionalChain([details, 'optionalAccess',
|
|
17788
|
+
if (_optionalChain([details, 'optionalAccess', _390 => _390.agentType])) {
|
|
17521
17789
|
return `Agent: ${details.agentType}`;
|
|
17522
17790
|
}
|
|
17523
17791
|
return "Agent: sub-agent";
|
|
@@ -17572,7 +17840,7 @@ function extractUsageFromMessage(message) {
|
|
|
17572
17840
|
const metrics = {};
|
|
17573
17841
|
let usage;
|
|
17574
17842
|
if (message.type === "assistant") {
|
|
17575
|
-
usage = _optionalChain([message, 'access',
|
|
17843
|
+
usage = _optionalChain([message, 'access', _391 => _391.message, 'optionalAccess', _392 => _392.usage]);
|
|
17576
17844
|
} else if (message.type === "result") {
|
|
17577
17845
|
usage = message.usage;
|
|
17578
17846
|
}
|
|
@@ -17605,15 +17873,15 @@ function buildLLMInput(promptMessages, conversationHistory) {
|
|
|
17605
17873
|
return inputParts.length > 0 ? inputParts : void 0;
|
|
17606
17874
|
}
|
|
17607
17875
|
function conversationMessageFromSDKMessage(message) {
|
|
17608
|
-
const role = _optionalChain([message, 'access',
|
|
17609
|
-
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]);
|
|
17610
17878
|
if (role && content !== void 0) {
|
|
17611
17879
|
return { content, role };
|
|
17612
17880
|
}
|
|
17613
17881
|
return void 0;
|
|
17614
17882
|
}
|
|
17615
17883
|
function messageContentHasBlockType(message, blockType) {
|
|
17616
|
-
const content = _optionalChain([message, 'access',
|
|
17884
|
+
const content = _optionalChain([message, 'access', _397 => _397.message, 'optionalAccess', _398 => _398.content]);
|
|
17617
17885
|
return Array.isArray(content) && content.some(
|
|
17618
17886
|
(block) => typeof block === "object" && block !== null && "type" in block && block.type === blockType
|
|
17619
17887
|
);
|
|
@@ -17637,14 +17905,14 @@ async function createLLMSpanForMessages(messages, promptMessages, conversationHi
|
|
|
17637
17905
|
return void 0;
|
|
17638
17906
|
}
|
|
17639
17907
|
const lastMessage = messages[messages.length - 1];
|
|
17640
|
-
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access',
|
|
17908
|
+
if (lastMessage.type !== "assistant" || !_optionalChain([lastMessage, 'access', _399 => _399.message, 'optionalAccess', _400 => _400.usage])) {
|
|
17641
17909
|
return void 0;
|
|
17642
17910
|
}
|
|
17643
17911
|
const model = lastMessage.message.model || options.model;
|
|
17644
17912
|
const usage = extractUsageFromMessage(lastMessage);
|
|
17645
17913
|
const input = buildLLMInput(promptMessages, conversationHistory);
|
|
17646
17914
|
const outputs = messages.map(
|
|
17647
|
-
(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
|
|
17648
17916
|
).filter(
|
|
17649
17917
|
(c) => c !== void 0
|
|
17650
17918
|
);
|
|
@@ -17664,7 +17932,7 @@ async function createLLMSpanForMessages(messages, promptMessages, conversationHi
|
|
|
17664
17932
|
});
|
|
17665
17933
|
const spanExport = await span.export();
|
|
17666
17934
|
await span.end();
|
|
17667
|
-
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;
|
|
17668
17936
|
return {
|
|
17669
17937
|
finalMessage,
|
|
17670
17938
|
spanExport
|
|
@@ -17800,18 +18068,18 @@ function createToolTracingHooks(resolveParentSpan, activeToolSpans, mcpServers,
|
|
|
17800
18068
|
subAgentDetailsByToolUseId.get(toolUseID)
|
|
17801
18069
|
)
|
|
17802
18070
|
};
|
|
17803
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18071
|
+
if (_optionalChain([response, 'optionalAccess', _409 => _409.status])) {
|
|
17804
18072
|
metadata["claude_agent_sdk.status"] = response.status;
|
|
17805
18073
|
}
|
|
17806
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18074
|
+
if (_optionalChain([response, 'optionalAccess', _410 => _410.totalDurationMs])) {
|
|
17807
18075
|
metadata["claude_agent_sdk.duration_ms"] = response.totalDurationMs;
|
|
17808
18076
|
}
|
|
17809
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
18077
|
+
if (_optionalChain([response, 'optionalAccess', _411 => _411.totalToolUseCount]) !== void 0) {
|
|
17810
18078
|
metadata["claude_agent_sdk.tool_use_count"] = response.totalToolUseCount;
|
|
17811
18079
|
}
|
|
17812
18080
|
subAgentSpan.log({
|
|
17813
18081
|
metadata,
|
|
17814
|
-
output: _optionalChain([response, 'optionalAccess',
|
|
18082
|
+
output: _optionalChain([response, 'optionalAccess', _412 => _412.content])
|
|
17815
18083
|
});
|
|
17816
18084
|
} finally {
|
|
17817
18085
|
subAgentSpan.end();
|
|
@@ -18043,7 +18311,7 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
18043
18311
|
if (state.currentMessages.length === 0) {
|
|
18044
18312
|
return;
|
|
18045
18313
|
}
|
|
18046
|
-
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));
|
|
18047
18315
|
const parentKey = llmParentKey(parentToolUseId);
|
|
18048
18316
|
const conversationHistory = getConversationHistory(state, parentKey);
|
|
18049
18317
|
const promptMessages = parentToolUseId ? _nullishCoalesce(state.promptMessagesByParentKey.get(parentKey), () => ( [])) : buildRootPromptMessages(
|
|
@@ -18083,14 +18351,14 @@ async function finalizeCurrentMessageGroup(state) {
|
|
|
18083
18351
|
}
|
|
18084
18352
|
state.activeLlmSpansByParentToolUse.delete(parentKey);
|
|
18085
18353
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
18086
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
18354
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _416 => _416.message, 'optionalAccess', _417 => _417.usage])) {
|
|
18087
18355
|
state.accumulatedOutputTokens += getNumberProperty(lastMessage.message.usage, "output_tokens") || 0;
|
|
18088
18356
|
}
|
|
18089
18357
|
state.currentMessages.length = 0;
|
|
18090
18358
|
}
|
|
18091
18359
|
function maybeTrackToolUseContext(state, message) {
|
|
18092
18360
|
seedTaskToolUseIdMapping(state.taskIdToToolUseId, message);
|
|
18093
|
-
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]))) {
|
|
18094
18362
|
return;
|
|
18095
18363
|
}
|
|
18096
18364
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
@@ -18293,7 +18561,7 @@ async function handleStreamMessage(state, message) {
|
|
|
18293
18561
|
const messageParentToolUseId = message.parent_tool_use_id;
|
|
18294
18562
|
if (messageParentToolUseId && message.type === "user") {
|
|
18295
18563
|
const conversationMessage = conversationMessageFromSDKMessage(message);
|
|
18296
|
-
if (_optionalChain([conversationMessage, 'optionalAccess',
|
|
18564
|
+
if (_optionalChain([conversationMessage, 'optionalAccess', _420 => _420.role]) === "user") {
|
|
18297
18565
|
await finalizeCurrentMessageGroup(state);
|
|
18298
18566
|
const parentKey = llmParentKey(messageParentToolUseId);
|
|
18299
18567
|
const conversationHistory = getConversationHistory(state, parentKey);
|
|
@@ -18312,13 +18580,13 @@ async function handleStreamMessage(state, message) {
|
|
|
18312
18580
|
return;
|
|
18313
18581
|
}
|
|
18314
18582
|
}
|
|
18315
|
-
const messageId = _optionalChain([message, 'access',
|
|
18583
|
+
const messageId = _optionalChain([message, 'access', _421 => _421.message, 'optionalAccess', _422 => _422.id]);
|
|
18316
18584
|
if (messageId && messageId !== state.currentMessageId) {
|
|
18317
18585
|
await finalizeCurrentMessageGroup(state);
|
|
18318
18586
|
state.currentMessageId = messageId;
|
|
18319
18587
|
state.currentMessageStartTime = getCurrentUnixTimestamp();
|
|
18320
18588
|
}
|
|
18321
|
-
if (message.type === "assistant" && _optionalChain([message, 'access',
|
|
18589
|
+
if (message.type === "assistant" && _optionalChain([message, 'access', _423 => _423.message, 'optionalAccess', _424 => _424.usage])) {
|
|
18322
18590
|
const parentToolUseId = _nullishCoalesce(message.parent_tool_use_id, () => ( null));
|
|
18323
18591
|
await ensureActiveLlmSpanForParentToolUse(
|
|
18324
18592
|
state.span,
|
|
@@ -18337,7 +18605,7 @@ async function handleStreamMessage(state, message) {
|
|
|
18337
18605
|
const finalUsageMetrics = extractUsageFromMessage(message);
|
|
18338
18606
|
if (state.currentMessages.length > 0 && finalUsageMetrics.completion_tokens !== void 0) {
|
|
18339
18607
|
const lastMessage = state.currentMessages[state.currentMessages.length - 1];
|
|
18340
|
-
if (_optionalChain([lastMessage, 'optionalAccess',
|
|
18608
|
+
if (_optionalChain([lastMessage, 'optionalAccess', _425 => _425.message, 'optionalAccess', _426 => _426.usage])) {
|
|
18341
18609
|
const adjustedTokens = finalUsageMetrics.completion_tokens - state.accumulatedOutputTokens;
|
|
18342
18610
|
if (adjustedTokens >= 0) {
|
|
18343
18611
|
lastMessage.message.usage.output_tokens = adjustedTokens;
|
|
@@ -18442,7 +18710,7 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
18442
18710
|
yield message;
|
|
18443
18711
|
}
|
|
18444
18712
|
} finally {
|
|
18445
|
-
_optionalChain([resolvePromptDone, 'optionalCall',
|
|
18713
|
+
_optionalChain([resolvePromptDone, 'optionalCall', _427 => _427()]);
|
|
18446
18714
|
}
|
|
18447
18715
|
})();
|
|
18448
18716
|
}
|
|
@@ -18480,7 +18748,7 @@ var ClaudeAgentSDKPlugin = class extends BasePlugin {
|
|
|
18480
18748
|
const skipLocalToolHooks = options[CLAUDE_AGENT_SDK_SKIP_LOCAL_TOOL_HOOKS_OPTION] === true || hasLocalToolHandlers;
|
|
18481
18749
|
const resolveToolUseParentSpan = async (toolUseID, context) => {
|
|
18482
18750
|
const trackedParentToolUseId = toolUseToParent.get(toolUseID);
|
|
18483
|
-
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)));
|
|
18484
18752
|
const parentKey = llmParentKey(parentToolUseId);
|
|
18485
18753
|
const activeLlmSpan = activeLlmSpansByParentToolUse.get(parentKey);
|
|
18486
18754
|
const latestLlmParent = parentToolUseId ? latestLlmParentBySubAgentToolUse.get(parentToolUseId) : latestRootLlmParentRef.value;
|
|
@@ -18709,7 +18977,7 @@ var CursorSDKPlugin = (_class18 = class extends BasePlugin {constructor(...args3
|
|
|
18709
18977
|
...extractRunResultMetadata(event.result)
|
|
18710
18978
|
},
|
|
18711
18979
|
metrics: buildDurationMetrics2(state.startTime),
|
|
18712
|
-
output: _nullishCoalesce(_optionalChain([event, 'access',
|
|
18980
|
+
output: _nullishCoalesce(_optionalChain([event, 'access', _429 => _429.result, 'optionalAccess', _430 => _430.result]), () => ( event.result))
|
|
18713
18981
|
});
|
|
18714
18982
|
} finally {
|
|
18715
18983
|
state.span.end();
|
|
@@ -18843,7 +19111,7 @@ function patchCursorAgentInPlace(agent) {
|
|
|
18843
19111
|
},
|
|
18844
19112
|
writable: true
|
|
18845
19113
|
});
|
|
18846
|
-
} catch (
|
|
19114
|
+
} catch (e59) {
|
|
18847
19115
|
}
|
|
18848
19116
|
}
|
|
18849
19117
|
function wrapSendOptionsCallbacks(options, state) {
|
|
@@ -18937,7 +19205,7 @@ function patchCursorRun(run, state) {
|
|
|
18937
19205
|
writable: true
|
|
18938
19206
|
});
|
|
18939
19207
|
}
|
|
18940
|
-
} catch (
|
|
19208
|
+
} catch (e60) {
|
|
18941
19209
|
void finalizeCursorRun(state, { output: run });
|
|
18942
19210
|
}
|
|
18943
19211
|
}
|
|
@@ -19030,9 +19298,9 @@ async function handleToolUpdate(state, update) {
|
|
|
19030
19298
|
toolCall
|
|
19031
19299
|
})));
|
|
19032
19300
|
finishToolSpan(toolState, {
|
|
19033
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
19301
|
+
error: _optionalChain([toolCall, 'optionalAccess', _431 => _431.status]) === "error" ? toLoggedError(result) : void 0,
|
|
19034
19302
|
metadata: {
|
|
19035
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
19303
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _432 => _432.status]), () => ( "completed"))
|
|
19036
19304
|
},
|
|
19037
19305
|
output: result
|
|
19038
19306
|
});
|
|
@@ -19053,10 +19321,10 @@ async function handleStreamMessage2(state, message) {
|
|
|
19053
19321
|
}
|
|
19054
19322
|
if (message.type === "assistant") {
|
|
19055
19323
|
const assistantMessage = message;
|
|
19056
|
-
for (const block of _nullishCoalesce(_optionalChain([assistantMessage, 'access',
|
|
19057
|
-
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") {
|
|
19058
19326
|
state.streamText.push(block.text);
|
|
19059
|
-
} else if (_optionalChain([block, 'optionalAccess',
|
|
19327
|
+
} else if (_optionalChain([block, 'optionalAccess', _436 => _436.type]) === "tool_use" && block.id) {
|
|
19060
19328
|
state.activeToolSpans.set(
|
|
19061
19329
|
block.id,
|
|
19062
19330
|
await startToolSpan(state, {
|
|
@@ -19125,29 +19393,29 @@ async function handleConversation(state, turns) {
|
|
|
19125
19393
|
state.conversationOutput = turns;
|
|
19126
19394
|
for (const turn of turns) {
|
|
19127
19395
|
if (turn.type === "agentConversationTurn") {
|
|
19128
|
-
for (const step of _nullishCoalesce(_optionalChain([turn, 'access',
|
|
19396
|
+
for (const step of _nullishCoalesce(_optionalChain([turn, 'access', _437 => _437.turn, 'optionalAccess', _438 => _438.steps]), () => ( []))) {
|
|
19129
19397
|
await handleConversationStep(state, step);
|
|
19130
19398
|
}
|
|
19131
19399
|
} else if (turn.type === "shellConversationTurn") {
|
|
19132
|
-
const command = _optionalChain([turn, 'access',
|
|
19400
|
+
const command = _optionalChain([turn, 'access', _439 => _439.turn, 'optionalAccess', _440 => _440.shellCommand, 'optionalAccess', _441 => _441.command]);
|
|
19133
19401
|
if (command) {
|
|
19134
19402
|
const callId = `shell:${state.activeToolSpans.size}:${command}`;
|
|
19135
19403
|
const toolState = await startToolSpan(state, {
|
|
19136
|
-
args: _optionalChain([turn, 'access',
|
|
19404
|
+
args: _optionalChain([turn, 'access', _442 => _442.turn, 'optionalAccess', _443 => _443.shellCommand]),
|
|
19137
19405
|
callId,
|
|
19138
19406
|
name: "shell",
|
|
19139
19407
|
status: "completed"
|
|
19140
19408
|
});
|
|
19141
19409
|
finishToolSpan(toolState, {
|
|
19142
19410
|
metadata: { "cursor_sdk.tool.status": "completed" },
|
|
19143
|
-
output: _optionalChain([turn, 'access',
|
|
19411
|
+
output: _optionalChain([turn, 'access', _444 => _444.turn, 'optionalAccess', _445 => _445.shellOutput])
|
|
19144
19412
|
});
|
|
19145
19413
|
}
|
|
19146
19414
|
}
|
|
19147
19415
|
}
|
|
19148
19416
|
}
|
|
19149
19417
|
async function handleConversationStep(state, step) {
|
|
19150
|
-
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") {
|
|
19151
19419
|
state.conversationText.push(step.message.text);
|
|
19152
19420
|
return;
|
|
19153
19421
|
}
|
|
@@ -19155,18 +19423,18 @@ async function handleConversationStep(state, step) {
|
|
|
19155
19423
|
return;
|
|
19156
19424
|
}
|
|
19157
19425
|
const toolCall = step.message;
|
|
19158
|
-
const callId = typeof _optionalChain([toolCall, 'optionalAccess',
|
|
19426
|
+
const callId = typeof _optionalChain([toolCall, 'optionalAccess', _448 => _448.callId]) === "string" ? toolCall.callId : `conversation-tool:${state.activeToolSpans.size}`;
|
|
19159
19427
|
const toolState = await startToolSpan(state, {
|
|
19160
19428
|
args: extractToolArgs(toolCall),
|
|
19161
19429
|
callId,
|
|
19162
19430
|
name: extractToolName(toolCall),
|
|
19163
|
-
status: _optionalChain([toolCall, 'optionalAccess',
|
|
19431
|
+
status: _optionalChain([toolCall, 'optionalAccess', _449 => _449.status]),
|
|
19164
19432
|
toolCall
|
|
19165
19433
|
});
|
|
19166
19434
|
finishToolSpan(toolState, {
|
|
19167
|
-
error: _optionalChain([toolCall, 'optionalAccess',
|
|
19435
|
+
error: _optionalChain([toolCall, 'optionalAccess', _450 => _450.status]) === "error" ? toLoggedError(toolCall.result) : void 0,
|
|
19168
19436
|
metadata: {
|
|
19169
|
-
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess',
|
|
19437
|
+
"cursor_sdk.tool.status": _nullishCoalesce(_optionalChain([toolCall, 'optionalAccess', _451 => _451.status]), () => ( "completed"))
|
|
19170
19438
|
},
|
|
19171
19439
|
output: extractToolResult(toolCall)
|
|
19172
19440
|
});
|
|
@@ -19183,7 +19451,7 @@ function handleStepUpdate(state, step) {
|
|
|
19183
19451
|
state.metadata["cursor_sdk.step_types"] = [step.type];
|
|
19184
19452
|
}
|
|
19185
19453
|
}
|
|
19186
|
-
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") {
|
|
19187
19455
|
state.stepText.push(step.message.text);
|
|
19188
19456
|
}
|
|
19189
19457
|
}
|
|
@@ -19194,10 +19462,10 @@ async function startToolSpan(state, args) {
|
|
|
19194
19462
|
"gen_ai.tool.call.id": args.callId,
|
|
19195
19463
|
"gen_ai.tool.name": name
|
|
19196
19464
|
};
|
|
19197
|
-
if (_optionalChain([args, 'access',
|
|
19465
|
+
if (_optionalChain([args, 'access', _454 => _454.truncated, 'optionalAccess', _455 => _455.args]) !== void 0) {
|
|
19198
19466
|
metadata["cursor_sdk.tool.args_truncated"] = args.truncated.args;
|
|
19199
19467
|
}
|
|
19200
|
-
if (_optionalChain([args, 'access',
|
|
19468
|
+
if (_optionalChain([args, 'access', _456 => _456.truncated, 'optionalAccess', _457 => _457.result]) !== void 0) {
|
|
19201
19469
|
metadata["cursor_sdk.tool.result_truncated"] = args.truncated.result;
|
|
19202
19470
|
}
|
|
19203
19471
|
const span = startSpan({
|
|
@@ -19254,7 +19522,7 @@ function finishToolSpan(toolState, result) {
|
|
|
19254
19522
|
}
|
|
19255
19523
|
}
|
|
19256
19524
|
} finally {
|
|
19257
|
-
_optionalChain([toolState, 'access',
|
|
19525
|
+
_optionalChain([toolState, 'access', _458 => _458.subAgentSpan, 'optionalAccess', _459 => _459.end, 'call', _460 => _460()]);
|
|
19258
19526
|
toolState.span.end();
|
|
19259
19527
|
}
|
|
19260
19528
|
}
|
|
@@ -19265,7 +19533,7 @@ async function finalizeCursorRun(state, params = {}) {
|
|
|
19265
19533
|
state.finalized = true;
|
|
19266
19534
|
const error = params.error;
|
|
19267
19535
|
const result = _nullishCoalesce(params.result, () => ( state.lastResult));
|
|
19268
|
-
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)));
|
|
19269
19537
|
try {
|
|
19270
19538
|
const metadata = {
|
|
19271
19539
|
...state.metadata,
|
|
@@ -19309,7 +19577,7 @@ function sanitizeUserMessage(message) {
|
|
|
19309
19577
|
}
|
|
19310
19578
|
return {
|
|
19311
19579
|
...message,
|
|
19312
|
-
images: _optionalChain([message, 'access',
|
|
19580
|
+
images: _optionalChain([message, 'access', _464 => _464.images, 'optionalAccess', _465 => _465.map, 'call', _466 => _466((image) => {
|
|
19313
19581
|
const imageRecord = image;
|
|
19314
19582
|
return {
|
|
19315
19583
|
...typeof imageRecord.url === "string" ? { url: imageRecord.url } : {},
|
|
@@ -19335,9 +19603,9 @@ function extractAgentOptionsMetadata(options) {
|
|
|
19335
19603
|
...options.cloud ? {
|
|
19336
19604
|
"cursor_sdk.runtime": "cloud",
|
|
19337
19605
|
"cursor_sdk.cloud.auto_create_pr": options.cloud.autoCreatePR,
|
|
19338
|
-
"cursor_sdk.cloud.env_type": _optionalChain([options, 'access',
|
|
19339
|
-
"cursor_sdk.cloud.env_name": _optionalChain([options, 'access',
|
|
19340
|
-
"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")])
|
|
19341
19609
|
} : {}
|
|
19342
19610
|
};
|
|
19343
19611
|
}
|
|
@@ -19347,7 +19615,7 @@ function extractSendMetadata(options) {
|
|
|
19347
19615
|
}
|
|
19348
19616
|
return {
|
|
19349
19617
|
...extractModelMetadata(options.model),
|
|
19350
|
-
..._optionalChain([options, 'access',
|
|
19618
|
+
..._optionalChain([options, 'access', _479 => _479.local, 'optionalAccess', _480 => _480.force]) !== void 0 ? { "cursor_sdk.local.force": options.local.force } : {}
|
|
19351
19619
|
};
|
|
19352
19620
|
}
|
|
19353
19621
|
function extractAgentMetadata(agent) {
|
|
@@ -19382,7 +19650,7 @@ function extractRunResultMetadata(result) {
|
|
|
19382
19650
|
};
|
|
19383
19651
|
}
|
|
19384
19652
|
function extractGitMetadata(git) {
|
|
19385
|
-
const branches = _optionalChain([git, 'optionalAccess',
|
|
19653
|
+
const branches = _optionalChain([git, 'optionalAccess', _481 => _481.branches]);
|
|
19386
19654
|
if (!branches || branches.length === 0) {
|
|
19387
19655
|
return {};
|
|
19388
19656
|
}
|
|
@@ -19395,7 +19663,7 @@ function extractGitMetadata(git) {
|
|
|
19395
19663
|
};
|
|
19396
19664
|
}
|
|
19397
19665
|
function extractModelMetadata(model) {
|
|
19398
|
-
if (!_optionalChain([model, 'optionalAccess',
|
|
19666
|
+
if (!_optionalChain([model, 'optionalAccess', _482 => _482.id])) {
|
|
19399
19667
|
return {};
|
|
19400
19668
|
}
|
|
19401
19669
|
return {
|
|
@@ -19457,7 +19725,7 @@ function formatSubAgentSpanName2(toolCall, args) {
|
|
|
19457
19725
|
return description ? `Agent: ${description}` : "Agent: sub-agent";
|
|
19458
19726
|
}
|
|
19459
19727
|
function getString(obj, key) {
|
|
19460
|
-
const value = _optionalChain([obj, 'optionalAccess',
|
|
19728
|
+
const value = _optionalChain([obj, 'optionalAccess', _483 => _483[key]]);
|
|
19461
19729
|
return typeof value === "string" ? value : void 0;
|
|
19462
19730
|
}
|
|
19463
19731
|
function safeLog2(span, event) {
|
|
@@ -19607,7 +19875,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19607
19875
|
}
|
|
19608
19876
|
}
|
|
19609
19877
|
onTraceStart(trace) {
|
|
19610
|
-
if (!_optionalChain([trace, 'optionalAccess',
|
|
19878
|
+
if (!_optionalChain([trace, 'optionalAccess', _484 => _484.traceId])) {
|
|
19611
19879
|
return Promise.resolve();
|
|
19612
19880
|
}
|
|
19613
19881
|
if (this.traceOrder.length >= this.maxTraces) {
|
|
@@ -19643,7 +19911,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19643
19911
|
return Promise.resolve();
|
|
19644
19912
|
}
|
|
19645
19913
|
async onTraceEnd(trace) {
|
|
19646
|
-
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess',
|
|
19914
|
+
const traceData = this.traceSpans.get(_optionalChain([trace, 'optionalAccess', _485 => _485.traceId]));
|
|
19647
19915
|
if (!traceData) {
|
|
19648
19916
|
return;
|
|
19649
19917
|
}
|
|
@@ -19663,7 +19931,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19663
19931
|
}
|
|
19664
19932
|
}
|
|
19665
19933
|
onSpanStart(span) {
|
|
19666
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
19934
|
+
if (!_optionalChain([span, 'optionalAccess', _486 => _486.spanId]) || !span.traceId) {
|
|
19667
19935
|
return Promise.resolve();
|
|
19668
19936
|
}
|
|
19669
19937
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -19682,7 +19950,7 @@ var OpenAIAgentsTraceProcessor = (_class19 = class _OpenAIAgentsTraceProcessor {
|
|
|
19682
19950
|
return Promise.resolve();
|
|
19683
19951
|
}
|
|
19684
19952
|
onSpanEnd(span) {
|
|
19685
|
-
if (!_optionalChain([span, 'optionalAccess',
|
|
19953
|
+
if (!_optionalChain([span, 'optionalAccess', _487 => _487.spanId]) || !span.traceId) {
|
|
19686
19954
|
return Promise.resolve();
|
|
19687
19955
|
}
|
|
19688
19956
|
const traceData = this.traceSpans.get(span.traceId);
|
|
@@ -20057,7 +20325,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20057
20325
|
};
|
|
20058
20326
|
tracingChannel2.subscribe(handlers);
|
|
20059
20327
|
this.unsubscribers.push(() => {
|
|
20060
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
20328
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _488 => _488()]);
|
|
20061
20329
|
tracingChannel2.unsubscribe(handlers);
|
|
20062
20330
|
});
|
|
20063
20331
|
}
|
|
@@ -20154,7 +20422,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20154
20422
|
};
|
|
20155
20423
|
tracingChannel2.subscribe(handlers);
|
|
20156
20424
|
this.unsubscribers.push(() => {
|
|
20157
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
20425
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _489 => _489()]);
|
|
20158
20426
|
tracingChannel2.unsubscribe(handlers);
|
|
20159
20427
|
});
|
|
20160
20428
|
}
|
|
@@ -20180,7 +20448,7 @@ var GoogleGenAIPlugin = class extends BasePlugin {
|
|
|
20180
20448
|
}
|
|
20181
20449
|
};
|
|
20182
20450
|
function isBackgroundInteractionCreate(params) {
|
|
20183
|
-
return _optionalChain([tryToDict, 'call',
|
|
20451
|
+
return _optionalChain([tryToDict, 'call', _490 => _490(params), 'optionalAccess', _491 => _491.background]) === true;
|
|
20184
20452
|
}
|
|
20185
20453
|
function ensureSpanState(states, event, create) {
|
|
20186
20454
|
const existing = states.get(event);
|
|
@@ -20193,10 +20461,10 @@ function ensureSpanState(states, event, create) {
|
|
|
20193
20461
|
}
|
|
20194
20462
|
function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
20195
20463
|
const state = _internalGetGlobalState();
|
|
20196
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
20464
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _492 => _492.contextManager]);
|
|
20197
20465
|
const startChannel = tracingChannel2.start;
|
|
20198
20466
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
20199
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
20467
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _493 => _493.bindStore]) || !currentSpanStore) {
|
|
20200
20468
|
return void 0;
|
|
20201
20469
|
}
|
|
20202
20470
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -20208,7 +20476,7 @@ function bindCurrentSpanStoreToStart2(tracingChannel2, states, create) {
|
|
|
20208
20476
|
return contextManager.wrapSpanForStore(span);
|
|
20209
20477
|
});
|
|
20210
20478
|
return () => {
|
|
20211
|
-
_optionalChain([startChannel, 'access',
|
|
20479
|
+
_optionalChain([startChannel, 'access', _494 => _494.unbindStore, 'optionalCall', _495 => _495(currentSpanStore)]);
|
|
20212
20480
|
};
|
|
20213
20481
|
}
|
|
20214
20482
|
function logErrorAndEndSpan(states, event) {
|
|
@@ -20537,7 +20805,7 @@ function createAttachmentFromInlineData(data, mimeType) {
|
|
|
20537
20805
|
}
|
|
20538
20806
|
function serializeGenerateContentTools(params) {
|
|
20539
20807
|
const config = params.config ? tryToDict(params.config) : null;
|
|
20540
|
-
const tools = _optionalChain([config, 'optionalAccess',
|
|
20808
|
+
const tools = _optionalChain([config, 'optionalAccess', _496 => _496.tools]);
|
|
20541
20809
|
if (!Array.isArray(tools)) {
|
|
20542
20810
|
return null;
|
|
20543
20811
|
}
|
|
@@ -20550,7 +20818,7 @@ function serializeGenerateContentTools(params) {
|
|
|
20550
20818
|
}
|
|
20551
20819
|
}
|
|
20552
20820
|
return serializedTools.length > 0 ? serializedTools : null;
|
|
20553
|
-
} catch (
|
|
20821
|
+
} catch (e61) {
|
|
20554
20822
|
return null;
|
|
20555
20823
|
}
|
|
20556
20824
|
}
|
|
@@ -20596,7 +20864,7 @@ function extractGenerateContentMetrics(response, startTime) {
|
|
|
20596
20864
|
metrics.end = end;
|
|
20597
20865
|
metrics.duration = end - startTime;
|
|
20598
20866
|
}
|
|
20599
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20867
|
+
if (_optionalChain([response, 'optionalAccess', _497 => _497.usageMetadata])) {
|
|
20600
20868
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
20601
20869
|
}
|
|
20602
20870
|
return metrics;
|
|
@@ -20609,7 +20877,7 @@ function extractEmbedContentMetrics(response, startTime) {
|
|
|
20609
20877
|
metrics.end = end;
|
|
20610
20878
|
metrics.duration = end - startTime;
|
|
20611
20879
|
}
|
|
20612
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20880
|
+
if (_optionalChain([response, 'optionalAccess', _498 => _498.usageMetadata])) {
|
|
20613
20881
|
populateUsageMetrics(metrics, response.usageMetadata);
|
|
20614
20882
|
}
|
|
20615
20883
|
const embeddingTokenCount = extractEmbedPromptTokenCount(response);
|
|
@@ -20627,7 +20895,7 @@ function extractInteractionMetrics(response, startTime) {
|
|
|
20627
20895
|
metrics.end = end;
|
|
20628
20896
|
metrics.duration = end - startTime;
|
|
20629
20897
|
}
|
|
20630
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
20898
|
+
if (_optionalChain([response, 'optionalAccess', _499 => _499.usage])) {
|
|
20631
20899
|
populateInteractionUsageMetrics(metrics, response.usage);
|
|
20632
20900
|
}
|
|
20633
20901
|
return metrics;
|
|
@@ -20650,11 +20918,11 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
20650
20918
|
if (!response) {
|
|
20651
20919
|
return void 0;
|
|
20652
20920
|
}
|
|
20653
|
-
const usagePromptTokens = _optionalChain([response, 'access',
|
|
20921
|
+
const usagePromptTokens = _optionalChain([response, 'access', _500 => _500.usageMetadata, 'optionalAccess', _501 => _501.promptTokenCount]);
|
|
20654
20922
|
if (typeof usagePromptTokens === "number" && Number.isFinite(usagePromptTokens)) {
|
|
20655
20923
|
return usagePromptTokens;
|
|
20656
20924
|
}
|
|
20657
|
-
const usageTotalTokens = _optionalChain([response, 'access',
|
|
20925
|
+
const usageTotalTokens = _optionalChain([response, 'access', _502 => _502.usageMetadata, 'optionalAccess', _503 => _503.totalTokenCount]);
|
|
20658
20926
|
if (typeof usageTotalTokens === "number" && Number.isFinite(usageTotalTokens)) {
|
|
20659
20927
|
return usageTotalTokens;
|
|
20660
20928
|
}
|
|
@@ -20665,8 +20933,8 @@ function extractEmbedPromptTokenCount(response) {
|
|
|
20665
20933
|
let total = 0;
|
|
20666
20934
|
let sawAny = false;
|
|
20667
20935
|
for (const embedding of embeddings) {
|
|
20668
|
-
const embeddingStats = tryToDict(_optionalChain([tryToDict, 'call',
|
|
20669
|
-
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]);
|
|
20670
20938
|
if (typeof tokenCount === "number" && Number.isFinite(tokenCount)) {
|
|
20671
20939
|
total += tokenCount;
|
|
20672
20940
|
sawAny = true;
|
|
@@ -20682,7 +20950,7 @@ function summarizeEmbedContentOutput(response) {
|
|
|
20682
20950
|
if (embeddings.length === 0) {
|
|
20683
20951
|
return void 0;
|
|
20684
20952
|
}
|
|
20685
|
-
const firstValues = _optionalChain([embeddings, 'access',
|
|
20953
|
+
const firstValues = _optionalChain([embeddings, 'access', _507 => _507[0], 'optionalAccess', _508 => _508.values]);
|
|
20686
20954
|
if (!Array.isArray(firstValues)) {
|
|
20687
20955
|
return void 0;
|
|
20688
20956
|
}
|
|
@@ -20754,7 +21022,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
20754
21022
|
}
|
|
20755
21023
|
if (chunk.candidates && Array.isArray(chunk.candidates)) {
|
|
20756
21024
|
for (const candidate of chunk.candidates) {
|
|
20757
|
-
if (_optionalChain([candidate, 'access',
|
|
21025
|
+
if (_optionalChain([candidate, 'access', _509 => _509.content, 'optionalAccess', _510 => _510.parts])) {
|
|
20758
21026
|
for (const part of candidate.content.parts) {
|
|
20759
21027
|
if (part.text !== void 0) {
|
|
20760
21028
|
if (part.thought) {
|
|
@@ -20785,7 +21053,7 @@ function aggregateGenerateContentChunks(chunks, startTime, firstTokenTime) {
|
|
|
20785
21053
|
parts.push({ text });
|
|
20786
21054
|
}
|
|
20787
21055
|
parts.push(...otherParts);
|
|
20788
|
-
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess',
|
|
21056
|
+
if (parts.length > 0 && _optionalChain([lastResponse, 'optionalAccess', _511 => _511.candidates])) {
|
|
20789
21057
|
const candidates = [];
|
|
20790
21058
|
for (const candidate of lastResponse.candidates) {
|
|
20791
21059
|
const candidateDict = {
|
|
@@ -20907,16 +21175,16 @@ function aggregateInteractionEvents(chunks, startTime) {
|
|
|
20907
21175
|
}
|
|
20908
21176
|
function extractInteractionUsageFromEvent(event) {
|
|
20909
21177
|
const metadata = tryToDict(event.metadata);
|
|
20910
|
-
const metadataUsage = tryToDict(_optionalChain([metadata, 'optionalAccess',
|
|
21178
|
+
const metadataUsage = tryToDict(_optionalChain([metadata, 'optionalAccess', _512 => _512.usage]));
|
|
20911
21179
|
if (metadataUsage) {
|
|
20912
21180
|
return metadataUsage;
|
|
20913
21181
|
}
|
|
20914
|
-
const metadataTotalUsage = tryToDict(_optionalChain([metadata, 'optionalAccess',
|
|
21182
|
+
const metadataTotalUsage = tryToDict(_optionalChain([metadata, 'optionalAccess', _513 => _513.total_usage]));
|
|
20915
21183
|
if (metadataTotalUsage) {
|
|
20916
21184
|
return metadataTotalUsage;
|
|
20917
21185
|
}
|
|
20918
21186
|
const interaction = tryToDict(event.interaction);
|
|
20919
|
-
const interactionUsage = tryToDict(_optionalChain([interaction, 'optionalAccess',
|
|
21187
|
+
const interactionUsage = tryToDict(_optionalChain([interaction, 'optionalAccess', _514 => _514.usage]));
|
|
20920
21188
|
return interactionUsage ? interactionUsage : void 0;
|
|
20921
21189
|
}
|
|
20922
21190
|
function compactInteractionStep(step) {
|
|
@@ -20982,7 +21250,7 @@ function extractResponseMetadata(response) {
|
|
|
20982
21250
|
if (Array.isArray(responseDict.candidates)) {
|
|
20983
21251
|
for (const candidate of responseDict.candidates) {
|
|
20984
21252
|
const candidateDict = tryToDict(candidate);
|
|
20985
|
-
if (_optionalChain([candidateDict, 'optionalAccess',
|
|
21253
|
+
if (_optionalChain([candidateDict, 'optionalAccess', _515 => _515.groundingMetadata]) !== void 0) {
|
|
20986
21254
|
candidateGroundingMetadata.push(candidateDict.groundingMetadata);
|
|
20987
21255
|
}
|
|
20988
21256
|
}
|
|
@@ -21063,9 +21331,9 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
21063
21331
|
name: "huggingface.chat_completion",
|
|
21064
21332
|
type: "llm" /* LLM */,
|
|
21065
21333
|
extractInput: extractChatInputWithMetadata,
|
|
21066
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
21334
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _516 => _516.choices]),
|
|
21067
21335
|
extractMetadata: (result) => extractResponseMetadata2(result),
|
|
21068
|
-
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
21336
|
+
extractMetrics: (result) => parseMetricsFromUsage(_optionalChain([result, 'optionalAccess', _517 => _517.usage]))
|
|
21069
21337
|
}),
|
|
21070
21338
|
traceSyncStreamChannel(huggingFaceChannels.chatCompletionStream, {
|
|
21071
21339
|
name: "huggingface.chat_completion_stream",
|
|
@@ -21083,7 +21351,7 @@ var HuggingFacePlugin = class extends BasePlugin {
|
|
|
21083
21351
|
extractInput: extractTextGenerationInputWithMetadata,
|
|
21084
21352
|
extractOutput: (result) => isObject(result) ? { generated_text: result.generated_text } : result,
|
|
21085
21353
|
extractMetadata: extractTextGenerationMetadata,
|
|
21086
|
-
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
21354
|
+
extractMetrics: (result) => extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _518 => _518.details]), () => ( null)))
|
|
21087
21355
|
}),
|
|
21088
21356
|
traceSyncStreamChannel(huggingFaceChannels.textGenerationStream, {
|
|
21089
21357
|
name: "huggingface.text_generation_stream",
|
|
@@ -21202,7 +21470,7 @@ function extractTextGenerationMetrics(details) {
|
|
|
21202
21470
|
return metrics;
|
|
21203
21471
|
}
|
|
21204
21472
|
function extractTextGenerationMetadata(result) {
|
|
21205
|
-
if (!isObject(_optionalChain([result, 'optionalAccess',
|
|
21473
|
+
if (!isObject(_optionalChain([result, 'optionalAccess', _519 => _519.details]))) {
|
|
21206
21474
|
return void 0;
|
|
21207
21475
|
}
|
|
21208
21476
|
return typeof result.details.finish_reason === "string" ? {
|
|
@@ -21248,7 +21516,7 @@ function patchChatCompletionStream(args) {
|
|
|
21248
21516
|
const lastChunk = chunks.at(-1);
|
|
21249
21517
|
const responseMetadata = extractResponseMetadata2(lastChunk);
|
|
21250
21518
|
const metrics = {
|
|
21251
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
21519
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _520 => _520.usage])),
|
|
21252
21520
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
21253
21521
|
};
|
|
21254
21522
|
span.log({
|
|
@@ -21286,8 +21554,8 @@ function patchTextGenerationStream(args) {
|
|
|
21286
21554
|
output: aggregateTextGenerationStreamChunks(chunks),
|
|
21287
21555
|
...streamMetadata ? { metadata: streamMetadata } : {},
|
|
21288
21556
|
metrics: {
|
|
21289
|
-
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess',
|
|
21290
|
-
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess',
|
|
21557
|
+
...extractTextGenerationMetrics(_nullishCoalesce(_optionalChain([lastChunk, 'optionalAccess', _521 => _521.details]), () => ( null))),
|
|
21558
|
+
...parseMetricsFromUsage(_optionalChain([lastChunk, 'optionalAccess', _522 => _522.usage])),
|
|
21291
21559
|
...firstChunkTime !== void 0 ? { time_to_first_token: firstChunkTime - startTime } : {}
|
|
21292
21560
|
}
|
|
21293
21561
|
});
|
|
@@ -21316,14 +21584,14 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
21316
21584
|
}));
|
|
21317
21585
|
const delta = isObject(choice.delta) ? choice.delta : void 0;
|
|
21318
21586
|
const message = isObject(choice.message) ? choice.message : void 0;
|
|
21319
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
21587
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _523 => _523.content]) === "string") {
|
|
21320
21588
|
existing.content += delta.content;
|
|
21321
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
21589
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _524 => _524.content]) === "string") {
|
|
21322
21590
|
existing.content = message.content;
|
|
21323
21591
|
}
|
|
21324
|
-
if (typeof _optionalChain([delta, 'optionalAccess',
|
|
21592
|
+
if (typeof _optionalChain([delta, 'optionalAccess', _525 => _525.role]) === "string") {
|
|
21325
21593
|
existing.role = delta.role;
|
|
21326
|
-
} else if (typeof _optionalChain([message, 'optionalAccess',
|
|
21594
|
+
} else if (typeof _optionalChain([message, 'optionalAccess', _526 => _526.role]) === "string") {
|
|
21327
21595
|
existing.role = message.role;
|
|
21328
21596
|
}
|
|
21329
21597
|
if (choice.finish_reason !== void 0) {
|
|
@@ -21351,7 +21619,7 @@ function aggregateChatCompletionChunks2(chunks) {
|
|
|
21351
21619
|
};
|
|
21352
21620
|
}
|
|
21353
21621
|
function getChatToolCallDeltas(value) {
|
|
21354
|
-
if (!Array.isArray(_optionalChain([value, 'optionalAccess',
|
|
21622
|
+
if (!Array.isArray(_optionalChain([value, 'optionalAccess', _527 => _527.tool_calls]))) {
|
|
21355
21623
|
return void 0;
|
|
21356
21624
|
}
|
|
21357
21625
|
const toolCalls = value.tool_calls.filter((toolCall) => isObject(toolCall));
|
|
@@ -21416,7 +21684,7 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
21416
21684
|
for (const chunk of chunks) {
|
|
21417
21685
|
if (typeof chunk.generated_text === "string") {
|
|
21418
21686
|
generatedText = chunk.generated_text;
|
|
21419
|
-
} else if (typeof _optionalChain([chunk, 'access',
|
|
21687
|
+
} else if (typeof _optionalChain([chunk, 'access', _528 => _528.token, 'optionalAccess', _529 => _529.text]) === "string" && !chunk.token.special) {
|
|
21420
21688
|
generatedText += chunk.token.text;
|
|
21421
21689
|
} else if (Array.isArray(chunk.choices)) {
|
|
21422
21690
|
for (const choice of chunk.choices) {
|
|
@@ -21440,17 +21708,17 @@ function aggregateTextGenerationStreamChunks(chunks) {
|
|
|
21440
21708
|
function extractTextGenerationStreamMetadata(chunks) {
|
|
21441
21709
|
for (let index = chunks.length - 1; index >= 0; index--) {
|
|
21442
21710
|
const chunk = chunks[index];
|
|
21443
|
-
if (isObject(_optionalChain([chunk, 'optionalAccess',
|
|
21711
|
+
if (isObject(_optionalChain([chunk, 'optionalAccess', _530 => _530.details])) && typeof chunk.details.finish_reason === "string") {
|
|
21444
21712
|
return {
|
|
21445
21713
|
finish_reason: chunk.details.finish_reason
|
|
21446
21714
|
};
|
|
21447
21715
|
}
|
|
21448
|
-
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess',
|
|
21716
|
+
if (!Array.isArray(_optionalChain([chunk, 'optionalAccess', _531 => _531.choices]))) {
|
|
21449
21717
|
continue;
|
|
21450
21718
|
}
|
|
21451
21719
|
for (let choiceIndex = chunk.choices.length - 1; choiceIndex >= 0; choiceIndex--) {
|
|
21452
21720
|
const choice = chunk.choices[choiceIndex];
|
|
21453
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
21721
|
+
if (_optionalChain([choice, 'optionalAccess', _532 => _532.finish_reason]) !== void 0) {
|
|
21454
21722
|
return { finish_reason: choice.finish_reason };
|
|
21455
21723
|
}
|
|
21456
21724
|
}
|
|
@@ -21526,14 +21794,14 @@ var OpenRouterAgentPlugin = class extends BasePlugin {
|
|
|
21526
21794
|
extractMetadata: (result, event) => {
|
|
21527
21795
|
if (!isObject(result)) {
|
|
21528
21796
|
return {
|
|
21529
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
21530
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
21797
|
+
step: _optionalChain([event, 'optionalAccess', _533 => _533.step]),
|
|
21798
|
+
step_type: _optionalChain([event, 'optionalAccess', _534 => _534.stepType])
|
|
21531
21799
|
};
|
|
21532
21800
|
}
|
|
21533
21801
|
return {
|
|
21534
21802
|
...extractOpenRouterResponseMetadata(result) || {},
|
|
21535
|
-
..._optionalChain([event, 'optionalAccess',
|
|
21536
|
-
..._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 } : {}
|
|
21537
21805
|
};
|
|
21538
21806
|
},
|
|
21539
21807
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage(result.usage) : {}
|
|
@@ -21688,7 +21956,7 @@ function isZodSchema3(value) {
|
|
|
21688
21956
|
function serializeZodSchema3(schema) {
|
|
21689
21957
|
try {
|
|
21690
21958
|
return zodToJsonSchema(schema);
|
|
21691
|
-
} catch (
|
|
21959
|
+
} catch (e62) {
|
|
21692
21960
|
return {
|
|
21693
21961
|
type: "object",
|
|
21694
21962
|
description: "Zod schema (conversion failed)"
|
|
@@ -21894,7 +22162,7 @@ function publishToolResult(tracingChannel2, event, result) {
|
|
|
21894
22162
|
}
|
|
21895
22163
|
function getToolCallId(context) {
|
|
21896
22164
|
const toolContext = context;
|
|
21897
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
22165
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _537 => _537.toolCall, 'optionalAccess', _538 => _538.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
21898
22166
|
}
|
|
21899
22167
|
var OPENROUTER_WRAPPED_CALL_MODEL_RESULT = /* @__PURE__ */ Symbol(
|
|
21900
22168
|
"braintrust.openrouter.wrappedCallModelResult"
|
|
@@ -21985,7 +22253,7 @@ function patchOpenRouterCallModelResult(args) {
|
|
|
21985
22253
|
}
|
|
21986
22254
|
try {
|
|
21987
22255
|
await endSpanWithResult(await originalGetResponse(), fallbackOutput);
|
|
21988
|
-
} catch (
|
|
22256
|
+
} catch (e63) {
|
|
21989
22257
|
await endSpanWithResult(void 0, fallbackOutput);
|
|
21990
22258
|
}
|
|
21991
22259
|
};
|
|
@@ -22290,9 +22558,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22290
22558
|
type: "llm" /* LLM */,
|
|
22291
22559
|
extractInput: (args) => {
|
|
22292
22560
|
const request = getOpenRouterRequestArg(args);
|
|
22293
|
-
const chatGenerationParams = isObject(_optionalChain([request, 'optionalAccess',
|
|
22294
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22295
|
-
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]);
|
|
22296
22564
|
const { messages, ...metadata } = chatGenerationParams;
|
|
22297
22565
|
return {
|
|
22298
22566
|
input: messages,
|
|
@@ -22303,7 +22571,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22303
22571
|
return isObject(result) ? result.choices : void 0;
|
|
22304
22572
|
},
|
|
22305
22573
|
extractMetrics: (result, startTime) => {
|
|
22306
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
22574
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _542 => _542.usage]));
|
|
22307
22575
|
if (startTime) {
|
|
22308
22576
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
22309
22577
|
}
|
|
@@ -22318,9 +22586,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22318
22586
|
type: "llm" /* LLM */,
|
|
22319
22587
|
extractInput: (args) => {
|
|
22320
22588
|
const request = getOpenRouterRequestArg(args);
|
|
22321
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
22322
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22323
|
-
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]);
|
|
22324
22592
|
const { input, ...metadata } = requestBody;
|
|
22325
22593
|
return {
|
|
22326
22594
|
input,
|
|
@@ -22335,7 +22603,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22335
22603
|
if (!isObject(result)) {
|
|
22336
22604
|
return void 0;
|
|
22337
22605
|
}
|
|
22338
|
-
const embedding = _optionalChain([result, 'access',
|
|
22606
|
+
const embedding = _optionalChain([result, 'access', _546 => _546.data, 'optionalAccess', _547 => _547[0], 'optionalAccess', _548 => _548.embedding]);
|
|
22339
22607
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
22340
22608
|
},
|
|
22341
22609
|
extractMetadata: (result) => {
|
|
@@ -22355,9 +22623,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22355
22623
|
type: "llm" /* LLM */,
|
|
22356
22624
|
extractInput: (args) => {
|
|
22357
22625
|
const request = getOpenRouterRequestArg(args);
|
|
22358
|
-
const requestBody = isObject(_optionalChain([request, 'optionalAccess',
|
|
22359
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22360
|
-
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])));
|
|
22361
22629
|
const { documents, query, ...metadata } = requestBody;
|
|
22362
22630
|
return {
|
|
22363
22631
|
input: {
|
|
@@ -22383,9 +22651,9 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22383
22651
|
type: "llm" /* LLM */,
|
|
22384
22652
|
extractInput: (args) => {
|
|
22385
22653
|
const request = getOpenRouterRequestArg(args);
|
|
22386
|
-
const openResponsesRequest = isObject(_optionalChain([request, 'optionalAccess',
|
|
22387
|
-
const httpReferer = _optionalChain([request, 'optionalAccess',
|
|
22388
|
-
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]);
|
|
22389
22657
|
const { input, ...metadata } = openResponsesRequest;
|
|
22390
22658
|
return {
|
|
22391
22659
|
input,
|
|
@@ -22395,7 +22663,7 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22395
22663
|
extractOutput: (result) => extractOpenRouterResponseOutput2(result),
|
|
22396
22664
|
extractMetadata: (result) => extractOpenRouterResponseMetadata2(result),
|
|
22397
22665
|
extractMetrics: (result, startTime) => {
|
|
22398
|
-
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess',
|
|
22666
|
+
const metrics = parseOpenRouterMetricsFromUsage2(_optionalChain([result, 'optionalAccess', _556 => _556.usage]));
|
|
22399
22667
|
if (startTime) {
|
|
22400
22668
|
metrics.time_to_first_token = getCurrentUnixTimestamp() - startTime;
|
|
22401
22669
|
}
|
|
@@ -22447,14 +22715,14 @@ var OpenRouterPlugin = class extends BasePlugin {
|
|
|
22447
22715
|
extractMetadata: (result, event) => {
|
|
22448
22716
|
if (!isObject(result)) {
|
|
22449
22717
|
return {
|
|
22450
|
-
step: _optionalChain([event, 'optionalAccess',
|
|
22451
|
-
step_type: _optionalChain([event, 'optionalAccess',
|
|
22718
|
+
step: _optionalChain([event, 'optionalAccess', _557 => _557.step]),
|
|
22719
|
+
step_type: _optionalChain([event, 'optionalAccess', _558 => _558.stepType])
|
|
22452
22720
|
};
|
|
22453
22721
|
}
|
|
22454
22722
|
return {
|
|
22455
22723
|
...extractOpenRouterResponseMetadata2(result) || {},
|
|
22456
|
-
..._optionalChain([event, 'optionalAccess',
|
|
22457
|
-
..._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 } : {}
|
|
22458
22726
|
};
|
|
22459
22727
|
},
|
|
22460
22728
|
extractMetrics: (result) => isObject(result) ? parseOpenRouterMetricsFromUsage2(result.usage) : {}
|
|
@@ -22613,7 +22881,7 @@ function isZodSchema4(value) {
|
|
|
22613
22881
|
function serializeZodSchema4(schema) {
|
|
22614
22882
|
try {
|
|
22615
22883
|
return zodToJsonSchema(schema);
|
|
22616
|
-
} catch (
|
|
22884
|
+
} catch (e64) {
|
|
22617
22885
|
return {
|
|
22618
22886
|
type: "object",
|
|
22619
22887
|
description: "Zod schema (conversion failed)"
|
|
@@ -22834,7 +23102,7 @@ function publishToolResult2(tracingChannel2, event, result) {
|
|
|
22834
23102
|
}
|
|
22835
23103
|
function getToolCallId2(context) {
|
|
22836
23104
|
const toolContext = context;
|
|
22837
|
-
return typeof _optionalChain([toolContext, 'optionalAccess',
|
|
23105
|
+
return typeof _optionalChain([toolContext, 'optionalAccess', _561 => _561.toolCall, 'optionalAccess', _562 => _562.id]) === "string" ? toolContext.toolCall.id : void 0;
|
|
22838
23106
|
}
|
|
22839
23107
|
function aggregateOpenRouterChatChunks(chunks) {
|
|
22840
23108
|
let role;
|
|
@@ -22850,12 +23118,12 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22850
23118
|
for (const chunk of chunks) {
|
|
22851
23119
|
metrics = {
|
|
22852
23120
|
...metrics,
|
|
22853
|
-
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess',
|
|
23121
|
+
...parseOpenRouterMetricsFromUsage2(_optionalChain([chunk, 'optionalAccess', _563 => _563.usage]))
|
|
22854
23122
|
};
|
|
22855
|
-
const choice = _optionalChain([chunk, 'optionalAccess',
|
|
22856
|
-
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]);
|
|
22857
23125
|
if (!delta) {
|
|
22858
|
-
if (_optionalChain([choice, 'optionalAccess',
|
|
23126
|
+
if (_optionalChain([choice, 'optionalAccess', _567 => _567.finish_reason]) !== void 0) {
|
|
22859
23127
|
finishReason = choice.finish_reason;
|
|
22860
23128
|
}
|
|
22861
23129
|
continue;
|
|
@@ -22881,7 +23149,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22881
23149
|
...delta.reasoning_details
|
|
22882
23150
|
];
|
|
22883
23151
|
}
|
|
22884
|
-
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));
|
|
22885
23153
|
const deltaFinishReason = _nullishCoalesce(_nullishCoalesce(delta.finishReason, () => ( delta.finish_reason)), () => ( void 0));
|
|
22886
23154
|
if (choiceFinishReason !== void 0) {
|
|
22887
23155
|
finishReason = choiceFinishReason;
|
|
@@ -22893,11 +23161,11 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22893
23161
|
continue;
|
|
22894
23162
|
}
|
|
22895
23163
|
for (const toolDelta of toolCallDeltas) {
|
|
22896
|
-
if (!_optionalChain([toolDelta, 'optionalAccess',
|
|
23164
|
+
if (!_optionalChain([toolDelta, 'optionalAccess', _570 => _570.function])) {
|
|
22897
23165
|
continue;
|
|
22898
23166
|
}
|
|
22899
23167
|
const toolIndex = _nullishCoalesce(toolDelta.index, () => ( 0));
|
|
22900
|
-
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess',
|
|
23168
|
+
const existingToolCall = _optionalChain([toolCalls, 'optionalAccess', _571 => _571[toolIndex]]);
|
|
22901
23169
|
if (!existingToolCall || toolDelta.id && existingToolCall.id !== void 0 && existingToolCall.id !== toolDelta.id) {
|
|
22902
23170
|
const nextToolCalls = [...toolCalls || []];
|
|
22903
23171
|
nextToolCalls[toolIndex] = {
|
|
@@ -22947,7 +23215,7 @@ function aggregateOpenRouterChatChunks(chunks) {
|
|
|
22947
23215
|
function aggregateOpenRouterResponseStreamEvents(chunks) {
|
|
22948
23216
|
let finalResponse;
|
|
22949
23217
|
for (const chunk of chunks) {
|
|
22950
|
-
const response = _optionalChain([chunk, 'optionalAccess',
|
|
23218
|
+
const response = _optionalChain([chunk, 'optionalAccess', _572 => _572.response]);
|
|
22951
23219
|
if (!response) {
|
|
22952
23220
|
continue;
|
|
22953
23221
|
}
|
|
@@ -23056,7 +23324,7 @@ function patchOpenRouterCallModelResult2(args) {
|
|
|
23056
23324
|
}
|
|
23057
23325
|
try {
|
|
23058
23326
|
await endSpanWithResult(await originalGetResponse(), fallbackOutput);
|
|
23059
|
-
} catch (
|
|
23327
|
+
} catch (e65) {
|
|
23060
23328
|
await endSpanWithResult(void 0, fallbackOutput);
|
|
23061
23329
|
}
|
|
23062
23330
|
};
|
|
@@ -23375,10 +23643,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23375
23643
|
type: "llm" /* LLM */,
|
|
23376
23644
|
extractInput: extractMessagesInputWithMetadata,
|
|
23377
23645
|
extractOutput: (result) => {
|
|
23378
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23646
|
+
return _optionalChain([result, 'optionalAccess', _573 => _573.choices]);
|
|
23379
23647
|
},
|
|
23380
23648
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23381
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23649
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _574 => _574.usage]), startTime)
|
|
23382
23650
|
})
|
|
23383
23651
|
);
|
|
23384
23652
|
this.unsubscribers.push(
|
|
@@ -23398,11 +23666,11 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23398
23666
|
type: "llm" /* LLM */,
|
|
23399
23667
|
extractInput: extractEmbeddingInputWithMetadata,
|
|
23400
23668
|
extractOutput: (result) => {
|
|
23401
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
23669
|
+
const embedding = _optionalChain([result, 'optionalAccess', _575 => _575.data, 'optionalAccess', _576 => _576[0], 'optionalAccess', _577 => _577.embedding]);
|
|
23402
23670
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
23403
23671
|
},
|
|
23404
23672
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23405
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23673
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _578 => _578.usage]))
|
|
23406
23674
|
})
|
|
23407
23675
|
);
|
|
23408
23676
|
this.unsubscribers.push(
|
|
@@ -23412,7 +23680,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23412
23680
|
extractInput: extractClassifierInputWithMetadata,
|
|
23413
23681
|
extractOutput: extractClassifierOutput,
|
|
23414
23682
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23415
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23683
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _579 => _579.usage]))
|
|
23416
23684
|
})
|
|
23417
23685
|
);
|
|
23418
23686
|
this.unsubscribers.push(
|
|
@@ -23422,7 +23690,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23422
23690
|
extractInput: extractClassifierInputWithMetadata,
|
|
23423
23691
|
extractOutput: extractClassifierOutput,
|
|
23424
23692
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23425
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23693
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _580 => _580.usage]))
|
|
23426
23694
|
})
|
|
23427
23695
|
);
|
|
23428
23696
|
this.unsubscribers.push(
|
|
@@ -23432,7 +23700,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23432
23700
|
extractInput: extractClassifierInputWithMetadata,
|
|
23433
23701
|
extractOutput: extractClassifierOutput,
|
|
23434
23702
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23435
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23703
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _581 => _581.usage]))
|
|
23436
23704
|
})
|
|
23437
23705
|
);
|
|
23438
23706
|
this.unsubscribers.push(
|
|
@@ -23442,7 +23710,7 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23442
23710
|
extractInput: extractClassifierInputWithMetadata,
|
|
23443
23711
|
extractOutput: extractClassifierOutput,
|
|
23444
23712
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23445
|
-
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
23713
|
+
extractMetrics: (result) => parseMistralMetricsFromUsage(_optionalChain([result, 'optionalAccess', _582 => _582.usage]))
|
|
23446
23714
|
})
|
|
23447
23715
|
);
|
|
23448
23716
|
this.unsubscribers.push(
|
|
@@ -23451,10 +23719,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23451
23719
|
type: "llm" /* LLM */,
|
|
23452
23720
|
extractInput: extractPromptInputWithMetadata,
|
|
23453
23721
|
extractOutput: (result) => {
|
|
23454
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23722
|
+
return _optionalChain([result, 'optionalAccess', _583 => _583.choices]);
|
|
23455
23723
|
},
|
|
23456
23724
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23457
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23725
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _584 => _584.usage]), startTime)
|
|
23458
23726
|
})
|
|
23459
23727
|
);
|
|
23460
23728
|
this.unsubscribers.push(
|
|
@@ -23474,10 +23742,10 @@ var MistralPlugin = class extends BasePlugin {
|
|
|
23474
23742
|
type: "llm" /* LLM */,
|
|
23475
23743
|
extractInput: extractMessagesInputWithMetadata,
|
|
23476
23744
|
extractOutput: (result) => {
|
|
23477
|
-
return _optionalChain([result, 'optionalAccess',
|
|
23745
|
+
return _optionalChain([result, 'optionalAccess', _585 => _585.choices]);
|
|
23478
23746
|
},
|
|
23479
23747
|
extractMetadata: (result) => extractMistralResponseMetadata(result),
|
|
23480
|
-
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess',
|
|
23748
|
+
extractMetrics: (result, startTime) => extractMistralMetrics(_optionalChain([result, 'optionalAccess', _586 => _586.usage]), startTime)
|
|
23481
23749
|
})
|
|
23482
23750
|
);
|
|
23483
23751
|
this.unsubscribers.push(
|
|
@@ -23732,11 +24000,11 @@ function mergeMistralContentParts(left, right) {
|
|
|
23732
24000
|
const merged = [...(left || []).map((part) => structuredClone(part))];
|
|
23733
24001
|
for (const part of right) {
|
|
23734
24002
|
const lastPart = merged[merged.length - 1];
|
|
23735
|
-
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") {
|
|
23736
24004
|
lastPart.text += part.text;
|
|
23737
24005
|
continue;
|
|
23738
24006
|
}
|
|
23739
|
-
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)) {
|
|
23740
24008
|
lastPart.thinking = mergeMistralTextSegments(
|
|
23741
24009
|
lastPart.thinking,
|
|
23742
24010
|
part.thinking
|
|
@@ -23791,13 +24059,13 @@ function createMergedToolCallDelta(delta) {
|
|
|
23791
24059
|
...delta,
|
|
23792
24060
|
function: {
|
|
23793
24061
|
...delta.function,
|
|
23794
|
-
arguments: typeof _optionalChain([delta, 'access',
|
|
24062
|
+
arguments: typeof _optionalChain([delta, 'access', _589 => _589.function, 'optionalAccess', _590 => _590.arguments]) === "string" ? delta.function.arguments : ""
|
|
23795
24063
|
}
|
|
23796
24064
|
};
|
|
23797
24065
|
}
|
|
23798
24066
|
function mergeToolCallDeltaPair(current, delta) {
|
|
23799
|
-
const currentArguments = typeof _optionalChain([current, 'access',
|
|
23800
|
-
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 : "";
|
|
23801
24069
|
return {
|
|
23802
24070
|
...current,
|
|
23803
24071
|
...delta,
|
|
@@ -23900,7 +24168,7 @@ function aggregateMistralStreamChunks(chunks) {
|
|
|
23900
24168
|
let metrics = {};
|
|
23901
24169
|
let metadata;
|
|
23902
24170
|
for (const event of chunks) {
|
|
23903
|
-
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess',
|
|
24171
|
+
const chunk = isMistralChatCompletionChunk(_optionalChain([event, 'optionalAccess', _595 => _595.data])) ? event.data : void 0;
|
|
23904
24172
|
if (!chunk) {
|
|
23905
24173
|
continue;
|
|
23906
24174
|
}
|
|
@@ -24029,7 +24297,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24029
24297
|
input: extractRunnerInput(params),
|
|
24030
24298
|
metadata
|
|
24031
24299
|
});
|
|
24032
|
-
} catch (
|
|
24300
|
+
} catch (e66) {
|
|
24033
24301
|
}
|
|
24034
24302
|
if (contextKey) {
|
|
24035
24303
|
this.activeRunnerSpans.set(contextKey, span);
|
|
@@ -24091,7 +24359,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24091
24359
|
};
|
|
24092
24360
|
tracingChannel2.subscribe(handlers);
|
|
24093
24361
|
this.unsubscribers.push(() => {
|
|
24094
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
24362
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _596 => _596()]);
|
|
24095
24363
|
tracingChannel2.unsubscribe(handlers);
|
|
24096
24364
|
});
|
|
24097
24365
|
}
|
|
@@ -24132,7 +24400,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24132
24400
|
metadata.model = modelName2;
|
|
24133
24401
|
}
|
|
24134
24402
|
span.log({ metadata });
|
|
24135
|
-
} catch (
|
|
24403
|
+
} catch (e67) {
|
|
24136
24404
|
}
|
|
24137
24405
|
if (contextKey && agentName) {
|
|
24138
24406
|
this.activeAgentSpans.set(agentContextKey(contextKey, agentName), span);
|
|
@@ -24194,7 +24462,7 @@ var GoogleADKPlugin = (_class21 = class extends BasePlugin {constructor(...args5
|
|
|
24194
24462
|
};
|
|
24195
24463
|
tracingChannel2.subscribe(handlers);
|
|
24196
24464
|
this.unsubscribers.push(() => {
|
|
24197
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
24465
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _597 => _597()]);
|
|
24198
24466
|
tracingChannel2.unsubscribe(handlers);
|
|
24199
24467
|
});
|
|
24200
24468
|
}
|
|
@@ -24303,7 +24571,7 @@ function bindAsyncIterableToCurrentSpan(stream, span) {
|
|
|
24303
24571
|
value: true
|
|
24304
24572
|
});
|
|
24305
24573
|
return stream;
|
|
24306
|
-
} catch (
|
|
24574
|
+
} catch (e68) {
|
|
24307
24575
|
return stream;
|
|
24308
24576
|
}
|
|
24309
24577
|
}
|
|
@@ -24334,17 +24602,17 @@ function bindAsyncIterableToCurrentSpan(stream, span) {
|
|
|
24334
24602
|
}
|
|
24335
24603
|
);
|
|
24336
24604
|
stream[Symbol.asyncIterator] = patchedIteratorFn;
|
|
24337
|
-
} catch (
|
|
24605
|
+
} catch (e69) {
|
|
24338
24606
|
return stream;
|
|
24339
24607
|
}
|
|
24340
24608
|
return stream;
|
|
24341
24609
|
}
|
|
24342
24610
|
function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
24343
24611
|
const state = _internalGetGlobalState();
|
|
24344
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
24612
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _598 => _598.contextManager]);
|
|
24345
24613
|
const startChannel = tracingChannel2.start;
|
|
24346
24614
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
24347
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
24615
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _599 => _599.bindStore]) || !currentSpanStore) {
|
|
24348
24616
|
return void 0;
|
|
24349
24617
|
}
|
|
24350
24618
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -24356,7 +24624,7 @@ function bindCurrentSpanStoreToStart3(tracingChannel2, states, create) {
|
|
|
24356
24624
|
return contextManager.wrapSpanForStore(span);
|
|
24357
24625
|
});
|
|
24358
24626
|
return () => {
|
|
24359
|
-
_optionalChain([startChannel, 'access',
|
|
24627
|
+
_optionalChain([startChannel, 'access', _600 => _600.unbindStore, 'optionalCall', _601 => _601(currentSpanStore)]);
|
|
24360
24628
|
};
|
|
24361
24629
|
}
|
|
24362
24630
|
function extractRunnerContextKey(paramsOrContext) {
|
|
@@ -24369,9 +24637,9 @@ function extractRunnerContextKey(paramsOrContext) {
|
|
|
24369
24637
|
return extractInvocationContextKey(invocationContext);
|
|
24370
24638
|
}
|
|
24371
24639
|
function extractInvocationContextKey(parentContext) {
|
|
24372
|
-
const session = _optionalChain([parentContext, 'optionalAccess',
|
|
24373
|
-
const userId = _optionalChain([session, 'optionalAccess',
|
|
24374
|
-
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]);
|
|
24375
24643
|
if (typeof userId !== "string" || typeof sessionId !== "string") {
|
|
24376
24644
|
return void 0;
|
|
24377
24645
|
}
|
|
@@ -24428,27 +24696,27 @@ function extractRunnerMetadata(paramsOrContext) {
|
|
|
24428
24696
|
metadata["google_adk.session_id"] = directSessionId;
|
|
24429
24697
|
}
|
|
24430
24698
|
const session = "session" in paramsOrContext ? paramsOrContext.session : void 0;
|
|
24431
|
-
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") {
|
|
24432
24700
|
metadata["google_adk.user_id"] = session.userId;
|
|
24433
24701
|
}
|
|
24434
|
-
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") {
|
|
24435
24703
|
metadata["google_adk.session_id"] = session.id;
|
|
24436
24704
|
}
|
|
24437
24705
|
return metadata;
|
|
24438
24706
|
}
|
|
24439
24707
|
function extractAgentName(agent, parentContext) {
|
|
24440
|
-
if (typeof _optionalChain([agent, 'optionalAccess',
|
|
24708
|
+
if (typeof _optionalChain([agent, 'optionalAccess', _607 => _607.name]) === "string" && agent.name.length > 0) {
|
|
24441
24709
|
return agent.name;
|
|
24442
24710
|
}
|
|
24443
24711
|
if (!parentContext) {
|
|
24444
24712
|
return void 0;
|
|
24445
24713
|
}
|
|
24446
24714
|
const contextAgent = parentContext.agent;
|
|
24447
|
-
return typeof _optionalChain([contextAgent, 'optionalAccess',
|
|
24715
|
+
return typeof _optionalChain([contextAgent, 'optionalAccess', _608 => _608.name]) === "string" && contextAgent.name.length > 0 ? contextAgent.name : void 0;
|
|
24448
24716
|
}
|
|
24449
24717
|
function extractModelName(agent, parentContext) {
|
|
24450
|
-
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess',
|
|
24451
|
-
if (!_optionalChain([modelAgent, 'optionalAccess',
|
|
24718
|
+
const modelAgent = _nullishCoalesce(agent, () => ( _optionalChain([parentContext, 'optionalAccess', _609 => _609.agent])));
|
|
24719
|
+
if (!_optionalChain([modelAgent, 'optionalAccess', _610 => _610.model])) {
|
|
24452
24720
|
return;
|
|
24453
24721
|
}
|
|
24454
24722
|
if (typeof modelAgent.model === "string") {
|
|
@@ -24461,30 +24729,30 @@ function extractModelName(agent, parentContext) {
|
|
|
24461
24729
|
}
|
|
24462
24730
|
function extractToolCallId(req) {
|
|
24463
24731
|
const toolContext = req.toolContext;
|
|
24464
|
-
return _optionalChain([toolContext, 'optionalAccess',
|
|
24732
|
+
return _optionalChain([toolContext, 'optionalAccess', _611 => _611.functionCallId]);
|
|
24465
24733
|
}
|
|
24466
24734
|
function extractToolName2(req, tool) {
|
|
24467
|
-
if (typeof _optionalChain([tool, 'optionalAccess',
|
|
24735
|
+
if (typeof _optionalChain([tool, 'optionalAccess', _612 => _612.name]) === "string" && tool.name.length > 0) {
|
|
24468
24736
|
return tool.name;
|
|
24469
24737
|
}
|
|
24470
24738
|
const toolContext = req.toolContext;
|
|
24471
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24472
|
-
const invocationTool = _optionalChain([invocationContext, 'optionalAccess',
|
|
24473
|
-
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]);
|
|
24474
24742
|
return typeof toolName === "string" && toolName.length > 0 ? toolName : void 0;
|
|
24475
24743
|
}
|
|
24476
24744
|
function extractToolAgentName(req) {
|
|
24477
24745
|
const toolContext = req.toolContext;
|
|
24478
|
-
const directName = _optionalChain([toolContext, 'optionalAccess',
|
|
24746
|
+
const directName = _optionalChain([toolContext, 'optionalAccess', _616 => _616.agentName]);
|
|
24479
24747
|
if (typeof directName === "string" && directName.length > 0) {
|
|
24480
24748
|
return directName;
|
|
24481
24749
|
}
|
|
24482
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24750
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _617 => _617.invocationContext]);
|
|
24483
24751
|
return extractAgentName(void 0, invocationContext);
|
|
24484
24752
|
}
|
|
24485
24753
|
function findToolParentSpan(req, activeAgentSpans, activeRunnerSpans) {
|
|
24486
24754
|
const toolContext = req.toolContext;
|
|
24487
|
-
const invocationContext = _optionalChain([toolContext, 'optionalAccess',
|
|
24755
|
+
const invocationContext = _optionalChain([toolContext, 'optionalAccess', _618 => _618.invocationContext]);
|
|
24488
24756
|
const contextKey = extractInvocationContextKey(invocationContext);
|
|
24489
24757
|
const agentName = extractToolAgentName(req);
|
|
24490
24758
|
if (contextKey && agentName) {
|
|
@@ -24866,7 +25134,7 @@ function extractCohereResponseMetadata(result) {
|
|
|
24866
25134
|
RESPONSE_METADATA_ALLOWLIST2
|
|
24867
25135
|
);
|
|
24868
25136
|
const meta = isObject(result.meta) ? result.meta : void 0;
|
|
24869
|
-
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;
|
|
24870
25138
|
const metadata = {
|
|
24871
25139
|
...responseMetadata,
|
|
24872
25140
|
...apiVersion ? { api_version: apiVersion } : {}
|
|
@@ -25027,13 +25295,13 @@ function getToolCallIndex2(toolCall, fallbackIndex) {
|
|
|
25027
25295
|
return typeof toolCall.index === "number" && Number.isInteger(toolCall.index) ? toolCall.index : fallbackIndex;
|
|
25028
25296
|
}
|
|
25029
25297
|
function appendToolCallDelta(existing, incoming) {
|
|
25030
|
-
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess',
|
|
25298
|
+
const currentArguments = isObject(_optionalChain([existing, 'optionalAccess', _621 => _621.function])) && typeof existing.function.arguments === "string" ? existing.function.arguments : "";
|
|
25031
25299
|
const incomingArguments = isObject(incoming.function) && typeof incoming.function.arguments === "string" ? incoming.function.arguments : "";
|
|
25032
25300
|
return {
|
|
25033
25301
|
...existing,
|
|
25034
25302
|
...incoming,
|
|
25035
25303
|
function: {
|
|
25036
|
-
...isObject(_optionalChain([existing, 'optionalAccess',
|
|
25304
|
+
...isObject(_optionalChain([existing, 'optionalAccess', _622 => _622.function])) ? existing.function : {},
|
|
25037
25305
|
...isObject(incoming.function) ? incoming.function : {},
|
|
25038
25306
|
...incomingArguments ? { arguments: `${currentArguments}${incomingArguments}` } : {}
|
|
25039
25307
|
}
|
|
@@ -25289,7 +25557,7 @@ function aggregateCohereChatStreamChunks(chunks) {
|
|
|
25289
25557
|
...mergedToolCalls.length > 0 ? { toolCalls: mergedToolCalls } : {}
|
|
25290
25558
|
};
|
|
25291
25559
|
} else if (mergedToolCalls.length > 0 || role || mergedText.length > 0 || aggregatedContentBlocks.length > 0) {
|
|
25292
|
-
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;
|
|
25293
25561
|
output = {
|
|
25294
25562
|
...role ? { role } : {},
|
|
25295
25563
|
...textContent ? { content: textContent } : {},
|
|
@@ -25338,7 +25606,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25338
25606
|
metadata: { ...metadata, provider: "groq" }
|
|
25339
25607
|
};
|
|
25340
25608
|
},
|
|
25341
|
-
extractOutput: (result) => _optionalChain([result, 'optionalAccess',
|
|
25609
|
+
extractOutput: (result) => _optionalChain([result, 'optionalAccess', _625 => _625.choices]),
|
|
25342
25610
|
extractMetrics: (result, startTime) => {
|
|
25343
25611
|
const metrics = parseGroqMetrics(result);
|
|
25344
25612
|
if (startTime) {
|
|
@@ -25361,7 +25629,7 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25361
25629
|
};
|
|
25362
25630
|
},
|
|
25363
25631
|
extractOutput: (result) => {
|
|
25364
|
-
const embedding = _optionalChain([result, 'optionalAccess',
|
|
25632
|
+
const embedding = _optionalChain([result, 'optionalAccess', _626 => _626.data, 'optionalAccess', _627 => _627[0], 'optionalAccess', _628 => _628.embedding]);
|
|
25365
25633
|
return Array.isArray(embedding) ? { embedding_length: embedding.length } : void 0;
|
|
25366
25634
|
},
|
|
25367
25635
|
extractMetrics: (result) => parseGroqMetrics(result)
|
|
@@ -25373,8 +25641,8 @@ var GroqPlugin = class extends BasePlugin {
|
|
|
25373
25641
|
}
|
|
25374
25642
|
};
|
|
25375
25643
|
function parseGroqMetrics(result) {
|
|
25376
|
-
const metrics = parseMetricsFromUsage(_optionalChain([result, 'optionalAccess',
|
|
25377
|
-
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]);
|
|
25378
25646
|
if (!xGroq || typeof xGroq !== "object") {
|
|
25379
25647
|
return metrics;
|
|
25380
25648
|
}
|
|
@@ -25398,7 +25666,7 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
25398
25666
|
);
|
|
25399
25667
|
const reasoning = aggregateGroqReasoning(chunks);
|
|
25400
25668
|
if (reasoning !== void 0) {
|
|
25401
|
-
const message = _optionalChain([aggregated, 'access',
|
|
25669
|
+
const message = _optionalChain([aggregated, 'access', _631 => _631.output, 'access', _632 => _632[0], 'optionalAccess', _633 => _633.message]);
|
|
25402
25670
|
if (message) {
|
|
25403
25671
|
message.reasoning = reasoning;
|
|
25404
25672
|
}
|
|
@@ -25411,8 +25679,8 @@ function aggregateGroqChatCompletionChunks(chunks, streamResult, endEvent) {
|
|
|
25411
25679
|
function aggregateGroqReasoning(chunks) {
|
|
25412
25680
|
let reasoning = "";
|
|
25413
25681
|
for (const chunk of chunks) {
|
|
25414
|
-
const delta = _optionalChain([chunk, 'access',
|
|
25415
|
-
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]);
|
|
25416
25684
|
if (typeof deltaReasoning === "string") {
|
|
25417
25685
|
reasoning += deltaReasoning;
|
|
25418
25686
|
}
|
|
@@ -25497,11 +25765,11 @@ function traceBedrockRuntimeClientSendChannel(channel2) {
|
|
|
25497
25765
|
shouldTrace: ([command, optionsOrCb, cb]) => getBedrockRuntimeOperation(command) !== void 0 && typeof optionsOrCb !== "function" && typeof cb !== "function",
|
|
25498
25766
|
type: "llm" /* LLM */,
|
|
25499
25767
|
extractInput: ([command]) => extractBedrockRuntimeInput(command),
|
|
25500
|
-
extractOutput: (result, endEvent) => extractBedrockRuntimeOutput(_optionalChain([endEvent, 'optionalAccess',
|
|
25501
|
-
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),
|
|
25502
25770
|
extractMetrics: (result) => extractBedrockRuntimeResponseMetrics(result),
|
|
25503
25771
|
patchResult: ({ endEvent, result, span, startTime }) => patchBedrockRuntimeStreamingResult({
|
|
25504
|
-
command: _optionalChain([endEvent, 'access',
|
|
25772
|
+
command: _optionalChain([endEvent, 'access', _642 => _642.arguments, 'optionalAccess', _643 => _643[0]]),
|
|
25505
25773
|
result,
|
|
25506
25774
|
span,
|
|
25507
25775
|
startTime
|
|
@@ -25522,8 +25790,8 @@ function extractBedrockRuntimeInput(command) {
|
|
|
25522
25790
|
const converseRequest = isObject(request) ? request : void 0;
|
|
25523
25791
|
return {
|
|
25524
25792
|
input: sanitizeBedrockValue({
|
|
25525
|
-
messages: _optionalChain([converseRequest, 'optionalAccess',
|
|
25526
|
-
system: _optionalChain([converseRequest, 'optionalAccess',
|
|
25793
|
+
messages: _optionalChain([converseRequest, 'optionalAccess', _644 => _644.messages]),
|
|
25794
|
+
system: _optionalChain([converseRequest, 'optionalAccess', _645 => _645.system])
|
|
25527
25795
|
}),
|
|
25528
25796
|
metadata
|
|
25529
25797
|
};
|
|
@@ -25531,7 +25799,7 @@ function extractBedrockRuntimeInput(command) {
|
|
|
25531
25799
|
if (operation === "invokeModel" || operation === "invokeModelWithBidirectionalStream" || operation === "invokeModelWithResponseStream") {
|
|
25532
25800
|
const invokeRequest = isObject(request) ? request : void 0;
|
|
25533
25801
|
return {
|
|
25534
|
-
input: _nullishCoalesce(parseJsonBody(_optionalChain([invokeRequest, 'optionalAccess',
|
|
25802
|
+
input: _nullishCoalesce(parseJsonBody(_optionalChain([invokeRequest, 'optionalAccess', _646 => _646.body])), () => ( summarizeBody(_optionalChain([invokeRequest, 'optionalAccess', _647 => _647.body])))),
|
|
25535
25803
|
metadata
|
|
25536
25804
|
};
|
|
25537
25805
|
}
|
|
@@ -25570,12 +25838,12 @@ function extractBedrockRuntimeOutput(command, result) {
|
|
|
25570
25838
|
const operation = getBedrockRuntimeOperation(command);
|
|
25571
25839
|
if (operation === "converse") {
|
|
25572
25840
|
return sanitizeBedrockValue(
|
|
25573
|
-
_optionalChain([result, 'optionalAccess',
|
|
25841
|
+
_optionalChain([result, 'optionalAccess', _648 => _648.output, 'optionalAccess', _649 => _649.message])
|
|
25574
25842
|
);
|
|
25575
25843
|
}
|
|
25576
25844
|
if (operation === "invokeModel") {
|
|
25577
25845
|
const response = isObject(result) ? result : void 0;
|
|
25578
|
-
return _nullishCoalesce(parseJsonBody(_optionalChain([response, 'optionalAccess',
|
|
25846
|
+
return _nullishCoalesce(parseJsonBody(_optionalChain([response, 'optionalAccess', _650 => _650.body])), () => ( summarizeBody(_optionalChain([response, 'optionalAccess', _651 => _651.body]))));
|
|
25579
25847
|
}
|
|
25580
25848
|
return sanitizeBedrockValue(result);
|
|
25581
25849
|
}
|
|
@@ -25612,8 +25880,8 @@ function extractBedrockRuntimeResponseMetrics(result) {
|
|
|
25612
25880
|
if (isObject(parsedBody)) {
|
|
25613
25881
|
const metadata = isObject(parsedBody.metadata) ? parsedBody.metadata : void 0;
|
|
25614
25882
|
const metrics = parseBedrockRuntimeMetrics(
|
|
25615
|
-
_nullishCoalesce(parsedBody.usage, () => ( _optionalChain([metadata, 'optionalAccess',
|
|
25616
|
-
_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])))
|
|
25617
25885
|
);
|
|
25618
25886
|
if (Object.keys(metrics).length > 0) {
|
|
25619
25887
|
return metrics;
|
|
@@ -25778,42 +26046,42 @@ function aggregateBedrockConverseStreamChunks(chunks) {
|
|
|
25778
26046
|
if (exception) {
|
|
25779
26047
|
return exception;
|
|
25780
26048
|
}
|
|
25781
|
-
if (typeof _optionalChain([chunk, 'access',
|
|
26049
|
+
if (typeof _optionalChain([chunk, 'access', _654 => _654.messageStart, 'optionalAccess', _655 => _655.role]) === "string") {
|
|
25782
26050
|
role = chunk.messageStart.role;
|
|
25783
26051
|
}
|
|
25784
|
-
const startIndex = _optionalChain([chunk, 'access',
|
|
26052
|
+
const startIndex = _optionalChain([chunk, 'access', _656 => _656.contentBlockStart, 'optionalAccess', _657 => _657.contentBlockIndex]);
|
|
25785
26053
|
if (typeof startIndex === "number") {
|
|
25786
26054
|
contentByIndex.set(startIndex, {
|
|
25787
26055
|
..._nullishCoalesce(contentByIndex.get(startIndex), () => ( {})),
|
|
25788
|
-
...sanitizeRecord(_optionalChain([chunk, 'access',
|
|
26056
|
+
...sanitizeRecord(_optionalChain([chunk, 'access', _658 => _658.contentBlockStart, 'optionalAccess', _659 => _659.start]))
|
|
25789
26057
|
});
|
|
25790
26058
|
}
|
|
25791
|
-
const deltaIndex = _optionalChain([chunk, 'access',
|
|
25792
|
-
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]);
|
|
25793
26061
|
if (typeof deltaIndex === "number" && isObject(delta)) {
|
|
25794
26062
|
const existing = _nullishCoalesce(contentByIndex.get(deltaIndex), () => ( {}));
|
|
25795
26063
|
contentByIndex.set(deltaIndex, mergeContentBlockDelta(existing, delta));
|
|
25796
26064
|
}
|
|
25797
|
-
if (typeof _optionalChain([chunk, 'access',
|
|
26065
|
+
if (typeof _optionalChain([chunk, 'access', _664 => _664.messageStop, 'optionalAccess', _665 => _665.stopReason]) === "string") {
|
|
25798
26066
|
stopReason = chunk.messageStop.stopReason;
|
|
25799
26067
|
}
|
|
25800
|
-
if (_optionalChain([chunk, 'access',
|
|
26068
|
+
if (_optionalChain([chunk, 'access', _666 => _666.messageStop, 'optionalAccess', _667 => _667.additionalModelResponseFields]) !== void 0) {
|
|
25801
26069
|
metadata.additionalModelResponseFields = sanitizeBedrockValue(
|
|
25802
26070
|
chunk.messageStop.additionalModelResponseFields
|
|
25803
26071
|
);
|
|
25804
26072
|
}
|
|
25805
|
-
if (_optionalChain([chunk, 'access',
|
|
26073
|
+
if (_optionalChain([chunk, 'access', _668 => _668.metadata, 'optionalAccess', _669 => _669.usage]) !== void 0) {
|
|
25806
26074
|
usage = chunk.metadata.usage;
|
|
25807
26075
|
}
|
|
25808
|
-
if (_optionalChain([chunk, 'access',
|
|
26076
|
+
if (_optionalChain([chunk, 'access', _670 => _670.metadata, 'optionalAccess', _671 => _671.metrics]) !== void 0) {
|
|
25809
26077
|
responseMetrics = chunk.metadata.metrics;
|
|
25810
26078
|
}
|
|
25811
|
-
if (_optionalChain([chunk, 'access',
|
|
26079
|
+
if (_optionalChain([chunk, 'access', _672 => _672.metadata, 'optionalAccess', _673 => _673.performanceConfig]) !== void 0) {
|
|
25812
26080
|
metadata.performanceConfig = sanitizeBedrockValue(
|
|
25813
26081
|
chunk.metadata.performanceConfig
|
|
25814
26082
|
);
|
|
25815
26083
|
}
|
|
25816
|
-
if (_optionalChain([chunk, 'access',
|
|
26084
|
+
if (_optionalChain([chunk, 'access', _674 => _674.metadata, 'optionalAccess', _675 => _675.serviceTier]) !== void 0) {
|
|
25817
26085
|
metadata.serviceTier = chunk.metadata.serviceTier;
|
|
25818
26086
|
}
|
|
25819
26087
|
}
|
|
@@ -25837,11 +26105,11 @@ function aggregateInvokeModelResponseStreamChunks(chunks) {
|
|
|
25837
26105
|
return exception;
|
|
25838
26106
|
}
|
|
25839
26107
|
}
|
|
25840
|
-
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);
|
|
25841
26109
|
const jsonLikeChunks = parsedChunks.filter(isObject);
|
|
25842
26110
|
const text = parsedChunks.map(extractTextFromJsonLike).join("");
|
|
25843
26111
|
const lastMetadataChunk = jsonLikeChunks.slice().reverse().find((chunk) => isObject(chunk.metadata));
|
|
25844
|
-
const metadata = isObject(_optionalChain([lastMetadataChunk, 'optionalAccess',
|
|
26112
|
+
const metadata = isObject(_optionalChain([lastMetadataChunk, 'optionalAccess', _678 => _678.metadata])) ? sanitizeRecord(lastMetadataChunk.metadata) : void 0;
|
|
25845
26113
|
let usage;
|
|
25846
26114
|
for (const chunk of jsonLikeChunks) {
|
|
25847
26115
|
const message = chunk.message;
|
|
@@ -25962,7 +26230,7 @@ function parseJsonBody(body) {
|
|
|
25962
26230
|
}
|
|
25963
26231
|
try {
|
|
25964
26232
|
return sanitizeBedrockValue(JSON.parse(text));
|
|
25965
|
-
} catch (
|
|
26233
|
+
} catch (e70) {
|
|
25966
26234
|
return void 0;
|
|
25967
26235
|
}
|
|
25968
26236
|
}
|
|
@@ -26115,8 +26383,8 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26115
26383
|
type: "llm" /* LLM */,
|
|
26116
26384
|
extractInput: ([input]) => extractGenerateInput(input),
|
|
26117
26385
|
extractOutput: extractGenerateOutput,
|
|
26118
|
-
extractMetadata: (result, event) => extractGenerateResponseMetadata(result, _optionalChain([event, 'optionalAccess',
|
|
26119
|
-
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]))
|
|
26120
26388
|
})
|
|
26121
26389
|
);
|
|
26122
26390
|
this.unsubscribers.push(
|
|
@@ -26133,7 +26401,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26133
26401
|
type: "function" /* FUNCTION */,
|
|
26134
26402
|
extractInput: ([params]) => extractEmbedInput(params),
|
|
26135
26403
|
extractOutput: (result) => summarizeEmbeddingResult(result),
|
|
26136
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
26404
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _682 => _682.arguments, 'optionalAccess', _683 => _683[0]])),
|
|
26137
26405
|
extractMetrics: () => ({})
|
|
26138
26406
|
})
|
|
26139
26407
|
);
|
|
@@ -26143,7 +26411,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26143
26411
|
type: "function" /* FUNCTION */,
|
|
26144
26412
|
extractInput: ([params]) => extractEmbedManyInput(params),
|
|
26145
26413
|
extractOutput: summarizeEmbeddingResult,
|
|
26146
|
-
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess',
|
|
26414
|
+
extractMetadata: (_result, event) => extractEmbedMetadata(_optionalChain([event, 'optionalAccess', _684 => _684.arguments, 'optionalAccess', _685 => _685[0]])),
|
|
26147
26415
|
extractMetrics: () => ({})
|
|
26148
26416
|
})
|
|
26149
26417
|
);
|
|
@@ -26194,7 +26462,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26194
26462
|
};
|
|
26195
26463
|
tracingChannel2.subscribe(handlers);
|
|
26196
26464
|
this.unsubscribers.push(() => {
|
|
26197
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
26465
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _686 => _686()]);
|
|
26198
26466
|
tracingChannel2.unsubscribe(handlers);
|
|
26199
26467
|
});
|
|
26200
26468
|
}
|
|
@@ -26242,7 +26510,7 @@ var GenkitPlugin = class extends BasePlugin {
|
|
|
26242
26510
|
};
|
|
26243
26511
|
tracingChannel2.subscribe(handlers);
|
|
26244
26512
|
this.unsubscribers.push(() => {
|
|
26245
|
-
_optionalChain([unbindCurrentSpanStore, 'optionalCall',
|
|
26513
|
+
_optionalChain([unbindCurrentSpanStore, 'optionalCall', _687 => _687()]);
|
|
26246
26514
|
tracingChannel2.unsubscribe(handlers);
|
|
26247
26515
|
});
|
|
26248
26516
|
}
|
|
@@ -26309,10 +26577,10 @@ function ensureActionSpanState(states, event, create) {
|
|
|
26309
26577
|
}
|
|
26310
26578
|
function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
26311
26579
|
const state = _internalGetGlobalState();
|
|
26312
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
26580
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _688 => _688.contextManager]);
|
|
26313
26581
|
const startChannel = tracingChannel2.start;
|
|
26314
26582
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
26315
|
-
if (!_optionalChain([startChannel, 'optionalAccess',
|
|
26583
|
+
if (!_optionalChain([startChannel, 'optionalAccess', _689 => _689.bindStore]) || !currentSpanStore) {
|
|
26316
26584
|
return void 0;
|
|
26317
26585
|
}
|
|
26318
26586
|
startChannel.bindStore(currentSpanStore, (event) => {
|
|
@@ -26324,7 +26592,7 @@ function bindActionCurrentSpanStoreToStart(tracingChannel2, states, create) {
|
|
|
26324
26592
|
return state2 ? contextManager.wrapSpanForStore(state2.span) : currentSpanStore.getStore();
|
|
26325
26593
|
});
|
|
26326
26594
|
return () => {
|
|
26327
|
-
_optionalChain([startChannel, 'access',
|
|
26595
|
+
_optionalChain([startChannel, 'access', _690 => _690.unbindStore, 'optionalCall', _691 => _691(currentSpanStore)]);
|
|
26328
26596
|
};
|
|
26329
26597
|
}
|
|
26330
26598
|
function normalizeInput(input) {
|
|
@@ -26371,25 +26639,25 @@ function extractGenerateOutput(result) {
|
|
|
26371
26639
|
}
|
|
26372
26640
|
function extractGenerateResponseMetadata(result, input) {
|
|
26373
26641
|
const normalized = input ? normalizeInput(input) : void 0;
|
|
26374
|
-
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;
|
|
26375
26643
|
return {
|
|
26376
26644
|
...genkitProviderMetadata(),
|
|
26377
26645
|
...pickDefined({
|
|
26378
|
-
model: modelName(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
26379
|
-
finishReason: _optionalChain([result, 'optionalAccess',
|
|
26380
|
-
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])
|
|
26381
26649
|
})
|
|
26382
26650
|
};
|
|
26383
26651
|
}
|
|
26384
26652
|
function extractEmbedInput(params) {
|
|
26385
26653
|
return {
|
|
26386
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
26654
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _698 => _698.content])),
|
|
26387
26655
|
metadata: extractEmbedMetadata(params)
|
|
26388
26656
|
};
|
|
26389
26657
|
}
|
|
26390
26658
|
function extractEmbedManyInput(params) {
|
|
26391
26659
|
return {
|
|
26392
|
-
input: processInputAttachments(_optionalChain([params, 'optionalAccess',
|
|
26660
|
+
input: processInputAttachments(_optionalChain([params, 'optionalAccess', _699 => _699.content])),
|
|
26393
26661
|
metadata: extractEmbedMetadata(params)
|
|
26394
26662
|
};
|
|
26395
26663
|
}
|
|
@@ -26397,7 +26665,7 @@ function extractEmbedMetadata(params) {
|
|
|
26397
26665
|
return {
|
|
26398
26666
|
...genkitProviderMetadata(),
|
|
26399
26667
|
...pickDefined({
|
|
26400
|
-
model: modelName(_optionalChain([params, 'optionalAccess',
|
|
26668
|
+
model: modelName(_optionalChain([params, 'optionalAccess', _700 => _700.embedder]))
|
|
26401
26669
|
})
|
|
26402
26670
|
};
|
|
26403
26671
|
}
|
|
@@ -26405,7 +26673,7 @@ function summarizeEmbeddingResult(result) {
|
|
|
26405
26673
|
if (Array.isArray(result)) {
|
|
26406
26674
|
return {
|
|
26407
26675
|
embedding_count: result.length,
|
|
26408
|
-
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
|
|
26409
26677
|
};
|
|
26410
26678
|
}
|
|
26411
26679
|
if (isObject(result) && Array.isArray(result.embeddings)) {
|
|
@@ -26432,7 +26700,7 @@ function patchGenerateStreamResult(result, span, startTime) {
|
|
|
26432
26700
|
finishSpan(async () => {
|
|
26433
26701
|
const streamedText = chunks.map((chunk) => safeGet(chunk, "text")).join("");
|
|
26434
26702
|
const response = await result.response;
|
|
26435
|
-
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess',
|
|
26703
|
+
const metrics = parseGenkitUsageMetrics(_optionalChain([response, 'optionalAccess', _706 => _706.usage]));
|
|
26436
26704
|
if (firstChunkTime !== void 0) {
|
|
26437
26705
|
metrics.time_to_first_token = firstChunkTime - startTime;
|
|
26438
26706
|
}
|
|
@@ -26525,22 +26793,22 @@ function extractActionMetadata(self) {
|
|
|
26525
26793
|
}
|
|
26526
26794
|
function extractActionSpanMetadata(args) {
|
|
26527
26795
|
const options = extractRunInNewSpanOptions(args);
|
|
26528
|
-
const labels = isObject(_optionalChain([options, 'optionalAccess',
|
|
26529
|
-
const metadata = isObject(_optionalChain([options, 'optionalAccess',
|
|
26530
|
-
const actionType = stringValue(_optionalChain([labels, 'optionalAccess',
|
|
26531
|
-
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]));
|
|
26532
26800
|
if (!actionType || !name) {
|
|
26533
26801
|
return void 0;
|
|
26534
26802
|
}
|
|
26535
26803
|
return {
|
|
26536
26804
|
actionType,
|
|
26537
|
-
key: stringValue(_optionalChain([labels, 'optionalAccess',
|
|
26805
|
+
key: stringValue(_optionalChain([labels, 'optionalAccess', _711 => _711["genkit:key"]])),
|
|
26538
26806
|
name
|
|
26539
26807
|
};
|
|
26540
26808
|
}
|
|
26541
26809
|
function extractActionSpanInput(args) {
|
|
26542
26810
|
const options = extractRunInNewSpanOptions(args);
|
|
26543
|
-
if (!isObject(_optionalChain([options, 'optionalAccess',
|
|
26811
|
+
if (!isObject(_optionalChain([options, 'optionalAccess', _712 => _712.metadata]))) {
|
|
26544
26812
|
return void 0;
|
|
26545
26813
|
}
|
|
26546
26814
|
return options.metadata.input;
|
|
@@ -26553,7 +26821,7 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
26553
26821
|
if (runStepName) {
|
|
26554
26822
|
return true;
|
|
26555
26823
|
}
|
|
26556
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
26824
|
+
switch (_optionalChain([metadata, 'optionalAccess', _713 => _713.actionType])) {
|
|
26557
26825
|
case "model":
|
|
26558
26826
|
case "background-model":
|
|
26559
26827
|
case "embedder":
|
|
@@ -26563,8 +26831,8 @@ function shouldTraceAction(metadata, runStepName) {
|
|
|
26563
26831
|
}
|
|
26564
26832
|
}
|
|
26565
26833
|
function actionSpanName(metadata, runStepName) {
|
|
26566
|
-
const actionType = _optionalChain([metadata, 'optionalAccess',
|
|
26567
|
-
const name = _optionalChain([metadata, 'optionalAccess',
|
|
26834
|
+
const actionType = _optionalChain([metadata, 'optionalAccess', _714 => _714.actionType]);
|
|
26835
|
+
const name = _optionalChain([metadata, 'optionalAccess', _715 => _715.name]);
|
|
26568
26836
|
if (actionType && name) {
|
|
26569
26837
|
return `genkit.${actionType}: ${name}`;
|
|
26570
26838
|
}
|
|
@@ -26577,7 +26845,7 @@ function actionSpanName(metadata, runStepName) {
|
|
|
26577
26845
|
return "genkit.action";
|
|
26578
26846
|
}
|
|
26579
26847
|
function actionSpanType(metadata) {
|
|
26580
|
-
switch (_optionalChain([metadata, 'optionalAccess',
|
|
26848
|
+
switch (_optionalChain([metadata, 'optionalAccess', _716 => _716.actionType])) {
|
|
26581
26849
|
case "tool":
|
|
26582
26850
|
case "tool.v2":
|
|
26583
26851
|
return "tool" /* TOOL */;
|
|
@@ -26592,9 +26860,9 @@ function actionMetadataForLog(metadata, runStepName) {
|
|
|
26592
26860
|
return {
|
|
26593
26861
|
...genkitProviderMetadata(),
|
|
26594
26862
|
...pickDefined({
|
|
26595
|
-
"genkit.action_type": _optionalChain([metadata, 'optionalAccess',
|
|
26596
|
-
"genkit.action_name": _optionalChain([metadata, 'optionalAccess',
|
|
26597
|
-
"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]),
|
|
26598
26866
|
"genkit.run_name": runStepName
|
|
26599
26867
|
})
|
|
26600
26868
|
};
|
|
@@ -26614,7 +26882,7 @@ function safeGet(value, key) {
|
|
|
26614
26882
|
}
|
|
26615
26883
|
try {
|
|
26616
26884
|
return value[key];
|
|
26617
|
-
} catch (
|
|
26885
|
+
} catch (e71) {
|
|
26618
26886
|
return void 0;
|
|
26619
26887
|
}
|
|
26620
26888
|
}
|
|
@@ -27054,10 +27322,10 @@ function injectTracingHooks2(config, state) {
|
|
|
27054
27322
|
const existingHooks = _nullishCoalesce(config.hooks, () => ( {}));
|
|
27055
27323
|
const onSessionEnd = async (input, invocation) => {
|
|
27056
27324
|
try {
|
|
27057
|
-
await _optionalChain([existingHooks, 'access',
|
|
27325
|
+
await _optionalChain([existingHooks, 'access', _720 => _720.onSessionEnd, 'optionalCall', _721 => _721(input, invocation)]);
|
|
27058
27326
|
} finally {
|
|
27059
27327
|
handleSessionEnd(state, input.reason, input.error);
|
|
27060
|
-
_optionalChain([state, 'access',
|
|
27328
|
+
_optionalChain([state, 'access', _722 => _722.unsubscribeEvents, 'optionalCall', _723 => _723()]);
|
|
27061
27329
|
}
|
|
27062
27330
|
};
|
|
27063
27331
|
config.hooks = {
|
|
@@ -27096,7 +27364,7 @@ function makeSessionHandlers(sessionStates, configArgIndex, includeProviderMetad
|
|
|
27096
27364
|
if (config.model) {
|
|
27097
27365
|
metadata["github_copilot.model"] = config.model;
|
|
27098
27366
|
}
|
|
27099
|
-
if (includeProviderMetadata && _optionalChain([config, 'access',
|
|
27367
|
+
if (includeProviderMetadata && _optionalChain([config, 'access', _724 => _724.provider, 'optionalAccess', _725 => _725.type])) {
|
|
27100
27368
|
metadata["github_copilot.provider_type"] = config.provider.type;
|
|
27101
27369
|
}
|
|
27102
27370
|
if (Object.keys(metadata).length > 0) {
|
|
@@ -27294,7 +27562,7 @@ function subscribeToFlueContext(value, state) {
|
|
|
27294
27562
|
}
|
|
27295
27563
|
released = true;
|
|
27296
27564
|
try {
|
|
27297
|
-
_optionalChain([unsubscribe, 'optionalCall',
|
|
27565
|
+
_optionalChain([unsubscribe, 'optionalCall', _726 => _726()]);
|
|
27298
27566
|
} catch (error) {
|
|
27299
27567
|
logInstrumentationError3("Flue context unsubscribe", error);
|
|
27300
27568
|
}
|
|
@@ -27326,7 +27594,7 @@ function isAutoContextTerminalEvent(event, ctx) {
|
|
|
27326
27594
|
if (type !== "operation") {
|
|
27327
27595
|
return false;
|
|
27328
27596
|
}
|
|
27329
|
-
return !_optionalChain([ctx, 'optionalAccess',
|
|
27597
|
+
return !_optionalChain([ctx, 'optionalAccess', _727 => _727.runId]) && typeof Reflect.get(event, "runId") !== "string";
|
|
27330
27598
|
}
|
|
27331
27599
|
function isObservableFlueContext(value) {
|
|
27332
27600
|
return isObjectLike(value) && typeof Reflect.get(value, "subscribeEvent") === "function";
|
|
@@ -27394,13 +27662,13 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27394
27662
|
case "workflow":
|
|
27395
27663
|
return this.ensureWorkflowSpanForExecution(operation, executionContext);
|
|
27396
27664
|
case "agent":
|
|
27397
|
-
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]);
|
|
27398
27666
|
case "model":
|
|
27399
|
-
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]);
|
|
27400
27668
|
case "tool":
|
|
27401
27669
|
return this.spanForToolExecution(operation, executionContext);
|
|
27402
27670
|
case "task":
|
|
27403
|
-
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]);
|
|
27404
27672
|
default:
|
|
27405
27673
|
return void 0;
|
|
27406
27674
|
}
|
|
@@ -27442,7 +27710,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27442
27710
|
ctx
|
|
27443
27711
|
);
|
|
27444
27712
|
}
|
|
27445
|
-
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]);
|
|
27446
27714
|
}
|
|
27447
27715
|
spanForToolExecution(operation, executionContext) {
|
|
27448
27716
|
const contextual = this.toolsByKey.get(
|
|
@@ -27513,7 +27781,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27513
27781
|
if (!event.runId) {
|
|
27514
27782
|
return;
|
|
27515
27783
|
}
|
|
27516
|
-
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")));
|
|
27517
27785
|
const input = flueRunInput(event);
|
|
27518
27786
|
const metadata = {
|
|
27519
27787
|
...extractPayloadMetadata(input),
|
|
@@ -27542,7 +27810,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27542
27810
|
if (!event.runId) {
|
|
27543
27811
|
return;
|
|
27544
27812
|
}
|
|
27545
|
-
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")));
|
|
27546
27814
|
const metadata = {
|
|
27547
27815
|
...extractEventMetadata(event, ctx),
|
|
27548
27816
|
...workflowName ? { "flue.workflow_name": workflowName } : {},
|
|
@@ -27642,8 +27910,8 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27642
27910
|
...provider ? { "flue.provider": provider } : {},
|
|
27643
27911
|
...event.purpose ? { "flue.turn_purpose": event.purpose } : {},
|
|
27644
27912
|
...reasoning ? { reasoning } : {},
|
|
27645
|
-
..._optionalChain([input, 'optionalAccess',
|
|
27646
|
-
..._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 } : {}
|
|
27647
27915
|
};
|
|
27648
27916
|
const parent = this.parentSpanForTurn(event);
|
|
27649
27917
|
const span = startFlueSpan(parent, {
|
|
@@ -27651,11 +27919,11 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27651
27919
|
spanAttributes: { type: "llm" /* LLM */ },
|
|
27652
27920
|
startTime: eventTime(event.timestamp),
|
|
27653
27921
|
event: {
|
|
27654
|
-
input: _optionalChain([input, 'optionalAccess',
|
|
27922
|
+
input: _optionalChain([input, 'optionalAccess', _750 => _750.messages]),
|
|
27655
27923
|
metadata
|
|
27656
27924
|
}
|
|
27657
27925
|
});
|
|
27658
|
-
this.logOperationInput(event.operationId, _nullishCoalesce(_optionalChain([input, 'optionalAccess',
|
|
27926
|
+
this.logOperationInput(event.operationId, _nullishCoalesce(_optionalChain([input, 'optionalAccess', _751 => _751.messages]), () => ( input)));
|
|
27659
27927
|
this.turnsByKey.set(key, { metadata, span });
|
|
27660
27928
|
}
|
|
27661
27929
|
handleTurn(event) {
|
|
@@ -27860,7 +28128,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27860
28128
|
}
|
|
27861
28129
|
}
|
|
27862
28130
|
if (event.runId) {
|
|
27863
|
-
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]);
|
|
27864
28132
|
}
|
|
27865
28133
|
return void 0;
|
|
27866
28134
|
}
|
|
@@ -27878,7 +28146,7 @@ var FlueObserveBridge = (_class22 = class {constructor() { _class22.prototype.__
|
|
|
27878
28146
|
}
|
|
27879
28147
|
}
|
|
27880
28148
|
if (event.runId) {
|
|
27881
|
-
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]);
|
|
27882
28150
|
}
|
|
27883
28151
|
return void 0;
|
|
27884
28152
|
}
|
|
@@ -28060,8 +28328,8 @@ function extractEventMetadata(event, ctx) {
|
|
|
28060
28328
|
...event.taskId ? { "flue.task_id": event.taskId } : {},
|
|
28061
28329
|
...event.operationId ? { "flue.operation_id": event.operationId } : {},
|
|
28062
28330
|
...event.turnId ? { "flue.turn_id": event.turnId } : {},
|
|
28063
|
-
...typeof _optionalChain([ctx, 'optionalAccess',
|
|
28064
|
-
...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 } : {}
|
|
28065
28333
|
};
|
|
28066
28334
|
}
|
|
28067
28335
|
function extractPayloadMetadata(payload) {
|
|
@@ -28078,40 +28346,40 @@ function flueRunInput(event) {
|
|
|
28078
28346
|
return event.input !== void 0 ? event.input : event.payload;
|
|
28079
28347
|
}
|
|
28080
28348
|
function flueTurnRequestInput(event) {
|
|
28081
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28349
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _762 => _762.request, 'optionalAccess', _763 => _763.input]), () => ( event.input));
|
|
28082
28350
|
}
|
|
28083
28351
|
function flueTurnRequestModel(event) {
|
|
28084
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28352
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _764 => _764.request, 'optionalAccess', _765 => _765.model]), () => ( event.model));
|
|
28085
28353
|
}
|
|
28086
28354
|
function flueTurnRequestProvider(event) {
|
|
28087
|
-
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])));
|
|
28088
28356
|
}
|
|
28089
28357
|
function flueTurnRequestApi(event) {
|
|
28090
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28358
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _770 => _770.request, 'optionalAccess', _771 => _771.api]), () => ( event.api));
|
|
28091
28359
|
}
|
|
28092
28360
|
function flueTurnRequestReasoning(event) {
|
|
28093
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28361
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _772 => _772.request, 'optionalAccess', _773 => _773.reasoning]), () => ( event.reasoning));
|
|
28094
28362
|
}
|
|
28095
28363
|
function flueTurnModel(event) {
|
|
28096
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28364
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _774 => _774.request, 'optionalAccess', _775 => _775.model]), () => ( event.model));
|
|
28097
28365
|
}
|
|
28098
28366
|
function flueTurnProvider(event) {
|
|
28099
|
-
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])));
|
|
28100
28368
|
}
|
|
28101
28369
|
function flueTurnApi(event) {
|
|
28102
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28370
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _780 => _780.request, 'optionalAccess', _781 => _781.api]), () => ( event.api));
|
|
28103
28371
|
}
|
|
28104
28372
|
function flueTurnUsage(event) {
|
|
28105
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28373
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _782 => _782.response, 'optionalAccess', _783 => _783.usage]), () => ( event.usage));
|
|
28106
28374
|
}
|
|
28107
28375
|
function flueTurnOutput(event) {
|
|
28108
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28376
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _784 => _784.response, 'optionalAccess', _785 => _785.output]), () => ( event.output));
|
|
28109
28377
|
}
|
|
28110
28378
|
function flueTurnStopReason(event) {
|
|
28111
|
-
return _nullishCoalesce(_optionalChain([event, 'access',
|
|
28379
|
+
return _nullishCoalesce(_optionalChain([event, 'access', _786 => _786.response, 'optionalAccess', _787 => _787.stopReason]), () => ( event.stopReason));
|
|
28112
28380
|
}
|
|
28113
28381
|
function flueTurnError(event) {
|
|
28114
|
-
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));
|
|
28115
28383
|
}
|
|
28116
28384
|
function flueToolInput(event) {
|
|
28117
28385
|
if (event.args !== void 0) {
|
|
@@ -28126,7 +28394,7 @@ function flueToolOutput(event) {
|
|
|
28126
28394
|
return event.output !== void 0 ? event.output : event.result;
|
|
28127
28395
|
}
|
|
28128
28396
|
function flueToolError(event) {
|
|
28129
|
-
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)));
|
|
28130
28398
|
}
|
|
28131
28399
|
function operationOutput(event) {
|
|
28132
28400
|
if (event.operationKind === "prompt" || event.operationKind === "skill") {
|
|
@@ -28203,9 +28471,9 @@ function startFlueSpan(parent, args) {
|
|
|
28203
28471
|
}
|
|
28204
28472
|
function runWithCurrentSpanStore(span, next) {
|
|
28205
28473
|
const state = _internalGetGlobalState();
|
|
28206
|
-
const contextManager = _optionalChain([state, 'optionalAccess',
|
|
28474
|
+
const contextManager = _optionalChain([state, 'optionalAccess', _795 => _795.contextManager]);
|
|
28207
28475
|
const currentSpanStore = contextManager ? contextManager[BRAINTRUST_CURRENT_SPAN_STORE] : void 0;
|
|
28208
|
-
if (contextManager && typeof _optionalChain([currentSpanStore, 'optionalAccess',
|
|
28476
|
+
if (contextManager && typeof _optionalChain([currentSpanStore, 'optionalAccess', _796 => _796.run]) === "function") {
|
|
28209
28477
|
return currentSpanStore.run(contextManager.wrapSpanForStore(span), next);
|
|
28210
28478
|
}
|
|
28211
28479
|
return withCurrent(span, () => next());
|
|
@@ -28241,11 +28509,11 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28241
28509
|
__init82() {this.firstTokenTimes = /* @__PURE__ */ new Map()}
|
|
28242
28510
|
__init83() {this.ttftMs = /* @__PURE__ */ new Map()}
|
|
28243
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);
|
|
28244
|
-
this.parent = _optionalChain([options, 'optionalAccess',
|
|
28512
|
+
this.parent = _optionalChain([options, 'optionalAccess', _797 => _797.parent]);
|
|
28245
28513
|
this.options = {
|
|
28246
|
-
debug: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
28247
|
-
excludeMetadataProps: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
28248
|
-
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])
|
|
28249
28517
|
};
|
|
28250
28518
|
}
|
|
28251
28519
|
startSpan({
|
|
@@ -28259,7 +28527,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28259
28527
|
if (!parentRunId) {
|
|
28260
28528
|
this.rootRunId = runId;
|
|
28261
28529
|
}
|
|
28262
|
-
const tags = _optionalChain([args, 'access',
|
|
28530
|
+
const tags = _optionalChain([args, 'access', _801 => _801.event, 'optionalAccess', _802 => _802.tags]);
|
|
28263
28531
|
const spanAttributes = args.spanAttributes || {};
|
|
28264
28532
|
spanAttributes.type = args.type || spanAttributes.type || "task";
|
|
28265
28533
|
args.type = spanAttributes.type;
|
|
@@ -28279,7 +28547,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28279
28547
|
tags: void 0,
|
|
28280
28548
|
metadata: {
|
|
28281
28549
|
...tags ? { tags } : {},
|
|
28282
|
-
..._optionalChain([args, 'access',
|
|
28550
|
+
..._optionalChain([args, 'access', _803 => _803.event, 'optionalAccess', _804 => _804.metadata]),
|
|
28283
28551
|
braintrust: {
|
|
28284
28552
|
integration_name: "langchain-js",
|
|
28285
28553
|
sdk_language: "javascript"
|
|
@@ -28381,7 +28649,7 @@ var BraintrustLangChainCallbackHandler = (_class23 = class {
|
|
|
28381
28649
|
});
|
|
28382
28650
|
}
|
|
28383
28651
|
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, runName) {
|
|
28384
|
-
if (_optionalChain([tags, 'optionalAccess',
|
|
28652
|
+
if (_optionalChain([tags, 'optionalAccess', _805 => _805.includes, 'call', _806 => _806("langsmith:hidden")])) {
|
|
28385
28653
|
this.skippedRuns.add(runId);
|
|
28386
28654
|
return;
|
|
28387
28655
|
}
|
|
@@ -28491,7 +28759,7 @@ function getSerializedName(serialized) {
|
|
|
28491
28759
|
if (typeof serialized.name === "string") {
|
|
28492
28760
|
return serialized.name;
|
|
28493
28761
|
}
|
|
28494
|
-
const lastIdPart = _optionalChain([serialized, 'access',
|
|
28762
|
+
const lastIdPart = _optionalChain([serialized, 'access', _807 => _807.id, 'optionalAccess', _808 => _808.at, 'call', _809 => _809(-1)]);
|
|
28495
28763
|
return typeof lastIdPart === "string" ? lastIdPart : void 0;
|
|
28496
28764
|
}
|
|
28497
28765
|
function cleanObject(obj) {
|
|
@@ -28504,6 +28772,16 @@ function cleanObject(obj) {
|
|
|
28504
28772
|
})
|
|
28505
28773
|
);
|
|
28506
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
|
+
}
|
|
28507
28785
|
function walkGenerations(response) {
|
|
28508
28786
|
const result = [];
|
|
28509
28787
|
const generations = response.generations || [];
|
|
@@ -28550,7 +28828,7 @@ function getMetricsFromResponse(response) {
|
|
|
28550
28828
|
continue;
|
|
28551
28829
|
}
|
|
28552
28830
|
const inputTokenDetails = usageMetadata.input_token_details;
|
|
28553
|
-
return
|
|
28831
|
+
return normalizeTokenMetrics({
|
|
28554
28832
|
total_tokens: usageMetadata.total_tokens,
|
|
28555
28833
|
prompt_tokens: usageMetadata.input_tokens,
|
|
28556
28834
|
completion_tokens: usageMetadata.output_tokens,
|
|
@@ -28560,7 +28838,7 @@ function getMetricsFromResponse(response) {
|
|
|
28560
28838
|
}
|
|
28561
28839
|
const llmOutput = response.llmOutput || {};
|
|
28562
28840
|
const tokenUsage = isRecord(llmOutput.tokenUsage) ? llmOutput.tokenUsage : isRecord(llmOutput.estimatedTokens) ? llmOutput.estimatedTokens : {};
|
|
28563
|
-
return
|
|
28841
|
+
return normalizeTokenMetrics({
|
|
28564
28842
|
total_tokens: tokenUsage.totalTokens,
|
|
28565
28843
|
prompt_tokens: tokenUsage.promptTokens,
|
|
28566
28844
|
completion_tokens: tokenUsage.completionTokens
|
|
@@ -28569,7 +28847,7 @@ function getMetricsFromResponse(response) {
|
|
|
28569
28847
|
function safeJsonParse(input) {
|
|
28570
28848
|
try {
|
|
28571
28849
|
return JSON.parse(input);
|
|
28572
|
-
} catch (
|
|
28850
|
+
} catch (e72) {
|
|
28573
28851
|
return input;
|
|
28574
28852
|
}
|
|
28575
28853
|
}
|
|
@@ -28628,7 +28906,7 @@ var LangChainPlugin = (_class24 = class extends BasePlugin {constructor(...args6
|
|
|
28628
28906
|
try {
|
|
28629
28907
|
result.addHandler(new BraintrustLangChainCallbackHandler(), true);
|
|
28630
28908
|
this.injectedManagers.add(result);
|
|
28631
|
-
} catch (
|
|
28909
|
+
} catch (e73) {
|
|
28632
28910
|
}
|
|
28633
28911
|
}
|
|
28634
28912
|
}, _class24);
|
|
@@ -28640,7 +28918,7 @@ function isCallbackManager(value) {
|
|
|
28640
28918
|
return typeof maybeManager.addHandler === "function";
|
|
28641
28919
|
}
|
|
28642
28920
|
function hasBraintrustHandler(manager) {
|
|
28643
|
-
return _nullishCoalesce(_optionalChain([manager, 'access',
|
|
28921
|
+
return _nullishCoalesce(_optionalChain([manager, 'access', _810 => _810.handlers, 'optionalAccess', _811 => _811.some, 'call', _812 => _812((handler) => {
|
|
28644
28922
|
if (typeof handler !== "object" || handler === null) {
|
|
28645
28923
|
return false;
|
|
28646
28924
|
}
|
|
@@ -28832,7 +29110,7 @@ var LangSmithPlugin = (_class25 = class extends BasePlugin {
|
|
|
28832
29110
|
}
|
|
28833
29111
|
if (this.shouldSkipLangChainRun(run)) {
|
|
28834
29112
|
const active2 = this.activeRuns.get(id);
|
|
28835
|
-
_optionalChain([active2, 'optionalAccess',
|
|
29113
|
+
_optionalChain([active2, 'optionalAccess', _813 => _813.span, 'access', _814 => _814.end, 'call', _815 => _815()]);
|
|
28836
29114
|
this.activeRuns.delete(id);
|
|
28837
29115
|
this.completedRuns.set(id, true);
|
|
28838
29116
|
return;
|
|
@@ -29187,14 +29465,14 @@ var PiCodingAgentPlugin = (_class26 = class extends BasePlugin {constructor(...a
|
|
|
29187
29465
|
};
|
|
29188
29466
|
channel2.subscribe(handlers);
|
|
29189
29467
|
this.unsubscribers.push(() => {
|
|
29190
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
29468
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _816 => _816()]);
|
|
29191
29469
|
channel2.unsubscribe(handlers);
|
|
29192
29470
|
});
|
|
29193
29471
|
}
|
|
29194
29472
|
}, _class26);
|
|
29195
29473
|
function startPiPromptRun(event, onFinalize) {
|
|
29196
29474
|
const session = extractSession(event);
|
|
29197
|
-
const agent = _optionalChain([session, 'optionalAccess',
|
|
29475
|
+
const agent = _optionalChain([session, 'optionalAccess', _817 => _817.agent]);
|
|
29198
29476
|
if (!session || !isPiAgent(agent)) {
|
|
29199
29477
|
return void 0;
|
|
29200
29478
|
}
|
|
@@ -29202,8 +29480,8 @@ function startPiPromptRun(event, onFinalize) {
|
|
|
29202
29480
|
...extractSessionMetadata(session),
|
|
29203
29481
|
...extractPromptOptionsMetadata(event.arguments[1]),
|
|
29204
29482
|
"pi_coding_agent.operation": "AgentSession.prompt",
|
|
29205
|
-
provider: _nullishCoalesce(_nullishCoalesce(_optionalChain([session, 'access',
|
|
29206
|
-
..._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]))) } : {},
|
|
29207
29485
|
...event.moduleVersion ? { "pi_coding_agent.version": event.moduleVersion } : {}
|
|
29208
29486
|
};
|
|
29209
29487
|
const span = startSpan({
|
|
@@ -29222,7 +29500,7 @@ function startPiPromptRun(event, onFinalize) {
|
|
|
29222
29500
|
activeToolSpans: /* @__PURE__ */ new Map(),
|
|
29223
29501
|
agent,
|
|
29224
29502
|
collectedLlmUsageMetrics: false,
|
|
29225
|
-
deferCompletionUntilTurnEnd: _optionalChain([options, 'optionalAccess',
|
|
29503
|
+
deferCompletionUntilTurnEnd: _optionalChain([options, 'optionalAccess', _833 => _833.streamingBehavior]) === "followUp" || _optionalChain([options, 'optionalAccess', _834 => _834.streamingBehavior]) === "steer",
|
|
29226
29504
|
finalized: false,
|
|
29227
29505
|
metadata,
|
|
29228
29506
|
metrics: {},
|
|
@@ -29265,11 +29543,11 @@ function promptContextStore() {
|
|
|
29265
29543
|
return piPromptContextStore;
|
|
29266
29544
|
}
|
|
29267
29545
|
function currentPromptContextFrames() {
|
|
29268
|
-
return _nullishCoalesce(_optionalChain([promptContextStore, 'call',
|
|
29546
|
+
return _nullishCoalesce(_optionalChain([promptContextStore, 'call', _835 => _835(), 'access', _836 => _836.getStore, 'call', _837 => _837(), 'optionalAccess', _838 => _838.frames]), () => ( []));
|
|
29269
29547
|
}
|
|
29270
29548
|
function currentPiPromptState() {
|
|
29271
29549
|
const frames = currentPromptContextFrames();
|
|
29272
|
-
return _optionalChain([frames, 'access',
|
|
29550
|
+
return _optionalChain([frames, 'access', _839 => _839[frames.length - 1], 'optionalAccess', _840 => _840.state]);
|
|
29273
29551
|
}
|
|
29274
29552
|
function enterPiPromptContext(state) {
|
|
29275
29553
|
const frame = {
|
|
@@ -29599,7 +29877,7 @@ function finishPiToolSpan(state, event) {
|
|
|
29599
29877
|
try {
|
|
29600
29878
|
toolState.span.end();
|
|
29601
29879
|
} finally {
|
|
29602
|
-
_optionalChain([toolState, 'access',
|
|
29880
|
+
_optionalChain([toolState, 'access', _841 => _841.restoreAutoInstrumentation, 'optionalCall', _842 => _842()]);
|
|
29603
29881
|
}
|
|
29604
29882
|
}
|
|
29605
29883
|
}
|
|
@@ -29608,10 +29886,10 @@ async function finalizePiPromptRun(state, error) {
|
|
|
29608
29886
|
return;
|
|
29609
29887
|
}
|
|
29610
29888
|
state.finalized = true;
|
|
29611
|
-
_optionalChain([state, 'access',
|
|
29889
|
+
_optionalChain([state, 'access', _843 => _843.onFinalize, 'optionalCall', _844 => _844(state)]);
|
|
29612
29890
|
restorePiStreamFn(state);
|
|
29613
29891
|
try {
|
|
29614
|
-
_optionalChain([state, 'access',
|
|
29892
|
+
_optionalChain([state, 'access', _845 => _845.unsubscribeAgent, 'optionalCall', _846 => _846()]);
|
|
29615
29893
|
} catch (unsubscribeError) {
|
|
29616
29894
|
logInstrumentationError4("Pi Coding Agent unsubscribe", unsubscribeError);
|
|
29617
29895
|
}
|
|
@@ -29619,7 +29897,7 @@ async function finalizePiPromptRun(state, error) {
|
|
|
29619
29897
|
finishOpenToolSpans(state, error);
|
|
29620
29898
|
const metadata = {
|
|
29621
29899
|
...state.metadata,
|
|
29622
|
-
...extractModelMetadata2(_optionalChain([state, 'access',
|
|
29900
|
+
...extractModelMetadata2(_optionalChain([state, 'access', _847 => _847.agent, 'access', _848 => _848.state, 'optionalAccess', _849 => _849.model]))
|
|
29623
29901
|
};
|
|
29624
29902
|
try {
|
|
29625
29903
|
safeLog4(state.span, {
|
|
@@ -29642,7 +29920,7 @@ function restorePiStreamFn(state) {
|
|
|
29642
29920
|
if (patchState.eventPromptState === state) {
|
|
29643
29921
|
patchState.eventPromptState = void 0;
|
|
29644
29922
|
}
|
|
29645
|
-
_optionalChain([state, 'access',
|
|
29923
|
+
_optionalChain([state, 'access', _850 => _850.restorePromptContext, 'optionalCall', _851 => _851()]);
|
|
29646
29924
|
if (patchState.activePromptStates.size > 0) {
|
|
29647
29925
|
return;
|
|
29648
29926
|
}
|
|
@@ -29670,13 +29948,13 @@ function finishPiLlmSpan(promptState, llmState, message, error) {
|
|
|
29670
29948
|
}
|
|
29671
29949
|
llmState.finalized = true;
|
|
29672
29950
|
promptState.activeLlmSpans.delete(llmState);
|
|
29673
|
-
const messageError = _optionalChain([message, 'optionalAccess',
|
|
29951
|
+
const messageError = _optionalChain([message, 'optionalAccess', _852 => _852.stopReason]) === "error" && message.errorMessage;
|
|
29674
29952
|
const metrics = {
|
|
29675
|
-
...extractUsageMetrics2(_optionalChain([message, 'optionalAccess',
|
|
29953
|
+
...extractUsageMetrics2(_optionalChain([message, 'optionalAccess', _853 => _853.usage])),
|
|
29676
29954
|
...cleanMetrics5(llmState.metrics),
|
|
29677
29955
|
...buildDurationMetrics3(llmState.startTime)
|
|
29678
29956
|
};
|
|
29679
|
-
const usageMetrics = extractUsageMetrics2(_optionalChain([message, 'optionalAccess',
|
|
29957
|
+
const usageMetrics = extractUsageMetrics2(_optionalChain([message, 'optionalAccess', _854 => _854.usage]));
|
|
29680
29958
|
if (Object.keys(usageMetrics).length > 0) {
|
|
29681
29959
|
promptState.collectedLlmUsageMetrics = true;
|
|
29682
29960
|
addMetrics(promptState.metrics, usageMetrics);
|
|
@@ -29703,7 +29981,7 @@ function finishOpenToolSpans(state, error) {
|
|
|
29703
29981
|
});
|
|
29704
29982
|
toolState.span.end();
|
|
29705
29983
|
} finally {
|
|
29706
|
-
_optionalChain([toolState, 'access',
|
|
29984
|
+
_optionalChain([toolState, 'access', _855 => _855.restoreAutoInstrumentation, 'optionalCall', _856 => _856()]);
|
|
29707
29985
|
}
|
|
29708
29986
|
}
|
|
29709
29987
|
state.activeToolSpans.clear();
|
|
@@ -29815,7 +30093,7 @@ function normalizeStopReason(reason) {
|
|
|
29815
30093
|
}
|
|
29816
30094
|
}
|
|
29817
30095
|
function extractPromptInput(text, options) {
|
|
29818
|
-
const images = _optionalChain([options, 'optionalAccess',
|
|
30096
|
+
const images = _optionalChain([options, 'optionalAccess', _857 => _857.images]);
|
|
29819
30097
|
if (!images || images.length === 0) {
|
|
29820
30098
|
return text;
|
|
29821
30099
|
}
|
|
@@ -29970,7 +30248,7 @@ function stringifyArguments(value) {
|
|
|
29970
30248
|
}
|
|
29971
30249
|
try {
|
|
29972
30250
|
return JSON.stringify(value);
|
|
29973
|
-
} catch (
|
|
30251
|
+
} catch (e74) {
|
|
29974
30252
|
return stringifyUnknown(value);
|
|
29975
30253
|
}
|
|
29976
30254
|
}
|
|
@@ -29983,7 +30261,7 @@ function stringifyUnknown(value) {
|
|
|
29983
30261
|
}
|
|
29984
30262
|
try {
|
|
29985
30263
|
return JSON.stringify(value);
|
|
29986
|
-
} catch (
|
|
30264
|
+
} catch (e75) {
|
|
29987
30265
|
return String(value);
|
|
29988
30266
|
}
|
|
29989
30267
|
}
|
|
@@ -30081,7 +30359,7 @@ var StrandsAgentSDKPlugin = (_class27 = class extends BasePlugin {constructor(..
|
|
|
30081
30359
|
};
|
|
30082
30360
|
channel2.subscribe(handlers);
|
|
30083
30361
|
this.unsubscribers.push(() => {
|
|
30084
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
30362
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _858 => _858()]);
|
|
30085
30363
|
channel2.unsubscribe(handlers);
|
|
30086
30364
|
});
|
|
30087
30365
|
}
|
|
@@ -30144,14 +30422,14 @@ var StrandsAgentSDKPlugin = (_class27 = class extends BasePlugin {constructor(..
|
|
|
30144
30422
|
};
|
|
30145
30423
|
tracingChannel2.subscribe(handlers);
|
|
30146
30424
|
this.unsubscribers.push(() => {
|
|
30147
|
-
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall',
|
|
30425
|
+
_optionalChain([unbindAutoInstrumentationSuppression, 'optionalCall', _859 => _859()]);
|
|
30148
30426
|
tracingChannel2.unsubscribe(handlers);
|
|
30149
30427
|
});
|
|
30150
30428
|
}
|
|
30151
30429
|
}, _class27);
|
|
30152
30430
|
function startAgentStream(event, activeChildParents) {
|
|
30153
30431
|
const agent = extractAgent(event);
|
|
30154
|
-
const model = _optionalChain([agent, 'optionalAccess',
|
|
30432
|
+
const model = _optionalChain([agent, 'optionalAccess', _860 => _860.model]);
|
|
30155
30433
|
const metadata = {
|
|
30156
30434
|
...extractAgentMetadata2(agent),
|
|
30157
30435
|
...extractModelMetadata3(model),
|
|
@@ -30197,7 +30475,7 @@ function startMultiAgentStream(event, operation, activeChildParents) {
|
|
|
30197
30475
|
const metadata = {
|
|
30198
30476
|
"strands.operation": operation,
|
|
30199
30477
|
provider: "strands",
|
|
30200
|
-
..._optionalChain([orchestrator, 'optionalAccess',
|
|
30478
|
+
..._optionalChain([orchestrator, 'optionalAccess', _861 => _861.id]) ? { "strands.orchestrator.id": orchestrator.id } : {},
|
|
30201
30479
|
...event.moduleVersion ? { "strands_agent_sdk.version": event.moduleVersion } : {}
|
|
30202
30480
|
};
|
|
30203
30481
|
const parentSpan = orchestrator ? getOnlyChildParent(activeChildParents, orchestrator) : void 0;
|
|
@@ -30260,7 +30538,7 @@ function handleAgentStreamEvent(state, event) {
|
|
|
30260
30538
|
},
|
|
30261
30539
|
metrics: {
|
|
30262
30540
|
...buildDurationMetrics4(state.startTime),
|
|
30263
|
-
...parseUsage(_optionalChain([event, 'access',
|
|
30541
|
+
...parseUsage(_optionalChain([event, 'access', _862 => _862.result, 'optionalAccess', _863 => _863.metrics, 'optionalAccess', _864 => _864.accumulatedUsage]))
|
|
30264
30542
|
},
|
|
30265
30543
|
output: extractAgentResultOutput(event.result)
|
|
30266
30544
|
});
|
|
@@ -30296,7 +30574,7 @@ function handleMultiAgentStreamEvent(state, event, activeChildParents) {
|
|
|
30296
30574
|
},
|
|
30297
30575
|
metrics: {
|
|
30298
30576
|
...buildDurationMetrics4(state.startTime),
|
|
30299
|
-
...parseUsage(_optionalChain([event, 'access',
|
|
30577
|
+
...parseUsage(_optionalChain([event, 'access', _865 => _865.result, 'optionalAccess', _866 => _866.usage]))
|
|
30300
30578
|
},
|
|
30301
30579
|
output: extractMultiAgentResultOutput(event.result)
|
|
30302
30580
|
});
|
|
@@ -30312,7 +30590,7 @@ function startModelSpan(state, event) {
|
|
|
30312
30590
|
if (state.activeModel) {
|
|
30313
30591
|
finalizeModelSpan(state);
|
|
30314
30592
|
}
|
|
30315
|
-
const model = _nullishCoalesce(event.model, () => ( _optionalChain([event, 'access',
|
|
30593
|
+
const model = _nullishCoalesce(event.model, () => ( _optionalChain([event, 'access', _867 => _867.agent, 'optionalAccess', _868 => _868.model])));
|
|
30316
30594
|
const metadata = {
|
|
30317
30595
|
...extractModelMetadata3(model),
|
|
30318
30596
|
"strands.operation": "model.stream",
|
|
@@ -30323,7 +30601,7 @@ function startModelSpan(state, event) {
|
|
|
30323
30601
|
state.span,
|
|
30324
30602
|
() => startSpan({
|
|
30325
30603
|
event: {
|
|
30326
|
-
input: Array.isArray(_optionalChain([event, 'access',
|
|
30604
|
+
input: Array.isArray(_optionalChain([event, 'access', _869 => _869.agent, 'optionalAccess', _870 => _870.messages])) ? processStrandsInputAttachments(
|
|
30327
30605
|
event.agent.messages,
|
|
30328
30606
|
state.attachmentCache
|
|
30329
30607
|
) : void 0,
|
|
@@ -30341,7 +30619,7 @@ function startModelSpan(state, event) {
|
|
|
30341
30619
|
};
|
|
30342
30620
|
}
|
|
30343
30621
|
function collectModelStreamMetadata(state, event) {
|
|
30344
|
-
if (!state.activeModel || _optionalChain([event, 'access',
|
|
30622
|
+
if (!state.activeModel || _optionalChain([event, 'access', _871 => _871.event, 'optionalAccess', _872 => _872.type]) !== "modelMetadataEvent") {
|
|
30345
30623
|
return;
|
|
30346
30624
|
}
|
|
30347
30625
|
Object.assign(state.activeModel.metrics, parseUsage(event.event.usage));
|
|
@@ -30358,18 +30636,18 @@ function finalizeModelSpan(state, event) {
|
|
|
30358
30636
|
state.activeModel = void 0;
|
|
30359
30637
|
const metadata = {
|
|
30360
30638
|
...modelState.metadata,
|
|
30361
|
-
..._optionalChain([event, 'optionalAccess',
|
|
30362
|
-
..._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 } : {}
|
|
30363
30641
|
};
|
|
30364
30642
|
const metrics = {
|
|
30365
30643
|
...buildDurationMetrics4(modelState.startTime),
|
|
30366
30644
|
...modelState.metrics
|
|
30367
30645
|
};
|
|
30368
30646
|
safeLog5(modelState.span, {
|
|
30369
|
-
..._optionalChain([event, 'optionalAccess',
|
|
30647
|
+
..._optionalChain([event, 'optionalAccess', _876 => _876.error]) ? { error: toLoggedError(event.error) } : {},
|
|
30370
30648
|
metadata,
|
|
30371
30649
|
metrics: cleanMetrics6(metrics),
|
|
30372
|
-
output: _optionalChain([event, 'optionalAccess',
|
|
30650
|
+
output: _optionalChain([event, 'optionalAccess', _877 => _877.stopData, 'optionalAccess', _878 => _878.message])
|
|
30373
30651
|
});
|
|
30374
30652
|
modelState.span.end();
|
|
30375
30653
|
}
|
|
@@ -30385,9 +30663,9 @@ function startToolSpan2(state, event) {
|
|
|
30385
30663
|
state.span,
|
|
30386
30664
|
() => startSpan({
|
|
30387
30665
|
event: {
|
|
30388
|
-
input: _optionalChain([toolUse, 'optionalAccess',
|
|
30666
|
+
input: _optionalChain([toolUse, 'optionalAccess', _879 => _879.input]),
|
|
30389
30667
|
metadata: {
|
|
30390
|
-
"gen_ai.tool.call.id": _optionalChain([toolUse, 'optionalAccess',
|
|
30668
|
+
"gen_ai.tool.call.id": _optionalChain([toolUse, 'optionalAccess', _880 => _880.toolUseId]),
|
|
30391
30669
|
"gen_ai.tool.name": name,
|
|
30392
30670
|
"strands.operation": "tool.call",
|
|
30393
30671
|
"strands.tool.name": name,
|
|
@@ -30440,8 +30718,8 @@ function finalizeToolSpanState(toolState, data = {}) {
|
|
|
30440
30718
|
safeLog5(toolState.span, {
|
|
30441
30719
|
...data.error ? { error: toLoggedError(data.error) } : {},
|
|
30442
30720
|
metadata: {
|
|
30443
|
-
..._nullishCoalesce(_optionalChain([data, 'access',
|
|
30444
|
-
"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])))
|
|
30445
30723
|
} : {},
|
|
30446
30724
|
...extractToolName3(_nullishCoalesce(data.toolUse, () => ( toolState.toolUse))) ? {
|
|
30447
30725
|
"gen_ai.tool.name": extractToolName3(
|
|
@@ -30461,7 +30739,7 @@ function startNodeSpan(state, event, activeChildParents) {
|
|
|
30461
30739
|
const child = extractNodeChild(node);
|
|
30462
30740
|
const metadata = {
|
|
30463
30741
|
"strands.node.id": nodeId,
|
|
30464
|
-
..._optionalChain([node, 'optionalAccess',
|
|
30742
|
+
..._optionalChain([node, 'optionalAccess', _889 => _889.type]) ? { "strands.node.type": node.type } : {},
|
|
30465
30743
|
"strands.operation": "node.call",
|
|
30466
30744
|
provider: "strands"
|
|
30467
30745
|
};
|
|
@@ -30484,21 +30762,21 @@ function startNodeSpan(state, event, activeChildParents) {
|
|
|
30484
30762
|
}
|
|
30485
30763
|
}
|
|
30486
30764
|
function logNodeResult(state, event) {
|
|
30487
|
-
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"));
|
|
30488
30766
|
const nodeState = state.activeNodes.get(nodeId);
|
|
30489
30767
|
if (!nodeState) {
|
|
30490
30768
|
return;
|
|
30491
30769
|
}
|
|
30492
30770
|
safeLog5(nodeState.span, {
|
|
30493
|
-
..._optionalChain([event, 'access',
|
|
30771
|
+
..._optionalChain([event, 'access', _892 => _892.result, 'optionalAccess', _893 => _893.error]) ? { error: toLoggedError(event.result.error) } : {},
|
|
30494
30772
|
metadata: {
|
|
30495
30773
|
...event.nodeType ? { "strands.node.type": event.nodeType } : {},
|
|
30496
|
-
..._optionalChain([event, 'access',
|
|
30774
|
+
..._optionalChain([event, 'access', _894 => _894.result, 'optionalAccess', _895 => _895.status]) ? { "strands.node.status": event.result.status } : {}
|
|
30497
30775
|
},
|
|
30498
30776
|
metrics: {
|
|
30499
30777
|
...buildDurationMetrics4(nodeState.startTime),
|
|
30500
|
-
...typeof _optionalChain([event, 'access',
|
|
30501
|
-
...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]))
|
|
30502
30780
|
},
|
|
30503
30781
|
output: extractNodeResultOutput(event.result)
|
|
30504
30782
|
});
|
|
@@ -30571,9 +30849,9 @@ function extractOrchestrator(event) {
|
|
|
30571
30849
|
}
|
|
30572
30850
|
function extractAgentMetadata2(agent) {
|
|
30573
30851
|
return {
|
|
30574
|
-
..._optionalChain([agent, 'optionalAccess',
|
|
30575
|
-
..._optionalChain([agent, 'optionalAccess',
|
|
30576
|
-
..._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 } : {}
|
|
30577
30855
|
};
|
|
30578
30856
|
}
|
|
30579
30857
|
function extractModelMetadata3(model) {
|
|
@@ -30581,28 +30859,28 @@ function extractModelMetadata3(model) {
|
|
|
30581
30859
|
const modelName2 = extractModelName2(model);
|
|
30582
30860
|
return {
|
|
30583
30861
|
...modelName2 ? { model: modelName2 } : {},
|
|
30584
|
-
..._optionalChain([config, 'optionalAccess',
|
|
30585
|
-
..._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 } : {}
|
|
30586
30864
|
};
|
|
30587
30865
|
}
|
|
30588
30866
|
function extractAgentResultMetadata(result) {
|
|
30589
30867
|
return {
|
|
30590
|
-
..._optionalChain([result, 'optionalAccess',
|
|
30591
|
-
...typeof _optionalChain([result, 'optionalAccess',
|
|
30592
|
-
...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" ? {
|
|
30593
30871
|
"strands.projected_context_size": result.metrics.projectedContextSize
|
|
30594
30872
|
} : {}
|
|
30595
30873
|
};
|
|
30596
30874
|
}
|
|
30597
30875
|
function extractMultiAgentResultMetadata(result) {
|
|
30598
30876
|
return {
|
|
30599
|
-
..._optionalChain([result, 'optionalAccess',
|
|
30600
|
-
...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 } : {}
|
|
30601
30879
|
};
|
|
30602
30880
|
}
|
|
30603
30881
|
function extractProvider(model) {
|
|
30604
30882
|
const config = getModelConfig(model);
|
|
30605
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30883
|
+
if (typeof _optionalChain([config, 'optionalAccess', _912 => _912.provider]) === "string") {
|
|
30606
30884
|
return config.provider;
|
|
30607
30885
|
}
|
|
30608
30886
|
const constructorName = getConstructorName(model).toLowerCase();
|
|
@@ -30625,13 +30903,13 @@ function extractProvider(model) {
|
|
|
30625
30903
|
}
|
|
30626
30904
|
function extractModelName2(model) {
|
|
30627
30905
|
const config = getModelConfig(model);
|
|
30628
|
-
if (typeof _optionalChain([model, 'optionalAccess',
|
|
30906
|
+
if (typeof _optionalChain([model, 'optionalAccess', _913 => _913.modelId]) === "string") {
|
|
30629
30907
|
return model.modelId;
|
|
30630
30908
|
}
|
|
30631
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30909
|
+
if (typeof _optionalChain([config, 'optionalAccess', _914 => _914.modelId]) === "string") {
|
|
30632
30910
|
return config.modelId;
|
|
30633
30911
|
}
|
|
30634
|
-
if (typeof _optionalChain([config, 'optionalAccess',
|
|
30912
|
+
if (typeof _optionalChain([config, 'optionalAccess', _915 => _915.model]) === "string") {
|
|
30635
30913
|
return config.model;
|
|
30636
30914
|
}
|
|
30637
30915
|
return void 0;
|
|
@@ -30648,7 +30926,7 @@ function getModelConfig(model) {
|
|
|
30648
30926
|
}
|
|
30649
30927
|
}
|
|
30650
30928
|
function formatAgentSpanName(agent) {
|
|
30651
|
-
return _optionalChain([agent, 'optionalAccess',
|
|
30929
|
+
return _optionalChain([agent, 'optionalAccess', _916 => _916.name]) ? `Agent: ${agent.name}` : "Strands Agent";
|
|
30652
30930
|
}
|
|
30653
30931
|
function formatModelSpanName(model) {
|
|
30654
30932
|
const modelName2 = extractModelName2(model);
|
|
@@ -30825,7 +31103,7 @@ function createStrandsMediaAttachment(mediaKey, media, cache) {
|
|
|
30825
31103
|
function getOrCreateStrandsAttachment(data, filename, contentType, cache) {
|
|
30826
31104
|
const key = `${contentType}\0${filename}`;
|
|
30827
31105
|
const attachments = typeof data === "string" ? cache.strings.get(data) : isObject(data) ? cache.objects.get(data) : void 0;
|
|
30828
|
-
const cached = _optionalChain([attachments, 'optionalAccess',
|
|
31106
|
+
const cached = _optionalChain([attachments, 'optionalAccess', _917 => _917.get, 'call', _918 => _918(key)]);
|
|
30829
31107
|
if (cached) {
|
|
30830
31108
|
return cached;
|
|
30831
31109
|
}
|
|
@@ -30853,24 +31131,24 @@ function normalizeContentBlocks(blocks) {
|
|
|
30853
31131
|
}
|
|
30854
31132
|
function parseUsage(usage) {
|
|
30855
31133
|
const metrics = {};
|
|
30856
|
-
assignMetric(metrics, "prompt_tokens", _optionalChain([usage, 'optionalAccess',
|
|
30857
|
-
assignMetric(metrics, "completion_tokens", _optionalChain([usage, 'optionalAccess',
|
|
30858
|
-
assignMetric(metrics, "tokens", _optionalChain([usage, 'optionalAccess',
|
|
30859
|
-
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]));
|
|
30860
31138
|
assignMetric(
|
|
30861
31139
|
metrics,
|
|
30862
31140
|
"prompt_cache_creation_tokens",
|
|
30863
|
-
_optionalChain([usage, 'optionalAccess',
|
|
31141
|
+
_optionalChain([usage, 'optionalAccess', _923 => _923.cacheWriteInputTokens])
|
|
30864
31142
|
);
|
|
30865
31143
|
return metrics;
|
|
30866
31144
|
}
|
|
30867
31145
|
function parseModelMetrics(metrics) {
|
|
30868
31146
|
const parsed = {};
|
|
30869
|
-
assignMetric(parsed, "strands.latency_ms", _optionalChain([metrics, 'optionalAccess',
|
|
31147
|
+
assignMetric(parsed, "strands.latency_ms", _optionalChain([metrics, 'optionalAccess', _924 => _924.latencyMs]));
|
|
30870
31148
|
assignMetric(
|
|
30871
31149
|
parsed,
|
|
30872
31150
|
"strands.time_to_first_byte_ms",
|
|
30873
|
-
_optionalChain([metrics, 'optionalAccess',
|
|
31151
|
+
_optionalChain([metrics, 'optionalAccess', _925 => _925.timeToFirstByteMs])
|
|
30874
31152
|
);
|
|
30875
31153
|
return parsed;
|
|
30876
31154
|
}
|
|
@@ -30897,20 +31175,20 @@ function cleanMetrics6(metrics) {
|
|
|
30897
31175
|
return cleaned;
|
|
30898
31176
|
}
|
|
30899
31177
|
function extractToolName3(toolUse, tool) {
|
|
30900
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess',
|
|
31178
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess', _926 => _926.name]), () => ( _optionalChain([tool, 'optionalAccess', _927 => _927.name]))), () => ( "unknown"));
|
|
30901
31179
|
}
|
|
30902
31180
|
function toolKey2(toolUse) {
|
|
30903
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess',
|
|
31181
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([toolUse, 'optionalAccess', _928 => _928.toolUseId]), () => ( _optionalChain([toolUse, 'optionalAccess', _929 => _929.name]))), () => ( "unknown"));
|
|
30904
31182
|
}
|
|
30905
31183
|
function findNode(orchestrator, nodeId) {
|
|
30906
31184
|
try {
|
|
30907
|
-
return _optionalChain([orchestrator, 'optionalAccess',
|
|
30908
|
-
} catch (
|
|
31185
|
+
return _optionalChain([orchestrator, 'optionalAccess', _930 => _930.nodes, 'optionalAccess', _931 => _931.get, 'call', _932 => _932(nodeId)]);
|
|
31186
|
+
} catch (e76) {
|
|
30909
31187
|
return void 0;
|
|
30910
31188
|
}
|
|
30911
31189
|
}
|
|
30912
31190
|
function extractNodeChild(node) {
|
|
30913
|
-
const child = _nullishCoalesce(_optionalChain([node, 'optionalAccess',
|
|
31191
|
+
const child = _nullishCoalesce(_optionalChain([node, 'optionalAccess', _933 => _933.agent]), () => ( _optionalChain([node, 'optionalAccess', _934 => _934.orchestrator])));
|
|
30914
31192
|
return isObject(child) ? child : void 0;
|
|
30915
31193
|
}
|
|
30916
31194
|
function pushChildParent(activeChildParents, child, span) {
|
|
@@ -31288,7 +31566,7 @@ function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
|
31288
31566
|
return { integrations };
|
|
31289
31567
|
}
|
|
31290
31568
|
function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
31291
|
-
return names.some((name) => _optionalChain([integrations, 'optionalAccess',
|
|
31569
|
+
return names.some((name) => _optionalChain([integrations, 'optionalAccess', _935 => _935[name]]) === false);
|
|
31292
31570
|
}
|
|
31293
31571
|
|
|
31294
31572
|
// src/instrumentation/registry.ts
|
|
@@ -31670,11 +31948,17 @@ function configureNode() {
|
|
|
31670
31948
|
isomorph_default.getPastNAncestors = getPastNAncestors;
|
|
31671
31949
|
isomorph_default.getEnv = (name) => {
|
|
31672
31950
|
const value = process.env[name];
|
|
31673
|
-
|
|
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;
|
|
31674
31958
|
};
|
|
31675
31959
|
isomorph_default.getBraintrustApiKey = async () => {
|
|
31676
31960
|
const value = process.env.BRAINTRUST_API_KEY;
|
|
31677
|
-
if (_optionalChain([value, 'optionalAccess',
|
|
31961
|
+
if (_optionalChain([value, 'optionalAccess', _940 => _940.trim, 'call', _941 => _941()])) {
|
|
31678
31962
|
return value;
|
|
31679
31963
|
}
|
|
31680
31964
|
const envPaths = [];
|
|
@@ -31705,7 +31989,7 @@ function configureNode() {
|
|
|
31705
31989
|
if ("contents" in nearestResult) {
|
|
31706
31990
|
const parsed = dotenv.parse(nearestResult.contents);
|
|
31707
31991
|
const apiKey = parsed.BRAINTRUST_API_KEY;
|
|
31708
|
-
return _optionalChain([apiKey, 'optionalAccess',
|
|
31992
|
+
return _optionalChain([apiKey, 'optionalAccess', _942 => _942.trim, 'call', _943 => _943()]) ? apiKey : void 0;
|
|
31709
31993
|
}
|
|
31710
31994
|
const e = nearestResult.error;
|
|
31711
31995
|
if (typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT") {
|
|
@@ -31755,6 +32039,24 @@ function configureNode() {
|
|
|
31755
32039
|
}
|
|
31756
32040
|
registry.enable();
|
|
31757
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
|
+
}
|
|
31758
32060
|
|
|
31759
32061
|
// dev/server.ts
|
|
31760
32062
|
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
@@ -32899,6 +33201,10 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
|
|
|
32899
33201
|
this._state = _state;
|
|
32900
33202
|
this.spanTypeFilter = spanTypeFilter;
|
|
32901
33203
|
}
|
|
33204
|
+
|
|
33205
|
+
|
|
33206
|
+
|
|
33207
|
+
|
|
32902
33208
|
static buildFilter(rootSpanId, spanTypeFilter, includeScorers = false) {
|
|
32903
33209
|
const children = [
|
|
32904
33210
|
// Base filter: root_span_id = 'value'
|
|
@@ -33011,7 +33317,7 @@ var CachedSpanFetcher = (_class31 = class {
|
|
|
33011
33317
|
async fetchSpans(spanType) {
|
|
33012
33318
|
const spans = await this.fetchFn(spanType, false);
|
|
33013
33319
|
for (const span of spans) {
|
|
33014
|
-
const type = _nullishCoalesce(_optionalChain([span, 'access',
|
|
33320
|
+
const type = _nullishCoalesce(_optionalChain([span, 'access', _946 => _946.span_attributes, 'optionalAccess', _947 => _947.type]), () => ( ""));
|
|
33015
33321
|
const existing = _nullishCoalesce(this.spanCache.get(type), () => ( []));
|
|
33016
33322
|
existing.push(span);
|
|
33017
33323
|
this.spanCache.set(type, existing);
|
|
@@ -33094,11 +33400,11 @@ var LocalTrace = (_class32 = class {
|
|
|
33094
33400
|
const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
|
|
33095
33401
|
if (cachedSpans && cachedSpans.length > 0) {
|
|
33096
33402
|
let spans = includeScorers ? cachedSpans : cachedSpans.filter(
|
|
33097
|
-
(span) => _optionalChain([span, 'access',
|
|
33403
|
+
(span) => _optionalChain([span, 'access', _948 => _948.span_attributes, 'optionalAccess', _949 => _949.purpose]) !== "scorer"
|
|
33098
33404
|
);
|
|
33099
33405
|
if (spanType && spanType.length > 0) {
|
|
33100
33406
|
spans = spans.filter(
|
|
33101
|
-
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access',
|
|
33407
|
+
(span) => spanType.includes(_nullishCoalesce(_optionalChain([span, 'access', _950 => _950.span_attributes, 'optionalAccess', _951 => _951.type]), () => ( "")))
|
|
33102
33408
|
);
|
|
33103
33409
|
}
|
|
33104
33410
|
return spans.map((span) => ({
|
|
@@ -33123,7 +33429,7 @@ var LocalTrace = (_class32 = class {
|
|
|
33123
33429
|
* Calls the API with the project_default preprocessor (which falls back to "thread").
|
|
33124
33430
|
*/
|
|
33125
33431
|
async getThread(options) {
|
|
33126
|
-
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
33432
|
+
const cacheKey = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _952 => _952.preprocessor]), () => ( "project_default"));
|
|
33127
33433
|
if (!this.threadCache.has(cacheKey)) {
|
|
33128
33434
|
const promise = this.fetchThread(options);
|
|
33129
33435
|
this.threadCache.set(cacheKey, promise);
|
|
@@ -33134,7 +33440,7 @@ var LocalTrace = (_class32 = class {
|
|
|
33134
33440
|
await this.ensureSpansReady();
|
|
33135
33441
|
await this.state.login({});
|
|
33136
33442
|
const result = await invoke({
|
|
33137
|
-
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
33443
|
+
globalFunction: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _953 => _953.preprocessor]), () => ( "project_default")),
|
|
33138
33444
|
functionType: "preprocessor",
|
|
33139
33445
|
input: {
|
|
33140
33446
|
trace_ref: {
|
|
@@ -33310,10 +33616,10 @@ function validateParametersWithJsonSchema(parameters, schema) {
|
|
|
33310
33616
|
const ajv = new (0, _ajv2.default)({ coerceTypes: true, useDefaults: true, strict: false });
|
|
33311
33617
|
const validate = ajv.compile(schema);
|
|
33312
33618
|
if (!validate(parameters)) {
|
|
33313
|
-
const errorMessages = _optionalChain([validate, 'access',
|
|
33619
|
+
const errorMessages = _optionalChain([validate, 'access', _954 => _954.errors, 'optionalAccess', _955 => _955.map, 'call', _956 => _956((err) => {
|
|
33314
33620
|
const path2 = err.instancePath || "root";
|
|
33315
33621
|
return `${path2}: ${err.message}`;
|
|
33316
|
-
}), 'access',
|
|
33622
|
+
}), 'access', _957 => _957.join, 'call', _958 => _958(", ")]);
|
|
33317
33623
|
throw Error(`Invalid parameters: ${errorMessages}`);
|
|
33318
33624
|
}
|
|
33319
33625
|
return rehydrateRemoteParameters(parameters, schema);
|
|
@@ -33346,6 +33652,8 @@ var EvalResultWithSummary = class {
|
|
|
33346
33652
|
this.summary = summary;
|
|
33347
33653
|
this.results = results;
|
|
33348
33654
|
}
|
|
33655
|
+
|
|
33656
|
+
|
|
33349
33657
|
/**
|
|
33350
33658
|
* @deprecated Use `summary` instead.
|
|
33351
33659
|
*/
|
|
@@ -33365,7 +33673,7 @@ var EvalResultWithSummary = class {
|
|
|
33365
33673
|
async function getPersistedBaseExperimentId(experiment) {
|
|
33366
33674
|
try {
|
|
33367
33675
|
return await experiment._getBaseExperimentId();
|
|
33368
|
-
} catch (
|
|
33676
|
+
} catch (e77) {
|
|
33369
33677
|
return void 0;
|
|
33370
33678
|
}
|
|
33371
33679
|
}
|
|
@@ -33660,7 +33968,7 @@ async function runEvaluator(experiment, evaluator, progressReporter, filters, st
|
|
|
33660
33968
|
}
|
|
33661
33969
|
async function runEvaluatorInternal(experiment, evaluator, progressReporter, filters, stream, parameters, collectResults, enableCache) {
|
|
33662
33970
|
if (enableCache) {
|
|
33663
|
-
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
33971
|
+
_optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess', _959 => _959.spanCache, 'optionalAccess', _960 => _960.start, 'call', _961 => _961()]);
|
|
33664
33972
|
}
|
|
33665
33973
|
try {
|
|
33666
33974
|
if (typeof evaluator.data === "string") {
|
|
@@ -33715,7 +34023,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33715
34023
|
const experimentIdPromise = experiment ? (async () => {
|
|
33716
34024
|
try {
|
|
33717
34025
|
return await experiment.id;
|
|
33718
|
-
} catch (
|
|
34026
|
+
} catch (e78) {
|
|
33719
34027
|
return void 0;
|
|
33720
34028
|
}
|
|
33721
34029
|
})() : void 0;
|
|
@@ -33740,7 +34048,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33740
34048
|
_xact_id: datum._xact_id
|
|
33741
34049
|
} : void 0;
|
|
33742
34050
|
const parsedDatumOrigin = ObjectReference.safeParse(datum.origin);
|
|
33743
|
-
const origin = _nullishCoalesce(inlineDatasetOrigin, () => ( (_optionalChain([parsedDatumOrigin, 'optionalAccess',
|
|
34051
|
+
const origin = _nullishCoalesce(inlineDatasetOrigin, () => ( (_optionalChain([parsedDatumOrigin, 'optionalAccess', _962 => _962.success]) ? parsedDatumOrigin.data : void 0)));
|
|
33744
34052
|
const baseEvent = {
|
|
33745
34053
|
name: "eval",
|
|
33746
34054
|
spanAttributes: {
|
|
@@ -33774,7 +34082,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33774
34082
|
objectType: parentComponents ? spanObjectTypeV3ToTypedString(
|
|
33775
34083
|
parentComponents.data.object_type
|
|
33776
34084
|
) : "experiment",
|
|
33777
|
-
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 () => ( "")) : ""))),
|
|
33778
34086
|
rootSpanId: rootSpan.rootSpanId,
|
|
33779
34087
|
ensureSpansFlushed,
|
|
33780
34088
|
state
|
|
@@ -33804,10 +34112,10 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33804
34112
|
span,
|
|
33805
34113
|
parameters: _nullishCoalesce(parameters, () => ( {})),
|
|
33806
34114
|
reportProgress: (event) => {
|
|
33807
|
-
_optionalChain([stream, 'optionalCall',
|
|
34115
|
+
_optionalChain([stream, 'optionalCall', _965 => _965({
|
|
33808
34116
|
...event,
|
|
33809
34117
|
id: rootSpan.id,
|
|
33810
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
34118
|
+
origin: _optionalChain([baseEvent, 'access', _966 => _966.event, 'optionalAccess', _967 => _967.origin]),
|
|
33811
34119
|
name: evaluator.evalName,
|
|
33812
34120
|
object_type: "task"
|
|
33813
34121
|
})]);
|
|
@@ -33995,7 +34303,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
33995
34303
|
tags: tags.length ? tags : void 0,
|
|
33996
34304
|
metadata,
|
|
33997
34305
|
error,
|
|
33998
|
-
origin: _optionalChain([baseEvent, 'access',
|
|
34306
|
+
origin: _optionalChain([baseEvent, 'access', _968 => _968.event, 'optionalAccess', _969 => _969.origin])
|
|
33999
34307
|
};
|
|
34000
34308
|
collectedResults.push({
|
|
34001
34309
|
...baseResult,
|
|
@@ -34035,7 +34343,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
34035
34343
|
break;
|
|
34036
34344
|
}
|
|
34037
34345
|
scheduledTrials++;
|
|
34038
|
-
_optionalChain([progressReporter, 'access',
|
|
34346
|
+
_optionalChain([progressReporter, 'access', _970 => _970.setTotal, 'optionalCall', _971 => _971(evaluator.evalName, scheduledTrials)]);
|
|
34039
34347
|
q.pushAsync({ datum, trialIndex }).catch((e) => {
|
|
34040
34348
|
if (queueErrors.length < 5) {
|
|
34041
34349
|
queueErrors.push(e);
|
|
@@ -34122,9 +34430,9 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
|
|
|
34122
34430
|
);
|
|
34123
34431
|
} finally {
|
|
34124
34432
|
if (enableCache) {
|
|
34125
|
-
const spanCache = _optionalChain([(_nullishCoalesce(evaluator.state, () => ( _internalGetGlobalState()))), 'optionalAccess',
|
|
34126
|
-
_optionalChain([spanCache, 'optionalAccess',
|
|
34127
|
-
_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()]);
|
|
34128
34436
|
}
|
|
34129
34437
|
}
|
|
34130
34438
|
}
|
|
@@ -34364,7 +34672,7 @@ async function cachedLogin(options) {
|
|
|
34364
34672
|
}
|
|
34365
34673
|
function makeCheckAuthorized(allowedOrgName) {
|
|
34366
34674
|
return async (req, _res, next) => {
|
|
34367
|
-
if (!_optionalChain([req, 'access',
|
|
34675
|
+
if (!_optionalChain([req, 'access', _977 => _977.ctx, 'optionalAccess', _978 => _978.token])) {
|
|
34368
34676
|
return next(_httperrors2.default.call(void 0, 401, "Unauthorized"));
|
|
34369
34677
|
}
|
|
34370
34678
|
try {
|
|
@@ -34377,7 +34685,7 @@ function makeCheckAuthorized(allowedOrgName) {
|
|
|
34377
34685
|
return next(_httperrors2.default.call(void 0, 403, errorMessage2));
|
|
34378
34686
|
}
|
|
34379
34687
|
const state = await cachedLogin({
|
|
34380
|
-
apiKey: _optionalChain([req, 'access',
|
|
34688
|
+
apiKey: _optionalChain([req, 'access', _979 => _979.ctx, 'optionalAccess', _980 => _980.token]),
|
|
34381
34689
|
orgName
|
|
34382
34690
|
});
|
|
34383
34691
|
req.ctx.state = state;
|
|
@@ -34638,6 +34946,7 @@ var ToolBuilder = (_class34 = class {
|
|
|
34638
34946
|
constructor(project) {;_class34.prototype.__init125.call(this);
|
|
34639
34947
|
this.project = project;
|
|
34640
34948
|
}
|
|
34949
|
+
|
|
34641
34950
|
__init125() {this.taskCounter = 0}
|
|
34642
34951
|
// This type definition is just a catch all so that the implementation can be
|
|
34643
34952
|
// less specific than the two more specific declarations above.
|
|
@@ -34668,6 +34977,7 @@ var ScorerBuilder = (_class35 = class {
|
|
|
34668
34977
|
constructor(project) {;_class35.prototype.__init126.call(this);
|
|
34669
34978
|
this.project = project;
|
|
34670
34979
|
}
|
|
34980
|
+
|
|
34671
34981
|
__init126() {this.taskCounter = 0}
|
|
34672
34982
|
create(opts) {
|
|
34673
34983
|
this.taskCounter++;
|
|
@@ -34727,6 +35037,7 @@ var ClassifierBuilder = (_class36 = class {
|
|
|
34727
35037
|
constructor(project) {;_class36.prototype.__init127.call(this);
|
|
34728
35038
|
this.project = project;
|
|
34729
35039
|
}
|
|
35040
|
+
|
|
34730
35041
|
__init127() {this.taskCounter = 0}
|
|
34731
35042
|
create(opts) {
|
|
34732
35043
|
this.taskCounter++;
|
|
@@ -34772,6 +35083,7 @@ var CodeFunction = class {
|
|
|
34772
35083
|
|
|
34773
35084
|
|
|
34774
35085
|
|
|
35086
|
+
|
|
34775
35087
|
key() {
|
|
34776
35088
|
return JSON.stringify([
|
|
34777
35089
|
_nullishCoalesce(this.project.id, () => ( "")),
|
|
@@ -34849,6 +35161,7 @@ var PromptBuilder = class {
|
|
|
34849
35161
|
constructor(project) {
|
|
34850
35162
|
this.project = project;
|
|
34851
35163
|
}
|
|
35164
|
+
|
|
34852
35165
|
create(opts) {
|
|
34853
35166
|
const toolFunctions = [];
|
|
34854
35167
|
const rawTools = [];
|
|
@@ -34925,6 +35238,7 @@ var ParametersBuilder = class {
|
|
|
34925
35238
|
constructor(project) {
|
|
34926
35239
|
this.project = project;
|
|
34927
35240
|
}
|
|
35241
|
+
|
|
34928
35242
|
create(opts) {
|
|
34929
35243
|
const slug = _nullishCoalesce(opts.slug, () => ( slugify(opts.name, { lower: true, strict: true })));
|
|
34930
35244
|
const codeParameters = new CodeParameters(this.project, {
|
|
@@ -35156,7 +35470,7 @@ function runDevServer(evaluators, opts) {
|
|
|
35156
35470
|
scores,
|
|
35157
35471
|
stream
|
|
35158
35472
|
} = evalBodySchema.parse(req.body);
|
|
35159
|
-
if (!_optionalChain([req, 'access',
|
|
35473
|
+
if (!_optionalChain([req, 'access', _981 => _981.ctx, 'optionalAccess', _982 => _982.state])) {
|
|
35160
35474
|
res.status(500).json({ error: "Braintrust state not initialized in request" });
|
|
35161
35475
|
return;
|
|
35162
35476
|
}
|
|
@@ -35207,12 +35521,12 @@ function runDevServer(evaluators, opts) {
|
|
|
35207
35521
|
...evaluator,
|
|
35208
35522
|
data: evalData.data,
|
|
35209
35523
|
scores: (_nullishCoalesce(evaluator.scores, () => ( []))).concat(
|
|
35210
|
-
_nullishCoalesce(_optionalChain([scores, 'optionalAccess',
|
|
35524
|
+
_nullishCoalesce(_optionalChain([scores, 'optionalAccess', _983 => _983.map, 'call', _984 => _984(
|
|
35211
35525
|
(score) => makeScorer(
|
|
35212
35526
|
state,
|
|
35213
35527
|
score.name,
|
|
35214
35528
|
score.function_id,
|
|
35215
|
-
_optionalChain([req, 'access',
|
|
35529
|
+
_optionalChain([req, 'access', _985 => _985.ctx, 'optionalAccess', _986 => _986.projectId])
|
|
35216
35530
|
)
|
|
35217
35531
|
)]), () => ( []))
|
|
35218
35532
|
),
|