@assistant-ui/react 0.5.56 → 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
@@ -603,7 +603,8 @@ type AssistantRuntime = ThreadRuntimeWithSubscribe & {
603
603
  /**
604
604
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
605
605
  */
606
- switchToThread: (threadId: string | null) => void;
606
+ switchToThread(threadId: null): void;
607
+ switchToThread(threadId: string): void;
607
608
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
608
609
  };
609
610
 
@@ -614,6 +615,7 @@ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChil
614
615
 
615
616
  type TextContentPartProviderProps = {
616
617
  text: string;
618
+ isRunning?: boolean | undefined;
617
619
  };
618
620
  declare const TextContentPartProvider: FC<PropsWithChildren<TextContentPartProviderProps>>;
619
621
 
@@ -621,7 +623,8 @@ type AssistantActionsState = Readonly<{
621
623
  /**
622
624
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
623
625
  */
624
- switchToThread: (threadId: string | null) => void;
626
+ switchToThread(threadId: null): void;
627
+ switchToThread(threadId: string): void;
625
628
  switchToNewThread: () => void;
626
629
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
627
630
  }>;
@@ -698,26 +701,30 @@ declare const useToolUIsStore: {
698
701
  };
699
702
  declare const useAssistantActions: {
700
703
  (): Readonly<{
701
- switchToThread: (threadId: string | null) => void;
704
+ switchToThread(threadId: null): void;
705
+ switchToThread(threadId: string): void;
702
706
  switchToNewThread: () => void;
703
707
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
704
708
  }>;
705
709
  <TSelected>(selector: (state: Readonly<{
706
- switchToThread: (threadId: string | null) => void;
710
+ switchToThread(threadId: null): void;
711
+ switchToThread(threadId: string): void;
707
712
  switchToNewThread: () => void;
708
713
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
709
714
  }>) => TSelected): TSelected;
710
715
  (options: {
711
716
  optional: true;
712
717
  }): Readonly<{
713
- switchToThread: (threadId: string | null) => void;
718
+ switchToThread(threadId: null): void;
719
+ switchToThread(threadId: string): void;
714
720
  switchToNewThread: () => void;
715
721
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
716
722
  }> | null;
717
723
  <TSelected>(options: {
718
724
  optional: true;
719
725
  selector?: (state: Readonly<{
720
- switchToThread: (threadId: string | null) => void;
726
+ switchToThread(threadId: null): void;
727
+ switchToThread(threadId: string): void;
721
728
  switchToNewThread: () => void;
722
729
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
723
730
  }>) => TSelected;
@@ -725,14 +732,16 @@ declare const useAssistantActions: {
725
732
  };
726
733
  declare const useAssistantActionsStore: {
727
734
  (): ReadonlyStore<Readonly<{
728
- switchToThread: (threadId: string | null) => void;
735
+ switchToThread(threadId: null): void;
736
+ switchToThread(threadId: string): void;
729
737
  switchToNewThread: () => void;
730
738
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
731
739
  }>>;
732
740
  (options: {
733
741
  optional: true;
734
742
  }): ReadonlyStore<Readonly<{
735
- switchToThread: (threadId: string | null) => void;
743
+ switchToThread(threadId: null): void;
744
+ switchToThread(threadId: string): void;
736
745
  switchToNewThread: () => void;
737
746
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
738
747
  }>> | null;
package/dist/index.d.ts CHANGED
@@ -603,7 +603,8 @@ type AssistantRuntime = ThreadRuntimeWithSubscribe & {
603
603
  /**
604
604
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
605
605
  */
606
- switchToThread: (threadId: string | null) => void;
606
+ switchToThread(threadId: null): void;
607
+ switchToThread(threadId: string): void;
607
608
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
608
609
  };
609
610
 
@@ -614,6 +615,7 @@ declare const AssistantRuntimeProvider: react.NamedExoticComponent<PropsWithChil
614
615
 
615
616
  type TextContentPartProviderProps = {
616
617
  text: string;
618
+ isRunning?: boolean | undefined;
617
619
  };
618
620
  declare const TextContentPartProvider: FC<PropsWithChildren<TextContentPartProviderProps>>;
619
621
 
@@ -621,7 +623,8 @@ type AssistantActionsState = Readonly<{
621
623
  /**
622
624
  * @deprecated Use `switchToNewThread` instead. This will be removed in 0.6.0.
623
625
  */
624
- switchToThread: (threadId: string | null) => void;
626
+ switchToThread(threadId: null): void;
627
+ switchToThread(threadId: string): void;
625
628
  switchToNewThread: () => void;
626
629
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
627
630
  }>;
@@ -698,26 +701,30 @@ declare const useToolUIsStore: {
698
701
  };
699
702
  declare const useAssistantActions: {
700
703
  (): Readonly<{
701
- switchToThread: (threadId: string | null) => void;
704
+ switchToThread(threadId: null): void;
705
+ switchToThread(threadId: string): void;
702
706
  switchToNewThread: () => void;
703
707
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
704
708
  }>;
705
709
  <TSelected>(selector: (state: Readonly<{
706
- switchToThread: (threadId: string | null) => void;
710
+ switchToThread(threadId: null): void;
711
+ switchToThread(threadId: string): void;
707
712
  switchToNewThread: () => void;
708
713
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
709
714
  }>) => TSelected): TSelected;
710
715
  (options: {
711
716
  optional: true;
712
717
  }): Readonly<{
713
- switchToThread: (threadId: string | null) => void;
718
+ switchToThread(threadId: null): void;
719
+ switchToThread(threadId: string): void;
714
720
  switchToNewThread: () => void;
715
721
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
716
722
  }> | null;
717
723
  <TSelected>(options: {
718
724
  optional: true;
719
725
  selector?: (state: Readonly<{
720
- switchToThread: (threadId: string | null) => void;
726
+ switchToThread(threadId: null): void;
727
+ switchToThread(threadId: string): void;
721
728
  switchToNewThread: () => void;
722
729
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
723
730
  }>) => TSelected;
@@ -725,14 +732,16 @@ declare const useAssistantActions: {
725
732
  };
726
733
  declare const useAssistantActionsStore: {
727
734
  (): ReadonlyStore<Readonly<{
728
- switchToThread: (threadId: string | null) => void;
735
+ switchToThread(threadId: null): void;
736
+ switchToThread(threadId: string): void;
729
737
  switchToNewThread: () => void;
730
738
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
731
739
  }>>;
732
740
  (options: {
733
741
  optional: true;
734
742
  }): ReadonlyStore<Readonly<{
735
- switchToThread: (threadId: string | null) => void;
743
+ switchToThread(threadId: null): void;
744
+ switchToThread(threadId: string): void;
736
745
  switchToNewThread: () => void;
737
746
  registerModelConfigProvider: (provider: ModelConfigProvider) => Unsubscribe;
738
747
  }>> | null;
package/dist/index.js CHANGED
@@ -1839,8 +1839,8 @@ var ExternalStoreRuntime = (_class9 = class extends BaseAssistantRuntime {
1839
1839
  if (!this.store.onSwitchToNewThread)
1840
1840
  throw new Error("Runtime does not support switching to new threads.");
1841
1841
  this.thread = new ExternalStoreThreadRuntime({
1842
- messages: [],
1843
- onNew: this.store.onNew
1842
+ ...this.store,
1843
+ messages: []
1844
1844
  });
1845
1845
  await this.store.onSwitchToNewThread();
1846
1846
  }
@@ -1849,8 +1849,9 @@ var ExternalStoreRuntime = (_class9 = class extends BaseAssistantRuntime {
1849
1849
  if (!this.store.onSwitchToThread)
1850
1850
  throw new Error("Runtime does not support switching threads.");
1851
1851
  this.thread = new ExternalStoreThreadRuntime({
1852
- messages: [],
1853
- onNew: this.store.onNew
1852
+ ...this.store,
1853
+ messages: []
1854
+ // ignore messages until rerender
1854
1855
  });
1855
1856
  this.store.onSwitchToThread(threadId);
1856
1857
  } else {
@@ -2347,16 +2348,37 @@ var AssistantRuntimeProvider = _react.memo.call(void 0, AssistantRuntimeProvider
2347
2348
 
2348
2349
 
2349
2350
 
2350
- 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 }) => {
2351
2358
  const [context] = _react.useState.call(void 0, () => {
2352
2359
  const useContentPart2 = _zustand.create.call(void 0, () => ({
2353
- status: { type: "complete" },
2360
+ status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
2354
2361
  part: { type: "text", text }
2355
2362
  }));
2356
2363
  return {
2357
2364
  useContentPart: useContentPart2
2358
2365
  };
2359
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]);
2360
2382
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContentPartContext.Provider, { value: context, children });
2361
2383
  };
2362
2384
 
@@ -3283,21 +3305,21 @@ MessagePrimitiveIf.displayName = "MessagePrimitive.If";
3283
3305
 
3284
3306
 
3285
3307
 
3286
- var COMPLETE_STATUS = {
3308
+ var COMPLETE_STATUS2 = {
3287
3309
  type: "complete"
3288
3310
  };
3289
3311
  var toContentPartStatus = (message, partIndex, part) => {
3290
- if (message.role !== "assistant") return COMPLETE_STATUS;
3312
+ if (message.role !== "assistant") return COMPLETE_STATUS2;
3291
3313
  const isLastPart = partIndex === Math.max(0, message.content.length - 1);
3292
3314
  if (part.type !== "tool-call") {
3293
3315
  if ("reason" in message.status && message.status.reason === "tool-calls" && isLastPart)
3294
3316
  throw new Error(
3295
3317
  "Encountered unexpected requires-action status. This is likely an internal bug in assistant-ui."
3296
3318
  );
3297
- return isLastPart ? message.status : COMPLETE_STATUS;
3319
+ return isLastPart ? message.status : COMPLETE_STATUS2;
3298
3320
  }
3299
3321
  if (!!part.result) {
3300
- return COMPLETE_STATUS;
3322
+ return COMPLETE_STATUS2;
3301
3323
  }
3302
3324
  return message.status;
3303
3325
  };