Skip to content

refactor: extraer el slice LLM de useStore - #107

Merged
IAnMove merged 2 commits into
mainfrom
refactor/usestore-llm-slice
Sep 2, 2026
Merged

refactor: extraer el slice LLM de useStore#107
IAnMove merged 2 commits into
mainfrom
refactor/usestore-llm-slice

Conversation

@IAnMove

@IAnMove IAnMove commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Contrato

PR medio y cohesivo del slice LLM del drawer de Studio. No mueve startGeneration.

Se mueve a ui/src/stores/llmSlice.ts (fachada pública useStore sin cambios de import):

  • estado: llmStatus, llmLoading, llmModels, isEnhancing, h3WindowPlan
  • acciones: loadLlmStatus, loadLlmModels, loadLlm, unloadLlm, enhancePrompt, updateH3WindowPrompt, clearH3WindowPlan

enhancePrompt sí se mueve. No está inlined en startGeneration; lee params/imágenes/ventanas del host y escribe el prompt (o el plan H3) sin llevarse el motor de generación. updateH3WindowPrompt es del drawer y no llama a generate.

Se queda en useStore.ts:

  • startGeneration, stopGeneration, reconnect de jobs/pipelines
  • auto-unload de VRAM antes de generate / Director image gen (sigue siendo best-effort; usa UNLOADED_LLM_STATUS del slice)
  • llmStreamText / llmStreamDone (Director stream, no el drawer)
  • services/production profile (el slice solo lee llm_provider para listar modelos)

Composición: bindSlice(set, get, createLlmSlice) sin as never. SliceCreator admite un host más ancho para que el drawer lea sibling config sin castear en el call site.

Cómo probar

cd ui && npx tsc -b --pretty false
npx eslint src/stores/llmSlice.ts src/stores/storeApi.ts src/stores/useStore.ts tests/architectureSlices.test.mjs --max-warnings=0
npx tsx --tsconfig tsconfig.app.json --import ./tests/setupI18n.ts --test tests/architectureSlices.test.mjs
npm test
cd ..
python tests/test_h3_window_planner.py
python scripts/architecture_contracts.py
python scripts/code_health.py --check

Local: tsc OK, eslint --max-warnings=0 OK, architectureSlices 12/12, npm test 506/506, H3 planner OK, architecture fixtures sin --write, code-health ratchet PASS. El inventario no cambia: el test de H3 sigue leyendo useStore.ts y ahora también llmSlice.ts.

Pendiente de CI. No mezclar hasta que los checks estén verdes. No aprobar este PR desde el mismo agente.

Generate

startGeneration / stopGeneration / job reconnect siguen en useStore. El slice aislado no expone esas acciones.

SLICE_QUEUE

No se edita docs/development/SLICE_QUEUE.md (conflicto con PRs paralelos). Tras el merge, anotar en la cola: slice LLM del drawer extraído (llmSlice.ts); generate sigue en la fachada.

No toca _launch_runtime.py, WanGP, app/wgp.py, app/models/**, launchers ni agentActions.ts.


Note

Low Risk
Structural refactor with tests and no backend changes; behavior should match the moved enhancePrompt and LLM load/unload paths, with slightly higher coupling risk via the wider slice host typing.

Overview
Moves Studio LLM drawer state and actions out of useStore.ts into a new llmSlice.ts, composed with bindSlice(set, get, createLlmSlice) so the public useStore API stays the same.

The slice owns llmStatus, model loading, enhancePrompt, and H3 window plan editing (h3WindowPlan, updateH3WindowPrompt, clearH3WindowPlan). enhancePrompt behavior is unchanged in intent: it still gathers media, branches to planH3Windows for multi-window H3 pacing, or calls llmEnhancePrompt otherwise. startGeneration, job reconnect, and best-effort LLM unload before GPU work remain in useStore, now resetting status via shared UNLOADED_LLM_STATUS.

storeApi gains a SliceCreator<TSlice, THost> host type so the LLM slice can read/write sibling fields (params, images, sliding windows) without as never; bindSlice passes the full store set/get directly instead of wrapping them.

Tests: architectureSlices.test.mjs adds LLM isolation/facade coverage; test_h3_window_planner includes llmSlice.ts when asserting UI/runtime H3 prompt wiring.

Reviewed by Cursor Bugbot for commit 164146e. Configure here.

Move Studio LLM status, models, load/unload, prompt enhance and H3 window
prompt edits into llmSlice, composed with bindSlice. Callers still import
useStore. startGeneration, stopGeneration and job reconnect stay in the facade.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

PR Review — Loreframe Studio

Risk: low
Scope: 6 file(s); +421/-253; React UI

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

Findings

  • low — UI changed — rebuild before merge
    Run cd ui && npm run build (CI already does this). Pinokio Update rebuilds for end users; keep ui/dist untracked.

Changed files

  • added: ui/src/stores/llmSlice.ts
  • modified: tests/test_h3_window_planner.py, tests/test_minimax_h3.py, ui/src/stores/storeApi.ts, ui/src/stores/useStore.ts, ui/tests/architectureSlices.test.mjs

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,157
Production files 510
Test LOC 64,485
Functions measured 14,757
Functions complexity ≥ 15 772
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:4412 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:8934 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,492
Test LOC +671
Functions ≥ 15 -2
Maximum complexity +0

Warnings

  • production LOC increased by +1,492
  • 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 73dea95 into main Sep 2, 2026
4 checks passed
@IAnMove
IAnMove deleted the refactor/usestore-llm-slice 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