PluginProbe
Extendify / 3.2.3
Extendify v3.2.3
3.2.3 3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 All 129 releases
← All changes | src/Agent/Agent.jsx +119 -46 3.2.1 → 3.2.3 View file →
@@ -12,9 +12,16 @@
12 12 useCanvasOpen,
13 13 } from '@agent/components/Canvas';
14 14 import { ChatInput } from '@agent/components/ChatInput';
15 15 import { ChatMessages } from '@agent/components/ChatMessages';
16 +import { StatusIndicator } from '@agent/components/messages/StatusIndicator';
16 17 import { UsageMessage } from '@agent/components/messages/UsageMessage';
18 +import { useFollowUpHistory } from '@agent/follow-ups/history';
19 +import {
20 + cardMessageIndex,
21 + pickNextCard,
22 + toolCallsThisRun,
23 +} from '@agent/follow-ups/pick-next';
17 24 import { useLockPost } from '@agent/hooks/useLockPost';
18 25 import { isAbilityTool, isAbilityWorkflow } from '@agent/lib/abilities';
19 26 import {
20 27 getClientToolFallbackReply,
@@ -20,15 +27,13 @@
20 27 getClientToolFallbackReply,
21 28 getClientTools,
22 29 } from '@agent/lib/client-tools';
23 30 import { localPickWorkflow } from '@agent/lib/local-pick';
24 -import { getRedirectUrl } from '@agent/lib/redirects';
25 31 import { doReload } from '@agent/lib/reload';
26 32 import { useCanvasStore } from '@agent/state/canvas';
27 33 import { useChatStore } from '@agent/state/chat';
28 34 import { useGlobalStore } from '@agent/state/global';
29 35 import { useStatusStore } from '@agent/state/status';
30 -import { useSuggestionsStore } from '@agent/state/suggestions';
31 36 import { useWorkflowStore } from '@agent/state/workflows';
32 37 import { hasRunComponent } from '@agent/workflows/abilities/components/run';
33 38 import startOnboardingWorkflow from '@agent/workflows/misc/start-onboarding';
34 39 import { useQuickEditStore } from '@quick-edit/state/store';
@@ -66,8 +71,18 @@
66 71 await new Promise((resolve) => setTimeout(resolve, ms));
67 72 return signal.aborted;
68 73 };
69 74
75 +const nextSteps = (workflowId, status, messages) => {
76 + if (status === 'completed') {
77 + useFollowUpHistory.getState().markDone(workflowId);
78 + }
79 + const card = pickNextCard({ workflowId, status, messages });
80 + return card
81 + ? { followUp: card.id, followUpData: card.data }
82 + : { followUp: null };
83 +};
84 +
70 85 export const Agent = () => {
71 86 const { addMessage, updateMessage, popMessage, messages } = useChatStore();
72 87 const { pushStatus, clearStatuses, leavingPage } = useStatusStore();
73 88 const {
@@ -100,9 +115,8 @@
100 115 const canvasOpen = useCanvasOpen();
101 116 const canvasAssist = useCanvasAssist();
102 117 const canvasNoticeShown = useRef(false);
103 118 const chatAvailable = useMemo(() => isChatAvailable(), [isChatAvailable]);
104 - const { addSuggestions, getSuggestions } = useSuggestionsStore();
105 119 // Options render only while their message is last; a reply dismisses them.
106 120 const lastMessage = messages.at(-1);
107 121 const qaSuggestions =
108 122 lastMessage?.type === 'message' &&
@@ -110,8 +124,18 @@
110 124 Array.isArray(lastMessage.details?.qaSuggestions)
111 125 ? lastMessage.details.qaSuggestions
112 126 : null;
113 127
128 + useEffect(() => {
129 + const { messages, updateMessage } = useChatStore.getState();
130 + const index = cardMessageIndex(messages);
131 + const { id, details } = messages[index] ?? {};
132 + if (!id || details.followUp !== undefined || details.followUpClosed) return;
133 + const { workflowId, status } = details;
134 + const steps = nextSteps(workflowId, status, messages.slice(0, index));
135 + if (steps.followUp) updateMessage(id, steps);
136 + }, []);
137 +
114 138 // Without this the input stays disabled for as long as the canvas is open.
115 139 useEffect(() => {
116 140 if (canvasOpen && canvasAssist) setCanType(true);
117 141 // A workflow reached by example carries no sessionId to key this on.
@@ -127,9 +151,14 @@
127 151 agentBlock && setBlock(null);
128 152 // A class or pin left up freezes Quick Edit hover site-wide.
129 153 document
130 154 .querySelector('.wp-site-blocks')
131 - ?.classList.remove('extendify-agent-working', 'extendify-agent-busy');
155 + ?.classList.remove(
156 + 'extendify-agent-working',
157 + 'extendify-agent-busy',
158 + 'extendify-agent-waiting',
159 + 'extendify-agent-task',
160 + );
132 161 setCommittedSelection(null);
133 162 clearStatuses();
134 163 window.dispatchEvent(new Event('extendify-agent:remove-block-highlight'));
135 164 }, [setBlock, clearStatuses]);
@@ -272,13 +301,15 @@
272 301 setCanType(true);
273 302 }, [addMessage, pushStatus, whenFinishedToolProps, workflow]);
274 303
275 304 const handleSubmit = useCallback(
276 - async (message, { hidden = false } = {}) => {
277 - // Suggestions reach the agent without the textarea; disabling it isn't enough.
305 + async (message, { hidden = false, step } = {}) => {
306 + // chat-submit events skip the textarea; disabling it isn't enough.
278 307 if (useQuickEditStore.getState().selected) return;
308 + if (whenFinishedToolProps?.processing) return;
279 309 setWaitingOnToolOrUser(false);
280 310 agentWorking.current = false;
311 + if (step) addMessage('tool', { ...step, inputs: {}, fromCard: true });
281 312 addMessage('message', { role: 'user', content: message, hidden });
282 313
283 314 // Without this a typed message would drop the workflow and close the canvas.
284 315 if (canvasOpen && canvasAssist) return handleCanvasMessage();
@@ -292,9 +323,9 @@
292 323 label: whenFinishedTool?.labels?.cancel,
293 324 agent: workflow.agent,
294 325 workflowId: workflow.id,
295 326 answerId,
296 - suggestions: getSuggestions(),
327 + followUp: null,
297 328 });
298 329 }
299 330
300 331 // Let some phrases auto load workflows
@@ -345,9 +376,8 @@
345 376 setWorkflow,
346 377 workflow,
347 378 workflowData,
348 379 getAvailableWorkflows,
349 - getSuggestions,
350 380 ],
351 381 );
352 382
353 383 // Used to inject a workflow final state
@@ -403,9 +433,10 @@
403 433 useEffect(() => {
404 434 // Allow external messages to trigger the agent
405 435 const handleMessage = ({ detail }) => {
406 436 if (!detail?.message) return;
407 - handleSubmit(detail.message, { hidden: detail.hidden });
437 + const { message, hidden, step } = detail;
438 + handleSubmit(message, { hidden, step });
408 439 };
409 440 // Allow external code to clear the block and workflow
410 441 const handleCleanup = () => {
411 442 // cleanup() resets canType and agentWorking, so read them before it runs.
@@ -423,9 +454,9 @@
423 454 addMessage('workflow', {
424 455 status: 'canceled',
425 456 agent: workflow?.agent,
426 457 workflowId: workflow?.id,
427 - suggestions: getSuggestions(),
458 + ...nextSteps(workflow?.id, 'canceled'),
428 459 });
429 460 return;
430 461 };
431 462 window.addEventListener('extendify-agent:cancel-workflow', handleCleanup);
@@ -443,9 +474,8 @@
443 474 setWorkflow,
444 475 addMessage,
445 476 workflow,
446 477 qaSuggestions,
447 - getSuggestions,
448 478 canType,
449 479 ]);
450 480
451 481 // Dispatching before chat-submit has a listener drops the workflow.
@@ -457,22 +487,39 @@
457 487 }),
458 488 );
459 489 }, []);
460 490
491 + // ChatMessages hides a confirm restored by a reload; left open, the workflow would sit unfinishable.
492 + useEffect(() => {
493 + const { getWorkflow, reloadedToolProps } = useWorkflowStore.getState();
494 + const { whenFinished, needsRedirect } = getWorkflow() ?? {};
495 + if (!reloadedToolProps?.id || !whenFinished?.component) return;
496 + if (whenFinished.canvas || needsRedirect?.()) return;
497 + window.dispatchEvent(new Event('extendify-agent:cancel-workflow'));
498 + }, []);
499 +
461 500 // Handle whenFinished component confirm/cancel
462 501 useEffect(() => {
463 502 const handleConfirm = async ({ detail }) => {
464 503 if (toolWorking.current) return;
465 - setWhenFinishedToolProps(null);
466 504 toolWorking.current = true;
467 505 const { data, whenFinishedToolProps, shouldRefreshPage, redirectUrl } =
468 506 detail ?? {};
469 - const { whenFinishedTool, answerId, redirectTo } =
507 + // Staged until the tool returns, so the chat shows it saving.
508 + setWhenFinishedToolProps(
509 + whenFinishedToolProps
510 + ? { ...whenFinishedToolProps, processing: true }
511 + : null,
512 + );
513 + const { whenFinishedTool, answerId } =
470 514 whenFinishedToolProps?.agentResponse || {};
471 515 const { id, labels } = whenFinishedTool || {};
472 516 // Staged unanswered so its own component can show the run in progress.
473 517 const runMessageId = id ? addMessage('tool', { id, inputs: data }) : null;
474 - if (!hasRunComponent(id)) pushStatus('workflow-tool-processing');
518 + // In the chat, the saving state shows this label instead.
519 + if (!hasRunComponent(id) && workflow?.whenFinished?.canvas) {
520 + pushStatus('workflow-tool-processing', labels?.started);
521 + }
475 522 // Not all workflows have a tool at the end (e.g. tours)
476 523 const toolResponse = await callTool?.({ tool: id, inputs: data }).catch(
477 524 (error) => {
478 525 const { sessionId } = workflow || {};
@@ -488,8 +535,9 @@
488 535 return { error: { message: error?.message, code: error?.code } };
489 536 },
490 537 );
491 538 toolWorking.current = false;
539 + setWhenFinishedToolProps(null);
492 540 if (runMessageId) updateMessage(runMessageId, { result: toolResponse });
493 541 if (toolResponse?.refused) {
494 542 await new Promise((resolve) => setTimeout(resolve, 1000));
495 543 const refusalMessages = {
@@ -522,9 +570,13 @@
522 570 setLoop((prev) => prev + 1);
523 571 return;
524 572 }
525 573
526 - addSuggestions(whenFinishedToolProps.agentResponse?.recommendations);
574 + // Reloading here unmounts a run component still watching its ability finish.
575 + const refreshForAbility =
576 + isAbilityTool(id) && shouldRefreshPage !== false;
577 + const willReload = redirectUrl || shouldRefreshPage || refreshForAbility;
578 + // A card shown now would flash just before the reload.
527 579 addMessage('workflow', {
528 580 status: 'completed',
529 581 label: labels?.confirm,
530 582 agent: workflow.agent,
@@ -529,9 +581,9 @@
529 581 label: labels?.confirm,
530 582 agent: workflow.agent,
531 583 workflowId: workflow.id,
532 584 answerId,
533 - suggestions: getSuggestions(),
585 + ...(willReload ? {} : nextSteps(workflow.id, 'completed')),
534 586 });
535 587 // A chat message persists, so the next turn's model knows the save was partial.
536 588 const refusedCount = toolResponse?.refusedOperations?.length;
537 589 if (refusedCount) {
@@ -551,13 +603,9 @@
551 603 }
552 604 setWorkflow(null);
553 605 useCanvasStore.getState().endSession();
554 606
555 - const url = getRedirectUrl(redirectTo, whenFinishedToolProps?.inputs);
556 - const refreshForAbility = isAbilityTool(id);
557 - if (url || redirectUrl || shouldRefreshPage || refreshForAbility) {
558 - return doReload(url || redirectUrl);
559 - }
607 + if (willReload) return doReload(redirectUrl);
560 608 cleanup();
561 609 };
562 610 const handleCancel = ({ detail }) => {
563 611 if (toolWorking.current) return;
@@ -570,9 +618,9 @@
570 618 label: whenFinishedTool?.labels?.cancel,
571 619 agent: workflow.agent,
572 620 workflowId: workflow.id,
573 621 answerId,
574 - suggestions: getSuggestions(),
622 + ...nextSteps(workflow.id, 'canceled'),
575 623 });
576 624 setWorkflow(null);
577 625 useCanvasStore.getState().endSession();
578 626 cleanup();
@@ -597,18 +645,9 @@
597 645 handleCancel,
598 646 );
599 647 window.removeEventListener('extendify-agent:workflow-retry', handleRetry);
600 648 };
601 - }, [
602 - addMessage,
603 - pushStatus,
604 - popMessage,
605 - cleanup,
606 - setWorkflow,
607 - workflow,
608 - getSuggestions,
609 - addSuggestions,
610 - ]);
649 + }, [addMessage, pushStatus, popMessage, cleanup, setWorkflow, workflow]);
611 650
612 651 useEffect(() => {
613 652 const handleClose = () => setOpen(false);
614 653 const handleOpen = () => setOpen(true);
@@ -628,9 +667,26 @@
628 667 if (open) return;
629 668 if (block) setBlock(null);
630 669 }, [open, block, setBlock]);
631 670
671 + // A pick answers select-block's "which one?"; making the user also type stalls it.
672 + const previousBlock = useRef(block);
632 673 useEffect(() => {
674 + const picked = block && !previousBlock.current;
675 + previousBlock.current = block;
676 + if (!picked || workflow?.id !== 'select-block') return;
677 + if (!waitingOnToolOrUser || !canType || whenFinishedToolProps?.id) return;
678 + handleSubmit('This is the block I mean.', { hidden: true });
679 + }, [
680 + block,
681 + workflow?.id,
682 + waitingOnToolOrUser,
683 + canType,
684 + whenFinishedToolProps?.id,
685 + handleSubmit,
686 + ]);
687 +
688 + useEffect(() => {
633 689 if (waitingOnToolOrUser || !open || !workflow?.id) return;
634 690 // Some workflows require they dont change pages
635 691 const theyMoved = workflow?.startingPage !== window.location.href;
636 692 // Requires a block to be selected
@@ -641,9 +697,9 @@
641 697 addMessage('workflow', {
642 698 status: 'canceled',
643 699 agent: workflow.agent,
644 700 workflowId: workflow.id,
645 - suggestions: getSuggestions(),
701 + ...nextSteps(workflow.id, 'canceled'),
646 702 });
647 703 setWorkflow(null);
648 704 cleanup();
649 705 return;
@@ -740,9 +796,8 @@
740 796 status: 'completed',
741 797 inputs,
742 798 workflowId: workflow.id,
743 799 });
744 - addSuggestions(agentResponse.recommendations);
745 800 setWorkflow(null);
746 801 addMessage('workflow', {
747 802 status: 'completed',
748 803 agent: workflow.agent,
@@ -747,9 +802,9 @@
747 802 status: 'completed',
748 803 agent: workflow.agent,
749 804 workflowId: workflow.id,
750 805 answerId,
751 - suggestions: getSuggestions(),
806 + ...nextSteps(workflow.id, 'completed'),
752 807 });
753 808 cleanup();
754 809 }
755 810 return;
@@ -755,19 +810,21 @@
755 810 return;
756 811 }
757 812 // If we're done, it means the AI has the answer
758 813 if (agentResponse.status !== 'in-progress') {
759 - const { recommendations, status } = agentResponse;
760 - const isCompleted = status === 'completed';
761 - if (recommendations) addSuggestions(recommendations);
814 + const status =
815 + agentResponse.status === 'completed' ? 'completed' : 'canceled';
816 + // A reply that changed nothing isn't a finished task to follow up.
817 + const didWork =
818 + toolCallsThisRun(useChatStore.getState().messages).length > 0;
762 819 setWorkflow(null);
763 820 cleanup();
764 821 addMessage('workflow', {
765 - status: isCompleted ? 'completed' : 'canceled',
822 + status,
766 823 agent: workflow.agent,
767 824 workflowId: workflow.id,
768 825 answerId,
769 - suggestions: getSuggestions(),
826 + ...(didWork ? nextSteps(workflow.id, status) : { followUp: null }),
770 827 });
771 828 return;
772 829 }
773 830 if (sessionId && sessionId !== workflow.sessionId) {
@@ -787,9 +844,10 @@
787 844 setWaitingOnToolOrUser(true);
788 845 setCanType(false);
789 846 return;
790 847 }
791 - pushStatus('tool-started', labels?.started);
848 + // A reply sent with the tool clears the status, blanking the line.
849 + pushStatus('agent-working');
792 850 const toolData = await Promise.all([
793 851 callTool({ tool: id, inputs }),
794 852 new Promise((resolve) => setTimeout(resolve, 3000)),
795 853 ])
@@ -820,8 +878,9 @@
820 878 id,
821 879 inputs,
822 880 result: toolData,
823 881 label: labels?.confirm,
882 + started: labels?.started,
824 883 });
825 884 setWaitingOnToolOrUser(false);
826 885 agentWorking.current = false;
827 886 setLoop((prev) => prev + 1); // Trigger next loop
@@ -867,10 +926,8 @@
867 926 setWhenFinishedToolProps,
868 927 block,
869 928 setBlock,
870 929 findAgent,
871 - addSuggestions,
872 - getSuggestions,
873 930 ]);
874 931
875 932 useEffect(() => {
876 933 if (!canType) return;
@@ -876,9 +933,15 @@
876 933 if (!canType) return;
877 934 document.querySelector('#extendify-agent-chat-textarea')?.focus();
878 935 }, [canType]);
879 936
880 - const busy = !canType || !chatAvailable || workflow?.id;
937 + // A task waiting on a reply leaves the page pickable so the user can answer by pointing.
938 + const waiting =
939 + canType &&
940 + chatAvailable &&
941 + Boolean(workflow?.id) &&
942 + !whenFinishedToolProps?.id;
943 + const busy = !canType || !chatAvailable || (workflow?.id && !waiting);
881 944 // `busy` is true at rest; 429 is blocked, not working.
882 945 const working = !canType && chatAvailable;
883 946
884 947 return (
@@ -883,9 +946,14 @@
883 946
884 947 return (
885 948 <>
886 949 <Canvas />
887 - <Chat busy={busy} working={working}>
950 + <Chat
951 + busy={busy}
952 + working={working}
953 + waiting={waiting}
954 + taskActive={Boolean(workflow?.id)}
955 + >
888 956 <div className="relative z-50 flex h-full flex-col justify-between overflow-auto">
889 957 <ChatMessages
890 958 redirectComponent={
891 959 workflow?.needsRedirect?.() ? workflow.redirectComponent : null
@@ -900,11 +968,16 @@
900 968 }}
901 969 />
902 970 </div>
903 971 <div className="p-4 pb-2 pt-0">
972 + <StatusIndicator />
904 973 <ChatInput
905 974 disabled={
906 - !canType || !chatAvailable || !!qaSuggestions || leavingPage
975 + !canType ||
976 + !chatAvailable ||
977 + !!qaSuggestions ||
978 + leavingPage ||
979 + whenFinishedToolProps?.processing
907 980 }
908 981 handleSubmit={handleSubmit}
909 982 />
910 983 </div>