mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
Fixed: #1109
feat(translator): enhance session ID derivation with user_id parsing in Claude
This commit is contained in:
@@ -22,6 +22,14 @@ import (
|
|||||||
// deriveSessionID generates a stable session ID from the request.
|
// deriveSessionID generates a stable session ID from the request.
|
||||||
// Uses the hash of the first user message to identify the conversation.
|
// Uses the hash of the first user message to identify the conversation.
|
||||||
func deriveSessionID(rawJSON []byte) string {
|
func deriveSessionID(rawJSON []byte) string {
|
||||||
|
userIDResult := gjson.GetBytes(rawJSON, "metadata.user_id")
|
||||||
|
if userIDResult.Exists() {
|
||||||
|
userID := userIDResult.String()
|
||||||
|
idx := strings.Index(userID, "session_")
|
||||||
|
if idx != -1 {
|
||||||
|
return userID[idx+8:]
|
||||||
|
}
|
||||||
|
}
|
||||||
messages := gjson.GetBytes(rawJSON, "messages")
|
messages := gjson.GetBytes(rawJSON, "messages")
|
||||||
if !messages.IsArray() {
|
if !messages.IsArray() {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user