baml
baml copied to clipboard
[bug] React hooks with streaming always return non-nullable types
Product
BAML
Describe the bug
From the docs:
But the React hooks are always returning the non-nullable types.
Reproduction Steps
Given the following BAML:
class MessageTest {
// MessageTest won't stream until type is known
type "error" | "success" | "info" @stream.not_null
// MessageTest will only stream when title is known
title string @stream.done @stream.not_null
// Timestamp will only appear when fully complete, until then it will be null
timestamp string @stream.done
// will stream token by token, and include completion state
content string @stream.with_state
// will stream token by token
other string
}
function GetMessageTest(input: string) -> MessageTest {
client CustomGPT5
prompt #"
"#
}
It generates two types:
// types.ts
export interface MessageTest {
type: "error" | "success" | "info"
title: string
timestamp: string
content: string
other: string
}
// partial_types.ts
interface MessageTest {
type: "error" | "success" | "info"
title: string
timestamp?: string | null
content?: StreamState<string | null>
other?: string | null
}
Then the hook's return type is:
// const data: {
// type: "error" | "success" | "info";
// title: string;
// timestamp: string;
// content: string;
// other: string;
// } | undefined
// const data: MessageTest | undefined
const { data } = useGetMessageTest({ stream: true });
Shouldn't it be partial_types.MessageTest? Because it is actually returning null in the nullable fields, which is causing Cannot access property on ... bugs.
BAML Version
0.211.2
Language/Framework
React
LLM Provider
None
LLM Model
No response
Operating System
macOS
Browser
Firefox
Code Editor
VS Code
Thanks for the report! I believe you're right that the data field of the hook should contain the partial type in your case, and we'll look into that.
In the meantime, you can work around the issue by using the streamData field (of the same hook) - does that work as expected for you?