Skip to content

Commit

Permalink
feat: cron task updates (#578)
Browse files Browse the repository at this point in the history
* fix: only enable test if its AI cloud

* fix: hidden true for cron tasks

* feat: add suggestions crons

* fix: add job id
  • Loading branch information
paulclindo authored Dec 21, 2024
1 parent a029ae3 commit 175743a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useCreateRecurringTask } from '@shinkai_network/shinkai-node-state/v2/m
import { useUpdateRecurringTask } from '@shinkai_network/shinkai-node-state/v2/mutations/updateRecurringTask/useUpdateRecurringTask';
import { useGetTools } from '@shinkai_network/shinkai-node-state/v2/queries/getToolsList/useGetToolsList';
import {
Badge,
Button,
DropdownMenu,
DropdownMenuContent,
Expand Down Expand Up @@ -270,7 +271,6 @@ function CronTask({ mode, initialValues }: CronTaskProps) {
<TextField autoFocus field={field} label="Task Name" />
)}
/>

<FormField
control={form.control}
name="description"
Expand All @@ -289,7 +289,6 @@ function CronTask({ mode, initialValues }: CronTaskProps) {
/>
)}
/>

<FormField
control={form.control}
name="cronExpression"
Expand All @@ -312,6 +311,41 @@ function CronTask({ mode, initialValues }: CronTaskProps) {
</span>
</div>
)}
<div className="flex flex-wrap gap-2">
{[
{
label: 'every 5 min',
cron: '*/5 * * * *',
},
{
label: 'every 5 hours',
cron: '0 */5 * * *',
},
{
label: 'every monday at 8am',
cron: '0 8 * * 1',
},
{
label: 'every january 1st at 12am',
cron: '0 0 1 1 *',
},
{
label: 'every 1st of the month at 12pm',
cron: '0 12 1 * *',
},
].map((item) => (
<Badge
className="cursor-pointer hover:bg-gray-400"
key={item.cron}
onClick={() => {
form.setValue('cronExpression', item.cron);
}}
variant="outline"
>
<span className="text-xs">{item.label}</span>
</Badge>
))}
</div>
</div>
<div className="space-y-4">
<div className="space-y-4">
Expand Down
28 changes: 15 additions & 13 deletions apps/shinkai-desktop/src/pages/add-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,24 @@ const AddAIPage = () => {
isLoading={isPending}
size="sm"
type="submit"
variant="outline"
variant={currentModel === Models.Ollama ? 'default' : 'outline'}
>
{t('llmProviders.add')}
</Button>
<Button
className="w-full"
disabled={isPending}
isLoading={isPending}
onClick={() => {
addAgentForm.handleSubmit(handleTestAndSave)();
}}
size="sm"
type="button"
>
Test & Add AI
</Button>
{currentModel !== Models.Ollama && (
<Button
className="w-full"
disabled={isPending}
isLoading={isPending}
onClick={() => {
addAgentForm.handleSubmit(handleTestAndSave)();
}}
size="sm"
type="button"
>
Test & Add AI
</Button>
)}
</div>
)}
</form>
Expand Down
21 changes: 17 additions & 4 deletions apps/shinkai-desktop/src/pages/task-logs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DialogClose } from '@radix-ui/react-dialog';
import { DotsVerticalIcon } from '@radix-ui/react-icons';
import { useTranslation } from '@shinkai_network/shinkai-i18n';
import { buildInboxIdFromJobId } from '@shinkai_network/shinkai-message-ts/utils/inbox_name_handler';
import { useRemoveRecurringTask } from '@shinkai_network/shinkai-node-state/v2/mutations/removeRecurringTask/useRemoveRecurringTask';
import { useGetRecurringTask } from '@shinkai_network/shinkai-node-state/v2/queries/getRecurringTask/useGetRecurringTask';
import { useGetRecurringTaskLogs } from '@shinkai_network/shinkai-node-state/v2/queries/getRecurringTaskLogs/useGetRecurringTaskLogs';
Expand Down Expand Up @@ -38,7 +39,7 @@ import {
XCircle,
} from 'lucide-react';
import React from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { Link, useNavigate, useParams } from 'react-router-dom';
import { toast } from 'sonner';

import { useAuth } from '../store/auth';
Expand Down Expand Up @@ -70,7 +71,11 @@ export const TaskLogs = () => {
});

return (
<SubpageLayout alignLeft className="max-w-4xl px-4" title="Scheduled Task Logs">
<SubpageLayout
alignLeft
className="max-w-4xl px-4"
title="Scheduled Task Logs"
>
{isGetRecurringTaskPending && (
<div className="p-4 text-center text-sm">
<p className="text-white">...</p>
Expand Down Expand Up @@ -144,14 +149,15 @@ export const TaskLogs = () => {
)}
{isSuccess && logs.length > 0 && (
<div className="divide-gray-375 divide-y py-2">
<div className="grid grid-cols-[360px_100px_1fr] items-center gap-6 py-1.5 font-mono text-xs text-gray-50">
<div className="grid grid-cols-[360px_100px_100px_1fr] items-center gap-6 py-1.5 font-mono text-xs text-gray-50">
<span>Execution Time</span>
<span>Status</span>
<span>Chat</span>
<span>Message</span>
</div>
{logs.map((log) => (
<div
className="grid grid-cols-[360px_100px_1fr] items-center gap-6 py-3 text-xs"
className="grid grid-cols-[360px_100px_100px_1fr] items-center gap-6 py-3 text-xs"
key={log.execution_time}
>
<div className="text-muted-foreground shrink-0 font-mono">
Expand All @@ -168,6 +174,13 @@ export const TaskLogs = () => {
{log.success ? 'Success' : 'Failed'}
</div>
</div>

<Link
className="text-gray-80 font-mono underline"
to={`/inboxes/${encodeURIComponent(buildInboxIdFromJobId(log.job_id))}`}
>
Go to chat
</Link>
<div className="text-gray-80 font-mono">
{log.error_message || '-'}
</div>
Expand Down
1 change: 1 addition & 0 deletions libs/shinkai-message-ts/src/api/recurring-tasks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ export type GetRecurringTaskLogsResponse = {
execution_time: string;
success: boolean;
error_message: string;
job_id: string;
}[];
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const createRecurringTask = async ({
network_folders: [],
},
associated_ui: null,
is_hidden: false,
is_hidden: true,
},
});

Expand All @@ -39,7 +39,7 @@ export const createRecurringTask = async ({
config: chatConfig,
job_creation_info: {
associated_ui: null,
is_hidden: false,
is_hidden: true,
scope: {
vector_fs_folders: [],
vector_fs_items: [],
Expand Down

0 comments on commit 175743a

Please sign in to comment.