better default title
This commit is contained in:
parent
76fb39fe99
commit
bd3fa47711
4 changed files with 16 additions and 12 deletions
|
|
@ -5,6 +5,7 @@ import { type Id } from './_generated/dataModel';
|
|||
import { type SessionObj } from './betterAuth';
|
||||
import { messageRoleValidator } from './schema';
|
||||
import { mutation } from './functions';
|
||||
import { getFirstSentence } from '../../utils/strings';
|
||||
|
||||
export const get = query({
|
||||
args: {
|
||||
|
|
@ -101,8 +102,11 @@ export const createAndAddMessage = mutation({
|
|||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
// use first sentence as a placeholder title
|
||||
const [firstSentence, full] = getFirstSentence(args.content);
|
||||
|
||||
const conversationId = await ctx.db.insert('conversations', {
|
||||
title: 'Untitled (for now)',
|
||||
title: firstSentence ?? full.slice(0, 35),
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Id type is janking out
|
||||
user_id: session.userId as any,
|
||||
updated_at: Date.now(),
|
||||
|
|
|
|||
8
src/lib/utils/strings.ts
Normal file
8
src/lib/utils/strings.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export function getFirstSentence(text: string): [string | null, string] {
|
||||
// match any punctuation followed by a space or the end of the string
|
||||
const index = text.match(/[.!?](\s|$)/)?.index;
|
||||
|
||||
if (index === undefined) return [null, text];
|
||||
|
||||
return [text.slice(0, index + 1), text];
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
import { api } from '$lib/backend/convex/_generated/api';
|
||||
import { session } from '$lib/state/session.svelte.js';
|
||||
import { ResultAsync } from 'neverthrow';
|
||||
import { getFirstSentence } from '$lib/utils/strings';
|
||||
|
||||
type Model = {
|
||||
id: string;
|
||||
|
|
@ -24,16 +25,7 @@
|
|||
|
||||
const client = useConvexClient();
|
||||
|
||||
function getShortDescription(text: string) {
|
||||
// match any punctuation followed by a space or the end of the string
|
||||
const index = text.match(/[.!?](\s|$)/)?.index;
|
||||
|
||||
if (index === undefined) return { shortDescription: null, fullDescription: text };
|
||||
|
||||
return { shortDescription: text.slice(0, index + 1), fullDescription: text };
|
||||
}
|
||||
|
||||
const { shortDescription, fullDescription } = $derived(getShortDescription(model.description));
|
||||
const [shortDescription, fullDescription] = $derived(getFirstSentence(model.description));
|
||||
|
||||
let showMore = $state(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ async function generateConversationTitle({
|
|||
const conversations = conversationResult.value;
|
||||
const conversation = conversations.find((c) => c._id === conversationId);
|
||||
|
||||
if (!conversation || !conversation.title.includes('Untitled')) {
|
||||
if (!conversation) {
|
||||
log('Title generation: Conversation not found or already has custom title', startTime);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue