bitfab 0.53.1 → 0.53.3

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
@@ -1069,9 +1069,9 @@ declare class BitfabClaudeAgentHandler {
1069
1069
  * The span records the call parameters (the prompt/messages) as its input and a
1070
1070
  * serializable summary (`{ text, toolCalls, usage, finishReason }`) as its
1071
1071
  * output. Streaming is handled by passing the model's stream through a
1072
- * transform that accumulates the assembled text/usage as the caller consumes
1073
- * it: the live stream is handed back unchanged (first-byte latency untouched)
1074
- * and the span is finalized once the stream completes.
1072
+ * reader that accumulates text and usage as the caller consumes it. Parts,
1073
+ * upstream errors, and cancellation propagate to the caller unchanged; the
1074
+ * span finalizes on completion, error, or cancellation with partial output.
1075
1075
  *
1076
1076
  * The middleware is fully duck-typed (no static or dynamic `ai` import), so it
1077
1077
  * adds no dependency and is browser-safe. It works with `ai` v5 and v6.
@@ -1112,6 +1112,7 @@ interface VercelGenerateResult {
1112
1112
  /** Duck-typed subset of a single streaming part from `doStream`. */
1113
1113
  interface VercelStreamPart {
1114
1114
  type: string;
1115
+ error?: unknown;
1115
1116
  delta?: string;
1116
1117
  textDelta?: string;
1117
1118
  toolCallId?: string;
@@ -3343,7 +3344,7 @@ interface CommitRef {
3343
3344
  /**
3344
3345
  * SDK version from package.json (injected at build time)
3345
3346
  */
3346
- declare const __version__ = "0.53.1";
3347
+ declare const __version__ = "0.53.3";
3347
3348
 
3348
3349
  /**
3349
3350
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -1069,9 +1069,9 @@ declare class BitfabClaudeAgentHandler {
1069
1069
  * The span records the call parameters (the prompt/messages) as its input and a
1070
1070
  * serializable summary (`{ text, toolCalls, usage, finishReason }`) as its
1071
1071
  * output. Streaming is handled by passing the model's stream through a
1072
- * transform that accumulates the assembled text/usage as the caller consumes
1073
- * it: the live stream is handed back unchanged (first-byte latency untouched)
1074
- * and the span is finalized once the stream completes.
1072
+ * reader that accumulates text and usage as the caller consumes it. Parts,
1073
+ * upstream errors, and cancellation propagate to the caller unchanged; the
1074
+ * span finalizes on completion, error, or cancellation with partial output.
1075
1075
  *
1076
1076
  * The middleware is fully duck-typed (no static or dynamic `ai` import), so it
1077
1077
  * adds no dependency and is browser-safe. It works with `ai` v5 and v6.
@@ -1112,6 +1112,7 @@ interface VercelGenerateResult {
1112
1112
  /** Duck-typed subset of a single streaming part from `doStream`. */
1113
1113
  interface VercelStreamPart {
1114
1114
  type: string;
1115
+ error?: unknown;
1115
1116
  delta?: string;
1116
1117
  textDelta?: string;
1117
1118
  toolCallId?: string;
@@ -3343,7 +3344,7 @@ interface CommitRef {
3343
3344
  /**
3344
3345
  * SDK version from package.json (injected at build time)
3345
3346
  */
3346
- declare const __version__ = "0.53.1";
3347
+ declare const __version__ = "0.53.3";
3347
3348
 
3348
3349
  /**
3349
3350
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  getCurrentTrace,
29
29
  reseedFromRegistry,
30
30
  seedFromRegistry
31
- } from "./chunk-ZCOZHNAA.js";
31
+ } from "./chunk-JFDOUOBS.js";
32
32
  import "./chunk-E5BLYL5X.js";
33
33
  import {
34
34
  BITFAB_PROGRESS_PREFIX,
@@ -37,7 +37,7 @@ import {
37
37
  ReplayError,
38
38
  reportReplayProgress,
39
39
  serializeReplayResult
40
- } from "./chunk-MMT5MWG5.js";
40
+ } from "./chunk-QVRPMSFH.js";
41
41
  import {
42
42
  BitfabError,
43
43
  DEFAULT_SERVICE_URL,
@@ -45,7 +45,7 @@ import {
45
45
  MixedTracingError,
46
46
  __version__,
47
47
  flushTraces
48
- } from "./chunk-ASMHSKFS.js";
48
+ } from "./chunk-LOQOG2MW.js";
49
49
  import "./chunk-H6LZRFMN.js";
50
50
  export {
51
51
  BITFAB_PROGRESS_PREFIX,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.53.1";
100
+ __version__ = "0.53.3";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -6733,6 +6733,17 @@ function runWithSeedContext(ctx, fn) {
6733
6733
  init_serialize();
6734
6734
  init_simulationPlan();
6735
6735
  init_spanOrigin();
6736
+
6737
+ // src/streamFinalizationError.ts
6738
+ var StreamFinalizationError = class extends Error {
6739
+ constructor(message, output) {
6740
+ super(message);
6741
+ this.output = output;
6742
+ this.name = "StreamFinalizationError";
6743
+ }
6744
+ };
6745
+
6746
+ // src/client.ts
6736
6747
  init_traceMetadata();
6737
6748
 
6738
6749
  // src/tracing.ts
@@ -7006,52 +7017,110 @@ function summarizeGenerate(result, model) {
7006
7017
  }
7007
7018
  return summary;
7008
7019
  }
7009
- function accumulateStream(onComplete, model) {
7020
+ function accumulateStream(source, onComplete, model) {
7021
+ const reader = source.getReader();
7010
7022
  let text = "";
7011
7023
  const toolCalls = [];
7012
7024
  let usage;
7013
7025
  let finishReason;
7014
7026
  let completed = false;
7015
- const complete = () => {
7027
+ let streamFailure;
7028
+ const complete = (failure = streamFailure) => {
7016
7029
  if (completed) {
7017
7030
  return;
7018
7031
  }
7019
7032
  completed = true;
7020
- const summary = {
7033
+ let error;
7034
+ if (failure !== void 0) {
7035
+ try {
7036
+ error = failure.error instanceof Error ? failure.error.message : String(
7037
+ failure.error ?? (failure.cancelled === true ? "Stream cancelled" : "Stream failed")
7038
+ );
7039
+ } catch {
7040
+ error = "Stream failed";
7041
+ }
7042
+ }
7043
+ onComplete({
7021
7044
  text,
7022
7045
  toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
7023
7046
  usage,
7024
- finishReason
7025
- };
7026
- if (model) {
7027
- summary.model = model;
7028
- }
7029
- onComplete(summary);
7047
+ finishReason,
7048
+ ...model !== void 0 && { model },
7049
+ ...failure !== void 0 && { error },
7050
+ ...failure?.cancelled === true && { cancelled: true }
7051
+ });
7030
7052
  };
7031
- return new TransformStream({
7032
- transform(part, controller) {
7033
- try {
7034
- if (part?.type === "text-delta") {
7035
- text += part.delta ?? part.textDelta ?? "";
7036
- } else if (part?.type === "tool-call") {
7037
- toolCalls.push({
7038
- toolCallId: part.toolCallId,
7039
- toolName: part.toolName,
7040
- input: part.input ?? part.args
7041
- });
7042
- } else if (part?.type === "finish") {
7043
- usage = part.usage;
7044
- finishReason = part.finishReason;
7045
- complete();
7053
+ return new ReadableStream(
7054
+ {
7055
+ start(controller) {
7056
+ void reader.closed.then(
7057
+ () => {
7058
+ queueMicrotask(() => {
7059
+ if (!completed) {
7060
+ complete();
7061
+ reader.releaseLock();
7062
+ controller.close();
7063
+ }
7064
+ });
7065
+ },
7066
+ (error) => {
7067
+ if (!completed) {
7068
+ complete({ error });
7069
+ controller.error(error);
7070
+ reader.releaseLock();
7071
+ }
7072
+ }
7073
+ );
7074
+ },
7075
+ async pull(controller) {
7076
+ try {
7077
+ const { done, value: part } = await reader.read();
7078
+ if (completed) {
7079
+ return;
7080
+ }
7081
+ if (done) {
7082
+ complete();
7083
+ reader.releaseLock();
7084
+ controller.close();
7085
+ return;
7086
+ }
7087
+ try {
7088
+ if (part?.type === "text-delta") {
7089
+ text += part.delta ?? part.textDelta ?? "";
7090
+ } else if (part?.type === "tool-call") {
7091
+ toolCalls.push({
7092
+ toolCallId: part.toolCallId,
7093
+ toolName: part.toolName,
7094
+ input: part.input ?? part.args
7095
+ });
7096
+ } else if (part?.type === "error") {
7097
+ streamFailure = { error: part.error };
7098
+ } else if (part?.type === "finish") {
7099
+ usage = part.usage;
7100
+ finishReason = part.finishReason;
7101
+ }
7102
+ } catch {
7103
+ }
7104
+ controller.enqueue(part);
7105
+ } catch (error) {
7106
+ if (!completed) {
7107
+ complete({ error });
7108
+ reader.releaseLock();
7109
+ controller.error(error);
7110
+ }
7111
+ }
7112
+ },
7113
+ async cancel(reason) {
7114
+ complete({ error: reason, cancelled: true });
7115
+ try {
7116
+ await reader.cancel(reason);
7117
+ } finally {
7118
+ reader.releaseLock();
7046
7119
  }
7047
- } catch {
7048
7120
  }
7049
- controller.enqueue(part);
7050
7121
  },
7051
- flush() {
7052
- complete();
7053
- }
7054
- });
7122
+ { highWaterMark: 0 }
7123
+ );
7055
7124
  }
7056
7125
  var BitfabVercelAiHandler = class {
7057
7126
  constructor(config) {
@@ -7092,14 +7161,22 @@ var BitfabVercelAiHandler = class {
7092
7161
  // awaits the summary the accumulator resolves once the stream drains.
7093
7162
  {
7094
7163
  type: "llm",
7095
- finalize: () => summary,
7164
+ finalize: async () => {
7165
+ const output = await summary;
7166
+ if (output.error !== void 0) {
7167
+ throw new StreamFinalizationError(output.error, output);
7168
+ }
7169
+ return output;
7170
+ },
7096
7171
  surface: "inherit",
7097
7172
  instrumentation: "vercel-ai"
7098
7173
  },
7099
7174
  async () => {
7100
7175
  const result = await doStream();
7101
- const stream = result.stream.pipeThrough(
7102
- accumulateStream(resolveSummary, label)
7176
+ const stream = accumulateStream(
7177
+ result.stream,
7178
+ resolveSummary,
7179
+ label
7103
7180
  );
7104
7181
  return { ...result, stream };
7105
7182
  }
@@ -8594,8 +8671,8 @@ var Bitfab = class {
8594
8671
  void self.httpClient.trackDeferred(
8595
8672
  Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch(
8596
8673
  (error) => sendSpan({
8597
- result: void 0,
8598
- error: error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
8674
+ result: error instanceof StreamFinalizationError ? error.output : void 0,
8675
+ error: error instanceof StreamFinalizationError ? error.message : error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
8599
8676
  })
8600
8677
  )
8601
8678
  );