Skip to content

Commit

Permalink
- improve: local data state (#401)
Browse files Browse the repository at this point in the history
* - fix: remove IDENTITY from .scret

* - fix: add env just if has value

* - fix: clear shinkai node options from app data

* - fix: set default options when remove storage

* - fix: clear default agent when logout

* - bump: shinkai-node version 0.7.28

* - ci: bump version v0.7.29
  • Loading branch information
agallardol authored Aug 5, 2024
1 parent 51409b0 commit 0ac50dd
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci-healchecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Download side binaries
env:
ARCH: x86_64-unknown-linux-gnu
SHINKAI_NODE_VERSION: v0.7.27
SHINKAI_NODE_VERSION: v0.7.28
OLLAMA_VERSION: v0.3.3
run: |
npx ts-node ./ci-scripts/download-side-binaries.ts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ jobs:
- name: Download side binaries
env:
ARCH: ${{ matrix.arch }}
SHINKAI_NODE_VERSION: v0.7.27
SHINKAI_NODE_VERSION: v0.7.28
OLLAMA_VERSION: v0.3.3
run: |
npx ts-node ./ci-scripts/download-side-binaries.ts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
- name: Download side binaries
env:
ARCH: ${{ matrix.arch }}
SHINKAI_NODE_VERSION: v0.7.27
SHINKAI_NODE_VERSION: v0.7.28
OLLAMA_VERSION: v0.3.3
run: |
npx ts-node ./ci-scripts/download-side-binaries.ts
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ $ git clone https://github.com/dcSpark/shinkai-apps
```
ARCH="aarch64-apple-darwin" \
OLLAMA_VERSION="v0.3.3" \
SHINKAI_NODE_VERSION="v0.7.27" \
SHINKAI_NODE_VERSION="v0.7.28" \
npx ts-node ./ci-scripts/download-side-binaries.ts
```

#### Linux
```
ARCH="x86_64-unknown-linux-gnu" \
OLLAMA_VERSION="v0.3.3"\
SHINKAI_NODE_VERSION="v0.7.27" \
SHINKAI_NODE_VERSION="v0.7.28" \
npx ts-node ./ci-scripts/download-side-binaries.ts
```

#### Windows
```
$ENV:OLLAMA_VERSION="v0.3.3"
$ENV:SHINKAI_NODE_VERSION="v0.7.27"
$ENV:SHINKAI_NODE_VERSION="v0.7.28"
$ENV:ARCH="x86_64-pc-windows-msvc"
npx ts-node ./ci-scripts/download-side-binaries.ts
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pub fn options_to_env<T: serde::Serialize>(options: &T) -> HashMap<String, Strin
let options_reflection = serde_json::to_value(options).unwrap();
for (key, value) in options_reflection.as_object().unwrap() {
let env_key = key.to_uppercase();
let env_value = value.as_str().unwrap_or_default().to_string();
env.insert(env_key, env_value);
if let Some(env_value) = value.as_str() {
env.insert(env_key, env_value.to_string());
}
}
env
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ impl ShinkaiNodeProcessHandler {
fs::remove_dir_all(path).map_err(|e| format!("Failed to remove directory: {}", e))?;
} else {
if preserve_keys && path.ends_with(".secret") {
// Delete the line starting with 'GLOBAL_IDENTITY_NAME=' in .secret file
if path.file_name().unwrap() == ".secret" {
let content = fs::read_to_string(&path)
.map_err(|e| format!("Failed to read .secret file: {}", e))?;
let new_content: String = content
.lines()
.filter(|line| !line.starts_with("GLOBAL_IDENTITY_NAME="))
.collect::<Vec<&str>>()
.join("\n");
fs::write(&path, new_content)
.map_err(|e| format!("Failed to write updated .secret file: {}", e))?;
}
continue;
}
fs::remove_file(path).map_err(|e| format!("Failed to remove file: {}", e))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
useShinkaiNodeRemoveStorageMutation,
useShinkaiNodeSpawnMutation,
} from '../lib/shinkai-node-manager/shinkai-node-manager-client';
import { useShinkaiNodeManager } from '../store/shinkai-node-manager';

export const ResetStorageBeforeConnectConfirmationPrompt = ({
onCancel,
onRestore,
onReset,
...props
}: {
Expand All @@ -29,7 +29,7 @@ export const ResetStorageBeforeConnectConfirmationPrompt = ({
} & AlertDialogProps) => {
// const navigate = useNavigate();
const { t } = useTranslation();

const { setShinkaiNodeOptions } = useShinkaiNodeManager();
const { mutateAsync: shinkaiNodeKill } = useShinkaiNodeKillMutation();
const { mutateAsync: shinkaiNodeSpawn } = useShinkaiNodeSpawnMutation();
const { mutateAsync: shinkaiNodeRemoveStorage } =
Expand All @@ -51,6 +51,7 @@ export const ResetStorageBeforeConnectConfirmationPrompt = ({
const reset = async (preserveKeys: boolean) => {
await shinkaiNodeKill();
await shinkaiNodeRemoveStorage({ preserveKeys });
setShinkaiNodeOptions(null);
await shinkaiNodeSpawn();
if (typeof onReset === 'function') {
onReset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ export const useShinkaiNodeRemoveStorageMutation = (
>,
) => {
const response = useMutation({
mutationFn: (
mutationFn: async (
options: Partial<ShinkaiNodeRemoveStorageOptions>,
): Promise<void> => {
await invoke('shinkai_node_set_default_options');
return invoke('shinkai_node_remove_storage', {
preserveKeys: options?.preserveKeys,
});
Expand Down
14 changes: 14 additions & 0 deletions apps/shinkai-desktop/src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { LocaleMode, switchLanguage } from '@shinkai_network/shinkai-i18n';
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';

import { SetupData, useAuth } from './auth';

type SettingsStore = {
defaultAgentId: string;
setDefaultAgentId: (defaultAgentId: string) => void;
Expand Down Expand Up @@ -76,3 +78,15 @@ export const useSettings = create<SettingsStore>()(
),
),
);

useAuth.subscribe((state, prevState) => {
handleAuthSideEffect(state.auth, prevState.auth);
});

const handleAuthSideEffect = async (auth: SetupData | null, prevAuth: SetupData | null) => {
// SignOut case
if (prevAuth && !auth) {
useSettings.getState().setDefaultAgentId('');
return;
}
};
2 changes: 1 addition & 1 deletion apps/shinkai-desktop/src/store/shinkai-node-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ShinkaiNodeManagerStore = {
setIsInUse: (value: boolean) => void;
shinkaiNodeOptions: Partial<ShinkaiNodeOptions> | null;
setShinkaiNodeOptions: (
shinkaiNodeOptions: Partial<ShinkaiNodeOptions>,
shinkaiNodeOptions: Partial<ShinkaiNodeOptions> | null,
) => void;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ const App = () => {
isPending: shinkaiNodeRemoveStorageIsPending,
mutateAsync: shinkaiNodeRemoveStorage,
} = useShinkaiNodeRemoveStorageMutation({
onSuccess: () => {
onSuccess: async () => {
successRemovingShinkaiNodeStorageToast();
setShinkaiNodeOptions(null);
setLogout();
},
onError: () => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shinkai/source",
"version": "0.7.28",
"version": "0.7.29",
"license": "SEE LICENSE IN LICENSE",
"files": [
"LICENSE"
Expand Down

0 comments on commit 0ac50dd

Please sign in to comment.