From 7f0ffa010979b21ef39e96889bd2a0ea3b61f955 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Tue, 29 Apr 2025 17:59:42 -0400 Subject: [PATCH] Add some random static text to test the thread --- crates/agent/src/assistant.rs | 2 +- .../src/preview_support/active_thread.rs | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/agent/src/assistant.rs b/crates/agent/src/assistant.rs index 2e5e5dc693..e6df4a1399 100644 --- a/crates/agent/src/assistant.rs +++ b/crates/agent/src/assistant.rs @@ -34,7 +34,7 @@ use prompt_store::PromptBuilder; use schemars::JsonSchema; use serde::Deserialize; use settings::Settings as _; -use thread::ThreadId; +pub use thread::{MessageSegment, ThreadId}; pub use crate::active_thread::ActiveThread; use crate::assistant_configuration::{AddContextServerModal, ManageProfilesModal}; diff --git a/crates/component_preview/src/preview_support/active_thread.rs b/crates/component_preview/src/preview_support/active_thread.rs index 82cad6693d..1f495d56a3 100644 --- a/crates/component_preview/src/preview_support/active_thread.rs +++ b/crates/component_preview/src/preview_support/active_thread.rs @@ -2,7 +2,7 @@ use languages::LanguageRegistry; use project::Project; use std::sync::Arc; -use agent::{ActiveThread, ThreadStore}; +use agent::{ActiveThread, MessageSegment, ThreadStore}; use assistant_tool::ToolWorkingSet; use gpui::{AppContext, AsyncApp, Entity, Task, WeakEntity}; use prompt_store::PromptBuilder; @@ -37,7 +37,20 @@ pub fn static_active_thread( cx: &mut App, ) -> Entity { let thread = thread_store.update(cx, |thread_store, cx| thread_store.create_thread(cx)); - + thread.update(cx, |thread, cx| { + thread.insert_assistant_message(vec![ + MessageSegment::Text("I'll help you fix the lifetime error in your `cx.spawn` call. When working with async operations in GPUI, there are specific patterns to follow for proper lifetime management.".to_string()), + MessageSegment::Text("\n\nLet's look at what's happening in your code:".to_string()), + MessageSegment::Text("\n\n---\n\nLet's check the current state of the active_thread.rs file to understand what might have changed:".to_string()), + MessageSegment::Text("\n\n---\n\nLooking at the implementation of `load_preview_thread_store` and understanding GPUI's async patterns, here's the issue:".to_string()), + MessageSegment::Text("\n\n1. `load_preview_thread_store` returns a `Task>>`, which means it's already a task".to_string()), + MessageSegment::Text("\n2. When you call this function inside another `spawn` call, you're nesting tasks incorrectly".to_string()), + MessageSegment::Text("\n3. The `this` parameter you're trying to use in your closure has the wrong context".to_string()), + MessageSegment::Text("\n\nHere's the correct way to implement this:".to_string()), + MessageSegment::Text("\n\n---\n\nThe problem is in how you're setting up the async closure and trying to reference variables like `window` and `language_registry` that aren't accessible in that scope.".to_string()), + MessageSegment::Text("\n\nHere's how to fix it:".to_string()), + ], cx); + }); cx.new(|cx| { ActiveThread::new( thread,