Preserve partial creation replies on stream failure
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
149
src/components/square-hole-creation/SquareHoleAgentWorkspace.tsx
Normal file
149
src/components/square-hole-creation/SquareHoleAgentWorkspace.tsx
Normal file
@@ -0,0 +1,149 @@
|
||||
import type {
|
||||
ExecuteSquareHoleActionRequest,
|
||||
SendSquareHoleMessageRequest,
|
||||
SquareHoleAnchorItemResponse,
|
||||
SquareHoleSessionSnapshot,
|
||||
} from '../../../packages/shared/src/contracts/squareHoleAgent';
|
||||
import {
|
||||
buildCreationAgentChatMessage,
|
||||
createCreationAgentChatQuickActions,
|
||||
createCreationAgentClientMessageId,
|
||||
resolveCreationAgentQuickActionMessage,
|
||||
} from '../../services/creation-agent';
|
||||
import {
|
||||
type CreationAgentAnchorView,
|
||||
type CreationAgentSessionView,
|
||||
type CreationAgentTheme,
|
||||
CreationAgentWorkspace,
|
||||
} from '../creation-agent';
|
||||
|
||||
type SquareHoleAgentWorkspaceProps = {
|
||||
session: SquareHoleSessionSnapshot | null;
|
||||
streamingReplyText?: string;
|
||||
isStreamingReply?: boolean;
|
||||
isBusy?: boolean;
|
||||
error?: string | null;
|
||||
onBack: () => void;
|
||||
onSubmitMessage: (payload: SendSquareHoleMessageRequest) => void;
|
||||
onExecuteAction: (payload: ExecuteSquareHoleActionRequest) => void;
|
||||
};
|
||||
|
||||
const SQUARE_HOLE_AGENT_THEME: CreationAgentTheme = {
|
||||
accentTextClass: 'text-sky-100/86',
|
||||
accentBgClass: 'bg-cyan-200',
|
||||
accentButtonClass: 'bg-cyan-200 shadow-slate-950/20',
|
||||
userBubbleClass: 'bg-slate-950 text-white',
|
||||
heroClass:
|
||||
'border border-cyan-100/18 bg-[radial-gradient(circle_at_top_left,rgba(125,211,252,0.28),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(248,113,113,0.2),transparent_32%),linear-gradient(135deg,rgba(15,23,42,0.96),rgba(20,83,45,0.92))]',
|
||||
anchorGridClass: 'grid gap-2 sm:grid-cols-4',
|
||||
};
|
||||
|
||||
const SQUARE_HOLE_QUICK_ACTIONS = [
|
||||
...createCreationAgentChatQuickActions(),
|
||||
{
|
||||
key: 'square-hole-auto-config',
|
||||
label: '自动配置',
|
||||
},
|
||||
];
|
||||
|
||||
function mapSquareHoleAnchor(
|
||||
anchor: SquareHoleAnchorItemResponse,
|
||||
): CreationAgentAnchorView {
|
||||
return {
|
||||
key: anchor.key,
|
||||
label: anchor.label,
|
||||
value: anchor.value,
|
||||
status: anchor.status,
|
||||
};
|
||||
}
|
||||
|
||||
function mapSquareHoleSession(
|
||||
session: SquareHoleSessionSnapshot,
|
||||
): CreationAgentSessionView {
|
||||
// 中文注释:方洞工作台只展示共创对话和四个创作锚点,正式运行规则由后端运行态快照裁决。
|
||||
const chatMessages = session.messages.filter(
|
||||
(message) =>
|
||||
message.kind === 'chat' ||
|
||||
message.kind === 'summary' ||
|
||||
message.kind === 'warning',
|
||||
);
|
||||
|
||||
return {
|
||||
sessionId: session.sessionId,
|
||||
title: null,
|
||||
assistantSummary: null,
|
||||
currentTurn: session.currentTurn,
|
||||
progressPercent: session.progressPercent,
|
||||
anchors: [
|
||||
session.anchorPack.theme,
|
||||
session.anchorPack.twistRule,
|
||||
session.anchorPack.shapeCount,
|
||||
session.anchorPack.difficulty,
|
||||
].map(mapSquareHoleAnchor),
|
||||
messages: chatMessages,
|
||||
recommendedReplies: [],
|
||||
};
|
||||
}
|
||||
|
||||
function buildSquareHoleChatPayload({
|
||||
text,
|
||||
quickFillRequested = false,
|
||||
}: {
|
||||
text: string;
|
||||
quickFillRequested?: boolean;
|
||||
}) {
|
||||
return buildCreationAgentChatMessage({
|
||||
clientMessageId: createCreationAgentClientMessageId('square-hole'),
|
||||
text,
|
||||
quickFillRequested,
|
||||
});
|
||||
}
|
||||
|
||||
export function SquareHoleAgentWorkspace({
|
||||
session,
|
||||
streamingReplyText = '',
|
||||
isStreamingReply = false,
|
||||
isBusy = false,
|
||||
error = null,
|
||||
onBack,
|
||||
onSubmitMessage,
|
||||
onExecuteAction,
|
||||
}: SquareHoleAgentWorkspaceProps) {
|
||||
return (
|
||||
<CreationAgentWorkspace
|
||||
session={session ? mapSquareHoleSession(session) : null}
|
||||
theme={SQUARE_HOLE_AGENT_THEME}
|
||||
loadingText="正在准备方洞挑战共创工作区..."
|
||||
composerPlaceholder="题材、反差规则、形状数量、难度..."
|
||||
primaryActionLabel="生成结果页"
|
||||
streamingReplyText={streamingReplyText}
|
||||
isStreamingReply={isStreamingReply}
|
||||
isBusy={isBusy}
|
||||
error={error}
|
||||
quickActions={SQUARE_HOLE_QUICK_ACTIONS}
|
||||
onBack={onBack}
|
||||
onSubmitText={(text) => {
|
||||
onSubmitMessage(buildSquareHoleChatPayload({ text }));
|
||||
}}
|
||||
onPrimaryAction={() => {
|
||||
onExecuteAction({ action: 'square_hole_compile_draft' });
|
||||
}}
|
||||
onQuickAction={(action) => {
|
||||
const quickActionMessage =
|
||||
action.key === 'square-hole-auto-config'
|
||||
? {
|
||||
text: '自动配置',
|
||||
quickFillRequested: true,
|
||||
}
|
||||
: resolveCreationAgentQuickActionMessage(
|
||||
action.key,
|
||||
'请总结一下当前方洞挑战设定。',
|
||||
);
|
||||
|
||||
onSubmitMessage(buildSquareHoleChatPayload(quickActionMessage));
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default SquareHoleAgentWorkspace;
|
||||
1
src/components/square-hole-creation/index.ts
Normal file
1
src/components/square-hole-creation/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { SquareHoleAgentWorkspace } from './SquareHoleAgentWorkspace';
|
||||
Reference in New Issue
Block a user