import { useMemo, useState } from 'react' import Markdown from 'react-markdown' import { AgentIcon } from '../../../shared/icons/AgentIcon' import { ChevronDownIcon } from '../../../shared/icons/ChevronDownIcon' import { ChevronRightIcon } from '../../../shared/icons/ChevronRightIcon' import { AgentAction } from '../../../shared/types/AgentAction' import { ChatHistoryActionItem } from '../../../shared/types/ChatHistoryItem' import { Streaming } from '../../../shared/types/Streaming' import { useAgent } from '../../agent/TldrawAgentAppProvider' import { ChatHistoryGroup } from './ChatHistoryGroup' import { getActionInfo } from './getActionInfo' export function ChatHistoryGroupWithoutDiff({ group }: { group: ChatHistoryGroup }) { const agent = useAgent() const { items } = group const nonEmptyItems = useMemo(() => { return items.filter((item) => { const { description } = getActionInfo(item.action, agent) return description !== null }) }, [items, agent]) const [collapsed, setCollapsed] = useState(true) const complete = useMemo(() => { return items.every((item) => item.action.complete) }, [items]) const summary = useMemo(() => { const time = Math.floor(items.reduce((acc, item) => acc + item.action.time, 0) / 1000) if (time === 0) return 'Thought for less than a second' if (time === 1) return 'Thought for 1 second' return `Thought for ${time} seconds` }, [items]) if (nonEmptyItems.length === 0) { return null } if (nonEmptyItems.length < 2) { return (
{nonEmptyItems.map((item, i) => { return })}
) } const showContent = !collapsed || !complete return (
{complete && ( )} {showContent && (
{nonEmptyItems.map((item, i) => { return })}
)}
) } function ChatHistoryItem({ item }: { item: ChatHistoryActionItem }) { const agent = useAgent() const { action } = item const { description, summary } = getActionInfo(action, agent) const collapsible = summary !== null const [collapsed, setCollapsed] = useState(collapsible) if (!description) return null return (
{action.complete && collapsible && ( )} {(!collapsed || !action.complete) && }
) } function ChatHistoryItemExpanded({ action }: { action: Streaming }) { const agent = useAgent() const { icon, description } = getActionInfo(action, agent) return (
{icon && ( )} {description}
) }