@bitfab/sdk 0.39.0 → 0.41.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/{chunk-2JQSYJJR.js → chunk-IFYX3KW6.js} +10 -3
- package/dist/{chunk-2JQSYJJR.js.map → chunk-IFYX3KW6.js.map} +1 -1
- package/dist/{chunk-FW7PZ3EP.js → chunk-RWZYZRYI.js} +2 -2
- package/dist/{chunk-SHJ3ABUG.js → chunk-U3AKIFW3.js} +162 -13
- package/dist/chunk-U3AKIFW3.js.map +1 -0
- package/dist/{chunk-RH4K4RSS.js → chunk-VEA6JOKL.js} +10 -3
- package/dist/{chunk-RH4K4RSS.js.map → chunk-VEA6JOKL.js.map} +1 -1
- package/dist/{http-GJZJKNZZ.js → http-JSBWHPNA.js} +2 -2
- package/dist/{http-PRCLI43J.js → http-UCJCOKW7.js} +2 -2
- package/dist/index.cjs +167 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +148 -3
- package/dist/index.d.ts +148 -3
- package/dist/index.js +5 -3
- package/dist/node.cjs +167 -10
- 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 +5 -3
- package/dist/node.js.map +1 -1
- package/dist/{replay-MZYX4IFV.js → replay-HMMWDSLB.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-SHJ3ABUG.js.map +0 -1
- /package/dist/{chunk-FW7PZ3EP.js.map → chunk-RWZYZRYI.js.map} +0 -0
- /package/dist/{http-GJZJKNZZ.js.map → http-JSBWHPNA.js.map} +0 -0
- /package/dist/{http-PRCLI43J.js.map → http-UCJCOKW7.js.map} +0 -0
- /package/dist/{replay-MZYX4IFV.js.map → replay-HMMWDSLB.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
replayContextReady,
|
|
6
6
|
runWithReplayContext,
|
|
7
7
|
warnOnce
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IFYX3KW6.js";
|
|
9
9
|
|
|
10
10
|
// src/codeChange.ts
|
|
11
11
|
var MAX_FILES = 60;
|
|
@@ -1147,4 +1147,4 @@ export {
|
|
|
1147
1147
|
sleepForReplayPersistence,
|
|
1148
1148
|
replay
|
|
1149
1149
|
};
|
|
1150
|
-
//# sourceMappingURL=chunk-
|
|
1150
|
+
//# sourceMappingURL=chunk-RWZYZRYI.js.map
|
|
@@ -14,14 +14,14 @@ import {
|
|
|
14
14
|
serializeValue,
|
|
15
15
|
toJsonSafe,
|
|
16
16
|
toJsonSafeReport
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-RWZYZRYI.js";
|
|
18
18
|
import {
|
|
19
19
|
BitfabError,
|
|
20
20
|
DEFAULT_SERVICE_URL,
|
|
21
21
|
HttpClient,
|
|
22
22
|
getReplayContext,
|
|
23
23
|
warnOnce
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-IFYX3KW6.js";
|
|
25
25
|
import {
|
|
26
26
|
__privateAdd,
|
|
27
27
|
__privateGet,
|
|
@@ -321,8 +321,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
321
321
|
const externalTrace = {
|
|
322
322
|
id: traceId,
|
|
323
323
|
started_at: this.traceStartedAt ?? nowIso(),
|
|
324
|
-
ended_at: endedAt ?? nowIso()
|
|
325
|
-
workflow_name: this.traceFunctionKey
|
|
324
|
+
ended_at: endedAt ?? nowIso()
|
|
326
325
|
};
|
|
327
326
|
if (metadata) {
|
|
328
327
|
externalTrace.metadata = metadata;
|
|
@@ -949,6 +948,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
|
|
|
949
948
|
};
|
|
950
949
|
}
|
|
951
950
|
|
|
951
|
+
// src/datasets.ts
|
|
952
|
+
var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
|
|
953
|
+
var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
|
|
954
|
+
var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
|
|
955
|
+
"completed",
|
|
956
|
+
"errored"
|
|
957
|
+
]);
|
|
958
|
+
function sleep(ms) {
|
|
959
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
960
|
+
}
|
|
961
|
+
function datasetPath(datasetId, suffix = "") {
|
|
962
|
+
return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
|
|
963
|
+
}
|
|
964
|
+
var DatasetsClient = class {
|
|
965
|
+
constructor(httpClient) {
|
|
966
|
+
this.httpClient = httpClient;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Create a dataset, or update the one already named this way under the same
|
|
970
|
+
* trace function. `created` reports which happened. An omitted description
|
|
971
|
+
* leaves an existing one untouched.
|
|
972
|
+
*/
|
|
973
|
+
async save(params) {
|
|
974
|
+
return this.httpClient.request("/api/sdk/datasets", {
|
|
975
|
+
traceFunctionKey: params.traceFunctionKey,
|
|
976
|
+
name: params.name,
|
|
977
|
+
...params.description === void 0 ? {} : { description: params.description }
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* List datasets, scoped to one trace function when `traceFunctionKey` is
|
|
982
|
+
* given and organization-wide otherwise.
|
|
983
|
+
*/
|
|
984
|
+
async list(params = {}) {
|
|
985
|
+
const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
|
|
986
|
+
const response = await this.httpClient.get(
|
|
987
|
+
`/api/sdk/datasets${query}`
|
|
988
|
+
);
|
|
989
|
+
return response.datasets;
|
|
990
|
+
}
|
|
991
|
+
/** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
|
|
992
|
+
async get(datasetId) {
|
|
993
|
+
const response = await this.httpClient.get(
|
|
994
|
+
datasetPath(datasetId)
|
|
995
|
+
);
|
|
996
|
+
return response.dataset;
|
|
997
|
+
}
|
|
998
|
+
/** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
|
|
999
|
+
async listTraces(datasetId) {
|
|
1000
|
+
return this.httpClient.get(
|
|
1001
|
+
datasetPath(datasetId, "/traces")
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Add traces to the dataset (1 to 100 ids per call). Traces outside the
|
|
1006
|
+
* organization or under another trace function are reported in
|
|
1007
|
+
* `skippedTraceIds` rather than failing the call.
|
|
1008
|
+
*/
|
|
1009
|
+
async addTraces(datasetId, traceIds) {
|
|
1010
|
+
return this.httpClient.request(
|
|
1011
|
+
datasetPath(datasetId, "/traces"),
|
|
1012
|
+
{ traceIds }
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
/** Remove traces from the dataset. The traces themselves are never deleted. */
|
|
1016
|
+
async removeTraces(datasetId, traceIds) {
|
|
1017
|
+
return this.httpClient.request(
|
|
1018
|
+
datasetPath(datasetId, "/removeTraces"),
|
|
1019
|
+
{ traceIds }
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Assign graders to the dataset (1 to 100 ids per call). Graders outside the
|
|
1024
|
+
* organization or under another trace function are reported in
|
|
1025
|
+
* `skippedGraderIds` rather than failing the call.
|
|
1026
|
+
*/
|
|
1027
|
+
async addGraders(datasetId, graderIds) {
|
|
1028
|
+
return this.httpClient.request(
|
|
1029
|
+
datasetPath(datasetId, "/graders"),
|
|
1030
|
+
{ graderIds }
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
/** Unassign graders from the dataset. */
|
|
1034
|
+
async removeGraders(datasetId, graderIds) {
|
|
1035
|
+
return this.httpClient.request(
|
|
1036
|
+
datasetPath(datasetId, "/removeGraders"),
|
|
1037
|
+
{ graderIds }
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Re-run graders over every trace in the dataset. Defaults to every assigned
|
|
1042
|
+
* grader; an unassigned id is rejected. Waits for the run to finish (up to
|
|
1043
|
+
* `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
|
|
1044
|
+
* run state seen either way. A request matching an in-flight run joins it.
|
|
1045
|
+
*/
|
|
1046
|
+
async rerunGraders(datasetId, options = {}) {
|
|
1047
|
+
const started = await this.httpClient.request(
|
|
1048
|
+
datasetPath(datasetId, "/rerunGraders"),
|
|
1049
|
+
options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
|
|
1050
|
+
);
|
|
1051
|
+
if (options.wait === false) {
|
|
1052
|
+
return started;
|
|
1053
|
+
}
|
|
1054
|
+
const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
|
|
1055
|
+
const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
|
|
1056
|
+
let run = started.run;
|
|
1057
|
+
while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
|
|
1058
|
+
await sleep(interval);
|
|
1059
|
+
run = await this.getGraderRerun(datasetId, run.id) ?? run;
|
|
1060
|
+
}
|
|
1061
|
+
return { run, joinedExisting: started.joinedExisting };
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The dataset's active grader re-run, or the run named by `runId`. Returns
|
|
1065
|
+
* `null` when nothing is active or the run does not belong to this dataset.
|
|
1066
|
+
*/
|
|
1067
|
+
async getGraderRerun(datasetId, runId) {
|
|
1068
|
+
const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
|
|
1069
|
+
const response = await this.httpClient.get(
|
|
1070
|
+
datasetPath(datasetId, `/rerunGraders${query}`)
|
|
1071
|
+
);
|
|
1072
|
+
return response.run;
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
|
|
952
1076
|
// src/dbSnapshot.ts
|
|
953
1077
|
var SUPPORTED_PROVIDERS = ["neon"];
|
|
954
1078
|
function validateDbSnapshotConfig(config) {
|
|
@@ -1350,8 +1474,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
1350
1474
|
externalTrace: {
|
|
1351
1475
|
id: rootSpan.traceId,
|
|
1352
1476
|
started_at: rootSpan.startedAt,
|
|
1353
|
-
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
1354
|
-
workflow_name: this.traceFunctionKey
|
|
1477
|
+
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
1355
1478
|
},
|
|
1356
1479
|
completed
|
|
1357
1480
|
};
|
|
@@ -1369,8 +1492,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
1369
1492
|
traceFunctionKey: this.traceFunctionKey,
|
|
1370
1493
|
externalTrace: {
|
|
1371
1494
|
id: rootSpan.traceId,
|
|
1372
|
-
started_at: rootSpan.startedAt
|
|
1373
|
-
workflow_name: this.traceFunctionKey
|
|
1495
|
+
started_at: rootSpan.startedAt
|
|
1374
1496
|
},
|
|
1375
1497
|
completed: false
|
|
1376
1498
|
};
|
|
@@ -2512,6 +2634,8 @@ var noOpSpan = {
|
|
|
2512
2634
|
var noOpTrace = {
|
|
2513
2635
|
setSessionId() {
|
|
2514
2636
|
},
|
|
2637
|
+
setName() {
|
|
2638
|
+
},
|
|
2515
2639
|
setMetadata() {
|
|
2516
2640
|
},
|
|
2517
2641
|
addContext() {
|
|
@@ -2586,6 +2710,15 @@ function getCurrentTrace() {
|
|
|
2586
2710
|
} catch {
|
|
2587
2711
|
}
|
|
2588
2712
|
},
|
|
2713
|
+
setName(name) {
|
|
2714
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
2715
|
+
return;
|
|
2716
|
+
}
|
|
2717
|
+
try {
|
|
2718
|
+
getOrCreateTraceState().name = name;
|
|
2719
|
+
} catch {
|
|
2720
|
+
}
|
|
2721
|
+
},
|
|
2589
2722
|
setMetadata(metadata) {
|
|
2590
2723
|
try {
|
|
2591
2724
|
if (typeof metadata !== "object" || metadata === null) {
|
|
@@ -2660,6 +2793,7 @@ var Bitfab = class {
|
|
|
2660
2793
|
serviceUrl: this.serviceUrl,
|
|
2661
2794
|
timeout: this.timeout
|
|
2662
2795
|
});
|
|
2796
|
+
this.datasets = new DatasetsClient(this.httpClient);
|
|
2663
2797
|
}
|
|
2664
2798
|
/**
|
|
2665
2799
|
* Decorate a class method as an automatically expanded trace root.
|
|
@@ -3564,6 +3698,7 @@ var Bitfab = class {
|
|
|
3564
3698
|
startedAt: traceState?.startedAt ?? startedAt,
|
|
3565
3699
|
endedAt,
|
|
3566
3700
|
sessionId: traceState?.sessionId,
|
|
3701
|
+
name: traceState?.name,
|
|
3567
3702
|
metadata: traceState?.metadata,
|
|
3568
3703
|
contexts: traceState?.contexts ?? [],
|
|
3569
3704
|
testRunId: traceState?.testRunId,
|
|
@@ -3882,6 +4017,15 @@ var Bitfab = class {
|
|
|
3882
4017
|
return Promise.resolve();
|
|
3883
4018
|
}
|
|
3884
4019
|
return this.httpClient.patchTrace(traceId, { setSessionId: sessionId });
|
|
4020
|
+
},
|
|
4021
|
+
setName: (name) => {
|
|
4022
|
+
if (!this.isTracingEnabled()) {
|
|
4023
|
+
return Promise.resolve();
|
|
4024
|
+
}
|
|
4025
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
4026
|
+
return Promise.resolve();
|
|
4027
|
+
}
|
|
4028
|
+
return this.httpClient.patchTrace(traceId, { setName: name });
|
|
3885
4029
|
}
|
|
3886
4030
|
};
|
|
3887
4031
|
}
|
|
@@ -3942,9 +4086,11 @@ var Bitfab = class {
|
|
|
3942
4086
|
const rawTrace = {
|
|
3943
4087
|
id: params.traceId,
|
|
3944
4088
|
started_at: params.startedAt,
|
|
3945
|
-
ended_at: params.endedAt
|
|
3946
|
-
workflow_name: params.traceFunctionKey
|
|
4089
|
+
ended_at: params.endedAt
|
|
3947
4090
|
};
|
|
4091
|
+
if (params.name) {
|
|
4092
|
+
rawTrace.name = params.name;
|
|
4093
|
+
}
|
|
3948
4094
|
if (params.metadata && Object.keys(params.metadata).length > 0) {
|
|
3949
4095
|
rawTrace.metadata = params.metadata;
|
|
3950
4096
|
}
|
|
@@ -4137,6 +4283,7 @@ var Bitfab = class {
|
|
|
4137
4283
|
contexts: [],
|
|
4138
4284
|
ingestionType: "seeded",
|
|
4139
4285
|
...options.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
4286
|
+
...options.name !== void 0 && { name: options.name },
|
|
4140
4287
|
...options.metadata !== void 0 && { metadata: options.metadata }
|
|
4141
4288
|
});
|
|
4142
4289
|
try {
|
|
@@ -4159,6 +4306,7 @@ var Bitfab = class {
|
|
|
4159
4306
|
startedAt,
|
|
4160
4307
|
endedAt: startedAt,
|
|
4161
4308
|
sessionId: options.sessionId,
|
|
4309
|
+
name: options.name,
|
|
4162
4310
|
metadata: options.metadata,
|
|
4163
4311
|
contexts: [],
|
|
4164
4312
|
ingestionType: "seeded"
|
|
@@ -4182,7 +4330,7 @@ var Bitfab = class {
|
|
|
4182
4330
|
`Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
|
|
4183
4331
|
);
|
|
4184
4332
|
}
|
|
4185
|
-
const { replay: doReplay } = await import("./replay-
|
|
4333
|
+
const { replay: doReplay } = await import("./replay-HMMWDSLB.js");
|
|
4186
4334
|
return doReplay(
|
|
4187
4335
|
this.httpClient,
|
|
4188
4336
|
this.serviceUrl,
|
|
@@ -4435,7 +4583,7 @@ async function seedFromRegistry(registry, pipeline, cases) {
|
|
|
4435
4583
|
sessionId: seedCase.sessionId
|
|
4436
4584
|
})
|
|
4437
4585
|
);
|
|
4438
|
-
const { flushTraces: flushTraces2 } = await import("./http-
|
|
4586
|
+
const { flushTraces: flushTraces2 } = await import("./http-UCJCOKW7.js");
|
|
4439
4587
|
await flushTraces2(3e4);
|
|
4440
4588
|
return { pipeline, traceFunctionKey, traceIds };
|
|
4441
4589
|
}
|
|
@@ -4452,6 +4600,7 @@ function resolveTraceFunctionKey(registration) {
|
|
|
4452
4600
|
|
|
4453
4601
|
export {
|
|
4454
4602
|
BitfabClaudeAgentHandler,
|
|
4603
|
+
DatasetsClient,
|
|
4455
4604
|
SUPPORTED_PROVIDERS,
|
|
4456
4605
|
BitfabLangGraphCallbackHandler,
|
|
4457
4606
|
BitfabLangGraphIntegration,
|
|
@@ -4467,4 +4616,4 @@ export {
|
|
|
4467
4616
|
defineReplayRegistry,
|
|
4468
4617
|
seedFromRegistry
|
|
4469
4618
|
};
|
|
4470
|
-
//# sourceMappingURL=chunk-
|
|
4619
|
+
//# sourceMappingURL=chunk-U3AKIFW3.js.map
|