Skip to content

Commit

Permalink
fix document saves
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon committed Feb 5, 2025
1 parent 192f6e8 commit b6041bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ai/tools/update-document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DataStreamWriter, tool } from 'ai';
import { Session } from 'next-auth';
import { z } from 'zod';
import { getDocumentById, saveDocument } from '@/lib/db/queries';
import { getDocumentById } from '@/lib/db/queries';
import { documentHandlersByBlockKind } from '@/lib/blocks/server';

interface UpdateDocumentProps {
Expand Down
16 changes: 16 additions & 0 deletions lib/blocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export function createDocumentHandler<T extends BlockKind>(config: {
kind: config.kind,
userId: args.session.user.id,
});
} else {
await saveDocument({
id: args.id,
title: args.title,
content: draftContent,
kind: config.kind,
userId: process.env.ANON_USERID!,
});
}

return;
Expand All @@ -79,6 +87,14 @@ export function createDocumentHandler<T extends BlockKind>(config: {
kind: config.kind,
userId: args.session.user.id,
});
} else {
await saveDocument({
id: args.document.id,
title: args.document.title,
content: draftContent,
kind: config.kind,
userId: process.env.ANON_USERID!,
});
}

return;
Expand Down

0 comments on commit b6041bb

Please sign in to comment.