Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/api_client_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Read the split HTTP client surface as one string for source contracts."""
from pathlib import Path

API_DIR = Path(__file__).resolve().parents[1] / "ui" / "src" / "api"


def api_client_source() -> str:
return "\n".join(
path.read_text(encoding="utf-8")
for path in sorted(API_DIR.glob("*.ts"))
)
5 changes: 3 additions & 2 deletions tests/test_activity_generation_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

from pathlib import Path

from tests.api_client_source import api_client_source


ROOT = Path(__file__).resolve().parents[1]
LAUNCH = ROOT / "app" / "_launch_runtime.py"
CLIENT = ROOT / "ui" / "src" / "api" / "client.ts"
STORE = ROOT / "ui" / "src" / "stores" / "useStore.ts"
ACTIVITY = ROOT / "ui" / "src" / "components" / "ActivityFooter.tsx"


def test_backend_status_and_reconnect_publish_frozen_generation_details():
launch = LAUNCH.read_text(encoding="utf-8")
client = CLIENT.read_text(encoding="utf-8")
client = api_client_source()
store = STORE.read_text(encoding="utf-8")

assert "def _public_generation_details" in launch
Expand Down
5 changes: 2 additions & 3 deletions tests/test_director_model_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
polish_prompts_third_pass,
should_polish_director_video_prompts,
)
from tests.api_client_source import api_client_source # noqa: E402
from services.director.planners.short_film import ( # noqa: E402
ShortFilmPlanner,
_route_video_pass2_guide,
Expand Down Expand Up @@ -1878,7 +1879,6 @@ def submit(params, **kwargs):

class TestDirectorUICatalogContract(unittest.TestCase):
def test_ui_preserves_backend_director_capabilities(self):
client_path = os.path.join(_ROOT_DIR, "ui", "src", "api", "client.ts")
store_path = os.path.join(_ROOT_DIR, "ui", "src", "stores", "useStore.ts")
types_path = os.path.join(_ROOT_DIR, "ui", "src", "types", "index.ts")
chat_path = os.path.join(
Expand All @@ -1894,8 +1894,7 @@ def test_ui_preserves_backend_director_capabilities(self):
)
launch_path = os.path.join(_APP_DIR, "_launch_runtime.py")
pipeline_path = os.path.join(_APP_DIR, "services", "director_pipeline.py")
with open(client_path, encoding="utf-8") as handle:
client = handle.read()
client = api_client_source()
with open(store_path, encoding="utf-8") as handle:
store = handle.read()
with open(types_path, encoding="utf-8") as handle:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_model_selection_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import os
import unittest

from tests.api_client_source import api_client_source


ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
LAUNCH_PATH = os.path.join(ROOT, "app", "_launch_runtime.py")
CLIENT_PATH = os.path.join(ROOT, "ui", "src", "api", "client.ts")

STORE_PATH = os.path.join(ROOT, "ui", "src", "stores", "useStore.ts")
STORY_PATH = os.path.join(
ROOT, "ui", "src", "features", "stories", "StoryLabPanel.tsx",
Expand Down Expand Up @@ -74,7 +76,7 @@ def test_backend_normalizes_per_mode_preferences(self):

def test_client_and_boot_hydration_use_server_preferences(self):
launch = _source(LAUNCH_PATH)
client = _source(CLIENT_PATH)
client = api_client_source()
store = _source(STORE_PATH)

self.assertIn('@api.get("/api/v1/model-selections")', launch)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_phase1_issue_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import unittest
from unittest import mock

from tests.api_client_source import api_client_source


_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
_LAUNCH_PATH = os.path.join(_ROOT, "app", "_launch_runtime.py")
Expand Down Expand Up @@ -46,7 +48,6 @@
"utils",
"loras_mutipliers.py",
)
_CLIENT_PATH = os.path.join(_ROOT, "ui", "src", "api", "client.ts")
_STORE_PATH = os.path.join(_ROOT, "ui", "src", "stores", "useStore.ts")
_INPUTS_PATH = os.path.join(
_ROOT, "ui", "src", "components", "Sidebar", "InputsPanel.tsx",
Expand Down Expand Up @@ -151,7 +152,7 @@ def test_locked_distilled_schedule_uses_model_default(self):
)

def test_frontend_sends_the_visible_advanced_values(self):
client = _read(_CLIENT_PATH)
client = api_client_source()
store = _read(_STORE_PATH)
for field in (
"num_inference_steps?: number",
Expand Down Expand Up @@ -1722,7 +1723,7 @@ def guarded_linspace(*args, **kwargs):

def test_ui_replaces_misleading_controls_with_one_recommended_toggle(self):
controls = _read(_OUTPAINT_CONTROLS_PATH)
client = _read(_CLIENT_PATH)
client = api_client_source()
store = _read(_STORE_PATH)
self.assertIn("Preserve original scene", controls)
self.assertIn("outpaintMaskPreserving: true", store)
Expand Down Expand Up @@ -2674,7 +2675,7 @@ def test_invalid_visibility_payload_is_rejected(self):

def test_server_and_frontend_use_durable_visibility(self):
launch = _read(_LAUNCH_PATH)
client = _read(_CLIENT_PATH)
client = api_client_source()
store = _read(_STORE_PATH)
self.assertIn('@api.get("/api/v1/model-visibility")', launch)
self.assertIn('@api.put("/api/v1/model-visibility")', launch)
Expand Down
15 changes: 7 additions & 8 deletions tests/test_scail2_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import numpy as np

from tests.api_client_source import api_client_source


_requires_torch = unittest.skipUnless(
importlib.util.find_spec("torch") is not None,
Expand Down Expand Up @@ -73,7 +75,6 @@
_EDIT_SUBMODE_PATH = os.path.join(
_ROOT, "ui", "src", "components", "Sidebar", "EditSubModeToggle.tsx",
)
_API_CLIENT_PATH = os.path.join(_ROOT, "ui", "src", "api", "client.ts")
_LORA_SELECTOR_PATH = os.path.join(
_ROOT, "ui", "src", "components", "SettingsDrawer", "LoraSelector.tsx",
)
Expand Down Expand Up @@ -3692,7 +3693,7 @@ def test_recast_discovers_mappings_across_the_selected_timeline(self):
scail2 = _read(_SCAIL2_PATH)
wan_handler = _read(_WAN_HANDLER_PATH)
controls = _read(_RECAST_CONTROLS_PATH)
client = _read(_API_CLIENT_PATH)
client = api_client_source()
magic_mask = _read(_MAGIC_MASK_PATH)
sam3 = _read(_SAM3_PREPROCESSOR_PATH)

Expand Down Expand Up @@ -3849,7 +3850,7 @@ def test_recast_uses_identity_latents_and_trims_motion_preroll(self):
_ROOT, "app", "models", "wan", "any2video.py",
))
wgp = _read(_WGP_PATH)
client = _read(os.path.join(_ROOT, "ui", "src", "api", "client.ts"))
client = api_client_source()

self.assertIn('"identity_image": identity_image', launch)
self.assertIn('"scail2_clip_reference_path"', launch)
Expand Down Expand Up @@ -3917,7 +3918,7 @@ def test_recast_resolution_profile_does_not_change_model_schedule(self):
store = _read(_STORE_PATH)
controls = _read(_RECAST_CONTROLS_PATH)
selector = _read(_SCAIL_RESOLUTION_SELECTOR_PATH)
client = _read(os.path.join(_ROOT, "ui", "src", "api", "client.ts"))
client = api_client_source()

self.assertIn('"512p": (896, 512)', launch)
self.assertIn('"704p": (1280, 704)', launch)
Expand Down Expand Up @@ -4091,9 +4092,7 @@ def test_recast_auto_face_detail_is_previewed_saved_and_automatic(self):
launch = _read(_LAUNCH_PATH)
store = _read(_STORE_PATH)
controls = _read(_RECAST_CONTROLS_PATH)
client = _read(os.path.join(
_ROOT, "ui", "src", "api", "client.ts",
))
client = api_client_source()

self.assertIn('body.get("auto_face_detail") is not False', launch)
self.assertIn(
Expand Down Expand Up @@ -4146,7 +4145,7 @@ def test_repaint_reuses_scail_animate_and_is_a_first_class_edit_mode(self):
store = _read(_STORE_PATH)
controls = _read(_REPAINT_CONTROLS_PATH)
toggle = _read(_EDIT_SUBMODE_PATH)
client = _read(_API_CLIENT_PATH)
client = api_client_source()

self.assertIn('@api.post("/api/v1/repaint")', launch)
self.assertIn('@api.post("/api/v1/repaint/preview")', launch)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_series_lab_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

from tests.api_client_source import api_client_source


ROOT = Path(__file__).resolve().parents[1]
SERIES = ROOT / "ui" / "src" / "features" / "series"
Expand Down Expand Up @@ -99,7 +101,7 @@ def test_backend_authority_selection_restore_and_recovery_cards_are_wired():
def test_episode_proposal_uses_readable_cards_and_manual_editing():
panel = source("SeriesEpisodePanel.tsx")
review = source("SeriesEpisodeProposalReview.tsx")
client = (ROOT / "ui" / "src" / "api" / "client.ts").read_text(encoding="utf-8")
client = api_client_source()
assert "SeriesEpisodeProposalReview" in panel
assert "Generated proposal — review and edit" in review
assert "Internal IDs remain protected" in review
Expand Down
6 changes: 4 additions & 2 deletions tests/test_story_lab_audio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

from tests.api_client_source import api_client_source


ROOT = Path(__file__).resolve().parents[1]
STORY = ROOT / "ui" / "src" / "features" / "stories" / "StoryLabPanel.tsx"
Expand All @@ -12,7 +14,7 @@
STORY_ACTIVITY = ROOT / "ui" / "src" / "features" / "stories" / "activityLifecycle.ts"
IMAGE_GENERATION = ROOT / "ui" / "src" / "lib" / "imageGeneration.ts"
STORE = ROOT / "ui" / "src" / "stores" / "useStore.ts"
API_CLIENT = ROOT / "ui" / "src" / "api" / "client.ts"



def test_lyria_prompt_does_not_require_an_optional_reference_song():
Expand Down Expand Up @@ -95,7 +97,7 @@ def test_story_lab_refresh_recovers_the_backend_job_without_opening_a_client_roo


def test_story_lab_status_polling_survives_transient_mobile_disconnects():
source = API_CLIENT.read_text(encoding="utf-8")
source = api_client_source()

assert "STORY_STATUS_RETRY_DELAYS_MS" in source
assert "getStoryGenerationStatusResilient" in source
Expand Down
6 changes: 4 additions & 2 deletions tests/test_story_montage_clip_history_ui.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from pathlib import Path

from tests.api_client_source import api_client_source


ROOT = Path(__file__).resolve().parents[1]
TIMELINE = ROOT / "ui" / "src" / "features" / "stories" / "StoryProductionTimeline.tsx"
HANDOFF = ROOT / "ui" / "src" / "features" / "stories" / "directorClipHandoff.ts"
MEDIA = ROOT / "ui" / "src" / "components" / "MainContent" / "MediaFeedItem.tsx"
MAIN = ROOT / "ui" / "src" / "components" / "MainContent" / "MainContent.tsx"
CLIENT = ROOT / "ui" / "src" / "api" / "client.ts"

STORE = ROOT / "ui" / "src" / "stores" / "useStore.ts"


Expand Down Expand Up @@ -39,7 +41,7 @@ def test_creator_handoff_reduces_multiclip_metadata_to_one_exact_slot():
def test_generated_video_can_be_selected_and_returns_to_story_montage():
media = MEDIA.read_text(encoding="utf-8")
main = MAIN.read_text(encoding="utf-8")
client = CLIENT.read_text(encoding="utf-8")
client = api_client_source()

assert "Usar en Montaje · clip" in media
assert "writeDirectorClipReplacementResult" in media
Expand Down
3 changes: 2 additions & 1 deletion ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ sequence used by CI. The build output is `ui/dist`; do not edit it manually.
## Architecture

- `src/api/client.ts` is the typed HTTP boundary. Browser code should use it
instead of creating feature-specific URL conventions.
instead of creating feature-specific URL conventions. Slice modules live
beside it and are reexported from `client.ts`.
- `src/stores/useStore.ts` is the public Zustand facade. Extracted reducers
and slices live beside it and must preserve that facade for existing views.
- `src/features/` owns large workflows such as Series Lab, Story Lab and the
Expand Down
86 changes: 86 additions & 0 deletions ui/src/api/characters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { BASE } from './http'

export async function fetchCharacterKitLibrary(workspace: string): Promise<import('../lib/characterKit').CharacterKitLibrary> {
const response = await fetch(`${BASE}/api/v1/character-kits/library?workspace=${encodeURIComponent(workspace)}`)
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Could not load Character Kits' }))
throw new Error(typeof error.detail === 'string' ? error.detail : 'Could not load Character Kits')
}
return response.json()
}

export async function saveCharacterKit(
workspace: string,
library: import('../lib/characterKit').CharacterKitLibrary,
kit: import('../lib/characterKit').CharacterKit,
): Promise<import('../lib/characterKit').CharacterKitLibrary> {
const response = await fetch(`${BASE}/api/v1/character-kits/library/kits/${encodeURIComponent(kit.id)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ workspace, baseRevision: library.revision, kit, makeActive: true }),
})
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Could not save Character Kit' }))
const detail = error.detail
throw new Error(typeof detail === 'string' ? detail : typeof detail?.message === 'string' ? detail.message : 'Could not save Character Kit')
}
return response.json()
}

export async function deleteCharacterKit(
workspace: string,
library: import('../lib/characterKit').CharacterKitLibrary,
kitId: string,
): Promise<import('../lib/characterKit').CharacterKitLibrary> {
const response = await fetch(`${BASE}/api/v1/character-kits/library/kits/${encodeURIComponent(kitId)}`, {
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ workspace, baseRevision: library.revision }),
})
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Could not delete Character Kit' }))
const detail = error.detail
throw new Error(typeof detail === 'string' ? detail : typeof detail?.message === 'string' ? detail.message : 'Could not delete Character Kit')
}
return response.json()
}

export async function cleanCharacterKitFaceOverlay(details: {
workspace: string
source: string
padding?: number
}): Promise<import('../lib/characterKitFaceRig').FaceRigCleanupResult> {
const response = await fetch(`${BASE}/api/v1/character-kits/face-rig/cleanup`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
workspace: details.workspace,
source: details.source,
padding: details.padding ?? 8,
}),
})
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Could not clean Face Rig overlay' }))
const detail = error.detail
throw new Error(typeof detail === 'string' ? detail : 'Could not clean Face Rig overlay')
}
return response.json()
}

export async function describeCharacterRefs(params: {
kind: 'character' | 'object'
image_paths: string[]
roles?: string[]
workspace?: string
}): Promise<{ a_prompt: string; kind: string }> {
const res = await fetch(`${BASE}/api/v1/characters/describe-refs`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params),
})
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: 'Could not describe the reference images' }))
throw new Error(err.detail || 'Could not describe the reference images')
}
return res.json()
}
Loading
Loading