feat: integrate knowledge base creation in RepoCard and update app context key

- Updated the context key for the QueryRouterServer from 'router' to 'app'.
- Added functionality to create a knowledge base in RepoCard component.
- Introduced a new BookOpen icon and tooltip for knowledge base indication.
- Implemented a toast notification for successful knowledge base creation.
- Cleaned up imports in main.tsx by commenting out unused app import.
This commit is contained in:
2026-02-16 00:46:07 +08:00
parent f876a65c6b
commit 3d66eee666
5 changed files with 271 additions and 183 deletions

View File

@@ -3,8 +3,7 @@ import { QueryRouterServer } from '@kevisual/router/browser'
import { useContextKey } from '@kevisual/context'
import { useConfigStore } from '@/app/config/store'
import { CNB } from '@kevisual/cnb'
export const app = useContextKey('router', new QueryRouterServer())
export const app = useContextKey('app', new QueryRouterServer())
export const cnb: CNB = useContextKey('cnb', () => {
const state = useConfigStore.getState()
@@ -13,9 +12,19 @@ export const cnb: CNB = useContextKey('cnb', () => {
if (config.ENABLE_CORS) {
cors.baseUrl = config.CNB_CORS_URL || 'https://cors.kevisual.cn'
}
console.log('state', state)
// if(state.config.)
return new CNB({
token: config.CNB_API_KEY,
cookie: config.CNB_COOKIE,
cors
})
})
})
//
// import '@kevisual/cnb-ai'
const url = 'https://kevisual.cn/root/cnb-ai/dist/app.js'
setTimeout(() => {
import(/* @vite-ignore */url)
}, 2000)

View File

@@ -13,10 +13,12 @@ import {
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover'
import { Star, GitFork, FileText, Edit, FolderGit2, MoreVertical, FileText as IssueIcon, Settings, Play, Trash2, RefreshCw } from 'lucide-react'
import { Star, GitFork, FileText, Edit, FolderGit2, MoreVertical, FileText as IssueIcon, Settings, Play, Trash2, RefreshCw, BookOpen } from 'lucide-react'
import { useRepoStore } from '../store'
import { useMemo, useState } from 'react'
import { myOrgs } from '../store/build'
import { app, cnb } from '@/agents/app'
import { toast } from 'sonner'
interface RepoCardProps {
repo: any
@@ -37,12 +39,36 @@ export function RepoCard({ repo, onStartWorkspace, onEdit, onIssue, onSettings,
const isWorkspaceActive = !!workspace
const owner = repo.path.split('/')[0]
const isMine = myOrgs.includes(owner)
const isKnowledge = repo?.flags === "KnowledgeBase"
const createKnow = async () => {
const res = await app.run({ path: 'cnb', key: 'build-knowledge-base', payload: { repo: repo.path } })
if (res.code === 200) {
toast.success("知识库创建中")
}
}
return (
<>
<Card className="relative p-0 overflow-hidden border border-neutral-200 bg-white hover:shadow-xl hover:border-neutral-300 transition-all duration-300 group pb-14">
<div className="p-6 space-y-4">
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-2 flex-1 min-w-0">
{isKnowledge && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger
render={
<div className="shrink-0">
<BookOpen className="w-5 h-5 text-neutral-700" />
</div>
}
/>
<TooltipContent>
<p></p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
<a
href={repo.web_url}
target="_blank"
@@ -103,6 +129,12 @@ export function RepoCard({ repo, onStartWorkspace, onEdit, onIssue, onSettings,
<Settings className="w-4 h-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => {
createKnow()
}} className="cursor-pointer">
<BookOpen className="w-4 h-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem
onClick={(e) => {
e.preventDefault()
@@ -201,7 +233,7 @@ export function RepoCard({ repo, onStartWorkspace, onEdit, onIssue, onSettings,
<span className="font-medium"></span>
</span>}
{isMine && (
<span
<span
className="flex items-center gap-1.5 hover:text-neutral-900 transition-colors cursor-pointer"
onClick={() => onSync?.(repo)}
>

View File

@@ -3,7 +3,7 @@ import { RouterProvider, createRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
import './index.css'
import { basename } from './modules/basename'
// import './agents/app'
// Set up a Router instance
const router = createRouter({
routeTree,