MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / spawn_draft_approve

Function spawn_draft_approve

crates/openshell-tui/src/lib.rs:1766–1802  ·  view source on GitHub ↗

Approve the currently selected draft chunk.

(app: &App, tx: mpsc::UnboundedSender<Event>)

Source from the content-addressed store, hash-verified

1764
1765/// Approve the currently selected draft chunk.
1766fn spawn_draft_approve(app: &App, tx: mpsc::UnboundedSender<Event>) {
1767 let mut client = app.client.clone();
1768 let name = match app.selected_sandbox_name() {
1769 Some(n) => n.to_string(),
1770 None => return,
1771 };
1772 let abs = app.draft_scroll + app.draft_selected;
1773 let chunk_id = match app.draft_chunks.get(abs) {
1774 Some(c) => c.id.clone(),
1775 None => return,
1776 };
1777 let rule_name = app
1778 .draft_chunks
1779 .get(abs)
1780 .map_or_else(String::new, |c| c.rule_name.clone());
1781
1782 tokio::spawn(async move {
1783 let req = openshell_core::proto::ApproveDraftChunkRequest { name, chunk_id };
1784 match tokio::time::timeout(Duration::from_secs(5), client.approve_draft_chunk(req)).await {
1785 Ok(Ok(resp)) => {
1786 let inner = resp.into_inner();
1787 let _ = tx.send(Event::DraftActionResult(Ok(format!(
1788 "Approved '{}' -> policy v{}",
1789 rule_name, inner.policy_version
1790 ))));
1791 }
1792 Ok(Err(e)) => {
1793 let _ = tx.send(Event::DraftActionResult(Err(e.message().to_string())));
1794 }
1795 Err(_) => {
1796 let _ = tx.send(Event::DraftActionResult(Err(
1797 "approve timed out".to_string()
1798 )));
1799 }
1800 }
1801 });
1802}
1803
1804/// Reject the currently selected draft chunk.
1805fn spawn_draft_reject(app: &App, tx: mpsc::UnboundedSender<Event>) {

Callers 1

runFunction · 0.85

Calls 5

selected_sandbox_nameMethod · 0.80
messageMethod · 0.80
spawnFunction · 0.50
getMethod · 0.45
approve_draft_chunkMethod · 0.45

Tested by

no test coverage detected