Files
happy-life-star/docs/superpowers/plans/2026-05-23-ai-runtime-client-sync.md
T
peanut 89fc42819d feat: AI 场景路由、ASR 服务及前后端全链路同步
- 新增 AI 场景路由控制器和管理接口
- 新增 ASR 语音识别服务及前后端集成
- 同步 AI Runtime 客户端到 Web/小程序/Life-Script
- 完善 AI 配置测试修复和管理后台路由配置
- 新增数据库迁移脚本

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 13:25:21 +08:00

3.3 KiB

AI Runtime Client Sync Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Synchronize AI calls in web, web-admin, life-script, and mini-program so user-facing AI output uses the backend scene routing runtime and streams text progressively.

Architecture: The backend remains the single trust boundary for provider credentials, scene bindings, user context enrichment, and workflow selection. Browser and mini-program clients call /ai/runtime/stream with sceneCode and inputs, while existing WebSocket chat is bridged through AiRuntimeService so chat also follows the configured chat scene. Existing business save APIs remain responsible for persistence after a stream completes.

Tech Stack: Spring Boot, STOMP WebSocket, FastJSON, Vue 3, React/Vite, uni-app chunked request, Element Plus.


Task 1: Backend Chat Bridge To Runtime

Files:

  • Modify: backend-single/src/main/java/com/emotion/service/impl/WebSocketServiceImpl.java

  • Modify: backend-single/src/main/java/com/emotion/dto/websocket/WebSocketMessage.java

  • Route chat generation through AiRuntimeService with sceneCode=chat.

  • Push start, delta, done, and error events over the existing user WebSocket topic.

  • Save the final assistant message after done using the accumulated stream output.

  • Preserve the existing user-message persistence and conversation ID behavior.

Task 2: Shared Runtime Clients

Files:

  • Create: web/src/services/aiRuntime.ts

  • Create: life-script/src/services/aiRuntime.js

  • Modify: mini-program/src/services/aiRuntime.js

  • Modify: web-admin/src/api/aiconfig.ts

  • Modify: web-admin/src/views/aiconfig/AiRoutingList.vue

  • Add browser SSE client helpers that parse unified AI stream events.

  • Keep mini-program chunk parsing but localize error messages and flush trailing frames.

  • Add a web-admin stream test helper and make the test dialog render output progressively.

Task 3: Client Scene Migration

Files:

  • Modify: life-script/src/services/ai.js

  • Modify: life-script/src/views/ScriptView.jsx

  • Modify: life-script/src/views/TimelineView.jsx

  • Modify: life-script/src/views/PathView.jsx

  • Modify: mini-program/src/pages/main/ScriptView.vue

  • Inspect: web/src/stores/chat.ts

  • Remove direct OpenRouter calls and hard-coded client API keys.

  • Route script_generate, life_healing, and path generation through streamAiScene.

  • Ensure pages append delta content instead of waiting for complete text.

  • Keep final persistence through existing business save APIs after stream completion.

Task 4: Verification

Commands:

  • mvn test

  • mvn -DskipTests clean package

  • npm run build in web

  • npm run build in web-admin

  • npm run build in life-script

  • npm run build:mp-weixin in mini-program

  • Backend tests pass.

  • Backend package succeeds.

  • All four frontend builds succeed.

  • Source scan shows no client-side external AI provider key or direct Dify/Coze/OpenRouter call.

  • Database scene bindings are enabled with streaming endpoints for chat, script_generate, short_story_generate, diary_summary, emotion_summary, emotion_analysis, and life_healing.