mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-17 05:59:39 +02:00
Pre-launch theme system audit found multiple parallel layers in themes.css
(--theme-X full hsl strings, --X partial shadcn aliases, --color-X populated
by runtime store with raw channels) plus dead-code companion files. The
inconsistency caused light-mode regressions when scoped-CSS consumers
wrote `var(--color-X)` standalone — the variable holds raw HSL channels
which is invalid as a color value, browser fell back to inherited (white).
Rewrite to one consistent layer:
- Source of truth: --color-X defined as raw HSL channels (e.g.
`0 0% 17%`) in :root, .dark, and all variant [data-theme="..."]
blocks. Matches the format the runtime store
(@mana/shared-theme/src/utils.ts) writes, eliminating the
static-fallback-vs-runtime mismatch and the corresponding flash
of unstyled content on hydration.
- @theme inline uses self-reference + Tailwind v4 <alpha-value>
placeholder so utility classes generate correctly AND opacity
modifiers work: `text-foreground/50` → `hsl(var(--color-foreground) / 0.5)`.
- @layer components (.btn-primary, .card, .badge, etc.) wraps
var(--color-X) refs with hsl() — they were broken in light mode
too for the same reason.
Convention going forward (also documented in the file header):
1. Markup: use Tailwind utility classes (text-foreground, bg-card, …)
2. Scoped CSS: hsl(var(--color-X)) — always wrap with hsl()
3. NEVER raw var(--color-X) in CSS — that's the bug pattern
Net file: 692 → 580 LOC. Single source layer, no indirection.
Also delete dead companion files (zero imports anywhere):
- tailwind-v4.css (had broken self-reference, never imported)
- theme-variables.css (legacy hex-based palette)
- components.css (legacy component utilities)
- index.js / preset.js / colors.js (Tailwind v3 preset format,
irrelevant under Tailwind v4)
package.json exports map shrinks accordingly to just `./themes.css`.
Consumers using `hsl(var(--color-X))` (~379 files across mana-web,
manavoxel-web, arcade-web) keep working unchanged — the public API
name `--color-X` is preserved. Only the broken pattern `var(--color-X)`
(~61 files) needs a follow-up sweep, handled in a separate commit.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
/**
|
|
* Planta module — Photo upload + AI plant analysis
|
|
* Ported from apps/planta/apps/server
|
|
*
|
|
* CRUD for plants, photos, watering handled by mana-sync.
|
|
* This module handles S3 uploads and Gemini Vision analysis.
|
|
*/
|
|
|
|
import { Hono } from 'hono';
|
|
import { logger, type AuthVariables } from '@mana/shared-hono';
|
|
|
|
const LLM_URL = process.env.MANA_LLM_URL || 'http://localhost:3025';
|
|
|
|
const routes = new Hono<{ Variables: AuthVariables }>();
|
|
|
|
// ─── Photo Upload (server-only: S3 storage) ─────────────────
|
|
|
|
routes.post('/photos/upload', async (c) => {
|
|
const userId = c.get('userId');
|
|
const formData = await c.req.formData();
|
|
const file = formData.get('file') as File | null;
|
|
const plantId = formData.get('plantId') as string | null;
|
|
|
|
if (!file) return c.json({ error: 'No file provided' }, 400);
|
|
if (file.size > 10 * 1024 * 1024) return c.json({ error: 'File too large (max 10MB)' }, 400);
|
|
|
|
try {
|
|
const { uploadImageToMedia } = await import('../../lib/media');
|
|
const buffer = await file.arrayBuffer();
|
|
const result = await uploadImageToMedia(buffer, file.name, { app: 'planta', userId });
|
|
|
|
return c.json(
|
|
{
|
|
storagePath: result.id,
|
|
publicUrl: result.urls.original,
|
|
mediaId: result.id,
|
|
plantId,
|
|
},
|
|
201
|
|
);
|
|
} catch (err) {
|
|
logger.error('planta.upload_failed', {
|
|
error: err instanceof Error ? err.message : String(err),
|
|
});
|
|
return c.json({ error: 'Upload failed' }, 500);
|
|
}
|
|
});
|
|
|
|
// ─── AI Analysis (server-only: Gemini Vision) ───────────────
|
|
|
|
routes.post('/analysis/identify', async (c) => {
|
|
const { photoUrl } = await c.req.json();
|
|
if (!photoUrl) return c.json({ error: 'photoUrl required' }, 400);
|
|
|
|
try {
|
|
const res = await fetch(`${LLM_URL}/api/v1/chat/completions`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
messages: [
|
|
{
|
|
role: 'system',
|
|
content:
|
|
'Du bist ein Pflanzenexperte. Analysiere das Bild und gib JSON zurück: {scientificName, commonNames[], confidence, healthAssessment, wateringAdvice, lightAdvice, generalTips[]}',
|
|
},
|
|
{
|
|
role: 'user',
|
|
content: [
|
|
{ type: 'text', text: 'Analysiere diese Pflanze.' },
|
|
{ type: 'image_url', image_url: { url: photoUrl } },
|
|
],
|
|
},
|
|
],
|
|
model: process.env.VISION_MODEL || 'gemini-2.0-flash',
|
|
response_format: { type: 'json_object' },
|
|
}),
|
|
});
|
|
|
|
if (!res.ok) return c.json({ error: 'AI analysis failed' }, 502);
|
|
|
|
const data = await res.json();
|
|
const content = data.choices?.[0]?.message?.content;
|
|
const analysis = typeof content === 'string' ? JSON.parse(content) : content;
|
|
|
|
return c.json(analysis);
|
|
} catch (err) {
|
|
logger.error('planta.analysis_failed', {
|
|
error: err instanceof Error ? err.message : String(err),
|
|
});
|
|
return c.json({ error: 'Analysis failed' }, 500);
|
|
}
|
|
});
|
|
|
|
export { routes as plantaRoutes };
|