@bitfab/sdk 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
@@ -7,6 +7,7 @@ import {
7
7
  BitfabOpenAIAgentHandler,
8
8
  BitfabOpenAITracingProcessor,
9
9
  BitfabVercelAiHandler,
10
+ DatasetsClient,
10
11
  SUPPORTED_PROVIDERS,
11
12
  defineReplayRegistry,
12
13
  finalizers,
@@ -14,7 +15,7 @@ import {
14
15
  getCurrentSpan,
15
16
  getCurrentTrace,
16
17
  seedFromRegistry
17
- } from "./chunk-SHJ3ABUG.js";
18
+ } from "./chunk-5NT4YDCQ.js";
18
19
  import "./chunk-ZUD7OFYB.js";
19
20
  import {
20
21
  BITFAB_PROGRESS_PREFIX,
@@ -23,14 +24,14 @@ import {
23
24
  ReplayError,
24
25
  reportReplayProgress,
25
26
  serializeReplayResult
26
- } from "./chunk-FW7PZ3EP.js";
27
+ } from "./chunk-EXT5FK54.js";
27
28
  import {
28
29
  BitfabError,
29
30
  DEFAULT_SERVICE_URL,
30
31
  HttpClient,
31
32
  __version__,
32
33
  flushTraces
33
- } from "./chunk-2JQSYJJR.js";
34
+ } from "./chunk-A22EYRSY.js";
34
35
  import "./chunk-H6LZRFMN.js";
35
36
  export {
36
37
  BITFAB_PROGRESS_PREFIX,
@@ -45,6 +46,7 @@ export {
45
46
  BitfabOpenAITracingProcessor,
46
47
  BitfabVercelAiHandler,
47
48
  DEFAULT_SERVICE_URL,
49
+ DatasetsClient,
48
50
  DbBranchReplayError,
49
51
  HttpClient,
50
52
  NO_MOCK_OVERRIDE,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.39.0";
91
+ __version__ = "0.40.0";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -1739,6 +1739,10 @@ var init_http = __esm({
1739
1739
  const response = await this.get(endpoint);
1740
1740
  return response.span;
1741
1741
  }
1742
+ /**
1743
+ * GET a JSON endpoint on the service with the client's API key. Throws a
1744
+ * `BitfabError` carrying the status text for any non-2xx response.
1745
+ */
1742
1746
  async get(endpoint) {
1743
1747
  const url = `${this.serviceUrl}${endpoint}`;
1744
1748
  const controller = new AbortController();
@@ -1752,7 +1756,10 @@ var init_http = __esm({
1752
1756
  if (!response.ok) {
1753
1757
  const errorText = await response.text();
1754
1758
  throw new BitfabError(
1755
- `HTTP ${response.status}: ${errorText.slice(0, 500)}`
1759
+ `HTTP ${response.status}: ${errorText.slice(0, 500)}`,
1760
+ void 0,
1761
+ response.status,
1762
+ parseRetryAfterMs(readHeader(response, "retry-after"))
1756
1763
  );
1757
1764
  }
1758
1765
  return await response.json();
@@ -3204,6 +3211,7 @@ __export(node_exports, {
3204
3211
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
3205
3212
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
3206
3213
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
3214
+ DatasetsClient: () => DatasetsClient,
3207
3215
  DbBranchReplayError: () => DbBranchReplayError,
3208
3216
  HttpClient: () => HttpClient,
3209
3217
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
@@ -4290,6 +4298,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4290
4298
  // src/client.ts
4291
4299
  init_constants();
4292
4300
 
4301
+ // src/datasets.ts
4302
+ var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
4303
+ var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
4304
+ var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
4305
+ "completed",
4306
+ "errored"
4307
+ ]);
4308
+ function sleep(ms) {
4309
+ return new Promise((resolve) => setTimeout(resolve, ms));
4310
+ }
4311
+ function datasetPath(datasetId, suffix = "") {
4312
+ return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
4313
+ }
4314
+ var DatasetsClient = class {
4315
+ constructor(httpClient) {
4316
+ this.httpClient = httpClient;
4317
+ }
4318
+ /**
4319
+ * Create a dataset, or update the one already named this way under the same
4320
+ * trace function. `created` reports which happened. An omitted description
4321
+ * leaves an existing one untouched.
4322
+ */
4323
+ async save(params) {
4324
+ return this.httpClient.request("/api/sdk/datasets", {
4325
+ traceFunctionKey: params.traceFunctionKey,
4326
+ name: params.name,
4327
+ ...params.description === void 0 ? {} : { description: params.description }
4328
+ });
4329
+ }
4330
+ /**
4331
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
4332
+ * given and organization-wide otherwise.
4333
+ */
4334
+ async list(params = {}) {
4335
+ const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
4336
+ const response = await this.httpClient.get(
4337
+ `/api/sdk/datasets${query}`
4338
+ );
4339
+ return response.datasets;
4340
+ }
4341
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
4342
+ async get(datasetId) {
4343
+ const response = await this.httpClient.get(
4344
+ datasetPath(datasetId)
4345
+ );
4346
+ return response.dataset;
4347
+ }
4348
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
4349
+ async listTraces(datasetId) {
4350
+ return this.httpClient.get(
4351
+ datasetPath(datasetId, "/traces")
4352
+ );
4353
+ }
4354
+ /**
4355
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
4356
+ * organization or under another trace function are reported in
4357
+ * `skippedTraceIds` rather than failing the call.
4358
+ */
4359
+ async addTraces(datasetId, traceIds) {
4360
+ return this.httpClient.request(
4361
+ datasetPath(datasetId, "/traces"),
4362
+ { traceIds }
4363
+ );
4364
+ }
4365
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
4366
+ async removeTraces(datasetId, traceIds) {
4367
+ return this.httpClient.request(
4368
+ datasetPath(datasetId, "/removeTraces"),
4369
+ { traceIds }
4370
+ );
4371
+ }
4372
+ /**
4373
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
4374
+ * organization or under another trace function are reported in
4375
+ * `skippedGraderIds` rather than failing the call.
4376
+ */
4377
+ async addGraders(datasetId, graderIds) {
4378
+ return this.httpClient.request(
4379
+ datasetPath(datasetId, "/graders"),
4380
+ { graderIds }
4381
+ );
4382
+ }
4383
+ /** Unassign graders from the dataset. */
4384
+ async removeGraders(datasetId, graderIds) {
4385
+ return this.httpClient.request(
4386
+ datasetPath(datasetId, "/removeGraders"),
4387
+ { graderIds }
4388
+ );
4389
+ }
4390
+ /**
4391
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
4392
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
4393
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
4394
+ * run state seen either way. A request matching an in-flight run joins it.
4395
+ */
4396
+ async rerunGraders(datasetId, options = {}) {
4397
+ const started = await this.httpClient.request(
4398
+ datasetPath(datasetId, "/rerunGraders"),
4399
+ options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
4400
+ );
4401
+ if (options.wait === false) {
4402
+ return started;
4403
+ }
4404
+ const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
4405
+ const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
4406
+ let run = started.run;
4407
+ while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
4408
+ await sleep(interval);
4409
+ run = await this.getGraderRerun(datasetId, run.id) ?? run;
4410
+ }
4411
+ return { run, joinedExisting: started.joinedExisting };
4412
+ }
4413
+ /**
4414
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
4415
+ * `null` when nothing is active or the run does not belong to this dataset.
4416
+ */
4417
+ async getGraderRerun(datasetId, runId) {
4418
+ const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
4419
+ const response = await this.httpClient.get(
4420
+ datasetPath(datasetId, `/rerunGraders${query}`)
4421
+ );
4422
+ return response.run;
4423
+ }
4424
+ };
4425
+
4293
4426
  // src/dbSnapshot.ts
4294
4427
  init_errors();
4295
4428
  var SUPPORTED_PROVIDERS = ["neon"];
@@ -6025,6 +6158,7 @@ var Bitfab = class {
6025
6158
  serviceUrl: this.serviceUrl,
6026
6159
  timeout: this.timeout
6027
6160
  });
6161
+ this.datasets = new DatasetsClient(this.httpClient);
6028
6162
  }
6029
6163
  /**
6030
6164
  * Decorate a class method as an automatically expanded trace root.
@@ -7842,6 +7976,7 @@ assertAsyncStorageRegistered();
7842
7976
  BitfabOpenAITracingProcessor,
7843
7977
  BitfabVercelAiHandler,
7844
7978
  DEFAULT_SERVICE_URL,
7979
+ DatasetsClient,
7845
7980
  DbBranchReplayError,
7846
7981
  HttpClient,
7847
7982
  NO_MOCK_OVERRIDE,