braintrust 3.29.0 → 3.30.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.js +1465 -881
- package/dev/dist/index.mjs +846 -262
- package/dist/apply-auto-instrumentation.js +217 -217
- package/dist/apply-auto-instrumentation.mjs +2 -2
- package/dist/auto-instrumentations/bundler/esbuild.cjs +13 -1
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/next.cjs +13 -1
- package/dist/auto-instrumentations/bundler/next.mjs +3 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +13 -1
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +13 -1
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +13 -1
- package/dist/auto-instrumentations/bundler/webpack.cjs +13 -1
- package/dist/auto-instrumentations/bundler/webpack.mjs +3 -3
- package/dist/auto-instrumentations/{chunk-DKTGDNA7.mjs → chunk-LW4HDHXT.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-OMCZ3MV2.mjs → chunk-OXINGIEZ.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-AOIYCVEL.mjs → chunk-U64OYU4Q.mjs} +13 -1
- package/dist/auto-instrumentations/hook.mjs +16 -4
- package/dist/auto-instrumentations/index.cjs +13 -1
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/browser.d.mts +133 -2
- package/dist/browser.d.ts +133 -2
- package/dist/browser.js +1143 -297
- package/dist/browser.mjs +1143 -297
- package/dist/{chunk-6Z5S7VOU.js → chunk-2XDW3UCG.js} +13 -1
- package/dist/{chunk-M6XPNJC4.mjs → chunk-BU6SM54N.mjs} +687 -115
- package/dist/{chunk-7FA6VP2S.mjs → chunk-N3JKQ3D3.mjs} +13 -1
- package/dist/{chunk-XLLGRXGR.js → chunk-TWCDSYJN.js} +1803 -1231
- package/dist/cli.js +819 -235
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +1143 -297
- package/dist/edge-light.mjs +1143 -297
- package/dist/index.d.mts +133 -2
- package/dist/index.d.ts +133 -2
- package/dist/index.js +902 -640
- package/dist/index.mjs +336 -74
- package/dist/instrumentation/index.d.mts +15 -0
- package/dist/instrumentation/index.d.ts +15 -0
- package/dist/instrumentation/index.js +857 -262
- package/dist/instrumentation/index.mjs +857 -262
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +1143 -297
- package/dist/workerd.mjs +1143 -297
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -143,7 +143,7 @@ import {
|
|
|
143
143
|
wrapMastraAgent,
|
|
144
144
|
wrapTraced,
|
|
145
145
|
zodToJsonSchema
|
|
146
|
-
} from "./chunk-
|
|
146
|
+
} from "./chunk-BU6SM54N.mjs";
|
|
147
147
|
import {
|
|
148
148
|
INSTRUMENTATION_NAMES,
|
|
149
149
|
__export,
|
|
@@ -177,7 +177,7 @@ import {
|
|
|
177
177
|
strandsAgentSDKChannels,
|
|
178
178
|
voyageAIChannels,
|
|
179
179
|
withSpanInstrumentationName
|
|
180
|
-
} from "./chunk-
|
|
180
|
+
} from "./chunk-N3JKQ3D3.mjs";
|
|
181
181
|
|
|
182
182
|
// src/exports.ts
|
|
183
183
|
var exports_exports = {};
|
|
@@ -256,6 +256,7 @@ __export(exports_exports, {
|
|
|
256
256
|
braintrustStreamChunkSchema: () => braintrustStreamChunkSchema,
|
|
257
257
|
buildLocalSummary: () => buildLocalSummary,
|
|
258
258
|
collectAnthropicSession: () => collectAnthropicSession,
|
|
259
|
+
completeOpenAIBatchTrace: () => completeOpenAIBatchTrace,
|
|
259
260
|
configureInstrumentation: () => configureInstrumentation,
|
|
260
261
|
constructLogs3OverflowRequest: () => constructLogs3OverflowRequest,
|
|
261
262
|
createFinalValuePassThroughStream: () => createFinalValuePassThroughStream,
|
|
@@ -294,6 +295,8 @@ __export(exports_exports, {
|
|
|
294
295
|
loginToState: () => loginToState,
|
|
295
296
|
logs3OverflowUploadSchema: () => logs3OverflowUploadSchema,
|
|
296
297
|
newId: () => newId,
|
|
298
|
+
openaiBatchesRetrieveTraced: () => openaiBatchesRetrieveTraced,
|
|
299
|
+
openaiFilesCreateTraced: () => openaiFilesCreateTraced,
|
|
297
300
|
parseCachedHeader: () => parseCachedHeader,
|
|
298
301
|
parseTemplateFormat: () => parseTemplateFormat,
|
|
299
302
|
permalink: () => permalink,
|
|
@@ -458,6 +461,260 @@ async function registerSandbox(options) {
|
|
|
458
461
|
};
|
|
459
462
|
}
|
|
460
463
|
|
|
464
|
+
// src/wrappers/openai-promise-utils.ts
|
|
465
|
+
function splitSpanInfo(allParams) {
|
|
466
|
+
const { span_info, ...params } = allParams;
|
|
467
|
+
return {
|
|
468
|
+
params,
|
|
469
|
+
span_info
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function createChannelContext(_channel, params, span_info) {
|
|
473
|
+
return {
|
|
474
|
+
arguments: (
|
|
475
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
476
|
+
[params]
|
|
477
|
+
),
|
|
478
|
+
span_info
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
async function tracePromiseWithResponse(channel, traceContext, apiPromise) {
|
|
482
|
+
let enhancedResponse;
|
|
483
|
+
const tracePromise = (
|
|
484
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
485
|
+
channel.tracePromise
|
|
486
|
+
);
|
|
487
|
+
const data = await tracePromise(async () => {
|
|
488
|
+
enhancedResponse = await apiPromise.withResponse();
|
|
489
|
+
traceContext.response = enhancedResponse.response;
|
|
490
|
+
return enhancedResponse.data;
|
|
491
|
+
}, traceContext);
|
|
492
|
+
if (!enhancedResponse) {
|
|
493
|
+
throw new Error("Expected withResponse() to provide response");
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
data,
|
|
497
|
+
response: enhancedResponse.response,
|
|
498
|
+
request_id: enhancedResponse.request_id
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
async function tracePromiseAsResponse(channel, traceContext, apiPromise) {
|
|
502
|
+
const tracePromise = (
|
|
503
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
504
|
+
channel.tracePromise
|
|
505
|
+
);
|
|
506
|
+
let response;
|
|
507
|
+
await tracePromise(async () => {
|
|
508
|
+
response = await apiPromise.asResponse();
|
|
509
|
+
traceContext.response = response;
|
|
510
|
+
return void 0;
|
|
511
|
+
}, traceContext);
|
|
512
|
+
if (!response) {
|
|
513
|
+
throw new Error("Expected asResponse() to provide response");
|
|
514
|
+
}
|
|
515
|
+
return response;
|
|
516
|
+
}
|
|
517
|
+
function createLazyAPIPromise(ensureExecuted, ensureResponse, getAPIPromise) {
|
|
518
|
+
let firstConsumption;
|
|
519
|
+
let enhancedResponsePromise;
|
|
520
|
+
let dataPromise;
|
|
521
|
+
let responsePromise;
|
|
522
|
+
const withResponse = () => {
|
|
523
|
+
firstConsumption ??= "data";
|
|
524
|
+
enhancedResponsePromise ??= firstConsumption === "data" ? ensureExecuted() : getAPIPromise().withResponse();
|
|
525
|
+
return enhancedResponsePromise;
|
|
526
|
+
};
|
|
527
|
+
const asResponse = () => {
|
|
528
|
+
firstConsumption ??= "response";
|
|
529
|
+
responsePromise ??= firstConsumption === "response" ? ensureResponse() : getAPIPromise().asResponse();
|
|
530
|
+
return responsePromise;
|
|
531
|
+
};
|
|
532
|
+
return new Proxy({}, {
|
|
533
|
+
get(target, prop, receiver) {
|
|
534
|
+
if (prop === "withResponse") {
|
|
535
|
+
return withResponse;
|
|
536
|
+
}
|
|
537
|
+
if (prop === "asResponse") {
|
|
538
|
+
return asResponse;
|
|
539
|
+
}
|
|
540
|
+
if (prop === "then" || prop === "catch" || prop === "finally" || prop in Promise.prototype) {
|
|
541
|
+
dataPromise ??= withResponse().then((result) => result.data);
|
|
542
|
+
const value = Reflect.get(dataPromise, prop, receiver);
|
|
543
|
+
return typeof value === "function" ? value.bind(dataPromise) : value;
|
|
544
|
+
}
|
|
545
|
+
return Reflect.get(target, prop, receiver);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/openai-batch.ts
|
|
551
|
+
function read(value, key) {
|
|
552
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
try {
|
|
556
|
+
return Reflect.get(value, key);
|
|
557
|
+
} catch {
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function isAsyncIterable(value) {
|
|
562
|
+
return typeof read(value, Symbol.asyncIterator) === "function";
|
|
563
|
+
}
|
|
564
|
+
function teeAsyncIterable(source) {
|
|
565
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
566
|
+
const stream = new ReadableStream({
|
|
567
|
+
async pull(controller) {
|
|
568
|
+
try {
|
|
569
|
+
const result = await iterator.next();
|
|
570
|
+
if (result.done) {
|
|
571
|
+
controller.close();
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (!(result.value instanceof Uint8Array)) {
|
|
575
|
+
throw new TypeError(
|
|
576
|
+
"OpenAI upload streams must yield Uint8Array chunks"
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
controller.enqueue(result.value);
|
|
580
|
+
} catch (error) {
|
|
581
|
+
controller.error(error);
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
async cancel(reason) {
|
|
585
|
+
await iterator.return?.(reason);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
const [uploadStream, trace] = stream.tee();
|
|
589
|
+
const upload = {
|
|
590
|
+
async *[Symbol.asyncIterator]() {
|
|
591
|
+
const reader = uploadStream.getReader();
|
|
592
|
+
try {
|
|
593
|
+
while (true) {
|
|
594
|
+
const result = await reader.read();
|
|
595
|
+
if (result.done) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
yield result.value;
|
|
599
|
+
}
|
|
600
|
+
} finally {
|
|
601
|
+
reader.releaseLock();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
const path = read(source, "path");
|
|
606
|
+
if (typeof path === "string") {
|
|
607
|
+
Object.defineProperty(upload, "path", { value: path });
|
|
608
|
+
}
|
|
609
|
+
return { upload, trace: new Response(trace) };
|
|
610
|
+
}
|
|
611
|
+
function teeUpload(upload) {
|
|
612
|
+
if (upload instanceof Blob) {
|
|
613
|
+
return { upload, trace: new Response(upload) };
|
|
614
|
+
}
|
|
615
|
+
if (upload instanceof Response) {
|
|
616
|
+
return { upload, trace: upload.clone() };
|
|
617
|
+
}
|
|
618
|
+
if (isAsyncIterable(upload)) {
|
|
619
|
+
return teeAsyncIterable(upload);
|
|
620
|
+
}
|
|
621
|
+
return void 0;
|
|
622
|
+
}
|
|
623
|
+
function openaiFilesCreateTraced(files) {
|
|
624
|
+
return (params, options) => {
|
|
625
|
+
const parent = getSpanParentObject();
|
|
626
|
+
const purpose = read(params, "purpose");
|
|
627
|
+
const file = read(params, "file");
|
|
628
|
+
if (purpose !== "batch") {
|
|
629
|
+
return files.create(params, options);
|
|
630
|
+
}
|
|
631
|
+
let branches;
|
|
632
|
+
try {
|
|
633
|
+
branches = teeUpload(file);
|
|
634
|
+
} catch {
|
|
635
|
+
return files.create(params, options);
|
|
636
|
+
}
|
|
637
|
+
if (!branches) {
|
|
638
|
+
return files.create(params, options);
|
|
639
|
+
}
|
|
640
|
+
const tracedParams = {
|
|
641
|
+
...Object(params),
|
|
642
|
+
file: branches.upload
|
|
643
|
+
};
|
|
644
|
+
const apiPromise = files.create(tracedParams, options);
|
|
645
|
+
let enhancedResponse;
|
|
646
|
+
const tracedResponse = openAIChannels.filesCreateTraced.invoke(
|
|
647
|
+
async () => {
|
|
648
|
+
enhancedResponse = await apiPromise.withResponse();
|
|
649
|
+
return enhancedResponse.data;
|
|
650
|
+
},
|
|
651
|
+
files,
|
|
652
|
+
[{ params, inputFileContent: branches.trace, parent }],
|
|
653
|
+
{}
|
|
654
|
+
).then((data) => {
|
|
655
|
+
if (!enhancedResponse) {
|
|
656
|
+
throw new Error(
|
|
657
|
+
"Expected OpenAI withResponse() to provide a response"
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
return { ...enhancedResponse, data };
|
|
661
|
+
});
|
|
662
|
+
return createLazyAPIPromise(
|
|
663
|
+
() => tracedResponse,
|
|
664
|
+
() => tracedResponse.then(({ response }) => response),
|
|
665
|
+
() => apiPromise
|
|
666
|
+
);
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function openaiBatchesRetrieveTraced(batches) {
|
|
670
|
+
return (batchId, options) => {
|
|
671
|
+
const apiPromise = batches.retrieve(batchId, options);
|
|
672
|
+
let enhancedResponse;
|
|
673
|
+
const tracedResponse = openAIChannels.batchesRetrieveTraced.invoke(
|
|
674
|
+
async () => {
|
|
675
|
+
enhancedResponse = await apiPromise.withResponse();
|
|
676
|
+
return enhancedResponse.data;
|
|
677
|
+
},
|
|
678
|
+
batches,
|
|
679
|
+
[{ batchId }],
|
|
680
|
+
{}
|
|
681
|
+
).then((data) => {
|
|
682
|
+
if (!enhancedResponse) {
|
|
683
|
+
throw new Error(
|
|
684
|
+
"Expected OpenAI withResponse() to provide a response"
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
return { ...enhancedResponse, data };
|
|
688
|
+
});
|
|
689
|
+
return createLazyAPIPromise(
|
|
690
|
+
() => tracedResponse,
|
|
691
|
+
() => tracedResponse.then(({ response }) => response),
|
|
692
|
+
() => apiPromise
|
|
693
|
+
);
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
async function completeOpenAIBatchTrace(args) {
|
|
697
|
+
const inputFileContent = Promise.resolve(args.inputFileContent);
|
|
698
|
+
const outputFileContent = args.outputFileContent === void 0 ? void 0 : Promise.resolve(args.outputFileContent);
|
|
699
|
+
const errorFileContent = args.errorFileContent === void 0 ? void 0 : Promise.resolve(args.errorFileContent);
|
|
700
|
+
void inputFileContent.catch(() => void 0);
|
|
701
|
+
void outputFileContent?.catch(() => void 0);
|
|
702
|
+
void errorFileContent?.catch(() => void 0);
|
|
703
|
+
await openAIChannels.batchesCompleteTrace.invoke(
|
|
704
|
+
async () => void 0,
|
|
705
|
+
void 0,
|
|
706
|
+
[
|
|
707
|
+
{
|
|
708
|
+
...args,
|
|
709
|
+
inputFileContent,
|
|
710
|
+
outputFileContent,
|
|
711
|
+
errorFileContent
|
|
712
|
+
}
|
|
713
|
+
],
|
|
714
|
+
{}
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
461
718
|
// src/functions/invoke.ts
|
|
462
719
|
async function invoke(args) {
|
|
463
720
|
const {
|
|
@@ -560,58 +817,6 @@ function initFunction({
|
|
|
560
817
|
return f;
|
|
561
818
|
}
|
|
562
819
|
|
|
563
|
-
// src/wrappers/openai-promise-utils.ts
|
|
564
|
-
function splitSpanInfo(allParams) {
|
|
565
|
-
const { span_info, ...params } = allParams;
|
|
566
|
-
return {
|
|
567
|
-
params,
|
|
568
|
-
span_info
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
function createChannelContext(_channel, params, span_info) {
|
|
572
|
-
return {
|
|
573
|
-
arguments: (
|
|
574
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
575
|
-
[params]
|
|
576
|
-
),
|
|
577
|
-
span_info
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
async function tracePromiseWithResponse(channel, traceContext, apiPromise) {
|
|
581
|
-
let enhancedResponse;
|
|
582
|
-
const tracePromise = (
|
|
583
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
584
|
-
channel.tracePromise
|
|
585
|
-
);
|
|
586
|
-
const data = await tracePromise(async () => {
|
|
587
|
-
enhancedResponse = await apiPromise.withResponse();
|
|
588
|
-
traceContext.response = enhancedResponse.response;
|
|
589
|
-
return enhancedResponse.data;
|
|
590
|
-
}, traceContext);
|
|
591
|
-
if (!enhancedResponse) {
|
|
592
|
-
throw new Error("Expected withResponse() to provide response");
|
|
593
|
-
}
|
|
594
|
-
return { data, response: enhancedResponse.response };
|
|
595
|
-
}
|
|
596
|
-
function createLazyAPIPromise(ensureExecuted) {
|
|
597
|
-
let dataPromise = null;
|
|
598
|
-
return new Proxy({}, {
|
|
599
|
-
get(target, prop, receiver) {
|
|
600
|
-
if (prop === "withResponse") {
|
|
601
|
-
return () => ensureExecuted();
|
|
602
|
-
}
|
|
603
|
-
if (prop === "then" || prop === "catch" || prop === "finally" || prop in Promise.prototype) {
|
|
604
|
-
if (!dataPromise) {
|
|
605
|
-
dataPromise = ensureExecuted().then((result) => result.data);
|
|
606
|
-
}
|
|
607
|
-
const value = Reflect.get(dataPromise, prop, receiver);
|
|
608
|
-
return typeof value === "function" ? value.bind(dataPromise) : value;
|
|
609
|
-
}
|
|
610
|
-
return Reflect.get(target, prop, receiver);
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
|
|
615
820
|
// src/wrappers/oai_responses.ts
|
|
616
821
|
function responsesProxy(openai) {
|
|
617
822
|
if (!openai.responses) {
|
|
@@ -648,17 +853,33 @@ function wrapResponsesAsync(target, channel) {
|
|
|
648
853
|
return (allParams, options) => {
|
|
649
854
|
const { span_info, params } = splitSpanInfo(allParams);
|
|
650
855
|
let executionPromise = null;
|
|
856
|
+
let apiPromise = null;
|
|
857
|
+
const getAPIPromise = () => {
|
|
858
|
+
apiPromise ??= target(params, options);
|
|
859
|
+
return apiPromise;
|
|
860
|
+
};
|
|
651
861
|
const ensureExecuted = () => {
|
|
652
862
|
if (!executionPromise) {
|
|
653
863
|
executionPromise = (async () => {
|
|
654
864
|
const traceContext = createChannelContext(channel, params, span_info);
|
|
655
|
-
|
|
656
|
-
|
|
865
|
+
return tracePromiseWithResponse(
|
|
866
|
+
channel,
|
|
867
|
+
traceContext,
|
|
868
|
+
getAPIPromise()
|
|
869
|
+
);
|
|
657
870
|
})();
|
|
658
871
|
}
|
|
659
872
|
return executionPromise;
|
|
660
873
|
};
|
|
661
|
-
return createLazyAPIPromise(
|
|
874
|
+
return createLazyAPIPromise(
|
|
875
|
+
ensureExecuted,
|
|
876
|
+
() => tracePromiseAsResponse(
|
|
877
|
+
channel,
|
|
878
|
+
createChannelContext(channel, params, span_info),
|
|
879
|
+
getAPIPromise()
|
|
880
|
+
),
|
|
881
|
+
getAPIPromise
|
|
882
|
+
);
|
|
662
883
|
};
|
|
663
884
|
}
|
|
664
885
|
function wrapResponsesSyncStream(target, channel) {
|
|
@@ -804,6 +1025,11 @@ function wrapChatCompletion(completion) {
|
|
|
804
1025
|
allParams
|
|
805
1026
|
);
|
|
806
1027
|
let executionPromise = null;
|
|
1028
|
+
let apiPromise = null;
|
|
1029
|
+
const getAPIPromise = () => {
|
|
1030
|
+
apiPromise ??= completion(params, options);
|
|
1031
|
+
return apiPromise;
|
|
1032
|
+
};
|
|
807
1033
|
const ensureExecuted = () => {
|
|
808
1034
|
if (!executionPromise) {
|
|
809
1035
|
executionPromise = (async () => {
|
|
@@ -813,32 +1039,44 @@ function wrapChatCompletion(completion) {
|
|
|
813
1039
|
span_info
|
|
814
1040
|
);
|
|
815
1041
|
if (params.stream) {
|
|
816
|
-
const completionPromise =
|
|
817
|
-
|
|
818
|
-
|
|
1042
|
+
const completionPromise = (
|
|
1043
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1044
|
+
getAPIPromise()
|
|
819
1045
|
);
|
|
820
|
-
const { data: data2, response: response2 } = await tracePromiseWithResponse(
|
|
1046
|
+
const { data: data2, response: response2, request_id: request_id2 } = await tracePromiseWithResponse(
|
|
821
1047
|
openAIChannels.chatCompletionsCreate,
|
|
822
1048
|
traceContext,
|
|
823
1049
|
completionPromise
|
|
824
1050
|
);
|
|
825
|
-
return { data: data2, response: response2 };
|
|
1051
|
+
return { data: data2, response: response2, request_id: request_id2 };
|
|
826
1052
|
}
|
|
827
|
-
const completionResponse =
|
|
828
|
-
|
|
829
|
-
|
|
1053
|
+
const completionResponse = (
|
|
1054
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1055
|
+
getAPIPromise()
|
|
830
1056
|
);
|
|
831
|
-
const { data, response } = await tracePromiseWithResponse(
|
|
1057
|
+
const { data, response, request_id } = await tracePromiseWithResponse(
|
|
832
1058
|
openAIChannels.chatCompletionsCreate,
|
|
833
1059
|
traceContext,
|
|
834
1060
|
completionResponse
|
|
835
1061
|
);
|
|
836
|
-
return { data, response };
|
|
1062
|
+
return { data, response, request_id };
|
|
837
1063
|
})();
|
|
838
1064
|
}
|
|
839
1065
|
return executionPromise;
|
|
840
1066
|
};
|
|
841
|
-
return createLazyAPIPromise(
|
|
1067
|
+
return createLazyAPIPromise(
|
|
1068
|
+
ensureExecuted,
|
|
1069
|
+
() => tracePromiseAsResponse(
|
|
1070
|
+
openAIChannels.chatCompletionsCreate,
|
|
1071
|
+
createChannelContext(
|
|
1072
|
+
openAIChannels.chatCompletionsCreate,
|
|
1073
|
+
params,
|
|
1074
|
+
span_info
|
|
1075
|
+
),
|
|
1076
|
+
getAPIPromise()
|
|
1077
|
+
),
|
|
1078
|
+
getAPIPromise
|
|
1079
|
+
);
|
|
842
1080
|
};
|
|
843
1081
|
}
|
|
844
1082
|
function createEndpointProxy(target, wrapperFn) {
|
|
@@ -856,6 +1094,11 @@ function wrapApiCreateWithChannel(create, channel) {
|
|
|
856
1094
|
return (allParams, options) => {
|
|
857
1095
|
const { span_info, params } = splitSpanInfo(allParams);
|
|
858
1096
|
let executionPromise = null;
|
|
1097
|
+
let apiPromise = null;
|
|
1098
|
+
const getAPIPromise = () => {
|
|
1099
|
+
apiPromise ??= create(params, options);
|
|
1100
|
+
return apiPromise;
|
|
1101
|
+
};
|
|
859
1102
|
const ensureExecuted = () => {
|
|
860
1103
|
if (!executionPromise) {
|
|
861
1104
|
executionPromise = (async () => {
|
|
@@ -863,13 +1106,21 @@ function wrapApiCreateWithChannel(create, channel) {
|
|
|
863
1106
|
return tracePromiseWithResponse(
|
|
864
1107
|
channel,
|
|
865
1108
|
traceContext,
|
|
866
|
-
|
|
1109
|
+
getAPIPromise()
|
|
867
1110
|
);
|
|
868
1111
|
})();
|
|
869
1112
|
}
|
|
870
1113
|
return executionPromise;
|
|
871
1114
|
};
|
|
872
|
-
return createLazyAPIPromise(
|
|
1115
|
+
return createLazyAPIPromise(
|
|
1116
|
+
ensureExecuted,
|
|
1117
|
+
() => tracePromiseAsResponse(
|
|
1118
|
+
channel,
|
|
1119
|
+
createChannelContext(channel, params, span_info),
|
|
1120
|
+
getAPIPromise()
|
|
1121
|
+
),
|
|
1122
|
+
getAPIPromise
|
|
1123
|
+
);
|
|
873
1124
|
};
|
|
874
1125
|
}
|
|
875
1126
|
var wrapEmbeddings = (create) => wrapApiCreateWithChannel(create, openAIChannels.embeddingsCreate);
|
|
@@ -3564,7 +3815,15 @@ var MAX_EVE_PROVIDER_CACHE_ENTRIES = 1e4;
|
|
|
3564
3815
|
function createEveInstrumentationProvider(options = {}) {
|
|
3565
3816
|
const bridge = new EveProviderBridge(options.metadata);
|
|
3566
3817
|
return {
|
|
3818
|
+
// Eve versions before tracePolicy use capture to decide whether provider
|
|
3819
|
+
// events include content. Newer versions prefer tracePolicy when both are
|
|
3820
|
+
// present, so keep the deprecated field for backwards compatibility.
|
|
3567
3821
|
capture: "content",
|
|
3822
|
+
tracePolicy: () => ({
|
|
3823
|
+
emit: true,
|
|
3824
|
+
recordInputs: true,
|
|
3825
|
+
recordOutputs: true
|
|
3826
|
+
}),
|
|
3568
3827
|
events: {
|
|
3569
3828
|
"action.completed": (event, context) => bridge.handleActionTerminal(event, context),
|
|
3570
3829
|
"action.failed": (event, context) => bridge.handleActionTerminal(event, context),
|
|
@@ -7732,7 +7991,7 @@ function isAsync(fn) {
|
|
|
7732
7991
|
function isAsyncGenerator(fn) {
|
|
7733
7992
|
return fn[Symbol.toStringTag] === "AsyncGenerator";
|
|
7734
7993
|
}
|
|
7735
|
-
function
|
|
7994
|
+
function isAsyncIterable2(obj) {
|
|
7736
7995
|
return typeof obj[Symbol.asyncIterator] === "function";
|
|
7737
7996
|
}
|
|
7738
7997
|
function wrapAsync(asyncFn) {
|
|
@@ -7904,7 +8163,7 @@ var eachOfLimit$2 = (limit) => {
|
|
|
7904
8163
|
if (isAsyncGenerator(obj)) {
|
|
7905
8164
|
return asyncEachOfLimit(obj, limit, iteratee, callback);
|
|
7906
8165
|
}
|
|
7907
|
-
if (
|
|
8166
|
+
if (isAsyncIterable2(obj)) {
|
|
7908
8167
|
return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback);
|
|
7909
8168
|
}
|
|
7910
8169
|
var nextElem = createIterator(obj);
|
|
@@ -9259,7 +9518,7 @@ function callEvaluatorData(data) {
|
|
|
9259
9518
|
baseExperiment
|
|
9260
9519
|
};
|
|
9261
9520
|
}
|
|
9262
|
-
function
|
|
9521
|
+
function isAsyncIterable3(value) {
|
|
9263
9522
|
return typeof value === "object" && value !== null && Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
|
|
9264
9523
|
}
|
|
9265
9524
|
function isIterable(value) {
|
|
@@ -9294,7 +9553,7 @@ async function _internalResolveEvaluatorData(evaluator, experiment) {
|
|
|
9294
9553
|
}).asDataset();
|
|
9295
9554
|
}
|
|
9296
9555
|
const resolvedDataResult = dataResult instanceof Promise ? await dataResult : dataResult;
|
|
9297
|
-
if (
|
|
9556
|
+
if (isAsyncIterable3(resolvedDataResult)) {
|
|
9298
9557
|
return resolvedDataResult;
|
|
9299
9558
|
}
|
|
9300
9559
|
if (Array.isArray(resolvedDataResult) || isIterable(resolvedDataResult)) {
|
|
@@ -12342,6 +12601,7 @@ export {
|
|
|
12342
12601
|
braintrustStreamChunkSchema,
|
|
12343
12602
|
buildLocalSummary,
|
|
12344
12603
|
collectAnthropicSession,
|
|
12604
|
+
completeOpenAIBatchTrace,
|
|
12345
12605
|
configureInstrumentation,
|
|
12346
12606
|
constructLogs3OverflowRequest,
|
|
12347
12607
|
createFinalValuePassThroughStream,
|
|
@@ -12381,6 +12641,8 @@ export {
|
|
|
12381
12641
|
loginToState,
|
|
12382
12642
|
logs3OverflowUploadSchema,
|
|
12383
12643
|
newId,
|
|
12644
|
+
openaiBatchesRetrieveTraced,
|
|
12645
|
+
openaiFilesCreateTraced,
|
|
12384
12646
|
parseCachedHeader,
|
|
12385
12647
|
parseTemplateFormat,
|
|
12386
12648
|
permalink,
|
|
@@ -10177,8 +10177,23 @@ type EveProviderStepAttemptTerminalEvent = {
|
|
|
10177
10177
|
readonly type: "step.attempt.completed" | "step.attempt.failed";
|
|
10178
10178
|
};
|
|
10179
10179
|
type EveProviderHandler<TEvent> = (event: TEvent, context: EveProviderContext) => void | PromiseLike<void>;
|
|
10180
|
+
type EveChannelAudience = "private" | "public" | "unknown";
|
|
10181
|
+
interface EveTraceCaptureContext {
|
|
10182
|
+
readonly agentName?: string;
|
|
10183
|
+
readonly audience: EveChannelAudience;
|
|
10184
|
+
readonly channelType?: string;
|
|
10185
|
+
}
|
|
10186
|
+
type EveTracePolicyDecision = {
|
|
10187
|
+
readonly emit: false;
|
|
10188
|
+
} | {
|
|
10189
|
+
readonly emit: true;
|
|
10190
|
+
readonly recordInputs: boolean;
|
|
10191
|
+
readonly recordOutputs: boolean;
|
|
10192
|
+
};
|
|
10193
|
+
type EveTraceCapturePolicy = (trace: EveTraceCaptureContext) => EveTracePolicyDecision | boolean;
|
|
10180
10194
|
interface EveProviderDefinition {
|
|
10181
10195
|
readonly capture?: "content" | "metadata";
|
|
10196
|
+
readonly tracePolicy?: EveTraceCapturePolicy;
|
|
10182
10197
|
readonly events?: {
|
|
10183
10198
|
readonly "action.completed"?: EveProviderHandler<EveProviderActionTerminalEvent>;
|
|
10184
10199
|
readonly "action.failed"?: EveProviderHandler<EveProviderActionTerminalEvent>;
|
|
@@ -10177,8 +10177,23 @@ type EveProviderStepAttemptTerminalEvent = {
|
|
|
10177
10177
|
readonly type: "step.attempt.completed" | "step.attempt.failed";
|
|
10178
10178
|
};
|
|
10179
10179
|
type EveProviderHandler<TEvent> = (event: TEvent, context: EveProviderContext) => void | PromiseLike<void>;
|
|
10180
|
+
type EveChannelAudience = "private" | "public" | "unknown";
|
|
10181
|
+
interface EveTraceCaptureContext {
|
|
10182
|
+
readonly agentName?: string;
|
|
10183
|
+
readonly audience: EveChannelAudience;
|
|
10184
|
+
readonly channelType?: string;
|
|
10185
|
+
}
|
|
10186
|
+
type EveTracePolicyDecision = {
|
|
10187
|
+
readonly emit: false;
|
|
10188
|
+
} | {
|
|
10189
|
+
readonly emit: true;
|
|
10190
|
+
readonly recordInputs: boolean;
|
|
10191
|
+
readonly recordOutputs: boolean;
|
|
10192
|
+
};
|
|
10193
|
+
type EveTraceCapturePolicy = (trace: EveTraceCaptureContext) => EveTracePolicyDecision | boolean;
|
|
10180
10194
|
interface EveProviderDefinition {
|
|
10181
10195
|
readonly capture?: "content" | "metadata";
|
|
10196
|
+
readonly tracePolicy?: EveTraceCapturePolicy;
|
|
10182
10197
|
readonly events?: {
|
|
10183
10198
|
readonly "action.completed"?: EveProviderHandler<EveProviderActionTerminalEvent>;
|
|
10184
10199
|
readonly "action.failed"?: EveProviderHandler<EveProviderActionTerminalEvent>;
|