mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 08:36:44 +00:00
Go-live runtime sync and control plane hardening (#1)
* Implement Mika runtime sync and go-live controls * Add CI validation workflow * Align CI with validated runtime checks * Fix Mika CI install workflow
This commit is contained in:
parent
cb54fa4666
commit
d87ea2657c
31 changed files with 4019 additions and 95 deletions
|
|
@ -23,6 +23,7 @@ import {
|
|||
useUpdateCronjobStatus,
|
||||
} from "@/hooks/use-cronjobs";
|
||||
import { useAvailableMcps, useUserIntegrations } from "@/hooks/use-integrations";
|
||||
import { syncAgentRuntime } from "@/lib/sync-agent-runtime";
|
||||
|
||||
interface Props {
|
||||
job: ScheduledJob;
|
||||
|
|
@ -45,6 +46,8 @@ export function CronjobCard({ job }: Props) {
|
|||
|
||||
const isActive = job.status === "active";
|
||||
const isAutoPaused = job.status === "auto_paused";
|
||||
const hasRuntimeError = job.runtime_state === "error" || job.runtime_last_status === "error";
|
||||
const runtimeErrorText = job.runtime_last_delivery_error ?? job.runtime_last_error;
|
||||
|
||||
async function toggle() {
|
||||
try {
|
||||
|
|
@ -53,6 +56,11 @@ export function CronjobCard({ job }: Props) {
|
|||
status: isActive ? "paused" : "active",
|
||||
});
|
||||
toast.success(isActive ? "Automação pausada." : "Automação ativada.");
|
||||
|
||||
const { error: syncError } = await syncAgentRuntime(job.agent_instance_id, "cronjobs");
|
||||
if (syncError) {
|
||||
toast.warning("Status salvo, mas o runtime do agente não sincronizou.");
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "Erro ao atualizar.");
|
||||
}
|
||||
|
|
@ -63,6 +71,11 @@ export function CronjobCard({ job }: Props) {
|
|||
await deleteMut.mutateAsync(job.id);
|
||||
toast.success("Automação excluída.");
|
||||
setConfirmDelete(false);
|
||||
|
||||
const { error: syncError } = await syncAgentRuntime(job.agent_instance_id, "cronjobs");
|
||||
if (syncError) {
|
||||
toast.warning("Automação removida, mas o runtime do agente não sincronizou.");
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "Erro ao excluir.");
|
||||
}
|
||||
|
|
@ -76,11 +89,15 @@ export function CronjobCard({ job }: Props) {
|
|||
<h3 className="font-semibold truncate">{job.name}</h3>
|
||||
{isActive && <Badge variant="success">Ativa</Badge>}
|
||||
{job.status === "paused" && <Badge variant="secondary">Pausada</Badge>}
|
||||
{job.status === "error" && <Badge variant="destructive">Erro</Badge>}
|
||||
{isAutoPaused && (
|
||||
<Badge variant="destructive" className="gap-1">
|
||||
<AlertTriangle className="h-3 w-3" /> Auto-pausada
|
||||
</Badge>
|
||||
)}
|
||||
{hasRuntimeError && !isAutoPaused && (
|
||||
<Badge variant="destructive">Runtime com erro</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground mt-1 line-clamp-2">
|
||||
{job.human_readable}
|
||||
|
|
@ -92,6 +109,10 @@ export function CronjobCard({ job }: Props) {
|
|||
<p className="text-xs text-destructive">{job.auto_paused_reason}</p>
|
||||
)}
|
||||
|
||||
{hasRuntimeError && runtimeErrorText && (
|
||||
<p className="text-xs text-destructive">{runtimeErrorText}</p>
|
||||
)}
|
||||
|
||||
{missingMcps.length > 0 && isActive && (
|
||||
<div className="rounded-md border border-amber-500/40 bg-amber-500/10 p-2 text-xs">
|
||||
<span className="text-amber-700 dark:text-amber-400 font-medium">
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { Label } from "@/components/ui/label";
|
|||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { invokeFunction } from "@/lib/invoke-function";
|
||||
import { syncAgentRuntime } from "@/lib/sync-agent-runtime";
|
||||
import { useCreateCronjob } from "@/hooks/use-cronjobs";
|
||||
import { useAvailableMcps, useUserIntegrations } from "@/hooks/use-integrations";
|
||||
import { useAgentInstance } from "@/hooks/use-agent-instance";
|
||||
|
|
@ -131,6 +132,12 @@ export function CronjobWizard({ onCreated, onCancel }: Props) {
|
|||
next_run_at: parsed?.next_run_at ?? null,
|
||||
});
|
||||
toast.success("Automação criada!");
|
||||
|
||||
const { error: syncError } = await syncAgentRuntime(agent.id, "cronjobs");
|
||||
if (syncError) {
|
||||
toast.warning("Automação criada, mas o runtime do agente não sincronizou.");
|
||||
}
|
||||
|
||||
onCreated?.(job.id);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "Erro ao criar automação";
|
||||
|
|
|
|||
|
|
@ -43,7 +43,11 @@ export function DisconnectMCPDialog({
|
|||
|
||||
async function handleDisconnect() {
|
||||
setSubmitting(true);
|
||||
const { error } = await invokeFunction("disconnect-integration", {
|
||||
const { data, error } = await invokeFunction<{
|
||||
success: boolean;
|
||||
paused_jobs_count: number;
|
||||
runtime_sync_warning?: string | null;
|
||||
}>("disconnect-integration", {
|
||||
integration_id: integrationId,
|
||||
});
|
||||
setSubmitting(false);
|
||||
|
|
@ -52,6 +56,9 @@ export function DisconnectMCPDialog({
|
|||
return;
|
||||
}
|
||||
toast.success(`${mcpName} desconectado.`);
|
||||
if (data?.runtime_sync_warning) {
|
||||
toast.warning("Integração removida, mas o runtime do agente não sincronizou.");
|
||||
}
|
||||
queryClient.invalidateQueries({ queryKey: ["user-integrations"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["user-integration-limits"] });
|
||||
onOpenChange(false);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { formatDistanceToNow } from "date-fns";
|
|||
import { ptBR } from "date-fns/locale";
|
||||
import { toast } from "sonner";
|
||||
import { supabase } from "@/integrations/supabase/client";
|
||||
import { syncAgentSkills } from "@/lib/sync-agent-skills";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
|
|
@ -39,6 +40,15 @@ export function SkillCard({ skill }: { skill: Skill }) {
|
|||
|
||||
const isArchived = skill.status === "archived";
|
||||
|
||||
async function syncRuntimeAfterMutation(actionLabel: string) {
|
||||
const { error } = await syncAgentSkills(skill.agent_instance_id);
|
||||
if (error) {
|
||||
toast.warning(`${actionLabel}, mas o sync com o container falhou.`, {
|
||||
description: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const updateStatus = useMutation({
|
||||
mutationFn: async (newStatus: string) => {
|
||||
const { error } = await supabase
|
||||
|
|
@ -56,16 +66,21 @@ export function SkillCard({ skill }: { skill: Skill }) {
|
|||
const handleToggleActive = () => {
|
||||
const next = skill.status === "active" ? "disabled" : "active";
|
||||
updateStatus.mutate(next, {
|
||||
onSuccess: () => toast.success(next === "active" ? "Skill ativada" : "Skill desativada"),
|
||||
onSuccess: async () => {
|
||||
const actionLabel = next === "active" ? "Skill ativada" : "Skill desativada";
|
||||
toast.success(actionLabel);
|
||||
await syncRuntimeAfterMutation(actionLabel);
|
||||
},
|
||||
onError: (e: unknown) => toast.error(e instanceof Error ? e.message : "Erro ao atualizar"),
|
||||
});
|
||||
};
|
||||
|
||||
const handleArchive = () => {
|
||||
updateStatus.mutate("archived", {
|
||||
onSuccess: () => {
|
||||
onSuccess: async () => {
|
||||
toast.success("Skill arquivada");
|
||||
setConfirmArchive(false);
|
||||
await syncRuntimeAfterMutation("Skill arquivada");
|
||||
},
|
||||
onError: (e: unknown) => toast.error(e instanceof Error ? e.message : "Erro ao arquivar"),
|
||||
});
|
||||
|
|
@ -73,7 +88,10 @@ export function SkillCard({ skill }: { skill: Skill }) {
|
|||
|
||||
const handleRestore = () => {
|
||||
updateStatus.mutate("draft", {
|
||||
onSuccess: () => toast.success("Skill restaurada como rascunho"),
|
||||
onSuccess: async () => {
|
||||
toast.success("Skill restaurada como rascunho");
|
||||
await syncRuntimeAfterMutation("Skill restaurada como rascunho");
|
||||
},
|
||||
onError: (e: unknown) => {
|
||||
if ((e as { code?: string })?.code === "23505") {
|
||||
toast.error("Já existe outra skill ativa com esse nome. Renomeie antes de restaurar.");
|
||||
|
|
@ -89,11 +107,12 @@ export function SkillCard({ skill }: { skill: Skill }) {
|
|||
const { error } = await supabase.from("skills").delete().eq("id", skill.id);
|
||||
if (error) throw error;
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: async () => {
|
||||
toast.success("Skill deletada");
|
||||
qc.invalidateQueries({ queryKey: ["skills"] });
|
||||
qc.invalidateQueries({ queryKey: ["user-limits"] });
|
||||
setConfirmDelete(false);
|
||||
await syncRuntimeAfterMutation("Skill deletada");
|
||||
},
|
||||
onError: (e: unknown) => toast.error(e instanceof Error ? e.message : "Erro ao deletar"),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue