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,10 +1,10 @@
import type { UserType } from "@/app/(auth)/auth";
import type { ChatModel } from "./models";
import type { UserType } from '@/app/(auth)/auth';
import type { ChatModel } from './models';
type Entitlements = {
interface Entitlements {
maxMessagesPerDay: number;
availableChatModelIds: ChatModel["id"][];
};
availableChatModelIds: Array<ChatModel['id']>;
}
export const entitlementsByUserType: Record<UserType, Entitlements> = {
/*
@ -12,7 +12,7 @@ export const entitlementsByUserType: Record<UserType, Entitlements> = {
*/
guest: {
maxMessagesPerDay: 20,
availableChatModelIds: ["chat-model", "chat-model-reasoning"],
availableChatModelIds: ['chat-model', 'chat-model-reasoning'],
},
/*
@ -20,7 +20,7 @@ export const entitlementsByUserType: Record<UserType, Entitlements> = {
*/
regular: {
maxMessagesPerDay: 100,
availableChatModelIds: ["chat-model", "chat-model-reasoning"],
availableChatModelIds: ['chat-model', 'chat-model-reasoning'],
},
/*

View file

@ -1,28 +1,28 @@
import type { LanguageModel } from "ai";
import type { LanguageModel } from 'ai';
const createMockModel = (): LanguageModel => {
return {
specificationVersion: "v2",
provider: "mock",
modelId: "mock-model",
defaultObjectGenerationMode: "tool",
specificationVersion: 'v2',
provider: 'mock',
modelId: 'mock-model',
defaultObjectGenerationMode: 'tool',
supportedUrls: [],
supportsImageUrls: false,
supportsStructuredOutputs: false,
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: "stop",
finishReason: 'stop',
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: "text", text: "Hello, world!" }],
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async () => ({
stream: new ReadableStream({
start(controller) {
controller.enqueue({
type: "text-delta",
id: "mock-id",
delta: "Mock response",
type: 'text-delta',
id: 'mock-id',
delta: 'Mock response',
});
controller.close();
},

View file

@ -1,13 +1,13 @@
import { simulateReadableStream } from "ai";
import { MockLanguageModelV2 } from "ai/test";
import { getResponseChunksByPrompt } from "@/tests/prompts/utils";
import { simulateReadableStream } from 'ai';
import { MockLanguageModelV2 } from 'ai/test';
import { getResponseChunksByPrompt } from '@/tests/prompts/utils';
export const chatModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: "stop",
finishReason: 'stop',
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: "text", text: "Hello, world!" }],
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({
@ -23,9 +23,9 @@ export const chatModel = new MockLanguageModelV2({
export const reasoningModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: "stop",
finishReason: 'stop',
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: "text", text: "Hello, world!" }],
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({
@ -41,9 +41,9 @@ export const reasoningModel = new MockLanguageModelV2({
export const titleModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: "stop",
finishReason: 'stop',
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: "text", text: "This is a test title" }],
content: [{ type: 'text', text: 'This is a test title' }],
warnings: [],
}),
doStream: async () => ({
@ -51,12 +51,12 @@ export const titleModel = new MockLanguageModelV2({
chunkDelayInMs: 500,
initialDelayInMs: 1000,
chunks: [
{ id: "1", type: "text-start" },
{ id: "1", type: "text-delta", delta: "This is a test title" },
{ id: "1", type: "text-end" },
{ id: '1', type: 'text-start' },
{ id: '1', type: 'text-delta', delta: 'This is a test title' },
{ id: '1', type: 'text-end' },
{
type: "finish",
finishReason: "stop",
type: 'finish',
finishReason: 'stop',
usage: { inputTokens: 3, outputTokens: 10, totalTokens: 13 },
},
],
@ -68,9 +68,9 @@ export const titleModel = new MockLanguageModelV2({
export const artifactModel = new MockLanguageModelV2({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: "stop",
finishReason: 'stop',
usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 },
content: [{ type: "text", text: "Hello, world!" }],
content: [{ type: 'text', text: 'Hello, world!' }],
warnings: [],
}),
doStream: async ({ prompt }) => ({

View file

@ -1,21 +1,21 @@
export const DEFAULT_CHAT_MODEL: string = "chat-model";
export const DEFAULT_CHAT_MODEL: string = 'chat-model';
export type ChatModel = {
export interface ChatModel {
id: string;
name: string;
description: string;
};
}
export const chatModels: ChatModel[] = [
export const chatModels: Array<ChatModel> = [
{
id: "chat-model",
name: "Grok Vision",
description: "Advanced multimodal model with vision and text capabilities",
id: 'chat-model',
name: 'Grok Vision',
description: 'Advanced multimodal model with vision and text capabilities',
},
{
id: "chat-model-reasoning",
name: "Grok Reasoning",
id: 'chat-model-reasoning',
name: 'Grok Reasoning',
description:
"Uses advanced chain-of-thought reasoning for complex problems",
'Uses advanced chain-of-thought reasoning for complex problems',
},
];

View file

@ -1,5 +1,5 @@
import type { Geo } from "@vercel/functions";
import type { ArtifactKind } from "@/components/artifact";
import type { ArtifactKind } from '@/components/artifact';
import type { Geo } from '@vercel/functions';
export const artifactsPrompt = `
Artifacts is a special user interface mode that helps users with writing, editing, and other content creation tasks. When artifact is open, it is on the right side of the screen, while the conversation is on the left side. When creating or updating documents, changes are reflected in real-time on the artifacts and visible to the user.
@ -33,14 +33,14 @@ Do not update document right after creating it. Wait for user feedback or reques
`;
export const regularPrompt =
"You are a friendly assistant! Keep your responses concise and helpful.";
'You are a friendly assistant! Keep your responses concise and helpful.';
export type RequestHints = {
latitude: Geo["latitude"];
longitude: Geo["longitude"];
city: Geo["city"];
country: Geo["country"];
};
export interface RequestHints {
latitude: Geo['latitude'];
longitude: Geo['longitude'];
city: Geo['city'];
country: Geo['country'];
}
export const getRequestPromptFromHints = (requestHints: RequestHints) => `\
About the origin of user's request:
@ -59,11 +59,11 @@ export const systemPrompt = ({
}) => {
const requestPrompt = getRequestPromptFromHints(requestHints);
if (selectedChatModel === "chat-model-reasoning") {
if (selectedChatModel === 'chat-model-reasoning') {
return `${regularPrompt}\n\n${requestPrompt}`;
} else {
return `${regularPrompt}\n\n${requestPrompt}\n\n${artifactsPrompt}`;
}
return `${regularPrompt}\n\n${requestPrompt}\n\n${artifactsPrompt}`;
};
export const codePrompt = `
@ -98,17 +98,24 @@ You are a spreadsheet creation assistant. Create a spreadsheet in csv format bas
export const updateDocumentPrompt = (
currentContent: string | null,
type: ArtifactKind
) => {
let mediaType = "document";
type: ArtifactKind,
) =>
type === 'text'
? `\
Improve the following contents of the document based on the given prompt.
if (type === "code") {
mediaType = "code snippet";
} else if (type === "sheet") {
mediaType = "spreadsheet";
}
${currentContent}
`
: type === 'code'
? `\
Improve the following code snippet based on the given prompt.
return `Improve the following contents of the ${mediaType} based on the given prompt.
${currentContent}
`
: type === 'sheet'
? `\
Improve the following spreadsheet based on the given prompt.
${currentContent}`;
};
${currentContent}
`
: '';

View file

@ -1,10 +1,10 @@
import { gateway } from "@ai-sdk/gateway";
import {
customProvider,
extractReasoningMiddleware,
wrapLanguageModel,
} from "ai";
import { isTestEnvironment } from "../constants";
} from 'ai';
import { gateway } from '@ai-sdk/gateway';
import { isTestEnvironment } from '../constants';
export const myProvider = isTestEnvironment
? (() => {
@ -13,24 +13,24 @@ export const myProvider = isTestEnvironment
chatModel,
reasoningModel,
titleModel,
} = require("./models.mock");
} = require('./models.mock');
return customProvider({
languageModels: {
"chat-model": chatModel,
"chat-model-reasoning": reasoningModel,
"title-model": titleModel,
"artifact-model": artifactModel,
'chat-model': chatModel,
'chat-model-reasoning': reasoningModel,
'title-model': titleModel,
'artifact-model': artifactModel,
},
});
})()
: customProvider({
languageModels: {
"chat-model": gateway.languageModel("xai/grok-2-vision-1212"),
"chat-model-reasoning": wrapLanguageModel({
model: gateway.languageModel("xai/grok-3-mini"),
middleware: extractReasoningMiddleware({ tagName: "think" }),
'chat-model': gateway.languageModel('xai/grok-2-vision-1212'),
'chat-model-reasoning': wrapLanguageModel({
model: gateway.languageModel('xai/grok-3-mini'),
middleware: extractReasoningMiddleware({ tagName: 'think' }),
}),
"title-model": gateway.languageModel("xai/grok-2-1212"),
"artifact-model": gateway.languageModel("xai/grok-2-1212"),
'title-model': gateway.languageModel('xai/grok-2-1212'),
'artifact-model': gateway.languageModel('xai/grok-2-1212'),
},
});

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