@assistant-ui/react 0.5.57 → 0.5.59

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.mts CHANGED
@@ -615,6 +615,7 @@ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChil
615
615
 
616
616
  type TextContentPartProviderProps = {
617
617
  text: string;
618
+ isRunning?: boolean | undefined;
618
619
  };
619
620
  declare const TextContentPartProvider: FC<PropsWithChildren<TextContentPartProviderProps>>;
620
621
 
package/dist/index.d.ts CHANGED
@@ -615,6 +615,7 @@ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChil
615
615
 
616
616
  type TextContentPartProviderProps = {
617
617
  text: string;
618
+ isRunning?: boolean | undefined;
618
619
  };
619
620
  declare const TextContentPartProvider: FC<PropsWithChildren<TextContentPartProviderProps>>;
620
621
 
package/dist/index.js CHANGED
@@ -774,7 +774,10 @@ var useSmooth = (state, smooth = false) => {
774
774
  const {
775
775
  part: { text }
776
776
  } = state;
777
- const id = useMessage((m) => m.message.id);
777
+ const id = useMessage({
778
+ optional: true,
779
+ selector: (m) => m.message.id
780
+ });
778
781
  const idRef = _react.useRef.call(void 0, id);
779
782
  const [displayedText, setDisplayedText] = _react.useState.call(void 0, text);
780
783
  const smoothStatusStore = useSmoothStatusStore({ optional: true });
@@ -2348,16 +2351,37 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
2348
2351
 
2349
2352
 
2350
2353
 
2351
- var TextContentPartProvider = ({ children, text }) => {
2354
+ var COMPLETE_STATUS = {
2355
+ type: "complete"
2356
+ };
2357
+ var RUNNING_STATUS = {
2358
+ type: "running"
2359
+ };
2360
+ var TextContentPartProvider = ({ children, text, isRunning }) => {
2352
2361
  const [context] = _react.useState.call(void 0, () => {
2353
2362
  const useContentPart2 = _zustand.create.call(void 0, () => ({
2354
- status: { type: "complete" },
2363
+ status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
2355
2364
  part: { type: "text", text }
2356
2365
  }));
2357
2366
  return {
2358
2367
  useContentPart: useContentPart2
2359
2368
  };
2360
2369
  });
2370
+ _react.useEffect.call(void 0, () => {
2371
+ const state = context.useContentPart.getState();
2372
+ const textUpdated = state.part.text !== text;
2373
+ const targetTextPart = textUpdated ? { type: "text", text } : state.part;
2374
+ const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
2375
+ const statusUpdated = state.status !== targetStatus;
2376
+ if (!textUpdated && !statusUpdated) return;
2377
+ writableStore(context.useContentPart).setState(
2378
+ {
2379
+ part: targetTextPart,
2380
+ status: targetStatus
2381
+ },
2382
+ true
2383
+ );
2384
+ }, [context, isRunning, text]);
2361
2385
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
2362
2386
  };
2363
2387
 
@@ -3284,21 +3308,21 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
3284
3308
 
3285
3309
 
3286
3310
 
3287
- var COMPLETE_STATUS = {
3311
+ var COMPLETE_STATUS2 = {
3288
3312
  type: "complete"
3289
3313
  };
3290
3314
  var toContentPartStatus = (message, partIndex, part) => {
3291
- if (message.role !== "assistant") return COMPLETE_STATUS;
3315
+ if (message.role !== "assistant") return COMPLETE_STATUS2;
3292
3316
  const isLastPart = partIndex === Math.max(0, message.content.length - 1);
3293
3317
  if (part.type !== "tool-call") {
3294
3318
  if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
3295
3319
  throw new Error(
3296
3320
  "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
3297
3321
  );
3298
- return isLastPart ? message.status : COMPLETE_STATUS;
3322
+ return isLastPart ? message.status : COMPLETE_STATUS2;
3299
3323
  }
3300
3324
  if (!!part.result) {
3301
- return COMPLETE_STATUS;
3325
+ return COMPLETE_STATUS2;
3302
3326
  }
3303
3327
  return message.status;
3304
3328
  };