#http stream responses not receiving as it streams, instead collected it

21 messages · Page 1 of 1 (latest)

exotic steeple
#

I'm trying to make an AI GUI. When entered the prompt the app will submit into the backend and then the backend will provide a stream of responses. All goes well until I tried to build the app, where normal fetch doesn't work. Then, I switched to @tauri-apps/plugin-http, but it cannot watch stream responses? Like it received all of it at once and concating them with newlines and errors out my JSON.parse(). Is there a workaround of this?

I've found this: https://github.com/tauri-apps/tauri/discussions/6613

but I don't know how to receive the stream responses in realtime? I don't want to collect it at the end, I want to render it as it is streaming. Maybe it does that but I'm a bit unfamiliar with Rust, so how would the frontend look like using that?

GitHub

Like fetch https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader const response = await fetch(url); const reader = response.body.getReader(); while (true) { const { value, done ...

exotic steeple
rose robin
#

you can try the linked PR and see if that works.

exotic steeple
#

Okay. Thank you.

exotic steeple
#

Hi @rose robin the PR that was linked worked good when I implemented it that way, any reason why it had not been merged yet?

rose robin
#

no reaction to the review comments 🤷

rose robin
#

but thanks for testing it

exotic steeple
exotic steeple
#

what do you think?

so I will send to the IPC channel everytime fetch is called, since Response.body always contains a stream anyways in the native fetch API

rose robin
#

i can't really follow your description tbh but feel free to open a PR and we'll take a look.

exotic steeple
#

@rose robin how do I test the plugin-workspace?

#

I have made the changes into plugin-workspace but I don't know how to setup the testing

rose robin
#

in your main project you could change tauri-plugin-http in cargo.toml to point to your local clone like toml tauri-plugin-http = { path = "path/to/plugins-workspace/plugins/http" }
imo the easiest way to test the javascript changes is to simple copy the guest-js/index.ts file into your project but you could also run pnpm build in the plugins-workspace folder and then in your test project do something like pnpm install ../path/to/plugins/http/dist-js (was it dist-js?)

exotic steeple
#

okay thanks I will test this out first.

exotic steeple
#

Can you please review it? I haven't tested it extensively

exotic steeple
#

Hi sorry for the version change, can you review it? I reverted. @rose robin

#

Ah crap sorry, I haven't fixed the pnpm lock and Cargo.lock. I'll do it tomorrow since it's getting late.

rose robin
#

no problem, i did that in the web interface

#

i'll leave the review to amr since he designed that plugin