# extendify/3.0.4/src/Agent/hooks/useWhenFinishedToolProps.js

Extendify, version 3.0.4. 73 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.0.4/code/src/Agent/hooks/useWhenFinishedToolProps.js
- Raw: https://pluginprobe.com/plugins/extendify/3.0.4/raw/src/Agent/hooks/useWhenFinishedToolProps.js
- Modified: 2026-03-05T17:57:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.0.4/code/src/Agent/hooks/useWhenFinishedToolProps.js#L10-L20`.

```javascript
import { recordAgentActivity } from '@agent/api';
import { useWorkflowStore } from '@agent/state/workflows';
import { useCallback, useMemo } from '@wordpress/element';

export const useWhenFinishedToolProps = () => {
	const { whenFinishedToolProps, setWhenFinishedToolProps, getWorkflow } =
		useWorkflowStore();

	const onConfirm = useCallback(
		(props = {}) => {
			if (!whenFinishedToolProps) return;
			const workflow = getWorkflow();
			recordAgentActivity({
				sessionId: workflow?.sessionId,
				action: 'workflow_tool_event',
				value: { trigger: 'confirm', workflow: workflow?.id },
			});
			window.dispatchEvent(
				new CustomEvent('extendify-agent:workflow-confirm', {
					detail: { ...props, whenFinishedToolProps },
				}),
			);
		},
		[whenFinishedToolProps, getWorkflow],
	);

	const onCancel = useCallback(() => {
		if (!whenFinishedToolProps) return;
		const workflow = getWorkflow();
		recordAgentActivity({
			sessionId: workflow?.sessionId,
			action: 'workflow_tool_event',
			value: { trigger: 'cancel', workflow: workflow?.id },
		});
		window.dispatchEvent(
			new CustomEvent('extendify-agent:workflow-cancel', {
				detail: { whenFinishedToolProps },
			}),
		);
	}, [whenFinishedToolProps, getWorkflow]);

	const onRetry = useCallback(() => {
		if (!whenFinishedToolProps) return;
		setWhenFinishedToolProps(null);
		const workflow = getWorkflow();
		recordAgentActivity({
			sessionId: workflow?.sessionId,
			action: 'workflow_tool_event',
			value: { trigger: 'retry', workflow: workflow?.id },
		});
		window.dispatchEvent(
			new CustomEvent('extendify-agent:workflow-retry', {
				detail: { whenFinishedToolProps },
			}),
		);
	}, [whenFinishedToolProps, setWhenFinishedToolProps, getWorkflow]);

	const onLoad = useCallback(() => {
		if (!whenFinishedToolProps) return;
		const c = Array.from(
			document.querySelectorAll(
				'#extendify-agent-chat-scroll-area div:last-child',
			),
		)?.at(-1);
		c?.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
	}, [whenFinishedToolProps]);

	return useMemo(() => {
		if (!whenFinishedToolProps) return null;
		return { ...whenFinishedToolProps, onConfirm, onCancel, onRetry, onLoad };
	}, [whenFinishedToolProps, onConfirm, onCancel, onRetry, onLoad]);
};

```
