🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(topic): strip markdown tokens from fallback titles (#15372)
Innei5119c0802d21
diff --git a/src/server/routers/lambda/thread.ts b/src/server/routers/lambda/thread.tsindex 638cc28bbaf..dcaec04d314 100644--- a/src/server/routers/lambda/thread.ts+++ b/src/server/routers/lambda/thread.ts@@ -8,6 +8,7 @@ import { authedProcedure, router } from '@/libs/trpc/lambda';import { serverDatabase } from '@/libs/trpc/lambda/middleware';import { type ThreadItem } from '@/types/topic/thread';import { createThreadSchema } from '@/types/topic/thread';+import { markdownToTxt } from '@/utils/markdownToTxt';/*** `ThreadModel.create` uses `onConflictDoNothing()` and returns undefined when@@ -73,7 +74,7 @@ export const threadRouter = router({metadata: input.metadata,parentThreadId: input.parentThreadId,sourceMessageId: input.sourceMessageId,- title: input.message.content.slice(0, 80),+ title: markdownToTxt(input.message.content).slice(0, 80),topicId: input.topicId,type: input.type,}),diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.tsindex 074232ada05..e7111afe11f 100644--- a/src/server/services/aiAgent/index.ts+++ b/src/server/services/aiAgent/index.ts@@ -84,6 +84,7 @@ import type { ConversationHistoryEntry } from '@/server/services/heterogeneousAgimport { KlavisService } from '@/server/services/klavis';import { MarketService } from '@/server/services/market';import { deviceProxy } from '@/server/services/toolExecution/deviceProxy';+import { markdownToTxt } from '@/utils/markdownToTxt';import { resolveDeviceAccessPolicy } from './deviceAccessPolicy';import { buildAllowedBuiltinTools, isDeviceToolIdentifier } from './deviceToolRegistry';@@ -630,11 +631,14 @@ export class AiAgentService {}: undefined;+ const fallbackTitleSource = markdownToTxt(prompt);const newTopic = await this.topicModel.create({agentId: resolvedAgentId,metadata,title:- title !== undefined ? title : prompt.slice(0, 50) + (prompt.length > 50 ? '...' : ''),+ title !== undefined+ ? title+ : fallbackTitleSource.slice(0, 50) + (fallbackTitleSource.length > 50 ? '...' : ''),trigger,});topicId = newTopic.id;@@ -2320,8 +2324,10 @@ export class AiAgentService {// - newTopic is explicitly provided, OR// - no topicId is provided (default behavior for group chat)if (newTopic || !inputTopicId) {+ const fallbackTitleSource = markdownToTxt(message);const topicTitle =- newTopic?.title || message.slice(0, 50) + (message.length > 50 ? '...' : '');+ newTopic?.title ||+ fallbackTitleSource.slice(0, 50) + (fallbackTitleSource.length > 50 ? '...' : '');const topicItem = await this.topicModel.create({agentId,groupId,diff --git a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts b/src/store/chat/slices/aiChat/actions/conversationLifecycle.tsindex 6a3651d6d6a..f20c9bc6355 100644--- a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts+++ b/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts@@ -58,6 +58,7 @@ import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';import { type StoreSetter } from '@/store/types';import { useUserMemoryStore } from '@/store/userMemory';+import { markdownToTxt } from '@/utils/markdownToTxt';import { dbMessageSelectors, displayMessageSelectors, topicSelectors } from '../../../selectors';import { messageMapKey } from '../../../utils/messageMapKey';@@ -516,7 +517,7 @@ export class ConversationLifecycleActionImpl {newTopic: !operationContext.topicId? {metadata: workingDirectory ? { workingDirectory } : undefined,- title: message.slice(0, 80) || t('defaultTitle', { ns: 'topic' }),+ title: markdownToTxt(message).slice(0, 80) || t('defaultTitle', { ns: 'topic' }),topicMessageIds: messages.map((m) => m.id),}: undefined,@@ -920,7 +921,7 @@ export class ConversationLifecycleActionImpl {}const firstUserText = messages.find((m) => m.role === 'user')?.content?.trim() ?? '';- const title = firstUserText.slice(0, 80) || 'New Topic';+ const title = markdownToTxt(firstUserText).slice(0, 80) || 'New Topic';await this.#get().internal_updateTopic(topicId, { title });// summaryTopicTitle would normally clear loading via onLoadingChange; do it manually.this.#get().internal_updateTopicLoading(topicId, false);diff --git a/src/store/home/slices/homeInput/action.ts b/src/store/home/slices/homeInput/action.tsindex 4f68ea4105c..020c7ac41bd 100644--- a/src/store/home/slices/homeInput/action.ts+++ b/src/store/home/slices/homeInput/action.ts@@ -10,6 +10,7 @@ import { useGlobalStore } from '@/store/global';import { useGroupProfileStore } from '@/store/groupProfile';import { type HomeStore } from '@/store/home/store';import { type StoreSetter } from '@/store/types';+import { markdownToTxt } from '@/utils/markdownToTxt';import { getStableNavigate } from '@/utils/stableNavigate';import { setNamespace } from '@/utils/storeDebug';@@ -83,7 +84,7 @@ export class HomeInputActionImpl {model,provider,systemRole: message,- title: message?.slice(0, 50) || 'New Agent',+ title: markdownToTxt(message ?? '').slice(0, 50) || 'New Agent',},groupId,});@@ -153,7 +154,7 @@ export class HomeInputActionImpl {systemPrompt: message,},groupId,- title: message?.slice(0, 50) || 'New Group',+ title: markdownToTxt(message ?? '').slice(0, 50) || 'New Group',});// 3. Load groups and refresh@@ -225,7 +226,7 @@ export class HomeInputActionImpl {const newDoc = await documentService.createDocument({editorData: '{}',fileType: 'custom/document',- title: message?.slice(0, 50) || 'Untitled',+ title: markdownToTxt(message ?? '').slice(0, 50) || 'Untitled',});// 3. Navigate to Page