🤯 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(cc): persist workingDirectory when CC topic is created (#13956)
Arvin Xuf38dcc4cfc79
diff --git a/packages/types/src/aiChat.ts b/packages/types/src/aiChat.tsindex 2e1dd8eb855..894c69af7de 100644--- a/packages/types/src/aiChat.ts+++ b/packages/types/src/aiChat.ts@@ -8,7 +8,7 @@ import { PageSelectionSchema } from './message/ui/params';import type { OpenAIChatMessage } from './openai/chat';import type { LobeUniformTool } from './tool';import { LobeUniformToolSchema } from './tool';-import type { ChatTopic } from './topic';+import type { ChatTopic, ChatTopicMetadata } from './topic';import type { ChatThreadType } from './topic/thread';import { ThreadType } from './topic/thread';@@ -66,6 +66,14 @@ export interface SendMessageServerParams {*/newThread?: CreateThreadWithMessageParams;newTopic?: {+ /**+ * Topic metadata persisted at creation time. For CC/heterogeneous+ * agents this carries `workingDirectory` so the topic is bound to a+ * project from the moment it's created (used by By-Project grouping+ * and CC `--resume` cwd verification), instead of waiting for the+ * post-execution metadata write which can be skipped on cancel/error.+ */+ metadata?: ChatTopicMetadata;title?: string;topicMessageIds?: string[];};@@ -111,6 +119,7 @@ export const AiSendMessageServerSchema = z.object({newThread: CreateThreadWithMessageSchema.optional(),newTopic: z.object({+ metadata: z.custom<ChatTopicMetadata>().optional(),title: z.string().optional(),topicMessageIds: z.array(z.string()).optional(),})diff --git a/src/server/routers/lambda/aiChat.ts b/src/server/routers/lambda/aiChat.tsindex cde2323e40e..60c0de3a7e8 100644--- a/src/server/routers/lambda/aiChat.ts+++ b/src/server/routers/lambda/aiChat.ts@@ -85,6 +85,7 @@ export const aiChatRouter = router({agentId: input.agentId,groupId: input.groupId,messages: input.newTopic.topicMessageIds,+ metadata: input.newTopic.metadata,sessionId,title: input.newTopic.title,});diff --git a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts b/src/store/chat/slices/aiChat/actions/conversationLifecycle.tsindex d2128464d22..800e74c599d 100644--- a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts+++ b/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts@@ -347,6 +347,13 @@ export class ConversationLifecycleActionImpl {const agentConfig = agentSelectors.getAgentConfigById(agentId)(getAgentStoreState());const heterogeneousProvider = agentConfig?.agencyConfig?.heterogeneousProvider;if (isDesktop && heterogeneousProvider?.type === 'claude-code') {+ // Resolve cwd up-front so the new topic is bound to a project at+ // creation time. Otherwise the row stays NULL until the post-execution+ // metadata write — which never lands on cancel/error and meanwhile+ // makes By-Project grouping miss the topic and `--resume` unsafe.+ const workingDirectory =+ agentByIdSelectors.getAgentWorkingDirectoryById(agentId)(getAgentStoreState());+// Persist messages to DB first (same as client mode)let heteroData: SendMessageServerResponse | undefined;try {@@ -358,6 +365,7 @@ export class ConversationLifecycleActionImpl {newAssistantMessage: { model, provider: 'claude-code' },newTopic: !operationContext.topicId? {+ metadata: workingDirectory ? { workingDirectory } : undefined,title: message.slice(0, 20) || t('defaultTitle', { ns: 'topic' }),topicMessageIds: messages.map((m) => m.id),}@@ -437,8 +445,6 @@ export class ConversationLifecycleActionImpl {try {const { executeHeterogeneousAgent } = await import('./heterogeneousAgentExecutor');- const workingDirectory =- agentByIdSelectors.getAgentWorkingDirectoryById(agentId)(getAgentStoreState());// Extract imageList from the persisted user message (chatUploadFileList// may already be cleared by this point, so we read from DB instead)const userMsg = heteroData.messages.find((m: any) => m.id === heteroData.userMessageId);