bitfab 0.39.0 → 0.40.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
@@ -540,7 +540,11 @@ declare class HttpClient {
540
540
  lookupFunction<T>(name: string): Promise<T>;
541
541
  getAutoTracePolicy<T>(traceFunctionKey: string, protocol: string): Promise<T>;
542
542
  getTraceSpan(traceId: string, lookup: SpanLookup): Promise<CapturedSpan | null>;
543
- private get;
543
+ /**
544
+ * GET a JSON endpoint on the service with the client's API key. Throws a
545
+ * `BitfabError` carrying the status text for any non-2xx response.
546
+ */
547
+ get<T>(endpoint: string): Promise<T>;
544
548
  /**
545
549
  * Queue an internal trace (from local BAML execution via `call()`) onto this
546
550
  * client's batching transport. `functionId` moves into the payload because
@@ -1034,6 +1038,141 @@ declare class BitfabVercelAiHandler {
1034
1038
  get middleware(): BitfabLanguageModelMiddleware;
1035
1039
  }
1036
1040
 
1041
+ interface DatasetGraderRef {
1042
+ id: string;
1043
+ name: string | null;
1044
+ }
1045
+ interface Dataset {
1046
+ id: string;
1047
+ traceFunctionKey: string;
1048
+ name: string;
1049
+ description: string | null;
1050
+ traceCount: number;
1051
+ graders: DatasetGraderRef[];
1052
+ createdAt: string;
1053
+ updatedAt: string;
1054
+ }
1055
+ interface SaveDatasetParams {
1056
+ traceFunctionKey: string;
1057
+ name: string;
1058
+ description?: string;
1059
+ }
1060
+ interface SaveDatasetResult {
1061
+ dataset: Dataset;
1062
+ created: boolean;
1063
+ }
1064
+ interface ListDatasetsParams {
1065
+ traceFunctionKey?: string;
1066
+ }
1067
+ interface DatasetTraceIds {
1068
+ datasetId: string;
1069
+ traceIds: string[];
1070
+ }
1071
+ interface AddDatasetTracesResult {
1072
+ dataset: Dataset;
1073
+ addedTraceIds: string[];
1074
+ alreadyPresentTraceIds: string[];
1075
+ skippedTraceIds: string[];
1076
+ }
1077
+ interface RemoveDatasetTracesResult {
1078
+ dataset: Dataset;
1079
+ removedTraceIds: string[];
1080
+ notPresentTraceIds: string[];
1081
+ }
1082
+ interface AddDatasetGradersResult {
1083
+ dataset: Dataset;
1084
+ addedGraderIds: string[];
1085
+ alreadyAssignedGraderIds: string[];
1086
+ skippedGraderIds: string[];
1087
+ }
1088
+ interface RemoveDatasetGradersResult {
1089
+ dataset: Dataset;
1090
+ removedGraderIds: string[];
1091
+ notAssignedGraderIds: string[];
1092
+ }
1093
+ type GraderRerunStatus = "pending" | "running" | "completed" | "errored";
1094
+ interface GraderRerunProgress {
1095
+ completedTraces: number;
1096
+ totalTraces: number;
1097
+ graderCount: number;
1098
+ }
1099
+ interface GraderRerunResult {
1100
+ tracesGraded: number;
1101
+ gradersRun: number;
1102
+ }
1103
+ interface GraderRerun {
1104
+ id: string;
1105
+ status: GraderRerunStatus;
1106
+ graderIds: string[];
1107
+ progress: GraderRerunProgress | null;
1108
+ result: GraderRerunResult | null;
1109
+ error: string | null;
1110
+ createdAt: string;
1111
+ updatedAt: string;
1112
+ }
1113
+ interface RerunGradersOptions {
1114
+ graderIds?: string[];
1115
+ wait?: boolean;
1116
+ timeoutMs?: number;
1117
+ pollIntervalMs?: number;
1118
+ }
1119
+ interface RerunGradersResult {
1120
+ run: GraderRerun;
1121
+ joinedExisting: boolean;
1122
+ }
1123
+ /**
1124
+ * Dataset operations for the authenticated organization, reached as
1125
+ * `client.datasets`. A dataset is a named bucket of traces scoped to one trace
1126
+ * function. Experiments replay against it and its graders score its members.
1127
+ */
1128
+ declare class DatasetsClient {
1129
+ private readonly httpClient;
1130
+ constructor(httpClient: HttpClient);
1131
+ /**
1132
+ * Create a dataset, or update the one already named this way under the same
1133
+ * trace function. `created` reports which happened. An omitted description
1134
+ * leaves an existing one untouched.
1135
+ */
1136
+ save(params: SaveDatasetParams): Promise<SaveDatasetResult>;
1137
+ /**
1138
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
1139
+ * given and organization-wide otherwise.
1140
+ */
1141
+ list(params?: ListDatasetsParams): Promise<Dataset[]>;
1142
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
1143
+ get(datasetId: string): Promise<Dataset>;
1144
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
1145
+ listTraces(datasetId: string): Promise<DatasetTraceIds>;
1146
+ /**
1147
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
1148
+ * organization or under another trace function are reported in
1149
+ * `skippedTraceIds` rather than failing the call.
1150
+ */
1151
+ addTraces(datasetId: string, traceIds: string[]): Promise<AddDatasetTracesResult>;
1152
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
1153
+ removeTraces(datasetId: string, traceIds: string[]): Promise<RemoveDatasetTracesResult>;
1154
+ /**
1155
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
1156
+ * organization or under another trace function are reported in
1157
+ * `skippedGraderIds` rather than failing the call.
1158
+ */
1159
+ addGraders(datasetId: string, graderIds: string[]): Promise<AddDatasetGradersResult>;
1160
+ /** Unassign graders from the dataset. */
1161
+ removeGraders(datasetId: string, graderIds: string[]): Promise<RemoveDatasetGradersResult>;
1162
+ /**
1163
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
1164
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
1165
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
1166
+ * run state seen either way. A request matching an in-flight run joins it.
1167
+ */
1168
+ rerunGraders(datasetId: string, options?: RerunGradersOptions): Promise<RerunGradersResult>;
1169
+ /**
1170
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
1171
+ * `null` when nothing is active or the run does not belong to this dataset.
1172
+ */
1173
+ getGraderRerun(datasetId: string, runId?: string): Promise<GraderRerun | null>;
1174
+ }
1175
+
1037
1176
  /**
1038
1177
  * LangGraph/LangChain callback handler for Bitfab tracing.
1039
1178
  *
@@ -2272,6 +2411,8 @@ declare class Bitfab {
2272
2411
  private readonly explicitlyEnabled;
2273
2412
  private readonly strict;
2274
2413
  private readonly httpClient;
2414
+ /** Dataset operations for the authenticated organization. */
2415
+ readonly datasets: DatasetsClient;
2275
2416
  private readonly bamlClient;
2276
2417
  private readonly dbSnapshot;
2277
2418
  private readonly autoTracePolicyRefreshes;
@@ -2955,7 +3096,7 @@ declare class BitfabFunction {
2955
3096
  /**
2956
3097
  * SDK version from package.json (injected at build time)
2957
3098
  */
2958
- declare const __version__ = "0.39.0";
3099
+ declare const __version__ = "0.40.0";
2959
3100
 
2960
3101
  /**
2961
3102
  * Constants for the Bitfab SDK.
@@ -3083,4 +3224,4 @@ interface SeedResult {
3083
3224
  */
3084
3225
  declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, cases: readonly SeedCase[]): Promise<SeedResult>;
3085
3226
 
3086
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type LangGraphIntegrationOptions, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SeedCase, type SeedResult, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3227
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedResult, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.d.ts CHANGED
@@ -540,7 +540,11 @@ declare class HttpClient {
540
540
  lookupFunction<T>(name: string): Promise<T>;
541
541
  getAutoTracePolicy<T>(traceFunctionKey: string, protocol: string): Promise<T>;
542
542
  getTraceSpan(traceId: string, lookup: SpanLookup): Promise<CapturedSpan | null>;
543
- private get;
543
+ /**
544
+ * GET a JSON endpoint on the service with the client's API key. Throws a
545
+ * `BitfabError` carrying the status text for any non-2xx response.
546
+ */
547
+ get<T>(endpoint: string): Promise<T>;
544
548
  /**
545
549
  * Queue an internal trace (from local BAML execution via `call()`) onto this
546
550
  * client's batching transport. `functionId` moves into the payload because
@@ -1034,6 +1038,141 @@ declare class BitfabVercelAiHandler {
1034
1038
  get middleware(): BitfabLanguageModelMiddleware;
1035
1039
  }
1036
1040
 
1041
+ interface DatasetGraderRef {
1042
+ id: string;
1043
+ name: string | null;
1044
+ }
1045
+ interface Dataset {
1046
+ id: string;
1047
+ traceFunctionKey: string;
1048
+ name: string;
1049
+ description: string | null;
1050
+ traceCount: number;
1051
+ graders: DatasetGraderRef[];
1052
+ createdAt: string;
1053
+ updatedAt: string;
1054
+ }
1055
+ interface SaveDatasetParams {
1056
+ traceFunctionKey: string;
1057
+ name: string;
1058
+ description?: string;
1059
+ }
1060
+ interface SaveDatasetResult {
1061
+ dataset: Dataset;
1062
+ created: boolean;
1063
+ }
1064
+ interface ListDatasetsParams {
1065
+ traceFunctionKey?: string;
1066
+ }
1067
+ interface DatasetTraceIds {
1068
+ datasetId: string;
1069
+ traceIds: string[];
1070
+ }
1071
+ interface AddDatasetTracesResult {
1072
+ dataset: Dataset;
1073
+ addedTraceIds: string[];
1074
+ alreadyPresentTraceIds: string[];
1075
+ skippedTraceIds: string[];
1076
+ }
1077
+ interface RemoveDatasetTracesResult {
1078
+ dataset: Dataset;
1079
+ removedTraceIds: string[];
1080
+ notPresentTraceIds: string[];
1081
+ }
1082
+ interface AddDatasetGradersResult {
1083
+ dataset: Dataset;
1084
+ addedGraderIds: string[];
1085
+ alreadyAssignedGraderIds: string[];
1086
+ skippedGraderIds: string[];
1087
+ }
1088
+ interface RemoveDatasetGradersResult {
1089
+ dataset: Dataset;
1090
+ removedGraderIds: string[];
1091
+ notAssignedGraderIds: string[];
1092
+ }
1093
+ type GraderRerunStatus = "pending" | "running" | "completed" | "errored";
1094
+ interface GraderRerunProgress {
1095
+ completedTraces: number;
1096
+ totalTraces: number;
1097
+ graderCount: number;
1098
+ }
1099
+ interface GraderRerunResult {
1100
+ tracesGraded: number;
1101
+ gradersRun: number;
1102
+ }
1103
+ interface GraderRerun {
1104
+ id: string;
1105
+ status: GraderRerunStatus;
1106
+ graderIds: string[];
1107
+ progress: GraderRerunProgress | null;
1108
+ result: GraderRerunResult | null;
1109
+ error: string | null;
1110
+ createdAt: string;
1111
+ updatedAt: string;
1112
+ }
1113
+ interface RerunGradersOptions {
1114
+ graderIds?: string[];
1115
+ wait?: boolean;
1116
+ timeoutMs?: number;
1117
+ pollIntervalMs?: number;
1118
+ }
1119
+ interface RerunGradersResult {
1120
+ run: GraderRerun;
1121
+ joinedExisting: boolean;
1122
+ }
1123
+ /**
1124
+ * Dataset operations for the authenticated organization, reached as
1125
+ * `client.datasets`. A dataset is a named bucket of traces scoped to one trace
1126
+ * function. Experiments replay against it and its graders score its members.
1127
+ */
1128
+ declare class DatasetsClient {
1129
+ private readonly httpClient;
1130
+ constructor(httpClient: HttpClient);
1131
+ /**
1132
+ * Create a dataset, or update the one already named this way under the same
1133
+ * trace function. `created` reports which happened. An omitted description
1134
+ * leaves an existing one untouched.
1135
+ */
1136
+ save(params: SaveDatasetParams): Promise<SaveDatasetResult>;
1137
+ /**
1138
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
1139
+ * given and organization-wide otherwise.
1140
+ */
1141
+ list(params?: ListDatasetsParams): Promise<Dataset[]>;
1142
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
1143
+ get(datasetId: string): Promise<Dataset>;
1144
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
1145
+ listTraces(datasetId: string): Promise<DatasetTraceIds>;
1146
+ /**
1147
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
1148
+ * organization or under another trace function are reported in
1149
+ * `skippedTraceIds` rather than failing the call.
1150
+ */
1151
+ addTraces(datasetId: string, traceIds: string[]): Promise<AddDatasetTracesResult>;
1152
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
1153
+ removeTraces(datasetId: string, traceIds: string[]): Promise<RemoveDatasetTracesResult>;
1154
+ /**
1155
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
1156
+ * organization or under another trace function are reported in
1157
+ * `skippedGraderIds` rather than failing the call.
1158
+ */
1159
+ addGraders(datasetId: string, graderIds: string[]): Promise<AddDatasetGradersResult>;
1160
+ /** Unassign graders from the dataset. */
1161
+ removeGraders(datasetId: string, graderIds: string[]): Promise<RemoveDatasetGradersResult>;
1162
+ /**
1163
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
1164
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
1165
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
1166
+ * run state seen either way. A request matching an in-flight run joins it.
1167
+ */
1168
+ rerunGraders(datasetId: string, options?: RerunGradersOptions): Promise<RerunGradersResult>;
1169
+ /**
1170
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
1171
+ * `null` when nothing is active or the run does not belong to this dataset.
1172
+ */
1173
+ getGraderRerun(datasetId: string, runId?: string): Promise<GraderRerun | null>;
1174
+ }
1175
+
1037
1176
  /**
1038
1177
  * LangGraph/LangChain callback handler for Bitfab tracing.
1039
1178
  *
@@ -2272,6 +2411,8 @@ declare class Bitfab {
2272
2411
  private readonly explicitlyEnabled;
2273
2412
  private readonly strict;
2274
2413
  private readonly httpClient;
2414
+ /** Dataset operations for the authenticated organization. */
2415
+ readonly datasets: DatasetsClient;
2275
2416
  private readonly bamlClient;
2276
2417
  private readonly dbSnapshot;
2277
2418
  private readonly autoTracePolicyRefreshes;
@@ -2955,7 +3096,7 @@ declare class BitfabFunction {
2955
3096
  /**
2956
3097
  * SDK version from package.json (injected at build time)
2957
3098
  */
2958
- declare const __version__ = "0.39.0";
3099
+ declare const __version__ = "0.40.0";
2959
3100
 
2960
3101
  /**
2961
3102
  * Constants for the Bitfab SDK.
@@ -3083,4 +3224,4 @@ interface SeedResult {
3083
3224
  */
3084
3225
  declare function seedFromRegistry(registry: ReplayRegistry, pipeline: string, cases: readonly SeedCase[]): Promise<SeedResult>;
3085
3226
 
3086
- export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, HttpClient, type LangGraphIntegrationOptions, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SeedCase, type SeedResult, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
3227
+ export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AddDatasetGradersResult, type AddDatasetTracesResult, type AllowedEnvVars, BITFAB_PROGRESS_PREFIX, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabLangGraphIntegration, type BitfabLanguageModelMiddleware, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, BitfabVercelAiHandler, type CaptureWhen, type CapturedSpan, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type Dataset, type DatasetGraderRef, type DatasetTraceIds, DatasetsClient, type DbBranchOptions, DbBranchReplayError, type DbBranchTimings, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type GraderRerun, type GraderRerunProgress, type GraderRerunResult, type GraderRerunStatus, HttpClient, type LangGraphIntegrationOptions, type ListDatasetsParams, type MockOverride, type MockOverrideCtx, type MockOverrideInput, type MockOverrideResolver, type MockStrategy, type MockValue, NO_MOCK_OVERRIDE, type NodeMatcher, type NodeMethodDecorator, type NodeOptions, type ProviderDefinition, type RemoveDatasetGradersResult, type RemoveDatasetTracesResult, ReplayBranch, ReplayError, type ReplayItem, type ReplayItemFinishProgress, type ReplayItemStartProgress, type ReplayOptions, type ReplayOptionsFactory, type ReplayProgress, type ReplayProgressItem, type ReplayRegistration, type ReplayRegistry, type ReplayRegistryContext, type ReplayRegistryOptions, type ReplayResult, type RerunGradersOptions, type RerunGradersResult, SUPPORTED_PROVIDERS, type SaveDatasetParams, type SaveDatasetResult, type SeedCase, type SeedResult, type SpanLookup, type SpanMethodDecorator, type SpanMethodDecoratorContext, type SpanNodeMeta, type SpanOccurrence, type SpanOptions, type SpanType, type TokenUsage, type TraceIngestionType, type TraceResponse, type TracingProcessor, type VercelCallParams, type VercelGenerateResult, type VercelStreamResult, type WrapBAMLOptions, type WrappedBamlFn, __version__, defineReplayRegistry, finalizers, flushTraces, getCurrentReplayBranch, getCurrentSpan, getCurrentTrace, reportReplayProgress, seedFromRegistry, serializeReplayResult };
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  BitfabOpenAIAgentHandler,
17
17
  BitfabOpenAITracingProcessor,
18
18
  BitfabVercelAiHandler,
19
+ DatasetsClient,
19
20
  SUPPORTED_PROVIDERS,
20
21
  defineReplayRegistry,
21
22
  finalizers,
@@ -23,7 +24,7 @@ import {
23
24
  getCurrentSpan,
24
25
  getCurrentTrace,
25
26
  seedFromRegistry
26
- } from "./chunk-B4EJ2EQT.js";
27
+ } from "./chunk-HBPJSNC2.js";
27
28
  import "./chunk-ZUD7OFYB.js";
28
29
  import {
29
30
  BITFAB_PROGRESS_PREFIX,
@@ -32,14 +33,14 @@ import {
32
33
  ReplayError,
33
34
  reportReplayProgress,
34
35
  serializeReplayResult
35
- } from "./chunk-7OKE7FGZ.js";
36
+ } from "./chunk-SMOV6KN5.js";
36
37
  import {
37
38
  BitfabError,
38
39
  DEFAULT_SERVICE_URL,
39
40
  HttpClient,
40
41
  __version__,
41
42
  flushTraces
42
- } from "./chunk-OXE6M7CZ.js";
43
+ } from "./chunk-DYURJJSV.js";
43
44
  import "./chunk-H6LZRFMN.js";
44
45
  export {
45
46
  BITFAB_PROGRESS_PREFIX,
@@ -54,6 +55,7 @@ export {
54
55
  BitfabOpenAITracingProcessor,
55
56
  BitfabVercelAiHandler,
56
57
  DEFAULT_SERVICE_URL,
58
+ DatasetsClient,
57
59
  DbBranchReplayError,
58
60
  HttpClient,
59
61
  NO_MOCK_OVERRIDE,
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.39.0";
100
+ __version__ = "0.40.0";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -1748,6 +1748,10 @@ var init_http = __esm({
1748
1748
  const response = await this.get(endpoint);
1749
1749
  return response.span;
1750
1750
  }
1751
+ /**
1752
+ * GET a JSON endpoint on the service with the client's API key. Throws a
1753
+ * `BitfabError` carrying the status text for any non-2xx response.
1754
+ */
1751
1755
  async get(endpoint) {
1752
1756
  const url = `${this.serviceUrl}${endpoint}`;
1753
1757
  const controller = new AbortController();
@@ -1761,7 +1765,10 @@ var init_http = __esm({
1761
1765
  if (!response.ok) {
1762
1766
  const errorText = await response.text();
1763
1767
  throw new BitfabError(
1764
- `HTTP ${response.status}: ${errorText.slice(0, 500)}`
1768
+ `HTTP ${response.status}: ${errorText.slice(0, 500)}`,
1769
+ void 0,
1770
+ response.status,
1771
+ parseRetryAfterMs(readHeader(response, "retry-after"))
1765
1772
  );
1766
1773
  }
1767
1774
  return await response.json();
@@ -3213,6 +3220,7 @@ __export(node_exports, {
3213
3220
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
3214
3221
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
3215
3222
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
3223
+ DatasetsClient: () => DatasetsClient,
3216
3224
  DbBranchReplayError: () => DbBranchReplayError,
3217
3225
  HttpClient: () => HttpClient,
3218
3226
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
@@ -4299,6 +4307,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4299
4307
  // src/client.ts
4300
4308
  init_constants();
4301
4309
 
4310
+ // src/datasets.ts
4311
+ var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
4312
+ var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
4313
+ var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
4314
+ "completed",
4315
+ "errored"
4316
+ ]);
4317
+ function sleep(ms) {
4318
+ return new Promise((resolve) => setTimeout(resolve, ms));
4319
+ }
4320
+ function datasetPath(datasetId, suffix = "") {
4321
+ return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
4322
+ }
4323
+ var DatasetsClient = class {
4324
+ constructor(httpClient) {
4325
+ this.httpClient = httpClient;
4326
+ }
4327
+ /**
4328
+ * Create a dataset, or update the one already named this way under the same
4329
+ * trace function. `created` reports which happened. An omitted description
4330
+ * leaves an existing one untouched.
4331
+ */
4332
+ async save(params) {
4333
+ return this.httpClient.request("/api/sdk/datasets", {
4334
+ traceFunctionKey: params.traceFunctionKey,
4335
+ name: params.name,
4336
+ ...params.description === void 0 ? {} : { description: params.description }
4337
+ });
4338
+ }
4339
+ /**
4340
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
4341
+ * given and organization-wide otherwise.
4342
+ */
4343
+ async list(params = {}) {
4344
+ const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
4345
+ const response = await this.httpClient.get(
4346
+ `/api/sdk/datasets${query}`
4347
+ );
4348
+ return response.datasets;
4349
+ }
4350
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
4351
+ async get(datasetId) {
4352
+ const response = await this.httpClient.get(
4353
+ datasetPath(datasetId)
4354
+ );
4355
+ return response.dataset;
4356
+ }
4357
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
4358
+ async listTraces(datasetId) {
4359
+ return this.httpClient.get(
4360
+ datasetPath(datasetId, "/traces")
4361
+ );
4362
+ }
4363
+ /**
4364
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
4365
+ * organization or under another trace function are reported in
4366
+ * `skippedTraceIds` rather than failing the call.
4367
+ */
4368
+ async addTraces(datasetId, traceIds) {
4369
+ return this.httpClient.request(
4370
+ datasetPath(datasetId, "/traces"),
4371
+ { traceIds }
4372
+ );
4373
+ }
4374
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
4375
+ async removeTraces(datasetId, traceIds) {
4376
+ return this.httpClient.request(
4377
+ datasetPath(datasetId, "/removeTraces"),
4378
+ { traceIds }
4379
+ );
4380
+ }
4381
+ /**
4382
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
4383
+ * organization or under another trace function are reported in
4384
+ * `skippedGraderIds` rather than failing the call.
4385
+ */
4386
+ async addGraders(datasetId, graderIds) {
4387
+ return this.httpClient.request(
4388
+ datasetPath(datasetId, "/graders"),
4389
+ { graderIds }
4390
+ );
4391
+ }
4392
+ /** Unassign graders from the dataset. */
4393
+ async removeGraders(datasetId, graderIds) {
4394
+ return this.httpClient.request(
4395
+ datasetPath(datasetId, "/removeGraders"),
4396
+ { graderIds }
4397
+ );
4398
+ }
4399
+ /**
4400
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
4401
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
4402
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
4403
+ * run state seen either way. A request matching an in-flight run joins it.
4404
+ */
4405
+ async rerunGraders(datasetId, options = {}) {
4406
+ const started = await this.httpClient.request(
4407
+ datasetPath(datasetId, "/rerunGraders"),
4408
+ options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
4409
+ );
4410
+ if (options.wait === false) {
4411
+ return started;
4412
+ }
4413
+ const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
4414
+ const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
4415
+ let run = started.run;
4416
+ while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
4417
+ await sleep(interval);
4418
+ run = await this.getGraderRerun(datasetId, run.id) ?? run;
4419
+ }
4420
+ return { run, joinedExisting: started.joinedExisting };
4421
+ }
4422
+ /**
4423
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
4424
+ * `null` when nothing is active or the run does not belong to this dataset.
4425
+ */
4426
+ async getGraderRerun(datasetId, runId) {
4427
+ const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
4428
+ const response = await this.httpClient.get(
4429
+ datasetPath(datasetId, `/rerunGraders${query}`)
4430
+ );
4431
+ return response.run;
4432
+ }
4433
+ };
4434
+
4302
4435
  // src/dbSnapshot.ts
4303
4436
  init_errors();
4304
4437
  var SUPPORTED_PROVIDERS = ["neon"];
@@ -6034,6 +6167,7 @@ var Bitfab = class {
6034
6167
  serviceUrl: this.serviceUrl,
6035
6168
  timeout: this.timeout
6036
6169
  });
6170
+ this.datasets = new DatasetsClient(this.httpClient);
6037
6171
  }
6038
6172
  /**
6039
6173
  * Decorate a class method as an automatically expanded trace root.
@@ -7851,6 +7985,7 @@ assertAsyncStorageRegistered();
7851
7985
  BitfabOpenAITracingProcessor,
7852
7986
  BitfabVercelAiHandler,
7853
7987
  DEFAULT_SERVICE_URL,
7988
+ DatasetsClient,
7854
7989
  DbBranchReplayError,
7855
7990
  HttpClient,
7856
7991
  NO_MOCK_OVERRIDE,