feat: enhance agent system with hot/quick questions, dynamic chat UI, and new enterprise agents
- Add hotQuestions and quickQuestions fields to agent model - Update admin form with textarea inputs for hot/quick questions - Make chat page display dynamic agent data (name, icon, questions) - Widen center chat area to 60% for better readability - Add enterprise service category and 3 new agents (jiaotou, promotion, group-policy) - Update Prisma schema formatting and seed data
This commit is contained in:
@@ -16,6 +16,8 @@ export default function AgentForm({
|
|||||||
icon?: string
|
icon?: string
|
||||||
categoryId?: number
|
categoryId?: number
|
||||||
features?: string
|
features?: string
|
||||||
|
hotQuestions?: string
|
||||||
|
quickQuestions?: string
|
||||||
status?: string
|
status?: string
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -27,6 +29,8 @@ export default function AgentForm({
|
|||||||
icon: agent?.icon || "",
|
icon: agent?.icon || "",
|
||||||
categoryId: agent?.categoryId || "",
|
categoryId: agent?.categoryId || "",
|
||||||
features: agent?.features || "",
|
features: agent?.features || "",
|
||||||
|
hotQuestions: agent?.hotQuestions ? JSON.parse(agent.hotQuestions).join('\n') : '',
|
||||||
|
quickQuestions: agent?.quickQuestions ? JSON.parse(agent.quickQuestions).join('\n') : '',
|
||||||
status: agent?.status || "active",
|
status: agent?.status || "active",
|
||||||
})
|
})
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@@ -44,10 +48,16 @@ export default function AgentForm({
|
|||||||
|
|
||||||
const method = agent?.id ? "PUT" : "POST"
|
const method = agent?.id ? "PUT" : "POST"
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
...formData,
|
||||||
|
hotQuestions: JSON.stringify(formData.hotQuestions.split('\n').filter(q => q.trim())),
|
||||||
|
quickQuestions: JSON.stringify(formData.quickQuestions.split('\n').filter(q => q.trim())),
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(formData),
|
body: JSON.stringify(body),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -175,6 +185,33 @@ export default function AgentForm({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
热点问题(每行一个)
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={formData.hotQuestions}
|
||||||
|
onChange={(e) => setFormData({ ...formData, hotQuestions: e.target.value })}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
|
||||||
|
placeholder="养老政策有哪些最新变化? 如何申请养老服务补贴? 老年人健康管理需要注意什么? 养老机构如何选择?"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||||
|
快捷提问(每行一个)
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={formData.quickQuestions}
|
||||||
|
onChange={(e) => setFormData({ ...formData, quickQuestions: e.target.value })}
|
||||||
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"
|
||||||
|
placeholder="养老政策咨询 养老机构推荐 养老服务申请"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ export default async function EditAgentPage({
|
|||||||
icon: agent.icon || "",
|
icon: agent.icon || "",
|
||||||
categoryId: agent.categoryId || undefined,
|
categoryId: agent.categoryId || undefined,
|
||||||
features: agent.features,
|
features: agent.features,
|
||||||
|
hotQuestions: agent.hotQuestions,
|
||||||
|
quickQuestions: agent.quickQuestions,
|
||||||
status: agent.status,
|
status: agent.status,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export default function LoginPage() {
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="text-center text-sm text-gray-500">
|
<div className="text-center text-sm text-gray-500">
|
||||||
默认账号: admin / admin123
|
{/* 默认账号: admin / admin123 */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ interface Agent {
|
|||||||
category: {
|
category: {
|
||||||
name: string
|
name: string
|
||||||
} | null
|
} | null
|
||||||
|
hotQuestions: string
|
||||||
|
quickQuestions: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AgentChatPage() {
|
export default function AgentChatPage() {
|
||||||
@@ -288,12 +290,8 @@ export default function AgentChatPage() {
|
|||||||
setInput(question)
|
setInput(question)
|
||||||
}
|
}
|
||||||
|
|
||||||
const suggestedQuestions = [
|
const hotQuestions = agent ? JSON.parse(agent.hotQuestions || '[]') : []
|
||||||
'养老政策有哪些最新变化?',
|
const quickQuestions = agent ? JSON.parse(agent.quickQuestions || '[]') : []
|
||||||
'如何申请养老服务补贴?',
|
|
||||||
'老年人健康管理需要注意什么?',
|
|
||||||
'养老机构如何选择?',
|
|
||||||
]
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
@@ -389,22 +387,21 @@ export default function AgentChatPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 中间聊天区域 */}
|
{/* 中间聊天区域 */}
|
||||||
<div className="w-1/2 flex flex-col">
|
<div className="w-[60%] flex flex-col">
|
||||||
<div className="flex flex-col h-full bg-white rounded-2xl shadow-lg overflow-hidden">
|
<div className="flex flex-col h-full bg-white rounded-2xl shadow-lg overflow-hidden">
|
||||||
{/* 聊天头部 */}
|
{/* 聊天头部 */}
|
||||||
<div className="bg-gradient-to-r from-blue-600 to-blue-700 text-white p-4 flex items-center justify-between">
|
<div className="bg-gradient-to-r from-blue-600 to-blue-700 text-white p-4 flex items-center justify-between">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div className="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
<div className="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
|
||||||
<i className="fas fa-heartbeat text-white text-xl"></i>
|
<span className="text-white text-xl">{agent.icon || '🤖'}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-semibold">智慧养老服务助手</h3>
|
<h3 className="font-semibold">{agent.name}</h3>
|
||||||
<p className="text-xs text-blue-100">
|
<p className="text-xs text-blue-100">
|
||||||
{sending ? '正在回复...' : '24小时为您服务'}
|
{sending ? '正在回复...' : '24小时为您服务'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="bg-white/20 px-3 py-1 rounded text-xs">智能小养正在为您服务</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 消息区域 */}
|
{/* 消息区域 */}
|
||||||
@@ -508,7 +505,7 @@ export default function AgentChatPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 右侧服务区域 */}
|
{/* 右侧服务区域 */}
|
||||||
<div className="w-1/3 bg-white rounded-2xl border border-gray-200 p-4 overflow-y-auto">
|
<div className="w-[23%] bg-white rounded-2xl border border-gray-200 p-4 overflow-y-auto">
|
||||||
{/* 自助服务 */}
|
{/* 自助服务 */}
|
||||||
<div className="bg-gray-50 rounded-lg p-4 mb-4">
|
<div className="bg-gray-50 rounded-lg p-4 mb-4">
|
||||||
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
||||||
@@ -549,7 +546,7 @@ export default function AgentChatPage() {
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-2">
|
||||||
{suggestedQuestions.map((question, index) => (
|
{hotQuestions.map((question: string, index: number) => (
|
||||||
<li key={index}>
|
<li key={index}>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleQuickQuestion(question)}
|
onClick={() => handleQuickQuestion(question)}
|
||||||
@@ -562,38 +559,25 @@ export default function AgentChatPage() {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 快捷提问 */}
|
{/* 快捷提问 */}
|
||||||
<div className="bg-gray-50 rounded-lg p-4">
|
<div className="bg-gray-50 rounded-lg p-4">
|
||||||
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
<h3 className="font-medium text-gray-900 mb-3 flex items-center gap-2">
|
||||||
<i className="fas fa-question-circle text-blue-600"></i>
|
<i className="fas fa-question-circle text-blue-600"></i>
|
||||||
快捷提问
|
快捷提问
|
||||||
</h3>
|
</h3>
|
||||||
<div className="border-b border-gray-200 mb-3">
|
<ul className="space-y-2">
|
||||||
<div className="flex gap-4 text-sm">
|
{quickQuestions.map((question: string, index: number) => (
|
||||||
<button className="pb-2 border-b-2 border-blue-600 text-blue-600 font-medium">
|
|
||||||
养老服务
|
|
||||||
</button>
|
|
||||||
<button className="pb-2 border-b-2 border-transparent text-gray-500 hover:text-gray-700 transition">
|
|
||||||
健康管理
|
|
||||||
</button>
|
|
||||||
<button className="pb-2 border-b-2 border-transparent text-gray-500 hover:text-gray-700 transition">
|
|
||||||
生活服务
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ul className="space-y-1">
|
|
||||||
{['养老政策咨询', '养老机构推荐', '养老服务申请'].map((question, index) => (
|
|
||||||
<li key={index}>
|
<li key={index}>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleQuickQuestion(question)}
|
onClick={() => handleQuickQuestion(question)}
|
||||||
className="block py-2 px-3 text-sm text-gray-700 hover:bg-blue-50 rounded transition w-full text-left"
|
className="text-sm text-gray-700 hover:text-blue-600 transition block py-1 text-left"
|
||||||
>
|
>
|
||||||
{question}
|
• {question}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -18,11 +18,14 @@ export async function PUT(
|
|||||||
icon: data.icon || null,
|
icon: data.icon || null,
|
||||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||||
features: data.features || "",
|
features: data.features || "",
|
||||||
|
hotQuestions: data.hotQuestions || "[]",
|
||||||
|
quickQuestions: data.quickQuestions || "[]",
|
||||||
status: data.status || "active",
|
status: data.status || "active",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return NextResponse.json(agent)
|
return NextResponse.json(agent)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('PUT /api/admin/agents error:', error)
|
||||||
return NextResponse.json({ error: "更新失败" }, { status: 500 })
|
return NextResponse.json({ error: "更新失败" }, { status: 500 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export async function POST(request: NextRequest) {
|
|||||||
icon: data.icon || null,
|
icon: data.icon || null,
|
||||||
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
categoryId: data.categoryId ? parseInt(data.categoryId) : null,
|
||||||
features: data.features || "",
|
features: data.features || "",
|
||||||
|
hotQuestions: data.hotQuestions || "[]",
|
||||||
|
quickQuestions: data.quickQuestions || "[]",
|
||||||
status: data.status || "active",
|
status: data.status || "active",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Binary file not shown.
+9
-10
@@ -1,6 +1,3 @@
|
|||||||
// This is your Prisma schema file,
|
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
@@ -27,9 +24,9 @@ model Category {
|
|||||||
name String @unique
|
name String @unique
|
||||||
icon String?
|
icon String?
|
||||||
description String?
|
description String?
|
||||||
agents Agent[]
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
agents Agent[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Agent {
|
model Agent {
|
||||||
@@ -39,12 +36,14 @@ model Agent {
|
|||||||
description String
|
description String
|
||||||
icon String?
|
icon String?
|
||||||
categoryId Int?
|
categoryId Int?
|
||||||
category Category? @relation(fields: [categoryId], references: [id])
|
|
||||||
features String @default("")
|
features String @default("")
|
||||||
|
hotQuestions String @default("[]")
|
||||||
|
quickQuestions String @default("[]")
|
||||||
usageCount Int @default(0)
|
usageCount Int @default(0)
|
||||||
status String @default("active")
|
status String @default("active")
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
category Category? @relation(fields: [categoryId], references: [id])
|
||||||
conversations Conversation[]
|
conversations Conversation[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,22 +60,22 @@ model News {
|
|||||||
model Conversation {
|
model Conversation {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
agentId Int
|
agentId Int
|
||||||
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
|
||||||
userId Int?
|
userId Int?
|
||||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
||||||
title String @default("新对话")
|
title String @default("新对话")
|
||||||
messages Message[]
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
user User? @relation(fields: [userId], references: [id])
|
||||||
|
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
||||||
|
messages Message[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model Message {
|
model Message {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
conversationId Int
|
conversationId Int
|
||||||
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
role String
|
||||||
role String // 'user' 或 'assistant'
|
|
||||||
content String
|
content String
|
||||||
timestamp DateTime @default(now())
|
timestamp DateTime @default(now())
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,15 @@ async function main() {
|
|||||||
description: "适用于虚拟主播、数字客服、形象代言等场景,提供逼真的数字人交互体验。",
|
description: "适用于虚拟主播、数字客服、形象代言等场景,提供逼真的数字人交互体验。",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
prisma.category.upsert({
|
||||||
|
where: { name: "企业服务" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: "企业服务",
|
||||||
|
icon: "🏢",
|
||||||
|
description: "适用于企业专属AI助手、行业解决方案等场景,提供定制化智能服务。",
|
||||||
|
},
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
console.log("Created categories:", categories.map(c => c.name).join(", "))
|
console.log("Created categories:", categories.map(c => c.name).join(", "))
|
||||||
|
|
||||||
@@ -91,6 +100,17 @@ async function main() {
|
|||||||
icon: "🤖",
|
icon: "🤖",
|
||||||
categoryId: categories[0].id,
|
categoryId: categories[0].id,
|
||||||
features: "智能问答, 知识库查询, 工单提交",
|
features: "智能问答, 知识库查询, 工单提交",
|
||||||
|
hotQuestions: JSON.stringify([
|
||||||
|
"养老政策有哪些最新变化?",
|
||||||
|
"如何申请养老服务补贴?",
|
||||||
|
"老年人健康管理需要注意什么?",
|
||||||
|
"养老机构如何选择?",
|
||||||
|
]),
|
||||||
|
quickQuestions: JSON.stringify([
|
||||||
|
"养老政策咨询",
|
||||||
|
"养老机构推荐",
|
||||||
|
"养老服务申请",
|
||||||
|
]),
|
||||||
usageCount: 1000,
|
usageCount: 1000,
|
||||||
status: "active",
|
status: "active",
|
||||||
},
|
},
|
||||||
@@ -137,6 +157,48 @@ async function main() {
|
|||||||
status: "active",
|
status: "active",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
prisma.agent.upsert({
|
||||||
|
where: { slug: "jiaotou-ai-assistant" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: "交投集团AI助手",
|
||||||
|
slug: "jiaotou-ai-assistant",
|
||||||
|
description: "专为交投集团打造的智能助手,提供交通投资政策解读、项目分析、数据分析等专业化服务,助力企业决策。",
|
||||||
|
icon: "🚇",
|
||||||
|
categoryId: categories[6].id,
|
||||||
|
features: "政策解读, 项目分析, 数据分析, 决策支持",
|
||||||
|
usageCount: 120,
|
||||||
|
status: "active",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
prisma.agent.upsert({
|
||||||
|
where: { slug: "promotion-content-ai" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: "宣传文稿AI助手",
|
||||||
|
slug: "promotion-content-ai",
|
||||||
|
description: "智能生成各类宣传文稿,包括新闻稿、活动文案、品牌宣传、海报文案等,快速产出高质量宣传内容。",
|
||||||
|
icon: "📝",
|
||||||
|
categoryId: categories[1].id,
|
||||||
|
features: "新闻稿, 活动文案, 品牌宣传, 海报文案",
|
||||||
|
usageCount: 95,
|
||||||
|
status: "active",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
prisma.agent.upsert({
|
||||||
|
where: { slug: "group-policy-ai-assistant" },
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
name: "集团制度AI助手",
|
||||||
|
slug: "group-policy-ai-assistant",
|
||||||
|
description: "专注于集团规章制度解读与咨询,快速查询、解读各类制度文件,助力合规管理与制度落地。",
|
||||||
|
icon: "📋",
|
||||||
|
categoryId: categories[6].id,
|
||||||
|
features: "制度解读, 合规咨询, 文件查询, 制度培训",
|
||||||
|
usageCount: 50,
|
||||||
|
status: "active",
|
||||||
|
},
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
console.log("Created agents:", agents.map(a => a.name).join(", "))
|
console.log("Created agents:", agents.map(a => a.name).join(", "))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user