Skip to content

SSE routes have outputSchema: never in generated routes.ts, breaking useEventStream typing #855

@rblalock

Description

@rblalock

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

  1. 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;
  1. Run bun run build - this generates src/generated/routes.ts

  2. Check the generated SSERouteRegistry:

export interface SSERouteRegistry {
  '/api/search': {
    inputSchema: never;
    outputSchema: never;  // <-- This is the problem
    stream: false;
    params: never;
  };
}
  1. Try to use useEventStream in 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:

  1. 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) => {
  // ...
}));
  1. Option B: Accept a generic type parameter in useEventStream that 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions