Restore Ultracite + fix sidebar (#1233)

This commit is contained in:
Hayden Bleasel 2025-09-21 11:02:31 -07:00 committed by GitHub
parent 8fbfc253fa
commit 947ed094a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 6908 additions and 8306 deletions

View file

@ -1,67 +1,68 @@
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';
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";
interface RequestSuggestionsProps {
type 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: Array<
Omit<Suggestion, 'userId' | 'createdAt' | 'documentCreatedAt'>
> = [];
const suggestions: 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-ignore todo: fix type
// @ts-expect-error 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,
});
@ -86,7 +87,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",
};
},
});