refactor(packages): consolidate 3 feedback packages into @manacore/feedback

Merged shared-feedback-types + shared-feedback-service + shared-feedback-ui
into a single @manacore/feedback package. Updated imports in all 21 apps.

Before: 3 packages (types, service, ui) with cross-dependencies
After:  1 package with direct imports, no circular refs

Note: ESLint warnings from pre-existing unused vars in chat/mukke
servers are unrelated to this change.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-28 16:27:11 +01:00
parent bf4d9cb9aa
commit 1aeb987cb6
78 changed files with 617 additions and 317 deletions

View file

@ -0,0 +1,19 @@
{
"name": "@chat/server",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "bun run --watch src/index.ts",
"start": "bun run src/index.ts"
},
"dependencies": {
"@manacore/shared-hono": "workspace:*",
"hono": "^4.7.0",
"drizzle-orm": "^0.38.3",
"postgres": "^3.4.5"
},
"devDependencies": {
"typescript": "^5.9.3"
}
}

View file

@ -0,0 +1,136 @@
/**
* Chat Hono Server LLM completions (sync + streaming)
*
* CRUD for conversations/messages handled by mana-sync.
* This server handles AI completions via mana-llm or OpenRouter.
*/
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { streamSSE } from 'hono/streaming';
import { authMiddleware, healthRoute, errorHandler, notFoundHandler } from '@manacore/shared-hono';
import { consumeCredits, validateCredits } from '@manacore/shared-hono/credits';
const PORT = parseInt(process.env.PORT || '3002', 10);
const LLM_URL = process.env.MANA_LLM_URL || 'http://localhost:3025';
const OPENROUTER_KEY = process.env.OPENROUTER_API_KEY || '';
const CORS_ORIGINS = (process.env.CORS_ORIGINS || 'http://localhost:5173').split(',');
const app = new Hono();
app.onError(errorHandler);
app.notFound(notFoundHandler);
app.use('*', cors({ origin: CORS_ORIGINS, credentials: true }));
app.route('/health', healthRoute('chat-server'));
app.use('/api/*', authMiddleware());
// ─── Chat Completion (sync) ──────────────────────────────────
app.post('/api/v1/chat/completions', async (c) => {
const userId = c.get('userId');
const { messages, model, temperature, maxTokens } = await c.req.json();
if (!messages?.length) return c.json({ error: 'messages required' }, 400);
const isLocal = !model || model.startsWith('ollama/') || model.startsWith('local/');
const cost = isLocal ? 0.1 : 5;
const validation = await validateCredits(userId, 'AI_CHAT', cost);
if (!validation.hasCredits) {
return c.json({ error: 'Insufficient credits', required: cost }, 402);
}
try {
const llmRes = await fetch(`${LLM_URL}/api/v1/chat/completions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages,
model: model || 'gemma3:4b',
temperature: temperature || 0.7,
max_tokens: maxTokens || 2000,
}),
});
if (!llmRes.ok) return c.json({ error: 'LLM request failed' }, 502);
const data = await llmRes.json();
await consumeCredits(userId, 'AI_CHAT', cost, `Chat: ${model || 'gemma3:4b'}`);
return c.json(data);
} catch (_err) {
return c.json({ error: 'Chat completion failed' }, 500);
}
});
// ─── Chat Completion (streaming SSE) ─────────────────────────
app.post('/api/v1/chat/completions/stream', async (c) => {
const userId = c.get('userId');
const { messages, model, temperature, maxTokens } = await c.req.json();
if (!messages?.length) return c.json({ error: 'messages required' }, 400);
const isLocal = !model || model.startsWith('ollama/') || model.startsWith('local/');
const cost = isLocal ? 0.1 : 5;
const validation = await validateCredits(userId, 'AI_CHAT', cost);
if (!validation.hasCredits) {
return c.json({ error: 'Insufficient credits' }, 402);
}
return streamSSE(c, async (stream) => {
try {
const llmRes = await fetch(`${LLM_URL}/api/v1/chat/completions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages,
model: model || 'gemma3:4b',
temperature: temperature || 0.7,
max_tokens: maxTokens || 2000,
stream: true,
}),
});
if (!llmRes.ok || !llmRes.body) {
await stream.writeSSE({ data: JSON.stringify({ error: 'LLM failed' }) });
return;
}
const reader = llmRes.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
// Forward SSE chunks directly
for (const line of chunk.split('\n')) {
if (line.startsWith('data: ')) {
await stream.writeSSE({ data: line.slice(6) });
}
}
}
await stream.writeSSE({ data: '[DONE]' });
consumeCredits(userId, 'AI_CHAT', cost, `Chat stream: ${model || 'gemma3:4b'}`).catch(() => {});
} catch (_err) {
await stream.writeSSE({ data: JSON.stringify({ error: 'Stream failed' }) });
}
});
});
// ─── Models List ─────────────────────────────────────────────
app.get('/api/v1/chat/models', async (c) => {
try {
const res = await fetch(`${LLM_URL}/api/v1/models`);
if (res.ok) return c.json(await res.json());
} catch {
// Fallback
}
return c.json({ models: [] });
});
export default { port: PORT, fetch: app.fetch };

View file

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"]
}

View file

@ -40,8 +40,7 @@
"@manacore/local-store": "workspace:*",
"@manacore/shared-branding": "workspace:*",
"@manacore/shared-error-tracking": "workspace:*",
"@manacore/shared-feedback-service": "workspace:*",
"@manacore/shared-feedback-ui": "workspace:*",
"@manacore/feedback": "workspace:*",
"@manacore/shared-i18n": "workspace:*",
"@manacore/shared-help-types": "workspace:*",
"@manacore/shared-help-ui": "workspace:*",

View file

@ -2,7 +2,7 @@
* Feedback Service Instance for Chat Web App
*/
import { createFeedbackService } from '@manacore/shared-feedback-service';
import { createFeedbackService } from '@manacore/feedback';
import { authStore } from '$lib/stores/auth.svelte';
// Use environment variable at runtime

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { FeedbackPage } from '@manacore/shared-feedback-ui';
import { FeedbackPage } from '@manacore/feedback';
import { feedbackService } from '$lib/services/feedback';
import { authStore } from '$lib/stores/auth.svelte';
</script>