Skip to content

🀯 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.

♻️ refactor(chat): rename aiChatβ†’agentRun and organize into layered module (#16155)

Arvin Xu0db8b77c5d11
diff --git a/packages/agent-signal/README.md b/packages/agent-signal/README.md
index 887db3eb28a..f6b050c97ef 100644
--- a/packages/agent-signal/README.md
+++ b/packages/agent-signal/README.md
@@ -80,7 +80,7 @@ Use the browser service facade for:
- Sending events through tRPC
- Keeping UI paths non-blocking
-See [src/services/agentSignal.ts](../../src/services/agentSignal.ts) and [src/store/chat/slices/aiChat/actions/agentSignalBridge.ts](../../src/store/chat/slices/aiChat/actions/agentSignalBridge.ts).
+See [src/services/agentSignal.ts](../../src/services/agentSignal.ts) and [src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.ts](../../src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.ts).
Use server services for:
@@ -101,12 +101,12 @@ See [src/server/services/agentSignal/emitter.ts](../../src/server/services/agent
| `agent.execution.failed` | `AGENT_SIGNAL_SOURCE_TYPES.agentExecutionFailed` | [Agent Runtime](../../src/server/services/agentRuntime/AgentRuntimeService.ts) | Server agent execution failed with operation, reason, error, topic, and context metadata. |
| `agent.user.message` | `AGENT_SIGNAL_SOURCE_TYPES.agentUserMessage` | [Workflow bridge](../../src/server/workflows/agentSignal/run.ts), [Bot router](../../src/server/services/bot/BotMessageRouter.ts) | User feedback/message content that policies can analyze for memory, prompt, document, or skill changes. |
| `bot.message.merged` | `AGENT_SIGNAL_SOURCE_TYPES.botMessageMerged` | [Bot router](../../src/server/services/bot/BotMessageRouter.ts) | Bot-platform message content merged into a conversation scope. |
-| `client.gateway.error` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayError` | [Gateway event handler](../../src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts) | Browser gateway error for a client-side runtime operation. |
-| `client.gateway.runtime_end` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayRuntimeEnd` | [Gateway event handler](../../src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts) | Browser gateway runtime finished for a client-side operation. |
-| `client.gateway.step_complete` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStepComplete` | [Gateway event handler](../../src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts) | Browser gateway step completed with operation and step index metadata. |
-| `client.gateway.stream_start` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStreamStart` | [Gateway event handler](../../src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts) | Browser gateway stream started with operation and first step metadata. |
-| `client.runtime.complete` | `AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeComplete` | [Chat streaming executor](../../src/store/chat/slices/aiChat/actions/streamingExecutor.ts) | Browser chat runtime completed with operation, topic, thread, and status metadata. |
-| `client.runtime.start` | `AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeStart` | [Chat streaming executor](../../src/store/chat/slices/aiChat/actions/streamingExecutor.ts) | Browser chat runtime started; workflow may bridge this into `agent.user.message` with serialized context. |
+| `client.gateway.error` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayError` | [Gateway event handler](../../src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts) | Browser gateway error for a client-side runtime operation. |
+| `client.gateway.runtime_end` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayRuntimeEnd` | [Gateway event handler](../../src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts) | Browser gateway runtime finished for a client-side operation. |
+| `client.gateway.step_complete` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStepComplete` | [Gateway event handler](../../src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts) | Browser gateway step completed with operation and step index metadata. |
+| `client.gateway.stream_start` | `AGENT_SIGNAL_SOURCE_TYPES.clientGatewayStreamStart` | [Gateway event handler](../../src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts) | Browser gateway stream started with operation and first step metadata. |
+| `client.runtime.complete` | `AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeComplete` | [Chat streaming executor](../../src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts) | Browser chat runtime completed with operation, topic, thread, and status metadata. |
+| `client.runtime.start` | `AGENT_SIGNAL_SOURCE_TYPES.clientRuntimeStart` | [Chat streaming executor](../../src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts) | Browser chat runtime started; workflow may bridge this into `agent.user.message` with serialized context. |
| `runtime.after_step` | `AGENT_SIGNAL_SOURCE_TYPES.runtimeAfterStep` | [Agent Runtime](../../src/server/services/agentRuntime/AgentRuntimeService.ts) | Server runtime step finished with operation, step index, topic, and context metadata. |
| `runtime.before_step` | `AGENT_SIGNAL_SOURCE_TYPES.runtimeBeforeStep` | [Agent Runtime](../../src/server/services/agentRuntime/AgentRuntimeService.ts) | Server runtime step is about to run with operation, step index, topic, and context metadata. |
@@ -118,7 +118,7 @@ See [src/server/services/agentSignal/emitter.ts](../../src/server/services/agent
- [Source type catalog](src/source/sourceTypes.ts): constants, payload map, source variants, and the client allow-list.
- [Scope-key helpers](src/source/scopeKey.ts): topic, bot thread, task, agent/user, and user scope-key builders.
- [Browser service facade](../../src/services/agentSignal.ts): tRPC client wrapper for browser code.
-- [Browser bridge](../../src/store/chat/slices/aiChat/actions/agentSignalBridge.ts): feature-gated non-blocking browser emission helper.
+- [Browser bridge](../../src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.ts): feature-gated non-blocking browser emission helper.
- [Lambda router](../../src/server/routers/lambda/agentSignal.ts): authenticated browser ingress and client source type validation.
- [Server emitter](../../src/server/services/agentSignal/emitter.ts): feature-gated immediate execution or workflow handoff.
- [Server orchestrator](../../src/server/services/agentSignal/orchestrator.ts): source event execution through policies, runtime, and observability.
@@ -126,8 +126,8 @@ See [src/server/services/agentSignal/emitter.ts](../../src/server/services/agent
- [Workflow trigger](../../src/server/workflows/agentSignal/index.ts): async Upstash Workflow handoff.
- [Workflow runner](../../src/server/workflows/agentSignal/run.ts): workflow execution and client runtime bridge.
- [Agent Runtime](../../src/server/services/agentRuntime/AgentRuntimeService.ts): server runtime source event producers.
-- [Chat](../../src/store/chat/slices/aiChat/actions/streamingExecutor.ts): browser chat runtime source event producer.
-- [Gateway event handler](../../src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts): browser gateway source event producer.
+- [Chat](../../src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts): browser chat runtime source event producer.
+- [Gateway event handler](../../src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts): browser gateway source event producer.
- [Bot router](../../src/server/services/bot/BotMessageRouter.ts): bot-platform source event producer.
## Adding A Source Event
diff --git a/packages/builtin-tool-agent-management/src/executor.ts b/packages/builtin-tool-agent-management/src/executor.ts
index bcbc554c4e2..b5f5aaa35ae 100644
--- a/packages/builtin-tool-agent-management/src/executor.ts
+++ b/packages/builtin-tool-agent-management/src/executor.ts
@@ -18,7 +18,7 @@ import { discoverService } from '@/services/discover';
import { getAgentStoreState, useAgentStore } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
-import { dispatchNonHeteroSubAgent } from '@/store/chat/slices/aiChat/actions/nonHeteroSubAgentDispatcher';
+import { dispatchNonHeteroSubAgent } from '@/store/chat/slices/agentRun/actions/dispatch/nonHeteroSubAgentDispatcher';
import { dbMessageSelectors } from '@/store/chat/slices/message/selectors';
import { messageMapKey } from '@/store/chat/utils/messageMapKey';
diff --git a/src/features/Conversation/store/slices/generation/action.test.ts b/src/features/Conversation/store/slices/generation/action.test.ts
index 89c60e808c9..88dbc4c7ea4 100644
--- a/src/features/Conversation/store/slices/generation/action.test.ts
+++ b/src/features/Conversation/store/slices/generation/action.test.ts
@@ -4,8 +4,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { messageService } from '@/services/message';
import { agentSelectors } from '@/store/agent/selectors';
-import * as agentDispatcher from '@/store/chat/slices/aiChat/actions/agentDispatcher';
-import * as heterogeneousAgentExecutor from '@/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor';
+import * as agentDispatcher from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
+import * as heterogeneousAgentExecutor from '@/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor';
import { INPUT_LOADING_OPERATION_TYPES } from '@/store/chat/slices/operation/types';
import { type ConversationContext, type ConversationHooks } from '../../../types';
diff --git a/src/features/Conversation/store/slices/generation/action.ts b/src/features/Conversation/store/slices/generation/action.ts
index 13f50633424..e32f6e0428a 100644
--- a/src/features/Conversation/store/slices/generation/action.ts
+++ b/src/features/Conversation/store/slices/generation/action.ts
@@ -15,13 +15,13 @@ import { getAgentStoreState } from '@/store/agent';
import { agentByIdSelectors, agentSelectors } from '@/store/agent/selectors';
import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
-import { selectRuntimeType } from '@/store/chat/slices/aiChat/actions/agentDispatcher';
+import { selectRuntimeType } from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
import {
parseMentionedAgentsFromEditorData,
parseSelectedSkillsFromEditorData,
parseSelectedToolsFromEditorData,
-} from '@/store/chat/slices/aiChat/actions/commandBus';
-import { resolveHeteroResume } from '@/store/chat/slices/aiChat/actions/heteroResume';
+} from '@/store/chat/slices/agentRun/actions/entries/commandBus';
+import { resolveHeteroResume } from '@/store/chat/slices/agentRun/actions/transports/hetero/heteroResume';
import { operationSelectors } from '@/store/chat/slices/operation/selectors';
import { INPUT_LOADING_OPERATION_TYPES } from '@/store/chat/slices/operation/types';
import {
@@ -156,7 +156,7 @@ const runHeterogeneousFromExistingMessage = async (
try {
const { executeHeterogeneousAgent } =
- await import('@/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor');
+ await import('@/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor');
await executeHeterogeneousAgent(() => useChatStore.getState(), {
assistantMessageId: assistantMsg.id,
context,
diff --git a/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts b/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts
index 81d0bbf6bda..ede9152d4d5 100644
--- a/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts
+++ b/src/features/Conversation/store/slices/generation/regenerateHeteroImages.test.ts
@@ -11,15 +11,18 @@ import { createStore } from '../../index';
// is regenerate silently dropping image attachments (the send path forwards
// them; this path must too).
const mockExecuteHeterogeneousAgent = vi.fn();
-vi.mock('@/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor', () => ({
- executeHeterogeneousAgent: (...args: any[]) => mockExecuteHeterogeneousAgent(...args),
-}));
-
-vi.mock('@/store/chat/slices/aiChat/actions/agentDispatcher', () => ({
+vi.mock(
+ '@/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor',
+ () => ({
+ executeHeterogeneousAgent: (...args: any[]) => mockExecuteHeterogeneousAgent(...args),
+ }),
+);
+
+vi.mock('@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher', () => ({
selectRuntimeType: () => 'hetero',
}));
-vi.mock('@/store/chat/slices/aiChat/actions/heteroResume', () => ({
+vi.mock('@/store/chat/slices/agentRun/actions/transports/hetero/heteroResume', () => ({
resolveHeteroResume: () => ({ cwdChanged: false, resumeSessionId: 'sess-1' }),
}));
diff --git a/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx b/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
index a0ea5a38887..ba3f181f0da 100644
--- a/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
+++ b/src/routes/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
@@ -14,7 +14,7 @@ import WideScreenContainer from '@/features/WideScreenContainer';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
import { useChatStore } from '@/store/chat';
-import { aiChatSelectors } from '@/store/chat/selectors';
+import { agentRunSelectors } from '@/store/chat/selectors';
import MessageFromUrl from './MessageFromUrl';
import { useSendMenuItems } from './useSendMenuItems';
@@ -36,7 +36,7 @@ const Desktop = memo((props: { targetMemberId?: string }) => {
const isGroupConfigLoading = useAgentGroupStore(agentGroupSelectors.isGroupsInit);
const [mainInputSendErrorMsg, clearSendMessageError] = useChatStore((s) => [
- aiChatSelectors.isCurrentSendMessageError(s),
+ agentRunSelectors.isCurrentSendMessageError(s),
s.clearSendMessageError,
]);
diff --git a/src/store/chat/initialState.ts b/src/store/chat/initialState.ts
index 12137bf9378..0169929e232 100644
--- a/src/store/chat/initialState.ts
+++ b/src/store/chat/initialState.ts
@@ -1,8 +1,8 @@
// sort-imports-ignore
+import { type ChatAIChatState } from './slices/agentRun/initialState';
+import { initialAiChatState } from './slices/agentRun/initialState';
import { type ChatAIAgentState } from './slices/aiAgent/initialState';
import { initialAiAgentState } from './slices/aiAgent/initialState';
-import { type ChatAIChatState } from './slices/aiChat/initialState';
-import { initialAiChatState } from './slices/aiChat/initialState';
import { type ChatToolState } from './slices/builtinTool/initialState';
import { initialToolState } from './slices/builtinTool/initialState';
import { type ChatMessageState } from './slices/message/initialState';
diff --git a/src/store/chat/selectors.ts b/src/store/chat/selectors.ts
index 55b34bc79a9..85c9b6b56e4 100644
--- a/src/store/chat/selectors.ts
+++ b/src/store/chat/selectors.ts
@@ -1,4 +1,4 @@
-export { aiChatSelectors } from './slices/aiChat/selectors';
+export { agentRunSelectors } from './slices/agentRun/selectors';
export { chatToolSelectors } from './slices/builtinTool/selectors';
export * from './slices/message/selectors';
export * from './slices/operation/selectors';
diff --git a/src/store/chat/slices/aiChat/__tests__/ai-chat.integration.test.ts b/src/store/chat/slices/agentRun/__tests__/ai-chat.integration.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/__tests__/ai-chat.integration.test.ts
rename to src/store/chat/slices/agentRun/__tests__/ai-chat.integration.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/agentDispatcher.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/agentDispatcher.test.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/__tests__/agentDispatcher.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/agentDispatcher.test.ts
index 6887480e7e4..1bf3b9d0f7d 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/agentDispatcher.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/agentDispatcher.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { selectRuntimeType } from '../agentDispatcher';
+import { selectRuntimeType } from '../dispatch/agentDispatcher';
const heteroProvider = { command: 'claude', type: 'claude-code' as const };
const remoteHeteroProvider = { type: 'openclaw' as const };
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/cancel-functionality.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/cancel-functionality.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/__tests__/cancel-functionality.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/cancel-functionality.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/clientToolExecution.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/clientToolExecution.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/clientToolExecution.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/clientToolExecution.test.ts
index 9604ce9913d..a7080519fc0 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/clientToolExecution.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/clientToolExecution.test.ts
@@ -1,7 +1,7 @@
import type { ToolExecuteData } from '@lobechat/agent-gateway-client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { ClientToolExecutionActionImpl } from '../clientToolExecution';
+import { ClientToolExecutionActionImpl } from '../transports/client/clientToolExecution';
// ─── Hoisted mocks ───
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/conversationControl.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/__tests__/conversationControl.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/conversationLifecycle.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/conversationLifecycle.test.ts
index 05cf5cc224e..d1a4c814c70 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/conversationLifecycle.test.ts
@@ -38,7 +38,7 @@ vi.mock('@lobechat/const', async (importOriginal) => {
};
});
-vi.mock('../heterogeneousAgentExecutor', () => ({
+vi.mock('../transports/hetero/heterogeneousAgentExecutor', () => ({
executeHeterogeneousAgent: (...args: any[]) => executeHeterogeneousAgentMock(...args),
}));
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts b/src/store/chat/slices/agentRun/actions/__tests__/fixtures.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/fixtures.ts
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/gateway.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/gateway.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
index 675d4f7c883..897432b7a5f 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/gateway.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/gateway.test.ts
@@ -5,8 +5,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type * as ConstVersion from '@/const/version';
import { aiAgentService } from '@/services/aiAgent';
-import type { GatewayConnection } from '../gateway';
-import { GatewayActionImpl } from '../gateway';
+import type { GatewayConnection } from '../transports/gateway/gateway';
+import { GatewayActionImpl } from '../transports/gateway/gateway';
vi.mock('@/services/aiAgent', () => ({
aiAgentService: {
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/gatewayEventHandler.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/gatewayEventHandler.test.ts
index 1e83fd093d9..238709c1ba9 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/gatewayEventHandler.test.ts
@@ -2,11 +2,11 @@ import type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { messageService } from '@/services/message';
-import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/aiChat/actions/agentSignalBridge';
+import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge';
import { notifyDesktopHumanApprovalRequired } from '@/store/chat/utils/desktopNotification';
-import { createGatewayEventHandler } from '../gatewayEventHandler';
-import { buildRunLifecycle } from '../runLifecycle/buildRunLifecycle';
+import { buildRunLifecycle } from '../lifecycle/buildRunLifecycle';
+import { createGatewayEventHandler } from '../transports/gateway/gatewayEventHandler';
vi.mock('@/services/message', () => ({
messageService: {
@@ -17,7 +17,7 @@ vi.mock('@/services/message', () => ({
vi.mock('@/store/chat/utils/desktopNotification', () => ({
notifyDesktopHumanApprovalRequired: vi.fn().mockResolvedValue(undefined),
}));
-vi.mock('@/store/chat/slices/aiChat/actions/agentSignalBridge', () => ({
+vi.mock('@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge', () => ({
emitClientAgentSignalSourceEvent: vi.fn().mockResolvedValue(undefined),
}));
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/helpers.ts b/src/store/chat/slices/agentRun/actions/__tests__/helpers.ts
similarity index 97%
rename from src/store/chat/slices/aiChat/actions/__tests__/helpers.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/helpers.ts
index 45622a2842a..58c5faacedd 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/helpers.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/helpers.ts
@@ -6,7 +6,7 @@ import { agentChatConfigSelectors, agentSelectors } from '@/store/agent/selector
import { useChatStore } from '../../../../store';
import { messageMapKey } from '../../../../utils/messageMapKey';
-import { createMockAgentConfig, createMockChatConfig,TEST_IDS } from './fixtures';
+import { createMockAgentConfig, createMockChatConfig, TEST_IDS } from './fixtures';
/**
* Setup mock selectors with default or custom values
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/heteroResume.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/heteroResume.test.ts
similarity index 97%
rename from src/store/chat/slices/aiChat/actions/__tests__/heteroResume.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/heteroResume.test.ts
index 2e2c03bd640..54704aa2b12 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/heteroResume.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/heteroResume.test.ts
@@ -1,7 +1,7 @@
import type { ChatTopicMetadata } from '@lobechat/types';
import { describe, expect, it } from 'vitest';
-import { resolveHeteroResume } from '../heteroResume';
+import { resolveHeteroResume } from '../transports/hetero/heteroResume';
describe('resolveHeteroResume', () => {
it('resumes when saved cwd matches current cwd', () => {
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts
index b4b40243767..419b2019d7e 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/heterogeneousAgentExecutor.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/heterogeneousAgentExecutor.test.ts
@@ -20,9 +20,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { useChatStore } from '@/store/chat/store';
-import { createGatewayEventHandler } from '../gatewayEventHandler';
-import type { HeterogeneousAgentExecutorParams } from '../heterogeneousAgentExecutor';
-import { executeHeterogeneousAgent } from '../heterogeneousAgentExecutor';
+import { createGatewayEventHandler } from '../transports/gateway/gatewayEventHandler';
+import type { HeterogeneousAgentExecutorParams } from '../transports/hetero/heterogeneousAgentExecutor';
+import { executeHeterogeneousAgent } from '../transports/hetero/heterogeneousAgentExecutor';
// ─── Mocks ───
@@ -69,7 +69,7 @@ vi.mock('@/services/electron/heterogeneousAgent', () => ({
}));
// Gateway event handler β€” we spy on it but let it run (it calls getMessages)
-vi.mock('../gatewayEventHandler', () => ({
+vi.mock('../transports/gateway/gatewayEventHandler', () => ({
createGatewayEventHandler: vi.fn(() => vi.fn()),
}));
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
index 715adcac7bd..6b105430a8b 100644
--- a/src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
@@ -91,7 +91,7 @@ const createMockRuntimeState = (operationId: string, status: AgentState['status'
// Keep zustand mock as it's needed globally
vi.mock('zustand/traditional');
-vi.mock('@/store/chat/slices/aiChat/actions/agentSignalBridge', () => ({
+vi.mock('@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge', () => ({
emitClientAgentSignalSourceEvent: agentSignalBridgeMock.emitClientAgentSignalSourceEvent,
}));
// Desktop notification gating: isDesktop defaults to false (web/test env), matching
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/streamingStates.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/streamingStates.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/__tests__/streamingStates.test.ts
rename to src/store/chat/slices/agentRun/actions/__tests__/streamingStates.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/agentDispatcher.ts b/src/store/chat/slices/agentRun/actions/dispatch/agentDispatcher.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/agentDispatcher.ts
rename to src/store/chat/slices/agentRun/actions/dispatch/agentDispatcher.ts
diff --git a/src/store/chat/slices/aiChat/actions/nonHeteroSubAgentDispatcher.ts b/src/store/chat/slices/agentRun/actions/dispatch/nonHeteroSubAgentDispatcher.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/nonHeteroSubAgentDispatcher.ts
rename to src/store/chat/slices/agentRun/actions/dispatch/nonHeteroSubAgentDispatcher.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/editorDataHelpers.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/editorDataHelpers.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/editorDataHelpers.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/editorDataHelpers.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/handlers.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/handlers.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/handlers.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/handlers.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/index.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/index.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/index.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/index.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/parseCommands.test.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/parseCommands.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/parseCommands.test.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/parseCommands.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/parseCommands.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/parseCommands.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/parseCommands.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/parseCommands.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/processCommands.test.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/processCommands.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/processCommands.test.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/processCommands.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/commandBus/types.ts b/src/store/chat/slices/agentRun/actions/entries/commandBus/types.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/commandBus/types.ts
rename to src/store/chat/slices/agentRun/actions/entries/commandBus/types.ts
diff --git a/src/store/chat/slices/aiChat/actions/conversationControl.ts b/src/store/chat/slices/agentRun/actions/entries/conversationControl.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/conversationControl.ts
rename to src/store/chat/slices/agentRun/actions/entries/conversationControl.ts
index 21cf2dedb32..c03147402f0 100644
--- a/src/store/chat/slices/aiChat/actions/conversationControl.ts
+++ b/src/store/chat/slices/agentRun/actions/entries/conversationControl.ts
@@ -9,21 +9,21 @@ import {
import { getAgentStoreState } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
+import { displayMessageSelectors } from '@/store/chat/selectors';
import {
type AgentRuntimeType,
selectRuntimeType,
-} from '@/store/chat/slices/aiChat/actions/agentDispatcher';
+} from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
+import { type OptimisticUpdateContext } from '@/store/chat/slices/message/actions/optimisticUpdate';
+import { dbMessageSelectors } from '@/store/chat/slices/message/selectors';
import { operationSelectors } from '@/store/chat/slices/operation/selectors';
import { AI_RUNTIME_OPERATION_TYPES } from '@/store/chat/slices/operation/types';
import { type ChatStore } from '@/store/chat/store';
+import { messageMapKey } from '@/store/chat/utils/messageMapKey';
import { type StoreSetter } from '@/store/types';
-import { displayMessageSelectors } from '../../../selectors';
-import { messageMapKey } from '../../../utils/messageMapKey';
-import { type OptimisticUpdateContext } from '../../message/actions/optimisticUpdate';
-import { dbMessageSelectors } from '../../message/selectors';
-import { buildRunLifecycle } from './runLifecycle/buildRunLifecycle';
-import { type RunScope } from './runLifecycle/types';
+import { buildRunLifecycle } from '../lifecycle/buildRunLifecycle';
+import { type RunScope } from '../lifecycle/types';
/**
* Actions for controlling conversation operations like cancellation and error handling
diff --git a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts b/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/conversationLifecycle.ts
rename to src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
index c6d991125e8..7b9282edb9f 100644
--- a/src/store/chat/slices/aiChat/actions/conversationLifecycle.ts
+++ b/src/store/chat/slices/agentRun/actions/entries/conversationLifecycle.ts
@@ -37,11 +37,17 @@ import {
chatConfigByIdSelectors,
} from '@/store/agent/selectors';
import { agentGroupByIdSelectors, getChatGroupStoreState } from '@/store/agentGroup';
-import { selectRuntimeType } from '@/store/chat/slices/aiChat/actions/agentDispatcher';
-import { resolveHeteroResume } from '@/store/chat/slices/aiChat/actions/heteroResume';
-import { dispatchNonHeteroSubAgent } from '@/store/chat/slices/aiChat/actions/nonHeteroSubAgentDispatcher';
-import { buildRunLifecycle } from '@/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle';
-import type { RunScope } from '@/store/chat/slices/aiChat/actions/runLifecycle/types';
+import {
+ dbMessageSelectors,
+ displayMessageSelectors,
+ topicSelectors,
+} from '@/store/chat/selectors';
+import { selectRuntimeType } from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
+import { dispatchNonHeteroSubAgent } from '@/store/chat/slices/agentRun/actions/dispatch/nonHeteroSubAgentDispatcher';
+import { buildRunLifecycle } from '@/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle';
+import type { RunScope } from '@/store/chat/slices/agentRun/actions/lifecycle/types';
+import { resolveHeteroResume } from '@/store/chat/slices/agentRun/actions/transports/hetero/heteroResume';
+import { AI_RUNTIME_OPERATION_TYPES, type QueuedFile } from '@/store/chat/slices/operation/types';
import { PortalViewType } from '@/store/chat/slices/portal/initialState';
import { chatPortalSelectors } from '@/store/chat/slices/portal/selectors';
import { type ChatStore } from '@/store/chat/store';
@@ -54,6 +60,8 @@ import {
getCompressionCandidateMessageIds,
hasRunningCompressionOperation,
} from '@/store/chat/utils/compression';
+import { messageMapKey } from '@/store/chat/utils/messageMapKey';
+import { topicMapKey } from '@/store/chat/utils/topicMapKey';
import { getElectronStoreState } from '@/store/electron';
import { useGlobalStore } from '@/store/global';
import { systemStatusSelectors } from '@/store/global/selectors';
@@ -62,10 +70,7 @@ 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';
-import { topicMapKey } from '../../../utils/topicMapKey';
-import { AI_RUNTIME_OPERATION_TYPES, type QueuedFile } from '../../operation/types';
+import { materializeLocalSystemToolSnapshots } from '../transports/client/localSystemToolSnapshots';
import type { CommandSendOverrides, SingleAgentMentionDirectRoute } from './commandBus';
import {
hasNonActionContent,
@@ -78,7 +83,6 @@ import {
parseSingleAgentMentionDirectRoute,
processCommands,
} from './commandBus';
-import { materializeLocalSystemToolSnapshots } from './localSystemToolSnapshots';
/**
* Extended params for sendMessage with context
*/
@@ -699,7 +703,8 @@ export class ConversationLifecycleActionImpl {
this.#get().associateMessageWithOperation(heteroData.assistantMessageId, heteroOpId);
try {
- const { executeHeterogeneousAgent } = await import('./heterogeneousAgentExecutor');
+ const { executeHeterogeneousAgent } =
+ await import('../transports/hetero/heterogeneousAgentExecutor');
// 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);
diff --git a/src/store/chat/slices/agentRun/actions/index.ts b/src/store/chat/slices/agentRun/actions/index.ts
new file mode 100644
index 00000000000..4945476cafd
--- /dev/null
+++ b/src/store/chat/slices/agentRun/actions/index.ts
@@ -0,0 +1,47 @@
+import { type StateCreator } from 'zustand/vanilla';
+
+import { type ChatStore } from '@/store/chat/store';
+import { flattenActions } from '@/store/utils/flattenActions';
+
+import { type ConversationControlAction } from './entries/conversationControl';
+import { ConversationControlActionImpl } from './entries/conversationControl';
+import { type ConversationLifecycleAction } from './entries/conversationLifecycle';
+import { ConversationLifecycleActionImpl } from './entries/conversationLifecycle';
+import { type ChatMemoryAction } from './state/memory';
+import { ChatMemoryActionImpl } from './state/memory';
+import { type StreamingStatesAction } from './state/streamingStates';
+import { StreamingStatesActionImpl } from './state/streamingStates';
+import { type ClientToolExecutionAction } from './transports/client/clientToolExecution';
+import { ClientToolExecutionActionImpl } from './transports/client/clientToolExecution';
+import { type StreamingExecutorAction } from './transports/client/streamingExecutor';
+import { StreamingExecutorActionImpl } from './transports/client/streamingExecutor';
+import { type GatewayAction } from './transports/gateway/gateway';
+import { GatewayActionImpl } from './transports/gateway/gateway';
+
+export type ChatAgentRunAction = ChatMemoryAction &
+ ClientToolExecutionAction &
+ ConversationLifecycleAction &
+ ConversationControlAction &
+ GatewayAction &
+ StreamingExecutorAction &
+ StreamingStatesAction;
+
+export const chatAgentRun: StateCreator<
+ ChatStore,
+ [['zustand/devtools', never]],
+ [],
+ ChatAgentRunAction
+> = (
+ ...params: Parameters<
+ StateCreator<ChatStore, [['zustand/devtools', never]], [], ChatAgentRunAction>
+ >
+) =>
+ flattenActions<ChatAgentRunAction>([
+ new ChatMemoryActionImpl(...params),
+ new ClientToolExecutionActionImpl(...params),
+ new ConversationLifecycleActionImpl(...params),
+ new ConversationControlActionImpl(...params),
+ new GatewayActionImpl(...params),
+ new StreamingExecutorActionImpl(...params),
+ new StreamingStatesActionImpl(...params),
+ ]);
diff --git a/src/store/chat/slices/aiChat/actions/agentSignalBridge.test.ts b/src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.test.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/agentSignalBridge.test.ts
rename to src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.test.ts
diff --git a/src/store/chat/slices/aiChat/actions/agentSignalBridge.ts b/src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/agentSignalBridge.ts
rename to src/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge.ts
diff --git a/src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.test.ts b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.test.ts
rename to src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
index d1a79c011c7..5cf662db026 100644
--- a/src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.test.ts
+++ b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.test.ts
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { ChatStore } from '@/store/chat/store';
-import type { AgentRuntimeType } from '../agentDispatcher';
+import type { AgentRuntimeType } from '../dispatch/agentDispatcher';
import { buildRunLifecycle } from './buildRunLifecycle';
import type { RunCompleteEvent, RunTerminalStatus, UserMessagePersistedEvent } from './types';
@@ -11,7 +11,7 @@ const agentSignalBridgeMock = vi.hoisted(() => ({
emitClientAgentSignalSourceEvent: vi.fn().mockResolvedValue(undefined),
}));
-vi.mock('@/store/chat/slices/aiChat/actions/agentSignalBridge', () => ({
+vi.mock('@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge', () => ({
emitClientAgentSignalSourceEvent: agentSignalBridgeMock.emitClientAgentSignalSourceEvent,
}));
diff --git a/src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.ts b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.ts
rename to src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
index 60111bc5fb0..64ff60623b7 100644
--- a/src/store/chat/slices/aiChat/actions/runLifecycle/buildRunLifecycle.ts
+++ b/src/store/chat/slices/agentRun/actions/lifecycle/buildRunLifecycle.ts
@@ -6,8 +6,8 @@ import { t } from 'i18next';
import { getAgentStoreState } from '@/store/agent';
import { agentSelectors } from '@/store/agent/selectors';
-import type { AgentRuntimeType } from '@/store/chat/slices/aiChat/actions/agentDispatcher';
-import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/aiChat/actions/agentSignalBridge';
+import type { AgentRuntimeType } from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
+import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge';
import type { ChatStore } from '@/store/chat/store';
import { resolveNotificationNavigatePath } from '@/store/chat/utils/desktopNotification';
import { markdownToTxt } from '@/utils/markdownToTxt';
diff --git a/src/store/chat/slices/aiChat/actions/runLifecycle/types.ts b/src/store/chat/slices/agentRun/actions/lifecycle/types.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/runLifecycle/types.ts
rename to src/store/chat/slices/agentRun/actions/lifecycle/types.ts
index 08705787a25..d39e250bfab 100644
--- a/src/store/chat/slices/aiChat/actions/runLifecycle/types.ts
+++ b/src/store/chat/slices/agentRun/actions/lifecycle/types.ts
@@ -1,7 +1,7 @@
import type { AgentState } from '@lobechat/agent-runtime';
import type { ConversationContext, UIChatMessage } from '@lobechat/types';
-import type { AgentRuntimeType } from '@/store/chat/slices/aiChat/actions/agentDispatcher';
+import type { AgentRuntimeType } from '@/store/chat/slices/agentRun/actions/dispatch/agentDispatcher';
import type { OperationStatus } from '@/store/chat/slices/operation/types';
/**
diff --git a/src/store/chat/slices/aiChat/actions/memory.ts b/src/store/chat/slices/agentRun/actions/state/memory.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/memory.ts
rename to src/store/chat/slices/agentRun/actions/state/memory.ts
diff --git a/src/store/chat/slices/aiChat/actions/streamingStates.ts b/src/store/chat/slices/agentRun/actions/state/streamingStates.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/streamingStates.ts
rename to src/store/chat/slices/agentRun/actions/state/streamingStates.ts
diff --git a/src/store/chat/slices/aiChat/actions/clientToolExecution.ts b/src/store/chat/slices/agentRun/actions/transports/client/clientToolExecution.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/clientToolExecution.ts
rename to src/store/chat/slices/agentRun/actions/transports/client/clientToolExecution.ts
diff --git a/src/store/chat/slices/aiChat/actions/localSystemToolSnapshots.ts b/src/store/chat/slices/agentRun/actions/transports/client/localSystemToolSnapshots.ts
similarity index 97%
rename from src/store/chat/slices/aiChat/actions/localSystemToolSnapshots.ts
rename to src/store/chat/slices/agentRun/actions/transports/client/localSystemToolSnapshots.ts
index e46fcab08a2..b6f49e7b4c2 100644
--- a/src/store/chat/slices/aiChat/actions/localSystemToolSnapshots.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/client/localSystemToolSnapshots.ts
@@ -6,7 +6,7 @@ import { nanoid } from 'nanoid';
import { localFileService } from '@/services/electron/localFileService';
-import type { ParsedLocalFileReference } from './commandBus/parseCommands';
+import type { ParsedLocalFileReference } from '../../entries/commandBus/parseCommands';
const DEFAULT_DIRECTORY_LIMIT = 100;
diff --git a/src/store/chat/slices/aiChat/actions/streamingExecutor.ts b/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/actions/streamingExecutor.ts
rename to src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
index 6a31360fc03..f15f8ec7df1 100644
--- a/src/store/chat/slices/aiChat/actions/streamingExecutor.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/client/streamingExecutor.ts
@@ -39,9 +39,16 @@ import { agentSelectors } from '@/store/agent/selectors';
import { aiModelSelectors } from '@/store/aiInfra/selectors';
import { getAiInfraStoreState } from '@/store/aiInfra/store';
import { createAgentExecutors } from '@/store/chat/agents/createAgentExecutors';
-import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/aiChat/actions/agentSignalBridge';
+import { topicSelectors } from '@/store/chat/selectors';
+import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge';
+import {
+ selectActivatedSkillsFromMessages,
+ selectActivatedToolIdsFromMessages,
+ selectTodosFromMessages,
+} from '@/store/chat/slices/message/selectors/dbMessage';
import { type ChatStore } from '@/store/chat/store';
import { notifyDesktopHumanApprovalRequired } from '@/store/chat/utils/desktopNotification';
+import { messageMapKey } from '@/store/chat/utils/messageMapKey';
import { getElectronStoreState } from '@/store/electron';
import { getServerConfigStoreState, serverConfigSelectors } from '@/store/serverConfig';
import { getTaskStoreState } from '@/store/task';
@@ -50,15 +57,8 @@ import { type StoreSetter } from '@/store/types';
import { toolInterventionSelectors } from '@/store/user/selectors';
import { getUserStoreState } from '@/store/user/store';
-import { topicSelectors } from '../../../selectors';
-import { messageMapKey } from '../../../utils/messageMapKey';
-import {
- selectActivatedSkillsFromMessages,
- selectActivatedToolIdsFromMessages,
- selectTodosFromMessages,
-} from '../../message/selectors/dbMessage';
-import { buildRunLifecycle } from './runLifecycle/buildRunLifecycle';
-import type { RunParkedReason, RunScope } from './runLifecycle/types';
+import { buildRunLifecycle } from '../../lifecycle/buildRunLifecycle';
+import type { RunParkedReason, RunScope } from '../../lifecycle/types';
const log = debug('lobe-store:streaming-executor');
diff --git a/src/store/chat/slices/aiChat/actions/gateway.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/gateway.ts
rename to src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
index eafa4a18821..59a079b19b0 100644
--- a/src/store/chat/slices/aiChat/actions/gateway.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
@@ -20,9 +20,9 @@ import type { StoreSetter } from '@/store/types';
import { useUserStore } from '@/store/user';
import { settingsSelectors } from '@/store/user/selectors';
+import { buildRunLifecycle } from '../../lifecycle/buildRunLifecycle';
+import type { RunScope } from '../../lifecycle/types';
import { createGatewayEventHandler, isCompletedRuntimeEnd } from './gatewayEventHandler';
-import { buildRunLifecycle } from './runLifecycle/buildRunLifecycle';
-import type { RunScope } from './runLifecycle/types';
/**
* When the agent runs against the local machine, resolve this desktop's
diff --git a/src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts
rename to src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts
index 8a48ac25284..fb05a387f66 100644
--- a/src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gatewayEventHandler.ts
@@ -17,11 +17,11 @@ import { AgentRuntimeErrorType } from '@lobechat/types';
import { isRecord, pickNonEmptyString, toRecord } from '@lobechat/utils/object';
import { messageService } from '@/services/message';
-import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/aiChat/actions/agentSignalBridge';
+import { emitClientAgentSignalSourceEvent } from '@/store/chat/slices/agentRun/actions/lifecycle/agentSignalBridge';
import type {
AgentRunLifecycle,
RunScope,
-} from '@/store/chat/slices/aiChat/actions/runLifecycle/types';
+} from '@/store/chat/slices/agentRun/actions/lifecycle/types';
import type { ChatStore } from '@/store/chat/store';
import { notifyDesktopHumanApprovalRequired } from '@/store/chat/utils/desktopNotification';
diff --git a/src/store/chat/slices/aiChat/actions/heteroResume.ts b/src/store/chat/slices/agentRun/actions/transports/hetero/heteroResume.ts
similarity index 100%
rename from src/store/chat/slices/aiChat/actions/heteroResume.ts
rename to src/store/chat/slices/agentRun/actions/transports/hetero/heteroResume.ts
diff --git a/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts b/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts
similarity index 99%
rename from src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts
rename to src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts
index 9909fadebba..dbcc5f28bee 100644
--- a/src/store/chat/slices/aiChat/actions/heterogeneousAgentExecutor.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/hetero/heterogeneousAgentExecutor.ts
@@ -34,14 +34,17 @@ import { message as antdMessage } from '@/components/AntdStaticMethods';
import { heterogeneousAgentService } from '@/services/electron/heterogeneousAgent';
import { messageService } from '@/services/message';
import { threadService } from '@/services/thread';
+import {
+ mergeQueuedMessages,
+ reconstructUploadFilesFromQueue,
+} from '@/store/chat/slices/operation/types';
import { type ChatStore, useChatStore } from '@/store/chat/store';
+import { messageMapKey } from '@/store/chat/utils/messageMapKey';
import { markdownToTxt } from '@/utils/markdownToTxt';
-import { messageMapKey } from '../../../utils/messageMapKey';
-import { mergeQueuedMessages, reconstructUploadFilesFromQueue } from '../../operation/types';
-import { createGatewayEventHandler } from './gatewayEventHandler';
-import { buildRunLifecycle } from './runLifecycle/buildRunLifecycle';
-import type { RunScope } from './runLifecycle/types';
+import { buildRunLifecycle } from '../../lifecycle/buildRunLifecycle';
+import type { RunScope } from '../../lifecycle/types';
+import { createGatewayEventHandler } from '../gateway/gatewayEventHandler';
/** Mirrors `idGenerator('threads', 16)` on the server so sync-allocated ids have the same shape. */
const generateThreadId = () => `thd_${createNanoId(16)()}`;
diff --git a/src/store/chat/slices/aiChat/initialState.ts b/src/store/chat/slices/agentRun/initialState.ts
similarity index 91%
rename from src/store/chat/slices/aiChat/initialState.ts
rename to src/store/chat/slices/agentRun/initialState.ts
index f94140e9bae..95047f7b695 100644
--- a/src/store/chat/slices/aiChat/initialState.ts
+++ b/src/store/chat/slices/agentRun/initialState.ts
@@ -1,5 +1,5 @@
import { type ChatInputEditor } from '@/features/ChatInput';
-import type { GatewayConnection } from '@/store/chat/slices/aiChat/actions/gateway';
+import type { GatewayConnection } from '@/store/chat/slices/agentRun/actions/transports/gateway/gateway';
export interface ChatAIChatState {
/**
diff --git a/src/store/chat/slices/aiChat/selectors.test.ts b/src/store/chat/slices/agentRun/selectors.test.ts
similarity index 79%
rename from src/store/chat/slices/aiChat/selectors.test.ts
rename to src/store/chat/slices/agentRun/selectors.test.ts
index 41ac89227d7..e66441c6a79 100644
--- a/src/store/chat/slices/aiChat/selectors.test.ts
+++ b/src/store/chat/slices/agentRun/selectors.test.ts
@@ -3,9 +3,9 @@ import { beforeEach, describe, expect, it } from 'vitest';
import { useChatStore } from '@/store/chat/store';
-import { aiChatSelectors } from './selectors';
+import { agentRunSelectors } from './selectors';
-describe('aiChatSelectors', () => {
+describe('agentRunSelectors', () => {
beforeEach(() => {
useChatStore.setState(useChatStore.getInitialState());
});
@@ -22,13 +22,13 @@ describe('aiChatSelectors', () => {
});
});
- expect(aiChatSelectors.isMessageInReasoning('msg1')(result.current)).toBe(true);
+ expect(agentRunSelectors.isMessageInReasoning('msg1')(result.current)).toBe(true);
});
it('should return false when message has no reasoning operation', () => {
const { result } = renderHook(() => useChatStore());
- expect(aiChatSelectors.isMessageInReasoning('msg1')(result.current)).toBe(false);
+ expect(agentRunSelectors.isMessageInReasoning('msg1')(result.current)).toBe(false);
});
});
@@ -40,8 +40,8 @@ describe('aiChatSelectors', () => {
useChatStore.setState({ searchWorkflowLoadingIds: ['msg1', 'msg2'] });
});
- expect(aiChatSelectors.isMessageInSearchWorkflow('msg1')(result.current)).toBe(true);
- expect(aiChatSelectors.isMessageInSearchWorkflow('msg2')(result.current)).toBe(true);
+ expect(agentRunSelectors.isMessageInSearchWorkflow('msg1')(result.current)).toBe(true);
+ expect(agentRunSelectors.isMessageInSearchWorkflow('msg2')(result.current)).toBe(true);
});
it('should return false when message is not in search workflow', () => {
@@ -51,7 +51,7 @@ describe('aiChatSelectors', () => {
useChatStore.setState({ searchWorkflowLoadingIds: ['msg1'] });
});
- expect(aiChatSelectors.isMessageInSearchWorkflow('msg2')(result.current)).toBe(false);
+ expect(agentRunSelectors.isMessageInSearchWorkflow('msg2')(result.current)).toBe(false);
});
});
@@ -63,13 +63,13 @@ describe('aiChatSelectors', () => {
useChatStore.setState({ searchWorkflowLoadingIds: ['msg1'] });
});
- expect(aiChatSelectors.isIntentUnderstanding('msg1')(result.current)).toBe(true);
+ expect(agentRunSelectors.isIntentUnderstanding('msg1')(result.current)).toBe(true);
});
it('should return false when message is not in search workflow', () => {
const { result } = renderHook(() => useChatStore());
- expect(aiChatSelectors.isIntentUnderstanding('msg1')(result.current)).toBe(false);
+ expect(agentRunSelectors.isIntentUnderstanding('msg1')(result.current)).toBe(false);
});
});
@@ -85,7 +85,7 @@ describe('aiChatSelectors', () => {
});
});
- expect(aiChatSelectors.isCurrentSendMessageLoading(result.current)).toBe(true);
+ expect(agentRunSelectors.isCurrentSendMessageLoading(result.current)).toBe(true);
});
it('should return false when there is no sendMessage operation', () => {
@@ -95,7 +95,7 @@ describe('aiChatSelectors', () => {
useChatStore.setState({ activeAgentId: 'session1', activeTopicId: 'topic1' });
});
- expect(aiChatSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
+ expect(agentRunSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
});
it('should return false when sendMessage operation is completed', () => {
@@ -115,7 +115,7 @@ describe('aiChatSelectors', () => {
result.current.completeOperation(opId);
});
- expect(aiChatSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
+ expect(agentRunSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
});
it('should return false for different context', () => {
@@ -129,7 +129,7 @@ describe('aiChatSelectors', () => {
});
});
- expect(aiChatSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
+ expect(agentRunSelectors.isCurrentSendMessageLoading(result.current)).toBe(false);
});
});
@@ -153,7 +153,7 @@ describe('aiChatSelectors', () => {
});
});
- expect(aiChatSelectors.isCurrentSendMessageError(result.current)).toBe('Network error');
+ expect(agentRunSelectors.isCurrentSendMessageError(result.current)).toBe('Network error');
});
it('should return undefined when there is no error', () => {
@@ -167,7 +167,7 @@ describe('aiChatSelectors', () => {
});
});
- expect(aiChatSelectors.isCurrentSendMessageError(result.current)).toBeUndefined();
+ expect(agentRunSelectors.isCurrentSendMessageError(result.current)).toBeUndefined();
});
it('should return undefined when there are no operations', () => {
@@ -177,7 +177,7 @@ describe('aiChatSelectors', () => {
useChatStore.setState({ activeAgentId: 'session1', activeTopicId: 'topic1' });
});
- expect(aiChatSelectors.isCurrentSendMessageError(result.current)).toBeUndefined();
+ expect(agentRunSelectors.isCurrentSendMessageError(result.current)).toBeUndefined();
});
it('should return the latest error when multiple operations exist', () => {
@@ -210,7 +210,7 @@ describe('aiChatSelectors', () => {
});
// Should return the latest (second) error
- expect(aiChatSelectors.isCurrentSendMessageError(result.current)).toBe('Second error');
+ expect(agentRunSelectors.isCurrentSendMessageError(result.current)).toBe('Second error');
});
});
@@ -226,7 +226,7 @@ describe('aiChatSelectors', () => {
});
expect(
- aiChatSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
+ agentRunSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
).toBe(true);
});
@@ -234,7 +234,7 @@ describe('aiChatSelectors', () => {
const { result } = renderHook(() => useChatStore());
expect(
- aiChatSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
+ agentRunSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
).toBe(false);
});
@@ -255,7 +255,7 @@ describe('aiChatSelectors', () => {
});
expect(
- aiChatSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
+ agentRunSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
).toBe(false);
});
@@ -270,10 +270,10 @@ describe('aiChatSelectors', () => {
});
expect(
- aiChatSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
+ agentRunSelectors.isSendMessageLoadingForTopic('main_session1_topic1')(result.current),
).toBe(true);
expect(
- aiChatSelectors.isSendMessageLoadingForTopic('main_session1_topic2')(result.current),
+ agentRunSelectors.isSendMessageLoadingForTopic('main_session1_topic2')(result.current),
).toBe(false);
});
});
diff --git a/src/store/chat/slices/aiChat/selectors.ts b/src/store/chat/slices/agentRun/selectors.ts
similarity index 98%
rename from src/store/chat/slices/aiChat/selectors.ts
rename to src/store/chat/slices/agentRun/selectors.ts
index af3d8961dae..c262984eb79 100644
--- a/src/store/chat/slices/aiChat/selectors.ts
+++ b/src/store/chat/slices/agentRun/selectors.ts
@@ -48,7 +48,7 @@ const isSendMessageLoadingForTopic = (topicKey: string) => (s: ChatStoreState) =
});
};
-export const aiChatSelectors = {
+export const agentRunSelectors = {
isCurrentSendMessageError,
isCurrentSendMessageLoading,
isIntentUnderstanding,
diff --git a/src/store/chat/slices/aiChat/actions/index.ts b/src/store/chat/slices/aiChat/actions/index.ts
deleted file mode 100644
index 0255305b6b6..00000000000
--- a/src/store/chat/slices/aiChat/actions/index.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { type StateCreator } from 'zustand/vanilla';
-
-import { type ChatStore } from '@/store/chat/store';
-import { flattenActions } from '@/store/utils/flattenActions';
-
-import { type ClientToolExecutionAction } from './clientToolExecution';
-import { ClientToolExecutionActionImpl } from './clientToolExecution';
-import { type ConversationControlAction } from './conversationControl';
-import { ConversationControlActionImpl } from './conversationControl';
-import { type ConversationLifecycleAction } from './conversationLifecycle';
-import { ConversationLifecycleActionImpl } from './conversationLifecycle';
-import { type GatewayAction } from './gateway';
-import { GatewayActionImpl } from './gateway';
-import { type ChatMemoryAction } from './memory';
-import { ChatMemoryActionImpl } from './memory';
-import { type StreamingExecutorAction } from './streamingExecutor';
-import { StreamingExecutorActionImpl } from './streamingExecutor';
-import { type StreamingStatesAction } from './streamingStates';
-import { StreamingStatesActionImpl } from './streamingStates';
-
-export type ChatAIChatAction = ChatMemoryAction &
- ClientToolExecutionAction &
- ConversationLifecycleAction &
- ConversationControlAction &
- GatewayAction &
- StreamingExecutorAction &
- StreamingStatesAction;
-
-export const chatAiChat: StateCreator<
- ChatStore,
- [['zustand/devtools', never]],
- [],
- ChatAIChatAction
-> = (
- ...params: Parameters<
- StateCreator<ChatStore, [['zustand/devtools', never]], [], ChatAIChatAction>
- >
-) =>
- flattenActions<ChatAIChatAction>([
- new ChatMemoryActionImpl(...params),
- new ClientToolExecutionActionImpl(...params),
- new ConversationLifecycleActionImpl(...params),
- new ConversationControlActionImpl(...params),
- new GatewayActionImpl(...params),
- new StreamingExecutorActionImpl(...params),
- new StreamingStatesActionImpl(...params),
- ]);
diff --git a/src/store/chat/store.ts b/src/store/chat/store.ts
index e08dbcbeb9d..09ce26a2ac3 100644
--- a/src/store/chat/store.ts
+++ b/src/store/chat/store.ts
@@ -10,10 +10,10 @@ import { flattenActions } from '../utils/flattenActions';
import { type ResetableStore, ResetableStoreAction } from '../utils/resetableStore';
import { type ChatStoreState } from './initialState';
import { initialState } from './initialState';
+import { type ChatAgentRunAction } from './slices/agentRun/actions';
+import { chatAgentRun } from './slices/agentRun/actions';
import { type ChatAIAgentAction } from './slices/aiAgent/actions';
import { chatAiAgent } from './slices/aiAgent/actions';
-import { type ChatAIChatAction } from './slices/aiChat/actions';
-import { chatAiChat } from './slices/aiChat/actions';
import { type ChatBuiltinToolAction } from './slices/builtinTool/actions';
import { chatToolSlice } from './slices/builtinTool/actions';
import { type ChatMessageAction } from './slices/message/actions';
@@ -35,7 +35,7 @@ import { ChatTTSActionImpl } from './slices/tts/action';
export type ChatStoreAction = ChatMessageAction &
ChatThreadAction &
- ChatAIChatAction &
+ ChatAgentRunAction &
ChatTopicAction &
ChatTranslateAction &
ChatTTSAction &
@@ -62,7 +62,7 @@ const createStore: StateCreator<ChatStore, [['zustand/devtools', never]]> = (
...(flattenActions<ChatStoreAction>([
chatMessage(...params),
new ChatThreadActionImpl(...params),
- chatAiChat(...params),
+ chatAgentRun(...params),
new ChatTopicActionImpl(...params),
new ChatTranslateActionImpl(...params),
new ChatTTSActionImpl(...params),
diff --git a/src/store/test-coverage.md b/src/store/test-coverage.md
index dd93e68f741..8a4b6667e75 100644
--- a/src/store/test-coverage.md
+++ b/src/store/test-coverage.md
@@ -234,7 +234,7 @@ Before updating documentation, create a summary of what was accomplished:
**Example Summary:**
```
-Store: chat/slices/aiChat
+Store: chat/slices/agentRun
Coverage: 65% β†’ 82% (+17%)
Tests Added: 52 new tests
Features Tested:
@@ -577,7 +577,7 @@ bunx eslint src/store/[domain]/
### Store-Specific Notes
-- **chat/aiChat**: Complex streaming logic, requires careful mocking of chatService
+- **chat/agentRun**: Complex streaming logic, requires careful mocking of chatService
- **chat/thread**: βœ… Comprehensive tests complete (39 tests, \~80 LOC)
- **tool/mcpStore**: βœ… Comprehensive tests complete (41 tests, 624 LOC)
- **file/fileManager**: βœ… Comprehensive tests complete (35 tests, 205 LOC)