@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
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.
|
|
91
|
+
__version__ = "0.41.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,
|
|
@@ -3529,8 +3537,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
3529
3537
|
const externalTrace = {
|
|
3530
3538
|
id: traceId,
|
|
3531
3539
|
started_at: this.traceStartedAt ?? nowIso(),
|
|
3532
|
-
ended_at: endedAt ?? nowIso()
|
|
3533
|
-
workflow_name: this.traceFunctionKey
|
|
3540
|
+
ended_at: endedAt ?? nowIso()
|
|
3534
3541
|
};
|
|
3535
3542
|
if (metadata) {
|
|
3536
3543
|
externalTrace.metadata = metadata;
|
|
@@ -4290,6 +4297,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
|
|
|
4290
4297
|
// src/client.ts
|
|
4291
4298
|
init_constants();
|
|
4292
4299
|
|
|
4300
|
+
// src/datasets.ts
|
|
4301
|
+
var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
|
|
4302
|
+
var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
|
|
4303
|
+
var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
|
|
4304
|
+
"completed",
|
|
4305
|
+
"errored"
|
|
4306
|
+
]);
|
|
4307
|
+
function sleep(ms) {
|
|
4308
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4309
|
+
}
|
|
4310
|
+
function datasetPath(datasetId, suffix = "") {
|
|
4311
|
+
return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
|
|
4312
|
+
}
|
|
4313
|
+
var DatasetsClient = class {
|
|
4314
|
+
constructor(httpClient) {
|
|
4315
|
+
this.httpClient = httpClient;
|
|
4316
|
+
}
|
|
4317
|
+
/**
|
|
4318
|
+
* Create a dataset, or update the one already named this way under the same
|
|
4319
|
+
* trace function. `created` reports which happened. An omitted description
|
|
4320
|
+
* leaves an existing one untouched.
|
|
4321
|
+
*/
|
|
4322
|
+
async save(params) {
|
|
4323
|
+
return this.httpClient.request("/api/sdk/datasets", {
|
|
4324
|
+
traceFunctionKey: params.traceFunctionKey,
|
|
4325
|
+
name: params.name,
|
|
4326
|
+
...params.description === void 0 ? {} : { description: params.description }
|
|
4327
|
+
});
|
|
4328
|
+
}
|
|
4329
|
+
/**
|
|
4330
|
+
* List datasets, scoped to one trace function when `traceFunctionKey` is
|
|
4331
|
+
* given and organization-wide otherwise.
|
|
4332
|
+
*/
|
|
4333
|
+
async list(params = {}) {
|
|
4334
|
+
const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
|
|
4335
|
+
const response = await this.httpClient.get(
|
|
4336
|
+
`/api/sdk/datasets${query}`
|
|
4337
|
+
);
|
|
4338
|
+
return response.datasets;
|
|
4339
|
+
}
|
|
4340
|
+
/** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
|
|
4341
|
+
async get(datasetId) {
|
|
4342
|
+
const response = await this.httpClient.get(
|
|
4343
|
+
datasetPath(datasetId)
|
|
4344
|
+
);
|
|
4345
|
+
return response.dataset;
|
|
4346
|
+
}
|
|
4347
|
+
/** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
|
|
4348
|
+
async listTraces(datasetId) {
|
|
4349
|
+
return this.httpClient.get(
|
|
4350
|
+
datasetPath(datasetId, "/traces")
|
|
4351
|
+
);
|
|
4352
|
+
}
|
|
4353
|
+
/**
|
|
4354
|
+
* Add traces to the dataset (1 to 100 ids per call). Traces outside the
|
|
4355
|
+
* organization or under another trace function are reported in
|
|
4356
|
+
* `skippedTraceIds` rather than failing the call.
|
|
4357
|
+
*/
|
|
4358
|
+
async addTraces(datasetId, traceIds) {
|
|
4359
|
+
return this.httpClient.request(
|
|
4360
|
+
datasetPath(datasetId, "/traces"),
|
|
4361
|
+
{ traceIds }
|
|
4362
|
+
);
|
|
4363
|
+
}
|
|
4364
|
+
/** Remove traces from the dataset. The traces themselves are never deleted. */
|
|
4365
|
+
async removeTraces(datasetId, traceIds) {
|
|
4366
|
+
return this.httpClient.request(
|
|
4367
|
+
datasetPath(datasetId, "/removeTraces"),
|
|
4368
|
+
{ traceIds }
|
|
4369
|
+
);
|
|
4370
|
+
}
|
|
4371
|
+
/**
|
|
4372
|
+
* Assign graders to the dataset (1 to 100 ids per call). Graders outside the
|
|
4373
|
+
* organization or under another trace function are reported in
|
|
4374
|
+
* `skippedGraderIds` rather than failing the call.
|
|
4375
|
+
*/
|
|
4376
|
+
async addGraders(datasetId, graderIds) {
|
|
4377
|
+
return this.httpClient.request(
|
|
4378
|
+
datasetPath(datasetId, "/graders"),
|
|
4379
|
+
{ graderIds }
|
|
4380
|
+
);
|
|
4381
|
+
}
|
|
4382
|
+
/** Unassign graders from the dataset. */
|
|
4383
|
+
async removeGraders(datasetId, graderIds) {
|
|
4384
|
+
return this.httpClient.request(
|
|
4385
|
+
datasetPath(datasetId, "/removeGraders"),
|
|
4386
|
+
{ graderIds }
|
|
4387
|
+
);
|
|
4388
|
+
}
|
|
4389
|
+
/**
|
|
4390
|
+
* Re-run graders over every trace in the dataset. Defaults to every assigned
|
|
4391
|
+
* grader; an unassigned id is rejected. Waits for the run to finish (up to
|
|
4392
|
+
* `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
|
|
4393
|
+
* run state seen either way. A request matching an in-flight run joins it.
|
|
4394
|
+
*/
|
|
4395
|
+
async rerunGraders(datasetId, options = {}) {
|
|
4396
|
+
const started = await this.httpClient.request(
|
|
4397
|
+
datasetPath(datasetId, "/rerunGraders"),
|
|
4398
|
+
options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
|
|
4399
|
+
);
|
|
4400
|
+
if (options.wait === false) {
|
|
4401
|
+
return started;
|
|
4402
|
+
}
|
|
4403
|
+
const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
|
|
4404
|
+
const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
|
|
4405
|
+
let run = started.run;
|
|
4406
|
+
while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
|
|
4407
|
+
await sleep(interval);
|
|
4408
|
+
run = await this.getGraderRerun(datasetId, run.id) ?? run;
|
|
4409
|
+
}
|
|
4410
|
+
return { run, joinedExisting: started.joinedExisting };
|
|
4411
|
+
}
|
|
4412
|
+
/**
|
|
4413
|
+
* The dataset's active grader re-run, or the run named by `runId`. Returns
|
|
4414
|
+
* `null` when nothing is active or the run does not belong to this dataset.
|
|
4415
|
+
*/
|
|
4416
|
+
async getGraderRerun(datasetId, runId) {
|
|
4417
|
+
const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
|
|
4418
|
+
const response = await this.httpClient.get(
|
|
4419
|
+
datasetPath(datasetId, `/rerunGraders${query}`)
|
|
4420
|
+
);
|
|
4421
|
+
return response.run;
|
|
4422
|
+
}
|
|
4423
|
+
};
|
|
4424
|
+
|
|
4293
4425
|
// src/dbSnapshot.ts
|
|
4294
4426
|
init_errors();
|
|
4295
4427
|
var SUPPORTED_PROVIDERS = ["neon"];
|
|
@@ -4699,8 +4831,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
4699
4831
|
externalTrace: {
|
|
4700
4832
|
id: rootSpan.traceId,
|
|
4701
4833
|
started_at: rootSpan.startedAt,
|
|
4702
|
-
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
4703
|
-
workflow_name: this.traceFunctionKey
|
|
4834
|
+
ended_at: rootSpan.endedAt ?? nowIso2()
|
|
4704
4835
|
},
|
|
4705
4836
|
completed
|
|
4706
4837
|
};
|
|
@@ -4718,8 +4849,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
4718
4849
|
traceFunctionKey: this.traceFunctionKey,
|
|
4719
4850
|
externalTrace: {
|
|
4720
4851
|
id: rootSpan.traceId,
|
|
4721
|
-
started_at: rootSpan.startedAt
|
|
4722
|
-
workflow_name: this.traceFunctionKey
|
|
4852
|
+
started_at: rootSpan.startedAt
|
|
4723
4853
|
},
|
|
4724
4854
|
completed: false
|
|
4725
4855
|
};
|
|
@@ -5877,6 +6007,8 @@ var noOpSpan = {
|
|
|
5877
6007
|
var noOpTrace = {
|
|
5878
6008
|
setSessionId() {
|
|
5879
6009
|
},
|
|
6010
|
+
setName() {
|
|
6011
|
+
},
|
|
5880
6012
|
setMetadata() {
|
|
5881
6013
|
},
|
|
5882
6014
|
addContext() {
|
|
@@ -5951,6 +6083,15 @@ function getCurrentTrace() {
|
|
|
5951
6083
|
} catch {
|
|
5952
6084
|
}
|
|
5953
6085
|
},
|
|
6086
|
+
setName(name) {
|
|
6087
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
6088
|
+
return;
|
|
6089
|
+
}
|
|
6090
|
+
try {
|
|
6091
|
+
getOrCreateTraceState().name = name;
|
|
6092
|
+
} catch {
|
|
6093
|
+
}
|
|
6094
|
+
},
|
|
5954
6095
|
setMetadata(metadata) {
|
|
5955
6096
|
try {
|
|
5956
6097
|
if (typeof metadata !== "object" || metadata === null) {
|
|
@@ -6025,6 +6166,7 @@ var Bitfab = class {
|
|
|
6025
6166
|
serviceUrl: this.serviceUrl,
|
|
6026
6167
|
timeout: this.timeout
|
|
6027
6168
|
});
|
|
6169
|
+
this.datasets = new DatasetsClient(this.httpClient);
|
|
6028
6170
|
}
|
|
6029
6171
|
/**
|
|
6030
6172
|
* Decorate a class method as an automatically expanded trace root.
|
|
@@ -6929,6 +7071,7 @@ var Bitfab = class {
|
|
|
6929
7071
|
startedAt: traceState?.startedAt ?? startedAt,
|
|
6930
7072
|
endedAt,
|
|
6931
7073
|
sessionId: traceState?.sessionId,
|
|
7074
|
+
name: traceState?.name,
|
|
6932
7075
|
metadata: traceState?.metadata,
|
|
6933
7076
|
contexts: traceState?.contexts ?? [],
|
|
6934
7077
|
testRunId: traceState?.testRunId,
|
|
@@ -7247,6 +7390,15 @@ var Bitfab = class {
|
|
|
7247
7390
|
return Promise.resolve();
|
|
7248
7391
|
}
|
|
7249
7392
|
return this.httpClient.patchTrace(traceId, { setSessionId: sessionId });
|
|
7393
|
+
},
|
|
7394
|
+
setName: (name) => {
|
|
7395
|
+
if (!this.isTracingEnabled()) {
|
|
7396
|
+
return Promise.resolve();
|
|
7397
|
+
}
|
|
7398
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
7399
|
+
return Promise.resolve();
|
|
7400
|
+
}
|
|
7401
|
+
return this.httpClient.patchTrace(traceId, { setName: name });
|
|
7250
7402
|
}
|
|
7251
7403
|
};
|
|
7252
7404
|
}
|
|
@@ -7307,9 +7459,11 @@ var Bitfab = class {
|
|
|
7307
7459
|
const rawTrace = {
|
|
7308
7460
|
id: params.traceId,
|
|
7309
7461
|
started_at: params.startedAt,
|
|
7310
|
-
ended_at: params.endedAt
|
|
7311
|
-
workflow_name: params.traceFunctionKey
|
|
7462
|
+
ended_at: params.endedAt
|
|
7312
7463
|
};
|
|
7464
|
+
if (params.name) {
|
|
7465
|
+
rawTrace.name = params.name;
|
|
7466
|
+
}
|
|
7313
7467
|
if (params.metadata && Object.keys(params.metadata).length > 0) {
|
|
7314
7468
|
rawTrace.metadata = params.metadata;
|
|
7315
7469
|
}
|
|
@@ -7502,6 +7656,7 @@ var Bitfab = class {
|
|
|
7502
7656
|
contexts: [],
|
|
7503
7657
|
ingestionType: "seeded",
|
|
7504
7658
|
...options.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
7659
|
+
...options.name !== void 0 && { name: options.name },
|
|
7505
7660
|
...options.metadata !== void 0 && { metadata: options.metadata }
|
|
7506
7661
|
});
|
|
7507
7662
|
try {
|
|
@@ -7524,6 +7679,7 @@ var Bitfab = class {
|
|
|
7524
7679
|
startedAt,
|
|
7525
7680
|
endedAt: startedAt,
|
|
7526
7681
|
sessionId: options.sessionId,
|
|
7682
|
+
name: options.name,
|
|
7527
7683
|
metadata: options.metadata,
|
|
7528
7684
|
contexts: [],
|
|
7529
7685
|
ingestionType: "seeded"
|
|
@@ -7842,6 +7998,7 @@ assertAsyncStorageRegistered();
|
|
|
7842
7998
|
BitfabOpenAITracingProcessor,
|
|
7843
7999
|
BitfabVercelAiHandler,
|
|
7844
8000
|
DEFAULT_SERVICE_URL,
|
|
8001
|
+
DatasetsClient,
|
|
7845
8002
|
DbBranchReplayError,
|
|
7846
8003
|
HttpClient,
|
|
7847
8004
|
NO_MOCK_OVERRIDE,
|