chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,181 @@
|
||||
import type { IntegrationSection } from '@/app/components/integrations/routes'
|
||||
import type { IntegrationSidebarNavItemData } from '@/app/components/integrations/sidebar-nav-item'
|
||||
import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PluginCategoryEnum } from '@/app/components/plugins/types'
|
||||
import { STEP_BY_STEP_TOUR_TARGETS } from '@/app/components/step-by-step-tour/target-registry'
|
||||
|
||||
export type IntegrationHeader = {
|
||||
description: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export const getPluginCategoryBySection = (section: IntegrationSection) => {
|
||||
if (section === 'builtin') return PluginCategoryEnum.tool
|
||||
if (section === 'trigger') return PluginCategoryEnum.trigger
|
||||
if (section === 'agent-strategy') return PluginCategoryEnum.agent
|
||||
if (section === 'extension') return PluginCategoryEnum.extension
|
||||
}
|
||||
|
||||
export function useIntegrationNav(section: IntegrationSection) {
|
||||
const { t } = useTranslation(['common', 'plugin', 'workflow', 'navigation'])
|
||||
const providerItem = useMemo<IntegrationSidebarNavItemData>(
|
||||
() => ({
|
||||
section: 'provider',
|
||||
label: t(($) => $['settings.provider'], { ns: 'navigation' }),
|
||||
icon: 'i-ri-brain-2-line',
|
||||
stepByStepTourTarget: STEP_BY_STEP_TOUR_TARGETS.integrationModelProviderNav,
|
||||
}),
|
||||
[t],
|
||||
)
|
||||
const dataSourceItem = useMemo<IntegrationSidebarNavItemData>(
|
||||
() => ({
|
||||
section: 'data-source',
|
||||
label: t(($) => $['settings.dataSource'], { ns: 'navigation' }),
|
||||
icon: 'i-ri-database-2-line',
|
||||
iconClassName: 'size-4',
|
||||
stepByStepTourTarget: STEP_BY_STEP_TOUR_TARGETS.integrationDataSourceNav,
|
||||
}),
|
||||
[t],
|
||||
)
|
||||
const customEndpointItem = useMemo<IntegrationSidebarNavItemData>(
|
||||
() => ({
|
||||
section: 'custom-endpoint',
|
||||
label: t(($) => $['settings.customEndpoint'], { ns: 'navigation' }),
|
||||
icon: 'i-custom-vender-integrations-api-extension',
|
||||
iconClassName: 'h-[13px] w-3.5',
|
||||
}),
|
||||
[t],
|
||||
)
|
||||
const toolItems = useMemo<IntegrationSidebarNavItemData[]>(() => {
|
||||
const items: IntegrationSidebarNavItemData[] = [
|
||||
{
|
||||
section: 'builtin',
|
||||
label: t(($) => $['toolsPage.toolPlugin'], { ns: 'navigation' }),
|
||||
icon: 'i-custom-vender-integrations-tools',
|
||||
iconClassName: 'h-[14px] w-[12.5px]',
|
||||
className: 'pl-8',
|
||||
stepByStepTourTarget: STEP_BY_STEP_TOUR_TARGETS.integrationToolPluginNav,
|
||||
},
|
||||
]
|
||||
|
||||
items.push(
|
||||
{
|
||||
section: 'mcp',
|
||||
label: 'MCP',
|
||||
icon: 'i-custom-vender-integrations-mcp',
|
||||
iconClassName: 'h-[14.5px] w-[13.5px]',
|
||||
className: 'pl-8',
|
||||
stepByStepTourTarget: STEP_BY_STEP_TOUR_TARGETS.integrationMcpNav,
|
||||
},
|
||||
{
|
||||
section: 'workflow-tool',
|
||||
label: t(($) => $['common.workflowAsTool'], { ns: 'navigation' }),
|
||||
icon: 'i-custom-vender-integrations-workflow-as-tool',
|
||||
iconClassName: 'size-4',
|
||||
className: 'pl-8',
|
||||
},
|
||||
{
|
||||
section: 'custom-tool',
|
||||
label: t(($) => $['settings.swaggerAPIAsTool'], { ns: 'navigation' }),
|
||||
icon: 'i-custom-vender-integrations-custom-tool',
|
||||
iconClassName: 'h-[14.5px] w-[12.5px]',
|
||||
className: 'pl-8',
|
||||
},
|
||||
)
|
||||
|
||||
return items
|
||||
}, [t])
|
||||
const secondaryItems = useMemo<IntegrationSidebarNavItemData[]>(
|
||||
() => [
|
||||
{
|
||||
section: 'trigger',
|
||||
label: t(($) => $['categorySingle.trigger'], { ns: 'plugin' }),
|
||||
icon: 'i-custom-vender-integrations-trigger',
|
||||
iconClassName: 'h-[13.5px] w-[13.5px]',
|
||||
stepByStepTourTarget: STEP_BY_STEP_TOUR_TARGETS.integrationTriggerNav,
|
||||
},
|
||||
{
|
||||
section: 'agent-strategy',
|
||||
label: t(($) => $['categorySingle.agent'], { ns: 'plugin' }),
|
||||
icon: 'i-custom-vender-integrations-agent-strategy',
|
||||
iconClassName: 'h-[14.5px] w-[15.5px]',
|
||||
},
|
||||
{
|
||||
section: 'extension',
|
||||
label: t(($) => $['categorySingle.extension'], { ns: 'plugin' }),
|
||||
icon: 'i-custom-vender-integrations-extension',
|
||||
iconClassName: 'h-[13.5px] w-3',
|
||||
},
|
||||
],
|
||||
[t],
|
||||
)
|
||||
const activeItem = [
|
||||
providerItem,
|
||||
dataSourceItem,
|
||||
...toolItems,
|
||||
...secondaryItems,
|
||||
customEndpointItem,
|
||||
].find((item) => item.section === section)
|
||||
const integrationHeader = useMemo<IntegrationHeader | null>(() => {
|
||||
switch (section) {
|
||||
case 'builtin':
|
||||
return {
|
||||
title: t(($) => $['toolsPage.toolPlugin'], { ns: 'navigation' }),
|
||||
description: t(($) => $['toolsPage.description'], { ns: 'navigation' }),
|
||||
}
|
||||
case 'mcp':
|
||||
return {
|
||||
title: 'MCP',
|
||||
description: t(($) => $['mcpPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'custom-tool':
|
||||
return {
|
||||
title: t(($) => $['settings.swaggerAPIAsTool'], { ns: 'navigation' }),
|
||||
description: t(($) => $['swaggerAPIAsToolPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'workflow-tool':
|
||||
return {
|
||||
title: t(($) => $['common.workflowAsTool'], { ns: 'navigation' }),
|
||||
description: t(($) => $['workflowAsToolPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'custom-endpoint':
|
||||
return {
|
||||
title: t(($) => $['settings.customEndpoint'], { ns: 'navigation' }),
|
||||
description: t(($) => $['apiBasedExtensionPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'data-source':
|
||||
return {
|
||||
title: t(($) => $['settings.dataSource'], { ns: 'navigation' }),
|
||||
description: t(($) => $['dataSourcePage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'trigger':
|
||||
return {
|
||||
title: t(($) => $['categorySingle.trigger'], { ns: 'plugin' }),
|
||||
description: t(($) => $['triggerPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'extension':
|
||||
return {
|
||||
title: t(($) => $['categorySingle.extension'], { ns: 'plugin' }),
|
||||
description: t(($) => $['extensionPage.description'], { ns: 'common' }),
|
||||
}
|
||||
case 'agent-strategy':
|
||||
return {
|
||||
title: t(($) => $['categorySingle.agent'], { ns: 'plugin' }),
|
||||
description: t(($) => $['agentStrategyPage.description'], { ns: 'common' }),
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}, [section, t])
|
||||
|
||||
return {
|
||||
activeItem,
|
||||
customEndpointItem,
|
||||
dataSourceItem,
|
||||
integrationHeader,
|
||||
providerItem,
|
||||
secondaryItems,
|
||||
toolItems,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { PermissionSettingKey } from '../permission-quick-panel'
|
||||
import type { IntegrationSection } from '@/app/components/integrations/routes'
|
||||
import type { PermissionType } from '@/app/components/plugins/types'
|
||||
import { usePluginSettingsAccess } from '@/app/components/plugins/plugin-page/use-reference-setting'
|
||||
|
||||
const isPluginCategorySection = (section: IntegrationSection) => {
|
||||
return (
|
||||
section === 'builtin' ||
|
||||
section === 'trigger' ||
|
||||
section === 'agent-strategy' ||
|
||||
section === 'extension'
|
||||
)
|
||||
}
|
||||
|
||||
export function useIntegrationPermissions(section: IntegrationSection) {
|
||||
const {
|
||||
permission,
|
||||
canDebugger,
|
||||
canInstallPlugin,
|
||||
canDeletePlugin,
|
||||
canSetPluginPreferences,
|
||||
canSetPermissions,
|
||||
canUpdatePlugin,
|
||||
isPermissionLoading,
|
||||
permissionError,
|
||||
setPluginPermissionSettings,
|
||||
} = usePluginSettingsAccess()
|
||||
const isPluginCategory = isPluginCategorySection(section)
|
||||
const showPluginCategorySetting = isPluginCategory && canSetPluginPreferences
|
||||
const showPermissionQuickPanel = canSetPermissions && !!permission
|
||||
|
||||
const handlePermissionChange = (key: PermissionSettingKey, value: PermissionType) => {
|
||||
if (!permission) return
|
||||
|
||||
setPluginPermissionSettings({
|
||||
...permission,
|
||||
[key]: value,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
canDebugger,
|
||||
canInstallPlugin,
|
||||
canDeletePlugin,
|
||||
canSetPluginPreferences,
|
||||
canUpdatePlugin,
|
||||
canManagement: canInstallPlugin,
|
||||
handlePermissionChange,
|
||||
isPluginCategory,
|
||||
isReferenceSettingLoading: isPermissionLoading,
|
||||
permission,
|
||||
referenceSettingError: permissionError,
|
||||
showPermissionQuickPanel,
|
||||
showPluginCategorySetting,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { IntegrationSection } from '@/app/components/integrations/routes'
|
||||
import { parseAsStringLiteral, useQueryState } from 'nuqs'
|
||||
import {
|
||||
INTEGRATION_SECTION_VALUES,
|
||||
sectionByToolCategory,
|
||||
TOOL_CATEGORY_VALUES,
|
||||
} from '@/app/components/integrations/routes'
|
||||
|
||||
const parseAsIntegrationSection = parseAsStringLiteral(INTEGRATION_SECTION_VALUES)
|
||||
const parseAsToolCategory = parseAsStringLiteral(TOOL_CATEGORY_VALUES)
|
||||
|
||||
export function useIntegrationSection(routeSection?: IntegrationSection) {
|
||||
const [sectionParam] = useQueryState('section', parseAsIntegrationSection)
|
||||
const [categoryParam] = useQueryState('category', parseAsToolCategory)
|
||||
|
||||
return (
|
||||
routeSection ??
|
||||
sectionParam ??
|
||||
(categoryParam ? sectionByToolCategory[categoryParam] : 'provider')
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { ToolCategory } from '@/app/components/integrations/routes'
|
||||
import { parseAsStringLiteral, useQueryState } from 'nuqs'
|
||||
import { TOOL_CATEGORY_VALUES } from '@/app/components/integrations/routes'
|
||||
|
||||
const toolProviderCategorySet = new Set<string>(TOOL_CATEGORY_VALUES)
|
||||
|
||||
const isToolProviderCategory = (value: string): value is ToolCategory => {
|
||||
return toolProviderCategorySet.has(value)
|
||||
}
|
||||
|
||||
const parseAsToolProviderCategory =
|
||||
parseAsStringLiteral(TOOL_CATEGORY_VALUES).withDefault('builtin')
|
||||
|
||||
export function useToolProviderCategory(category?: ToolCategory) {
|
||||
const [categoryParam, setCategoryParam] = useQueryState('category', parseAsToolProviderCategory)
|
||||
const activeTab = category ?? categoryParam
|
||||
const isRouteCategory = !!category
|
||||
|
||||
const handleCategoryChange = (state: string, onCategoryChanged?: () => void) => {
|
||||
if (!isToolProviderCategory(state)) return
|
||||
|
||||
setCategoryParam(state)
|
||||
|
||||
if (state !== activeTab) onCategoryChanged?.()
|
||||
}
|
||||
|
||||
return {
|
||||
activeTab,
|
||||
handleCategoryChange,
|
||||
isRouteCategory,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user