diff --git a/openclaw/src/index.test.ts b/openclaw/src/index.test.ts index da2ff908..6b3a08d5 100644 --- a/openclaw/src/index.test.ts +++ b/openclaw/src/index.test.ts @@ -8,7 +8,7 @@ import claudeMemPlugin from "./index.js"; function createMockApi(pluginConfigOverride: Record = {}) { const logs: string[] = []; - const sentMessages: Array<{ to: string; text: string; channel: string }> = []; + const sentMessages: Array<{ to: string; text: string; channel: string; opts?: any }> = []; let registeredService: any = null; const registeredCommands: Map = new Map(); @@ -62,8 +62,8 @@ function createMockApi(pluginConfigOverride: Record = {}) { }, }, whatsapp: { - sendMessageWhatsApp: async (to: string, text: string) => { - sentMessages.push({ to, text, channel: "whatsapp" }); + sendMessageWhatsApp: async (to: string, text: string, opts?: { verbose: boolean }) => { + sentMessages.push({ to, text, channel: "whatsapp", opts }); }, }, line: { @@ -761,6 +761,11 @@ describe("SSE stream integration", () => { function startSSEServer(): Promise { return new Promise((resolve) => { server = createServer((req: IncomingMessage, res: ServerResponse) => { + if (req.url !== "/stream") { + res.writeHead(404); + res.end(); + return; + } res.writeHead(200, { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", @@ -923,7 +928,7 @@ describe("SSE stream integration", () => { await getService().start({}); await new Promise((resolve) => setTimeout(resolve, 200)); - assert.ok(logs.some((l) => l.includes(`localhost:${serverPort}`))); + assert.ok(logs.some((l) => l.includes(`127.0.0.1:${serverPort}`))); await getService().stop({}); }); diff --git a/openclaw/src/index.ts b/openclaw/src/index.ts index fc9ab906..f750023d 100644 --- a/openclaw/src/index.ts +++ b/openclaw/src/index.ts @@ -301,9 +301,9 @@ async function connectToSSEStream( while (!abortController.signal.aborted) { try { setConnectionState("reconnecting"); - api.logger.info(`[claude-mem] Connecting to SSE stream at http://localhost:${port}/stream`); + api.logger.info(`[claude-mem] Connecting to SSE stream at ${workerBaseUrl(port)}/stream`); - const response = await fetch(`http://localhost:${port}/stream`, { + const response = await fetch(`${workerBaseUrl(port)}/stream`, { signal: abortController.signal, headers: { Accept: "text/event-stream" }, }); @@ -339,12 +339,14 @@ async function connectToSSEStream( buffer = frames.pop() || ""; for (const frame of frames) { - const dataLine = frame + // SSE spec: concatenate all data: lines with \n + const dataLines = frame .split("\n") - .find((line) => line.startsWith("data:")); - if (!dataLine) continue; + .filter((line) => line.startsWith("data:")) + .map((line) => line.slice(5).trim()); + if (dataLines.length === 0) continue; - const jsonStr = dataLine.slice(5).trim(); + const jsonStr = dataLines.join("\n"); if (!jsonStr) continue; try {