-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Summary
When using sse() middleware for Server-Sent Events routes, the generated src/generated/routes.ts file sets outputSchema: never for SSE routes in the SSERouteRegistry. This causes useEventStream from @agentuity/react to return data typed as never, requiring manual casting.
Reproduction Steps
- Create an SSE route in
src/api/index.ts:
import { createRouter, sse } from '@agentuity/runtime';
const api = createRouter();
api.get('/search', sse(async (c, stream) => {
await stream.writeSSE({
data: JSON.stringify({ type: 'token', content: 'hello' }),
});
stream.close();
}));
export default api;-
Run
bun run build- this generatessrc/generated/routes.ts -
Check the generated
SSERouteRegistry:
export interface SSERouteRegistry {
'/api/search': {
inputSchema: never;
outputSchema: never; // <-- This is the problem
stream: false;
params: never;
};
}- Try to use
useEventStreamin React:
import { useEventStream } from '@agentuity/react';
interface StreamMessage {
type: 'token' | 'complete';
content?: string;
}
function MyComponent() {
const { data, isConnected } = useEventStream('/api/search');
// ERROR: data is typed as `never`
// Cannot access data.type, data.content, etc.
console.log(data.type); // TS error: Property 'type' does not exist on type 'never'
}Current Workaround
Cast the data manually:
const { data: rawData } = useEventStream('/api/search');
const data = rawData as StreamMessage | undefined;Expected Behavior
SSE routes should support typed output schemas, either:
- Option A: Allow defining output type in the route that flows to the registry:
api.get('/search', sse<{ type: string; content?: string }>(async (c, stream) => {
// ...
}));- Option B: Accept a generic type parameter in
useEventStreamthat overrides the registry type:
const { data } = useEventStream<StreamMessage>('/api/search');Environment
@agentuity/runtime: latest@agentuity/react: latest@agentuity/cli: latest
Additional Context
This is particularly important for LLM token streaming use cases where the frontend needs to accumulate typed messages (status updates, tokens, completion signals) from the SSE stream.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels