-
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.
- Loading branch information
1 parent
42a6ee1
commit 4e24f6f
Showing
8 changed files
with
763 additions
and
532 deletions.
There are no files selected for viewing
622 changes: 622 additions & 0 deletions
622
apps/shinkai-desktop/src/components/cron-task/component/cron-task.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
import { useGetRecurringTask } from '@shinkai_network/shinkai-node-state/v2/queries/getRecurringTask/useGetRecurringTask'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import CronTask from '../components/cron-task/component/cron-task'; | ||
import { useAuth } from '../store/auth'; | ||
|
||
export default function EditTaskPage() { | ||
const auth = useAuth((state) => state.auth); | ||
const { taskId } = useParams(); | ||
const { data: task, isSuccess: isGetRecurringTaskSuccess } = | ||
useGetRecurringTask({ | ||
nodeAddress: auth?.node_address ?? '', | ||
token: auth?.api_v2_key ?? '', | ||
recurringTaskId: taskId ?? '', | ||
}); | ||
|
||
return ( | ||
<CronTask | ||
initialValues={ | ||
isGetRecurringTaskSuccess | ||
? { | ||
action: task.action, | ||
cron: task.cron, | ||
task_id: task.task_id, | ||
created_at: task.created_at, | ||
last_modified: task.last_modified, | ||
description: task.description, | ||
name: task.name, | ||
} | ||
: undefined | ||
} | ||
mode="edit" | ||
/> | ||
); | ||
} |
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
48 changes: 48 additions & 0 deletions
48
libs/shinkai-node-state/src/v2/mutations/updateRecurringTask/index.ts
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,48 @@ | ||
import { setRecurringTask as setRecurringTaskApi } from '@shinkai_network/shinkai-message-ts/api/recurring-tasks/index'; | ||
|
||
import { UpdateRecurringTaskInput } from './types'; | ||
|
||
export const updateRecurringTask = async ({ | ||
nodeAddress, | ||
token, | ||
name, | ||
description, | ||
llmProvider, | ||
cronExpression, | ||
chatConfig, | ||
message, | ||
toolRouterKey, | ||
taskId, | ||
jobId, | ||
}: UpdateRecurringTaskInput) => { | ||
const response = await setRecurringTaskApi(nodeAddress, token, { | ||
cron_task_id: taskId, | ||
name: name, | ||
description: description, | ||
cron: cronExpression, | ||
action: { | ||
CreateJobWithConfigAndMessage: { | ||
config: chatConfig, | ||
job_creation_info: { | ||
associated_ui: null, | ||
is_hidden: false, | ||
scope: { | ||
vector_fs_folders: [], | ||
vector_fs_items: [], | ||
local_vrpack: [], | ||
local_vrkai: [], | ||
network_folders: [], | ||
}, | ||
}, | ||
message: { | ||
job_id: jobId, | ||
content: message, | ||
tool_router_key: toolRouterKey, | ||
|
||
files_inbox: '', | ||
}, | ||
}, | ||
}, | ||
}); | ||
return response; | ||
}; |
18 changes: 18 additions & 0 deletions
18
libs/shinkai-node-state/src/v2/mutations/updateRecurringTask/types.ts
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,18 @@ | ||
import { Token } from '@shinkai_network/shinkai-message-ts/api/general/types'; | ||
import { JobConfig } from '@shinkai_network/shinkai-message-ts/api/jobs/types'; | ||
import { CreateRecurringTaskResponse } from '@shinkai_network/shinkai-message-ts/api/recurring-tasks/types'; | ||
|
||
export type UpdateRecurringTaskOutput = CreateRecurringTaskResponse; | ||
|
||
export type UpdateRecurringTaskInput = Token & { | ||
nodeAddress: string; | ||
name: string; | ||
description?: string; | ||
taskId: string; | ||
jobId: string; | ||
cronExpression: string; | ||
message: string; | ||
toolRouterKey?: string; | ||
llmProvider: string; | ||
chatConfig: JobConfig; | ||
}; |
33 changes: 33 additions & 0 deletions
33
libs/shinkai-node-state/src/v2/mutations/updateRecurringTask/useUpdateRecurringTask.ts
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,33 @@ | ||
import { | ||
useMutation, | ||
type UseMutationOptions, | ||
useQueryClient, | ||
} from '@tanstack/react-query'; | ||
|
||
import { FunctionKeyV2 } from '../../constants'; | ||
import { APIError } from '../../types'; | ||
import { updateRecurringTask } from './index'; | ||
import { UpdateRecurringTaskInput, UpdateRecurringTaskOutput } from './types'; | ||
|
||
type Options = UseMutationOptions< | ||
UpdateRecurringTaskOutput, | ||
APIError, | ||
UpdateRecurringTaskInput | ||
>; | ||
|
||
export const useUpdateRecurringTask = (options?: Options) => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationFn: updateRecurringTask, | ||
...options, | ||
onSuccess: (response, variables, context) => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [FunctionKeyV2.GET_RECURRING_TASKS], | ||
}); | ||
|
||
if (options?.onSuccess) { | ||
options.onSuccess(response, variables, context); | ||
} | ||
}, | ||
}); | ||
}; |