mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-21 21:26:42 +02:00
New Bun/Hono service on port 3068 that bundles many web-research providers behind a unified interface for side-by-side comparison. All eval runs persist in research.* (mana_platform) so quality can be reviewed later. Providers (Phase 1+2): search: searxng, duckduckgo, brave, tavily, exa, serper extract: readability (via mana-search), jina-reader, firecrawl Endpoints: POST /v1/search, /v1/search/compare — single + fan-out POST /v1/extract, /v1/extract/compare — single + fan-out GET /v1/runs, /v1/runs/:id — history POST /v1/runs/:run/results/:id/rate — manual eval GET /v1/providers, /v1/providers/health — catalog + readiness Auto-routing: when `provider` is omitted, queries are classified via regex (fast path, 0ms) with optional mana-llm fallback, then routed to the first available provider for that query type (news → tavily, academic → exa, semantic → exa, etc.). Credits: server-key calls go through mana-credits reserve → commit/refund so failed provider calls don't charge the user. BYO-keys supported via research.provider_configs (UI arrives in Phase 4). Cache: Redis with graceful degradation (1h TTL for search, 24h for extract). Pay-per-use APIs only — no subscription-gated providers. Docs: docs/plans/mana-research-service.md + docs/reports/web-research-capabilities.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
/**
|
|
* /v1/runs — user's saved eval runs + per-result rating.
|
|
*/
|
|
|
|
import { Hono } from 'hono';
|
|
import { z } from 'zod';
|
|
import type { HonoEnv } from '../lib/hono-env';
|
|
import { BadRequestError, NotFoundError } from '../lib/errors';
|
|
import type { RunStorage } from '../storage/runs';
|
|
|
|
const rateSchema = z.object({
|
|
rating: z.number().int().min(1).max(5),
|
|
notes: z.string().max(2000).optional(),
|
|
});
|
|
|
|
export function createRunsRoutes(storage: RunStorage) {
|
|
return new Hono<HonoEnv>()
|
|
.get('/', async (c) => {
|
|
const user = c.get('user');
|
|
const limit = Math.min(parseInt(c.req.query('limit') || '50', 10), 200);
|
|
const offset = parseInt(c.req.query('offset') || '0', 10);
|
|
const runs = await storage.listRuns(user.userId, limit, offset);
|
|
return c.json({ runs });
|
|
})
|
|
.get('/:id', async (c) => {
|
|
const user = c.get('user');
|
|
const id = c.req.param('id');
|
|
const out = await storage.getRunWithResults(id, user.userId);
|
|
if (!out) throw new NotFoundError('Run not found');
|
|
return c.json(out);
|
|
})
|
|
.post('/:runId/results/:resultId/rate', async (c) => {
|
|
const user = c.get('user');
|
|
const body = rateSchema.parse(await c.req.json());
|
|
const ok = await storage.rateResult(
|
|
c.req.param('resultId'),
|
|
user.userId,
|
|
body.rating,
|
|
body.notes
|
|
);
|
|
if (!ok) throw new BadRequestError('Cannot rate this result');
|
|
return c.json({ success: true });
|
|
});
|
|
}
|