refactor: Update tenant ID handling across the application

This commit is contained in:
wizardchen
2025-11-25 16:30:54 +08:00
parent 9f6f5f5773
commit 64c44c9e27
78 changed files with 437 additions and 601 deletions
+2 -2
View File
@@ -17,11 +17,11 @@ import (
type DatabaseQueryTool struct {
BaseTool
db *gorm.DB
tenantID uint
tenantID uint64
}
// NewDatabaseQueryTool creates a new database query tool
func NewDatabaseQueryTool(db *gorm.DB, tenantID uint) *DatabaseQueryTool {
func NewDatabaseQueryTool(db *gorm.DB, tenantID uint64) *DatabaseQueryTool {
description := `Execute SQL queries to retrieve information from the database.
## Security Features
+2 -2
View File
@@ -12,14 +12,14 @@ import (
// GetDocumentInfoTool retrieves detailed information about a document/knowledge
type GetDocumentInfoTool struct {
BaseTool
tenantID uint
tenantID uint64
knowledgeService interfaces.KnowledgeService
chunkService interfaces.ChunkService
}
// NewGetDocumentInfoTool creates a new get document info tool
func NewGetDocumentInfoTool(
tenantID uint,
tenantID uint64,
knowledgeService interfaces.KnowledgeService,
chunkService interfaces.ChunkService,
) *GetDocumentInfoTool {
+2 -2
View File
@@ -17,12 +17,12 @@ import (
type GrepChunksTool struct {
BaseTool
db *gorm.DB
tenantID uint
tenantID uint64
knowledgeBaseIDs []string
}
// NewGrepChunksTool creates a new grep chunks tool
func NewGrepChunksTool(db *gorm.DB, tenantID uint, knowledgeBaseIDs []string) *GrepChunksTool {
func NewGrepChunksTool(db *gorm.DB, tenantID uint64, knowledgeBaseIDs []string) *GrepChunksTool {
description := `Unix-style text pattern matching tool for knowledge base chunks.
Searches for text patterns in chunk content, similar to the Unix grep command.
+2 -2
View File
@@ -32,7 +32,7 @@ type KnowledgeSearchTool struct {
BaseTool
knowledgeBaseService interfaces.KnowledgeBaseService
chunkService interfaces.ChunkService
tenantID uint
tenantID uint64
allowedKBs []string
rerankModel rerank.Reranker
chatModel chat.Chat // Optional chat model for LLM-based reranking
@@ -43,7 +43,7 @@ type KnowledgeSearchTool struct {
func NewKnowledgeSearchTool(
knowledgeBaseService interfaces.KnowledgeBaseService,
chunkService interfaces.ChunkService,
tenantID uint,
tenantID uint64,
allowedKBs []string,
rerankModel rerank.Reranker,
chatModel chat.Chat,
@@ -12,14 +12,14 @@ import (
// ListKnowledgeChunksTool retrieves chunk snapshots for a specific knowledge document.
type ListKnowledgeChunksTool struct {
BaseTool
tenantID uint
tenantID uint64
chunkService interfaces.ChunkService
knowledgeService interfaces.KnowledgeService
}
// NewListKnowledgeChunksTool creates a new tool instance.
func NewListKnowledgeChunksTool(
tenantID uint,
tenantID uint64,
knowledgeService interfaces.KnowledgeService,
chunkService interfaces.ChunkService,
) *ListKnowledgeChunksTool {
+2 -2
View File
@@ -124,8 +124,8 @@ func (t *WebSearchTool) Execute(ctx context.Context, args map[string]interface{}
logger.Infof(ctx, "[Tool][WebSearch] Searching with query: %s, max_results: %d", query, t.maxResults)
// Get tenant ID from context
tenantID := uint(0)
if tid, ok := ctx.Value(types.TenantIDContextKey).(uint); ok {
tenantID := uint64(0)
if tid, ok := ctx.Value(types.TenantIDContextKey).(uint64); ok {
tenantID = tid
}