fix(todo): skip unsafe continuation tails
This commit is contained in:
@@ -5,7 +5,9 @@ import { HOOK_NAME } from "./constants"
|
||||
interface MessagePart {
|
||||
type?: string
|
||||
name?: string
|
||||
tool?: string
|
||||
toolName?: string
|
||||
state?: { status?: string }
|
||||
text?: string
|
||||
synthetic?: boolean
|
||||
}
|
||||
@@ -16,6 +18,20 @@ interface Message {
|
||||
parts?: MessagePart[]
|
||||
}
|
||||
|
||||
const QUESTION_TOOL_NAMES = new Set(["question", "ask_user_question", "askuserquestion"])
|
||||
|
||||
function getToolName(part: MessagePart): string | undefined {
|
||||
return part.name ?? part.tool ?? part.toolName
|
||||
}
|
||||
|
||||
function isUnansweredQuestionTool(part: MessagePart): boolean {
|
||||
const toolName = getToolName(part)
|
||||
if (!QUESTION_TOOL_NAMES.has(toolName?.toLowerCase() ?? "")) {
|
||||
return false
|
||||
}
|
||||
return part.state?.status !== "completed"
|
||||
}
|
||||
|
||||
export function hasUnansweredQuestion(messages: Message[]): boolean {
|
||||
if (!messages || messages.length === 0) return false
|
||||
|
||||
@@ -33,8 +49,8 @@ export function hasUnansweredQuestion(messages: Message[]): boolean {
|
||||
if (role === "assistant" && msg.parts) {
|
||||
const hasQuestion = msg.parts.some(
|
||||
(part) =>
|
||||
(part.type === "tool_use" || part.type === "tool-invocation") &&
|
||||
(part.name === "question" || part.toolName === "question"),
|
||||
(part.type === "tool" || part.type === "tool_use" || part.type === "tool-invocation") &&
|
||||
isUnansweredQuestionTool(part),
|
||||
)
|
||||
if (hasQuestion) {
|
||||
log(`[${HOOK_NAME}] Detected pending question tool in last assistant message`)
|
||||
|
||||
Reference in New Issue
Block a user