braintrust 3.16.0 → 3.18.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.
Files changed (55) hide show
  1. package/bin/bt +41 -0
  2. package/dev/dist/index.d.mts +13 -0
  3. package/dev/dist/index.d.ts +13 -0
  4. package/dev/dist/index.js +4300 -2199
  5. package/dev/dist/index.mjs +2211 -110
  6. package/dist/apply-auto-instrumentation.js +238 -186
  7. package/dist/apply-auto-instrumentation.mjs +68 -16
  8. package/dist/auto-instrumentations/bundler/esbuild.cjs +90 -15
  9. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  10. package/dist/auto-instrumentations/bundler/next.cjs +90 -15
  11. package/dist/auto-instrumentations/bundler/next.mjs +3 -3
  12. package/dist/auto-instrumentations/bundler/rollup.cjs +90 -15
  13. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  14. package/dist/auto-instrumentations/bundler/vite.cjs +90 -15
  15. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  16. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +89 -14
  17. package/dist/auto-instrumentations/bundler/webpack.cjs +90 -15
  18. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
  19. package/dist/auto-instrumentations/{chunk-VXJONZVX.mjs → chunk-GNUEZ2PE.mjs} +13 -3
  20. package/dist/auto-instrumentations/{chunk-CNQ7BUKN.mjs → chunk-MYCHHXOE.mjs} +1 -1
  21. package/dist/auto-instrumentations/{chunk-E5DUYJWK.mjs → chunk-ZYKZEMRT.mjs} +82 -15
  22. package/dist/auto-instrumentations/hook.mjs +102 -15
  23. package/dist/auto-instrumentations/index.cjs +84 -16
  24. package/dist/auto-instrumentations/index.d.mts +3 -1
  25. package/dist/auto-instrumentations/index.d.ts +3 -1
  26. package/dist/auto-instrumentations/index.mjs +5 -3
  27. package/dist/auto-instrumentations/loader/cjs-patch.cjs +1 -1
  28. package/dist/auto-instrumentations/loader/cjs-patch.mjs +1 -1
  29. package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
  30. package/dist/browser.d.mts +177 -11
  31. package/dist/browser.d.ts +177 -11
  32. package/dist/browser.js +2296 -104
  33. package/dist/browser.mjs +2455 -263
  34. package/dist/{chunk-VMBQETG3.js → chunk-73IYIIOL.js} +28 -2
  35. package/dist/{chunk-O4ZIWXO3.mjs → chunk-BYFADLEZ.mjs} +27 -1
  36. package/dist/cli.js +2228 -113
  37. package/dist/edge-light.d.mts +1 -1
  38. package/dist/edge-light.d.ts +1 -1
  39. package/dist/edge-light.js +2296 -104
  40. package/dist/edge-light.mjs +2455 -263
  41. package/dist/index.d.mts +177 -11
  42. package/dist/index.d.ts +177 -11
  43. package/dist/index.js +3296 -1128
  44. package/dist/index.mjs +2272 -104
  45. package/dist/instrumentation/index.d.mts +3 -0
  46. package/dist/instrumentation/index.d.ts +3 -0
  47. package/dist/instrumentation/index.js +2171 -105
  48. package/dist/instrumentation/index.mjs +2171 -105
  49. package/dist/workerd.d.mts +1 -1
  50. package/dist/workerd.d.ts +1 -1
  51. package/dist/workerd.js +2296 -104
  52. package/dist/workerd.mjs +2455 -263
  53. package/package.json +19 -5
  54. package/scripts/bt-helper.js +139 -0
  55. package/scripts/install.js +153 -0
package/bin/bt ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // Runtime launcher for the `bt` CLI. Resolves the platform-specific binary
5
+ // (installed via the matching `@braintrust/bt-*` optionalDependency, or
6
+ // downloaded by `scripts/install.js` as a fallback) and forwards argv,
7
+ // stdio, signals, and the exit code.
8
+
9
+ const childProcess = require("node:child_process");
10
+ const { getBinaryPath } = require("../scripts/bt-helper");
11
+
12
+ let binaryPath;
13
+ try {
14
+ binaryPath = getBinaryPath();
15
+ } catch (err) {
16
+ console.error(err.message);
17
+ process.exit(1);
18
+ }
19
+
20
+ const child = childProcess
21
+ .spawn(binaryPath, process.argv.slice(2), {
22
+ stdio: "inherit",
23
+ windowsHide: true,
24
+ })
25
+ .on("error", (err) => {
26
+ console.error(err);
27
+ process.exit(1);
28
+ })
29
+ .on("exit", (code, signal) => {
30
+ if (signal) {
31
+ // Detach our forwarding listener so the re-raised signal hits Node's
32
+ // default handler; otherwise we'd intercept it again and exit 0.
33
+ process.removeAllListeners(signal);
34
+ process.kill(process.pid, signal);
35
+ return;
36
+ }
37
+ process.exit(code ?? 1);
38
+ });
39
+
40
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
41
+ process.on("SIGINT", () => child.kill("SIGINT"));
@@ -11497,12 +11497,14 @@ declare class ObjectFetcher<RecordType> implements AsyncIterable<WithTransaction
11497
11497
  }
11498
11498
  type BaseMetadata = Record<string, unknown> | void;
11499
11499
  type DefaultMetadataType = void;
11500
+ type EvalCaseOrigin = ObjectReferenceType;
11500
11501
  type EvalCase<Input, Expected, Metadata> = {
11501
11502
  input: Input;
11502
11503
  tags?: string[];
11503
11504
  id?: string;
11504
11505
  _xact_id?: TransactionId;
11505
11506
  created?: string | null;
11507
+ origin?: EvalCaseOrigin;
11506
11508
  upsert_id?: string;
11507
11509
  trialCount?: number;
11508
11510
  } & (Expected extends void ? object : {
@@ -11541,6 +11543,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
11541
11543
  _waitForId(): Promise<void>;
11542
11544
  get name(): Promise<string>;
11543
11545
  get project(): Promise<ObjectMetadata>;
11546
+ _getBaseExperimentId(): Promise<string | undefined>;
11544
11547
  private parentObjectType;
11545
11548
  protected getState(): Promise<BraintrustState>;
11546
11549
  /**
@@ -13201,6 +13204,7 @@ declare class Project {
13201
13204
  prompts: PromptBuilder;
13202
13205
  parameters: ParametersBuilder;
13203
13206
  scorers: ScorerBuilder;
13207
+ classifiers: ClassifierBuilder;
13204
13208
  private _publishableCodeFunctions;
13205
13209
  private _publishablePrompts;
13206
13210
  private _publishableParameters;
@@ -13239,6 +13243,12 @@ declare class ScorerBuilder {
13239
13243
  constructor(project: Project);
13240
13244
  create<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>>(opts: ScorerOpts<Output, Input, Params, Returns, Fn>): void;
13241
13245
  }
13246
+ declare class ClassifierBuilder {
13247
+ private readonly project;
13248
+ private taskCounter;
13249
+ constructor(project: Project);
13250
+ create<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>>(opts: ClassifierOpts<Output, Input, Params, Returns, Fn>): CodeFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns, Fn>;
13251
+ }
13242
13252
  type Schema<Input, Output> = Partial<{
13243
13253
  parameters: z.ZodSchema<Input>;
13244
13254
  returns: z.ZodSchema<Output>;
@@ -13264,6 +13274,9 @@ type ScorerOptsUnion<Output, Input, Params, Returns, Fn extends GenericFunction<
13264
13274
  type ScorerOpts<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>> = ScorerOptsUnion<Output, Input, Params, Returns, Fn> & {
13265
13275
  metadata?: Record<string, unknown>;
13266
13276
  };
13277
+ type ClassifierOpts<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>> = CodeOpts<Exact<Params, ScorerArgs<Output, Input>>, Returns, Fn> & {
13278
+ metadata?: Record<string, unknown>;
13279
+ };
13267
13280
  declare class CodeFunction<Input, Output, Fn extends GenericFunction<Input, Output>> {
13268
13281
  readonly project: Project;
13269
13282
  readonly handler: Fn;
@@ -11497,12 +11497,14 @@ declare class ObjectFetcher<RecordType> implements AsyncIterable<WithTransaction
11497
11497
  }
11498
11498
  type BaseMetadata = Record<string, unknown> | void;
11499
11499
  type DefaultMetadataType = void;
11500
+ type EvalCaseOrigin = ObjectReferenceType;
11500
11501
  type EvalCase<Input, Expected, Metadata> = {
11501
11502
  input: Input;
11502
11503
  tags?: string[];
11503
11504
  id?: string;
11504
11505
  _xact_id?: TransactionId;
11505
11506
  created?: string | null;
11507
+ origin?: EvalCaseOrigin;
11506
11508
  upsert_id?: string;
11507
11509
  trialCount?: number;
11508
11510
  } & (Expected extends void ? object : {
@@ -11541,6 +11543,7 @@ declare class Experiment extends ObjectFetcher<ExperimentEvent> implements Expor
11541
11543
  _waitForId(): Promise<void>;
11542
11544
  get name(): Promise<string>;
11543
11545
  get project(): Promise<ObjectMetadata>;
11546
+ _getBaseExperimentId(): Promise<string | undefined>;
11544
11547
  private parentObjectType;
11545
11548
  protected getState(): Promise<BraintrustState>;
11546
11549
  /**
@@ -13201,6 +13204,7 @@ declare class Project {
13201
13204
  prompts: PromptBuilder;
13202
13205
  parameters: ParametersBuilder;
13203
13206
  scorers: ScorerBuilder;
13207
+ classifiers: ClassifierBuilder;
13204
13208
  private _publishableCodeFunctions;
13205
13209
  private _publishablePrompts;
13206
13210
  private _publishableParameters;
@@ -13239,6 +13243,12 @@ declare class ScorerBuilder {
13239
13243
  constructor(project: Project);
13240
13244
  create<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>>(opts: ScorerOpts<Output, Input, Params, Returns, Fn>): void;
13241
13245
  }
13246
+ declare class ClassifierBuilder {
13247
+ private readonly project;
13248
+ private taskCounter;
13249
+ constructor(project: Project);
13250
+ create<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>>(opts: ClassifierOpts<Output, Input, Params, Returns, Fn>): CodeFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns, Fn>;
13251
+ }
13242
13252
  type Schema<Input, Output> = Partial<{
13243
13253
  parameters: z.ZodSchema<Input>;
13244
13254
  returns: z.ZodSchema<Output>;
@@ -13264,6 +13274,9 @@ type ScorerOptsUnion<Output, Input, Params, Returns, Fn extends GenericFunction<
13264
13274
  type ScorerOpts<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>> = ScorerOptsUnion<Output, Input, Params, Returns, Fn> & {
13265
13275
  metadata?: Record<string, unknown>;
13266
13276
  };
13277
+ type ClassifierOpts<Output, Input, Params, Returns, Fn extends GenericFunction<Exact<Params, ScorerArgs<Output, Input>>, Returns>> = CodeOpts<Exact<Params, ScorerArgs<Output, Input>>, Returns, Fn> & {
13278
+ metadata?: Record<string, unknown>;
13279
+ };
13267
13280
  declare class CodeFunction<Input, Output, Fn extends GenericFunction<Input, Output>> {
13268
13281
  readonly project: Project;
13269
13282
  readonly handler: Fn;