Implementation:Langgenius Dify UninstallPlugin
| Knowledge Sources | Dify |
|---|---|
| Domains | Plugin_System, Marketplace, Frontend |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Description
The UninstallPlugin module in web/service/plugins.ts provides the imperative service functions for managing the post-installation lifecycle of plugins: uninstallation, task listing, and task status checking. These three functions form the terminal phase of the plugin lifecycle:
- uninstallPlugin -- Removes an installed plugin from the workspace by posting its
plugin_installation_idto the uninstall endpoint. - fetchPluginTasks -- Retrieves a paginated list of all plugin installation/upgrade tasks for the workspace, used to populate the task progress panel.
- checkTaskStatus -- Checks the current status of a specific task by its
taskId, used for polling individual task progress.
These functions are consumed both directly by UI event handlers and indirectly by the usePluginTaskList React Query hook which implements automatic polling and plugin list refresh on task completion.
Usage
These functions are called when a user uninstalls a plugin from the plugin management interface, or when the frontend needs to track the progress of ongoing installation/upgrade tasks.
Code Reference
Source Location
web/service/plugins.ts (Lines 92--106)
Signature
export const fetchPluginTasks = async () => {
return get<PluginTasksResponse>('/workspaces/current/plugin/tasks?page=1&page_size=255')
}
export const checkTaskStatus = async (taskId: string) => {
return get<TaskStatusResponse>(`/workspaces/current/plugin/tasks/${taskId}`)
}
export const uninstallPlugin = async (pluginId: string) => {
return post<UninstallPluginResponse>(
'/workspaces/current/plugin/uninstall',
{ body: { plugin_installation_id: pluginId } },
)
}
Import
import { fetchPluginTasks, checkTaskStatus, uninstallPlugin } from '@/service/plugins'
I/O Contract
uninstallPlugin
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | pluginId | string |
The plugin_installation_id identifying the installed plugin instance
|
| Output | (response) | UninstallPluginResponse |
Confirmation of uninstallation with status |
fetchPluginTasks
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | (none) | -- | No parameters; fetches page 1 with up to 255 tasks |
| Output | tasks | PluginTask[] |
Array of task objects with id, status, plugin info, and timestamps |
checkTaskStatus
| Direction | Field | Type | Description |
|---|---|---|---|
| Input | taskId | string |
The unique identifier of the task to check |
| Output | (response) | TaskStatusResponse |
The current status of the task (running, success, or failed) with details |
Usage Examples
Uninstalling a plugin
import { uninstallPlugin } from '@/service/plugins'
async function handleUninstall(installationId: string) {
const response = await uninstallPlugin(installationId)
// Refresh the installed plugins list after uninstall
invalidateInstalledPluginList()
}
Polling task status after installation
import { checkTaskStatus } from '@/service/plugins'
async function pollUntilComplete(taskId: string): Promise<TaskStatusResponse> {
const status = await checkTaskStatus(taskId)
if (status.status === 'running') {
await new Promise(resolve => setTimeout(resolve, 5000))
return pollUntilComplete(taskId)
}
return status
}
Fetching all active tasks for the progress panel
import { fetchPluginTasks } from '@/service/plugins'
const { tasks } = await fetchPluginTasks()
const activeTasks = tasks.filter(t => t.status === 'running')
const completedTasks = tasks.filter(t => t.status === 'success')
const failedTasks = tasks.filter(t => t.status === 'failed')
Using the usePluginTaskList hook for automatic polling
import { usePluginTaskList } from '@/service/use-plugins'
function TaskPanel() {
const { pluginTasks, isFetched } = usePluginTaskList()
// The hook automatically polls every 5 seconds while tasks are running
// and refreshes the plugin list when all tasks complete
return (
<ul>
{pluginTasks.map(task => (
<li key={task.id}>{task.plugin_id}: {task.status}</li>
))}
</ul>
)
}