Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/claudesync/cli/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ def init(config, name, project):
click.echo(f"Failed to create chat conversation: {str(e)}")


def process_message_event(event):
"""Process a single streaming event from the message response."""
# Handle new API format (content_block_delta with text_delta)
if event.get("type") == "content_block_delta":
delta = event.get("delta", {})
if delta.get("type") == "text_delta":
click.echo(delta.get("text", ""), nl=False)
# Handle legacy format (for backward compatibility)
elif "completion" in event:
click.echo(event["completion"], nl=False)
elif "content" in event:
click.echo(event["content"], nl=False)
elif "error" in event:
click.echo(f"\nError: {event['error']}")
elif "message_limit" in event:
click.echo(f"\nRemaining messages: {event['message_limit']['remaining']}")


@chat.command()
@click.argument("message", nargs=-1, required=True)
@click.option("--chat", help="UUID of the chat to send the message to")
Expand Down Expand Up @@ -219,16 +237,7 @@ def message(config, message, chat, timezone, model):
for event in provider.send_message(
active_organization_id, chat, message, timezone, model
):
if "completion" in event:
click.echo(event["completion"], nl=False)
elif "content" in event:
click.echo(event["content"], nl=False)
elif "error" in event:
click.echo(f"\nError: {event['error']}")
elif "message_limit" in event:
click.echo(
f"\nRemaining messages: {event['message_limit']['remaining']}"
)
process_message_event(event)

click.echo() # Print a newline at the end of the response

Expand Down
1 change: 1 addition & 0 deletions src/claudesync/providers/base_claude_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def send_message(
data = {
"prompt": prompt,
"timezone": timezone,
"rendering_mode": "messages",
"attachments": [],
"files": [],
}
Expand Down