* Add errors to AppState, deduplicating to avoid showing the same error multiple times
( setAppState: (updater: (prev: AppState) => AppState) => void, newErrors: PluginError[], )
| 101 | * Add errors to AppState, deduplicating to avoid showing the same error multiple times |
| 102 | */ |
| 103 | function addErrorsToAppState( |
| 104 | setAppState: (updater: (prev: AppState) => AppState) => void, |
| 105 | newErrors: PluginError[], |
| 106 | ): void { |
| 107 | if (newErrors.length === 0) return |
| 108 | |
| 109 | setAppState(prevState => { |
| 110 | // Build set of existing error keys |
| 111 | const existingKeys = new Set( |
| 112 | prevState.plugins.errors.map(e => getErrorKey(e)), |
| 113 | ) |
| 114 | |
| 115 | // Only add errors that don't already exist |
| 116 | const uniqueNewErrors = newErrors.filter( |
| 117 | error => !existingKeys.has(getErrorKey(error)), |
| 118 | ) |
| 119 | |
| 120 | if (uniqueNewErrors.length === 0) { |
| 121 | return prevState |
| 122 | } |
| 123 | |
| 124 | return { |
| 125 | ...prevState, |
| 126 | plugins: { |
| 127 | ...prevState.plugins, |
| 128 | errors: [...prevState.plugins.errors, ...uniqueNewErrors], |
| 129 | }, |
| 130 | } |
| 131 | }) |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Hook to manage MCP (Model Context Protocol) server connections and updates |
no test coverage detected