Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
120 lines
4.9 KiB
Python
120 lines
4.9 KiB
Python
"""Apps shelf catalog (MH8): one data file per app under ``assets/presets/apps``.
|
|
|
|
An app is shown only when (1) its runner can run on this deployment (a key or a
|
|
package it needs is present), (2) its preview loop is uploaded (recorded in
|
|
``previews.json``) and ``APPS_PREVIEWS_LIVE`` is on, and (3) its copy names no
|
|
tool or model. No placeholder tiles: an app without a real preview stays hidden.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
import re
|
|
from dataclasses import dataclass, field
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
ASSETS = Path(__file__).resolve().parents[3] / "assets" / "presets" / "apps"
|
|
PREVIEWS_FILE = ASSETS / "previews.json"
|
|
PREVIEWS_LIVE_ENV = "APPS_PREVIEWS_LIVE"
|
|
_FILE = re.compile(r"^(?P<id>[a-z0-9-]+)@v(?P<version>\d+)\.json$")
|
|
RUNNERS = ("plan", "image_edit", "image_gen", "transcribe", "local")
|
|
LOCAL_TOOLS = ("transition", "remove_bg", "beat_cut", "hook_score")
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class App:
|
|
id: str
|
|
version: int
|
|
name: str
|
|
blurb: str
|
|
input: dict[str, Any]
|
|
runner: str
|
|
price: dict[str, Any]
|
|
preview: str
|
|
plan: dict[str, Any] = field(default_factory=dict)
|
|
edit: dict[str, Any] = field(default_factory=dict)
|
|
local: str = ""
|
|
|
|
|
|
def _load(path: Path) -> App:
|
|
match = _FILE.match(path.name)
|
|
if not match:
|
|
raise ValueError(f"app file {path.name} must be named <id>@v<N>.json")
|
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
if data.get("id") != match["id"] or int(data.get("version", 0)) != int(match["version"]):
|
|
raise ValueError(f"{path.name}: id or version does not match the file name")
|
|
if data["runner"] not in RUNNERS:
|
|
raise ValueError(f"{path.name}: unknown runner {data['runner']!r}")
|
|
if data["runner"] == "local" and data.get("local") not in LOCAL_TOOLS:
|
|
raise ValueError(f"{path.name}: unknown local tool {data.get('local')!r}")
|
|
return App(id=data["id"], version=int(data["version"]), name=data["name"], blurb=data["blurb"],
|
|
input=dict(data["input"]), runner=data["runner"], price=dict(data["price"]),
|
|
preview=str(data.get("preview") or ""), plan=dict(data.get("plan") or {}),
|
|
edit=dict(data.get("edit") or {}), local=str(data.get("local") or ""))
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def all_apps() -> tuple[App, ...]:
|
|
newest: dict[str, App] = {}
|
|
for path in sorted(ASSETS.glob("*@v*.json")):
|
|
app = _load(path)
|
|
if app.id not in newest or app.version > newest[app.id].version:
|
|
newest[app.id] = app
|
|
return tuple(sorted(newest.values(), key=lambda a: a.id))
|
|
|
|
|
|
def get(app_id: str) -> App | None:
|
|
wanted = str(app_id or "").strip().lower()
|
|
return next((a for a in all_apps() if a.id == wanted), None)
|
|
|
|
|
|
def previews() -> dict[str, str]:
|
|
try:
|
|
return dict(json.loads(PREVIEWS_FILE.read_text(encoding="utf-8")).get("live") or {})
|
|
except (OSError, ValueError):
|
|
return {}
|
|
|
|
|
|
def runner_ready(app: App, env: dict[str, str] | None = None) -> bool:
|
|
source = os.environ if env is None else env
|
|
if app.runner == "image_edit":
|
|
# Either a real image-edit provider works: Muse Image (Meta Model API,
|
|
# $0.01/image, preferred — see runners.edit_image_auto) or fal's Flux
|
|
# Kontext queue ($0.04/image, the original provider), kept as a real
|
|
# fallback. An app only needs one configured key to be ready.
|
|
has_muse = bool((source.get("MODEL_API_KEY") or source.get("MUSE_API_KEY") or "").strip())
|
|
has_fal = bool((source.get("FAL_KEY") or "").strip())
|
|
return has_muse or has_fal
|
|
if app.runner == "image_gen":
|
|
# Text-to-image has only one real provider wired for the apps shelf
|
|
# (Muse Image's generations endpoint) — no fal fallback exists here,
|
|
# unlike image_edit's Flux Kontext fallback, so this needs the real
|
|
# key present, not just "any image provider".
|
|
return bool((source.get("MODEL_API_KEY") or source.get("MUSE_API_KEY") or "").strip())
|
|
if app.runner == "transcribe":
|
|
# Only one real provider wired here too (Muse Voice Transcribe) —
|
|
# same key as every other Meta Model API service.
|
|
return bool((source.get("MODEL_API_KEY") or source.get("MUSE_API_KEY") or "").strip())
|
|
if app.local == "remove_bg":
|
|
return importlib.util.find_spec("rembg") is not None
|
|
return True
|
|
|
|
|
|
def visible(app: App, env: dict[str, str] | None = None) -> bool:
|
|
source = os.environ if env is None else env
|
|
live = (source.get(PREVIEWS_LIVE_ENV) or "").strip().lower() in {"1", "true", "yes", "on"}
|
|
return live and app.id in previews() and runner_ready(app, source)
|
|
|
|
|
|
def copy_hits(app: App) -> list[str]:
|
|
from app.domains.presets_hub.catalog import vendor_hits
|
|
|
|
return list(vendor_hits(" ".join([app.name, app.blurb, json.dumps(app.input)])))
|
|
|
|
|
|
__all__ = ["ASSETS", "App", "all_apps", "copy_hits", "get", "previews", "runner_ready", "visible"]
|