bitfab 0.53.1 → 0.53.2

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BitfabError
3
- } from "./chunk-ZNY2HZT3.js";
3
+ } from "./chunk-S4UK5HNW.js";
4
4
 
5
5
  // src/codeChange.ts
6
6
  var NUL = String.fromCharCode(0);
@@ -207,7 +207,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
207
207
  sessionId: seedCase.sessionId
208
208
  })
209
209
  );
210
- const { flushTraces: flushTraces2 } = await import("./http-7QLUPC6F.js");
210
+ const { flushTraces: flushTraces2 } = await import("./http-LOZSAC23.js");
211
211
  await flushTraces2(3e4);
212
212
  return { pipeline, traceFunctionKey, traceIds };
213
213
  }
@@ -744,4 +744,4 @@ export {
744
744
  runRegistryMain,
745
745
  runIfEntrypoint
746
746
  };
747
- //# sourceMappingURL=chunk-ZEGNMZU7.js.map
747
+ //# sourceMappingURL=chunk-3LSPOHL7.js.map
@@ -19,7 +19,7 @@ import {
19
19
  serializeValue,
20
20
  toJsonSafe,
21
21
  toJsonSafeReport
22
- } from "./chunk-MMT5MWG5.js";
22
+ } from "./chunk-V3KD7B3B.js";
23
23
  import {
24
24
  BitfabError,
25
25
  DEFAULT_SERVICE_URL,
@@ -35,7 +35,7 @@ import {
35
35
  recordCallerTraceMetadata,
36
36
  retireTraceMetadata,
37
37
  warnOnce
38
- } from "./chunk-ASMHSKFS.js";
38
+ } from "./chunk-JZAKQDGR.js";
39
39
  import {
40
40
  __privateAdd,
41
41
  __privateGet,
@@ -2482,6 +2482,15 @@ function runWithSeedContext(ctx, fn) {
2482
2482
  return fn();
2483
2483
  }
2484
2484
 
2485
+ // src/streamFinalizationError.ts
2486
+ var StreamFinalizationError = class extends Error {
2487
+ constructor(message, output) {
2488
+ super(message);
2489
+ this.output = output;
2490
+ this.name = "StreamFinalizationError";
2491
+ }
2492
+ };
2493
+
2485
2494
  // src/tracing.ts
2486
2495
  var BitfabOpenAITracingProcessor = class {
2487
2496
  /**
@@ -2749,52 +2758,110 @@ function summarizeGenerate(result, model) {
2749
2758
  }
2750
2759
  return summary;
2751
2760
  }
2752
- function accumulateStream(onComplete, model) {
2761
+ function accumulateStream(source, onComplete, model) {
2762
+ const reader = source.getReader();
2753
2763
  let text = "";
2754
2764
  const toolCalls = [];
2755
2765
  let usage;
2756
2766
  let finishReason;
2757
2767
  let completed = false;
2758
- const complete = () => {
2768
+ let streamFailure;
2769
+ const complete = (failure = streamFailure) => {
2759
2770
  if (completed) {
2760
2771
  return;
2761
2772
  }
2762
2773
  completed = true;
2763
- const summary = {
2774
+ let error;
2775
+ if (failure !== void 0) {
2776
+ try {
2777
+ error = failure.error instanceof Error ? failure.error.message : String(
2778
+ failure.error ?? (failure.cancelled === true ? "Stream cancelled" : "Stream failed")
2779
+ );
2780
+ } catch {
2781
+ error = "Stream failed";
2782
+ }
2783
+ }
2784
+ onComplete({
2764
2785
  text,
2765
2786
  toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
2766
2787
  usage,
2767
- finishReason
2768
- };
2769
- if (model) {
2770
- summary.model = model;
2771
- }
2772
- onComplete(summary);
2788
+ finishReason,
2789
+ ...model !== void 0 && { model },
2790
+ ...failure !== void 0 && { error },
2791
+ ...failure?.cancelled === true && { cancelled: true }
2792
+ });
2773
2793
  };
2774
- return new TransformStream({
2775
- transform(part, controller) {
2776
- try {
2777
- if (part?.type === "text-delta") {
2778
- text += part.delta ?? part.textDelta ?? "";
2779
- } else if (part?.type === "tool-call") {
2780
- toolCalls.push({
2781
- toolCallId: part.toolCallId,
2782
- toolName: part.toolName,
2783
- input: part.input ?? part.args
2784
- });
2785
- } else if (part?.type === "finish") {
2786
- usage = part.usage;
2787
- finishReason = part.finishReason;
2788
- complete();
2794
+ return new ReadableStream(
2795
+ {
2796
+ start(controller) {
2797
+ void reader.closed.then(
2798
+ () => {
2799
+ queueMicrotask(() => {
2800
+ if (!completed) {
2801
+ complete();
2802
+ reader.releaseLock();
2803
+ controller.close();
2804
+ }
2805
+ });
2806
+ },
2807
+ (error) => {
2808
+ if (!completed) {
2809
+ complete({ error });
2810
+ controller.error(error);
2811
+ reader.releaseLock();
2812
+ }
2813
+ }
2814
+ );
2815
+ },
2816
+ async pull(controller) {
2817
+ try {
2818
+ const { done, value: part } = await reader.read();
2819
+ if (completed) {
2820
+ return;
2821
+ }
2822
+ if (done) {
2823
+ complete();
2824
+ reader.releaseLock();
2825
+ controller.close();
2826
+ return;
2827
+ }
2828
+ try {
2829
+ if (part?.type === "text-delta") {
2830
+ text += part.delta ?? part.textDelta ?? "";
2831
+ } else if (part?.type === "tool-call") {
2832
+ toolCalls.push({
2833
+ toolCallId: part.toolCallId,
2834
+ toolName: part.toolName,
2835
+ input: part.input ?? part.args
2836
+ });
2837
+ } else if (part?.type === "error") {
2838
+ streamFailure = { error: part.error };
2839
+ } else if (part?.type === "finish") {
2840
+ usage = part.usage;
2841
+ finishReason = part.finishReason;
2842
+ }
2843
+ } catch {
2844
+ }
2845
+ controller.enqueue(part);
2846
+ } catch (error) {
2847
+ if (!completed) {
2848
+ complete({ error });
2849
+ reader.releaseLock();
2850
+ controller.error(error);
2851
+ }
2852
+ }
2853
+ },
2854
+ async cancel(reason) {
2855
+ complete({ error: reason, cancelled: true });
2856
+ try {
2857
+ await reader.cancel(reason);
2858
+ } finally {
2859
+ reader.releaseLock();
2789
2860
  }
2790
- } catch {
2791
2861
  }
2792
- controller.enqueue(part);
2793
2862
  },
2794
- flush() {
2795
- complete();
2796
- }
2797
- });
2863
+ { highWaterMark: 0 }
2864
+ );
2798
2865
  }
2799
2866
  var BitfabVercelAiHandler = class {
2800
2867
  constructor(config) {
@@ -2835,14 +2902,22 @@ var BitfabVercelAiHandler = class {
2835
2902
  // awaits the summary the accumulator resolves once the stream drains.
2836
2903
  {
2837
2904
  type: "llm",
2838
- finalize: () => summary,
2905
+ finalize: async () => {
2906
+ const output = await summary;
2907
+ if (output.error !== void 0) {
2908
+ throw new StreamFinalizationError(output.error, output);
2909
+ }
2910
+ return output;
2911
+ },
2839
2912
  surface: "inherit",
2840
2913
  instrumentation: "vercel-ai"
2841
2914
  },
2842
2915
  async () => {
2843
2916
  const result = await doStream();
2844
- const stream = result.stream.pipeThrough(
2845
- accumulateStream(resolveSummary, label)
2917
+ const stream = accumulateStream(
2918
+ result.stream,
2919
+ resolveSummary,
2920
+ label
2846
2921
  );
2847
2922
  return { ...result, stream };
2848
2923
  }
@@ -4336,8 +4411,8 @@ var Bitfab = class {
4336
4411
  void self.httpClient.trackDeferred(
4337
4412
  Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
4338
4413
  (error) => sendSpan({
4339
- result: void 0,
4340
- error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
4414
+ result: error instanceof StreamFinalizationError ? error.output : void 0,
4415
+ error: error instanceof StreamFinalizationError ? error.message : error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
4341
4416
  })
4342
4417
  )
4343
4418
  );
@@ -4983,7 +5058,7 @@ var Bitfab = class {
4983
5058
  await runWithSeedContext({ traceId }, async () => target(...args));
4984
5059
  } finally {
4985
5060
  try {
4986
- const { flushTraces: flushTraces2 } = await import("./http-2OOKOZQ3.js");
5061
+ const { flushTraces: flushTraces2 } = await import("./http-PUEEHMKU.js");
4987
5062
  await flushTraces2(3e4);
4988
5063
  } finally {
4989
5064
  unrecorded = activeTraceStates.delete(traceId);
@@ -5042,7 +5117,7 @@ var Bitfab = class {
5042
5117
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
5043
5118
  );
5044
5119
  }
5045
- const { replay: doReplay } = await import("./replay-KJKIGXRH.js");
5120
+ const { replay: doReplay } = await import("./replay-SSJ72WEI.js");
5046
5121
  return doReplay(
5047
5122
  this.httpClient,
5048
5123
  this.serviceUrl,
@@ -5326,7 +5401,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
5326
5401
  sessionId: seedCase.sessionId
5327
5402
  })
5328
5403
  );
5329
- const { flushTraces: flushTraces2 } = await import("./http-2OOKOZQ3.js");
5404
+ const { flushTraces: flushTraces2 } = await import("./http-PUEEHMKU.js");
5330
5405
  await flushTraces2(3e4);
5331
5406
  return { pipeline, traceFunctionKey, traceIds };
5332
5407
  }
@@ -5363,4 +5438,4 @@ export {
5363
5438
  reseedFromRegistry,
5364
5439
  seedFromRegistry
5365
5440
  };
5366
- //# sourceMappingURL=chunk-ZCOZHNAA.js.map
5441
+ //# sourceMappingURL=chunk-6SPWEVFD.js.map