MCPcopy
hub / github.com/vercel/chatbot / POST

Function POST

app/(chat)/api/document/route.ts:42–85  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

40}
41
42export async function POST(request: Request) {
43 const { searchParams } = new URL(request.url);
44 const id = searchParams.get('id');
45
46 if (!id) {
47 return new ChatSDKError(
48 'bad_request:api',
49 'Parameter id is required.',
50 ).toResponse();
51 }
52
53 const session = await auth();
54
55 if (!session?.user) {
56 return new ChatSDKError('not_found:document').toResponse();
57 }
58
59 const {
60 content,
61 title,
62 kind,
63 }: { content: string; title: string; kind: ArtifactKind } =
64 await request.json();
65
66 const documents = await getDocumentsById({ id });
67
68 if (documents.length > 0) {
69 const [document] = documents;
70
71 if (document.userId !== session.user.id) {
72 return new ChatSDKError('forbidden:document').toResponse();
73 }
74 }
75
76 const document = await saveDocument({
77 id,
78 content,
79 title,
80 kind,
81 userId: session.user.id,
82 });
83
84 return Response.json(document, { status: 200 });
85}
86
87export async function DELETE(request: Request) {
88 const { searchParams } = new URL(request.url);

Callers

nothing calls this directly

Calls 3

getDocumentsByIdFunction · 0.90
saveDocumentFunction · 0.90
toResponseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…