mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
29 lines
646 B
Go
29 lines
646 B
Go
package memory
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
)
|
|
|
|
type contextKey string
|
|
|
|
const memoryBotIDContextKey contextKey = "memory_bot_id"
|
|
|
|
// WithBotID attaches bot ID to context so model selection can honor bot settings.
|
|
func WithBotID(ctx context.Context, botID string) context.Context {
|
|
botID = strings.TrimSpace(botID)
|
|
if botID == "" {
|
|
return ctx
|
|
}
|
|
return context.WithValue(ctx, memoryBotIDContextKey, botID)
|
|
}
|
|
|
|
// BotIDFromContext returns bot ID carried by WithBotID.
|
|
func BotIDFromContext(ctx context.Context) string {
|
|
if ctx == nil {
|
|
return ""
|
|
}
|
|
botID, _ := ctx.Value(memoryBotIDContextKey).(string)
|
|
return strings.TrimSpace(botID)
|
|
}
|