Skip to content

Commit 9214edb

Browse files
committed
feat(frontend): refine task context controls
1 parent 2968dc9 commit 9214edb

File tree

6 files changed

+113
-105
lines changed

6 files changed

+113
-105
lines changed

frontend/src/components/console/nav/nav-project.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ function SidebarTaskItem({ task, isActive, onStop, onDelete, onRenameSuccess }:
5050
const isPending = task.status === "pending"
5151
const isProcessing = task.status === "processing"
5252
const isFinished = task.status === "finished" || task.status === "error"
53-
const canStop = isPending || isProcessing
5453
const TaskIcon =
5554
isFinished
5655
? IconPointFilled

frontend/src/components/console/task/chat-inputbox.tsx

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import { useState, useRef } from "react"
22
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea } from "@/components/ui/input-group"
3-
import { IconCommand, IconLoader, IconPlayerStopFilled, IconRecycle, IconSend, IconTerminal2 } from "@tabler/icons-react"
3+
import { IconCommand, IconLoader, IconPlayerStopFilled, IconSend, IconTerminal2 } from "@tabler/icons-react"
44
import React from "react"
55
import { VoiceInputButton } from "./voice-input-button"
66
import type { TaskMessageHandlerStatus } from "@/components/console/task/task-message-handler"
77
import type { AvailableCommand, AvailableCommands, TaskStreamStatus } from "./task-shared"
88
import { Button } from "@/components/ui/button"
99
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
10-
import {
11-
AlertDialog,
12-
AlertDialogAction,
13-
AlertDialogCancel,
14-
AlertDialogContent,
15-
AlertDialogDescription,
16-
AlertDialogFooter,
17-
AlertDialogHeader,
18-
AlertDialogTitle,
19-
} from "@/components/ui/alert-dialog"
2010
import { cn } from "@/lib/utils"
2111

2212

@@ -26,15 +16,13 @@ interface TaskChatInputBoxProps {
2616
onSend: (content: string) => void
2717
sending: boolean
2818
queueSize: number
29-
sendResetSession: () => Promise<boolean>
3019
executionTimeMs?: number
3120
onCancel?: () => void
3221
}
3322

34-
export const TaskChatInputBox = ({ streamStatus, availableCommands, onSend, sending, queueSize, sendResetSession, executionTimeMs = 0, onCancel }: TaskChatInputBoxProps) => {
23+
export const TaskChatInputBox = ({ streamStatus, availableCommands, onSend, sending, queueSize, executionTimeMs = 0, onCancel }: TaskChatInputBoxProps) => {
3524
const [content, setContent] = useState('')
3625
const [isComposing, setIsComposing] = useState(false)
37-
const [resetDialogOpen, setResetDialogOpen] = useState(false)
3826
const textareaRef = useRef<HTMLTextAreaElement>(null)
3927
const isExecuting = (streamStatus === 'connected' || streamStatus === 'inited')
4028

@@ -109,20 +97,11 @@ export const TaskChatInputBox = ({ streamStatus, availableCommands, onSend, send
10997
<div className="flex flex-row gap-2 items-center min-w-0">
11098
<DropdownMenu>
11199
<DropdownMenuTrigger asChild>
112-
<Button variant="outline" size="icon-sm" className="rounded-full" disabled={controlsDisabled}>
100+
<Button variant="outline" size="icon-sm" className="rounded-full" disabled={controlsDisabled || !showCommandItems}>
113101
<IconTerminal2 />
114102
</Button>
115103
</DropdownMenuTrigger>
116104
<DropdownMenuContent className={showCommandItems ? "w-[min(90vw,32rem)] min-w-80 max-w-[min(90vw,32rem)]" : "w-48 min-w-48"}>
117-
<DropdownMenuItem className="flex flex-col items-start gap-1 whitespace-normal" onClick={() => setResetDialogOpen(true)}>
118-
<div className="flex min-w-0 flex-row flex-wrap items-center gap-2">
119-
<IconRecycle />
120-
<div className="font-bold text-xs">重置上下文</div>
121-
</div>
122-
<div className="max-w-full truncate pl-6 text-xs text-muted-foreground">
123-
清空当前会话上下文,后续操作将基于新的上下文继续进行。
124-
</div>
125-
</DropdownMenuItem>
126105
{showCommandItems && (
127106
<>
128107
{commandItems.map((command: AvailableCommand, index: number) => (
@@ -169,30 +148,6 @@ export const TaskChatInputBox = ({ streamStatus, availableCommands, onSend, send
169148
</div>
170149
</InputGroupAddon>
171150
</InputGroup>
172-
173-
{/* Reset Session 确认对话框 */}
174-
<AlertDialog open={resetDialogOpen} onOpenChange={setResetDialogOpen}>
175-
<AlertDialogContent>
176-
<AlertDialogHeader>
177-
<AlertDialogTitle>重置上下文</AlertDialogTitle>
178-
<AlertDialogDescription>
179-
确定要重置当前上下文吗?后续操作将会基于新的上下文进行。
180-
</AlertDialogDescription>
181-
</AlertDialogHeader>
182-
<AlertDialogFooter>
183-
<AlertDialogCancel>取消</AlertDialogCancel>
184-
<AlertDialogAction
185-
onClick={() => {
186-
void sendResetSession()
187-
setResetDialogOpen(false)
188-
}}
189-
>
190-
确认
191-
</AlertDialogAction>
192-
</AlertDialogFooter>
193-
</AlertDialogContent>
194-
</AlertDialog>
195-
196151
</div>
197152
)
198153
}

frontend/src/components/console/task/chat-panel.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ interface TaskChatPanelProps {
9494
queueSize: number
9595
sendUserInput: (content: string) => void
9696
sendCancelCommand: () => void
97-
sendResetSession: () => Promise<boolean>
9897
}
9998

100-
export const TaskChatPanel = ({ scrollContainerRef: externalScrollRef, inputPortalTargetRef, messages, cli, streamStatus, disabled, availableCommands, sending, sendUserInput, sendCancelCommand, sendResetSession, queueSize }: TaskChatPanelProps) => {
99+
export const TaskChatPanel = ({ scrollContainerRef: externalScrollRef, inputPortalTargetRef, messages, cli, streamStatus, disabled, availableCommands, sending, sendUserInput, sendCancelCommand, queueSize }: TaskChatPanelProps) => {
101100
const [timeCost, setTimeCost] = React.useState(0)
102101
const internalScrollRef = React.useRef<HTMLDivElement>(null)
103102
const scrollContainerRef = externalScrollRef ?? internalScrollRef
@@ -236,7 +235,6 @@ export const TaskChatPanel = ({ scrollContainerRef: externalScrollRef, inputPort
236235
onSend={sendUserInput}
237236
sending={sending}
238237
queueSize={queueSize}
239-
sendResetSession={sendResetSession}
240238
/>
241239
),
242240
inputPortalTargetRef.current
@@ -253,7 +251,6 @@ export const TaskChatPanel = ({ scrollContainerRef: externalScrollRef, inputPort
253251
onSend={sendUserInput}
254252
sending={sending}
255253
queueSize={queueSize}
256-
sendResetSession={sendResetSession}
257254
/>
258255
))}
259256

frontend/src/components/console/task/task-control-client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ interface RestartTaskResponse extends TaskControlCallResponse {
7575

7676
export class TaskControlClient implements TaskRepositoryClient {
7777
private static readonly CONNECT_TIMEOUT_MS = 10000
78+
private static readonly DEFAULT_CALL_TIMEOUT_MS = 5000
79+
private static readonly RESTART_TIMEOUT_MS = 15000
7880

7981
private readonly taskId: string
8082
private readonly onStateChange?: (state: TaskControlClientState) => void
@@ -179,7 +181,11 @@ export class TaskControlClient implements TaskRepositoryClient {
179181
return { ...this.state }
180182
}
181183

182-
async call<T>(kind: string, payload: Record<string, unknown>, timeout = 5000): Promise<T | null> {
184+
async call<T>(
185+
kind: string,
186+
payload: Record<string, unknown>,
187+
timeout = TaskControlClient.DEFAULT_CALL_TIMEOUT_MS,
188+
): Promise<T | null> {
183189
if (this.socket?.readyState !== WebSocket.OPEN) {
184190
return null
185191
}
@@ -266,7 +272,7 @@ export class TaskControlClient implements TaskRepositoryClient {
266272
restart(loadSession: boolean) {
267273
return this.call<RestartTaskResponse>("restart", {
268274
load_session: loadSession,
269-
}).then((response) => !!response?.success)
275+
}, TaskControlClient.RESTART_TIMEOUT_MS).then((response) => !!response?.success)
270276
}
271277

272278
private handleSocketMessage(rawData: string) {

0 commit comments

Comments
 (0)