From ad864d113cb03fc50329d5e16e5ecdd0e477b138 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 29 May 2026 03:29:49 +0000 Subject: [PATCH 1/3] refactor(ai): convert chat_sdk.ai module to package for chat/ai subpath (vercel/chat#492) Mirror upstream PR vercel/chat#492 which split ai.ts into ai/messages.ts to make room for ai/tools.ts. Convert the chat_sdk.ai module into a package: - src/chat_sdk/ai/messages.py: to_ai_messages + supporting types, moved verbatim from the former ai.py (docstring path updated only). - src/chat_sdk/ai/__init__.py: re-export shim exposing every symbol the old module exported, so from chat_sdk.ai import to_ai_messages keeps working. - tests/test_ai.py renamed to tests/test_ai_messages.py (logic unchanged). No public import path changed. PR 1 of 3 (module move only); the tool factory (create_chat_tools) lands in PR 2. Design issue #109, tracking #98. https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj --- src/chat_sdk/ai/__init__.py | 35 +++++++++++++++++++++++ src/chat_sdk/{ai.py => ai/messages.py} | 2 +- tests/{test_ai.py => test_ai_messages.py} | 0 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/chat_sdk/ai/__init__.py rename src/chat_sdk/{ai.py => ai/messages.py} (99%) rename tests/{test_ai.py => test_ai_messages.py} (100%) diff --git a/src/chat_sdk/ai/__init__.py b/src/chat_sdk/ai/__init__.py new file mode 100644 index 00000000..41d1f758 --- /dev/null +++ b/src/chat_sdk/ai/__init__.py @@ -0,0 +1,35 @@ +"""AI SDK integration for the chat SDK. + +Python port of the ``chat/ai`` subpath. Mirrors the upstream structure where +``ai.ts`` was split into ``ai/messages.ts`` (and, in later PRs, ``ai/tools.ts``) +to make room for tool factories. + +Re-exports everything the former ``chat_sdk.ai`` module exposed so existing +imports such as ``from chat_sdk.ai import to_ai_messages`` keep working. +""" + +from __future__ import annotations + +from chat_sdk.ai.messages import ( + AiAssistantMessage, + AiFilePart, + AiImagePart, + AiMessage, + AiMessagePart, + AiTextPart, + AiUserMessage, + ToAiMessagesOptions, + to_ai_messages, +) + +__all__ = [ + "AiAssistantMessage", + "AiFilePart", + "AiImagePart", + "AiMessage", + "AiMessagePart", + "AiTextPart", + "AiUserMessage", + "ToAiMessagesOptions", + "to_ai_messages", +] diff --git a/src/chat_sdk/ai.py b/src/chat_sdk/ai/messages.py similarity index 99% rename from src/chat_sdk/ai.py rename to src/chat_sdk/ai/messages.py index 1fc2d500..13b27fc8 100644 --- a/src/chat_sdk/ai.py +++ b/src/chat_sdk/ai/messages.py @@ -1,6 +1,6 @@ """Convert chat Messages to AI SDK format. -Python port of ai.ts. +Python port of ``ai/messages.ts``. """ from __future__ import annotations diff --git a/tests/test_ai.py b/tests/test_ai_messages.py similarity index 100% rename from tests/test_ai.py rename to tests/test_ai_messages.py From a5ff616c7f8fe4366c8c68bfe8fd45dc906e4d1d Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 30 May 2026 00:01:17 +0000 Subject: [PATCH 2/3] fix(scripts): update AI test-fidelity mapping after module move (review) --- scripts/verify_test_fidelity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/verify_test_fidelity.py b/scripts/verify_test_fidelity.py index 63f8acc6..cf346c90 100644 --- a/scripts/verify_test_fidelity.py +++ b/scripts/verify_test_fidelity.py @@ -45,7 +45,7 @@ "packages/chat/src/markdown.test.ts": "tests/test_markdown_faithful.py", "packages/chat/src/streaming-markdown.test.ts": "tests/test_streaming_markdown.py", "packages/chat/src/serialization.test.ts": "tests/test_serialization.py", - "packages/chat/src/ai.test.ts": "tests/test_ai.py", + "packages/chat/src/ai/messages.test.ts": "tests/test_ai_messages.py", "packages/chat/src/from-full-stream.test.ts": "tests/test_from_full_stream.py", } From 85a84206c6c28d7ef50831f882d6ad6e89ec6c7f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 30 May 2026 00:15:16 +0000 Subject: [PATCH 3/3] fix(ai): unbreak strict fidelity check + re-export TEXT_MIME_PREFIXES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two CI / review follow-ups on PR #116: 1. Fidelity-mapping fix went too far in the previous commit. The script's parity pin is `chat@4.26.0` (see `lint.yml:63`), where the upstream AI test file is still the flat `packages/chat/src/ai.test.ts` — the move to `ai/messages.test.ts` happened in 4.29.0. Pointing the mapping at the 4.29-era path made `verify_test_fidelity.py --strict` fail with "upstream checkout missing — mapped TS file not found". Revert just the TS half of the mapping to `ai.test.ts`; keep the Python half at `tests/test_ai_messages.py` (the file this PR actually renamed). When the parity pin moves to 4.29.0 the TS path can advance too. Locally verified against a fresh `chat@4.26.0` clone: TOTAL: 564/564 matched (100%), 0 missing All TS tests have Python equivalents. 2. The package shim was missing `TEXT_MIME_PREFIXES` (flagged by Codex P2). The PR description promises to "re-export everything the former `chat_sdk.ai` module exposed" — add the constant to both the import block and `__all__` so the contract holds. https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj --- scripts/verify_test_fidelity.py | 2 +- src/chat_sdk/ai/__init__.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/verify_test_fidelity.py b/scripts/verify_test_fidelity.py index cf346c90..e559019f 100644 --- a/scripts/verify_test_fidelity.py +++ b/scripts/verify_test_fidelity.py @@ -45,7 +45,7 @@ "packages/chat/src/markdown.test.ts": "tests/test_markdown_faithful.py", "packages/chat/src/streaming-markdown.test.ts": "tests/test_streaming_markdown.py", "packages/chat/src/serialization.test.ts": "tests/test_serialization.py", - "packages/chat/src/ai/messages.test.ts": "tests/test_ai_messages.py", + "packages/chat/src/ai.test.ts": "tests/test_ai_messages.py", "packages/chat/src/from-full-stream.test.ts": "tests/test_from_full_stream.py", } diff --git a/src/chat_sdk/ai/__init__.py b/src/chat_sdk/ai/__init__.py index 41d1f758..d5a874dc 100644 --- a/src/chat_sdk/ai/__init__.py +++ b/src/chat_sdk/ai/__init__.py @@ -11,6 +11,7 @@ from __future__ import annotations from chat_sdk.ai.messages import ( + TEXT_MIME_PREFIXES, AiAssistantMessage, AiFilePart, AiImagePart, @@ -23,6 +24,7 @@ ) __all__ = [ + "TEXT_MIME_PREFIXES", "AiAssistantMessage", "AiFilePart", "AiImagePart",