Skip to content

armgit / dify

Public Imported from GitHub
0

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.

2.7 KB
Raw Blame
'use client'

import { useAtomValueRawSync } from 'jotai'
import { useTranslation } from 'react-i18next'
import { KnowledgeModelReadinessBanner } from '../components/knowledge-model-readiness-banner'
import { useKnowledgeSpacePermission } from '../space/context'
import { RetrievalComposer } from './composer'
import { RetrievalHistoryPanel } from './history-panel'
import { RetrievalResultPanel } from './result-panel'
import { RetrievalRuntimeController } from './runtime-controller'
import { RetrievalStateBoundary } from './state/boundary'
import { retrievalComposerModeAtom } from './state/graph'
import { retrievalCanQueryAtom, retrievalKnowledgeSpaceIdAtom } from './state/inputs'

function RetrievalTestSurface() {
  const { t } = useTranslation(['knowledgeSpace', 'knowledgeRetrieval'])
  const knowledgeSpaceId = useAtomValueRawSync(retrievalKnowledgeSpaceIdAtom)
  const canQuery = useAtomValueRawSync(retrievalCanQueryAtom)
  const mode = useAtomValueRawSync(retrievalComposerModeAtom)

  return (
    <div className="flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-lg bg-components-panel-bg px-6 pt-3 pb-5">
      <header className="shrink-0">
        <h1 className="title-xl-semi-bold leading-6 text-text-primary">
          {t(($) => $['retrievalTest.title'], { ns: 'knowledgeSpace' })}
        </h1>
        <p className="mt-1 w-full system-xs-regular text-text-tertiary">
          {t(($) => $['retrievalTest.description'], { ns: 'knowledgeRetrieval' })}
        </p>
      </header>
      {canQuery && (
        <KnowledgeModelReadinessBanner
          capability={mode === 'deep' ? 'deep' : mode === 'research' ? 'research' : 'query'}
          className="mt-4"
          knowledgeSpaceId={knowledgeSpaceId}
        />
      )}
      {!canQuery && (
        <p
          className="mt-4 inline-flex items-center gap-1.5 system-xs-regular text-text-warning"
          role="status"
        >
          <span aria-hidden className="i-ri-lock-line size-3.5" />
          {t(($) => $.permissionRestricted)}
        </p>
      )}

      <div className="mt-4 flex min-h-0 min-w-0 flex-1 flex-col lg:flex-row">
        <section className="flex min-h-0 w-full shrink-0 flex-col pb-5 lg:w-117 lg:pr-6">
          <RetrievalComposer />
          <RetrievalHistoryPanel />
        </section>
        <RetrievalResultPanel />
      </div>
    </div>
  )
}

export function RetrievalTestPage({ knowledgeSpaceId }: { knowledgeSpaceId: string }) {
  const canQuery = useKnowledgeSpacePermission('knowledge_space_query')

  return (
    <RetrievalStateBoundary canQuery={canQuery} knowledgeSpaceId={knowledgeSpaceId}>
      <RetrievalRuntimeController />
      <RetrievalTestSurface />
    </RetrievalStateBoundary>
  )
}