braintrust 3.13.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dev/dist/index.d.mts +6 -8
  2. package/dev/dist/index.d.ts +6 -8
  3. package/dev/dist/index.js +809 -466
  4. package/dev/dist/index.mjs +367 -24
  5. package/dist/apply-auto-instrumentation.js +204 -174
  6. package/dist/apply-auto-instrumentation.mjs +35 -5
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +225 -1
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -1
  9. package/dist/auto-instrumentations/bundler/next.cjs +225 -1
  10. package/dist/auto-instrumentations/bundler/next.mjs +3 -2
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +225 -1
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -1
  13. package/dist/auto-instrumentations/bundler/vite.cjs +225 -1
  14. package/dist/auto-instrumentations/bundler/vite.mjs +2 -1
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +8 -0
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +225 -1
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -2
  18. package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
  19. package/dist/auto-instrumentations/{chunk-WFEUJACP.mjs → chunk-OTUQ7KH5.mjs} +1 -1
  20. package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
  21. package/dist/auto-instrumentations/{chunk-GJOO4ESL.mjs → chunk-XKAAVWT6.mjs} +23 -1
  22. package/dist/auto-instrumentations/hook.mjs +7980 -7
  23. package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
  24. package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
  25. package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
  26. package/dist/browser.d.mts +127 -11
  27. package/dist/browser.d.ts +127 -11
  28. package/dist/browser.js +293 -24
  29. package/dist/browser.mjs +293 -24
  30. package/dist/{chunk-26JGOELH.js → chunk-NKD77KGB.js} +179 -1
  31. package/dist/{chunk-75IQCUB2.mjs → chunk-NU2GSPHX.mjs} +179 -1
  32. package/dist/cli.js +374 -51
  33. package/dist/edge-light.d.mts +1 -1
  34. package/dist/edge-light.d.ts +1 -1
  35. package/dist/edge-light.js +293 -24
  36. package/dist/edge-light.mjs +293 -24
  37. package/dist/index.d.mts +127 -11
  38. package/dist/index.d.ts +127 -11
  39. package/dist/index.js +1113 -838
  40. package/dist/index.mjs +305 -30
  41. package/dist/instrumentation/index.d.mts +7 -8
  42. package/dist/instrumentation/index.d.ts +7 -8
  43. package/dist/instrumentation/index.js +101 -24
  44. package/dist/instrumentation/index.mjs +101 -24
  45. package/dist/workerd.d.mts +1 -1
  46. package/dist/workerd.d.ts +1 -1
  47. package/dist/workerd.js +293 -24
  48. package/dist/workerd.mjs +293 -24
  49. package/package.json +1 -7
  50. package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
package/dist/index.mjs CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  googleGenAIChannels,
15
15
  groqChannels,
16
16
  huggingFaceChannels,
17
+ installMastraExporterFactory,
18
+ isInstrumentationIntegrationDisabled,
17
19
  isomorph_default,
18
20
  langChainChannels,
19
21
  mistralChannels,
@@ -24,7 +26,7 @@ import {
24
26
  openRouterChannels,
25
27
  patchTracingChannel,
26
28
  readDisabledInstrumentationEnvConfig
27
- } from "./chunk-75IQCUB2.mjs";
29
+ } from "./chunk-NU2GSPHX.mjs";
28
30
 
29
31
  // src/node/config.ts
30
32
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -4085,6 +4087,76 @@ var LRUCache = class {
4085
4087
  }
4086
4088
  };
4087
4089
 
4090
+ // src/prompt-cache/cache-config.ts
4091
+ var CACHE_LOCATION_ENV_VAR = "BRAINTRUST_CACHE_LOCATION";
4092
+ var DEFAULT_CACHE_MEMORY_MAX = 1 << 10;
4093
+ var DEFAULT_CACHE_DISK_MAX = 1 << 20;
4094
+ var warnedInvalidCacheModeEnvValue = false;
4095
+ var warnedUnavailableDiskCacheMode = false;
4096
+ function warnInvalidCacheMode(value) {
4097
+ if (warnedInvalidCacheModeEnvValue) {
4098
+ return;
4099
+ }
4100
+ warnedInvalidCacheModeEnvValue = true;
4101
+ debugLogger.warn(
4102
+ `Invalid ${CACHE_LOCATION_ENV_VAR} value "${value}". Expected "mixed", "memory", "disk", or "none". Falling back to "mixed".`
4103
+ );
4104
+ }
4105
+ function warnUnavailableDiskCache() {
4106
+ if (warnedUnavailableDiskCacheMode) {
4107
+ return;
4108
+ }
4109
+ warnedUnavailableDiskCacheMode = true;
4110
+ debugLogger.warn(
4111
+ `Disk cache is not supported on this platform, so ${CACHE_LOCATION_ENV_VAR}="disk" disables prompt and parameters caching.`
4112
+ );
4113
+ }
4114
+ function parseCacheMode() {
4115
+ const value = isomorph_default.getEnv(CACHE_LOCATION_ENV_VAR);
4116
+ const normalized = value?.trim().toLowerCase();
4117
+ if (!normalized) {
4118
+ return "mixed";
4119
+ }
4120
+ if (normalized === "mixed" || normalized === "memory" || normalized === "disk" || normalized === "none") {
4121
+ return normalized;
4122
+ }
4123
+ warnInvalidCacheMode(value ?? "");
4124
+ return "mixed";
4125
+ }
4126
+ function parsePositiveIntegerEnv(envVar, defaultValue) {
4127
+ const value = Number(isomorph_default.getEnv(envVar));
4128
+ return Number.isInteger(value) && value > 0 ? value : defaultValue;
4129
+ }
4130
+ function createCacheLayers({
4131
+ memoryMaxEnvVar,
4132
+ diskCacheDirEnvVar,
4133
+ diskMaxEnvVar,
4134
+ getDefaultDiskCacheDir
4135
+ }) {
4136
+ const mode = parseCacheMode();
4137
+ const memoryCache = mode === "mixed" || mode === "memory" ? new LRUCache({
4138
+ max: parsePositiveIntegerEnv(
4139
+ memoryMaxEnvVar,
4140
+ DEFAULT_CACHE_MEMORY_MAX
4141
+ )
4142
+ }) : void 0;
4143
+ let diskCache;
4144
+ if (mode === "mixed" || mode === "disk") {
4145
+ if (canUseDiskCache()) {
4146
+ diskCache = new DiskCache({
4147
+ cacheDir: isomorph_default.getEnv(diskCacheDirEnvVar) ?? getDefaultDiskCacheDir(),
4148
+ max: parsePositiveIntegerEnv(diskMaxEnvVar, DEFAULT_CACHE_DISK_MAX)
4149
+ });
4150
+ } else if (mode === "disk") {
4151
+ warnUnavailableDiskCache();
4152
+ }
4153
+ }
4154
+ if (diskCache) {
4155
+ return { memoryCache, diskCache };
4156
+ }
4157
+ return { memoryCache };
4158
+ }
4159
+
4088
4160
  // src/prompt-cache/prompt-cache.ts
4089
4161
  function createCacheKey(key) {
4090
4162
  if (key.id) {
@@ -4112,16 +4184,18 @@ var PromptCache = class {
4112
4184
  */
4113
4185
  async get(key) {
4114
4186
  const cacheKey = createCacheKey(key);
4115
- const memoryPrompt = this.memoryCache.get(cacheKey);
4116
- if (memoryPrompt !== void 0) {
4117
- return memoryPrompt;
4187
+ if (this.memoryCache) {
4188
+ const memoryPrompt = this.memoryCache.get(cacheKey);
4189
+ if (memoryPrompt !== void 0) {
4190
+ return memoryPrompt;
4191
+ }
4118
4192
  }
4119
4193
  if (this.diskCache) {
4120
4194
  const diskPrompt = await this.diskCache.get(cacheKey);
4121
4195
  if (!diskPrompt) {
4122
4196
  return void 0;
4123
4197
  }
4124
- this.memoryCache.set(cacheKey, diskPrompt);
4198
+ this.memoryCache?.set(cacheKey, diskPrompt);
4125
4199
  return diskPrompt;
4126
4200
  }
4127
4201
  return void 0;
@@ -4136,7 +4210,7 @@ var PromptCache = class {
4136
4210
  */
4137
4211
  async set(key, value) {
4138
4212
  const cacheKey = createCacheKey(key);
4139
- this.memoryCache.set(cacheKey, value);
4213
+ this.memoryCache?.set(cacheKey, value);
4140
4214
  if (this.diskCache) {
4141
4215
  await this.diskCache.set(cacheKey, value);
4142
4216
  }
@@ -4166,23 +4240,25 @@ var ParametersCache = class {
4166
4240
  }
4167
4241
  async get(key) {
4168
4242
  const cacheKey = createCacheKey2(key);
4169
- const memoryParams = this.memoryCache.get(cacheKey);
4170
- if (memoryParams !== void 0) {
4171
- return memoryParams;
4243
+ if (this.memoryCache) {
4244
+ const memoryParams = this.memoryCache.get(cacheKey);
4245
+ if (memoryParams !== void 0) {
4246
+ return memoryParams;
4247
+ }
4172
4248
  }
4173
4249
  if (this.diskCache) {
4174
4250
  const diskParams = await this.diskCache.get(cacheKey);
4175
4251
  if (!diskParams) {
4176
4252
  return void 0;
4177
4253
  }
4178
- this.memoryCache.set(cacheKey, diskParams);
4254
+ this.memoryCache?.set(cacheKey, diskParams);
4179
4255
  return diskParams;
4180
4256
  }
4181
4257
  return void 0;
4182
4258
  }
4183
4259
  async set(key, value) {
4184
4260
  const cacheKey = createCacheKey2(key);
4185
- this.memoryCache.set(cacheKey, value);
4261
+ this.memoryCache?.set(cacheKey, value);
4186
4262
  if (this.diskCache) {
4187
4263
  await this.diskCache.set(cacheKey, value);
4188
4264
  }
@@ -4714,21 +4790,22 @@ var BraintrustState = class _BraintrustState {
4714
4790
  setGlobalDebugLogLevel(void 0);
4715
4791
  }
4716
4792
  this.resetLoginInfo();
4717
- const memoryCache = new LRUCache({
4718
- max: Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_MEMORY_MAX")) ?? 1 << 10
4793
+ const { memoryCache, diskCache } = createCacheLayers({
4794
+ memoryMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_MEMORY_MAX",
4795
+ diskCacheDirEnvVar: "BRAINTRUST_PROMPT_CACHE_DIR",
4796
+ diskMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_DISK_MAX",
4797
+ getDefaultDiskCacheDir: () => `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/prompt_cache`
4719
4798
  });
4720
- const diskCache = canUseDiskCache() ? new DiskCache({
4721
- cacheDir: isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DIR") ?? `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/prompt_cache`,
4722
- max: Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DISK_MAX")) ?? 1 << 20
4723
- }) : void 0;
4724
4799
  this.promptCache = new PromptCache({ memoryCache, diskCache });
4725
- const parametersMemoryCache = new LRUCache({
4726
- max: Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX")) ?? 1 << 10
4800
+ const {
4801
+ memoryCache: parametersMemoryCache,
4802
+ diskCache: parametersDiskCache
4803
+ } = createCacheLayers({
4804
+ memoryMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX",
4805
+ diskCacheDirEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DIR",
4806
+ diskMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DISK_MAX",
4807
+ getDefaultDiskCacheDir: () => `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/parameters_cache`
4727
4808
  });
4728
- const parametersDiskCache = canUseDiskCache() ? new DiskCache({
4729
- cacheDir: isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DIR") ?? `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/parameters_cache`,
4730
- max: Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DISK_MAX")) ?? 1 << 20
4731
- }) : void 0;
4732
4809
  this.parametersCache = new ParametersCache({
4733
4810
  memoryCache: parametersMemoryCache,
4734
4811
  diskCache: parametersDiskCache
@@ -25236,7 +25313,7 @@ var BraintrustPlugin = class extends BasePlugin {
25236
25313
  this.config = config;
25237
25314
  }
25238
25315
  onEnable() {
25239
- const integrations = this.config.integrations || {};
25316
+ const integrations = this.config.integrations ?? {};
25240
25317
  if (integrations.openai !== false) {
25241
25318
  this.openaiPlugin = new OpenAIPlugin();
25242
25319
  this.openaiPlugin.enable();
@@ -25301,7 +25378,7 @@ var BraintrustPlugin = class extends BasePlugin {
25301
25378
  this.genkitPlugin = new GenkitPlugin();
25302
25379
  this.genkitPlugin.enable();
25303
25380
  }
25304
- if (getIntegrationConfig(integrations, "gitHubCopilot") !== false) {
25381
+ if (integrations.gitHubCopilot !== false) {
25305
25382
  this.gitHubCopilotPlugin = new GitHubCopilotPlugin();
25306
25383
  this.gitHubCopilotPlugin.enable();
25307
25384
  }
@@ -25489,6 +25566,201 @@ function configureInstrumentation(config) {
25489
25566
  registry.configure(config);
25490
25567
  }
25491
25568
 
25569
+ // src/wrappers/mastra.ts
25570
+ var MASTRA_BRAINTRUST_EXPORTER_NAME = "braintrust";
25571
+ var SPAN_TYPE_MAP = {
25572
+ agent_run: "task" /* TASK */,
25573
+ model_generation: "llm" /* LLM */,
25574
+ model_step: "llm" /* LLM */,
25575
+ model_chunk: "llm" /* LLM */,
25576
+ tool_call: "tool" /* TOOL */,
25577
+ mcp_tool_call: "tool" /* TOOL */,
25578
+ workflow_run: "task" /* TASK */,
25579
+ workflow_step: "function" /* FUNCTION */,
25580
+ workflow_conditional: "function" /* FUNCTION */,
25581
+ workflow_conditional_eval: "function" /* FUNCTION */,
25582
+ workflow_parallel: "function" /* FUNCTION */,
25583
+ workflow_loop: "function" /* FUNCTION */,
25584
+ workflow_sleep: "function" /* FUNCTION */,
25585
+ workflow_wait_event: "function" /* FUNCTION */,
25586
+ memory_operation: "function" /* FUNCTION */,
25587
+ workspace_action: "function" /* FUNCTION */,
25588
+ rag_ingestion: "task" /* TASK */,
25589
+ rag_embedding: "llm" /* LLM */,
25590
+ rag_vector_operation: "function" /* FUNCTION */,
25591
+ rag_action: "function" /* FUNCTION */,
25592
+ graph_action: "function" /* FUNCTION */,
25593
+ scorer_run: "score" /* SCORE */,
25594
+ scorer_step: "score" /* SCORE */,
25595
+ processor_run: "function" /* FUNCTION */,
25596
+ generic: "function" /* FUNCTION */
25597
+ };
25598
+ function spanTypeFor(mastraType) {
25599
+ return SPAN_TYPE_MAP[mastraType] ?? "function" /* FUNCTION */;
25600
+ }
25601
+ function epochSeconds(value) {
25602
+ if (value === void 0) return void 0;
25603
+ const ms = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
25604
+ return Number.isFinite(ms) ? ms / 1e3 : void 0;
25605
+ }
25606
+ function modelMetrics(attributes) {
25607
+ if (!isObject(attributes)) return void 0;
25608
+ const usage = isObject(attributes.usage) ? attributes.usage : void 0;
25609
+ if (!usage) return void 0;
25610
+ const out = {};
25611
+ if (typeof usage.inputTokens === "number")
25612
+ out.prompt_tokens = usage.inputTokens;
25613
+ if (typeof usage.outputTokens === "number")
25614
+ out.completion_tokens = usage.outputTokens;
25615
+ if (typeof usage.inputTokens === "number" && typeof usage.outputTokens === "number") {
25616
+ out.tokens = usage.inputTokens + usage.outputTokens;
25617
+ }
25618
+ const inputDetails = isObject(usage.inputDetails) ? usage.inputDetails : void 0;
25619
+ const outputDetails = isObject(usage.outputDetails) ? usage.outputDetails : void 0;
25620
+ if (inputDetails && typeof inputDetails.cacheRead === "number") {
25621
+ out.prompt_cached_tokens = inputDetails.cacheRead;
25622
+ }
25623
+ if (inputDetails && typeof inputDetails.cacheWrite === "number") {
25624
+ out.prompt_cache_creation_tokens = inputDetails.cacheWrite;
25625
+ }
25626
+ if (outputDetails && typeof outputDetails.reasoning === "number") {
25627
+ out.completion_reasoning_tokens = outputDetails.reasoning;
25628
+ }
25629
+ return Object.keys(out).length > 0 ? out : void 0;
25630
+ }
25631
+ function buildMetadata(exported) {
25632
+ const out = {};
25633
+ if (exported.entityId !== void 0) out.entity_id = exported.entityId;
25634
+ if (exported.entityName !== void 0) out.entity_name = exported.entityName;
25635
+ if (exported.entityType !== void 0) out.entity_type = exported.entityType;
25636
+ if (exported.metadata && isObject(exported.metadata)) {
25637
+ Object.assign(out, exported.metadata);
25638
+ }
25639
+ if (exported.attributes && isObject(exported.attributes)) {
25640
+ for (const [key, value] of Object.entries(exported.attributes)) {
25641
+ if (key === "usage") continue;
25642
+ if (value !== void 0) out[key] = value;
25643
+ }
25644
+ }
25645
+ if (exported.tags && exported.tags.length > 0) {
25646
+ out.tags = exported.tags;
25647
+ }
25648
+ if (exported.requestContext && isObject(exported.requestContext)) {
25649
+ out.request_context = exported.requestContext;
25650
+ }
25651
+ return out;
25652
+ }
25653
+ var BraintrustObservabilityExporter = class {
25654
+ name = MASTRA_BRAINTRUST_EXPORTER_NAME;
25655
+ spans = /* @__PURE__ */ new Map();
25656
+ // Captured at the first SPAN_STARTED event. Mastra's observability bus may
25657
+ // dispatch later events outside the user's AsyncLocalStorage context, where
25658
+ // `currentSpan()` returns NOOP_SPAN — which would make our `startSpan()`
25659
+ // calls go to a no-op logger and silently drop. Anchoring on the parent
25660
+ // we observe while still in-context keeps the whole Mastra subtree under
25661
+ // the user's traced scenario.
25662
+ capturedParent;
25663
+ constructor() {
25664
+ _internalSetInitialState();
25665
+ }
25666
+ async exportTracingEvent(event) {
25667
+ const exported = event.exportedSpan;
25668
+ if (exported.isInternal === true) return;
25669
+ try {
25670
+ switch (event.type) {
25671
+ case "span_started":
25672
+ this.onStart(exported);
25673
+ break;
25674
+ case "span_updated":
25675
+ this.onUpdate(exported);
25676
+ break;
25677
+ case "span_ended":
25678
+ this.onEnd(exported);
25679
+ break;
25680
+ }
25681
+ } catch (err) {
25682
+ logExporterError(err);
25683
+ }
25684
+ }
25685
+ async flush() {
25686
+ const state = _internalGetGlobalState();
25687
+ if (state) {
25688
+ await state.bgLogger().flush();
25689
+ }
25690
+ }
25691
+ async shutdown() {
25692
+ await this.flush();
25693
+ this.spans.clear();
25694
+ }
25695
+ onStart(exported) {
25696
+ if (this.spans.has(exported.id)) return;
25697
+ const args = {
25698
+ name: exported.name,
25699
+ spanAttributes: { type: spanTypeFor(exported.type) },
25700
+ startTime: epochSeconds(exported.startTime)
25701
+ };
25702
+ const parentRecord = exported.parentSpanId ? this.spans.get(exported.parentSpanId) : void 0;
25703
+ if (!this.capturedParent) {
25704
+ const probe = currentSpan();
25705
+ if (probe && probe.spanId) {
25706
+ this.capturedParent = probe;
25707
+ }
25708
+ }
25709
+ const span = parentRecord ? parentRecord.span.startSpan(args) : this.capturedParent ? this.capturedParent.startSpan(args) : startSpan(args);
25710
+ const record = { span, hasLoggedInput: false };
25711
+ this.logPayload(record, exported);
25712
+ this.spans.set(exported.id, record);
25713
+ if (exported.isEvent === true) {
25714
+ span.end({ endTime: args.startTime });
25715
+ this.spans.delete(exported.id);
25716
+ }
25717
+ }
25718
+ onUpdate(exported) {
25719
+ const record = this.spans.get(exported.id);
25720
+ if (!record) return;
25721
+ this.logPayload(record, exported);
25722
+ }
25723
+ onEnd(exported) {
25724
+ const record = this.spans.get(exported.id);
25725
+ if (!record) return;
25726
+ this.logPayload(record, exported);
25727
+ if (exported.errorInfo) {
25728
+ record.span.log({
25729
+ error: exported.errorInfo.message || exported.errorInfo.name || "Unknown Mastra error"
25730
+ });
25731
+ }
25732
+ record.span.end({ endTime: epochSeconds(exported.endTime) });
25733
+ this.spans.delete(exported.id);
25734
+ }
25735
+ logPayload(record, exported) {
25736
+ const event = {};
25737
+ if (exported.input !== void 0) {
25738
+ event.input = exported.input;
25739
+ record.hasLoggedInput = true;
25740
+ }
25741
+ if (exported.output !== void 0) {
25742
+ event.output = exported.output;
25743
+ }
25744
+ const metadata = buildMetadata(exported);
25745
+ if (Object.keys(metadata).length > 0) {
25746
+ event.metadata = metadata;
25747
+ }
25748
+ const metrics = modelMetrics(exported.attributes);
25749
+ if (metrics) {
25750
+ event.metrics = metrics;
25751
+ }
25752
+ if (Object.keys(event).length > 0) {
25753
+ record.span.log(event);
25754
+ }
25755
+ }
25756
+ };
25757
+ function logExporterError(err) {
25758
+ debugLogger.warn("Mastra exporter failure:", err);
25759
+ }
25760
+ function wrapMastraAgent(agent, _options) {
25761
+ return agent;
25762
+ }
25763
+
25492
25764
  // src/node/config.ts
25493
25765
  var BRAINTRUST_ENV_SEARCH_PARENT_LIMIT = 64;
25494
25766
  function configureNode() {
@@ -25574,6 +25846,12 @@ function configureNode() {
25574
25846
  isomorph_default.gunzip = promisify(zlib.gunzip);
25575
25847
  isomorph_default.hash = (data) => crypto.createHash("sha256").update(data).digest("hex");
25576
25848
  _internalSetInitialState();
25849
+ const disabled = readDisabledInstrumentationEnvConfig(
25850
+ isomorph_default.getEnv("BRAINTRUST_DISABLE_INSTRUMENTATION")
25851
+ ).integrations;
25852
+ if (!isInstrumentationIntegrationDisabled(disabled, "mastra")) {
25853
+ installMastraExporterFactory(() => new BraintrustObservabilityExporter());
25854
+ }
25577
25855
  registry.enable();
25578
25856
  }
25579
25857
 
@@ -25588,6 +25866,7 @@ __export(exports_exports, {
25588
25866
  BaseExperiment: () => BaseExperiment,
25589
25867
  BraintrustLangChainCallbackHandler: () => BraintrustLangChainCallbackHandler,
25590
25868
  BraintrustMiddleware: () => BraintrustMiddleware,
25869
+ BraintrustObservabilityExporter: () => BraintrustObservabilityExporter,
25591
25870
  BraintrustState: () => BraintrustState,
25592
25871
  BraintrustStream: () => BraintrustStream,
25593
25872
  CachedSpanFetcher: () => CachedSpanFetcher,
@@ -27203,11 +27482,6 @@ function toolRunnerProxy(toolRunner, anthropic, channel) {
27203
27482
  });
27204
27483
  }
27205
27484
 
27206
- // src/wrappers/mastra.ts
27207
- function wrapMastraAgent(agent, _options) {
27208
- return agent;
27209
- }
27210
-
27211
27485
  // src/wrappers/claude-agent-sdk/claude-agent-sdk.ts
27212
27486
  function wrapClaudeAgentSDK(sdk) {
27213
27487
  const s = sdk;
@@ -32702,6 +32976,7 @@ export {
32702
32976
  BaseExperiment,
32703
32977
  BraintrustLangChainCallbackHandler,
32704
32978
  BraintrustMiddleware,
32979
+ BraintrustObservabilityExporter,
32705
32980
  BraintrustState,
32706
32981
  BraintrustStream,
32707
32982
  CachedSpanFetcher,
@@ -6137,6 +6137,7 @@ interface InstrumentationIntegrationsConfig {
6137
6137
  cursor?: boolean;
6138
6138
  cursorSDK?: boolean;
6139
6139
  flue?: boolean;
6140
+ mastra?: boolean;
6140
6141
  openAIAgents?: boolean;
6141
6142
  openrouter?: boolean;
6142
6143
  openrouterAgent?: boolean;
@@ -6737,17 +6738,15 @@ interface PromptKey {
6737
6738
  id?: string;
6738
6739
  }
6739
6740
  /**
6740
- * A two-layer cache for Braintrust prompts with both in-memory and filesystem storage.
6741
+ * A configurable cache for Braintrust prompts with optional in-memory and filesystem storage.
6741
6742
  *
6742
- * This cache implements either a one or two-layer caching strategy:
6743
- * 1. A fast in-memory LRU cache for frequently accessed prompts.
6744
- * 2. An optional persistent filesystem-based cache that serves as a backing store.
6743
+ * This cache can use either layer independently, both layers together, or no layers.
6745
6744
  */
6746
6745
  declare class PromptCache {
6747
- private readonly memoryCache;
6746
+ private readonly memoryCache?;
6748
6747
  private readonly diskCache?;
6749
6748
  constructor(options: {
6750
- memoryCache: LRUCache<string, Prompt>;
6749
+ memoryCache?: LRUCache<string, Prompt>;
6751
6750
  diskCache?: DiskCache<Prompt>;
6752
6751
  });
6753
6752
  /**
@@ -6774,10 +6773,10 @@ interface ParametersKey {
6774
6773
  id?: string;
6775
6774
  }
6776
6775
  declare class ParametersCache {
6777
- private readonly memoryCache;
6776
+ private readonly memoryCache?;
6778
6777
  private readonly diskCache?;
6779
6778
  constructor(options: {
6780
- memoryCache: LRUCache<string, RemoteEvalParameters>;
6779
+ memoryCache?: LRUCache<string, RemoteEvalParameters>;
6781
6780
  diskCache?: DiskCache<RemoteEvalParameters>;
6782
6781
  });
6783
6782
  get(key: ParametersKey): Promise<RemoteEvalParameters | undefined>;
@@ -6137,6 +6137,7 @@ interface InstrumentationIntegrationsConfig {
6137
6137
  cursor?: boolean;
6138
6138
  cursorSDK?: boolean;
6139
6139
  flue?: boolean;
6140
+ mastra?: boolean;
6140
6141
  openAIAgents?: boolean;
6141
6142
  openrouter?: boolean;
6142
6143
  openrouterAgent?: boolean;
@@ -6737,17 +6738,15 @@ interface PromptKey {
6737
6738
  id?: string;
6738
6739
  }
6739
6740
  /**
6740
- * A two-layer cache for Braintrust prompts with both in-memory and filesystem storage.
6741
+ * A configurable cache for Braintrust prompts with optional in-memory and filesystem storage.
6741
6742
  *
6742
- * This cache implements either a one or two-layer caching strategy:
6743
- * 1. A fast in-memory LRU cache for frequently accessed prompts.
6744
- * 2. An optional persistent filesystem-based cache that serves as a backing store.
6743
+ * This cache can use either layer independently, both layers together, or no layers.
6745
6744
  */
6746
6745
  declare class PromptCache {
6747
- private readonly memoryCache;
6746
+ private readonly memoryCache?;
6748
6747
  private readonly diskCache?;
6749
6748
  constructor(options: {
6750
- memoryCache: LRUCache<string, Prompt>;
6749
+ memoryCache?: LRUCache<string, Prompt>;
6751
6750
  diskCache?: DiskCache<Prompt>;
6752
6751
  });
6753
6752
  /**
@@ -6774,10 +6773,10 @@ interface ParametersKey {
6774
6773
  id?: string;
6775
6774
  }
6776
6775
  declare class ParametersCache {
6777
- private readonly memoryCache;
6776
+ private readonly memoryCache?;
6778
6777
  private readonly diskCache?;
6779
6778
  constructor(options: {
6780
- memoryCache: LRUCache<string, RemoteEvalParameters>;
6779
+ memoryCache?: LRUCache<string, RemoteEvalParameters>;
6781
6780
  diskCache?: DiskCache<RemoteEvalParameters>;
6782
6781
  });
6783
6782
  get(key: ParametersKey): Promise<RemoteEvalParameters | undefined>;