mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 09:08:46 +02:00
Replace the deprecated copilotRuntimeNextJSAppRouterEndpoint wrapper (which was already the v2 single-route handler underneath) with createCopilotRuntimeHandler from @copilotkit/runtime/v2, built once at module scope, and plug in a custom PostgresAgentRunner: - run() proxies the agent's event stream untouched — MAF persists every turn in chatthreadsnapshot, so the BFF records nothing - connect() forwards to MAF's snapshot hydration (empty-messages run → RUN_STARTED → MESSAGES_SNAPSHOT → RUN_FINISHED, no LLM call), making the DB the only conversation store — correct across clears, restarts and future instances - stop() aborts via a process-local live-run map (same pattern as the official sqlite-runner); isRunning() has no caller in the v2 SSE path This deletes the whole workaround layer the in-memory runner forced: the connect intercepts (URL + envelope forms) and Asistente's client-side hydration run. The ask-box flow now awaits connectAgent instead. Auth moves to a single Request rewrite (ws_token cookie → Authorization Bearer) before the handler — the v2 path forwards authorization + x-* headers to both run clones and runner.connect. Stays in single-route mode: same envelope protocol the client already auto-detected, no exposure to CopilotKit#4953, /threads* REST not needed. Telemetry disabled via COPILOTKIT_TELEMETRY_DISABLED. Verified full matrix in dev: fresh ask, reload replay via runner, 3 cleared convos + double navigation (only last survives), card renders once and survives follow-up + reload, Inicio ask-box with history, stale-tab persists only its new turn. 126 backend tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>