From 9dcdb7b50ba1e221f2b77ffab3fb78f7ac011526 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 19 Nov 2024 15:46:09 +0300 Subject: [PATCH] Make document call component clickable (#558) --- app/(chat)/chat/[id]/page.tsx | 1 - components/document.tsx | 52 +++++++++++++++++++++++++++-------- components/message.tsx | 13 +++++++-- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/app/(chat)/chat/[id]/page.tsx b/app/(chat)/chat/[id]/page.tsx index 5d5b062..acf5da3 100644 --- a/app/(chat)/chat/[id]/page.tsx +++ b/app/(chat)/chat/[id]/page.tsx @@ -1,4 +1,3 @@ - import { cookies } from 'next/headers'; import { notFound } from 'next/navigation'; diff --git a/components/document.tsx b/components/document.tsx index bb415d9..4c7eb2e 100644 --- a/components/document.tsx +++ b/components/document.tsx @@ -3,14 +3,19 @@ import type { SetStateAction } from 'react'; import type { UIBlock } from './block'; import { FileIcon, LoaderIcon, MessageIcon, PencilEditIcon } from './icons'; -const getActionText = (type: 'create' | 'update' | 'request-suggestions') => { +const getActionText = ( + type: 'create' | 'update' | 'request-suggestions', + tense: 'present' | 'past', +) => { switch (type) { case 'create': - return 'Creating'; + return tense === 'present' ? 'Creating' : 'Created'; case 'update': - return 'Updating'; + return tense === 'present' ? 'Updating' : 'Updated'; case 'request-suggestions': - return 'Adding suggestions'; + return tense === 'present' + ? 'Adding suggestions' + : 'Added suggestions to'; default: return null; } @@ -26,7 +31,6 @@ interface DocumentToolResultProps { export function DocumentToolResult({ type, result, - block, setBlock, }: DocumentToolResultProps) { return ( @@ -62,8 +66,8 @@ export function DocumentToolResult({ ) : null} -
- {getActionText(type)} {result.title} +
+ {`${getActionText(type, 'past')} "${result.title}"`}
); @@ -72,11 +76,35 @@ export function DocumentToolResult({ interface DocumentToolCallProps { type: 'create' | 'update' | 'request-suggestions'; args: { title: string }; + setBlock: (value: SetStateAction) => void; } -export function DocumentToolCall({ type, args }: DocumentToolCallProps) { +export function DocumentToolCall({ + type, + args, + setBlock, +}: DocumentToolCallProps) { return ( -
+ ); } diff --git a/components/message.tsx b/components/message.tsx index 6340fca..cbbf2d2 100644 --- a/components/message.tsx +++ b/components/message.tsx @@ -104,13 +104,22 @@ export const PreviewMessage = ({ {toolName === 'getWeather' ? ( ) : toolName === 'createDocument' ? ( - + ) : toolName === 'updateDocument' ? ( - + ) : toolName === 'requestSuggestions' ? ( ) : null}