History

Fix assistant message capture: use item/completed events instead of broken condition

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.

Cursor Agent committed 8 months ago

Commit 320868a1 parent dbbc2251 file · +26 −19Browse files

Unified · Split

apps/server/src/wsServer.ts+26−19
@@ -151,25 +151,32 @@ export function createServer(options: ServerOptions) { · 150 unmodified lines
151151 data: event,
152152 };
153153 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+ }
173180 }
174181 });
175182

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t