@bitfab/sdk 0.36.3 → 0.36.5

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
@@ -1878,6 +1878,27 @@ interface SpanOptions {
1878
1878
  */
1879
1879
  finalize?: (result: any) => unknown | Promise<unknown>;
1880
1880
  }
1881
+ /**
1882
+ * The standard method context passed to a decorator.
1883
+ *
1884
+ * Defined structurally instead of referencing TypeScript's built-in
1885
+ * `ClassMethodDecoratorContext`, which was added in TypeScript 5.0. This keeps
1886
+ * the SDK's non-decorator APIs consumable by projects on older compilers.
1887
+ */
1888
+ interface SpanMethodDecoratorContext<TThis, TValue> {
1889
+ readonly kind: "method";
1890
+ readonly name: string | symbol;
1891
+ readonly static: boolean;
1892
+ readonly private: boolean;
1893
+ readonly access: {
1894
+ has(object: TThis): boolean;
1895
+ get(object: TThis): TValue;
1896
+ };
1897
+ addInitializer(initializer: (this: TThis) => void): void;
1898
+ readonly metadata?: Record<PropertyKey, unknown>;
1899
+ }
1900
+ /** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
1901
+ type SpanMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(originalMethod: (this: TThis, ...args: TArgs) => TReturn, context: SpanMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>) => (this: TThis, ...args: TArgs) => TReturn;
1881
1902
 
1882
1903
  /**
1883
1904
  * Client for making provider-based API calls via BAML.
@@ -2148,6 +2169,31 @@ declare class Bitfab {
2148
2169
  * @returns A wrapped function with the same signature that creates spans for inputs and outputs
2149
2170
  */
2150
2171
  withSpan<TArgs extends unknown[], TReturn>(traceFunctionKey: string, optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
2172
+ /**
2173
+ * Create a standard ECMAScript method decorator that records each invocation
2174
+ * as a span.
2175
+ *
2176
+ * It supports instance, static, and private methods; use
2177
+ * {@link Bitfab.withSpan} for standalone functions, class fields, and
2178
+ * accessors.
2179
+ *
2180
+ * @example
2181
+ * ```typescript
2182
+ * const bitfab = new Bitfab({ apiKey: process.env.BITFAB_API_KEY });
2183
+ *
2184
+ * class OrderService {
2185
+ * @bitfab.span("order-processing", { type: "agent" })
2186
+ * async process(orderId: string) {
2187
+ * return { orderId };
2188
+ * }
2189
+ * }
2190
+ * ```
2191
+ *
2192
+ * @param traceFunctionKey - A string identifier for grouping spans
2193
+ * @param options - Span configuration applied to the decorated method
2194
+ * @returns A standard ECMAScript method decorator
2195
+ */
2196
+ span(traceFunctionKey: string, options?: SpanOptions): SpanMethodDecorator;
2151
2197
  /**
2152
2198
  * Get a detached handle to a previously-created trace, looked up by the
2153
2199
  * canonical Bitfab trace ID.
@@ -2292,6 +2338,25 @@ declare class BitfabFunction {
2292
2338
  * @returns A wrapped function with the same signature that creates spans
2293
2339
  */
2294
2340
  withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
2341
+ /**
2342
+ * Create a standard ECMAScript method decorator bound to this function key.
2343
+ *
2344
+ * @example
2345
+ * ```typescript
2346
+ * const orders = client.getFunction("order-processing");
2347
+ *
2348
+ * class OrderService {
2349
+ * @orders.span({ type: "agent" })
2350
+ * async process(orderId: string) {
2351
+ * return { orderId };
2352
+ * }
2353
+ * }
2354
+ * ```
2355
+ *
2356
+ * @param options - Span configuration applied to the decorated method
2357
+ * @returns A standard ECMAScript method decorator
2358
+ */
2359
+ span(options?: SpanOptions): SpanMethodDecorator;
2295
2360
  /**
2296
2361
  * Get a Vercel AI SDK language-model middleware bound to this function's key.
2297
2362
  *
@@ -2399,7 +2464,7 @@ declare class BitfabFunction {
2399
2464
  /**
2400
2465
  * SDK version from package.json (injected at build time)
2401
2466
  */
2402
- declare const __version__ = "0.36.3";
2467
+ declare const __version__ = "0.36.5";
2403
2468
 
2404
2469
  /**
2405
2470
  * Constants for the Bitfab SDK.
@@ -2467,4 +2532,4 @@ declare const finalizers: {
2467
2532
  readableStream: typeof readableStream;
2468
2533
  };
2469
2534
 
2470
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2535
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -1878,6 +1878,27 @@ interface SpanOptions {
1878
1878
  */
1879
1879
  finalize?: (result: any) => unknown | Promise<unknown>;
1880
1880
  }
1881
+ /**
1882
+ * The standard method context passed to a decorator.
1883
+ *
1884
+ * Defined structurally instead of referencing TypeScript's built-in
1885
+ * `ClassMethodDecoratorContext`, which was added in TypeScript 5.0. This keeps
1886
+ * the SDK's non-decorator APIs consumable by projects on older compilers.
1887
+ */
1888
+ interface SpanMethodDecoratorContext<TThis, TValue> {
1889
+ readonly kind: "method";
1890
+ readonly name: string | symbol;
1891
+ readonly static: boolean;
1892
+ readonly private: boolean;
1893
+ readonly access: {
1894
+ has(object: TThis): boolean;
1895
+ get(object: TThis): TValue;
1896
+ };
1897
+ addInitializer(initializer: (this: TThis) => void): void;
1898
+ readonly metadata?: Record<PropertyKey, unknown>;
1899
+ }
1900
+ /** A standard ECMAScript method decorator produced by {@link Bitfab.span}. */
1901
+ type SpanMethodDecorator = <TThis, TArgs extends unknown[], TReturn>(originalMethod: (this: TThis, ...args: TArgs) => TReturn, context: SpanMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>) => (this: TThis, ...args: TArgs) => TReturn;
1881
1902
 
1882
1903
  /**
1883
1904
  * Client for making provider-based API calls via BAML.
@@ -2148,6 +2169,31 @@ declare class Bitfab {
2148
2169
  * @returns A wrapped function with the same signature that creates spans for inputs and outputs
2149
2170
  */
2150
2171
  withSpan<TArgs extends unknown[], TReturn>(traceFunctionKey: string, optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
2172
+ /**
2173
+ * Create a standard ECMAScript method decorator that records each invocation
2174
+ * as a span.
2175
+ *
2176
+ * It supports instance, static, and private methods; use
2177
+ * {@link Bitfab.withSpan} for standalone functions, class fields, and
2178
+ * accessors.
2179
+ *
2180
+ * @example
2181
+ * ```typescript
2182
+ * const bitfab = new Bitfab({ apiKey: process.env.BITFAB_API_KEY });
2183
+ *
2184
+ * class OrderService {
2185
+ * @bitfab.span("order-processing", { type: "agent" })
2186
+ * async process(orderId: string) {
2187
+ * return { orderId };
2188
+ * }
2189
+ * }
2190
+ * ```
2191
+ *
2192
+ * @param traceFunctionKey - A string identifier for grouping spans
2193
+ * @param options - Span configuration applied to the decorated method
2194
+ * @returns A standard ECMAScript method decorator
2195
+ */
2196
+ span(traceFunctionKey: string, options?: SpanOptions): SpanMethodDecorator;
2151
2197
  /**
2152
2198
  * Get a detached handle to a previously-created trace, looked up by the
2153
2199
  * canonical Bitfab trace ID.
@@ -2292,6 +2338,25 @@ declare class BitfabFunction {
2292
2338
  * @returns A wrapped function with the same signature that creates spans
2293
2339
  */
2294
2340
  withSpan<TArgs extends unknown[], TReturn>(optionsOrFn: SpanOptions | ((...args: TArgs) => TReturn), maybeFn?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
2341
+ /**
2342
+ * Create a standard ECMAScript method decorator bound to this function key.
2343
+ *
2344
+ * @example
2345
+ * ```typescript
2346
+ * const orders = client.getFunction("order-processing");
2347
+ *
2348
+ * class OrderService {
2349
+ * @orders.span({ type: "agent" })
2350
+ * async process(orderId: string) {
2351
+ * return { orderId };
2352
+ * }
2353
+ * }
2354
+ * ```
2355
+ *
2356
+ * @param options - Span configuration applied to the decorated method
2357
+ * @returns A standard ECMAScript method decorator
2358
+ */
2359
+ span(options?: SpanOptions): SpanMethodDecorator;
2295
2360
  /**
2296
2361
  * Get a Vercel AI SDK language-model middleware bound to this function's key.
2297
2362
  *
@@ -2399,7 +2464,7 @@ declare class BitfabFunction {
2399
2464
  /**
2400
2465
  * SDK version from package.json (injected at build time)
2401
2466
  */
2402
- declare const __version__ = "0.36.3";
2467
+ declare const __version__ = "0.36.5";
2403
2468
 
2404
2469
  /**
2405
2470
  * Constants for the Bitfab SDK.
@@ -2467,4 +2532,4 @@ declare const finalizers: {
2467
2532
  readableStream: typeof readableStream;
2468
2533
  };
2469
2534
 
2470
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
2535
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type MockOverride, type MockOverrideCtx, type MockStrategy, type MockValue, type NodeMatcher, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayOptions, type ReplayProgress, type ReplayResult, SUPPORTED_PROVIDERS, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, serializeReplayResult };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  getCurrentReplayBranch,
12
12
  getCurrentSpan,
13
13
  getCurrentTrace
14
- } from "./chunk-4CTDZMG5.js";
14
+ } from "./chunk-IYHBVIPJ.js";
15
15
  import {
16
16
  BITFAB_PROGRESS_PREFIX,
17
17
  BitfabError,
@@ -23,7 +23,7 @@ import {
23
23
  flushTraces,
24
24
  reportReplayProgress,
25
25
  serializeReplayResult
26
- } from "./chunk-M2GISXGV.js";
26
+ } from "./chunk-FLP6CNRE.js";
27
27
  export {
28
28
  BITFAB_PROGRESS_PREFIX,
29
29
  Bitfab,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.36.3";
91
+ __version__ = "0.36.5";
92
92
  }
93
93
  });
94
94
 
@@ -5782,7 +5782,7 @@ var Bitfab = class {
5782
5782
  }
5783
5783
  };
5784
5784
  executeWithContext = () => {
5785
- const result = fn(...args);
5785
+ const result = fn.apply(this, args);
5786
5786
  if (result instanceof Promise) {
5787
5787
  return result.then((resolvedResult) => {
5788
5788
  recordSpan(resolvedResult);
@@ -5812,7 +5812,7 @@ var Bitfab = class {
5812
5812
  `withSpan-setup:${traceFunctionKey}`,
5813
5813
  `tracing setup failed for "${traceFunctionKey}"; running it untraced. The function still runs and returns normally; no span is recorded.`
5814
5814
  );
5815
- return fn(...args);
5815
+ return fn.apply(this, args);
5816
5816
  }
5817
5817
  return runWithSpanStack(newStack, executeWithContext);
5818
5818
  };
@@ -5821,6 +5821,40 @@ var Bitfab = class {
5821
5821
  });
5822
5822
  return wrappedFn;
5823
5823
  }
5824
+ /**
5825
+ * Create a standard ECMAScript method decorator that records each invocation
5826
+ * as a span.
5827
+ *
5828
+ * It supports instance, static, and private methods; use
5829
+ * {@link Bitfab.withSpan} for standalone functions, class fields, and
5830
+ * accessors.
5831
+ *
5832
+ * @example
5833
+ * ```typescript
5834
+ * const bitfab = new Bitfab({ apiKey: process.env.BITFAB_API_KEY });
5835
+ *
5836
+ * class OrderService {
5837
+ * @bitfab.span("order-processing", { type: "agent" })
5838
+ * async process(orderId: string) {
5839
+ * return { orderId };
5840
+ * }
5841
+ * }
5842
+ * ```
5843
+ *
5844
+ * @param traceFunctionKey - A string identifier for grouping spans
5845
+ * @param options - Span configuration applied to the decorated method
5846
+ * @returns A standard ECMAScript method decorator
5847
+ */
5848
+ span(traceFunctionKey, options = {}) {
5849
+ return (originalMethod, context) => {
5850
+ if (context.kind !== "method") {
5851
+ throw new BitfabError(
5852
+ `Bitfab span decorators can only decorate methods; ${String(context.name)} is a ${context.kind}`
5853
+ );
5854
+ }
5855
+ return this.withSpan(traceFunctionKey, options, originalMethod);
5856
+ };
5857
+ }
5824
5858
  /**
5825
5859
  * Get a detached handle to a previously-created trace, looked up by the
5826
5860
  * canonical Bitfab trace ID.
@@ -6097,6 +6131,27 @@ var BitfabFunction = class {
6097
6131
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
6098
6132
  return this.client.withSpan(this.traceFunctionKey, options, fn);
6099
6133
  }
6134
+ /**
6135
+ * Create a standard ECMAScript method decorator bound to this function key.
6136
+ *
6137
+ * @example
6138
+ * ```typescript
6139
+ * const orders = client.getFunction("order-processing");
6140
+ *
6141
+ * class OrderService {
6142
+ * @orders.span({ type: "agent" })
6143
+ * async process(orderId: string) {
6144
+ * return { orderId };
6145
+ * }
6146
+ * }
6147
+ * ```
6148
+ *
6149
+ * @param options - Span configuration applied to the decorated method
6150
+ * @returns A standard ECMAScript method decorator
6151
+ */
6152
+ span(options = {}) {
6153
+ return this.client.span(this.traceFunctionKey, options);
6154
+ }
6100
6155
  /**
6101
6156
  * Get a Vercel AI SDK language-model middleware bound to this function's key.
6102
6157
  *