mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 06:56:44 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
44a251cb16
commit
fbd4abea70
1 changed files with 24 additions and 1 deletions
|
|
@ -187,7 +187,9 @@ Deno.serve(async (req) => {
|
|||
);
|
||||
}
|
||||
|
||||
// 7) Atualiza agent_instances
|
||||
// 7) Atualiza agent_instances — reseta para 'provisioning' se estava em erro,
|
||||
// garante que o provision-agent re-execute do zero.
|
||||
const nextStatus = agent.status === "error" ? "provisioning" : agent.status;
|
||||
const { error: updErr } = await admin
|
||||
.from("agent_instances")
|
||||
.update({
|
||||
|
|
@ -197,6 +199,7 @@ Deno.serve(async (req) => {
|
|||
telegram_token_invalid: false,
|
||||
telegram_webhook_configured: false,
|
||||
telegram_first_message_received_at: null,
|
||||
status: nextStatus,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", agent.id);
|
||||
|
|
@ -206,6 +209,26 @@ Deno.serve(async (req) => {
|
|||
return jsonResponse({ error: "Falha ao salvar dados do bot." }, 500);
|
||||
}
|
||||
|
||||
// 8) Auto-provisionamento: dispara provision-agent assincronamente para que
|
||||
// o container seja criado/atualizado no Railway. Fire-and-forget — o wizard
|
||||
// não bloqueia esperando o deploy completar.
|
||||
if (nextStatus === "provisioning" || agent.status === "active") {
|
||||
try {
|
||||
const provisionUrl = `${supabaseUrl}/functions/v1/provision-agent`;
|
||||
console.log(`auto-provision: disparando para agent ${agent.id}`);
|
||||
fetch(provisionUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${serviceKey}`,
|
||||
},
|
||||
body: JSON.stringify({ agent_instance_id: agent.id }),
|
||||
}).catch((err) => console.error("auto-provision fetch error:", err));
|
||||
} catch (err) {
|
||||
console.error("auto-provision trigger error:", err);
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResponse({
|
||||
valid: true,
|
||||
bot_username: botUsername,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue