forked from Rockachopa/Timmy-time-dashboard
feat: code quality audit + autoresearch integration + infra hardening (#150)
This commit is contained in:
committed by
GitHub
parent
fd0ede0d51
commit
ae3bb1cc21
@@ -21,6 +21,7 @@ from typing import Any, Optional
|
||||
|
||||
class PlatformState(Enum):
|
||||
"""Lifecycle state of a chat platform connection."""
|
||||
|
||||
DISCONNECTED = auto()
|
||||
CONNECTING = auto()
|
||||
CONNECTED = auto()
|
||||
@@ -30,13 +31,12 @@ class PlatformState(Enum):
|
||||
@dataclass
|
||||
class ChatMessage:
|
||||
"""Vendor-agnostic representation of a chat message."""
|
||||
|
||||
content: str
|
||||
author: str
|
||||
channel_id: str
|
||||
platform: str
|
||||
timestamp: str = field(
|
||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||
)
|
||||
timestamp: str = field(default_factory=lambda: datetime.now(timezone.utc).isoformat())
|
||||
message_id: Optional[str] = None
|
||||
thread_id: Optional[str] = None
|
||||
attachments: list[str] = field(default_factory=list)
|
||||
@@ -46,13 +46,12 @@ class ChatMessage:
|
||||
@dataclass
|
||||
class ChatThread:
|
||||
"""Vendor-agnostic representation of a conversation thread."""
|
||||
|
||||
thread_id: str
|
||||
title: str
|
||||
channel_id: str
|
||||
platform: str
|
||||
created_at: str = field(
|
||||
default_factory=lambda: datetime.now(timezone.utc).isoformat()
|
||||
)
|
||||
created_at: str = field(default_factory=lambda: datetime.now(timezone.utc).isoformat())
|
||||
archived: bool = False
|
||||
message_count: int = 0
|
||||
metadata: dict[str, Any] = field(default_factory=dict)
|
||||
@@ -61,6 +60,7 @@ class ChatThread:
|
||||
@dataclass
|
||||
class InviteInfo:
|
||||
"""Parsed invite extracted from an image or text."""
|
||||
|
||||
url: str
|
||||
code: str
|
||||
platform: str
|
||||
@@ -71,6 +71,7 @@ class InviteInfo:
|
||||
@dataclass
|
||||
class PlatformStatus:
|
||||
"""Current status of a chat platform connection."""
|
||||
|
||||
platform: str
|
||||
state: PlatformState
|
||||
token_set: bool
|
||||
|
||||
@@ -115,7 +115,9 @@ class InviteParser:
|
||||
"""Strategy 2: Use Ollama vision model for local OCR."""
|
||||
try:
|
||||
import base64
|
||||
|
||||
import httpx
|
||||
|
||||
from config import settings
|
||||
except ImportError:
|
||||
logger.debug("httpx not available for Ollama vision.")
|
||||
|
||||
15
src/integrations/chat_bridge/vendors/discord.py
vendored
15
src/integrations/chat_bridge/vendors/discord.py
vendored
@@ -90,10 +90,7 @@ class DiscordVendor(ChatPlatform):
|
||||
try:
|
||||
import discord
|
||||
except ImportError:
|
||||
logger.error(
|
||||
"discord.py is not installed. "
|
||||
'Run: pip install ".[discord]"'
|
||||
)
|
||||
logger.error("discord.py is not installed. " 'Run: pip install ".[discord]"')
|
||||
return False
|
||||
|
||||
try:
|
||||
@@ -267,6 +264,7 @@ class DiscordVendor(ChatPlatform):
|
||||
|
||||
try:
|
||||
from config import settings
|
||||
|
||||
return settings.discord_token or None
|
||||
except Exception:
|
||||
return None
|
||||
@@ -363,9 +361,7 @@ class DiscordVendor(ChatPlatform):
|
||||
# Show typing indicator while the agent processes
|
||||
async with target.typing():
|
||||
run = await asyncio.wait_for(
|
||||
asyncio.to_thread(
|
||||
agent.run, content, stream=False, session_id=session_id
|
||||
),
|
||||
asyncio.to_thread(agent.run, content, stream=False, session_id=session_id),
|
||||
timeout=300,
|
||||
)
|
||||
response = run.content if hasattr(run, "content") else str(run)
|
||||
@@ -374,7 +370,9 @@ class DiscordVendor(ChatPlatform):
|
||||
response = "Sorry, that took too long. Please try a simpler request."
|
||||
except Exception as exc:
|
||||
logger.error("Discord: agent.run() failed: %s", exc)
|
||||
response = "I'm having trouble reaching my language model right now. Please try again shortly."
|
||||
response = (
|
||||
"I'm having trouble reaching my language model right now. Please try again shortly."
|
||||
)
|
||||
|
||||
# Strip hallucinated tool-call JSON and chain-of-thought narration
|
||||
from timmy.session import _clean_response
|
||||
@@ -408,6 +406,7 @@ class DiscordVendor(ChatPlatform):
|
||||
|
||||
# Create a thread from this message
|
||||
from config import settings
|
||||
|
||||
thread_name = f"{settings.agent_name} | {message.author.display_name}"
|
||||
thread = await message.create_thread(
|
||||
name=thread_name[:100],
|
||||
|
||||
Reference in New Issue
Block a user