(
flowId: string,
options?: {
removeQueuedInMemory?: boolean
rootDir?: string
},
)
| 123 | } |
| 124 | |
| 125 | export async function cancelAutonomyFlowText( |
| 126 | flowId: string, |
| 127 | options?: { |
| 128 | removeQueuedInMemory?: boolean |
| 129 | rootDir?: string |
| 130 | }, |
| 131 | ): Promise<string> { |
| 132 | const cancelled = await requestManagedAutonomyFlowCancel({ |
| 133 | flowId, |
| 134 | rootDir: options?.rootDir, |
| 135 | }) |
| 136 | if (!cancelled) { |
| 137 | return 'Autonomy flow not found.' |
| 138 | } |
| 139 | if (!cancelled.accepted) { |
| 140 | return `Autonomy flow ${flowId} is already terminal (${cancelled.flow.status}).` |
| 141 | } |
| 142 | |
| 143 | let removedCount = 0 |
| 144 | if (options?.removeQueuedInMemory) { |
| 145 | const removed = removeByFilter(cmd => cmd.autonomy?.flowId === flowId) |
| 146 | removedCount = removed.length |
| 147 | for (const command of removed) { |
| 148 | if (command.autonomy?.runId) { |
| 149 | await markAutonomyRunCancelled(command.autonomy.runId, options?.rootDir) |
| 150 | } |
| 151 | } |
| 152 | } else { |
| 153 | for (const runId of cancelled.queuedRunIds) { |
| 154 | await markAutonomyRunCancelled(runId, options?.rootDir) |
| 155 | } |
| 156 | removedCount = cancelled.queuedRunIds.length |
| 157 | } |
| 158 | |
| 159 | return cancelled.flow.status === 'running' |
| 160 | ? `Cancellation requested for flow ${flowId}. The current step is still running, and no new steps will be started.` |
| 161 | : `Cancelled flow ${flowId}. Removed ${removedCount} queued step(s).` |
| 162 | } |
| 163 | |
| 164 | export async function autonomyFlowCancelHandler(flowId: string): Promise<void> { |
| 165 | process.stdout.write(`${await cancelAutonomyFlowText(flowId)}\n`) |
no test coverage detected