import { defineTool } from '@earendil-works/pi-coding-agent'; import { Type } from 'typebox'; import { withLinearAuth, linearGraphQL } from '../client'; import { PaginationParams, paginationVariables, FilterParam } from '../params'; import { WORKFLOW_STATE_SELECTION } from '../selections'; import type { JsonObject, LinearConnection } from '../types'; import { compactObject, asObject } from '../util'; import { renderLinearIssueStatusListCall, renderLinearIssueStatusListResult, } from '../renderers/issue-statuses'; export function issueStatusTools() { return [ defineTool({ name: 'linear_list_issue_statuses', label: 'Linear List Issue Statuses', description: 'List workflow states (issue statuses). Supports full workflowStates query args.', parameters: Type.Object({ ...PaginationParams, ...FilterParam, }), renderCall: renderLinearIssueStatusListCall, async execute(_toolCallId, params, signal, _onUpdate, ctx) { return withLinearAuth(ctx, signal, async (apiKey) => { const variables = compactObject({ ...paginationVariables(params, 50), filter: asObject(params.filter), }); const data = await linearGraphQL<{ workflowStates: LinearConnection; }>( apiKey, `query ListIssueStatuses( $after: String $before: String $filter: WorkflowStateFilter $first: Int $includeArchived: Boolean $last: Int $orderBy: PaginationOrderBy ) { workflowStates( after: $after before: $before filter: $filter first: $first includeArchived: $includeArchived last: $last orderBy: $orderBy ) { nodes { ${WORKFLOW_STATE_SELECTION} } pageInfo { hasNextPage hasPreviousPage startCursor endCursor } } }`, variables, signal, ); const states = data.workflowStates.nodes; const pageInfo = data.workflowStates.pageInfo; return { content: [{ type: 'text', text: JSON.stringify({ states, pageInfo }, null, 2) }], details: { states, pageInfo }, }; }); }, renderResult: renderLinearIssueStatusListResult, }), ]; }