@danhachuel/thunderbolt 0.5.12 → 0.5.14
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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.5.09 (normalizado pelo npm para 0.5.9)
|
|
4
|
+
|
|
5
|
+
Adicionado um shim de compatibilidade que intercepta a escrita de saída do Click antes do carregamento do Streamlit e grava directamente em UTF-8, evitando o caminho nativo que volta a procurar `utf-16-le` durante o shutdown do Windows. Incluídos testes com um console simulado em `utf-16-le`.
|
|
6
|
+
|
|
7
|
+
## 0.5.08 (normalizado pelo npm para 0.5.8)
|
|
8
|
+
|
|
9
|
+
Corrigido o erro `LookupError: unknown encoding: utf-16-le` que podia ocorrer durante o shutdown do Streamlit no Windows. O launcher Node agora materializa as variáveis de encoding e `CLICK_NO_WIN_CONSOLE` no processo pai antes de iniciar Python; os workers de automação e pipeline também aplicam as mesmas definições antes dos imports restantes.
|
|
@@ -30,9 +30,29 @@ def _items(value: Any) -> list[dict[str, Any]]:
|
|
|
30
30
|
for key in ("items", "designs", "results"):
|
|
31
31
|
if isinstance(value.get(key), list):
|
|
32
32
|
return [dict(item) for item in value[key] if isinstance(item, Mapping)]
|
|
33
|
+
for key in ("data", "result", "response"):
|
|
34
|
+
if isinstance(value.get(key), (Mapping, list)):
|
|
35
|
+
nested = _items(value[key])
|
|
36
|
+
if nested:
|
|
37
|
+
return nested
|
|
33
38
|
return []
|
|
34
39
|
|
|
35
40
|
|
|
41
|
+
def _design_id(value: Any) -> str:
|
|
42
|
+
"""Extract a Canva design identifier from REST/MCP result variants."""
|
|
43
|
+
if isinstance(value, Mapping):
|
|
44
|
+
for key in ("design_id", "designId", "id"):
|
|
45
|
+
candidate = str(value.get(key) or "").strip()
|
|
46
|
+
if candidate:
|
|
47
|
+
return candidate
|
|
48
|
+
for key in ("design", "resource", "data"):
|
|
49
|
+
if isinstance(value.get(key), Mapping):
|
|
50
|
+
found = _design_id(value[key])
|
|
51
|
+
if found:
|
|
52
|
+
return found
|
|
53
|
+
return ""
|
|
54
|
+
|
|
55
|
+
|
|
36
56
|
def _first_id(value: Any, keys: tuple[str, ...]) -> str:
|
|
37
57
|
if isinstance(value, Mapping):
|
|
38
58
|
for key in keys:
|
|
@@ -102,8 +122,8 @@ def run_direct_canva_thumbnail(
|
|
|
102
122
|
candidates = _items(result)
|
|
103
123
|
if not candidates:
|
|
104
124
|
raise CanvaMCPError("Canva não encontrou designs para as palavras-chave da thumbnail.")
|
|
105
|
-
selected = candidates[0]
|
|
106
|
-
design_id =
|
|
125
|
+
selected = next((candidate for candidate in candidates if _design_id(candidate)), candidates[0])
|
|
126
|
+
design_id = _design_id(selected)
|
|
107
127
|
if not design_id:
|
|
108
128
|
raise CanvaMCPError("A pesquisa Canva devolveu um design sem ID.")
|
|
109
129
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danhachuel/thunderbolt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.14",
|
|
4
4
|
"description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "scripts/cli.mjs",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"seed/references/*.md",
|
|
26
26
|
"seed/references/*.sql",
|
|
27
27
|
"README.md",
|
|
28
|
+
"CHANGELOG.md",
|
|
28
29
|
"MANUAL-INSTALACAO.md",
|
|
29
30
|
"THIRD-PARTY-NOTICES.md",
|
|
30
31
|
"requirements.txt",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import io
|
|
4
3
|
import os
|
|
5
4
|
import sys
|
|
5
|
+
from windows_encoding_compat import install as install_windows_encoding, wrap_stream
|
|
6
6
|
|
|
7
7
|
# Este ficheiro é o primeiro módulo Python executado pelo launcher. As
|
|
8
8
|
# variáveis e os streams precisam de ser corrigidos antes de qualquer import
|
|
@@ -11,6 +11,7 @@ os.environ["PYTHONIOENCODING"] = "utf-8"
|
|
|
11
11
|
os.environ["PYTHONUTF8"] = "1"
|
|
12
12
|
os.environ["PYTHONLEGACYWINDOWSSTDIO"] = "1"
|
|
13
13
|
os.environ["CLICK_NO_WIN_CONSOLE"] = "1"
|
|
14
|
+
install_windows_encoding()
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
def _utf8_stream(stream: object) -> object:
|
|
@@ -20,7 +21,7 @@ def _utf8_stream(stream: object) -> object:
|
|
|
20
21
|
if buffer is None:
|
|
21
22
|
return stream
|
|
22
23
|
try:
|
|
23
|
-
return
|
|
24
|
+
return wrap_stream(stream)
|
|
24
25
|
except (AttributeError, OSError, ValueError):
|
|
25
26
|
return stream
|
|
26
27
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Windows console compatibility for Click/Streamlit shutdown output."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import io
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Any, Callable
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
_UTF8_ENV = {
|
|
11
|
+
"CLICK_NO_WIN_CONSOLE": "1",
|
|
12
|
+
"PYTHONIOENCODING": "utf-8",
|
|
13
|
+
"PYTHONUTF8": "1",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _safe_click_echo(original: Callable[..., Any]) -> Callable[..., Any]:
|
|
18
|
+
def echo(message: Any = None, file: Any = None, nl: bool = True, err: bool = False, color: Any = None) -> Any:
|
|
19
|
+
target = file if file is not None else (sys.stderr if err else sys.stdout)
|
|
20
|
+
if message is None:
|
|
21
|
+
message = ""
|
|
22
|
+
text = str(message) + ("\n" if nl else "")
|
|
23
|
+
buffer = getattr(target, "buffer", None)
|
|
24
|
+
try:
|
|
25
|
+
if buffer is not None and hasattr(buffer, "write"):
|
|
26
|
+
buffer.write(text.encode("utf-8", "replace"))
|
|
27
|
+
if hasattr(buffer, "flush"):
|
|
28
|
+
buffer.flush()
|
|
29
|
+
else:
|
|
30
|
+
target.write(text)
|
|
31
|
+
if hasattr(target, "flush"):
|
|
32
|
+
target.flush()
|
|
33
|
+
return None
|
|
34
|
+
except (AttributeError, OSError, UnicodeError, ValueError, LookupError):
|
|
35
|
+
# Fall back to Click for non-console streams (files, testing runners).
|
|
36
|
+
return original(message, file=file, nl=nl, err=err, color=color)
|
|
37
|
+
|
|
38
|
+
echo.__name__ = getattr(original, "__name__", "echo")
|
|
39
|
+
echo.__doc__ = getattr(original, "__doc__", None)
|
|
40
|
+
return echo
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def install(*, force: bool = False) -> None:
|
|
44
|
+
"""Install the Windows-safe Click output path before Streamlit imports Click."""
|
|
45
|
+
os.environ.update(_UTF8_ENV)
|
|
46
|
+
if not force and os.name != "nt":
|
|
47
|
+
return
|
|
48
|
+
try:
|
|
49
|
+
import click
|
|
50
|
+
except ImportError:
|
|
51
|
+
return
|
|
52
|
+
if getattr(click, "_thunderbolt_utf8_echo", False):
|
|
53
|
+
return
|
|
54
|
+
click.echo = _safe_click_echo(click.echo)
|
|
55
|
+
click._thunderbolt_utf8_echo = True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def wrap_stream(stream: Any) -> Any:
|
|
59
|
+
"""Wrap a text stream as UTF-8 without closing its inherited buffer twice."""
|
|
60
|
+
if stream is None or getattr(stream, "buffer", None) is None:
|
|
61
|
+
return stream
|
|
62
|
+
try:
|
|
63
|
+
wrapper = io.TextIOWrapper(stream.buffer, encoding="utf-8", errors="replace", line_buffering=True)
|
|
64
|
+
setattr(wrapper, "_thunderbolt_utf8", True)
|
|
65
|
+
return wrapper
|
|
66
|
+
except (AttributeError, OSError, ValueError):
|
|
67
|
+
return stream
|