fix(playground): handle legacy string message content
Summary
- Playgrounds saved before the AI SDK v5 migration store message
contentas a plain string, buttransformFromLegacyassumed an array and called.mapon it. - Opening any such playground crashed with
message.content.map is not a function. - Fix: normalize non-array (legacy string / nullish)
contentinto a singletextpart before mapping, so the editor and the v4→v5 part upgrade always see an array.
Fixes #1905
Verification
$ npx tsx --test tests/playground-transform-legacy.test.ts
# tests 3
# pass 3
# fail 0
- New regression test covers legacy string content, preserved array content (v4 tool-call/tool-result upgrade), and nullish content.
tsc --noEmitclean on changed files.
[!NOTE]
Low Risk
Localized playground load-path fix with regression tests; no auth, persistence, or API contract changes.
Overview
Fixes a crash when opening playgrounds saved before the AI SDK v5 migration, where message content was stored as a plain string (or null) instead of a parts array. transformFromLegacy called .map on that value and threw message.content.map is not a function.
The change introduces toContentParts, which leaves array content unchanged and wraps non-array values in a single { type: "text", text: ... } part (empty string for null/undefined). transformFromLegacy runs that normalization before the existing v4→v5 part upgrade logic.
Adds playground-transform-legacy.test.ts covering legacy string content, array + tool-call/result upgrade, and nullish content.
Reviewed by Cursor Bugbot for commit c7c99ccda94bdaf7accfc9d3c208264b000ea5fe. Bugbot is set up for automated code reviews on this repo. Configure here.