Skip to content

Commit 8f17b40

Browse files
author
Hex
committed
fix: TS build errors, dedup guards, model switcher rebuild
- Guard nullable getSessionFilePath return in chat.ts - Cast backend for listGatewaySessions (OpenClaw-specific, not on interface) - Replace findLastIndex with manual loop in streaming tests (es2022 compat) - Remove unused vitest imports in streaming.test.ts - Add missing mock properties in ws.test.ts - Rebuild client with all fixes applied
1 parent ec58eb0 commit 8f17b40

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

packages/server/src/chat/chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ export function createChatModule(
290290
if (pollTimers.has(threadKey)) return // already polling
291291

292292
const filePath = getSessionFilePath(sessionKey)
293+
if (!filePath) return
293294

294295
// Start from current file size (only read NEW entries)
295296
try {

packages/server/src/chat/routes.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,20 @@ export function createChatRoutes(chatModule: ChatModule, backend: AgentBackend,
191191
let activeStatus = live.status
192192
if (!activeStatus || activeStatus === 'idle') {
193193
// Check gateway for real agent status — fire-and-forget, don't block SSE
194-
backend
195-
.listGatewaySessions()
196-
.then((sessions) => {
197-
const sessionKey = chatModule.resolveSessionKey(threadKey)
198-
const match = sessions.find((s: any) => s.key === sessionKey)
199-
if (match && match.agentStatus && match.agentStatus !== 'idle') {
200-
send('status', { status: match.agentStatus, threadKey })
201-
chatModule.ensurePolling(threadKey, match.agentStatus)
202-
}
203-
})
204-
.catch(() => {})
194+
const backendAny = backend as any
195+
if (typeof backendAny.listGatewaySessions === 'function') {
196+
backendAny
197+
.listGatewaySessions()
198+
.then((sessions: any[]) => {
199+
const sessionKey = chatModule.resolveSessionKey(threadKey)
200+
const match = sessions.find((s: any) => s.key === sessionKey)
201+
if (match && match.agentStatus && match.agentStatus !== 'idle') {
202+
send('status', { status: match.agentStatus, threadKey })
203+
chatModule.ensurePolling(threadKey, match.agentStatus)
204+
}
205+
})
206+
.catch(() => {})
207+
}
205208
}
206209
if (activeStatus && activeStatus !== 'idle') {
207210
send('status', { status: activeStatus, threadKey })

packages/server/src/chat/streaming.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests for chat streaming, turn completion, and work item handling
22
// Run: cd packages/server && npx vitest run src/chat/streaming.test.ts
33

4-
import { describe, it, expect, vi, beforeEach } from 'vitest'
4+
import { describe, it, expect } from 'vitest'
55
import type { WorkItem, ParsedTurn } from '@sovereign/core'
66

77
// ── Test: thinking accumulation ────────────────────────────────────────
@@ -129,7 +129,13 @@ describe('thinking work item replacement', () => {
129129

130130
// Replace logic
131131
const items = [...workItems]
132-
const lastThinkIdx = items.findLastIndex((w) => w.type === 'thinking')
132+
let lastThinkIdx = -1
133+
for (let i = items.length - 1; i >= 0; i--) {
134+
if (items[i].type === 'thinking') {
135+
lastThinkIdx = i
136+
break
137+
}
138+
}
133139
if (lastThinkIdx >= 0) {
134140
items[lastThinkIdx] = newThinking
135141
} else {
@@ -146,7 +152,13 @@ describe('thinking work item replacement', () => {
146152
const newThinking: WorkItem = { type: 'thinking', output: 'New thought', timestamp: 2 }
147153

148154
const items = [...workItems]
149-
const lastThinkIdx = items.findLastIndex((w) => w.type === 'thinking')
155+
let lastThinkIdx = -1
156+
for (let i = items.length - 1; i >= 0; i--) {
157+
if (items[i].type === 'thinking') {
158+
lastThinkIdx = i
159+
break
160+
}
161+
}
150162
if (lastThinkIdx >= 0) {
151163
items[lastThinkIdx] = newThinking
152164
} else {

packages/server/src/chat/ws.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ function createMockChatModule(): ChatModule {
3838
loadMapping: vi.fn(),
3939
chatEvents: new EventEmitter(),
4040
getLiveState: vi.fn(() => ({})),
41-
resolveSessionKey: vi.fn((tk: string) => `session-${tk}`)
41+
resolveSessionKey: vi.fn((tk: string) => `session-${tk}`),
42+
ensurePolling: vi.fn(),
43+
trackSSEClient: vi.fn(),
44+
untrackSSEClient: vi.fn()
4245
}
4346
}
4447

0 commit comments

Comments
 (0)