Files
simstudioai--sim/apps/sim/tools/rootly/run_workflow.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

129 lines
4.6 KiB
TypeScript

import type { RootlyRunWorkflowParams, RootlyRunWorkflowResponse } from '@/tools/rootly/types'
import type { ToolConfig } from '@/tools/types'
export const rootlyRunWorkflowTool: ToolConfig<RootlyRunWorkflowParams, RootlyRunWorkflowResponse> =
{
id: 'rootly_run_workflow',
name: 'Rootly Run Workflow',
description: 'Trigger a Rootly automation workflow, optionally scoped to an incident or alert.',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Rootly API key',
},
workflowId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The ID of the workflow to run',
},
incidentId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Incident ID to run the workflow against',
},
alertId: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Alert ID to run the workflow against',
},
immediate: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description:
'Run immediately (true) or respect the workflow wait time (false). Default true',
},
checkConditions: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Whether to evaluate the workflow conditions before running. Default false',
},
},
request: {
url: (params) =>
`https://api.rootly.com/v1/workflows/${params.workflowId.trim()}/workflow_runs`,
method: 'POST',
headers: (params) => ({
'Content-Type': 'application/vnd.api+json',
Authorization: `Bearer ${params.apiKey}`,
}),
body: (params) => {
const attributes: Record<string, unknown> = {}
if (params.incidentId) attributes.incident_id = params.incidentId.trim()
if (params.alertId) attributes.alert_id = params.alertId.trim()
if (params.immediate !== undefined) attributes.immediate = params.immediate
if (params.checkConditions !== undefined)
attributes.check_conditions = params.checkConditions
return { data: { type: 'workflow_runs', attributes } }
},
},
transformResponse: async (response: Response) => {
if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
return {
success: false,
output: { workflowRun: {} as RootlyRunWorkflowResponse['output']['workflowRun'] },
error: errorData.errors?.[0]?.detail || `HTTP ${response.status}: ${response.statusText}`,
}
}
const data = await response.json()
const attrs = data.data?.attributes || {}
return {
success: true,
output: {
workflowRun: {
id: data.data?.id ?? null,
workflowId: attrs.workflow_id ?? null,
status: attrs.status ?? null,
statusMessage: attrs.status_message ?? null,
triggeredBy: attrs.triggered_by ?? null,
incidentId: attrs.incident_id ?? null,
alertId: attrs.alert_id ?? null,
startedAt: attrs.started_at ?? null,
completedAt: attrs.completed_at ?? null,
failedAt: attrs.failed_at ?? null,
canceledAt: attrs.canceled_at ?? null,
},
},
}
},
outputs: {
workflowRun: {
type: 'object',
description: 'The triggered workflow run',
properties: {
id: { type: 'string', description: 'Unique workflow run ID' },
workflowId: { type: 'string', description: 'ID of the workflow that ran' },
status: {
type: 'string',
description:
'Run status (queued, started, completed, completed_with_errors, failed, canceled)',
},
statusMessage: { type: 'string', description: 'Status detail message' },
triggeredBy: {
type: 'string',
description: 'What triggered the run (system, user, workflow)',
},
incidentId: { type: 'string', description: 'Associated incident ID' },
alertId: { type: 'string', description: 'Associated alert ID' },
startedAt: { type: 'string', description: 'When the run started' },
completedAt: { type: 'string', description: 'When the run completed' },
failedAt: { type: 'string', description: 'When the run failed' },
canceledAt: { type: 'string', description: 'When the run was canceled' },
},
},
},
}