Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
590 changes: 577 additions & 13 deletions apps/sim/blocks/blocks/pagerduty.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions apps/sim/tools/pagerduty/create_incident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export const createIncidentTool: ToolConfig<
visibility: 'user-or-llm',
description: 'User ID to assign the incident to',
},
incidentKey: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description:
'De-duplication key. A subsequent request with the same service and incident key updates the existing open incident instead of creating a new one',
},
},

request: {
Expand Down Expand Up @@ -106,6 +113,7 @@ export const createIncidentTool: ToolConfig<
},
]
}
if (params.incidentKey) incident.incident_key = params.incidentKey

return { incident }
},
Expand Down
93 changes: 93 additions & 0 deletions apps/sim/tools/pagerduty/get_incident.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type {
PagerDutyGetIncidentParams,
PagerDutyGetIncidentResponse,
} from '@/tools/pagerduty/types'
import type { ToolConfig } from '@/tools/types'

export const getIncidentTool: ToolConfig<PagerDutyGetIncidentParams, PagerDutyGetIncidentResponse> =
{
id: 'pagerduty_get_incident',
name: 'PagerDuty Get Incident',
description: 'Get a single incident from PagerDuty by ID.',
version: '1.0.0',

params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'PagerDuty REST API Key',
},
incidentId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the incident to fetch',
},
},

request: {
url: (params) =>
`https://api.pagerduty.com/incidents/${params.incidentId.trim()}?include[]=services`,
method: 'GET',
headers: (params) => ({
Authorization: `Token token=${params.apiKey}`,
Accept: 'application/vnd.pagerduty+json;version=2',
'Content-Type': 'application/json',
}),
},

transformResponse: async (response: Response) => {
const data = await response.json()

if (!response.ok) {
throw new Error(data.error?.message || `PagerDuty API error: ${response.status}`)
}

const inc = data.incident ?? {}
return {
success: true,
output: {
id: inc.id ?? null,
incidentNumber: inc.incident_number ?? null,
title: inc.title ?? null,
status: inc.status ?? null,
urgency: inc.urgency ?? null,
createdAt: inc.created_at ?? null,
updatedAt: inc.updated_at ?? null,
resolvedAt: inc.resolved_at ?? null,
serviceName: inc.service?.summary ?? null,
serviceId: inc.service?.id ?? null,
assigneeName: inc.assignments?.[0]?.assignee?.summary ?? null,
assigneeId: inc.assignments?.[0]?.assignee?.id ?? null,
escalationPolicyName: inc.escalation_policy?.summary ?? null,
escalationPolicyId: inc.escalation_policy?.id ?? null,
incidentKey: inc.incident_key ?? null,
htmlUrl: inc.html_url ?? null,
},
}
},

outputs: {
id: { type: 'string', description: 'Incident ID' },
incidentNumber: { type: 'number', description: 'Incident number' },
title: { type: 'string', description: 'Incident title' },
status: { type: 'string', description: 'Incident status' },
urgency: { type: 'string', description: 'Incident urgency' },
createdAt: { type: 'string', description: 'Creation timestamp' },
updatedAt: { type: 'string', description: 'Last updated timestamp', optional: true },
resolvedAt: { type: 'string', description: 'Resolution timestamp', optional: true },
serviceName: { type: 'string', description: 'Service name', optional: true },
serviceId: { type: 'string', description: 'Service ID', optional: true },
assigneeName: { type: 'string', description: 'Assignee name', optional: true },
assigneeId: { type: 'string', description: 'Assignee ID', optional: true },
escalationPolicyName: {
type: 'string',
description: 'Escalation policy name',
optional: true,
},
escalationPolicyId: { type: 'string', description: 'Escalation policy ID', optional: true },
incidentKey: { type: 'string', description: 'De-duplication key', optional: true },
htmlUrl: { type: 'string', description: 'PagerDuty web URL' },
},
}
90 changes: 90 additions & 0 deletions apps/sim/tools/pagerduty/get_service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import type {
PagerDutyGetServiceParams,
PagerDutyGetServiceResponse,
} from '@/tools/pagerduty/types'
import type { ToolConfig } from '@/tools/types'

export const getServiceTool: ToolConfig<PagerDutyGetServiceParams, PagerDutyGetServiceResponse> = {
id: 'pagerduty_get_service',
name: 'PagerDuty Get Service',
description: 'Get a single service from PagerDuty by ID.',
version: '1.0.0',

params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'PagerDuty REST API Key',
},
serviceId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the service to fetch',
},
},

request: {
url: (params) =>
`https://api.pagerduty.com/services/${params.serviceId.trim()}?include[]=escalation_policies`,
method: 'GET',
headers: (params) => ({
Authorization: `Token token=${params.apiKey}`,
Accept: 'application/vnd.pagerduty+json;version=2',
'Content-Type': 'application/json',
}),
},

transformResponse: async (response: Response) => {
const data = await response.json()

if (!response.ok) {
throw new Error(data.error?.message || `PagerDuty API error: ${response.status}`)
}

const svc = data.service ?? {}
return {
success: true,
output: {
id: svc.id ?? null,
name: svc.name ?? null,
description: svc.description ?? null,
status: svc.status ?? null,
autoResolveTimeout: svc.auto_resolve_timeout ?? null,
acknowledgementTimeout: svc.acknowledgement_timeout ?? null,
createdAt: svc.created_at ?? null,
lastIncidentTimestamp: svc.last_incident_timestamp ?? null,
escalationPolicyName: svc.escalation_policy?.summary ?? null,
escalationPolicyId: svc.escalation_policy?.id ?? null,
htmlUrl: svc.html_url ?? null,
},
}
},

outputs: {
id: { type: 'string', description: 'Service ID' },
name: { type: 'string', description: 'Service name' },
description: { type: 'string', description: 'Service description', optional: true },
status: { type: 'string', description: 'Service status' },
autoResolveTimeout: {
type: 'number',
description: 'Seconds before an open incident auto-resolves',
optional: true,
},
acknowledgementTimeout: {
type: 'number',
description: 'Seconds before an acknowledged incident reverts to triggered',
optional: true,
},
createdAt: { type: 'string', description: 'Creation timestamp', optional: true },
lastIncidentTimestamp: {
type: 'string',
description: 'Timestamp of the most recent incident',
optional: true,
},
escalationPolicyName: { type: 'string', description: 'Escalation policy name', optional: true },
escalationPolicyId: { type: 'string', description: 'Escalation policy ID', optional: true },
htmlUrl: { type: 'string', description: 'PagerDuty web URL' },
},
}
18 changes: 18 additions & 0 deletions apps/sim/tools/pagerduty/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { addNoteTool } from '@/tools/pagerduty/add_note'
import { createIncidentTool } from '@/tools/pagerduty/create_incident'
import { getIncidentTool } from '@/tools/pagerduty/get_incident'
import { getServiceTool } from '@/tools/pagerduty/get_service'
import { listEscalationPoliciesTool } from '@/tools/pagerduty/list_escalation_policies'
import { listIncidentAlertsTool } from '@/tools/pagerduty/list_incident_alerts'
import { listIncidentsTool } from '@/tools/pagerduty/list_incidents'
import { listOncallsTool } from '@/tools/pagerduty/list_oncalls'
import { listSchedulesTool } from '@/tools/pagerduty/list_schedules'
import { listServicesTool } from '@/tools/pagerduty/list_services'
import { listUsersTool } from '@/tools/pagerduty/list_users'
import { mergeIncidentsTool } from '@/tools/pagerduty/merge_incidents'
import { sendEventTool } from '@/tools/pagerduty/send_event'
import { snoozeIncidentTool } from '@/tools/pagerduty/snooze_incident'
import { updateIncidentTool } from '@/tools/pagerduty/update_incident'

export const pagerdutyListIncidentsTool = listIncidentsTool
export const pagerdutyGetIncidentTool = getIncidentTool
export const pagerdutyCreateIncidentTool = createIncidentTool
export const pagerdutyUpdateIncidentTool = updateIncidentTool
export const pagerdutySnoozeIncidentTool = snoozeIncidentTool
export const pagerdutyMergeIncidentsTool = mergeIncidentsTool
export const pagerdutyAddNoteTool = addNoteTool
export const pagerdutyListIncidentAlertsTool = listIncidentAlertsTool
export const pagerdutyListServicesTool = listServicesTool
export const pagerdutyGetServiceTool = getServiceTool
export const pagerdutyListOncallsTool = listOncallsTool
export const pagerdutyListEscalationPoliciesTool = listEscalationPoliciesTool
export const pagerdutyListSchedulesTool = listSchedulesTool
export const pagerdutyListUsersTool = listUsersTool
export const pagerdutySendEventTool = sendEventTool
119 changes: 119 additions & 0 deletions apps/sim/tools/pagerduty/list_escalation_policies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import type {
PagerDutyListEscalationPoliciesParams,
PagerDutyListEscalationPoliciesResponse,
} from '@/tools/pagerduty/types'
import type { ToolConfig } from '@/tools/types'

export const listEscalationPoliciesTool: ToolConfig<
PagerDutyListEscalationPoliciesParams,
PagerDutyListEscalationPoliciesResponse
> = {
id: 'pagerduty_list_escalation_policies',
name: 'PagerDuty List Escalation Policies',
description: 'List escalation policies from PagerDuty with an optional name filter.',
version: '1.0.0',

params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'PagerDuty REST API Key',
},
query: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Filter escalation policies by name',
},
limit: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Maximum number of results (max 100)',
},
offset: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Offset to start pagination search results',
},
},

request: {
url: (params) => {
const query = new URLSearchParams()
if (params.query) query.set('query', params.query)
if (params.limit) query.set('limit', params.limit)
if (params.offset) query.set('offset', params.offset)
const qs = query.toString()
return `https://api.pagerduty.com/escalation_policies${qs ? `?${qs}` : ''}`
},
method: 'GET',
headers: (params) => ({
Authorization: `Token token=${params.apiKey}`,
Accept: 'application/vnd.pagerduty+json;version=2',
'Content-Type': 'application/json',
}),
},

transformResponse: async (response: Response) => {
const data = await response.json()

if (!response.ok) {
throw new Error(data.error?.message || `PagerDuty API error: ${response.status}`)
}

return {
success: true,
output: {
escalationPolicies: (data.escalation_policies ?? []).map((ep: Record<string, unknown>) => ({
id: ep.id ?? null,
name: ep.name ?? null,
description: ep.description ?? null,
numLoops: ep.num_loops ?? 0,
onCallHandoffNotifications: ep.on_call_handoff_notifications ?? null,
htmlUrl: ep.html_url ?? null,
})),
total: data.total ?? null,
more: data.more ?? false,
offset: data.offset ?? 0,
},
}
},

outputs: {
escalationPolicies: {
type: 'array',
description: 'Array of escalation policies',
items: {
type: 'object',
properties: {
id: { type: 'string', description: 'Escalation policy ID' },
name: { type: 'string', description: 'Escalation policy name' },
description: { type: 'string', description: 'Escalation policy description' },
numLoops: { type: 'number', description: 'Number of times the policy repeats' },
onCallHandoffNotifications: {
type: 'string',
description: 'Handoff notification setting (if_has_services or always)',
},
htmlUrl: { type: 'string', description: 'PagerDuty web URL' },
},
},
},
total: {
type: 'number',
description:
'Total number of matching escalation policies (null unless explicitly requested by PagerDuty)',
optional: true,
},
more: {
type: 'boolean',
description: 'Whether more results are available',
},
offset: {
type: 'number',
description: 'Offset used for this page of results',
},
},
}
Loading
Loading