You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow destructuring output and errorText on ToolUIPart (#7140)
## Summary
This way you can accomplish the following use case, rendering a
component for a tool type safely:
```tsx
export function EditorToolPreview({
input,
state,
toolCallId,
output,
}: Extract<MyToolPart, { type: 'tool-str_replace_editor' }>) {
return <pre>{JSON.stringify(output, null, 2)}</pre>;
}
function ChatMessage({ message }: { message: MyUIMessage }) {
return (
<ChatAssistantMessage className="">
{message.parts.map((part: any, index: number) => {
if (part.type === 'text') {
return <Markdown key={index} markdown={part.text} />;
}
if (part.type === 'tool-str_replace_editor') {
return <EditorToolPreview key={index} {...part} />;
}
return null;
})}
</ChatAssistantMessage>
);
}
```
Without this PR you can't destructure output directly in the component
props because you would need to discriminate on `state` first:
```tsx
export function EditorToolPreview(
props: Extract<MyToolPart, { type: 'tool-str_replace_editor' }>,
) {
if (props.state === 'output-available') {
return <pre>{JSON.stringify(props.output, null, 2)}</pre>;
}
return null;
}
```
This means changing a lot of code to migrate to v5 to use props instead
of destructuring
0 commit comments