chore: fix go fmt formatting issues after rebase

Apply go fmt to files that had formatting inconsistencies
(alignment, indentation) after rebasing onto refactor/channel-system.
This commit is contained in:
Hoshina 2026-02-27 17:35:50 +08:00
parent 42ee9ab1e3
commit d429dcdd76
5 changed files with 33 additions and 18 deletions

View file

@ -211,12 +211,16 @@ func (al *AgentLoop) Run(ctx context.Context) error {
}) })
logger.InfoCF("agent", "Published outbound response", logger.InfoCF("agent", "Published outbound response",
map[string]any{ map[string]any{
"channel": msg.Channel, "channel": msg.Channel,
"chat_id": msg.ChatID, "chat_id": msg.ChatID,
"content_len": len(response), "content_len": len(response),
}) })
} else { } else {
logger.DebugCF("agent", "Skipped outbound (message tool already sent)", map[string]any{"channel": msg.Channel}) logger.DebugCF(
"agent",
"Skipped outbound (message tool already sent)",
map[string]any{"channel": msg.Channel},
)
} }
} }
}() }()
@ -395,7 +399,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
"agent_id": agent.ID, "agent_id": agent.ID,
"session_key": sessionKey, "session_key": sessionKey,
"matched_by": route.MatchedBy, "matched_by": route.MatchedBy,
}) })
return al.runAgentLoop(ctx, agent, processOptions{ return al.runAgentLoop(ctx, agent, processOptions{
SessionKey: sessionKey, SessionKey: sessionKey,

View file

@ -18,15 +18,14 @@ import (
"time" "time"
"github.com/mdp/qrterminal/v3" "github.com/mdp/qrterminal/v3"
_ "modernc.org/sqlite"
"go.mau.fi/whatsmeow" "go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/store/sqlstore" "go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events" "go.mau.fi/whatsmeow/types/events"
waLog "go.mau.fi/whatsmeow/util/log" waLog "go.mau.fi/whatsmeow/util/log"
"go.mau.fi/whatsmeow/proto/waE2E"
"go.mau.fi/whatsmeow/types"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
_ "modernc.org/sqlite"
"github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/channels" "github.com/sipeed/picoclaw/pkg/channels"
@ -61,7 +60,11 @@ type WhatsAppNativeChannel struct {
// NewWhatsAppNativeChannel creates a WhatsApp channel that uses whatsmeow for connection. // NewWhatsAppNativeChannel creates a WhatsApp channel that uses whatsmeow for connection.
// storePath is the directory for the SQLite session store (e.g. workspace/whatsapp). // storePath is the directory for the SQLite session store (e.g. workspace/whatsapp).
func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (channels.Channel, error) { func NewWhatsAppNativeChannel(
cfg config.WhatsAppConfig,
bus *bus.MessageBus,
storePath string,
) (channels.Channel, error) {
base := channels.NewBaseChannel("whatsapp_native", cfg, bus, cfg.AllowFrom, channels.WithMaxMessageLength(65536)) base := channels.NewBaseChannel("whatsapp_native", cfg, bus, cfg.AllowFrom, channels.WithMaxMessageLength(65536))
if storePath == "" { if storePath == "" {
storePath = "whatsapp" storePath = "whatsapp"
@ -77,7 +80,7 @@ func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, st
func (c *WhatsAppNativeChannel) Start(ctx context.Context) error { func (c *WhatsAppNativeChannel) Start(ctx context.Context) error {
logger.InfoCF("whatsapp", "Starting WhatsApp native channel (whatsmeow)", map[string]any{"store": c.storePath}) logger.InfoCF("whatsapp", "Starting WhatsApp native channel (whatsmeow)", map[string]any{"store": c.storePath})
if err := os.MkdirAll(c.storePath, 0700); err != nil { if err := os.MkdirAll(c.storePath, 0o700); err != nil {
return fmt.Errorf("create session store dir: %w", err) return fmt.Errorf("create session store dir: %w", err)
} }
@ -173,7 +176,7 @@ func (c *WhatsAppNativeChannel) Stop(ctx context.Context) error {
return nil return nil
} }
func (c *WhatsAppNativeChannel) eventHandler(evt interface{}) { func (c *WhatsAppNativeChannel) eventHandler(evt any) {
switch evt.(type) { switch evt.(type) {
case *events.Message: case *events.Message:
c.handleIncoming(evt.(*events.Message)) c.handleIncoming(evt.(*events.Message))
@ -284,7 +287,11 @@ func (c *WhatsAppNativeChannel) handleIncoming(evt *events.Message) {
return return
} }
logger.DebugCF("whatsapp", "WhatsApp message received", map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)}) logger.DebugCF(
"whatsapp",
"WhatsApp message received",
map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)},
)
c.HandleMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender) c.HandleMessage(c.runCtx, peer, messageID, senderID, chatID, content, mediaPaths, metadata, sender)
} }

View file

@ -12,6 +12,10 @@ import (
// NewWhatsAppNativeChannel returns an error when the binary was not built with -tags whatsapp_native. // NewWhatsAppNativeChannel returns an error when the binary was not built with -tags whatsapp_native.
// Build with: go build -tags whatsapp_native ./cmd/... // Build with: go build -tags whatsapp_native ./cmd/...
func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, storePath string) (channels.Channel, error) { func NewWhatsAppNativeChannel(
cfg config.WhatsAppConfig,
bus *bus.MessageBus,
storePath string,
) (channels.Channel, error) {
return nil, fmt.Errorf("whatsapp native not compiled in; build with -tags whatsapp_native") return nil, fmt.Errorf("whatsapp native not compiled in; build with -tags whatsapp_native")
} }

View file

@ -224,9 +224,9 @@ type PlaceholderConfig struct {
type WhatsAppConfig struct { type WhatsAppConfig struct {
Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WHATSAPP_ENABLED"` Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_WHATSAPP_ENABLED"`
BridgeURL string `json:"bridge_url" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"` BridgeURL string `json:"bridge_url" env:"PICOCLAW_CHANNELS_WHATSAPP_BRIDGE_URL"`
UseNative bool `json:"use_native" env:"PICOCLAW_CHANNELS_WHATSAPP_USE_NATIVE"` UseNative bool `json:"use_native" env:"PICOCLAW_CHANNELS_WHATSAPP_USE_NATIVE"`
SessionStorePath string `json:"session_store_path" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"` SessionStorePath string `json:"session_store_path" env:"PICOCLAW_CHANNELS_WHATSAPP_SESSION_STORE_PATH"`
AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WHATSAPP_ALLOW_FROM"` AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_WHATSAPP_ALLOW_FROM"`
} }

View file

@ -5,8 +5,8 @@ import (
"unicode" "unicode"
) )
// SanitizeMessage removes Unicode control characters, format characters (RTL overrides, // SanitizeMessage removes Unicode control characters, format characters (RTL overrides,
// zero-width characters), and other non-graphic characters that could confuse an LLM // zero-width characters), and other non-graphic characters that could confuse an LLM
// or cause display issues in the agent UI. // or cause display issues in the agent UI.
func SanitizeMessageContent(input string) string { func SanitizeMessageContent(input string) string {
var sb strings.Builder var sb strings.Builder
@ -16,7 +16,7 @@ func SanitizeMessageContent(input string) string {
for _, r := range input { for _, r := range input {
// unicode.IsGraphic returns true if the rune is a Unicode graphic character. // unicode.IsGraphic returns true if the rune is a Unicode graphic character.
// This includes letters, marks, numbers, punctuation, and symbols. // This includes letters, marks, numbers, punctuation, and symbols.
// It excludes control characters (Cc), format characters (Cf), // It excludes control characters (Cc), format characters (Cf),
// surrogates (Cs), and private use (Co). // surrogates (Cs), and private use (Co).
if unicode.IsGraphic(r) || r == '\n' || r == '\r' || r == '\t' { if unicode.IsGraphic(r) || r == '\n' || r == '\r' || r == '\t' {
sb.WriteRune(r) sb.WriteRune(r)