@tangle-network/agent-app 4.0.27 → 4.0.29

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.
@@ -30,7 +30,7 @@ import {
30
30
  sandboxRunFailureDetail,
31
31
  streamSandboxPrompt,
32
32
  turnStorageBindings
33
- } from "./chunk-U4HKZV5U.js";
33
+ } from "./chunk-7TZX2KSH.js";
34
34
  import {
35
35
  redactErrorMessage
36
36
  } from "./chunk-MH74DY2I.js";
@@ -2102,6 +2102,28 @@ function startTurnPrefetch(prefetch, input) {
2102
2102
  // src/chat-routes/turn-execution.ts
2103
2103
  import { deriveExecutionId as deriveExecutionId2, handleChatTurn } from "@tangle-network/agent-runtime/durable";
2104
2104
 
2105
+ // src/chat-routes/producer-trace.ts
2106
+ function traceProducerStream(stream, trace) {
2107
+ return {
2108
+ [Symbol.asyncIterator]() {
2109
+ const inner = stream[Symbol.asyncIterator]();
2110
+ let first = true;
2111
+ return {
2112
+ async next(...args) {
2113
+ const asked = Date.now();
2114
+ const result = await inner.next(...args);
2115
+ if (first) trace.record("produce.setup", "other", asked, Date.now());
2116
+ else if (result.done) trace.record("produce.settle", "other", asked, Date.now());
2117
+ first = false;
2118
+ return result;
2119
+ },
2120
+ ...inner.return ? { return: inner.return.bind(inner) } : {},
2121
+ ...inner.throw ? { throw: inner.throw.bind(inner) } : {}
2122
+ };
2123
+ }
2124
+ };
2125
+ }
2126
+
2105
2127
  // src/chat-routes/native-turn-timing.ts
2106
2128
  function createNativeTimingTransfer(read, onError) {
2107
2129
  let persist;
@@ -2863,7 +2885,7 @@ function createTurnEngine(identity, ctx, log, state, dispatched, produceArgs, tr
2863
2885
  });
2864
2886
  }
2865
2887
  state.producer = await started;
2866
- yield* state.producer.stream;
2888
+ yield* traceProducerStream(state.producer.stream, trace);
2867
2889
  };
2868
2890
  let source = redact ? redactEvents(producerStream(), redact) : producerStream();
2869
2891
  if (options.cancel && state.cancellationAbort && !state.closeCancellation) {
@@ -3723,4 +3745,4 @@ export {
3723
3745
  createChatTurnRoutes,
3724
3746
  streamChatRouteAsSandboxEvents
3725
3747
  };
3726
- //# sourceMappingURL=chunk-7ZNW7NOX.js.map
3748
+ //# sourceMappingURL=chunk-WXK2AKRZ.js.map