-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: retrieve logs * feat: use tauri path resolver * feat: display logs --------- Co-authored-by: paulclindo <[email protected]>
- Loading branch information
1 parent
b70973a
commit e40778f
Showing
7 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use tauri::Manager; | ||
|
||
#[tauri::command] | ||
pub async fn retrieve_logs(app_handle: tauri::AppHandle) -> Result<String, String> { | ||
let log_dir = app_handle.path().app_log_dir().map_err(|e| e.to_string())?; | ||
let product_name = app_handle | ||
.config() | ||
.product_name | ||
.clone() | ||
.unwrap_or("Shinkai Desktop".to_string()); | ||
let log_file = format!("{}/{}.log", log_dir.display(), product_name); | ||
|
||
let log_contents = match std::fs::read_to_string(log_file) { | ||
Ok(contents) => contents, | ||
Err(e) => { | ||
log::error!("Failed to read log file: {}", e); | ||
return Err("Failed to read log file".to_string()); | ||
} | ||
}; | ||
|
||
Ok(log_contents) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod fetch; | ||
pub mod galxe; | ||
pub mod hardware; | ||
pub mod logs; | ||
pub mod shinkai_node_manager_commands; | ||
pub mod spotlight_commands; | ||
pub mod fetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
QueryObserverOptions, | ||
useQuery, | ||
UseQueryResult | ||
} from '@tanstack/react-query'; | ||
import { invoke } from '@tauri-apps/api/core'; | ||
|
||
export const useRetrieveLogsQuery = ( | ||
options?: Omit<QueryObserverOptions, 'queryKey'>, | ||
): UseQueryResult<string, Error> => { | ||
const query = useQuery({ | ||
queryKey: ['retrieve_logs'], | ||
queryFn: (): Promise<string> => invoke('retrieve_logs'), | ||
...options, | ||
}); | ||
return { ...query } as UseQueryResult<string, Error>; | ||
}; | ||
|
||
export const retrieveLogs = async (): Promise<string> => { | ||
return invoke('retrieve_logs'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ import { z } from 'zod'; | |
|
||
import logo from '../../../src-tauri/icons/[email protected]'; | ||
import { OllamaModels } from '../../components/shinkai-node-manager/ollama-models'; | ||
import { useRetrieveLogsQuery } from '../../lib/shinkai-logs/logs-client'; | ||
import { ALLOWED_OLLAMA_MODELS } from '../../lib/shinkai-node-manager/ollama-models'; | ||
import { | ||
shinkaiNodeQueryClient, | ||
|
@@ -84,6 +85,7 @@ const App = () => { | |
const setLogout = useAuth((auth) => auth.setLogout); | ||
const { setShinkaiNodeOptions } = useShinkaiNodeManager(); | ||
const logsScrollRef = useRef<HTMLDivElement | null>(null); | ||
const tauriLogsScrollRef = useRef<HTMLDivElement | null>(null); | ||
const [isConfirmResetDialogOpened, setIsConfirmResetDialogOpened] = | ||
useState<boolean>(false); | ||
const { data: shinkaiNodeIsRunning } = useShinkaiNodeIsRunningQuery({ | ||
|
@@ -94,10 +96,11 @@ const App = () => { | |
}); | ||
const { data: lastNLogs } = useShinkaiNodeGetLastNLogsQuery( | ||
{ length: 100 }, | ||
{ | ||
refetchInterval: 1000, | ||
}, | ||
{ refetchInterval: 1000 }, | ||
); | ||
|
||
const { data: tauriLogs } = useRetrieveLogsQuery(); | ||
|
||
const { | ||
isPending: shinkaiNodeSpawnIsPending, | ||
mutateAsync: shinkaiNodeSpawn, | ||
|
@@ -314,7 +317,19 @@ const App = () => { | |
> | ||
<TabsList className="w-full"> | ||
<TabsTrigger className="grow" value="logs"> | ||
Logs | ||
Shinkai Node Logs | ||
</TabsTrigger> | ||
<TabsTrigger | ||
className="grow" | ||
onClick={() => { | ||
tauriLogsScrollRef.current?.scrollIntoView({ | ||
behavior: 'smooth', | ||
block: 'end', | ||
}); | ||
}} | ||
value="tauri-logs" | ||
> | ||
Tauri Logs | ||
</TabsTrigger> | ||
<TabsTrigger className="grow" value="options"> | ||
Options | ||
|
@@ -342,6 +357,16 @@ const App = () => { | |
</div> | ||
</ScrollArea> | ||
</TabsContent> | ||
<TabsContent className="h-full overflow-hidden" value="tauri-logs"> | ||
<ScrollArea className="flex h-full flex-1 flex-col overflow-auto [&>div>div]:!block"> | ||
<div | ||
className="text-gray-80 whitespace-pre-wrap p-1 font-mono text-xs leading-relaxed" | ||
ref={tauriLogsScrollRef} | ||
> | ||
{tauriLogs} | ||
</div> | ||
</ScrollArea> | ||
</TabsContent> | ||
<TabsContent className="h-full overflow-hidden" value="options"> | ||
<ScrollArea className="flex h-full flex-1 flex-col overflow-auto [&>div>div]:!block"> | ||
<div className="flex flex-row justify-end pr-4"> | ||
|