Skip to content

refactor: extraer el router HTTP de LLM - #106

Merged
IAnMove merged 2 commits into
mainfrom
refactor/llm-http-router
Sep 2, 2026
Merged

refactor: extraer el router HTTP de LLM#106
IAnMove merged 2 commits into
mainfrom
refactor/llm-http-router

Conversation

@IAnMove

@IAnMove IAnMove commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Qué

Extrae el dominio HTTP de /api/v1/llm fuera de _launch_runtime.py hacia app/routers/llm.py, imitando el montaje de Comics (create_comics_router + segundo include_router para no romper ordinales).

Contrato (11 rutas)

create_llm_router (ordinales 80–87, misma posición que el primer /api/v1/llm):

  • GET /api/v1/llm/status
  • POST /api/v1/llm/load
  • POST /api/v1/llm/unload
  • GET /api/v1/llm/models
  • GET /api/v1/llm/stream-status
  • POST /api/v1/llm/generate
  • POST /api/v1/llm/test
  • POST /api/v1/llm/write-song

create_llm_prompt_router (ordinales 89–91, segundo include_router justo después de Director generate-music):

  • POST /api/v1/llm/plan-h3-windows
  • POST /api/v1/llm/enhance-prompt
  • POST /api/v1/llm/describe-image

route_table.json no cambia ordinales, method, path, endpoint ni status. Solo source pasa a app/routers/llm.py en esas 11 rutas.

Cómo se conservan los ordinales

scripts/architecture_contracts.py expande cada factory en su api.include_router(...). El primer montaje sustituye el bloque control/generate/song-writer; el segundo se coloca justo donde estaban plan-h3 / enhance / describe, después de POST /api/v1/director/generate-music (ordinal 88, sigue en launch).

Qué permanece en launch

  • /api/v1/director/* (incluido director_generate_music, plan-prompts, pipeline). Director es Paso 5 y está fuera de alcance.
  • _ensure_llm_loaded (lo usan CivitAI, Director, Story Lab, Comics, describe-refs, …).
  • _enhance_with_wangp (WanGP/offload; se inyecta en el router).
  • _comic_writing_llm, _effective_llm_routing, _llm_provider_credentials.

Director generate-music importa _parse_song_output y los fallbacks ACE-Step desde routers.llm. llm_service.py no se parte (plan 6.b no es este ticket).

Inyección (sin WanGP en el router)

  • Control/generate/song: get_services_config, effective_llm_routing, llm_provider_credentials, llm_default_device, default_llm_repo, ensure_llm_loaded, comic_writing_llm.
  • Prompt tools: lo anterior + public_llm_providers, get_model_def, get_lora_dir, get_cached_hardware, get_enhancer_enabled, enhance_with_wangp.

El router no importa wgp ni _launch_runtime.

Tests

python -m compileall -q app/routers/llm.py app/services/llm_service.py
python scripts/architecture_contracts.py
python -m pytest -q tests/test_architecture_contracts.py tests/test_llm_router.py tests/test_minimax_song_writer_prompt.py tests/test_h3_window_planner.py tests/test_minimax_h3.py::TestMiniMaxH3Definition::test_h3_enhance_path_preserves_context_ir_contract

No hace falta GPU ni create_app().

Los tests que rebanaban launch para song-writer / plan-h3 / enhance se retargetean a app/routers/llm.py. test_minimax_song_writer_prompt.py deja de ser lector de launch (sale del wire inventory). tests/test_llm_router.py cubre superficie path/method/endpoint y validación 400.

Fuera de alcance

  • No se toca /api/v1/director/*, stories, series, audio, video-editor.
  • No se toca ui/src/stores/useStore.ts, WanGP, app/wgp.py, app/models/**, launchers, Pinokio.
  • No se toca docs/development/SLICE_QUEUE.md (nota post-merge: marcar el router LLM como landed en «Backend by domain»).
  • Un solo commit revertible. Sin features nuevas.

No mezclar hasta CI verde.


Note

Cursor Bugbot is generating a summary for commit 91e80ef. Configure here.

Copy the /api/v1/llm HTTP domain out of _launch_runtime.py into
app/routers/llm.py. Mount create_llm_router at ordinals 80-87 and
create_llm_prompt_router at 89-91 so Director generate-music stays
at 88. No WanGP imports in the router: config, routing and enhancer
primitives are injected from launch. llm_service.py is unchanged.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

PR Review — Loreframe Studio

Risk: medium
Scope: 8 file(s); +928/-651

Automated review from scripts/analyze_pr.py. This is a heuristic pass (no LLM) so humans still own the merge decision.

Findings

  • medium — Large pull request
    928 additions / 651 deletions. Reviewers will have an easier time with smaller, focused PRs.
  • medium — Very large file change (app/routers/llm.py)
    app/routers/llm.py adds 759 lines. Consider splitting the PR.

Changed files

  • added: app/routers/llm.py, tests/test_llm_router.py
  • modified: app/_launch_runtime.py, tests/fixtures/architecture_wire_inventory.json, tests/fixtures/route_table.json, tests/test_h3_window_planner.py, tests/test_minimax_h3.py, tests/test_minimax_song_writer_prompt.py

CONTRIBUTING checklist

  • python scripts/verify_clean_repo.py
  • python -m compileall -q app/services app/launch.py scripts
  • cd ui && npm run build if the UI changed
  • No weights, CivitAI sidecars, or generated guides
  • Stays local-first (no required accounts / telemetry)

Posted by the repo PR review workflow. Re-runs on each push to the PR.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Code health

Metric Value
Production LOC 235,061
Production files 509
Test LOC 64,413
Functions measured 14,750
Functions complexity ≥ 15 773
Maximum complexity 667

Markdown, JSON catalogs and tests are out of this table. Only app/ runtime + ui/src TS/JS count.

Most complex functions

Complexity Where
667 app/wgp.py:7157 generate_video
374 ui/src/stores/useStore.ts:4426 Async method 'startGeneration'
356 app/_launch_runtime.py:23154 _run_generation
308 app/wgp.py:12274 generate_video_tab
272 ui/src/components/Sidebar/SceneAnimatorPanel.tsx:469 Function 'SceneAnimatorPanel'
266 ui/src/stores/useStore.ts:9164 Async method 'loadSettingsFromOutput'
258 app/services/director/planners/short_film.py:3433 ShortFilmPlanner._plan_story_driven
254 app/services/director_pipeline.py:13539 _run_video_generation
245 app/services/director_pipeline.py:7663 _run_pipeline
241 ui/src/features/agent/agentActions.ts:1077 Function 'parseAction'
227 ui/src/features/agent/agentActions.ts:2672 Async function 'executeAgentActions'
226 app/services/director_pipeline.py:6492 update_comic_preview

Trend vs baseline

Metric Δ
Production LOC +1,396
Test LOC +599
Functions ≥ 15 -1
Maximum complexity +0

Warnings

  • production LOC increased by +1,396
  • complexity hotspot ui/src/stores/useStore.ts rose 373 -> 374
  • complexity hotspot app/services/model3d_service.py rose 51 -> 54
  • complexity hotspot ui/src/components/MainContent/TabFilter.tsx rose 19 -> 23
  • complexity hotspot ui/src/features/agent/AgentAssistantPanel.tsx rose 19 -> 23
  • hotspot ui/src/features/agent/agentActions.ts increased by +3 lines
  • hotspot ui/src/features/video-editor/VideoEditorPanel.tsx increased by +10 lines
  • hotspot ui/src/types/index.ts increased by +3 lines
  • hotspot app/services/model3d_service.py increased by +58 lines
  • hotspot ui/src/features/agent/capabilityRegistry.ts increased by +2 lines
  • hotspot ui/src/features/agent/applicationAdapters.ts increased by +7 lines

Ratchet passed.

@IAnMove
IAnMove merged commit 83b5e50 into main Sep 2, 2026
4 checks passed
@IAnMove
IAnMove deleted the refactor/llm-http-router branch September 5, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant