@bitfab/sdk 0.33.6 → 0.34.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/README.md +19 -0
- package/dist/chunk-4J36FZ4K.js +2299 -0
- package/dist/chunk-4J36FZ4K.js.map +1 -0
- package/dist/{chunk-JANSX65W.js → chunk-ESKBRHVG.js} +90 -608
- package/dist/chunk-ESKBRHVG.js.map +1 -0
- package/dist/index.cjs +2300 -1369
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +374 -28
- package/dist/index.d.ts +374 -28
- package/dist/index.js +5 -5
- package/dist/node.cjs +2290 -1359
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +5 -5
- package/dist/{replay-SRQI4QMY.js → replay-QFNYP7EY.js} +2 -2
- package/package.json +6 -1
- package/dist/chunk-DPV6PBWE.js +0 -916
- package/dist/chunk-DPV6PBWE.js.map +0 -1
- package/dist/chunk-JANSX65W.js.map +0 -1
- /package/dist/{replay-SRQI4QMY.js.map → replay-QFNYP7EY.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -70,7 +70,21 @@ interface DbSnapshotRef {
|
|
|
70
70
|
*/
|
|
71
71
|
declare class BitfabError extends Error {
|
|
72
72
|
readonly url?: string | undefined;
|
|
73
|
-
|
|
73
|
+
/**
|
|
74
|
+
* HTTP status the request failed with, when it failed with one. The
|
|
75
|
+
* transport's retry policy needs the code itself (retry 408/425/429/5xx,
|
|
76
|
+
* never a 4xx the server will reject again), which a formatted message
|
|
77
|
+
* cannot supply. Absent for network failures and non-HTTP errors.
|
|
78
|
+
*/
|
|
79
|
+
readonly status?: number | undefined;
|
|
80
|
+
constructor(message: string, url?: string | undefined,
|
|
81
|
+
/**
|
|
82
|
+
* HTTP status the request failed with, when it failed with one. The
|
|
83
|
+
* transport's retry policy needs the code itself (retry 408/425/429/5xx,
|
|
84
|
+
* never a 4xx the server will reject again), which a formatted message
|
|
85
|
+
* cannot supply. Absent for network failures and non-HTTP errors.
|
|
86
|
+
*/
|
|
87
|
+
status?: number | undefined);
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
/**
|
|
@@ -196,6 +210,15 @@ interface DbBranchLease {
|
|
|
196
210
|
*/
|
|
197
211
|
region?: string;
|
|
198
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Wire shape of the caller's `ReplayOptions.dbBranch`, sent to
|
|
215
|
+
* `/api/sdk/replay/start` and applied per lease.
|
|
216
|
+
*/
|
|
217
|
+
interface DbBranchSettings {
|
|
218
|
+
minCu?: number;
|
|
219
|
+
maxCu?: number;
|
|
220
|
+
warmupSql?: string;
|
|
221
|
+
}
|
|
199
222
|
/**
|
|
200
223
|
* Pre-built lookup table of historical span outputs.
|
|
201
224
|
* Keys are `${traceFunctionKey}:${spanName}:${callIndex}` so that repeated
|
|
@@ -248,17 +271,6 @@ interface ReplayContext {
|
|
|
248
271
|
* must also set this.
|
|
249
272
|
*/
|
|
250
273
|
dbSnapshotAccessed?: boolean;
|
|
251
|
-
/**
|
|
252
|
-
* Collector for the replay item's trace-persistence work. When present,
|
|
253
|
-
* the root span's send path pushes a promise that resolves only after
|
|
254
|
-
* every span upload AND the trace completion have been sent (registered
|
|
255
|
-
* synchronously at send time, so the replay runner can await it after
|
|
256
|
-
* the wrapped fn resolves). This is what lets replay guarantee traces
|
|
257
|
-
* are persisted server-side before `completeReplay` builds the
|
|
258
|
-
* trace-ID mapping. Absent outside replay, where sends stay
|
|
259
|
-
* fire-and-forget.
|
|
260
|
-
*/
|
|
261
|
-
pendingPersistence?: Promise<unknown>[];
|
|
262
274
|
}
|
|
263
275
|
|
|
264
276
|
/**
|
|
@@ -266,16 +278,23 @@ interface ReplayContext {
|
|
|
266
278
|
*
|
|
267
279
|
* This module provides:
|
|
268
280
|
* - HttpClient class for making API requests
|
|
269
|
-
* - awaitOnExit helper
|
|
281
|
+
* - awaitOnExit helper so deferred span work still gates process exit
|
|
270
282
|
*/
|
|
271
283
|
|
|
272
284
|
/**
|
|
273
|
-
* Wait for
|
|
274
|
-
* Useful in tests and scripts to ensure all
|
|
285
|
+
* Wait for pending fire-and-forget requests AND every live span transport to
|
|
286
|
+
* deliver, within one total deadline. Useful in tests and scripts to ensure all
|
|
287
|
+
* data has been sent before asserting or exiting.
|
|
288
|
+
*
|
|
289
|
+
* Returns `false` when delivery failed or the deadline expired, so a caller
|
|
290
|
+
* that depends on persistence (replay does) can react instead of assuming a
|
|
291
|
+
* drained queue means the server has the data. When delivery goes through a
|
|
292
|
+
* Collector, `true` means the Collector accepted the spans; it is not proof
|
|
293
|
+
* that Bitfab committed them.
|
|
275
294
|
*
|
|
276
|
-
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
295
|
+
* @param timeoutMs - Maximum total time to wait in milliseconds (default: 5000)
|
|
277
296
|
*/
|
|
278
|
-
declare function flushTraces(timeoutMs?: number): Promise<
|
|
297
|
+
declare function flushTraces(timeoutMs?: number): Promise<boolean>;
|
|
279
298
|
/**
|
|
280
299
|
* How the API key is supplied internally: either a literal string or a
|
|
281
300
|
* function resolved each time the key is needed (at request/send time). The
|
|
@@ -284,6 +303,11 @@ declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
|
284
303
|
* case) is still picked up.
|
|
285
304
|
*/
|
|
286
305
|
type ApiKeyInput = string | (() => string | undefined);
|
|
306
|
+
interface HttpClientConfig {
|
|
307
|
+
apiKey?: ApiKeyInput;
|
|
308
|
+
serviceUrl: string;
|
|
309
|
+
timeout?: number;
|
|
310
|
+
}
|
|
287
311
|
type SpanOccurrence = "first" | "last" | number;
|
|
288
312
|
type SpanLookup = {
|
|
289
313
|
id: string;
|
|
@@ -310,6 +334,163 @@ interface CapturedSpan {
|
|
|
310
334
|
startedAt: string | null;
|
|
311
335
|
endedAt: string | null;
|
|
312
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* HTTP client for Bitfab API requests.
|
|
339
|
+
*
|
|
340
|
+
* Provides methods for different API endpoints with proper error handling,
|
|
341
|
+
* timeouts, and authentication.
|
|
342
|
+
*/
|
|
343
|
+
declare class HttpClient {
|
|
344
|
+
private readonly apiKey;
|
|
345
|
+
private readonly serviceUrl;
|
|
346
|
+
private readonly timeout;
|
|
347
|
+
private traceTransport;
|
|
348
|
+
private readonly deferredWork;
|
|
349
|
+
private closed;
|
|
350
|
+
private closing;
|
|
351
|
+
constructor(config: HttpClientConfig);
|
|
352
|
+
/**
|
|
353
|
+
* Resolve the API key at the moment it is needed (request time), invoking
|
|
354
|
+
* the function form if one was supplied. Never read at construction.
|
|
355
|
+
*/
|
|
356
|
+
private resolveApiKey;
|
|
357
|
+
/**
|
|
358
|
+
* This client's span transport, built on first use.
|
|
359
|
+
*
|
|
360
|
+
* Lazy on purpose: a client that never sends a span must never start a batch
|
|
361
|
+
* worker. Every framework integration created from a `Bitfab` client shares
|
|
362
|
+
* the owning client's `HttpClient`, so handlers reuse this one worker instead
|
|
363
|
+
* of each spinning up their own.
|
|
364
|
+
*/
|
|
365
|
+
private getTraceTransport;
|
|
366
|
+
/**
|
|
367
|
+
* Track deferred span work so this client's own lifecycle waits for it, and
|
|
368
|
+
* so the process-wide flush and exit hook do too.
|
|
369
|
+
*/
|
|
370
|
+
trackDeferred<T>(promise: Promise<T>): Promise<T>;
|
|
371
|
+
/**
|
|
372
|
+
* Settle only THIS client's deferred span work. Scoped deliberately: the
|
|
373
|
+
* global set can contain another client's long-running finalize, and
|
|
374
|
+
* attributing its timeout here would fail a client whose own work succeeded.
|
|
375
|
+
*/
|
|
376
|
+
settleDeferredWork(timeoutMs?: number): Promise<boolean>;
|
|
377
|
+
/**
|
|
378
|
+
* Wait for spans queued by this client to be delivered, within one deadline.
|
|
379
|
+
* Returns false on delivery failure or timeout.
|
|
380
|
+
*/
|
|
381
|
+
waitForPendingRequests(timeoutMs?: number): Promise<boolean>;
|
|
382
|
+
/**
|
|
383
|
+
* Flush and permanently close this client's tracing transport. Idempotent:
|
|
384
|
+
* a second call joins the first rather than tearing down a pipeline the
|
|
385
|
+
* first call already owns.
|
|
386
|
+
*/
|
|
387
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
388
|
+
/**
|
|
389
|
+
* Make an HTTP request to the Bitfab API. Defaults to POST; pass
|
|
390
|
+
* `options.method` to use a different verb (e.g. "PATCH").
|
|
391
|
+
*
|
|
392
|
+
* @param endpoint - The API endpoint (without base URL)
|
|
393
|
+
* @param payload - The request body
|
|
394
|
+
* @param options - Optional request options
|
|
395
|
+
* @returns The parsed JSON response
|
|
396
|
+
* @throws {BitfabError} If the request fails
|
|
397
|
+
*/
|
|
398
|
+
request<T>(endpoint: string, payload: Record<string, unknown>, options?: {
|
|
399
|
+
timeout?: number;
|
|
400
|
+
method?: "POST" | "PATCH" | "PUT";
|
|
401
|
+
}): Promise<T>;
|
|
402
|
+
/**
|
|
403
|
+
* Look up a function by name.
|
|
404
|
+
* Blocks until complete - needed for function execution.
|
|
405
|
+
*/
|
|
406
|
+
lookupFunction<T>(name: string): Promise<T>;
|
|
407
|
+
getTraceSpan(traceId: string, lookup: SpanLookup): Promise<CapturedSpan | null>;
|
|
408
|
+
private get;
|
|
409
|
+
/**
|
|
410
|
+
* Queue an internal trace (from local BAML execution via `call()`) onto this
|
|
411
|
+
* client's batching transport. `functionId` moves into the payload because
|
|
412
|
+
* the OTLP carrier has no path to carry it.
|
|
413
|
+
*/
|
|
414
|
+
sendInternalTrace(functionId: string, payload: Record<string, unknown>): void;
|
|
415
|
+
/**
|
|
416
|
+
* Queue an external span (from withSpan wrapper or OpenAI tracing) onto this
|
|
417
|
+
* client's batching transport. Fire-and-forget: the transport owns delivery,
|
|
418
|
+
* so callers await `flushTraces()` or `close()` rather than a per-span
|
|
419
|
+
* promise.
|
|
420
|
+
*/
|
|
421
|
+
sendExternalSpan(payload: Record<string, unknown>): void;
|
|
422
|
+
/**
|
|
423
|
+
* Queue an external trace completion (from OpenAI tracing) onto this
|
|
424
|
+
* client's batching transport. Fire-and-forget for the same reason as
|
|
425
|
+
* {@link HttpClient.sendExternalSpan}; replay confirms persistence with the
|
|
426
|
+
* server-authoritative barrier in `replay.ts`, not by awaiting this call.
|
|
427
|
+
*/
|
|
428
|
+
sendExternalTrace(payload: Record<string, unknown>): void;
|
|
429
|
+
/**
|
|
430
|
+
* Partial update of an existing trace identified by its Bitfab trace ID.
|
|
431
|
+
* Used by the detached `client.getTrace(id)` handle.
|
|
432
|
+
*
|
|
433
|
+
* Blocking, like the other trace-API calls: it resolves once the server has
|
|
434
|
+
* applied the change and rejects if the server refused it. A patch targets a
|
|
435
|
+
* trace that is already closed, so there is no batch for it to ride along
|
|
436
|
+
* with and no later signal that would reveal a silent failure.
|
|
437
|
+
*/
|
|
438
|
+
patchTrace(traceId: string, payload: {
|
|
439
|
+
appendContexts?: Record<string, unknown>[];
|
|
440
|
+
mergeMetadata?: Record<string, unknown>;
|
|
441
|
+
setSessionId?: string;
|
|
442
|
+
}): Promise<void>;
|
|
443
|
+
/**
|
|
444
|
+
* Start a replay session by fetching historical traces.
|
|
445
|
+
* Blocking call - creates a test run and returns lightweight item references.
|
|
446
|
+
*/
|
|
447
|
+
startReplay(traceFunctionKey: string, limit: number | undefined, traceIds?: string[], name?: string, codeChangeDescription?: string | null, codeChangeFiles?: CodeChangeFile[] | null, includeDbBranchLease?: boolean, experimentGroupId?: string, datasetId?: string, graderIds?: string[], dbBranchSettings?: DbBranchSettings): Promise<StartReplayResponse>;
|
|
448
|
+
/**
|
|
449
|
+
* Fetch an external span by ID.
|
|
450
|
+
* Blocking GET request.
|
|
451
|
+
*/
|
|
452
|
+
getExternalSpan(spanId: string): Promise<ExternalSpanResponse>;
|
|
453
|
+
/**
|
|
454
|
+
* Fetch the span tree for a root span.
|
|
455
|
+
* Blocking GET request.
|
|
456
|
+
*
|
|
457
|
+
* Pass `includeOutputs: false` for a payload-free tree (structure +
|
|
458
|
+
* `externalSpanId` only), so recorded outputs are fetched lazily per mocked
|
|
459
|
+
* span instead of all up front. Omit it (default eager) for `mock: "all"`.
|
|
460
|
+
*/
|
|
461
|
+
getSpanTree(externalSpanId: string, options?: {
|
|
462
|
+
includeOutputs?: boolean;
|
|
463
|
+
}): Promise<SpanTreeResponse>;
|
|
464
|
+
/**
|
|
465
|
+
* Read which of a replay run's traces the server has fully persisted.
|
|
466
|
+
*
|
|
467
|
+
* With `expectedSpanCounts`, a trace appears in the response only once it
|
|
468
|
+
* has a final status AND at least that many persisted spans, which is what
|
|
469
|
+
* makes this a real barrier rather than a "the row exists" check.
|
|
470
|
+
*/
|
|
471
|
+
getReplayStatus(testRunId: string, expectedSpanCounts: Record<string, number>): Promise<ReplayStatusResponse>;
|
|
472
|
+
/**
|
|
473
|
+
* Mark a replay test run as completed.
|
|
474
|
+
* Blocking call.
|
|
475
|
+
*/
|
|
476
|
+
completeReplay(testRunId: string): Promise<CompleteReplayResponse>;
|
|
477
|
+
/**
|
|
478
|
+
* Ask the server to materialize a per-trace DB branch lease from a
|
|
479
|
+
* captured `dbSnapshotRef`. Blocking - the resolver creates a Neon
|
|
480
|
+
* snapshot + preview branch and polls operations to readiness, which
|
|
481
|
+
* can take seconds.
|
|
482
|
+
*/
|
|
483
|
+
resolveDbBranchLease(testRunId: string, traceId: string, dbBranchSettings?: DbBranchSettings): Promise<{
|
|
484
|
+
dbSnapshotRef: DbSnapshotRef | null;
|
|
485
|
+
lease: DbBranchLease | null;
|
|
486
|
+
leaseError: {
|
|
487
|
+
code: string;
|
|
488
|
+
message: string;
|
|
489
|
+
} | null;
|
|
490
|
+
}>;
|
|
491
|
+
/** Release a previously-resolved DB branch by deleting its Neon branch. Idempotent server-side. */
|
|
492
|
+
releaseDbBranchLease(neonBranchId: string): Promise<void>;
|
|
493
|
+
}
|
|
313
494
|
interface TokenUsage {
|
|
314
495
|
input: number | null;
|
|
315
496
|
output: number | null;
|
|
@@ -328,6 +509,112 @@ interface CodeChangeFile {
|
|
|
328
509
|
before: string;
|
|
329
510
|
after: string;
|
|
330
511
|
}
|
|
512
|
+
interface StartReplayResponse {
|
|
513
|
+
testRunId: string;
|
|
514
|
+
testRunUrl: string;
|
|
515
|
+
items: Array<{
|
|
516
|
+
/** Bitfab trace ID of the original (historical) trace being replayed. */
|
|
517
|
+
originalTraceId?: string;
|
|
518
|
+
/** External span ID the recorded inputs were read from (the original root span). */
|
|
519
|
+
originalSpanId?: string;
|
|
520
|
+
/** @deprecated alias for `originalTraceId`; the only key emitted by servers that predate the rename. */
|
|
521
|
+
sourceTraceId: string;
|
|
522
|
+
/** @deprecated alias for `originalSpanId`; the only key emitted by servers that predate the rename. */
|
|
523
|
+
sourceSpanId: string;
|
|
524
|
+
durationMs: number | null;
|
|
525
|
+
tokens: TokenUsage | null;
|
|
526
|
+
model: string | null;
|
|
527
|
+
/**
|
|
528
|
+
* The DB snapshot ref captured by the SDK at trace open. Surfaced so
|
|
529
|
+
* the SDK can pass it to the lease-resolver step (or report when no
|
|
530
|
+
* snapshot was captured for this trace).
|
|
531
|
+
*/
|
|
532
|
+
dbSnapshotRef?: DbSnapshotRef;
|
|
533
|
+
/**
|
|
534
|
+
* Populated once the server-side resolver has materialized a per-item
|
|
535
|
+
* branch from `dbSnapshotRef`. The SDK exposes this to customer code
|
|
536
|
+
* via `getCurrentReplayBranch()`. Absent until the resolver lands.
|
|
537
|
+
*/
|
|
538
|
+
dbBranchLease?: DbBranchLease;
|
|
539
|
+
/**
|
|
540
|
+
* Why the branch could not be resolved, when one was requested and the
|
|
541
|
+
* attempt failed. Distinct from both fields being absent, which means the
|
|
542
|
+
* trace carried no snapshot ref so nothing was attempted.
|
|
543
|
+
*/
|
|
544
|
+
dbBranchLeaseError?: {
|
|
545
|
+
code: string;
|
|
546
|
+
message: string;
|
|
547
|
+
};
|
|
548
|
+
}>;
|
|
549
|
+
}
|
|
550
|
+
interface ExternalSpanResponse {
|
|
551
|
+
id: string;
|
|
552
|
+
externalTraceId: string;
|
|
553
|
+
rawData: {
|
|
554
|
+
span_data: {
|
|
555
|
+
input: unknown;
|
|
556
|
+
output: unknown;
|
|
557
|
+
input_meta?: unknown;
|
|
558
|
+
output_meta?: unknown;
|
|
559
|
+
input_serialized?: {
|
|
560
|
+
json: unknown;
|
|
561
|
+
meta: unknown;
|
|
562
|
+
};
|
|
563
|
+
output_serialized?: {
|
|
564
|
+
json: unknown;
|
|
565
|
+
meta: unknown;
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
interface ReplayStatusResponse {
|
|
571
|
+
/**
|
|
572
|
+
* Local replay trace id -> server trace row id, for the traces the server
|
|
573
|
+
* considers fully persisted. Traces still short of their expected span count
|
|
574
|
+
* are simply absent.
|
|
575
|
+
*/
|
|
576
|
+
traceIds?: Record<string, string>;
|
|
577
|
+
}
|
|
578
|
+
interface CompleteReplayResponse {
|
|
579
|
+
id: string;
|
|
580
|
+
status: string;
|
|
581
|
+
traceIds?: Record<string, string>;
|
|
582
|
+
/**
|
|
583
|
+
* Per-replay-trace token usage, keyed by the server trace id (the values of
|
|
584
|
+
* `traceIds`). Aggregated server-side from the freshly-uploaded replay spans,
|
|
585
|
+
* so it's the REPLAYED run's tokens (the same source Studio reads), not the
|
|
586
|
+
* original trace's. The SDK maps each item onto this to set
|
|
587
|
+
* `ReplayItem.tokens`. Absent on servers that predate this field.
|
|
588
|
+
*/
|
|
589
|
+
tokens?: Record<string, TokenUsage | null>;
|
|
590
|
+
/**
|
|
591
|
+
* Number of traces the server has persisted for this test run at
|
|
592
|
+
* completion time. Lets the SDK distinguish "uploads failed" from
|
|
593
|
+
* "server never saw them" when the trace-ID mapping is incomplete.
|
|
594
|
+
*/
|
|
595
|
+
traceCount?: number;
|
|
596
|
+
}
|
|
597
|
+
interface SpanTreeNode {
|
|
598
|
+
/** Upstream platform span id. Stable structural identity; NOT the row id. */
|
|
599
|
+
sourceSpanId: string;
|
|
600
|
+
/**
|
|
601
|
+
* The `externalSpans` row id, accepted by {@link HttpClient.getExternalSpan}.
|
|
602
|
+
* Distinct from `sourceSpanId`; used to lazily fetch this node's output when
|
|
603
|
+
* the tree was fetched with `includeOutputs: false`. Optional so trees from
|
|
604
|
+
* older servers (which omit it) still deserialize.
|
|
605
|
+
*/
|
|
606
|
+
externalSpanId?: string;
|
|
607
|
+
traceFunctionKey: string;
|
|
608
|
+
spanName: string;
|
|
609
|
+
type: string;
|
|
610
|
+
/** Omitted when the tree was fetched payload-free (`includeOutputs: false`). */
|
|
611
|
+
output?: unknown;
|
|
612
|
+
outputMeta?: unknown;
|
|
613
|
+
children: SpanTreeNode[];
|
|
614
|
+
}
|
|
615
|
+
interface SpanTreeResponse {
|
|
616
|
+
root: SpanTreeNode;
|
|
617
|
+
}
|
|
331
618
|
|
|
332
619
|
/**
|
|
333
620
|
* Claude Agent SDK handler for Bitfab tracing.
|
|
@@ -375,6 +662,7 @@ interface ActiveSpanContext$2 {
|
|
|
375
662
|
*/
|
|
376
663
|
declare class BitfabClaudeAgentHandler {
|
|
377
664
|
private readonly httpClient;
|
|
665
|
+
private readonly ownsHttpClient;
|
|
378
666
|
private readonly traceFunctionKey;
|
|
379
667
|
private readonly getActiveSpanContext;
|
|
380
668
|
private runToSpan;
|
|
@@ -401,7 +689,20 @@ declare class BitfabClaudeAgentHandler {
|
|
|
401
689
|
serviceUrl?: string;
|
|
402
690
|
timeout?: number;
|
|
403
691
|
getActiveSpanContext?: () => ActiveSpanContext$2 | null;
|
|
692
|
+
/**
|
|
693
|
+
* The owning `Bitfab` client's HTTP client. Supplied by
|
|
694
|
+
* `getClaudeAgentHandler()` so this handler shares that client's single
|
|
695
|
+
* span-transport worker instead of starting a second one.
|
|
696
|
+
* @internal
|
|
697
|
+
*/
|
|
698
|
+
_httpClient?: HttpClient;
|
|
404
699
|
});
|
|
700
|
+
/**
|
|
701
|
+
* Flush and release the span transport this handler started. A no-op when
|
|
702
|
+
* the handler borrowed a `Bitfab` client's HTTP client: that client's
|
|
703
|
+
* `close()` owns the worker's lifetime.
|
|
704
|
+
*/
|
|
705
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
405
706
|
private ensureTrace;
|
|
406
707
|
private getParentId;
|
|
407
708
|
private maybeStartRootSpan;
|
|
@@ -620,6 +921,7 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
620
921
|
ignoreRetriever: boolean;
|
|
621
922
|
ignoreCustomEvent: boolean;
|
|
622
923
|
private readonly httpClient;
|
|
924
|
+
private readonly ownsHttpClient;
|
|
623
925
|
private readonly traceFunctionKey;
|
|
624
926
|
private readonly getActiveSpanContext;
|
|
625
927
|
private runToSpan;
|
|
@@ -630,7 +932,20 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
630
932
|
serviceUrl?: string;
|
|
631
933
|
timeout?: number;
|
|
632
934
|
getActiveSpanContext?: () => ActiveSpanContext$1 | null;
|
|
935
|
+
/**
|
|
936
|
+
* The owning `Bitfab` client's HTTP client. Supplied by
|
|
937
|
+
* `getLangGraphCallbackHandler()` so this handler shares that client's
|
|
938
|
+
* single span-transport worker instead of starting a second one.
|
|
939
|
+
* @internal
|
|
940
|
+
*/
|
|
941
|
+
_httpClient?: HttpClient;
|
|
633
942
|
});
|
|
943
|
+
/**
|
|
944
|
+
* Flush and release the span transport this handler started. A no-op when
|
|
945
|
+
* the handler borrowed a `Bitfab` client's HTTP client: that client's
|
|
946
|
+
* `close()` owns the worker's lifetime.
|
|
947
|
+
*/
|
|
948
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
634
949
|
private startSpan;
|
|
635
950
|
private completeSpan;
|
|
636
951
|
private sendSpan;
|
|
@@ -1163,6 +1478,7 @@ interface TracingProcessor {
|
|
|
1163
1478
|
*/
|
|
1164
1479
|
declare class BitfabOpenAITracingProcessor implements TracingProcessor {
|
|
1165
1480
|
private readonly httpClient;
|
|
1481
|
+
private readonly ownsHttpClient;
|
|
1166
1482
|
private activeTraces;
|
|
1167
1483
|
private readonly getActiveSpanContext;
|
|
1168
1484
|
private activeSpanMappings;
|
|
@@ -1178,7 +1494,20 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
|
|
|
1178
1494
|
serviceUrl?: string;
|
|
1179
1495
|
timeout?: number;
|
|
1180
1496
|
getActiveSpanContext?: () => ActiveSpanContext | null;
|
|
1497
|
+
/**
|
|
1498
|
+
* The owning `Bitfab` client's HTTP client. Supplied by
|
|
1499
|
+
* `getOpenAiTracingProcessor()` so this processor shares that client's
|
|
1500
|
+
* single span-transport worker instead of starting a second one.
|
|
1501
|
+
* @internal
|
|
1502
|
+
*/
|
|
1503
|
+
_httpClient?: HttpClient;
|
|
1181
1504
|
});
|
|
1505
|
+
/**
|
|
1506
|
+
* Flush and release the span transport this processor started. A no-op when
|
|
1507
|
+
* the processor borrowed a `Bitfab` client's HTTP client: that client's
|
|
1508
|
+
* `close()` owns the worker's lifetime.
|
|
1509
|
+
*/
|
|
1510
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
1182
1511
|
/**
|
|
1183
1512
|
* Called when a trace is started.
|
|
1184
1513
|
* If there's an active withSpan context, the trace ID is remapped to the
|
|
@@ -1208,7 +1537,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
|
|
|
1208
1537
|
/**
|
|
1209
1538
|
* Called when the trace processor is shutting down.
|
|
1210
1539
|
*/
|
|
1211
|
-
shutdown(
|
|
1540
|
+
shutdown(timeout?: number): Promise<void>;
|
|
1212
1541
|
/**
|
|
1213
1542
|
* Send trace to Bitfab API (fire-and-forget).
|
|
1214
1543
|
* When traceIdOverride is provided, the trace ID is remapped to link
|
|
@@ -1289,21 +1618,23 @@ interface DetachedTrace {
|
|
|
1289
1618
|
* Append a context entry to this trace. Each call adds one entry to the
|
|
1290
1619
|
* server-side contexts array; existing entries are preserved.
|
|
1291
1620
|
*
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1621
|
+
* Resolves once the server has applied the change and REJECTS if the server
|
|
1622
|
+
* refused it. A detached patch targets an already-closed trace, so it rides
|
|
1623
|
+
* no batch and no later signal would reveal a silent failure - the caller is
|
|
1624
|
+
* the only one who can react.
|
|
1295
1625
|
*/
|
|
1296
|
-
addContext(context: Record<string, unknown>): Promise<
|
|
1626
|
+
addContext(context: Record<string, unknown>): Promise<void>;
|
|
1297
1627
|
/**
|
|
1298
1628
|
* Merge metadata into this trace. Server-side shallow-merges the new keys
|
|
1299
1629
|
* into the existing metadata object; existing keys are preserved unless
|
|
1300
|
-
* overwritten by the new values.
|
|
1630
|
+
* overwritten by the new values. Rejects if the server refused the update.
|
|
1301
1631
|
*/
|
|
1302
|
-
setMetadata(metadata: Record<string, unknown>): Promise<
|
|
1632
|
+
setMetadata(metadata: Record<string, unknown>): Promise<void>;
|
|
1303
1633
|
/**
|
|
1304
1634
|
* Set the sessionId for this trace. Replaces any existing sessionId.
|
|
1635
|
+
* Rejects if the server refused the update.
|
|
1305
1636
|
*/
|
|
1306
|
-
setSessionId(sessionId: string): Promise<
|
|
1637
|
+
setSessionId(sessionId: string): Promise<void>;
|
|
1307
1638
|
}
|
|
1308
1639
|
/**
|
|
1309
1640
|
* A handle to the current active trace, allowing trace-level context to be set.
|
|
@@ -1508,6 +1839,21 @@ declare class Bitfab {
|
|
|
1508
1839
|
* @param config - Configuration options for the client
|
|
1509
1840
|
*/
|
|
1510
1841
|
constructor(config: BitfabConfig);
|
|
1842
|
+
/**
|
|
1843
|
+
* Flush and permanently close this client's tracing resources: its pending
|
|
1844
|
+
* requests and the single span-transport worker shared by its decorators and
|
|
1845
|
+
* framework handlers.
|
|
1846
|
+
*
|
|
1847
|
+
* Resolves `false` when delivery failed or the deadline expired. Long-lived
|
|
1848
|
+
* processes never need this (the transport batches in the background and the
|
|
1849
|
+
* exit hook drains it); scripts and tests that want a hard guarantee should
|
|
1850
|
+
* await it.
|
|
1851
|
+
*
|
|
1852
|
+
* Deliberately not a `Symbol.asyncDispose` method: the SDK targets runtimes
|
|
1853
|
+
* where that symbol may be absent, and a computed key on a missing symbol
|
|
1854
|
+
* throws at class-definition time, taking the whole SDK down on load.
|
|
1855
|
+
*/
|
|
1856
|
+
close(timeoutMs?: number): Promise<boolean>;
|
|
1511
1857
|
/**
|
|
1512
1858
|
* Resolve the API key lazily, the first time a span actually needs it.
|
|
1513
1859
|
*
|
|
@@ -1780,13 +2126,13 @@ declare class Bitfab {
|
|
|
1780
2126
|
/**
|
|
1781
2127
|
* Send trace completion when a root span ends.
|
|
1782
2128
|
* Internal method to record trace completion with end time.
|
|
1783
|
-
*
|
|
2129
|
+
* Queued on the client's span transport; delivery is the transport's job.
|
|
1784
2130
|
*/
|
|
1785
2131
|
private sendTraceCompletion;
|
|
1786
2132
|
/**
|
|
1787
2133
|
* Send a wrapper span from function execution.
|
|
1788
2134
|
* Internal method to record spans when using withSpan.
|
|
1789
|
-
*
|
|
2135
|
+
* Queued on the client's span transport; delivery is the transport's job.
|
|
1790
2136
|
*/
|
|
1791
2137
|
private sendWrapperSpan;
|
|
1792
2138
|
/**
|
|
@@ -1983,7 +2329,7 @@ declare class BitfabFunction {
|
|
|
1983
2329
|
/**
|
|
1984
2330
|
* SDK version from package.json (injected at build time)
|
|
1985
2331
|
*/
|
|
1986
|
-
declare const __version__ = "0.
|
|
2332
|
+
declare const __version__ = "0.34.0";
|
|
1987
2333
|
|
|
1988
2334
|
/**
|
|
1989
2335
|
* Constants for the Bitfab SDK.
|