Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/components/DebugPromptView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ function getMessageCharCount(message: CoreMessage): number {
if (isTextPart(part)) return sum + part.text.length;
if (isFilePart(part) && typeof part.data === 'string') return sum + part.data.length;
if (isToolCallPart(part)) {
return sum + part.toolName.length + part.toolCallId.length + JSON.stringify(part.args).length;
// AI SDK 5: args renamed to input
return sum + part.toolName.length + part.toolCallId.length + JSON.stringify(part.input).length;
}
if (part.type === 'tool-result') {
return sum + part.toolName.length + part.toolCallId.length + JSON.stringify(part.result).length;
// AI SDK 5: result renamed to output
return sum + part.toolName.length + part.toolCallId.length + JSON.stringify(part.output).length;
}
return sum;
}, 0);
Expand Down Expand Up @@ -320,7 +322,7 @@ function MessageContentView({ content, showRawJson = false }: MessageContentView
const fileData = typeof part.data === 'string' ? part.data : '[Binary Data]';
return (
<div key={idx} className="rounded bg-purple-50 p-2 dark:bg-purple-900/10">
<div className="text-xs font-medium text-purple-500">file: {part.filename || part.mimeType}</div>
<div className="text-xs font-medium text-purple-500">file: {part.filename || part.mediaType}</div>
<div className="whitespace-pre-wrap font-mono text-sm">{fileData}</div>
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion app/components/ExistingChat.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useReloadMessages } from '~/lib/stores/startup/reloadMessages';
import { useSplines } from '~/lib/splines';
import { UserProvider } from '~/components/UserProvider';
import { Toaster } from '~/components/ui/Toaster';
import { isToolUIPart, getToolName } from 'ai';

export function ExistingChat({ chatId }: { chatId: string }) {
// Fill in the chatID store from props early in app initialization. If this
Expand Down Expand Up @@ -74,7 +75,9 @@ function ExistingChatWrapper({ chatId }: { chatId: string }) {
const hadSuccessfulDeploy = initialMessages?.some(
(message) =>
message.role === 'assistant' &&
message.parts?.some((part) => part.type === 'tool-invocation' && part.toolInvocation.toolName === 'deploy'),
// In AI SDK 5, tool parts are identified via isToolUIPart helper
// toolName is accessed via getToolName() helper
message.parts?.some((part) => isToolUIPart(part) && getToolName(part) === 'deploy'),
);

if (initialMessages === null) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/Homepage.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRef } from 'react';
import { useConvexChatHomepage } from '~/lib/stores/startup';
import { Toaster } from '~/components/ui/Toaster';
import { setPageLoadChatId } from '~/lib/stores/chatId';
import type { Message } from '@ai-sdk/react';
import type { UIMessage } from 'ai';
import type { PartCache } from '~/lib/hooks/useMessageParser';
import { UserProvider } from '~/components/UserProvider';

Expand Down Expand Up @@ -43,4 +43,4 @@ const ChatWrapper = ({ initialId }: { initialId: string }) => {
);
};

const emptyList: Message[] = [];
const emptyList: UIMessage[] = [];
34 changes: 25 additions & 9 deletions app/components/chat/AssistantMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { memo, useMemo } from 'react';
import { Markdown } from './Markdown';
import type { Message } from 'ai';
import type { UIMessage } from 'ai';
import { isToolUIPart } from 'ai';

// Helper to extract text content from UIMessage parts
function getMessageContent(message: UIMessage): string {
if (!message.parts) {
return '';
}
return message.parts
.filter((p): p is { type: 'text'; text: string } => p.type === 'text')
.map((p) => p.text)
.join('');
}
import { ToolCall } from './ToolCall';
import { makePartId, type PartId } from 'chef-agent/partId.js';
import { ExclamationTriangleIcon, DotFilledIcon } from '@radix-ui/react-icons';
Expand All @@ -10,16 +22,19 @@ import { calculateChefTokens, usageFromGeneration, type ChefTokenBreakdown } fro
import { captureMessage } from '@sentry/remix';

interface AssistantMessageProps {
message: Message;
message: UIMessage;
}

export const AssistantMessage = memo(function AssistantMessage({ message }: AssistantMessageProps) {
const { showUsageAnnotations } = useLaunchDarkly();
const parsedAnnotations = useMemo(() => parseAnnotations(message.annotations), [message.annotations]);
// TODO: In AI SDK 5, annotations are handled differently - they're now in message.metadata
// or sent as custom data parts. For now, access via any cast for backwards compatibility.
const messageAny = message as any;
const parsedAnnotations = useMemo(() => parseAnnotations(messageAny.annotations ?? []), [messageAny.annotations]);
if (!message.parts) {
return (
<div className="w-full overflow-hidden">
<Markdown html>{message.content}</Markdown>
<Markdown html>{getMessageContent(message)}</Markdown>
</div>
);
}
Expand Down Expand Up @@ -64,22 +79,23 @@ function AssistantMessagePart({
partId,
parsedAnnotations,
}: {
part: NonNullable<Message['parts']>[number];
part: NonNullable<UIMessage['parts']>[number];
showUsageAnnotations: boolean;
partId: PartId;
parsedAnnotations: ReturnType<typeof parseAnnotations>;
}) {
if (part.type === 'tool-invocation') {
// In AI SDK 5, tool parts have type `tool-${toolName}` and properties directly on the part
if (isToolUIPart(part)) {
return (
<>
{showUsageAnnotations &&
displayModelAndUsage({
model: parsedAnnotations.modelForToolCall[part.toolInvocation.toolCallId],
usageAnnotation: parsedAnnotations.usageForToolCall[part.toolInvocation.toolCallId] ?? undefined,
model: parsedAnnotations.modelForToolCall[part.toolCallId],
usageAnnotation: parsedAnnotations.usageForToolCall[part.toolCallId] ?? undefined,
showUsageAnnotations,
})}

<ToolCall partId={partId} toolCallId={part.toolInvocation.toolCallId} />
<ToolCall partId={partId} toolCallId={part.toolCallId} />
</>
);
}
Expand Down
7 changes: 4 additions & 3 deletions app/components/chat/BaseChat.client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Sheet } from '@ui/Sheet';
import type { Message } from 'ai';
import type { UIMessage } from 'ai';
import { getTextFromParts } from '~/lib/common/messageHelpers';
import React, { type ReactNode, type RefCallback, useCallback, useEffect, useMemo, useState } from 'react';
import Landing from '~/components/landing/Landing';
import { Workbench } from '~/components/workbench/Workbench.client';
Expand Down Expand Up @@ -48,7 +49,7 @@ interface BaseChatProps {
streamStatus: 'streaming' | 'submitted' | 'ready' | 'error';
currentError: Error | undefined;
toolStatus: ToolStatus;
messages: Message[];
messages: UIMessage[];
terminalInitializationOptions: TerminalInitializationOptions | undefined;
disableChatMessage: ReactNode | string | null;

Expand Down Expand Up @@ -134,7 +135,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
const lastUserMessage = messages.findLast((message) => message.role === 'user');
const resendMessage = useCallback(async () => {
if (lastUserMessage) {
await onSend?.(lastUserMessage.content);
await onSend?.(getTextFromParts(lastUserMessage));
}
}, [lastUserMessage, onSend]);
const baseChat = (
Expand Down
Loading
Loading