Skip to content

Commit e134c62

Browse files
committed
fix(integrations): address incident workflow review fixes
1 parent d4e6fe4 commit e134c62

7 files changed

Lines changed: 107 additions & 120 deletions

File tree

apps/sim/tools/incidentio/schedule_entries_list.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,19 @@ export const scheduleEntriesListTool: ToolConfig<
4444

4545
request: {
4646
url: (params) => {
47-
const queryParams: string[] = []
47+
const url = new URL('https://api.incident.io/v2/schedule_entries')
4848

49-
queryParams.push(`schedule_id=${params.schedule_id}`)
49+
url.searchParams.set('schedule_id', params.schedule_id.trim())
5050

5151
if (params.entry_window_start) {
52-
queryParams.push(`entry_window_start=${encodeURIComponent(params.entry_window_start)}`)
52+
url.searchParams.set('entry_window_start', params.entry_window_start)
5353
}
5454

5555
if (params.entry_window_end) {
56-
queryParams.push(`entry_window_end=${encodeURIComponent(params.entry_window_end)}`)
56+
url.searchParams.set('entry_window_end', params.entry_window_end)
5757
}
5858

59-
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''
60-
return `https://api.incident.io/v2/schedule_entries${queryString}`
59+
return url.toString()
6160
},
6261
method: 'GET',
6362
headers: (params) => ({

apps/sim/tools/incidentio/types.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,31 @@ export const INCIDENTIO_FOLLOW_UP_OUTPUT: OutputProperty = {
175175
export const INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES = {
176176
id: { type: 'string', description: 'Workflow ID' },
177177
name: { type: 'string', description: 'Workflow name' },
178+
trigger: { type: 'string', description: 'Workflow trigger' },
179+
once_for: { type: 'array', description: 'Fields that make the workflow run once' },
180+
version: { type: 'number', description: 'Workflow version' },
181+
expressions: { type: 'array', description: 'Workflow expressions' },
182+
condition_groups: { type: 'array', description: 'Workflow condition groups' },
183+
steps: { type: 'array', description: 'Workflow steps' },
184+
include_private_incidents: {
185+
type: 'boolean',
186+
description: 'Whether the workflow includes private incidents',
187+
},
188+
include_private_escalations: {
189+
type: 'boolean',
190+
description: 'Whether the workflow includes private escalations',
191+
},
192+
runs_on_incident_modes: { type: 'array', description: 'Incident modes the workflow runs on' },
193+
continue_on_step_error: {
194+
type: 'boolean',
195+
description: 'Whether execution continues after a step error',
196+
},
197+
runs_on_incidents: { type: 'string', description: 'Incident lifecycle filter' },
178198
state: { type: 'string', description: 'Workflow state (active, draft, disabled)' },
199+
delay: { type: 'object', description: 'Workflow delay configuration', optional: true },
179200
folder: { type: 'string', description: 'Workflow folder', optional: true },
180-
created_at: { type: 'string', description: 'When the workflow was created', optional: true },
181-
updated_at: { type: 'string', description: 'When the workflow was last updated', optional: true },
201+
runs_from: { type: 'string', description: 'When the workflow runs from', optional: true },
202+
shortform: { type: 'string', description: 'Workflow shortform identifier', optional: true },
182203
} as const satisfies Record<string, OutputProperty>
183204

184205
/**
@@ -499,13 +520,25 @@ export interface IncidentioFollowUpsShowResponse extends ToolResponse {
499520
}
500521

501522
// Workflow types
502-
interface Workflow {
523+
export interface Workflow {
503524
id: string
504525
name: string
526+
trigger: string
527+
once_for: unknown[]
528+
version: number
529+
expressions: unknown[]
530+
condition_groups: unknown[]
531+
steps: unknown[]
532+
include_private_incidents: boolean
533+
include_private_escalations: boolean
534+
runs_on_incident_modes: string[]
535+
continue_on_step_error: boolean
536+
runs_on_incidents: 'newly_created' | 'newly_created_and_active' | 'active' | 'all'
505537
state: 'active' | 'draft' | 'disabled'
538+
delay?: unknown
506539
folder?: string
507-
created_at?: string
508-
updated_at?: string
540+
runs_from?: string
541+
shortform?: string
509542
}
510543

511544
// Workflows List tool types

apps/sim/tools/incidentio/utils.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
import type { Workflow } from '@/tools/incidentio/types'
2+
13
function getJsonParseErrorMessage(error: unknown): string {
24
return error instanceof Error ? error.message : String(error)
35
}
46

7+
function toStringValue(value: unknown): string {
8+
return typeof value === 'string' ? value : String(value ?? '')
9+
}
10+
11+
function toOptionalStringValue(value: unknown): string | undefined {
12+
return typeof value === 'string' && value ? value : undefined
13+
}
14+
15+
function toNumberValue(value: unknown): number {
16+
return typeof value === 'number' ? value : Number(value ?? 0)
17+
}
18+
19+
function toBooleanValue(value: unknown): boolean {
20+
return value === true
21+
}
22+
23+
function toArrayValue<T = unknown>(value: unknown): T[] {
24+
return Array.isArray(value) ? (value as T[]) : []
25+
}
26+
527
export function parseIncidentioJsonParam(
628
jsonString: string | undefined,
729
paramName: string,
@@ -26,3 +48,26 @@ export function parseRequiredIncidentioJsonParam(
2648

2749
return parseIncidentioJsonParam(jsonString, paramName, undefined)
2850
}
51+
52+
export function mapIncidentioWorkflow(workflow: Record<string, unknown>): Workflow {
53+
return {
54+
id: toStringValue(workflow.id),
55+
name: toStringValue(workflow.name),
56+
trigger: toStringValue(workflow.trigger),
57+
once_for: toArrayValue(workflow.once_for),
58+
version: toNumberValue(workflow.version),
59+
expressions: toArrayValue(workflow.expressions),
60+
condition_groups: toArrayValue(workflow.condition_groups),
61+
steps: toArrayValue(workflow.steps),
62+
include_private_incidents: toBooleanValue(workflow.include_private_incidents),
63+
include_private_escalations: toBooleanValue(workflow.include_private_escalations),
64+
runs_on_incident_modes: toArrayValue<string>(workflow.runs_on_incident_modes),
65+
continue_on_step_error: toBooleanValue(workflow.continue_on_step_error),
66+
runs_on_incidents: toStringValue(workflow.runs_on_incidents) as Workflow['runs_on_incidents'],
67+
state: toStringValue(workflow.state) as Workflow['state'],
68+
delay: workflow.delay,
69+
folder: toOptionalStringValue(workflow.folder),
70+
runs_from: toOptionalStringValue(workflow.runs_from),
71+
shortform: toOptionalStringValue(workflow.shortform),
72+
}
73+
}

apps/sim/tools/incidentio/workflows_create.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { WorkflowsCreateParams, WorkflowsCreateResponse } from '@/tools/incidentio/types'
2-
import { parseIncidentioJsonParam } from '@/tools/incidentio/utils'
2+
import { INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES } from '@/tools/incidentio/types'
3+
import { mapIncidentioWorkflow, parseIncidentioJsonParam } from '@/tools/incidentio/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
export const workflowsCreateTool: ToolConfig<WorkflowsCreateParams, WorkflowsCreateResponse> = {
@@ -157,14 +158,7 @@ export const workflowsCreateTool: ToolConfig<WorkflowsCreateParams, WorkflowsCre
157158
success: true,
158159
output: {
159160
management_meta: data.management_meta,
160-
workflow: {
161-
id: data.workflow.id,
162-
name: data.workflow.name,
163-
state: data.workflow.state,
164-
folder: data.workflow.folder,
165-
created_at: data.workflow.created_at,
166-
updated_at: data.workflow.updated_at,
167-
},
161+
workflow: mapIncidentioWorkflow(data.workflow),
168162
},
169163
}
170164
},
@@ -173,25 +167,7 @@ export const workflowsCreateTool: ToolConfig<WorkflowsCreateParams, WorkflowsCre
173167
workflow: {
174168
type: 'object',
175169
description: 'The created workflow',
176-
properties: {
177-
id: { type: 'string', description: 'Unique identifier for the workflow' },
178-
name: { type: 'string', description: 'Name of the workflow' },
179-
state: {
180-
type: 'string',
181-
description: 'State of the workflow (active, draft, or disabled)',
182-
},
183-
folder: { type: 'string', description: 'Folder the workflow belongs to', optional: true },
184-
created_at: {
185-
type: 'string',
186-
description: 'When the workflow was created',
187-
optional: true,
188-
},
189-
updated_at: {
190-
type: 'string',
191-
description: 'When the workflow was last updated',
192-
optional: true,
193-
},
194-
},
170+
properties: INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES,
195171
},
196172
management_meta: {
197173
type: 'json',

apps/sim/tools/incidentio/workflows_list.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { WorkflowsListParams, WorkflowsListResponse } from '@/tools/incidentio/types'
2+
import { INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES } from '@/tools/incidentio/types'
3+
import { mapIncidentioWorkflow } from '@/tools/incidentio/utils'
24
import type { ToolConfig } from '@/tools/types'
35

46
export const workflowsListTool: ToolConfig<WorkflowsListParams, WorkflowsListResponse> = {
@@ -31,14 +33,10 @@ export const workflowsListTool: ToolConfig<WorkflowsListParams, WorkflowsListRes
3133
return {
3234
success: true,
3335
output: {
34-
workflows: data.workflows.map((workflow: any) => ({
35-
id: workflow.id,
36-
name: workflow.name,
37-
state: workflow.state,
38-
folder: workflow.folder,
39-
created_at: workflow.created_at,
40-
updated_at: workflow.updated_at,
41-
})),
36+
workflows:
37+
data.workflows?.map((workflow: Record<string, unknown>) =>
38+
mapIncidentioWorkflow(workflow)
39+
) ?? [],
4240
},
4341
}
4442
},
@@ -49,25 +47,7 @@ export const workflowsListTool: ToolConfig<WorkflowsListParams, WorkflowsListRes
4947
description: 'List of workflows',
5048
items: {
5149
type: 'object',
52-
properties: {
53-
id: { type: 'string', description: 'Unique identifier for the workflow' },
54-
name: { type: 'string', description: 'Name of the workflow' },
55-
state: {
56-
type: 'string',
57-
description: 'State of the workflow (active, draft, or disabled)',
58-
},
59-
folder: { type: 'string', description: 'Folder the workflow belongs to', optional: true },
60-
created_at: {
61-
type: 'string',
62-
description: 'When the workflow was created',
63-
optional: true,
64-
},
65-
updated_at: {
66-
type: 'string',
67-
description: 'When the workflow was last updated',
68-
optional: true,
69-
},
70-
},
50+
properties: INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES,
7151
},
7252
},
7353
},

apps/sim/tools/incidentio/workflows_show.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { WorkflowsShowParams, WorkflowsShowResponse } from '@/tools/incidentio/types'
2+
import { INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES } from '@/tools/incidentio/types'
3+
import { mapIncidentioWorkflow } from '@/tools/incidentio/utils'
24
import type { ToolConfig } from '@/tools/types'
35

46
export const workflowsShowTool: ToolConfig<WorkflowsShowParams, WorkflowsShowResponse> = {
@@ -38,14 +40,7 @@ export const workflowsShowTool: ToolConfig<WorkflowsShowParams, WorkflowsShowRes
3840
success: true,
3941
output: {
4042
management_meta: data.management_meta,
41-
workflow: {
42-
id: data.workflow.id,
43-
name: data.workflow.name,
44-
state: data.workflow.state,
45-
folder: data.workflow.folder,
46-
created_at: data.workflow.created_at,
47-
updated_at: data.workflow.updated_at,
48-
},
43+
workflow: mapIncidentioWorkflow(data.workflow),
4944
},
5045
}
5146
},
@@ -54,25 +49,7 @@ export const workflowsShowTool: ToolConfig<WorkflowsShowParams, WorkflowsShowRes
5449
workflow: {
5550
type: 'object',
5651
description: 'The workflow details',
57-
properties: {
58-
id: { type: 'string', description: 'Unique identifier for the workflow' },
59-
name: { type: 'string', description: 'Name of the workflow' },
60-
state: {
61-
type: 'string',
62-
description: 'State of the workflow (active, draft, or disabled)',
63-
},
64-
folder: { type: 'string', description: 'Folder the workflow belongs to', optional: true },
65-
created_at: {
66-
type: 'string',
67-
description: 'When the workflow was created',
68-
optional: true,
69-
},
70-
updated_at: {
71-
type: 'string',
72-
description: 'When the workflow was last updated',
73-
optional: true,
74-
},
75-
},
52+
properties: INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES,
7653
},
7754
management_meta: {
7855
type: 'json',

apps/sim/tools/incidentio/workflows_update.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { WorkflowsUpdateParams, WorkflowsUpdateResponse } from '@/tools/incidentio/types'
2+
import { INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES } from '@/tools/incidentio/types'
23
import {
4+
mapIncidentioWorkflow,
35
parseIncidentioJsonParam,
46
parseRequiredIncidentioJsonParam,
57
} from '@/tools/incidentio/utils'
@@ -140,14 +142,7 @@ export const workflowsUpdateTool: ToolConfig<WorkflowsUpdateParams, WorkflowsUpd
140142
success: true,
141143
output: {
142144
management_meta: data.management_meta,
143-
workflow: {
144-
id: data.workflow.id,
145-
name: data.workflow.name,
146-
state: data.workflow.state,
147-
folder: data.workflow.folder,
148-
created_at: data.workflow.created_at,
149-
updated_at: data.workflow.updated_at,
150-
},
145+
workflow: mapIncidentioWorkflow(data.workflow),
151146
},
152147
}
153148
},
@@ -156,25 +151,7 @@ export const workflowsUpdateTool: ToolConfig<WorkflowsUpdateParams, WorkflowsUpd
156151
workflow: {
157152
type: 'object',
158153
description: 'The updated workflow',
159-
properties: {
160-
id: { type: 'string', description: 'Unique identifier for the workflow' },
161-
name: { type: 'string', description: 'Name of the workflow' },
162-
state: {
163-
type: 'string',
164-
description: 'State of the workflow (active, draft, or disabled)',
165-
},
166-
folder: { type: 'string', description: 'Folder the workflow belongs to', optional: true },
167-
created_at: {
168-
type: 'string',
169-
description: 'When the workflow was created',
170-
optional: true,
171-
},
172-
updated_at: {
173-
type: 'string',
174-
description: 'When the workflow was last updated',
175-
optional: true,
176-
},
177-
},
154+
properties: INCIDENTIO_WORKFLOW_OUTPUT_PROPERTIES,
178155
},
179156
management_meta: {
180157
type: 'json',

0 commit comments

Comments
 (0)