mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
feat(chatbot): remove agentId from request and resolve it via team settings, toggle chatbot icon with tooltip guard
This commit is contained in:
@@ -18,10 +18,13 @@ import {
|
||||
DockToRight,
|
||||
DockToRightFilled,
|
||||
} from '@/ui/components/ui/icons'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { AncestorFolder } from '@shumai/dtos'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from '@/ui/components/ui/tooltip'
|
||||
import { Link, useNavigate } from '@tanstack/react-router'
|
||||
import {
|
||||
Check,
|
||||
@@ -33,6 +36,10 @@ import {
|
||||
List,
|
||||
Bot,
|
||||
} from 'lucide-react'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { AncestorFolder } from '@shumai/dtos'
|
||||
|
||||
interface BreadcrumbNavProps {
|
||||
teamId: string
|
||||
@@ -107,6 +114,21 @@ export function BreadcrumbNav({
|
||||
const navigate = useNavigate()
|
||||
const { canEdit } = usePermissions(projectId)
|
||||
|
||||
const { data: teamSettings } = useQuery({
|
||||
queryKey: ['teams', teamId, 'settings'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].settings.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to fetch settings')
|
||||
return res.json()
|
||||
},
|
||||
enabled: !!teamId && !isPublic,
|
||||
})
|
||||
|
||||
const isChatbotDisabled =
|
||||
!isPublic && !(teamSettings as { chatbotAgentId?: string | null })?.chatbotAgentId
|
||||
|
||||
const handleVersionClick = (versionId: string) => {
|
||||
if (!fileId) return
|
||||
if (isPublic && shareId) {
|
||||
@@ -444,22 +466,41 @@ export function BreadcrumbNav({
|
||||
|
||||
{/* Chatbot Toggle Button */}
|
||||
{!isPublic && onChatbotToggle && (
|
||||
<button
|
||||
onClick={onChatbotToggle}
|
||||
className={`h-9 w-9 flex items-center justify-center rounded-md border border-border bg-background transition-colors ${
|
||||
isChatbotOpen
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent hover:text-foreground'
|
||||
}`}
|
||||
title={isChatbotOpen ? m.hide_chatbot() : m.show_chatbot()}
|
||||
>
|
||||
<Bot
|
||||
className={cn(
|
||||
'h-4 w-4 transition-colors',
|
||||
isChatbotOpen ? 'text-primary fill-primary/10' : 'text-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span>
|
||||
<button
|
||||
disabled={isChatbotDisabled}
|
||||
onClick={onChatbotToggle}
|
||||
className={cn(
|
||||
'h-9 w-9 flex items-center justify-center rounded-md border border-border bg-background transition-colors',
|
||||
isChatbotOpen
|
||||
? 'bg-accent text-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent hover:text-foreground',
|
||||
isChatbotDisabled && 'opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
>
|
||||
<Bot
|
||||
className={cn(
|
||||
'h-4 w-4 transition-colors',
|
||||
isChatbotOpen ? 'text-primary fill-primary/10' : 'text-muted-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>
|
||||
{isChatbotDisabled
|
||||
? m.configure_chatbot_agent_first()
|
||||
: isChatbotOpen
|
||||
? m.hide_chatbot()
|
||||
: m.show_chatbot()}
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,13 @@ import { client } from '@/ui/api/client'
|
||||
import { Card, CardContent } from '@/ui/components/ui/card'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Badge } from '@/ui/components/ui/badge'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Loader2,
|
||||
@@ -16,7 +23,7 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
import { AgentInfo, AgentType, ThinkingLevel } from '@shumai/dtos'
|
||||
import { AgentInfo, AgentType, ThinkingLevel, UpdateTeamSettingsRequest } from '@shumai/dtos'
|
||||
import { AgentFormDialog } from './AgentFormDialog'
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -143,6 +150,35 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||
},
|
||||
})
|
||||
|
||||
const { data: teamSettings } = useQuery({
|
||||
queryKey: ['teams', teamId, 'settings'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.teams[':teamId'].settings.$get({
|
||||
param: { teamId },
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to fetch team settings')
|
||||
return res.json()
|
||||
},
|
||||
})
|
||||
|
||||
const updateSettingsMutation = useMutation({
|
||||
mutationFn: async (params: UpdateTeamSettingsRequest) => {
|
||||
const res = await client.api.teams[':teamId'].settings.$patch({
|
||||
param: { teamId },
|
||||
json: params,
|
||||
})
|
||||
if (!res.ok) throw new Error('failed to update settings')
|
||||
return res.json()
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'settings'] })
|
||||
toast.success(m.settings_saved())
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err.message)
|
||||
},
|
||||
})
|
||||
|
||||
const toggleSection = (type: string) => {
|
||||
setExpandedSections((prev) => ({
|
||||
...prev,
|
||||
@@ -213,6 +249,55 @@ export function AgentsSettings({ teamId }: AgentsSettingsProps) {
|
||||
<Loader2 className="w-4 h-4 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Global Chatbot Agent Configuration Card */}
|
||||
<Card className="border-border shadow-xs">
|
||||
<CardContent className="p-6">
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<h4 className="font-semibold text-foreground flex items-center gap-2 text-sm md:text-base">
|
||||
<Bot className="w-5 h-5 text-primary" />
|
||||
{m.global_chatbot()}
|
||||
</h4>
|
||||
<p className="text-xs md:text-sm text-muted-foreground">
|
||||
{m.global_chatbot_description()}
|
||||
</p>
|
||||
</div>
|
||||
<div className="w-full md:w-72 shrink-0">
|
||||
{agents.filter((a) => a.type === 'chat' && a.enabled).length === 0 ? (
|
||||
<div className="text-xs text-amber-600 bg-amber-50 dark:bg-amber-950/20 dark:text-amber-400 p-2.5 rounded-lg border border-amber-200 dark:border-amber-900/30">
|
||||
{m.no_chat_agents_warning()}
|
||||
</div>
|
||||
) : (
|
||||
<Select
|
||||
value={
|
||||
(teamSettings as { chatbotAgentId?: string | null })?.chatbotAgentId || ''
|
||||
}
|
||||
onValueChange={(val) => {
|
||||
updateSettingsMutation.mutate({
|
||||
key: 'chatbotAgentId',
|
||||
value: val || null,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder={m.select_chatbot_agent()} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{agents
|
||||
.filter((a) => a.type === 'chat' && a.enabled)
|
||||
.map((agent) => (
|
||||
<SelectItem key={agent.id} value={agent.id}>
|
||||
{agent.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{AGENT_TYPES.map((section) => {
|
||||
const typeAgents = agents.filter((a) => a.type === section.type)
|
||||
const Icon = section.icon
|
||||
|
||||
Reference in New Issue
Block a user