chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动

演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-18 13:59:25 +08:00
1 parent 60158935f4
commit 6519682885
15831 files changed
+3063428

No files matched your search

@@ -0,0 +1,86 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import { TaskStatus } from '../../../types'
import checkTaskStatus from '../check-task-status'
const { fetchTask } = vi.hoisted(() => ({ fetchTask: vi.fn() }))
vi.mock('@/service/plugins', () => ({ checkTaskStatus: fetchTask }))
const task = (status: TaskStatus) => ({
task: {
plugins: [
{
plugin_unique_identifier: 'other-plugin',
status: TaskStatus.failed,
message: 'Unrelated failure',
},
{ plugin_unique_identifier: 'test-plugin', status, message: '' },
],
},
})
const params = { taskId: 'task-1', pluginUniqueIdentifier: 'test-plugin' }
describe('checkTaskStatus', () => {
beforeEach(() => {
vi.resetAllMocks()
vi.useFakeTimers()
})
afterEach(() => vi.useRealTimers())
it('fails when the requested package is absent from the task', async () => {
fetchTask.mockResolvedValue({
task: { plugins: [{ plugin_unique_identifier: 'other-plugin', status: TaskStatus.success }] },
})
await expect(checkTaskStatus().check(params)).resolves.toEqual({
status: TaskStatus.failed,
error: 'Plugin package not found',
})
})
it('follows the requested package through pending and running until success', async () => {
fetchTask
.mockResolvedValueOnce(task(TaskStatus.pending))
.mockResolvedValueOnce(task(TaskStatus.running))
.mockResolvedValueOnce(task(TaskStatus.success))
const completed = vi.fn()
const result = checkTaskStatus().check(params).then(completed)
await vi.advanceTimersByTimeAsync(0)
expect(fetchTask).toHaveBeenCalledExactlyOnceWith('task-1')
expect(completed).not.toHaveBeenCalled()
await vi.advanceTimersByTimeAsync(10_000)
expect(fetchTask).toHaveBeenCalledTimes(2)
expect(completed).not.toHaveBeenCalled()
await vi.advanceTimersByTimeAsync(10_000)
await result
expect(fetchTask).toHaveBeenNthCalledWith(3, 'task-1')
expect(completed).toHaveBeenCalledExactlyOnceWith({ status: TaskStatus.success })
})
it('stops one checker before its first request without stopping another installation', async () => {
fetchTask.mockResolvedValue(task(TaskStatus.success))
const stopped = checkTaskStatus()
const active = checkTaskStatus()
stopped.stop()
await expect(stopped.check(params)).resolves.toEqual({ status: TaskStatus.success })
expect(fetchTask).not.toHaveBeenCalled()
await expect(active.check({ ...params, taskId: 'task-2' })).resolves.toEqual({
status: TaskStatus.success,
})
expect(fetchTask).toHaveBeenCalledExactlyOnceWith('task-2')
})
it('does not fetch again when stopped during the polling interval', async () => {
fetchTask.mockResolvedValue(task(TaskStatus.running))
const checker = checkTaskStatus()
const result = checker.check(params)
await vi.advanceTimersByTimeAsync(0)
checker.stop()
await vi.advanceTimersByTimeAsync(10_000)
await expect(result).resolves.toEqual({ status: TaskStatus.success })
expect(fetchTask).toHaveBeenCalledExactlyOnceWith('task-1')
})
})
@@ -0,0 +1,59 @@
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { renderWithConsoleQuery as render } from '@/test/console/query-data'
import { createPluginDeclarationFixture } from '@/test/fixtures/plugin'
import { PluginCategoryEnum } from '../../../types'
import Installed from '../installed'
it('closes without a navigation link when installation matches the current category', async () => {
const user = userEvent.setup()
const onCancel = vi.fn()
render(
<Installed
payload={createPluginDeclarationFixture({ category: PluginCategoryEnum.extension })}
installContextCategory={PluginCategoryEnum.extension}
isFailed={false}
onCancel={onCancel}
/>,
)
expect(
screen.queryByRole('link', { name: 'plugin.installModal.viewDetails' }),
).not.toBeInTheDocument()
await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
expect(onCancel).toHaveBeenCalledOnce()
})
it('links to the installed category after success but keeps failures in the current context', async () => {
const user = userEvent.setup()
const onCancel = vi.fn()
const payload = createPluginDeclarationFixture({ category: PluginCategoryEnum.extension })
const { rerender } = render(
<Installed
payload={payload}
installContextCategory={PluginCategoryEnum.trigger}
isFailed={false}
onCancel={onCancel}
/>,
)
const details = screen.getByRole('link', { name: 'plugin.installModal.viewDetails' })
expect(details).toHaveAttribute('href', '/integrations/extension')
await user.click(details)
expect(onCancel).toHaveBeenCalledOnce()
rerender(
<Installed
payload={payload}
installContextCategory={PluginCategoryEnum.trigger}
isFailed
errMsg="Package verification failed"
onCancel={onCancel}
/>,
)
expect(screen.getByText('Package verification failed')).toBeInTheDocument()
expect(
screen.queryByRole('link', { name: 'plugin.installModal.viewDetails' }),
).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'common.operation.close' })).toBeEnabled()
})
@@ -0,0 +1,61 @@
import { checkTaskStatus as fetchCheckTaskStatus } from '@/service/plugins'
import { sleep } from '@/utils'
import { TaskStatus } from '../../types'
const INTERVAL = 10 * 1000 // 10 seconds
const isUnfinishedStatus = (status: TaskStatus) =>
status === TaskStatus.pending || status === TaskStatus.running
type Params = {
taskId: string
pluginUniqueIdentifier: string
}
function checkTaskStatus() {
let nextStatus: TaskStatus = TaskStatus.running
let isStop = false
const doCheckStatus = async ({ taskId, pluginUniqueIdentifier }: Params) => {
if (isStop) {
return {
status: TaskStatus.success,
}
}
const res = await fetchCheckTaskStatus(taskId)
const { plugins } = res.task
const plugin = plugins.find((p) => p.plugin_unique_identifier === pluginUniqueIdentifier)
if (!plugin) {
nextStatus = TaskStatus.failed
return {
status: TaskStatus.failed,
error: 'Plugin package not found',
}
}
nextStatus = plugin.status
if (isUnfinishedStatus(nextStatus)) {
await sleep(INTERVAL)
return await doCheckStatus({
taskId,
pluginUniqueIdentifier,
})
}
if (nextStatus === TaskStatus.failed) {
return {
status: TaskStatus.failed,
error: plugin.message,
}
}
return {
status: TaskStatus.success,
}
}
return {
check: doCheckStatus,
stop: () => {
isStop = true
},
}
}
export default checkTaskStatus
@@ -0,0 +1,156 @@
'use client'
import type { FC } from 'react'
import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../../types'
import { Button, buttonVariants } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
import * as React from 'react'
import { Trans, useTranslation } from 'react-i18next'
import Badge from '@/app/components/base/badge/index'
import { buildIntegrationPath } from '@/app/components/integrations/routes'
import Link from '@/next/link'
import Card from '../../card'
import { PluginCategoryEnum } from '../../types'
import { pluginManifestInMarketToPluginProps, pluginManifestToCardPluginProps } from '../utils'
type Props = Readonly<{
payload?: Plugin | PluginDeclaration | PluginManifestInMarket | null
isMarketPayload?: boolean
isFailed: boolean
errMsg?: string | null
installContextCategory?: PluginCategoryEnum
onCancel: () => void
}>
type CategoryTarget = {
labelKey:
| 'menus.tools'
| 'settings.agentStrategy'
| 'settings.dataSource'
| 'settings.extension'
| 'settings.provider'
| 'settings.trigger'
path: string
}
const categoryTargetMap: Partial<Record<PluginCategoryEnum, CategoryTarget>> = {
[PluginCategoryEnum.model]: {
labelKey: 'settings.provider',
path: buildIntegrationPath('provider'),
},
[PluginCategoryEnum.tool]: {
labelKey: 'menus.tools',
path: buildIntegrationPath('builtin'),
},
[PluginCategoryEnum.datasource]: {
labelKey: 'settings.dataSource',
path: buildIntegrationPath('data-source'),
},
[PluginCategoryEnum.trigger]: {
labelKey: 'settings.trigger',
path: buildIntegrationPath('trigger'),
},
[PluginCategoryEnum.agent]: {
labelKey: 'settings.agentStrategy',
path: buildIntegrationPath('agent-strategy'),
},
[PluginCategoryEnum.extension]: {
labelKey: 'settings.extension',
path: buildIntegrationPath('extension'),
},
}
const Installed: FC<Props> = ({
payload,
isMarketPayload,
isFailed,
errMsg,
installContextCategory,
onCancel,
}) => {
const { t } = useTranslation(['plugin', 'common', 'navigation'])
const installedCategory = payload?.category
const categoryTarget =
!isFailed && installContextCategory && installedCategory !== installContextCategory
? categoryTargetMap[installedCategory as PluginCategoryEnum]
: undefined
const categoryName = categoryTarget
? t(($) => $[categoryTarget.labelKey], { ns: 'navigation' })
: ''
const handleClose = () => {
onCancel()
}
return (
<>
<div className="flex min-h-0 min-w-0 flex-col items-start justify-center gap-2 self-stretch overflow-x-hidden overflow-y-auto px-6 py-3">
<p
className={cn(
'w-full max-w-full min-w-0 system-md-regular text-text-secondary',
isFailed && 'wrap-anywhere whitespace-pre-wrap',
)}
>
{isFailed && errMsg ? (
errMsg
) : categoryTarget ? (
<Trans
t={t}
i18nKey={($) => $['installModal.installedSuccessfullyWithPageDesc']}
ns="plugin"
components={{
categoryName: <span className="system-sm-semibold text-text-secondary" />,
}}
values={{ categoryName }}
/>
) : (
t(
($) =>
$[`installModal.${isFailed ? 'installFailedDesc' : 'installedSuccessfullyDesc'}`],
{ ns: 'plugin' },
)
)}
</p>
{payload && (
<div className="flex flex-wrap content-start items-start gap-1 self-stretch rounded-2xl bg-background-section-burn p-2">
<Card
className="w-full"
payload={
isMarketPayload
? pluginManifestInMarketToPluginProps(payload as PluginManifestInMarket)
: pluginManifestToCardPluginProps(payload as PluginDeclaration)
}
installed={!isFailed}
installFailed={isFailed}
titleLeft={
<Badge className="mx-1" size="s">
{(payload as PluginDeclaration).version ||
(payload as PluginManifestInMarket).latest_version}
</Badge>
}
compact
/>
</div>
)}
</div>
{/* Action Buttons */}
<div className="flex shrink-0 items-center justify-end gap-2 self-stretch p-6 pt-5">
{categoryTarget ? (
<Link
href={categoryTarget.path}
className={cn(buttonVariants({ variant: 'primary' }), 'min-w-18')}
onClick={handleClose}
>
<>
<span>{t(($) => $['installModal.viewDetails'], { ns: 'plugin' })}</span>
<span className="i-ri-arrow-right-up-line size-4 shrink-0" aria-hidden="true" />
</>
</Link>
) : (
<Button variant="primary" className="min-w-18" onClick={handleClose}>
{t(($) => $['operation.close'], { ns: 'common' })}
</Button>
)}
</div>
</>
)
}
export default React.memo(Installed)
@@ -0,0 +1,41 @@
'use client'
import type { FC } from 'react'
import { CheckboxSkeleton } from '@langgenius/dify-ui/checkbox'
import { RiCloseLine } from '@remixicon/react'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { LoadingPlaceholder } from '@/app/components/plugins/card/base/placeholder'
const LoadingError: FC = () => {
const { t } = useTranslation(['plugin'])
return (
<div className="flex items-center space-x-2">
<CheckboxSkeleton className="shrink-0" />
<div className="relative grow rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg p-4 pb-3 shadow-xs">
<div className="flex">
<div className="relative flex h-10 w-10 items-center justify-center gap-2 rounded-[10px] border-[0.5px] border-state-destructive-border bg-state-destructive-hover p-1 backdrop-blur-xs">
<div className="flex size-5 items-center justify-center">
<span
aria-hidden
className="i-custom-vender-other-group h-4 w-3.5 text-text-quaternary"
/>
</div>
<div className="absolute -right-1 -bottom-1 rounded-full border-2 border-components-panel-bg bg-state-destructive-solid">
<RiCloseLine className="size-3 text-text-primary-on-surface" />
</div>
</div>
<div className="ml-3 grow">
<div className="flex h-5 items-center system-md-semibold text-text-destructive">
{t(($) => $['installModal.pluginLoadError'], { ns: 'plugin' })}
</div>
<div className="mt-0.5 system-xs-regular text-text-tertiary">
{t(($) => $['installModal.pluginLoadErrorDesc'], { ns: 'plugin' })}
</div>
</div>
</div>
<LoadingPlaceholder className="mt-3 w-105" />
</div>
</div>
)
}
export default React.memo(LoadingError)
@@ -0,0 +1,17 @@
'use client'
import { CheckboxSkeleton } from '@langgenius/dify-ui/checkbox'
import * as React from 'react'
import Placeholder from '../../card/base/placeholder'
const Loading = () => {
return (
<div className="flex items-center space-x-2">
<CheckboxSkeleton className="shrink-0" />
<div className="relative grow rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg p-4 pb-3 shadow-xs">
<Placeholder wrapClassName="w-full" />
</div>
</div>
)
}
export default React.memo(Loading)
@@ -0,0 +1,20 @@
import { useAtomValue } from 'jotai'
import { useCallback } from 'react'
import { API_PREFIX } from '@/config'
import { currentWorkspaceIdAtom } from '@/context/workspace-state'
const useGetIcon = () => {
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom)
const getIconUrl = useCallback(
(fileName: string) => {
return `${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=${currentWorkspaceId}&filename=${fileName}`
},
[currentWorkspaceId],
)
return {
getIconUrl,
}
}
export default useGetIcon
@@ -0,0 +1,28 @@
'use client'
import type { FC } from 'react'
import type { VersionProps } from '../../types'
import * as React from 'react'
import Badge from '@/app/components/base/badge/index'
const Version: FC<VersionProps> = ({ hasInstalled, installedVersion, toInstallVersion }) => {
return (
<>
{!hasInstalled ? (
<Badge className="mx-1" size="s">
{toInstallVersion}
</Badge>
) : (
<>
<Badge className="mx-1" size="s" variant="warning">
{`${installedVersion} -> ${toInstallVersion}`}
</Badge>
{/* <div className='flex px-0.5 justify-center items-center gap-0.5'>
<div className='text-text-warning system-xs-medium'>Used in 3 apps</div>
<RiInformation2Line className='w-4 h-4 text-text-tertiary' />
</div> */}
</>
)}
</>
)
}
export default React.memo(Version)