braintrust 3.25.0 → 3.27.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 (79) hide show
  1. package/NOTICE +6 -0
  2. package/dev/dist/index.d.mts +130 -2
  3. package/dev/dist/index.d.ts +130 -2
  4. package/dev/dist/index.js +4133 -1421
  5. package/dev/dist/index.mjs +3242 -530
  6. package/dist/apply-auto-instrumentation.js +526 -426
  7. package/dist/apply-auto-instrumentation.mjs +329 -229
  8. package/dist/auto-instrumentations/bundler/esbuild.cjs +1198 -364
  9. package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
  10. package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
  11. package/dist/auto-instrumentations/bundler/esbuild.mjs +6 -8
  12. package/dist/auto-instrumentations/bundler/next.cjs +1227 -413
  13. package/dist/auto-instrumentations/bundler/next.mjs +7 -29
  14. package/dist/auto-instrumentations/bundler/rollup.cjs +1198 -364
  15. package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
  16. package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
  17. package/dist/auto-instrumentations/bundler/rollup.mjs +6 -8
  18. package/dist/auto-instrumentations/bundler/vite.cjs +1249 -387
  19. package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
  20. package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
  21. package/dist/auto-instrumentations/bundler/vite.mjs +34 -8
  22. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1368 -324
  23. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
  24. package/dist/auto-instrumentations/bundler/webpack.cjs +1198 -364
  25. package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
  26. package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
  27. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -4
  28. package/dist/auto-instrumentations/chunk-2AMDGD65.mjs +1396 -0
  29. package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-BW33ULMW.mjs} +2 -6
  30. package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-I55G56ZL.mjs} +114 -221
  31. package/dist/auto-instrumentations/chunk-JPUFNW7X.mjs +649 -0
  32. package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-XEYKUBLY.mjs} +191 -73
  33. package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-ZNHTSSGI.mjs} +231 -69
  34. package/dist/auto-instrumentations/hook.mjs +406 -183
  35. package/dist/auto-instrumentations/index.cjs +853 -49
  36. package/dist/auto-instrumentations/index.d.mts +10 -2
  37. package/dist/auto-instrumentations/index.d.ts +10 -2
  38. package/dist/auto-instrumentations/index.mjs +10 -1
  39. package/dist/auto-instrumentations/loader/cjs-patch.cjs +566 -221
  40. package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
  41. package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
  42. package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
  43. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  44. package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
  45. package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
  46. package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
  47. package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
  48. package/dist/browser.d.mts +871 -199
  49. package/dist/browser.d.ts +871 -199
  50. package/dist/browser.js +3737 -549
  51. package/dist/browser.mjs +3737 -549
  52. package/dist/{chunk-ABR2QWDP.mjs → chunk-CZM5JIQL.mjs} +788 -132
  53. package/dist/{chunk-P25IOOU4.js → chunk-MF7NU6BT.js} +795 -139
  54. package/dist/{chunk-GSIDVFE6.js → chunk-QRHGVBKU.js} +3580 -1463
  55. package/dist/{chunk-2SANLSWX.mjs → chunk-YKD22IMR.mjs} +2505 -388
  56. package/dist/cli.js +3244 -533
  57. package/dist/edge-light.d.mts +1 -1
  58. package/dist/edge-light.d.ts +1 -1
  59. package/dist/edge-light.js +3737 -552
  60. package/dist/edge-light.mjs +3737 -552
  61. package/dist/index.d.mts +871 -199
  62. package/dist/index.d.ts +871 -199
  63. package/dist/index.js +893 -446
  64. package/dist/index.mjs +463 -16
  65. package/dist/instrumentation/index.d.mts +138 -6
  66. package/dist/instrumentation/index.d.ts +138 -6
  67. package/dist/instrumentation/index.js +3362 -559
  68. package/dist/instrumentation/index.mjs +3362 -559
  69. package/dist/vitest-evals-reporter.js +45 -43
  70. package/dist/vitest-evals-reporter.mjs +5 -3
  71. package/dist/workerd.d.mts +1 -1
  72. package/dist/workerd.d.ts +1 -1
  73. package/dist/workerd.js +3737 -552
  74. package/dist/workerd.mjs +3737 -552
  75. package/licenses/node-diagnostics-channel/LICENSE +19 -0
  76. package/package.json +34 -35
  77. package/dist/auto-instrumentations/chunk-VT6DDNKM.mjs +0 -856
  78. package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
  79. package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
package/dist/index.mjs CHANGED
@@ -63,6 +63,7 @@ import {
63
63
  braintrustFlueObserver,
64
64
  braintrustStreamChunkSchema,
65
65
  buildBedrockRuntimeSpanInfo,
66
+ collectAnthropicSession,
66
67
  configureInstrumentation,
67
68
  configureNode,
68
69
  constructLogs3OverflowRequest,
@@ -91,6 +92,7 @@ import {
91
92
  initExperiment,
92
93
  initLogger,
93
94
  injectTraceContext,
95
+ instrumentCloudflareAIChatAgent,
94
96
  isEmpty,
95
97
  isObject,
96
98
  isTemplateFormat,
@@ -139,7 +141,7 @@ import {
139
141
  wrapMastraAgent,
140
142
  wrapTraced,
141
143
  zodToJsonSchema
142
- } from "./chunk-2SANLSWX.mjs";
144
+ } from "./chunk-YKD22IMR.mjs";
143
145
  import {
144
146
  INSTRUMENTATION_NAMES,
145
147
  __export,
@@ -147,6 +149,8 @@ import {
147
149
  anthropicChannels,
148
150
  bedrockRuntimeChannels,
149
151
  claudeAgentSDKChannels,
152
+ cloudflareAgentsChannels,
153
+ cloudflareThinkChannels,
150
154
  cohereChannels,
151
155
  cursorSDKChannels,
152
156
  genkitChannels,
@@ -156,9 +160,12 @@ import {
156
160
  groqChannels,
157
161
  harnessAgentChannels,
158
162
  huggingFaceChannels,
163
+ huggingFaceTransformersChannels,
164
+ isSupportedHuggingFaceTransformersTask,
159
165
  isomorph_default,
160
166
  langSmithChannels,
161
167
  mistralChannels,
168
+ ollamaChannels,
162
169
  openAIChannels,
163
170
  openAICodexChannels,
164
171
  openRouterAgentChannels,
@@ -166,7 +173,7 @@ import {
166
173
  piCodingAgentChannels,
167
174
  strandsAgentSDKChannels,
168
175
  withSpanInstrumentationName
169
- } from "./chunk-ABR2QWDP.mjs";
176
+ } from "./chunk-CZM5JIQL.mjs";
170
177
 
171
178
  // src/exports.ts
172
179
  var exports_exports = {};
@@ -240,6 +247,7 @@ __export(exports_exports, {
240
247
  braintrustFlueObserver: () => braintrustFlueObserver,
241
248
  braintrustStreamChunkSchema: () => braintrustStreamChunkSchema,
242
249
  buildLocalSummary: () => buildLocalSummary,
250
+ collectAnthropicSession: () => collectAnthropicSession,
243
251
  configureInstrumentation: () => configureInstrumentation,
244
252
  constructLogs3OverflowRequest: () => constructLogs3OverflowRequest,
245
253
  createFinalValuePassThroughStream: () => createFinalValuePassThroughStream,
@@ -317,6 +325,9 @@ __export(exports_exports, {
317
325
  wrapAnthropic: () => wrapAnthropic,
318
326
  wrapBedrockRuntime: () => wrapBedrockRuntime,
319
327
  wrapClaudeAgentSDK: () => wrapClaudeAgentSDK,
328
+ wrapCloudflareAIChat: () => wrapCloudflareAIChat,
329
+ wrapCloudflareAgent: () => wrapCloudflareAgent,
330
+ wrapCloudflareThink: () => wrapCloudflareThink,
320
331
  wrapCohere: () => wrapCohere,
321
332
  wrapCopilotClient: () => wrapCopilotClient,
322
333
  wrapCursorSDK: () => wrapCursorSDK,
@@ -325,11 +336,13 @@ __export(exports_exports, {
325
336
  wrapGoogleGenAI: () => wrapGoogleGenAI,
326
337
  wrapGroq: () => wrapGroq,
327
338
  wrapHuggingFace: () => wrapHuggingFace,
339
+ wrapHuggingFaceTransformers: () => wrapHuggingFaceTransformers,
328
340
  wrapLangSmithClient: () => wrapLangSmithClient,
329
341
  wrapLangSmithRunTrees: () => wrapLangSmithRunTrees,
330
342
  wrapLangSmithTraceable: () => wrapLangSmithTraceable,
331
343
  wrapMastraAgent: () => wrapMastraAgent,
332
344
  wrapMistral: () => wrapMistral,
345
+ wrapOllama: () => wrapOllama,
333
346
  wrapOpenAI: () => wrapOpenAI,
334
347
  wrapOpenAICodexSDK: () => wrapOpenAICodexSDK,
335
348
  wrapOpenAIv4: () => wrapOpenAIv4,
@@ -3534,6 +3547,66 @@ function betaProxy(beta, anthropic) {
3534
3547
  if (prop === "messages") {
3535
3548
  return betaMessagesProxy(target.messages, anthropic);
3536
3549
  }
3550
+ if (prop === "sessions") {
3551
+ return target.sessions ? betaSessionsProxy(target.sessions) : target.sessions;
3552
+ }
3553
+ return Reflect.get(target, prop, receiver);
3554
+ }
3555
+ });
3556
+ }
3557
+ function betaSessionsProxy(sessions) {
3558
+ return new Proxy(sessions, {
3559
+ get(target, prop, receiver) {
3560
+ if (prop === "events") {
3561
+ return betaSessionEventsProxy(target.events);
3562
+ }
3563
+ if (prop === "threads") {
3564
+ return target.threads ? betaSessionThreadsProxy(target.threads) : target.threads;
3565
+ }
3566
+ return Reflect.get(target, prop, receiver);
3567
+ }
3568
+ });
3569
+ }
3570
+ function betaSessionEventsProxy(events) {
3571
+ return new Proxy(events, {
3572
+ get(target, prop, receiver) {
3573
+ if (prop === "stream") {
3574
+ return new TypedApplyProxy(target.stream, {
3575
+ apply(stream, thisArg, argArray) {
3576
+ return anthropicChannels.betaSessionsEventsStream.tracePromise(
3577
+ () => Reflect.apply(stream, thisArg, argArray),
3578
+ { arguments: argArray }
3579
+ );
3580
+ }
3581
+ });
3582
+ }
3583
+ return Reflect.get(target, prop, receiver);
3584
+ }
3585
+ });
3586
+ }
3587
+ function betaSessionThreadsProxy(threads) {
3588
+ return new Proxy(threads, {
3589
+ get(target, prop, receiver) {
3590
+ if (prop === "events") {
3591
+ return betaSessionThreadEventsProxy(target.events);
3592
+ }
3593
+ return Reflect.get(target, prop, receiver);
3594
+ }
3595
+ });
3596
+ }
3597
+ function betaSessionThreadEventsProxy(events) {
3598
+ return new Proxy(events, {
3599
+ get(target, prop, receiver) {
3600
+ if (prop === "stream") {
3601
+ return new TypedApplyProxy(target.stream, {
3602
+ apply(stream, thisArg, argArray) {
3603
+ return anthropicChannels.betaSessionsThreadsEventsStream.tracePromise(
3604
+ () => Reflect.apply(stream, thisArg, argArray),
3605
+ { arguments: argArray }
3606
+ );
3607
+ }
3608
+ });
3609
+ }
3537
3610
  return Reflect.get(target, prop, receiver);
3538
3611
  }
3539
3612
  });
@@ -3727,6 +3800,52 @@ function claudeAgentSDKProxy(sdk) {
3727
3800
  });
3728
3801
  }
3729
3802
 
3803
+ // src/wrappers/cloudflare-think.ts
3804
+ var WRAPPED_THINK = /* @__PURE__ */ Symbol.for("braintrust.cloudflare-think.wrapped");
3805
+ function wrapCloudflareThink(sdk) {
3806
+ if (!sdk || typeof sdk !== "object") {
3807
+ return sdk;
3808
+ }
3809
+ const thinkModule = sdk;
3810
+ if (typeof thinkModule.Think !== "function") {
3811
+ return sdk;
3812
+ }
3813
+ patchThinkClass(thinkModule.Think);
3814
+ return sdk;
3815
+ }
3816
+ function patchThinkClass(Think) {
3817
+ const prototype = Think.prototype;
3818
+ if (!prototype || prototype[WRAPPED_THINK]) {
3819
+ return;
3820
+ }
3821
+ const descriptor = Object.getOwnPropertyDescriptor(
3822
+ prototype,
3823
+ "_runInferenceLoop"
3824
+ );
3825
+ if (!descriptor || typeof descriptor.value !== "function") {
3826
+ return;
3827
+ }
3828
+ const original = descriptor.value;
3829
+ Object.defineProperty(prototype, "_runInferenceLoop", {
3830
+ ...descriptor,
3831
+ value: function wrappedCloudflareThinkRunInferenceLoop(input) {
3832
+ const args = [input];
3833
+ return cloudflareThinkChannels.runInferenceLoop.tracePromise(
3834
+ () => Reflect.apply(original, this, args),
3835
+ {
3836
+ arguments: args,
3837
+ self: this
3838
+ }
3839
+ );
3840
+ }
3841
+ });
3842
+ Object.defineProperty(prototype, WRAPPED_THINK, {
3843
+ configurable: false,
3844
+ enumerable: false,
3845
+ value: true
3846
+ });
3847
+ }
3848
+
3730
3849
  // src/wrappers/openai-codex.ts
3731
3850
  var WRAPPED_CLIENT = /* @__PURE__ */ Symbol.for("braintrust.openai-codex.wrapped-client");
3732
3851
  var WRAPPED_THREAD = /* @__PURE__ */ Symbol.for("braintrust.openai-codex.wrapped-thread");
@@ -4019,14 +4138,9 @@ function patchAgentSessionClass(AgentSession) {
4019
4138
  ...descriptor,
4020
4139
  value: function wrappedPiCodingAgentPrompt(text, options) {
4021
4140
  const args = [text, options];
4022
- return piCodingAgentChannels.prompt.tracePromise(
4023
- () => Reflect.apply(originalPrompt, this, args),
4024
- {
4025
- arguments: args,
4026
- self: this,
4027
- session: this
4028
- }
4029
- );
4141
+ return piCodingAgentChannels.prompt.invoke(originalPrompt, this, args, {
4142
+ session: this
4143
+ });
4030
4144
  }
4031
4145
  });
4032
4146
  Object.defineProperty(prototype, WRAPPED_PROMPT, {
@@ -4036,6 +4150,67 @@ function patchAgentSessionClass(AgentSession) {
4036
4150
  });
4037
4151
  }
4038
4152
 
4153
+ // src/wrappers/cloudflare-agent.ts
4154
+ var WRAPPED_RUN_AGENT_TOOL = /* @__PURE__ */ Symbol.for(
4155
+ "braintrust.cloudflare-agents.wrapped-run-agent-tool"
4156
+ );
4157
+ function wrapCloudflareAgent(Agent) {
4158
+ if (typeof Agent !== "function") {
4159
+ warnUnsupportedAgent();
4160
+ return Agent;
4161
+ }
4162
+ const prototypeDescriptor = Object.getOwnPropertyDescriptor(
4163
+ Agent,
4164
+ "prototype"
4165
+ );
4166
+ const prototype = prototypeDescriptor && "value" in prototypeDescriptor ? prototypeDescriptor.value : void 0;
4167
+ if (!isObjectLike(prototype)) {
4168
+ warnUnsupportedAgent();
4169
+ return Agent;
4170
+ }
4171
+ if (ownValue(prototype, WRAPPED_RUN_AGENT_TOOL) === true) {
4172
+ return Agent;
4173
+ }
4174
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, "runAgentTool");
4175
+ if (!descriptor || typeof descriptor.value !== "function") {
4176
+ warnUnsupportedAgent();
4177
+ return Agent;
4178
+ }
4179
+ const originalRunAgentTool = descriptor.value;
4180
+ Object.defineProperty(prototype, "runAgentTool", {
4181
+ ...descriptor,
4182
+ value: function wrappedRunAgentTool(...args) {
4183
+ const options = args[1];
4184
+ if (ownValue(options, "detached")) {
4185
+ return Reflect.apply(originalRunAgentTool, this, args);
4186
+ }
4187
+ return cloudflareAgentsChannels.runAgentTool.tracePromise(
4188
+ () => Reflect.apply(originalRunAgentTool, this, args),
4189
+ { arguments: args, self: this }
4190
+ );
4191
+ }
4192
+ });
4193
+ Object.defineProperty(prototype, WRAPPED_RUN_AGENT_TOOL, {
4194
+ configurable: false,
4195
+ enumerable: false,
4196
+ value: true
4197
+ });
4198
+ return Agent;
4199
+ }
4200
+ function ownValue(value, key) {
4201
+ if (!isObjectLike(value)) {
4202
+ return void 0;
4203
+ }
4204
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
4205
+ return descriptor && "value" in descriptor ? descriptor.value : void 0;
4206
+ }
4207
+ function isObjectLike(value) {
4208
+ return typeof value === "object" && value !== null || typeof value === "function";
4209
+ }
4210
+ function warnUnsupportedAgent() {
4211
+ debugLogger.warn("Unsupported Cloudflare Agents Agent class. Not wrapping.");
4212
+ }
4213
+
4039
4214
  // src/wrappers/strands-agent-sdk.ts
4040
4215
  var WRAPPED_CLASS = /* @__PURE__ */ Symbol.for("braintrust.strands-agent-sdk.wrapped-class");
4041
4216
  var WRAPPED_INSTANCE = /* @__PURE__ */ Symbol.for(
@@ -4204,6 +4379,81 @@ async function consumeAsyncGenerator(generator) {
4204
4379
  return result.value;
4205
4380
  }
4206
4381
 
4382
+ // src/wrappers/cloudflare-ai-chat.ts
4383
+ var wrappedClasses = /* @__PURE__ */ new WeakMap();
4384
+ function wrapCloudflareAIChat(module) {
4385
+ if (!module || typeof module !== "object") {
4386
+ return module;
4387
+ }
4388
+ const candidate = module;
4389
+ let AIChatAgent;
4390
+ try {
4391
+ AIChatAgent = Reflect.get(candidate, "AIChatAgent");
4392
+ } catch (error) {
4393
+ debugLogger.debug("Failed to inspect @cloudflare/ai-chat module:", error);
4394
+ return module;
4395
+ }
4396
+ if (typeof AIChatAgent !== "function") {
4397
+ debugLogger.warn(
4398
+ "Unsupported @cloudflare/ai-chat module. AIChatAgent was not found; not wrapping."
4399
+ );
4400
+ return module;
4401
+ }
4402
+ const target = isModuleNamespace5(module) ? Object.setPrototypeOf({}, module) : candidate;
4403
+ return new Proxy(target, {
4404
+ get(target2, property, receiver) {
4405
+ const value = Reflect.get(target2, property, receiver);
4406
+ if (property === "AIChatAgent" && typeof value === "function") {
4407
+ return wrapAIChatAgentClass(
4408
+ value
4409
+ );
4410
+ }
4411
+ return value;
4412
+ }
4413
+ });
4414
+ }
4415
+ function wrapAIChatAgentClass(AgentClass) {
4416
+ const cached = wrappedClasses.get(AgentClass);
4417
+ if (cached) {
4418
+ return cached;
4419
+ }
4420
+ const wrapped = new Proxy(AgentClass, {
4421
+ get(target, property) {
4422
+ const value = Reflect.get(target, property, target);
4423
+ return typeof value === "function" ? value.bind(target) : value;
4424
+ },
4425
+ construct(target, args, newTarget) {
4426
+ const instance = Reflect.construct(
4427
+ target,
4428
+ args,
4429
+ newTarget
4430
+ );
4431
+ return instrumentCloudflareAIChatAgent(instance);
4432
+ }
4433
+ });
4434
+ wrappedClasses.set(AgentClass, wrapped);
4435
+ wrappedClasses.set(wrapped, wrapped);
4436
+ return wrapped;
4437
+ }
4438
+ function isModuleNamespace5(value) {
4439
+ if (!value || typeof value !== "object") {
4440
+ return false;
4441
+ }
4442
+ try {
4443
+ if (Reflect.get(value, Symbol.toStringTag) === "Module") {
4444
+ return true;
4445
+ }
4446
+ const keys = Object.keys(value);
4447
+ if (keys.length === 0) {
4448
+ return false;
4449
+ }
4450
+ const descriptor = Object.getOwnPropertyDescriptor(value, keys[0]);
4451
+ return descriptor ? !descriptor.configurable && !descriptor.writable : false;
4452
+ } catch {
4453
+ return false;
4454
+ }
4455
+ }
4456
+
4207
4457
  // src/wrappers/google-genai.ts
4208
4458
  function wrapGoogleGenAI(googleGenAI) {
4209
4459
  if (!googleGenAI || typeof googleGenAI !== "object") {
@@ -4856,6 +5106,120 @@ function wrapFeatureExtraction(original, endpointUrl) {
4856
5106
  };
4857
5107
  }
4858
5108
 
5109
+ // src/wrappers/huggingface-transformers.ts
5110
+ var PIPELINE_CONSTRUCTOR_KEYS = /* @__PURE__ */ new Set([
5111
+ "TextGenerationPipeline",
5112
+ "Text2TextGenerationPipeline",
5113
+ "SummarizationPipeline",
5114
+ "FeatureExtractionPipeline",
5115
+ "QuestionAnsweringPipeline"
5116
+ ]);
5117
+ var wrappedValues = /* @__PURE__ */ new WeakMap();
5118
+ function wrapHuggingFaceTransformers(transformers) {
5119
+ const pipelineTask = transformers?.task;
5120
+ if (typeof transformers === "function" && isSupportedHuggingFaceTransformersTask(pipelineTask)) {
5121
+ return wrapPipeline(transformers);
5122
+ }
5123
+ if (!isSupportedModule(transformers)) {
5124
+ return transformers;
5125
+ }
5126
+ const existing = wrappedValues.get(transformers);
5127
+ if (existing) {
5128
+ return existing;
5129
+ }
5130
+ const proxy = new Proxy(Object.create(transformers), {
5131
+ get(_target, property, receiver) {
5132
+ const value = Reflect.get(transformers, property, receiver);
5133
+ if (property === "pipeline" && typeof value === "function") {
5134
+ return wrapPipelineFactory(value);
5135
+ }
5136
+ if (typeof property === "string" && PIPELINE_CONSTRUCTOR_KEYS.has(property) && typeof value === "function") {
5137
+ return wrapPipelineConstructor(
5138
+ value
5139
+ );
5140
+ }
5141
+ return value;
5142
+ }
5143
+ });
5144
+ wrappedValues.set(transformers, proxy);
5145
+ wrappedValues.set(proxy, proxy);
5146
+ return proxy;
5147
+ }
5148
+ function isSupportedModule(value) {
5149
+ if (value === null || typeof value !== "object" && typeof value !== "function") {
5150
+ return false;
5151
+ }
5152
+ if (typeof Reflect.get(value, "pipeline") === "function") {
5153
+ return true;
5154
+ }
5155
+ for (const key of PIPELINE_CONSTRUCTOR_KEYS) {
5156
+ if (typeof Reflect.get(value, key) === "function") {
5157
+ return true;
5158
+ }
5159
+ }
5160
+ return false;
5161
+ }
5162
+ function wrapPipelineFactory(factory) {
5163
+ const existing = wrappedValues.get(factory);
5164
+ if (existing) {
5165
+ return existing;
5166
+ }
5167
+ const wrapped = function(...args) {
5168
+ const [task] = args;
5169
+ const context = {
5170
+ arguments: args
5171
+ };
5172
+ return huggingFaceTransformersChannels.pipeline.tracePromise(() => Reflect.apply(factory, this, args), context).then((pipeline) => {
5173
+ if (isSupportedHuggingFaceTransformersTask(pipeline.task ?? task)) {
5174
+ return wrapPipeline(pipeline);
5175
+ }
5176
+ return pipeline;
5177
+ });
5178
+ };
5179
+ wrappedValues.set(factory, wrapped);
5180
+ wrappedValues.set(wrapped, wrapped);
5181
+ return wrapped;
5182
+ }
5183
+ function wrapPipelineConstructor(constructor) {
5184
+ const existing = wrappedValues.get(constructor);
5185
+ if (existing) {
5186
+ return existing;
5187
+ }
5188
+ const proxy = new Proxy(constructor, {
5189
+ construct(target, args, newTarget) {
5190
+ const pipeline = Reflect.construct(target, args, newTarget);
5191
+ if (isSupportedHuggingFaceTransformersTask(pipeline.task)) {
5192
+ return wrapPipeline(pipeline);
5193
+ }
5194
+ return pipeline;
5195
+ }
5196
+ });
5197
+ wrappedValues.set(constructor, proxy);
5198
+ wrappedValues.set(proxy, proxy);
5199
+ return proxy;
5200
+ }
5201
+ function wrapPipeline(pipeline) {
5202
+ const existing = wrappedValues.get(pipeline);
5203
+ if (existing) {
5204
+ return existing;
5205
+ }
5206
+ const proxy = new Proxy(pipeline, {
5207
+ apply(target, thisArg, args) {
5208
+ const context = {
5209
+ arguments: args,
5210
+ self: target
5211
+ };
5212
+ return huggingFaceTransformersChannels.pipelineCall.tracePromise(
5213
+ () => Reflect.apply(target, thisArg, args),
5214
+ context
5215
+ );
5216
+ }
5217
+ });
5218
+ wrappedValues.set(pipeline, proxy);
5219
+ wrappedValues.set(proxy, proxy);
5220
+ return proxy;
5221
+ }
5222
+
4859
5223
  // src/wrappers/openrouter-agent.ts
4860
5224
  function wrapOpenRouterAgent(agent) {
4861
5225
  const candidate = agent;
@@ -5216,6 +5580,83 @@ function wrapAgentsStream(stream) {
5216
5580
  });
5217
5581
  }
5218
5582
 
5583
+ // src/wrappers/ollama.ts
5584
+ function wrapOllama(ollama) {
5585
+ if (isSupportedOllamaClient(ollama)) {
5586
+ return ollamaProxy(ollama);
5587
+ }
5588
+ debugLogger.warn("Unsupported Ollama library. Not wrapping.");
5589
+ return ollama;
5590
+ }
5591
+ var ollamaProxyCache = /* @__PURE__ */ new WeakMap();
5592
+ function isSupportedOllamaClient(value) {
5593
+ return isObject(value) && ["chat", "generate", "embed"].some(
5594
+ (name) => typeof value[name] === "function"
5595
+ );
5596
+ }
5597
+ function ollamaProxy(ollama) {
5598
+ const cached = ollamaProxyCache.get(ollama);
5599
+ if (cached) {
5600
+ return cached;
5601
+ }
5602
+ let chatSource;
5603
+ let wrappedChat;
5604
+ let generateSource;
5605
+ let wrappedGenerate;
5606
+ let embedSource;
5607
+ let wrappedEmbed;
5608
+ const proxy = new Proxy(ollama, {
5609
+ get(target, prop, receiver) {
5610
+ switch (prop) {
5611
+ case "chat": {
5612
+ const source = target.chat;
5613
+ if (source !== chatSource) {
5614
+ chatSource = source;
5615
+ wrappedChat = typeof source === "function" ? wrapChat(source.bind(target)) : source;
5616
+ }
5617
+ return wrappedChat;
5618
+ }
5619
+ case "generate": {
5620
+ const source = target.generate;
5621
+ if (source !== generateSource) {
5622
+ generateSource = source;
5623
+ wrappedGenerate = typeof source === "function" ? wrapGenerate2(source.bind(target)) : source;
5624
+ }
5625
+ return wrappedGenerate;
5626
+ }
5627
+ case "embed": {
5628
+ const source = target.embed;
5629
+ if (source !== embedSource) {
5630
+ embedSource = source;
5631
+ wrappedEmbed = typeof source === "function" ? wrapEmbed3(source.bind(target)) : source;
5632
+ }
5633
+ return wrappedEmbed;
5634
+ }
5635
+ default:
5636
+ return Reflect.get(target, prop, receiver);
5637
+ }
5638
+ }
5639
+ });
5640
+ ollamaProxyCache.set(ollama, proxy);
5641
+ ollamaProxyCache.set(proxy, proxy);
5642
+ return proxy;
5643
+ }
5644
+ function wrapChat(chat) {
5645
+ return (request) => ollamaChannels.chat.tracePromise(() => chat(request), {
5646
+ arguments: [request]
5647
+ });
5648
+ }
5649
+ function wrapGenerate2(generate) {
5650
+ return (request) => ollamaChannels.generate.tracePromise(() => generate(request), {
5651
+ arguments: [request]
5652
+ });
5653
+ }
5654
+ function wrapEmbed3(embed) {
5655
+ return (request) => ollamaChannels.embed.tracePromise(() => embed(request), {
5656
+ arguments: [request]
5657
+ });
5658
+ }
5659
+
5219
5660
  // src/wrappers/cohere.ts
5220
5661
  function wrapCohere(cohere) {
5221
5662
  if (isSupportedCohereClient(cohere)) {
@@ -5246,11 +5687,11 @@ function cohereProxy(cohere) {
5246
5687
  get(target, prop, receiver) {
5247
5688
  switch (prop) {
5248
5689
  case "chat":
5249
- return typeof target.chat === "function" ? wrapChat(target.chat.bind(target)) : target.chat;
5690
+ return typeof target.chat === "function" ? wrapChat2(target.chat.bind(target)) : target.chat;
5250
5691
  case "chatStream":
5251
5692
  return typeof target.chatStream === "function" ? wrapChatStream2(target.chatStream.bind(target)) : target.chatStream;
5252
5693
  case "embed":
5253
- return typeof target.embed === "function" ? wrapEmbed3(target.embed.bind(target)) : target.embed;
5694
+ return typeof target.embed === "function" ? wrapEmbed4(target.embed.bind(target)) : target.embed;
5254
5695
  case "rerank":
5255
5696
  return typeof target.rerank === "function" ? wrapRerank3(target.rerank.bind(target)) : target.rerank;
5256
5697
  default: {
@@ -5263,7 +5704,7 @@ function cohereProxy(cohere) {
5263
5704
  cohereProxyCache.set(cohere, proxy);
5264
5705
  return proxy;
5265
5706
  }
5266
- function wrapChat(chat) {
5707
+ function wrapChat2(chat) {
5267
5708
  return (request, options) => cohereChannels.chat.tracePromise(() => chat(request, options), {
5268
5709
  arguments: [request]
5269
5710
  });
@@ -5273,7 +5714,7 @@ function wrapChatStream2(chatStream) {
5273
5714
  arguments: [request]
5274
5715
  });
5275
5716
  }
5276
- function wrapEmbed3(embed) {
5717
+ function wrapEmbed4(embed) {
5277
5718
  return (request, options) => cohereChannels.embed.tracePromise(() => embed(request, options), {
5278
5719
  arguments: [request]
5279
5720
  });
@@ -5572,7 +6013,7 @@ function wrapNamespaceExport(namespace, exportName, marker, wrap2) {
5572
6013
  );
5573
6014
  return namespace;
5574
6015
  }
5575
- const target = isModuleNamespace5(namespace) ? Object.setPrototypeOf({}, namespace) : candidate;
6016
+ const target = isModuleNamespace6(namespace) ? Object.setPrototypeOf({}, namespace) : candidate;
5576
6017
  const moduleNamespace = target !== candidate;
5577
6018
  let wrappedExport;
5578
6019
  return new Proxy(target, {
@@ -5606,7 +6047,7 @@ function wrapNamespaceExport(namespace, exportName, marker, wrap2) {
5606
6047
  }
5607
6048
  });
5608
6049
  }
5609
- function isModuleNamespace5(value) {
6050
+ function isModuleNamespace6(value) {
5610
6051
  if (!value || typeof value !== "object") {
5611
6052
  return false;
5612
6053
  }
@@ -10125,6 +10566,7 @@ export {
10125
10566
  braintrustFlueObserver,
10126
10567
  braintrustStreamChunkSchema,
10127
10568
  buildLocalSummary,
10569
+ collectAnthropicSession,
10128
10570
  configureInstrumentation,
10129
10571
  constructLogs3OverflowRequest,
10130
10572
  createFinalValuePassThroughStream,
@@ -10203,6 +10645,9 @@ export {
10203
10645
  wrapAnthropic,
10204
10646
  wrapBedrockRuntime,
10205
10647
  wrapClaudeAgentSDK,
10648
+ wrapCloudflareAIChat,
10649
+ wrapCloudflareAgent,
10650
+ wrapCloudflareThink,
10206
10651
  wrapCohere,
10207
10652
  wrapCopilotClient,
10208
10653
  wrapCursorSDK,
@@ -10211,11 +10656,13 @@ export {
10211
10656
  wrapGoogleGenAI,
10212
10657
  wrapGroq,
10213
10658
  wrapHuggingFace,
10659
+ wrapHuggingFaceTransformers,
10214
10660
  wrapLangSmithClient,
10215
10661
  wrapLangSmithRunTrees,
10216
10662
  wrapLangSmithTraceable,
10217
10663
  wrapMastraAgent,
10218
10664
  wrapMistral,
10665
+ wrapOllama,
10219
10666
  wrapOpenAI,
10220
10667
  wrapOpenAICodexSDK,
10221
10668
  wrapOpenAIv4,