fix(web): annotate group replies with sender
This commit is contained in:
@@ -15,6 +15,7 @@ import { applyTemplate, type TemplateContext } from "./templating.js";
|
||||
import {
|
||||
formatToolAggregate,
|
||||
shortenMeta,
|
||||
shortenPath,
|
||||
TOOL_RESULT_FLUSH_COUNT,
|
||||
TOOL_RESULT_DEBOUNCE_MS,
|
||||
} from "./tool-meta.js";
|
||||
@@ -439,7 +440,7 @@ export async function runCommandReply(
|
||||
const textBlocks = Array.isArray(msg.content)
|
||||
? (msg.content as Array<{ type?: string; text?: string }>)
|
||||
.filter((c) => c?.type === "text" && typeof c.text === "string")
|
||||
.map((c) => c.text.trim())
|
||||
.map((c) => (c.text ?? "").trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
if (textBlocks.length === 0) return;
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
} from "./templating.js";
|
||||
import { isAudio, transcribeInboundAudio } from "./transcription.js";
|
||||
import type { GetReplyOptions, ReplyPayload } from "./types.js";
|
||||
import { triggerWarelayRestart } from "../infra/restart.js";
|
||||
|
||||
export type { GetReplyOptions, ReplyPayload } from "./types.js";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const TOOL_RESULT_DEBOUNCE_MS = 500;
|
||||
export const TOOL_RESULT_FLUSH_COUNT = 5;
|
||||
|
||||
function shortenPath(p: string): string {
|
||||
export function shortenPath(p: string): string {
|
||||
const home = process.env.HOME;
|
||||
if (home && (p === home || p.startsWith(`${home}/`)))
|
||||
return p.replace(home, "~");
|
||||
|
||||
@@ -1068,6 +1068,7 @@ describe("web auto-reply", () => {
|
||||
expect(payload.Body).toContain("Chat messages since your last reply");
|
||||
expect(payload.Body).toContain("Alice: hello group");
|
||||
expect(payload.Body).toContain("@bot ping");
|
||||
expect(payload.Body).toContain("[from: Bob (+222)]");
|
||||
});
|
||||
|
||||
it("emits heartbeat logs with connection metadata", async () => {
|
||||
|
||||
@@ -716,6 +716,12 @@ export async function monitorWebProvider(
|
||||
.join("\\n");
|
||||
combinedBody = `[Chat messages since your last reply - for context]\\n${historyText}\\n\\n[Current message - respond to this]\\n${buildLine(latest)}`;
|
||||
}
|
||||
// Always surface who sent the triggering message so the agent can address them.
|
||||
const senderLabel =
|
||||
latest.senderName && latest.senderE164
|
||||
? `${latest.senderName} (${latest.senderE164})`
|
||||
: latest.senderName ?? latest.senderE164 ?? "Unknown";
|
||||
combinedBody = `${combinedBody}\\n[from: ${senderLabel}]`;
|
||||
// Clear stored history after using it
|
||||
groupHistories.set(conversationId, []);
|
||||
}
|
||||
@@ -812,10 +818,14 @@ export async function monitorWebProvider(
|
||||
}
|
||||
}
|
||||
|
||||
const fromDisplay =
|
||||
latest.chatType === "group"
|
||||
? conversationId
|
||||
: latest.from ?? "unknown";
|
||||
if (isVerbose()) {
|
||||
console.log(
|
||||
success(
|
||||
`↩️ Auto-replied to ${from} (web${replyPayload.mediaUrl || replyPayload.mediaUrls?.length ? ", media" : ""}; batched ${messages.length})`,
|
||||
`↩️ Auto-replied to ${fromDisplay} (web${replyPayload.mediaUrl || replyPayload.mediaUrls?.length ? ", media" : ""}; batched ${messages.length})`,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
@@ -827,7 +837,7 @@ export async function monitorWebProvider(
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(
|
||||
danger(`Failed sending web auto-reply to ${from}: ${String(err)}`),
|
||||
danger(`Failed sending web auto-reply to ${latest.from ?? conversationId}: ${String(err)}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user