refactor: dedupe message action helpers

This commit is contained in:
Peter Steinberger
2026-01-17 03:45:59 +00:00
parent a32e5d040c
commit 7f1f9473a0
3 changed files with 45 additions and 16 deletions

View File

@@ -8,9 +8,15 @@ const mocks = vi.hoisted(() => ({
appendAssistantMessageToSessionTranscript: vi.fn(async () => ({ ok: true, sessionFile: "x" })),
}));
vi.mock("../../infra/outbound/message-action-runner.js", () => ({
runMessageAction: mocks.runMessageAction,
}));
vi.mock("../../infra/outbound/message-action-runner.js", async () => {
const actual = await vi.importActual<
typeof import("../../infra/outbound/message-action-runner.js")
>("../../infra/outbound/message-action-runner.js");
return {
...actual,
runMessageAction: mocks.runMessageAction,
};
});
vi.mock("../../config/sessions.js", async () => {
const actual = await vi.importActual<typeof import("../../config/sessions.js")>(

View File

@@ -14,7 +14,7 @@ import {
resolveMirroredTranscriptText,
} from "../../config/sessions.js";
import { GATEWAY_CLIENT_IDS, GATEWAY_CLIENT_MODES } from "../../gateway/protocol/client-info.js";
import { runMessageAction } from "../../infra/outbound/message-action-runner.js";
import { getToolResult, runMessageAction } from "../../infra/outbound/message-action-runner.js";
import { resolveSessionAgentId } from "../agent-scope.js";
import { normalizeAccountId } from "../../routing/session-key.js";
import { channelTargetSchema, channelTargetsSchema, stringEnum } from "../schema/typebox.js";
@@ -227,7 +227,8 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
}
}
if ("toolResult" in result && result.toolResult) return result.toolResult;
const toolResult = getToolResult(result);
if (toolResult) return toolResult;
return jsonResult(result.payload);
},
};