@truefoundry/assistant-ui-runtime 0.1.3-rc.2 → 0.1.3-rc.3

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.js CHANGED
@@ -2831,17 +2831,23 @@ function bindAbort(session, abortSignal) {
2831
2831
  return onAbort;
2832
2832
  }
2833
2833
  async function* streamTurnContent(session, foldState, options, abortSignal, groupRootBaseline, onTurnIdAvailable) {
2834
- const previousTurnId = options.previousTurnId === null ? void 0 : options.previousTurnId ?? "auto";
2834
+ const previousTurnId = options.previousTurnId === null ? null : options.previousTurnId ?? "auto";
2835
2835
  const turn = session.prepareTurn({
2836
2836
  input: buildTurnInput(options),
2837
- ...previousTurnId != null ? { previousTurnId } : {}
2837
+ ...previousTurnId !== void 0 ? { previousTurnId } : {}
2838
2838
  });
2839
2839
  const onAbort = bindAbort(session, abortSignal);
2840
2840
  if (abortSignal.aborted) {
2841
2841
  return;
2842
2842
  }
2843
+ let turnIdNotified = false;
2844
+ const notifyTurnIdIfAvailable = () => {
2845
+ if (!turnIdNotified && turn.id != null) {
2846
+ onTurnIdAvailable?.(turn.id);
2847
+ turnIdNotified = true;
2848
+ }
2849
+ };
2843
2850
  try {
2844
- let turnIdNotified = false;
2845
2851
  for await (const update of streamTurnEvents(
2846
2852
  turn.execute(
2847
2853
  { stream: true },
@@ -2853,16 +2859,12 @@ async function* streamTurnContent(session, foldState, options, abortSignal, grou
2853
2859
  foldState,
2854
2860
  groupRootBaseline
2855
2861
  )) {
2856
- if (!turnIdNotified && turn.id != null) {
2857
- onTurnIdAvailable?.(turn.id);
2858
- turnIdNotified = true;
2859
- }
2862
+ notifyTurnIdIfAvailable();
2860
2863
  yield update;
2861
2864
  }
2862
- if (!turnIdNotified && turn.id != null) {
2863
- onTurnIdAvailable?.(turn.id);
2864
- }
2865
+ notifyTurnIdIfAvailable();
2865
2866
  } catch (error) {
2867
+ notifyTurnIdIfAvailable();
2866
2868
  if (error instanceof Error && error.name === "AbortError") {
2867
2869
  return;
2868
2870
  }
@@ -3260,6 +3262,7 @@ function useTrueFoundryAgentMessages({
3260
3262
  const isContinuation = "inputs" in options || "resumeMcpAuth" in options && options.resumeMcpAuth === true;
3261
3263
  const continuationTurnId = snapshotRef.current.activeStream?.turnId;
3262
3264
  const turnId = isContinuation && continuationTurnId != null ? continuationTurnId : generateId();
3265
+ const isFirstTurnInSession = "userMessage" in options && options.previousTurnId === void 0 && snapshotRef.current.turns.length === 0 && snapshotRef.current.pendingUser == null && snapshotRef.current.activeStream == null;
3263
3266
  const turnIdRef = { current: turnId };
3264
3267
  if ("inputs" in options) {
3265
3268
  applyUserToolResponsesToFold(
@@ -3335,7 +3338,7 @@ function useTrueFoundryAgentMessages({
3335
3338
  snapshotRef.current.fold,
3336
3339
  {
3337
3340
  userMessage: options.userMessage,
3338
- ...options.previousTurnId !== void 0 ? { previousTurnId: options.previousTurnId } : {},
3341
+ ...options.previousTurnId !== void 0 ? { previousTurnId: options.previousTurnId } : isFirstTurnInSession ? { previousTurnId: null } : {},
3339
3342
  ...streamHeaders
3340
3343
  },
3341
3344
  signal,