mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 12:16:49 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
b913f43dde
commit
70393534eb
4 changed files with 36 additions and 2 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.45.4";
|
||||
import { corsHeaders } from "../_shared/cors.ts";
|
||||
import { authorizeInternalRequest } from "../_shared/internal-auth.ts";
|
||||
import { setHermesSuspended, getServiceContext } from "../_shared/railway.ts";
|
||||
|
||||
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
|
||||
|
|
@ -40,11 +41,19 @@ Deno.serve(async (req) => {
|
|||
|
||||
const { data: agent } = await supabase
|
||||
.from("agent_instances")
|
||||
.select("id, status, railway_service_id, vps_pool_id")
|
||||
.select("id, status, railway_service_id, vps_pool_id, user_id")
|
||||
.eq("id", body.agent_instance_id)
|
||||
.maybeSingle();
|
||||
|
||||
if (!agent) return jsonResponse(404, { error: "agent_instance not found" });
|
||||
|
||||
// Auth: X-Internal-Secret (trigger), JWT de admin, OU JWT do dono do agente.
|
||||
const auth = await authorizeInternalRequest(req, { ownerUserId: agent.user_id });
|
||||
if (!auth.ok) {
|
||||
console.warn(`suspend-agent: auth rejected (${auth.reason})`);
|
||||
return jsonResponse(401, { error: "unauthorized", reason: auth.reason });
|
||||
}
|
||||
|
||||
if (agent.status === "suspended") {
|
||||
return jsonResponse(200, { ok: true, already_suspended: true });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue