feat(canvas): 画布工作区 - 整合侧栏与风格预设并修复提示词回填
选择性整合 #547,保留主分支节点与工具条设计。新增默认折叠的节点、资产、任务和历史面板,风格与预设保留在节点内,移除重复入口。 补齐工具权限、提示词解析、资源引用保护及数据库迁移,修复提示词清空和连续编辑后的生成配置同步。 验证:前端全量 1925 项测试、构建、类型检查及 lint 通过;后端 go test ./... 通过。真实模型、PostgreSQL 实库与登录态页面验收仍待进行。 Refs #547 Co-authored-by: bensharp <bensharp@qq.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion int64 = 29
|
||||
const CurrentSchemaVersion int64 = 31
|
||||
|
||||
const baselineSchemaChecksum = "sha256:open-ai-canvas-schema-v1-20260830"
|
||||
const schemaMigrationAppliedAtIndexChecksum = "sha256:schema-migrations-applied-at-index-v2-20260830"
|
||||
@@ -99,6 +99,12 @@ var schemaMigrations = []migration{
|
||||
{version: 29, name: "agent_resource_leases", checksum: "sha256:agent-resource-leases-v29-20260919", apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.CloudAgentResourceLease{})
|
||||
}},
|
||||
{version: 30, name: "builtin_tools", checksum: "sha256:builtin-tools-v30", apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.Tool{})
|
||||
}},
|
||||
{version: 31, name: "tool_favorites", checksum: "sha256:tool-favorites-v31", apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.ToolFavorite{})
|
||||
}},
|
||||
}
|
||||
|
||||
func migrateChannelCreditCost(tx *gorm.DB) error {
|
||||
|
||||
@@ -599,3 +599,76 @@ func TestMigrateSchemaV13AddsCloudAgentCanvasMutation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSchemaV30AddsBuiltinTools(t *testing.T) {
|
||||
db, err := Open(Config{Driver: "sqlite", DSN: "file:migration-builtin-tools-v30?mode=memory&cache=shared"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !db.Migrator().HasTable(&model.Tool{}) {
|
||||
t.Fatal("migration v30 did not create tools table")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateSchemaV31AddsToolUserActions(t *testing.T) {
|
||||
db, err := Open(Config{Driver: "sqlite", DSN: "file:migration-tool-user-actions-v31?mode=memory&cache=shared"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !db.Migrator().HasTable(&model.ToolFavorite{}) {
|
||||
t.Fatal("migration v31 did not create tool_favorites table")
|
||||
}
|
||||
}
|
||||
|
||||
func TestToolsUpgradeFromMain29PreservesMigrationChecksums(t *testing.T) {
|
||||
db, err := Open(Config{Driver: "sqlite", DSN: "file:tools-main29-upgrade?mode=memory&cache=shared"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.AutoMigrate(&schemaMigration{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, item := range schemaMigrations {
|
||||
if item.version > 29 {
|
||||
break
|
||||
}
|
||||
if err := item.apply(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&schemaMigration{Version: item.version, Name: item.name, Checksum: item.checksum, AppliedAt: time.Now()}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// The initial migration uses today's model registry; restore the actual v29
|
||||
// boundary so this test proves that v30/v31 create the new tables.
|
||||
if err := db.Migrator().DropTable(&model.ToolFavorite{}, &model.Tool{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if db.Migrator().HasTable(&model.Tool{}) || db.Migrator().HasTable(&model.ToolFavorite{}) {
|
||||
t.Fatal("tool tables must not exist before upgrading v29")
|
||||
}
|
||||
for range 2 {
|
||||
if err := MigrateSchema(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, version := range []int64{28, 29} {
|
||||
var record schemaMigration
|
||||
if err := db.First(&record, version).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := map[int64]string{28: "sha256:agent-execution-journal-v28", 29: "sha256:agent-resource-leases-v29-20260919"}
|
||||
if record.Checksum != expected[version] {
|
||||
t.Fatal("main checksum changed")
|
||||
}
|
||||
}
|
||||
if !db.Migrator().HasTable(&model.Tool{}) || !db.Migrator().HasTable(&model.ToolFavorite{}) {
|
||||
t.Fatal("tools tables missing")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ func Models() []any {
|
||||
&model.SkillVersion{},
|
||||
&model.SkillFile{},
|
||||
&model.UserSkillState{},
|
||||
&model.Tool{},
|
||||
&model.ToolFavorite{},
|
||||
&model.Resource{},
|
||||
&model.ResourceDeletionJob{},
|
||||
&model.AnnouncementImageDraft{},
|
||||
|
||||
Reference in New Issue
Block a user