-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathschemas.ts
More file actions
299 lines (260 loc) · 9.51 KB
/
schemas.ts
File metadata and controls
299 lines (260 loc) · 9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// @NOTE : Please keep this file in sync with @sourcebot/web/src/features/search/types.ts
// At some point, we should move these to a shared package...
import { z } from "zod";
export 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(),
});
export const rangeSchema = z.object({
start: locationSchema,
end: locationSchema,
});
export const symbolSchema = z.object({
symbol: z.string(),
kind: z.string(),
});
export const searchOptionsSchema = z.object({
matches: z.number(), // The number of matches to return.
contextLines: z.number().optional(), // The number of context lines to return.
whole: z.boolean().optional(), // Whether to return the whole file as part of the response.
isRegexEnabled: z.boolean().optional(), // Whether to enable regular expression search.
isCaseSensitivityEnabled: z.boolean().optional(), // Whether to enable case sensitivity.
});
export const searchRequestSchema = z.object({
query: z.string(), // The zoekt query to execute.
...searchOptionsSchema.shape,
});
export const repositoryInfoSchema = z.object({
id: z.number(),
codeHostType: z.string(),
name: z.string(),
displayName: z.string().optional(),
webUrl: z.string().optional(),
});
// Many of these fields are defined in zoekt/api.go.
export const searchStatsSchema = z.object({
// The actual number of matches returned by the search.
// This will always be less than or equal to `totalMatchCount`.
actualMatchCount: z.number(),
// The total number of matches found during the search.
totalMatchCount: z.number(),
// The duration (in nanoseconds) of the search.
duration: z.number(),
// Number of files containing a match.
fileCount: z.number(),
// Candidate files whose contents weren't examined because we
// gathered enough matches.
filesSkipped: z.number(),
// Amount of I/O for reading contents.
contentBytesLoaded: z.number(),
// Amount of I/O for reading from index.
indexBytesLoaded: z.number(),
// Number of search shards that had a crash.
crashes: z.number(),
// Number of files in shards that we considered.
shardFilesConsidered: z.number(),
// Files that we evaluated. Equivalent to files for which all
// atom matches (including negations) evaluated to true.
filesConsidered: z.number(),
// Files for which we loaded file content to verify substring matches
filesLoaded: z.number(),
// Shards that we scanned to find matches.
shardsScanned: z.number(),
// Shards that we did not process because a query was canceled.
shardsSkipped: z.number(),
// Shards that we did not process because the query was rejected by the
// ngram filter indicating it had no matches.
shardsSkippedFilter: z.number(),
// Number of candidate matches as a result of searching ngrams.
ngramMatches: z.number(),
// NgramLookups is the number of times we accessed an ngram in the index.
ngramLookups: z.number(),
// Wall clock time for queued search.
wait: z.number(),
// Aggregate wall clock time spent constructing and pruning the match tree.
// This accounts for time such as lookups in the trigram index.
matchTreeConstruction: z.number(),
// Aggregate wall clock time spent searching the match tree. This accounts
// for the bulk of search work done looking for matches.
matchTreeSearch: z.number(),
// Number of times regexp was called on files that we evaluated.
regexpsConsidered: z.number(),
// FlushReason explains why results were flushed.
flushReason: z.string(),
});
export const searchResponseSchema = z.object({
stats: searchStatsSchema,
files: z.array(z.object({
fileName: z.object({
// The name of the file
text: z.string(),
// Any matching ranges
matchRanges: z.array(rangeSchema),
}),
webUrl: z.string(),
externalWebUrl: z.string().optional(),
repository: z.string(),
repositoryId: z.number(),
language: z.string(),
chunks: z.array(z.object({
content: z.string(),
matchRanges: z.array(rangeSchema),
contentStart: locationSchema,
symbols: z.array(z.object({
...symbolSchema.shape,
parent: symbolSchema.optional(),
})).optional(),
})),
branches: z.array(z.string()).optional(),
// Set if `whole` is true.
content: z.string().optional(),
})),
repositoryInfo: z.array(repositoryInfoSchema),
isSearchExhaustive: z.boolean(),
});
export const repositoryQuerySchema = z.object({
codeHostType: z.string(),
repoId: z.number(),
repoName: z.string(),
repoDisplayName: z.string().optional(),
webUrl: z.string(),
externalWebUrl: z.string().optional(),
imageUrl: z.string().optional(),
indexedAt: z.coerce.date().optional(),
pushedAt: z.coerce.date().optional(),
});
export const listReposResponseSchema = repositoryQuerySchema.array();
export const listReposQueryParamsSchema = z.object({
query: z
.string()
.describe("Filter repositories by name (case-insensitive)")
.optional(),
page: z
.number()
.int()
.positive()
.describe("Page number for pagination (min 1). Default: 1")
.optional()
.default(1),
perPage: z
.number()
.int()
.positive()
.max(100)
.describe("Results per page for pagination (min 1, max 100). Default: 30")
.optional()
.default(30),
sort: z
.enum(['name', 'pushed'])
.describe("Sort repositories by 'name' or 'pushed' (most recent commit). Default: 'name'")
.optional()
.default('name'),
direction: z
.enum(['asc', 'desc'])
.describe("Sort direction: 'asc' or 'desc'. Default: 'asc'")
.optional()
.default('asc'),
});
export const fileSourceRequestSchema = z.object({
repo: z
.string()
.describe("The repository name."),
path: z
.string()
.describe("The path to the file."),
ref: z
.string()
.optional()
.describe("Commit SHA, branch or tag name to fetch the source code for. If not provided, uses the default branch of the repository."),
});
export const fileSourceResponseSchema = z.object({
source: z.string(),
language: z.string(),
path: z.string(),
repo: z.string(),
repoCodeHostType: z.string(),
repoDisplayName: z.string().optional(),
repoExternalWebUrl: z.string().optional(),
webUrl: z.string(),
externalWebUrl: z.string().optional(),
});
export const serviceErrorSchema = z.object({
statusCode: z.number(),
errorCode: z.string(),
message: z.string(),
});
export const listCommitsQueryParamsSchema = z.object({
repo: z
.string()
.describe("The name of the repository to list commits for."),
query: z
.string()
.describe("Search query to filter commits by message content (case-insensitive).")
.optional(),
since: z
.string()
.describe(`Show commits more recent than this date. Filters by actual commit time. Supports ISO 8601 (e.g., '2024-01-01') or relative formats (e.g., '30 days ago', 'last week').`)
.optional(),
until: z
.string()
.describe(`Show commits older than this date. Filters by actual commit time. Supports ISO 8601 (e.g., '2024-12-31') or relative formats (e.g., 'yesterday').`)
.optional(),
author: z
.string()
.describe(`Filter commits by author name or email (case-insensitive).`)
.optional(),
ref: z
.string()
.describe("Commit SHA, branch or tag name to list commits of. If not provided, uses the default branch of the repository.")
.optional(),
page: z
.number()
.int()
.positive()
.describe("Page number for pagination (min 1). Default: 1")
.optional()
.default(1),
perPage: z
.number()
.int()
.positive()
.max(100)
.describe("Results per page for pagination (min 1, max 100). Default: 50")
.optional()
.default(50),
});
export const listCommitsResponseSchema = z.array(z.object({
hash: z.string(),
date: z.string(),
message: z.string(),
refs: z.string(),
body: z.string(),
author_name: z.string(),
author_email: z.string(),
}));
export const askCodebaseRequestSchema = z.object({
query: z
.string()
.describe("The query to ask about the codebase."),
repos: z
.array(z.string())
.optional()
.describe("The repositories that are accessible to the agent during the chat. If not provided, all repositories are accessible."),
});
export const sourceSchema = z.object({
type: z.literal('file'),
repo: z.string(),
path: z.string(),
name: z.string(),
language: z.string(),
revision: z.string(),
});
export const askCodebaseResponseSchema = z.object({
answer: z.string().describe("The agent's final answer in markdown format"),
chatId: z.string().describe("ID of the persisted chat session"),
chatUrl: z.string().describe("URL to view the chat in the web UI"),
});