The condition (event.kind === 'notification' || event.method === 'turn/completed') used || where && was needed, but even with &&, notification events don't carry event.message (only session/error events do), so AppendAssistantMessage was never dispatched. Fix by intercepting item/completed notifications for agentMessage items and extracting the text from event.payload.item.text, consistent with how the web client handles these events in session-logic.ts.
Unified · Split
| @@ -151,25 +151,32 @@ export function createServer(options: ServerOptions) { · 150 unmodified lines | ||
| 151 | 151 | data: event, |
| 152 | 152 | }; |
| 153 | 153 | broadcastPush(push); |
| 154 | − if ( | |
| 155 | − event.threadId && | |
| 156 | − typeof event.message === "string" && | |
| 157 | − event.message.trim().length > 0 && | |
| 158 | − (event.kind === "notification" || event.method === "turn/completed") | |
| 159 | − ) { | |
| 160 | − void coreEngine.dispatch({ | |
| 161 | − command: { | |
| 162 | − kind: "AppendAssistantMessage", | |
| 163 | − commandId: crypto.randomUUID(), | |
| 164 | − issuedAt: new Date().toISOString(), | |
| 165 | − payload: { | |
| 166 | − threadId: event.threadId, | |
| 167 | − messageId: event.itemId ?? crypto.randomUUID(), | |
| 168 | − text: event.message, | |
| 169 | − createdAt: event.createdAt, | |
| 170 | − }, | |
| 171 | − }, | |
| 172 | − }); | |
| 154 | + if (event.threadId && event.kind === "notification" && event.method === "item/completed") { | |
| 155 | + const pl = event.payload as Record<string, unknown> | undefined; | |
| 156 | + const item = pl && typeof pl === "object" ? (pl as Record<string, unknown>).item : undefined; | |
| 157 | + if (item && typeof item === "object") { | |
| 158 | + const rec = item as Record<string, unknown>; | |
| 159 | + if (rec.type === "agentMessage" && typeof rec.text === "string") { | |
| 160 | + const text = rec.text as string; | |
| 161 | + if (text.trim().length > 0) { | |
| 162 | + const messageId = | |
| 163 | + typeof rec.id === "string" ? rec.id : (event.itemId ?? crypto.randomUUID()); | |
| 164 | + void coreEngine.dispatch({ | |
| 165 | + command: { | |
| 166 | + kind: "AppendAssistantMessage", | |
| 167 | + commandId: crypto.randomUUID(), | |
| 168 | + issuedAt: new Date().toISOString(), | |
| 169 | + payload: { | |
| 170 | + threadId: event.threadId, | |
| 171 | + messageId, | |
| 172 | + text, | |
| 173 | + createdAt: event.createdAt, | |
| 174 | + }, | |
| 175 | + }, | |
| 176 | + }); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + } | |
| 173 | 180 | } |
| 174 | 181 | }); |
| 175 | 182 | |