mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 12:47:48 +01:00
Closes the FC↔OC read loop. The subscription mirror (Loop A) writes FleetCrown subscriptions into OrangeCat as services. This commit adds the inverse: the dispatch strategist now reads the actor's OrangeCat services + products via @orangecat/sdk's .list() (which is already integration-key authenticated server-side — no OC change required) and surfaces a brief "Commercial context" section into the Groq prompt. src/lib/integrations/orangecat-context.ts (new): - getOrangeCatContext() — fetches services + products in parallel, caches 5 min in-memory, races a 1.5s timeout. Returns null silently when no ORANGECAT_API_KEY is set. Falls back to stale cache on transient OC failure rather than blocking dispatch. - renderOrangeCatContext(ctx) — compact text rendering for the prompt. Empty when nothing commercial to report (so the strategist proceeds with FC-only context, unchanged behavior). src/app/api/control/dispatch/route.ts: - buildPrompt() gains an orangeCatContext param. - Call site fetches OC context in parallel with Groq composition. - Strictly non-fatal — any OC failure swallowed via .catch(() => ""). This is the smallest end-to-end demonstration of bidirectional FC↔OC integration. When ORANGECAT_API_KEY is set, the agent's auto-injected prompts can carry "this actor sells N services on OrangeCat (X, Y, Z)" context, letting Groq prefer revenue-adjacent work when handoff signals are weak. When the key is absent, behavior is identical to pre-commit. Followup gaps (not in this commit): - @orangecat/sdk lacks .get(id) — would need OC's entityCrudHandler to switch from supabase.auth.getUser() to resolveRequestAuth before the SDK could expose it. /list works today; /[id] does not. - Transaction history endpoint not yet wired — would let the strategist see "you have $X coming in this month, prioritize delivery work." Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>