-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontracts.ts
More file actions
277 lines (244 loc) · 9.21 KB
/
contracts.ts
File metadata and controls
277 lines (244 loc) · 9.21 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
import { z } from 'zod';
export const threadKindSchema = z.enum(['issue', 'pull_request']);
export type ThreadKind = z.infer<typeof threadKindSchema>;
export const searchModeSchema = z.enum(['keyword', 'semantic', 'hybrid']);
export type SearchMode = z.infer<typeof searchModeSchema>;
export const repositorySchema = z.object({
id: z.number().int().positive(),
owner: z.string(),
name: z.string(),
fullName: z.string(),
githubRepoId: z.string().nullable(),
updatedAt: z.string(),
});
export type RepositoryDto = z.infer<typeof repositorySchema>;
export const threadSchema = z.object({
id: z.number().int().positive(),
repoId: z.number().int().positive(),
number: z.number().int().positive(),
kind: threadKindSchema,
state: z.string(),
isClosed: z.boolean(),
closedAtGh: z.string().nullable().optional(),
closedAtLocal: z.string().nullable().optional(),
closeReasonLocal: z.string().nullable().optional(),
title: z.string(),
body: z.string().nullable(),
authorLogin: z.string().nullable(),
htmlUrl: z.string().url(),
labels: z.array(z.string()),
updatedAtGh: z.string().nullable(),
clusterId: z.number().int().positive().nullable().optional(),
});
export type ThreadDto = z.infer<typeof threadSchema>;
export const healthResponseSchema = z.object({
ok: z.boolean(),
configPath: z.string(),
configFileExists: z.boolean(),
dbPath: z.string(),
apiPort: z.number().int().positive(),
githubConfigured: z.boolean(),
openaiConfigured: z.boolean(),
});
export type HealthResponse = z.infer<typeof healthResponseSchema>;
export const repositoriesResponseSchema = z.object({
repositories: z.array(repositorySchema),
});
export type RepositoriesResponse = z.infer<typeof repositoriesResponseSchema>;
export const threadsResponseSchema = z.object({
repository: repositorySchema,
threads: z.array(threadSchema),
});
export type ThreadsResponse = z.infer<typeof threadsResponseSchema>;
export const neighborSchema = z.object({
threadId: z.number().int().positive(),
number: z.number().int().positive(),
kind: threadKindSchema,
title: z.string(),
score: z.number(),
});
export type NeighborDto = z.infer<typeof neighborSchema>;
export const authorThreadSchema = z.object({
thread: threadSchema,
strongestSameAuthorMatch: neighborSchema.nullable(),
});
export type AuthorThreadDto = z.infer<typeof authorThreadSchema>;
export const authorThreadsResponseSchema = z.object({
repository: repositorySchema,
authorLogin: z.string(),
threads: z.array(authorThreadSchema),
});
export type AuthorThreadsResponse = z.infer<typeof authorThreadsResponseSchema>;
export const searchHitSchema = z.object({
thread: threadSchema,
keywordScore: z.number().nullable(),
semanticScore: z.number().nullable(),
hybridScore: z.number(),
neighbors: z.array(neighborSchema).default([]),
});
export type SearchHitDto = z.infer<typeof searchHitSchema>;
export const searchResponseSchema = z.object({
repository: repositorySchema,
query: z.string(),
mode: searchModeSchema,
hits: z.array(searchHitSchema),
});
export type SearchResponse = z.infer<typeof searchResponseSchema>;
export const neighborsResponseSchema = z.object({
repository: repositorySchema,
thread: threadSchema,
neighbors: z.array(neighborSchema),
});
export type NeighborsResponse = z.infer<typeof neighborsResponseSchema>;
export const clusterMemberSchema = z.object({
threadId: z.number().int().positive(),
number: z.number().int().positive(),
kind: threadKindSchema,
isClosed: z.boolean().default(false),
title: z.string(),
scoreToRepresentative: z.number().nullable(),
});
export type ClusterMemberDto = z.infer<typeof clusterMemberSchema>;
export const clusterSchema = z.object({
id: z.number().int().positive(),
repoId: z.number().int().positive(),
isClosed: z.boolean().default(false),
closedAtLocal: z.string().nullable().optional(),
closeReasonLocal: z.string().nullable().optional(),
representativeThreadId: z.number().int().positive().nullable(),
memberCount: z.number().int().nonnegative(),
members: z.array(clusterMemberSchema),
});
export type ClusterDto = z.infer<typeof clusterSchema>;
export const clustersResponseSchema = z.object({
repository: repositorySchema,
clusters: z.array(clusterSchema),
});
export type ClustersResponse = z.infer<typeof clustersResponseSchema>;
export const repoStatsSchema = z.object({
openIssueCount: z.number().int().nonnegative(),
openPullRequestCount: z.number().int().nonnegative(),
lastGithubReconciliationAt: z.string().nullable(),
lastEmbedRefreshAt: z.string().nullable(),
staleEmbedThreadCount: z.number().int().nonnegative(),
staleEmbedSourceCount: z.number().int().nonnegative(),
latestClusterRunId: z.number().int().positive().nullable(),
latestClusterRunFinishedAt: z.string().nullable(),
});
export type RepoStatsDto = z.infer<typeof repoStatsSchema>;
export const clusterSummarySchema = z.object({
clusterId: z.number().int().positive(),
displayTitle: z.string(),
isClosed: z.boolean().default(false),
closedAtLocal: z.string().nullable().optional(),
closeReasonLocal: z.string().nullable().optional(),
totalCount: z.number().int().nonnegative(),
issueCount: z.number().int().nonnegative(),
pullRequestCount: z.number().int().nonnegative(),
latestUpdatedAt: z.string().nullable(),
representativeThreadId: z.number().int().positive().nullable(),
representativeNumber: z.number().int().positive().nullable(),
representativeKind: threadKindSchema.nullable(),
});
export type ClusterSummaryDto = z.infer<typeof clusterSummarySchema>;
export const clusterSummariesResponseSchema = z.object({
repository: repositorySchema,
stats: repoStatsSchema,
clusters: z.array(clusterSummarySchema),
});
export type ClusterSummariesResponse = z.infer<typeof clusterSummariesResponseSchema>;
export const threadSummariesSchema = z.object({
problem_summary: z.string().optional(),
solution_summary: z.string().optional(),
maintainer_signal_summary: z.string().optional(),
dedupe_summary: z.string().optional(),
});
export type ThreadSummariesDto = z.infer<typeof threadSummariesSchema>;
export const clusterThreadDumpSchema = z.object({
thread: threadSchema,
bodySnippet: z.string().nullable(),
summaries: threadSummariesSchema,
});
export type ClusterThreadDumpDto = z.infer<typeof clusterThreadDumpSchema>;
export const clusterDetailResponseSchema = z.object({
repository: repositorySchema,
stats: repoStatsSchema,
cluster: clusterSummarySchema,
members: z.array(clusterThreadDumpSchema),
});
export type ClusterDetailResponse = z.infer<typeof clusterDetailResponseSchema>;
export const syncResultSchema = z.object({
runId: z.number().int().positive(),
threadsSynced: z.number().int().nonnegative(),
commentsSynced: z.number().int().nonnegative(),
threadsClosed: z.number().int().nonnegative(),
});
export type SyncResultDto = z.infer<typeof syncResultSchema>;
export const embedResultSchema = z.object({
runId: z.number().int().positive(),
embedded: z.number().int().nonnegative(),
});
export type EmbedResultDto = z.infer<typeof embedResultSchema>;
export const clusterResultSchema = z.object({
runId: z.number().int().positive(),
edges: z.number().int().nonnegative(),
clusters: z.number().int().nonnegative(),
});
export type ClusterResultDto = z.infer<typeof clusterResultSchema>;
export const refreshRequestSchema = z.object({
owner: z.string(),
repo: z.string(),
sync: z.boolean().optional(),
embed: z.boolean().optional(),
cluster: z.boolean().optional(),
});
export type RefreshRequest = z.infer<typeof refreshRequestSchema>;
export const refreshResponseSchema = z.object({
repository: repositorySchema,
selected: z.object({
sync: z.boolean(),
embed: z.boolean(),
cluster: z.boolean(),
}),
sync: syncResultSchema.nullable(),
embed: embedResultSchema.nullable(),
cluster: clusterResultSchema.nullable(),
});
export type RefreshResponse = z.infer<typeof refreshResponseSchema>;
export const closeThreadRequestSchema = z.object({
owner: z.string(),
repo: z.string(),
threadNumber: z.number().int().positive(),
});
export type CloseThreadRequest = z.infer<typeof closeThreadRequestSchema>;
export const closeClusterRequestSchema = z.object({
owner: z.string(),
repo: z.string(),
clusterId: z.number().int().positive(),
});
export type CloseClusterRequest = z.infer<typeof closeClusterRequestSchema>;
export const closeResponseSchema = z.object({
ok: z.boolean(),
repository: repositorySchema,
thread: threadSchema.nullable().optional(),
clusterId: z.number().int().positive().nullable().optional(),
clusterClosed: z.boolean().optional(),
message: z.string(),
});
export type CloseResponse = z.infer<typeof closeResponseSchema>;
export const rerunActionSchema = z.enum(['summarize', 'embed', 'cluster']);
export type RerunAction = z.infer<typeof rerunActionSchema>;
export const actionRequestSchema = z.object({
owner: z.string(),
repo: z.string(),
action: rerunActionSchema,
threadNumber: z.number().int().positive().optional(),
});
export type ActionRequest = z.infer<typeof actionRequestSchema>;
export const actionResponseSchema = z.object({
ok: z.boolean(),
action: rerunActionSchema,
runId: z.number().int().positive().nullable(),
message: z.string(),
});
export type ActionResponse = z.infer<typeof actionResponseSchema>;