mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 16:06:43 +02:00
Schließt die platform/product-split-Lücke: HEAD's apps/api/src/index.ts
referenziert seit dem Forms-M10d-Commit personasInternalRoutes /
personasAdminRoutes — die Implementierung lag aber noch nicht im Repo.
Build war strukturell broken bis hierhin.
Was wandert von mana-auth nach apps/api:
apps/api/src/modules/personas/
├── schema.ts — pgSchema('personas') mit personas /
│ persona_actions / persona_feedback;
│ userId ist plain text (Cross-DB-FK auf
│ mana-auth's auth.users geht nach Split nicht).
├── internal-routes.ts — service-key gated GET /due, POST /:id/actions
│ und POST /:id/feedback. Append-only +
│ idempotent über deterministische row-ids
│ (tickId-i-tool / tickId-module).
└── admin-routes.ts — admin-JWT gated CRUD; ruft mana-auth via
/api/v1/admin/users + /api/v1/auth/register
+ /api/v1/internal/users/:id/persona-stamp
für den User-Lifecycle.
Persona-runner-Client zeigt jetzt auf apps/api:
- config.ts: neues apiUrl-Feld (default http://localhost:3060,
Env MANA_API_URL); authUrl bleibt für /api/v1/auth/login + spaces.
- clients/mana-auth-internal.ts: drei Calls treffen jetzt
/api/v1/personas/internal/* statt mana-auth's
/api/v1/internal/personas/* — Datei-Name bleibt um Call-Site-Diff
klein zu halten.
- index.ts: ManaAuthInternalClient bekommt config.apiUrl statt authUrl.
Seed/Cleanup-Skripte:
- --api= als bevorzugter Flag, --auth= als Legacy-Alias (cached
Shell-History würde sonst hart brechen).
- default http://localhost:3060, Env MANA_API_URL.
- Endpoint-Pfade umgeschrieben:
POST /api/v1/admin/personas → /api/v1/personas/admin
DELETE /api/v1/admin/personas/:id → /api/v1/personas/admin/:id
drizzle.config.ts: schema-Array + schemaFilter um 'personas' erweitert.
DB-push ist Pflicht-Schritt vor erstem Boot, sonst 42P01 auf /due.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
/**
|
|
* Service configuration. Every value env-overridable so dev/staging/prod
|
|
* can dial them independently without a code change.
|
|
*/
|
|
|
|
export interface Config {
|
|
port: number;
|
|
|
|
/** mana-auth base URL — for login + spaces list. */
|
|
authUrl: string;
|
|
/** apps/api base URL — for /api/v1/personas/internal/* callbacks
|
|
* (due, actions, feedback). Personas live in mana_platform now,
|
|
* not in mana-auth. */
|
|
apiUrl: string;
|
|
/** mana-mcp base URL — where Claude talks to the tool registry. */
|
|
mcpUrl: string;
|
|
|
|
/** Service key for /api/v1/personas/internal/* callbacks into apps/api. */
|
|
serviceKey: string;
|
|
|
|
/** Anthropic API key that drives each persona's Claude call. */
|
|
anthropicApiKey: string;
|
|
|
|
/** Deterministic per-persona password seed. Must match whatever is
|
|
* in scripts/personas/password.ts — the same function derives the
|
|
* same password here, so the runner can log in without storing any
|
|
* per-persona credentials. */
|
|
personaSeedSecret: string;
|
|
|
|
/** How often the tick loop runs. Default 60 s — fine-grained enough
|
|
* that a persona with tickCadence='hourly' stays on schedule, cheap
|
|
* enough that dispatching 10 personas never backs up. */
|
|
tickIntervalMs: number;
|
|
|
|
/** Max personas running in parallel per tick. Scoped to Claude API
|
|
* rate limits — conservative default 2, tier-dependent. */
|
|
concurrency: number;
|
|
|
|
/**
|
|
* Pause the loop without redeploying. Useful when the user wants
|
|
* persona activity to stop (e.g. during a demo) but the service
|
|
* should stay up so health checks don't page.
|
|
*/
|
|
paused: boolean;
|
|
}
|
|
|
|
function intEnv(name: string, fallback: number): number {
|
|
const raw = process.env[name];
|
|
if (!raw) return fallback;
|
|
const n = Number(raw);
|
|
if (!Number.isInteger(n) || n <= 0) {
|
|
throw new Error(`${name} must be a positive integer, got "${raw}"`);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
function boolEnv(name: string, fallback: boolean): boolean {
|
|
const raw = process.env[name];
|
|
if (raw == null) return fallback;
|
|
return raw === '1' || raw.toLowerCase() === 'true';
|
|
}
|
|
|
|
export function loadConfig(): Config {
|
|
return {
|
|
port: intEnv('PORT', 3070),
|
|
authUrl: process.env.MANA_AUTH_URL ?? 'http://localhost:3001',
|
|
apiUrl: process.env.MANA_API_URL ?? 'http://localhost:3060',
|
|
mcpUrl: process.env.MANA_MCP_URL ?? 'http://localhost:3069',
|
|
serviceKey: process.env.MANA_SERVICE_KEY ?? '',
|
|
anthropicApiKey: process.env.ANTHROPIC_API_KEY ?? '',
|
|
personaSeedSecret: process.env.PERSONA_SEED_SECRET ?? 'dev-persona-seed-secret-rotate-in-prod',
|
|
tickIntervalMs: intEnv('TICK_INTERVAL_MS', 60_000),
|
|
concurrency: intEnv('PERSONA_CONCURRENCY', 2),
|
|
paused: boolEnv('RUNNER_PAUSED', false),
|
|
};
|
|
}
|
|
|
|
export function assertProductionSecrets(config: Config): void {
|
|
if (process.env.NODE_ENV !== 'production') return;
|
|
const missing: string[] = [];
|
|
if (!config.serviceKey) missing.push('MANA_SERVICE_KEY');
|
|
if (!config.anthropicApiKey) missing.push('ANTHROPIC_API_KEY');
|
|
if (config.personaSeedSecret === 'dev-persona-seed-secret-rotate-in-prod') {
|
|
missing.push('PERSONA_SEED_SECRET (dev fallback in prod)');
|
|
}
|
|
if (missing.length > 0) {
|
|
throw new Error(
|
|
`mana-persona-runner production start blocked — missing/unsafe: ${missing.join(', ')}`
|
|
);
|
|
}
|
|
}
|