useAISDKRuntime Error When Used Inside AssistantRuntimeProvider
Issue Description
When attempting to use useAISDKRuntime within the AssistantRuntimeProvider context, it throws a "ThreadListItem is only available inside" error, incorrectly detecting that it's being called outside the provider.
Root Cause Analysis
The issue occurs within useAISDKRuntime due to the following chain:
useAISDKRuntimeinternally callsAISDKMessageConverter.useThreadMessages- This in turn calls
useAssistantApi() - However,
useAssistantApi()is only available withinAssistantProvider, causing an error when called outside this context - The error message states: "ThreadListItem is only available inside"
Current Implementation Pattern
Current Working Pattern
The implementation follows this structure:
- Runtime created outside provider:
useCustomChatRuntimeis called within theAssistantInnercomponent - Runtime injected into provider: The created runtime is passed as a prop to
AssistantRuntimeProvider
const MyApp = () => {
const runtime = useChatRuntime({ // Runtime created outside provider
api: "/api/chat",
});
return (
<AssistantRuntimeProvider runtime={runtime}> // Runtime injected
<Thread />
</AssistantRuntimeProvider>
);
};
Question for Maintainers
Is this design pattern aligned with the library's architecture philosophy?
It seems counterintuitive that useAISDKRuntime cannot be used within AssistantRuntimeProvider, despite the provider being designed to accept runtime instances.
- The runtime must be created outside the provider scope
useAISDKRuntimefails when used in what seems like the appropriate context- Developers are forced to use
useExternalStoreRuntimedirectly as a workaround
Are we misunderstanding the intended design pattern, or is this a limitation that could be addressed?
When implementing custom thread functionality (wanting to customize thread management implementation), the "ThreadListItem is only available inside" error occurs and it's detected as being called outside the provider, but I feel this aligns with the design philosophy. With useChatRuntime, you can't fully control thread management and message state, right?
I just tried putting two useChatRuntimes inside another via AssistantRuntimeProvider and had no issues. I would love to fix this issue but need to be able to reproduce it. The behavior you describe is not expected and should not happen
nevermind I was able to reproduce the error
thanks!