-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathAskFollowupQuestionTool.ts
More file actions
68 lines (55 loc) · 2.3 KB
/
Copy pathAskFollowupQuestionTool.ts
File metadata and controls
68 lines (55 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Task } from "../task/Task"
import { formatResponse } from "../prompts/responses"
import type { ToolUse } from "../../shared/tools"
import { getSuggestionMode } from "@roo-code/types"
import { BaseTool, ToolCallbacks } from "./BaseTool"
interface Suggestion {
text: string
mode?: unknown
}
interface AskFollowupQuestionParams {
question: string
follow_up: Suggestion[]
}
export class AskFollowupQuestionTool extends BaseTool<"ask_followup_question"> {
readonly name = "ask_followup_question" as const
async execute(params: AskFollowupQuestionParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
const { question, follow_up } = params
const { handleError, pushToolResult } = callbacks
const recordMissingParamError = async (paramName: string): Promise<void> => {
task.consecutiveMistakeCount++
task.recordToolError("ask_followup_question")
task.didToolFailInCurrentTurn = true
pushToolResult(await task.sayAndCreateMissingParamError("ask_followup_question", paramName))
}
try {
if (!question) {
await recordMissingParamError("question")
return
}
if (!follow_up || !Array.isArray(follow_up)) {
await recordMissingParamError("follow_up")
return
}
// Transform follow_up suggestions to the format expected by task.ask
const follow_up_json = {
question,
suggest: follow_up.map((s) => ({ answer: s.text, mode: getSuggestionMode(s.mode) })),
}
task.consecutiveMistakeCount = 0
const { text, images } = await task.ask("followup", JSON.stringify(follow_up_json), false)
const safeText = text ?? ""
await task.say("user_feedback", safeText, images)
pushToolResult(formatResponse.toolResult(`<user_message>\n${safeText}\n</user_message>`, images))
} catch (error) {
await handleError("asking question", error as Error)
}
}
override async handlePartial(task: Task, block: ToolUse<"ask_followup_question">): Promise<void> {
const question: string | undefined = block.nativeArgs?.question ?? block.params.question
// During partial streaming, only show the question to avoid displaying raw JSON
// The full JSON with suggestions will be sent when the tool call is complete (!block.partial)
await task.ask("followup", question ?? "", block.partial).catch(() => {})
}
}
export const askFollowupQuestionTool = new AskFollowupQuestionTool()