diff --git a/crates/ide-host/src/plugins/api.rs b/crates/ide-host/src/plugins/api.rs index 37906fa5c..791f285e9 100644 --- a/crates/ide-host/src/plugins/api.rs +++ b/crates/ide-host/src/plugins/api.rs @@ -9,8 +9,9 @@ use ide_extension::Package; use ide_extension::ledger::{Ledger, Subject}; use ide_language::ProgramPin; use ide_plugin::{ - CommitChange, CommitDraft, EventKind, HostApi, HostError, HttpRequest, HttpResponse, NotificationLevel, - ProcessChunk, ProcessCommand, ProcessOptions, ProcessOutput, Prompt, RepositoryStatus, SettingsTarget, StatusItem, + CommitChange, CommitDraft, EventKind, HostApi, HostError, HttpRequest, HttpResponse, HttpStreamHead, + NotificationLevel, ProcessChunk, ProcessCommand, ProcessOptions, ProcessOutput, Prompt, RepositoryStatus, + SettingsTarget, StatusItem, }; use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet, HashMap}; @@ -327,6 +328,14 @@ fn network_error(error: reqwest::Error) -> HostError { HostError::Failed(ide_http::client::describe(&error)) } +fn response_headers(response: &reqwest::Response) -> Vec<(String, String)> { + response + .headers() + .iter() + .map(|(k, v)| (k.as_str().to_owned(), String::from_utf8_lossy(v.as_bytes()).into_owned())) + .collect() +} + fn redirect_capability(from: &reqwest::Url, to: &reqwest::Url) -> Result { if from.scheme() == "https" && to.scheme() == "http" { ide_plugin::net_host(to.as_str()).map(Capability::NetHttp) @@ -737,6 +746,7 @@ pub(super) struct Shared { processes: Mutex>>, next_process: AtomicU64, connections: super::ipc::Connections, + http_streams: super::http_stream::HttpStreams, pub loopbacks: RwLock>, process_shutdowns: Mutex>>, pub(super) prompts: Mutex>, @@ -850,6 +860,7 @@ impl Shared { processes: Mutex::default(), next_process: AtomicU64::new(1), connections: super::ipc::Connections::default(), + http_streams: super::http_stream::HttpStreams::default(), loopbacks: RwLock::new(Arc::new(super::auth::Loopbacks::default())), process_shutdowns: Mutex::default(), prompts: Mutex::default(), @@ -1078,6 +1089,7 @@ impl Shared { self.kill_processes(plugin); self.connections.clear(plugin); + self.http_streams.clear(plugin); self.websockets.disconnect_plugin(plugin); self.setting_snapshots.lock().retain(|(_, p), _| p != plugin); let channels: Vec<_> = { @@ -1365,6 +1377,47 @@ impl PluginApi { self.approved_program_in_project(program, None) } + /// `request` with its secrets filled in and a redirect policy that checks + /// every hop against its grants; the caller sets the timeout. + fn http_request(&self, request: HttpRequest) -> Result { + let secrets = self.shared.secrets.read().clone(); + let id = self.id().to_owned(); + let mut headers = reqwest::header::HeaderMap::new(); + for (name, value) in &request.headers { + let value = fill_secrets(value, |n| secrets.get(&id, n))?; + let name = reqwest::header::HeaderName::from_bytes(name.as_bytes()) + .map_err(|e| HostError::Invalid(format!("header {name:?}: {e}")))?; + let mut value = reqwest::header::HeaderValue::from_str(&value) + .map_err(|e| HostError::Invalid(format!("header {name}: {e}")))?; + value.set_sensitive(true); + headers.append(name, value); + } + let method = reqwest::Method::from_bytes(request.method.to_ascii_uppercase().as_bytes()) + .map_err(|_| HostError::Invalid(format!("method {:?}", request.method)))?; + let grants = request.grants.clone(); + let policy = reqwest::redirect::Policy::custom(move |attempt| { + if attempt.previous().len() >= 10 { + return attempt.error("too many redirects"); + } + let wanted = attempt.previous().last().map_or_else( + || ide_plugin::net_capability(attempt.url().as_str()), + |from| redirect_capability(from, attempt.url()), + ); + match wanted { + Ok(wanted) if grants.iter().any(|g| g.covers(&wanted)) => attempt.follow(), + Ok(wanted) => attempt.error(RedirectDenied(wanted.to_string())), + Err(error) => attempt.error(error), + } + }); + let client = ide_http::client::build_with_redirect(&ide_core::proxy_settings::proxy(), policy) + .map_err(|e| HostError::Failed(e.message))?; + let builder = client.request(method, &request.url).headers(headers); + Ok(match request.body { + Some(body) => builder.body(body), + None => builder, + }) + } + pub(super) fn approved_program_in_project(&self, program: &str, root: Option<&Path>) -> Result { if let Some(pin) = root.and_then(|root| { self.shared.project_pins.read().get(&(self.id().into(), format!("process:{program}"), root.into())).cloned() @@ -2838,52 +2891,14 @@ impl HostApi for PluginApi { } fn fetch(&self, request: HttpRequest, cancel: &CancellationToken) -> Result { - let secrets = self.shared.secrets.read().clone(); - let id = self.id().to_owned(); - let mut headers = reqwest::header::HeaderMap::new(); - for (name, value) in &request.headers { - let value = fill_secrets(value, |n| secrets.get(&id, n))?; - let name = reqwest::header::HeaderName::from_bytes(name.as_bytes()) - .map_err(|e| HostError::Invalid(format!("header {name:?}: {e}")))?; - let mut value = reqwest::header::HeaderValue::from_str(&value) - .map_err(|e| HostError::Invalid(format!("header {name}: {e}")))?; - value.set_sensitive(true); - headers.append(name, value); - } - let method = reqwest::Method::from_bytes(request.method.to_ascii_uppercase().as_bytes()) - .map_err(|_| HostError::Invalid(format!("method {:?}", request.method)))?; - let grants = request.grants.clone(); - let policy = reqwest::redirect::Policy::custom(move |attempt| { - if attempt.previous().len() >= 10 { - return attempt.error("too many redirects"); - } - let wanted = attempt.previous().last().map_or_else( - || ide_plugin::net_capability(attempt.url().as_str()), - |from| redirect_capability(from, attempt.url()), - ); - match wanted { - Ok(wanted) if grants.iter().any(|g| g.covers(&wanted)) => attempt.follow(), - Ok(wanted) => attempt.error(RedirectDenied(wanted.to_string())), - Err(error) => attempt.error(error), - } - }); - let client = ide_http::client::build_with_redirect(&ide_core::proxy_settings::proxy(), policy) - .map_err(|e| HostError::Failed(e.message))?; - let builder = client.request(method, &request.url).headers(headers).timeout(request.timeout); - let builder = match request.body { - Some(body) => builder.body(body), - None => builder, - }; + let timeout = request.timeout; + let builder = self.http_request(request)?.timeout(timeout); let cancel = cancel.clone(); net_runtime().block_on(async move { let send = async { let response = builder.send().await.map_err(network_error)?; let status = response.status().as_u16(); - let headers = response - .headers() - .iter() - .map(|(k, v)| (k.as_str().to_owned(), String::from_utf8_lossy(v.as_bytes()).into_owned())) - .collect(); + let headers = response_headers(&response); let mut body = Vec::new(); let mut response = response; while let Some(chunk) = response.chunk().await.map_err(|e| HostError::Failed(e.to_string()))? { @@ -2901,6 +2916,40 @@ impl HostApi for PluginApi { }) } + fn fetch_stream(&self, request: HttpRequest, cancel: &CancellationToken) -> Result { + self.shared.http_streams.check(self.id())?; + // Only the wait for the headers is bounded: the body may keep coming. + let timeout = request.timeout; + let builder = self.http_request(request)?; + let cancel = cancel.clone(); + let response = net_runtime().block_on(async move { + tokio::select! { + r = tokio::time::timeout(timeout, builder.send()) => r + .map_err(|_| HostError::Failed("timed out waiting for the response headers".into()))? + .map_err(network_error), + () = cancel.cancelled() => Err(HostError::Cancelled), + } + })?; + let status = response.status().as_u16(); + let headers = response_headers(&response); + let id = self.shared.http_streams.insert(self.id(), response)?; + Ok(HttpStreamHead { id, status, headers }) + } + + fn http_stream_read( + &self, + id: u64, + max: usize, + timeout: Duration, + cancel: &CancellationToken, + ) -> Result<(Vec, bool), HostError> { + self.shared.http_streams.read(self.id(), id, max, timeout, cancel) + } + + fn http_stream_close(&self, id: u64) { + self.shared.http_streams.close(self.id(), id); + } + fn websocket_connect( &self, root: &Path, diff --git a/crates/ide-host/src/plugins/http_stream.rs b/crates/ide-host/src/plugins/http_stream.rs new file mode 100644 index 000000000..a310e2fd5 --- /dev/null +++ b/crates/ide-host/src/plugins/http_stream.rs @@ -0,0 +1,112 @@ +//! Plugin-owned HTTP response bodies read as they arrive (`net.fetch-stream`), +//! closed on resource drop and plugin shutdown. +use super::api::net_runtime; +use ide_core::CancellationToken; +use ide_plugin::HostError; +use parking_lot::Mutex; +use std::collections::HashMap; +use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::time::Duration; + +/// Most response streams one plugin keeps open at once. +const MAX_STREAMS: usize = 8; + +struct Body { + response: reqwest::Response, + /// The part of the last chunk the plugin hasn't read yet. + pending: Vec, + done: bool, +} + +struct Stream { + body: tokio::sync::Mutex, + closed: CancellationToken, +} + +#[derive(Default)] +pub(super) struct HttpStreams { + next: AtomicU64, + entries: Mutex>>, +} + +impl HttpStreams { + /// Fails when `plugin` already has the most streams open. + pub fn check(&self, plugin: &str) -> Result<(), HostError> { + if self.entries.lock().keys().filter(|(p, _)| p == plugin).count() >= MAX_STREAMS { + Err(HostError::Invalid("at most eight response streams per plugin".into())) + } else { + Ok(()) + } + } + + pub fn insert(&self, plugin: &str, response: reqwest::Response) -> Result { + let mut entries = self.entries.lock(); + if entries.keys().filter(|(p, _)| p == plugin).count() >= MAX_STREAMS { + return Err(HostError::Invalid("at most eight response streams per plugin".into())); + } + let id = self.next.fetch_add(1, Ordering::Relaxed); + let body = Body { response, pending: Vec::new(), done: false }; + entries.insert( + (plugin.into(), id), + Arc::new(Stream { body: tokio::sync::Mutex::new(body), closed: CancellationToken::new() }), + ); + Ok(id) + } + + pub fn read( + &self, + plugin: &str, + id: u64, + max: usize, + timeout: Duration, + cancel: &CancellationToken, + ) -> Result<(Vec, bool), HostError> { + let entry = self + .entries + .lock() + .get(&(plugin.into(), id)) + .cloned() + .ok_or_else(|| HostError::NotFound("response stream".into()))?; + net_runtime().block_on(async { + let read = async { + let mut body = entry.body.lock().await; + // `chunk` takes nothing until it is ready, so a timeout that drops + // this future in the middle loses no bytes. + if body.pending.is_empty() && !body.done { + match body.response.chunk().await { + Ok(Some(chunk)) => body.pending = chunk.to_vec(), + Ok(None) => body.done = true, + Err(e) => return Err(HostError::Failed(ide_http::client::describe(&e))), + } + } + let count = body.pending.len().min(max); + let bytes: Vec = body.pending.drain(..count).collect(); + Ok((bytes, body.done && body.pending.is_empty())) + }; + tokio::select! { + biased; + () = cancel.cancelled() => Err(HostError::Cancelled), + () = entry.closed.cancelled() => Err(HostError::Cancelled), + r = read => r, + () = tokio::time::sleep(timeout) => Ok((Vec::new(), false)), + } + }) + } + + pub fn close(&self, plugin: &str, id: u64) { + if let Some(entry) = self.entries.lock().remove(&(plugin.into(), id)) { + entry.closed.cancel(); + } + } + + pub fn clear(&self, plugin: &str) { + self.entries.lock().retain(|(p, _), entry| { + if p != plugin { + return true; + } + entry.closed.cancel(); + false + }); + } +} diff --git a/crates/ide-host/src/plugins/mod.rs b/crates/ide-host/src/plugins/mod.rs index 7c9a981fe..3b32ca3ca 100644 --- a/crates/ide-host/src/plugins/mod.rs +++ b/crates/ide-host/src/plugins/mod.rs @@ -31,6 +31,7 @@ mod execution; mod external_watch; mod files_changed; mod hover; +mod http_stream; mod icon_extensions; mod icon_patterns; mod icon_settings; diff --git a/crates/ide-host/tests/plugins.rs b/crates/ide-host/tests/plugins.rs index 98b454ded..620854a29 100644 --- a/crates/ide-host/tests/plugins.rs +++ b/crates/ide-host/tests/plugins.rs @@ -6545,6 +6545,58 @@ fn api14_denies_new_privileges_and_requires_an_invoking_window() { assert_eq!(f.host.declared_secret("api14", "token"), None); } +/// `net.fetch-stream`: the body is read as it arrives, so a plugin gets the +/// first server-sent event while the server is still sending (here it never +/// finishes), and a short body ends with `done`. The same grants as `fetch`. +#[test] +fn fetch_stream_reads_events_before_the_body_ends() { + use std::io::{BufRead, BufReader, Write}; + let f = fixture(Limits::default()); + f.host.install_from_dir(&sample("api14"), &Consent::default()).unwrap(); + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let port = listener.local_addr().unwrap().port(); + std::thread::spawn(move || { + for (n, stream) in listener.incoming().flatten().enumerate() { + std::thread::spawn(move || { + let mut reader = BufReader::new(stream.try_clone().unwrap()); + let mut line = String::new(); + while reader.read_line(&mut line).unwrap_or(0) > 0 && line != "\r\n" { + line.clear(); + } + let mut stream = stream; + let chunk = |stream: &mut std::net::TcpStream, s: &str| { + write!(stream, "{:x}\r\n{s}\r\n", s.len()).and_then(|()| stream.flush()) + }; + let _ = write!( + stream, + "HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nTransfer-Encoding: chunked\r\n\r\n" + ); + let _ = chunk(&mut stream, "data: one\n\nevent: delta\ndata: t"); + if n == 0 { + // Never ends: only streaming lets the plugin see "one" in time. + std::thread::sleep(Duration::from_secs(30)); + return; + } + let _ = chunk(&mut stream, "wo\n\n"); + let _ = write!(stream, "0\r\n\r\n"); + }); + } + }); + let url = format!("http://localhost:{port}/events"); + + let err = f.run("api14", "fetch-stream", Some(&format!("1 {url}"))).unwrap_err(); + assert!(err.contains("net:localhost") && err.contains("not granted"), "{err}"); + f.host.set_capability("api14", "net:localhost", true).unwrap(); + + let started = std::time::Instant::now(); + let out = f.run("api14", "fetch-stream", Some(&format!("1 {url}"))).unwrap(); + assert_eq!(out.as_deref(), Some("200|message:one")); + assert!(started.elapsed() < Duration::from_secs(10), "{:?}", started.elapsed()); + + let out = f.run("api14", "fetch-stream", Some(&format!("3 {url}"))).unwrap(); + assert_eq!(out.as_deref(), Some("200|message:one|delta:two|done")); +} + /// `net:ask`: a first request to a host outside the manifest asks the user /// from an invoking window ("once" allows this request, "always" remembers /// the host, refusal and dismissal deny). Background calls are denied without diff --git a/crates/ide-plugin/src/runtime.rs b/crates/ide-plugin/src/runtime.rs index ab3fc21ac..c1c41e75a 100644 --- a/crates/ide-plugin/src/runtime.rs +++ b/crates/ide-plugin/src/runtime.rs @@ -8,9 +8,9 @@ use crate::types::{ PluginHover, PluginInlayHint, ProviderDocument, SemanticToken, }; use crate::types::{ - EventKind, HostError, HttpRequest, HttpResponse, Invocation, Limits, NotificationLevel, ProcessChunk, - ProcessCommand, ProcessOutput, Prompt, RepositoryStatus, StatusItem, SyntaxFold, SyntaxSymbol, SyntaxToken, - WorkbenchEvent, + EventKind, HostError, HttpRequest, HttpResponse, HttpStreamHead, Invocation, Limits, NotificationLevel, + ProcessChunk, ProcessCommand, ProcessOutput, Prompt, RepositoryStatus, StatusItem, SyntaxFold, SyntaxSymbol, + SyntaxToken, WorkbenchEvent, }; use crate::types::{ FieldValue, ServiceLog, ServiceLogToggle, ServicePane, ServiceTab, TableSort, View, ViewBody, ViewButton, @@ -365,6 +365,20 @@ pub trait HostApi: Send + Sync { fn publish_diagnostics(&self, path: &Path, items: Vec) -> Result<(), HostError>; /// Performs `request` (its host is granted), filling in secret placeholders. fn fetch(&self, request: HttpRequest, cancel: &CancellationToken) -> Result; + /// As [`HostApi::fetch`], returning once the headers arrive (`request.timeout` + /// bounds only that wait); the body is read with [`HostApi::http_stream_read`]. + fn fetch_stream(&self, request: HttpRequest, cancel: &CancellationToken) -> Result; + /// The next body bytes of an owned stream, at most `max`: empty and not done + /// when nothing arrived within `timeout`; `true` once the body has ended. + fn http_stream_read( + &self, + id: u64, + max: usize, + timeout: Duration, + cancel: &CancellationToken, + ) -> Result<(Vec, bool), HostError>; + /// Closes an owned stream, including when its resource is dropped. + fn http_stream_close(&self, id: u64); fn websocket_connect( &self, diff --git a/crates/ide-plugin/src/types.rs b/crates/ide-plugin/src/types.rs index c3101c4b2..0a70f2775 100644 --- a/crates/ide-plugin/src/types.rs +++ b/crates/ide-plugin/src/types.rs @@ -574,6 +574,15 @@ pub struct HttpResponse { pub body: Vec, } +/// A response whose body is still arriving (WIT `net.response-stream`). +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct HttpStreamHead { + /// Owned by this plugin instance; read with [`crate::HostApi::http_stream_read`]. + pub id: u64, + pub status: u16, + pub headers: Vec<(String, String)>, +} + /// What a one-off process printed (WIT `process.output`). #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct ProcessOutput { diff --git a/crates/ide-plugin/src/wit_host.rs b/crates/ide-plugin/src/wit_host.rs index e33fb1981..1d7e47265 100644 --- a/crates/ide-plugin/src/wit_host.rs +++ b/crates/ide-plugin/src/wit_host.rs @@ -27,6 +27,7 @@ pub(crate) mod bindings { "openidea:plugin/process.child": super::ChildRes, "openidea:plugin/ipc.connection": super::ConnectionRes, "openidea:plugin/net.websocket": super::WebSocketRes, + "openidea:plugin/net.response-stream": super::ResponseStreamRes, "openidea:plugin/auth.loopback": super::LoopbackRes, }, }); @@ -263,6 +264,21 @@ impl Drop for WebSocketRes { } } +/// A response body still arriving, owned by this plugin instance. Releasing +/// the component resource closes the connection. +pub struct ResponseStreamRes { + id: u64, + status: u16, + headers: Vec<(String, String)>, + host: std::sync::Arc, +} + +impl Drop for ResponseStreamRes { + fn drop(&mut self) { + self.host.http_stream_close(self.id); + } +} + impl Drop for ChildRes { fn drop(&mut self) { self.host.release_process(self.id); @@ -1866,12 +1882,11 @@ impl diagnostics::Host for StoreData { } } -impl net::Host for StoreData { - fn fetch(&mut self, req: net::Request) -> Fallible { - let capability = match net_capability(&req.url) { - Ok(h) => h, - Err(e) => return Ok(Err(wit::Error::Invalid(e))), - }; +impl StoreData { + /// The host request for `req` once its grants (asking under `net:ask`), + /// secrets and body size are checked: shared by `fetch` and `fetch-stream`. + fn net_request(&mut self, req: net::Request) -> Result { + let capability = net_capability(&req.url).map_err(wit::Error::Invalid)?; let mut grants = self.granted.clone(); if let Err(e) = self.require(capability.clone()) { // `net:ask`: an HTTPS (or loopback) host the manifest does not list @@ -1880,35 +1895,38 @@ impl net::Host for StoreData { let askable = matches!(&capability, Capability::Net(_)) && self.granted.iter().any(|g| g.covers(&Capability::NetAsk)); let allowed = match &capability { - Capability::Net(host) if askable => match self.ask_net(host) { - Ok(Some(_)) => true, - Ok(None) => false, - // A cancelled or failed question is not a refusal. - Err(e) => return Ok(Err(e)), - }, + // A cancelled or failed question is not a refusal. + Capability::Net(host) if askable => self.ask_net(host)?.is_some(), _ => false, }; if !allowed { - return Ok(Err(e)); + return Err(e); } grants.push(capability.clone()); } - if req.headers.iter().any(|h| h.value.contains("{{secret:")) - && let Err(e) = self.require(Capability::Secrets) - { - return Ok(Err(e)); + if req.headers.iter().any(|h| h.value.contains("{{secret:")) { + self.require(Capability::Secrets)?; } if req.body.as_ref().is_some_and(|b| b.len() > MAX_REQUEST_BODY) { - return Ok(Err(wit::Error::Invalid("request body larger than 8 MiB".into()))); + return Err(wit::Error::Invalid("request body larger than 8 MiB".into())); } let wanted = Duration::from_millis(u64::from(req.timeout_ms.unwrap_or(30_000))); - let request = HttpRequest { + Ok(HttpRequest { method: req.method, url: req.url, headers: req.headers.into_iter().map(|h| (h.name, h.value)).collect(), body: req.body, timeout: wanted.min(self.io_timeout()), grants, + }) + } +} + +impl net::Host for StoreData { + fn fetch(&mut self, req: net::Request) -> Fallible { + let request = match self.net_request(req) { + Ok(request) => request, + Err(e) => return Ok(Err(e)), }; let token = self.cancel.token(); let outcome = self.host.fetch(request, &token); @@ -1924,6 +1942,28 @@ impl net::Host for StoreData { .map_err(to_wit)) } + fn fetch_stream(&mut self, req: net::Request) -> Fallible> { + let request = match self.net_request(req) { + Ok(request) => request, + Err(e) => return Ok(Err(e)), + }; + let token = self.cancel.token(); + match self.host.fetch_stream(request, &token) { + Ok(head) => self + .push(ResponseStreamRes { + id: head.id, + status: head.status, + headers: head.headers, + host: self.host.clone(), + }) + .map(Ok), + Err(e) => { + self.grant_io_error_grace(); + Ok(Err(to_wit(e))) + } + } + } + fn websocket_connect( &mut self, project: Resource, @@ -1989,6 +2029,43 @@ impl net::HostWebsocket for StoreData { } } +impl net::HostResponseStream for StoreData { + fn status(&mut self, this: Resource) -> wasmtime::Result { + Ok(self.table.get(&this)?.status) + } + + fn headers(&mut self, this: Resource) -> wasmtime::Result> { + let stream = self.table.get(&this)?; + Ok(stream + .headers + .iter() + .map(|(name, value)| net::Header { name: name.clone(), value: value.clone() }) + .collect()) + } + + fn read(&mut self, this: Resource, max_bytes: u32, timeout_ms: u32) -> Fallible { + let id = self.table.get(&this)?.id; + let timeout = Duration::from_millis(u64::from(timeout_ms)).min(self.io_timeout()); + let max = (max_bytes as usize).min(1 << 20); + let outcome = self.host.http_stream_read(id, max, timeout, &self.cancel.token()); + if outcome.is_err() { + self.grant_io_error_grace(); + } + Ok(outcome.map(|(bytes, done)| net::BodyChunk { bytes, done }).map_err(to_wit)) + } + + fn close(&mut self, this: Resource) -> wasmtime::Result<()> { + let id = self.table.get(&this)?.id; + self.host.http_stream_close(id); + Ok(()) + } + + fn drop(&mut self, this: Resource) -> wasmtime::Result<()> { + self.table.delete(this)?; + Ok(()) + } +} + impl secrets::Host for StoreData { fn set(&mut self, name: String, value: String) -> Fallible<()> { if let Err(e) = self.require(Capability::Secrets) { diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm index 18b1de65e..23d126ccc 100644 Binary files a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources index 811172aab..e54204d5b 100644 --- a/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/api14/dist/plugin.wasm.sources @@ -1 +1 @@ -1e6a4ba99409620e9bf3ceb51387704018737f186a89037b05bcbcee1e38a967 +8a08e92c30faaa683e531fd91c8a69392d75165cff62153e216008f7abbcb1ea diff --git a/crates/ide-plugin/tests/fixtures/api14/plugin.toml b/crates/ide-plugin/tests/fixtures/api14/plugin.toml index 57284485e..28a70d4d6 100644 --- a/crates/ide-plugin/tests/fixtures/api14/plugin.toml +++ b/crates/ide-plugin/tests/fixtures/api14/plugin.toml @@ -24,6 +24,10 @@ title = "ipc" id = "fetch" title = "fetch" +[[contributes.commands]] +id = "fetch-stream" +title = "fetch-stream" + [[contributes.commands]] id = "window-status" title = "window-status" diff --git a/crates/ide-plugin/tests/fixtures/api14/src/lib.rs b/crates/ide-plugin/tests/fixtures/api14/src/lib.rs index 2e0ff7114..fa5b63123 100644 --- a/crates/ide-plugin/tests/fixtures/api14/src/lib.rs +++ b/crates/ide-plugin/tests/fixtures/api14/src/lib.rs @@ -73,6 +73,21 @@ impl Plugin for Api14 { let response = host::fetch(&openidea_plugin::HttpRequest::get(arg))?; Ok(Some(String::from_utf8_lossy(&response.body).into())) } + "fetch-stream" => { + // ` `: the first `count` events, then the stream is dropped. + let (count, url) = arg.split_once(' ').unwrap_or(("1", arg)); + let stream = host::fetch_stream(&openidea_plugin::HttpRequest::get(url))?; + let mut out = vec![stream.status().to_string()]; + let mut events = stream.events(); + for _ in 0..count.parse::().unwrap_or(1) { + out.push(match events.next(5_000)? { + Some(event) => format!("{}:{}", event.event, event.data), + None if events.is_done() => "done".into(), + None => "timeout".into(), + }); + } + Ok(Some(out.join("|"))) + } "global-status" | "window-status" => { let item = StatusItem { text: arg.into(), tooltip: None, command: Some("events".into()) }; if id == "global-status" { diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm index 74281b99a..2e73c20e7 100644 Binary files a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources index c7696c4e8..bad256f05 100644 --- a/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/build-graph/dist/plugin.wasm.sources @@ -1 +1 @@ -667622767aa8c75a44c1348f6d07979ecb7a2db7ede9613999b61658a58557f5 +de08e41d78da65ee3de2c709112e8d8905b50432bd59af1701dd633f674fa121 diff --git a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm index 9228b6bc6..db32d8f77 100644 Binary files a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources index d1865ac94..39d9ae978 100644 --- a/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/clipboard/dist/plugin.wasm.sources @@ -1 +1 @@ -689a9f36b9d13e0b57bd1540321a06da65837510fd9a37225776abd8baccfd7c +455c833fc7d02c083a1ae67d1df507f29581f77d7f8624ff562f1ce982efc730 diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm index 95589b91a..2f3bc2f46 100644 Binary files a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources index 675178ea3..c6b1608bd 100644 --- a/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/commit/dist/plugin.wasm.sources @@ -1 +1 @@ -0316df8c6f5fd4523f077c1a12d2d8af9592729a66a5a99a155dde42bb331e96 +a891db4b18f175648ec47a6c1e20edde0ff266d38b37a1fd2acc8f95ddf0d5b4 diff --git a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm index a168be506..f4b9eb9af 100644 Binary files a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources index 55210d2d0..a74a8ac35 100644 --- a/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/completion-list/dist/plugin.wasm.sources @@ -1 +1 @@ -6732e125bfefcfad1c5712516e05bdaff7ceea4e71994de45109086e252e5f72 +30f99018d1c6e518fbc179b2090a7f65856e10b9bed4bb76e605d88acec86393 diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm index 7f777a779..435b95087 100644 Binary files a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources index d440b817b..7a7d77bd8 100644 --- a/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/data-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -bb6c942f198534adf96354dd670c175f73954782f516762c564d157f5004b744 +39e361f892aa0944bc3eac5a2a9f5a7133deced54ca28193f8d789eaccc1a326 diff --git a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm index 67e871f3c..38a8f4232 100644 Binary files a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources index 0ba70c5d6..34db3995f 100644 --- a/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/decorations/dist/plugin.wasm.sources @@ -1 +1 @@ -fa0957c9041bc31f7dc5b58aa912fa83851e6f0058d055e9582950195a1015b4 +f36cf494eb56ebb9d6459a0b84b854ce413eed79e563074bc850de3ee4a4bb2d diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm index d9d074aa4..8ffb5016d 100644 Binary files a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources index 762fa3411..8acea0b2f 100644 --- a/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/detail-views/dist/plugin.wasm.sources @@ -1 +1 @@ -00ac40b08a5a39d4e011e9391732f19c20eb439a6f980b8d96334a5547c28666 +ea314de1d7cdf468b69603bda1766c7361497c9a50fc3e43ab508592d1861fe7 diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm index 28aa6cf18..be292139f 100644 Binary files a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources index b9f0381a6..379feed1d 100644 --- a/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/diagnostics/dist/plugin.wasm.sources @@ -1 +1 @@ -82473da5332e96dc9ef3a82947cde59b0a5d6acd49f8baad7c4fcc46ed4284dc +218dbcd47abeb8ef4b06e13cbbfdd7e24790c11f27c352ce95cfbb6cba61a062 diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm index 0eadcd550..f30e6a92a 100644 Binary files a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources index 3e69301c3..c66abe571 100644 --- a/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/endpoints/dist/plugin.wasm.sources @@ -1 +1 @@ -8532a968b8522e9b1b6f0df3aed073191e2a441ab960f96af79d7132fda4090a +78bad0a6062a0131527a700e0b75ca24fd96162e8fe326b45b5a96c8da8723b4 diff --git a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm index 2a328bfbe..dafee9919 100644 Binary files a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources index 4c8371148..b45686b30 100644 --- a/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/execution-output/dist/plugin.wasm.sources @@ -1 +1 @@ -ee0f3be61a8684275dc15acfdfe374b6d1751078d15c92608ba39ccbc6e10c67 +f90db44c3df10b60fca9e337eba1d3269d8299ca06f5e60cbd9ab7dd65d32fba diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm index 47b3fb080..e35f02844 100644 Binary files a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources index 22092a49e..24263db43 100644 --- a/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/execution/dist/plugin.wasm.sources @@ -1 +1 @@ -4a3602e6024dcbeccb59ef9b324bab3e3254c908a7513c4f08bcbd212e368f9f +72aac6f440205694028e52df9932340131f6f30d89fbe3e9363a97110c912336 diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm index 26bf3a91c..6ce6a0536 100644 Binary files a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources index fedcc8da5..e7d970fd0 100644 --- a/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/ext-owner/dist/plugin.wasm.sources @@ -1 +1 @@ -bd6aa162f07d96a580a8891433fd042e08a976f0f3ce4aee7694957ad394057c +366172ef7c2d4d2d218d3a653763852983b0af21e7e79ee644c4c216b64b2665 diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm index f9c19f881..df5231a36 100644 Binary files a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources index 62b39eca8..5868d40ad 100644 --- a/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/file-templates/dist/plugin.wasm.sources @@ -1 +1 @@ -edac72326d401c873394ff0de9a659d5f3642259df136b87fb9b6cfe632e60c5 +3eac3cab007df8f12e89b044f02348f564a5ec53376743ffccaacc6df383fd37 diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm index 2a9ae988f..5acb3bc01 100644 Binary files a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources index d1e06bf1c..d4eee67e7 100644 --- a/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/files-events/dist/plugin.wasm.sources @@ -1 +1 @@ -7454788469a0c0662987a4a774d8fc59b20b0dfec9bbac754e8e4aa0a46a1b43 +3dab8c8f0177ab0de22a6daccc374c7aaa7e37f6959815edee5641d45bffa3ab diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm index 016415016..3d5858f7a 100644 Binary files a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources index 76aa82b59..21f4a105c 100644 --- a/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/grouped-views/dist/plugin.wasm.sources @@ -1 +1 @@ -268b18f9303602b00f5c0d7254967aeb95c377b5a85011ead539b4ccab5811e2 +834b90f241c89b7f24217f4ea579810de703da23806b7e21113df5a43ea20dbb diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm index 256455f4c..3336d50c3 100644 Binary files a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources index d5811972b..55e34f34e 100644 --- a/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hello/dist/plugin.wasm.sources @@ -1 +1 @@ -9e8809f276ef27561fe337f8268b3cf4f06be7ac1707a61e6e41407ec932bbb1 +dbff03557f56e4483e8770c1dcca455c78f4331265613a93475ee28a8c581d79 diff --git a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm index 7edde6f83..54162f64f 100644 Binary files a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources index 52fbbddf9..714a13a8a 100644 --- a/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hover-actions/dist/plugin.wasm.sources @@ -1 +1 @@ -c4594d365423395722e7f8e14f6d9c32ad4ff579b2eb42f5e2c5650e7cfa6bdc +e674c90857e859a6a7684f9d7899dbdf05f9fe5d310ed809def6bf5403877bda diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm index 4cf764325..575e4287c 100644 Binary files a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources index d4bf84492..da27628c2 100644 --- a/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/hover/dist/plugin.wasm.sources @@ -1 +1 @@ -91b267d3845bbd199662c0857ee23634a1d1b287204ce81fa148f1ce43eace3b +0e856198f5839dc675afcc883b43aa9c950c4f73807fe0b1145d976e00bbf2f4 diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm index 14a5b9aa5..45ba00d90 100644 Binary files a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources index b477854ae..c3839f137 100644 --- a/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/indexer/dist/plugin.wasm.sources @@ -1 +1 @@ -8e5c91ab272fa1678fbef9607f12513f7a589ef3fd293cfd7a52497cf637de3d +b693136d64688418665ef010b5cb83b86fc4b0adc052b7783530cc53d863085e diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm index e6e59cf14..f24235b92 100644 Binary files a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources index 041a41567..531e8ff29 100644 --- a/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/inlay-hints/dist/plugin.wasm.sources @@ -1 +1 @@ -a2e19194ba5f42e9d02d996c77444e8a5267fecc99bb02933f35aabb22fddadd +cb07913a6a7a1f61521818ffada5b59b8b30e08bc5ef3ed21a9d3a1924ac4445 diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm index dc090e355..3db9ab6a5 100644 Binary files a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources index 0be794602..280b6d490 100644 --- a/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/jobs/dist/plugin.wasm.sources @@ -1 +1 @@ -78a9be879f2a07417c26a0818d2896ba6d93ea60bed69f3ebaf963ea1842147b +47642c0e293829c19528d85d6058b0ea08d68d3380032c4e04937322c88178a2 diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm index 53884bd14..e1a338f81 100644 Binary files a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources index 311953313..6013fe74b 100644 --- a/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/language-features/dist/plugin.wasm.sources @@ -1 +1 @@ -2cc25b5de5003300b686ecc47a9f2379dcb61ed954c0b41db6b5945c865fffb7 +61cc8a30b6db4a50502b014e4849365cd25b86cc197305d570241186bb1bdbaf diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm index cd9fb8d3d..30fddae21 100644 Binary files a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources index 1e0ccade9..e6d068659 100644 --- a/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/lsp-requests/dist/plugin.wasm.sources @@ -1 +1 @@ -a1167c3620a2fd143d94cbb235139f7f428f5360dcab65730f5abf0c5944b061 +72c8ce5f05dd3425fad3e9d8928a06f79f258beaaabcde7f14d5c1c65d3c2d97 diff --git a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources index a7ca6341a..7388e4326 100644 --- a/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/misbehave/dist/plugin.wasm.sources @@ -1 +1 @@ -57062a5c91e85524e22d61ef7cdda9f5241f760ccb47b3fd7a53c7bbd86ce58a +667102db97617a5149e1a4fb1f81bb57a25cf0265cf08b37f76a976b42bd54a8 diff --git a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm index b10061b8f..fe346db6a 100644 Binary files a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources index cb7e02a9f..5c7045c18 100644 --- a/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/net-setting/dist/plugin.wasm.sources @@ -1 +1 @@ -4ede6078038216c3c81de9732c32d653669a06c55b3482f7640cae3a2eab6b8c +70b2bd11475b9cafb21ebe8cd2dfc888e442c9de0220d93c85fb3a25b45e96da diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm index 7b46dbd87..17fe4635d 100644 Binary files a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources index 0ab3af451..1fadc765b 100644 --- a/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/path-events/dist/plugin.wasm.sources @@ -1 +1 @@ -1f1b4a5aa2913ab087224d152df4c308e7b572c746ffabee18786fce78c50f9d +1f633882937a9b8fa9d73466cd96dd6f6e3ff620148fd831fdced35fc2d79517 diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm index 529473c0a..cb495642d 100644 Binary files a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources index 4caf77fde..77603ce81 100644 --- a/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/private-dir/dist/plugin.wasm.sources @@ -1 +1 @@ -37ace7bb2fece14d1178166c3b81c938bebdf3938399384dff319eaa6dbc964f +6e9a028bd06f3d79f05462a82bcc250a589f938c029633a73d28750a8ae72dbe diff --git a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm index 9873ecae1..6726d578c 100644 Binary files a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources index 6311b8644..15d625f42 100644 --- a/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/run-anything/dist/plugin.wasm.sources @@ -1 +1 @@ -679aa7de740ef9c777fee6c72ed586ce9a8dc1b1f2d553214c080c0003626971 +c5f5ca68fac368b962ce152be508927ed42c60d1796adb9eadfc9c903766cc4c diff --git a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm index 1b0c4bdbd..230d11e61 100644 Binary files a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources index 550868b65..ca7a53e57 100644 --- a/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/search/dist/plugin.wasm.sources @@ -1 +1 @@ -7a7eb7e96053b06c75b4881619370b2faeca9da042fb6b54a75b38a98a1b8ad8 +cba28a450b12be242a5e0e4285ea61af01b055eced9d28c0c102383186596a1c diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm index e6b6a34eb..982bc8a57 100644 Binary files a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources index f25b987df..5e4c11e88 100644 --- a/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/semantic-tokens/dist/plugin.wasm.sources @@ -1 +1 @@ -fee91a25750bc82ef5f44e85891466229da3884bbeca737331e72bd6f533c082 +baf3b27249b7cf07ffc62f1d5a6989ac17738d19074bb5d927ada85e202eac94 diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm index 1ce73f3f5..d638e4000 100644 Binary files a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources index 297178ba5..7bc66ca85 100644 --- a/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/settings-pages/dist/plugin.wasm.sources @@ -1 +1 @@ -3f7c0bd15b37966fb6dd400ce32f6310c19aedfcdc8adfd90d6af4d1a409c96a +a47ab3aaf7b2858899bee1999a6cb031a27436132c202081085da92b7c352321 diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm index 57f28d822..ed44dfc07 100644 Binary files a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources index 897919baa..7a3059a91 100644 --- a/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/storage/dist/plugin.wasm.sources @@ -1 +1 @@ -54e09f6d2ae0bb4772661ec7d77f3b92e30da19f115847e456615af1d99ee608 +8f6e6b21759f7feeac98aac63d916d470ea1321d8023110b27fe4d4ae383a9e7 diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm index 71bb2dd7f..6d24e96e5 100644 Binary files a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources index 2bfd8d303..47b0e1260 100644 --- a/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/symbols/dist/plugin.wasm.sources @@ -1 +1 @@ -993bc87ead9037693e1f33a1d6ff20f08fb09ed5b0bb9a03641a6785f2a90f1c +3d783bec5d19f49de0dd736030eaf693d0b8a5f71799617e7a21d5c939809d17 diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm index d194ce510..bfa47a308 100644 Binary files a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources index c006796d5..9e8b73772 100644 --- a/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/tables/dist/plugin.wasm.sources @@ -1 +1 @@ -7b3456731392cca0aae6243689f7beab47d775a3f6adbadc0dd4bf1f23db8f5d +06b50aaaddd87cd8d412db5d94375c703e205991e5de2db517d6342578fed332 diff --git a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm index 37d063458..40c039e07 100644 Binary files a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources index 26f5d7a9b..8ade8fdef 100644 --- a/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/watch-paths/dist/plugin.wasm.sources @@ -1 +1 @@ -5b2c9bb2a80ab7c7b777ce35bd5e86bd16c90085b6cfa5639eaa28850a7b828a +a0eb78229020e413e63fa93df7cbd631b1b5f02336eb6453bc75de39d41aafd9 diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm index 9856e8a65..36f25f3ef 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources index 09d3cd3de..2baaa6164 100644 --- a/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-content/dist/plugin.wasm.sources @@ -1 +1 @@ -6a40da7abf14285fb3274a6e2ace582373e5f96689360428c6db1287c62da043 +60aee3fc7660b9f2fe53c7baf446b4a3c12e7f25ae092ed3a05331e2919221b4 diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm index 251293a26..f2474b9ac 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources index 647c3ee12..d4af7b1dc 100644 --- a/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-log/dist/plugin.wasm.sources @@ -1 +1 @@ -5b86ed9e234d07d2c824719ec30e3705cfed1ae873e38be1c417c0a2623c95e2 +77db8099d8a68aafffc6eda2b1388b587a30f4fa83bfd611b968e5d4a680ad38 diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm index c883d345f..fb7d9b45b 100644 Binary files a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm and b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm differ diff --git a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources index 99b957f95..ff38d8300 100644 --- a/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources +++ b/crates/ide-plugin/tests/fixtures/web-pty/dist/plugin.wasm.sources @@ -1 +1 @@ -a0170f44828c31babcdae54fcaefb1546d7f7dfecb8145c21ad293a90acfaac7 +eb5277d6c1856122e1f7dc999d8d55067a6327fb3cb89c870661d280c63946fd diff --git a/docs/en/plugins/api/index.mdx b/docs/en/plugins/api/index.mdx index da88075ed..f07da8321 100644 --- a/docs/en/plugins/api/index.mdx +++ b/docs/en/plugins/api/index.mdx @@ -40,7 +40,7 @@ The plugin calls these. Most are gated by a [capability](/en/plugins/capabilitie | `events` | [events.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/events.wit) | Subscribing to workbench events, optionally filtered by path | | `tasks` | [events.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/events.wit) | Long-running work with a progress indicator and a longer time budget | | `diagnostics` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | Publishing problems for files and reading the Problems view | -| `net` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | HTTP(S) requests (`net:` / `net.http:` / `net:ask`) | +| `net` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | HTTP(S) requests (`net:` / `net.http:` / `net:ask`), streamed responses (`fetch-stream`, 1.19) | | `secrets` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | Secrets in the OS keychain, used only through `{{secret:}}` in requests | | `process` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | Running approved programs once, with an environment, or behind a handle | | `ipc` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | Local sockets and named pipes on the project machine (API 1.4) | diff --git a/docs/en/plugins/capabilities.mdx b/docs/en/plugins/capabilities.mdx index 89842cd06..9da68cdcf 100644 --- a/docs/en/plugins/capabilities.mdx +++ b/docs/en/plugins/capabilities.mdx @@ -65,7 +65,7 @@ Later: | `clipboard.read` | Medium | `host::read_clipboard`: the clipboard's text and image, only in commands and view actions the user ran (event handlers and other unattended calls are denied) | 1.11 | | `agents` | Medium | `host::fork_agent_session`: fork a recorded native agent session (`claude` or `codex`) into a new task in the invoking window's project; trusted projects only | 1.18 | | `secrets` | Medium | `{{secret:}}` in request headers, `secret_is_set`, `secret_set`, `secret_delete` | 1.0 | -| `net:` | Medium | `host::fetch` over HTTPS (and loopback HTTP) to that host; `*.example.com` matches subdomains | 1.0 | +| `net:` | Medium | `host::fetch` / `host::fetch_stream` over HTTPS (and loopback HTTP) to that host; `*.example.com` matches subdomains | 1.0 | | `net:ask` | Medium | Ask the user at the first request to an HTTPS host that isn't declared | 1.5 | | `net.http:` | Medium | Unencrypted HTTP to that host | 1.4 | | `database.sources` | Medium | Manage only the plugin's own project database sources and write their credentials; trusted projects only | 1.4 | diff --git a/docs/en/plugins/versioning.mdx b/docs/en/plugins/versioning.mdx index 5fabf69d6..79924b693 100644 --- a/docs/en/plugins/versioning.mdx +++ b/docs/en/plugins/versioning.mdx @@ -33,7 +33,7 @@ The plugin API has one version number: the version of the WIT package in [`wit/` | 1.16.0 | OpenIDEA 0.1.52 | Optional `completion-list-provider` export: completion marked incomplete is asked again while typing on, without re-asking the language server or other plugins; `decorations.set-markdown`: line-end decorations whose hover is a Markdown card | | 1.17.0 | OpenIDEA 0.1.53 | `decorations.set-styled`: editor decorations with their own `#rrggbb` / `#rrggbbaa` foreground and background, for colors outside the theme palette | | 1.18.0 | OpenIDEA 0.1.54 | `[[contributes.overlays]]`: a package web page floating over the workbench that never takes the keyboard focus, placed and resized through `openidea.overlay`; `[[contributes.dialogs]]`: a package web page in a modal, resizable IDE dialog opened with `views.reveal`, with a `closed` view event and `openidea.dialog.close()`; `events.subscribe-paths-with-options` (`debounce-ms`), `workspace.project.generation` and `FilesChanged` project/generation fields, stale run target/configuration rejection, and the `project-closed` lifecycle event; `execution-configurations`, `run.start-with-options` and `runDetectors.outputMode`: `pipes` or `pty` console output for plugin run configurations; `[[contributes.runAnything]]` with the `run-anything-provider` export: Run Anything lines starting with the plugin's prefix; `views.open-terminal-session-in`: a keyed terminal in a project directory; `workspace.invoking-project`: the project of the window a call serves, also in `gutter-actions` and `hover-actions`; `events.watch-paths` and the `watched-files-changed` event: files and directories outside the project, within `fs.read` grants; the `run-configuration-completion` export: completion in the Arguments field of the plugin's own run configurations; `services.context` and `services.toolbar` menus on the IDE's own Services nodes, with the selected services as the command argument; `executor` on `[[contributes.javaAgents]]`: "Run/Debug '' with " beside Run and Debug, the only launches that get that agent, also startable from the plugin's own commands with a configuration id; grant-scoped `agents.fork-session`: fork a recorded native agent session (`claude` or `codex`) into a new task in the invoking window's project (`agents` capability), with the host validating the session and building the fork invocation itself | -| 1.19.0 | In development on `main` | `[capabilities.reasons]`: the plugin's own sentence on why it asks for a capability, shown below the host's description in the permission dialog and Settings › Plugins; `settings.open` / `settings.open-permissions`: open Settings at one of the plugin's own pages or at its permissions | +| 1.19.0 | In development on `main` | `[capabilities.reasons]`: the plugin's own sentence on why it asks for a capability, shown below the host's description in the permission dialog and Settings › Plugins; `settings.open` / `settings.open-permissions`: open Settings at one of the plugin's own pages or at its permissions; `net.fetch-stream`: a response whose body is read as it arrives (server-sent events, streamed model replies), with the SDK's `host::fetch_stream` and `sse` parser | The full list of what each version added is in [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md). diff --git a/docs/zh/plugins/api/index.mdx b/docs/zh/plugins/api/index.mdx index eb9dbdca7..3e886089c 100644 --- a/docs/zh/plugins/api/index.mdx +++ b/docs/zh/plugins/api/index.mdx @@ -40,7 +40,7 @@ description: "openidea:plugin WIT 包中的每个 interface:一句话说明及 | `events` | [events.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/events.wit) | 订阅工作台事件,可按路径过滤 | | `tasks` | [events.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/events.wit) | 带进度指示、时间预算更长的后台工作 | | `diagnostics` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | 为文件发布问题,读取 问题 视图 | -| `net` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | HTTP(S) 请求(`net:` / `net.http:` / `net:ask`) | +| `net` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | HTTP(S) 请求(`net:` / `net.http:` / `net:ask`)、流式响应(`fetch-stream`,1.19) | | `secrets` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | 系统钥匙串中的密钥,只能通过请求中的 `{{secret:<name>}}` 使用 | | `process` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | 运行已批准的程序:一次性运行、带环境变量运行,或通过句柄保持运行 | | `ipc` | [io.wit](https://github.com/l0ng-ai/openidea/blob/main/wit/io.wit) | 项目所在机器上的本地套接字和命名管道(API 1.4) | diff --git a/docs/zh/plugins/capabilities.mdx b/docs/zh/plugins/capabilities.mdx index 5b1c5f820..35ede6de4 100644 --- a/docs/zh/plugins/capabilities.mdx +++ b/docs/zh/plugins/capabilities.mdx @@ -65,7 +65,7 @@ optional = ["net:127.0.0.1", "clipboard.read"] | `clipboard.read` | 中 | `host::read_clipboard`:读取剪贴板的文本和图片,仅限用户运行的命令和视图操作(事件处理器等无人值守的调用会被拒绝) | 1.11 | | `agents` | 中 | `host::fork_agent_session`:把录制的原生 agent 会话(`claude` 或 `codex`)派生为当前窗口项目中的新任务;仅限受信任项目 | 1.18 | | `secrets` | 中 | 请求头中的 `{{secret:<name>}}`、`secret_is_set`、`secret_set`、`secret_delete` | 1.0 | -| `net:<host>` | 中 | `host::fetch` 通过 HTTPS(以及回环地址的 HTTP)访问该主机;`*.example.com` 匹配子域名 | 1.0 | +| `net:<host>` | 中 | `host::fetch` / `host::fetch_stream` 通过 HTTPS(以及回环地址的 HTTP)访问该主机;`*.example.com` 匹配子域名 | 1.0 | | `net:ask` | 中 | 第一次请求未声明的 HTTPS 主机时询问用户 | 1.5 | | `net.http:<host>` | 中 | 通过未加密的 HTTP 访问该主机 | 1.4 | | `database.sources` | 中 | 只管理插件自己的项目数据源并写入其凭据;仅限受信任项目 | 1.4 | diff --git a/docs/zh/plugins/versioning.mdx b/docs/zh/plugins/versioning.mdx index 64aeecb48..8089c9210 100644 --- a/docs/zh/plugins/versioning.mdx +++ b/docs/zh/plugins/versioning.mdx @@ -30,7 +30,7 @@ description: "engines.openidea、插件 API 从 1.0 到 1.19 的各个版本, | 1.16.0 | OpenIDEA 0.1.52 | 可选 `completion-list-provider` 导出:标记为不完整的补全在继续输入时再次询问,不会重新询问语言服务器和其他插件;`decorations.set-markdown`:悬停显示 Markdown 卡片的行尾装饰 | | 1.17.0 | OpenIDEA 0.1.53 | `decorations.set-styled`:自带 `#rrggbb` / `#rrggbbaa` 前景色和背景色的编辑器装饰,用于主题调色板之外的颜色 | | 1.18.0 | OpenIDEA 0.1.54 | `[[contributes.overlays]]`:悬浮在工作台上方、从不抢占键盘焦点的插件网页,可通过 `openidea.overlay` 移动和调整大小;`[[contributes.dialogs]]`:插件网页显示在可调整大小的模态对话框中,用 `views.reveal` 打开,关闭时发 `closed` 视图事件,页面可调用 `openidea.dialog.close()`;`events.subscribe-paths-with-options`(`debounce-ms`)、`workspace.project.generation` 与 `FilesChanged` 的 `project`/`generation` 字段、过期运行目标/配置拒绝以及 `project-closed` 生命周期事件;`execution-configurations`、`run.start-with-options` 与 `runDetectors.outputMode`:插件运行配置的控制台输出方式(`pipes` 或 `pty`);`[[contributes.runAnything]]` 与 `run-anything-provider` 导出:以插件前缀开头的 Run Anything 行;`views.open-terminal-session-in`:在项目子目录中打开带 key 的终端;`workspace.invoking-project`:本次调用所服务窗口的项目,`gutter-actions` 和 `hover-actions` 中也可用;`events.watch-paths` 与 `watched-files-changed` 事件:监听项目之外、`fs.read` 授权范围内的文件和目录;`run-configuration-completion` 导出:补全插件自己运行配置的“实参”字段;`services.context` 和 `services.toolbar` 菜单:作用于 IDE 自带的 Services 节点,命令参数是选中的服务;`[[contributes.javaAgents]]` 的 `executor`:运行和调试旁边的“使用 <title> 运行/调试 '<name>'”,只有经它启动时才加载该代理,插件自己的命令也可用配置 id 经它启动;需授权的 `agents.fork-session`:把录制的原生 agent 会话(`claude` 或 `codex`)派生为调用窗口项目中的新任务(`agents` 能力),宿主自行校验会话并构造 fork 调用 | -| 1.19.0 | `main` 上开发中 | `[capabilities.reasons]`:插件用一句话说明为什么需要某个能力,显示在授权对话框和 设置 › 插件 中宿主说明的下方;`settings.open` / `settings.open-permissions`:打开设置并定位到插件自己的页面或它的权限 | +| 1.19.0 | `main` 上开发中 | `[capabilities.reasons]`:插件用一句话说明为什么需要某个能力,显示在授权对话框和 设置 › 插件 中宿主说明的下方;`settings.open` / `settings.open-permissions`:打开设置并定位到插件自己的页面或它的权限;`net.fetch-stream`:边到达边读取响应体(服务器推送事件 SSE、模型的流式回复),SDK 提供 `host::fetch_stream` 和 `sse` 解析器 | 每个版本新增内容的完整列表见 [`plugins/README.md`](https://github.com/l0ng-ai/openidea/blob/main/plugins/README.md)。 diff --git a/plugins/official/ai-completion/dist/plugin.wasm b/plugins/official/ai-completion/dist/plugin.wasm index 5dea1ac22..3ff8a3354 100644 Binary files a/plugins/official/ai-completion/dist/plugin.wasm and b/plugins/official/ai-completion/dist/plugin.wasm differ diff --git a/plugins/official/ai-completion/dist/plugin.wasm.sources b/plugins/official/ai-completion/dist/plugin.wasm.sources index 5d039a7e4..041a5bd89 100644 --- a/plugins/official/ai-completion/dist/plugin.wasm.sources +++ b/plugins/official/ai-completion/dist/plugin.wasm.sources @@ -1 +1 @@ -ec3d63216f12488f1da4dec9925df931ee01bcbd310fe4c63310635040644e77 +7669b056e8fdfac23cf680bce156f9e5458102f5606d972c46563b75af96e90c diff --git a/plugins/official/blame-annotations/dist/plugin.wasm b/plugins/official/blame-annotations/dist/plugin.wasm index 2221f66bb..6de803d68 100644 Binary files a/plugins/official/blame-annotations/dist/plugin.wasm and b/plugins/official/blame-annotations/dist/plugin.wasm differ diff --git a/plugins/official/blame-annotations/dist/plugin.wasm.sources b/plugins/official/blame-annotations/dist/plugin.wasm.sources index f68224800..13c40827d 100644 --- a/plugins/official/blame-annotations/dist/plugin.wasm.sources +++ b/plugins/official/blame-annotations/dist/plugin.wasm.sources @@ -1 +1 @@ -59f291af42ebf3c995cc2dbc1af884ee6907379a2b2dbce5a111ebce5751ad92 +0482fcab4ffa4ec70dbe1e27d6498cf6a6511cdac2c2effe2547f50b5fc051fe diff --git a/plugins/official/checkstyle/dist/plugin.wasm b/plugins/official/checkstyle/dist/plugin.wasm index 368b4faab..83ac68a30 100644 Binary files a/plugins/official/checkstyle/dist/plugin.wasm and b/plugins/official/checkstyle/dist/plugin.wasm differ diff --git a/plugins/official/checkstyle/dist/plugin.wasm.sources b/plugins/official/checkstyle/dist/plugin.wasm.sources index 6538352be..8e4e01d6d 100644 --- a/plugins/official/checkstyle/dist/plugin.wasm.sources +++ b/plugins/official/checkstyle/dist/plugin.wasm.sources @@ -1 +1 @@ -f398b771ebb770eafc8b29257f7a8b3f169c17bcde272139df3ad36560d8f7b6 +079e6faf15706581715b1916319f2e86c368dd728a78abc62269845a0e8f287b diff --git a/plugins/official/container-runner/dist/plugin.wasm b/plugins/official/container-runner/dist/plugin.wasm index 801062f41..b6e3997b5 100644 Binary files a/plugins/official/container-runner/dist/plugin.wasm and b/plugins/official/container-runner/dist/plugin.wasm differ diff --git a/plugins/official/container-runner/dist/plugin.wasm.sources b/plugins/official/container-runner/dist/plugin.wasm.sources index 93b2726a6..5c67b9293 100644 --- a/plugins/official/container-runner/dist/plugin.wasm.sources +++ b/plugins/official/container-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -8e726e190c66dc9fa045efa6941848f5a8b5f60f63f03bdd13bfd1722899ae16 +44218a9f34c15352af7351bda6a0e4530fdee0f5a22662452e7425fcc696671f diff --git a/plugins/official/csv-editor/dist/plugin.wasm b/plugins/official/csv-editor/dist/plugin.wasm index a32028b1e..0a213f9e1 100644 Binary files a/plugins/official/csv-editor/dist/plugin.wasm and b/plugins/official/csv-editor/dist/plugin.wasm differ diff --git a/plugins/official/csv-editor/dist/plugin.wasm.sources b/plugins/official/csv-editor/dist/plugin.wasm.sources index 127f13e9b..c186fd848 100644 --- a/plugins/official/csv-editor/dist/plugin.wasm.sources +++ b/plugins/official/csv-editor/dist/plugin.wasm.sources @@ -1 +1 @@ -a5f08d18870968e9f4780726bb5f9fd58d3f50a25db9a604e01c1761924ea34e +f47264da1f56bbccc582b5f5b9f6bd8545fdc94ee640423f262f394c7603f00e diff --git a/plugins/official/git-toolbox/dist/plugin.wasm b/plugins/official/git-toolbox/dist/plugin.wasm index 6d848f3ff..d5265867a 100644 Binary files a/plugins/official/git-toolbox/dist/plugin.wasm and b/plugins/official/git-toolbox/dist/plugin.wasm differ diff --git a/plugins/official/git-toolbox/dist/plugin.wasm.sources b/plugins/official/git-toolbox/dist/plugin.wasm.sources index 332272c0c..5a559a44b 100644 --- a/plugins/official/git-toolbox/dist/plugin.wasm.sources +++ b/plugins/official/git-toolbox/dist/plugin.wasm.sources @@ -1 +1 @@ -662266c107febeacc99efb7a51c73274728d583e0c21aab26cfac2e88a41093c +2ed60850f5429f99a8915eace8ca31316a35e7e2f1db32b8724d060095fca989 diff --git a/plugins/official/graphviz/dist/plugin.wasm b/plugins/official/graphviz/dist/plugin.wasm index a074a31ca..fc12f3e28 100644 Binary files a/plugins/official/graphviz/dist/plugin.wasm and b/plugins/official/graphviz/dist/plugin.wasm differ diff --git a/plugins/official/graphviz/dist/plugin.wasm.sources b/plugins/official/graphviz/dist/plugin.wasm.sources index ef79b685c..a58037c01 100644 --- a/plugins/official/graphviz/dist/plugin.wasm.sources +++ b/plugins/official/graphviz/dist/plugin.wasm.sources @@ -1 +1 @@ -6cef597fe53bc2feaa69e8c0aa0f61ffaebb02ef6997807d7885f618108a0699 +74f235e639f4f53aa5acf47bfd4d2700da9cf8ac872eb0939398289f139117b9 diff --git a/plugins/official/key-promoter/dist/plugin.wasm b/plugins/official/key-promoter/dist/plugin.wasm index 28ff98d54..26e7b2ceb 100644 Binary files a/plugins/official/key-promoter/dist/plugin.wasm and b/plugins/official/key-promoter/dist/plugin.wasm differ diff --git a/plugins/official/key-promoter/dist/plugin.wasm.sources b/plugins/official/key-promoter/dist/plugin.wasm.sources index dfd34aba3..3841c80a9 100644 --- a/plugins/official/key-promoter/dist/plugin.wasm.sources +++ b/plugins/official/key-promoter/dist/plugin.wasm.sources @@ -1 +1 @@ -79a96aa7ec15c2313f88df85b1a77e9a6b53242e54d8142348d7d6fbc529856d +710603f678feed64fda76b11d50a3e1fa86fb1370276b44d40f6a93615cadac4 diff --git a/plugins/official/license-header/dist/plugin.wasm b/plugins/official/license-header/dist/plugin.wasm index f703c2383..6ea121c1d 100644 Binary files a/plugins/official/license-header/dist/plugin.wasm and b/plugins/official/license-header/dist/plugin.wasm differ diff --git a/plugins/official/license-header/dist/plugin.wasm.sources b/plugins/official/license-header/dist/plugin.wasm.sources index b9e00bff2..ecca87bf9 100644 --- a/plugins/official/license-header/dist/plugin.wasm.sources +++ b/plugins/official/license-header/dist/plugin.wasm.sources @@ -1 +1 @@ -26ded505a4c8ae5cc22412fd1943763100a1ff69bf87b110be150db30ef54aa1 +556be41df2cc0a789902e454443e304df8ff9c22531ba96377ef558ad96c59b3 diff --git a/plugins/official/mybatis/dist/plugin.wasm b/plugins/official/mybatis/dist/plugin.wasm index 0002e8dd2..f0e031613 100644 Binary files a/plugins/official/mybatis/dist/plugin.wasm and b/plugins/official/mybatis/dist/plugin.wasm differ diff --git a/plugins/official/mybatis/dist/plugin.wasm.sources b/plugins/official/mybatis/dist/plugin.wasm.sources index e4456ecbe..26bf684b5 100644 --- a/plugins/official/mybatis/dist/plugin.wasm.sources +++ b/plugins/official/mybatis/dist/plugin.wasm.sources @@ -1 +1 @@ -6ee414c5c12d8e06a4898105cc02d8c963b9ff45c3a53b54535637057ea9cdd8 +00cd39c9a2f54a6df074a58b8bc3dbfc8e1ec8538f60d7f1c66274a853c03e84 diff --git a/plugins/official/regex-tester/dist/plugin.wasm b/plugins/official/regex-tester/dist/plugin.wasm index 746128a41..b20ce3d2a 100644 Binary files a/plugins/official/regex-tester/dist/plugin.wasm and b/plugins/official/regex-tester/dist/plugin.wasm differ diff --git a/plugins/official/regex-tester/dist/plugin.wasm.sources b/plugins/official/regex-tester/dist/plugin.wasm.sources index 6bcb2a2f8..6984bee21 100644 --- a/plugins/official/regex-tester/dist/plugin.wasm.sources +++ b/plugins/official/regex-tester/dist/plugin.wasm.sources @@ -1 +1 @@ -bb1823f2fd9c975edfd484839e084dc21c4e5f1a9e865dfef83307b655bc5d4f +46b048dc587fb4069d32109372cfbfcb298bba8827738ea827b9e9591933be39 diff --git a/plugins/official/solidity/dist/plugin.wasm b/plugins/official/solidity/dist/plugin.wasm index 4e06e7cb8..36bba709c 100644 Binary files a/plugins/official/solidity/dist/plugin.wasm and b/plugins/official/solidity/dist/plugin.wasm differ diff --git a/plugins/official/solidity/dist/plugin.wasm.sources b/plugins/official/solidity/dist/plugin.wasm.sources index 300f08e22..b068a1cc1 100644 --- a/plugins/official/solidity/dist/plugin.wasm.sources +++ b/plugins/official/solidity/dist/plugin.wasm.sources @@ -1 +1 @@ -416a2291cde741b6ea699ddc1973f465507bb55d50bfc64661e12c2c38a74e35 +d7d57a18eccced4073ddd74d38505822b6651d0b896ab1958260a833519f990a diff --git a/plugins/official/string-tools/dist/plugin.wasm b/plugins/official/string-tools/dist/plugin.wasm index 93f54eafa..df36af5f2 100644 Binary files a/plugins/official/string-tools/dist/plugin.wasm and b/plugins/official/string-tools/dist/plugin.wasm differ diff --git a/plugins/official/string-tools/dist/plugin.wasm.sources b/plugins/official/string-tools/dist/plugin.wasm.sources index 0e1087d9a..5ff3870b6 100644 --- a/plugins/official/string-tools/dist/plugin.wasm.sources +++ b/plugins/official/string-tools/dist/plugin.wasm.sources @@ -1 +1 @@ -f7d72615195a0ec09257f443fd2a0534ba75a3b17918bddbd43717f43c21016f +0c6bed6791810872b4369bb8e8f095d6309fc7d831b44b9fced2773ec9f49651 diff --git a/plugins/official/test-runner/dist/plugin.wasm b/plugins/official/test-runner/dist/plugin.wasm index 0e9a04261..fb323f702 100644 Binary files a/plugins/official/test-runner/dist/plugin.wasm and b/plugins/official/test-runner/dist/plugin.wasm differ diff --git a/plugins/official/test-runner/dist/plugin.wasm.sources b/plugins/official/test-runner/dist/plugin.wasm.sources index bc22af45b..714eeca81 100644 --- a/plugins/official/test-runner/dist/plugin.wasm.sources +++ b/plugins/official/test-runner/dist/plugin.wasm.sources @@ -1 +1 @@ -2e800980d61fe2e36d52bb63feddfbc9868413e34cddf1d1e33f048f3fc71800 +8388a6986ea82af0ddb1093c59d3b77bb2e7635bace30ddb2f1d4e16300d3177 diff --git a/plugins/official/todo-finder/dist/plugin.wasm b/plugins/official/todo-finder/dist/plugin.wasm index 89d97da89..91e0dd94b 100644 Binary files a/plugins/official/todo-finder/dist/plugin.wasm and b/plugins/official/todo-finder/dist/plugin.wasm differ diff --git a/plugins/official/todo-finder/dist/plugin.wasm.sources b/plugins/official/todo-finder/dist/plugin.wasm.sources index 49fcca0a6..ddab05c8e 100644 --- a/plugins/official/todo-finder/dist/plugin.wasm.sources +++ b/plugins/official/todo-finder/dist/plugin.wasm.sources @@ -1 +1 @@ -483c1c02536edee5c6d27bc0cec89fb3bb52a5f854a38c27ca7e72a9cb7f2c1d +0a016d0cb7c4cf7ce97b54570813b25731b9dde81a1b8581c3b57502c8fd42e2 diff --git a/sdk/rust/openidea-plugin/src/host.rs b/sdk/rust/openidea-plugin/src/host.rs index b1fde364b..c4fdb2cbe 100644 --- a/sdk/rust/openidea-plugin/src/host.rs +++ b/sdk/rust/openidea-plugin/src/host.rs @@ -770,15 +770,36 @@ mod imp { wit::diagnostics::publish(path, &items).map_err(error) } - pub fn fetch(req: &HttpRequest) -> Result<HttpResponse, Error> { - let r = wit::net::Request { + fn net_request(req: &HttpRequest) -> wit::net::Request { + wit::net::Request { method: req.method.clone(), url: req.url.clone(), headers: req.headers.iter().map(|(n, v)| wit::net::Header { name: n.clone(), value: v.clone() }).collect(), body: req.body.clone(), timeout_ms: req.timeout_ms, - }; - wit::net::fetch(&r) + } + } + + pub type ResponseStreamRes = wit::net::ResponseStream; + + pub fn fetch_stream(req: &HttpRequest) -> Result<ResponseStreamRes, Error> { + wit::net::fetch_stream(&net_request(req)).map_err(error) + } + pub fn response_stream_status(r: &ResponseStreamRes) -> u16 { + r.status() + } + pub fn response_stream_headers(r: &ResponseStreamRes) -> Vec<(String, String)> { + r.headers().into_iter().map(|h| (h.name, h.value)).collect() + } + pub fn response_stream_read(r: &ResponseStreamRes, max: u32, timeout: u32) -> Result<(Vec<u8>, bool), Error> { + r.read(max, timeout).map(|c| (c.bytes, c.done)).map_err(error) + } + pub fn response_stream_close(r: &ResponseStreamRes) { + r.close() + } + + pub fn fetch(req: &HttpRequest) -> Result<HttpResponse, Error> { + wit::net::fetch(&net_request(req)) .map(|r| HttpResponse { status: r.status, headers: r.headers.into_iter().map(|h| (h.name, h.value)).collect(), @@ -1476,6 +1497,52 @@ pub fn fetch(request: &HttpRequest) -> Result<HttpResponse, Error> { imp::fetch(request) } +/// As [`fetch`], with the same grants, secrets and redirects, but returns as +/// soon as the response headers arrive; the body is then read as it comes in +/// with [`ResponseStream::read`], or as server-sent events with +/// [`ResponseStream::events`] (API 1.19). `timeout_ms` bounds only the wait for +/// the headers. At most eight streams may be open at once. +pub fn fetch_stream(request: &HttpRequest) -> Result<ResponseStream, Error> { + imp::fetch_stream(request).map(|inner| ResponseStream { inner }) +} + +/// A response whose body is still arriving (API 1.19). Dropping it closes the +/// connection. +pub struct ResponseStream { + inner: imp::ResponseStreamRes, +} + +/// The next piece of a [`ResponseStream`]'s body. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct BodyChunk { + pub bytes: Vec<u8>, + /// The body has ended: later reads return no more bytes. + pub done: bool, +} + +impl ResponseStream { + pub fn status(&self) -> u16 { + imp::response_stream_status(&self.inner) + } + pub fn headers(&self) -> Vec<(String, String)> { + imp::response_stream_headers(&self.inner) + } + /// The next bytes of the body, at most `max_bytes` (and 1 MiB). Waits up to + /// `timeout_ms` within the call's budget; no bytes and `done == false` + /// when nothing arrived in time. Zero only takes what already arrived. + pub fn read(&self, max_bytes: u32, timeout_ms: u32) -> Result<BodyChunk, Error> { + imp::response_stream_read(&self.inner, max_bytes, timeout_ms).map(|(bytes, done)| BodyChunk { bytes, done }) + } + /// Reads the body as `text/event-stream`. + pub fn events(self) -> crate::sse::EventStream { + crate::sse::EventStream::new(self) + } + /// Closes the connection; reads then fail. Dropping the stream also closes it. + pub fn close(&self) { + imp::response_stream_close(&self.inner) + } +} + /// A host-owned background WebSocket. Dropping it closes the connection. pub struct WebSocket { inner: imp::WebSocketRes, diff --git a/sdk/rust/openidea-plugin/src/lib.rs b/sdk/rust/openidea-plugin/src/lib.rs index 75f84f51e..609f138c1 100644 --- a/sdk/rust/openidea-plugin/src/lib.rs +++ b/sdk/rust/openidea-plugin/src/lib.rs @@ -53,6 +53,7 @@ pub mod mock; pub mod providers; pub mod search; pub mod semantic_tokens; +pub mod sse; pub mod syntax; pub mod text; mod types; diff --git a/sdk/rust/openidea-plugin/src/mock.rs b/sdk/rust/openidea-plugin/src/mock.rs index e56603eaf..41d2033c1 100644 --- a/sdk/rust/openidea-plugin/src/mock.rs +++ b/sdk/rust/openidea-plugin/src/mock.rs @@ -125,6 +125,9 @@ struct State { console_rules: Vec<ConsoleRule>, ipc: BTreeMap<u64, VecDeque<u8>>, next_ipc: u64, + /// Open `fetch_stream` bodies, read in pieces of at most the asked size. + streams: BTreeMap<u64, VecDeque<u8>>, + next_stream: u64, loopbacks: BTreeSet<u64>, next_loopback: u64, output: BTreeMap<String, String>, @@ -2456,6 +2459,47 @@ pub mod current { }) } + pub struct ResponseStreamRes { + id: u64, + status: u16, + headers: Vec<(String, String)>, + owner: Rc<RefCell<State>>, + } + impl Drop for ResponseStreamRes { + fn drop(&mut self) { + self.owner.borrow_mut().streams.remove(&self.id); + } + } + /// Answered by the `MockHost::on_fetch` handler, like `fetch`. + pub fn fetch_stream(req: &HttpRequest) -> Result<ResponseStreamRes, Error> { + if with(|s| s.streams.len()) >= 8 { + return Err(Error::Invalid("at most eight response streams per plugin".into())); + } + let response = fetch(req)?; + with(|s| { + s.next_stream += 1; + s.streams.insert(s.next_stream, response.body.into()); + let owner = CURRENT.with(|c| c.borrow().as_ref().unwrap().clone()); + Ok(ResponseStreamRes { id: s.next_stream, status: response.status, headers: response.headers, owner }) + }) + } + pub fn response_stream_status(r: &ResponseStreamRes) -> u16 { + r.status + } + pub fn response_stream_headers(r: &ResponseStreamRes) -> Vec<(String, String)> { + r.headers.clone() + } + pub fn response_stream_read(r: &ResponseStreamRes, max: u32, _timeout: u32) -> Result<(Vec<u8>, bool), Error> { + let mut s = r.owner.borrow_mut(); + let body = s.streams.get_mut(&r.id).ok_or_else(|| Error::NotFound("response stream".into()))?; + let count = body.len().min(max as usize).min(1 << 20); + let bytes: Vec<u8> = body.drain(..count).collect(); + Ok((bytes, body.is_empty())) + } + pub fn response_stream_close(r: &ResponseStreamRes) { + r.owner.borrow_mut().streams.remove(&r.id); + } + pub fn websocket_connect(project: &ProjectRes, req: &WebSocketRequest) -> Result<WebSocketRes, Error> { with(|s| { require(s, "project.read")?; @@ -3636,6 +3680,37 @@ mod tests { assert_eq!(mock.diagnostics()["/project/a.java"].len(), 1); } + #[test] + fn streamed_responses_read_in_pieces_and_as_events() { + let mock = MockHost::install().with_capabilities(&["net:api.x.io"]); + assert!(matches!(host::fetch_stream(&HttpRequest::get("https://other.io")), Err(Error::Denied(_)))); + mock.on_fetch(|_| { + Ok(HttpResponse { + status: 200, + headers: vec![("content-type".into(), "text/event-stream".into())], + body: b"data: one\n\nevent: end\ndata: two\n\n".to_vec(), + }) + }); + let stream = host::fetch_stream(&HttpRequest::get("https://api.x.io/v1")).unwrap(); + assert_eq!((stream.status(), stream.headers()[0].1.as_str()), (200, "text/event-stream")); + assert_eq!(stream.read(4, 0).unwrap(), host::BodyChunk { bytes: b"data".to_vec(), done: false }); + stream.close(); + assert!(matches!(stream.read(4, 0), Err(Error::NotFound(_)))); + + let mut events = host::fetch_stream(&HttpRequest::get("https://api.x.io/v1")).unwrap().events(); + assert_eq!(events.next(0).unwrap().unwrap().data, "one"); + let last = events.next(0).unwrap().unwrap(); + assert_eq!((last.event.as_str(), last.data.as_str()), ("end", "two")); + assert_eq!(events.next(0).unwrap(), None); + assert!(events.is_done()); + drop(events); + + let open: Vec<_> = (0..8).map(|_| host::fetch_stream(&HttpRequest::get("https://api.x.io")).unwrap()).collect(); + assert!(matches!(host::fetch_stream(&HttpRequest::get("https://api.x.io")), Err(Error::Invalid(_)))); + drop(open); + assert!(host::fetch_stream(&HttpRequest::get("https://api.x.io")).is_ok()); + } + #[test] fn private_directory_needs_no_filesystem_grants() { let _mock = MockHost::install().with_capabilities(&[]); diff --git a/sdk/rust/openidea-plugin/src/sse.rs b/sdk/rust/openidea-plugin/src/sse.rs new file mode 100644 index 000000000..aba451aaa --- /dev/null +++ b/sdk/rust/openidea-plugin/src/sse.rs @@ -0,0 +1,212 @@ +//! Server-sent events (`text/event-stream`) read from a +//! [`ResponseStream`](crate::host::ResponseStream) as they arrive (API 1.19): +//! a model's streamed reply, a build's progress. +//! +//! ```no_run +//! # use openidea_plugin::{host, HttpRequest}; +//! # fn run(request: &HttpRequest) -> Result<(), openidea_plugin::Error> { +//! let mut events = host::fetch_stream(request)?.events(); +//! while let Some(event) = events.next(10_000)? { +//! if event.data == "[DONE]" { +//! break; +//! } +//! // Use event.data … +//! } +//! # Ok(()) +//! # } +//! ``` + +use crate::Error; +use crate::host::ResponseStream; +use std::collections::VecDeque; + +/// Bytes asked for per read. +const READ_SIZE: u32 = 64 << 10; + +/// One dispatched event. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct Event { + /// The `event:` field; `message` when the server sent none. + pub event: String, + /// The `data:` lines joined with `\n`. + pub data: String, + /// The last `id:` the stream sent, if any (it carries over to later events). + pub id: Option<String>, + /// The `retry:` field of this event, in milliseconds. + pub retry: Option<u32>, +} + +/// An incremental `text/event-stream` parser, for bytes from any source. +#[derive(Debug, Default)] +pub struct Parser { + line: Vec<u8>, + /// The previous line ended with `\r`: a `\n` right after it is part of that end. + after_cr: bool, + started: bool, + event: String, + data: String, + has_data: bool, + id: Option<String>, + retry: Option<u32>, +} + +impl Parser { + pub fn new() -> Self { + Self::default() + } + + /// Feeds the next bytes; returns the events they complete. + pub fn push(&mut self, bytes: &[u8]) -> Vec<Event> { + let mut out = Vec::new(); + for &b in bytes { + if self.after_cr { + self.after_cr = false; + if b == b'\n' { + continue; + } + } + match b { + b'\n' | b'\r' => { + self.after_cr = b == b'\r'; + let line = std::mem::take(&mut self.line); + if let Some(event) = self.line_done(&line) { + out.push(event); + } + } + _ => self.line.push(b), + } + } + out + } + + fn line_done(&mut self, line: &[u8]) -> Option<Event> { + let mut line = String::from_utf8_lossy(line).into_owned(); + if !self.started { + self.started = true; + if let Some(rest) = line.strip_prefix('\u{feff}') { + line = rest.to_owned(); + } + } + if line.is_empty() { + return self.dispatch(); + } + if line.starts_with(':') { + return None; + } + let (field, value) = match line.split_once(':') { + Some((field, value)) => (field, value.strip_prefix(' ').unwrap_or(value)), + None => (line.as_str(), ""), + }; + match field { + "event" => self.event = value.to_owned(), + "data" => { + if self.has_data { + self.data.push('\n'); + } + self.data.push_str(value); + self.has_data = true; + } + "id" if !value.contains('\0') => self.id = Some(value.to_owned()), + "retry" => { + if let Ok(ms) = value.parse() { + self.retry = Some(ms); + } + } + _ => {} + } + None + } + + fn dispatch(&mut self) -> Option<Event> { + let event = std::mem::take(&mut self.event); + let retry = self.retry.take(); + if !std::mem::take(&mut self.has_data) { + return None; + } + Some(Event { + event: if event.is_empty() { "message".into() } else { event }, + data: std::mem::take(&mut self.data), + id: self.id.clone(), + retry, + }) + } +} + +/// The events of a [`ResponseStream`], from [`ResponseStream::events`]. +pub struct EventStream { + stream: ResponseStream, + parser: Parser, + queued: VecDeque<Event>, + done: bool, +} + +impl EventStream { + pub(crate) fn new(stream: ResponseStream) -> Self { + Self { stream, parser: Parser::new(), queued: VecDeque::new(), done: false } + } + + /// The underlying response, for its status and headers. + pub fn response(&self) -> &ResponseStream { + &self.stream + } + + /// The next event. Waits up to `timeout_ms` for each read of more bytes; + /// `None` when a read brought nothing in that time or the body ended + /// ([`EventStream::is_done`] tells which). An event left unfinished at the + /// end of the body is dropped, as browsers do. + pub fn next(&mut self, timeout_ms: u32) -> Result<Option<Event>, Error> { + loop { + if let Some(event) = self.queued.pop_front() { + return Ok(Some(event)); + } + if self.done { + return Ok(None); + } + let chunk = self.stream.read(READ_SIZE, timeout_ms)?; + self.done = chunk.done; + self.queued.extend(self.parser.push(&chunk.bytes)); + if chunk.bytes.is_empty() && !chunk.done { + return Ok(self.queued.pop_front()); + } + } + } + + /// The body has ended and every event was returned. + pub fn is_done(&self) -> bool { + self.done && self.queued.is_empty() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn data(events: &[Event]) -> Vec<&str> { + events.iter().map(|e| e.data.as_str()).collect() + } + + #[test] + fn events_split_across_pushes_and_line_endings() { + let mut p = Parser::new(); + assert!(p.push(b"\xef\xbb\xbfdata: a\r").is_empty()); + // The `\n` after a `\r` ending a push belongs to that line end. + let events = p.push(b"\ndata:b\r\n\r\nevent: delta\nid: 7\ndata: {\"x\":1}\n\n: comment\n\n"); + assert_eq!(data(&events), ["a\nb", "{\"x\":1}"]); + assert_eq!(events[0].event, "message"); + assert_eq!((events[1].event.as_str(), events[1].id.as_deref()), ("delta", Some("7"))); + let events = p.push(b"data: next\rretry: 5\r\r"); + assert_eq!(data(&events), ["next"]); + // The id carries over; retry belongs to its event. + assert_eq!((events[0].id.as_deref(), events[0].retry), (Some("7"), Some(5))); + } + + #[test] + fn events_without_data_and_unknown_fields_are_not_dispatched() { + let mut p = Parser::new(); + assert!(p.push(b"event: ping\n\nfoo: bar\n\n").is_empty()); + let events = p.push(b"data\n\ndata: \xe4\xbd\xa0\xe5"); + assert_eq!(data(&events), [""]); + // A character split between pushes stays whole. + assert_eq!(data(&p.push(b"\xa5\xbd\n\n")), ["你好"]); + } +} diff --git a/sdk/rust/openidea-plugin/wit/io.wit b/sdk/rust/openidea-plugin/wit/io.wit index bd4a73ff7..a3e830eda 100644 --- a/sdk/rust/openidea-plugin/wit/io.wit +++ b/sdk/rust/openidea-plugin/wit/io.wit @@ -108,6 +108,32 @@ interface net { /// project binding, so resource methods cannot be redirected to another /// project. websocket-connect: func(project: borrow<project>, req: websocket-request) -> result<websocket, error>; + + record body-chunk { + bytes: list<u8>, + /// The body has ended: this read and every later one return no more bytes. + done: bool, + } + + /// A response whose body is read as it arrives: server-sent events, a + /// model's streamed reply (API 1.19). At most eight may be open for a + /// plugin. Dropping this resource closes the connection, as does stopping + /// the plugin. + resource response-stream { + status: func() -> u16; + headers: func() -> list<header>; + /// The next bytes of the body, at most `max-bytes` (and 1 MiB). Waits + /// up to `timeout-ms` for them within the call's budget and returns + /// none, with `done` false, when nothing arrived in time; zero only + /// takes what has already arrived. + read: func(max-bytes: u32, timeout-ms: u32) -> result<body-chunk, error>; + close: func(); + } + + /// As `fetch`, with the same grants, secrets and redirects, but returns + /// once the response headers arrive (API 1.19). `timeout-ms` bounds the + /// wait for the headers; the body has no overall limit. + fetch-stream: func(req: request) -> result<response-stream, error>; } /// Secrets the user stored for the plugin (Settings › Plugins, kept in the diff --git a/wit/io.wit b/wit/io.wit index bd4a73ff7..a3e830eda 100644 --- a/wit/io.wit +++ b/wit/io.wit @@ -108,6 +108,32 @@ interface net { /// project binding, so resource methods cannot be redirected to another /// project. websocket-connect: func(project: borrow<project>, req: websocket-request) -> result<websocket, error>; + + record body-chunk { + bytes: list<u8>, + /// The body has ended: this read and every later one return no more bytes. + done: bool, + } + + /// A response whose body is read as it arrives: server-sent events, a + /// model's streamed reply (API 1.19). At most eight may be open for a + /// plugin. Dropping this resource closes the connection, as does stopping + /// the plugin. + resource response-stream { + status: func() -> u16; + headers: func() -> list<header>; + /// The next bytes of the body, at most `max-bytes` (and 1 MiB). Waits + /// up to `timeout-ms` for them within the call's budget and returns + /// none, with `done` false, when nothing arrived in time; zero only + /// takes what has already arrived. + read: func(max-bytes: u32, timeout-ms: u32) -> result<body-chunk, error>; + close: func(); + } + + /// As `fetch`, with the same grants, secrets and redirects, but returns + /// once the response headers arrive (API 1.19). `timeout-ms` bounds the + /// wait for the headers; the body has no overall limit. + fetch-stream: func(req: request) -> result<response-stream, error>; } /// Secrets the user stored for the plugin (Settings › Plugins, kept in the