Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 66b74dd

Browse files
committed
Implement Action Dialect function for interactive walkthrough buttons
- Add Action function for creating interactive buttons in walkthroughs - Simple pass-through function with description, button text, and optional tell_agent - Register Action function in DialectInterpreter for both normal and test modes - Add comprehensive test with expect-test validation - Enables interactive elements in walkthroughs Example usage: {"action": {"description": "Generate code", "button": "Generate", "tell_agent": "Create auth system"}}
1 parent 0590322 commit 66b74dd

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

server/src/ide.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,45 @@ fn process_file(
372372
}
373373
Vec::new()
374374
}
375+
376+
/// Create an interactive action button for walkthroughs.
377+
///
378+
/// Examples:
379+
/// - `{"action": {"description": "Click to run tests", "button": "Run Tests"}}`
380+
/// - `{"action": {"description": "Generate boilerplate", "button": "Generate", "tell_agent": "Generate user authentication boilerplate"}}`
381+
#[derive(Deserialize)]
382+
pub struct Action {
383+
/// Description shown to user
384+
pub description: String,
385+
386+
/// Button text
387+
pub button: String,
388+
389+
/// Optional text to send to agent when clicked
390+
pub tell_agent: Option<String>,
391+
}
392+
393+
#[derive(Serialize)]
394+
pub struct ResolvedAction {
395+
pub description: String,
396+
pub button: String,
397+
pub tell_agent: Option<String>,
398+
}
399+
400+
impl<U: IpcClient> DialectFunction<U> for Action {
401+
type Output = ResolvedAction;
402+
403+
const DEFAULT_FIELD_NAME: Option<&'static str> = None;
404+
405+
async fn execute(
406+
self,
407+
_interpreter: &mut DialectInterpreter<U>,
408+
) -> anyhow::Result<Self::Output> {
409+
// Action is already resolved, just pass through
410+
Ok(ResolvedAction {
411+
description: self.description,
412+
button: self.button,
413+
tell_agent: self.tell_agent,
414+
})
415+
}
416+
}

server/src/ide/test.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,39 @@ async fn test_comment_function_with_symbol_def() {
729729
"#]]
730730
.assert_debug_eq(&result);
731731
}
732+
733+
#[tokio::test]
734+
async fn test_action_function() {
735+
use expect_test::expect;
736+
737+
let mock_client = MockIpcClient::new();
738+
let mut interpreter = DialectInterpreter::new(mock_client);
739+
interpreter.add_function::<FindDefinitions>();
740+
interpreter.add_function::<FindReferences>();
741+
interpreter.add_function::<crate::ide::Search>();
742+
interpreter.add_function::<crate::ide::GitDiff>();
743+
interpreter.add_function::<crate::ide::Comment>();
744+
interpreter.add_function::<crate::ide::Action>();
745+
746+
// Test action with tell_agent
747+
let program = serde_json::json!({
748+
"action": {
749+
"description": "Generate authentication boilerplate code",
750+
"button": "Generate Auth",
751+
"tell_agent": "Create a complete authentication system with login, logout, and middleware"
752+
}
753+
});
754+
755+
let result = interpreter.evaluate(program).await;
756+
757+
expect![[r#"
758+
Ok(
759+
Object {
760+
"button": String("Generate Auth"),
761+
"description": String("Generate authentication boilerplate code"),
762+
"tell_agent": String("Create a complete authentication system with login, logout, and middleware"),
763+
},
764+
)
765+
"#]]
766+
.assert_debug_eq(&result);
767+
}

server/src/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl DialecticServer {
7474
interpreter.add_function::<crate::ide::Search>();
7575
interpreter.add_function::<crate::ide::GitDiff>();
7676
interpreter.add_function::<crate::ide::Comment>();
77+
interpreter.add_function::<crate::ide::Action>();
7778

7879
Ok(Self {
7980
ipc: ipc.clone(),
@@ -178,6 +179,7 @@ impl DialecticServer {
178179
interpreter.add_function::<crate::ide::Search>();
179180
interpreter.add_function::<crate::ide::GitDiff>();
180181
interpreter.add_function::<crate::ide::Comment>();
182+
interpreter.add_function::<crate::ide::Action>();
181183

182184
Self {
183185
ipc,

0 commit comments

Comments
 (0)