@danhachuel/thunderbolt 0.5.79 → 0.5.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes_ui/pipeline_worker.py +37 -25
- package/package.json +1 -1
|
@@ -658,28 +658,37 @@ def _normalise_video_route(task: dict[str, Any], settings: dict[str, Any]) -> st
|
|
|
658
658
|
return raw if raw in {"pexels", "pixabay", "local"} else "pexels"
|
|
659
659
|
|
|
660
660
|
|
|
661
|
-
def
|
|
662
|
-
"""Return stock
|
|
661
|
+
def _material_video_attempts(task: dict[str, Any], settings: dict[str, Any]) -> list[tuple[str, str]]:
|
|
662
|
+
"""Return one stock attempt per configured key in persisted priority order."""
|
|
663
663
|
route = _normalise_video_route(task, settings)
|
|
664
664
|
if route not in {"pexels", "pixabay"}:
|
|
665
|
-
return [route]
|
|
665
|
+
return [(route, "")]
|
|
666
666
|
|
|
667
|
-
|
|
668
|
-
|
|
667
|
+
has_explicit_cards = isinstance(settings.get("material_source_cards"), list) and bool(settings.get("material_source_cards"))
|
|
668
|
+
attempts: list[tuple[str, str]] = []
|
|
669
|
+
for card in material_source_cards(settings, enabled_only=True) if has_explicit_cards else []:
|
|
669
670
|
provider = str(card.get("provider") or "").strip().casefold()
|
|
670
|
-
|
|
671
|
+
api_key = str(card.get("api_key") or "").strip()
|
|
672
|
+
if provider not in {"pexels", "pixabay"} or not api_key:
|
|
671
673
|
continue
|
|
672
|
-
|
|
673
|
-
|
|
674
|
+
attempts.append((provider, api_key))
|
|
675
|
+
|
|
676
|
+
# A selected source is an explicit preference for this task. Its individual
|
|
677
|
+
# keys remain in their configured priority order before other providers.
|
|
678
|
+
preferred = [item for item in attempts if item[0] == route]
|
|
679
|
+
fallback = [item for item in attempts if item[0] != route]
|
|
680
|
+
ordered = preferred + fallback
|
|
681
|
+
if ordered:
|
|
682
|
+
return ordered
|
|
683
|
+
# Legacy settings keep the complete key list in one config field. Let
|
|
684
|
+
# MoneyPrinterTurbo retain its own list handling when no individual cards
|
|
685
|
+
# are available, preserving backwards compatibility for older installs.
|
|
686
|
+
return [(route, "")]
|
|
674
687
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
ordered_providers.insert(0, route)
|
|
680
|
-
elif material_api_keys(settings, route):
|
|
681
|
-
ordered_providers.insert(0, route)
|
|
682
|
-
return ordered_providers or [route]
|
|
688
|
+
|
|
689
|
+
def _material_video_routes(task: dict[str, Any], settings: dict[str, Any]) -> list[str]:
|
|
690
|
+
"""Return provider names for compatibility with diagnostics and callers."""
|
|
691
|
+
return [provider for provider, _api_key in _material_video_attempts(task, settings)]
|
|
683
692
|
|
|
684
693
|
|
|
685
694
|
def _video_timeout_seconds(task: dict[str, Any], settings: dict[str, Any] | None = None) -> int:
|
|
@@ -890,6 +899,7 @@ def _run_video_helper_once(
|
|
|
890
899
|
task: dict[str, Any],
|
|
891
900
|
*,
|
|
892
901
|
route_override: str = "",
|
|
902
|
+
api_key_override: str = "",
|
|
893
903
|
settings: dict[str, Any] | None = None,
|
|
894
904
|
) -> Path:
|
|
895
905
|
helper_dir = Path(__file__).resolve().parents[1] / "seed" / "skills"
|
|
@@ -917,6 +927,8 @@ def _run_video_helper_once(
|
|
|
917
927
|
definition = provider_definition(provider)
|
|
918
928
|
route = str(route_override or _normalise_video_route(task, settings)).strip().casefold()
|
|
919
929
|
source_keys = material_api_keys(settings, route) if route in {"pexels", "pixabay"} else []
|
|
930
|
+
if api_key_override and route in {"pexels", "pixabay"}:
|
|
931
|
+
source_keys = [str(api_key_override).strip()]
|
|
920
932
|
if route in {"pexels", "pixabay"} and not source_keys:
|
|
921
933
|
source_label = "Pexels" if route == "pexels" else "Pixabay"
|
|
922
934
|
message = f"Configure pelo menos uma API key de {source_label} em Configurações > Configuração API > Fontes de materiais."
|
|
@@ -1175,31 +1187,31 @@ def _stock_fallback_is_eligible(route: str, error: PipelineError) -> bool:
|
|
|
1175
1187
|
def _run_video_helper(task: dict[str, Any]) -> Path:
|
|
1176
1188
|
"""Run the stock helper with provider fallback in the configured priority order."""
|
|
1177
1189
|
settings = _settings()
|
|
1178
|
-
|
|
1179
|
-
if len(
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
for index, route in enumerate(
|
|
1190
|
+
attempts = _material_video_attempts(task, settings)
|
|
1191
|
+
if len(attempts) <= 1:
|
|
1192
|
+
route, api_key = attempts[0] if attempts else ("", "")
|
|
1193
|
+
return _run_video_helper_once(task, route_override=route, api_key_override=api_key, settings=settings)
|
|
1194
|
+
for index, (route, api_key) in enumerate(attempts):
|
|
1183
1195
|
attempt_task = dict(task)
|
|
1184
1196
|
generation_settings = task.get("generation_settings") if isinstance(task.get("generation_settings"), dict) else {}
|
|
1185
1197
|
attempt_task["material_source"] = route
|
|
1186
1198
|
attempt_task["generation_settings"] = {**generation_settings, "material_source": route}
|
|
1187
1199
|
try:
|
|
1188
|
-
return _run_video_helper_once(attempt_task, route_override=route, settings=settings)
|
|
1200
|
+
return _run_video_helper_once(attempt_task, route_override=route, api_key_override=api_key, settings=settings)
|
|
1189
1201
|
except PipelineStopped:
|
|
1190
1202
|
raise
|
|
1191
1203
|
except PipelineError as exc:
|
|
1192
|
-
if not _stock_fallback_is_eligible(route, exc) or index == len(
|
|
1204
|
+
if not _stock_fallback_is_eligible(route, exc) or index == len(attempts) - 1:
|
|
1193
1205
|
metadata = dict(getattr(exc, "failure_metadata", {}) or {})
|
|
1194
1206
|
metadata["failure_route"] = route
|
|
1195
|
-
metadata["fallback_attempts"] = " → ".join(_provider_api_label(item) for item in
|
|
1207
|
+
metadata["fallback_attempts"] = " → ".join(_provider_api_label(item[0]) for item in attempts[: index + 1])
|
|
1196
1208
|
message = (
|
|
1197
1209
|
f"Falha no provider {_provider_api_label(route)} após tentar "
|
|
1198
1210
|
f"{metadata['fallback_attempts']}. Último erro: {exc}"
|
|
1199
1211
|
)
|
|
1200
1212
|
raise PipelineError(message, failure_metadata=metadata) from exc
|
|
1201
1213
|
|
|
1202
|
-
raise PipelineError("
|
|
1214
|
+
raise PipelineError("Nenhuma chave de provider de vídeo stock configurada.")
|
|
1203
1215
|
|
|
1204
1216
|
|
|
1205
1217
|
def _read_persisted_script(task: dict[str, Any], channel: dict[str, Any], blueprint: dict[str, Any], topic: str) -> dict[str, Any] | None:
|
package/package.json
CHANGED