137 lines
3.9 KiB
TypeScript
137 lines
3.9 KiB
TypeScript
import { z } from 'zod'
|
|
import { defineMethod, type RpcMethod } from '../core'
|
|
import { OptionalFiniteNumber, OptionalString, requiredString } from '../schemas'
|
|
|
|
const VALID_FILTERS = ['assigned', 'created', 'all', 'completed'] as const
|
|
|
|
const Connect = z.object({
|
|
apiKey: requiredString('Invalid API key')
|
|
})
|
|
|
|
const SearchIssues = z.object({
|
|
query: requiredString('Missing query'),
|
|
limit: OptionalFiniteNumber
|
|
})
|
|
|
|
const ListIssues = z
|
|
.object({
|
|
filter: z.enum(VALID_FILTERS).optional(),
|
|
limit: OptionalFiniteNumber
|
|
})
|
|
.optional()
|
|
|
|
const CreateIssue = z.object({
|
|
teamId: requiredString('Team ID is required'),
|
|
title: requiredString('Title is required'),
|
|
description: OptionalString
|
|
})
|
|
|
|
const IssueId = z.object({
|
|
id: requiredString('Issue ID is required')
|
|
})
|
|
|
|
const IssueComment = z.object({
|
|
issueId: requiredString('Issue ID is required'),
|
|
body: requiredString('Comment body is required')
|
|
})
|
|
|
|
const TeamId = z.object({
|
|
teamId: requiredString('Team ID is required')
|
|
})
|
|
|
|
const IssueUpdate = z.object({
|
|
id: requiredString('Issue ID is required'),
|
|
updates: z.object({
|
|
stateId: OptionalString,
|
|
title: OptionalString,
|
|
assigneeId: z.union([z.string(), z.null()]).optional(),
|
|
priority: z.number().int().min(0).max(4).optional(),
|
|
labelIds: z.array(z.string()).optional()
|
|
})
|
|
})
|
|
|
|
export const LINEAR_METHODS: RpcMethod[] = [
|
|
defineMethod({
|
|
name: 'linear.connect',
|
|
params: Connect,
|
|
handler: async (params, { runtime }) => runtime.linearConnect(params.apiKey.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.disconnect',
|
|
params: null,
|
|
handler: async (_params, { runtime }) => runtime.linearDisconnect()
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.status',
|
|
params: null,
|
|
handler: async (_params, { runtime }) => runtime.linearStatus()
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.testConnection',
|
|
params: null,
|
|
handler: async (_params, { runtime }) => runtime.linearTestConnection()
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.searchIssues',
|
|
params: SearchIssues,
|
|
handler: async (params, { runtime }) => runtime.linearSearchIssues(params.query, params.limit)
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.listIssues',
|
|
params: ListIssues,
|
|
handler: async (params, { runtime }) => runtime.linearListIssues(params?.filter, params?.limit)
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.createIssue',
|
|
params: CreateIssue,
|
|
handler: async (params, { runtime }) =>
|
|
runtime.linearCreateIssue(
|
|
params.teamId.trim(),
|
|
params.title.trim(),
|
|
params.description?.trim() || undefined
|
|
)
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.getIssue',
|
|
params: IssueId,
|
|
handler: async (params, { runtime }) => runtime.linearGetIssue(params.id.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.updateIssue',
|
|
params: IssueUpdate,
|
|
handler: async (params, { runtime }) =>
|
|
runtime.linearUpdateIssue(params.id.trim(), params.updates)
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.addIssueComment',
|
|
params: IssueComment,
|
|
handler: async (params, { runtime }) =>
|
|
runtime.linearAddIssueComment(params.issueId.trim(), params.body.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.issueComments',
|
|
params: z.object({ issueId: requiredString('Issue ID is required') }),
|
|
handler: async (params, { runtime }) => runtime.linearIssueComments(params.issueId.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.listTeams',
|
|
params: null,
|
|
handler: async (_params, { runtime }) => runtime.linearListTeams()
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.teamStates',
|
|
params: TeamId,
|
|
handler: async (params, { runtime }) => runtime.linearTeamStates(params.teamId.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.teamLabels',
|
|
params: TeamId,
|
|
handler: async (params, { runtime }) => runtime.linearTeamLabels(params.teamId.trim())
|
|
}),
|
|
defineMethod({
|
|
name: 'linear.teamMembers',
|
|
params: TeamId,
|
|
handler: async (params, { runtime }) => runtime.linearTeamMembers(params.teamId.trim())
|
|
})
|
|
]
|