feat(merge): 以官方 main 为基底融合 PR#530 多维表格与本地定制
- 多维表格(canvas-batch-table-node/use-canvas-batch-table/canvas-batch-table 等)以 PR#530 实现为主 - 保留官方 main 全部新功能:banner/画布版本历史/提示词编辑/方舟 Agent Plan/支付导出 - 移植本地定制:ddcat 多参考图校验、万有引力 lxmone 连接错误提示、Description v20(v24)、自建插件(a6api/metaso-h3/antigravity-proxy/lxmone)、seccomp、Windows 脚本 - 迁移版本升至 v24(官方 v20-23 banner/版本历史 + 我们的 Description 列) - 修复官方缺失的 markdownPlainText import
This commit is contained in:
1 parent
4eaa28b807
commit
9b9a7f4a72
63 files changed
+9087
-892
No files matched your search
@@ -22,6 +22,7 @@ type ChannelModelRequest struct {
|
||||
ProviderModelKey string `json:"providerModelKey"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Icon string `json:"icon"`
|
||||
Description string `json:"description"`
|
||||
Capability string `json:"capability"`
|
||||
Protocol string `json:"protocol"`
|
||||
BillingMode string `json:"billingMode"`
|
||||
@@ -351,6 +352,7 @@ func (s *Service) SaveAdminChannelModel(actor *model.User, channelID string, id
|
||||
item.DisplayName = modelKey
|
||||
}
|
||||
item.Icon = strings.TrimSpace(req.Icon)
|
||||
item.Description = truncateRunes(strings.TrimSpace(req.Description), 600)
|
||||
item.Capability = capability
|
||||
item.Protocol = protocol
|
||||
s.applyChannelModelPriceTierSummary(item, tiers)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"image"
|
||||
_ "image/png"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Opt-in only: this test makes two paid requests and never logs credentials or payloads.
|
||||
func TestDDCatLiveImageRoundTrip(t *testing.T) {
|
||||
key := os.Getenv("DDCAT_SMOKE_API_KEY")
|
||||
if key == "" {
|
||||
t.Skip("set DDCAT_SMOKE_API_KEY to explicitly enable paid live verification")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Minute)
|
||||
defer cancel()
|
||||
ctx = withProtocolRegistry(ctx, loadOfficialFallbackRegistry())
|
||||
input := canvasGenerationInput{Mode: "image", Prompt: "A single blue ceramic cup on a plain white background, no text.", Config: providerConfig{BaseURL: "https://api.ddcat.pronhubcn.com/v1", APIKey: key, Model: "gpt-image-2.5", InterfaceType: "openai-image", Size: "1:1"}}
|
||||
for _, mode := range []string{"generate", "edit"} {
|
||||
result, err := runImageTask(ctx, input)
|
||||
if err != nil {
|
||||
t.Fatalf("%s failed: %v", mode, err)
|
||||
}
|
||||
images, ok := result["images"].([]interface{})
|
||||
if !ok || len(images) == 0 {
|
||||
t.Fatalf("%s returned no images", mode)
|
||||
}
|
||||
item, ok := images[0].(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatal("invalid image result")
|
||||
}
|
||||
dataURL := stringField(item, "dataUrl")
|
||||
_, encoded, ok := strings.Cut(dataURL, ",")
|
||||
if !ok {
|
||||
t.Fatal("missing inline image")
|
||||
}
|
||||
raw, err := base64.StdEncoding.DecodeString(encoded)
|
||||
if err != nil {
|
||||
t.Fatal("invalid image base64")
|
||||
}
|
||||
info, format, err := image.DecodeConfig(bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("invalid image bytes: %v", err)
|
||||
}
|
||||
t.Logf("%s: %s %dx%d, %d bytes", mode, format, info.Width, info.Height, len(raw))
|
||||
if dir := os.Getenv("DDCAT_SMOKE_OUTPUT"); dir != "" {
|
||||
if err := os.WriteFile(dir+"/"+mode+".png", raw, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
input.ReferenceImages = []providerMedia{{Name: "reference.png", Type: "image/png", DataURL: dataURL}}
|
||||
input.Prompt = "Change the blue cup to red. Keep the white background and composition."
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ type PublicChannelModel struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
SortOrder int `json:"sortOrder"`
|
||||
Icon string `json:"icon"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Capability string `json:"capability"`
|
||||
Protocol model.ChannelInterfaceType `json:"protocol"`
|
||||
CapabilityConfig map[string]any `json:"capabilityConfig,omitempty"`
|
||||
@@ -204,6 +205,7 @@ func (s *Service) sanitizeChannelModel(cm *model.ChannelModel) (PublicChannelMod
|
||||
DisplayName: cm.DisplayName,
|
||||
SortOrder: cm.SortOrder,
|
||||
Icon: cm.Icon,
|
||||
Description: cm.Description,
|
||||
Capability: cm.Capability,
|
||||
Protocol: cm.Protocol,
|
||||
CapabilityConfig: capabilityConfig,
|
||||
|
||||
@@ -271,6 +271,7 @@ func doBinaryWithConsumer(req *http.Request, onChunk func(string, []byte)) ([]by
|
||||
client := OutboundHTTPClient(requestTimeout)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
err = providerConnectionError(err)
|
||||
if runtimeService != nil {
|
||||
_ = runtimeService.RecordChannelResult(req.Context(), channelID, !errors.Is(err, context.Canceled))
|
||||
}
|
||||
@@ -304,6 +305,7 @@ func doBinaryWithConsumer(req *http.Request, onChunk func(string, []byte)) ([]by
|
||||
break
|
||||
}
|
||||
if readErr != nil {
|
||||
readErr = providerConnectionError(readErr)
|
||||
recordProviderRequest(req, startedAt, resp.StatusCode, buffered.Bytes(), readErr)
|
||||
return nil, "", readErr
|
||||
}
|
||||
@@ -329,6 +331,13 @@ func doBinaryWithConsumer(req *http.Request, onChunk func(string, []byte)) ([]by
|
||||
return data, mimeType, nil
|
||||
}
|
||||
|
||||
func providerConnectionError(err error) error {
|
||||
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
||||
return fmt.Errorf("模型服务连接提前关闭,未收到完整结果;请先核对中转站任务和扣费记录,再决定是否重试:%w", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func parseRetryAfter(value string, now time.Time) time.Duration {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
|
||||
@@ -19,6 +19,11 @@ import (
|
||||
)
|
||||
|
||||
func runImageTask(ctx context.Context, input canvasGenerationInput) (map[string]interface{}, error) {
|
||||
if input.Config.InterfaceType == string(model.ChannelInterfaceOpenAIImage) {
|
||||
if err := validateOpenAIImageInput(input); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if _, ok := declarativeProtocolAdapterForContext(ctx, input.Config.InterfaceType); ok {
|
||||
return runDeclarativeProtocolTask(ctx, input)
|
||||
}
|
||||
@@ -113,6 +118,30 @@ func runImageTask(ctx context.Context, input canvasGenerationInput) (map[string]
|
||||
return map[string]interface{}{"mode": "image", "images": images}, nil
|
||||
}
|
||||
|
||||
// Validate before selecting the plugin so declarative and handwritten paths share
|
||||
// the same write boundary. Invalid explicit sizes must not silently become auto.
|
||||
func validateOpenAIImageInput(input canvasGenerationInput) error {
|
||||
if input.Mask != nil && len(input.ReferenceImages) == 0 {
|
||||
return errors.New("蒙版编辑必须提供与蒙版同尺寸的源图片")
|
||||
}
|
||||
raw := strings.TrimSpace(input.Config.Size)
|
||||
if raw == "" || raw == "auto" {
|
||||
return nil
|
||||
}
|
||||
size := normalizePixelSize(raw)
|
||||
widthText, heightText, ok := strings.Cut(size, "x")
|
||||
width, widthErr := strconv.Atoi(widthText)
|
||||
height, heightErr := strconv.Atoi(heightText)
|
||||
if !ok || widthErr != nil || heightErr != nil || width <= 0 || height <= 0 {
|
||||
return errors.New("图片尺寸无效:请选择支持的宽高比或填写正整数像素尺寸,如 1024x1024")
|
||||
}
|
||||
base, err := url.Parse(input.Config.BaseURL)
|
||||
if err == nil && strings.EqualFold(base.Hostname(), "api.ddcat.pronhubcn.com") && (width > 4096 || height > 4096) {
|
||||
return errors.New("ddcat 图片尺寸超过上游限制:宽和高均不得超过 4096 像素")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runGeminiImageTask(ctx context.Context, input canvasGenerationInput) (map[string]interface{}, error) {
|
||||
if input.Mask != nil {
|
||||
return nil, errors.New("Gemini Images 不支持蒙版编辑,请移除蒙版后重试")
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenAIImageRejectsInvalidSizeBeforeSubmission(t *testing.T) {
|
||||
for _, size := range []string{"banana", "7:0", "0x1024", "-1x1024", "4097x1024", "1024x5000"} {
|
||||
t.Run(size, func(t *testing.T) {
|
||||
_, err := runImageTask(context.Background(), canvasGenerationInput{Mode: "image", Config: providerConfig{InterfaceType: "openai-image", BaseURL: "https://api.ddcat.pronhubcn.com/v1", Size: size}})
|
||||
if err == nil || !strings.Contains(err.Error(), "尺寸") {
|
||||
t.Fatalf("expected local size rejection: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, size := range []string{"", "auto", "1:1", "16:9", "1024x1024", "4096x4096"} {
|
||||
if err := validateOpenAIImageInput(canvasGenerationInput{Config: providerConfig{Size: size}}); err != nil {
|
||||
t.Fatalf("valid size %q: %v", size, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenAIImageRejectsMaskWithoutSourceBeforePlugin(t *testing.T) {
|
||||
_, err := runImageTask(context.Background(), canvasGenerationInput{Mode: "image", Config: providerConfig{InterfaceType: "openai-image"}, Mask: &providerMedia{ID: "mask"}})
|
||||
if err == nil || !strings.Contains(err.Error(), "源图片") {
|
||||
t.Fatalf("expected missing source rejection: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderConnectionErrorPreservesCause(t *testing.T) {
|
||||
for _, cause := range []error{io.EOF, io.ErrUnexpectedEOF} {
|
||||
err := providerConnectionError(cause)
|
||||
if !errors.Is(err, cause) || !strings.Contains(err.Error(), "扣费记录") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
if providerConnectionError(context.Canceled) != context.Canceled {
|
||||
t.Fatal("cancellation must remain unchanged")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageSubmissionEOFIsNotAutomaticallyReplayed(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
calls := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
calls++
|
||||
conn, _, err := w.(http.Hijacker).Hijack()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
conn.Close()
|
||||
}))
|
||||
defer server.Close()
|
||||
err := postJSON(context.Background(), providerConfig{BaseURL: server.URL}, "/v1/images/generations", map[string]string{"prompt": "cup"}, &map[string]interface{}{})
|
||||
if err == nil || !strings.Contains(err.Error(), "连接提前关闭") || calls != 1 {
|
||||
t.Fatalf("calls=%d error=%v", calls, err)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"infinite-canvas/backend/internal/model"
|
||||
"infinite-canvas/backend/internal/protocol"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -186,6 +187,10 @@ func protocolRequestFromInput(input canvasGenerationInput) protocol.GenerationRe
|
||||
resolution = declared
|
||||
}
|
||||
}
|
||||
aspectRatio := input.Config.Size
|
||||
if input.Mode == "image" && strings.TrimSpace(input.Config.InterfaceType) == string(model.ChannelInterfaceOpenAIImage) {
|
||||
aspectRatio = normalizePixelSize(aspectRatio)
|
||||
}
|
||||
request := protocol.GenerationRequest{
|
||||
Capability: protocol.Capability(input.Mode),
|
||||
Model: input.Config.Model,
|
||||
@@ -194,7 +199,7 @@ func protocolRequestFromInput(input canvasGenerationInput) protocol.GenerationRe
|
||||
Images: protocolImageReferences(input),
|
||||
Videos: protocolMediaReferences(input.ReferenceVideos, "video"),
|
||||
Audios: protocolMediaReferences(input.ReferenceAudios, "audio"),
|
||||
AspectRatio: input.Config.Size,
|
||||
AspectRatio: aspectRatio,
|
||||
Resolution: resolution,
|
||||
Quality: input.Config.Quality,
|
||||
GenerateAudio: parseBool(input.Config.VideoGenerateAudio, false),
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion int64 = 23
|
||||
const CurrentSchemaVersion int64 = 24
|
||||
|
||||
const baselineSchemaChecksum = "sha256:open-ai-canvas-schema-v1-20260830"
|
||||
const schemaMigrationAppliedAtIndexChecksum = "sha256:schema-migrations-applied-at-index-v2-20260830"
|
||||
@@ -89,6 +89,16 @@ var schemaMigrations = []migration{
|
||||
{version: 23, name: "canvas_revision_history", checksum: "sha256:canvas-revision-history-v23-20260918", apply: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.CanvasProject{}, &model.CanvasSnapshot{}, &model.CanvasSnapshotResource{})
|
||||
}},
|
||||
{version: 24, name: "channel_model_description", checksum: "sha256:channel-model-description-v24-20260918", apply: migrateSchemaV24},
|
||||
}
|
||||
|
||||
// migrateSchemaV24 为系统渠道模型补充面向用户的说明字段。
|
||||
// 说明只用于前台选型展示,存量模型保持空说明,不影响价格、路由与结算。
|
||||
func migrateSchemaV24(tx *gorm.DB) error {
|
||||
if !tx.Migrator().HasColumn(&model.ChannelModel{}, "Description") {
|
||||
return tx.Migrator().AddColumn(&model.ChannelModel{}, "Description")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateSchemaV14(tx *gorm.DB) error {
|
||||
|
||||
@@ -44,6 +44,7 @@ type ChannelModel struct {
|
||||
DisplayName string `json:"displayName" gorm:"size:160"`
|
||||
SortOrder int `json:"sortOrder" gorm:"not null;default:0"`
|
||||
Icon string `json:"icon" gorm:"size:80"`
|
||||
Description string `json:"description" gorm:"size:600"`
|
||||
Capability string `json:"capability" gorm:"size:32;index"`
|
||||
Protocol ChannelInterfaceType `json:"protocol" gorm:"size:32;index"`
|
||||
BillingMode string `json:"billingMode" gorm:"size:32"`
|
||||
|
||||
Reference in new issue
Block a user