Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(core): parse search API responses (#4572)
Ryan Yu0d8df7032c6f
diff --git a/packages/core/api/client.ts b/packages/core/api/client.tsindex b44e1f69ec..a7322c1388 100644--- a/packages/core/api/client.ts+++ b/packages/core/api/client.ts@@ -159,6 +159,8 @@ import {EMPTY_CREATE_AGENT_FROM_TEMPLATE_RESPONSE,EMPTY_GROUPED_ISSUES_RESPONSE,EMPTY_LIST_ISSUES_RESPONSE,+ EMPTY_SEARCH_ISSUES_RESPONSE,+ EMPTY_SEARCH_PROJECTS_RESPONSE,EMPTY_SQUAD,EMPTY_SQUAD_LIST,EMPTY_SQUAD_MEMBER_STATUS_LIST,@@ -177,6 +179,8 @@ import {RuntimeUsageByAgentListSchema,RuntimeUsageByHourListSchema,RuntimeUsageListSchema,+ SearchIssuesResponseSchema,+ SearchProjectsResponseSchema,SquadSchema,SquadListSchema,SquadMemberStatusListResponseSchema,@@ -551,7 +555,13 @@ export class ApiClient {if (params.limit !== undefined) search.set("limit", String(params.limit));if (params.offset !== undefined) search.set("offset", String(params.offset));if (params.include_closed) search.set("include_closed", "true");- return this.fetch(`/api/issues/search?${search}`, params.signal ? { signal: params.signal } : undefined);+ const raw = await this.fetch<unknown>(+ `/api/issues/search?${search}`,+ params.signal ? { signal: params.signal } : undefined,+ );+ return parseWithFallback(raw, SearchIssuesResponseSchema, EMPTY_SEARCH_ISSUES_RESPONSE, {+ endpoint: "GET /api/issues/search",+ });}async searchProjects(params: { q: string; limit?: number; offset?: number; include_closed?: boolean; signal?: AbortSignal }): Promise<SearchProjectsResponse> {@@ -559,7 +569,13 @@ export class ApiClient {if (params.limit !== undefined) search.set("limit", String(params.limit));if (params.offset !== undefined) search.set("offset", String(params.offset));if (params.include_closed) search.set("include_closed", "true");- return this.fetch(`/api/projects/search?${search}`, params.signal ? { signal: params.signal } : undefined);+ const raw = await this.fetch<unknown>(+ `/api/projects/search?${search}`,+ params.signal ? { signal: params.signal } : undefined,+ );+ return parseWithFallback(raw, SearchProjectsResponseSchema, EMPTY_SEARCH_PROJECTS_RESPONSE, {+ endpoint: "GET /api/projects/search",+ });}async getIssue(id: string): Promise<Issue> {diff --git a/packages/core/api/schema.test.ts b/packages/core/api/schema.test.tsindex ae7d1c9ce4..0850502cda 100644--- a/packages/core/api/schema.test.ts+++ b/packages/core/api/schema.test.ts@@ -91,6 +91,24 @@ describe("ApiClient schema fallback", () => {});});+ describe("searchIssues", () => {+ it("falls back to an empty result when the response is malformed", async () => {+ stubFetchJson({ issues: "not-an-array", total: 0 });+ const client = new ApiClient("https://api.example.test");+ const res = await client.searchIssues({ q: "bug" });+ expect(res).toEqual({ issues: [], total: 0 });+ });+ });++ describe("searchProjects", () => {+ it("falls back to an empty result when the response is malformed", async () => {+ stubFetchJson({ projects: "not-an-array", total: 0 });+ const client = new ApiClient("https://api.example.test");+ const res = await client.searchProjects({ q: "roadmap" });+ expect(res).toEqual({ projects: [], total: 0 });+ });+ });+describe("listAutopilots", () => {const baseAutopilot = {id: "ap-1",diff --git a/packages/core/api/schemas.ts b/packages/core/api/schemas.tsindex 359813e1b6..eb2b4bbaa0 100644--- a/packages/core/api/schemas.ts+++ b/packages/core/api/schemas.ts@@ -17,6 +17,8 @@ import type {GroupedIssuesResponse,ListIssuesResponse,ListWebhookDeliveriesResponse,+ SearchIssuesResponse,+ SearchProjectsResponse,Squad,TimelineEntry,User,@@ -275,6 +277,55 @@ export const EMPTY_LIST_ISSUES_RESPONSE: ListIssuesResponse = {total: 0,};+const SearchIssueResultSchema = IssueSchema.extend({+ match_source: z.string(),+ matched_snippet: z.string().optional(),+ matched_description_snippet: z.string().optional(),+ matched_comment_snippet: z.string().optional(),+}).loose();++export const SearchIssuesResponseSchema = z.object({+ issues: z.array(SearchIssueResultSchema).default([]),+ total: z.number().default(0),+}).loose();++export const EMPTY_SEARCH_ISSUES_RESPONSE: SearchIssuesResponse = {+ issues: [],+ total: 0,+};++const ProjectSchema = z.object({+ id: z.string(),+ workspace_id: z.string(),+ title: z.string(),+ description: z.string().nullable(),+ icon: z.string().nullable(),+ status: z.string(),+ priority: z.string(),+ lead_type: z.string().nullable(),+ lead_id: z.string().nullable(),+ created_at: z.string(),+ updated_at: z.string(),+ issue_count: z.number().default(0),+ done_count: z.number().default(0),+ resource_count: z.number().default(0),+}).loose();++const SearchProjectResultSchema = ProjectSchema.extend({+ match_source: z.string(),+ matched_snippet: z.string().optional(),+}).loose();++export const SearchProjectsResponseSchema = z.object({+ projects: z.array(SearchProjectResultSchema).default([]),+ total: z.number().default(0),+}).loose();++export const EMPTY_SEARCH_PROJECTS_RESPONSE: SearchProjectsResponse = {+ projects: [],+ total: 0,+};+const IssueAssigneeGroupSchema = z.object({id: z.string(),assignee_type: z.string().nullable(),