Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix:智能执行新增任务等待队列

yangzequ54ff358e2201
diff --git a/jiuwenclaw/web/src/components/ChatPanel/InputArea.tsx b/jiuwenclaw/web/src/components/ChatPanel/InputArea.tsx
index 4fb5895026..4cb5e84e5c 100644
--- a/jiuwenclaw/web/src/components/ChatPanel/InputArea.tsx
+++ b/jiuwenclaw/web/src/components/ChatPanel/InputArea.tsx
@@ -27,9 +27,10 @@ export function InputArea({
const isComposingRef = useRef(false);
const activePointerIdRef = useRef<number | null>(null);
const isVoicePressingRef = useRef(false);
- const { isPaused } = useChatStore();
+ const { isPaused, taskQueue, addToTaskQueue, removeFromTaskQueue } = useChatStore();
const { mode } = useSessionStore();
const isInterruptible = isProcessing || isPaused;
+ const isAgentMode = mode === 'agent';
const modes: Array<{ value: AgentMode; label: string; icon: JSX.Element }> = [
{ value: 'plan', label: '任务规划', icon: (
<svg className="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
@@ -107,7 +108,13 @@ export function InputArea({
}
if (isInterruptible) {
- onInterrupt(trimmed);
+ if (isAgentMode) {
+ // 智能执行模式下,将任务添加到队列
+ addToTaskQueue(trimmed);
+ } else {
+ // 其他模式下,中断当前任务
+ onInterrupt(trimmed);
+ }
} else {
onSubmit(trimmed);
}
@@ -117,7 +124,7 @@ export function InputArea({
if (textareaRef.current) {
textareaRef.current.style.height = 'auto';
}
- }, [value, pendingVoiceText, isInterruptible, isListening, onSubmit, onInterrupt, stopListening]);
+ }, [value, pendingVoiceText, isInterruptible, isListening, onSubmit, onInterrupt, stopListening, isAgentMode, addToTaskQueue]);
const handleKeyDown = useCallback(
(e: KeyboardEvent<HTMLTextAreaElement>) => {
@@ -219,6 +226,35 @@ export function InputArea({
</div>
)}
+ {/* 智能执行模式下的等待任务盒子 */}
+ {isAgentMode && taskQueue.length > 0 && (
+ <div className="chat-input-task-queue">
+ <div className="chat-input-task-queue-header">
+ <svg className="w-4 h-4 mr-2" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" />
+ </svg>
+ 等待任务 ({taskQueue.length})
+ </div>
+ <div className="chat-input-task-queue-list">
+ {taskQueue.map((task) => (
+ <div key={task.id} className="chat-input-task-item">
+ <span className="chat-input-task-content">{task.content}</span>
+ <button
+ type="button"
+ onClick={() => removeFromTaskQueue(task.id)}
+ className="chat-input-task-remove"
+ title="移除任务"
+ >
+ <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={2}>
+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </button>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+
<textarea
ref={textareaRef}
value={displayValue}
@@ -230,6 +266,8 @@ export function InputArea({
placeholder={
isListening
? '正在听取语音...'
+ : isAgentMode && isInterruptible
+ ? '处理中,输入新指令将加入等待队列...'
: isInterruptible
? '处理中,输入新指令可中断...'
: 'Enter 发送,Shift+Enter 换行,按住语音键开始录音'
diff --git a/jiuwenclaw/web/src/hooks/useWebSocket.ts b/jiuwenclaw/web/src/hooks/useWebSocket.ts
index 84b626e632..d7f7865ba4 100644
--- a/jiuwenclaw/web/src/hooks/useWebSocket.ts
+++ b/jiuwenclaw/web/src/hooks/useWebSocket.ts
@@ -178,6 +178,7 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
const onConnectRef = useRef(onConnect);
const onDisconnectRef = useRef(onDisconnect);
const onErrorRef = useRef(onError);
+ const sendMessageRef = useRef<typeof sendMessage>();
const recentEventRef = useRef<Map<string, number>>(new Map());
const eventDedupDroppedRef = useRef<Record<string, number>>({});
@@ -199,6 +200,7 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
clearSubtasks,
clearMessages,
setPendingQuestion,
+ removeFromTaskQueue,
} = useChatStore();
const { setTodos, clearTodos } = useTodoStore();
const {
@@ -346,6 +348,11 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
[addMessage, request, setProcessing, setThinking]
);
+ // 存储sendMessage函数到ref
+ useEffect(() => {
+ sendMessageRef.current = sendMessage;
+ }, [sendMessage]);
+
// 统一中断接口 - pause/cancel/supplement/resume
const interrupt = useCallback(
async (
@@ -671,6 +678,20 @@ export function useWebSocket(options: UseWebSocketOptions): UseWebSocketReturn {
if (!isProcessingNow) {
setThinking(false);
clearSubtasks();
+
+ // 检查是否有等待的任务队列
+ const currentMode = useSessionStore.getState().mode;
+ const { taskQueue } = useChatStore.getState();
+ if (currentMode === 'agent' && taskQueue.length > 0) {
+ // 智能执行模式下,自动处理队列中的下一个任务
+ const nextTask = taskQueue[0];
+ if (nextTask && activeSessionIdRef.current && sendMessageRef.current) {
+ // 从队列中移除该任务
+ removeFromTaskQueue(nextTask.id);
+ // 发送下一个任务
+ sendMessageRef.current(nextTask.content, activeSessionIdRef.current);
+ }
+ }
}
}),
webClient.on('chat.error', ({ payload }) => {
diff --git a/jiuwenclaw/web/src/index.css b/jiuwenclaw/web/src/index.css
index f1cd65d637..a11b988a4f 100644
--- a/jiuwenclaw/web/src/index.css
+++ b/jiuwenclaw/web/src/index.css
@@ -783,6 +783,74 @@ select {
white-space: pre-wrap;
}
+ /* Chat input task queue */
+ .chat-input-task-queue {
+ margin-bottom: 12px;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-md);
+ background: var(--card);
+ box-shadow: var(--shadow-sm);
+ animation: rise 0.3s var(--ease-out);
+ }
+
+ .chat-input-task-queue-header {
+ display: flex;
+ align-items: center;
+ padding: 8px 12px;
+ border-bottom: 1px solid var(--border);
+ background: var(--bg-elevated);
+ font-size: var(--font-size-sm);
+ font-weight: 500;
+ color: var(--text-strong);
+ }
+
+ .chat-input-task-queue-list {
+ max-height: 150px;
+ overflow-y: auto;
+ padding: 4px 0;
+ }
+
+ .chat-input-task-item {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 8px 12px;
+ transition: background var(--duration-fast) ease;
+ }
+
+ .chat-input-task-item:hover {
+ background: var(--bg-hover);
+ }
+
+ .chat-input-task-content {
+ flex: 1;
+ font-size: var(--font-size-sm);
+ color: var(--text);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .chat-input-task-remove {
+ flex-shrink: 0;
+ width: 20px;
+ height: 20px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border: none;
+ border-radius: var(--radius-sm);
+ background: transparent;
+ color: var(--muted);
+ cursor: pointer;
+ transition: all var(--duration-fast) ease;
+ }
+
+ .chat-input-task-remove:hover {
+ background: var(--danger-subtle);
+ color: var(--danger);
+ }
+
.chat-text :where(p) {
margin: 0.5em 0;
}
diff --git a/jiuwenclaw/web/src/stores/chatStore.ts b/jiuwenclaw/web/src/stores/chatStore.ts
index 5520f2387a..950b4a0fdd 100644
--- a/jiuwenclaw/web/src/stores/chatStore.ts
+++ b/jiuwenclaw/web/src/stores/chatStore.ts
@@ -40,6 +40,12 @@ export interface SubtaskState {
is_parallel: boolean;
}
+interface TaskItem {
+ id: string;
+ content: string;
+ timestamp: number;
+}
+
interface ChatState {
messages: Message[];
isProcessing: boolean;
@@ -58,6 +64,8 @@ interface ChatState {
toolCallDedupDropped: number;
toolResultDedupDropped: number;
};
+ // 任务队列
+ taskQueue: TaskItem[];
// 用户问题相关
pendingQuestion: AskUserQuestionPayload | null; // 待回答的问题
@@ -77,6 +85,10 @@ interface ChatState {
updateSubtask: (payload: SubtaskUpdatePayload) => void;
clearSubtasks: () => void;
clearMessages: () => void;
+ // 任务队列相关
+ addToTaskQueue: (content: string) => void;
+ clearTaskQueue: () => void;
+ removeFromTaskQueue: (id: string) => void;
// 用户问题相关
setPendingQuestion: (question: AskUserQuestionPayload | null) => void;
}
@@ -99,6 +111,7 @@ export const useChatStore = create<ChatState>((set, get) => ({
toolCallDedupDropped: 0,
toolResultDedupDropped: 0,
},
+ taskQueue: [],
pendingQuestion: null,
addMessage: (message) => {
@@ -446,10 +459,34 @@ export const useChatStore = create<ChatState>((set, get) => ({
toolCallDedupDropped: 0,
toolResultDedupDropped: 0,
},
+ taskQueue: [],
pendingQuestion: null,
});
},
+ addToTaskQueue: (content) => {
+ set((state) => ({
+ taskQueue: [
+ ...state.taskQueue,
+ {
+ id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
+ content,
+ timestamp: Date.now(),
+ },
+ ],
+ }));
+ },
+
+ clearTaskQueue: () => {
+ set({ taskQueue: [] });
+ },
+
+ removeFromTaskQueue: (id) => {
+ set((state) => ({
+ taskQueue: state.taskQueue.filter((task) => task.id !== id),
+ }));
+ },
+
setPendingQuestion: (question) => {
set({ pendingQuestion: question });
},