Upgrade linter and formatter to Ultracite (#1224)

This commit is contained in:
Hayden Bleasel 2025-09-20 12:47:10 -07:00 committed by GitHub
parent b1d254283b
commit 0e320b391d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 6951 additions and 8342 deletions

View file

@ -1,43 +1,37 @@
import { Artifact } from '@/components/create-artifact';
import { parse, unparse } from "papaparse";
import { toast } from "sonner";
import { Artifact } from "@/components/create-artifact";
import {
CopyIcon,
LineChartIcon,
RedoIcon,
SparklesIcon,
UndoIcon,
} from '@/components/icons';
import { SpreadsheetEditor } from '@/components/sheet-editor';
import { parse, unparse } from 'papaparse';
import { toast } from 'sonner';
} from "@/components/icons";
import { SpreadsheetEditor } from "@/components/sheet-editor";
type Metadata = any;
export const sheetArtifact = new Artifact<'sheet', Metadata>({
kind: 'sheet',
description: 'Useful for working with spreadsheets',
initialize: async () => {},
export const sheetArtifact = new Artifact<"sheet", Metadata>({
kind: "sheet",
description: "Useful for working with spreadsheets",
initialize: () => null,
onStreamPart: ({ setArtifact, streamPart }) => {
if (streamPart.type === 'data-sheetDelta') {
if (streamPart.type === "data-sheetDelta") {
setArtifact((draftArtifact) => ({
...draftArtifact,
content: streamPart.data,
isVisible: true,
status: 'streaming',
status: "streaming",
}));
}
},
content: ({
content,
currentVersionIndex,
isCurrentVersion,
onSaveContent,
status,
}) => {
content: ({ content, currentVersionIndex, onSaveContent, status }) => {
return (
<SpreadsheetEditor
content={content}
currentVersionIndex={currentVersionIndex}
isCurrentVersion={isCurrentVersion}
isCurrentVersion={true}
saveContent={onSaveContent}
status={status}
/>
@ -46,9 +40,9 @@ export const sheetArtifact = new Artifact<'sheet', Metadata>({
actions: [
{
icon: <UndoIcon size={18} />,
description: 'View Previous version',
description: "View Previous version",
onClick: ({ handleVersionChange }) => {
handleVersionChange('prev');
handleVersionChange("prev");
},
isDisabled: ({ currentVersionIndex }) => {
if (currentVersionIndex === 0) {
@ -60,9 +54,9 @@ export const sheetArtifact = new Artifact<'sheet', Metadata>({
},
{
icon: <RedoIcon size={18} />,
description: 'View Next version',
description: "View Next version",
onClick: ({ handleVersionChange }) => {
handleVersionChange('next');
handleVersionChange("next");
},
isDisabled: ({ isCurrentVersion }) => {
if (isCurrentVersion) {
@ -74,44 +68,44 @@ export const sheetArtifact = new Artifact<'sheet', Metadata>({
},
{
icon: <CopyIcon />,
description: 'Copy as .csv',
description: "Copy as .csv",
onClick: ({ content }) => {
const parsed = parse<string[]>(content, { skipEmptyLines: true });
const nonEmptyRows = parsed.data.filter((row) =>
row.some((cell) => cell.trim() !== ''),
row.some((cell) => cell.trim() !== "")
);
const cleanedCsv = unparse(nonEmptyRows);
navigator.clipboard.writeText(cleanedCsv);
toast.success('Copied csv to clipboard!');
toast.success("Copied csv to clipboard!");
},
},
],
toolbar: [
{
description: 'Format and clean data',
description: "Format and clean data",
icon: <SparklesIcon />,
onClick: ({ sendMessage }) => {
sendMessage({
role: 'user',
role: "user",
parts: [
{ type: 'text', text: 'Can you please format and clean the data?' },
{ type: "text", text: "Can you please format and clean the data?" },
],
});
},
},
{
description: 'Analyze and visualize data',
description: "Analyze and visualize data",
icon: <LineChartIcon />,
onClick: ({ sendMessage }) => {
sendMessage({
role: 'user',
role: "user",
parts: [
{
type: 'text',
text: 'Can you please analyze and visualize the data by creating a new code artifact in python?',
type: "text",
text: "Can you please analyze and visualize the data by creating a new code artifact in python?",
},
],
});

View file

@ -1,33 +1,33 @@
import { myProvider } from '@/lib/ai/providers';
import { sheetPrompt, updateDocumentPrompt } from '@/lib/ai/prompts';
import { createDocumentHandler } from '@/lib/artifacts/server';
import { streamObject } from 'ai';
import { z } from 'zod';
import { streamObject } from "ai";
import { z } from "zod";
import { sheetPrompt, updateDocumentPrompt } from "@/lib/ai/prompts";
import { myProvider } from "@/lib/ai/providers";
import { createDocumentHandler } from "@/lib/artifacts/server";
export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
kind: 'sheet',
export const sheetDocumentHandler = createDocumentHandler<"sheet">({
kind: "sheet",
onCreateDocument: async ({ title, dataStream }) => {
let draftContent = '';
let draftContent = "";
const { fullStream } = streamObject({
model: myProvider.languageModel('artifact-model'),
model: myProvider.languageModel("artifact-model"),
system: sheetPrompt,
prompt: title,
schema: z.object({
csv: z.string().describe('CSV data'),
csv: z.string().describe("CSV data"),
}),
});
for await (const delta of fullStream) {
const { type } = delta;
if (type === 'object') {
if (type === "object") {
const { object } = delta;
const { csv } = object;
if (csv) {
dataStream.write({
type: 'data-sheetDelta',
type: "data-sheetDelta",
data: csv,
transient: true,
});
@ -38,7 +38,7 @@ export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
}
dataStream.write({
type: 'data-sheetDelta',
type: "data-sheetDelta",
data: draftContent,
transient: true,
});
@ -46,11 +46,11 @@ export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
return draftContent;
},
onUpdateDocument: async ({ document, description, dataStream }) => {
let draftContent = '';
let draftContent = "";
const { fullStream } = streamObject({
model: myProvider.languageModel('artifact-model'),
system: updateDocumentPrompt(document.content, 'sheet'),
model: myProvider.languageModel("artifact-model"),
system: updateDocumentPrompt(document.content, "sheet"),
prompt: description,
schema: z.object({
csv: z.string(),
@ -60,13 +60,13 @@ export const sheetDocumentHandler = createDocumentHandler<'sheet'>({
for await (const delta of fullStream) {
const { type } = delta;
if (type === 'object') {
if (type === "object") {
const { object } = delta;
const { csv } = object;
if (csv) {
dataStream.write({
type: 'data-sheetDelta',
type: "data-sheetDelta",
data: csv,
transient: true,
});