braintrust 0.0.140 → 0.0.141-dev1
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/.turbo/turbo-build.log +42 -0
- package/.turbo/turbo-watch.log +1843 -0
- package/LICENSE +201 -0
- package/braintrust-0.0.141.tgz +0 -0
- package/dist/{logger.d.ts → browser.d.mts} +168 -92
- package/dist/browser.d.ts +1089 -2
- package/dist/browser.js +383 -9185
- package/dist/browser.mjs +254 -7
- package/dist/cli.js +3887 -27452
- package/dist/index.d.mts +1250 -0
- package/dist/index.d.ts +1236 -41
- package/dist/index.js +1706 -18925
- package/dist/index.mjs +255 -121
- package/package.json +40 -23
- package/tsup.config.ts +23 -0
- package/turbo.json +8 -0
- package/vitest.config.js +6 -0
- package/dist/browser-config.d.ts +0 -6
- package/dist/cli.d.ts +0 -35
- package/dist/framework.d.ts +0 -180
- package/dist/framework.test.d.ts +0 -1
- package/dist/functions.d.ts +0 -15
- package/dist/gitutil.d.ts +0 -17
- package/dist/isomorph.d.ts +0 -27
- package/dist/jest/nodeModulesPaths.d.ts +0 -15
- package/dist/jest/tryRealpath.d.ts +0 -7
- package/dist/node.d.ts +0 -1
- package/dist/progress.d.ts +0 -18
- package/dist/stackutil.d.ts +0 -8
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/util.d.ts +0 -11
- package/dist/wrappers/ai-sdk.d.ts +0 -8
- package/dist/wrappers/oai.d.ts +0 -34
- package/jest.config.js +0 -5
package/dist/index.mjs
CHANGED
|
@@ -316,6 +316,125 @@ var LazyValue = class {
|
|
|
316
316
|
// src/logger.ts
|
|
317
317
|
import Mustache from "mustache";
|
|
318
318
|
import { z } from "zod";
|
|
319
|
+
|
|
320
|
+
// src/stream.ts
|
|
321
|
+
import { callEventSchema } from "@braintrust/core/typespecs";
|
|
322
|
+
import {
|
|
323
|
+
createParser
|
|
324
|
+
} from "eventsource-parser";
|
|
325
|
+
var BraintrustStream = class _BraintrustStream {
|
|
326
|
+
stream;
|
|
327
|
+
constructor(baseStream) {
|
|
328
|
+
this.stream = baseStream.pipeThrough(btStreamParser());
|
|
329
|
+
}
|
|
330
|
+
copy() {
|
|
331
|
+
const [newStream, copyStream] = this.stream.tee();
|
|
332
|
+
this.stream = copyStream;
|
|
333
|
+
return new _BraintrustStream(newStream);
|
|
334
|
+
}
|
|
335
|
+
toReadableStream() {
|
|
336
|
+
return this.stream;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
function btStreamParser() {
|
|
340
|
+
const decoder = new TextDecoder();
|
|
341
|
+
let parser;
|
|
342
|
+
return new TransformStream({
|
|
343
|
+
async start(controller) {
|
|
344
|
+
parser = createParser((event) => {
|
|
345
|
+
if (event.type === "reconnect-interval") {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const parsed = callEventSchema.safeParse(event);
|
|
349
|
+
if (!parsed.success) {
|
|
350
|
+
throw new Error(`Failed to parse event: ${parsed.error}`);
|
|
351
|
+
}
|
|
352
|
+
switch (event.event) {
|
|
353
|
+
case "text_delta":
|
|
354
|
+
controller.enqueue({
|
|
355
|
+
type: "text_delta",
|
|
356
|
+
data: JSON.parse(event.data)
|
|
357
|
+
});
|
|
358
|
+
break;
|
|
359
|
+
case "json_delta":
|
|
360
|
+
controller.enqueue({
|
|
361
|
+
type: "json_delta",
|
|
362
|
+
data: event.data
|
|
363
|
+
});
|
|
364
|
+
break;
|
|
365
|
+
case "done":
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
},
|
|
370
|
+
async transform(chunk, controller) {
|
|
371
|
+
if (chunk instanceof Uint8Array) {
|
|
372
|
+
parser.feed(decoder.decode(chunk));
|
|
373
|
+
} else if (typeof chunk === "string") {
|
|
374
|
+
parser.feed(chunk);
|
|
375
|
+
} else {
|
|
376
|
+
controller.enqueue(chunk);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
async flush(controller) {
|
|
380
|
+
controller.terminate();
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
function createFinalValuePassThroughStream(onFinal) {
|
|
385
|
+
const decoder = new TextDecoder();
|
|
386
|
+
const textChunks = [];
|
|
387
|
+
const jsonChunks = [];
|
|
388
|
+
const transformStream = new TransformStream({
|
|
389
|
+
transform(chunk, controller) {
|
|
390
|
+
if (typeof chunk === "string") {
|
|
391
|
+
textChunks.push(chunk);
|
|
392
|
+
} else if (chunk instanceof Uint8Array) {
|
|
393
|
+
textChunks.push(decoder.decode(chunk));
|
|
394
|
+
} else {
|
|
395
|
+
const chunkType = chunk.type;
|
|
396
|
+
switch (chunkType) {
|
|
397
|
+
case "text_delta":
|
|
398
|
+
textChunks.push(chunk.data);
|
|
399
|
+
break;
|
|
400
|
+
case "json_delta":
|
|
401
|
+
jsonChunks.push(chunk.data);
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
const _type = chunkType;
|
|
405
|
+
throw new Error(`Unknown chunk type ${_type}`);
|
|
406
|
+
}
|
|
407
|
+
controller.enqueue(chunk);
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
flush(controller) {
|
|
411
|
+
if (jsonChunks.length > 0) {
|
|
412
|
+
onFinal(JSON.parse(jsonChunks.join("")));
|
|
413
|
+
} else if (textChunks.length > 0) {
|
|
414
|
+
onFinal(textChunks.join(""));
|
|
415
|
+
} else {
|
|
416
|
+
onFinal(void 0);
|
|
417
|
+
}
|
|
418
|
+
controller.terminate();
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
return transformStream;
|
|
422
|
+
}
|
|
423
|
+
function devNullWritableStream() {
|
|
424
|
+
return new WritableStream({
|
|
425
|
+
write(chunk) {
|
|
426
|
+
},
|
|
427
|
+
close() {
|
|
428
|
+
},
|
|
429
|
+
abort(reason) {
|
|
430
|
+
},
|
|
431
|
+
start(controller) {
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/logger.ts
|
|
437
|
+
import { waitUntil } from "@vercel/functions";
|
|
319
438
|
var NoopSpan = class {
|
|
320
439
|
id;
|
|
321
440
|
kind = "span";
|
|
@@ -352,6 +471,7 @@ var loginSchema = z.strictObject({
|
|
|
352
471
|
appPublicUrl: z.string(),
|
|
353
472
|
orgName: z.string(),
|
|
354
473
|
logUrl: z.string(),
|
|
474
|
+
proxyUrl: z.string(),
|
|
355
475
|
loginToken: z.string(),
|
|
356
476
|
orgId: z.string().nullish(),
|
|
357
477
|
gitMetadataSettings: gitMetadataSettingsSchema.nullish()
|
|
@@ -390,11 +510,13 @@ var BraintrustState = class _BraintrustState {
|
|
|
390
510
|
orgId = null;
|
|
391
511
|
orgName = null;
|
|
392
512
|
logUrl = null;
|
|
513
|
+
proxyUrl = null;
|
|
393
514
|
loggedIn = false;
|
|
394
515
|
gitMetadataSettings;
|
|
395
516
|
fetch = globalThis.fetch;
|
|
396
517
|
_apiConn = null;
|
|
397
518
|
_logConn = null;
|
|
519
|
+
_proxyConn = null;
|
|
398
520
|
resetLoginInfo() {
|
|
399
521
|
this.appUrl = null;
|
|
400
522
|
this.appPublicUrl = null;
|
|
@@ -402,10 +524,12 @@ var BraintrustState = class _BraintrustState {
|
|
|
402
524
|
this.orgId = null;
|
|
403
525
|
this.orgName = null;
|
|
404
526
|
this.logUrl = null;
|
|
527
|
+
this.proxyUrl = null;
|
|
405
528
|
this.loggedIn = false;
|
|
406
529
|
this.gitMetadataSettings = void 0;
|
|
407
530
|
this._apiConn = null;
|
|
408
531
|
this._logConn = null;
|
|
532
|
+
this._proxyConn = null;
|
|
409
533
|
}
|
|
410
534
|
copyLoginInfo(other) {
|
|
411
535
|
this.appUrl = other.appUrl;
|
|
@@ -414,10 +538,12 @@ var BraintrustState = class _BraintrustState {
|
|
|
414
538
|
this.orgId = other.orgId;
|
|
415
539
|
this.orgName = other.orgName;
|
|
416
540
|
this.logUrl = other.logUrl;
|
|
541
|
+
this.proxyUrl = other.proxyUrl;
|
|
417
542
|
this.loggedIn = other.loggedIn;
|
|
418
543
|
this.gitMetadataSettings = other.gitMetadataSettings;
|
|
419
544
|
this._apiConn = other._apiConn;
|
|
420
545
|
this._logConn = other._logConn;
|
|
546
|
+
this._proxyConn = other._proxyConn;
|
|
421
547
|
}
|
|
422
548
|
serialize() {
|
|
423
549
|
if (!this.loggedIn) {
|
|
@@ -425,7 +551,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
425
551
|
"Cannot serialize BraintrustState without being logged in"
|
|
426
552
|
);
|
|
427
553
|
}
|
|
428
|
-
if (!this.appUrl || !this.appPublicUrl || !this.logUrl || !this.orgName || !this.loginToken || !this.loggedIn) {
|
|
554
|
+
if (!this.appUrl || !this.appPublicUrl || !this.logUrl || !this.proxyUrl || !this.orgName || !this.loginToken || !this.loggedIn) {
|
|
429
555
|
throw new Error(
|
|
430
556
|
"Cannot serialize BraintrustState without all login attributes"
|
|
431
557
|
);
|
|
@@ -437,6 +563,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
437
563
|
orgId: this.orgId,
|
|
438
564
|
orgName: this.orgName,
|
|
439
565
|
logUrl: this.logUrl,
|
|
566
|
+
proxyUrl: this.proxyUrl,
|
|
440
567
|
gitMetadataSettings: this.gitMetadataSettings
|
|
441
568
|
};
|
|
442
569
|
}
|
|
@@ -459,6 +586,7 @@ var BraintrustState = class _BraintrustState {
|
|
|
459
586
|
state.logConn().set_token(state.loginToken);
|
|
460
587
|
state.logConn().make_long_lived();
|
|
461
588
|
state.apiConn().set_token(state.loginToken);
|
|
589
|
+
state.proxyConn().set_token(state.loginToken);
|
|
462
590
|
state.loggedIn = true;
|
|
463
591
|
state.loginReplaceLogConn(state.logConn());
|
|
464
592
|
return state;
|
|
@@ -497,6 +625,15 @@ var BraintrustState = class _BraintrustState {
|
|
|
497
625
|
}
|
|
498
626
|
return this._logConn;
|
|
499
627
|
}
|
|
628
|
+
proxyConn() {
|
|
629
|
+
if (!this._proxyConn) {
|
|
630
|
+
if (!this.proxyUrl) {
|
|
631
|
+
throw new Error("Must initialize proxyUrl before requesting proxyConn");
|
|
632
|
+
}
|
|
633
|
+
this._proxyConn = new HTTPConnection(this.proxyUrl, this.fetch);
|
|
634
|
+
}
|
|
635
|
+
return this._proxyConn;
|
|
636
|
+
}
|
|
500
637
|
bgLogger() {
|
|
501
638
|
return this._bgLogger;
|
|
502
639
|
}
|
|
@@ -809,6 +946,11 @@ var Logger = class {
|
|
|
809
946
|
parentObjectType() {
|
|
810
947
|
return SpanObjectTypeV2.PROJECT_LOGS;
|
|
811
948
|
}
|
|
949
|
+
triggerWaitUntilFlush() {
|
|
950
|
+
if (!this.state.bgLogger().syncFlush) {
|
|
951
|
+
return waitUntil(this.state.bgLogger().flush());
|
|
952
|
+
}
|
|
953
|
+
}
|
|
812
954
|
/**
|
|
813
955
|
* Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
|
|
814
956
|
*
|
|
@@ -834,6 +976,7 @@ var Logger = class {
|
|
|
834
976
|
this.lastStartTime = span.end();
|
|
835
977
|
const ret = span.id;
|
|
836
978
|
if (this.asyncFlush === true) {
|
|
979
|
+
this.triggerWaitUntilFlush();
|
|
837
980
|
return ret;
|
|
838
981
|
} else {
|
|
839
982
|
return (async () => {
|
|
@@ -861,6 +1004,7 @@ var Logger = class {
|
|
|
861
1004
|
() => span.end()
|
|
862
1005
|
);
|
|
863
1006
|
if (this.asyncFlush) {
|
|
1007
|
+
this.triggerWaitUntilFlush();
|
|
864
1008
|
return ret;
|
|
865
1009
|
} else {
|
|
866
1010
|
return (async () => {
|
|
@@ -1292,6 +1436,8 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
1292
1436
|
appUrl,
|
|
1293
1437
|
apiKey,
|
|
1294
1438
|
orgName,
|
|
1439
|
+
forceLogin,
|
|
1440
|
+
fetch,
|
|
1295
1441
|
metadata,
|
|
1296
1442
|
gitMetadataSettings,
|
|
1297
1443
|
projectId,
|
|
@@ -1309,7 +1455,7 @@ function init(projectOrOptions, optionalOptions) {
|
|
|
1309
1455
|
}
|
|
1310
1456
|
const lazyMetadata2 = new LazyValue(
|
|
1311
1457
|
async () => {
|
|
1312
|
-
await state.login({ apiKey, appUrl, orgName });
|
|
1458
|
+
await state.login({ apiKey, appUrl, orgName, fetch, forceLogin });
|
|
1313
1459
|
const args = {
|
|
1314
1460
|
project_name: project,
|
|
1315
1461
|
project_id: projectId,
|
|
@@ -1480,6 +1626,8 @@ function initDataset(projectOrOptions, optionalOptions) {
|
|
|
1480
1626
|
appUrl,
|
|
1481
1627
|
apiKey,
|
|
1482
1628
|
orgName,
|
|
1629
|
+
fetch,
|
|
1630
|
+
forceLogin,
|
|
1483
1631
|
projectId,
|
|
1484
1632
|
useOutput: legacy,
|
|
1485
1633
|
state: stateArg
|
|
@@ -1490,7 +1638,9 @@ function initDataset(projectOrOptions, optionalOptions) {
|
|
|
1490
1638
|
await state.login({
|
|
1491
1639
|
orgName,
|
|
1492
1640
|
apiKey,
|
|
1493
|
-
appUrl
|
|
1641
|
+
appUrl,
|
|
1642
|
+
fetch,
|
|
1643
|
+
forceLogin
|
|
1494
1644
|
});
|
|
1495
1645
|
const args = {
|
|
1496
1646
|
org_id: state.orgId,
|
|
@@ -1569,6 +1719,7 @@ function initLogger(options = {}) {
|
|
|
1569
1719
|
apiKey,
|
|
1570
1720
|
orgName,
|
|
1571
1721
|
forceLogin,
|
|
1722
|
+
fetch,
|
|
1572
1723
|
state: stateArg
|
|
1573
1724
|
} = options || {};
|
|
1574
1725
|
const computeMetadataArgs = {
|
|
@@ -1582,7 +1733,8 @@ function initLogger(options = {}) {
|
|
|
1582
1733
|
orgName,
|
|
1583
1734
|
apiKey,
|
|
1584
1735
|
appUrl,
|
|
1585
|
-
forceLogin
|
|
1736
|
+
forceLogin,
|
|
1737
|
+
fetch
|
|
1586
1738
|
});
|
|
1587
1739
|
return computeLoggerMetadata(state, computeMetadataArgs);
|
|
1588
1740
|
}
|
|
@@ -1606,6 +1758,8 @@ async function loadPrompt({
|
|
|
1606
1758
|
appUrl,
|
|
1607
1759
|
apiKey,
|
|
1608
1760
|
orgName,
|
|
1761
|
+
fetch,
|
|
1762
|
+
forceLogin,
|
|
1609
1763
|
state: stateArg
|
|
1610
1764
|
}) {
|
|
1611
1765
|
if (isEmpty(projectName) && isEmpty(projectId)) {
|
|
@@ -1618,7 +1772,9 @@ async function loadPrompt({
|
|
|
1618
1772
|
state.login({
|
|
1619
1773
|
orgName,
|
|
1620
1774
|
apiKey,
|
|
1621
|
-
appUrl
|
|
1775
|
+
appUrl,
|
|
1776
|
+
fetch,
|
|
1777
|
+
forceLogin
|
|
1622
1778
|
});
|
|
1623
1779
|
const args = {
|
|
1624
1780
|
project_name: projectName,
|
|
@@ -1661,6 +1817,7 @@ async function login(options = {}) {
|
|
|
1661
1817
|
}
|
|
1662
1818
|
await _globalState.login(options);
|
|
1663
1819
|
globalThis.__inherited_braintrust_state = _globalState;
|
|
1820
|
+
return _globalState;
|
|
1664
1821
|
}
|
|
1665
1822
|
async function loginToState(options = {}) {
|
|
1666
1823
|
const {
|
|
@@ -1699,6 +1856,7 @@ async function loginToState(options = {}) {
|
|
|
1699
1856
|
}
|
|
1700
1857
|
conn.make_long_lived();
|
|
1701
1858
|
state.apiConn().set_token(apiKey);
|
|
1859
|
+
state.proxyConn().set_token(apiKey);
|
|
1702
1860
|
state.loginToken = conn.token;
|
|
1703
1861
|
state.loggedIn = true;
|
|
1704
1862
|
state.loginReplaceLogConn(conn);
|
|
@@ -1870,6 +2028,12 @@ function _check_org_info(state, org_info, org_name) {
|
|
|
1870
2028
|
state.orgId = org.id;
|
|
1871
2029
|
state.orgName = org.name;
|
|
1872
2030
|
state.logUrl = isomorph_default.getEnv("BRAINTRUST_API_URL") ?? org.api_url;
|
|
2031
|
+
state.proxyUrl = isomorph_default.getEnv("BRAINTRUST_PROXY_URL") ?? org.proxy_url;
|
|
2032
|
+
if (state.proxyUrl) {
|
|
2033
|
+
const url = new URL(state.proxyUrl);
|
|
2034
|
+
url.pathname = "";
|
|
2035
|
+
state.proxyUrl = url.toString();
|
|
2036
|
+
}
|
|
1873
2037
|
state.gitMetadataSettings = org.git_metadata || void 0;
|
|
1874
2038
|
break;
|
|
1875
2039
|
}
|
|
@@ -1881,7 +2045,9 @@ function _check_org_info(state, org_info, org_name) {
|
|
|
1881
2045
|
}
|
|
1882
2046
|
}
|
|
1883
2047
|
function _urljoin(...parts) {
|
|
1884
|
-
return parts.map(
|
|
2048
|
+
return parts.map(
|
|
2049
|
+
(x, i) => x.replace(/^\//, "").replace(i < parts.length - 1 ? /\/$/ : "", "")
|
|
2050
|
+
).join("/");
|
|
1885
2051
|
}
|
|
1886
2052
|
function validateTags(tags) {
|
|
1887
2053
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -2380,12 +2546,32 @@ var SpanImpl = class _SpanImpl {
|
|
|
2380
2546
|
const sanitized = validateAndSanitizeExperimentLogPartialArgs(event ?? {});
|
|
2381
2547
|
let sanitizedAndInternalData = { ...internalData };
|
|
2382
2548
|
mergeDicts(sanitizedAndInternalData, sanitized);
|
|
2549
|
+
const serializableInternalData = {};
|
|
2550
|
+
const lazyInternalData = {};
|
|
2551
|
+
for (const [key, value] of Object.entries(sanitizedAndInternalData)) {
|
|
2552
|
+
if (value instanceof BraintrustStream) {
|
|
2553
|
+
const streamCopy = value.copy();
|
|
2554
|
+
lazyInternalData[key] = new LazyValue(async () => {
|
|
2555
|
+
return await new Promise((resolve) => {
|
|
2556
|
+
streamCopy.toReadableStream().pipeThrough(createFinalValuePassThroughStream(resolve)).pipeTo(devNullWritableStream());
|
|
2557
|
+
});
|
|
2558
|
+
});
|
|
2559
|
+
} else if (value instanceof ReadableStream) {
|
|
2560
|
+
lazyInternalData[key] = new LazyValue(async () => {
|
|
2561
|
+
return await new Promise((resolve) => {
|
|
2562
|
+
value.pipeThrough(createFinalValuePassThroughStream(resolve)).pipeTo(devNullWritableStream());
|
|
2563
|
+
});
|
|
2564
|
+
});
|
|
2565
|
+
} else {
|
|
2566
|
+
serializableInternalData[key] = value;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2383
2569
|
let partialRecord = {
|
|
2384
2570
|
id: this.id,
|
|
2385
2571
|
span_id: this.spanId,
|
|
2386
2572
|
root_span_id: this.rootSpanId,
|
|
2387
2573
|
span_parents: this.spanParents,
|
|
2388
|
-
...
|
|
2574
|
+
...serializableInternalData,
|
|
2389
2575
|
[IS_MERGE_FIELD]: this.isMerge
|
|
2390
2576
|
};
|
|
2391
2577
|
const serializedPartialRecord = JSON.stringify(partialRecord, (k, v) => {
|
|
@@ -2409,6 +2595,14 @@ var SpanImpl = class _SpanImpl {
|
|
|
2409
2595
|
}
|
|
2410
2596
|
const computeRecord = async () => ({
|
|
2411
2597
|
...partialRecord,
|
|
2598
|
+
...Object.fromEntries(
|
|
2599
|
+
await Promise.all(
|
|
2600
|
+
Object.entries(lazyInternalData).map(async ([key, value]) => [
|
|
2601
|
+
key,
|
|
2602
|
+
await value.get()
|
|
2603
|
+
])
|
|
2604
|
+
)
|
|
2605
|
+
),
|
|
2412
2606
|
...new SpanComponentsV2({
|
|
2413
2607
|
objectType: this.parentObjectType,
|
|
2414
2608
|
objectId: await this.parentObjectId.get()
|
|
@@ -2773,6 +2967,55 @@ function configureNode() {
|
|
|
2773
2967
|
_internalSetInitialState();
|
|
2774
2968
|
}
|
|
2775
2969
|
|
|
2970
|
+
// src/functions/invoke.ts
|
|
2971
|
+
import {
|
|
2972
|
+
INVOKE_API_VERSION
|
|
2973
|
+
} from "@braintrust/core/typespecs";
|
|
2974
|
+
async function invoke(args) {
|
|
2975
|
+
const {
|
|
2976
|
+
orgName,
|
|
2977
|
+
apiKey,
|
|
2978
|
+
appUrl,
|
|
2979
|
+
forceLogin,
|
|
2980
|
+
fetch,
|
|
2981
|
+
arg,
|
|
2982
|
+
parent: parentArg,
|
|
2983
|
+
state: stateArg,
|
|
2984
|
+
stream,
|
|
2985
|
+
schema,
|
|
2986
|
+
...functionId
|
|
2987
|
+
} = args;
|
|
2988
|
+
const state = stateArg ?? _internalGetGlobalState();
|
|
2989
|
+
await state.login({
|
|
2990
|
+
orgName,
|
|
2991
|
+
apiKey,
|
|
2992
|
+
appUrl,
|
|
2993
|
+
forceLogin
|
|
2994
|
+
});
|
|
2995
|
+
const parent = parentArg ? typeof parentArg === "string" ? parentArg : await parentArg.export() : await currentSpan().export();
|
|
2996
|
+
const request = {
|
|
2997
|
+
...functionId,
|
|
2998
|
+
arg,
|
|
2999
|
+
parent,
|
|
3000
|
+
stream,
|
|
3001
|
+
api_version: INVOKE_API_VERSION
|
|
3002
|
+
};
|
|
3003
|
+
const resp = await state.proxyConn().post(`function/invoke`, request, {
|
|
3004
|
+
headers: {
|
|
3005
|
+
Accept: stream ? "text/event-stream" : "application/json"
|
|
3006
|
+
}
|
|
3007
|
+
});
|
|
3008
|
+
if (stream) {
|
|
3009
|
+
if (!resp.body) {
|
|
3010
|
+
throw new Error("Received empty stream body");
|
|
3011
|
+
}
|
|
3012
|
+
return new BraintrustStream(resp.body);
|
|
3013
|
+
} else {
|
|
3014
|
+
const data = await resp.json();
|
|
3015
|
+
return schema ? schema.parse(data) : data;
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
|
|
2776
3019
|
// src/framework.ts
|
|
2777
3020
|
import chalk from "chalk";
|
|
2778
3021
|
import { SpanTypeAttribute as SpanTypeAttribute2, mergeDicts as mergeDicts2 } from "@braintrust/core";
|
|
@@ -2817,7 +3060,7 @@ var BarProgressReporter = class {
|
|
|
2817
3060
|
// src/framework.ts
|
|
2818
3061
|
import pluralize from "pluralize";
|
|
2819
3062
|
|
|
2820
|
-
//
|
|
3063
|
+
// ../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
|
|
2821
3064
|
function initialParams(fn) {
|
|
2822
3065
|
return function(...args) {
|
|
2823
3066
|
var callback = args.pop();
|
|
@@ -3792,93 +4035,6 @@ function queue(worker, concurrency) {
|
|
|
3792
4035
|
_worker(items[0], cb);
|
|
3793
4036
|
}, concurrency, 1);
|
|
3794
4037
|
}
|
|
3795
|
-
var Heap = class {
|
|
3796
|
-
constructor() {
|
|
3797
|
-
this.heap = [];
|
|
3798
|
-
this.pushCount = Number.MIN_SAFE_INTEGER;
|
|
3799
|
-
}
|
|
3800
|
-
get length() {
|
|
3801
|
-
return this.heap.length;
|
|
3802
|
-
}
|
|
3803
|
-
empty() {
|
|
3804
|
-
this.heap = [];
|
|
3805
|
-
return this;
|
|
3806
|
-
}
|
|
3807
|
-
percUp(index) {
|
|
3808
|
-
let p;
|
|
3809
|
-
while (index > 0 && smaller(this.heap[index], this.heap[p = parent(index)])) {
|
|
3810
|
-
let t = this.heap[index];
|
|
3811
|
-
this.heap[index] = this.heap[p];
|
|
3812
|
-
this.heap[p] = t;
|
|
3813
|
-
index = p;
|
|
3814
|
-
}
|
|
3815
|
-
}
|
|
3816
|
-
percDown(index) {
|
|
3817
|
-
let l;
|
|
3818
|
-
while ((l = leftChi(index)) < this.heap.length) {
|
|
3819
|
-
if (l + 1 < this.heap.length && smaller(this.heap[l + 1], this.heap[l])) {
|
|
3820
|
-
l = l + 1;
|
|
3821
|
-
}
|
|
3822
|
-
if (smaller(this.heap[index], this.heap[l])) {
|
|
3823
|
-
break;
|
|
3824
|
-
}
|
|
3825
|
-
let t = this.heap[index];
|
|
3826
|
-
this.heap[index] = this.heap[l];
|
|
3827
|
-
this.heap[l] = t;
|
|
3828
|
-
index = l;
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
push(node) {
|
|
3832
|
-
node.pushCount = ++this.pushCount;
|
|
3833
|
-
this.heap.push(node);
|
|
3834
|
-
this.percUp(this.heap.length - 1);
|
|
3835
|
-
}
|
|
3836
|
-
unshift(node) {
|
|
3837
|
-
return this.heap.push(node);
|
|
3838
|
-
}
|
|
3839
|
-
shift() {
|
|
3840
|
-
let [top] = this.heap;
|
|
3841
|
-
this.heap[0] = this.heap[this.heap.length - 1];
|
|
3842
|
-
this.heap.pop();
|
|
3843
|
-
this.percDown(0);
|
|
3844
|
-
return top;
|
|
3845
|
-
}
|
|
3846
|
-
toArray() {
|
|
3847
|
-
return [...this];
|
|
3848
|
-
}
|
|
3849
|
-
*[Symbol.iterator]() {
|
|
3850
|
-
for (let i = 0; i < this.heap.length; i++) {
|
|
3851
|
-
yield this.heap[i].data;
|
|
3852
|
-
}
|
|
3853
|
-
}
|
|
3854
|
-
remove(testFn) {
|
|
3855
|
-
let j = 0;
|
|
3856
|
-
for (let i = 0; i < this.heap.length; i++) {
|
|
3857
|
-
if (!testFn(this.heap[i])) {
|
|
3858
|
-
this.heap[j] = this.heap[i];
|
|
3859
|
-
j++;
|
|
3860
|
-
}
|
|
3861
|
-
}
|
|
3862
|
-
this.heap.splice(j);
|
|
3863
|
-
for (let i = parent(this.heap.length - 1); i >= 0; i--) {
|
|
3864
|
-
this.percDown(i);
|
|
3865
|
-
}
|
|
3866
|
-
return this;
|
|
3867
|
-
}
|
|
3868
|
-
};
|
|
3869
|
-
function leftChi(i) {
|
|
3870
|
-
return (i << 1) + 1;
|
|
3871
|
-
}
|
|
3872
|
-
function parent(i) {
|
|
3873
|
-
return (i + 1 >> 1) - 1;
|
|
3874
|
-
}
|
|
3875
|
-
function smaller(x, y) {
|
|
3876
|
-
if (x.priority !== y.priority) {
|
|
3877
|
-
return x.priority < y.priority;
|
|
3878
|
-
} else {
|
|
3879
|
-
return x.pushCount < y.pushCount;
|
|
3880
|
-
}
|
|
3881
|
-
}
|
|
3882
4038
|
function race(tasks, callback) {
|
|
3883
4039
|
callback = once(callback);
|
|
3884
4040
|
if (!Array.isArray(tasks))
|
|
@@ -4999,44 +5155,19 @@ function postProcessOutput(text, tool_calls, finish_reason) {
|
|
|
4999
5155
|
}
|
|
5000
5156
|
|
|
5001
5157
|
// src/index.ts
|
|
5002
|
-
import {
|
|
5003
|
-
ParentExperimentIds,
|
|
5004
|
-
ParentProjectLogIds,
|
|
5005
|
-
IdField as IdField2,
|
|
5006
|
-
InputField,
|
|
5007
|
-
InputsField,
|
|
5008
|
-
OtherExperimentLogFields,
|
|
5009
|
-
ExperimentLogPartialArgs as ExperimentLogPartialArgs2,
|
|
5010
|
-
ExperimentLogFullArgs as ExperimentLogFullArgs2,
|
|
5011
|
-
LogFeedbackFullArgs as LogFeedbackFullArgs2,
|
|
5012
|
-
LogCommentFullArgs,
|
|
5013
|
-
CommentEvent,
|
|
5014
|
-
DatasetRecord as DatasetRecord2
|
|
5015
|
-
} from "@braintrust/core";
|
|
5016
5158
|
configureNode();
|
|
5017
5159
|
export {
|
|
5018
5160
|
BaseExperiment,
|
|
5019
5161
|
BraintrustState,
|
|
5020
|
-
|
|
5162
|
+
BraintrustStream,
|
|
5021
5163
|
Dataset,
|
|
5022
|
-
DatasetRecord2 as DatasetRecord,
|
|
5023
5164
|
Eval,
|
|
5024
5165
|
Experiment,
|
|
5025
|
-
ExperimentLogFullArgs2 as ExperimentLogFullArgs,
|
|
5026
|
-
ExperimentLogPartialArgs2 as ExperimentLogPartialArgs,
|
|
5027
|
-
IdField2 as IdField,
|
|
5028
|
-
InputField,
|
|
5029
|
-
InputsField,
|
|
5030
5166
|
LEGACY_CACHED_HEADER,
|
|
5031
5167
|
LazyValue,
|
|
5032
|
-
LogCommentFullArgs,
|
|
5033
|
-
LogFeedbackFullArgs2 as LogFeedbackFullArgs,
|
|
5034
5168
|
Logger,
|
|
5035
5169
|
NOOP_SPAN,
|
|
5036
5170
|
NoopSpan,
|
|
5037
|
-
OtherExperimentLogFields,
|
|
5038
|
-
ParentExperimentIds,
|
|
5039
|
-
ParentProjectLogIds,
|
|
5040
5171
|
Prompt,
|
|
5041
5172
|
ReadonlyExperiment,
|
|
5042
5173
|
Reporter,
|
|
@@ -5045,15 +5176,18 @@ export {
|
|
|
5045
5176
|
_internalGetGlobalState,
|
|
5046
5177
|
_internalSetInitialState,
|
|
5047
5178
|
buildLocalSummary,
|
|
5179
|
+
createFinalValuePassThroughStream,
|
|
5048
5180
|
currentExperiment,
|
|
5049
5181
|
currentLogger,
|
|
5050
5182
|
currentSpan,
|
|
5183
|
+
devNullWritableStream,
|
|
5051
5184
|
flush,
|
|
5052
5185
|
getSpanParentObject,
|
|
5053
5186
|
init,
|
|
5054
5187
|
initDataset,
|
|
5055
5188
|
initExperiment,
|
|
5056
5189
|
initLogger,
|
|
5190
|
+
invoke,
|
|
5057
5191
|
loadPrompt,
|
|
5058
5192
|
log,
|
|
5059
5193
|
login,
|