agents
agents copied to clipboard
Type-safe react stub streaming calls
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.