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
This commit is contained in:
root
2026-05-08 20:15:54 +08:00
parent 362c37fb42
commit f2d7037ca2
16 changed files with 298 additions and 102 deletions
BIN
View File
Binary file not shown.
@@ -0,0 +1,29 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_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 '',
"hotQuestions" TEXT NOT NULL DEFAULT '[]',
"quickQuestions" TEXT NOT NULL DEFAULT '[]',
"difyApiUrl" TEXT,
"difyApiKey" TEXT,
"usageCount" INTEGER NOT NULL DEFAULT 0,
"status" TEXT NOT NULL DEFAULT 'active',
"isFeatured" BOOLEAN NOT NULL DEFAULT false,
"featuredOrder" INTEGER NOT NULL DEFAULT 0,
"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
);
INSERT INTO "new_Agent" ("categoryId", "createdAt", "description", "features", "icon", "id", "name", "slug", "status", "updatedAt", "usageCount") SELECT "categoryId", "createdAt", "description", "features", "icon", "id", "name", "slug", "status", "updatedAt", "usageCount" FROM "Agent";
DROP TABLE "Agent";
ALTER TABLE "new_Agent" RENAME TO "Agent";
CREATE UNIQUE INDEX "Agent_slug_key" ON "Agent"("slug");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
+4
View File
@@ -39,8 +39,12 @@ model Agent {
features String @default("")
hotQuestions String @default("[]")
quickQuestions String @default("[]")
difyApiUrl String?
difyApiKey String?
usageCount Int @default(0)
status String @default("active")
isFeatured Boolean @default(false)
featuredOrder Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
category Category? @relation(fields: [categoryId], references: [id])
+40 -21
View File
@@ -113,20 +113,37 @@ async function main() {
]),
usageCount: 1000,
status: "active",
isFeatured: true,
featuredOrder: 1,
difyApiUrl: "https://api.dify.ai/v1",
difyApiKey: "app-demo-key-123456",
},
}),
prisma.agent.upsert({
where: { slug: "writing-assistant-pro" },
where: { slug: "huaiqi-secretary" },
update: {},
create: {
name: "写作助手 Pro",
slug: "writing-assistant-pro",
description: "营销文案、博客文章、邮件草稿,输入关键词即可生成高质量内容。",
icon: "✍️",
categoryId: categories[1].id,
features: "营销文案, 博客文章, 邮件草稿",
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({
@@ -141,6 +158,8 @@ async function main() {
features: "数据清洗, 数据可视化, 分析报告",
usageCount: 620,
status: "active",
isFeatured: true,
featuredOrder: 3,
},
}),
prisma.agent.upsert({
@@ -185,20 +204,20 @@ async function main() {
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",
},
}),
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(", "))