Refactor assistant configuration and database seeding

- Update Makefile to include new database seed commands for assistants and credentials.
- Refactor assistant model to use explicit fields instead of a config dictionary, improving data integrity and clarity.
- Implement new seeding SQL script for assistants, ensuring dependencies on credentials are respected.
- Modify backend routes and frontend components to accommodate the new assistant structure, including direct field access for prompt, API URL, and keys.
- Enhance the AssistantPage component to handle the new data structure and streamline the save process for different assistant types.
This commit is contained in:
Xin Wang
2026-06-09 10:37:29 +08:00
parent 23e1cf5d42
commit 519cc0fefe
8 changed files with 197 additions and 185 deletions

View File

@@ -7,7 +7,7 @@
PSQL = docker compose exec -T postgres psql -U postgres -d postgres
.DEFAULT_GOAL := help
.PHONY: help up down restart logs api-logs db db-list db-seed db-clear db-reset
.PHONY: help up down restart logs api-logs db db-list db-seed db-seed-credentials db-seed-assistants db-clear db-reset
help: ## 列出所有可用目标
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
@@ -33,13 +33,19 @@ api-logs: ## 只看后端日志
db: ## 进入交互式 psql
docker compose exec postgres psql -U postgres -d postgres
db-list: ## 列出模型凭证(key 明文,仅本地调试用)
db-list: ## 列出凭证与助手(key 明文,仅本地调试用)
@$(PSQL) -c "SELECT id, name, type, interface_type, is_default FROM provider_credentials ORDER BY id;"
@$(PSQL) -c "SELECT id, name, type FROM assistants ORDER BY id;"
db-seed: ## 灌入 12 条模型凭证种子(幂等)
db-seed-credentials: ## 灌入 12 条模型凭证种子(幂等)
$(PSQL) < backend/db/seed_credentials.sql
db-clear: ## 清空模型凭证表
$(PSQL) -c "TRUNCATE provider_credentials;"
db-seed-assistants: ## 灌入 知识库 + 助手 种子(幂等;依赖凭证已就绪)
$(PSQL) < backend/db/seed_assistants.sql
db-reset: db-clear db-seed ## 清空后重新灌种子
db-seed: db-seed-credentials db-seed-assistants ## 全量灌种子(凭证→知识库→助手,幂等,可重复执行)
db-clear: ## 清空 助手/知识库/凭证 三表(按依赖顺序)
$(PSQL) -c "TRUNCATE assistants, knowledge_bases, provider_credentials CASCADE;"
db-reset: db-clear db-seed ## 清空后重新灌全部种子