this repo has no description
at contributing 50 lines 2.2 kB view raw
1"""Thread tool for adding posts to Bluesky threads atomically.""" 2from typing import Optional 3from pydantic import BaseModel, Field, validator 4 5 6class ReplyThreadPostArgs(BaseModel): 7 text: str = Field( 8 ..., 9 description="Text content for the post (max 300 characters)" 10 ) 11 lang: Optional[str] = Field( 12 default="en-US", 13 description="Language code for the post (e.g., 'en-US', 'es', 'ja', 'th'). Defaults to 'en-US'" 14 ) 15 16 @validator('text') 17 def validate_text_length(cls, v): 18 if len(v) > 300: 19 raise ValueError(f"Text exceeds 300 character limit (current: {len(v)} characters)") 20 return v 21 22 23def add_post_to_bluesky_reply_thread(text: str, lang: str = "en-US") -> str: 24 """ 25 Add a single post to the current Bluesky reply thread. This tool indicates to the handler 26 that it should add this post to the ongoing reply thread context when responding to a notification. 27 28 This is distinct from bluesky_reply which handles the complete reply process. Use this tool 29 when you want to build a reply thread incrementally, adding posts one at a time. 30 31 This is an atomic operation - each call adds exactly one post. The handler (bsky.py) 32 manages the thread state and ensures proper threading when multiple posts are queued. 33 34 Args: 35 text: Text content for the post (max 300 characters) 36 lang: Language code for the post (e.g., 'en-US', 'es', 'ja', 'th'). Defaults to 'en-US' 37 38 Returns: 39 Confirmation message that the post has been queued for the reply thread 40 41 Raises: 42 Exception: If text exceeds character limit. On failure, the post will be omitted 43 from the reply thread and the agent may try again with corrected text. 44 """ 45 # Validate input 46 if len(text) > 300: 47 raise Exception(f"Text exceeds 300 character limit (current: {len(text)} characters). This post will be omitted from the thread. You may try again with shorter text.") 48 49 # Return confirmation - the actual posting will be handled by bsky.py 50 return f"Post queued for reply thread: {text[:50]}{'...' if len(text) > 50 else ''} (Language: {lang})"