Skip to content

Instantly share code, notes, and snippets.

@airhorns
Created January 22, 2025 15:14
Show Gist options
  • Save airhorns/865741798bce46ebf53192e7effb7a84 to your computer and use it in GitHub Desktop.
Save airhorns/865741798bce46ebf53192e7effb7a84 to your computer and use it in GitHub Desktop.
diff --git a/dist/traceable.cjs b/dist/traceable.cjs
index e28a67a3d8a5ad543aff6a565c9fd93824b6bc31..3981c280d572d671de3bd202504feb1f4cd0c7d6 100644
--- a/dist/traceable.cjs
+++ b/dist/traceable.cjs
@@ -377,20 +377,25 @@ function traceable(wrappedFunc, config) {
});
return tappedStream;
}
- async function* wrapAsyncIteratorForTracing(iterator, snapshot) {
+ async function* wrapAsyncGeneratorForTracing(iterable, snapshot) {
let finished = false;
const chunks = [];
try {
+ const iterator = iterable[Symbol.asyncIterator]();
while (true) {
const { value, done } = await (snapshot
? snapshot(() => iterator.next())
: iterator.next());
if (done) {
+ if (value != chunks[chunks.length - 1]) {
+ chunks.push(value);
+ }
finished = true;
break;
+ } else {
+ chunks.push(value);
+ yield value;
}
- chunks.push(value);
- yield value;
}
}
catch (e) {
@@ -403,15 +408,7 @@ function traceable(wrappedFunc, config) {
await currentRunTree?.end(handleRunOutputs(await handleChunks(chunks), processOutputsFn));
await handleEnd();
}
- }
- function wrapAsyncGeneratorForTracing(iterable, snapshot) {
- if ((0, asserts_js_1.isReadableStream)(iterable)) {
- return tapReadableStreamForTracing(iterable, snapshot);
- }
- const iterator = iterable[Symbol.asyncIterator]();
- const wrappedIterator = wrapAsyncIteratorForTracing(iterator, snapshot);
- iterable[Symbol.asyncIterator] = () => wrappedIterator;
- return iterable;
+ return chunks[chunks.length - 1];
}
async function handleEnd() {
const onEnd = config?.on_end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment