fix(captain): 修复 playground 500 — GetConfig nil pointer panic + 清理重复 buildSystemPrompt

根因:captain_assistants.config 中 temperature 字段为字符串 "0.5",
json.Unmarshal 到 float64 字段失败,GetConfig() 返回 nil,
调用方吞掉错误后 BuildAssistantPrompt 解引用 nil cfg 导致 panic。

修复:
- GetConfig() unmarshal 失败时返回空 &cfg{} 而非 nil,防止 nil dereference
- 删除 captain_assistant_service.go 中重复的 buildSystemPrompt 函数,
  统一使用 SystemPromptBuilder.BuildAssistantPrompt
- generatePlaygroundLLMResponse / GenerateResponse 增加
  ErrProviderNotConfigured 检查,返回 fallback 消息而非 500
This commit is contained in:
Rogee
2026-08-01 17:21:01 +08:00
parent bb4c4bb807
commit 31238476b1
2 changed files with 18 additions and 21 deletions
+5 -1
View File
@@ -2,6 +2,7 @@ package model
import (
"encoding/json"
"fmt"
"github.com/pgvector/pgvector-go"
)
@@ -118,7 +119,10 @@ func (a *CaptainAssistant) GetConfig() (*AssistantConfig, error) {
return &cfg, nil
}
if err := json.Unmarshal(a.Config, &cfg); err != nil {
return nil, err
// Return an empty config rather than nil so callers that ignore the
// error do not dereference a nil pointer. The raw JSON may contain
// type mismatches (e.g. temperature as string) from older data.
return &cfg, fmt.Errorf("parse assistant config: %w", err)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(a.Config, &fields); err == nil {