mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(session): address review regressions
This commit is contained in:
@@ -93,9 +93,7 @@ func normalizeProcessOptions(opts processOptions) processOptions {
|
||||
MessageID: strings.TrimSpace(opts.MessageID),
|
||||
ReplyToMessageID: strings.TrimSpace(opts.ReplyToMessageID),
|
||||
}
|
||||
if inbound.Channel != "" && inbound.ChatID != "" {
|
||||
inbound.ChatType = "direct"
|
||||
}
|
||||
inbound.ChatType = inferChatTypeFromSessionScope(opts.Dispatch.SessionScope)
|
||||
if inbound.Channel != "" || inbound.ChatID != "" || inbound.SenderID != "" ||
|
||||
inbound.MessageID != "" || inbound.ReplyToMessageID != "" {
|
||||
inbound = bus.NormalizeInboundMessage(bus.InboundMessage{Context: inbound}).Context
|
||||
@@ -132,3 +130,18 @@ func normalizeProcessOptions(opts processOptions) processOptions {
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func inferChatTypeFromSessionScope(scope *session.SessionScope) string {
|
||||
if scope == nil || len(scope.Values) == 0 {
|
||||
return ""
|
||||
}
|
||||
chatValue := strings.TrimSpace(scope.Values["chat"])
|
||||
if chatValue == "" {
|
||||
return ""
|
||||
}
|
||||
chatType, _, ok := strings.Cut(chatValue, ":")
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return strings.ToLower(strings.TrimSpace(chatType))
|
||||
}
|
||||
|
||||
@@ -108,3 +108,28 @@ func TestNormalizeProcessOptions_UsesDispatchAsSourceOfTruth(t *testing.T) {
|
||||
t.Fatalf("SessionScope = %#v, want support scope", opts.SessionScope)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProcessOptions_InfersLegacyChatTypeFromSessionScope(t *testing.T) {
|
||||
opts := normalizeProcessOptions(processOptions{
|
||||
Channel: "telegram",
|
||||
ChatID: "-100123",
|
||||
SenderID: "user-1",
|
||||
UserMessage: "hello",
|
||||
SessionScope: &session.SessionScope{
|
||||
Version: session.ScopeVersionV1,
|
||||
AgentID: "main",
|
||||
Channel: "telegram",
|
||||
Dimensions: []string{"chat"},
|
||||
Values: map[string]string{
|
||||
"chat": "group:-100123",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if opts.Dispatch.InboundContext == nil {
|
||||
t.Fatal("Dispatch.InboundContext is nil")
|
||||
}
|
||||
if opts.Dispatch.InboundContext.ChatType != "group" {
|
||||
t.Fatalf("Dispatch.InboundContext.ChatType = %q, want group", opts.Dispatch.InboundContext.ChatType)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -292,16 +292,18 @@ func (al *AgentLoop) continueWithSteeringMessages(
|
||||
ctx context.Context,
|
||||
agent *AgentInstance,
|
||||
sessionKey, channel, chatID string,
|
||||
scope *session.SessionScope,
|
||||
steeringMsgs []providers.Message,
|
||||
) (string, error) {
|
||||
dispatch := DispatchRequest{
|
||||
SessionKey: sessionKey,
|
||||
SessionKey: sessionKey,
|
||||
SessionScope: session.CloneScope(scope),
|
||||
}
|
||||
if channel != "" || chatID != "" {
|
||||
dispatch.InboundContext = &bus.InboundContext{
|
||||
Channel: channel,
|
||||
ChatID: chatID,
|
||||
ChatType: "direct",
|
||||
ChatType: inferChatTypeFromSessionScope(scope),
|
||||
}
|
||||
}
|
||||
return al.runAgentLoop(ctx, agent, processOptions{
|
||||
@@ -372,7 +374,12 @@ func (al *AgentLoop) Continue(ctx context.Context, sessionKey, channel, chatID s
|
||||
}
|
||||
}
|
||||
|
||||
return al.continueWithSteeringMessages(ctx, agent, sessionKey, channel, chatID, steeringMsgs)
|
||||
var scope *session.SessionScope
|
||||
if metaStore, ok := agent.Sessions.(session.MetadataAwareSessionStore); ok {
|
||||
scope = metaStore.GetSessionScope(sessionKey)
|
||||
}
|
||||
|
||||
return al.continueWithSteeringMessages(ctx, agent, sessionKey, channel, chatID, scope, steeringMsgs)
|
||||
}
|
||||
|
||||
func (al *AgentLoop) InterruptGraceful(hint string) error {
|
||||
|
||||
Reference in New Issue
Block a user