@dudousxd/nestjs-agent-react 0.29.1 → 0.29.2

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/dist/index.d.cts CHANGED
@@ -120,6 +120,12 @@ interface AgentChatTransportOptions {
120
120
  * and surfaces its 404". Wire this to the thread's `activeRunId`.
121
121
  */
122
122
  getResumeRunId?: () => string | undefined;
123
+ /**
124
+ * Fires once `reconnectToStream` has attached to a run's stream, with that run's id. A resumed
125
+ * stream replays frames but opens with no `meta` frame, so this is the only place a caller learns
126
+ * which run it is now reading — what a Stop pressed after a reload has to cancel.
127
+ */
128
+ onResumeAttached?: (runId: string) => void;
123
129
  /** Fires whenever a stream emits its `meta` frame. */
124
130
  onMeta?: (meta: AgentStreamMeta) => void;
125
131
  /**
package/dist/index.d.ts CHANGED
@@ -120,6 +120,12 @@ interface AgentChatTransportOptions {
120
120
  * and surfaces its 404". Wire this to the thread's `activeRunId`.
121
121
  */
122
122
  getResumeRunId?: () => string | undefined;
123
+ /**
124
+ * Fires once `reconnectToStream` has attached to a run's stream, with that run's id. A resumed
125
+ * stream replays frames but opens with no `meta` frame, so this is the only place a caller learns
126
+ * which run it is now reading — what a Stop pressed after a reload has to cancel.
127
+ */
128
+ onResumeAttached?: (runId: string) => void;
123
129
  /** Fires whenever a stream emits its `meta` frame. */
124
130
  onMeta?: (meta: AgentStreamMeta) => void;
125
131
  /**
package/dist/index.js CHANGED
@@ -569,6 +569,7 @@ var AgentChatTransport = class {
569
569
  return null;
570
570
  }
571
571
  this.captureHeaderMeta(response);
572
+ this.options.onResumeAttached?.(response.runId ?? runId);
572
573
  return this.toChunkStream(response, {
573
574
  runId,
574
575
  ...headers !== void 0 ? { headers } : {}
@@ -4714,6 +4715,14 @@ function storedMessageToUiMessage(message) {
4714
4715
  approved: false,
4715
4716
  ...refusalReason(result) !== void 0 ? { reason: refusalReason(result) } : {}
4716
4717
  }
4718
+ } : typeof result.error === "string" && result.error !== "" ? {
4719
+ // A call that FAILED — the tool threw, its input was refused, or its turn died
4720
+ // before it was settled — is not an available output either. The live stream says
4721
+ // so with `tool-output-error`; a reloaded thread has to say the same, or the card of
4722
+ // an action that never ran comes back reading as one that completed.
4723
+ state: "output-error",
4724
+ input: call.input,
4725
+ errorText: result.error
4717
4726
  } : { state: "output-available", input: call.input, output: result.output } : { state: "input-available", input: call.input }
4718
4727
  });
4719
4728
  parts.push(...pushedByCall.get(call.id) ?? []);
@@ -4951,6 +4960,12 @@ function useAgentChat(options = {}) {
4951
4960
  return { ...turnBody(), ...regenerate2 ? { regenerate: true } : {} };
4952
4961
  },
4953
4962
  getResumeRunId: () => latest.current.resumeRunId ?? autoResumeRunIdRef.current,
4963
+ // A stream attached to after a reload carries no `meta` frame: without this the chat would
4964
+ // be reading a run it cannot name, and `cancel()` would stop nothing.
4965
+ onResumeAttached: (resumedRunId) => {
4966
+ settlingRunIdRef.current = resumedRunId;
4967
+ setRunId(resumedRunId);
4968
+ },
4954
4969
  onMeta,
4955
4970
  onAttemptStart: () => {
4956
4971
  settlingRunIdRef.current = void 0;
@@ -5420,7 +5435,14 @@ function useAgentChat(options = {}) {
5420
5435
  } catch {
5421
5436
  }
5422
5437
  }
5423
- }, [client]);
5438
+ const threadId = currentThreadId();
5439
+ if (threadId !== void 0 && queueStateRef.current.items.length > 0 && typeof client.getQueue === "function") {
5440
+ try {
5441
+ applyQueue(await client.getQueue(threadId));
5442
+ } catch {
5443
+ }
5444
+ }
5445
+ }, [client, currentThreadId, applyQueue]);
5424
5446
  const approve = useCallback11(
5425
5447
  async ({ toolCallId, remember, via }) => {
5426
5448
  await requireBackendMethod(