@code-rag/api-server 0.1.6 → 0.1.8
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/dist/routes/context.js +1 -1
- package/dist/routes/viewer.d.ts +6 -70
- package/dist/server.d.ts +1 -0
- package/dist/server.js +20 -55
- package/package.json +2 -2
package/dist/routes/context.js
CHANGED
|
@@ -60,7 +60,7 @@ export function createContextRouter(deps) {
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
// Expand context via dependency graph
|
|
63
|
-
const expanded = deps.contextExpander.expand(results);
|
|
63
|
+
const expanded = await deps.contextExpander.expand(results);
|
|
64
64
|
// Assemble within token budget
|
|
65
65
|
const optimizer = new TokenBudgetOptimizer({ maxTokens: max_tokens });
|
|
66
66
|
const assembled = optimizer.assemble(expanded);
|
package/dist/routes/viewer.d.ts
CHANGED
|
@@ -1,74 +1,10 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import type { LanceDBStore, CodeRAGConfig, HybridSearch, DependencyGraph
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}
|
|
2
|
+
import type { LanceDBStore, CodeRAGConfig, HybridSearch, DependencyGraph } from '@code-rag/core';
|
|
3
|
+
import type { ViewerStatsResponse, ViewerChunksResponse, ViewerChunkDetailResponse, ViewerSearchResponse, ViewerGraphResponse, ViewerEmbeddingsResponse, ViewerChunkSummary as ChunkSummary, ViewerPaginationMeta as PaginationMeta, ViewerChunkDetail as ChunkDetail, ViewerSearchResultType as ViewerSearchResult, ViewerEmbeddingPoint as EmbeddingPoint } from '@code-rag/core';
|
|
4
|
+
export type { ViewerStatsResponse, ViewerChunksResponse, ViewerChunkDetailResponse, ViewerSearchResponse, ViewerGraphResponse, ViewerEmbeddingsResponse, };
|
|
5
|
+
export type { ChunkSummary, ChunkDetail, PaginationMeta, ViewerSearchResult, EmbeddingPoint };
|
|
6
|
+
/** @deprecated Use ViewerGraphResponse from @code-rag/core instead */
|
|
7
|
+
export type GraphResponse = ViewerGraphResponse;
|
|
72
8
|
export interface ViewerDeps {
|
|
73
9
|
readonly getStore: () => LanceDBStore | null;
|
|
74
10
|
readonly getConfig: () => CodeRAGConfig | null;
|
package/dist/server.d.ts
CHANGED
package/dist/server.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
|
-
import {
|
|
4
|
-
import { readFile } from 'node:fs/promises';
|
|
5
|
-
import { join, resolve } from 'node:path';
|
|
3
|
+
import { createRuntime, DependencyGraph, } from '@code-rag/core';
|
|
6
4
|
import { parseApiKeys, createAuthMiddleware } from './middleware/auth.js';
|
|
7
5
|
import { createRateLimitMiddleware, parseRateLimitConfig } from './middleware/rate-limit.js';
|
|
8
6
|
import { createSearchRouter } from './routes/search.js';
|
|
@@ -22,6 +20,7 @@ export class ApiServer {
|
|
|
22
20
|
port;
|
|
23
21
|
httpServer = null;
|
|
24
22
|
// Core services (populated after initialize())
|
|
23
|
+
runtime = null;
|
|
25
24
|
config = null;
|
|
26
25
|
store = null;
|
|
27
26
|
hybridSearch = null;
|
|
@@ -129,62 +128,23 @@ export class ApiServer {
|
|
|
129
128
|
*/
|
|
130
129
|
async initialize() {
|
|
131
130
|
try {
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
131
|
+
const runtimeResult = await createRuntime({ rootDir: this.rootDir });
|
|
132
|
+
if (runtimeResult.isErr()) {
|
|
134
133
|
// eslint-disable-next-line no-console
|
|
135
|
-
console.error(`[api-server]
|
|
134
|
+
console.error(`[api-server] ${runtimeResult.error.message}`);
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
|
-
this.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
console.error('[api-server] Storage path escapes project root');
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this.store = new LanceDBStore(storagePath, this.config.embedding.dimensions);
|
|
152
|
-
await this.store.connect();
|
|
153
|
-
// Load BM25 index
|
|
154
|
-
let bm25Index = new BM25Index();
|
|
155
|
-
const bm25Path = join(storagePath, 'bm25-index.json');
|
|
156
|
-
try {
|
|
157
|
-
const bm25Data = await readFile(bm25Path, 'utf-8');
|
|
158
|
-
bm25Index = BM25Index.deserialize(bm25Data);
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
// No saved BM25 index, start empty
|
|
137
|
+
this.runtime = runtimeResult.value;
|
|
138
|
+
this.config = this.runtime.config;
|
|
139
|
+
this.store = this.runtime.store;
|
|
140
|
+
this.hybridSearch = this.runtime.hybridSearch;
|
|
141
|
+
this.contextExpander = this.runtime.contextExpander;
|
|
142
|
+
this.reranker = this.runtime.reranker;
|
|
143
|
+
// Expose graph as DependencyGraph for viewer API (getAllNodes, getAllEdges)
|
|
144
|
+
const graphInstance = this.runtime.graph;
|
|
145
|
+
if (graphInstance instanceof DependencyGraph) {
|
|
146
|
+
this.graph = graphInstance;
|
|
162
147
|
}
|
|
163
|
-
// Create HybridSearch
|
|
164
|
-
this.hybridSearch = new HybridSearch(this.store, bm25Index, embeddingProvider, this.config.search);
|
|
165
|
-
// Create re-ranker if enabled
|
|
166
|
-
if (this.config.reranker?.enabled) {
|
|
167
|
-
this.reranker = new CrossEncoderReRanker({
|
|
168
|
-
model: this.config.reranker.model,
|
|
169
|
-
topN: this.config.reranker.topN,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
// Load dependency graph
|
|
173
|
-
let graph = new DependencyGraph();
|
|
174
|
-
const graphPath = join(storagePath, 'graph.json');
|
|
175
|
-
try {
|
|
176
|
-
const graphData = await readFile(graphPath, 'utf-8');
|
|
177
|
-
const parsed = JSON.parse(graphData);
|
|
178
|
-
graph = DependencyGraph.fromJSON(parsed);
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// No saved graph, start empty
|
|
182
|
-
}
|
|
183
|
-
// Store graph for viewer API
|
|
184
|
-
this.graph = graph;
|
|
185
|
-
// Create context expander
|
|
186
|
-
const chunkLookup = (_chunkId) => undefined;
|
|
187
|
-
this.contextExpander = new ContextExpander(graph, chunkLookup);
|
|
188
148
|
}
|
|
189
149
|
catch (error) {
|
|
190
150
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -219,6 +179,11 @@ export class ApiServer {
|
|
|
219
179
|
});
|
|
220
180
|
this.httpServer = null;
|
|
221
181
|
}
|
|
182
|
+
// Close the runtime (LanceDB, etc.)
|
|
183
|
+
if (this.runtime) {
|
|
184
|
+
this.runtime.close();
|
|
185
|
+
this.runtime = null;
|
|
186
|
+
}
|
|
222
187
|
}
|
|
223
188
|
/** Expose Express app for testing with supertest. */
|
|
224
189
|
getApp() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-rag/api-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "REST API server for CodeRAG — Express-based server with authentication, rate limiting, and OpenAPI docs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"express": "^4.21.2",
|
|
43
43
|
"zod": "^4.3.6",
|
|
44
|
-
"@code-rag/core": "0.1.
|
|
44
|
+
"@code-rag/core": "0.1.8"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/express": "^5.0.2",
|