import { Bell, Bookmark, ChevronRight, Gamepad2, Menu, MessageCircle, Moon, Music, PanelLeftClose, Settings, Sparkles, UserRound, } from 'lucide-react'; import { useMemo, useState } from 'react'; import type { CreativeAgentInputPart } from '../../../packages/shared/src/contracts/creativeAgent'; import type { CreationWorkShelfItem } from '../custom-world-home/creationWorkShelf'; import { RpgEntryBrandLogo } from '../rpg-entry/RpgEntryBrandLogo'; import { CreativeAgentInputComposer } from './CreativeAgentInputComposer'; import { createCreativeAgentClientMessageId } from './creativeAgentViewModel'; type CreativeAgentHomePrompt = { id: string; label: string; prompt: string; icon: typeof Sparkles; tone: 'cool' | 'green' | 'warm' | 'purple' | 'rose'; badge?: string; }; export type CreativeAgentHistoryItem = { id: string; title: string; groupLabel: string; source: CreationWorkShelfItem; }; type CreativeAgentHomeProps = { recentItems: CreativeAgentHistoryItem[]; isBusy: boolean; error: string | null; onStartNewChat: () => void; onOpenHistoryItem: (item: CreationWorkShelfItem) => void; onOpenDrafts: () => void; onOpenAccount: () => void; onOpenSettings: () => void; onSubmitMessage: (payload: { clientMessageId: string; content: CreativeAgentInputPart[]; }) => void; }; const PROMPT_SUGGESTIONS: CreativeAgentHomePrompt[] = [ { id: 'identity', label: '你是谁', prompt: '介绍一下你能帮我创作什么。', icon: Sparkles, tone: 'cool', }, { id: 'flash-app', label: '一句话生成闪应用', prompt: '帮我把一个灵感做成可互动的小应用。', icon: Moon, tone: 'green', }, { id: 'mini-game', label: '捏个小游戏', prompt: '帮我做一个适合马上玩的创意小游戏。', icon: Gamepad2, tone: 'warm', }, { id: 'world-model', label: '体验世界模型', prompt: '用一个世界设定帮我生成可体验的互动内容。', icon: Bookmark, tone: 'purple', badge: 'Beta', }, { id: 'music', label: '音乐扭蛋', prompt: '把一段音乐灵感做成互动拼图。', icon: Music, tone: 'rose', }, ]; function buildCreativeHomeInputParts(payload: { text: string; image: { imageUrl: string; thumbnailUrl: string } | null; }): CreativeAgentInputPart[] { const content: CreativeAgentInputPart[] = []; if (payload.text) { content.push({ type: 'input_text', text: payload.text, }); } if (payload.image) { content.push({ type: 'input_image', imageUrl: payload.image.imageUrl, thumbnailUrl: payload.image.thumbnailUrl, assetId: null, }); } return content; } function groupRecentItemsByLabel(items: CreativeAgentHistoryItem[]) { const groups: Array<{ label: string; items: CreativeAgentHistoryItem[] }> = []; for (const item of items) { const lastGroup = groups[groups.length - 1]; if (lastGroup?.label === item.groupLabel) { lastGroup.items.push(item); continue; } groups.push({ label: item.groupLabel, items: [item], }); } return groups; } function CreativeAgentPromptButton({ item, disabled, onClick, }: { item: CreativeAgentHomePrompt; disabled: boolean; onClick: () => void; }) { const Icon = item.icon; return ( ); } function CreativeAgentDrawer({ open, recentItems, onClose, onStartNewChat, onOpenHistoryItem, onOpenDrafts, onOpenAccount, onOpenSettings, }: { open: boolean; recentItems: CreativeAgentHistoryItem[]; onClose: () => void; onStartNewChat: () => void; onOpenHistoryItem: (item: CreationWorkShelfItem) => void; onOpenDrafts: () => void; onOpenAccount: () => void; onOpenSettings: () => void; }) { const groupedItems = useMemo( () => groupRecentItemsByLabel(recentItems), [recentItems], ); return ( <>
); } export function CreativeAgentHome({ recentItems, isBusy, error, onStartNewChat, onOpenHistoryItem, onOpenDrafts, onOpenAccount, onOpenSettings, onSubmitMessage, }: CreativeAgentHomeProps) { const [drawerOpen, setDrawerOpen] = useState(false); const submitText = (text: string) => { const trimmedText = text.trim(); if (!trimmedText || isBusy) { return; } onSubmitMessage({ clientMessageId: createCreativeAgentClientMessageId(), content: [ { type: 'input_text', text: trimmedText, }, ], }); }; return (

Hi, 朋友

让复杂,变简单

{PROMPT_SUGGESTIONS.map((item) => ( submitText(item.prompt)} /> ))}
{error ? (
{error}
) : null}
{ const content = buildCreativeHomeInputParts(payload); if (content.length === 0) { return; } onSubmitMessage({ clientMessageId: createCreativeAgentClientMessageId(), content, }); }} />
setDrawerOpen(false)} onStartNewChat={onStartNewChat} onOpenHistoryItem={onOpenHistoryItem} onOpenDrafts={onOpenDrafts} onOpenAccount={onOpenAccount} onOpenSettings={onOpenSettings} />
); } export default CreativeAgentHome;