Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MessageActivity } from "./message-activity";
import { GoalDraftCard } from "./goal-draft-card";
import type { GoalDraft } from "../../../../../../loopx/control_plane/collaboration/goal_draft.js";
import {goalDraftReady} from "./goal-create-request";
import {Fragment, useEffect, useEffectEvent, useLayoutEffect, useRef, useState} from "react";
import {Fragment, memo, useEffect, useEffectEvent, useLayoutEffect, useRef, useState} from "react";
import { CollaborationCards } from "./collaboration-card";
import {ConversationReplyContext} from "./conversation-requests";
import { Activity, Bot, Sparkles } from "lucide-react";
Expand Down Expand Up @@ -55,7 +55,7 @@ function LinkedHistoryImage({name, source, ready, zh}: {name: string; source: st
onError={() => setImageRead(current => current?.source === source ? {source, failed: true} : current)}/>;
}

export function ChannelTimeline({
export const ChannelTimeline = memo(function ChannelTimeline({
emptyState,
readOnly = false,
items,
Expand Down Expand Up @@ -329,4 +329,4 @@ export function ChannelTimeline({
</div>
</>
);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../../../../../loopx/control_plane/presentation/action_review_plan.js";
import { refreshAttention } from "./attention-details";
import { teamPlanAssignments, teamPlanAppliedLine, teamPlanAppliedOutcome, teamPlanFields, teamPlanGoalId, teamPlanLaneCount, teamPlanReceiptGapLanes, teamPlanTodoIds } from "./team-plan-preview";
import { Suspense, lazy, useEffect, useLayoutEffect, useMemo, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type ReactNode } from "react";
import { Suspense, lazy, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ClipboardEvent as ReactClipboardEvent, type ReactNode } from "react";

import {
applyTypedAction,
Expand Down Expand Up @@ -1343,7 +1343,9 @@ export function PersonalWorkspacePage({
active: Boolean(runningMessage || selectedAgentModelReadback?.active_turn_id),
refreshKey: `${managerMessages.length}:${Boolean(managerMessages.at(-1)?.pending)}:${steering}`,
});
const queuedTurnKeys = new Set(conversationQueue.turns.map(turn => JSON.stringify([conversationSessionId, turn.turn_id])));
const queueTurns = conversationQueue.readReady ? conversationQueue.turns : undefined;
const queuedTurnKeys = useMemo(() => queueTurns && new Set(queueTurns.map(turn =>
JSON.stringify([conversationSessionId, turn.turn_id]))), [queueTurns, conversationSessionId]);
const observedQueue = useRef<{scope: string; snapshot: string} | null>(null);
useEffect(() => {
const turnId = conversationQueue.activeTurnId;
Expand Down Expand Up @@ -1407,8 +1409,62 @@ export function PersonalWorkspacePage({
|| managerChannelProposalIds.includes(item.proposal.previewId)))),
[items, managerSessionProposalIds, managerChannelProposalIds],
);
const boundManagerChat = Boolean(selectedWorkspaceRef || originalConversation);
const managerTimelineItems = useMemo(() => boundManagerChat
? managerChatItems.filter(item => item.kind === "message") : managerChatItems, [boundManagerChat, managerChatItems]);
const managedTimelineItems = useMemo(() => visibleTimelineItems.filter(item => item.kind === "message"), [visibleTimelineItems]);
const managerTimelineUnavailable = Boolean(originalConversation && (originalSourceUnresolved
|| (conversationHistoryState && conversationHistoryState.phase !== "ready")));
const managerTimelineTitle = managerTimelineUnavailable
? originalConversation?.error || conversationHistoryState?.phase === "unavailable" || conversationHistoryState?.phase === "partial"
? (locale === "zh-CN" ? "原会话暂不可用" : "Original conversation unavailable")
: (locale === "zh-CN" ? "正在读取原会话…" : "Reading the original conversation…")
: workspaceTitle;
const managerTimelineDescription = managerTimelineUnavailable ? "" : t("workspace.empty");
const managerTimelineEmpty = useMemo(() => managerTimelineTitle
? {title: managerTimelineTitle, description: managerTimelineDescription} : undefined,
[managerTimelineTitle, managerTimelineDescription]);
const timelineKey = `${selectionScope}:${conversationKey}:${selectedAgentId}`;

// Draft edits do not change history. A retained history action still calls
// the latest committed handler in its own conversation.
const currentTimelineActions = useRef<typeof nextTimelineActions>(null);
const timelineActionTarget = agentWorkActive ? conversationKey : selectedGoal?.goalId ?? conversationKey;
const canCancelTimelineTurn = !readOnly && Boolean(callbacks.onCancelConversationPreparation);
const canInterruptTimelineTurn = !readOnly && Boolean(callbacks.onInterruptConversationTurn);
const goalDraftTargetChanged = t("actionReview.targetChanged");
const nextTimelineActions = {
key: timelineKey,
select: setSelection,
review: readOnly ? undefined : reviewGoalDraft,
apply: readOnly ? undefined : confirmGoalDraft,
suggest: readOnly ? undefined : suggestReply,
adjust: focusTurnComposer,
cancel: canCancelTimelineTurn ? () => callbacks.onCancelConversationPreparation?.(timelineActionTarget) : undefined,
interrupt: canInterruptTimelineTurn ? (turnId: string) => callbacks.onInterruptConversationTurn?.(timelineActionTarget, turnId) : undefined,
openEvidence: (goalId: string) => { selectGoal(goalId, "chat"); },
};
useLayoutEffect(() => { currentTimelineActions.current = nextTimelineActions; });
const timelineActions = useMemo(() => {
const current = () => currentTimelineActions.current?.key === timelineKey ? currentTimelineActions.current : null;
return {
onSelect: (value: WorkspaceDrawerSelection) => current()?.select(value),
onReviewGoalDraft: async (...args: Parameters<typeof reviewGoalDraft>) => current()?.review?.(...args),
onApplyGoalDraft: async (proposal: WorkspaceActionPreview) => {
const apply = current()?.apply;
if (!apply) throw new Error(goalDraftTargetChanged);
return apply(proposal);
},
onSuggestReply: (text: string) => current()?.suggest?.(text),
onAdjustTurn: (turnId: string) => current()?.adjust(turnId),
onCancelPreparation: () => current()?.cancel?.(),
onInterruptTurn: async (turnId: string) => { await current()?.interrupt?.(turnId); },
onOpenGoalEvidence: (goalId: string) => current()?.openEvidence(goalId),
};
}, [timelineKey, goalDraftTargetChanged]);
const conversationOpen = (!agentWorkActive || managedWorkActive) && (selectedGoal ? selectedGoalTab === "chat" : managerChatOpen);
const boundHistory = Boolean(originalConversation);
const onReadTimelineMessage = useCallback(() => { followConversationRef.current = false; }, []);
const historyPositionScope = JSON.stringify([selectionScope, conversationKey, selectedAgentId,
conversationMessageFocus?.sessionId, conversationMessageFocus?.messageId]);
const [positionedHistoryScope, setPositionedHistoryScope] = useState<string | null>(null);
Expand All @@ -1418,7 +1474,7 @@ export function PersonalWorkspacePage({
historyPhase: conversationHistoryState?.phase,
historyPositionReady: !boundHistory || (conversationOpen && positionedHistoryScope === historyPositionScope),
onRetryHistory: conversationHistoryState?.retry,
onReadMessage: () => { followConversationRef.current = false; },
onReadMessage: onReadTimelineMessage,
};
const latestMessage = managerMessages.at(-1);
const latestMessageTextLength = latestMessage?.text.length ?? 0;
Expand Down Expand Up @@ -3044,10 +3100,10 @@ export function PersonalWorkspacePage({
sessionId={selectedWorkSessionId} onSession={(id, replace) => callbacks.onSelectWorkSession?.(id, replace)}
onSelect={id => callbacks.onSelectWorkAgent?.(id)} onClose={() => callbacks.onSelectWorkAgent?.(null)}>
{workspaceConversations?.managed?.error ? <p role="alert">{workspaceConversations.managed.error} <button type="button" onClick={workspaceConversations.managed.retry}>{t("history.retry")}</button></p> : null}
<ChannelTimeline key={`${selectionScope}:${conversationKey}:${selectedAgentId}`} {...timelineReading} readOnly={readOnly} items={visibleTimelineItems.filter(item => item.kind === "message")} onSelect={setSelection} selectedGoal={selectedGoal}
onAdjustTurn={steeringTurnId ? focusTurnComposer : undefined}
onCancelPreparation={!readOnly && callbacks.onCancelConversationPreparation ? () => callbacks.onCancelConversationPreparation!(conversationKey) : undefined}
onInterruptTurn={!readOnly && callbacks.onInterruptConversationTurn ? turnId => callbacks.onInterruptConversationTurn!(conversationKey, turnId) : undefined}/>
<ChannelTimeline key={timelineKey} {...timelineReading} readOnly={readOnly} items={managedTimelineItems} onSelect={timelineActions.onSelect} selectedGoal={selectedGoal}
onAdjustTurn={steeringTurnId ? timelineActions.onAdjustTurn : undefined}
onCancelPreparation={canCancelTimelineTurn ? timelineActions.onCancelPreparation : undefined}
onInterruptTurn={canInterruptTimelineTurn ? timelineActions.onInterruptTurn : undefined}/>
</GoalAgentWorkPage> : (<>
{selectedGoal && activeSessionRun?.goalId === selectedGoal.goalId ? (
<SessionRecordHeader
Expand All @@ -3056,13 +3112,15 @@ export function PersonalWorkspacePage({
run={activeSessionRun}
/>
) : null}
<ChannelTimeline key={`${selectionScope}:${conversationKey}:${selectedAgentId}`} {...timelineReading} readOnly={readOnly} goalDraftPreparationContext={`${goalAgentId}:${locale}`} onReviewGoalDraft={readOnly ? undefined : reviewGoalDraft} onApplyGoalDraft={readOnly ? undefined : confirmGoalDraft} onSuggestReply={readOnly ? undefined : suggestReply} items={visibleTimelineItems} onSelect={setSelection} selectedGoal={selectedGoal}
onAdjustTurn={steeringTurnId ? focusTurnComposer : undefined}
onCancelPreparation={!readOnly && callbacks.onCancelConversationPreparation
? () => callbacks.onCancelConversationPreparation!(selectedGoal.goalId) : undefined}
onInterruptTurn={!readOnly && callbacks.onInterruptConversationTurn
? (turnId) => callbacks.onInterruptConversationTurn!(selectedGoal.goalId, turnId)
: undefined} />
<ChannelTimeline key={timelineKey} {...timelineReading} readOnly={readOnly}
goalDraftPreparationContext={`${goalAgentId}:${locale}`}
onReviewGoalDraft={readOnly ? undefined : timelineActions.onReviewGoalDraft}
onApplyGoalDraft={readOnly ? undefined : timelineActions.onApplyGoalDraft}
onSuggestReply={readOnly ? undefined : timelineActions.onSuggestReply}
items={visibleTimelineItems} onSelect={timelineActions.onSelect} selectedGoal={selectedGoal}
onAdjustTurn={steeringTurnId ? timelineActions.onAdjustTurn : undefined}
onCancelPreparation={canCancelTimelineTurn ? timelineActions.onCancelPreparation : undefined}
onInterruptTurn={canInterruptTimelineTurn ? timelineActions.onInterruptTurn : undefined} />
</>),
}} />
</GoalWorkBrowseProvider>
Expand All @@ -3074,24 +3132,16 @@ export function PersonalWorkspacePage({
recheckingRuntimes={recheckingRuntimes} onRecheckRuntimes={callbacks.onRecheckRuntimes ? recheckRuntimes : undefined}
operations={actionReadback.isError ? [] : homeOperations} onSelectOperation={proposal => setSelection({kind: "proposal", item: proposal})} />
) : (
<ChannelTimeline key={`${selectionScope}:${conversationKey}:${selectedAgentId}`} {...timelineReading} readOnly={readOnly}
emptyState={originalConversation && (originalSourceUnresolved
|| (conversationHistoryState && conversationHistoryState.phase !== "ready")) ? {
title: originalConversation.error || conversationHistoryState?.phase === "unavailable" || conversationHistoryState?.phase === "partial"
? (locale === "zh-CN" ? "原会话暂不可用" : "Original conversation unavailable")
: (locale === "zh-CN" ? "正在读取原会话…" : "Reading the original conversation…"),
description: "",
} : workspaceTitle ? {title: workspaceTitle, description: t("workspace.empty")} : undefined}
goalDraftPreparationContext={`${goalAgentId}:${locale}`} onReviewGoalDraft={readOnly ? undefined : reviewGoalDraft} onApplyGoalDraft={readOnly ? undefined : confirmGoalDraft} onSuggestReply={readOnly ? undefined : suggestReply}
items={selectedWorkspaceRef || originalConversation ? managerChatItems.filter((item) => item.kind === "message") : managerChatItems}
onSelect={setSelection} selectedGoal={null} showManagerTeamResults={!selectedWorkspaceRef && !originalConversation}
onAdjustTurn={steeringTurnId ? focusTurnComposer : undefined}
onCancelPreparation={!readOnly && callbacks.onCancelConversationPreparation
? () => callbacks.onCancelConversationPreparation!(conversationKey) : undefined}
onInterruptTurn={!readOnly && callbacks.onInterruptConversationTurn
? (turnId) => callbacks.onInterruptConversationTurn!(conversationKey, turnId)
: undefined}
onOpenGoalEvidence={(goalId) => { selectGoal(goalId, "chat"); }} />
<ChannelTimeline key={timelineKey} {...timelineReading} readOnly={readOnly} emptyState={managerTimelineEmpty}
goalDraftPreparationContext={`${goalAgentId}:${locale}`}
onReviewGoalDraft={readOnly ? undefined : timelineActions.onReviewGoalDraft}
onApplyGoalDraft={readOnly ? undefined : timelineActions.onApplyGoalDraft}
onSuggestReply={readOnly ? undefined : timelineActions.onSuggestReply}
items={managerTimelineItems} onSelect={timelineActions.onSelect} selectedGoal={null} showManagerTeamResults={!boundManagerChat}
onAdjustTurn={steeringTurnId ? timelineActions.onAdjustTurn : undefined}
onCancelPreparation={canCancelTimelineTurn ? timelineActions.onCancelPreparation : undefined}
onInterruptTurn={canInterruptTimelineTurn ? timelineActions.onInterruptTurn : undefined}
onOpenGoalEvidence={timelineActions.onOpenGoalEvidence} />
))}
</> : null}
</div>
Expand Down
4 changes: 4 additions & 0 deletions examples/personal-workspace-browser/goal-draft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const goalDraftScenario = {
const requests = api.turnRequests.length;
await card.getByRole("button", {name: "资本支出变化", exact: true}).click();
assert.equal(await composer.inputValue(), "资本支出变化");
await composer.fill("保留现金流的判断。");
await card.getByRole("button", {name: "资本支出变化", exact: true}).click();
assert.equal(await composer.inputValue(), "保留现金流的判断。\n资本支出变化",
"An existing suggestion appends to the current draft");
assert.equal(api.turnRequests.length, requests, "Suggestion auto-sent a request");
assert.equal(api.actionPreviews.length, 0);
assert.equal(api.durableWriteCount, writes);
Expand Down
Loading