Skip to content

Commit a478e02

Browse files
roberttwangclaude
andcommitted
Merge main into feat/ui-ux-polish
Resolve conflicts with the latest main; keep both sides' additions (i18n dictionaries, runner/A2A rows, review-mode run header, user turn actions) without dropping either branch's behaviour. Co-Authored-By: Claude Code <noreply@anthropic.com>
2 parents 7fa55fb + f3c1fcd commit a478e02

105 files changed

Lines changed: 4015 additions & 415 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎chatbot/src/ActivityTrace.jsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,28 @@ function Narration({
353353
),
354354
);
355355
}
356+
// The history response already contains the visible answer. Fetch the trace
357+
// when the reader opens it, or follows a dispatch into a subagent's process.
358+
export function DeferredActivity({ sessionId, index, activityRef, loadActivity }) {
359+
const [error, setError] = useState("");
360+
const [attempt, setAttempt] = useState(0);
361+
useEffect(() => {
362+
let current = true;
363+
setError("");
364+
loadActivity(sessionId, index, activityRef).catch((e) => {
365+
if (current) setError(e.message || "执行过程加载失败");
366+
});
367+
return () => { current = false; };
368+
}, [sessionId, index, activityRef, loadActivity, attempt]);
369+
return error ? (
370+
<p role="alert" className="execution-empty">
371+
{error} <button type="button" onClick={() => setAttempt(n => n + 1)}>重试</button>
372+
</p>
373+
) : <p role="status" className="execution-empty">正在读取执行过程…</p>;
374+
}
375+
356376
export function ReplyTimeline({
377+
deferredActivity = null,
357378
steps = [],
358379
startedAt,
359380
finishedAt,
@@ -375,6 +396,7 @@ export function ReplyTimeline({
375396
live={live}
376397
interrupted={interrupted}
377398
approvals={approvals}
399+
deferredActivity={deferredActivity}
378400
narration={traceBlocks(steps, { live })}
379401
citationProps={{
380402
knowledgeReads,
@@ -393,6 +415,7 @@ export function ReplyTimeline({
393415
// the whole process into its elapsed-time line; opening it shows every note,
394416
// thought and step between the line and the answer.
395417
export default function ActivityTrace({
418+
deferredActivity = null,
396419
steps = [],
397420
startedAt,
398421
finishedAt,
@@ -505,7 +528,7 @@ export default function ActivityTrace({
505528
</summary>
506529
{expanded ? (
507530
<div className="execution-body" aria-label="执行过程">
508-
{blocks.length ? (
531+
{deferredActivity ? <DeferredActivity {...deferredActivity} /> : blocks.length ? (
509532
<Narration
510533
blocks={blocks}
511534
live={false}

‎chatbot/src/App.jsx‎

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import {
2626
api,
2727
write,
2828
attachmentURL,
29+
attachmentThumbnailURL,
2930
parseReply,
3031
collectArtifacts,
32+
messageOffset,
3133
visibleText,
3234
elapsedSeconds,
3335
formatElapsed,
@@ -114,6 +116,7 @@ const environmentVisibilityKey = "agentflow.native-chat.environmentVisibility.v1
114116
const sessionApprovalScope = ({ id, projectId }) => `approval.session:${JSON.stringify([id, projectId || ""])}`;
115117
const draftApprovalScope = (slot, projectId) =>
116118
slot.startsWith("issue:") ? `approval.${JSON.stringify([slot, projectId])}` : `approval.${slot}`;
119+
const maxMessageAttachments = 8;
117120
const draftSnapshot = ({ text, attachments, references }) => JSON.stringify({ text, attachments, references });
118121
const sidebarWidthKey = "agentflow.sidebarWidth";
119122
const sidebarLayoutKey = "agentflow.sidebarLayoutVersion";
@@ -236,19 +239,20 @@ function copiedReply(message, generation, live) {
236239
}
237240
return reply;
238241
}
239-
function ReplyHeading({ message, steps }) {
242+
function ReplyHeading({ message, steps, deferredActivity }) {
240243
return (
241244
<div className="reply-heading">
242245
<ActivityTrace
243246
steps={steps}
244247
startedAt={message.startedAt}
245248
finishedAt={message.createdAt}
246249
interrupted={!!message.unfinished}
250+
deferredActivity={deferredActivity}
247251
/>
248252
</div>
249253
);
250254
}
251-
function AssistantTurn({ message, steps, assets, projectId, sessionId, local, readOnly, onCLIInstall }) {
255+
function AssistantTurn({ message, steps, deferredActivity, assets, projectId, sessionId, local, readOnly, onCLIInstall }) {
252256
const reply = parseReply(message);
253257
const answer = hasTextSegments(steps)
254258
? finalReply(reply.message, steps)
@@ -282,12 +286,13 @@ function AssistantTurn({ message, steps, assets, projectId, sessionId, local, re
282286
steps={steps}
283287
startedAt={message.startedAt}
284288
finishedAt={message.createdAt}
289+
deferredActivity={deferredActivity}
285290
knowledgeReads={message.knowledgeReads}
286291
knowledgeSummary={knowledgeSummary}
287292
onCitationClick={handleCitationClick}
288293
/>
289294
) : (
290-
<ReplyHeading message={message} steps={steps} />
295+
<ReplyHeading message={message} steps={steps} deferredActivity={deferredActivity} />
291296
)}
292297
<div className="message-body">
293298
<RichContent
@@ -516,8 +521,14 @@ export default function App() {
516521
draftOrigin = useRef(null),
517522
savingDraftApproval = useRef(null),
518523
previousArtifacts = useRef({ id: null, ids: new Set(), baselined: false }),
519-
dialogInput = useRef(),
520-
composerPreviews = useRef(new Map());
524+
dialogInput = useRef();
525+
const previews = useMemo(() => ({ uploaded: new Map(), pending: new Set() }), [chat.user?.id]);
526+
useEffect(() => () => {
527+
for (const url of previews.uploaded.values()) URL.revokeObjectURL(url);
528+
for (const url of previews.pending) URL.revokeObjectURL(url);
529+
previews.uploaded.clear();
530+
previews.pending.clear();
531+
}, [previews]);
521532
// A requirement handed over by the workbench drafts in its own slot so the
522533
// project's unsent new-conversation draft and attachments stay untouched.
523534
const newDraftSlot = issueDraft && issueDraft.projectId === chat.projectId ? "issue:" + issueDraft.issueId : "new:" + chat.projectId;
@@ -717,6 +728,14 @@ export default function App() {
717728
url.searchParams.delete("quickAccess");
718729
history.replaceState(history.state, "", url);
719730
}
731+
// The workbench lifts its toasts over the composer only when the composer
732+
// sits at the bottom (an open conversation). On the home page the composer
733+
// is centred and grows downward, so a lifted toast would land on 发送.
734+
const layout = chat.activeId ? "conversation" : "home";
735+
useEffect(() => {
736+
if (window.parent !== window)
737+
window.parent.postMessage({ type: "agentflow-chat-layout", layout }, location.origin);
738+
}, [layout]);
720739
useEffect(() => {
721740
const wide = sidebarViewport().matchMedia("(min-width:1001px)");
722741
const apply = () => setSidebarWidth(readSidebarWidth());
@@ -873,6 +892,10 @@ export default function App() {
873892
previousArtifacts.current = previous;
874893
}
875894
if (!chat.activeId || chat.session?.id !== chat.activeId) return;
895+
// A view=recent tail is still part of restoring the conversation. The
896+
// full transcript adds the artifacts of earlier turns, which are not new,
897+
// so the first complete snapshot is the baseline, as for any other open.
898+
if (chat.session.messagesPartial) return;
876899
const entries = [...sidebarArtifacts, ...conversationRuns];
877900
const addedEntries = previous.baselined
878901
? entries.filter((entry) => !previous.ids.has(entry.id)) : [];
@@ -911,6 +934,7 @@ export default function App() {
911934
}, [
912935
chat.activeId,
913936
chat.session?.id,
937+
chat.session?.messagesPartial,
914938
artifactList,
915939
conversationRuns,
916940
panel,
@@ -991,7 +1015,7 @@ export default function App() {
9911015
closeMenu();
9921016
}
9931017
async function submit() {
994-
if (!hasComposerExecutor || uploading || composerLoading || draftReady.current !== draftKey ||
1018+
if (!chat.ready || !hasComposerExecutor || uploading || composerLoading || draftReady.current !== draftKey ||
9951019
(!chat.activeId && savingDraftApproval.current)) return;
9961020
follow.current = true;
9971021
const snapshot = draftSnapshot({ text, attachments, references });
@@ -1019,12 +1043,10 @@ export default function App() {
10191043
if (ok) {
10201044
const clearedDraft = clearDraftIfUnchanged(draftKey, snapshot);
10211045
if (clearedDraft && savedDraftKey) clearDraftApproval(draftApproval.scope, savedApprovalMode);
1022-
let clearedVisible = clearedDraft && visible.key === draftKey;
10231046
if (copiedFrom?.snapshot === snapshot && /^(new|issue):/.test(copiedFrom.slot)) {
10241047
const originKey = draftKeyPrefix + copiedFrom.slot;
10251048
if (clearDraftIfUnchanged(originKey, snapshot)) {
10261049
if (copiedFrom.approvalScope) clearDraftApproval(copiedFrom.approvalScope, copiedFrom.mode);
1027-
clearedVisible ||= visible.key === originKey;
10281050
}
10291051
}
10301052
if (!clearedDraft && copiedFrom) {
@@ -1039,10 +1061,6 @@ export default function App() {
10391061
persistDraft(draftKey, { text, attachments, references });
10401062
}
10411063
}
1042-
for (const attachment of attachments) {
1043-
if (clearedVisible || !visible.attachments.some((current) => current.id === attachment.id))
1044-
releaseComposerPreview(attachment.id);
1045-
}
10461064
} else if (visible.key === savedDraftKey && draftReady.current === savedDraftKey &&
10471065
!visible.text && !visible.attachments.length && !visible.references.length) {
10481066
// The session was saved but the first message was rejected. Keep its
@@ -1074,23 +1092,23 @@ export default function App() {
10741092
}
10751093
function composerPreviewURL(a) {
10761094
return (
1077-
composerPreviews.current.get(a.id) ||
1095+
previews.uploaded.get(a.id) ||
10781096
attachmentURL(a, chat.session?.id || chat.activeId || "")
10791097
);
10801098
}
1081-
function releaseComposerPreview(id) {
1082-
const url = composerPreviews.current.get(id);
1099+
function releaseUploadedPreview(id) {
1100+
const url = previews.uploaded.get(id);
10831101
if (!url) return;
10841102
URL.revokeObjectURL(url);
1085-
composerPreviews.current.delete(id);
1103+
previews.uploaded.delete(id);
10861104
}
10871105
function removeAttachment(a) {
1088-
releaseComposerPreview(a.id);
1106+
releaseUploadedPreview(a.id);
10891107
setAttachments((old) => old.filter((x) => x.id !== a.id));
10901108
}
10911109
async function upload(files) {
10921110
if (!files.length) return;
1093-
if (files.length + attachments.length > 8) {
1111+
if (files.length + attachments.length > maxMessageAttachments) {
10941112
chat.setError("每轮最多上传 8 个文件。");
10951113
return;
10961114
}
@@ -1114,7 +1132,10 @@ export default function App() {
11141132
previewURL,
11151133
}
11161134
: null;
1117-
if (slot) setPendingAttachments((old) => [...old, slot]);
1135+
if (slot) {
1136+
previews.pending.add(previewURL);
1137+
setPendingAttachments((old) => [...old, slot]);
1138+
}
11181139
try {
11191140
if (chat.local) {
11201141
const localDataUrl = await new Promise((resolve, reject) => {
@@ -1140,10 +1161,18 @@ export default function App() {
11401161
method: "POST",
11411162
body,
11421163
});
1143-
if (previewURL) composerPreviews.current.set(uploaded.id, previewURL);
1164+
if (previewURL) {
1165+
// A disposed view already revoked its pending URLs.
1166+
if (!previews.pending.delete(previewURL)) return;
1167+
// Keep a full turn of recent screenshots through optimistic sends
1168+
// and transcript refreshes, without persisting browser-local URLs.
1169+
if (previews.uploaded.size >= maxMessageAttachments)
1170+
releaseUploadedPreview(previews.uploaded.keys().next().value);
1171+
previews.uploaded.set(uploaded.id, previewURL);
1172+
}
11441173
results.push(uploaded);
11451174
} catch (err) {
1146-
if (previewURL) URL.revokeObjectURL(previewURL);
1175+
if (previews.pending.delete(previewURL)) URL.revokeObjectURL(previewURL);
11471176
throw err;
11481177
} finally {
11491178
if (slot)
@@ -1321,6 +1350,8 @@ export default function App() {
13211350
}));
13221351
}, [chat.activeId, chat.projectId]);
13231352
const messages = chat.session?.messages || [];
1353+
// Stored index of messages[0]; artifacts name messages by that index.
1354+
const messageBase = messageOffset(chat.session);
13241355
const conversationStarted = Boolean(
13251356
chat.activeId && chat.session?.id === chat.activeId &&
13261357
(messages.length || chat.busy || sidebarArtifacts.length || conversationRuns.length),
@@ -2282,6 +2313,7 @@ export default function App() {
22822313
scroll={scroll}
22832314
follow={follow}
22842315
loading={!chat.session && !chat.error}
2316+
earlier={!!chat.session?.messagesPartial}
22852317
renderMessage={(message, index) =>
22862318
isProposalTimeout(message, messages[index - 1]) ? null : confirmationCaption(message, messages[index - 1]) ? (
22872319
<div
@@ -2301,6 +2333,10 @@ export default function App() {
23012333
{message.role === "assistant" ? (
23022334
<AssistantTurn
23032335
message={message}
2336+
deferredActivity={message.activityRef ? {
2337+
sessionId: chat.session.id, index: messageBase + index,
2338+
activityRef: message.activityRef, loadActivity: chat.loadActivity,
2339+
} : null}
23042340
steps={activityForReply(
23052341
message,
23062342
chat.generation,
@@ -2356,7 +2392,7 @@ export default function App() {
23562392
<>
23572393
<IconButton
23582394
label="编辑消息"
2359-
disabled={chat.busy}
2395+
disabled={chat.busy || !!chat.session?.messagesPartial}
23602396
onClick={() =>
23612397
setDialog({
23622398
type: "edit",
@@ -2370,7 +2406,7 @@ export default function App() {
23702406
</IconButton>
23712407
<IconButton
23722408
label="从此处创建分支"
2373-
disabled={chat.busy}
2409+
disabled={chat.busy || !!chat.session?.messagesPartial}
23742410
onClick={() =>
23752411
setDialog({
23762412
type: "edit",
@@ -2398,6 +2434,7 @@ export default function App() {
23982434
<Attachment
23992435
key={a.id}
24002436
attachment={a}
2437+
localPreviewURL={previews.uploaded.get(a.id)}
24012438
sessionId={chat.session.id}
24022439
onOpen={openArtifact}
24032440
/>
@@ -2408,7 +2445,7 @@ export default function App() {
24082445
<>
24092446
<div className="message-drafts">
24102447
{artifactList
2411-
.filter((a) => a.draft && a.messageIndex === index)
2448+
.filter((a) => a.draft && a.messageIndex === messageBase + index)
24122449
.map((a) => (
24132450
<DraftCard
24142451
key={a.id}
@@ -2636,7 +2673,7 @@ export default function App() {
26362673
setImagePreview({ src: url, name: a.name })
26372674
}
26382675
>
2639-
<img src={url} alt={a.name} />
2676+
<img src={attachmentThumbnailURL(url, a.mimeType)} alt={a.name} />
26402677
</button>
26412678
<button
26422679
type="button"
@@ -2846,6 +2883,7 @@ export default function App() {
28462883
title={chat.busy ? "当前回复结束后自动发送" : undefined}
28472884
disabled={
28482885
!chat.ready ||
2886+
!!chat.session?.messagesPartial ||
28492887
!hasComposerExecutor ||
28502888
!!chat.missingServerCLI ||
28512889
chat.submitting ||

‎chatbot/src/ArtifactPanel.jsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, { useEffect, useRef, useState } from "react";
22
import HarnessIcon from "./HarnessIcon";
3-
import { api } from "./api";
3+
import { api, messageOffset } from "./api";
44
import { ArtifactPreview, RichContent } from "./RichContent";
55
import { DraftCard } from "./SidePanel";
66
import SopRunPanel, { runStatus } from "./SopRunPanel";
77
import ChangesPanel from "./ChangesPanel";
88
import AgentBrowser from "./AgentBrowser";
99
import WorkspaceIDE from "./WorkspaceIDE";
1010
import { SubagentSession, subagentName, subagentStatus } from "./SubagentSession";
11+
import { DeferredActivity } from "./ActivityTrace";
1112
import { collectSubagents, resumeMissed } from "./activity";
1213
import { IconButton } from "./ui";
1314
import { definitionTarget, actionName } from "./platform.js";
@@ -207,6 +208,7 @@ export default function ArtifactPanel({
207208
chat?.session?.messages || [],
208209
live ? chat?.live?.activity || [] : [],
209210
chat?.model || "",
211+
messageOffset(chat?.session),
210212
);
211213
// A new subagent is keyed by its dispatch until its agent ID arrives, so
212214
// an opened one is found by either.
@@ -646,6 +648,8 @@ export default function ArtifactPanel({
646648
onSelectNode={setNodeId}
647649
onClose={() => setSelected(null)}
648650
/>
651+
) : selectedAgent?.deferredActivity ? (
652+
<DeferredActivity {...selectedAgent.deferredActivity} sessionId={chat.session.id} loadActivity={chat.loadActivity} />
649653
) : selectedAgent ? (
650654
<SubagentSession
651655
agent={selectedAgent}

‎chatbot/src/MessageHistory.jsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useLayoutEffect, useRef, useState } from "react";
22

33
const pageSize = 40;
44

5-
export default function MessageHistory({ messages, renderMessage, scroll, follow, loading, children }) {
5+
export default function MessageHistory({ messages, renderMessage, scroll, follow, loading, earlier, children }) {
66
const [limit, setLimit] = useState(pageSize);
77
const [readingFrom, setReadingFrom] = useState(null);
88
const anchor = useRef(null);
@@ -41,6 +41,7 @@ export default function MessageHistory({ messages, renderMessage, scroll, follow
4141
<div className="message-scroll" ref={scroll} onScroll={onScroll}>
4242
<div className="message-column">
4343
{loading ? <div className="loading-session">正在恢复对话…</div> : null}
44+
{earlier ? <div className="loading-session">正在补齐更早的消息…</div> : null}
4445
{first > 0 ? (
4546
<button type="button" className="message-history-more" onClick={showEarlier}>
4647
显示更早的消息

0 commit comments

Comments
 (0)