| 130 | |
| 131 | /// Cancel a task (skip downstream execution, remove from list) |
| 132 | export async function cancelTask( |
| 133 | task: PendingTask & { _tokenConfig?: ExtensionToken } |
| 134 | ): Promise<void> { |
| 135 | const tokenConfig = task._tokenConfig; |
| 136 | |
| 137 | if (!tokenConfig) { |
| 138 | throw new Error('Task missing token configuration'); |
| 139 | } |
| 140 | |
| 141 | const executionId = encodeURIComponent(task.executionId); |
| 142 | const url = `${tokenConfig.cloudUrl}/api/ext/${tokenConfig.token}/tasks/${executionId}/cancel`; |
| 143 | |
| 144 | console.log('[WeaveMind] Cancelling task:', { url, executionId: task.executionId }); |
| 145 | |
| 146 | const response = await fetch(url, { |
| 147 | method: 'POST', |
| 148 | headers: { 'Content-Type': 'application/json' }, |
| 149 | }); |
| 150 | |
| 151 | if (!response.ok) { |
| 152 | const text = await response.text(); |
| 153 | throw new Error(`HTTP ${response.status}: ${text}`); |
| 154 | } |
| 155 | |
| 156 | console.log('[WeaveMind] Task cancelled successfully'); |
| 157 | } |
| 158 | |
| 159 | /// Submit a trigger form (fires the trigger with form data) |
| 160 | export async function submitTrigger( |