'use client'
import type {
AgentIconType,
AgentReferencingWorkflowResponse,
} from '@dify/contracts/api/console/agent/types.gen'
import type { ReactNode } from 'react'
import { Button } from '@langgenius/dify-ui/button'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import AppIcon from '@/app/components/base/app-icon'
import useTimestamp from '@/hooks/use-timestamp'
import Link from '@/next/link'
import { consoleQuery } from '@/service/client'
type WorkflowReferencesTableProps = {
agentId: string
enabled?: boolean
}
const workflowTableColSpan = 5
const getWorkflowReferenceHref = (reference: AgentReferencingWorkflowResponse) =>
`/app/${reference.app_id}/workflow`
export function WorkflowReferencesTable({ agentId, enabled = true }: WorkflowReferencesTableProps) {
const { t } = useTranslation('agentV2')
const { t: tCommon } = useTranslation('common')
const workflowReferencesQuery = useQuery(
consoleQuery.agent.byAgentId.referencingWorkflows.get.queryOptions({
input: {
params: {
agent_id: agentId,
},
},
enabled,
}),
)
const workflowReferences = workflowReferencesQuery.data?.data ?? []
return (
|
{t(($) => $['agentDetail.access.workflow.table.name'])}
|
{t(($) => $['agentDetail.access.workflow.table.version'])}
|
{t(($) => $['agentDetail.access.workflow.table.nodes'])}
|
{t(($) => $['agentDetail.access.workflow.table.lastUpdated'])}
|
{t(($) => $['agentDetail.access.workflow.table.actions'])}
|
{enabled && workflowReferencesQuery.isPending && (
{t(($) => $['agentDetail.access.workflow.loading'])}
)}
{enabled && workflowReferencesQuery.isError && (
{t(($) => $['agentDetail.access.workflow.loadFailed'])}
)}
{enabled && workflowReferencesQuery.isSuccess && workflowReferences.length === 0 && (
{t(($) => $['agentDetail.access.workflow.empty'])}
)}
{enabled &&
workflowReferencesQuery.isSuccess &&
workflowReferences.map((reference) => (
))}
)
}
function WorkflowAccessRow({ reference }: { reference: AgentReferencingWorkflowResponse }) {
const { t } = useTranslation('agentV2')
const { formatTime } = useTimestamp()
const imageUrl =
reference.app_icon_type === 'image' || reference.app_icon_type === 'link'
? reference.app_icon
: undefined
const iconType = (imageUrl ? 'image' : reference.app_icon_type) as
| AgentIconType
| null
| undefined
const updatedAt =
reference.app_updated_at != null
? formatTime(
reference.app_updated_at,
t(($) => $['roster.dateTimeFormat']),
)
: t(($) => $['agentDetail.access.workflow.notAvailable'])
const nodeCount = reference.node_ids?.length ?? 0
return (
|
|
{reference.workflow_version}
|
{t(($) => $['agentDetail.access.workflow.nodeCount'], { count: nodeCount })}
|
{updatedAt}
|
$['agentDetail.access.workflow.openInStudioFor'], {
name: reference.app_name,
})}
className="inline-flex items-center gap-0.5 rounded-sm text-text-secondary hover:text-text-accent hover:underline focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"
>
{t(($) => $['agentDetail.access.workflow.openInStudio'])}
|
)
}
function WorkflowAccessStateRow({ children }: { children: ReactNode }) {
return (
|
{children}
|
)
}