chore: update to ai sdk v5 beta (#1074)
This commit is contained in:
parent
7d8e71383f
commit
4c281fe09d
54 changed files with 1372 additions and 1060 deletions
|
|
@ -1,46 +1,51 @@
|
|||
import { generateUUID } from '@/lib/utils';
|
||||
import { DataStreamWriter, tool } from 'ai';
|
||||
import { tool, type UIMessageStreamWriter } from 'ai';
|
||||
import { z } from 'zod';
|
||||
import { Session } from 'next-auth';
|
||||
import type { Session } from 'next-auth';
|
||||
import {
|
||||
artifactKinds,
|
||||
documentHandlersByArtifactKind,
|
||||
} from '@/lib/artifacts/server';
|
||||
import type { ChatMessage } from '@/lib/types';
|
||||
|
||||
interface CreateDocumentProps {
|
||||
session: Session;
|
||||
dataStream: DataStreamWriter;
|
||||
dataStream: UIMessageStreamWriter<ChatMessage>;
|
||||
}
|
||||
|
||||
export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
|
||||
tool({
|
||||
description:
|
||||
'Create a document for a writing or content creation activities. This tool will call other functions that will generate the contents of the document based on the title and kind.',
|
||||
parameters: z.object({
|
||||
inputSchema: z.object({
|
||||
title: z.string(),
|
||||
kind: z.enum(artifactKinds),
|
||||
}),
|
||||
execute: async ({ title, kind }) => {
|
||||
const id = generateUUID();
|
||||
|
||||
dataStream.writeData({
|
||||
type: 'kind',
|
||||
content: kind,
|
||||
dataStream.write({
|
||||
type: 'data-kind',
|
||||
data: kind,
|
||||
transient: true,
|
||||
});
|
||||
|
||||
dataStream.writeData({
|
||||
type: 'id',
|
||||
content: id,
|
||||
dataStream.write({
|
||||
type: 'data-id',
|
||||
data: id,
|
||||
transient: true,
|
||||
});
|
||||
|
||||
dataStream.writeData({
|
||||
type: 'title',
|
||||
content: title,
|
||||
dataStream.write({
|
||||
type: 'data-title',
|
||||
data: title,
|
||||
transient: true,
|
||||
});
|
||||
|
||||
dataStream.writeData({
|
||||
type: 'clear',
|
||||
content: '',
|
||||
dataStream.write({
|
||||
type: 'data-clear',
|
||||
data: null,
|
||||
transient: true,
|
||||
});
|
||||
|
||||
const documentHandler = documentHandlersByArtifactKind.find(
|
||||
|
|
@ -59,7 +64,7 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
|
|||
session,
|
||||
});
|
||||
|
||||
dataStream.writeData({ type: 'finish', content: '' });
|
||||
dataStream.write({ type: 'data-finish', data: null, transient: true });
|
||||
|
||||
return {
|
||||
id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue