bitfab 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-B4EJ2EQT.js → chunk-7NLXU444.js} +162 -13
- package/dist/chunk-7NLXU444.js.map +1 -0
- package/dist/{chunk-7OKE7FGZ.js → chunk-7VQJ2ABI.js} +2 -2
- package/dist/{chunk-3JIPWENI.js → chunk-RF55DQIZ.js} +10 -3
- package/dist/{chunk-3JIPWENI.js.map → chunk-RF55DQIZ.js.map} +1 -1
- package/dist/{chunk-OXE6M7CZ.js → chunk-T3JPGYBQ.js} +10 -3
- package/dist/{chunk-OXE6M7CZ.js.map → chunk-T3JPGYBQ.js.map} +1 -1
- package/dist/{http-RMF7T3LG.js → http-DOTAISBC.js} +2 -2
- package/dist/{http-ALSBGWPS.js → http-DXZSUEUK.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-6VF5AG2X.js → replay-WSPGQ2BI.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-B4EJ2EQT.js.map +0 -1
- /package/dist/{chunk-7OKE7FGZ.js.map → chunk-7VQJ2ABI.js.map} +0 -0
- /package/dist/{http-ALSBGWPS.js.map → http-DOTAISBC.js.map} +0 -0
- /package/dist/{http-RMF7T3LG.js.map → http-DXZSUEUK.js.map} +0 -0
- /package/dist/{replay-6VF5AG2X.js.map → replay-WSPGQ2BI.js.map} +0 -0
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.
|
|
100
|
+
__version__ = "0.41.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,
|
|
@@ -3538,8 +3546,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
3538
3546
|
const externalTrace = {
|
|
3539
3547
|
id: traceId,
|
|
3540
3548
|
started_at: this.traceStartedAt ?? nowIso(),
|
|
3541
|
-
ended_at: endedAt ?? nowIso()
|
|
3542
|
-
workflow_name: this.traceFunctionKey
|
|
3549
|
+
ended_at: endedAt ?? nowIso()
|
|
3543
3550
|
};
|
|
3544
3551
|
if (metadata) {
|
|
3545
3552
|
externalTrace.metadata = metadata;
|
|
@@ -4299,6 +4306,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
|
|
|
4299
4306
|
// src/client.ts
|
|
4300
4307
|
init_constants();
|
|
4301
4308
|
|
|
4309
|
+
// src/datasets.ts
|
|
4310
|
+
var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
|
|
4311
|
+
var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
|
|
4312
|
+
var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
|
|
4313
|
+
"completed",
|
|
4314
|
+
"errored"
|
|
4315
|
+
]);
|
|
4316
|
+
function sleep(ms) {
|
|
4317
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4318
|
+
}
|
|
4319
|
+
function datasetPath(datasetId, suffix = "") {
|
|
4320
|
+
return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
|
|
4321
|
+
}
|
|
4322
|
+
var DatasetsClient = class {
|
|
4323
|
+
constructor(httpClient) {
|
|
4324
|
+
this.httpClient = httpClient;
|
|
4325
|
+
}
|
|
4326
|
+
/**
|
|
4327
|
+
* Create a dataset, or update the one already named this way under the same
|
|
4328
|
+
* trace function. `created` reports which happened. An omitted description
|
|
4329
|
+
* leaves an existing one untouched.
|
|
4330
|
+
*/
|
|
4331
|
+
async save(params) {
|
|
4332
|
+
return this.httpClient.request("/api/sdk/datasets", {
|
|
4333
|
+
traceFunctionKey: params.traceFunctionKey,
|
|
4334
|
+
name: params.name,
|
|
4335
|
+
...params.description === void 0 ? {} : { description: params.description }
|
|
4336
|
+
});
|
|
4337
|
+
}
|
|
4338
|
+
/**
|
|
4339
|
+
* List datasets, scoped to one trace function when `traceFunctionKey` is
|
|
4340
|
+
* given and organization-wide otherwise.
|
|
4341
|
+
*/
|
|
4342
|
+
async list(params = {}) {
|
|
4343
|
+
const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
|
|
4344
|
+
const response = await this.httpClient.get(
|
|
4345
|
+
`/api/sdk/datasets${query}`
|
|
4346
|
+
);
|
|
4347
|
+
return response.datasets;
|
|
4348
|
+
}
|
|
4349
|
+
/** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
|
|
4350
|
+
async get(datasetId) {
|
|
4351
|
+
const response = await this.httpClient.get(
|
|
4352
|
+
datasetPath(datasetId)
|
|
4353
|
+
);
|
|
4354
|
+
return response.dataset;
|
|
4355
|
+
}
|
|
4356
|
+
/** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
|
|
4357
|
+
async listTraces(datasetId) {
|
|
4358
|
+
return this.httpClient.get(
|
|
4359
|
+
datasetPath(datasetId, "/traces")
|
|
4360
|
+
);
|
|
4361
|
+
}
|
|
4362
|
+
/**
|
|
4363
|
+
* Add traces to the dataset (1 to 100 ids per call). Traces outside the
|
|
4364
|
+
* organization or under another trace function are reported in
|
|
4365
|
+
* `skippedTraceIds` rather than failing the call.
|
|
4366
|
+
*/
|
|
4367
|
+
async addTraces(datasetId, traceIds) {
|
|
4368
|
+
return this.httpClient.request(
|
|
4369
|
+
datasetPath(datasetId, "/traces"),
|
|
4370
|
+
{ traceIds }
|
|
4371
|
+
);
|
|
4372
|
+
}
|
|
4373
|
+
/** Remove traces from the dataset. The traces themselves are never deleted. */
|
|
4374
|
+
async removeTraces(datasetId, traceIds) {
|
|
4375
|
+
return this.httpClient.request(
|
|
4376
|
+
datasetPath(datasetId, "/removeTraces"),
|
|
4377
|
+
{ traceIds }
|
|
4378
|
+
);
|
|
4379
|
+
}
|
|
4380
|
+
/**
|
|
4381
|
+
* Assign graders to the dataset (1 to 100 ids per call). Graders outside the
|
|
4382
|
+
* organization or under another trace function are reported in
|
|
4383
|
+
* `skippedGraderIds` rather than failing the call.
|
|
4384
|
+
*/
|
|
4385
|
+
async addGraders(datasetId, graderIds) {
|
|
4386
|
+
return this.httpClient.request(
|
|
4387
|
+
datasetPath(datasetId, "/graders"),
|
|
4388
|
+
{ graderIds }
|
|
4389
|
+
);
|
|
4390
|
+
}
|
|
4391
|
+
/** Unassign graders from the dataset. */
|
|
4392
|
+
async removeGraders(datasetId, graderIds) {
|
|
4393
|
+
return this.httpClient.request(
|
|
4394
|
+
datasetPath(datasetId, "/removeGraders"),
|
|
4395
|
+
{ graderIds }
|
|
4396
|
+
);
|
|
4397
|
+
}
|
|
4398
|
+
/**
|
|
4399
|
+
* Re-run graders over every trace in the dataset. Defaults to every assigned
|
|
4400
|
+
* grader; an unassigned id is rejected. Waits for the run to finish (up to
|
|
4401
|
+
* `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
|
|
4402
|
+
* run state seen either way. A request matching an in-flight run joins it.
|
|
4403
|
+
*/
|
|
4404
|
+
async rerunGraders(datasetId, options = {}) {
|
|
4405
|
+
const started = await this.httpClient.request(
|
|
4406
|
+
datasetPath(datasetId, "/rerunGraders"),
|
|
4407
|
+
options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
|
|
4408
|
+
);
|
|
4409
|
+
if (options.wait === false) {
|
|
4410
|
+
return started;
|
|
4411
|
+
}
|
|
4412
|
+
const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
|
|
4413
|
+
const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
|
|
4414
|
+
let run = started.run;
|
|
4415
|
+
while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
|
|
4416
|
+
await sleep(interval);
|
|
4417
|
+
run = await this.getGraderRerun(datasetId, run.id) ?? run;
|
|
4418
|
+
}
|
|
4419
|
+
return { run, joinedExisting: started.joinedExisting };
|
|
4420
|
+
}
|
|
4421
|
+
/**
|
|
4422
|
+
* The dataset's active grader re-run, or the run named by `runId`. Returns
|
|
4423
|
+
* `null` when nothing is active or the run does not belong to this dataset.
|
|
4424
|
+
*/
|
|
4425
|
+
async getGraderRerun(datasetId, runId) {
|
|
4426
|
+
const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
|
|
4427
|
+
const response = await this.httpClient.get(
|
|
4428
|
+
datasetPath(datasetId, `/rerunGraders${query}`)
|
|
4429
|
+
);
|
|
4430
|
+
return response.run;
|
|
4431
|
+
}
|
|
4432
|
+
};
|
|
4433
|
+
|
|
4302
4434
|
// src/dbSnapshot.ts
|
|
4303
4435
|
init_errors();
|
|
4304
4436
|
var SUPPORTED_PROVIDERS = ["neon"];
|
|
@@ -4708,8 +4840,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
4708
4840
|
externalTrace: {
|
|
4709
4841
|
id: rootSpan.traceId,
|
|
4710
4842
|
started_at: rootSpan.startedAt,
|
|
4711
|
-
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
4712
|
-
workflow_name: this.traceFunctionKey
|
|
4843
|
+
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
4713
4844
|
},
|
|
4714
4845
|
completed
|
|
4715
4846
|
};
|
|
@@ -4727,8 +4858,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
4727
4858
|
traceFunctionKey: this.traceFunctionKey,
|
|
4728
4859
|
externalTrace: {
|
|
4729
4860
|
id: rootSpan.traceId,
|
|
4730
|
-
started_at: rootSpan.startedAt
|
|
4731
|
-
workflow_name: this.traceFunctionKey
|
|
4861
|
+
started_at: rootSpan.startedAt
|
|
4732
4862
|
},
|
|
4733
4863
|
completed: false
|
|
4734
4864
|
};
|
|
@@ -5886,6 +6016,8 @@ var noOpSpan = {
|
|
|
5886
6016
|
var noOpTrace = {
|
|
5887
6017
|
setSessionId() {
|
|
5888
6018
|
},
|
|
6019
|
+
setName() {
|
|
6020
|
+
},
|
|
5889
6021
|
setMetadata() {
|
|
5890
6022
|
},
|
|
5891
6023
|
addContext() {
|
|
@@ -5960,6 +6092,15 @@ function getCurrentTrace() {
|
|
|
5960
6092
|
} catch {
|
|
5961
6093
|
}
|
|
5962
6094
|
},
|
|
6095
|
+
setName(name) {
|
|
6096
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
6097
|
+
return;
|
|
6098
|
+
}
|
|
6099
|
+
try {
|
|
6100
|
+
getOrCreateTraceState().name = name;
|
|
6101
|
+
} catch {
|
|
6102
|
+
}
|
|
6103
|
+
},
|
|
5963
6104
|
setMetadata(metadata) {
|
|
5964
6105
|
try {
|
|
5965
6106
|
if (typeof metadata !== "object" || metadata === null) {
|
|
@@ -6034,6 +6175,7 @@ var Bitfab = class {
|
|
|
6034
6175
|
serviceUrl: this.serviceUrl,
|
|
6035
6176
|
timeout: this.timeout
|
|
6036
6177
|
});
|
|
6178
|
+
this.datasets = new DatasetsClient(this.httpClient);
|
|
6037
6179
|
}
|
|
6038
6180
|
/**
|
|
6039
6181
|
* Decorate a class method as an automatically expanded trace root.
|
|
@@ -6938,6 +7080,7 @@ var Bitfab = class {
|
|
|
6938
7080
|
startedAt: traceState?.startedAt ?? startedAt,
|
|
6939
7081
|
endedAt,
|
|
6940
7082
|
sessionId: traceState?.sessionId,
|
|
7083
|
+
name: traceState?.name,
|
|
6941
7084
|
metadata: traceState?.metadata,
|
|
6942
7085
|
contexts: traceState?.contexts ?? [],
|
|
6943
7086
|
testRunId: traceState?.testRunId,
|
|
@@ -7256,6 +7399,15 @@ var Bitfab = class {
|
|
|
7256
7399
|
return Promise.resolve();
|
|
7257
7400
|
}
|
|
7258
7401
|
return this.httpClient.patchTrace(traceId, { setSessionId: sessionId });
|
|
7402
|
+
},
|
|
7403
|
+
setName: (name) => {
|
|
7404
|
+
if (!this.isTracingEnabled()) {
|
|
7405
|
+
return Promise.resolve();
|
|
7406
|
+
}
|
|
7407
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
7408
|
+
return Promise.resolve();
|
|
7409
|
+
}
|
|
7410
|
+
return this.httpClient.patchTrace(traceId, { setName: name });
|
|
7259
7411
|
}
|
|
7260
7412
|
};
|
|
7261
7413
|
}
|
|
@@ -7316,9 +7468,11 @@ var Bitfab = class {
|
|
|
7316
7468
|
const rawTrace = {
|
|
7317
7469
|
id: params.traceId,
|
|
7318
7470
|
started_at: params.startedAt,
|
|
7319
|
-
ended_at: params.endedAt
|
|
7320
|
-
workflow_name: params.traceFunctionKey
|
|
7471
|
+
ended_at: params.endedAt
|
|
7321
7472
|
};
|
|
7473
|
+
if (params.name) {
|
|
7474
|
+
rawTrace.name = params.name;
|
|
7475
|
+
}
|
|
7322
7476
|
if (params.metadata && Object.keys(params.metadata).length > 0) {
|
|
7323
7477
|
rawTrace.metadata = params.metadata;
|
|
7324
7478
|
}
|
|
@@ -7511,6 +7665,7 @@ var Bitfab = class {
|
|
|
7511
7665
|
contexts: [],
|
|
7512
7666
|
ingestionType: "seeded",
|
|
7513
7667
|
...options.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
7668
|
+
...options.name !== void 0 && { name: options.name },
|
|
7514
7669
|
...options.metadata !== void 0 && { metadata: options.metadata }
|
|
7515
7670
|
});
|
|
7516
7671
|
try {
|
|
@@ -7533,6 +7688,7 @@ var Bitfab = class {
|
|
|
7533
7688
|
startedAt,
|
|
7534
7689
|
endedAt: startedAt,
|
|
7535
7690
|
sessionId: options.sessionId,
|
|
7691
|
+
name: options.name,
|
|
7536
7692
|
metadata: options.metadata,
|
|
7537
7693
|
contexts: [],
|
|
7538
7694
|
ingestionType: "seeded"
|
|
@@ -7851,6 +8007,7 @@ assertAsyncStorageRegistered();
|
|
|
7851
8007
|
BitfabOpenAITracingProcessor,
|
|
7852
8008
|
BitfabVercelAiHandler,
|
|
7853
8009
|
DEFAULT_SERVICE_URL,
|
|
8010
|
+
DatasetsClient,
|
|
7854
8011
|
DbBranchReplayError,
|
|
7855
8012
|
HttpClient,
|
|
7856
8013
|
NO_MOCK_OVERRIDE,
|