Files
simstudioai--sim/apps/sim/tools/github/cancel_workflow_run.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

148 lines
4.0 KiB
TypeScript

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 },
},
}