ACP champagne (#35609)

cherry pick changes from #35510 onto latest main

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Lukas Wirth <lukas@zed.dev>
This commit is contained in:
Ben Brandt 2025-08-06 11:01:06 +02:00 committed by GitHub
parent 69794db331
commit eb4b73b88e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 2361 additions and 67 deletions

View file

@ -92,7 +92,12 @@ pub struct ToolUseRequest {
pub struct FakeLanguageModel {
provider_id: LanguageModelProviderId,
provider_name: LanguageModelProviderName,
current_completion_txs: Mutex<Vec<(LanguageModelRequest, mpsc::UnboundedSender<String>)>>,
current_completion_txs: Mutex<
Vec<(
LanguageModelRequest,
mpsc::UnboundedSender<LanguageModelCompletionEvent>,
)>,
>,
}
impl Default for FakeLanguageModel {
@ -118,10 +123,21 @@ impl FakeLanguageModel {
self.current_completion_txs.lock().len()
}
pub fn stream_completion_response(
pub fn send_completion_stream_text_chunk(
&self,
request: &LanguageModelRequest,
chunk: impl Into<String>,
) {
self.send_completion_stream_event(
request,
LanguageModelCompletionEvent::Text(chunk.into()),
);
}
pub fn send_completion_stream_event(
&self,
request: &LanguageModelRequest,
event: impl Into<LanguageModelCompletionEvent>,
) {
let current_completion_txs = self.current_completion_txs.lock();
let tx = current_completion_txs
@ -129,7 +145,7 @@ impl FakeLanguageModel {
.find(|(req, _)| req == request)
.map(|(_, tx)| tx)
.unwrap();
tx.unbounded_send(chunk.into()).unwrap();
tx.unbounded_send(event.into()).unwrap();
}
pub fn end_completion_stream(&self, request: &LanguageModelRequest) {
@ -138,8 +154,15 @@ impl FakeLanguageModel {
.retain(|(req, _)| req != request);
}
pub fn stream_last_completion_response(&self, chunk: impl Into<String>) {
self.stream_completion_response(self.pending_completions().last().unwrap(), chunk);
pub fn send_last_completion_stream_text_chunk(&self, chunk: impl Into<String>) {
self.send_completion_stream_text_chunk(self.pending_completions().last().unwrap(), chunk);
}
pub fn send_last_completion_stream_event(
&self,
event: impl Into<LanguageModelCompletionEvent>,
) {
self.send_completion_stream_event(self.pending_completions().last().unwrap(), event);
}
pub fn end_last_completion_stream(&self) {
@ -201,12 +224,7 @@ impl LanguageModel for FakeLanguageModel {
> {
let (tx, rx) = mpsc::unbounded();
self.current_completion_txs.lock().push((request, tx));
async move {
Ok(rx
.map(|text| Ok(LanguageModelCompletionEvent::Text(text)))
.boxed())
}
.boxed()
async move { Ok(rx.map(Ok).boxed()) }.boxed()
}
fn as_fake(&self) -> &Self {