Text artifact preview renders garbled characters for non-ASCII (multibyte) content
- Dominant language
- TypeScript
- Stars
- 1k
- Forks
- 267
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 9
Description
## 🔴 Required Information
**Describe the Bug:**
When a tool saves a text artifact containing non-ASCII characters using
`Part.from_text()`, the preview in the Artifacts tab and inline chat bubble
renders garbled characters instead of the original text.
**Steps to Reproduce:**
Please provide a numbered list of steps to reproduce the behavior:
1. Create an agent with a tool that saves a text artifact:
```
async def save_text_file(filename: str, tool_context: ToolContext) -> str:
part = types.Part.from_text(text="こんにちは")
await tool_context.save_artifact("hello.txt", part)
return "Saved"
```
2. Run adk web and ask the agent to call the tool
3. Open the Artifacts tab in the right panel
4. Observe the text preview
**Expected Behavior:**
```
こんにちは
```
**Observed Behavior:**
```
ã?"ã‚"ã?«ã?¡ã?¯
```
UTF-8 bytes are misinterpreted as Latin-1 (ISO-8859-1).
**Environment Details:**
- ADK Library Version: 2.1.0
- Desktop OS: Windows
- Python Version: 3.12.10
**Model Information:**
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash
---
## 🟡 Optional Information
**Regression:**
N/A
**Logs:**
N/A
**Screenshots / Video:**
**Before (garbled):**
**After applying fix (`decodeURIComponent(escape(atob(base64)))`)**
**Additional Context:**
Root Cause:
`renderArtifact()` encodes text as `btoa(unescape(encodeURIComponent(text)))`,
but `getTextContent()` only calls `atob(base64)` without the reverse step.
Fix (2 occurrences in `artifact-tab.component.ts`):
Before:
```
return atob(base64);
```
After:
```
return decodeURIComponent(escape(atob(base64)));
```
**Minimal Reproduction Code:**
```
async def save_text_file(filename: str, tool_context: ToolContext) -> str:
part = types.Part.from_text(text="こんにちは")
await tool_context.save_artifact("hello.txt", part)
return "Saved"
```
**How often has this issue occurred?:**
- Always (100%)
Contributor guide
Assessment
This issue has not been assessed yet.