Skip to content

Commit b43e8d9

Browse files
fix(core): root re-export deprecated chat/ai type aliases
Upstream packages/chat/src/index.ts:8-27 re-exports toAiMessages plus eight deprecated AI type aliases (AiAssistantMessage, AiFilePart, AiImagePart, AiMessage, AiMessagePart, AiTextPart, AiUserMessage, ToAiMessagesOptions) from the package root for backwards compatibility, each marked @deprecated pointing at the chat/ai subpath. Ours re-exported only to_ai_messages, so chat_sdk.AiMessage et al. did not resolve. Add the eight deprecated root re-exports from chat_sdk.ai (the canonical home) to match upstream's deprecated-alias surface, and pin the behavior with a root re-export test. No new optional-dep cost: chat_sdk.ai is already imported at the root for to_ai_messages, and the aliased types are plain TypedDict/dataclass/Union with no ai/zod peer-dep imports.
1 parent 17aa41a commit b43e8d9

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

src/chat_sdk/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
"""Python port of Vercel Chat SDK."""
22

3-
from chat_sdk.ai import to_ai_messages
3+
# Re-exported from `chat_sdk.ai` for backwards compatibility.
4+
#
5+
# Prefer importing these from `chat_sdk.ai` in new code — that subpackage is the
6+
# home for every AI SDK helper (`to_ai_messages`, `create_chat_tools`, etc.).
7+
# The AI type aliases below are deprecated at the root and mirror upstream's
8+
# `packages/chat/src/index.ts` deprecated re-export surface (@deprecated → chat/ai).
9+
from chat_sdk.ai import (
10+
AiAssistantMessage,
11+
AiFilePart,
12+
AiImagePart,
13+
AiMessage,
14+
AiMessagePart,
15+
AiTextPart,
16+
AiUserMessage,
17+
ToAiMessagesOptions,
18+
to_ai_messages,
19+
)
420
from chat_sdk.cards import (
521
Actions,
622
ActionsElement,
@@ -235,6 +251,15 @@
235251
"post_postable_object",
236252
# AI
237253
"to_ai_messages",
254+
# AI type aliases — deprecated at the root; canonical home is chat_sdk.ai.
255+
"AiAssistantMessage",
256+
"AiFilePart",
257+
"AiImagePart",
258+
"AiMessage",
259+
"AiMessagePart",
260+
"AiTextPart",
261+
"AiUserMessage",
262+
"ToAiMessagesOptions",
238263
# Standalone reviver for workflow-safe deserialization
239264
"reviver",
240265
# Card builders (PascalCase primary — matches source TS SDK)

tests/test_root_reexports.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Root package re-export surface.
2+
3+
Upstream (`packages/chat/src/index.ts`) re-exports `toAiMessages` plus eight
4+
deprecated AI type aliases from the package root for backwards compatibility,
5+
each marked `@deprecated` and pointing at the canonical `chat/ai` subpath.
6+
7+
These tests pin the Python equivalent: `chat_sdk.AiMessage` (and friends)
8+
resolve at the root and are identical objects to their canonical
9+
`chat_sdk.ai` home, while `chat_sdk.ai` remains the preferred import.
10+
"""
11+
12+
from __future__ import annotations
13+
14+
import chat_sdk
15+
import chat_sdk.ai as chat_sdk_ai
16+
17+
# The exact set of deprecated AI type aliases re-exported from the root,
18+
# mirroring upstream index.ts:8-27.
19+
_DEPRECATED_AI_TYPE_ALIASES = (
20+
"AiAssistantMessage",
21+
"AiFilePart",
22+
"AiImagePart",
23+
"AiMessage",
24+
"AiMessagePart",
25+
"AiTextPart",
26+
"AiUserMessage",
27+
"ToAiMessagesOptions",
28+
)
29+
30+
31+
def test_deprecated_ai_type_aliases_resolve_at_root() -> None:
32+
for name in _DEPRECATED_AI_TYPE_ALIASES:
33+
assert hasattr(chat_sdk, name), f"chat_sdk.{name} should resolve at the root"
34+
35+
36+
def test_root_ai_aliases_are_the_canonical_objects() -> None:
37+
# The root re-export must be the same object as the canonical chat_sdk.ai
38+
# home — not a fresh shadow type — so isinstance / identity checks agree.
39+
for name in _DEPRECATED_AI_TYPE_ALIASES:
40+
assert getattr(chat_sdk, name) is getattr(chat_sdk_ai, name)
41+
42+
43+
def test_deprecated_ai_type_aliases_in_dunder_all() -> None:
44+
for name in _DEPRECATED_AI_TYPE_ALIASES:
45+
assert name in chat_sdk.__all__, f"{name} missing from chat_sdk.__all__"
46+
47+
48+
def test_to_ai_messages_still_re_exported_at_root() -> None:
49+
# The helper that the aliases accompany stays available and canonical.
50+
assert chat_sdk.to_ai_messages is chat_sdk_ai.to_ai_messages
51+
assert "to_ai_messages" in chat_sdk.__all__

0 commit comments

Comments
 (0)