feat: prepare deep search production runtime
Memind CI / Test, build, and release guards (pull_request) Successful in 4m4s

This commit is contained in:
john
2026-07-24 09:53:06 +08:00
parent 46041c3456
commit 53ed38c250
16 changed files with 681 additions and 9 deletions
+33 -1
View File
@@ -6,6 +6,7 @@ import {
createPortalGatewayResearchLlmResolver,
} from './deep-search-engine.mjs';
import { createDeepSearchStore } from './deep-search-store.mjs';
import { searchGithubCode } from './mindsearch-providers.mjs';
function sendJson(res, status, body) {
const payload = JSON.stringify(body);
@@ -63,19 +64,50 @@ function canAccessTask(task, requestUserId) {
export function createDeepSearchHttpServer({
engine,
secret = process.env.TKMIND_DEEP_SEARCH_SECRET || '',
githubToken = process.env.GITHUB_TOKEN || '',
githubSearch = searchGithubCode,
logger = console,
} = {}) {
if (!engine) throw new Error('Deep Search engine is required');
return http.createServer(async (req, res) => {
const url = new URL(req.url ?? '/', 'http://deep-search.local');
if (url.pathname === '/health' && req.method === 'GET') {
return sendJson(res, 200, engine.getHealth());
return sendJson(res, 200, {
...engine.getHealth(),
providers: {
github: { configured: Boolean(githubToken) },
},
});
}
if (secret && req.headers['x-secret-key'] !== secret) {
return sendJson(res, 401, { code: 'UNAUTHORIZED', message: 'Invalid service secret' });
}
const requestUserId = String(req.headers['x-user-id'] ?? '').trim();
try {
if (url.pathname === '/v1/providers/github/search' && req.method === 'POST') {
if (!githubToken) {
const error = new Error('GitHub search token is not configured');
error.status = 503;
throw error;
}
const input = await readJson(req, { maxBytes: 32_000 });
const query = String(input.query ?? '').trim();
if (!query || query.length > 500) {
const error = new Error('query must be 1-500 characters');
error.status = 400;
throw error;
}
const limit = Math.max(1, Math.min(20, Number(input.limit ?? 10) || 10));
const results = await githubSearch(query, {
limit,
token: githubToken,
});
return sendJson(res, 200, {
query,
results,
service: 'tkmind-deep-search',
});
}
if (url.pathname === '/v1/search' && req.method === 'POST') {
const input = await readJson(req);
const results = await engine.search(input);