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 | data: event, | 151 | data: event, |
| 152 | }; | 152 | }; |
| 153 | broadcastPush(push); | 153 | broadcastPush(push); |
| 154 | if ( | 154 | if (event.threadId && event.kind === "notification" && event.method === "item/completed") { |
| 155 | event.threadId && | 155 | const pl = event.payload as Record<string, unknown> | undefined; |
| 156 | typeof event.message === "string" && | 156 | const item = pl && typeof pl === "object" ? (pl as Record<string, unknown>).item : undefined; |
| 157 | event.message.trim().length > 0 && | 157 | if (item && typeof item === "object") { |
| 158 | (event.kind === "notification" || event.method === "turn/completed") | 158 | const rec = item as Record<string, unknown>; |
| 159 | ) { | 159 | if (rec.type === "agentMessage" && typeof rec.text === "string") { |
| 160 | void coreEngine.dispatch({ | 160 | const text = rec.text as string; |
| 161 | command: { | 161 | if (text.trim().length > 0) { |
| 162 | kind: "AppendAssistantMessage", | 162 | const messageId = |
| 163 | commandId: crypto.randomUUID(), | 163 | typeof rec.id === "string" ? rec.id : (event.itemId ?? crypto.randomUUID()); |
| 164 | issuedAt: new Date().toISOString(), | 164 | void coreEngine.dispatch({ |
| 165 | payload: { | 165 | command: { |
| 166 | threadId: event.threadId, | 166 | kind: "AppendAssistantMessage", |
| 167 | messageId: event.itemId ?? crypto.randomUUID(), | 167 | commandId: crypto.randomUUID(), |
| 168 | text: event.message, | 168 | issuedAt: new Date().toISOString(), |
| 169 | createdAt: event.createdAt, | 169 | payload: { |
| 170 | }, | 170 | threadId: event.threadId, |
| 171 | }, | 171 | messageId, |
| 172 | }); | 172 | text, |
| 173 | createdAt: event.createdAt, | ||
| 174 | }, | ||
| 175 | }, | ||
| 176 | }); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 173 | } | 180 | } |
| 174 | }); | 181 | }); |
| 175 | 182 | ||