2026-02-06 16:01:54 +09:00
|
|
|
const TARGET_TOOLS = ["task", "Task", "task_tool", "call_omo_agent"]
|
2026-01-09 02:24:43 +09:00
|
|
|
|
|
|
|
|
const SESSION_ID_PATTERNS = [
|
|
|
|
|
/Session ID: (ses_[a-zA-Z0-9_-]+)/,
|
|
|
|
|
/session_id: (ses_[a-zA-Z0-9_-]+)/,
|
|
|
|
|
/<task_metadata>\s*session_id: (ses_[a-zA-Z0-9_-]+)/,
|
|
|
|
|
/sessionId: (ses_[a-zA-Z0-9_-]+)/,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
function extractSessionId(output: string): string | null {
|
|
|
|
|
for (const pattern of SESSION_ID_PATTERNS) {
|
|
|
|
|
const match = output.match(pattern)
|
|
|
|
|
if (match) return match[1]
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createTaskResumeInfoHook() {
|
2026-01-25 13:28:44 +09:00
|
|
|
const toolExecuteAfter = async (
|
|
|
|
|
input: { tool: string; sessionID: string; callID: string },
|
|
|
|
|
output: { title: string; output: string; metadata: unknown }
|
|
|
|
|
) => {
|
|
|
|
|
if (!TARGET_TOOLS.includes(input.tool)) return
|
|
|
|
|
if (output.output.startsWith("Error:") || output.output.startsWith("Failed")) return
|
|
|
|
|
if (output.output.includes("\nto continue:")) return
|
2026-01-09 02:24:43 +09:00
|
|
|
|
2026-01-25 13:28:44 +09:00
|
|
|
const sessionId = extractSessionId(output.output)
|
|
|
|
|
if (!sessionId) return
|
2026-01-09 02:24:43 +09:00
|
|
|
|
2026-02-06 16:01:54 +09:00
|
|
|
output.output = output.output.trimEnd() + `\n\nto continue: task(session_id="${sessionId}", prompt="...")`
|
2026-01-25 13:28:44 +09:00
|
|
|
}
|
2026-01-09 02:24:43 +09:00
|
|
|
|
2026-01-25 13:28:44 +09:00
|
|
|
return {
|
|
|
|
|
"tool.execute.after": toolExecuteAfter,
|
|
|
|
|
}
|
2026-01-09 02:24:43 +09:00
|
|
|
}
|