Skip to content

Commit 9cb5012

Browse files
authoredJan 2, 2025··
Extract prompt input popup logic to makepad (#332)
* mofa fake multi servers * always insert default mofa address * use command text input for prompt input * update Cargo.toml to use command text input branch * back to rik

File tree

6 files changed

+248
-498
lines changed

6 files changed

+248
-498
lines changed
 

‎Cargo.lock

+55-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ members = [
66
"moly-protocol",
77
"moly-backend",
88
"moly-fake-backend",
9-
"moly-mofa"
9+
"moly-mofa",
1010
]
1111
exclude = ["packaging/before-packaging-command"]
1212

1313
[package]
1414
name = "moly"
1515
version = "0.1.0"
1616
edition = "2021"
17-
rust-version = "1.79" ## required by cargo-packager
17+
rust-version = "1.79" ## required by cargo-packager
1818
description = "Desktop app for downloading and chatting with AI LLMs"
1919

2020
## Rename the binary to `_moly_app` to avoid naming conflicts
@@ -28,7 +28,7 @@ path = "src/main.rs"
2828
moly-protocol = { path = "moly-protocol" }
2929
moly-backend = { path = "moly-backend" }
3030
moly-fake-backend = { path = "moly-fake-backend" }
31-
moly-mofa = { path = "moly-mofa"}
31+
moly-mofa = { path = "moly-mofa" }
3232

3333
makepad-widgets = { git = "https://github.com/makepad/makepad", branch = "rik" }
3434
makepad-code-editor = { git = "https://github.com/makepad/makepad", branch = "rik" }

‎src/chat/chat_panel.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,11 @@ impl ChatPanel {
651651
mode: PromptInputMode,
652652
button: PromptInputButton,
653653
) {
654-
let prompt_input = self.text_input(id!(main_prompt_input.prompt));
654+
let prompt = self.command_text_input(id!(main_prompt_input.prompt));
655+
let prompt_text_input = prompt.text_input_ref();
655656

656657
let enabled = match mode {
657-
PromptInputMode::Enabled => !prompt_input.text().is_empty(),
658+
PromptInputMode::Enabled => !prompt_text_input.text().is_empty(),
658659
PromptInputMode::Disabled => false,
659660
};
660661

@@ -665,7 +666,7 @@ impl ChatPanel {
665666
(vec3(0.816, 0.835, 0.867), 0.0)
666667
};
667668

668-
prompt_input.apply_over(
669+
prompt_text_input.apply_over(
669670
cx,
670671
live! {
671672
draw_text: { prompt_enabled: (prompt_enabled) }
@@ -736,19 +737,21 @@ impl ChatPanel {
736737
}
737738

738739
fn handle_prompt_input_actions(&mut self, cx: &mut Cx, actions: &Actions, scope: &mut Scope) {
739-
let prompt_input = self.text_input(id!(main_prompt_input.prompt));
740-
if let Some(_text) = prompt_input.changed(actions) {
740+
let prompt = self.command_text_input(id!(main_prompt_input.prompt));
741+
let prompt_text_input = prompt.text_input_ref();
742+
743+
if let Some(_text) = prompt_text_input.changed(actions) {
741744
self.redraw(cx);
742745
}
743746

744747
if self
745748
.button(id!(main_prompt_input.prompt_send_button))
746749
.clicked(&actions)
747750
{
748-
self.send_message(cx, scope, prompt_input.text(), None);
751+
self.send_message(cx, scope, prompt_text_input.text(), None);
749752
}
750753

751-
if let Some(prompt) = prompt_input.returned(actions) {
754+
if let Some(prompt) = prompt_text_input.returned(actions) {
752755
self.send_message(cx, scope, prompt, None);
753756
}
754757
}

‎src/chat/entity_button.rs

+8
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,18 @@ pub struct EntityButton {
122122

123123
#[rust]
124124
entity: Option<ChatEntityId>,
125+
126+
/// Do not listen to events. Make this fully read-only.
127+
#[live]
128+
pub deaf: bool,
125129
}
126130

127131
impl Widget for EntityButton {
128132
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
133+
if self.deaf {
134+
return;
135+
}
136+
129137
self.view.handle_event(cx, event, scope);
130138
}
131139

‎src/chat/prompt_input.rs

+160-433
Large diffs are not rendered by default.

‎src/data/chats/chat_entity.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ impl<'a> ChatEntityRef<'a> {
3535
}
3636
}
3737
}
38+
39+
impl<'a> From<&'a MofaAgent> for ChatEntityRef<'a> {
40+
fn from(agent: &'a MofaAgent) -> Self {
41+
ChatEntityRef::Agent(agent)
42+
}
43+
}
44+
45+
impl<'a> From<&'a File> for ChatEntityRef<'a> {
46+
fn from(file: &'a File) -> Self {
47+
ChatEntityRef::ModelFile(file)
48+
}
49+
}

0 commit comments

Comments
 (0)
Please sign in to comment.