fix(mattermost): share progress draft labels

This commit is contained in:
Vincent Koc
2026-05-03 18:48:00 -07:00
parent 56b83230df
commit 90c0edcb61
3 changed files with 29 additions and 7 deletions

View File

@@ -243,11 +243,17 @@ describe("createMattermostDraftStream", () => {
});
describe("buildMattermostToolStatusText", () => {
it("renders a status with the tool name", () => {
expect(buildMattermostToolStatusText({ name: "read" })).toBe("Running `read`…");
it("renders a status with the shared tool label", () => {
expect(buildMattermostToolStatusText({ name: "read" })).toBe("📖 Read");
});
it("falls back to a generic running tool status", () => {
expect(buildMattermostToolStatusText({ name: "exec" })).toBe("Running `exec`…");
it("honors raw exec detail mode", () => {
expect(
buildMattermostToolStatusText({
name: "exec",
args: { command: "pnpm test -- --watch=false" },
detailMode: "raw",
}),
).toBe("🛠️ Exec: run tests, `pnpm test -- --watch=false`");
});
});

View File

@@ -1,4 +1,5 @@
import { createFinalizableDraftLifecycle } from "openclaw/plugin-sdk/channel-lifecycle";
import { formatChannelProgressDraftLine } from "openclaw/plugin-sdk/channel-streaming";
import {
createMattermostPost,
deleteMattermostPost,
@@ -31,9 +32,23 @@ function normalizeMattermostDraftText(text: string, maxChars: number): string {
return `${trimmed.slice(0, Math.max(0, maxChars - 3)).trimEnd()}...`;
}
export function buildMattermostToolStatusText(params: { name?: string; phase?: string }): string {
const tool = params.name?.trim() ? ` \`${params.name.trim()}\`` : " tool";
return `Running${tool}`;
export function buildMattermostToolStatusText(params: {
name?: string;
phase?: string;
args?: Record<string, unknown>;
detailMode?: "explain" | "raw";
}): string {
return (
formatChannelProgressDraftLine(
{
event: "tool",
name: params.name,
phase: params.phase,
args: params.args,
},
params.detailMode ? { detailMode: params.detailMode } : undefined,
) ?? "Running tool..."
);
}
export function createMattermostDraftStream(params: {