@code-rag/api-server 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/README.md +26 -0
- package/dist/dashboard/data-collector.d.ts +61 -0
- package/dist/dashboard/data-collector.js +244 -0
- package/dist/dashboard/data-collector.js.map +1 -0
- package/dist/dashboard/data-collector.test.d.ts +1 -0
- package/dist/dashboard/data-collector.test.js +334 -0
- package/dist/dashboard/data-collector.test.js.map +1 -0
- package/dist/dashboard/index.d.ts +10 -0
- package/dist/dashboard/index.js +6 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/dashboard/routes.d.ts +18 -0
- package/dist/dashboard/routes.js +150 -0
- package/dist/dashboard/routes.js.map +1 -0
- package/dist/dashboard/templates.d.ts +47 -0
- package/dist/dashboard/templates.js +591 -0
- package/dist/dashboard/templates.js.map +1 -0
- package/dist/dashboard/templates.test.d.ts +1 -0
- package/dist/dashboard/templates.test.js +408 -0
- package/dist/dashboard/templates.test.js.map +1 -0
- package/dist/dashboard/types.d.ts +119 -0
- package/dist/dashboard/types.js +4 -0
- package/dist/dashboard/types.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/auth.d.ts +37 -0
- package/dist/middleware/auth.js +92 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/rate-limit.d.ts +26 -0
- package/dist/middleware/rate-limit.js +79 -0
- package/dist/middleware/rate-limit.js.map +1 -0
- package/dist/openapi.d.ts +14 -0
- package/dist/openapi.js +363 -0
- package/dist/openapi.js.map +1 -0
- package/dist/routes/context.d.ts +15 -0
- package/dist/routes/context.js +84 -0
- package/dist/routes/context.js.map +1 -0
- package/dist/routes/history.d.ts +56 -0
- package/dist/routes/history.js +308 -0
- package/dist/routes/history.js.map +1 -0
- package/dist/routes/index-trigger.d.ts +21 -0
- package/dist/routes/index-trigger.js +47 -0
- package/dist/routes/index-trigger.js.map +1 -0
- package/dist/routes/search.d.ts +24 -0
- package/dist/routes/search.js +85 -0
- package/dist/routes/search.js.map +1 -0
- package/dist/routes/status.d.ts +14 -0
- package/dist/routes/status.js +37 -0
- package/dist/routes/status.js.map +1 -0
- package/dist/routes/team.d.ts +62 -0
- package/dist/routes/team.js +129 -0
- package/dist/routes/team.js.map +1 -0
- package/dist/routes/viewer.d.ts +78 -0
- package/dist/routes/viewer.js +387 -0
- package/dist/routes/viewer.js.map +1 -0
- package/dist/routes/viewer.test.d.ts +1 -0
- package/dist/routes/viewer.test.js +509 -0
- package/dist/routes/viewer.test.js.map +1 -0
- package/dist/server.d.ts +45 -0
- package/dist/server.js +227 -0
- package/dist/server.js.map +1 -0
- package/dist/server.test.d.ts +1 -0
- package/dist/server.test.js +620 -0
- package/dist/server.test.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/routes/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;IACnD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAC1B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EACxB,2CAA2C,CAC5C,CAAC,QAAQ,EAAE;IACZ,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAA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CACpC,CAAC;YACJ,CAAC;YAED,uBAAuB;YACvB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;gBAChE,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC;oBACxB,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC;gBAC/B,CAAC;gBACD,oDAAoD;YACtD,CAAC;YAED,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAE5C,GAAG,CAAC,IAAI,CAAC;gBACP,OAAO,EAAE,SAAS;gBAClB,KAAK,EAAE,SAAS,CAAC,MAAM;aACxB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACzE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,uBAAuB;gBAC9B,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import type { LanceDBStore, CodeRAGConfig } from '@code-rag/core';
|
|
3
|
+
export interface StatusResponse {
|
|
4
|
+
total_chunks: number;
|
|
5
|
+
last_indexed: string | null;
|
|
6
|
+
model: string;
|
|
7
|
+
languages: string[] | 'auto';
|
|
8
|
+
health: 'ok' | 'degraded' | 'not_initialized';
|
|
9
|
+
}
|
|
10
|
+
export interface StatusRouteDeps {
|
|
11
|
+
readonly store: LanceDBStore | null;
|
|
12
|
+
readonly config: CodeRAGConfig | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function createStatusRouter(deps: StatusRouteDeps): Router;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
export function createStatusRouter(deps) {
|
|
3
|
+
const router = Router();
|
|
4
|
+
router.get('/', async (_req, res) => {
|
|
5
|
+
try {
|
|
6
|
+
let totalChunks = 0;
|
|
7
|
+
let health = 'not_initialized';
|
|
8
|
+
if (deps.store) {
|
|
9
|
+
const countResult = await deps.store.count();
|
|
10
|
+
if (countResult.isOk()) {
|
|
11
|
+
totalChunks = countResult.value;
|
|
12
|
+
health = totalChunks > 0 ? 'ok' : 'degraded';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
health = 'degraded';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const status = {
|
|
19
|
+
total_chunks: totalChunks,
|
|
20
|
+
last_indexed: null,
|
|
21
|
+
model: deps.config?.embedding.model ?? 'unknown',
|
|
22
|
+
languages: deps.config?.project.languages ?? 'auto',
|
|
23
|
+
health,
|
|
24
|
+
};
|
|
25
|
+
res.json(status);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
29
|
+
res.status(500).json({
|
|
30
|
+
error: 'Status Check Failed',
|
|
31
|
+
message,
|
|
32
|
+
health: 'degraded',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return router;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/routes/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAgBjC,MAAM,UAAU,kBAAkB,CAAC,IAAqB;IACtD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IAExB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QAClC,IAAI,CAAC;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/core';
|
|
4
|
+
export declare const connectRequestSchema: z.ZodObject<{
|
|
5
|
+
provider: z.ZodEnum<{
|
|
6
|
+
s3: "s3";
|
|
7
|
+
"azure-blob": "azure-blob";
|
|
8
|
+
gcs: "gcs";
|
|
9
|
+
}>;
|
|
10
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
11
|
+
container: z.ZodOptional<z.ZodString>;
|
|
12
|
+
region: z.ZodOptional<z.ZodString>;
|
|
13
|
+
team_id: z.ZodString;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type ConnectRequest = z.infer<typeof connectRequestSchema>;
|
|
16
|
+
export declare const syncRequestSchema: z.ZodObject<{
|
|
17
|
+
force: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type SyncRequest = z.infer<typeof syncRequestSchema>;
|
|
20
|
+
export interface ConnectResponse {
|
|
21
|
+
readonly status: 'connected';
|
|
22
|
+
readonly team_id: string;
|
|
23
|
+
readonly provider: string;
|
|
24
|
+
readonly connected_at: string;
|
|
25
|
+
}
|
|
26
|
+
export interface AnalyticsResponse {
|
|
27
|
+
readonly top_queries: ReadonlyArray<{
|
|
28
|
+
query: string;
|
|
29
|
+
count: number;
|
|
30
|
+
}>;
|
|
31
|
+
readonly coverage_gaps: ReadonlyArray<{
|
|
32
|
+
file_path: string;
|
|
33
|
+
reason: string;
|
|
34
|
+
}>;
|
|
35
|
+
readonly total_queries: number;
|
|
36
|
+
readonly unique_users: number;
|
|
37
|
+
}
|
|
38
|
+
export interface SyncResponse {
|
|
39
|
+
readonly status: 'synced' | 'failed';
|
|
40
|
+
readonly files_synced: number;
|
|
41
|
+
readonly duration_ms: number;
|
|
42
|
+
}
|
|
43
|
+
export interface TeamConnection {
|
|
44
|
+
readonly teamId: string;
|
|
45
|
+
readonly provider: string;
|
|
46
|
+
readonly connectedAt: Date;
|
|
47
|
+
}
|
|
48
|
+
export interface QueryRecord {
|
|
49
|
+
readonly query: string;
|
|
50
|
+
readonly userId: string;
|
|
51
|
+
readonly timestamp: Date;
|
|
52
|
+
}
|
|
53
|
+
export interface TeamState {
|
|
54
|
+
connections: Map<string, TeamConnection>;
|
|
55
|
+
queryLog: QueryRecord[];
|
|
56
|
+
}
|
|
57
|
+
export declare function createTeamState(): TeamState;
|
|
58
|
+
export interface TeamRouteDeps {
|
|
59
|
+
readonly storageProvider: CloudStorageProvider | null;
|
|
60
|
+
readonly teamState: TeamState;
|
|
61
|
+
}
|
|
62
|
+
export declare function createTeamRouter(deps: TeamRouteDeps): Router;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { StorageError } from '@code-rag/core';
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Schemas
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export const connectRequestSchema = z.object({
|
|
8
|
+
provider: z.enum(['s3', 'azure-blob', 'gcs']),
|
|
9
|
+
bucket: z.string().min(1, 'bucket must not be empty').optional(),
|
|
10
|
+
container: z.string().min(1, 'container must not be empty').optional(),
|
|
11
|
+
region: z.string().optional(),
|
|
12
|
+
team_id: z.string().min(1, 'team_id must not be empty'),
|
|
13
|
+
});
|
|
14
|
+
export const syncRequestSchema = z.object({
|
|
15
|
+
force: z.boolean().optional().default(false),
|
|
16
|
+
});
|
|
17
|
+
export function createTeamState() {
|
|
18
|
+
return {
|
|
19
|
+
connections: new Map(),
|
|
20
|
+
queryLog: [],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Router
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
export function createTeamRouter(deps) {
|
|
27
|
+
const router = Router();
|
|
28
|
+
// POST /api/v1/team/connect — connect CLI to cloud index
|
|
29
|
+
router.post('/connect', (req, res) => {
|
|
30
|
+
const parsed = connectRequestSchema.safeParse(req.body);
|
|
31
|
+
if (!parsed.success) {
|
|
32
|
+
res.status(400).json({
|
|
33
|
+
error: 'Validation Error',
|
|
34
|
+
details: parsed.error.issues,
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { provider, team_id } = parsed.data;
|
|
39
|
+
const connection = {
|
|
40
|
+
teamId: team_id,
|
|
41
|
+
provider,
|
|
42
|
+
connectedAt: new Date(),
|
|
43
|
+
};
|
|
44
|
+
deps.teamState.connections.set(team_id, connection);
|
|
45
|
+
const response = {
|
|
46
|
+
status: 'connected',
|
|
47
|
+
team_id,
|
|
48
|
+
provider,
|
|
49
|
+
connected_at: connection.connectedAt.toISOString(),
|
|
50
|
+
};
|
|
51
|
+
res.status(200).json(response);
|
|
52
|
+
});
|
|
53
|
+
// GET /api/v1/team/analytics — team-level analytics
|
|
54
|
+
router.get('/analytics', (_req, res) => {
|
|
55
|
+
const queryLog = deps.teamState.queryLog;
|
|
56
|
+
// Most searched queries
|
|
57
|
+
const queryCounts = new Map();
|
|
58
|
+
const uniqueUsers = new Set();
|
|
59
|
+
for (const record of queryLog) {
|
|
60
|
+
const current = queryCounts.get(record.query) ?? 0;
|
|
61
|
+
queryCounts.set(record.query, current + 1);
|
|
62
|
+
uniqueUsers.add(record.userId);
|
|
63
|
+
}
|
|
64
|
+
const topQueries = [...queryCounts.entries()]
|
|
65
|
+
.map(([query, count]) => ({ query, count }))
|
|
66
|
+
.sort((a, b) => b.count - a.count)
|
|
67
|
+
.slice(0, 20);
|
|
68
|
+
// Coverage gaps: files that were searched for but not found
|
|
69
|
+
// For now, return empty since we'd need index data to determine gaps
|
|
70
|
+
const coverageGaps = [];
|
|
71
|
+
const response = {
|
|
72
|
+
top_queries: topQueries,
|
|
73
|
+
coverage_gaps: coverageGaps,
|
|
74
|
+
total_queries: queryLog.length,
|
|
75
|
+
unique_users: uniqueUsers.size,
|
|
76
|
+
};
|
|
77
|
+
res.status(200).json(response);
|
|
78
|
+
});
|
|
79
|
+
// POST /api/v1/team/sync — trigger index sync to cloud storage
|
|
80
|
+
router.post('/sync', async (req, res) => {
|
|
81
|
+
const parsed = syncRequestSchema.safeParse(req.body);
|
|
82
|
+
if (!parsed.success) {
|
|
83
|
+
res.status(400).json({
|
|
84
|
+
error: 'Validation Error',
|
|
85
|
+
details: parsed.error.issues,
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!deps.storageProvider) {
|
|
90
|
+
res.status(503).json({
|
|
91
|
+
error: 'Service Unavailable',
|
|
92
|
+
message: 'Cloud storage provider not configured. Connect to a team first.',
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const startTime = Date.now();
|
|
98
|
+
// Upload a sync marker to verify connectivity
|
|
99
|
+
const syncMarker = Buffer.from(JSON.stringify({
|
|
100
|
+
synced_at: new Date().toISOString(),
|
|
101
|
+
force: parsed.data.force,
|
|
102
|
+
}));
|
|
103
|
+
const uploadResult = await deps.storageProvider.upload('sync/latest.json', syncMarker);
|
|
104
|
+
if (uploadResult.isErr()) {
|
|
105
|
+
const syncError = uploadResult.error;
|
|
106
|
+
res.status(500).json({
|
|
107
|
+
error: 'Sync Failed',
|
|
108
|
+
message: syncError instanceof StorageError ? syncError.message : 'Unknown storage error',
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const durationMs = Date.now() - startTime;
|
|
113
|
+
const response = {
|
|
114
|
+
status: 'synced',
|
|
115
|
+
files_synced: 1,
|
|
116
|
+
duration_ms: durationMs,
|
|
117
|
+
};
|
|
118
|
+
res.status(200).json(response);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
122
|
+
res.status(500).json({
|
|
123
|
+
error: 'Sync Failed',
|
|
124
|
+
message,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return router;
|
|
129
|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C,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACzE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,aAAa;gBACpB,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import type { LanceDBStore, CodeRAGConfig, HybridSearch, DependencyGraph, GraphNode, GraphEdge } from '@code-rag/core';
|
|
3
|
+
export interface ViewerStatsResponse {
|
|
4
|
+
data: {
|
|
5
|
+
chunkCount: number;
|
|
6
|
+
fileCount: number;
|
|
7
|
+
languages: Record<string, number>;
|
|
8
|
+
storageBytes: number | null;
|
|
9
|
+
lastIndexed: string | null;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface ChunkSummary {
|
|
13
|
+
id: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
chunkType: string;
|
|
16
|
+
name: string;
|
|
17
|
+
language: string;
|
|
18
|
+
startLine: number;
|
|
19
|
+
endLine: number;
|
|
20
|
+
contentPreview: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PaginationMeta {
|
|
23
|
+
page: number;
|
|
24
|
+
pageSize: number;
|
|
25
|
+
total: number;
|
|
26
|
+
totalPages: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ChunkDetail {
|
|
29
|
+
id: string;
|
|
30
|
+
filePath: string;
|
|
31
|
+
chunkType: string;
|
|
32
|
+
name: string;
|
|
33
|
+
language: string;
|
|
34
|
+
startLine: number;
|
|
35
|
+
endLine: number;
|
|
36
|
+
content: string;
|
|
37
|
+
nlSummary: string;
|
|
38
|
+
metadata: Record<string, unknown>;
|
|
39
|
+
vector?: number[];
|
|
40
|
+
}
|
|
41
|
+
export interface GraphResponse {
|
|
42
|
+
data: {
|
|
43
|
+
nodes: GraphNode[];
|
|
44
|
+
edges: GraphEdge[];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface ViewerSearchResult {
|
|
48
|
+
chunkId: string;
|
|
49
|
+
filePath: string;
|
|
50
|
+
chunkType: string;
|
|
51
|
+
name: string;
|
|
52
|
+
content: string;
|
|
53
|
+
nlSummary: string;
|
|
54
|
+
score: number;
|
|
55
|
+
method: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ViewerSearchResponse {
|
|
58
|
+
data: {
|
|
59
|
+
results: ViewerSearchResult[];
|
|
60
|
+
timing: {
|
|
61
|
+
totalMs: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface EmbeddingPoint {
|
|
66
|
+
id: string;
|
|
67
|
+
filePath: string;
|
|
68
|
+
chunkType: string;
|
|
69
|
+
language: string;
|
|
70
|
+
vector: number[];
|
|
71
|
+
}
|
|
72
|
+
export interface ViewerDeps {
|
|
73
|
+
readonly getStore: () => LanceDBStore | null;
|
|
74
|
+
readonly getConfig: () => CodeRAGConfig | null;
|
|
75
|
+
readonly getHybridSearch: () => HybridSearch | null;
|
|
76
|
+
readonly getGraph: () => DependencyGraph | null;
|
|
77
|
+
}
|
|
78
|
+
export declare function createViewerRouter(deps: ViewerDeps): Router;
|