Skip to content

Commit 305dc48

Browse files
roberttwangclaude
andcommitted
Merge main into fix/sweep-1127-knowledge-english-ui
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 cfb2ae5 + f3c1fcd commit 305dc48

105 files changed

Lines changed: 4004 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
@@ -514,8 +519,14 @@ export default function App() {
514519
draftOrigin = useRef(null),
515520
savingDraftApproval = useRef(null),
516521
previousArtifacts = useRef({ id: null, ids: new Set(), baselined: false }),
517-
dialogInput = useRef(),
518-
composerPreviews = useRef(new Map());
522+
dialogInput = useRef();
523+
const previews = useMemo(() => ({ uploaded: new Map(), pending: new Set() }), [chat.user?.id]);
524+
useEffect(() => () => {
525+
for (const url of previews.uploaded.values()) URL.revokeObjectURL(url);
526+
for (const url of previews.pending) URL.revokeObjectURL(url);
527+
previews.uploaded.clear();
528+
previews.pending.clear();
529+
}, [previews]);
519530
// A requirement handed over by the workbench drafts in its own slot so the
520531
// project's unsent new-conversation draft and attachments stay untouched.
521532
const newDraftSlot = issueDraft && issueDraft.projectId === chat.projectId ? "issue:" + issueDraft.issueId : "new:" + chat.projectId;
@@ -715,6 +726,14 @@ export default function App() {
715726
url.searchParams.delete("quickAccess");
716727
history.replaceState(history.state, "", url);
717728
}
729+
// The workbench lifts its toasts over the composer only when the composer
730+
// sits at the bottom (an open conversation). On the home page the composer
731+
// is centred and grows downward, so a lifted toast would land on 发送.
732+
const layout = chat.activeId ? "conversation" : "home";
733+
useEffect(() => {
734+
if (window.parent !== window)
735+
window.parent.postMessage({ type: "agentflow-chat-layout", layout }, location.origin);
736+
}, [layout]);
718737
useEffect(() => {
719738
const wide = sidebarViewport().matchMedia("(min-width:1001px)");
720739
const apply = () => setSidebarWidth(readSidebarWidth());
@@ -858,6 +877,10 @@ export default function App() {
858877
previousArtifacts.current = previous;
859878
}
860879
if (!chat.activeId || chat.session?.id !== chat.activeId) return;
880+
// A view=recent tail is still part of restoring the conversation. The
881+
// full transcript adds the artifacts of earlier turns, which are not new,
882+
// so the first complete snapshot is the baseline, as for any other open.
883+
if (chat.session.messagesPartial) return;
861884
const entries = [...sidebarArtifacts, ...conversationRuns];
862885
const addedEntries = previous.baselined
863886
? entries.filter((entry) => !previous.ids.has(entry.id)) : [];
@@ -896,6 +919,7 @@ export default function App() {
896919
}, [
897920
chat.activeId,
898921
chat.session?.id,
922+
chat.session?.messagesPartial,
899923
artifactList,
900924
conversationRuns,
901925
panel,
@@ -976,7 +1000,7 @@ export default function App() {
9761000
closeMenu();
9771001
}
9781002
async function submit() {
979-
if (!hasComposerExecutor || uploading || composerLoading || draftReady.current !== draftKey ||
1003+
if (!chat.ready || !hasComposerExecutor || uploading || composerLoading || draftReady.current !== draftKey ||
9801004
(!chat.activeId && savingDraftApproval.current)) return;
9811005
follow.current = true;
9821006
const snapshot = draftSnapshot({ text, attachments, references });
@@ -1004,12 +1028,10 @@ export default function App() {
10041028
if (ok) {
10051029
const clearedDraft = clearDraftIfUnchanged(draftKey, snapshot);
10061030
if (clearedDraft && savedDraftKey) clearDraftApproval(draftApproval.scope, savedApprovalMode);
1007-
let clearedVisible = clearedDraft && visible.key === draftKey;
10081031
if (copiedFrom?.snapshot === snapshot && /^(new|issue):/.test(copiedFrom.slot)) {
10091032
const originKey = draftKeyPrefix + copiedFrom.slot;
10101033
if (clearDraftIfUnchanged(originKey, snapshot)) {
10111034
if (copiedFrom.approvalScope) clearDraftApproval(copiedFrom.approvalScope, copiedFrom.mode);
1012-
clearedVisible ||= visible.key === originKey;
10131035
}
10141036
}
10151037
if (!clearedDraft && copiedFrom) {
@@ -1024,10 +1046,6 @@ export default function App() {
10241046
persistDraft(draftKey, { text, attachments, references });
10251047
}
10261048
}
1027-
for (const attachment of attachments) {
1028-
if (clearedVisible || !visible.attachments.some((current) => current.id === attachment.id))
1029-
releaseComposerPreview(attachment.id);
1030-
}
10311049
} else if (visible.key === savedDraftKey && draftReady.current === savedDraftKey &&
10321050
!visible.text && !visible.attachments.length && !visible.references.length) {
10331051
// The session was saved but the first message was rejected. Keep its
@@ -1059,23 +1077,23 @@ export default function App() {
10591077
}
10601078
function composerPreviewURL(a) {
10611079
return (
1062-
composerPreviews.current.get(a.id) ||
1080+
previews.uploaded.get(a.id) ||
10631081
attachmentURL(a, chat.session?.id || chat.activeId || "")
10641082
);
10651083
}
1066-
function releaseComposerPreview(id) {
1067-
const url = composerPreviews.current.get(id);
1084+
function releaseUploadedPreview(id) {
1085+
const url = previews.uploaded.get(id);
10681086
if (!url) return;
10691087
URL.revokeObjectURL(url);
1070-
composerPreviews.current.delete(id);
1088+
previews.uploaded.delete(id);
10711089
}
10721090
function removeAttachment(a) {
1073-
releaseComposerPreview(a.id);
1091+
releaseUploadedPreview(a.id);
10741092
setAttachments((old) => old.filter((x) => x.id !== a.id));
10751093
}
10761094
async function upload(files) {
10771095
if (!files.length) return;
1078-
if (files.length + attachments.length > 8) {
1096+
if (files.length + attachments.length > maxMessageAttachments) {
10791097
chat.setError("每轮最多上传 8 个文件。");
10801098
return;
10811099
}
@@ -1099,7 +1117,10 @@ export default function App() {
10991117
previewURL,
11001118
}
11011119
: null;
1102-
if (slot) setPendingAttachments((old) => [...old, slot]);
1120+
if (slot) {
1121+
previews.pending.add(previewURL);
1122+
setPendingAttachments((old) => [...old, slot]);
1123+
}
11031124
try {
11041125
if (chat.local) {
11051126
const localDataUrl = await new Promise((resolve, reject) => {
@@ -1125,10 +1146,18 @@ export default function App() {
11251146
method: "POST",
11261147
body,
11271148
});
1128-
if (previewURL) composerPreviews.current.set(uploaded.id, previewURL);
1149+
if (previewURL) {
1150+
// A disposed view already revoked its pending URLs.
1151+
if (!previews.pending.delete(previewURL)) return;
1152+
// Keep a full turn of recent screenshots through optimistic sends
1153+
// and transcript refreshes, without persisting browser-local URLs.
1154+
if (previews.uploaded.size >= maxMessageAttachments)
1155+
releaseUploadedPreview(previews.uploaded.keys().next().value);
1156+
previews.uploaded.set(uploaded.id, previewURL);
1157+
}
11291158
results.push(uploaded);
11301159
} catch (err) {
1131-
if (previewURL) URL.revokeObjectURL(previewURL);
1160+
if (previews.pending.delete(previewURL)) URL.revokeObjectURL(previewURL);
11321161
throw err;
11331162
} finally {
11341163
if (slot)
@@ -1306,6 +1335,8 @@ export default function App() {
13061335
}));
13071336
}, [chat.activeId, chat.projectId]);
13081337
const messages = chat.session?.messages || [];
1338+
// Stored index of messages[0]; artifacts name messages by that index.
1339+
const messageBase = messageOffset(chat.session);
13091340
const conversationStarted = Boolean(
13101341
chat.activeId && chat.session?.id === chat.activeId &&
13111342
(messages.length || chat.busy || sidebarArtifacts.length || conversationRuns.length),
@@ -2257,6 +2288,7 @@ export default function App() {
22572288
scroll={scroll}
22582289
follow={follow}
22592290
loading={!chat.session && !chat.error}
2291+
earlier={!!chat.session?.messagesPartial}
22602292
renderMessage={(message, index) =>
22612293
isProposalTimeout(message, messages[index - 1]) ? null : confirmationCaption(message, messages[index - 1]) ? (
22622294
<div
@@ -2276,6 +2308,10 @@ export default function App() {
22762308
{message.role === "assistant" ? (
22772309
<AssistantTurn
22782310
message={message}
2311+
deferredActivity={message.activityRef ? {
2312+
sessionId: chat.session.id, index: messageBase + index,
2313+
activityRef: message.activityRef, loadActivity: chat.loadActivity,
2314+
} : null}
22792315
steps={activityForReply(
22802316
message,
22812317
chat.generation,
@@ -2331,7 +2367,7 @@ export default function App() {
23312367
<>
23322368
<IconButton
23332369
label="编辑消息"
2334-
disabled={chat.busy}
2370+
disabled={chat.busy || !!chat.session?.messagesPartial}
23352371
onClick={() =>
23362372
setDialog({
23372373
type: "edit",
@@ -2345,7 +2381,7 @@ export default function App() {
23452381
</IconButton>
23462382
<IconButton
23472383
label="从此处创建分支"
2348-
disabled={chat.busy}
2384+
disabled={chat.busy || !!chat.session?.messagesPartial}
23492385
onClick={() =>
23502386
setDialog({
23512387
type: "edit",
@@ -2373,6 +2409,7 @@ export default function App() {
23732409
<Attachment
23742410
key={a.id}
23752411
attachment={a}
2412+
localPreviewURL={previews.uploaded.get(a.id)}
23762413
sessionId={chat.session.id}
23772414
onOpen={openArtifact}
23782415
/>
@@ -2383,7 +2420,7 @@ export default function App() {
23832420
<>
23842421
<div className="message-drafts">
23852422
{artifactList
2386-
.filter((a) => a.draft && a.messageIndex === index)
2423+
.filter((a) => a.draft && a.messageIndex === messageBase + index)
23872424
.map((a) => (
23882425
<DraftCard
23892426
key={a.id}
@@ -2611,7 +2648,7 @@ export default function App() {
26112648
setImagePreview({ src: url, name: a.name })
26122649
}
26132650
>
2614-
<img src={url} alt={a.name} />
2651+
<img src={attachmentThumbnailURL(url, a.mimeType)} alt={a.name} />
26152652
</button>
26162653
<button
26172654
type="button"
@@ -2821,6 +2858,7 @@ export default function App() {
28212858
title={chat.busy ? "当前回复结束后自动发送" : undefined}
28222859
disabled={
28232860
!chat.ready ||
2861+
!!chat.session?.messagesPartial ||
28242862
!hasComposerExecutor ||
28252863
!!chat.missingServerCLI ||
28262864
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)