MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / main

Function main

apps/cli/scripts/integration/cases/cancel-active-task.ts:6–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4 'Run exactly this command and do not summarize until it finishes: sleep 12 && echo "done". After it finishes, reply with exactly "done".'
5
6async function main() {
7 const startRequestId = `start-a-${Date.now()}`
8 const cancelRequestId = `cancel-${Date.now()}`
9 const shutdownRequestId = `shutdown-${Date.now()}`
10
11 let initSeen = false
12 let startAccepted = false
13 let startCommandToolUseSeen = false
14 let sentCancel = false
15 let cancelDone = false
16 let sentShutdown = false
17
18 await runStreamCase({
19 onEvent(event: StreamEvent, context) {
20 if (event.type === "system" && event.subtype === "init" && !initSeen) {
21 initSeen = true
22 context.sendCommand({
23 command: "start",
24 requestId: startRequestId,
25 prompt: LONG_PROMPT,
26 })
27 return
28 }
29
30 if (
31 event.type === "control" &&
32 event.subtype === "ack" &&
33 event.command === "start" &&
34 event.requestId === startRequestId
35 ) {
36 startAccepted = true
37 return
38 }
39
40 if (
41 event.type === "tool_use" &&
42 event.subtype === "command" &&
43 event.done === true &&
44 event.requestId === startRequestId
45 ) {
46 startCommandToolUseSeen = true
47 }
48
49 if (startAccepted && startCommandToolUseSeen && !sentCancel) {
50 context.sendCommand({
51 command: "cancel",
52 requestId: cancelRequestId,
53 })
54 sentCancel = true
55 return
56 }
57
58 if (
59 event.type === "control" &&
60 event.subtype === "done" &&
61 event.command === "cancel" &&
62 event.requestId === cancelRequestId
63 ) {

Callers 1

Calls 1

runStreamCaseFunction · 0.90

Tested by

no test coverage detected