mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 22:15:47 +00:00
feat(http): support persistent sessions via X-GoClaw-User-Id header (#713)
When X-GoClaw-User-Id header is provided, build a stable session key
using BuildSessionKey() — same canonical format as Telegram, Discord,
Slack channels. This allows HTTP API clients to maintain conversation
history across multiple requests.
Without the header, behavior is unchanged (random session per request).
Session key format:
With userId: agent:{id}:http:direct:{userId} (persistent)
Without: agent:{id}:http-{random} (stateless)
Co-authored-by: Claude Code <claude@anthropic.com>
This commit is contained in:
1 parent
3ed1d5f9d8
commit
94d2799788
1 file changed
+6
-4
@@ -156,12 +156,14 @@ func (h *ChatCompletionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
runID := uuid.NewString()
|
||||
// Include userID in session key for multi-tenant isolation
|
||||
sessionSuffix := "http-" + runID[:8]
|
||||
// Build stable session key per user — same user+agent always reuses the same session
|
||||
var sessionKey string
|
||||
if userID != "" {
|
||||
sessionSuffix = "http-" + userID + "-" + runID[:8]
|
||||
sessionKey = sessions.BuildSessionKey(agentID, "http", sessions.PeerDirect, userID)
|
||||
} else {
|
||||
// No user ID — fallback to random session (stateless)
|
||||
sessionKey = sessions.SessionKey(agentID, "http-"+runID[:8])
|
||||
}
|
||||
sessionKey := sessions.SessionKey(agentID, sessionSuffix)
|
||||
|
||||
slog.Info("chat completions request", "agent", agentID, "stream", req.Stream, "user", userID)
|
||||
|
||||
|
||||
Reference in new issue
Block a user