Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ov_cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use serde_json::Value;
use std::fs::File;
use std::path::Path;
use tempfile::{Builder, NamedTempFile};
use zip::write::FileOptions;
use url::Url;
use zip::CompressionMethod;
use zip::write::FileOptions;

use crate::error::{Error, Result};

Expand Down
36 changes: 19 additions & 17 deletions crates/ov_cli/src/commands/admin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};
use serde_json::json;

pub async fn create_account(
Expand All @@ -10,7 +10,9 @@ pub async fn create_account(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let response = client.admin_create_account(account_id, admin_user_id).await?;
let response = client
.admin_create_account(account_id, admin_user_id)
.await?;
output_success(&response, output_format, compact);
Ok(())
}
Expand All @@ -32,13 +34,12 @@ pub async fn delete_account(
compact: bool,
) -> Result<()> {
let response = client.admin_delete_account(account_id).await?;
let result = if response.is_null()
|| response.as_object().map(|o| o.is_empty()).unwrap_or(false)
{
json!({"account_id": account_id})
} else {
response
};
let result =
if response.is_null() || response.as_object().map(|o| o.is_empty()).unwrap_or(false) {
json!({"account_id": account_id})
} else {
response
};
output_success(&result, output_format, compact);
Ok(())
}
Expand All @@ -51,7 +52,9 @@ pub async fn register_user(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let response = client.admin_register_user(account_id, user_id, role).await?;
let response = client
.admin_register_user(account_id, user_id, role)
.await?;
output_success(&response, output_format, compact);
Ok(())
}
Expand All @@ -75,13 +78,12 @@ pub async fn remove_user(
compact: bool,
) -> Result<()> {
let response = client.admin_remove_user(account_id, user_id).await?;
let result = if response.is_null()
|| response.as_object().map(|o| o.is_empty()).unwrap_or(false)
{
json!({"account_id": account_id, "user_id": user_id})
} else {
response
};
let result =
if response.is_null() || response.as_object().map(|o| o.is_empty()).unwrap_or(false) {
json!({"account_id": account_id, "user_id": user_id})
} else {
response
};
output_success(&result, output_format, compact);
Ok(())
}
Expand Down
33 changes: 24 additions & 9 deletions crates/ov_cli/src/commands/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::time::Duration;

use clap::Parser;
use reqwest::Client;
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
use rustyline::error::ReadlineError;
use serde::{Deserialize, Serialize};
use termimad::MadSkin;

Expand Down Expand Up @@ -90,7 +90,7 @@ struct ChatResponse {
/// Stream event from SSE
#[derive(Debug, Deserialize)]
struct ChatStreamEvent {
event: String, // "reasoning", "tool_call", "tool_result", "response"
event: String, // "reasoning", "tool_call", "tool_result", "response"
data: serde_json::Value,
timestamp: Option<String>,
}
Expand Down Expand Up @@ -198,7 +198,11 @@ impl ChatCommand {
let mut buffer = String::new();
let mut final_message = String::new();

while let Some(chunk) = response.chunk().await.map_err(|e| Error::Network(format!("Stream error: {}", e)))? {
while let Some(chunk) = response
.chunk()
.await
.map_err(|e| Error::Network(format!("Stream error: {}", e)))?
{
let chunk_str = String::from_utf8_lossy(&chunk);
buffer.push_str(&chunk_str);

Expand All @@ -221,7 +225,8 @@ impl ChatCommand {
} else if let Some(obj) = event.data.as_object() {
if let Some(msg) = obj.get("message").and_then(|m| m.as_str()) {
final_message = msg.to_string();
} else if let Some(err) = obj.get("error").and_then(|e| e.as_str()) {
} else if let Some(err) = obj.get("error").and_then(|e| e.as_str())
{
eprintln!("\x1b[1;31mError: {}\x1b[0m", err);
}
}
Expand Down Expand Up @@ -290,7 +295,10 @@ impl ChatCommand {
}

// Send message
match self.send_interactive_message(client, input, &mut session_id).await {
match self
.send_interactive_message(client, input, &mut session_id)
.await
{
Ok(_) => {}
Err(e) => {
eprintln!("\x1b[1;31mError: {}\x1b[0m", e);
Expand Down Expand Up @@ -330,9 +338,11 @@ impl ChatCommand {
session_id: &mut Option<String>,
) -> Result<()> {
if self.stream {
self.send_interactive_message_stream(client, input, session_id).await
self.send_interactive_message_stream(client, input, session_id)
.await
} else {
self.send_interactive_message_non_stream(client, input, session_id).await
self.send_interactive_message_non_stream(client, input, session_id)
.await
}
}

Expand Down Expand Up @@ -431,7 +441,11 @@ impl ChatCommand {
let mut final_message = String::new();
let mut got_session_id = false;

while let Some(chunk) = response.chunk().await.map_err(|e| Error::Network(format!("Stream error: {}", e)))? {
while let Some(chunk) = response
.chunk()
.await
.map_err(|e| Error::Network(format!("Stream error: {}", e)))?
{
let chunk_str = String::from_utf8_lossy(&chunk);
buffer.push_str(&chunk_str);

Expand Down Expand Up @@ -464,7 +478,8 @@ impl ChatCommand {
} else if let Some(obj) = event.data.as_object() {
if let Some(msg) = obj.get("message").and_then(|m| m.as_str()) {
final_message = msg.to_string();
} else if let Some(err) = obj.get("error").and_then(|e| e.as_str()) {
} else if let Some(err) = obj.get("error").and_then(|e| e.as_str())
{
eprintln!("\x1b[1;31mError: {}\x1b[0m", err);
}
}
Expand Down
13 changes: 5 additions & 8 deletions crates/ov_cli/src/commands/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ pub async fn reindex(
Ok(())
}

pub async fn get(
client: &HttpClient,
uri: &str,
local_path: &str,
) -> Result<()> {
pub async fn get(client: &HttpClient, uri: &str, local_path: &str) -> Result<()> {
// Check if target path already exists
let path = Path::new(local_path);
if path.exists() {
return Err(crate::error::Error::Client(
format!("File already exists: {}", local_path)
));
return Err(crate::error::Error::Client(format!(
"File already exists: {}",
local_path
)));
}

// Ensure parent directory exists
Expand Down
25 changes: 22 additions & 3 deletions crates/ov_cli/src/commands/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn ls(
client: &HttpClient,
Expand All @@ -14,7 +14,17 @@ pub async fn ls(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let result = client.ls(uri, simple, recursive, output, abs_limit, show_all_hidden, node_limit).await?;
let result = client
.ls(
uri,
simple,
recursive,
output,
abs_limit,
show_all_hidden,
node_limit,
)
.await?;
output_success(&result, output_format, compact);
Ok(())
}
Expand All @@ -30,7 +40,16 @@ pub async fn tree(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let result = client.tree(uri, output, abs_limit, show_all_hidden, node_limit, level_limit).await?;
let result = client
.tree(
uri,
output,
abs_limit,
show_all_hidden,
node_limit,
level_limit,
)
.await?;
output_success(&result, output_format, compact);
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ov_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ pub mod admin;
pub mod chat;
pub mod content;
pub mod crypto;
pub mod search;
pub mod filesystem;
pub mod observer;
pub mod pack;
pub mod relations;
pub mod resources;
pub mod search;
pub mod session;
pub mod system;
pub mod resources;
pub mod relations;
pub mod pack;
20 changes: 4 additions & 16 deletions crates/ov_cli/src/commands/observer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn queue(
client: &HttpClient,
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
pub async fn queue(client: &HttpClient, output_format: OutputFormat, compact: bool) -> Result<()> {
let response: serde_json::Value = client.get("/api/v1/observer/queue", &[]).await?;
output_success(&response, output_format, compact);
Ok(())
Expand All @@ -22,11 +18,7 @@ pub async fn vikingdb(
Ok(())
}

pub async fn vlm(
client: &HttpClient,
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
pub async fn vlm(client: &HttpClient, output_format: OutputFormat, compact: bool) -> Result<()> {
let response: serde_json::Value = client.get("/api/v1/observer/vlm", &[]).await?;
output_success(&response, output_format, compact);
Ok(())
Expand All @@ -52,11 +44,7 @@ pub async fn retrieval(
Ok(())
}

pub async fn system(
client: &HttpClient,
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
pub async fn system(client: &HttpClient, output_format: OutputFormat, compact: bool) -> Result<()> {
let response: serde_json::Value = client.get("/api/v1/observer/system", &[]).await?;
output_success(&response, output_format, compact);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/ov_cli/src/commands/pack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn export(
client: &HttpClient,
Expand Down
2 changes: 1 addition & 1 deletion crates/ov_cli/src/commands/relations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn list_relations(
client: &HttpClient,
Expand Down
2 changes: 1 addition & 1 deletion crates/ov_cli/src/commands/resources.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn add_resource(
client: &HttpClient,
Expand Down
17 changes: 13 additions & 4 deletions crates/ov_cli/src/commands/search.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::HttpClient;
use crate::error::Result;
use crate::output::{output_success, OutputFormat};
use crate::output::{OutputFormat, output_success};

pub async fn find(
client: &HttpClient,
Expand All @@ -11,7 +11,9 @@ pub async fn find(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let result = client.find(query.to_string(), uri.to_string(), node_limit, threshold).await?;
let result = client
.find(query.to_string(), uri.to_string(), node_limit, threshold)
.await?;
output_success(&result, output_format, compact);
Ok(())
}
Expand All @@ -26,7 +28,15 @@ pub async fn search(
output_format: OutputFormat,
compact: bool,
) -> Result<()> {
let result = client.search(query.to_string(), uri.to_string(), session_id, node_limit, threshold).await?;
let result = client
.search(
query.to_string(),
uri.to_string(),
session_id,
node_limit,
threshold,
)
.await?;
output_success(&result, output_format, compact);
Ok(())
}
Expand All @@ -45,7 +55,6 @@ pub async fn grep(
Ok(())
}


pub async fn glob(
client: &HttpClient,
pattern: &str,
Expand Down
Loading
Loading