Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(web): open Marketplace details externally for self-hosted editions (#42576)
Coding On Starc3d5b5fa4d6f
diff --git a/web/app/components/plugins/__tests__/provider-card.spec.tsx b/web/app/components/plugins/__tests__/provider-card.spec.tsxindex 4eb06a65138..c1a91267c13 100644--- a/web/app/components/plugins/__tests__/provider-card.spec.tsx+++ b/web/app/components/plugins/__tests__/provider-card.spec.tsx@@ -1,7 +1,8 @@import type { Plugin } from '../types'-import { fireEvent, render, screen } from '@testing-library/react'+import { fireEvent, screen } from '@testing-library/react'import { ThemeProvider } from 'next-themes'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { render } from '@/test/console/render'import ProviderCard from '../provider-card'import { PluginCategoryEnum } from '../types'@@ -23,7 +24,8 @@ vi.mock('@/app/components/plugins/install-plugin/hooks/use-plugin-install-permisdefault: () => ({ canInstallPlugin: true }),}))-vi.mock('@/app/components/plugins/marketplace/utils', () => ({+vi.mock('@/app/components/plugins/marketplace/utils', async (importOriginal) => ({+ ...(await importOriginal<typeof import('@/app/components/plugins/marketplace/utils')>()),getPluginLinkInMarketplace: (plugin: Plugin, params: Record<string, string>) =>`/marketplace/${plugin.org}/${plugin.name}?language=${params.language}&theme=${params.theme}`,}))@@ -46,6 +48,15 @@ vi.mock('../card/base/title', () => ({default: ({ title }: { title: string }) => <div data-testid="title">{title}</div>,}))+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const payload = {type: 'plugin',org: 'dify',@@ -72,6 +83,7 @@ const payload = {describe('ProviderCard', () => {beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()})@@ -105,4 +117,18 @@ describe('ProviderCard', () => {fireEvent.click(screen.getByTestId('close-install-modal'))expect(screen.queryByTestId('install-modal')).not.toBeInTheDocument()})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'uses the official detail destination for %s',+ (edition) => {+ deploymentState.deploymentEdition = edition+ renderProviderCard()+ const link = screen.getByRole('link', { name: /plugin.detailPanel.operation.detail/i })+ const url = new URL(link.getAttribute('href')!)+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.pathname).toBe('/plugin/dify/provider-one')+ expect(url.searchParams.get('source')).toBe(window.location.origin)+ expect(link).toHaveAttribute('target', '_blank')+ expect(link).toHaveAttribute('rel', 'noopener noreferrer')+ },+ )})diff --git a/web/app/components/plugins/marketplace/creator-profile/__tests__/dify-profile.spec.tsx b/web/app/components/plugins/marketplace/creator-profile/__tests__/dify-profile.spec.tsxindex 59eaf16bddc..be3dfaf5216 100644--- a/web/app/components/plugins/marketplace/creator-profile/__tests__/dify-profile.spec.tsx+++ b/web/app/components/plugins/marketplace/creator-profile/__tests__/dify-profile.spec.tsx@@ -4,10 +4,19 @@ import type { LoadedCreatorProfile } from '../model'import type { Plugin } from '@/app/components/plugins/types'import { screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'-import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'import { renderWithNuqs } from '@/test/nuqs-testing'import DifyCreatorProfile from '../dify-profile'+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const mocks = vi.hoisted(() => ({push: vi.fn(),installedInfo: { 'dify/deep_research': { version: '0.0.1' } },@@ -111,6 +120,7 @@ const loadedProfile: LoadedCreatorProfile = {vi.mock('#i18n', async () => {const { withSelectorKey } = await import('@/test/i18n-mock')return {+ useLocale: () => 'en-US',useTranslation: () => ({t: withSelectorKey((key: string) => key),}),@@ -161,19 +171,25 @@ vi.mock('../header', () => ({}: {onSuggestionSelect: (selection: MarketplaceSearchSelection) => void}) => (- <button- type="button"- onClick={() => {- onSuggestionSelect({ kind: 'plugin', plugin: searchPlugin })- }}- >- Select search plugin- </button>+ <>+ <button+ type="button"+ onClick={() => {+ onSuggestionSelect({ kind: 'plugin', plugin: searchPlugin })+ }}+ >+ Select search plugin+ </button>+ <button type="button" onClick={() => onSuggestionSelect({ kind: 'template', template })}>+ Select search template+ </button>+ </>),}))describe('DifyCreatorProfile', () => {beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()})@@ -210,4 +226,44 @@ describe('DifyCreatorProfile', () => {expect(dialog).toHaveTextContent('search_result')expect(dialog).toHaveTextContent('not installed')})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'links %s creator inventory to official details',+ (edition) => {+ deploymentState.deploymentEdition = edition+ renderWithNuqs(<DifyCreatorProfile loadedProfile={loadedProfile} locale="en-US" />)+ for (const name of ['Deep Research', 'Research Template']) {+ const link = screen.getByRole('link', { name })+ const url = new URL(link.getAttribute('href')!)+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.searchParams.get('source')).toBe(window.location.origin)+ expect(link).toHaveAttribute('target', '_blank')+ expect(link).toHaveAttribute('rel', 'noopener noreferrer')+ }+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ },+ )++ afterEach(() => {+ vi.restoreAllMocks()+ })++ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'opens %s creator search results externally',+ async (edition) => {+ deploymentState.deploymentEdition = edition+ const open = vi.spyOn(window, 'open').mockReturnValue(null)+ const user = userEvent.setup()+ const { onUrlUpdate } = renderWithNuqs(+ <DifyCreatorProfile loadedProfile={loadedProfile} locale="en-US" />,+ )+ await user.click(screen.getByRole('button', { name: 'Select search plugin' }))+ expect(open).toHaveBeenCalledTimes(1)+ expect(new URL(String(open.mock.calls[0]![0])).pathname).toBe('/plugin/dify/search_result')+ await user.click(screen.getByRole('button', { name: 'Select search template' }))+ expect(open).toHaveBeenCalledTimes(2)+ expect(new URL(String(open.mock.calls[1]![0])).pathname).toBe('/template/dify/template-one')+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ expect(onUrlUpdate).not.toHaveBeenCalled()+ },+ )})diff --git a/web/app/components/plugins/marketplace/creator-profile/creation-card.tsx b/web/app/components/plugins/marketplace/creator-profile/creation-card.tsxindex 72d62ba275e..647389565bf 100644--- a/web/app/components/plugins/marketplace/creator-profile/creation-card.tsx+++ b/web/app/components/plugins/marketplace/creator-profile/creation-card.tsx@@ -75,7 +75,13 @@ function CreationCardContent({ creation }: { creation: CreatorCreation }) {export default function CreationCard({ creation, action }: CreationCardProps) {if (action.type === 'link') {return (- <Link href={action.href} aria-label={creation.title} className={cardClassName}>+ <Link+ href={action.href}+ target={action.target}+ rel={action.target === '_blank' ? 'noopener noreferrer' : undefined}+ aria-label={creation.title}+ className={cardClassName}+ ><CreationCardContent creation={creation} /></Link>)diff --git a/web/app/components/plugins/marketplace/creator-profile/dify-profile.tsx b/web/app/components/plugins/marketplace/creator-profile/dify-profile.tsxindex 8ae4997db63..c4d3178e508 100644--- a/web/app/components/plugins/marketplace/creator-profile/dify-profile.tsx+++ b/web/app/components/plugins/marketplace/creator-profile/dify-profile.tsx@@ -2,13 +2,14 @@import type { MarketplaceTemplate } from '@dify/contracts/marketplace'import type { MarketplaceSearchSelection } from '../home/marketplace-search-autocomplete'-import type { CreatorCreation, LoadedCreatorProfile } from './model'+import type { CreatorCreation, CreatorCreationAction, LoadedCreatorProfile } from './model'import type { Plugin } from '@/app/components/plugins/types'import { useMemo, useState } from 'react'import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed'import { useRouter } from '@/next/navigation'import MarketplaceDetailDialog from '../detail-dialog'import TemplateDetailDialog from '../templates/template-detail-dialog'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import { getFormattedPlugin } from '../utils'import CreatorProfileHeader from './header'import CreatorProfileView from './view'@@ -33,6 +34,7 @@ const normalizePlugin = (plugin: Plugin): Plugin => ({export default function DifyCreatorProfile({ loadedProfile, locale }: DifyCreatorProfileProps) {const router = useRouter()+ const navigation = useMarketplaceDetailNavigation()const [selected, setSelected] = useState<SelectedCreation | null>(null)const [sourceProfile, setSourceProfile] = useState(loadedProfile)const [pluginsByCreationId, setPluginsByCreationId] = useState(loadedProfile.pluginsByCreationId)@@ -50,11 +52,13 @@ export default function DifyCreatorProfile({ loadedProfile, locale }: DifyCreato() =>Array.from(new Set([- ...profilePlugins.map((plugin) => plugin.plugin_id),+ ...profilePlugins+ .filter((plugin) => !navigation.pluginHref(plugin))+ .map((plugin) => plugin.plugin_id),...(selected?.kind === 'plugin' ? [selected.plugin.plugin_id] : []),]),).sort(),- [profilePlugins, selected],+ [navigation, profilePlugins, selected],)const { installedInfo } = useCheckInstalled({pluginIds,@@ -74,15 +78,28 @@ export default function DifyCreatorProfile({ loadedProfile, locale }: DifyCreatoconst selectSearchResult = (selection: MarketplaceSearchSelection) => {if (selection.kind === 'plugin') {+ if (navigation.openPlugin(selection.plugin)) return { preserveQuery: true }setSelected({kind: 'plugin',plugin: normalizePlugin(getFormattedPlugin(selection.plugin)),})return}+ if (navigation.openTemplate(selection.template)) return { preserveQuery: true }setSelected({ kind: 'template', template: selection.template })}+ const getCreationAction = (creation: CreatorCreation): CreatorCreationAction => {+ const target = creation.target+ const href =+ target.type === 'plugin'+ ? navigation.pluginHref({ org: target.org, name: target.name, type: target.pluginType })+ : navigation.templateHref({ id: target.id, publisher_unique_handle: target.publisher })+ return href+ ? { type: 'link', href, target: '_blank' }+ : { type: 'select', onSelect: () => selectCreation(creation) }+ }+const closeSelected = () => setSelected(null)const selectedPlugin = selected?.kind === 'plugin' ? selected.plugin : nullconst selectedTemplate = selected?.kind === 'template' ? selected.template : null@@ -102,10 +119,7 @@ export default function DifyCreatorProfile({ loadedProfile, locale }: DifyCreato...records.templatesByCreationId,}))}}- getCreationAction={(creation) => ({- type: 'select',- onSelect: () => selectCreation(creation),- })}+ getCreationAction={getCreationAction}header={<CreatorProfileHeader locale={locale} onSuggestionSelect={selectSearchResult} />}/>diff --git a/web/app/components/plugins/marketplace/creator-profile/header.tsx b/web/app/components/plugins/marketplace/creator-profile/header.tsxindex e4b072eb080..027331dac41 100644--- a/web/app/components/plugins/marketplace/creator-profile/header.tsx+++ b/web/app/components/plugins/marketplace/creator-profile/header.tsx@@ -12,7 +12,7 @@ import { MarketplaceLogo } from '../marketplace-logo'type CreatorProfileHeaderProps = {actions?: React.ReactNodelocale: string- onSuggestionSelect: (selection: MarketplaceSearchSelection) => void+ onSuggestionSelect: (selection: MarketplaceSearchSelection) => { preserveQuery: boolean } | void}export default function CreatorProfileHeader({diff --git a/web/app/components/plugins/marketplace/creator-profile/model.ts b/web/app/components/plugins/marketplace/creator-profile/model.tsindex ed0d729d537..0d37e82d453 100644--- a/web/app/components/plugins/marketplace/creator-profile/model.ts+++ b/web/app/components/plugins/marketplace/creator-profile/model.ts@@ -114,7 +114,7 @@ export type LoadedCreatorProfile = {}export type CreatorCreationAction =- | { type: 'link'; href: string }+ | { type: 'link'; href: string; target?: '_blank' }| { type: 'select'; onSelect: () => void }export type CreatorProfileAdapterInput = {diff --git a/web/app/components/plugins/marketplace/home/__tests__/embedded-marketplace-search.spec.tsx b/web/app/components/plugins/marketplace/home/__tests__/embedded-marketplace-search.spec.tsxindex 018f6e30a41..dffc78ceb6a 100644--- a/web/app/components/plugins/marketplace/home/__tests__/embedded-marketplace-search.spec.tsx+++ b/web/app/components/plugins/marketplace/home/__tests__/embedded-marketplace-search.spec.tsx@@ -1,16 +1,30 @@import { QueryClient, QueryClientProvider } from '@tanstack/react-query'import { screen, waitFor, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'-import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'import { renderWithNuqs } from '@/test/nuqs-testing'import EmbeddedMarketplaceSearch from '../embedded-marketplace-search'-const { debounceState, mockPluginSearch, mockTemplateSearch } = vi.hoisted(() => ({- debounceState: { useRealDebounce: false },- mockPluginSearch: vi.fn(),- mockTemplateSearch: vi.fn(),+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',}))+vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})++const { debounceState, mockPluginSearch, mockTemplateSearch, mockCheckInstalled } = vi.hoisted(+ () => ({+ debounceState: { useRealDebounce: false },+ mockCheckInstalled: vi.fn((_options: { pluginIds: string[]; enabled: boolean }) => ({+ installedInfo: {},+ })),+ mockPluginSearch: vi.fn(),+ mockTemplateSearch: vi.fn(),+ }),+)+vi.mock('ahooks', async (importOriginal) => {const original = await importOriginal<typeof import('ahooks')>()@@ -60,7 +74,7 @@ vi.mock('@/service/marketplace', () => ({}))vi.mock('@/app/components/plugins/install-plugin/hooks/use-check-installed', () => ({- default: () => ({ installedInfo: {} }),+ default: mockCheckInstalled,}))vi.mock('@/next/navigation', () => ({@@ -97,6 +111,7 @@ const renderSearch = () => {describe('EmbeddedMarketplaceSearch', () => {beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()debounceState.useRealDebounce = falsequeryClient = new QueryClient({@@ -240,4 +255,84 @@ describe('EmbeddedMarketplaceSearch', () => {})expect(screen.queryByRole('dialog', { name: 'plugin-detail' })).not.toBeInTheDocument()})+ afterEach(() => {+ vi.restoreAllMocks()+ })++ describe.each(['COMMUNITY', 'ENTERPRISE'] as const)('%s external search', (edition) => {+ it.each([+ ['plugin', 'mouse'],+ ['plugin', 'keyboard'],+ ['template', 'mouse'],+ ['template', 'keyboard'],+ ] as const)(+ 'opens one tab for a %s using %s without changing the catalog',+ async (kind, interaction) => {+ deploymentState.deploymentEdition = edition+ const open = vi.spyOn(window, 'open').mockReturnValue(null)+ mockPluginSearch.mockResolvedValue({+ data: {+ plugins:+ kind === 'plugin'+ ? [+ {+ type: 'plugin',+ org: 'langgenius',+ name: 'google-search',+ plugin_id: 'langgenius/google-search',+ label: { en_US: 'Google Search' },+ brief: {},+ category: 'tool',+ },+ ]+ : [],+ total: 1,+ },+ })+ mockTemplateSearch.mockResolvedValue({+ data: {+ templates:+ kind === 'template'+ ? [+ {+ id: 'template-1',+ template_name: 'Legal Research Agent',+ publisher_unique_handle: 'dify',+ overview: '',+ usage_count: 1,+ categories: [],+ icon: '',+ icon_background: '',+ icon_file_key: '',+ },+ ]+ : [],+ total: 1,+ },+ })+ const user = userEvent.setup()+ const { onUrlUpdate } = renderSearch()+ const input = screen.getByRole('combobox')+ await user.type(input, 'search')+ const option = await screen.findByRole('option')+ if (interaction === 'mouse') await user.click(option)+ else await user.keyboard('{ArrowDown}{Enter}')+ expect(open).toHaveBeenCalledTimes(1)+ const [href, target, features] = open.mock.calls[0]!+ const url = new URL(String(href))+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.pathname).toBe(+ kind === 'plugin' ? '/plugin/langgenius/google-search' : '/template/dify/template-1',+ )+ expect(url.searchParams.get('source')).toBe(window.location.origin)+ expect(target).toBe('_blank')+ expect(features).toBe('noopener,noreferrer')+ expect(input).toHaveValue('search')++ expect(onUrlUpdate).not.toHaveBeenCalled()+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ expect(mockCheckInstalled.mock.calls.every(([options]) => !options.enabled)).toBe(true)+ },+ )+ })})diff --git a/web/app/components/plugins/marketplace/home/__tests__/home-trending.spec.tsx b/web/app/components/plugins/marketplace/home/__tests__/home-trending.spec.tsxindex 864ca5bddd1..fb3631db4a7 100644--- a/web/app/components/plugins/marketplace/home/__tests__/home-trending.spec.tsx+++ b/web/app/components/plugins/marketplace/home/__tests__/home-trending.spec.tsx@@ -1,8 +1,10 @@import type { PluginBanner } from '@dify/contracts/marketplace'-import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react'+import type { Window } from 'happy-dom'+import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test'import { trackEvent } from '@/app/components/base/amplitude'+import { render } from '@/test/console/render'import { trackMarketplaceSiteEvent } from '@/utils/marketplace-site-track'import HomeTrending from '../home-trending'@@ -18,6 +20,7 @@ vi.mock('@/utils/marketplace-site-track', () => ({vi.mock('#i18n', async () => {const { withSelectorKey } = await import('@/test/i18n-mock')return {+ useLocale: () => 'en-US',useTranslation: (namespace: string) => ({t: withSelectorKey((key: string) => `${namespace}.${key}`),}),@@ -81,6 +84,15 @@ vi.mock('../../templates/template-detail-dialog', () => ({) : null,}))+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const banners: PluginBanner[] = [{id: 'recommend',@@ -162,11 +174,17 @@ const banners: PluginBanner[] = [const mockTrackEvent = vi.mocked(trackEvent)const mockTrackMarketplaceSiteEvent = vi.mocked(trackMarketplaceSiteEvent)+const navigationSettings = (window as unknown as Window).happyDOM.settings.navigation+const originalNavigation = navigationSettings.disableMainFrameNavigation+beforeEach(() => {+ navigationSettings.disableMainFrameNavigation = true+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()})afterEach(() => {+ navigationSettings.disableMainFrameNavigation = originalNavigationvi.unstubAllGlobals()})@@ -1130,4 +1148,55 @@ describe('HomeTrending', () => {vi.useRealTimers()}})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'links %s recommendations directly to the official site',+ (edition) => {+ deploymentState.deploymentEdition = edition+ const mixedBanner: PluginBanner = {+ id: 'mixed',+ style_type: 'recommend',+ title: 'Trending',+ sort: 0,+ language: 'en',+ content: {+ theme_type: 'hottest',+ cards: [+ {+ item_type: 'plugin',+ item_id: 'langgenius/dropbox',+ display_name: 'Dropbox',+ link: '',+ card_position: 0,+ },+ {+ item_type: 'template',+ item_id: 'tpl-1',+ display_name: 'Support Bot',+ creator: 'aisa-team',+ link: '',+ card_position: 1,+ },+ ],+ },+ }+ render(<HomeTrending banners={[mixedBanner]} isMarketplacePlatform={false} page="plugins" />)+ const links = screen+ .getAllByRole('link')+ .filter((link) => link.getAttribute('href')?.startsWith('https://marketplace.dify.ai/'))+ expect(links.length).toBeGreaterThan(0)+ expect(+ links.some((link) => new URL(link.getAttribute('href')!).pathname.startsWith('/plugin/')),+ ).toBe(true)+ expect(+ links.some((link) => new URL(link.getAttribute('href')!).pathname.startsWith('/template/')),+ ).toBe(true)+ for (const link of links) {+ expect(link).toHaveAttribute('target', '_blank')+ expect(new URL(link.getAttribute('href')!).searchParams.get('source')).toBe(+ window.location.origin,+ )+ }+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ },+ )})diff --git a/web/app/components/plugins/marketplace/home/embedded-marketplace-search.tsx b/web/app/components/plugins/marketplace/home/embedded-marketplace-search.tsxindex a844981da36..e94ae93cdca 100644--- a/web/app/components/plugins/marketplace/home/embedded-marketplace-search.tsx+++ b/web/app/components/plugins/marketplace/home/embedded-marketplace-search.tsx@@ -11,6 +11,7 @@ import { useSearchPluginText } from '../atoms'import MarketplaceDetailDialog from '../detail-dialog'import TemplateDetailDialog from '../templates/template-detail-dialog'import { useOptionalTemplateDetailRoute } from '../templates/use-optional-template-detail-route'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import { getFormattedPlugin } from '../utils'import { MarketplaceSearchAutocomplete } from './marketplace-search-autocomplete'@@ -28,6 +29,7 @@ export default function EmbeddedMarketplaceSearch() {const { t } = useTranslation()const locale = useLocale()const router = useRouter()+ const navigation = useMarketplaceDetailNavigation()const [query, setQuery] = useSearchPluginText()const [value, setValue] = useState(query ?? '')const [valueQuery, setValueQuery] = useState(query)@@ -46,11 +48,13 @@ export default function EmbeddedMarketplaceSearch() {const handleSuggestionSelect = useCallback((selection: MarketplaceSearchSelection) => {if (selection.kind === 'plugin') {+ if (navigation.openPlugin(selection.plugin)) return { preserveQuery: true }setSelectedTemplate(null)setSelectedPlugin(normalizePlugin(getFormattedPlugin(selection.plugin)))return}+ if (navigation.openTemplate(selection.template)) return { preserveQuery: true }setSelectedPlugin(null)if (templateDetailRoute) {templateDetailRoute.open(selection.template)@@ -58,7 +62,7 @@ export default function EmbeddedMarketplaceSearch() {}setSelectedTemplate(selection.template)},- [templateDetailRoute],+ [navigation, templateDetailRoute],)return (diff --git a/web/app/components/plugins/marketplace/home/home-trending-slides.tsx b/web/app/components/plugins/marketplace/home/home-trending-slides.tsxindex 032a32b49d2..39142cc6cf4 100644--- a/web/app/components/plugins/marketplace/home/home-trending-slides.tsx+++ b/web/app/components/plugins/marketplace/home/home-trending-slides.tsx@@ -30,6 +30,7 @@ import {import MarketplaceDetailDialog from '../detail-dialog'import TemplateDetailDialog from '../templates/template-detail-dialog'import { useOptionalTemplateDetailRoute } from '../templates/use-optional-template-detail-route'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import {getPluginLinkInMarketplace,getTemplateDetailLinkInMarketplace,@@ -329,7 +330,26 @@ function RecommendCardFace({ card }: { card: BannerRecommendCard }) {)}-function EmbeddedRecommendPluginCard({+function EmbeddedRecommendPluginCard(props: Parameters<typeof CloudRecommendPluginCard>[0]) {+ const navigation = useMarketplaceDetailNavigation()+ const href = navigation.pluginHref(props.initialPlugin)+ if (!href) return <CloudRecommendPluginCard {...props} />++ return (+ <Link+ href={href}+ target="_blank"+ rel="noopener noreferrer"+ aria-label={props.card.display_name}+ className={recommendCardClassName}+ onClick={() => trackRecommendCardClick(props.banner, props.card, props.page, href)}+ >+ <RecommendCardFace card={props.card} />+ </Link>+ )+}++function CloudRecommendPluginCard({banner,card,initialPlugin,@@ -390,7 +410,26 @@ function EmbeddedRecommendPluginCard({)}-function EmbeddedRecommendTemplateCard({+function EmbeddedRecommendTemplateCard(props: Parameters<typeof CloudRecommendTemplateCard>[0]) {+ const navigation = useMarketplaceDetailNavigation()+ const href = navigation.templateHref(props.template)+ if (!href) return <CloudRecommendTemplateCard {...props} />++ return (+ <Link+ href={href}+ target="_blank"+ rel="noopener noreferrer"+ aria-label={props.card.display_name}+ className={recommendCardClassName}+ onClick={() => trackRecommendCardClick(props.banner, props.card, props.page, href)}+ >+ <RecommendCardFace card={props.card} />+ </Link>+ )+}++function CloudRecommendTemplateCard({banner,card,template,diff --git a/web/app/components/plugins/marketplace/home/marketplace-search-autocomplete.tsx b/web/app/components/plugins/marketplace/home/marketplace-search-autocomplete.tsxindex cd6893e2be0..2f12ed87c2a 100644--- a/web/app/components/plugins/marketplace/home/marketplace-search-autocomplete.tsx+++ b/web/app/components/plugins/marketplace/home/marketplace-search-autocomplete.tsx@@ -60,7 +60,7 @@ type MarketplaceSearchAutocompleteProps = {category?: stringinputName?: stringlocale: string- onSuggestionSelect?: (selection: MarketplaceSearchSelection) => void+ onSuggestionSelect?: (selection: MarketplaceSearchSelection) => { preserveQuery: boolean } | voidonValueChange: (value: string) => voidplaceholder: stringscope: MarketplaceSearchScope@@ -193,9 +193,9 @@ export function MarketplaceSearchAutocomplete({}const openSuggestion = (selection: MarketplaceSearchSelection) => {if (onSuggestionSelect) {- onSuggestionSelect(selection)+ const result = onSuggestionSelect(selection)queueMicrotask(() => {- onValueChange('')+ if (!result?.preserveQuery) onValueChange('')setIsOpen(false)})returndiff --git a/web/app/components/plugins/marketplace/list/__tests__/card-wrapper.spec.tsx b/web/app/components/plugins/marketplace/list/__tests__/card-wrapper.spec.tsxindex 5511b439f00..dca8d31aa65 100644--- a/web/app/components/plugins/marketplace/list/__tests__/card-wrapper.spec.tsx+++ b/web/app/components/plugins/marketplace/list/__tests__/card-wrapper.spec.tsx@@ -1,10 +1,11 @@import type { ComponentProps } from 'react'import type { Plugin } from '@/app/components/plugins/types'-import { fireEvent, render, screen } from '@testing-library/react'+import { fireEvent, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { ThemeProvider } from 'next-themes'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'import { PluginCategoryEnum } from '@/app/components/plugins/types'+import { render } from '@/test/console/render'import { trackMarketplaceSiteCardClick } from '@/utils/marketplace-site-track'import CardWrapper from '../card-wrapper'@@ -65,18 +66,24 @@ vi.mock('../../detail-dialog', () => ({) : null,}))-vi.mock('../../utils', () => ({- getPluginDetailLinkInMarketplace: (plugin: Plugin) => `/detail/${plugin.org}/${plugin.name}`,-}))-vi.mock('@/utils/marketplace-site-track', () => ({trackMarketplaceSiteCardClick: vi.fn(),}))vi.mock('@/context/i18n', () => ({useGetLanguage: () => 'en-US',+ useLocale: () => 'en-US',}))+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const plugin = {type: 'plugin',org: 'dify',@@ -103,6 +110,7 @@ const plugin = {describe('CardWrapper', () => {beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()})@@ -155,7 +163,7 @@ describe('CardWrapper', () => {it('links the card to its marketplace detail when explicitly enabled', () => {renderCardWrapper({ linkToMarketplaceDetail: true })- expect(screen.getByRole('link')).toHaveAttribute('href', '/detail/dify/plugin-a')+ expect(screen.getByRole('link')).toHaveAttribute('href', '/plugin/dify/plugin-a')fireEvent.click(screen.getByRole('link'))expect(trackMarketplaceSiteCardClick).toHaveBeenCalledWith({itemId: 'dify/plugin-a',@@ -220,4 +228,37 @@ describe('CardWrapper', () => {expect(screen.getByRole('dialog', { name: 'marketplace detail' })).toBeInTheDocument()expect(screen.queryByTestId('install-modal')).not.toBeInTheDocument()})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'links %s plugin details to the official site while preserving direct installation',+ async (edition) => {+ deploymentState.deploymentEdition = edition+ const user = userEvent.setup()+ render(<CardWrapper plugin={plugin} showInstallButton />)++ const card = screen.getByRole('link', { name: 'Plugin A' })+ const url = new URL(card.getAttribute('href')!)+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.pathname).toBe('/plugin/dify/plugin-a')+ expect(url.searchParams.get('source')).toBe(window.location.origin)+ expect([...url.searchParams.keys()].sort()).toEqual(['language', 'source'])+ expect(card).toHaveAttribute('target', '_blank')+ expect(card).toHaveAttribute('rel', 'noopener noreferrer')+ expect(+ screen.getByRole('link', { name: 'plugin.detailPanel.operation.detail' }),+ ).toHaveAttribute('href', url.toString())+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ expect(document.querySelector('iframe')).toBeNull()++ await user.click(screen.getByRole('button', { name: 'plugin.detailPanel.operation.install' }))+ expect(screen.getByTestId('install-modal')).toBeInTheDocument()+ },+ )++ it('keeps Bundle details inside Dify in Community edition', async () => {+ deploymentState.deploymentEdition = 'COMMUNITY'+ const user = userEvent.setup()+ render(<CardWrapper plugin={{ ...plugin, type: 'bundle' }} />)+ await user.click(screen.getByRole('button', { name: 'Plugin A' }))+ expect(screen.getByRole('dialog', { name: 'marketplace detail' })).toBeInTheDocument()+ })})diff --git a/web/app/components/plugins/marketplace/list/card-wrapper.tsx b/web/app/components/plugins/marketplace/list/card-wrapper.tsxindex 7a4db8ffdc3..102a25fe3ee 100644--- a/web/app/components/plugins/marketplace/list/card-wrapper.tsx+++ b/web/app/components/plugins/marketplace/list/card-wrapper.tsx@@ -1,6 +1,6 @@'use client'import type { Plugin } from '@/app/components/plugins/types'-import { Button } from '@langgenius/dify-ui/button'+import { Button, buttonVariants } from '@langgenius/dify-ui/button'import { useBoolean } from 'ahooks'import * as React from 'react'import { useMemo } from 'react'@@ -15,6 +15,7 @@ import { renderI18nObject } from '@/i18n/metadata'import Link from '@/next/link'import { trackMarketplaceSiteCardClick } from '@/utils/marketplace-site-track'import MarketplaceDetailDialog from '../detail-dialog'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import { getPluginDetailLinkInMarketplace } from '../utils'type CardWrapperProps = {@@ -24,13 +25,14 @@ type CardWrapperProps = {linkToMarketplaceDetail?: booleansection?: string}-const CardWrapperComponent = ({+const CardWrapperContent = ({plugin,showInstallButton,isInstalled = false,linkToMarketplaceDetail = false,section = 'list',-}: CardWrapperProps) => {+ externalDetailHref,+}: CardWrapperProps & { externalDetailHref?: string }) => {const { t } = useTranslation()const locale = useGetLanguage()const [@@ -94,12 +96,22 @@ const CardWrapperComponent = ({className="group relative cursor-pointer rounded-xl"data-marketplace-card={plugin.plugin_id}>- <button- type="button"- aria-label={pluginLabel}- className="absolute inset-0 z-[1] rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"- onClick={showMarketplaceDetail}- />+ {externalDetailHref ? (+ <a+ href={externalDetailHref}+ target="_blank"+ rel="noopener noreferrer"+ aria-label={pluginLabel}+ className="absolute inset-0 z-[1] rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"+ />+ ) : (+ <button+ type="button"+ aria-label={pluginLabel}+ className="absolute inset-0 z-[1] rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"+ onClick={showMarketplaceDetail}+ />+ )}{cardBody}{showInstallAction && (<div className="pointer-events-none absolute right-[-0.5px] bottom-[-0.5px] left-[-0.5px] z-10 flex items-center gap-2 rounded-b-xl bg-linear-to-t from-components-panel-on-panel-item-bg-hover from-60% to-background-gradient-mask-transparent px-4 pt-8 pb-4 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100">@@ -116,23 +128,38 @@ const CardWrapperComponent = ({? t(($) => $['task.installed'], { ns: 'plugin' }): t(($) => $['detailPanel.operation.install'], { ns: 'plugin' })}</Button>- <Button- className="min-w-0 flex-1 shadow-xs backdrop-blur-[5px]"- onClick={(event) => {- event.stopPropagation()- showMarketplaceDetail()- }}- >- {t(($) => $['detailPanel.operation.detail'], { ns: 'plugin' })}- </Button>+ {externalDetailHref ? (+ <a+ href={externalDetailHref}+ target="_blank"+ rel="noopener noreferrer"+ className={buttonVariants({+ className: 'min-w-0 flex-1 shadow-xs backdrop-blur-[5px]',+ })}+ >+ {t(($) => $['detailPanel.operation.detail'], { ns: 'plugin' })}+ </a>+ ) : (+ <Button+ className="min-w-0 flex-1 shadow-xs backdrop-blur-[5px]"+ onClick={(event) => {+ event.stopPropagation()+ showMarketplaceDetail()+ }}+ >+ {t(($) => $['detailPanel.operation.detail'], { ns: 'plugin' })}+ </Button>+ )}</div>)}- <MarketplaceDetailDialog- isInstalled={isInstalled}- open={isShowMarketplaceDetail}- plugin={plugin}- onOpenChange={handleMarketplaceDetailOpenChange}- />+ {!externalDetailHref && (+ <MarketplaceDetailDialog+ isInstalled={isInstalled}+ open={isShowMarketplaceDetail}+ plugin={plugin}+ onOpenChange={handleMarketplaceDetailOpenChange}+ />+ )}{isShowInstallFromMarketplace && (<InstallFromMarketplacemanifest={plugin}@@ -145,6 +172,19 @@ const CardWrapperComponent = ({)}+function DifyCardWrapper(props: CardWrapperProps) {+ const navigation = useMarketplaceDetailNavigation()+ return <CardWrapperContent {...props} externalDetailHref={navigation.pluginHref(props.plugin)} />+}++function CardWrapperComponent(props: CardWrapperProps) {+ return props.linkToMarketplaceDetail ? (+ <CardWrapperContent {...props} />+ ) : (+ <DifyCardWrapper {...props} />+ )+}+// Memoize the component to prevent unnecessary re-renders when props haven't changedconst CardWrapper = React.memo(CardWrapperComponent)diff --git a/web/app/components/plugins/marketplace/templates/__tests__/template-card.spec.tsx b/web/app/components/plugins/marketplace/templates/__tests__/template-card.spec.tsxindex 1deaf17f96b..1ab99b23a67 100644--- a/web/app/components/plugins/marketplace/templates/__tests__/template-card.spec.tsx+++ b/web/app/components/plugins/marketplace/templates/__tests__/template-card.spec.tsx@@ -1,11 +1,30 @@import type { MarketplaceTemplate } from '@dify/contracts/marketplace'import type { Window } from 'happy-dom'-import { fireEvent, render, screen } from '@testing-library/react'+import { fireEvent, screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'-import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import {+ afterAll,+ afterEach,+ beforeAll,+ beforeEach,+ describe,+ expect,+ it,+ vi,+} from 'vite-plus/test'+import { render } from '@/test/console/render'import TemplateCard from '../template-card'import { TemplateDetailRouteProvider } from '../template-detail-route'+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const { mockPush } = vi.hoisted(() => ({mockPush: vi.fn(),}))@@ -41,6 +60,7 @@ const template: MarketplaceTemplate = {}describe('TemplateCard', () => {+ const originalUrl = window.location.hrefconst navigationSettings = (window as unknown as Window).happyDOM.settings.navigationconst originalDisableChildFrameNavigation = navigationSettings.disableChildFrameNavigation@@ -49,9 +69,14 @@ describe('TemplateCard', () => {})beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'vi.clearAllMocks()})+ afterEach(() => {+ ;(window as unknown as Window).happyDOM.setURL(originalUrl)+ })+afterAll(() => {navigationSettings.disableChildFrameNavigation = originalDisableChildFrameNavigation})@@ -124,4 +149,33 @@ describe('TemplateCard', () => {expect(window.location.pathname).toBe(`/templates/dify/${routedTemplate.id}`)expect(screen.getByRole('dialog')).toBeInTheDocument()})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'opens %s template links outside Dify without changing the catalog route',+ (edition) => {+ deploymentState.deploymentEdition = edition+ ;(window as unknown as Window).happyDOM.setURL(+ 'https://ai.njueai.com:8443/templates?q=research',+ )+ const before = window.location.href+ render(+ <TemplateDetailRouteProvider>+ <TemplateCard partnerText="Partner" template={template} />+ </TemplateDetailRouteProvider>,+ )+ const link = screen.getByRole('link', { name: template.template_name })+ const url = new URL(link.getAttribute('href')!)+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.pathname).toBe('/template/dify/template%2Fone')+ expect(Object.fromEntries(url.searchParams)).toEqual({+ source: window.location.origin,+ language: 'en-US',+ theme: 'dark',+ })+ expect(link).toHaveAttribute('target', '_blank')+ expect(link).toHaveAttribute('rel', 'noopener noreferrer')+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ expect(document.querySelector('iframe')).toBeNull()+ expect(window.location.href).toBe(before)+ },+ )})diff --git a/web/app/components/plugins/marketplace/templates/__tests__/template-detail-route.spec.tsx b/web/app/components/plugins/marketplace/templates/__tests__/template-detail-route.spec.tsxindex ee6f43c38ea..30af204c6cc 100644--- a/web/app/components/plugins/marketplace/templates/__tests__/template-detail-route.spec.tsx+++ b/web/app/components/plugins/marketplace/templates/__tests__/template-detail-route.spec.tsx@@ -1,10 +1,20 @@import type { MarketplaceTemplate } from '@dify/contracts/marketplace'-import { render, screen } from '@testing-library/react'+import { screen } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'+import { render } from '@/test/console/render'import { TemplateDetailRouteProvider } from '../template-detail-route'import { useOptionalTemplateDetailRoute } from '../use-optional-template-detail-route'+const deploymentState = vi.hoisted(() => ({+ deploymentEdition: 'CLOUD' as 'CLOUD' | 'COMMUNITY' | 'ENTERPRISE',+}))++vi.mock('@/features/system-features/state', async () => {+ const { createSystemFeaturesStateModuleMock } = await import('@/test/console/state-fixture')+ return createSystemFeaturesStateModuleMock(() => deploymentState)+})+const id = 'c558a1fb-bb8c-4a5e-9404-d681c6659cf2'const template: MarketplaceTemplate = {@@ -53,6 +63,7 @@ function OpenButton() {describe('TemplateDetailRouteProvider', () => {beforeEach(() => {+ deploymentState.deploymentEdition = 'CLOUD'window.history.replaceState(window.history.state, '', '/templates')})@@ -101,4 +112,25 @@ describe('TemplateDetailRouteProvider', () => {await user.click(screen.getByRole('button', { name: 'Close' }))expect(window.location.pathname).toBe('/templates/marketing')})+ it.each(['COMMUNITY', 'ENTERPRISE'] as const)(+ 'replaces a legacy %s template detail URL with its official detail',+ (edition) => {+ deploymentState.deploymentEdition = edition+ window.history.replaceState(window.history.state, '', `/templates/dify/${id}`)+ const replace = vi.spyOn(window.location, 'replace').mockImplementation(() => {})+ render(+ <TemplateDetailRouteProvider initialSelection={{ publisher: 'dify', id }}>+ <span>catalog</span>+ </TemplateDetailRouteProvider>,+ )+ expect(replace).toHaveBeenCalledOnce()+ const url = new URL(replace.mock.calls[0]![0])+ expect(url.origin).toBe('https://marketplace.dify.ai')+ expect(url.pathname).toBe(`/template/dify/${id}`)+ expect(url.searchParams.get('source')).toBe(window.location.origin)+ expect(url.searchParams.has('view')).toBe(false)+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ replace.mockRestore()+ },+ )})diff --git a/web/app/components/plugins/marketplace/templates/template-card.tsx b/web/app/components/plugins/marketplace/templates/template-card.tsxindex 147959922d3..40483b82f84 100644--- a/web/app/components/plugins/marketplace/templates/template-card.tsx+++ b/web/app/components/plugins/marketplace/templates/template-card.tsx@@ -10,6 +10,7 @@ import { MARKETPLACE_API_PREFIX } from '@/config'import { useRouter } from '@/next/navigation'import { formatNumberAbbreviated } from '@/utils/format'import { getIconFromMarketPlace } from '@/utils/get-icon'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import TemplateDetailDialog from './template-detail-dialog'import { useOptionalTemplateDetailRoute } from './use-optional-template-detail-route'@@ -23,6 +24,8 @@ const MAX_VISIBLE_PLUGIN_DEPENDENCIES = 7export default function TemplateCard({ template, className, partnerText }: TemplateCardProps) {const router = useRouter()+ const navigation = useMarketplaceDetailNavigation()+ const externalHref = navigation.templateHref(template)const templateDetailRoute = useOptionalTemplateDetailRoute()const [isDetailOpen, { setTrue: showDetail, setFalse: hideDetail }] = useBoolean(false)const publisher =@@ -57,12 +60,22 @@ export default function TemplateCard({ template, className, partnerText }: TemplclassName,)}>- <button- type="button"- aria-label={template.template_name}- className="absolute inset-0 z-[1] cursor-pointer rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"- onClick={openDetail}- />+ {externalHref ? (+ <a+ href={externalHref}+ target="_blank"+ rel="noopener noreferrer"+ aria-label={template.template_name}+ className="absolute inset-0 z-[1] cursor-pointer rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"+ />+ ) : (+ <button+ type="button"+ aria-label={template.template_name}+ className="absolute inset-0 z-[1] cursor-pointer rounded-xl outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"+ onClick={openDetail}+ />+ )}<div className="relative z-0 flex shrink-0 items-center gap-3 px-4 pt-4 pb-2"><AppIconsize="large"@@ -107,7 +120,7 @@ export default function TemplateCard({ template, className, partnerText }: Templ)}</div></article>- {!templateDetailRoute && (+ {!externalHref && !templateDetailRoute && (<TemplateDetailDialogopen={isDetailOpen}template={template}diff --git a/web/app/components/plugins/marketplace/templates/template-detail-route.tsx b/web/app/components/plugins/marketplace/templates/template-detail-route.tsxindex 4c800286a54..4e5a727f175 100644--- a/web/app/components/plugins/marketplace/templates/template-detail-route.tsx+++ b/web/app/components/plugins/marketplace/templates/template-detail-route.tsx@@ -5,6 +5,7 @@ import type { ReactNode } from 'react'import type { TemplateDetailSelection } from './template-links'import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { useRouter } from '@/next/navigation'+import { useMarketplaceDetailNavigation } from '../use-detail-navigation'import TemplateDetailDialog from './template-detail-dialog'import { buildTemplateDetailHref, parseTemplateDetailPath } from './template-links'import { TemplateDetailRouteContext } from './use-optional-template-detail-route'@@ -30,13 +31,49 @@ function templateFromSelection(}}-export function TemplateDetailRouteProvider({- children,- initialSelection,-}: {+type TemplateDetailRouteProps = {children: ReactNodeinitialSelection?: TemplateDetailSelection-}) {+}++export function TemplateDetailRouteProvider(props: TemplateDetailRouteProps) {+ const navigation = useMarketplaceDetailNavigation()+ if (!navigation.opensExternally) return <CloudTemplateDetailRouteProvider {...props} />++ return (+ <TemplateDetailRouteContext+ value={{+ close: () => {},+ isOpen: () => false,+ open: (template) => {+ navigation.openTemplate(template)+ },+ }}+ >+ {props.children}+ {props.initialSelection && (+ <ExternalTemplateDetailRedirect selection={props.initialSelection} />+ )}+ </TemplateDetailRouteContext>+ )+}++function ExternalTemplateDetailRedirect({ selection }: { selection: TemplateDetailSelection }) {+ const navigation = useMarketplaceDetailNavigation()+ const href = navigation.templateHref(templateFromSelection(selection))+ const redirectedRef = useRef(false)+ useEffect(() => {+ if (!href || !navigation.source || redirectedRef.current) return+ redirectedRef.current = true+ window.location.replace(href)+ }, [href, navigation.source])+ return null+}++function CloudTemplateDetailRouteProvider({+ children,+ initialSelection,+}: TemplateDetailRouteProps) {const router = useRouter()const catalogHrefRef = useRef('/templates')const [template, setTemplate] = useState<MarketplaceTemplate | null>(() =>@@ -90,7 +127,7 @@ export function TemplateDetailRouteProvider({)return (- <TemplateDetailRouteContext.Provider value={value}>+ <TemplateDetailRouteContext value={value}>{children}{template && (<TemplateDetailDialog@@ -102,6 +139,6 @@ export function TemplateDetailRouteProvider({}}/>)}- </TemplateDetailRouteContext.Provider>+ </TemplateDetailRouteContext>)}diff --git a/web/app/components/plugins/marketplace/use-detail-navigation.ts b/web/app/components/plugins/marketplace/use-detail-navigation.tsnew file mode 100644index 00000000000..1385f78b75b--- /dev/null+++ b/web/app/components/plugins/marketplace/use-detail-navigation.ts@@ -0,0 +1,60 @@+'use client'++import type { MarketplacePlugin, MarketplaceTemplate } from '@dify/contracts/marketplace'+import { useAtomValue } from 'jotai'+import { useTheme } from 'next-themes'+import { useSyncExternalStore } from 'react'+import { useLocale } from '#i18n'+import { deploymentEditionAtom } from '@/features/system-features/state'+import { getPluginDetailLinkInMarketplace, getTemplateDetailLinkInMarketplace } from './utils'++const subscribe = () => () => {}+const getOrigin = () => window.location.origin+const getServerOrigin = () => ''++type PluginDetail = Pick<MarketplacePlugin, 'org' | 'name' | 'type'>+type TemplateDetail = Pick<+ MarketplaceTemplate,+ 'id' | 'publisher_handle' | 'publisher_unique_handle'+>++// Only Dify entrypoints use this hook. Standalone Marketplace components must+// not depend on the Console's deployment state or query its system features.+export function useMarketplaceDetailNavigation() {+ const edition = useAtomValue(deploymentEditionAtom)+ const language = useLocale()+ const { resolvedTheme } = useTheme()+ const source = useSyncExternalStore(subscribe, getOrigin, getServerOrigin)+ const opensExternally = edition === 'COMMUNITY' || edition === 'ENTERPRISE'++ const officialUrl = (path: string) => {+ const url = new URL(path, 'https://marketplace.dify.ai')+ if (source) url.searchParams.set('source', source)+ url.searchParams.set('language', language)+ if (resolvedTheme) url.searchParams.set('theme', resolvedTheme)+ return url.toString()+ }+ const pluginHref = (plugin: PluginDetail) =>+ opensExternally && plugin.type !== 'bundle'+ ? officialUrl(getPluginDetailLinkInMarketplace(plugin))+ : undefined+ const templateHref = (template: TemplateDetail) =>+ opensExternally ? officialUrl(getTemplateDetailLinkInMarketplace(template)) : undefined++ // Search selections are commands, so open synchronously within the gesture.+ // Ordinary cards use the href directly to retain native link behavior.+ const open = (href: string | undefined) => {+ if (!href) return false+ window.open(href, '_blank', 'noopener,noreferrer')+ return true+ }++ return {+ source,+ opensExternally,+ pluginHref,+ templateHref,+ openPlugin: (plugin: PluginDetail) => open(pluginHref(plugin)),+ openTemplate: (template: TemplateDetail) => open(templateHref(template)),+ }+}diff --git a/web/app/components/plugins/provider-card.tsx b/web/app/components/plugins/provider-card.tsxindex c5acd60e045..4052bdb8074 100644--- a/web/app/components/plugins/provider-card.tsx+++ b/web/app/components/plugins/provider-card.tsx@@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next'import { useLocale } from '#i18n'import usePluginInstallPermission from '@/app/components/plugins/install-plugin/hooks/use-plugin-install-permission'import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'+import { useMarketplaceDetailNavigation } from '@/app/components/plugins/marketplace/use-detail-navigation'import { getPluginLinkInMarketplace } from '@/app/components/plugins/marketplace/utils'import { useRenderI18nObject } from '@/hooks/use-i18n'import Badge from '../base/badge'@@ -35,6 +36,7 @@ const ProviderCardComponent: FC<Props> = ({ className, payload }) => {const { canInstallPlugin } = usePluginInstallPermission()const { org, label } = payloadconst locale = useLocale()+ const navigation = useMarketplaceDetailNavigation()// Memoize the marketplace link params to prevent unnecessary re-rendersconst marketplaceLinkParams = useMemo(() => ({ language: locale, theme }), [locale, theme])@@ -80,7 +82,10 @@ const ProviderCardComponent: FC<Props> = ({ className, payload }) => {</Button>)}<a- href={getPluginLinkInMarketplace(payload, marketplaceLinkParams)}+ href={+ navigation.pluginHref(payload) ??+ getPluginLinkInMarketplace(payload, marketplaceLinkParams)+ }target="_blank"rel="noopener noreferrer"className={cn(buttonVariants({ variant: 'secondary' }), 'grow gap-0.5')}