2025-09-21 12:03:29 +01:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
import type { getWeather } from './ai/tools/get-weather';
|
|
|
|
|
import type { createDocument } from './ai/tools/create-document';
|
|
|
|
|
import type { updateDocument } from './ai/tools/update-document';
|
|
|
|
|
import type { requestSuggestions } from './ai/tools/request-suggestions';
|
|
|
|
|
import type { InferUITool, UIMessage } from 'ai';
|
|
|
|
|
import type { AppUsage } from './usage';
|
|
|
|
|
|
|
|
|
|
import type { ArtifactKind } from '@/components/artifact';
|
|
|
|
|
import type { Suggestion } from './db/schema';
|
|
|
|
|
|
|
|
|
|
export type DataPart = { type: 'append-message'; message: string };
|
2025-07-03 02:26:34 -07:00
|
|
|
|
|
|
|
|
export const messageMetadataSchema = z.object({
|
|
|
|
|
createdAt: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export type MessageMetadata = z.infer<typeof messageMetadataSchema>;
|
|
|
|
|
|
|
|
|
|
type weatherTool = InferUITool<typeof getWeather>;
|
|
|
|
|
type createDocumentTool = InferUITool<ReturnType<typeof createDocument>>;
|
|
|
|
|
type updateDocumentTool = InferUITool<ReturnType<typeof updateDocument>>;
|
|
|
|
|
type requestSuggestionsTool = InferUITool<
|
|
|
|
|
ReturnType<typeof requestSuggestions>
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
export type ChatTools = {
|
|
|
|
|
getWeather: weatherTool;
|
|
|
|
|
createDocument: createDocumentTool;
|
|
|
|
|
updateDocument: updateDocumentTool;
|
|
|
|
|
requestSuggestions: requestSuggestionsTool;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type CustomUIDataTypes = {
|
|
|
|
|
textDelta: string;
|
|
|
|
|
imageDelta: string;
|
|
|
|
|
sheetDelta: string;
|
|
|
|
|
codeDelta: string;
|
|
|
|
|
suggestion: Suggestion;
|
|
|
|
|
appendMessage: string;
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
|
|
|
|
kind: ArtifactKind;
|
|
|
|
|
clear: null;
|
|
|
|
|
finish: null;
|
2025-09-15 11:32:28 +02:00
|
|
|
usage: AppUsage;
|
2025-07-03 02:26:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type ChatMessage = UIMessage<
|
|
|
|
|
MessageMetadata,
|
|
|
|
|
CustomUIDataTypes,
|
|
|
|
|
ChatTools
|
|
|
|
|
>;
|
|
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
export interface Attachment {
|
2025-07-03 02:26:34 -07:00
|
|
|
name: string;
|
|
|
|
|
url: string;
|
|
|
|
|
contentType: string;
|
2025-09-21 12:03:29 +01:00
|
|
|
}
|