| 34 | }; |
| 35 | |
| 36 | export function usePlanReadyActions({ |
| 37 | activeWorkspace, |
| 38 | activeThreadId, |
| 39 | collaborationModes, |
| 40 | resolvedModel, |
| 41 | resolvedEffort, |
| 42 | connectWorkspace, |
| 43 | sendUserMessageToThread, |
| 44 | setSelectedCollaborationModeId, |
| 45 | persistThreadCodexParams, |
| 46 | }: UsePlanReadyActionsOptions) { |
| 47 | const findCollaborationMode = useCallback( |
| 48 | (wanted: string) => { |
| 49 | const normalized = wanted.trim().toLowerCase(); |
| 50 | if (!normalized) { |
| 51 | return null; |
| 52 | } |
| 53 | return ( |
| 54 | collaborationModes.find( |
| 55 | (mode) => mode.id.trim().toLowerCase() === normalized, |
| 56 | ) ?? |
| 57 | collaborationModes.find( |
| 58 | (mode) => (mode.mode || mode.id).trim().toLowerCase() === normalized, |
| 59 | ) ?? |
| 60 | null |
| 61 | ); |
| 62 | }, |
| 63 | [collaborationModes], |
| 64 | ); |
| 65 | |
| 66 | const isPlanMode = useCallback((mode: CollaborationModeOption | null) => { |
| 67 | if (!mode) { |
| 68 | return false; |
| 69 | } |
| 70 | const modeValue = (mode.mode || mode.id).trim().toLowerCase(); |
| 71 | return modeValue === "plan"; |
| 72 | }, []); |
| 73 | |
| 74 | const findImplementationMode = useCallback(() => { |
| 75 | const defaultMode = findCollaborationMode("default"); |
| 76 | if (defaultMode && !isPlanMode(defaultMode)) { |
| 77 | return defaultMode; |
| 78 | } |
| 79 | |
| 80 | const codeMode = findCollaborationMode("code"); |
| 81 | if (codeMode && !isPlanMode(codeMode)) { |
| 82 | return codeMode; |
| 83 | } |
| 84 | |
| 85 | return collaborationModes.find((mode) => !isPlanMode(mode)) ?? null; |
| 86 | }, [collaborationModes, findCollaborationMode, isPlanMode]); |
| 87 | |
| 88 | const buildCollaborationModePayloadFor = useCallback( |
| 89 | (mode: CollaborationModeOption | null) => { |
| 90 | if (!mode) { |
| 91 | return null; |
| 92 | } |
| 93 | |