Files
simstudioai--sim/apps/sim/tools/github/trigger_workflow.ts
T
wehub-resource-sync d25d482dc2
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

111 lines
3.3 KiB
TypeScript

import type { TriggerWorkflowParams, TriggerWorkflowResponse } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const triggerWorkflowTool: ToolConfig<TriggerWorkflowParams, TriggerWorkflowResponse> = {
id: 'github_trigger_workflow',
name: 'GitHub Trigger Workflow',
description:
'Trigger a workflow dispatch event for a GitHub Actions workflow. The workflow must have a workflow_dispatch trigger configured. Returns 204 No Content on success.',
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',
},
workflow_id: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Workflow ID (number) or workflow filename (e.g., "main.yaml")',
},
ref: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Git reference (branch or tag name) to run the workflow on',
},
inputs: {
type: 'object',
required: false,
visibility: 'user-or-llm',
description: 'Input keys and values configured in the workflow file',
},
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/workflows/${params.workflow_id}/dispatches`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => ({
ref: params.ref,
...(params.inputs && { inputs: params.inputs }),
}),
},
transformResponse: async (response) => {
const content = `Workflow dispatched successfully on ref: ${response.url.includes('ref') ? 'requested ref' : 'default branch'}
The workflow run should start shortly.`
return {
success: true,
output: {
content,
metadata: {},
},
}
},
outputs: {
content: { type: 'string', description: 'Confirmation message' },
metadata: {
type: 'object',
description: 'Empty metadata object (204 No Content response)',
},
},
}
export const triggerWorkflowV2Tool: ToolConfig = {
id: 'github_trigger_workflow_v2',
name: triggerWorkflowTool.name,
description: triggerWorkflowTool.description,
version: '2.0.0',
params: triggerWorkflowTool.params,
request: triggerWorkflowTool.request,
oauth: triggerWorkflowTool.oauth,
transformResponse: async (response: Response, params) => {
return {
success: true,
output: {
triggered: response.status === 204,
workflow_id: params?.workflow_id ?? null,
ref: params?.ref ?? null,
},
}
},
outputs: {
triggered: { type: 'boolean', description: 'Whether workflow was triggered' },
workflow_id: { type: 'string', description: 'Workflow ID or filename', optional: true },
ref: { type: 'string', description: 'Git reference used', optional: true },
},
}