|
1 | 1 | import { LLMock } from "@copilotkit/aimock" |
| 2 | +import type { ChatCompletionRequest } from "@copilotkit/aimock" |
2 | 3 |
|
3 | 4 | import { toolResultContains } from "./tool-result" |
4 | 5 |
|
5 | 6 | const SUBTASK_PARENT_MARKER = "SUBTASK_PARENT_CANCELLATION_SMOKE" |
6 | 7 | const SUBTASK_CHILD_MARKER = "SUBTASK_CHILD_CALCULATOR_SMOKE" |
7 | 8 |
|
8 | | -export const SUBTASK_CHILD_PROMPT = `${SUBTASK_CHILD_MARKER}: Ask the user exactly this follow-up question: What is the square root of 81? After the user answers, complete with only the answer.` |
| 9 | +const SUBTASK_CHILD_PROMPT = `${SUBTASK_CHILD_MARKER}: Ask the user exactly this follow-up question: What is the square root of 81? After the user answers, complete with only the answer.` |
9 | 10 | export const SUBTASK_PARENT_PROMPT = `${SUBTASK_PARENT_MARKER}: Use the new_task tool exactly once. Create an ask-mode subtask with this exact message: "${SUBTASK_CHILD_PROMPT}" Do not answer directly.` |
10 | 11 | export const SUBTASK_CHILD_FOLLOWUP_ANSWER = "9" |
11 | 12 | const INTERRUPTED_TOOL_RESULT = "Task was interrupted before this tool call could be completed." |
12 | 13 |
|
| 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 | + |
13 | 30 | export function addSubtaskFixtures(mock: InstanceType<typeof LLMock>) { |
14 | 31 | mock.addFixture({ |
15 | 32 | match: { |
@@ -66,39 +83,11 @@ export function addSubtaskFixtures(mock: InstanceType<typeof LLMock>) { |
66 | 83 | }, |
67 | 84 | }) |
68 | 85 |
|
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")) |
85 | 87 |
|
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 | + ) |
102 | 91 |
|
103 | 92 | mock.addFixture({ |
104 | 93 | match: { |
|
0 commit comments