Update application code and dependencies
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Page" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"slug" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Setting" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"key" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Page_slug_key" ON "Page"("slug");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Setting_key_key" ON "Setting"("key");
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `Page` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `Setting` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
PRAGMA foreign_keys=off;
|
||||
DROP TABLE "Page";
|
||||
PRAGMA foreign_keys=on;
|
||||
|
||||
-- DropTable
|
||||
PRAGMA foreign_keys=off;
|
||||
DROP TABLE "Setting";
|
||||
PRAGMA foreign_keys=on;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"email" TEXT NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"name" TEXT,
|
||||
"role" TEXT NOT NULL DEFAULT 'admin',
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Category" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" TEXT NOT NULL,
|
||||
"icon" TEXT,
|
||||
"description" TEXT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Agent" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" TEXT NOT NULL,
|
||||
"slug" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"icon" TEXT,
|
||||
"categoryId" INTEGER,
|
||||
"features" TEXT NOT NULL DEFAULT '',
|
||||
"usageCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"status" TEXT NOT NULL DEFAULT 'active',
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Agent_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "News" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"title" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"type" TEXT NOT NULL DEFAULT 'news',
|
||||
"published" BOOLEAN NOT NULL DEFAULT false,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Category_name_key" ON "Category"("name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Agent_slug_key" ON "Agent"("slug");
|
||||
@@ -0,0 +1,23 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Conversation" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"agentId" INTEGER NOT NULL,
|
||||
"userId" INTEGER,
|
||||
"title" TEXT NOT NULL DEFAULT '新对话',
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Conversation_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "Agent" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Message" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"conversationId" INTEGER NOT NULL,
|
||||
"role" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"timestamp" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Message_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "Conversation" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "sqlite"
|
||||
@@ -0,0 +1,82 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
username String @unique
|
||||
password String
|
||||
name String?
|
||||
role String @default("admin")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
conversations Conversation[]
|
||||
}
|
||||
|
||||
model Category {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
icon String?
|
||||
description String?
|
||||
agents Agent[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Agent {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
slug String @unique
|
||||
description String
|
||||
icon String?
|
||||
categoryId Int?
|
||||
category Category? @relation(fields: [categoryId], references: [id])
|
||||
features String @default("")
|
||||
usageCount Int @default(0)
|
||||
status String @default("active")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
conversations Conversation[]
|
||||
}
|
||||
|
||||
model News {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
content String
|
||||
type String @default("news")
|
||||
published Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Conversation {
|
||||
id Int @id @default(autoincrement())
|
||||
agentId Int
|
||||
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
title String @default("新对话")
|
||||
messages Message[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Message {
|
||||
id Int @id @default(autoincrement())
|
||||
conversationId Int
|
||||
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
||||
role String // 'user' 或 'assistant'
|
||||
content String
|
||||
timestamp DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
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: "适用于虚拟主播、数字客服、形象代言等场景,提供逼真的数字人交互体验。",
|
||||
},
|
||||
}),
|
||||
])
|
||||
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: "智能问答, 知识库查询, 工单提交",
|
||||
usageCount: 1000,
|
||||
status: "active",
|
||||
},
|
||||
}),
|
||||
prisma.agent.upsert({
|
||||
where: { slug: "writing-assistant-pro" },
|
||||
update: {},
|
||||
create: {
|
||||
name: "写作助手 Pro",
|
||||
slug: "writing-assistant-pro",
|
||||
description: "营销文案、博客文章、邮件草稿,输入关键词即可生成高质量内容。",
|
||||
icon: "✍️",
|
||||
categoryId: categories[1].id,
|
||||
features: "营销文案, 博客文章, 邮件草稿",
|
||||
usageCount: 850,
|
||||
status: "active",
|
||||
},
|
||||
}),
|
||||
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",
|
||||
},
|
||||
}),
|
||||
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",
|
||||
},
|
||||
}),
|
||||
])
|
||||
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()
|
||||
})
|
||||
Reference in New Issue
Block a user