From fc2c12e8ec08efc9b948438fb720db1ff88ca9ca Mon Sep 17 00:00:00 2001 From: hujiaxin Date: Mon, 14 Sep 2026 17:57:49 +0800 Subject: [PATCH] fix(models): protect auto-tag model references --- docs/api/model.md | 2 +- frontend/src/api/model/modelUsage.test.ts | 1 + frontend/src/api/model/modelUsage.ts | 2 ++ frontend/src/i18n/locales/en-US.ts | 1 + frontend/src/i18n/locales/ja-JP.ts | 1 + frontend/src/i18n/locales/ko-KR.ts | 1 + frontend/src/i18n/locales/ru-RU.ts | 1 + frontend/src/i18n/locales/zh-CN.ts | 1 + .../application/repository/knowledgebase.go | 2 +- internal/application/repository/model_usage.go | 15 ++++++++++----- .../application/repository/model_usage_test.go | 17 +++++++++++++++++ internal/types/model.go | 1 + website-docs/04-api/02-api-model-system.md | 2 +- 13 files changed, 39 insertions(+), 8 deletions(-) diff --git a/docs/api/model.md b/docs/api/model.md index 9a8b16e7..a21deecd 100644 --- a/docs/api/model.md +++ b/docs/api/model.md @@ -458,7 +458,7 @@ curl --location --request DELETE 'http://localhost:8080/api/v1/models/8fdc464d-8 } ``` -`bindings` 是稳定的配置类型标识:知识库可能返回 `embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`;智能体可能返回 `chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆可能返回 `embedding_model`、`extract_model`。同一对象的多处引用会合并到一个 `bindings` 数组。`knowledge_bases` / `agents` 最多各返回 50 条;未截断的引用数在 `knowledge_base_total` / `agent_total`。404 表示模型不存在。 +`bindings` 是稳定的配置类型标识:知识库可能返回 `embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`、`auto_tag_model`;智能体可能返回 `chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆可能返回 `embedding_model`、`extract_model`。同一对象的多处引用会合并到一个 `bindings` 数组。`knowledge_bases` / `agents` 最多各返回 50 条;未截断的引用数在 `knowledge_base_total` / `agent_total`。404 表示模型不存在。 ## 参数说明 diff --git a/frontend/src/api/model/modelUsage.test.ts b/frontend/src/api/model/modelUsage.test.ts index bbd195b9..a6e0c3fc 100644 --- a/frontend/src/api/model/modelUsage.test.ts +++ b/frontend/src/api/model/modelUsage.test.ts @@ -118,6 +118,7 @@ test('maps knowledge-base bindings to the configuration section that owns them', assert.equal(modelUsageKnowledgeBaseSection(['embedding_model']), 'models') assert.equal(modelUsageKnowledgeBaseSection(['summary_model']), 'models') assert.equal(modelUsageKnowledgeBaseSection(['wiki_synthesis_model']), 'models') + assert.equal(modelUsageKnowledgeBaseSection(['auto_tag_model']), 'models') assert.equal(modelUsageKnowledgeBaseSection(['image_processing_model']), 'multimodal') assert.equal(modelUsageKnowledgeBaseSection(['vlm_model']), 'multimodal') assert.equal(modelUsageKnowledgeBaseSection(['asr_model']), 'asr') diff --git a/frontend/src/api/model/modelUsage.ts b/frontend/src/api/model/modelUsage.ts index 94bc2271..0850e8e5 100644 --- a/frontend/src/api/model/modelUsage.ts +++ b/frontend/src/api/model/modelUsage.ts @@ -7,6 +7,7 @@ export const KNOWN_MODEL_USAGE_BINDINGS = [ 'vlm_model', 'asr_model', 'wiki_synthesis_model', + 'auto_tag_model', 'chat_model', 'rerank_model', 'query_understand_model', @@ -133,6 +134,7 @@ const knowledgeBaseUsageSections: Partial>'model_id' = ? OR "+ "vlm_config->>'model_id' = ? OR "+ "asr_config->>'model_id' = ? OR "+ - "wiki_config->>'synthesis_model_id' = ?", - modelID, modelID, modelID, modelID, modelID, modelID, + "wiki_config->>'synthesis_model_id' = ? OR "+ + "auto_tag_config->>'model_id' = ?", + modelID, modelID, modelID, modelID, modelID, modelID, modelID, ) } return db.Where( @@ -70,8 +74,9 @@ func scopeKnowledgeBasesByModelID(db *gorm.DB, modelID string) *gorm.DB { "json_extract(image_processing_config, '$.model_id') = ? OR "+ "json_extract(vlm_config, '$.model_id') = ? OR "+ "json_extract(asr_config, '$.model_id') = ? OR "+ - "json_extract(wiki_config, '$.synthesis_model_id') = ?", - modelID, modelID, modelID, modelID, modelID, modelID, + "json_extract(wiki_config, '$.synthesis_model_id') = ? OR "+ + "json_extract(auto_tag_config, '$.model_id') = ?", + modelID, modelID, modelID, modelID, modelID, modelID, modelID, ) } diff --git a/internal/application/repository/model_usage_test.go b/internal/application/repository/model_usage_test.go index 8698a17a..597af4ff 100644 --- a/internal/application/repository/model_usage_test.go +++ b/internal/application/repository/model_usage_test.go @@ -83,6 +83,7 @@ func TestListModelUsages_KnowledgeBase(t *testing.T) { allBindings.VLMConfig = types.VLMConfig{Enabled: true, ModelID: modelID} allBindings.ASRConfig = types.ASRConfig{Enabled: true, ModelID: modelID} allBindings.WikiConfig = &types.WikiConfig{SynthesisModelID: modelID} + allBindings.AutoTagConfig = &types.AutoTagConfig{Enabled: true, ModelID: modelID} require.NoError(t, db.Create(allBindings).Error) vlmOnly := makeKB(nil) @@ -115,9 +116,25 @@ func TestListModelUsages_KnowledgeBase(t *testing.T) { types.ModelUsageBindingVLMModel, types.ModelUsageBindingASRModel, types.ModelUsageBindingWikiSynthesisModel, + types.ModelUsageBindingAutoTagModel, }, usages[1].Bindings) } +func TestCountByModelID_KnowledgeBaseAutoTag(t *testing.T) { + ctx := context.Background() + db := setupModelUsageTestDB(t) + repo := NewKnowledgeBaseRepository(db) + modelID := "auto-tag-model" + + kb := makeKB(nil) + kb.AutoTagConfig = &types.AutoTagConfig{Enabled: true, ModelID: modelID} + require.NoError(t, db.Create(kb).Error) + + count, err := repo.CountByModelID(ctx, 1, modelID) + require.NoError(t, err) + assert.Equal(t, int64(1), count) +} + func TestListModelUsages_KnowledgeBaseRespectsLimit(t *testing.T) { ctx := context.Background() db := setupModelUsageTestDB(t) diff --git a/internal/types/model.go b/internal/types/model.go index bbacaae1..80f88ffc 100644 --- a/internal/types/model.go +++ b/internal/types/model.go @@ -44,6 +44,7 @@ const ( ModelUsageBindingVLMModel ModelUsageBinding = "vlm_model" ModelUsageBindingASRModel ModelUsageBinding = "asr_model" ModelUsageBindingWikiSynthesisModel ModelUsageBinding = "wiki_synthesis_model" + ModelUsageBindingAutoTagModel ModelUsageBinding = "auto_tag_model" ModelUsageBindingChatModel ModelUsageBinding = "chat_model" ModelUsageBindingRerankModel ModelUsageBinding = "rerank_model" ModelUsageBindingQueryUnderstandModel ModelUsageBinding = "query_understand_model" diff --git a/website-docs/04-api/02-api-model-system.md b/website-docs/04-api/02-api-model-system.md index f8323447..831a6d98 100644 --- a/website-docs/04-api/02-api-model-system.md +++ b/website-docs/04-api/02-api-model-system.md @@ -107,7 +107,7 @@ curl -X PUT $BASE/api/v1/models/m-1 -H "Authorization: Bearer $TOKEN" \ } ``` -知识库绑定值:`embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`;智能体绑定值:`chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆绑定值:`embedding_model`、`extract_model`。详情包含对象 `id`、`name`、合并后的 `bindings`,以及 `knowledge_base_total` / `agent_total`。列表最多各 50 条,删除守卫以总数为准。 +知识库绑定值:`embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`、`auto_tag_model`;智能体绑定值:`chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆绑定值:`embedding_model`、`extract_model`。详情包含对象 `id`、`name`、合并后的 `bindings`,以及 `knowledge_base_total` / `agent_total`。列表最多各 50 条,删除守卫以总数为准。 ```bash curl -X DELETE $BASE/api/v1/models/m-1 -H "Authorization: Bearer $TOKEN"