Files
ai-portal/prisma/seed.ts
T
root f2d7037ca2 feat: add save feedback prompts, featured agent fields, dynamic Dify API config, and chat improvements
- Add success/error feedback messages near submit buttons in all admin forms
- Display success prompt for 1s before redirect after save
- Show API error details on save failure
- Add isFeatured/featuredOrder fields to Agent model and admin UI
- Add difyApiUrl/difyApiKey fields for per-agent Dify API configuration
- Show featured badge column in agent admin list
- Display featured agents on homepage sorted by order
- Refactor chat page streaming with AbortController and stable userId
- Improve Dify API proxy to use per-agent credentials
2026-05-08 20:15:54 +08:00

271 lines
8.8 KiB
TypeScript

import { PrismaClient } from "@prisma/client"
import bcrypt from "bcryptjs"
const prisma = new PrismaClient()
async function main() {
// 创建管理员用户
const hashedPassword = await bcrypt.hash("admin123", 10)
const admin = await prisma.user.upsert({
where: { username: "admin" },
update: {},
create: {
email: "admin@nextapp.com",
username: "admin",
password: hashedPassword,
name: "管理员",
role: "admin",
},
})
console.log("Created admin user:", admin.username)
// 创建分类
const categories = await Promise.all([
prisma.category.upsert({
where: { name: "客服" },
update: {},
create: {
name: "客服",
icon: "🤖",
description: "适用于企业客服、在线问答、售后支持等场景,7×24小时在线服务。",
},
}),
prisma.category.upsert({
where: { name: "写作" },
update: {},
create: {
name: "写作",
icon: "✍️",
description: "适用于营销文案、博客文章、邮件草稿等场景,快速生成高质量内容。",
},
}),
prisma.category.upsert({
where: { name: "数据分析" },
update: {},
create: {
name: "数据分析",
icon: "📊",
description: "适用于数据清洗、分析、可视化等场景,自动生成结构化分析报告。",
},
}),
prisma.category.upsert({
where: { name: "编程" },
update: {},
create: {
name: "编程",
icon: "💻",
description: "适用于代码审查、SQL生成等场景,提高开发效率,减少bug。",
},
}),
prisma.category.upsert({
where: { name: "生活娱乐" },
update: {},
create: {
name: "生活娱乐",
icon: "✈️",
description: "适用于旅行规划、菜谱推荐等场景,让生活更加便捷智能。",
},
}),
prisma.category.upsert({
where: { name: "数字人" },
update: {},
create: {
name: "数字人",
icon: "🧑‍💼",
description: "适用于虚拟主播、数字客服、形象代言等场景,提供逼真的数字人交互体验。",
},
}),
prisma.category.upsert({
where: { name: "企业服务" },
update: {},
create: {
name: "企业服务",
icon: "🏢",
description: "适用于企业专属AI助手、行业解决方案等场景,提供定制化智能服务。",
},
}),
])
console.log("Created categories:", categories.map(c => c.name).join(", "))
// 创建智能体
const agents = await Promise.all([
prisma.agent.upsert({
where: { slug: "smart-customer-service" },
update: {},
create: {
name: "智能客服助手",
slug: "smart-customer-service",
description: "7×24 小时在线,精准理解用户意图,自动处理常见咨询,支持多轮对话。",
icon: "🤖",
categoryId: categories[0].id,
features: "智能问答, 知识库查询, 工单提交",
hotQuestions: JSON.stringify([
"养老政策有哪些最新变化?",
"如何申请养老服务补贴?",
"老年人健康管理需要注意什么?",
"养老机构如何选择?",
]),
quickQuestions: JSON.stringify([
"养老政策咨询",
"养老机构推荐",
"养老服务申请",
]),
usageCount: 1000,
status: "active",
isFeatured: true,
featuredOrder: 1,
difyApiUrl: "https://api.dify.ai/v1",
difyApiKey: "app-demo-key-123456",
},
}),
prisma.agent.upsert({
where: { slug: "huaiqi-secretary" },
update: {},
create: {
name: "淮企小秘书",
slug: "huaiqi-secretary",
description: "专为淮安企业打造的智能秘书,提供政策解读、企业办事指南、惠企政策查询等一站式服务,助力企业高效运营。",
icon: "🏢",
categoryId: categories[6].id,
features: "政策解读, 企业办事指南, 惠企政策, 智能问答",
hotQuestions: JSON.stringify([
"到淮安这边投资,项目审批快吗?",
"目前淮安对绿色工厂有哪些支持政策?",
"请问企业实施技术改造项目,淮安市有哪些支持政策?",
"淮安有哪些产业配套服务?",
]),
quickQuestions: JSON.stringify([
"惠企政策查询",
"企业办事指南",
"政策解读",
]),
usageCount: 850,
status: "active",
isFeatured: true,
featuredOrder: 2,
},
}),
prisma.agent.upsert({
where: { slug: "data-analysis-master" },
update: {},
create: {
name: "数据分析大师",
slug: "data-analysis-master",
description: "上传 CSV/Excel,自动清洗、分析、可视化,输出结构化分析报告。",
icon: "📊",
categoryId: categories[2].id,
features: "数据清洗, 数据可视化, 分析报告",
usageCount: 620,
status: "active",
isFeatured: true,
featuredOrder: 3,
},
}),
prisma.agent.upsert({
where: { slug: "digital-human-assistant" },
update: {},
create: {
name: "数字人助手",
slug: "digital-human-assistant",
description: "超写实数字人,支持语音交互、表情动画、多场景应用,适用于虚拟主播、智能客服、形象代言等场景。",
icon: "🧑‍💼",
categoryId: categories[5].id,
features: "语音交互, 表情动画, 虚拟主播, 智能客服",
usageCount: 380,
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(", "))
// 创建新闻
const news = await Promise.all([
prisma.news.upsert({
where: { id: 1 },
update: {},
create: {
title: "智能客服助手 3.0 正式上线,支持多模态交互",
content: "全新版本集成图像识别与语音交互能力,响应速度提升 40%,企业客户满意度评分达 4.9/5.0。",
type: "news",
published: true,
},
}),
prisma.news.upsert({
where: { id: 2 },
update: {},
create: {
title: "2026 AI Agent 市场白皮书:企业渗透率突破 35%",
content: "据最新行业报告,AI 智能体正在从尝鲜阶段走向规模化落地,客服与内容生成场景率先规模化。",
type: "industry",
published: true,
},
}),
prisma.news.upsert({
where: { id: 3 },
update: {},
create: {
title: "江苏冲浪软件科技与华为云达成战略合作",
content: "双方将在 AI 智能体研发、云端部署与行业解决方案展开深度合作,首期联合创新实验室正式揭牌。",
type: "cooperation",
published: true,
},
}),
])
console.log("Created news:", news.map(n => n.title).join(", "))
console.log("Seed data created successfully!")
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})