mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-06 21:11:50 +08:00
feat: 接入 Jev 拦截判定模型
Add TypeSafe System One as an isolated intercept judge backend.
This commit is contained in:
1 parent
0ed68d9143
commit
b0e25d766f
18 files changed
+552
-32
No files matched your search
+28
-2
@@ -139,7 +139,7 @@ func (d *DB) ProfileByID(id int64) (*LLMProfile, error) {
|
||||
// walk the slice front to back.
|
||||
func (d *DB) PoolProfiles() ([]*LLMProfile, error) {
|
||||
rows, err := d.Query(`SELECT ` + profileColsKey + ` FROM llm_profiles
|
||||
WHERE COALESCE(api_key,'') <> '' AND (is_default OR NOT pool_exclude)
|
||||
WHERE format <> 'jev' AND COALESCE(api_key,'') <> '' AND (is_default OR NOT pool_exclude)
|
||||
ORDER BY is_default DESC, priority DESC, id ASC`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -158,6 +158,12 @@ ORDER BY is_default DESC, priority DESC, id ASC`)
|
||||
|
||||
// SaveProfile inserts (id==0) or updates a profile. Empty apiKey on update keeps existing.
|
||||
func (d *DB) SaveProfile(p *LLMProfile) (int64, error) {
|
||||
if p.Format == "jev" && p.ID != 0 {
|
||||
var active bool
|
||||
if err := d.QueryRow(`SELECT is_default FROM llm_profiles WHERE id=$1`, p.ID).Scan(&active); err == nil && active {
|
||||
return 0, ErrJevProfileJudgeOnly
|
||||
}
|
||||
}
|
||||
hint := p.APIKeyHint
|
||||
if len(p.APIKey) >= 4 {
|
||||
hint = "…" + p.APIKey[len(p.APIKey)-4:]
|
||||
@@ -187,6 +193,7 @@ var (
|
||||
ErrActiveLLMProfileDelete = errors.New("cannot delete the active LLM profile; activate another profile first")
|
||||
ErrLLMProfileReferencesChanged = errors.New("LLM profile references changed while deleting; retry the request")
|
||||
ErrLLMProfileNotFound = errors.New("LLM profile not found")
|
||||
ErrJevProfileJudgeOnly = errors.New("Jev System One 配置仅可用于拦截判定模型,不能用于对话或任务")
|
||||
)
|
||||
|
||||
func (d *DB) DeleteProfile(id int64) error {
|
||||
@@ -422,6 +429,16 @@ func (d *DB) SetActiveProfile(id int64) error {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
var format string
|
||||
if err := tx.QueryRow(`SELECT format FROM llm_profiles WHERE id=$1 FOR KEY SHARE`, id).Scan(&format); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return ErrLLMProfileNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
if format == "jev" {
|
||||
return ErrJevProfileJudgeOnly
|
||||
}
|
||||
if _, err := tx.Exec(`UPDATE llm_profiles SET is_default=false WHERE is_default`); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -613,6 +630,15 @@ func (d *DB) SetAgentLLMProfile(key string, id *int64) error {
|
||||
if err := lockLLMProfileForReference(tx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
if id != nil {
|
||||
var format string
|
||||
if err := tx.QueryRow(`SELECT format FROM llm_profiles WHERE id=$1`, *id).Scan(&format); err != nil {
|
||||
return err
|
||||
}
|
||||
if format == "jev" {
|
||||
return ErrJevProfileJudgeOnly
|
||||
}
|
||||
}
|
||||
if _, err := tx.Exec(`UPDATE agents SET llm_profile_id=$1 WHERE id=$2`, id, agentID); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -815,7 +841,7 @@ type MCPServer struct {
|
||||
Env json.RawMessage `json:"env"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Insecure bool `json:"insecure"` // http: skip TLS cert verification (self-signed servers, issue #108)
|
||||
Insecure bool `json:"insecure"` // http: skip TLS cert verification (self-signed servers, issue #108)
|
||||
Tools []string `json:"tools,omitempty"` // cached tool names (mcp_tools_cache)
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,25 @@ func TestConfigStores(t *testing.T) {
|
||||
d.DeleteMCP(mid)
|
||||
}
|
||||
|
||||
func TestJevProfileCannotBeActivatedOrAgentBound(t *testing.T) {
|
||||
d, err := Open(testDSN(t))
|
||||
if err != nil {
|
||||
t.Skipf("postgres unavailable (%v) — skipping", err)
|
||||
}
|
||||
defer d.Close()
|
||||
id, err := d.SaveProfile(&LLMProfile{Name: "t-jev-only", Format: "jev", Model: "jev-latest", APIKey: "jev-key"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM llm_profiles WHERE id=$1`, id) })
|
||||
if err := d.SetActiveProfile(id); !errors.Is(err, ErrJevProfileJudgeOnly) {
|
||||
t.Fatalf("activate Jev error=%v, want %v", err, ErrJevProfileJudgeOnly)
|
||||
}
|
||||
if err := d.SetAgentLLMProfile("planner", &id); !errors.Is(err, ErrJevProfileJudgeOnly) {
|
||||
t.Fatalf("bind Jev error=%v, want %v", err, ErrJevProfileJudgeOnly)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s, sub string) bool {
|
||||
return len(s) >= len(sub) && (indexOf(s, sub) >= 0)
|
||||
}
|
||||
|
||||
+3
-3
@@ -362,7 +362,7 @@ CREATE TABLE IF NOT EXISTS settings (
|
||||
CREATE TABLE IF NOT EXISTS llm_profiles (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
format TEXT NOT NULL CHECK (format IN ('openai','anthropic','openai-responses')),
|
||||
format TEXT NOT NULL CHECK (format IN ('openai','anthropic','openai-responses','jev')),
|
||||
base_url TEXT,
|
||||
proxy TEXT,
|
||||
model TEXT NOT NULL,
|
||||
@@ -415,11 +415,11 @@ ALTER TABLE llm_profiles ADD COLUMN IF NOT EXISTS priority INTEGER NOT NULL
|
||||
ALTER TABLE llm_profiles ADD COLUMN IF NOT EXISTS pool_exclude BOOLEAN NOT NULL DEFAULT false;
|
||||
-- 流式开关;补旧库。默认 true = 保持既有的流式行为,旧配置无感升级。
|
||||
ALTER TABLE llm_profiles ADD COLUMN IF NOT EXISTS streaming BOOLEAN NOT NULL DEFAULT true;
|
||||
-- 放开 format 约束以容纳 openai-responses(OpenAI Responses API);补旧库。
|
||||
-- 放开 format 约束以容纳 openai-responses(OpenAI Responses API)和 Jev System One;补旧库。
|
||||
-- 每次启动执行,幂等:先删旧 CHECK 再建含三值的新 CHECK。
|
||||
ALTER TABLE llm_profiles DROP CONSTRAINT IF EXISTS llm_profiles_format_check;
|
||||
ALTER TABLE llm_profiles ADD CONSTRAINT llm_profiles_format_check
|
||||
CHECK (format IN ('openai','anthropic','openai-responses'));
|
||||
CHECK (format IN ('openai','anthropic','openai-responses','jev'));
|
||||
|
||||
-- 输出上限及其字段名;补旧库。默认 0 / '' = 不发送上限、沿用 max_tokens 字段名,
|
||||
-- 旧配置行为完全不变。
|
||||
|
||||
Reference in new issue
Block a user