-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathcancel_workflow_run.ts
More file actions
147 lines (136 loc) · 4.04 KB
/
Copy pathcancel_workflow_run.ts
File metadata and controls
147 lines (136 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import type { CancelWorkflowRunParams, CancelWorkflowRunResponse } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const cancelWorkflowRunTool: ToolConfig<CancelWorkflowRunParams, CancelWorkflowRunResponse> =
{
id: 'github_cancel_workflow_run',
name: 'GitHub Cancel Workflow Run',
description:
'Cancel a workflow run. Returns 202 Accepted if cancellation is initiated, or 409 Conflict if the run cannot be cancelled (already completed).',
version: '1.0.0',
params: {
owner: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository owner (user or organization)',
},
repo: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository name',
},
run_id: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Workflow run ID to cancel',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub Personal Access Token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/actions/runs/${params.run_id}/cancel`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
},
transformResponse: async (response, params) => {
if (!params) {
return {
success: false,
error: 'Missing parameters',
output: {
content: '',
metadata: {
run_id: 0,
status: 'error',
},
},
}
}
if (response.status === 202) {
const content = `Workflow run #${params.run_id} cancellation initiated successfully.
The run will be cancelled shortly.`
return {
success: true,
output: {
content,
metadata: {
run_id: params.run_id,
status: 'cancellation_initiated',
},
},
}
}
if (response.status === 409) {
const content = `Cannot cancel workflow run #${params.run_id}.
The run may have already completed or been cancelled.`
return {
success: false,
output: {
content,
metadata: {
run_id: params.run_id,
status: 'cannot_cancel',
},
},
}
}
const content = `Workflow run #${params.run_id} cancellation request processed.`
return {
success: true,
output: {
content,
metadata: {
run_id: params.run_id,
status: 'processed',
},
},
}
},
outputs: {
content: { type: 'string', description: 'Cancellation status message' },
metadata: {
type: 'object',
description: 'Cancellation metadata',
properties: {
run_id: { type: 'number', description: 'Workflow run ID' },
status: {
type: 'string',
description: 'Cancellation status (cancellation_initiated, cannot_cancel, processed)',
},
},
},
},
}
export const cancelWorkflowRunV2Tool: ToolConfig = {
id: 'github_cancel_workflow_run_v2',
name: cancelWorkflowRunTool.name,
description: cancelWorkflowRunTool.description,
version: '2.0.0',
params: cancelWorkflowRunTool.params,
request: cancelWorkflowRunTool.request,
oauth: cancelWorkflowRunTool.oauth,
transformResponse: async (response: Response, params) => {
return {
success: true,
output: {
cancelled: response.status === 202,
run_id: params?.run_id ?? null,
},
}
},
outputs: {
cancelled: { type: 'boolean', description: 'Whether cancellation was initiated' },
run_id: { type: 'number', description: 'Workflow run ID', optional: true },
},
}