Skip to content

Commit c3a080c

Browse files
committed
fix(pagerduty): reject empty merge sources, enforce dedupKey, require integer snooze duration
- merge_incidents: throw if source_incidents ends up empty after filtering blanks - send_event: require dedupKey for acknowledge/resolve to match block's required condition - snooze_incident: require an integer duration, not just a finite number
1 parent 904886a commit c3a080c

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

apps/sim/tools/pagerduty/merge_incidents.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,23 @@ export const mergeIncidentsTool: ToolConfig<
5050
'Content-Type': 'application/json',
5151
From: params.fromEmail,
5252
}),
53-
body: (params) => ({
54-
source_incidents: params.sourceIncidentIds
53+
body: (params) => {
54+
const sourceIds = params.sourceIncidentIds
5555
.split(',')
5656
.map((id) => id.trim())
5757
.filter((id) => id.length > 0)
58-
.map((id) => ({
58+
59+
if (sourceIds.length === 0) {
60+
throw new Error('sourceIncidentIds must contain at least one non-empty incident ID')
61+
}
62+
63+
return {
64+
source_incidents: sourceIds.map((id) => ({
5965
id,
6066
type: 'incident_reference',
6167
})),
62-
}),
68+
}
69+
},
6370
},
6471

6572
transformResponse: async (response: Response) => {

apps/sim/tools/pagerduty/send_event.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export const sendEventTool: ToolConfig<PagerDutySendEventParams, PagerDutySendEv
8080
event_action: params.eventAction,
8181
}
8282

83+
if (params.eventAction === 'acknowledge' || params.eventAction === 'resolve') {
84+
if (!params.dedupKey) {
85+
throw new Error('dedupKey is required when eventAction is acknowledge or resolve')
86+
}
87+
}
88+
8389
if (params.dedupKey) body.dedup_key = params.dedupKey
8490

8591
if (params.eventAction === 'trigger') {

apps/sim/tools/pagerduty/snooze_incident.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const snoozeIncidentTool: ToolConfig<
5252
}),
5353
body: (params) => {
5454
const duration = Number(params.duration)
55-
if (!Number.isFinite(duration) || duration < 1 || duration > 604800) {
55+
if (!Number.isInteger(duration) || duration < 1 || duration > 604800) {
5656
throw new Error('duration must be a whole number of seconds between 1 and 604800')
5757
}
5858
return { duration }

0 commit comments

Comments
 (0)