@@ -4,7 +4,6 @@ import { toast } from "sonner";
44import {
55 type CreateChannelManagedAgentInput ,
66 useAttachManagedAgentToChannelMutation ,
7- useAvailableAcpRuntimes ,
87 useCreateChannelManagedAgentMutation ,
98 useManagedAgentsQuery ,
109 usePersonasQuery ,
@@ -15,6 +14,7 @@ import { applyReusableAgentAccessPolicy } from "@/features/agents/channelAgents"
1514import { resolvePersonaRuntime } from "@/features/agents/lib/resolvePersonaRuntime" ;
1615import { useAddChannelMembersMutation } from "@/features/channels/hooks" ;
1716import { useCanAddChannelMembers } from "@/features/channels/useCanAddChannelMembers" ;
17+ import { useMentionAvailableRuntimes } from "./useMentionAvailableRuntimes" ;
1818import { useNonMemberInvite } from "./useNonMemberInvite" ;
1919import { dmThreadAgentMentionError } from "@/features/messages/lib/dmThreadAgentMentionError" ;
2020import {
@@ -27,7 +27,7 @@ import {
2727} from "@/features/messages/lib/imetaMediaMarkdown" ;
2828import { useActivePreparedLinkPreviews } from "./useActivePreparedLinkPreviews" ;
2929import { invokeTauri } from "@/shared/api/tauri" ;
30- import type { AcpRuntime , ManagedAgent } from "@/shared/api/types" ;
30+ import type { ManagedAgent } from "@/shared/api/types" ;
3131import { normalizePubkey , truncatePubkey } from "@/shared/lib/pubkey" ;
3232import { buildCustomEmojiTags } from "@/shared/lib/customEmojiTags" ;
3333import {
@@ -111,7 +111,6 @@ export function useMentionSendFlow({
111111 useCreateChannelManagedAgentMutation ( channelId ) ;
112112 const provisionPersonaAgentMutation =
113113 useProvisionChannelManagedAgentMutation ( channelId ) ;
114- const availableRuntimesQuery = useAvailableAcpRuntimes ( ) ;
115114 const managedAgentsQuery = useManagedAgentsQuery ( ) ;
116115 const personasQuery = usePersonasQuery ( ) ;
117116 const startAgentMutation = useStartManagedAgentMutation ( ) ;
@@ -127,25 +126,7 @@ export function useMentionSendFlow({
127126 const getPersonas = React . useCallback ( async ( ) => {
128127 return personasQuery . data ?? ( await personasQuery . refetch ( ) ) . data ?? [ ] ;
129128 } , [ personasQuery . data , personasQuery . refetch ] ) ;
130- const getAvailableRuntimes = React . useCallback ( async ( ) : Promise <
131- AcpRuntime [ ]
132- > => {
133- const cached = availableRuntimesQuery . data ?? [ ] ;
134- if ( cached . length > 0 || ! availableRuntimesQuery . isLoading ) {
135- return cached ;
136- }
137- const refetched = await availableRuntimesQuery . refetch ( ) ;
138- return ( refetched . data ?? [ ] ) . filter (
139- ( runtime ) : runtime is AcpRuntime =>
140- runtime . availability === "available" &&
141- runtime . command !== null &&
142- runtime . binaryPath !== null ,
143- ) ;
144- } , [
145- availableRuntimesQuery . data ,
146- availableRuntimesQuery . isLoading ,
147- availableRuntimesQuery . refetch ,
148- ] ) ;
129+ const getAvailableRuntimes = useMentionAvailableRuntimes ( ) ;
149130 const ensureManagedAgentMentionsReady = React . useCallback (
150131 async (
151132 mentionPubkeys : string [ ] ,
@@ -669,7 +650,11 @@ export function useMentionSendFlow({
669650 await finishSend ( uploaded , signal ) ;
670651 } catch ( error ) {
671652 restoreComposerAfterFailure ( ) ;
672- toast . error ( error instanceof AgentMentionAuthorizationError ? error . message : formatMessageSendError ( error ) ) ;
653+ toast . error (
654+ error instanceof AgentMentionAuthorizationError
655+ ? error . message
656+ : formatMessageSendError ( error ) ,
657+ ) ;
673658 } finally {
674659 settleUpload ( ) ;
675660 }
@@ -697,7 +682,11 @@ export function useMentionSendFlow({
697682 await finishSend ( [ ] ) ;
698683 } catch ( error ) {
699684 restoreComposerAfterFailure ( ) ;
700- toast . error ( error instanceof AgentMentionAuthorizationError ? error . message : formatMessageSendError ( error ) ) ;
685+ toast . error (
686+ error instanceof AgentMentionAuthorizationError
687+ ? error . message
688+ : formatMessageSendError ( error ) ,
689+ ) ;
701690 }
702691 }
703692 } catch ( error ) {
@@ -762,20 +751,22 @@ export function useMentionSendFlow({
762751 }
763752 isMentionSendPendingRef . current = true ;
764753 setIsMentionSendPending ( true ) ;
765- // Capture exact selections before any async preparation can navigate the
766- // reused editor to another draft (possibly with identical display text).
767- claimDraftSend ( effectiveDraftKey ) ;
768- const composerRevision = getComposerRevision ( ) ;
769- const savedMentionRefs = mentions . getDraftMentionRefs ( trimmed ) . slice ( ) ;
770- const selectedMentionPubkeys = mentions . extractMentionPubkeys ( trimmed ) ;
771- const selectedPersonas = mentions . extractMentionPersonas ( trimmed ) ;
772- const isSendCancelled = ( ) =>
773- preparedLinkPreviews ?. signal . aborted === true ;
774754 let sendPromoted = false ;
775- if ( preparedLinkPreviews ) {
776- activePreparedLinkPreviews . add ( preparedLinkPreviews ) ;
777- }
778755 try {
756+ // Capture exact selections before any async preparation can navigate the
757+ // reused editor to another draft (possibly with identical display text).
758+ // Ambiguous-name extraction can throw; it owns the same visible failure
759+ // and pending-state cleanup as the asynchronous preparation below.
760+ claimDraftSend ( effectiveDraftKey ) ;
761+ const composerRevision = getComposerRevision ( ) ;
762+ const savedMentionRefs = mentions . getDraftMentionRefs ( trimmed ) . slice ( ) ;
763+ const selectedMentionPubkeys = mentions . extractMentionPubkeys ( trimmed ) ;
764+ const selectedPersonas = mentions . extractMentionPersonas ( trimmed ) ;
765+ const isSendCancelled = ( ) =>
766+ preparedLinkPreviews ?. signal . aborted === true ;
767+ if ( preparedLinkPreviews ) {
768+ activePreparedLinkPreviews . add ( preparedLinkPreviews ) ;
769+ }
779770 if ( isSendCancelled ( ) ) return ;
780771 const dmThreadAgentMentionErrorMessage = dmThreadAgentMentionError ( {
781772 trimmed,
0 commit comments