fix: update grep_chunks tool to support multiple patterns

- Renamed the input parameter from "pattern" to "patterns" to reflect that multiple text patterns can be provided.
- Updated the schema definition and input structure accordingly to ensure consistency in handling multiple patterns.
- Enhanced error logging to specify "patterns" when no valid input is provided, improving clarity for debugging.

These changes improve the functionality of the grep_chunks tool by allowing users to search for multiple patterns simultaneously.
This commit is contained in:
wizardchen
2026-03-13 11:57:40 +08:00
parent 890dfb4bb3
commit f41b0e77fd
2 changed files with 23 additions and 13 deletions
+18 -8
View File
@@ -3,6 +3,7 @@ package middleware
import (
"context"
"errors"
"fmt"
"log"
"net/http"
"slices"
@@ -190,16 +191,25 @@ func Auth(
types.TenantInfoContextKey, t,
)
// 通过 TenantID 关联查询用户
// 通过 TenantID 关联查询用户;找不到时构造系统虚拟用户,
// 确保所有依赖 UserContextKey 的下游 handler 正常工作。
user, err := userService.GetUserByTenantID(c.Request.Context(), tenantID)
if err == nil && user != nil {
c.Set(types.UserContextKey.String(), user)
c.Set(types.UserIDContextKey.String(), user.ID)
ctx = context.WithValue(
context.WithValue(ctx, types.UserContextKey, user),
types.UserIDContextKey, user.ID,
)
if err != nil || user == nil {
user = &types.User{
ID: fmt.Sprintf("system-%d", tenantID),
Username: fmt.Sprintf("system-%d", tenantID),
Email: fmt.Sprintf("system-%d@api-key.local", tenantID),
TenantID: tenantID,
IsActive: true,
}
log.Printf("No user found for tenant %d via API key, using synthetic system user %s", tenantID, user.ID)
}
c.Set(types.UserContextKey.String(), user)
c.Set(types.UserIDContextKey.String(), user.ID)
ctx = context.WithValue(
context.WithValue(ctx, types.UserContextKey, user),
types.UserIDContextKey, user.ID,
)
c.Request = c.Request.WithContext(ctx)
c.Next()