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

144 lines
5.1 KiB
TypeScript

import type { RootlyListOnCallsParams, RootlyListOnCallsResponse } from '@/tools/rootly/types'
import type { ToolConfig } from '@/tools/types'
export const rootlyListOnCallsTool: ToolConfig<RootlyListOnCallsParams, RootlyListOnCallsResponse> =
{
id: 'rootly_list_on_calls',
name: 'Rootly List On-Calls',
description: 'List current on-call entries from Rootly with optional filtering.',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Rootly API key',
},
scheduleIds: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated schedule IDs to filter by',
},
escalationPolicyIds: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated escalation policy IDs to filter by',
},
userIds: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated user IDs to filter by',
},
serviceIds: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Comma-separated service IDs to filter by',
},
},
request: {
url: (params) => {
const queryParams = new URLSearchParams()
if (params.scheduleIds) queryParams.set('filter[schedule_ids]', params.scheduleIds)
if (params.escalationPolicyIds)
queryParams.set('filter[escalation_policy_ids]', params.escalationPolicyIds)
if (params.userIds) queryParams.set('filter[user_ids]', params.userIds)
if (params.serviceIds) queryParams.set('filter[service_ids]', params.serviceIds)
queryParams.set('include', 'user,schedule,escalation_policy')
return `https://api.rootly.com/v1/oncalls?${queryParams.toString()}`
},
method: 'GET',
headers: (params) => ({
'Content-Type': 'application/vnd.api+json',
Authorization: `Bearer ${params.apiKey}`,
}),
},
transformResponse: async (response: Response) => {
if (!response.ok) {
const errorData = await response.json().catch(() => ({}))
return {
success: false,
output: { onCalls: [], totalCount: 0 },
error: errorData.errors?.[0]?.detail || `HTTP ${response.status}: ${response.statusText}`,
}
}
const data = await response.json()
const included = (data.included || []) as Record<string, unknown>[]
const findIncluded = (
type: string,
id: string | null
): Record<string, unknown> | undefined =>
id ? included.find((i) => i.type === type && i.id === id) : undefined
const onCalls = (data.data || []).map((item: Record<string, unknown>) => {
const attrs = (item.attributes || {}) as Record<string, unknown>
const rels = (item.relationships || {}) as Record<string, Record<string, unknown>>
const userId = ((rels.user?.data as Record<string, unknown>)?.id as string) ?? null
const scheduleId = ((rels.schedule?.data as Record<string, unknown>)?.id as string) ?? null
const escalationPolicyId =
((rels.escalation_policy?.data as Record<string, unknown>)?.id as string) ?? null
const userIncl = findIncluded('users', userId)
const scheduleIncl = findIncluded('schedules', scheduleId)
return {
id: (item.id as string) ?? null,
userId,
userName: userIncl
? (((userIncl.attributes as Record<string, unknown>)?.full_name as string) ?? null)
: null,
scheduleId,
scheduleName: scheduleIncl
? (((scheduleIncl.attributes as Record<string, unknown>)?.name as string) ?? null)
: null,
escalationPolicyId,
startTime: (attrs.starts_at as string) ?? null,
endTime: (attrs.ends_at as string) ?? null,
}
})
return {
success: true,
output: {
onCalls,
totalCount: data.meta?.total_count ?? onCalls.length,
},
}
},
outputs: {
onCalls: {
type: 'array',
description: 'List of on-call entries',
items: {
type: 'object',
properties: {
id: { type: 'string', description: 'Unique on-call entry ID' },
userId: { type: 'string', description: 'ID of the on-call user' },
userName: { type: 'string', description: 'Name of the on-call user' },
scheduleId: { type: 'string', description: 'ID of the associated schedule' },
scheduleName: { type: 'string', description: 'Name of the associated schedule' },
escalationPolicyId: {
type: 'string',
description: 'ID of the associated escalation policy',
},
startTime: { type: 'string', description: 'On-call start time' },
endTime: { type: 'string', description: 'On-call end time' },
},
},
},
totalCount: {
type: 'number',
description: 'Total number of on-call entries returned',
},
},
}