Revert "Upgrade linter and formatter to Ultracite" (#1226)
This commit is contained in:
parent
0e320b391d
commit
1aff7d9868
177 changed files with 8334 additions and 6943 deletions
|
|
@ -1,68 +1,67 @@
|
|||
import { streamObject, tool, type UIMessageStreamWriter } from "ai";
|
||||
import type { Session } from "next-auth";
|
||||
import { z } from "zod";
|
||||
import { getDocumentById, saveSuggestions } from "@/lib/db/queries";
|
||||
import type { Suggestion } from "@/lib/db/schema";
|
||||
import type { ChatMessage } from "@/lib/types";
|
||||
import { generateUUID } from "@/lib/utils";
|
||||
import { myProvider } from "../providers";
|
||||
import { z } from 'zod';
|
||||
import type { Session } from 'next-auth';
|
||||
import { streamObject, tool, type UIMessageStreamWriter } from 'ai';
|
||||
import { getDocumentById, saveSuggestions } from '@/lib/db/queries';
|
||||
import type { Suggestion } from '@/lib/db/schema';
|
||||
import { generateUUID } from '@/lib/utils';
|
||||
import { myProvider } from '../providers';
|
||||
import type { ChatMessage } from '@/lib/types';
|
||||
|
||||
type RequestSuggestionsProps = {
|
||||
interface RequestSuggestionsProps {
|
||||
session: Session;
|
||||
dataStream: UIMessageStreamWriter<ChatMessage>;
|
||||
};
|
||||
}
|
||||
|
||||
export const requestSuggestions = ({
|
||||
session,
|
||||
dataStream,
|
||||
}: RequestSuggestionsProps) =>
|
||||
tool({
|
||||
description: "Request suggestions for a document",
|
||||
description: 'Request suggestions for a document',
|
||||
inputSchema: z.object({
|
||||
documentId: z
|
||||
.string()
|
||||
.describe("The ID of the document to request edits"),
|
||||
.describe('The ID of the document to request edits'),
|
||||
}),
|
||||
execute: async ({ documentId }) => {
|
||||
const document = await getDocumentById({ id: documentId });
|
||||
|
||||
if (!document || !document.content) {
|
||||
return {
|
||||
error: "Document not found",
|
||||
error: 'Document not found',
|
||||
};
|
||||
}
|
||||
|
||||
const suggestions: Omit<
|
||||
Suggestion,
|
||||
"userId" | "createdAt" | "documentCreatedAt"
|
||||
>[] = [];
|
||||
const suggestions: Array<
|
||||
Omit<Suggestion, 'userId' | 'createdAt' | 'documentCreatedAt'>
|
||||
> = [];
|
||||
|
||||
const { elementStream } = streamObject({
|
||||
model: myProvider.languageModel("artifact-model"),
|
||||
model: myProvider.languageModel('artifact-model'),
|
||||
system:
|
||||
"You are a help writing assistant. Given a piece of writing, please offer suggestions to improve the piece of writing and describe the change. It is very important for the edits to contain full sentences instead of just words. Max 5 suggestions.",
|
||||
'You are a help writing assistant. Given a piece of writing, please offer suggestions to improve the piece of writing and describe the change. It is very important for the edits to contain full sentences instead of just words. Max 5 suggestions.',
|
||||
prompt: document.content,
|
||||
output: "array",
|
||||
output: 'array',
|
||||
schema: z.object({
|
||||
originalSentence: z.string().describe("The original sentence"),
|
||||
suggestedSentence: z.string().describe("The suggested sentence"),
|
||||
description: z.string().describe("The description of the suggestion"),
|
||||
originalSentence: z.string().describe('The original sentence'),
|
||||
suggestedSentence: z.string().describe('The suggested sentence'),
|
||||
description: z.string().describe('The description of the suggestion'),
|
||||
}),
|
||||
});
|
||||
|
||||
for await (const element of elementStream) {
|
||||
// @ts-expect-error todo: fix type
|
||||
// @ts-ignore todo: fix type
|
||||
const suggestion: Suggestion = {
|
||||
originalText: element.originalSentence,
|
||||
suggestedText: element.suggestedSentence,
|
||||
description: element.description,
|
||||
id: generateUUID(),
|
||||
documentId,
|
||||
documentId: documentId,
|
||||
isResolved: false,
|
||||
};
|
||||
|
||||
dataStream.write({
|
||||
type: "data-suggestion",
|
||||
type: 'data-suggestion',
|
||||
data: suggestion,
|
||||
transient: true,
|
||||
});
|
||||
|
|
@ -87,7 +86,7 @@ export const requestSuggestions = ({
|
|||
id: documentId,
|
||||
title: document.title,
|
||||
kind: document.kind,
|
||||
message: "Suggestions have been added to the document",
|
||||
message: 'Suggestions have been added to the document',
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue