fix(channels): address PR review feedback
- Change chatID separator from ':' to '|' for robustness - Use per-message ctx instead of channel-level c.ctx in HandleMessage - Distinguish error types: ErrSessionNotFound -> ErrSendFailed (permanent) - Update xiaoyi-agent-sdk dependency
This commit is contained in:
parent
693db82347
commit
b3ff44fae9
3 changed files with 10 additions and 6 deletions
2
go.mod
2
go.mod
|
|
@ -19,7 +19,7 @@ require (
|
||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
github.com/tencent-connect/botgo v0.2.1
|
github.com/tencent-connect/botgo v0.2.1
|
||||||
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260227130030-0515fa30d618
|
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260228122638-808341089b7f
|
||||||
go.mau.fi/whatsmeow v0.0.0-20260219150138-7ae702b1eed4
|
go.mau.fi/whatsmeow v0.0.0-20260219150138-7ae702b1eed4
|
||||||
golang.org/x/oauth2 v0.35.0
|
golang.org/x/oauth2 v0.35.0
|
||||||
golang.org/x/time v0.14.0
|
golang.org/x/time v0.14.0
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -202,8 +202,8 @@ github.com/vektah/gqlparser/v2 v2.5.27 h1:RHPD3JOplpk5mP5JGX8RKZkt2/Vwj/PZv0HxTd
|
||||||
github.com/vektah/gqlparser/v2 v2.5.27/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
|
github.com/vektah/gqlparser/v2 v2.5.27/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
|
||||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||||
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260227130030-0515fa30d618 h1:2lZ4jVfUzdWU2ubDjdrO5eqqUeDnPZBeUrgkIFjiGKg=
|
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260228122638-808341089b7f h1:H2SONTyMFS8Iva/9FJmU+4unMPruf7Estc5HmTf7kNQ=
|
||||||
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260227130030-0515fa30d618/go.mod h1:IXaPNIZ8Ta3iIhw1DmlDS3T0UumdrNtv0rIIBWvE/MU=
|
github.com/ystyle/xiaoyi-agent-sdk v0.0.0-20260228122638-808341089b7f/go.mod h1:IXaPNIZ8Ta3iIhw1DmlDS3T0UumdrNtv0rIIBWvE/MU=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package xiaoyi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -116,7 +117,7 @@ func (c *XiaoYiChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
|
||||||
return channels.ErrNotRunning
|
return channels.ErrNotRunning
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(msg.ChatID, ":", 2)
|
parts := strings.SplitN(msg.ChatID, "|", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
return fmt.Errorf("invalid chat_id format: %w", channels.ErrSendFailed)
|
return fmt.Errorf("invalid chat_id format: %w", channels.ErrSendFailed)
|
||||||
}
|
}
|
||||||
|
|
@ -131,6 +132,9 @@ func (c *XiaoYiChannel) Send(ctx context.Context, msg bus.OutboundMessage) error
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := c.client.ReplyStream(ctx, taskID, sessionID, msg.Content, false, false); err != nil {
|
if err := c.client.ReplyStream(ctx, taskID, sessionID, msg.Content, false, false); err != nil {
|
||||||
|
if errors.Is(err, types.ErrSessionNotFound) {
|
||||||
|
return fmt.Errorf("xiaoyi session not found: %w", channels.ErrSendFailed)
|
||||||
|
}
|
||||||
return fmt.Errorf("xiaoyi reply: %w", channels.ErrTemporary)
|
return fmt.Errorf("xiaoyi reply: %w", channels.ErrTemporary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +169,7 @@ func (c *XiaoYiChannel) handleMessage(ctx context.Context, msg types.Message) er
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
chatID := fmt.Sprintf("%s:%s", sessionID, taskID)
|
chatID := fmt.Sprintf("%s|%s", sessionID, taskID)
|
||||||
peer := bus.Peer{Kind: "direct", ID: sessionID}
|
peer := bus.Peer{Kind: "direct", ID: sessionID}
|
||||||
|
|
||||||
if err := c.client.SendStatus(ctx, taskID, sessionID, "Processing...", "working"); err != nil {
|
if err := c.client.SendStatus(ctx, taskID, sessionID, "Processing...", "working"); err != nil {
|
||||||
|
|
@ -176,7 +180,7 @@ func (c *XiaoYiChannel) handleMessage(ctx context.Context, msg types.Message) er
|
||||||
"task_id": taskID,
|
"task_id": taskID,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.HandleMessage(c.ctx,
|
c.HandleMessage(ctx,
|
||||||
peer,
|
peer,
|
||||||
"",
|
"",
|
||||||
sessionID,
|
sessionID,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue