Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de97871

Browse files
feat: separate out user_task into user_task_init and user_task_update events (tailcallhq#385)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 2bb4473 commit de97871

39 files changed

Lines changed: 418 additions & 377 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ Cargo.lock
3737
*.new
3838
.vscode/
3939
.fastembed_cache/
40+
*.log*

Cargo.lock

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/forge_api/src/api.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ use crate::API;
1414

1515
pub struct ForgeAPI<F> {
1616
app: Arc<F>,
17-
_executor_service: ForgeExecutorService<F>,
18-
_suggestion_service: ForgeSuggestionService<F>,
19-
_loader: ForgeLoaderService<F>,
17+
executor_service: ForgeExecutorService<F>,
18+
suggestion_service: ForgeSuggestionService<F>,
19+
loader: ForgeLoaderService<F>,
2020
}
2121

2222
impl<F: App + Infrastructure> ForgeAPI<F> {
2323
pub fn new(app: Arc<F>) -> Self {
2424
Self {
2525
app: app.clone(),
26-
_executor_service: ForgeExecutorService::new(app.clone()),
27-
_suggestion_service: ForgeSuggestionService::new(app.clone()),
28-
_loader: ForgeLoaderService::new(app.clone()),
26+
executor_service: ForgeExecutorService::new(app.clone()),
27+
suggestion_service: ForgeSuggestionService::new(app.clone()),
28+
loader: ForgeLoaderService::new(app.clone()),
2929
}
3030
}
3131
}
@@ -41,7 +41,7 @@ impl ForgeAPI<ForgeApp<ForgeInfra>> {
4141
#[async_trait::async_trait]
4242
impl<F: App + Infrastructure> API for ForgeAPI<F> {
4343
async fn suggestions(&self) -> Result<Vec<File>> {
44-
self._suggestion_service.suggestions().await
44+
self.suggestion_service.suggestions().await
4545
}
4646

4747
async fn tools(&self) -> Vec<ToolDefinition> {
@@ -56,7 +56,7 @@ impl<F: App + Infrastructure> API for ForgeAPI<F> {
5656
&self,
5757
chat: ChatRequest,
5858
) -> anyhow::Result<MpscStream<Result<AgentMessage<ChatResponse>, anyhow::Error>>> {
59-
Ok(self._executor_service.chat(chat).await?)
59+
Ok(self.executor_service.chat(chat).await?)
6060
}
6161

6262
async fn init(&self, workflow: Workflow) -> anyhow::Result<ConversationId> {
@@ -68,7 +68,7 @@ impl<F: App + Infrastructure> API for ForgeAPI<F> {
6868
}
6969

7070
async fn load(&self, path: Option<&Path>) -> anyhow::Result<Workflow> {
71-
self._loader.load(path).await
71+
self.loader.load(path).await
7272
}
7373

7474
async fn conversation(

crates/forge_app/src/app.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@ use std::sync::Arc;
33
use forge_domain::App;
44

55
use crate::conversation::ForgeConversationService;
6-
use crate::prompt::ForgePromptService;
76
use crate::provider::ForgeProviderService;
7+
use crate::suggestion::ForgeSuggestionService;
8+
use crate::template::ForgeTemplateService;
89
use crate::tool_service::ForgeToolService;
910
use crate::Infrastructure;
1011

12+
/// ForgeApp is the main application container that implements the App trait.
13+
/// It provides access to all core services required by the application.
14+
///
15+
/// Type Parameters:
16+
/// - F: The infrastructure implementation that provides core services like
17+
/// environment, file reading, vector indexing, and embedding.
1118
pub struct ForgeApp<F> {
1219
infra: Arc<F>,
13-
_tool_service: ForgeToolService,
14-
_provider_service: ForgeProviderService,
15-
_conversation_service: ForgeConversationService,
16-
_prompt_service: ForgePromptService,
20+
tool_service: ForgeToolService,
21+
provider_service: ForgeProviderService,
22+
conversation_service: ForgeConversationService,
23+
prompt_service: ForgeTemplateService,
24+
suggestion_service: Arc<ForgeSuggestionService<F>>,
1725
}
1826

1927
impl<F: Infrastructure> ForgeApp<F> {
2028
pub fn new(infra: Arc<F>) -> Self {
29+
let suggestion_service = Arc::new(ForgeSuggestionService::new(infra.clone()));
2130
Self {
2231
infra: infra.clone(),
23-
_tool_service: ForgeToolService::new(infra.clone()),
24-
_provider_service: ForgeProviderService::new(infra.clone()),
25-
_conversation_service: ForgeConversationService::new(),
26-
_prompt_service: ForgePromptService::new(),
32+
tool_service: ForgeToolService::new(infra.clone(), suggestion_service.clone()),
33+
provider_service: ForgeProviderService::new(infra.clone()),
34+
conversation_service: ForgeConversationService::new(),
35+
prompt_service: ForgeTemplateService::new(),
36+
suggestion_service,
2737
}
2838
}
2939
}
@@ -32,29 +42,34 @@ impl<F: Infrastructure> App for ForgeApp<F> {
3242
type ToolService = ForgeToolService;
3343
type ProviderService = ForgeProviderService;
3444
type ConversationService = ForgeConversationService;
35-
type PromptService = ForgePromptService;
45+
type PromptService = ForgeTemplateService;
46+
type SuggestionService = ForgeSuggestionService<F>;
3647

3748
fn tool_service(&self) -> &Self::ToolService {
38-
&self._tool_service
49+
&self.tool_service
50+
}
51+
52+
fn suggestion_service(&self) -> &Self::SuggestionService {
53+
&self.suggestion_service
3954
}
4055

4156
fn provider_service(&self) -> &Self::ProviderService {
42-
&self._provider_service
57+
&self.provider_service
4358
}
4459

4560
fn conversation_service(&self) -> &Self::ConversationService {
46-
&self._conversation_service
61+
&self.conversation_service
4762
}
4863

4964
fn prompt_service(&self) -> &Self::PromptService {
50-
&self._prompt_service
65+
&self.prompt_service
5166
}
5267
}
5368

5469
impl<F: Infrastructure> Infrastructure for ForgeApp<F> {
5570
type EnvironmentService = F::EnvironmentService;
5671
type FileReadService = F::FileReadService;
57-
type KnowledgeRepository = F::KnowledgeRepository;
72+
type VectorIndex = F::VectorIndex;
5873
type EmbeddingService = F::EmbeddingService;
5974

6075
fn environment_service(&self) -> &Self::EnvironmentService {
@@ -65,8 +80,8 @@ impl<F: Infrastructure> Infrastructure for ForgeApp<F> {
6580
self.infra.file_read_service()
6681
}
6782

68-
fn textual_knowledge_repo(&self) -> &Self::KnowledgeRepository {
69-
self.infra.textual_knowledge_repo()
83+
fn vector_index(&self) -> &Self::VectorIndex {
84+
self.infra.vector_index()
7085
}
7186

7287
fn embedding_service(&self) -> &Self::EmbeddingService {

crates/forge_app/src/conversation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ConversationService for ForgeConversationService {
5959
.get_mut(id)
6060
.ok_or_else(|| anyhow::anyhow!("Conversation not found"))?
6161
.events
62-
.insert(event.name.clone(), event);
62+
.push(event);
6363
Ok(())
6464
}
6565
}

crates/forge_app/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
mod app;
22
mod conversation;
3-
mod prompt;
43
mod provider;
4+
mod suggestion;
5+
mod template;
56
mod tool_service;
67
mod tools;
78

89
use std::path::Path;
910

1011
pub use app::*;
11-
use forge_domain::{Knowledge, Query};
12-
use serde_json::Value;
12+
use forge_domain::{Point, Query, Suggestion};
1313

1414
/// Repository for accessing system environment information
1515
#[async_trait::async_trait]
@@ -33,9 +33,9 @@ pub trait FileReadService: Send + Sync {
3333
}
3434

3535
#[async_trait::async_trait]
36-
pub trait KnowledgeRepository<T>: Send + Sync {
37-
async fn store(&self, information: Vec<Knowledge<T>>) -> anyhow::Result<()>;
38-
async fn search(&self, query: Query) -> anyhow::Result<Vec<Value>>;
36+
pub trait VectorIndex<T>: Send + Sync {
37+
async fn store(&self, point: Point<T>) -> anyhow::Result<()>;
38+
async fn search(&self, query: Query) -> anyhow::Result<Vec<Point<T>>>;
3939
}
4040

4141
#[async_trait::async_trait]
@@ -46,11 +46,11 @@ pub trait EmbeddingService: Send + Sync {
4646
pub trait Infrastructure: Send + Sync + 'static {
4747
type EnvironmentService: EnvironmentService;
4848
type FileReadService: FileReadService;
49-
type KnowledgeRepository: KnowledgeRepository<Value>;
49+
type VectorIndex: VectorIndex<Suggestion>;
5050
type EmbeddingService: EmbeddingService;
5151

5252
fn environment_service(&self) -> &Self::EnvironmentService;
5353
fn file_read_service(&self) -> &Self::FileReadService;
54-
fn textual_knowledge_repo(&self) -> &Self::KnowledgeRepository;
54+
fn vector_index(&self) -> &Self::VectorIndex;
5555
fn embedding_service(&self) -> &Self::EmbeddingService;
5656
}

crates/forge_app/src/suggestion.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::sync::Arc;
2+
3+
use anyhow::Result;
4+
use async_trait::async_trait;
5+
use forge_domain::{Point, Query, Suggestion, SuggestionService};
6+
7+
use crate::{EmbeddingService, Infrastructure, VectorIndex};
8+
9+
pub struct ForgeSuggestionService<F> {
10+
infra: Arc<F>,
11+
}
12+
13+
impl<F: Infrastructure> ForgeSuggestionService<F> {
14+
pub fn new(infra: Arc<F>) -> Self {
15+
Self { infra }
16+
}
17+
}
18+
19+
#[async_trait]
20+
impl<F: Infrastructure> SuggestionService for ForgeSuggestionService<F> {
21+
async fn search(&self, query: &str) -> Result<Vec<Suggestion>> {
22+
let embeddings = self.infra.embedding_service().embed(query).await?;
23+
let suggestions = self
24+
.infra
25+
.vector_index()
26+
.search(Query::new(embeddings).limit(5u64))
27+
.await?;
28+
Ok(suggestions.into_iter().map(|p| p.content).collect())
29+
}
30+
31+
async fn insert(&self, suggestion: Suggestion) -> Result<()> {
32+
let embeddings = self
33+
.infra
34+
.embedding_service()
35+
.embed(&suggestion.use_case)
36+
.await?;
37+
38+
let point = Point::new(suggestion, embeddings);
39+
self.infra.vector_index().store(point).await
40+
}
41+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use forge_domain::{Prompt, PromptService};
1+
use forge_domain::{Template, TemplateService};
22
use handlebars::Handlebars;
33
use rust_embed::Embed;
44
use serde::Serialize;
@@ -7,17 +7,17 @@ use serde::Serialize;
77
#[folder = "../../templates/"]
88
struct Templates;
99

10-
pub struct ForgePromptService {
10+
pub struct ForgeTemplateService {
1111
hb: Handlebars<'static>,
1212
}
1313

14-
impl Default for ForgePromptService {
14+
impl Default for ForgeTemplateService {
1515
fn default() -> Self {
1616
Self::new()
1717
}
1818
}
1919

20-
impl ForgePromptService {
20+
impl ForgeTemplateService {
2121
pub fn new() -> Self {
2222
let mut hb = Handlebars::new();
2323
hb.set_strict_mode(true);
@@ -31,10 +31,10 @@ impl ForgePromptService {
3131
}
3232

3333
#[async_trait::async_trait]
34-
impl PromptService for ForgePromptService {
34+
impl TemplateService for ForgeTemplateService {
3535
async fn render<T: Serialize + Send + Sync>(
3636
&self,
37-
prompt: &Prompt<T>,
37+
prompt: &Template<T>,
3838
ctx: &T,
3939
) -> anyhow::Result<String> {
4040
Ok(self.hb.render_template(prompt.template.as_str(), ctx)?)

crates/forge_app/src/tool_service.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::collections::HashMap;
22
use std::sync::Arc;
33

4-
use forge_domain::{Tool, ToolCallFull, ToolDefinition, ToolName, ToolResult, ToolService};
4+
use forge_domain::{
5+
SuggestionService, Tool, ToolCallFull, ToolDefinition, ToolName, ToolResult, ToolService,
6+
};
57
use tokio::time::{timeout, Duration};
68
use tracing::{debug, error};
79

@@ -15,8 +17,8 @@ pub struct ForgeToolService {
1517
}
1618

1719
impl ForgeToolService {
18-
pub fn new<F: Infrastructure>(infra: Arc<F>) -> Self {
19-
ForgeToolService::from_iter(crate::tools::tools(infra.clone()))
20+
pub fn new<F: Infrastructure, S: SuggestionService>(infra: Arc<F>, suggest: Arc<S>) -> Self {
21+
ForgeToolService::from_iter(crate::tools::tools(infra.clone(), suggest.clone()))
2022
}
2123
}
2224

crates/forge_app/src/tools/fs/fs_write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub struct FSWriteInput {
2424
/// Always provide absolute paths for file locations. The tool
2525
/// automatically handles the creation of any missing intermediary directories
2626
/// in the specified path.
27+
/// IMPORTANT: DO NOT attempt to use this tool to move or rename files, use the
28+
/// shell tool instead.
2729
#[derive(ToolDescription)]
2830
pub struct FSWrite;
2931

0 commit comments

Comments
 (0)