Skip to content

Commit 04d1745

Browse files
steipeteampagent
andauthored
perf(line): skip empty inbound media projection (#127827)
Co-authored-by: Amp <[email protected]>
1 parent 54257e0 commit 04d1745

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎extensions/line/src/bot-message-context.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import { buildLineMessageContext, buildLinePostbackContext } from "./bot-message
1818
import type { ResolvedLineAccount } from "./types.js";
1919

2020
const logVerboseMock = vi.hoisted(() => vi.fn());
21+
const toInboundMediaFactsWithMetadataMock = vi.hoisted(() => vi.fn());
22+
23+
vi.mock("openclaw/plugin-sdk/channel-inbound", async (importOriginal) => {
24+
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/channel-inbound")>();
25+
toInboundMediaFactsWithMetadataMock.mockImplementation(actual.toInboundMediaFactsWithMetadata);
26+
return {
27+
...actual,
28+
toInboundMediaFactsWithMetadata: toInboundMediaFactsWithMetadataMock,
29+
};
30+
});
2131

2232
vi.mock("openclaw/plugin-sdk/runtime-env", async () => {
2333
const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/runtime-env")>(
@@ -89,6 +99,7 @@ describe("buildLineMessageContext", () => {
8999

90100
beforeEach(async () => {
91101
logVerboseMock.mockClear();
102+
toInboundMediaFactsWithMetadataMock.mockClear();
92103
setActivePluginRegistry(
93104
createTestRegistry([
94105
{
@@ -129,6 +140,21 @@ describe("buildLineMessageContext", () => {
129140
expect(context?.ctxPayload.To).toBe("line:group:group-1");
130141
});
131142

143+
it("skips media metadata projection for text-only messages", async () => {
144+
const event = createMessageEvent({ type: "user", userId: "user-1" });
145+
146+
const context = await buildLineMessageContext({
147+
event,
148+
allMedia: [],
149+
cfg,
150+
account,
151+
commandAuthorized: true,
152+
});
153+
154+
expect(context?.ctxPayload.media).toEqual([]);
155+
expect(toInboundMediaFactsWithMetadataMock).not.toHaveBeenCalled();
156+
});
157+
132158
it("passes the caller-provided inbound history through to the context payload", async () => {
133159
const event = createMessageEvent({ type: "group", groupId: "group-1", userId: "user-1" });
134160

‎extensions/line/src/bot-message-context.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ async function finalizeLineInboundContext(params: {
296296
});
297297

298298
const agentBody = params.agentBody ?? params.rawBody;
299-
const media = await toInboundMediaFactsWithMetadata(params.media);
299+
const media =
300+
params.media.length === 0 ? [] : await toInboundMediaFactsWithMetadata(params.media);
300301
const body = formatInboundEnvelope({
301302
channel: "LINE",
302303
from: conversationLabel,

0 commit comments

Comments
 (0)