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,136 @@
import type { TriggerEvent } from '@/app/components/plugins/types'
import type { TriggerProviderApiEntity } from '@/app/components/workflow/block-selector/types'
import { render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import { EventDetailDrawer } from '../event-detail-drawer'
vi.mock('@/app/components/header/account-setting/model-provider-page/hooks', () => ({
useLanguage: () => 'en_US',
}))
const mockEventInfo = {
name: 'test-event',
identity: {
author: 'test-author',
name: 'test-event',
label: { en_US: 'Test Event' },
},
description: { en_US: 'Test event description' },
parameters: [
{
name: 'param1',
label: { en_US: 'Parameter 1' },
type: 'text-input',
auto_generate: null,
template: null,
scope: null,
required: true,
multiple: false,
default: null,
min: null,
max: null,
precision: null,
description: { en_US: 'A test parameter' },
},
],
output_schema: {
properties: {
result: { type: 'string', description: 'Result' },
},
required: ['result'],
},
} as unknown as TriggerEvent
const mockProviderInfo = {
provider: 'test-provider',
author: 'test-author',
name: 'test-provider/test-name',
icon: 'icon.png',
description: { en_US: 'Provider desc' },
supported_creation_methods: [],
} as unknown as TriggerProviderApiEntity
describe('EventDetailDrawer', () => {
const onClose = vi.fn()
const renderEvent = (eventInfo = mockEventInfo) =>
render(
<EventDetailDrawer eventInfo={eventInfo} providerInfo={mockProviderInfo} onClose={onClose} />,
)
beforeEach(() => vi.clearAllMocks())
it('shows the event identity, provider, required parameters and output fields', () => {
renderEvent()
const drawer = within(screen.getByRole('dialog'))
expect(drawer.getByText('Test Event')).toBeInTheDocument()
expect(drawer.getByText('Test event description')).toBeInTheDocument()
expect(drawer.getByText('test-author')).toBeInTheDocument()
expect(drawer.getByText('test-name')).toBeInTheDocument()
expect(drawer.getByText('Parameter 1')).toBeInTheDocument()
expect(drawer.getByText('A test parameter')).toBeInTheDocument()
expect(drawer.getByText('tools.setBuiltInTools.string')).toBeInTheDocument()
expect(drawer.getByText('tools.setBuiltInTools.required')).toBeInTheDocument()
expect(drawer.getByText('result')).toBeInTheDocument()
expect(drawer.getByText('Result')).toBeInTheDocument()
expect(drawer.getByText('app.structOutput.required')).toBeInTheDocument()
})
it.each(['common.operation.close', 'plugin.detailPanel.operation.back'])(
'closes through %s',
async (name) => {
const user = userEvent.setup()
renderEvent()
await user.click(screen.getByRole('button', { name }))
expect(onClose).toHaveBeenCalledOnce()
},
)
it('shows an empty parameter state and no stale output fields', () => {
renderEvent({ ...mockEventInfo, parameters: [], output_schema: {} })
expect(screen.getByText('pluginTrigger.events.item.noParameters')).toBeInTheDocument()
expect(screen.getByText('pluginTrigger.events.output')).toBeInTheDocument()
expect(screen.queryByText('Parameter 1')).not.toBeInTheDocument()
expect(screen.queryByText('result')).not.toBeInTheDocument()
})
it.each([
['number-input', 'tools.setBuiltInTools.number'],
['checkbox', 'boolean'],
['file', 'tools.setBuiltInTools.file'],
])('labels a %s parameter as %s', (type, label) => {
renderEvent({ ...mockEventInfo, parameters: [{ ...mockEventInfo.parameters[0]!, type }] })
expect(screen.getByText(label)).toBeInTheDocument()
})
it('renders converted nested, array, enum and nullable output schemas', () => {
renderEvent({
...mockEventInfo,
output_schema: {
properties: {
records: { type: 'array', items: { type: 'string' }, description: 'Collected values' },
nested: {
type: 'object',
properties: { inner: { type: 'number', description: 'Nested value' } },
required: ['inner'],
},
status: { type: 'string', enum: ['active', 'inactive'] },
nullable: { type: ['string', 'null'], description: 'Optional value' },
},
required: ['nested'],
},
})
expect(screen.getByText('records')).toBeInTheDocument()
expect(screen.getByText('array[string]')).toBeInTheDocument()
expect(screen.getByText('Collected values')).toBeInTheDocument()
expect(screen.getByText('inner')).toBeInTheDocument()
expect(screen.getByText('number')).toBeInTheDocument()
expect(screen.getByText('Nested value')).toBeInTheDocument()
expect(screen.getAllByText('app.structOutput.required')).toHaveLength(2)
expect(screen.getByText(/"active"/)).toBeInTheDocument()
expect(screen.getByText('"inactive"')).toBeInTheDocument()
expect(screen.getByText('nullable')).toBeInTheDocument()
expect(screen.getByText('string')).toBeInTheDocument()
expect(screen.getByText('Optional value')).toBeInTheDocument()
})
})
@@ -0,0 +1,191 @@
'use client'
import type { TFunction } from 'i18next'
import type { FC } from 'react'
import type { TriggerEvent } from '@/app/components/plugins/types'
import type { TriggerProviderApiEntity } from '@/app/components/workflow/block-selector/types'
import { cn } from '@langgenius/dify-ui/cn'
import {
Drawer,
DrawerBackdrop,
DrawerContent,
DrawerPopup,
DrawerPortal,
DrawerViewport,
} from '@langgenius/dify-ui/drawer'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { Separator } from '@langgenius/dify-ui/separator'
import { RiArrowLeftLine, RiCloseLine } from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
import Icon from '@/app/components/plugins/card/base/card-icon'
import Description from '@/app/components/plugins/card/base/description'
import OrgInfo from '@/app/components/plugins/card/base/org-info'
import { triggerEventParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
import Field from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show/field'
type EventDetailDrawerProps = {
eventInfo: TriggerEvent
providerInfo: TriggerProviderApiEntity
onClose: () => void
}
const getType = (type: string, t: TFunction<['tools']>) => {
if (type === 'number-input') return t(($) => $['setBuiltInTools.number'], { ns: 'tools' })
if (type === 'text-input') return t(($) => $['setBuiltInTools.string'], { ns: 'tools' })
if (type === 'checkbox') return 'boolean'
if (type === 'file') return t(($) => $['setBuiltInTools.file'], { ns: 'tools' })
return type
}
// Convert JSON Schema to StructuredOutput format
const convertSchemaToField = (schema: any): any => {
const field: any = {
type: Array.isArray(schema.type) ? schema.type[0] : schema.type || 'string',
}
if (schema.description) field.description = schema.description
if (schema.properties) {
field.properties = Object.entries(schema.properties).reduce(
(acc, [key, value]: [string, any]) => ({
...acc,
[key]: convertSchemaToField(value),
}),
{},
)
}
if (schema.required) field.required = schema.required
if (schema.items) field.items = convertSchemaToField(schema.items)
if (schema.enum) field.enum = schema.enum
return field
}
export const EventDetailDrawer: FC<EventDetailDrawerProps> = (props) => {
const { eventInfo, providerInfo, onClose } = props
const language = useLanguage()
const { t } = useTranslation(['tools', 'common', 'plugin', 'pluginTrigger'])
const parametersSchemas = triggerEventParametersToFormSchemas(eventInfo.parameters)
// Convert output_schema properties to array for direct rendering
const outputFields = eventInfo.output_schema?.properties
? Object.entries(eventInfo.output_schema.properties).map(([name, schema]: [string, any]) => ({
name,
field: convertSchemaToField(schema),
required: eventInfo.output_schema.required?.includes(name) || false,
}))
: []
return (
<Drawer
open
modal
swipeDirection="right"
onOpenChange={(open) => {
if (!open) onClose()
}}
>
<DrawerPortal>
<DrawerBackdrop className="bg-transparent" />
<DrawerViewport>
<DrawerPopup
className={cn(
'justify-start bg-components-panel-bg! p-0! shadow-xl data-[swipe-direction=right]:top-2 data-[swipe-direction=right]:right-2 data-[swipe-direction=right]:bottom-2 data-[swipe-direction=right]:h-[calc(100dvh-16px)] data-[swipe-direction=right]:w-100 data-[swipe-direction=right]:max-w-[calc(100vw-1rem)] data-[swipe-direction=right]:rounded-2xl data-[swipe-direction=right]:border-[0.5px] data-[swipe-direction=right]:border-components-panel-border',
)}
>
<DrawerContent className="flex min-h-0 flex-1 flex-col p-0 pb-0">
<div className="relative border-b border-divider-subtle p-4 pb-3">
<div className="absolute top-3 right-3">
<IconButton
aria-label={t(($) => $['operation.close'], { ns: 'common' })}
onClick={onClose}
>
<RiCloseLine aria-hidden="true" className="size-4" />
</IconButton>
</div>
<button
type="button"
className="mb-2 flex cursor-pointer items-center gap-1 rounded-sm system-xs-semibold-uppercase text-text-accent-secondary outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"
onClick={onClose}
>
<RiArrowLeftLine aria-hidden="true" className="size-4" />
{t(($) => $['detailPanel.operation.back'], { ns: 'plugin' })}
</button>
<div className="flex items-center gap-1">
<Icon size="tiny" className="size-6" src={providerInfo.icon!} />
<OrgInfo
packageNameClassName="w-auto"
orgName={providerInfo.author}
packageName={providerInfo.name.split('/').pop() || ''}
/>
</div>
<div className="mt-1 system-md-semibold text-text-primary">
{eventInfo?.identity?.label[language]}
</div>
<Description
className="mt-3 mb-2 h-auto"
text={eventInfo.description[language]!}
descriptionLineRows={2}
></Description>
</div>
<div className="flex h-full flex-col gap-2 overflow-y-auto px-4 pt-4 pb-2">
<div className="system-sm-semibold-uppercase text-text-secondary">
{t(($) => $['setBuiltInTools.parameters'], { ns: 'tools' })}
</div>
{parametersSchemas.length > 0 ? (
parametersSchemas.map((item, index) => (
<div key={index} className="py-1">
<div className="flex items-center gap-2">
<div className="code-sm-semibold text-text-secondary">
{item.label[language]}
</div>
<div className="system-xs-regular text-text-tertiary">
{getType(item.type, t)}
</div>
{item.required && (
<div className="system-xs-medium text-text-warning-secondary">
{t(($) => $['setBuiltInTools.required'], { ns: 'tools' })}
</div>
)}
</div>
{item.description && (
<div className="mt-0.5 system-xs-regular text-text-tertiary">
{item.description?.[language]}
</div>
)}
</div>
))
) : (
<div className="system-xs-regular text-text-tertiary">
{t(($) => $['events.item.noParameters'], { ns: 'pluginTrigger' })}
</div>
)}
<Separator className="mt-1 mb-2" />
<div className="flex flex-col gap-2">
<div className="system-sm-semibold-uppercase text-text-secondary">
{t(($) => $['events.output'], { ns: 'pluginTrigger' })}
</div>
<div className="relative -left-1.75">
{outputFields.map((item) => (
<Field
key={item.name}
name={item.name}
payload={item.field}
required={item.required}
rootClassName="code-sm-semibold text-text-secondary"
/>
))}
</div>
</div>
</div>
</DrawerContent>
</DrawerPopup>
</DrawerViewport>
</DrawerPortal>
</Drawer>
)
}
@@ -0,0 +1,86 @@
import type { TriggerEvent } from '@/app/components/plugins/types'
import type { TriggerProviderApiEntity } from '@/app/components/workflow/block-selector/types'
import { cn } from '@langgenius/dify-ui/cn'
import { useId, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useTriggerProviderInfo } from '@/service/use-triggers'
import { usePluginStore } from '../store'
import { EventDetailDrawer } from './event-detail-drawer'
type TriggerEventCardProps = {
eventInfo: TriggerEvent
providerInfo: TriggerProviderApiEntity
}
const TriggerEventCard = ({ eventInfo, providerInfo }: TriggerEventCardProps) => {
const { identity, description } = eventInfo
const language = useLanguage()
const [showDetail, setShowDetail] = useState(false)
const titleId = useId()
const descriptionId = useId()
const title = identity.label?.[language] ?? identity.label?.en_US ?? ''
const descriptionText = description?.[language] ?? description?.en_US ?? ''
return (
<>
<button
type="button"
aria-labelledby={titleId}
aria-describedby={descriptionText ? descriptionId : undefined}
className={cn(
'bg-components-panel-item-bg w-full cursor-pointer rounded-xl border-[0.5px] border-components-panel-border-subtle px-4 py-3 text-left shadow-xs outline-hidden hover:bg-components-panel-on-panel-item-bg-hover focus-visible:ring-2 focus-visible:ring-state-accent-solid',
)}
onClick={() => setShowDetail(true)}
>
<div id={titleId} className="pb-0.5 system-md-semibold text-text-secondary">
{title}
</div>
<div id={descriptionId} className="line-clamp-2 system-xs-regular text-text-tertiary">
{descriptionText}
</div>
</button>
{showDetail && (
<EventDetailDrawer
eventInfo={eventInfo}
providerInfo={providerInfo}
onClose={() => setShowDetail(false)}
/>
)}
</>
)
}
export const TriggerEventsList = () => {
const { t } = useTranslation(['pluginTrigger'])
const detail = usePluginStore((state) => state.detail)
const { data: providerInfo } = useTriggerProviderInfo(detail?.provider || '')
const triggerEvents = providerInfo?.events || []
if (!providerInfo || !triggerEvents.length) return null
return (
<div className="px-4 pt-2 pb-4">
<div className="mb-1 py-1">
<div className="mb-1 flex h-6 items-center justify-between system-sm-semibold-uppercase text-text-secondary">
{t(($) => $['events.actionNum'], {
ns: 'pluginTrigger',
num: triggerEvents.length,
event: t(($) => $[`events.${triggerEvents.length > 1 ? 'events' : 'event'}`], {
ns: 'pluginTrigger',
}),
})}
</div>
</div>
<div className="flex flex-col gap-2">
{triggerEvents.map((triggerEvent: TriggerEvent) => (
<TriggerEventCard
key={`${detail?.plugin_id}${triggerEvent.identity?.name || ''}`}
eventInfo={triggerEvent}
providerInfo={providerInfo}
/>
))}
</div>
</div>
)
}