@tangle-network/agent-app 0.47.7 → 0.47.8

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.
@@ -1148,6 +1148,7 @@ function createProtectedRuntimeChatProducer(options) {
1148
1148
  }
1149
1149
  });
1150
1150
  let completed = false;
1151
+ let streamedText = "";
1151
1152
  for await (const event of streamAgentTurn(
1152
1153
  { kind: "executor", factory, profile },
1153
1154
  { prompt: options.prompt },
@@ -1157,6 +1158,7 @@ function createProtectedRuntimeChatProducer(options) {
1157
1158
  timeoutMs: Math.max(1, options.grant.deadlineAtMs - Date.now())
1158
1159
  }
1159
1160
  )) {
1161
+ if (event.type === "text_delta") streamedText += event.text;
1160
1162
  if (event.type === "text_delta" || event.type === "reasoning_delta") {
1161
1163
  await emit({ type: "message.part.updated", data: {
1162
1164
  part: { id: event.type, type: event.type === "text_delta" ? "text" : "reasoning" },
@@ -1165,6 +1167,17 @@ function createProtectedRuntimeChatProducer(options) {
1165
1167
  }
1166
1168
  if (event.type === "final") {
1167
1169
  if (event.status !== "completed") throw new Error(`Protected execution ${event.status}`);
1170
+ if (event.text !== void 0) {
1171
+ if (!event.text.startsWith(streamedText)) {
1172
+ throw new Error("Protected execution revised already streamed text");
1173
+ }
1174
+ const suffix = event.text.slice(streamedText.length);
1175
+ if (suffix) await emit({ type: "message.part.updated", data: {
1176
+ part: { id: "text_delta", type: "text" },
1177
+ delta: suffix
1178
+ } });
1179
+ streamedText = event.text;
1180
+ }
1168
1181
  completed = true;
1169
1182
  await emit({ type: "result", data: { finalText: event.text } });
1170
1183
  }