Revert "Upgrade linter and formatter to Ultracite" (#1226)

This commit is contained in:
josh 2025-09-21 12:03:29 +01:00 committed by GitHub
parent 0e320b391d
commit 1aff7d9868
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 8334 additions and 6943 deletions

View file

@ -1,22 +1,22 @@
import { tool, type UIMessageStreamWriter } from "ai";
import type { Session } from "next-auth";
import { z } from "zod";
import { generateUUID } from '@/lib/utils';
import { tool, type UIMessageStreamWriter } from 'ai';
import { z } from 'zod';
import type { Session } from 'next-auth';
import {
artifactKinds,
documentHandlersByArtifactKind,
} from "@/lib/artifacts/server";
import type { ChatMessage } from "@/lib/types";
import { generateUUID } from "@/lib/utils";
} from '@/lib/artifacts/server';
import type { ChatMessage } from '@/lib/types';
type CreateDocumentProps = {
interface CreateDocumentProps {
session: Session;
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.",
'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.',
inputSchema: z.object({
title: z.string(),
kind: z.enum(artifactKinds),
@ -25,32 +25,32 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
const id = generateUUID();
dataStream.write({
type: "data-kind",
type: 'data-kind',
data: kind,
transient: true,
});
dataStream.write({
type: "data-id",
type: 'data-id',
data: id,
transient: true,
});
dataStream.write({
type: "data-title",
type: 'data-title',
data: title,
transient: true,
});
dataStream.write({
type: "data-clear",
type: 'data-clear',
data: null,
transient: true,
});
const documentHandler = documentHandlersByArtifactKind.find(
(documentHandlerByArtifactKind) =>
documentHandlerByArtifactKind.kind === kind
documentHandlerByArtifactKind.kind === kind,
);
if (!documentHandler) {
@ -64,13 +64,13 @@ export const createDocument = ({ session, dataStream }: CreateDocumentProps) =>
session,
});
dataStream.write({ type: "data-finish", data: null, transient: true });
dataStream.write({ type: 'data-finish', data: null, transient: true });
return {
id,
title,
kind,
content: "A document was created and is now visible to the user.",
content: 'A document was created and is now visible to the user.',
};
},
});

View file

@ -1,15 +1,15 @@
import { tool } from "ai";
import { z } from "zod";
import { tool } from 'ai';
import { z } from 'zod';
export const getWeather = tool({
description: "Get the current weather at a location",
description: 'Get the current weather at a location',
inputSchema: z.object({
latitude: z.number(),
longitude: z.number(),
}),
execute: async ({ latitude, longitude }) => {
const response = await fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`,
);
const weatherData = await response.json();

View file

@ -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',
};
},
});

View file

@ -1,42 +1,42 @@
import { tool, type UIMessageStreamWriter } from "ai";
import type { Session } from "next-auth";
import { z } from "zod";
import { documentHandlersByArtifactKind } from "@/lib/artifacts/server";
import { getDocumentById } from "@/lib/db/queries";
import type { ChatMessage } from "@/lib/types";
import { tool, type UIMessageStreamWriter } from 'ai';
import type { Session } from 'next-auth';
import { z } from 'zod';
import { getDocumentById } from '@/lib/db/queries';
import { documentHandlersByArtifactKind } from '@/lib/artifacts/server';
import type { ChatMessage } from '@/lib/types';
type UpdateDocumentProps = {
interface UpdateDocumentProps {
session: Session;
dataStream: UIMessageStreamWriter<ChatMessage>;
};
}
export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
tool({
description: "Update a document with the given description.",
description: 'Update a document with the given description.',
inputSchema: z.object({
id: z.string().describe("The ID of the document to update"),
id: z.string().describe('The ID of the document to update'),
description: z
.string()
.describe("The description of changes that need to be made"),
.describe('The description of changes that need to be made'),
}),
execute: async ({ id, description }) => {
const document = await getDocumentById({ id });
if (!document) {
return {
error: "Document not found",
error: 'Document not found',
};
}
dataStream.write({
type: "data-clear",
type: 'data-clear',
data: null,
transient: true,
});
const documentHandler = documentHandlersByArtifactKind.find(
(documentHandlerByArtifactKind) =>
documentHandlerByArtifactKind.kind === document.kind
documentHandlerByArtifactKind.kind === document.kind,
);
if (!documentHandler) {
@ -50,13 +50,13 @@ export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
session,
});
dataStream.write({ type: "data-finish", data: null, transient: true });
dataStream.write({ type: 'data-finish', data: null, transient: true });
return {
id,
title: document.title,
kind: document.kind,
content: "The document has been updated successfully.",
content: 'The document has been updated successfully.',
};
},
});