Skip to content

Commit 389a114

Browse files
committed
fix: hide empty background task messages
1 parent 81043da commit 389a114

3 files changed

Lines changed: 102 additions & 29 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export interface LiveUserMessageVisibilityInput {
2+
prompt: string;
3+
attachments: readonly unknown[];
4+
pluginCommand?: unknown;
5+
}
6+
7+
export function hasVisibleLiveUserMessage(
8+
turn: LiveUserMessageVisibilityInput,
9+
): boolean {
10+
return (
11+
turn.prompt.trim().length > 0 ||
12+
turn.attachments.length > 0 ||
13+
turn.pluginCommand !== undefined
14+
);
15+
}

apps/kimi-code/src/components/chat/ConversationViews.tsx

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
type QueuedPrompt,
4545
type RemoteQueuedPrompt,
4646
} from "../../chat/liveTurns";
47+
import { hasVisibleLiveUserMessage } from "../../chat/liveTurnVisibility";
4748
import { isVisibleRetryStep } from "../../chat/retryStatus";
4849
import {
4950
mediaSourceUrl,
@@ -172,41 +173,44 @@ export function LiveTurnView({
172173
);
173174
const streaming = isTurnRunning(turn);
174175
const cronFire = parseCronFireMessage(turn.prompt);
176+
const showUserMessage = hasVisibleLiveUserMessage(turn);
175177

176178
return (
177179
<section
178180
className="conversation-turn live-conversation-turn"
179181
data-conversation-turn-id={outlineId}
180182
>
181-
<article className={`message user-message live-user-message${cronFire ? " cron-fire-message" : ""}`}>
182-
<div className="message-meta">
183-
<time>{formatTime(turn.createdAt)}</time>
184-
</div>
185-
<div className={`user-bubble${cronFire ? " cron-fire-bubble" : ""}`}>
186-
{cronFire ? (
187-
<CronFireMessageContent fire={cronFire} />
188-
) : turn.pluginCommand ? (
189-
<PluginCommandDisplayContent
190-
command={turn.pluginCommand}
191-
onOpen={() =>
192-
onPluginCommandOpen({
193-
...turn.pluginCommand!,
194-
id: turn.userMessageId ?? turn.promptId ?? turn.createdAt,
195-
content: turn.pluginCommandContent ?? "",
196-
createdAt: turn.createdAt,
197-
})
198-
}
199-
/>
200-
) : (
201-
<SkillPromptDisplayContent
202-
text={turn.prompt}
203-
skills={turn.skills}
204-
onSkillOpen={onSkillOpen}
205-
/>
206-
)}
207-
<PromptAttachmentContent attachments={turn.attachments} />
208-
</div>
209-
</article>
183+
{showUserMessage && (
184+
<article className={`message user-message live-user-message${cronFire ? " cron-fire-message" : ""}`}>
185+
<div className="message-meta">
186+
<time>{formatTime(turn.createdAt)}</time>
187+
</div>
188+
<div className={`user-bubble${cronFire ? " cron-fire-bubble" : ""}`}>
189+
{cronFire ? (
190+
<CronFireMessageContent fire={cronFire} />
191+
) : turn.pluginCommand ? (
192+
<PluginCommandDisplayContent
193+
command={turn.pluginCommand}
194+
onOpen={() =>
195+
onPluginCommandOpen({
196+
...turn.pluginCommand!,
197+
id: turn.userMessageId ?? turn.promptId ?? turn.createdAt,
198+
content: turn.pluginCommandContent ?? "",
199+
createdAt: turn.createdAt,
200+
})
201+
}
202+
/>
203+
) : (
204+
<SkillPromptDisplayContent
205+
text={turn.prompt}
206+
skills={turn.skills}
207+
onSkillOpen={onSkillOpen}
208+
/>
209+
)}
210+
<PromptAttachmentContent attachments={turn.attachments} />
211+
</div>
212+
</article>
213+
)}
210214
<article className={`message assistant-message live-turn ${turn.status}`}>
211215
<div className="assistant-body">
212216
{visibleSteps.map((step) => {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { hasVisibleLiveUserMessage } from "../src/chat/liveTurnVisibility.ts";
5+
6+
test("hides a model-facing background task turn without visible user content", () => {
7+
assert.equal(
8+
hasVisibleLiveUserMessage({
9+
prompt: "",
10+
attachments: [],
11+
pluginCommand: undefined,
12+
}),
13+
false,
14+
);
15+
});
16+
17+
test("keeps visible prompts, attachments, and plugin commands", () => {
18+
assert.equal(
19+
hasVisibleLiveUserMessage({
20+
prompt: "hello",
21+
attachments: [],
22+
pluginCommand: undefined,
23+
}),
24+
true,
25+
);
26+
assert.equal(
27+
hasVisibleLiveUserMessage({
28+
prompt: "",
29+
attachments: [
30+
{
31+
id: "attachment-1",
32+
name: "image.png",
33+
kind: "image",
34+
mediaType: "image/png",
35+
size: 1,
36+
},
37+
],
38+
pluginCommand: undefined,
39+
}),
40+
true,
41+
);
42+
assert.equal(
43+
hasVisibleLiveUserMessage({
44+
prompt: "",
45+
attachments: [],
46+
pluginCommand: {
47+
pluginId: "plugin-1",
48+
commandName: "run",
49+
args: "",
50+
},
51+
}),
52+
true,
53+
);
54+
});

0 commit comments

Comments
 (0)