agents icon indicating copy to clipboard operation
agents copied to clipboard

Type-safe react stub streaming calls

Open ruifigueira opened this issue 5 months ago • 2 comments

Proposal to add type safety to streaming calls.

Usage:

class MyAgent extends Agent<typeof env, {}> {
  @callable({ streaming: true })
  performStream(response: StreamingResponse<number, string>, result: string): void {
    response.send(1);
    response.send(2);
    response.end(result);
  }
}

const { stub } = useAgent<MyAgent, {}>({ agent: "my-agent" });

stub.performStream({
  onChunk: (chunk) => console.log('streaming: ', chunk),
  onDone: (finalChunk) => console.log('done: ', finalChunk),
}, "hello");

I'm opening this as a draft as I'm not very happy with the current solution, first argument being a StreamOptions doesn't seem right.

I'll gladly accept suggestions on how to improve it.

ruifigueira avatar May 24 '25 23:05 ruifigueira