@ghcrawl/api-contract 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +44 -0
- package/src/client.ts +135 -0
- package/src/contracts.test.ts +85 -0
- package/src/contracts.ts +229 -0
- package/src/index.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PwrDrvr LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ghcrawl/api-contract",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "ghcrawl shared transport contracts and validation schemas",
|
|
6
|
+
"author": "PwrDrvr LLC <harold@pwrdrvr.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/pwrdrvr/ghcrawl",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/pwrdrvr/ghcrawl/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/pwrdrvr/ghcrawl.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ghcrawl",
|
|
18
|
+
"api",
|
|
19
|
+
"contracts",
|
|
20
|
+
"zod"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"src"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./src/index.ts",
|
|
34
|
+
"default": "./src/index.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"zod": "^3.24.1"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "tsx --test src/*.test.ts src/**/*.test.ts"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
actionRequestSchema,
|
|
3
|
+
actionResponseSchema,
|
|
4
|
+
clusterDetailResponseSchema,
|
|
5
|
+
clusterSummariesResponseSchema,
|
|
6
|
+
clustersResponseSchema,
|
|
7
|
+
healthResponseSchema,
|
|
8
|
+
refreshRequestSchema,
|
|
9
|
+
refreshResponseSchema,
|
|
10
|
+
repositoriesResponseSchema,
|
|
11
|
+
searchResponseSchema,
|
|
12
|
+
threadsResponseSchema,
|
|
13
|
+
type ActionRequest,
|
|
14
|
+
type ActionResponse,
|
|
15
|
+
type ClusterDetailResponse,
|
|
16
|
+
type ClusterSummariesResponse,
|
|
17
|
+
type ClustersResponse,
|
|
18
|
+
type HealthResponse,
|
|
19
|
+
type RefreshRequest,
|
|
20
|
+
type RefreshResponse,
|
|
21
|
+
type RepositoriesResponse,
|
|
22
|
+
type SearchMode,
|
|
23
|
+
type SearchResponse,
|
|
24
|
+
type ThreadsResponse,
|
|
25
|
+
} from './contracts.js';
|
|
26
|
+
|
|
27
|
+
export type GitcrawlClient = {
|
|
28
|
+
health: () => Promise<HealthResponse>;
|
|
29
|
+
listRepositories: () => Promise<RepositoriesResponse>;
|
|
30
|
+
listThreads: (params: { owner: string; repo: string; kind?: 'issue' | 'pull_request' }) => Promise<ThreadsResponse>;
|
|
31
|
+
search: (params: { owner: string; repo: string; query: string; mode?: SearchMode }) => Promise<SearchResponse>;
|
|
32
|
+
listClusters: (params: { owner: string; repo: string }) => Promise<ClustersResponse>;
|
|
33
|
+
listClusterSummaries: (params: {
|
|
34
|
+
owner: string;
|
|
35
|
+
repo: string;
|
|
36
|
+
minSize?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
sort?: 'recent' | 'size';
|
|
39
|
+
search?: string;
|
|
40
|
+
}) => Promise<ClusterSummariesResponse>;
|
|
41
|
+
getClusterDetail: (params: {
|
|
42
|
+
owner: string;
|
|
43
|
+
repo: string;
|
|
44
|
+
clusterId: number;
|
|
45
|
+
memberLimit?: number;
|
|
46
|
+
bodyChars?: number;
|
|
47
|
+
}) => Promise<ClusterDetailResponse>;
|
|
48
|
+
refresh: (request: RefreshRequest) => Promise<RefreshResponse>;
|
|
49
|
+
rerun: (request: ActionRequest) => Promise<ActionResponse>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type FetchLike = typeof fetch;
|
|
53
|
+
|
|
54
|
+
async function readJson<T>(res: Response, schema: { parse: (value: unknown) => T }): Promise<T> {
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const text = await res.text().catch(() => '');
|
|
57
|
+
throw new Error(`API request failed ${res.status} ${res.statusText}: ${text.slice(0, 2000)}`);
|
|
58
|
+
}
|
|
59
|
+
const value = (await res.json()) as unknown;
|
|
60
|
+
return schema.parse(value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createGitcrawlClient(baseUrl: string, fetchImpl: FetchLike = fetch): GitcrawlClient {
|
|
64
|
+
const normalized = baseUrl.replace(/\/+$/, '');
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
async health() {
|
|
68
|
+
const res = await fetchImpl(`${normalized}/health`);
|
|
69
|
+
return readJson(res, healthResponseSchema);
|
|
70
|
+
},
|
|
71
|
+
async listRepositories() {
|
|
72
|
+
const res = await fetchImpl(`${normalized}/repositories`);
|
|
73
|
+
return readJson(res, repositoriesResponseSchema);
|
|
74
|
+
},
|
|
75
|
+
async listThreads(params) {
|
|
76
|
+
const search = new URLSearchParams({ owner: params.owner, repo: params.repo });
|
|
77
|
+
if (params.kind) search.set('kind', params.kind);
|
|
78
|
+
const res = await fetchImpl(`${normalized}/threads?${search.toString()}`);
|
|
79
|
+
return readJson(res, threadsResponseSchema);
|
|
80
|
+
},
|
|
81
|
+
async search(params) {
|
|
82
|
+
const search = new URLSearchParams({
|
|
83
|
+
owner: params.owner,
|
|
84
|
+
repo: params.repo,
|
|
85
|
+
query: params.query,
|
|
86
|
+
});
|
|
87
|
+
if (params.mode) search.set('mode', params.mode);
|
|
88
|
+
const res = await fetchImpl(`${normalized}/search?${search.toString()}`);
|
|
89
|
+
return readJson(res, searchResponseSchema);
|
|
90
|
+
},
|
|
91
|
+
async listClusters(params) {
|
|
92
|
+
const search = new URLSearchParams({ owner: params.owner, repo: params.repo });
|
|
93
|
+
const res = await fetchImpl(`${normalized}/clusters?${search.toString()}`);
|
|
94
|
+
return readJson(res, clustersResponseSchema);
|
|
95
|
+
},
|
|
96
|
+
async listClusterSummaries(params) {
|
|
97
|
+
const search = new URLSearchParams({ owner: params.owner, repo: params.repo });
|
|
98
|
+
if (params.minSize !== undefined) search.set('minSize', String(params.minSize));
|
|
99
|
+
if (params.limit !== undefined) search.set('limit', String(params.limit));
|
|
100
|
+
if (params.sort) search.set('sort', params.sort);
|
|
101
|
+
if (params.search) search.set('search', params.search);
|
|
102
|
+
const res = await fetchImpl(`${normalized}/cluster-summaries?${search.toString()}`);
|
|
103
|
+
return readJson(res, clusterSummariesResponseSchema);
|
|
104
|
+
},
|
|
105
|
+
async getClusterDetail(params) {
|
|
106
|
+
const search = new URLSearchParams({
|
|
107
|
+
owner: params.owner,
|
|
108
|
+
repo: params.repo,
|
|
109
|
+
clusterId: String(params.clusterId),
|
|
110
|
+
});
|
|
111
|
+
if (params.memberLimit !== undefined) search.set('memberLimit', String(params.memberLimit));
|
|
112
|
+
if (params.bodyChars !== undefined) search.set('bodyChars', String(params.bodyChars));
|
|
113
|
+
const res = await fetchImpl(`${normalized}/cluster-detail?${search.toString()}`);
|
|
114
|
+
return readJson(res, clusterDetailResponseSchema);
|
|
115
|
+
},
|
|
116
|
+
async refresh(request) {
|
|
117
|
+
const body = refreshRequestSchema.parse(request);
|
|
118
|
+
const res = await fetchImpl(`${normalized}/actions/refresh`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { 'content-type': 'application/json' },
|
|
121
|
+
body: JSON.stringify(body),
|
|
122
|
+
});
|
|
123
|
+
return readJson(res, refreshResponseSchema);
|
|
124
|
+
},
|
|
125
|
+
async rerun(request) {
|
|
126
|
+
const body = actionRequestSchema.parse(request);
|
|
127
|
+
const res = await fetchImpl(`${normalized}/actions/rerun`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: { 'content-type': 'application/json' },
|
|
130
|
+
body: JSON.stringify(body),
|
|
131
|
+
});
|
|
132
|
+
return readJson(res, actionResponseSchema);
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import { actionRequestSchema, healthResponseSchema, neighborsResponseSchema, searchResponseSchema } from './contracts.js';
|
|
5
|
+
|
|
6
|
+
test('health schema accepts configured status payload', () => {
|
|
7
|
+
const parsed = healthResponseSchema.parse({
|
|
8
|
+
ok: true,
|
|
9
|
+
configPath: '/Users/example/.config/ghcrawl/config.json',
|
|
10
|
+
configFileExists: true,
|
|
11
|
+
dbPath: 'data/ghcrawl.db',
|
|
12
|
+
apiPort: 5179,
|
|
13
|
+
githubConfigured: true,
|
|
14
|
+
openaiConfigured: false,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
assert.equal(parsed.apiPort, 5179);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('search schema rejects invalid mode', () => {
|
|
21
|
+
assert.throws(() =>
|
|
22
|
+
searchResponseSchema.parse({
|
|
23
|
+
repository: {
|
|
24
|
+
id: 1,
|
|
25
|
+
owner: 'openclaw',
|
|
26
|
+
name: 'openclaw',
|
|
27
|
+
fullName: 'openclaw/openclaw',
|
|
28
|
+
githubRepoId: null,
|
|
29
|
+
updatedAt: new Date().toISOString(),
|
|
30
|
+
},
|
|
31
|
+
query: 'panic',
|
|
32
|
+
mode: 'invalid',
|
|
33
|
+
hits: [],
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('action request accepts optional thread number', () => {
|
|
39
|
+
const parsed = actionRequestSchema.parse({
|
|
40
|
+
owner: 'openclaw',
|
|
41
|
+
repo: 'openclaw',
|
|
42
|
+
action: 'summarize',
|
|
43
|
+
threadNumber: 42,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
assert.equal(parsed.threadNumber, 42);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('neighbors schema accepts repository, source thread, and neighbor list', () => {
|
|
50
|
+
const parsed = neighborsResponseSchema.parse({
|
|
51
|
+
repository: {
|
|
52
|
+
id: 1,
|
|
53
|
+
owner: 'openclaw',
|
|
54
|
+
name: 'openclaw',
|
|
55
|
+
fullName: 'openclaw/openclaw',
|
|
56
|
+
githubRepoId: null,
|
|
57
|
+
updatedAt: new Date().toISOString(),
|
|
58
|
+
},
|
|
59
|
+
thread: {
|
|
60
|
+
id: 10,
|
|
61
|
+
repoId: 1,
|
|
62
|
+
number: 42,
|
|
63
|
+
kind: 'issue',
|
|
64
|
+
state: 'open',
|
|
65
|
+
title: 'Downloader hangs',
|
|
66
|
+
body: 'The transfer never finishes.',
|
|
67
|
+
authorLogin: 'alice',
|
|
68
|
+
htmlUrl: 'https://github.com/openclaw/openclaw/issues/42',
|
|
69
|
+
labels: ['bug'],
|
|
70
|
+
updatedAtGh: new Date().toISOString(),
|
|
71
|
+
clusterId: null,
|
|
72
|
+
},
|
|
73
|
+
neighbors: [
|
|
74
|
+
{
|
|
75
|
+
threadId: 11,
|
|
76
|
+
number: 43,
|
|
77
|
+
kind: 'pull_request',
|
|
78
|
+
title: 'Fix downloader hang',
|
|
79
|
+
score: 0.93,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
assert.equal(parsed.neighbors[0].number, 43);
|
|
85
|
+
});
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const threadKindSchema = z.enum(['issue', 'pull_request']);
|
|
4
|
+
export type ThreadKind = z.infer<typeof threadKindSchema>;
|
|
5
|
+
|
|
6
|
+
export const searchModeSchema = z.enum(['keyword', 'semantic', 'hybrid']);
|
|
7
|
+
export type SearchMode = z.infer<typeof searchModeSchema>;
|
|
8
|
+
|
|
9
|
+
export const repositorySchema = z.object({
|
|
10
|
+
id: z.number().int().positive(),
|
|
11
|
+
owner: z.string(),
|
|
12
|
+
name: z.string(),
|
|
13
|
+
fullName: z.string(),
|
|
14
|
+
githubRepoId: z.string().nullable(),
|
|
15
|
+
updatedAt: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export type RepositoryDto = z.infer<typeof repositorySchema>;
|
|
18
|
+
|
|
19
|
+
export const threadSchema = z.object({
|
|
20
|
+
id: z.number().int().positive(),
|
|
21
|
+
repoId: z.number().int().positive(),
|
|
22
|
+
number: z.number().int().positive(),
|
|
23
|
+
kind: threadKindSchema,
|
|
24
|
+
state: z.string(),
|
|
25
|
+
title: z.string(),
|
|
26
|
+
body: z.string().nullable(),
|
|
27
|
+
authorLogin: z.string().nullable(),
|
|
28
|
+
htmlUrl: z.string().url(),
|
|
29
|
+
labels: z.array(z.string()),
|
|
30
|
+
updatedAtGh: z.string().nullable(),
|
|
31
|
+
clusterId: z.number().int().positive().nullable().optional(),
|
|
32
|
+
});
|
|
33
|
+
export type ThreadDto = z.infer<typeof threadSchema>;
|
|
34
|
+
|
|
35
|
+
export const healthResponseSchema = z.object({
|
|
36
|
+
ok: z.boolean(),
|
|
37
|
+
configPath: z.string(),
|
|
38
|
+
configFileExists: z.boolean(),
|
|
39
|
+
dbPath: z.string(),
|
|
40
|
+
apiPort: z.number().int().positive(),
|
|
41
|
+
githubConfigured: z.boolean(),
|
|
42
|
+
openaiConfigured: z.boolean(),
|
|
43
|
+
});
|
|
44
|
+
export type HealthResponse = z.infer<typeof healthResponseSchema>;
|
|
45
|
+
|
|
46
|
+
export const repositoriesResponseSchema = z.object({
|
|
47
|
+
repositories: z.array(repositorySchema),
|
|
48
|
+
});
|
|
49
|
+
export type RepositoriesResponse = z.infer<typeof repositoriesResponseSchema>;
|
|
50
|
+
|
|
51
|
+
export const threadsResponseSchema = z.object({
|
|
52
|
+
repository: repositorySchema,
|
|
53
|
+
threads: z.array(threadSchema),
|
|
54
|
+
});
|
|
55
|
+
export type ThreadsResponse = z.infer<typeof threadsResponseSchema>;
|
|
56
|
+
|
|
57
|
+
export const neighborSchema = z.object({
|
|
58
|
+
threadId: z.number().int().positive(),
|
|
59
|
+
number: z.number().int().positive(),
|
|
60
|
+
kind: threadKindSchema,
|
|
61
|
+
title: z.string(),
|
|
62
|
+
score: z.number(),
|
|
63
|
+
});
|
|
64
|
+
export type NeighborDto = z.infer<typeof neighborSchema>;
|
|
65
|
+
|
|
66
|
+
export const searchHitSchema = z.object({
|
|
67
|
+
thread: threadSchema,
|
|
68
|
+
keywordScore: z.number().nullable(),
|
|
69
|
+
semanticScore: z.number().nullable(),
|
|
70
|
+
hybridScore: z.number(),
|
|
71
|
+
neighbors: z.array(neighborSchema).default([]),
|
|
72
|
+
});
|
|
73
|
+
export type SearchHitDto = z.infer<typeof searchHitSchema>;
|
|
74
|
+
|
|
75
|
+
export const searchResponseSchema = z.object({
|
|
76
|
+
repository: repositorySchema,
|
|
77
|
+
query: z.string(),
|
|
78
|
+
mode: searchModeSchema,
|
|
79
|
+
hits: z.array(searchHitSchema),
|
|
80
|
+
});
|
|
81
|
+
export type SearchResponse = z.infer<typeof searchResponseSchema>;
|
|
82
|
+
|
|
83
|
+
export const neighborsResponseSchema = z.object({
|
|
84
|
+
repository: repositorySchema,
|
|
85
|
+
thread: threadSchema,
|
|
86
|
+
neighbors: z.array(neighborSchema),
|
|
87
|
+
});
|
|
88
|
+
export type NeighborsResponse = z.infer<typeof neighborsResponseSchema>;
|
|
89
|
+
|
|
90
|
+
export const clusterMemberSchema = z.object({
|
|
91
|
+
threadId: z.number().int().positive(),
|
|
92
|
+
number: z.number().int().positive(),
|
|
93
|
+
kind: threadKindSchema,
|
|
94
|
+
title: z.string(),
|
|
95
|
+
scoreToRepresentative: z.number().nullable(),
|
|
96
|
+
});
|
|
97
|
+
export type ClusterMemberDto = z.infer<typeof clusterMemberSchema>;
|
|
98
|
+
|
|
99
|
+
export const clusterSchema = z.object({
|
|
100
|
+
id: z.number().int().positive(),
|
|
101
|
+
repoId: z.number().int().positive(),
|
|
102
|
+
representativeThreadId: z.number().int().positive().nullable(),
|
|
103
|
+
memberCount: z.number().int().nonnegative(),
|
|
104
|
+
members: z.array(clusterMemberSchema),
|
|
105
|
+
});
|
|
106
|
+
export type ClusterDto = z.infer<typeof clusterSchema>;
|
|
107
|
+
|
|
108
|
+
export const clustersResponseSchema = z.object({
|
|
109
|
+
repository: repositorySchema,
|
|
110
|
+
clusters: z.array(clusterSchema),
|
|
111
|
+
});
|
|
112
|
+
export type ClustersResponse = z.infer<typeof clustersResponseSchema>;
|
|
113
|
+
|
|
114
|
+
export const repoStatsSchema = z.object({
|
|
115
|
+
openIssueCount: z.number().int().nonnegative(),
|
|
116
|
+
openPullRequestCount: z.number().int().nonnegative(),
|
|
117
|
+
lastGithubReconciliationAt: z.string().nullable(),
|
|
118
|
+
lastEmbedRefreshAt: z.string().nullable(),
|
|
119
|
+
staleEmbedThreadCount: z.number().int().nonnegative(),
|
|
120
|
+
staleEmbedSourceCount: z.number().int().nonnegative(),
|
|
121
|
+
latestClusterRunId: z.number().int().positive().nullable(),
|
|
122
|
+
latestClusterRunFinishedAt: z.string().nullable(),
|
|
123
|
+
});
|
|
124
|
+
export type RepoStatsDto = z.infer<typeof repoStatsSchema>;
|
|
125
|
+
|
|
126
|
+
export const clusterSummarySchema = z.object({
|
|
127
|
+
clusterId: z.number().int().positive(),
|
|
128
|
+
displayTitle: z.string(),
|
|
129
|
+
totalCount: z.number().int().nonnegative(),
|
|
130
|
+
issueCount: z.number().int().nonnegative(),
|
|
131
|
+
pullRequestCount: z.number().int().nonnegative(),
|
|
132
|
+
latestUpdatedAt: z.string().nullable(),
|
|
133
|
+
representativeThreadId: z.number().int().positive().nullable(),
|
|
134
|
+
representativeNumber: z.number().int().positive().nullable(),
|
|
135
|
+
representativeKind: threadKindSchema.nullable(),
|
|
136
|
+
});
|
|
137
|
+
export type ClusterSummaryDto = z.infer<typeof clusterSummarySchema>;
|
|
138
|
+
|
|
139
|
+
export const clusterSummariesResponseSchema = z.object({
|
|
140
|
+
repository: repositorySchema,
|
|
141
|
+
stats: repoStatsSchema,
|
|
142
|
+
clusters: z.array(clusterSummarySchema),
|
|
143
|
+
});
|
|
144
|
+
export type ClusterSummariesResponse = z.infer<typeof clusterSummariesResponseSchema>;
|
|
145
|
+
|
|
146
|
+
export const threadSummariesSchema = z.object({
|
|
147
|
+
problem_summary: z.string().optional(),
|
|
148
|
+
solution_summary: z.string().optional(),
|
|
149
|
+
maintainer_signal_summary: z.string().optional(),
|
|
150
|
+
dedupe_summary: z.string().optional(),
|
|
151
|
+
});
|
|
152
|
+
export type ThreadSummariesDto = z.infer<typeof threadSummariesSchema>;
|
|
153
|
+
|
|
154
|
+
export const clusterThreadDumpSchema = z.object({
|
|
155
|
+
thread: threadSchema,
|
|
156
|
+
bodySnippet: z.string().nullable(),
|
|
157
|
+
summaries: threadSummariesSchema,
|
|
158
|
+
});
|
|
159
|
+
export type ClusterThreadDumpDto = z.infer<typeof clusterThreadDumpSchema>;
|
|
160
|
+
|
|
161
|
+
export const clusterDetailResponseSchema = z.object({
|
|
162
|
+
repository: repositorySchema,
|
|
163
|
+
stats: repoStatsSchema,
|
|
164
|
+
cluster: clusterSummarySchema,
|
|
165
|
+
members: z.array(clusterThreadDumpSchema),
|
|
166
|
+
});
|
|
167
|
+
export type ClusterDetailResponse = z.infer<typeof clusterDetailResponseSchema>;
|
|
168
|
+
|
|
169
|
+
export const syncResultSchema = z.object({
|
|
170
|
+
runId: z.number().int().positive(),
|
|
171
|
+
threadsSynced: z.number().int().nonnegative(),
|
|
172
|
+
commentsSynced: z.number().int().nonnegative(),
|
|
173
|
+
threadsClosed: z.number().int().nonnegative(),
|
|
174
|
+
});
|
|
175
|
+
export type SyncResultDto = z.infer<typeof syncResultSchema>;
|
|
176
|
+
|
|
177
|
+
export const embedResultSchema = z.object({
|
|
178
|
+
runId: z.number().int().positive(),
|
|
179
|
+
embedded: z.number().int().nonnegative(),
|
|
180
|
+
});
|
|
181
|
+
export type EmbedResultDto = z.infer<typeof embedResultSchema>;
|
|
182
|
+
|
|
183
|
+
export const clusterResultSchema = z.object({
|
|
184
|
+
runId: z.number().int().positive(),
|
|
185
|
+
edges: z.number().int().nonnegative(),
|
|
186
|
+
clusters: z.number().int().nonnegative(),
|
|
187
|
+
});
|
|
188
|
+
export type ClusterResultDto = z.infer<typeof clusterResultSchema>;
|
|
189
|
+
|
|
190
|
+
export const refreshRequestSchema = z.object({
|
|
191
|
+
owner: z.string(),
|
|
192
|
+
repo: z.string(),
|
|
193
|
+
sync: z.boolean().optional(),
|
|
194
|
+
embed: z.boolean().optional(),
|
|
195
|
+
cluster: z.boolean().optional(),
|
|
196
|
+
});
|
|
197
|
+
export type RefreshRequest = z.infer<typeof refreshRequestSchema>;
|
|
198
|
+
|
|
199
|
+
export const refreshResponseSchema = z.object({
|
|
200
|
+
repository: repositorySchema,
|
|
201
|
+
selected: z.object({
|
|
202
|
+
sync: z.boolean(),
|
|
203
|
+
embed: z.boolean(),
|
|
204
|
+
cluster: z.boolean(),
|
|
205
|
+
}),
|
|
206
|
+
sync: syncResultSchema.nullable(),
|
|
207
|
+
embed: embedResultSchema.nullable(),
|
|
208
|
+
cluster: clusterResultSchema.nullable(),
|
|
209
|
+
});
|
|
210
|
+
export type RefreshResponse = z.infer<typeof refreshResponseSchema>;
|
|
211
|
+
|
|
212
|
+
export const rerunActionSchema = z.enum(['summarize', 'embed', 'cluster']);
|
|
213
|
+
export type RerunAction = z.infer<typeof rerunActionSchema>;
|
|
214
|
+
|
|
215
|
+
export const actionRequestSchema = z.object({
|
|
216
|
+
owner: z.string(),
|
|
217
|
+
repo: z.string(),
|
|
218
|
+
action: rerunActionSchema,
|
|
219
|
+
threadNumber: z.number().int().positive().optional(),
|
|
220
|
+
});
|
|
221
|
+
export type ActionRequest = z.infer<typeof actionRequestSchema>;
|
|
222
|
+
|
|
223
|
+
export const actionResponseSchema = z.object({
|
|
224
|
+
ok: z.boolean(),
|
|
225
|
+
action: rerunActionSchema,
|
|
226
|
+
runId: z.number().int().positive().nullable(),
|
|
227
|
+
message: z.string(),
|
|
228
|
+
});
|
|
229
|
+
export type ActionResponse = z.infer<typeof actionResponseSchema>;
|
package/src/index.ts
ADDED