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
119 changes: 85 additions & 34 deletions crates/ov_cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,30 +433,63 @@ impl HttpClient {
directly_upload_media: bool,
) -> Result<serde_json::Value> {
let path_obj = Path::new(path);

// Check if it's a local directory and not a local server
if path_obj.exists() && path_obj.is_dir() && !self.is_local_server() {
// Zip the directory
let zip_file = self.zip_directory(path_obj)?;
let temp_path = self.upload_temp_file(zip_file.path()).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"target": target,
"reason": reason,
"instruction": instruction,
"wait": wait,
"timeout": timeout,
"strict": strict,
"ignore_dirs": ignore_dirs,
"include": include,
"exclude": exclude,
"directly_upload_media": directly_upload_media,
});

self.post("/api/v1/resources", &body).await

if path_obj.exists() && !self.is_local_server() {
if path_obj.is_dir() {
let zip_file = self.zip_directory(path_obj)?;
let temp_path = self.upload_temp_file(zip_file.path()).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"target": target,
"reason": reason,
"instruction": instruction,
"wait": wait,
"timeout": timeout,
"strict": strict,
"ignore_dirs": ignore_dirs,
"include": include,
"exclude": exclude,
"directly_upload_media": directly_upload_media,
});

self.post("/api/v1/resources", &body).await
} else if path_obj.is_file() {
let temp_path = self.upload_temp_file(path_obj).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"target": target,
"reason": reason,
"instruction": instruction,
"wait": wait,
"timeout": timeout,
"strict": strict,
"ignore_dirs": ignore_dirs,
"include": include,
"exclude": exclude,
"directly_upload_media": directly_upload_media,
});

self.post("/api/v1/resources", &body).await
} else {
let body = serde_json::json!({
"path": path,
"target": target,
"reason": reason,
"instruction": instruction,
"wait": wait,
"timeout": timeout,
"strict": strict,
"ignore_dirs": ignore_dirs,
"include": include,
"exclude": exclude,
"directly_upload_media": directly_upload_media,
});

self.post("/api/v1/resources", &body).await
}
} else {
// Regular case - use path directly
let body = serde_json::json!({
"path": path,
"target": target,
Expand All @@ -470,7 +503,7 @@ impl HttpClient {
"exclude": exclude,
"directly_upload_media": directly_upload_media,
});

self.post("/api/v1/resources", &body).await
}
}
Expand All @@ -483,16 +516,34 @@ impl HttpClient {
) -> Result<serde_json::Value> {
let path_obj = Path::new(data);

if path_obj.exists() && path_obj.is_dir() && !self.is_local_server() {
let zip_file = self.zip_directory(path_obj)?;
let temp_path = self.upload_temp_file(zip_file.path()).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"wait": wait,
"timeout": timeout,
});
self.post("/api/v1/skills", &body).await
if path_obj.exists() && !self.is_local_server() {
if path_obj.is_dir() {
let zip_file = self.zip_directory(path_obj)?;
let temp_path = self.upload_temp_file(zip_file.path()).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"wait": wait,
"timeout": timeout,
});
self.post("/api/v1/skills", &body).await
} else if path_obj.is_file() {
let temp_path = self.upload_temp_file(path_obj).await?;

let body = serde_json::json!({
"temp_path": temp_path,
"wait": wait,
"timeout": timeout,
});
self.post("/api/v1/skills", &body).await
} else {
let body = serde_json::json!({
"data": data,
"wait": wait,
"timeout": timeout,
});
self.post("/api/v1/skills", &body).await
}
} else {
let body = serde_json::json!({
"data": data,
Expand Down
10 changes: 10 additions & 0 deletions crates/ov_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::PathBuf;

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

const OPENVIKING_CLI_CONFIG_ENV: &str = "OPENVIKING_CLI_CONFIG_FILE";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
#[serde(default = "default_url")]
Expand Down Expand Up @@ -53,6 +55,14 @@ impl Config {
}

pub fn load_default() -> Result<Self> {
// Resolution order: env var > default path
if let Ok(env_path) = std::env::var(OPENVIKING_CLI_CONFIG_ENV) {
let p = PathBuf::from(env_path);
if p.exists() {
return Self::from_file(&p.to_string_lossy());
}
}

let config_path = default_config_path()?;
if config_path.exists() {
Self::from_file(&config_path.to_string_lossy())
Expand Down
8 changes: 4 additions & 4 deletions crates/ov_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ enum Commands {
/// Wait until processing is complete
#[arg(long)]
wait: bool,
/// Wait timeout in seconds
/// Wait timeout in seconds (only used with --wait)
#[arg(long)]
timeout: f64,
timeout: Option<f64>,
/// No strict mode for directory scanning
#[arg(long = "no-strict", default_value_t = false)]
no_strict: bool,
Expand Down Expand Up @@ -588,7 +588,7 @@ async fn handle_add_resource(
reason: String,
instruction: String,
wait: bool,
timeout: f64,
timeout: Option<f64>,
no_strict: bool,
ignore_dirs: Option<String>,
include: Option<String>,
Expand Down Expand Up @@ -635,7 +635,7 @@ async fn handle_add_resource(
reason,
instruction,
wait,
Some(timeout),
timeout,
strict,
ignore_dirs,
include,
Expand Down
36 changes: 24 additions & 12 deletions openviking_cli/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,19 @@ async def add_resource(
}

path_obj = Path(path)
if path_obj.exists() and path_obj.is_dir() and not self._is_local_server():
zip_path = self._zip_directory(path)
try:
temp_path = await self._upload_temp_file(zip_path)
if path_obj.exists() and not self._is_local_server():
if path_obj.is_dir():
zip_path = self._zip_directory(path)
try:
temp_path = await self._upload_temp_file(zip_path)
request_data["temp_path"] = temp_path
finally:
Path(zip_path).unlink(missing_ok=True)
elif path_obj.is_file():
temp_path = await self._upload_temp_file(path)
request_data["temp_path"] = temp_path
finally:
Path(zip_path).unlink(missing_ok=True)
else:
request_data["path"] = path
else:
request_data["path"] = path

Expand All @@ -334,13 +340,19 @@ async def add_skill(

if isinstance(data, str):
path_obj = Path(data)
if path_obj.exists() and path_obj.is_dir() and not self._is_local_server():
zip_path = self._zip_directory(data)
try:
temp_path = await self._upload_temp_file(zip_path)
if path_obj.exists() and not self._is_local_server():
if path_obj.is_dir():
zip_path = self._zip_directory(data)
try:
temp_path = await self._upload_temp_file(zip_path)
request_data["temp_path"] = temp_path
finally:
Path(zip_path).unlink(missing_ok=True)
elif path_obj.is_file():
temp_path = await self._upload_temp_file(data)
request_data["temp_path"] = temp_path
finally:
Path(zip_path).unlink(missing_ok=True)
else:
request_data["data"] = data
else:
request_data["data"] = data
else:
Expand Down
Loading