Implementation:Langgenius Dify InstallPlugin
| Knowledge Sources | |
|---|---|
| Domains | Plugin Management Installation Task Management |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for installing plugins from marketplace, GitHub, or local packages provided by the Dify plugin service layer.
Description
This module provides five API functions that cover the full installation workflow. updateFromMarketPlace triggers a marketplace-based installation (or upgrade) by posting plugin identifiers to the backend. uploadFile handles local .difypkg or bundle file uploads via multipart form data using XMLHttpRequest. uploadGitHub submits a GitHub repository URL along with a release version and package name. After any of these operations, fetchPluginTasks retrieves the list of all active installation tasks for the workspace, and checkTaskStatus polls a specific task by ID to track its progress through pending, running, success, or failed states.
Usage
Use these functions when:
- Implementing the marketplace install button that triggers a one-click installation.
- Building a GitHub import dialog that lets users specify a repo, version, and package.
- Handling drag-and-drop or file-picker uploads of local .difypkg files.
- Displaying installation progress with polling-based status updates.
- Managing bundle installations where multiple plugins are installed as a group.
Code Reference
Source Location
- Repository: Dify
- File:
web/service/plugins.ts(lines 20-98)
Signature
// Install or upgrade from the marketplace
export const updateFromMarketPlace = async (
body: Record<string, string>
): Promise<InstallPackageResponse>
// POST /workspaces/current/plugin/upgrade/marketplace
// Upload a local plugin package or bundle
export const uploadFile = async (
file: File,
isBundle: boolean
): void
// POST /workspaces/current/plugin/upload/{pkg|bundle} (multipart)
// Upload from a GitHub release
export const uploadGitHub = async (
repoUrl: string,
selectedVersion: string,
selectedPackage: string
): Promise<uploadGitHubResponse>
// POST /workspaces/current/plugin/upload/github
// Fetch all active plugin tasks for the workspace
export const fetchPluginTasks = async (): Promise<PluginTasksResponse>
// GET /workspaces/current/plugin/tasks?page=1&page_size=255
// Check the status of a specific installation task
export const checkTaskStatus = async (
taskId: string
): Promise<TaskStatusResponse>
// GET /workspaces/current/plugin/tasks/{taskId}
Import
import {
uploadFile,
uploadGitHub,
updateFromMarketPlace,
fetchPluginTasks,
checkTaskStatus,
} from '@/service/plugins'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| body | Record<string, string> | Yes (marketplace) | Object containing original_plugin_unique_identifier and new_plugin_unique_identifier for marketplace install/upgrade |
| file | File | Yes (local) | The .difypkg or bundle file to upload |
| isBundle | boolean | Yes (local) | Whether the file is a bundle (multiple plugins) or a single package |
| repoUrl | string | Yes (GitHub) | Full URL of the GitHub repository |
| selectedVersion | string | Yes (GitHub) | Release tag or version string to install |
| selectedPackage | string | Yes (GitHub) | Name of the package file within the release |
| taskId | string | Yes (polling) | Unique identifier of the installation task to check |
Outputs
| Name | Type | Description |
|---|---|---|
| InstallPackageResponse | object | Contains task_id and status information for the initiated installation |
| uploadGitHubResponse | object | Contains unique_identifier and manifest information for the uploaded GitHub plugin |
| PluginTasksResponse | object | Contains an array of active tasks with their IDs, statuses, and associated plugin identifiers |
| TaskStatusResponse | object | Contains the current status (pending, running, success, failed), progress details, and any error messages for a specific task |
Dependencies
| Dependency | Purpose |
|---|---|
@/service/base (post) |
HTTP POST requests for installation commands |
@/service/base (upload) |
Multipart file upload with XMLHttpRequest |
@/service/base (get) |
HTTP GET requests for task polling |
Usage Examples
import {
updateFromMarketPlace,
uploadFile,
uploadGitHub,
fetchPluginTasks,
checkTaskStatus,
} from '@/service/plugins'
// 1. Install from the marketplace
const installResult = await updateFromMarketPlace({
original_plugin_unique_identifier: '',
new_plugin_unique_identifier: 'langgenius/google-search/0.2.0',
})
// 2. Upload a local .difypkg file
const fileInput = document.querySelector<HTMLInputElement>('#plugin-file')
if (fileInput?.files?.[0]) {
await uploadFile(fileInput.files[0], false) // single package, not a bundle
}
// 3. Install from GitHub
const githubResult = await uploadGitHub(
'https://github.com/langgenius/dify-plugin-google-search',
'v0.2.0',
'google-search.difypkg',
)
// 4. Poll for installation completion
const tasks = await fetchPluginTasks()
for (const task of tasks.tasks) {
let status = await checkTaskStatus(task.id)
while (status.status === 'pending' || status.status === 'running') {
await new Promise(resolve => setTimeout(resolve, 2000))
status = await checkTaskStatus(task.id)
}
console.log(`Task ${task.id}: ${status.status}`)
}