import { z } from "zod"; export type SearchRequest = z.infer; export const searchRequestSchema = z.object({ query: z.string(), numResults: z.number(), whole: z.optional(z.boolean()), }); export type SearchResponse = z.infer; export type SearchResult = SearchResponse["Result"]; export type SearchResultFile = SearchResult["Files"][number]; export type SearchResultFileMatch = SearchResultFile["ChunkMatches"][number]; export type SearchResultRange = z.infer; export type SearchResultLocation = z.infer; // @see : https://github.com/TaqlaAI/zoekt/blob/main/api.go#L212 const locationSchema = z.object({ // 0-based byte offset from the beginning of the file ByteOffset: z.number(), // 1-based line number from the beginning of the file LineNumber: z.number(), // 1-based column number (in runes) from the beginning of line Column: z.number(), }); const rangeSchema = z.object({ Start: locationSchema, End: locationSchema, }); export const searchResponseSchema = z.object({ Result: z.object({ Duration: z.number(), FileCount: z.number(), Files: z.array(z.object({ FileName: z.string(), Repository: z.string(), Version: z.string(), Language: z.string(), Branches: z.array(z.string()), ChunkMatches: z.array(z.object({ Content: z.string(), Ranges: z.array(rangeSchema), FileName: z.boolean(), ContentStart: locationSchema, Score: z.number(), })), Checksum: z.string(), Score: z.number(), // Set if `whole` is true. Content: z.optional(z.string()), })), }), }); export type FileSourceRequest = z.infer; export const fileSourceRequestSchema = z.object({ fileName: z.string(), repository: z.string() }); export type FileSourceResponse = z.infer; export const fileSourceResponseSchema = z.object({ source: z.string(), });