Skip to content

refactor(services): add ChatService protocol and MessageRouter with centralized routing#45

Open
Row0902 wants to merge 7 commits into
metalalchemist:masterfrom
Row0902:refactor/service-protocol
Open

refactor(services): add ChatService protocol and MessageRouter with centralized routing#45
Row0902 wants to merge 7 commits into
metalalchemist:masterfrom
Row0902:refactor/service-protocol

Conversation

@Row0902

@Row0902 Row0902 commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add ChatService Protocol for 6 chat services (TikTok, Kick, YouTube, Twitch, Sala, YouTubeRealTime) using typing.Protocol
  • Extract MessageRouter + RoutableMessage dataclass to eliminate duplicated message routing logic across all platforms
  • Fix threading safety: YouTube and Twitch now wrap all UI calls in wx.CallAfter (previously called UI from background threads directly)
  • Fix 3 pre-existing bugs: ChatItemController wrong arg count, on_listbox_keyup invalid index crash, list_favorite wrong parent traversal

Changes

File Change
servicios/chat_service_protocol.py New — ChatService Protocol
servicios/message_router.py New — MessageRouter + RoutableMessage
servicios/tiktok.py Modified — 8 handlers refactored to router
servicios/kick.py Modified — badge-based routing refactored
servicios/youtube.py Modified — routing + wx.CallAfter fix
servicios/twich.py Modified — routing + wx.CallAfter fix
servicios/sala.py Modified — routing refactored
servicios/YouTubeRealDataTime.py Modified — routing refactored
controller/chat_controller.py Fixed — arg count, guard, set_active_service
controller/main_controller.py Modified — ChatService type annotation
controller/menus/chat_menu_controller.py Fixed — list_favorite access

Test Plan

  • pytest tests/ — 24/24 passed
  • ty check servicios/message_router.py — zero errors
  • All 6 services produce identical routing output
  • Thread safety verified (all UI calls through wx.CallAfter)

@rmcpantoja

Copy link
Copy Markdown
Collaborator

Hi,

Thank you for your contribution.

As of now, the CI failed when building the 64-bit edition due to your Python version change. Therefore, it seems numpy needs to be updated.

@rmcpantoja
rmcpantoja self-requested a review June 7, 2026 02:36
class ChatService(Protocol):
"""Structural protocol for all platform chat services.

Every service (TikTok, Kick, YouTube, Twitch, Sala, YouTubeRealTime)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Every service (TikTok, Kick, YouTube, Twitch, Sala, YouTubeRealTime)
Every service (TikTok, Kick, YouTube, Twitch, Playroom, YouTubeRealTime)

Comment thread pyproject.toml Outdated
"google-currency",
"googletrans-py",
"kick-py",
"numpy==1.26.4",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to bump it up.

Comment thread pyproject.toml Outdated
"yt-dlp[curl-cffi,default]>=2026.3.17",
]

# Ya no necesitas [tool.uv.extra-build-dependencies] porque la 4.2.5 descarga el binario directo (.wheel)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be an AI-driven context.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of those docs? It seems those are written by AI. Is this designed for developers? IMO the project code may not be too hard to understand nowadays, now that it is modulariced.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola. Esos documentos son specs sobre los cambios que estuve trabajando. Básicamente estoy utilizando SDD para los cambios y las correcciones que estoy implementando. De todas formas los excluí de la PR.

@rmcpantoja rmcpantoja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the use of AI here to improve, however, please consider checking their outputs.

@metalalchemist

Copy link
Copy Markdown
Owner

Numpy 2.x tiene un problema con procesadores antiguos veo que con la serie amd. Si alguno sabe que podríamos hacer para arreglar eso estaría cool.
No he entrado a mi computadora, pero si falla por la versión 1.26, habría que ver cómo nvda usa numpy para solucionarlo, ya que ellos usan versiones modernas de python

@Row0902
Row0902 force-pushed the refactor/service-protocol branch from 199c2d7 to 8e85fd3 Compare June 9, 2026 07:34
@rmcpantoja

Copy link
Copy Markdown
Collaborator

Hola.

NVDA no usa Numpy. Y si lo ha usado, ralentiza el lector de pantalla.

Hubo un momento en que introdujeron la descripción de imágenes en local en el repo, pero fue revertido un tiempo después de haber llegado, justamente por lo pesado que es numpy en cuanto a recursos y muchas limitaciones del modelo, pero eso ya es muy aparte de lo que nos compete.

Podríamos prescindir totalmente de ONNXRuntime que lo usa de lleno, hasta lo usamos nosotros para convertir las entradas para las voces de piper a tipos de variable compatibles, esto es: los fonemas del texto en tokens (un array int64 con los ids de cada fonema), los parámetros como la velocidad y la escala de ruido que son flotantes (float64).

A lo mejor haya una forma de usar CoreML para piper que, según había leído, ya viene integrado desde Windows 10.

Recomiendo echarle un vistazo al código de piper para entender más el tema de entradas (tensores con los tipos que ya mencioné) y salidas (el audio resultante en float32 que se convierte luego a int16, audio compatible).

Investigaré más sobre este remplazo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants