11import { LLMock } from "@copilotkit/aimock"
2+ import type { ChatCompletionRequest } from "@copilotkit/aimock"
23
34import { toolResultContains } from "./tool-result"
45
@@ -10,6 +11,22 @@ export const SUBTASK_PARENT_PROMPT = `${SUBTASK_PARENT_MARKER}: Use the new_task
1011export const SUBTASK_CHILD_FOLLOWUP_ANSWER = "9"
1112const INTERRUPTED_TOOL_RESULT = "Task was interrupted before this tool call could be completed."
1213
14+ const completionAfterAnswer = ( followupId : string , completionId : string ) => ( {
15+ match : {
16+ toolCallId : followupId ,
17+ predicate : ( req : ChatCompletionRequest ) => toolResultContains ( req , followupId , [ SUBTASK_CHILD_FOLLOWUP_ANSWER ] ) ,
18+ } ,
19+ response : {
20+ toolCalls : [
21+ {
22+ name : "attempt_completion" ,
23+ arguments : JSON . stringify ( { result : "9" } ) ,
24+ id : completionId ,
25+ } ,
26+ ] ,
27+ } ,
28+ } )
29+
1330export function addSubtaskFixtures ( mock : InstanceType < typeof LLMock > ) {
1431 mock . addFixture ( {
1532 match : {
@@ -66,39 +83,11 @@ export function addSubtaskFixtures(mock: InstanceType<typeof LLMock>) {
6683 } ,
6784 } )
6885
69- mock . addFixture ( {
70- match : {
71- toolCallId : "call_subtasks_child_followup_001" ,
72- predicate : ( req ) =>
73- toolResultContains ( req , "call_subtasks_child_followup_001" , [ SUBTASK_CHILD_FOLLOWUP_ANSWER ] ) ,
74- } ,
75- response : {
76- toolCalls : [
77- {
78- name : "attempt_completion" ,
79- arguments : JSON . stringify ( { result : "9" } ) ,
80- id : "call_subtasks_child_completion_002" ,
81- } ,
82- ] ,
83- } ,
84- } )
86+ mock . addFixture ( completionAfterAnswer ( "call_subtasks_child_followup_001" , "call_subtasks_child_completion_002" ) )
8587
86- mock . addFixture ( {
87- match : {
88- toolCallId : "call_subtasks_child_followup_resume_002" ,
89- predicate : ( req ) =>
90- toolResultContains ( req , "call_subtasks_child_followup_resume_002" , [ SUBTASK_CHILD_FOLLOWUP_ANSWER ] ) ,
91- } ,
92- response : {
93- toolCalls : [
94- {
95- name : "attempt_completion" ,
96- arguments : JSON . stringify ( { result : "9" } ) ,
97- id : "call_subtasks_child_completion_resume_003" ,
98- } ,
99- ] ,
100- } ,
101- } )
88+ mock . addFixture (
89+ completionAfterAnswer ( "call_subtasks_child_followup_resume_002" , "call_subtasks_child_completion_resume_003" ) ,
90+ )
10291
10392 mock . addFixture ( {
10493 match : {
0 commit comments