@bitfab/sdk 0.58.4 → 0.59.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/autoTrace.cjs +50 -4
- package/dist/autoTrace.cjs.map +1 -1
- package/dist/autoTrace.d.cts +2 -1
- package/dist/autoTrace.d.ts +2 -1
- package/dist/autoTrace.js +4 -2
- package/dist/{chunk-BVUGW7BJ.js → chunk-4BNE5ETI.js} +6 -6
- package/dist/{chunk-3LJVTDD5.js → chunk-6IM35I7O.js} +2 -2
- package/dist/{chunk-3LJVTDD5.js.map → chunk-6IM35I7O.js.map} +1 -1
- package/dist/{chunk-VCRFFCLY.js → chunk-BAOIRE5T.js} +20 -2
- package/dist/chunk-BAOIRE5T.js.map +1 -0
- package/dist/{chunk-RCHSYWKI.js → chunk-ETZUSSF6.js} +38 -8
- package/dist/chunk-ETZUSSF6.js.map +1 -0
- package/dist/{chunk-ZLAFCSCP.js → chunk-FBMHGUIK.js} +6 -21
- package/dist/chunk-FBMHGUIK.js.map +1 -0
- package/dist/{chunk-74ECLOFY.js → chunk-IW23QVY3.js} +3 -3
- package/dist/{chunk-UKJ3RWVS.js → chunk-KGIKT4UT.js} +123 -26
- package/dist/chunk-KGIKT4UT.js.map +1 -0
- package/dist/{http-NG5NP6PH.js → http-FXLIHCQK.js} +2 -2
- package/dist/{http-XTSUPZEC.js → http-HJJR2ZCE.js} +3 -3
- package/dist/index.cjs +142 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -10
- package/dist/index.d.ts +32 -10
- package/dist/index.js +13 -5
- package/dist/node.cjs +142 -20
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +13 -5
- package/dist/node.js.map +1 -1
- package/dist/{replay-JHFO457Z.js → replay-WBWGCZF7.js} +4 -4
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-RCHSYWKI.js.map +0 -1
- package/dist/chunk-UKJ3RWVS.js.map +0 -1
- package/dist/chunk-VCRFFCLY.js.map +0 -1
- package/dist/chunk-ZLAFCSCP.js.map +0 -1
- /package/dist/{chunk-BVUGW7BJ.js.map → chunk-4BNE5ETI.js.map} +0 -0
- /package/dist/{chunk-74ECLOFY.js.map → chunk-IW23QVY3.js.map} +0 -0
- /package/dist/{http-NG5NP6PH.js.map → http-FXLIHCQK.js.map} +0 -0
- /package/dist/{http-XTSUPZEC.js.map → http-HJJR2ZCE.js.map} +0 -0
- /package/dist/{replay-JHFO457Z.js.map → replay-WBWGCZF7.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6IM35I7O.js";
|
|
10
10
|
export {
|
|
11
11
|
BitfabError,
|
|
12
12
|
HttpClient,
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
parseRetryAfterMs,
|
|
17
17
|
serializePayloadBody
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=http-
|
|
19
|
+
//# sourceMappingURL=http-FXLIHCQK.js.map
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-FBMHGUIK.js";
|
|
10
|
+
import "./chunk-BAOIRE5T.js";
|
|
11
11
|
export {
|
|
12
12
|
BitfabError,
|
|
13
13
|
HttpClient,
|
|
@@ -17,4 +17,4 @@ export {
|
|
|
17
17
|
parseRetryAfterMs,
|
|
18
18
|
serializePayloadBody
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=http-
|
|
20
|
+
//# sourceMappingURL=http-HJJR2ZCE.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var __version__, __packageName__;
|
|
|
42
42
|
var init_version_generated = __esm({
|
|
43
43
|
"src/version.generated.ts"() {
|
|
44
44
|
"use strict";
|
|
45
|
-
__version__ = "0.
|
|
45
|
+
__version__ = "0.59.0";
|
|
46
46
|
__packageName__ = "@bitfab/sdk";
|
|
47
47
|
}
|
|
48
48
|
});
|
|
@@ -4390,6 +4390,8 @@ var init_replay = __esm({
|
|
|
4390
4390
|
var index_exports = {};
|
|
4391
4391
|
__export(index_exports, {
|
|
4392
4392
|
AssertionCategoriesClient: () => AssertionCategoriesClient,
|
|
4393
|
+
AssertionGenerationError: () => AssertionGenerationError,
|
|
4394
|
+
AssertionGenerationTimeoutError: () => AssertionGenerationTimeoutError,
|
|
4393
4395
|
BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
|
|
4394
4396
|
Bitfab: () => Bitfab,
|
|
4395
4397
|
BitfabClaudeAgentHandler: () => BitfabClaudeAgentHandler,
|
|
@@ -4405,6 +4407,8 @@ __export(index_exports, {
|
|
|
4405
4407
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
4406
4408
|
DatasetsClient: () => DatasetsClient,
|
|
4407
4409
|
DbBranchReplayError: () => DbBranchReplayError,
|
|
4410
|
+
GraderRerunError: () => GraderRerunError,
|
|
4411
|
+
GraderRerunTimeoutError: () => GraderRerunTimeoutError,
|
|
4408
4412
|
GradersClient: () => GradersClient,
|
|
4409
4413
|
HttpClient: () => HttpClient,
|
|
4410
4414
|
LabelsClient: () => LabelsClient,
|
|
@@ -5097,6 +5101,7 @@ init_asyncStorage();
|
|
|
5097
5101
|
// src/autoTrace.ts
|
|
5098
5102
|
init_asyncStorage();
|
|
5099
5103
|
init_captureSuppression();
|
|
5104
|
+
init_warnOnce();
|
|
5100
5105
|
var autoTraceGlobal = globalThis;
|
|
5101
5106
|
var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
|
|
5102
5107
|
storage: null,
|
|
@@ -5164,6 +5169,26 @@ function runWithAutoTraceNodeConfiguration(nodeConfiguration, fn) {
|
|
|
5164
5169
|
}
|
|
5165
5170
|
return result;
|
|
5166
5171
|
}
|
|
5172
|
+
var SUBTREE_TRACING_DOCS_URL = "https://docs.bitfab.ai/typescript-sdk#experimental-subtree-tracing";
|
|
5173
|
+
function transformInstalled() {
|
|
5174
|
+
return autoTraceGlobal.__bitfab_auto_trace_transformed_v1__ === true;
|
|
5175
|
+
}
|
|
5176
|
+
function runsOnNode() {
|
|
5177
|
+
return typeof process !== "undefined" && Boolean(process.versions?.node);
|
|
5178
|
+
}
|
|
5179
|
+
function closeAutoTraceRoot() {
|
|
5180
|
+
autoTraceState.activeRoots -= 1;
|
|
5181
|
+
}
|
|
5182
|
+
function settleAutoTraceRoot(context) {
|
|
5183
|
+
closeAutoTraceRoot();
|
|
5184
|
+
if (transformInstalled() || !runsOnNode()) {
|
|
5185
|
+
return;
|
|
5186
|
+
}
|
|
5187
|
+
warnOnce(
|
|
5188
|
+
"auto-trace-transform-missing",
|
|
5189
|
+
`trace root "${context.traceFunctionKey}" recorded only its own span. No module in this build was compiled by @bitfab/transform, so calls beneath the root were not discovered. Install @bitfab/transform and add its adapter to the server build: ${SUBTREE_TRACING_DOCS_URL}`
|
|
5190
|
+
);
|
|
5191
|
+
}
|
|
5167
5192
|
function runWithAutoTraceRootContext(context, spanStack, fn) {
|
|
5168
5193
|
autoTraceState.activeRoots += 1;
|
|
5169
5194
|
const entries = [
|
|
@@ -5174,19 +5199,19 @@ function runWithAutoTraceRootContext(context, spanStack, fn) {
|
|
|
5174
5199
|
try {
|
|
5175
5200
|
result = runWithAutoTraceScope({ entries }, fn);
|
|
5176
5201
|
} catch (error) {
|
|
5177
|
-
|
|
5202
|
+
settleAutoTraceRoot(context);
|
|
5178
5203
|
throw error;
|
|
5179
5204
|
}
|
|
5180
5205
|
if (isAutoTraceAsyncGenerator(result)) {
|
|
5181
|
-
|
|
5206
|
+
closeAutoTraceRoot();
|
|
5182
5207
|
return wrapAutoTraceAsyncGenerator(context, spanStack, result);
|
|
5183
5208
|
}
|
|
5184
5209
|
if (result instanceof Promise) {
|
|
5185
5210
|
return result.finally(() => {
|
|
5186
|
-
|
|
5211
|
+
settleAutoTraceRoot(context);
|
|
5187
5212
|
});
|
|
5188
5213
|
}
|
|
5189
|
-
|
|
5214
|
+
settleAutoTraceRoot(context);
|
|
5190
5215
|
return result;
|
|
5191
5216
|
}
|
|
5192
5217
|
function invokeThroughAutoTraceEntries(entries, step, fn) {
|
|
@@ -5811,11 +5836,39 @@ init_constants();
|
|
|
5811
5836
|
|
|
5812
5837
|
// src/datasets.ts
|
|
5813
5838
|
var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
|
|
5814
|
-
var
|
|
5839
|
+
var RERUN_POLL_INTERVAL_MS = 1e3;
|
|
5815
5840
|
var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
|
|
5816
5841
|
"completed",
|
|
5817
5842
|
"errored"
|
|
5818
5843
|
]);
|
|
5844
|
+
var GraderRerunError = class extends Error {
|
|
5845
|
+
constructor(message, run) {
|
|
5846
|
+
super(message);
|
|
5847
|
+
this.run = run;
|
|
5848
|
+
this.name = "GraderRerunError";
|
|
5849
|
+
}
|
|
5850
|
+
};
|
|
5851
|
+
var GraderRerunTimeoutError = class extends GraderRerunError {
|
|
5852
|
+
constructor(datasetId, run, timeoutMs) {
|
|
5853
|
+
super(
|
|
5854
|
+
`Grader re-run ${run.id} on dataset ${datasetId} was still ${run.status} after ${timeoutMs}ms. It keeps running on Bitfab; read it later with getGraderRerun.`,
|
|
5855
|
+
run
|
|
5856
|
+
);
|
|
5857
|
+
this.name = "GraderRerunTimeoutError";
|
|
5858
|
+
}
|
|
5859
|
+
};
|
|
5860
|
+
function finishedRerun(datasetId, run, joinedExisting) {
|
|
5861
|
+
if (!TERMINAL_RERUN_STATUSES.has(run.status)) {
|
|
5862
|
+
return null;
|
|
5863
|
+
}
|
|
5864
|
+
if (run.status === "errored") {
|
|
5865
|
+
throw new GraderRerunError(
|
|
5866
|
+
`Grader re-run ${run.id} on dataset ${datasetId} errored: ${run.error ?? "no reason recorded"}`,
|
|
5867
|
+
run
|
|
5868
|
+
);
|
|
5869
|
+
}
|
|
5870
|
+
return { run, joinedExisting };
|
|
5871
|
+
}
|
|
5819
5872
|
function sleep(ms) {
|
|
5820
5873
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5821
5874
|
}
|
|
@@ -5915,28 +5968,25 @@ var DatasetsClient = class {
|
|
|
5915
5968
|
{ graderIds }
|
|
5916
5969
|
);
|
|
5917
5970
|
}
|
|
5918
|
-
/**
|
|
5919
|
-
* Re-run graders over every trace in the dataset. Defaults to every assigned
|
|
5920
|
-
* grader; an unassigned id is rejected. Waits for the run to finish (up to
|
|
5921
|
-
* `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
|
|
5922
|
-
* run state seen either way. A request matching an in-flight run joins it.
|
|
5923
|
-
*/
|
|
5924
5971
|
async rerunGraders(datasetId, options = {}) {
|
|
5925
5972
|
const started = await this.httpClient.request(
|
|
5926
5973
|
datasetPath(datasetId, "/rerunGraders"),
|
|
5927
5974
|
options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
|
|
5928
5975
|
);
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
}
|
|
5932
|
-
const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
|
|
5933
|
-
const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
|
|
5976
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS;
|
|
5977
|
+
const deadline = Date.now() + timeoutMs;
|
|
5934
5978
|
let run = started.run;
|
|
5935
|
-
while (
|
|
5936
|
-
|
|
5979
|
+
while (true) {
|
|
5980
|
+
const finished = finishedRerun(datasetId, run, started.joinedExisting);
|
|
5981
|
+
if (finished !== null) {
|
|
5982
|
+
return finished;
|
|
5983
|
+
}
|
|
5984
|
+
if (Date.now() >= deadline) {
|
|
5985
|
+
throw new GraderRerunTimeoutError(datasetId, run, timeoutMs);
|
|
5986
|
+
}
|
|
5987
|
+
await sleep(RERUN_POLL_INTERVAL_MS);
|
|
5937
5988
|
run = await this.getGraderRerun(datasetId, run.id) ?? run;
|
|
5938
5989
|
}
|
|
5939
|
-
return { run, joinedExisting: started.joinedExisting };
|
|
5940
5990
|
}
|
|
5941
5991
|
/**
|
|
5942
5992
|
* The dataset's active grader re-run, or the run named by `runId`. Returns
|
|
@@ -7792,6 +7842,46 @@ init_traceMetadata();
|
|
|
7792
7842
|
// src/traces.ts
|
|
7793
7843
|
var ASSERTIONS_PATH = "/api/sdk/traces/assertions";
|
|
7794
7844
|
var SEARCH_PATH = "/api/sdk/traces/search";
|
|
7845
|
+
var DEFAULT_GENERATION_TIMEOUT_MS = 6e5;
|
|
7846
|
+
var GENERATION_POLL_INTERVAL_MS = 2e3;
|
|
7847
|
+
var AssertionGenerationError = class extends Error {
|
|
7848
|
+
constructor(message, traceId) {
|
|
7849
|
+
super(message);
|
|
7850
|
+
this.traceId = traceId;
|
|
7851
|
+
this.name = "AssertionGenerationError";
|
|
7852
|
+
}
|
|
7853
|
+
};
|
|
7854
|
+
var AssertionGenerationTimeoutError = class extends AssertionGenerationError {
|
|
7855
|
+
constructor(traceId, timeoutMs) {
|
|
7856
|
+
super(
|
|
7857
|
+
`Assertion generation for trace ${traceId} did not finish within ${timeoutMs}ms. Generation keeps running on Bitfab. Call getAssertions and read its generation field to check its status.`,
|
|
7858
|
+
traceId
|
|
7859
|
+
);
|
|
7860
|
+
this.name = "AssertionGenerationTimeoutError";
|
|
7861
|
+
}
|
|
7862
|
+
};
|
|
7863
|
+
function sleep2(ms) {
|
|
7864
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7865
|
+
}
|
|
7866
|
+
function isGenerationFinished(traceId, generation) {
|
|
7867
|
+
if (generation === null || generation.status === "running") {
|
|
7868
|
+
return false;
|
|
7869
|
+
}
|
|
7870
|
+
if (generation.status === "failed") {
|
|
7871
|
+
throw new AssertionGenerationError(
|
|
7872
|
+
`Assertion generation for trace ${traceId} failed: ${generation.error ?? "no reason recorded"}. Pass regenerate: true to try again.`,
|
|
7873
|
+
traceId
|
|
7874
|
+
);
|
|
7875
|
+
}
|
|
7876
|
+
return true;
|
|
7877
|
+
}
|
|
7878
|
+
function draftsInGenerationOrder(assertions, assertionIds) {
|
|
7879
|
+
const byId = new Map(assertions.map((assertion) => [assertion.id, assertion]));
|
|
7880
|
+
return assertionIds.flatMap((id) => {
|
|
7881
|
+
const assertion = byId.get(id);
|
|
7882
|
+
return assertion === void 0 ? [] : [assertion];
|
|
7883
|
+
});
|
|
7884
|
+
}
|
|
7795
7885
|
function traceAssertionsPath(traceId, suffix = "") {
|
|
7796
7886
|
return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions${suffix}`;
|
|
7797
7887
|
}
|
|
@@ -7823,6 +7913,34 @@ var TracesClient = class {
|
|
|
7823
7913
|
});
|
|
7824
7914
|
return response.assertions;
|
|
7825
7915
|
}
|
|
7916
|
+
async generateAssertions(traceId, options = {}) {
|
|
7917
|
+
const started = await this.httpClient.request(
|
|
7918
|
+
traceAssertionsPath(traceId, "/generate"),
|
|
7919
|
+
{
|
|
7920
|
+
...options.guidance === void 0 ? {} : { guidance: options.guidance },
|
|
7921
|
+
...options.categoryIds === void 0 ? {} : { categoryIds: options.categoryIds },
|
|
7922
|
+
...options.regenerate === void 0 ? {} : { regenerate: options.regenerate }
|
|
7923
|
+
}
|
|
7924
|
+
);
|
|
7925
|
+
if (isGenerationFinished(traceId, started.generation)) {
|
|
7926
|
+
return started.assertions;
|
|
7927
|
+
}
|
|
7928
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_GENERATION_TIMEOUT_MS;
|
|
7929
|
+
const deadline = Date.now() + timeoutMs;
|
|
7930
|
+
while (true) {
|
|
7931
|
+
if (Date.now() >= deadline) {
|
|
7932
|
+
throw new AssertionGenerationTimeoutError(traceId, timeoutMs);
|
|
7933
|
+
}
|
|
7934
|
+
await sleep2(GENERATION_POLL_INTERVAL_MS);
|
|
7935
|
+
const read2 = await this.getAssertions(traceId);
|
|
7936
|
+
if (isGenerationFinished(traceId, read2.generation)) {
|
|
7937
|
+
return draftsInGenerationOrder(
|
|
7938
|
+
read2.assertions,
|
|
7939
|
+
read2.generation.assertionIds
|
|
7940
|
+
);
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
}
|
|
7826
7944
|
async archiveAssertions(params) {
|
|
7827
7945
|
const response = await this.httpClient.request(
|
|
7828
7946
|
traceAssertionsPath(params.traceId, "/archive"),
|
|
@@ -11041,6 +11159,8 @@ function resolveTraceFunctionKey(registration) {
|
|
|
11041
11159
|
// Annotate the CommonJS export names for ESM import in node:
|
|
11042
11160
|
0 && (module.exports = {
|
|
11043
11161
|
AssertionCategoriesClient,
|
|
11162
|
+
AssertionGenerationError,
|
|
11163
|
+
AssertionGenerationTimeoutError,
|
|
11044
11164
|
BITFAB_PROGRESS_PREFIX,
|
|
11045
11165
|
Bitfab,
|
|
11046
11166
|
BitfabClaudeAgentHandler,
|
|
@@ -11056,6 +11176,8 @@ function resolveTraceFunctionKey(registration) {
|
|
|
11056
11176
|
DEFAULT_SERVICE_URL,
|
|
11057
11177
|
DatasetsClient,
|
|
11058
11178
|
DbBranchReplayError,
|
|
11179
|
+
GraderRerunError,
|
|
11180
|
+
GraderRerunTimeoutError,
|
|
11059
11181
|
GradersClient,
|
|
11060
11182
|
HttpClient,
|
|
11061
11183
|
LabelsClient,
|