From f0c0219c4cd6cc86b12b8635c185dc0a4327a225 Mon Sep 17 00:00:00 2001 From: Cytown Date: Sun, 29 Mar 2026 16:58:48 +0800 Subject: [PATCH] fix for review --- pkg/channels/pico/protocol.go | 2 ++ pkg/gateway/gateway.go | 8 +++----- web/backend/api/gateway.go | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/channels/pico/protocol.go b/pkg/channels/pico/protocol.go index 0a630e193..192c96164 100644 --- a/pkg/channels/pico/protocol.go +++ b/pkg/channels/pico/protocol.go @@ -17,6 +17,8 @@ const ( TypeTypingStop = "typing.stop" TypeError = "error" TypePong = "pong" + + PicoTokenPrefix = "pico-" ) // PicoMessage is the wire format for all Pico Protocol messages. diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index a63530806..1a9ab4461 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -22,7 +22,7 @@ import ( _ "github.com/sipeed/picoclaw/pkg/channels/line" _ "github.com/sipeed/picoclaw/pkg/channels/maixcam" _ "github.com/sipeed/picoclaw/pkg/channels/onebot" - _ "github.com/sipeed/picoclaw/pkg/channels/pico" + "github.com/sipeed/picoclaw/pkg/channels/pico" _ "github.com/sipeed/picoclaw/pkg/channels/qq" _ "github.com/sipeed/picoclaw/pkg/channels/slack" _ "github.com/sipeed/picoclaw/pkg/channels/telegram" @@ -662,8 +662,6 @@ func setupCronTool( return cronService, nil } -const picoTokenPrefix = "pico-" - // overridePicoToken replaces the pico channel token with the one from the PID file. // The PID file is the single source of truth for the pico auth token; // it is generated once at gateway startup and remains unchanged across reloads. @@ -672,10 +670,10 @@ func overridePicoToken(cfg *config.Config, token string) { return } picoToken := cfg.Channels.Pico.Token.String() - if picoToken == "" || strings.HasPrefix(picoToken, picoTokenPrefix) { + if picoToken == "" || strings.HasPrefix(picoToken, pico.PicoTokenPrefix) { return } - cfg.Channels.Pico.SetToken(picoTokenPrefix + token + picoToken) + cfg.Channels.Pico.SetToken(pico.PicoTokenPrefix + token + picoToken) } func createHeartbeatHandler(agentLoop *agent.AgentLoop) func(prompt, channel, chatID string) *tools.ToolResult { diff --git a/web/backend/api/gateway.go b/web/backend/api/gateway.go index 98fb77a04..ce3a9ca1e 100644 --- a/web/backend/api/gateway.go +++ b/web/backend/api/gateway.go @@ -17,6 +17,7 @@ import ( "syscall" "time" + "github.com/sipeed/picoclaw/pkg/channels/pico" "github.com/sipeed/picoclaw/pkg/config" "github.com/sipeed/picoclaw/pkg/health" "github.com/sipeed/picoclaw/pkg/logger" @@ -59,9 +60,8 @@ func refreshPicoTokensLocked(configPath string) { } const ( - protocolKey = "Sec-Websocket-Protocol" - picoTokenPrefix = "pico-" - tokenPrefix = "token." + protocolKey = "Sec-Websocket-Protocol" + tokenPrefix = "token." ) // picoComposedToken returns "pico-"+pidToken+picoToken for gateway auth. @@ -75,7 +75,7 @@ func picoComposedToken(token string) string { if tokenPrefix+gateway.picoToken != token { return "" } - return picoTokenPrefix + gateway.pidData.Token + gateway.picoToken + return pico.PicoTokenPrefix + gateway.pidData.Token + gateway.picoToken } var (