fix(agent): enforce tag scopes across knowledge tools
This commit is contained in:
@@ -144,6 +144,17 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
allowed, scopeErr := searchTargetsAllowKnowledgeID(ctx, t.searchTargets, chunk.KnowledgeID, chunk.KnowledgeBaseID, t.knowledgeService)
|
||||
if scopeErr != nil || !allowed {
|
||||
mu.Lock()
|
||||
if scopeErr != nil {
|
||||
results["faq:"+id] = &docInfo{err: fmt.Errorf("failed to validate FAQ scope: %v", scopeErr)}
|
||||
} else {
|
||||
results["faq:"+id] = &docInfo{err: fmt.Errorf("FAQ entry %s is not within the current @mention scope", id)}
|
||||
}
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
var meta *types.FAQChunkMetadata
|
||||
if chunk.ChunkType == types.ChunkTypeFAQ {
|
||||
meta, _ = chunk.FAQMetadata()
|
||||
@@ -179,6 +190,17 @@ func (t *GetDocumentInfoTool) Execute(ctx context.Context, args json.RawMessage)
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
allowed, scopeErr := searchTargetsAllowKnowledgeID(ctx, t.searchTargets, knowledge.ID, knowledge.KnowledgeBaseID, t.knowledgeService)
|
||||
if scopeErr != nil || !allowed {
|
||||
mu.Lock()
|
||||
if scopeErr != nil {
|
||||
results[id] = &docInfo{err: fmt.Errorf("failed to validate document scope: %v", scopeErr)}
|
||||
} else {
|
||||
results[id] = &docInfo{err: fmt.Errorf("document %s is not within the current @mention scope", knowledge.ID)}
|
||||
}
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
// Use knowledge's actual tenant_id for chunk query (supports cross-tenant shared KB).
|
||||
// Keep chunk-type filter aligned with list_knowledge_chunks so the
|
||||
|
||||
Reference in New Issue
Block a user