@assistant-ui/react 0.5.57 → 0.5.58

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -2348,16 +2348,37 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
2348
2348
 
2349
2349
 
2350
2350
 
2351
- var TextContentPartProvider = ({ children, text }) => {
2351
+ var COMPLETE_STATUS = {
2352
+ type: "complete"
2353
+ };
2354
+ var RUNNING_STATUS = {
2355
+ type: "running"
2356
+ };
2357
+ var TextContentPartProvider = ({ children, text, isRunning }) => {
2352
2358
  const [context] = _react.useState.call(void 0, () => {
2353
2359
  const useContentPart2 = _zustand.create.call(void 0, () => ({
2354
- status: { type: "complete" },
2360
+ status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
2355
2361
  part: { type: "text", text }
2356
2362
  }));
2357
2363
  return {
2358
2364
  useContentPart: useContentPart2
2359
2365
  };
2360
2366
  });
2367
+ _react.useEffect.call(void 0, () => {
2368
+ const state = context.useContentPart.getState();
2369
+ const textUpdated = state.part.text !== text;
2370
+ const targetTextPart = textUpdated ? { type: "text", text } : state.part;
2371
+ const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
2372
+ const statusUpdated = state.status !== targetStatus;
2373
+ if (!textUpdated && !statusUpdated) return;
2374
+ writableStore(context.useContentPart).setState(
2375
+ {
2376
+ part: targetTextPart,
2377
+ status: targetStatus
2378
+ },
2379
+ true
2380
+ );
2381
+ }, [context, isRunning, text]);
2361
2382
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
2362
2383
  };
2363
2384
 
@@ -3284,21 +3305,21 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
3284
3305
 
3285
3306
 
3286
3307
 
3287
- var COMPLETE_STATUS = {
3308
+ var COMPLETE_STATUS2 = {
3288
3309
  type: "complete"
3289
3310
  };
3290
3311
  var toContentPartStatus = (message, partIndex, part) => {
3291
- if (message.role !== "assistant") return COMPLETE_STATUS;
3312
+ if (message.role !== "assistant") return COMPLETE_STATUS2;
3292
3313
  const isLastPart = partIndex === Math.max(0, message.content.length - 1);
3293
3314
  if (part.type !== "tool-call") {
3294
3315
  if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
3295
3316
  throw new Error(
3296
3317
  "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
3297
3318
  );
3298
- return isLastPart ? message.status : COMPLETE_STATUS;
3319
+ return isLastPart ? message.status : COMPLETE_STATUS2;
3299
3320
  }
3300
3321
  if (!!part.result) {
3301
- return COMPLETE_STATUS;
3322
+ return COMPLETE_STATUS2;
3302
3323
  }
3303
3324
  return message.status;
3304
3325
  };