Skip to content

Commit

Permalink
Merge branch 'vercel:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
athrael-soju authored Nov 19, 2024
2 parents 75dd3b4 + fdd0ace commit 552d3b5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
11 changes: 4 additions & 7 deletions app/(chat)/api/files/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ const FileSchema = z.object({
.refine((file) => file.size <= 5 * 1024 * 1024, {
message: 'File size should be less than 5MB',
})
.refine(
(file) =>
['image/jpeg', 'image/png', 'application/pdf'].includes(file.type),
{
message: 'File type should be JPEG, PNG, or PDF',
},
),
// Update the file type based on the kind of files you want to accept
.refine((file) => ['image/jpeg', 'image/png'].includes(file.type), {
message: 'File type should be JPEG or PNG',
}),
});

export async function POST(request: Request) {
Expand Down
1 change: 0 additions & 1 deletion app/(chat)/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { cookies } from 'next/headers';
import { notFound } from 'next/navigation';

Expand Down
52 changes: 40 additions & 12 deletions components/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -26,7 +31,6 @@ interface DocumentToolResultProps {
export function DocumentToolResult({
type,
result,
block,
setBlock,
}: DocumentToolResultProps) {
return (
Expand Down Expand Up @@ -62,8 +66,8 @@ export function DocumentToolResult({
<MessageIcon />
) : null}
</div>
<div className="">
{getActionText(type)} {result.title}
<div className="text-left">
{`${getActionText(type, 'past')} "${result.title}"`}
</div>
</button>
);
Expand All @@ -72,11 +76,35 @@ export function DocumentToolResult({
interface DocumentToolCallProps {
type: 'create' | 'update' | 'request-suggestions';
args: { title: string };
setBlock: (value: SetStateAction<UIBlock>) => void;
}

export function DocumentToolCall({ type, args }: DocumentToolCallProps) {
export function DocumentToolCall({
type,
args,
setBlock,
}: DocumentToolCallProps) {
return (
<div className="w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3">
<button
type="button"
className="cursor pointer w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3"
onClick={(event) => {
const rect = event.currentTarget.getBoundingClientRect();

const boundingBox = {
top: rect.top,
left: rect.left,
width: rect.width,
height: rect.height,
};

setBlock((currentBlock) => ({
...currentBlock,
isVisible: true,
boundingBox,
}));
}}
>
<div className="flex flex-row gap-3 items-start">
<div className="text-zinc-500 mt-1">
{type === 'create' ? (
Expand All @@ -88,12 +116,12 @@ export function DocumentToolCall({ type, args }: DocumentToolCallProps) {
) : null}
</div>

<div className="">
{getActionText(type)} {args.title}
<div className="text-left">
{`${getActionText(type, 'present')} ${args.title ? `"${args.title}"` : ''}`}
</div>
</div>

<div className="animate-spin mt-1">{<LoaderIcon />}</div>
</div>
</button>
);
}
13 changes: 11 additions & 2 deletions components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ export const PreviewMessage = ({
{toolName === 'getWeather' ? (
<Weather />
) : toolName === 'createDocument' ? (
<DocumentToolCall type="create" args={args} />
<DocumentToolCall
type="create"
args={args}
setBlock={setBlock}
/>
) : toolName === 'updateDocument' ? (
<DocumentToolCall type="update" args={args} />
<DocumentToolCall
type="update"
args={args}
setBlock={setBlock}
/>
) : toolName === 'requestSuggestions' ? (
<DocumentToolCall
type="request-suggestions"
args={args}
setBlock={setBlock}
/>
) : null}
</div>
Expand Down

0 comments on commit 552d3b5

Please sign in to comment.