@hef2024/llmasaservice-ui 0.20.2 → 0.20.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
@@ -5698,9 +5698,13 @@ var AIAgentPanel = import_react14.default.forwardRef(({
5698
5698
  const [currentAgentId, setCurrentAgentId] = (0, import_react14.useState)(
5699
5699
  defaultAgent || agentIds[0] || ""
5700
5700
  );
5701
+ const [pendingFollowOnPrompt, setPendingFollowOnPrompt] = (0, import_react14.useState)(null);
5702
+ const [agentSwitchSettled, setAgentSwitchSettled] = (0, import_react14.useState)(true);
5703
+ const lastProcessedFollowOnRef = (0, import_react14.useRef)("");
5701
5704
  (0, import_react14.useEffect)(() => {
5702
5705
  if (selectedAgent && selectedAgent !== currentAgentId) {
5703
5706
  const oldAgentId = currentAgentId;
5707
+ setAgentSwitchSettled(false);
5704
5708
  setCurrentAgentId(selectedAgent);
5705
5709
  if (onAgentSwitch) {
5706
5710
  onAgentSwitch(oldAgentId, selectedAgent);
@@ -5720,6 +5724,37 @@ var AIAgentPanel = import_react14.default.forwardRef(({
5720
5724
  }
5721
5725
  }
5722
5726
  }, [selectedAgent]);
5727
+ (0, import_react14.useEffect)(() => {
5728
+ if (!agentSwitchSettled && followOnPrompt && followOnPrompt !== "" && followOnPrompt !== lastProcessedFollowOnRef.current) {
5729
+ setPendingFollowOnPrompt(followOnPrompt);
5730
+ lastProcessedFollowOnRef.current = followOnPrompt;
5731
+ }
5732
+ }, [followOnPrompt, agentSwitchSettled]);
5733
+ (0, import_react14.useEffect)(() => {
5734
+ if (!agentSwitchSettled) {
5735
+ const timer = setTimeout(() => {
5736
+ setAgentSwitchSettled(true);
5737
+ }, 100);
5738
+ return () => clearTimeout(timer);
5739
+ }
5740
+ }, [agentSwitchSettled]);
5741
+ const effectiveFollowOnPrompt = (0, import_react14.useMemo)(() => {
5742
+ if (!agentSwitchSettled) {
5743
+ return "";
5744
+ }
5745
+ if (pendingFollowOnPrompt) {
5746
+ return pendingFollowOnPrompt;
5747
+ }
5748
+ return followOnPrompt;
5749
+ }, [followOnPrompt, pendingFollowOnPrompt, agentSwitchSettled]);
5750
+ (0, import_react14.useEffect)(() => {
5751
+ if (agentSwitchSettled && pendingFollowOnPrompt) {
5752
+ const timer = setTimeout(() => {
5753
+ setPendingFollowOnPrompt(null);
5754
+ }, 100);
5755
+ return () => clearTimeout(timer);
5756
+ }
5757
+ }, [agentSwitchSettled, pendingFollowOnPrompt]);
5723
5758
  const [apiConversations, setApiConversations] = (0, import_react14.useState)([]);
5724
5759
  const [conversationsLoading, setConversationsLoading] = (0, import_react14.useState)(false);
5725
5760
  const [conversationsError, setConversationsError] = (0, import_react14.useState)(null);
@@ -6766,7 +6801,7 @@ var AIAgentPanel = import_react14.default.forwardRef(({
6766
6801
  initialMessage,
6767
6802
  hideInitialPrompt,
6768
6803
  followOnQuestions,
6769
- followOnPrompt,
6804
+ followOnPrompt: effectiveFollowOnPrompt,
6770
6805
  agentOptions,
6771
6806
  currentAgentId,
6772
6807
  handleAgentSwitch,
package/dist/index.mjs CHANGED
@@ -5665,9 +5665,13 @@ var AIAgentPanel = React13.forwardRef(({
5665
5665
  const [currentAgentId, setCurrentAgentId] = useState8(
5666
5666
  defaultAgent || agentIds[0] || ""
5667
5667
  );
5668
+ const [pendingFollowOnPrompt, setPendingFollowOnPrompt] = useState8(null);
5669
+ const [agentSwitchSettled, setAgentSwitchSettled] = useState8(true);
5670
+ const lastProcessedFollowOnRef = useRef6("");
5668
5671
  useEffect9(() => {
5669
5672
  if (selectedAgent && selectedAgent !== currentAgentId) {
5670
5673
  const oldAgentId = currentAgentId;
5674
+ setAgentSwitchSettled(false);
5671
5675
  setCurrentAgentId(selectedAgent);
5672
5676
  if (onAgentSwitch) {
5673
5677
  onAgentSwitch(oldAgentId, selectedAgent);
@@ -5687,6 +5691,37 @@ var AIAgentPanel = React13.forwardRef(({
5687
5691
  }
5688
5692
  }
5689
5693
  }, [selectedAgent]);
5694
+ useEffect9(() => {
5695
+ if (!agentSwitchSettled && followOnPrompt && followOnPrompt !== "" && followOnPrompt !== lastProcessedFollowOnRef.current) {
5696
+ setPendingFollowOnPrompt(followOnPrompt);
5697
+ lastProcessedFollowOnRef.current = followOnPrompt;
5698
+ }
5699
+ }, [followOnPrompt, agentSwitchSettled]);
5700
+ useEffect9(() => {
5701
+ if (!agentSwitchSettled) {
5702
+ const timer = setTimeout(() => {
5703
+ setAgentSwitchSettled(true);
5704
+ }, 100);
5705
+ return () => clearTimeout(timer);
5706
+ }
5707
+ }, [agentSwitchSettled]);
5708
+ const effectiveFollowOnPrompt = useMemo4(() => {
5709
+ if (!agentSwitchSettled) {
5710
+ return "";
5711
+ }
5712
+ if (pendingFollowOnPrompt) {
5713
+ return pendingFollowOnPrompt;
5714
+ }
5715
+ return followOnPrompt;
5716
+ }, [followOnPrompt, pendingFollowOnPrompt, agentSwitchSettled]);
5717
+ useEffect9(() => {
5718
+ if (agentSwitchSettled && pendingFollowOnPrompt) {
5719
+ const timer = setTimeout(() => {
5720
+ setPendingFollowOnPrompt(null);
5721
+ }, 100);
5722
+ return () => clearTimeout(timer);
5723
+ }
5724
+ }, [agentSwitchSettled, pendingFollowOnPrompt]);
5690
5725
  const [apiConversations, setApiConversations] = useState8([]);
5691
5726
  const [conversationsLoading, setConversationsLoading] = useState8(false);
5692
5727
  const [conversationsError, setConversationsError] = useState8(null);
@@ -6733,7 +6768,7 @@ var AIAgentPanel = React13.forwardRef(({
6733
6768
  initialMessage,
6734
6769
  hideInitialPrompt,
6735
6770
  followOnQuestions,
6736
- followOnPrompt,
6771
+ followOnPrompt: effectiveFollowOnPrompt,
6737
6772
  agentOptions,
6738
6773
  currentAgentId,
6739
6774
  handleAgentSwitch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hef2024/llmasaservice-ui",
3
- "version": "0.20.2",
3
+ "version": "0.20.3",
4
4
  "description": "Prebuilt UI components for LLMAsAService.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -716,11 +716,20 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
716
716
  defaultAgent || agentIds[0] || ''
717
717
  );
718
718
 
719
+ // Track pending follow-on prompt after agent switch (to handle timing issues)
720
+ const [pendingFollowOnPrompt, setPendingFollowOnPrompt] = useState<string | null>(null);
721
+ const [agentSwitchSettled, setAgentSwitchSettled] = useState(true);
722
+ const lastProcessedFollowOnRef = useRef<string>('');
723
+
719
724
  // Sync with controlled selectedAgent prop when it changes
720
725
  useEffect(() => {
721
726
  // Only sync if selectedAgent is provided (controlled mode) and differs from current
722
727
  if (selectedAgent && selectedAgent !== currentAgentId) {
723
728
  const oldAgentId = currentAgentId;
729
+
730
+ // Mark that an agent switch is in progress (not yet settled)
731
+ setAgentSwitchSettled(false);
732
+
724
733
  setCurrentAgentId(selectedAgent);
725
734
 
726
735
  // Fire onAgentSwitch callback for programmatic changes too
@@ -744,7 +753,54 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
744
753
  });
745
754
  }
746
755
  }
747
- }, [selectedAgent]); // Note: intentionally excluding currentAgentId and onAgentSwitch to only trigger on prop change
756
+ }, [selectedAgent]); // Note: intentionally excluding other deps to only trigger on prop change
757
+
758
+ // Queue followOnPrompt if it arrives during an agent switch
759
+ useEffect(() => {
760
+ if (!agentSwitchSettled && followOnPrompt && followOnPrompt !== '' && followOnPrompt !== lastProcessedFollowOnRef.current) {
761
+ // Agent switch in progress - queue the prompt
762
+ setPendingFollowOnPrompt(followOnPrompt);
763
+ lastProcessedFollowOnRef.current = followOnPrompt;
764
+ }
765
+ }, [followOnPrompt, agentSwitchSettled]);
766
+
767
+ // Mark agent switch as settled after a short delay (allows ChatPanelWrapper to re-render)
768
+ useEffect(() => {
769
+ if (!agentSwitchSettled) {
770
+ const timer = setTimeout(() => {
771
+ setAgentSwitchSettled(true);
772
+ }, 100); // Small delay to ensure ChatPanelWrapper has re-rendered with new agent
773
+
774
+ return () => clearTimeout(timer);
775
+ }
776
+ }, [agentSwitchSettled]);
777
+
778
+ // Compute effective follow-on prompt (handles timing with agent switch)
779
+ const effectiveFollowOnPrompt = useMemo(() => {
780
+ // If agent switch hasn't settled yet, don't send any prompt
781
+ if (!agentSwitchSettled) {
782
+ return '';
783
+ }
784
+
785
+ // If there's a pending prompt from agent switch, use it
786
+ if (pendingFollowOnPrompt) {
787
+ return pendingFollowOnPrompt;
788
+ }
789
+
790
+ // Otherwise use the prop directly
791
+ return followOnPrompt;
792
+ }, [followOnPrompt, pendingFollowOnPrompt, agentSwitchSettled]);
793
+
794
+ // Clear pending prompt after it's been passed down
795
+ useEffect(() => {
796
+ if (agentSwitchSettled && pendingFollowOnPrompt) {
797
+ // Clear after a tick to ensure it was processed
798
+ const timer = setTimeout(() => {
799
+ setPendingFollowOnPrompt(null);
800
+ }, 100);
801
+ return () => clearTimeout(timer);
802
+ }
803
+ }, [agentSwitchSettled, pendingFollowOnPrompt]);
748
804
 
749
805
  // API-based conversation state
750
806
  const [apiConversations, setApiConversations] = useState<APIConversationSummary[]>([]);
@@ -2267,7 +2323,7 @@ const AIAgentPanel = React.forwardRef<AIAgentPanelHandle, AIAgentPanelProps>(({
2267
2323
  initialMessage={initialMessage}
2268
2324
  hideInitialPrompt={hideInitialPrompt}
2269
2325
  followOnQuestions={followOnQuestions}
2270
- followOnPrompt={followOnPrompt}
2326
+ followOnPrompt={effectiveFollowOnPrompt}
2271
2327
  agentOptions={agentOptions}
2272
2328
  currentAgentId={currentAgentId}
2273
2329
  handleAgentSwitch={handleAgentSwitch}