braintrust 3.30.0 → 3.31.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/dev/dist/index.d.mts +4 -1
- package/dev/dist/index.d.ts +4 -1
- package/dev/dist/index.js +28 -7
- package/dev/dist/index.mjs +28 -7
- package/dist/apply-auto-instrumentation.js +216 -216
- package/dist/apply-auto-instrumentation.mjs +1 -1
- package/dist/auto-instrumentations/bundler/next.cjs +9 -3
- package/dist/auto-instrumentations/bundler/next.mjs +9 -3
- package/dist/auto-instrumentations/hook.mjs +3 -1
- package/dist/browser.d.mts +481 -478
- package/dist/browser.d.ts +481 -478
- package/dist/browser.js +30 -9
- package/dist/browser.mjs +30 -9
- package/dist/{chunk-2XDW3UCG.js → chunk-4AQGZS6X.js} +1 -1
- package/dist/{chunk-BU6SM54N.mjs → chunk-AJT4FR25.mjs} +17 -6
- package/dist/{chunk-N3JKQ3D3.mjs → chunk-CE3BLB2L.mjs} +1 -1
- package/dist/{chunk-TWCDSYJN.js → chunk-V32LW47Z.js} +535 -524
- package/dist/cli.js +29 -8
- package/dist/edge-light.js +30 -9
- package/dist/edge-light.mjs +30 -9
- package/dist/index.d.mts +481 -478
- package/dist/index.d.ts +481 -478
- package/dist/index.js +460 -450
- package/dist/index.mjs +15 -5
- package/dist/instrumentation/index.js +17 -6
- package/dist/instrumentation/index.mjs +17 -6
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.js +30 -9
- package/dist/workerd.mjs +30 -9
- package/package.json +1 -1
package/dist/browser.d.mts
CHANGED
|
@@ -673,6 +673,9 @@ interface Score {
|
|
|
673
673
|
*/
|
|
674
674
|
error?: unknown;
|
|
675
675
|
}
|
|
676
|
+
type SingleScore = Omit<Score, "name"> & {
|
|
677
|
+
name?: string;
|
|
678
|
+
};
|
|
676
679
|
|
|
677
680
|
declare const spanComponentsV4Schema: z.ZodIntersection<z.ZodIntersection<z.ZodObject<{
|
|
678
681
|
object_type: z.ZodNativeEnum<typeof SpanObjectTypeV3>;
|
|
@@ -25630,483 +25633,6 @@ declare function wrapLangSmithTraceable<T>(namespace: T): T;
|
|
|
25630
25633
|
declare function wrapLangSmithRunTrees<T>(namespace: T): T;
|
|
25631
25634
|
declare function wrapLangSmithClient<T>(namespace: T): T;
|
|
25632
25635
|
|
|
25633
|
-
type ScorerFunction<Output = unknown> = (args: {
|
|
25634
|
-
output: Output;
|
|
25635
|
-
expected?: unknown;
|
|
25636
|
-
input?: unknown;
|
|
25637
|
-
metadata?: Record<string, unknown>;
|
|
25638
|
-
}) => Score | Promise<Score> | number | null | Array<Score>;
|
|
25639
|
-
type ProgressEvent = {
|
|
25640
|
-
type: "suite_start";
|
|
25641
|
-
suiteName: string;
|
|
25642
|
-
} | {
|
|
25643
|
-
type: "test_start";
|
|
25644
|
-
testName: string;
|
|
25645
|
-
} | {
|
|
25646
|
-
type: "test_complete";
|
|
25647
|
-
testName: string;
|
|
25648
|
-
passed: boolean;
|
|
25649
|
-
duration: number;
|
|
25650
|
-
} | {
|
|
25651
|
-
type: "suite_complete";
|
|
25652
|
-
suiteName: string;
|
|
25653
|
-
passed: number;
|
|
25654
|
-
failed: number;
|
|
25655
|
-
};
|
|
25656
|
-
|
|
25657
|
-
interface BraintrustTestConfig {
|
|
25658
|
-
input?: unknown;
|
|
25659
|
-
expected?: unknown;
|
|
25660
|
-
metadata?: Record<string, unknown>;
|
|
25661
|
-
tags?: string[];
|
|
25662
|
-
scorers?: ScorerFunction[];
|
|
25663
|
-
data?: Array<{
|
|
25664
|
-
input?: unknown;
|
|
25665
|
-
expected?: unknown;
|
|
25666
|
-
metadata?: Record<string, unknown>;
|
|
25667
|
-
tags?: string[];
|
|
25668
|
-
}>;
|
|
25669
|
-
}
|
|
25670
|
-
interface TestConfig extends BraintrustTestConfig {
|
|
25671
|
-
[key: string]: unknown;
|
|
25672
|
-
}
|
|
25673
|
-
type WithModifiers<T> = T & {
|
|
25674
|
-
skip: T;
|
|
25675
|
-
only: T;
|
|
25676
|
-
concurrent: T;
|
|
25677
|
-
todo: (name: string) => void;
|
|
25678
|
-
};
|
|
25679
|
-
type TestContext = Pick<BraintrustTestConfig, "input" | "expected" | "metadata">;
|
|
25680
|
-
type BaseTestFunction<VitestContext = unknown> = {
|
|
25681
|
-
(name: string, fn: (context: VitestContext) => void | Promise<void>): void;
|
|
25682
|
-
each?: <T>(cases: readonly T[]) => (name: string, fn: (context: T) => void | Promise<void>) => void;
|
|
25683
|
-
};
|
|
25684
|
-
type TestFunction<VitestContext = unknown> = WithModifiers<BaseTestFunction<VitestContext>>;
|
|
25685
|
-
type BaseDescribeFunction = {
|
|
25686
|
-
(name: string, factory: () => void): void;
|
|
25687
|
-
each?: <T>(cases: readonly T[]) => (name: string, factory: () => void) => void;
|
|
25688
|
-
};
|
|
25689
|
-
type DescribeFunction = WithModifiers<BaseDescribeFunction>;
|
|
25690
|
-
interface BaseWrappedTest<VitestContext = unknown> {
|
|
25691
|
-
(name: string, fn: (context: VitestContext) => unknown | Promise<unknown>): void;
|
|
25692
|
-
(name: string, config: TestConfig, fn: (context: TestContext & VitestContext) => unknown | Promise<unknown>): void;
|
|
25693
|
-
each: <T>(cases: readonly T[]) => (name: string, fn: (context: T & TestContext & VitestContext) => unknown | Promise<unknown>) => void;
|
|
25694
|
-
}
|
|
25695
|
-
type WrappedTest<VitestContext = unknown> = WithModifiers<BaseWrappedTest<VitestContext>>;
|
|
25696
|
-
interface BaseWrappedDescribe {
|
|
25697
|
-
(name: string, factory: () => void): void;
|
|
25698
|
-
each: <T>(cases: readonly T[]) => (name: string, factory: () => void) => void;
|
|
25699
|
-
}
|
|
25700
|
-
type WrappedDescribe = WithModifiers<BaseWrappedDescribe>;
|
|
25701
|
-
interface VitestMethods<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> {
|
|
25702
|
-
test: TestFunction<VitestContext>;
|
|
25703
|
-
it?: TestFunction<VitestContext>;
|
|
25704
|
-
expect: ExpectType;
|
|
25705
|
-
describe: DescribeFunction;
|
|
25706
|
-
beforeAll?: (fn: () => void | Promise<void>) => void;
|
|
25707
|
-
afterAll?: (fn: () => void | Promise<void>) => void;
|
|
25708
|
-
beforeEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
25709
|
-
afterEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
25710
|
-
}
|
|
25711
|
-
interface BraintrustVitest<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> {
|
|
25712
|
-
test: WrappedTest<VitestContext>;
|
|
25713
|
-
it: WrappedTest<VitestContext>;
|
|
25714
|
-
expect: ExpectType;
|
|
25715
|
-
describe: WrappedDescribe;
|
|
25716
|
-
beforeAll: (fn: () => void | Promise<void>) => void;
|
|
25717
|
-
afterAll: (fn: () => void | Promise<void>) => void;
|
|
25718
|
-
beforeEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
25719
|
-
afterEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
25720
|
-
logOutputs: (outputs: Record<string, unknown>) => void;
|
|
25721
|
-
logFeedback: (feedback: {
|
|
25722
|
-
name: string;
|
|
25723
|
-
score: number;
|
|
25724
|
-
metadata?: Record<string, unknown>;
|
|
25725
|
-
}) => void;
|
|
25726
|
-
getCurrentSpan: () => Span | null;
|
|
25727
|
-
/**
|
|
25728
|
-
* Helper function to flush the experiment and optionally display a summary.
|
|
25729
|
-
* Use this in afterAll() instead of manually calling getExperimentContext().
|
|
25730
|
-
*
|
|
25731
|
-
* @param options - Optional configuration
|
|
25732
|
-
* @param options.displaySummary - Whether to display the experiment summary (defaults to true)
|
|
25733
|
-
*/
|
|
25734
|
-
flushExperiment: (options?: {
|
|
25735
|
-
displaySummary?: boolean;
|
|
25736
|
-
}) => Promise<void>;
|
|
25737
|
-
}
|
|
25738
|
-
interface WrapperConfig {
|
|
25739
|
-
projectName?: string;
|
|
25740
|
-
/**
|
|
25741
|
-
* The id of the project to create experiments in. Takes precedence over
|
|
25742
|
-
* `projectName` if both are set.
|
|
25743
|
-
*/
|
|
25744
|
-
projectId?: string;
|
|
25745
|
-
/**
|
|
25746
|
-
* If true, displays a formatted experiment summary with scores and URL after the test suite completes.
|
|
25747
|
-
* Defaults to true. Set to false to suppress the summary output.
|
|
25748
|
-
*/
|
|
25749
|
-
displaySummary?: boolean;
|
|
25750
|
-
/**
|
|
25751
|
-
* Callback for real-time progress events.
|
|
25752
|
-
* Called when tests start, complete, or progress updates occur.
|
|
25753
|
-
* Progress reporting is always enabled when this callback is provided.
|
|
25754
|
-
*/
|
|
25755
|
-
onProgress?: (event: ProgressEvent) => void;
|
|
25756
|
-
}
|
|
25757
|
-
|
|
25758
|
-
/**
|
|
25759
|
-
* Wraps Vitest methods with Braintrust experiment tracking. This automatically creates
|
|
25760
|
-
* datasets and experiments from your Vitest tests, tracking pass/fail rates and evaluation metrics.
|
|
25761
|
-
* Experiments are automatically flushed after all tests complete.
|
|
25762
|
-
*
|
|
25763
|
-
* @param vitestMethods - Object containing Vitest methods (test, describe, expect, etc.)
|
|
25764
|
-
* @param config - Optional configuration object
|
|
25765
|
-
* @param config.projectName - Project name for the experiment (defaults to suite name)
|
|
25766
|
-
* @param config.displaySummary - If true, displays experiment summary after flushing (defaults to true)
|
|
25767
|
-
* @returns Wrapped Vitest methods with Braintrust experiment tracking
|
|
25768
|
-
*
|
|
25769
|
-
* @example Basic Usage
|
|
25770
|
-
* ```typescript
|
|
25771
|
-
* import * as vitest from "vitest";
|
|
25772
|
-
* import { wrapVitest } from 'braintrust';
|
|
25773
|
-
*
|
|
25774
|
-
* const {test, expect, describe } = wrapVitest(
|
|
25775
|
-
* { projectName: 'my-project' }
|
|
25776
|
-
* );
|
|
25777
|
-
*
|
|
25778
|
-
* describe('Translation Tests', () => {
|
|
25779
|
-
*
|
|
25780
|
-
* // Tests with input/expected are automatically added to the dataset
|
|
25781
|
-
* test(
|
|
25782
|
-
* 'translates hello',
|
|
25783
|
-
* {
|
|
25784
|
-
* input: { text: 'hello' },
|
|
25785
|
-
* expected: 'hola',
|
|
25786
|
-
* metadata: { language: 'spanish' },
|
|
25787
|
-
* },
|
|
25788
|
-
* async ({ input, expected }) => {
|
|
25789
|
-
* const result = await translate(input.text);
|
|
25790
|
-
* bt.logOutputs({ translation: result });
|
|
25791
|
-
* expect(result).toBe(expected);
|
|
25792
|
-
* }
|
|
25793
|
-
* );
|
|
25794
|
-
*
|
|
25795
|
-
* // Tests without input/expected still run and track pass/fail
|
|
25796
|
-
* test('basic functionality', async () => {
|
|
25797
|
-
* const result = await someFunction();
|
|
25798
|
-
* expect(result).toBeTruthy();
|
|
25799
|
-
* });
|
|
25800
|
-
* });
|
|
25801
|
-
* ```
|
|
25802
|
-
*
|
|
25803
|
-
* @see README.md for full documentation and examples
|
|
25804
|
-
*/
|
|
25805
|
-
declare function wrapVitest<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown>(vitestMethods: VitestMethods<VitestContext, ExpectType>, config?: WrapperConfig): BraintrustVitest<VitestContext, ExpectType>;
|
|
25806
|
-
|
|
25807
|
-
/** Progress events emitted by the node-test integration. */
|
|
25808
|
-
type NodeTestProgressEvent = {
|
|
25809
|
-
type: "test_start";
|
|
25810
|
-
testName: string;
|
|
25811
|
-
} | {
|
|
25812
|
-
type: "test_complete";
|
|
25813
|
-
testName: string;
|
|
25814
|
-
passed: boolean;
|
|
25815
|
-
duration: number;
|
|
25816
|
-
};
|
|
25817
|
-
/**
|
|
25818
|
-
* Minimal test context interface compatible with node:test's TestContext.
|
|
25819
|
-
* We only use `name` from the context, making this compatible with any
|
|
25820
|
-
* test runner that provides a `{ name?: string }` context object.
|
|
25821
|
-
*/
|
|
25822
|
-
interface MinimalTestContext {
|
|
25823
|
-
name?: string;
|
|
25824
|
-
}
|
|
25825
|
-
/**
|
|
25826
|
-
* Configuration for `initNodeTestSuite()`.
|
|
25827
|
-
*/
|
|
25828
|
-
interface NodeTestSuiteConfig {
|
|
25829
|
-
/** Project name for the Braintrust experiment. */
|
|
25830
|
-
projectName: string;
|
|
25831
|
-
/** Optional experiment name. Defaults to a timestamp-based name. */
|
|
25832
|
-
experimentName?: string;
|
|
25833
|
-
/**
|
|
25834
|
-
* If true, displays a formatted experiment summary after flushing.
|
|
25835
|
-
* Defaults to true.
|
|
25836
|
-
*/
|
|
25837
|
-
displaySummary?: boolean;
|
|
25838
|
-
/**
|
|
25839
|
-
* Pass `after` from `node:test` to auto-register a flush hook.
|
|
25840
|
-
* When provided, `suite.flush()` is called automatically after all tests.
|
|
25841
|
-
*/
|
|
25842
|
-
after?: (fn: () => void | Promise<void>) => void;
|
|
25843
|
-
/**
|
|
25844
|
-
* Callback for real-time progress events.
|
|
25845
|
-
* Emits `test_start` and `test_complete` events.
|
|
25846
|
-
*/
|
|
25847
|
-
onProgress?: (event: NodeTestProgressEvent) => void;
|
|
25848
|
-
}
|
|
25849
|
-
/**
|
|
25850
|
-
* Configuration for a single eval test case.
|
|
25851
|
-
*/
|
|
25852
|
-
interface EvalConfig {
|
|
25853
|
-
/** Test input data, logged to the span. */
|
|
25854
|
-
input?: unknown;
|
|
25855
|
-
/** Expected output, passed to scorers. */
|
|
25856
|
-
expected?: unknown;
|
|
25857
|
-
/** Custom metadata, logged to the span. */
|
|
25858
|
-
metadata?: Record<string, unknown>;
|
|
25859
|
-
/** Tags for organizing test cases. */
|
|
25860
|
-
tags?: string[];
|
|
25861
|
-
/** Scorer functions to evaluate the output. */
|
|
25862
|
-
scorers?: ScorerFunction[];
|
|
25863
|
-
/** Override span name (defaults to `t.name`, then `"unnamed test"`). */
|
|
25864
|
-
name?: string;
|
|
25865
|
-
}
|
|
25866
|
-
/**
|
|
25867
|
-
* Context passed to the eval test function.
|
|
25868
|
-
*/
|
|
25869
|
-
interface EvalContext {
|
|
25870
|
-
input: unknown;
|
|
25871
|
-
expected?: unknown;
|
|
25872
|
-
metadata?: Record<string, unknown>;
|
|
25873
|
-
}
|
|
25874
|
-
/**
|
|
25875
|
-
* The public API surface returned by `initNodeTestSuite()`.
|
|
25876
|
-
*/
|
|
25877
|
-
interface NodeTestSuite {
|
|
25878
|
-
/**
|
|
25879
|
-
* Creates a test function compatible with `node:test`.
|
|
25880
|
-
* Pass the result to `test()` from `node:test`.
|
|
25881
|
-
*
|
|
25882
|
-
* @param config - Eval configuration (input, expected, scorers, etc.)
|
|
25883
|
-
* @param fn - The test function. Its return value is logged as output and passed to scorers.
|
|
25884
|
-
* @returns A function accepting a test context `t` from `node:test`.
|
|
25885
|
-
*/
|
|
25886
|
-
eval(config: EvalConfig, fn: (context: EvalContext) => unknown | Promise<unknown>): (t: MinimalTestContext) => Promise<void>;
|
|
25887
|
-
/**
|
|
25888
|
-
* Flush the experiment: summarize results and send data to Braintrust.
|
|
25889
|
-
* Called automatically if `after` was provided in the config.
|
|
25890
|
-
*/
|
|
25891
|
-
flush(): Promise<void>;
|
|
25892
|
-
}
|
|
25893
|
-
|
|
25894
|
-
/**
|
|
25895
|
-
* Creates a new Node.js test suite with Braintrust experiment tracking.
|
|
25896
|
-
*
|
|
25897
|
-
* @example
|
|
25898
|
-
* ```typescript
|
|
25899
|
-
* import { test, describe, after } from 'node:test';
|
|
25900
|
-
* import { initNodeTestSuite } from 'braintrust';
|
|
25901
|
-
*
|
|
25902
|
-
* describe('My Tests', () => {
|
|
25903
|
-
* const suite = initNodeTestSuite({ projectName: 'my-project', after });
|
|
25904
|
-
*
|
|
25905
|
-
* test('my eval', suite.eval(
|
|
25906
|
-
* { input: 'hello', expected: 'world', scorers: [myScorer] },
|
|
25907
|
-
* async ({ input }) => {
|
|
25908
|
-
* return await myFunction(input);
|
|
25909
|
-
* }
|
|
25910
|
-
* ));
|
|
25911
|
-
* });
|
|
25912
|
-
* ```
|
|
25913
|
-
*/
|
|
25914
|
-
declare function initNodeTestSuite(config: NodeTestSuiteConfig): NodeTestSuite;
|
|
25915
|
-
|
|
25916
|
-
type LangChainSerialized = {
|
|
25917
|
-
id?: unknown[];
|
|
25918
|
-
name?: string;
|
|
25919
|
-
};
|
|
25920
|
-
type LangChainCallbackHandlerOptions<IsAsyncFlush extends boolean> = {
|
|
25921
|
-
debug: boolean;
|
|
25922
|
-
excludeMetadataProps: RegExp;
|
|
25923
|
-
logger?: Logger<IsAsyncFlush> | Span;
|
|
25924
|
-
parent?: Span | (() => Span);
|
|
25925
|
-
};
|
|
25926
|
-
type LangChainStartSpanArgs = StartSpanArgs & {
|
|
25927
|
-
parentRunId?: string;
|
|
25928
|
-
runId: string;
|
|
25929
|
-
};
|
|
25930
|
-
type LangChainEndSpanArgs = ExperimentLogPartialArgs & {
|
|
25931
|
-
parentRunId?: string;
|
|
25932
|
-
runId: string;
|
|
25933
|
-
tags?: string[];
|
|
25934
|
-
};
|
|
25935
|
-
type LangChainLLMResult = {
|
|
25936
|
-
generations?: unknown[];
|
|
25937
|
-
llmOutput?: Record<string, unknown>;
|
|
25938
|
-
};
|
|
25939
|
-
|
|
25940
|
-
declare const BRAINTRUST_LANGCHAIN_CALLBACK_HANDLER_NAME = "BraintrustCallbackHandler";
|
|
25941
|
-
declare class BraintrustLangChainCallbackHandler<IsAsyncFlush extends boolean = true> {
|
|
25942
|
-
name: string;
|
|
25943
|
-
private spans;
|
|
25944
|
-
private skippedRuns;
|
|
25945
|
-
private parent?;
|
|
25946
|
-
private rootRunId?;
|
|
25947
|
-
private options;
|
|
25948
|
-
private startTimes;
|
|
25949
|
-
private firstTokenTimes;
|
|
25950
|
-
private ttftMs;
|
|
25951
|
-
constructor(options?: Partial<LangChainCallbackHandlerOptions<IsAsyncFlush>>);
|
|
25952
|
-
protected startSpan({ runId, parentRunId, ...args }: LangChainStartSpanArgs): void;
|
|
25953
|
-
protected endSpan({ runId, parentRunId, tags, metadata, ...args }: LangChainEndSpanArgs): void;
|
|
25954
|
-
handleLLMStart(llm: LangChainSerialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
25955
|
-
handleLLMError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25956
|
-
handleLLMEnd(output: LangChainLLMResult, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25957
|
-
handleChatModelStart(llm: LangChainSerialized, messages: unknown[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
25958
|
-
handleChainStart(chain: LangChainSerialized, inputs: unknown, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): Promise<void>;
|
|
25959
|
-
handleChainError(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
25960
|
-
inputs?: Record<string, unknown>;
|
|
25961
|
-
}): Promise<void>;
|
|
25962
|
-
handleChainEnd(outputs: unknown, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
25963
|
-
inputs?: Record<string, unknown>;
|
|
25964
|
-
}): Promise<void>;
|
|
25965
|
-
handleToolStart(tool: LangChainSerialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
25966
|
-
handleToolError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25967
|
-
handleToolEnd(output: unknown, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25968
|
-
handleAgentAction(action: Record<string, unknown>, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25969
|
-
handleAgentEnd(action: unknown, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25970
|
-
handleRetrieverStart(retriever: LangChainSerialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): Promise<void>;
|
|
25971
|
-
handleRetrieverEnd(documents: unknown[], runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25972
|
-
handleRetrieverError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
25973
|
-
handleLLMNewToken(_token: string, _idx: {
|
|
25974
|
-
prompt: number;
|
|
25975
|
-
completion: number;
|
|
25976
|
-
}, runId: string, _parentRunId?: string, _tags?: string[]): Promise<void>;
|
|
25977
|
-
}
|
|
25978
|
-
|
|
25979
|
-
interface BuildContext {
|
|
25980
|
-
getFunctionId(functionObj: unknown): Promise<FunctionIdType>;
|
|
25981
|
-
}
|
|
25982
|
-
interface Node {
|
|
25983
|
-
readonly id: string;
|
|
25984
|
-
__type: "node";
|
|
25985
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
25986
|
-
addDependency(dependency: Dependency): void;
|
|
25987
|
-
}
|
|
25988
|
-
type NodeLike = Node | Prompt<boolean, boolean> | ProxyVariable;
|
|
25989
|
-
type LazyGraphNode = {
|
|
25990
|
-
type: "lazy";
|
|
25991
|
-
id: string;
|
|
25992
|
-
};
|
|
25993
|
-
declare class GraphBuilder {
|
|
25994
|
-
private nodes;
|
|
25995
|
-
private edges;
|
|
25996
|
-
private nodeLikeNodes;
|
|
25997
|
-
readonly IN: InputNode;
|
|
25998
|
-
readonly OUT: OutputNode;
|
|
25999
|
-
constructor();
|
|
26000
|
-
build(context: BuildContext): Promise<GraphDataType>;
|
|
26001
|
-
addEdge({ source, sourceVar, target, targetVar, expr, purpose, }: {
|
|
26002
|
-
source: NodeLike;
|
|
26003
|
-
sourceVar?: string;
|
|
26004
|
-
target: NodeLike;
|
|
26005
|
-
targetVar?: string;
|
|
26006
|
-
expr?: string;
|
|
26007
|
-
purpose: GraphEdgeType["purpose"];
|
|
26008
|
-
}): void;
|
|
26009
|
-
resolveNode(node: NodeLike): [Node, string[]];
|
|
26010
|
-
literal<T>(value: T): LiteralNode<T>;
|
|
26011
|
-
gate(options: {
|
|
26012
|
-
condition: string;
|
|
26013
|
-
}): GateNode;
|
|
26014
|
-
aggregator(): AggregatorNode;
|
|
26015
|
-
promptTemplate(options: {
|
|
26016
|
-
prompt: PromptBlockDataType;
|
|
26017
|
-
}): PromptTemplateNode;
|
|
26018
|
-
private generateId;
|
|
26019
|
-
private createInputNode;
|
|
26020
|
-
private createOutputNode;
|
|
26021
|
-
private createPromptNode;
|
|
26022
|
-
}
|
|
26023
|
-
type ProxyVariable = {
|
|
26024
|
-
[key: string]: ProxyVariable;
|
|
26025
|
-
};
|
|
26026
|
-
type TransformFn = (input: ProxyVariable) => Node;
|
|
26027
|
-
interface Dependency {
|
|
26028
|
-
node: Node;
|
|
26029
|
-
sourceVar?: string;
|
|
26030
|
-
targetVar?: string;
|
|
26031
|
-
expr?: string;
|
|
26032
|
-
}
|
|
26033
|
-
declare abstract class BaseNode implements Node {
|
|
26034
|
-
protected graph: GraphBuilder;
|
|
26035
|
-
readonly id: string;
|
|
26036
|
-
readonly __type = "node";
|
|
26037
|
-
dependencies: Dependency[];
|
|
26038
|
-
constructor(graph: GraphBuilder, id: string);
|
|
26039
|
-
addDependency(dependency: Dependency): void;
|
|
26040
|
-
abstract build(context: BuildContext): Promise<GraphNodeType>;
|
|
26041
|
-
}
|
|
26042
|
-
declare class InputNode extends BaseNode implements Node {
|
|
26043
|
-
constructor(graph: GraphBuilder, id: string);
|
|
26044
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26045
|
-
}
|
|
26046
|
-
declare class OutputNode extends BaseNode implements Node {
|
|
26047
|
-
constructor(graph: GraphBuilder, id: string);
|
|
26048
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26049
|
-
}
|
|
26050
|
-
declare class PromptNode extends BaseNode implements Node {
|
|
26051
|
-
private prompt;
|
|
26052
|
-
constructor(graph: GraphBuilder, id: string, prompt: Prompt);
|
|
26053
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26054
|
-
}
|
|
26055
|
-
declare class GateNode extends BaseNode implements Node {
|
|
26056
|
-
private condition;
|
|
26057
|
-
constructor(graph: GraphBuilder, id: string, condition: string);
|
|
26058
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26059
|
-
}
|
|
26060
|
-
declare class AggregatorNode extends BaseNode implements Node {
|
|
26061
|
-
constructor(graph: GraphBuilder, id: string);
|
|
26062
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26063
|
-
}
|
|
26064
|
-
declare class PromptTemplateNode extends BaseNode implements Node {
|
|
26065
|
-
private prompt;
|
|
26066
|
-
constructor(graph: GraphBuilder, id: string, prompt: PromptBlockDataType);
|
|
26067
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26068
|
-
}
|
|
26069
|
-
declare class LiteralNode<T> extends BaseNode implements Node {
|
|
26070
|
-
private value;
|
|
26071
|
-
constructor(graph: GraphBuilder, id: string, value: T);
|
|
26072
|
-
build(context: BuildContext): Promise<GraphNodeType>;
|
|
26073
|
-
}
|
|
26074
|
-
declare function createGraph(): GraphBuilder;
|
|
26075
|
-
declare function escapePath(parts: string[]): string | undefined;
|
|
26076
|
-
declare function unescapePath(path: string): string[];
|
|
26077
|
-
declare const _default: {
|
|
26078
|
-
createGraph: typeof createGraph;
|
|
26079
|
-
};
|
|
26080
|
-
|
|
26081
|
-
type graphFramework_AggregatorNode = AggregatorNode;
|
|
26082
|
-
declare const graphFramework_AggregatorNode: typeof AggregatorNode;
|
|
26083
|
-
type graphFramework_BuildContext = BuildContext;
|
|
26084
|
-
type graphFramework_GateNode = GateNode;
|
|
26085
|
-
declare const graphFramework_GateNode: typeof GateNode;
|
|
26086
|
-
type graphFramework_GraphBuilder = GraphBuilder;
|
|
26087
|
-
declare const graphFramework_GraphBuilder: typeof GraphBuilder;
|
|
26088
|
-
type graphFramework_InputNode = InputNode;
|
|
26089
|
-
declare const graphFramework_InputNode: typeof InputNode;
|
|
26090
|
-
type graphFramework_LazyGraphNode = LazyGraphNode;
|
|
26091
|
-
type graphFramework_LiteralNode<T> = LiteralNode<T>;
|
|
26092
|
-
declare const graphFramework_LiteralNode: typeof LiteralNode;
|
|
26093
|
-
type graphFramework_Node = Node;
|
|
26094
|
-
type graphFramework_NodeLike = NodeLike;
|
|
26095
|
-
type graphFramework_OutputNode = OutputNode;
|
|
26096
|
-
declare const graphFramework_OutputNode: typeof OutputNode;
|
|
26097
|
-
type graphFramework_PromptNode = PromptNode;
|
|
26098
|
-
declare const graphFramework_PromptNode: typeof PromptNode;
|
|
26099
|
-
type graphFramework_PromptTemplateNode = PromptTemplateNode;
|
|
26100
|
-
declare const graphFramework_PromptTemplateNode: typeof PromptTemplateNode;
|
|
26101
|
-
type graphFramework_ProxyVariable = ProxyVariable;
|
|
26102
|
-
type graphFramework_TransformFn = TransformFn;
|
|
26103
|
-
declare const graphFramework_createGraph: typeof createGraph;
|
|
26104
|
-
declare const graphFramework_escapePath: typeof escapePath;
|
|
26105
|
-
declare const graphFramework_unescapePath: typeof unescapePath;
|
|
26106
|
-
declare namespace graphFramework {
|
|
26107
|
-
export { graphFramework_AggregatorNode as AggregatorNode, type graphFramework_BuildContext as BuildContext, graphFramework_GateNode as GateNode, graphFramework_GraphBuilder as GraphBuilder, graphFramework_InputNode as InputNode, type graphFramework_LazyGraphNode as LazyGraphNode, graphFramework_LiteralNode as LiteralNode, type graphFramework_Node as Node, type graphFramework_NodeLike as NodeLike, graphFramework_OutputNode as OutputNode, graphFramework_PromptNode as PromptNode, graphFramework_PromptTemplateNode as PromptTemplateNode, type graphFramework_ProxyVariable as ProxyVariable, type graphFramework_TransformFn as TransformFn, graphFramework_createGraph as createGraph, _default as default, graphFramework_escapePath as escapePath, graphFramework_unescapePath as unescapePath };
|
|
26108
|
-
}
|
|
26109
|
-
|
|
26110
25636
|
type GenericFunction<Input, Output> = ((input: Input) => Output) | ((input: Input) => Promise<Output>);
|
|
26111
25637
|
interface BaseFnOpts {
|
|
26112
25638
|
name: string;
|
|
@@ -46710,7 +46236,7 @@ type EvalScorerArgs<Input, Output, Expected, Metadata extends BaseMetadata = Def
|
|
|
46710
46236
|
output: Output;
|
|
46711
46237
|
trace?: Trace;
|
|
46712
46238
|
};
|
|
46713
|
-
type OneOrMoreScores =
|
|
46239
|
+
type OneOrMoreScores = SingleScore | number | null | Array<Score>;
|
|
46714
46240
|
type EvalScorer<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreScores | Promise<OneOrMoreScores>;
|
|
46715
46241
|
type OneOrMoreClassifications = Classification | Classification[] | null;
|
|
46716
46242
|
type EvalClassifier<Input, Output, Expected, Metadata extends BaseMetadata = DefaultMetadataType> = (args: EvalScorerArgs<Input, Output, Expected, Metadata>) => OneOrMoreClassifications | Promise<OneOrMoreClassifications>;
|
|
@@ -46980,6 +46506,483 @@ type ScoreAccumulator = {
|
|
|
46980
46506
|
declare function buildLocalSummary(evaluator: EvaluatorDef<any, any, any, any>, results: EvalResult<any, any, any, any>[], precomputedScores?: ScoreAccumulator): ExperimentSummary;
|
|
46981
46507
|
declare function reportFailures<Input, Output, Expected, Metadata extends BaseMetadata>(evaluator: EvaluatorDef<Input, Output, Expected, Metadata>, failingResults: EvalResult<Input, Output, Expected, Metadata>[], { verbose, jsonl }: ReporterOpts): void;
|
|
46982
46508
|
|
|
46509
|
+
type ScorerFunction<Output = unknown> = (args: {
|
|
46510
|
+
output: Output;
|
|
46511
|
+
expected?: unknown;
|
|
46512
|
+
input?: unknown;
|
|
46513
|
+
metadata?: Record<string, unknown>;
|
|
46514
|
+
}) => OneOrMoreScores | Promise<OneOrMoreScores>;
|
|
46515
|
+
type ProgressEvent = {
|
|
46516
|
+
type: "suite_start";
|
|
46517
|
+
suiteName: string;
|
|
46518
|
+
} | {
|
|
46519
|
+
type: "test_start";
|
|
46520
|
+
testName: string;
|
|
46521
|
+
} | {
|
|
46522
|
+
type: "test_complete";
|
|
46523
|
+
testName: string;
|
|
46524
|
+
passed: boolean;
|
|
46525
|
+
duration: number;
|
|
46526
|
+
} | {
|
|
46527
|
+
type: "suite_complete";
|
|
46528
|
+
suiteName: string;
|
|
46529
|
+
passed: number;
|
|
46530
|
+
failed: number;
|
|
46531
|
+
};
|
|
46532
|
+
|
|
46533
|
+
interface BraintrustTestConfig {
|
|
46534
|
+
input?: unknown;
|
|
46535
|
+
expected?: unknown;
|
|
46536
|
+
metadata?: Record<string, unknown>;
|
|
46537
|
+
tags?: string[];
|
|
46538
|
+
scorers?: ScorerFunction[];
|
|
46539
|
+
data?: Array<{
|
|
46540
|
+
input?: unknown;
|
|
46541
|
+
expected?: unknown;
|
|
46542
|
+
metadata?: Record<string, unknown>;
|
|
46543
|
+
tags?: string[];
|
|
46544
|
+
}>;
|
|
46545
|
+
}
|
|
46546
|
+
interface TestConfig extends BraintrustTestConfig {
|
|
46547
|
+
[key: string]: unknown;
|
|
46548
|
+
}
|
|
46549
|
+
type WithModifiers<T> = T & {
|
|
46550
|
+
skip: T;
|
|
46551
|
+
only: T;
|
|
46552
|
+
concurrent: T;
|
|
46553
|
+
todo: (name: string) => void;
|
|
46554
|
+
};
|
|
46555
|
+
type TestContext = Pick<BraintrustTestConfig, "input" | "expected" | "metadata">;
|
|
46556
|
+
type BaseTestFunction<VitestContext = unknown> = {
|
|
46557
|
+
(name: string, fn: (context: VitestContext) => void | Promise<void>): void;
|
|
46558
|
+
each?: <T>(cases: readonly T[]) => (name: string, fn: (context: T) => void | Promise<void>) => void;
|
|
46559
|
+
};
|
|
46560
|
+
type TestFunction<VitestContext = unknown> = WithModifiers<BaseTestFunction<VitestContext>>;
|
|
46561
|
+
type BaseDescribeFunction = {
|
|
46562
|
+
(name: string, factory: () => void): void;
|
|
46563
|
+
each?: <T>(cases: readonly T[]) => (name: string, factory: () => void) => void;
|
|
46564
|
+
};
|
|
46565
|
+
type DescribeFunction = WithModifiers<BaseDescribeFunction>;
|
|
46566
|
+
interface BaseWrappedTest<VitestContext = unknown> {
|
|
46567
|
+
(name: string, fn: (context: VitestContext) => unknown | Promise<unknown>): void;
|
|
46568
|
+
(name: string, config: TestConfig, fn: (context: TestContext & VitestContext) => unknown | Promise<unknown>): void;
|
|
46569
|
+
each: <T>(cases: readonly T[]) => (name: string, fn: (context: T & TestContext & VitestContext) => unknown | Promise<unknown>) => void;
|
|
46570
|
+
}
|
|
46571
|
+
type WrappedTest<VitestContext = unknown> = WithModifiers<BaseWrappedTest<VitestContext>>;
|
|
46572
|
+
interface BaseWrappedDescribe {
|
|
46573
|
+
(name: string, factory: () => void): void;
|
|
46574
|
+
each: <T>(cases: readonly T[]) => (name: string, factory: () => void) => void;
|
|
46575
|
+
}
|
|
46576
|
+
type WrappedDescribe = WithModifiers<BaseWrappedDescribe>;
|
|
46577
|
+
interface VitestMethods<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> {
|
|
46578
|
+
test: TestFunction<VitestContext>;
|
|
46579
|
+
it?: TestFunction<VitestContext>;
|
|
46580
|
+
expect: ExpectType;
|
|
46581
|
+
describe: DescribeFunction;
|
|
46582
|
+
beforeAll?: (fn: () => void | Promise<void>) => void;
|
|
46583
|
+
afterAll?: (fn: () => void | Promise<void>) => void;
|
|
46584
|
+
beforeEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
46585
|
+
afterEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
46586
|
+
}
|
|
46587
|
+
interface BraintrustVitest<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> {
|
|
46588
|
+
test: WrappedTest<VitestContext>;
|
|
46589
|
+
it: WrappedTest<VitestContext>;
|
|
46590
|
+
expect: ExpectType;
|
|
46591
|
+
describe: WrappedDescribe;
|
|
46592
|
+
beforeAll: (fn: () => void | Promise<void>) => void;
|
|
46593
|
+
afterAll: (fn: () => void | Promise<void>) => void;
|
|
46594
|
+
beforeEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
46595
|
+
afterEach?: (fn: (context: VitestContext) => void | Promise<void>) => void;
|
|
46596
|
+
logOutputs: (outputs: Record<string, unknown>) => void;
|
|
46597
|
+
logFeedback: (feedback: {
|
|
46598
|
+
name: string;
|
|
46599
|
+
score: number;
|
|
46600
|
+
metadata?: Record<string, unknown>;
|
|
46601
|
+
}) => void;
|
|
46602
|
+
getCurrentSpan: () => Span | null;
|
|
46603
|
+
/**
|
|
46604
|
+
* Helper function to flush the experiment and optionally display a summary.
|
|
46605
|
+
* Use this in afterAll() instead of manually calling getExperimentContext().
|
|
46606
|
+
*
|
|
46607
|
+
* @param options - Optional configuration
|
|
46608
|
+
* @param options.displaySummary - Whether to display the experiment summary (defaults to true)
|
|
46609
|
+
*/
|
|
46610
|
+
flushExperiment: (options?: {
|
|
46611
|
+
displaySummary?: boolean;
|
|
46612
|
+
}) => Promise<void>;
|
|
46613
|
+
}
|
|
46614
|
+
interface WrapperConfig {
|
|
46615
|
+
projectName?: string;
|
|
46616
|
+
/**
|
|
46617
|
+
* The id of the project to create experiments in. Takes precedence over
|
|
46618
|
+
* `projectName` if both are set.
|
|
46619
|
+
*/
|
|
46620
|
+
projectId?: string;
|
|
46621
|
+
/**
|
|
46622
|
+
* If true, displays a formatted experiment summary with scores and URL after the test suite completes.
|
|
46623
|
+
* Defaults to true. Set to false to suppress the summary output.
|
|
46624
|
+
*/
|
|
46625
|
+
displaySummary?: boolean;
|
|
46626
|
+
/**
|
|
46627
|
+
* Callback for real-time progress events.
|
|
46628
|
+
* Called when tests start, complete, or progress updates occur.
|
|
46629
|
+
* Progress reporting is always enabled when this callback is provided.
|
|
46630
|
+
*/
|
|
46631
|
+
onProgress?: (event: ProgressEvent) => void;
|
|
46632
|
+
}
|
|
46633
|
+
|
|
46634
|
+
/**
|
|
46635
|
+
* Wraps Vitest methods with Braintrust experiment tracking. This automatically creates
|
|
46636
|
+
* datasets and experiments from your Vitest tests, tracking pass/fail rates and evaluation metrics.
|
|
46637
|
+
* Experiments are automatically flushed after all tests complete.
|
|
46638
|
+
*
|
|
46639
|
+
* @param vitestMethods - Object containing Vitest methods (test, describe, expect, etc.)
|
|
46640
|
+
* @param config - Optional configuration object
|
|
46641
|
+
* @param config.projectName - Project name for the experiment (defaults to suite name)
|
|
46642
|
+
* @param config.displaySummary - If true, displays experiment summary after flushing (defaults to true)
|
|
46643
|
+
* @returns Wrapped Vitest methods with Braintrust experiment tracking
|
|
46644
|
+
*
|
|
46645
|
+
* @example Basic Usage
|
|
46646
|
+
* ```typescript
|
|
46647
|
+
* import * as vitest from "vitest";
|
|
46648
|
+
* import { wrapVitest } from 'braintrust';
|
|
46649
|
+
*
|
|
46650
|
+
* const {test, expect, describe } = wrapVitest(
|
|
46651
|
+
* { projectName: 'my-project' }
|
|
46652
|
+
* );
|
|
46653
|
+
*
|
|
46654
|
+
* describe('Translation Tests', () => {
|
|
46655
|
+
*
|
|
46656
|
+
* // Tests with input/expected are automatically added to the dataset
|
|
46657
|
+
* test(
|
|
46658
|
+
* 'translates hello',
|
|
46659
|
+
* {
|
|
46660
|
+
* input: { text: 'hello' },
|
|
46661
|
+
* expected: 'hola',
|
|
46662
|
+
* metadata: { language: 'spanish' },
|
|
46663
|
+
* },
|
|
46664
|
+
* async ({ input, expected }) => {
|
|
46665
|
+
* const result = await translate(input.text);
|
|
46666
|
+
* bt.logOutputs({ translation: result });
|
|
46667
|
+
* expect(result).toBe(expected);
|
|
46668
|
+
* }
|
|
46669
|
+
* );
|
|
46670
|
+
*
|
|
46671
|
+
* // Tests without input/expected still run and track pass/fail
|
|
46672
|
+
* test('basic functionality', async () => {
|
|
46673
|
+
* const result = await someFunction();
|
|
46674
|
+
* expect(result).toBeTruthy();
|
|
46675
|
+
* });
|
|
46676
|
+
* });
|
|
46677
|
+
* ```
|
|
46678
|
+
*
|
|
46679
|
+
* @see README.md for full documentation and examples
|
|
46680
|
+
*/
|
|
46681
|
+
declare function wrapVitest<VitestContext = unknown, ExpectType extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown>(vitestMethods: VitestMethods<VitestContext, ExpectType>, config?: WrapperConfig): BraintrustVitest<VitestContext, ExpectType>;
|
|
46682
|
+
|
|
46683
|
+
/** Progress events emitted by the node-test integration. */
|
|
46684
|
+
type NodeTestProgressEvent = {
|
|
46685
|
+
type: "test_start";
|
|
46686
|
+
testName: string;
|
|
46687
|
+
} | {
|
|
46688
|
+
type: "test_complete";
|
|
46689
|
+
testName: string;
|
|
46690
|
+
passed: boolean;
|
|
46691
|
+
duration: number;
|
|
46692
|
+
};
|
|
46693
|
+
/**
|
|
46694
|
+
* Minimal test context interface compatible with node:test's TestContext.
|
|
46695
|
+
* We only use `name` from the context, making this compatible with any
|
|
46696
|
+
* test runner that provides a `{ name?: string }` context object.
|
|
46697
|
+
*/
|
|
46698
|
+
interface MinimalTestContext {
|
|
46699
|
+
name?: string;
|
|
46700
|
+
}
|
|
46701
|
+
/**
|
|
46702
|
+
* Configuration for `initNodeTestSuite()`.
|
|
46703
|
+
*/
|
|
46704
|
+
interface NodeTestSuiteConfig {
|
|
46705
|
+
/** Project name for the Braintrust experiment. */
|
|
46706
|
+
projectName: string;
|
|
46707
|
+
/** Optional experiment name. Defaults to a timestamp-based name. */
|
|
46708
|
+
experimentName?: string;
|
|
46709
|
+
/**
|
|
46710
|
+
* If true, displays a formatted experiment summary after flushing.
|
|
46711
|
+
* Defaults to true.
|
|
46712
|
+
*/
|
|
46713
|
+
displaySummary?: boolean;
|
|
46714
|
+
/**
|
|
46715
|
+
* Pass `after` from `node:test` to auto-register a flush hook.
|
|
46716
|
+
* When provided, `suite.flush()` is called automatically after all tests.
|
|
46717
|
+
*/
|
|
46718
|
+
after?: (fn: () => void | Promise<void>) => void;
|
|
46719
|
+
/**
|
|
46720
|
+
* Callback for real-time progress events.
|
|
46721
|
+
* Emits `test_start` and `test_complete` events.
|
|
46722
|
+
*/
|
|
46723
|
+
onProgress?: (event: NodeTestProgressEvent) => void;
|
|
46724
|
+
}
|
|
46725
|
+
/**
|
|
46726
|
+
* Configuration for a single eval test case.
|
|
46727
|
+
*/
|
|
46728
|
+
interface EvalConfig {
|
|
46729
|
+
/** Test input data, logged to the span. */
|
|
46730
|
+
input?: unknown;
|
|
46731
|
+
/** Expected output, passed to scorers. */
|
|
46732
|
+
expected?: unknown;
|
|
46733
|
+
/** Custom metadata, logged to the span. */
|
|
46734
|
+
metadata?: Record<string, unknown>;
|
|
46735
|
+
/** Tags for organizing test cases. */
|
|
46736
|
+
tags?: string[];
|
|
46737
|
+
/** Scorer functions to evaluate the output. */
|
|
46738
|
+
scorers?: ScorerFunction[];
|
|
46739
|
+
/** Override span name (defaults to `t.name`, then `"unnamed test"`). */
|
|
46740
|
+
name?: string;
|
|
46741
|
+
}
|
|
46742
|
+
/**
|
|
46743
|
+
* Context passed to the eval test function.
|
|
46744
|
+
*/
|
|
46745
|
+
interface EvalContext {
|
|
46746
|
+
input: unknown;
|
|
46747
|
+
expected?: unknown;
|
|
46748
|
+
metadata?: Record<string, unknown>;
|
|
46749
|
+
}
|
|
46750
|
+
/**
|
|
46751
|
+
* The public API surface returned by `initNodeTestSuite()`.
|
|
46752
|
+
*/
|
|
46753
|
+
interface NodeTestSuite {
|
|
46754
|
+
/**
|
|
46755
|
+
* Creates a test function compatible with `node:test`.
|
|
46756
|
+
* Pass the result to `test()` from `node:test`.
|
|
46757
|
+
*
|
|
46758
|
+
* @param config - Eval configuration (input, expected, scorers, etc.)
|
|
46759
|
+
* @param fn - The test function. Its return value is logged as output and passed to scorers.
|
|
46760
|
+
* @returns A function accepting a test context `t` from `node:test`.
|
|
46761
|
+
*/
|
|
46762
|
+
eval(config: EvalConfig, fn: (context: EvalContext) => unknown | Promise<unknown>): (t: MinimalTestContext) => Promise<void>;
|
|
46763
|
+
/**
|
|
46764
|
+
* Flush the experiment: summarize results and send data to Braintrust.
|
|
46765
|
+
* Called automatically if `after` was provided in the config.
|
|
46766
|
+
*/
|
|
46767
|
+
flush(): Promise<void>;
|
|
46768
|
+
}
|
|
46769
|
+
|
|
46770
|
+
/**
|
|
46771
|
+
* Creates a new Node.js test suite with Braintrust experiment tracking.
|
|
46772
|
+
*
|
|
46773
|
+
* @example
|
|
46774
|
+
* ```typescript
|
|
46775
|
+
* import { test, describe, after } from 'node:test';
|
|
46776
|
+
* import { initNodeTestSuite } from 'braintrust';
|
|
46777
|
+
*
|
|
46778
|
+
* describe('My Tests', () => {
|
|
46779
|
+
* const suite = initNodeTestSuite({ projectName: 'my-project', after });
|
|
46780
|
+
*
|
|
46781
|
+
* test('my eval', suite.eval(
|
|
46782
|
+
* { input: 'hello', expected: 'world', scorers: [myScorer] },
|
|
46783
|
+
* async ({ input }) => {
|
|
46784
|
+
* return await myFunction(input);
|
|
46785
|
+
* }
|
|
46786
|
+
* ));
|
|
46787
|
+
* });
|
|
46788
|
+
* ```
|
|
46789
|
+
*/
|
|
46790
|
+
declare function initNodeTestSuite(config: NodeTestSuiteConfig): NodeTestSuite;
|
|
46791
|
+
|
|
46792
|
+
type LangChainSerialized = {
|
|
46793
|
+
id?: unknown[];
|
|
46794
|
+
name?: string;
|
|
46795
|
+
};
|
|
46796
|
+
type LangChainCallbackHandlerOptions<IsAsyncFlush extends boolean> = {
|
|
46797
|
+
debug: boolean;
|
|
46798
|
+
excludeMetadataProps: RegExp;
|
|
46799
|
+
logger?: Logger<IsAsyncFlush> | Span;
|
|
46800
|
+
parent?: Span | (() => Span);
|
|
46801
|
+
};
|
|
46802
|
+
type LangChainStartSpanArgs = StartSpanArgs & {
|
|
46803
|
+
parentRunId?: string;
|
|
46804
|
+
runId: string;
|
|
46805
|
+
};
|
|
46806
|
+
type LangChainEndSpanArgs = ExperimentLogPartialArgs & {
|
|
46807
|
+
parentRunId?: string;
|
|
46808
|
+
runId: string;
|
|
46809
|
+
tags?: string[];
|
|
46810
|
+
};
|
|
46811
|
+
type LangChainLLMResult = {
|
|
46812
|
+
generations?: unknown[];
|
|
46813
|
+
llmOutput?: Record<string, unknown>;
|
|
46814
|
+
};
|
|
46815
|
+
|
|
46816
|
+
declare const BRAINTRUST_LANGCHAIN_CALLBACK_HANDLER_NAME = "BraintrustCallbackHandler";
|
|
46817
|
+
declare class BraintrustLangChainCallbackHandler<IsAsyncFlush extends boolean = true> {
|
|
46818
|
+
name: string;
|
|
46819
|
+
private spans;
|
|
46820
|
+
private skippedRuns;
|
|
46821
|
+
private parent?;
|
|
46822
|
+
private rootRunId?;
|
|
46823
|
+
private options;
|
|
46824
|
+
private startTimes;
|
|
46825
|
+
private firstTokenTimes;
|
|
46826
|
+
private ttftMs;
|
|
46827
|
+
constructor(options?: Partial<LangChainCallbackHandlerOptions<IsAsyncFlush>>);
|
|
46828
|
+
protected startSpan({ runId, parentRunId, ...args }: LangChainStartSpanArgs): void;
|
|
46829
|
+
protected endSpan({ runId, parentRunId, tags, metadata, ...args }: LangChainEndSpanArgs): void;
|
|
46830
|
+
handleLLMStart(llm: LangChainSerialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
46831
|
+
handleLLMError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46832
|
+
handleLLMEnd(output: LangChainLLMResult, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46833
|
+
handleChatModelStart(llm: LangChainSerialized, messages: unknown[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
46834
|
+
handleChainStart(chain: LangChainSerialized, inputs: unknown, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, runName?: string): Promise<void>;
|
|
46835
|
+
handleChainError(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
46836
|
+
inputs?: Record<string, unknown>;
|
|
46837
|
+
}): Promise<void>;
|
|
46838
|
+
handleChainEnd(outputs: unknown, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
|
|
46839
|
+
inputs?: Record<string, unknown>;
|
|
46840
|
+
}): Promise<void>;
|
|
46841
|
+
handleToolStart(tool: LangChainSerialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runName?: string): Promise<void>;
|
|
46842
|
+
handleToolError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46843
|
+
handleToolEnd(output: unknown, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46844
|
+
handleAgentAction(action: Record<string, unknown>, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46845
|
+
handleAgentEnd(action: unknown, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46846
|
+
handleRetrieverStart(retriever: LangChainSerialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): Promise<void>;
|
|
46847
|
+
handleRetrieverEnd(documents: unknown[], runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46848
|
+
handleRetrieverError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
46849
|
+
handleLLMNewToken(_token: string, _idx: {
|
|
46850
|
+
prompt: number;
|
|
46851
|
+
completion: number;
|
|
46852
|
+
}, runId: string, _parentRunId?: string, _tags?: string[]): Promise<void>;
|
|
46853
|
+
}
|
|
46854
|
+
|
|
46855
|
+
interface BuildContext {
|
|
46856
|
+
getFunctionId(functionObj: unknown): Promise<FunctionIdType>;
|
|
46857
|
+
}
|
|
46858
|
+
interface Node {
|
|
46859
|
+
readonly id: string;
|
|
46860
|
+
__type: "node";
|
|
46861
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46862
|
+
addDependency(dependency: Dependency): void;
|
|
46863
|
+
}
|
|
46864
|
+
type NodeLike = Node | Prompt<boolean, boolean> | ProxyVariable;
|
|
46865
|
+
type LazyGraphNode = {
|
|
46866
|
+
type: "lazy";
|
|
46867
|
+
id: string;
|
|
46868
|
+
};
|
|
46869
|
+
declare class GraphBuilder {
|
|
46870
|
+
private nodes;
|
|
46871
|
+
private edges;
|
|
46872
|
+
private nodeLikeNodes;
|
|
46873
|
+
readonly IN: InputNode;
|
|
46874
|
+
readonly OUT: OutputNode;
|
|
46875
|
+
constructor();
|
|
46876
|
+
build(context: BuildContext): Promise<GraphDataType>;
|
|
46877
|
+
addEdge({ source, sourceVar, target, targetVar, expr, purpose, }: {
|
|
46878
|
+
source: NodeLike;
|
|
46879
|
+
sourceVar?: string;
|
|
46880
|
+
target: NodeLike;
|
|
46881
|
+
targetVar?: string;
|
|
46882
|
+
expr?: string;
|
|
46883
|
+
purpose: GraphEdgeType["purpose"];
|
|
46884
|
+
}): void;
|
|
46885
|
+
resolveNode(node: NodeLike): [Node, string[]];
|
|
46886
|
+
literal<T>(value: T): LiteralNode<T>;
|
|
46887
|
+
gate(options: {
|
|
46888
|
+
condition: string;
|
|
46889
|
+
}): GateNode;
|
|
46890
|
+
aggregator(): AggregatorNode;
|
|
46891
|
+
promptTemplate(options: {
|
|
46892
|
+
prompt: PromptBlockDataType;
|
|
46893
|
+
}): PromptTemplateNode;
|
|
46894
|
+
private generateId;
|
|
46895
|
+
private createInputNode;
|
|
46896
|
+
private createOutputNode;
|
|
46897
|
+
private createPromptNode;
|
|
46898
|
+
}
|
|
46899
|
+
type ProxyVariable = {
|
|
46900
|
+
[key: string]: ProxyVariable;
|
|
46901
|
+
};
|
|
46902
|
+
type TransformFn = (input: ProxyVariable) => Node;
|
|
46903
|
+
interface Dependency {
|
|
46904
|
+
node: Node;
|
|
46905
|
+
sourceVar?: string;
|
|
46906
|
+
targetVar?: string;
|
|
46907
|
+
expr?: string;
|
|
46908
|
+
}
|
|
46909
|
+
declare abstract class BaseNode implements Node {
|
|
46910
|
+
protected graph: GraphBuilder;
|
|
46911
|
+
readonly id: string;
|
|
46912
|
+
readonly __type = "node";
|
|
46913
|
+
dependencies: Dependency[];
|
|
46914
|
+
constructor(graph: GraphBuilder, id: string);
|
|
46915
|
+
addDependency(dependency: Dependency): void;
|
|
46916
|
+
abstract build(context: BuildContext): Promise<GraphNodeType>;
|
|
46917
|
+
}
|
|
46918
|
+
declare class InputNode extends BaseNode implements Node {
|
|
46919
|
+
constructor(graph: GraphBuilder, id: string);
|
|
46920
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46921
|
+
}
|
|
46922
|
+
declare class OutputNode extends BaseNode implements Node {
|
|
46923
|
+
constructor(graph: GraphBuilder, id: string);
|
|
46924
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46925
|
+
}
|
|
46926
|
+
declare class PromptNode extends BaseNode implements Node {
|
|
46927
|
+
private prompt;
|
|
46928
|
+
constructor(graph: GraphBuilder, id: string, prompt: Prompt);
|
|
46929
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46930
|
+
}
|
|
46931
|
+
declare class GateNode extends BaseNode implements Node {
|
|
46932
|
+
private condition;
|
|
46933
|
+
constructor(graph: GraphBuilder, id: string, condition: string);
|
|
46934
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46935
|
+
}
|
|
46936
|
+
declare class AggregatorNode extends BaseNode implements Node {
|
|
46937
|
+
constructor(graph: GraphBuilder, id: string);
|
|
46938
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46939
|
+
}
|
|
46940
|
+
declare class PromptTemplateNode extends BaseNode implements Node {
|
|
46941
|
+
private prompt;
|
|
46942
|
+
constructor(graph: GraphBuilder, id: string, prompt: PromptBlockDataType);
|
|
46943
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46944
|
+
}
|
|
46945
|
+
declare class LiteralNode<T> extends BaseNode implements Node {
|
|
46946
|
+
private value;
|
|
46947
|
+
constructor(graph: GraphBuilder, id: string, value: T);
|
|
46948
|
+
build(context: BuildContext): Promise<GraphNodeType>;
|
|
46949
|
+
}
|
|
46950
|
+
declare function createGraph(): GraphBuilder;
|
|
46951
|
+
declare function escapePath(parts: string[]): string | undefined;
|
|
46952
|
+
declare function unescapePath(path: string): string[];
|
|
46953
|
+
declare const _default: {
|
|
46954
|
+
createGraph: typeof createGraph;
|
|
46955
|
+
};
|
|
46956
|
+
|
|
46957
|
+
type graphFramework_AggregatorNode = AggregatorNode;
|
|
46958
|
+
declare const graphFramework_AggregatorNode: typeof AggregatorNode;
|
|
46959
|
+
type graphFramework_BuildContext = BuildContext;
|
|
46960
|
+
type graphFramework_GateNode = GateNode;
|
|
46961
|
+
declare const graphFramework_GateNode: typeof GateNode;
|
|
46962
|
+
type graphFramework_GraphBuilder = GraphBuilder;
|
|
46963
|
+
declare const graphFramework_GraphBuilder: typeof GraphBuilder;
|
|
46964
|
+
type graphFramework_InputNode = InputNode;
|
|
46965
|
+
declare const graphFramework_InputNode: typeof InputNode;
|
|
46966
|
+
type graphFramework_LazyGraphNode = LazyGraphNode;
|
|
46967
|
+
type graphFramework_LiteralNode<T> = LiteralNode<T>;
|
|
46968
|
+
declare const graphFramework_LiteralNode: typeof LiteralNode;
|
|
46969
|
+
type graphFramework_Node = Node;
|
|
46970
|
+
type graphFramework_NodeLike = NodeLike;
|
|
46971
|
+
type graphFramework_OutputNode = OutputNode;
|
|
46972
|
+
declare const graphFramework_OutputNode: typeof OutputNode;
|
|
46973
|
+
type graphFramework_PromptNode = PromptNode;
|
|
46974
|
+
declare const graphFramework_PromptNode: typeof PromptNode;
|
|
46975
|
+
type graphFramework_PromptTemplateNode = PromptTemplateNode;
|
|
46976
|
+
declare const graphFramework_PromptTemplateNode: typeof PromptTemplateNode;
|
|
46977
|
+
type graphFramework_ProxyVariable = ProxyVariable;
|
|
46978
|
+
type graphFramework_TransformFn = TransformFn;
|
|
46979
|
+
declare const graphFramework_createGraph: typeof createGraph;
|
|
46980
|
+
declare const graphFramework_escapePath: typeof escapePath;
|
|
46981
|
+
declare const graphFramework_unescapePath: typeof unescapePath;
|
|
46982
|
+
declare namespace graphFramework {
|
|
46983
|
+
export { graphFramework_AggregatorNode as AggregatorNode, type graphFramework_BuildContext as BuildContext, graphFramework_GateNode as GateNode, graphFramework_GraphBuilder as GraphBuilder, graphFramework_InputNode as InputNode, type graphFramework_LazyGraphNode as LazyGraphNode, graphFramework_LiteralNode as LiteralNode, type graphFramework_Node as Node, type graphFramework_NodeLike as NodeLike, graphFramework_OutputNode as OutputNode, graphFramework_PromptNode as PromptNode, graphFramework_PromptTemplateNode as PromptTemplateNode, type graphFramework_ProxyVariable as ProxyVariable, type graphFramework_TransformFn as TransformFn, graphFramework_createGraph as createGraph, _default as default, graphFramework_escapePath as escapePath, graphFramework_unescapePath as unescapePath };
|
|
46984
|
+
}
|
|
46985
|
+
|
|
46983
46986
|
declare const BATCH_TASK_KIND = "braintrust.durable.batch-task";
|
|
46984
46987
|
declare const BATCH_SCORER_KIND = "braintrust.durable.batch-scorer";
|
|
46985
46988
|
type JsonPrimitive = string | number | boolean | null;
|