mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 14:56:51 +00:00
Fixed Railway projectId fetch
X-Lovable-Edit-ID: edt-ef3db142-71bc-4e8a-8bb2-c39dfbc758c8 Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
commit
a8df36d6bf
3 changed files with 31 additions and 16 deletions
|
|
@ -197,11 +197,11 @@ export async function setHermesSuspended(opts: {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Busca o environmentId do primeiro deployment de um serviço. Útil quando vps_pool_id está null. */
|
/** Busca env+project IDs do primeiro deployment de um serviço. Útil quando vps_pool_id está null. */
|
||||||
export async function getServiceEnvironmentId(opts: {
|
export async function getServiceContext(opts: {
|
||||||
token: string;
|
token: string;
|
||||||
serviceId: string;
|
serviceId: string;
|
||||||
}): Promise<string | null> {
|
}): Promise<{ environmentId: string | null; projectId: string | null }> {
|
||||||
const query = `
|
const query = `
|
||||||
query Service($id: String!) {
|
query Service($id: String!) {
|
||||||
service(id: $id) {
|
service(id: $id) {
|
||||||
|
|
@ -216,10 +216,21 @@ export async function getServiceEnvironmentId(opts: {
|
||||||
service: { projectId: string; deployments: { edges: { node: { environmentId: string } }[] } };
|
service: { projectId: string; deployments: { edges: { node: { environmentId: string } }[] } };
|
||||||
}>(query, { id: opts.serviceId }, opts.token);
|
}>(query, { id: opts.serviceId }, opts.token);
|
||||||
if (res.errors?.length) {
|
if (res.errors?.length) {
|
||||||
console.error("getServiceEnvironmentId errors:", JSON.stringify(res.errors));
|
console.error("getServiceContext errors:", JSON.stringify(res.errors));
|
||||||
return null;
|
return { environmentId: null, projectId: null };
|
||||||
}
|
}
|
||||||
return res.data?.service?.deployments?.edges?.[0]?.node?.environmentId ?? null;
|
return {
|
||||||
|
environmentId: res.data?.service?.deployments?.edges?.[0]?.node?.environmentId ?? null,
|
||||||
|
projectId: res.data?.service?.projectId ?? null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated use getServiceContext */
|
||||||
|
export async function getServiceEnvironmentId(opts: {
|
||||||
|
token: string;
|
||||||
|
serviceId: string;
|
||||||
|
}): Promise<string | null> {
|
||||||
|
return (await getServiceContext(opts)).environmentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Apaga o webhook do Telegram para que o Hermes assuma via polling. */
|
/** Apaga o webhook do Telegram para que o Hermes assuma via polling. */
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.45.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.45.4";
|
||||||
import { corsHeaders } from "../_shared/cors.ts";
|
import { corsHeaders } from "../_shared/cors.ts";
|
||||||
import { setHermesSuspended, getServiceEnvironmentId } from "../_shared/railway.ts";
|
import { setHermesSuspended, getServiceContext } from "../_shared/railway.ts";
|
||||||
|
|
||||||
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
|
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
|
||||||
const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
||||||
|
|
@ -67,14 +67,16 @@ Deno.serve(async (req) => {
|
||||||
environmentId = pool?.railway_environment_id ?? null;
|
environmentId = pool?.railway_environment_id ?? null;
|
||||||
projectId = pool?.railway_project_id ?? undefined;
|
projectId = pool?.railway_project_id ?? undefined;
|
||||||
}
|
}
|
||||||
if (!environmentId) {
|
if (!environmentId || !projectId) {
|
||||||
environmentId = await getServiceEnvironmentId({
|
const ctx = await getServiceContext({
|
||||||
token: RAILWAY_API_TOKEN,
|
token: RAILWAY_API_TOKEN,
|
||||||
serviceId: agent.railway_service_id,
|
serviceId: agent.railway_service_id,
|
||||||
});
|
});
|
||||||
|
environmentId = environmentId ?? ctx.environmentId;
|
||||||
|
projectId = projectId ?? ctx.projectId ?? undefined;
|
||||||
}
|
}
|
||||||
if (!environmentId) {
|
if (!environmentId || !projectId) {
|
||||||
return jsonResponse(500, { error: "could not resolve railway environmentId" });
|
return jsonResponse(500, { error: "could not resolve railway environmentId/projectId" });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.45.4";
|
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.45.4";
|
||||||
import { corsHeaders } from "../_shared/cors.ts";
|
import { corsHeaders } from "../_shared/cors.ts";
|
||||||
import { setHermesSuspended, getServiceEnvironmentId } from "../_shared/railway.ts";
|
import { setHermesSuspended, getServiceContext } from "../_shared/railway.ts";
|
||||||
|
|
||||||
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
|
const SUPABASE_URL = Deno.env.get("SUPABASE_URL")!;
|
||||||
const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
||||||
|
|
@ -69,14 +69,16 @@ Deno.serve(async (req) => {
|
||||||
environmentId = pool?.railway_environment_id ?? null;
|
environmentId = pool?.railway_environment_id ?? null;
|
||||||
projectId = pool?.railway_project_id ?? undefined;
|
projectId = pool?.railway_project_id ?? undefined;
|
||||||
}
|
}
|
||||||
if (!environmentId) {
|
if (!environmentId || !projectId) {
|
||||||
environmentId = await getServiceEnvironmentId({
|
const ctx = await getServiceContext({
|
||||||
token: RAILWAY_API_TOKEN,
|
token: RAILWAY_API_TOKEN,
|
||||||
serviceId: agent.railway_service_id,
|
serviceId: agent.railway_service_id,
|
||||||
});
|
});
|
||||||
|
environmentId = environmentId ?? ctx.environmentId;
|
||||||
|
projectId = projectId ?? ctx.projectId ?? undefined;
|
||||||
}
|
}
|
||||||
if (!environmentId) {
|
if (!environmentId || !projectId) {
|
||||||
return jsonResponse(500, { error: "could not resolve railway environmentId" });
|
return jsonResponse(500, { error: "could not resolve railway environmentId/projectId" });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue