feat: v1 — persistent shell, model gateway, artifact improvements (#1462)
This commit is contained in:
parent
3651670fb9
commit
f9652b452a
161 changed files with 5166 additions and 8009 deletions
|
|
@ -1,22 +1,29 @@
|
|||
import { tool, type UIMessageStreamWriter } from "ai";
|
||||
import type { Session } from "next-auth";
|
||||
import { z } from "zod";
|
||||
import { documentHandlersByArtifactKind } from "@/lib/artifacts/server";
|
||||
import type { AuthSession } from "@/lib/auth";
|
||||
import { getDocumentById } from "@/lib/db/queries";
|
||||
import type { ChatMessage } from "@/lib/types";
|
||||
|
||||
type UpdateDocumentProps = {
|
||||
session: NonNullable<AuthSession>;
|
||||
session: Session;
|
||||
dataStream: UIMessageStreamWriter<ChatMessage>;
|
||||
modelId: string;
|
||||
};
|
||||
|
||||
export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
|
||||
export const updateDocument = ({
|
||||
session,
|
||||
dataStream,
|
||||
modelId,
|
||||
}: UpdateDocumentProps) =>
|
||||
tool({
|
||||
description: "Update a document with the given description.",
|
||||
description:
|
||||
"Full rewrite of an existing artifact. Only use for major changes where most content needs replacing. Prefer editDocument for targeted changes.",
|
||||
inputSchema: z.object({
|
||||
id: z.string().describe("The ID of the document to update"),
|
||||
id: z.string().describe("The ID of the artifact to rewrite"),
|
||||
description: z
|
||||
.string()
|
||||
.default("Improve the content")
|
||||
.describe("The description of changes that need to be made"),
|
||||
}),
|
||||
execute: async ({ id, description }) => {
|
||||
|
|
@ -28,6 +35,10 @@ export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
|
|||
};
|
||||
}
|
||||
|
||||
if (document.userId !== session.user?.id) {
|
||||
return { error: "Forbidden" };
|
||||
}
|
||||
|
||||
dataStream.write({
|
||||
type: "data-clear",
|
||||
data: null,
|
||||
|
|
@ -48,6 +59,7 @@ export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
|
|||
description,
|
||||
dataStream,
|
||||
session,
|
||||
modelId,
|
||||
});
|
||||
|
||||
dataStream.write({ type: "data-finish", data: null, transient: true });
|
||||
|
|
@ -56,7 +68,10 @@ export const updateDocument = ({ session, dataStream }: UpdateDocumentProps) =>
|
|||
id,
|
||||
title: document.title,
|
||||
kind: document.kind,
|
||||
content: "The document has been updated successfully.",
|
||||
content:
|
||||
document.kind === "code"
|
||||
? "The script has been updated successfully."
|
||||
: "The document has been updated successfully.",
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue