@danhachuel/thunderbolt 0.7.5 → 0.7.7

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/app/main.py CHANGED
@@ -2625,17 +2625,19 @@ def _channel_average_video_time(channel: dict[str, Any], *, prompt_master: str =
2625
2625
 
2626
2626
 
2627
2627
  def _refresh_youtube_channel_metrics(channel: dict[str, Any], youtube: YouTubeAdapter) -> tuple[bool, str]:
2628
- result = youtube.fetch_channel_public(str(channel.get("url") or channel.get("handle") or ""))
2628
+ channel_ref = str(channel.get("youtube_channel_id") or channel.get("youtube_id") or channel.get("url") or channel.get("handle") or "")
2629
+ result = youtube.fetch_channel(channel_ref) if youtube.api_key else youtube.fetch_channel_public(channel_ref)
2629
2630
  if not result.ok or not isinstance(result.data, dict):
2630
2631
  return False, result.message
2631
2632
  data = result.data
2632
- update_channel(str(channel["id"]), {
2633
- "subscriber_count": data.get("subscriber_count"),
2634
- "video_count": data.get("video_count"),
2635
- "view_count": data.get("view_count"),
2633
+ updates = {
2636
2634
  "metrics_source": data.get("metrics_source", "youtube_public_page"),
2637
2635
  "last_public_lookup_at": data.get("last_public_lookup_at", now()),
2638
- })
2636
+ }
2637
+ for field in ("youtube_id", "name", "handle", "url", "thumbnail_url", "subscriber_count", "video_count", "view_count"):
2638
+ if data.get(field) is not None and data.get(field) != "":
2639
+ updates[field] = data[field]
2640
+ update_channel(str(channel["id"]), updates)
2639
2641
  return True, "Métricas YouTube actualizadas."
2640
2642
 
2641
2643
 
@@ -117,7 +117,17 @@ def _connected_account_id(client: Any, user_id: str, toolkit: str, selector: str
117
117
  try:
118
118
  response = client.connected_accounts.list(user_ids=[_require_user_id(user_id)], statuses=["ACTIVE"])
119
119
  raw = _safe_value(response)
120
- items = raw.get("items", []) if isinstance(raw, dict) else raw
120
+ if isinstance(raw, dict):
121
+ # Composio SDK versions expose the list either directly or under
122
+ # ``data``; accept both shapes so aliases are never sent as IDs.
123
+ items = raw.get("items")
124
+ if items is None:
125
+ data = raw.get("data")
126
+ items = data.get("items", data) if isinstance(data, dict) else data
127
+ if items is None:
128
+ items = raw.get("connected_accounts", [])
129
+ else:
130
+ items = raw
121
131
  if not isinstance(items, list):
122
132
  items = []
123
133
  matching_items = []
@@ -135,8 +145,15 @@ def _connected_account_id(client: Any, user_id: str, toolkit: str, selector: str
135
145
  for item in matching_items:
136
146
  candidates = [item.get("id"), item.get("nanoid"), item.get("alias"), item.get("name")]
137
147
  if any(str(candidate or "").strip().casefold() == wanted for candidate in candidates):
138
- return str(item.get("id") or item.get("nanoid") or value).strip()
139
- return value
148
+ technical_id = str(item.get("id") or item.get("nanoid") or "").strip()
149
+ if technical_id:
150
+ return technical_id
151
+ available = [str(item.get("alias") or item.get("name") or item.get("id") or "").strip() for item in matching_items]
152
+ available = [item for item in available if item]
153
+ suffix = f" Contas activas: {', '.join(available)}." if available else ""
154
+ raise ComposioUploadError(
155
+ f"A connected account `{value}` não foi encontrada para o toolkit {toolkit or 'seleccionado'}.{suffix}"
156
+ )
140
157
  if len(matching_items) == 1:
141
158
  item = matching_items[0]
142
159
  return str(item.get("id") or item.get("nanoid") or "").strip()
@@ -81,7 +81,7 @@ def _parse_public_count(value: Any) -> int | None:
81
81
  text = _text_from_node(value).lower().replace(" ", "")
82
82
  if not text:
83
83
  return None
84
- match = re.search(r"([0-9][0-9.,]*)(mil|milhões|mi|bi|[kmb])?", text)
84
+ match = re.search(r"([0-9][0-9.,]*)(milhões|mil|mi|bi|[kmb])?", text)
85
85
  if not match:
86
86
  return None
87
87
  number = match.group(1)
@@ -89,6 +89,16 @@ def _parse_public_count(value: Any) -> int | None:
89
89
  if suffix == "milhões":
90
90
  suffix = "m"
91
91
  try:
92
+ if suffix:
93
+ # YouTube pode devolver "193 mil", "193,4 mil" ou "1.234 mil".
94
+ # Um ponto seguido de três algarismos é separador de milhares;
95
+ # vírgula/ponto com 1–2 algarismos é a parte decimal.
96
+ if "." in number and "," in number:
97
+ number = number.replace(".", "").replace(",", ".")
98
+ elif "," in number:
99
+ number = number.replace(",", ".")
100
+ elif re.fullmatch(r"\d+\.\d{3}", number):
101
+ number = number.replace(".", "")
92
102
  if suffix in {"k", "mil"}:
93
103
  return int(float(number.replace(",", ".")) * 1_000)
94
104
  if suffix in {"m", "mi"}:
@@ -412,6 +422,7 @@ class YouTubeAdapter:
412
422
  break
413
423
  subscriber_value = _find_first_key(initial_data, "subscriberCountText")
414
424
  video_value = _find_first_key(initial_data, "videoCountText")
425
+ view_value = _find_first_key(initial_data, "viewCountText")
415
426
  data = {
416
427
  "youtube_id": youtube_id or feed.get("youtube_id", ""),
417
428
  "name": title,
@@ -421,7 +432,7 @@ class YouTubeAdapter:
421
432
  "thumbnail_url": thumbnail_url,
422
433
  "subscriber_count": _parse_public_count(subscriber_value),
423
434
  "video_count": _parse_public_count(video_value) or feed.get("video_count"),
424
- "view_count": None,
435
+ "view_count": _parse_public_count(view_value),
425
436
  "metrics_source": "youtube_public_page" if (page_title or page_description or page_thumbnail) else ("youtube_public_feed" if feed.get("name") else "youtube_public_page"),
426
437
  "public_lookup": True,
427
438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.7.05",
3
+ "version": "0.7.07",
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",