Skip to content

Commit 18a7dc4

Browse files
committed
fix compile
1 parent d099ef8 commit 18a7dc4

3 files changed

Lines changed: 144 additions & 26 deletions

File tree

hindsight-cli/src/commands/explore.rs

Lines changed: 137 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct App {
7474

7575
documents: Vec<Map<String, Value>>,
7676
documents_state: ListState,
77+
viewing_document: Option<Map<String, Value>>,
7778

7879
// Recall state
7980
recall_query: String,
@@ -121,6 +122,7 @@ impl App {
121122

122123
documents: Vec::new(),
123124
documents_state: ListState::default(),
125+
viewing_document: None,
124126

125127
recall_query: String::new(),
126128
recall_results: Vec::new(),
@@ -459,12 +461,46 @@ impl App {
459461
}
460462
}
461463
}
464+
View::Documents(bank_id) => {
465+
if let Some(i) = self.documents_state.selected() {
466+
if let Some(doc) = self.documents.get(i) {
467+
// Fetch full document content
468+
let doc_id = doc.get("id")
469+
.and_then(|v| v.as_str())
470+
.unwrap_or("");
471+
472+
if !doc_id.is_empty() {
473+
match self.client.get_document(bank_id, doc_id, false) {
474+
Ok(full_doc) => {
475+
// Convert to Map for display
476+
let doc_map: Map<String, Value> = serde_json::from_value(
477+
serde_json::to_value(full_doc)?
478+
)?;
479+
self.viewing_document = Some(doc_map);
480+
self.status_message = format!("Viewing document: {}", doc_id);
481+
}
482+
Err(e) => {
483+
self.error_message = format!("Failed to load document: {}", e);
484+
}
485+
}
486+
}
487+
}
488+
}
489+
}
462490
_ => {}
463491
}
464492
Ok(())
465493
}
466494

467495
fn go_back(&mut self) {
496+
// If viewing a document, close it first
497+
if self.viewing_document.is_some() {
498+
self.viewing_document = None;
499+
self.status_message = "Closed document view".to_string();
500+
return;
501+
}
502+
503+
// Otherwise go back to previous view
468504
if let Some(prev_view) = self.view_history.pop() {
469505
self.view = prev_view;
470506
let _ = self.refresh();
@@ -479,6 +515,31 @@ impl App {
479515
}
480516
Ok(())
481517
}
518+
519+
fn delete_selected_document(&mut self) -> Result<()> {
520+
if let View::Documents(bank_id) = &self.view {
521+
if let Some(i) = self.documents_state.selected() {
522+
if let Some(doc) = self.documents.get(i) {
523+
let doc_id = doc.get("id")
524+
.and_then(|v| v.as_str())
525+
.unwrap_or("");
526+
527+
if !doc_id.is_empty() {
528+
match self.client.delete_document(bank_id, doc_id, false) {
529+
Ok(_) => {
530+
self.status_message = format!("Deleted document: {}", doc_id);
531+
self.refresh()?;
532+
}
533+
Err(e) => {
534+
self.error_message = format!("Failed to delete document: {}", e);
535+
}
536+
}
537+
}
538+
}
539+
}
540+
}
541+
Ok(())
542+
}
482543
}
483544

484545
fn ui(f: &mut Frame, app: &mut App) {
@@ -779,31 +840,77 @@ fn render_entities(f: &mut Frame, app: &mut App, area: Rect) {
779840
}
780841

781842
fn render_documents(f: &mut Frame, app: &mut App, area: Rect) {
782-
let items: Vec<ListItem> = app
783-
.documents
784-
.iter()
785-
.map(|doc| {
786-
let id = doc.get("id")
787-
.and_then(|v| v.as_str())
788-
.unwrap_or("unknown");
789-
let content_type = doc.get("content_type")
790-
.and_then(|v| v.as_str())
791-
.unwrap_or("unknown");
792-
let content = format!("{} ({})", id, content_type);
793-
ListItem::new(content).style(Style::default().fg(Color::White))
794-
})
795-
.collect();
843+
// If viewing a document, show its content
844+
if let Some(doc) = &app.viewing_document {
845+
let chunks = Layout::default()
846+
.direction(Direction::Vertical)
847+
.constraints([
848+
Constraint::Length(5), // Document metadata
849+
Constraint::Min(0), // Content
850+
])
851+
.split(area);
852+
853+
// Metadata section
854+
let doc_id = doc.get("id")
855+
.and_then(|v| v.as_str())
856+
.unwrap_or("unknown");
857+
let content_type = doc.get("content_type")
858+
.and_then(|v| v.as_str())
859+
.unwrap_or("unknown");
860+
let created_at = doc.get("created_at")
861+
.and_then(|v| v.as_str())
862+
.unwrap_or("unknown");
796863

797-
let list = List::new(items)
798-
.block(Block::default().borders(Borders::ALL).title("Documents"))
799-
.highlight_style(
800-
Style::default()
801-
.bg(Color::DarkGray)
802-
.add_modifier(Modifier::BOLD),
803-
)
804-
.highlight_symbol(">> ");
864+
let metadata_text = format!(
865+
"ID: {}\nType: {}\nCreated: {}\n",
866+
doc_id, content_type, created_at
867+
);
868+
869+
let metadata = Paragraph::new(metadata_text)
870+
.block(Block::default().borders(Borders::ALL).title("Document Metadata"))
871+
.style(Style::default().fg(Color::Cyan));
872+
873+
f.render_widget(metadata, chunks[0]);
874+
875+
// Content section
876+
let content = doc.get("content")
877+
.and_then(|v| v.as_str())
878+
.unwrap_or("No content available");
879+
880+
let content_widget = Paragraph::new(content)
881+
.block(Block::default().borders(Borders::ALL).title("Content (Esc to close)"))
882+
.wrap(Wrap { trim: false })
883+
.style(Style::default().fg(Color::White));
805884

806-
f.render_stateful_widget(list, area, &mut app.documents_state);
885+
f.render_widget(content_widget, chunks[1]);
886+
} else {
887+
// Show document list
888+
let items: Vec<ListItem> = app
889+
.documents
890+
.iter()
891+
.map(|doc| {
892+
let id = doc.get("id")
893+
.and_then(|v| v.as_str())
894+
.unwrap_or("unknown");
895+
let content_type = doc.get("content_type")
896+
.and_then(|v| v.as_str())
897+
.unwrap_or("unknown");
898+
let content = format!("{} ({})", id, content_type);
899+
ListItem::new(content).style(Style::default().fg(Color::White))
900+
})
901+
.collect();
902+
903+
let list = List::new(items)
904+
.block(Block::default().borders(Borders::ALL).title("Documents"))
905+
.highlight_style(
906+
Style::default()
907+
.bg(Color::DarkGray)
908+
.add_modifier(Modifier::BOLD),
909+
)
910+
.highlight_symbol(">> ");
911+
912+
f.render_stateful_widget(list, area, &mut app.documents_state);
913+
}
807914
}
808915

809916
fn render_recall(f: &mut Frame, app: &mut App, area: Rect) {
@@ -1010,6 +1117,13 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> Result<()> {
10101117
}
10111118
}
10121119

1120+
// Delete document
1121+
KeyCode::Delete => {
1122+
if matches!(app.view, View::Documents(_)) {
1123+
app.delete_selected_document()?;
1124+
}
1125+
}
1126+
10131127
_ => {}
10141128
}
10151129
}

hindsight-control-plane/src/app/api/operations/[agentId]/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export async function GET(
1111
client: lowLevelClient,
1212
path: { bank_id: agentId }
1313
});
14-
return NextResponse.json(response.data, { status: 200 });
14+
// Ensure proper JSON serialization
15+
const data = JSON.parse(JSON.stringify(response.data));
16+
return NextResponse.json(data, { status: 200 });
1517
} catch (error) {
1618
console.error('Error fetching operations:', error);
1719
return NextResponse.json(
@@ -42,7 +44,9 @@ export async function DELETE(
4244
path: { bank_id: agentId, operation_id: operationId }
4345
});
4446

45-
return NextResponse.json(response.data, { status: 200 });
47+
// Ensure proper JSON serialization
48+
const data = JSON.parse(JSON.stringify(response.data));
49+
return NextResponse.json(data, { status: 200 });
4650
} catch (error) {
4751
console.error('Error canceling operation:', error);
4852
return NextResponse.json(

hindsight-control-plane/src/app/api/stats/[agentId]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function GET(
77
) {
88
try {
99
const { agentId } = await params;
10-
const response = await sdk.getBankStats({
10+
const response = await sdk.getAgentStats({
1111
client: lowLevelClient,
1212
path: { bank_id: agentId }
1313
});

0 commit comments

Comments
 (0)