Skip to content

Commit 1c75671

Browse files
fix: GitHub raw dict helper + PostableObject history cache
- Extract _build_raw_message() in GitHub adapter (was duplicated between post_message and edit_message) - PostableObject posts now cached in message history for both Thread and Channel, so Plan objects appear in messages()/all_messages() like regular posts. Uses fallback text as the cached message content. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 59cfb47 commit 1c75671

3 files changed

Lines changed: 35 additions & 30 deletions

File tree

src/chat_sdk/adapters/github/adapter.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -476,24 +476,10 @@ async def post_message(self, thread_id: str, message: AdapterPostableMessage) ->
476476
{"body": body},
477477
)
478478

479-
raw: dict[str, Any] = {
480-
"type": "review_comment" if decoded.review_comment_id else "issue_comment",
481-
"comment": comment,
482-
"repository": {
483-
"id": 0,
484-
"name": decoded.repo,
485-
"full_name": f"{decoded.owner}/{decoded.repo}",
486-
"owner": {"id": 0, "login": decoded.owner, "type": "User"},
487-
},
488-
"pr_number": decoded.pr_number,
489-
}
490-
if not decoded.review_comment_id:
491-
raw["thread_type"] = decoded.type or "pr"
492-
493479
return RawMessage(
494480
id=str(comment["id"]),
495481
thread_id=thread_id,
496-
raw=raw,
482+
raw=self._build_raw_message(decoded, comment),
497483
)
498484

499485
async def edit_message(self, thread_id: str, message_id: str, message: AdapterPostableMessage) -> RawMessage:
@@ -518,24 +504,10 @@ async def edit_message(self, thread_id: str, message_id: str, message: AdapterPo
518504
{"body": body},
519505
)
520506

521-
raw: dict[str, Any] = {
522-
"type": "review_comment" if decoded.review_comment_id else "issue_comment",
523-
"comment": comment,
524-
"repository": {
525-
"id": 0,
526-
"name": decoded.repo,
527-
"full_name": f"{decoded.owner}/{decoded.repo}",
528-
"owner": {"id": 0, "login": decoded.owner, "type": "User"},
529-
},
530-
"pr_number": decoded.pr_number,
531-
}
532-
if not decoded.review_comment_id:
533-
raw["thread_type"] = decoded.type or "pr"
534-
535507
return RawMessage(
536508
id=str(comment["id"]),
537509
thread_id=thread_id,
538-
raw=raw,
510+
raw=self._build_raw_message(decoded, comment),
539511
)
540512

541513
async def stream(
@@ -553,6 +525,24 @@ async def stream(
553525
text += chunk.text
554526
return await self.post_message(thread_id, {"markdown": text})
555527

528+
@staticmethod
529+
def _build_raw_message(decoded: Any, comment: dict[str, Any]) -> dict[str, Any]:
530+
"""Build the raw message dict for post/edit responses."""
531+
raw: dict[str, Any] = {
532+
"type": "review_comment" if decoded.review_comment_id else "issue_comment",
533+
"comment": comment,
534+
"repository": {
535+
"id": 0,
536+
"name": decoded.repo,
537+
"full_name": f"{decoded.owner}/{decoded.repo}",
538+
"owner": {"id": 0, "login": decoded.owner, "type": "User"},
539+
},
540+
"pr_number": decoded.pr_number,
541+
}
542+
if not decoded.review_comment_id:
543+
raw["thread_type"] = decoded.type or "pr"
544+
return raw
545+
556546
async def delete_message(self, thread_id: str, message_id: str) -> None:
557547
"""Delete a message."""
558548
decoded = self.decode_thread_id(thread_id)

src/chat_sdk/channel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ async def post(
284284
"""
285285
if is_postable_object(message):
286286
await self._handle_postable_object(message)
287+
# Cache fallback text in history so the plan appears in channel.messages()
288+
if self._message_history is not None:
289+
fallback_text = message.get_fallback_text() if hasattr(message, "get_fallback_text") else ""
290+
fallback_msg = _to_message(
291+
self._create_sent_message("postable-obj", PostableMarkdown(markdown=fallback_text))
292+
)
293+
await self._message_history.append(self._id, fallback_msg)
287294
return message
288295

289296
if _is_async_iterable(message):

src/chat_sdk/thread.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ async def post(
443443
# Handle PostableObject (e.g. Plan)
444444
if is_postable_object(message):
445445
await self._handle_postable_object(message)
446+
# Cache the fallback text in message history so the plan appears
447+
# in thread.messages() / all_messages() like regular posts.
448+
if self._message_history is not None:
449+
fallback_text = message.get_fallback_text() if hasattr(message, "get_fallback_text") else ""
450+
fallback_msg = _to_message(
451+
self._create_sent_message("postable-obj", PostableMarkdown(markdown=fallback_text), self._id)
452+
)
453+
await self._message_history.append(self._id, fallback_msg)
446454
return message
447455

448456
# Handle AsyncIterable (streaming)

0 commit comments

Comments
 (0)