mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-15 03:32:43 +08:00
fix(parser): 修复 Gemini init 事件 session_id 未提取的问题 (#111)
Gemini CLI 的 session_id 出现在 init 事件中,但 parser 的 isGemini 判定条件只检查 role/delta/status 字段,导致 init 事件被当作 "Unknown event" 忽略,session_id 无法提取。 修复方案:在 isGemini 条件中增加对 init 事件的识别。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2096,6 +2096,16 @@ func TestBackendParseJSONStream_GeminiEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackendParseJSONStream_GeminiInitEventSessionID(t *testing.T) {
|
||||||
|
input := `{"type":"init","session_id":"gemini-abc123"}`
|
||||||
|
|
||||||
|
_, threadID := parseJSONStream(strings.NewReader(input))
|
||||||
|
|
||||||
|
if threadID != "gemini-abc123" {
|
||||||
|
t.Fatalf("threadID=%q, want %q", threadID, "gemini-abc123")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackendParseJSONStream_GeminiEvents_DeltaFalseStillDetected(t *testing.T) {
|
func TestBackendParseJSONStream_GeminiEvents_DeltaFalseStillDetected(t *testing.T) {
|
||||||
input := `{"type":"init","session_id":"xyz789"}
|
input := `{"type":"init","session_id":"xyz789"}
|
||||||
{"type":"message","content":"Hi","delta":false,"session_id":"xyz789"}
|
{"type":"message","content":"Hi","delta":false,"session_id":"xyz789"}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ func parseJSONStreamInternal(r io.Reader, warnFn func(string), infoFn func(strin
|
|||||||
if !isClaude && event.Type == "result" && event.SessionID != "" && event.Status == "" {
|
if !isClaude && event.Type == "result" && event.SessionID != "" && event.Status == "" {
|
||||||
isClaude = true
|
isClaude = true
|
||||||
}
|
}
|
||||||
isGemini := event.Role != "" || event.Delta != nil || event.Status != ""
|
isGemini := (event.Type == "init" && event.SessionID != "") || event.Role != "" || event.Delta != nil || event.Status != ""
|
||||||
|
|
||||||
// Handle Codex events
|
// Handle Codex events
|
||||||
if isCodex {
|
if isCodex {
|
||||||
|
|||||||
Reference in New Issue
Block a user