@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.mjs CHANGED
@@ -2345,19 +2345,40 @@ var AssistantRuntimeProviderImpl = ({ children, runtime }) => {
2345
2345
  var AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
2346
2346
 
2347
2347
  // src/context/providers/TextContentPartProvider.tsx
2348
- import { useState as useState9 } from "react";
2348
+ import { useEffect as useEffect5, useState as useState9 } from "react";
2349
2349
  import { create as create11 } from "zustand";
2350
2350
  import { jsx as jsx9 } from "react/jsx-runtime";
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] = useState9(() => {
2353
2359
  const useContentPart2 = create11(() => ({
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
+ useEffect5(() => {
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__ */ jsx9(ContentPartContext.Provider, { value: context, children });
2362
2383
  };
2363
2384
 
@@ -2452,11 +2473,11 @@ var useSwitchToNewThread = () => {
2452
2473
  };
2453
2474
 
2454
2475
  // src/model-config/useAssistantTool.tsx
2455
- import { useEffect as useEffect5 } from "react";
2476
+ import { useEffect as useEffect6 } from "react";
2456
2477
  var useAssistantTool = (tool) => {
2457
2478
  const assistantActionsStore = useAssistantActionsStore();
2458
2479
  const toolUIsStore = useToolUIsStore();
2459
- useEffect5(() => {
2480
+ useEffect6(() => {
2460
2481
  const { toolName, render, ...rest } = tool;
2461
2482
  const config = {
2462
2483
  tools: {
@@ -2485,10 +2506,10 @@ var makeAssistantTool = (tool) => {
2485
2506
  };
2486
2507
 
2487
2508
  // src/model-config/useAssistantToolUI.tsx
2488
- import { useEffect as useEffect6 } from "react";
2509
+ import { useEffect as useEffect7 } from "react";
2489
2510
  var useAssistantToolUI = (tool) => {
2490
2511
  const toolUIsStore = useToolUIsStore();
2491
- useEffect6(() => {
2512
+ useEffect7(() => {
2492
2513
  if (!tool) return;
2493
2514
  const { toolName, render } = tool;
2494
2515
  return toolUIsStore.getState().setToolUI(toolName, render);
@@ -2506,10 +2527,10 @@ var makeAssistantToolUI = (tool) => {
2506
2527
  };
2507
2528
 
2508
2529
  // src/model-config/useAssistantInstructions.tsx
2509
- import { useEffect as useEffect7 } from "react";
2530
+ import { useEffect as useEffect8 } from "react";
2510
2531
  var useAssistantInstructions = (instruction) => {
2511
2532
  const actionsStore = useAssistantActionsStore();
2512
- useEffect7(() => {
2533
+ useEffect8(() => {
2513
2534
  const config = {
2514
2535
  system: instruction
2515
2536
  };
@@ -3048,11 +3069,11 @@ import { composeEventHandlers as composeEventHandlers3 } from "@radix-ui/primiti
3048
3069
 
3049
3070
  // src/utils/hooks/useOnComposerFocus.tsx
3050
3071
  import { useCallbackRef as useCallbackRef2 } from "@radix-ui/react-use-callback-ref";
3051
- import { useEffect as useEffect8 } from "react";
3072
+ import { useEffect as useEffect9 } from "react";
3052
3073
  var useOnComposerFocus = (callback) => {
3053
3074
  const callbackRef = useCallbackRef2(callback);
3054
3075
  const threadComposerStore = useThreadComposerStore();
3055
- useEffect8(() => {
3076
+ useEffect9(() => {
3056
3077
  return threadComposerStore.getState().onFocus(() => {
3057
3078
  callbackRef();
3058
3079
  });
@@ -3281,24 +3302,24 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
3281
3302
  import { memo as memo2 } from "react";
3282
3303
 
3283
3304
  // src/context/providers/ContentPartProvider.tsx
3284
- import { useEffect as useEffect9, useState as useState11 } from "react";
3305
+ import { useEffect as useEffect10, useState as useState11 } from "react";
3285
3306
  import { create as create12 } from "zustand";
3286
3307
  import { jsx as jsx20 } from "react/jsx-runtime";
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
  };
@@ -3328,7 +3349,7 @@ var useContentPartContext2 = (partIndex) => {
3328
3349
  );
3329
3350
  return { useContentPart: useContentPart2 };
3330
3351
  });
3331
- useEffect9(() => {
3352
+ useEffect10(() => {
3332
3353
  const syncContentPart = (message) => {
3333
3354
  const newState = getContentPartState(
3334
3355
  message,
@@ -3535,7 +3556,7 @@ var {
3535
3556
  } = createContextStoreHook(useMessageAttachmentContext, "useAttachment");
3536
3557
 
3537
3558
  // src/context/providers/MessageAttachmentProvider.tsx
3538
- import { useEffect as useEffect10, useState as useState12 } from "react";
3559
+ import { useEffect as useEffect11, useState as useState12 } from "react";
3539
3560
  import { create as create13 } from "zustand";
3540
3561
  import { jsx as jsx24 } from "react/jsx-runtime";
3541
3562
  var getAttachment = ({ message }, useAttachment2, partIndex) => {
@@ -3557,7 +3578,7 @@ var useMessageAttachmentContext2 = (partIndex) => {
3557
3578
  return { type: "message", useAttachment: useAttachment2 };
3558
3579
  }
3559
3580
  );
3560
- useEffect10(() => {
3581
+ useEffect11(() => {
3561
3582
  const syncAttachment = (messageState) => {
3562
3583
  const newState = getAttachment(
3563
3584
  messageState,
@@ -3677,7 +3698,7 @@ import { Slot } from "@radix-ui/react-slot";
3677
3698
  import {
3678
3699
  forwardRef as forwardRef16,
3679
3700
  useCallback as useCallback17,
3680
- useEffect as useEffect11,
3701
+ useEffect as useEffect12,
3681
3702
  useRef as useRef4
3682
3703
  } from "react";
3683
3704
  import TextareaAutosize from "react-textarea-autosize";
@@ -3730,7 +3751,7 @@ var ComposerPrimitiveInput = forwardRef16(
3730
3751
  textareaRef.current.value.length
3731
3752
  );
3732
3753
  }, [autoFocusEnabled]);
3733
- useEffect11(() => focus(), [focus]);
3754
+ useEffect12(() => focus(), [focus]);
3734
3755
  useOnComposerFocus(() => {
3735
3756
  if (composerStore.getState().type === "thread") {
3736
3757
  focus();
@@ -3778,7 +3799,7 @@ var ComposerPrimitiveAddAttachment = createActionButton(
3778
3799
  import { memo as memo4 } from "react";
3779
3800
 
3780
3801
  // src/context/providers/ComposerAttachmentProvider.tsx
3781
- import { useEffect as useEffect12, useState as useState13 } from "react";
3802
+ import { useEffect as useEffect13, useState as useState13 } from "react";
3782
3803
  import { create as create14 } from "zustand";
3783
3804
  import { jsx as jsx29 } from "react/jsx-runtime";
3784
3805
  var getAttachment2 = ({ attachments }, useAttachment2, partIndex) => {
@@ -3798,7 +3819,7 @@ var useComposerAttachmentContext2 = (partIndex) => {
3798
3819
  return { type: "composer", useAttachment: useAttachment2 };
3799
3820
  }
3800
3821
  );
3801
- useEffect12(() => {
3822
+ useEffect13(() => {
3802
3823
  const syncAttachment = (composer) => {
3803
3824
  const newState = getAttachment2(
3804
3825
  composer,
@@ -3971,11 +3992,11 @@ var useOnResizeContent = (callback) => {
3971
3992
 
3972
3993
  // src/utils/hooks/useOnScrollToBottom.tsx
3973
3994
  import { useCallbackRef as useCallbackRef4 } from "@radix-ui/react-use-callback-ref";
3974
- import { useEffect as useEffect13 } from "react";
3995
+ import { useEffect as useEffect14 } from "react";
3975
3996
  var useOnScrollToBottom = (callback) => {
3976
3997
  const callbackRef = useCallbackRef4(callback);
3977
3998
  const threadViewportStore = useThreadViewportStore();
3978
- useEffect13(() => {
3999
+ useEffect14(() => {
3979
4000
  return threadViewportStore.getState().onScrollToBottom(() => {
3980
4001
  callbackRef();
3981
4002
  });
@@ -4048,7 +4069,7 @@ ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
4048
4069
  import { memo as memo5 } from "react";
4049
4070
 
4050
4071
  // src/context/providers/MessageProvider.tsx
4051
- import { useEffect as useEffect14, useState as useState14 } from "react";
4072
+ import { useEffect as useEffect15, useState as useState14 } from "react";
4052
4073
  import { create as create17 } from "zustand";
4053
4074
 
4054
4075
  // src/context/stores/EditComposer.ts
@@ -4174,7 +4195,7 @@ var useMessageContext2 = (messageIndex) => {
4174
4195
  });
4175
4196
  return { useMessage: useMessage2, useMessageUtils: useMessageUtils2, useEditComposer: useEditComposer2 };
4176
4197
  });
4177
- useEffect14(() => {
4198
+ useEffect15(() => {
4178
4199
  const syncMessage = (thread) => {
4179
4200
  const newState = getMessageState(
4180
4201
  thread,