@agentv/core 2.18.4 → 2.19.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/dist/index.d.cts CHANGED
@@ -14,6 +14,11 @@ interface ProviderStreamCallbacks {
14
14
  onToolCallStart?: (toolName: string, toolCallId?: string) => void;
15
15
  onToolCallEnd?: (toolName: string, input: unknown, output: unknown, durationMs: number, toolCallId?: string) => void;
16
16
  onLlmCallEnd?: (model: string, tokenUsage?: ProviderTokenUsage) => void;
17
+ /** Returns active OTel span IDs for Braintrust trace bridging (optional) */
18
+ getActiveSpanIds?: () => {
19
+ parentSpanId: string;
20
+ rootSpanId: string;
21
+ } | null;
17
22
  }
18
23
  interface ProviderRequest {
19
24
  readonly question: string;
@@ -36,6 +41,11 @@ interface ProviderRequest {
36
41
  readonly captureFileChanges?: boolean;
37
42
  /** Real-time observability callbacks (optional) */
38
43
  readonly streamCallbacks?: ProviderStreamCallbacks;
44
+ /** Braintrust span IDs for trace-claude-code plugin (optional) */
45
+ readonly braintrustSpanIds?: {
46
+ readonly parentSpanId: string;
47
+ readonly rootSpanId: string;
48
+ };
39
49
  }
40
50
  /**
41
51
  * A tool call within an output message.
@@ -3207,6 +3217,11 @@ declare class OtelStreamingObserver {
3207
3217
  onLlmCall(model: string, tokenUsage?: ProviderTokenUsage): void;
3208
3218
  /** Finalize root span with score/verdict after evaluation completes */
3209
3219
  finalizeEvalCase(score: number, error?: string): void;
3220
+ /** Return the active eval span's trace ID and span ID for Braintrust trace bridging */
3221
+ getActiveSpanIds(): {
3222
+ parentSpanId: string;
3223
+ rootSpanId: string;
3224
+ } | null;
3210
3225
  /** Get ProviderStreamCallbacks for passing to providers */
3211
3226
  getStreamCallbacks(): ProviderStreamCallbacks;
3212
3227
  }
package/dist/index.d.ts CHANGED
@@ -14,6 +14,11 @@ interface ProviderStreamCallbacks {
14
14
  onToolCallStart?: (toolName: string, toolCallId?: string) => void;
15
15
  onToolCallEnd?: (toolName: string, input: unknown, output: unknown, durationMs: number, toolCallId?: string) => void;
16
16
  onLlmCallEnd?: (model: string, tokenUsage?: ProviderTokenUsage) => void;
17
+ /** Returns active OTel span IDs for Braintrust trace bridging (optional) */
18
+ getActiveSpanIds?: () => {
19
+ parentSpanId: string;
20
+ rootSpanId: string;
21
+ } | null;
17
22
  }
18
23
  interface ProviderRequest {
19
24
  readonly question: string;
@@ -36,6 +41,11 @@ interface ProviderRequest {
36
41
  readonly captureFileChanges?: boolean;
37
42
  /** Real-time observability callbacks (optional) */
38
43
  readonly streamCallbacks?: ProviderStreamCallbacks;
44
+ /** Braintrust span IDs for trace-claude-code plugin (optional) */
45
+ readonly braintrustSpanIds?: {
46
+ readonly parentSpanId: string;
47
+ readonly rootSpanId: string;
48
+ };
39
49
  }
40
50
  /**
41
51
  * A tool call within an output message.
@@ -3207,6 +3217,11 @@ declare class OtelStreamingObserver {
3207
3217
  onLlmCall(model: string, tokenUsage?: ProviderTokenUsage): void;
3208
3218
  /** Finalize root span with score/verdict after evaluation completes */
3209
3219
  finalizeEvalCase(score: number, error?: string): void;
3220
+ /** Return the active eval span's trace ID and span ID for Braintrust trace bridging */
3221
+ getActiveSpanIds(): {
3222
+ parentSpanId: string;
3223
+ rootSpanId: string;
3224
+ } | null;
3210
3225
  /** Get ProviderStreamCallbacks for passing to providers */
3211
3226
  getStreamCallbacks(): ProviderStreamCallbacks;
3212
3227
  }
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  readTextFile,
18
18
  resolveFileReference,
19
19
  resolveTargetDefinition
20
- } from "./chunk-V42NUK73.js";
20
+ } from "./chunk-ACTIPQZ3.js";
21
21
  import {
22
22
  OtlpJsonFileExporter
23
23
  } from "./chunk-HFSYZHGF.js";
@@ -3824,7 +3824,7 @@ var ClaudeProvider = class {
3824
3824
  // a Claude Code session the CLAUDECODE env var is set, which causes the
3825
3825
  // subprocess to refuse to start ("cannot be launched inside another Claude
3826
3826
  // Code session"). Passing a sanitized env removes that guard.
3827
- env: sanitizeEnvForClaudeSdk()
3827
+ env: sanitizeEnvForClaudeSdk(request.braintrustSpanIds)
3828
3828
  };
3829
3829
  if (this.config.model) {
3830
3830
  queryOptions.model = this.config.model;
@@ -4128,10 +4128,14 @@ function summarizeMessage(msg) {
4128
4128
  return void 0;
4129
4129
  }
4130
4130
  }
4131
- function sanitizeEnvForClaudeSdk() {
4131
+ function sanitizeEnvForClaudeSdk(braintrustSpanIds) {
4132
4132
  const env = { ...process.env };
4133
4133
  env.CLAUDECODE = void 0;
4134
4134
  env.CLAUDE_CODE_ENTRYPOINT = void 0;
4135
+ if (braintrustSpanIds) {
4136
+ env.CC_PARENT_SPAN_ID = braintrustSpanIds.parentSpanId;
4137
+ env.CC_ROOT_SPAN_ID = braintrustSpanIds.rootSpanId;
4138
+ }
4135
4139
  return env;
4136
4140
  }
4137
4141
  function isClaudeLogStreamingDisabled() {
@@ -15083,6 +15087,7 @@ async function invokeProvider(provider, options) {
15083
15087
  signal.addEventListener("abort", () => controller.abort(), { once: true });
15084
15088
  }
15085
15089
  try {
15090
+ const braintrustSpanIds = streamCallbacks?.getActiveSpanIds?.() ?? void 0;
15086
15091
  return await provider.invoke({
15087
15092
  question: promptInputs.question,
15088
15093
  guidelines: promptInputs.guidelines,
@@ -15098,7 +15103,8 @@ async function invokeProvider(provider, options) {
15098
15103
  cwd,
15099
15104
  workspaceFile,
15100
15105
  captureFileChanges: captureFileChanges2,
15101
- streamCallbacks
15106
+ streamCallbacks,
15107
+ braintrustSpanIds: braintrustSpanIds ?? void 0
15102
15108
  });
15103
15109
  } finally {
15104
15110
  if (timeout !== void 0) {
@@ -15653,9 +15659,16 @@ var OTEL_BACKEND_PRESETS = {
15653
15659
  braintrust: {
15654
15660
  name: "braintrust",
15655
15661
  endpoint: "https://api.braintrust.dev/otel/v1/traces",
15656
- headers: (env) => ({
15657
- Authorization: `Bearer ${env.BRAINTRUST_API_KEY ?? ""}`
15658
- })
15662
+ headers: (env) => {
15663
+ const headers = {
15664
+ Authorization: `Bearer ${env.BRAINTRUST_API_KEY ?? ""}`
15665
+ };
15666
+ const parent = env.BRAINTRUST_PARENT ?? (env.BRAINTRUST_PROJECT_ID ? `project_id:${env.BRAINTRUST_PROJECT_ID}` : void 0) ?? (env.BRAINTRUST_PROJECT ? `project_name:${env.BRAINTRUST_PROJECT}` : void 0);
15667
+ if (parent) {
15668
+ headers["x-bt-parent"] = parent;
15669
+ }
15670
+ return headers;
15671
+ }
15659
15672
  },
15660
15673
  confident: {
15661
15674
  name: "confident",
@@ -16003,11 +16016,23 @@ var OtelStreamingObserver = class {
16003
16016
  this.rootSpan = null;
16004
16017
  this.rootCtx = null;
16005
16018
  }
16019
+ /** Return the active eval span's trace ID and span ID for Braintrust trace bridging */
16020
+ getActiveSpanIds() {
16021
+ if (!this.rootSpan) return null;
16022
+ try {
16023
+ const spanCtx = this.rootSpan.spanContext?.() ?? this.rootSpan._spanContext;
16024
+ if (!spanCtx?.traceId || !spanCtx?.spanId) return null;
16025
+ return { parentSpanId: spanCtx.spanId, rootSpanId: spanCtx.traceId };
16026
+ } catch {
16027
+ return null;
16028
+ }
16029
+ }
16006
16030
  /** Get ProviderStreamCallbacks for passing to providers */
16007
16031
  getStreamCallbacks() {
16008
16032
  return {
16009
16033
  onToolCallEnd: (name, input, output, durationMs, toolCallId) => this.onToolCall(name, input, output, durationMs, toolCallId),
16010
- onLlmCallEnd: (model, tokenUsage) => this.onLlmCall(model, tokenUsage)
16034
+ onLlmCallEnd: (model, tokenUsage) => this.onLlmCall(model, tokenUsage),
16035
+ getActiveSpanIds: () => this.getActiveSpanIds()
16011
16036
  };
16012
16037
  }
16013
16038
  };