Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api/v2/agent/status): fix model value while in-progress

Gergő Móricze2900b21e528
diff --git a/apps/api/src/controllers/v2/agent-status.ts b/apps/api/src/controllers/v2/agent-status.ts
index 9280e013c..482445f07 100644
--- a/apps/api/src/controllers/v2/agent-status.ts
+++ b/apps/api/src/controllers/v2/agent-status.ts
@@ -4,8 +4,9 @@ import {
supabaseGetAgentByIdDirect,
supabaseGetAgentRequestByIdDirect,
} from "../../lib/supabase-jobs";
-import { logger as _logger } from "../../lib/logger";
+import { logger as _logger, logger } from "../../lib/logger";
import { getJobFromGCS } from "../../lib/gcs-jobs";
+import { config } from "../../config";
export async function agentStatusController(
req: RequestWithAuth<{ jobId: string }, AgentStatusResponse, any>,
@@ -24,19 +25,53 @@ export async function agentStatusController(
const agent = await supabaseGetAgentByIdDirect(req.params.jobId);
+ let model: "spark-1-pro" | "spark-1-mini";
+ if (agent) {
+ model = (agent.options?.model ?? "spark-1-pro") as
+ | "spark-1-pro"
+ | "spark-1-mini";
+ } else {
+ try {
+ const optionsRequest = await fetch(
+ config.EXTRACT_V3_BETA_URL +
+ "/v2/extract/" +
+ req.params.jobId +
+ "/options",
+ {
+ headers: {
+ Authorization: `Bearer ${config.AGENT_INTEROP_SECRET}`,
+ },
+ },
+ );
+
+ if (optionsRequest.status !== 200) {
+ logger.warn("Failed to get agent request details", {
+ status: optionsRequest.status,
+ method: "agentStatusController",
+ module: "api/v2",
+ text: await optionsRequest.text(),
+ });
+ model = "spark-1-pro"; // fall back to this value
+ } else {
+ model = ((await optionsRequest.json()).model ?? "spark-1-pro") as
+ | "spark-1-pro"
+ | "spark-1-mini";
+ }
+ } catch (error) {
+ logger.warn("Failed to get agent request details", {
+ error,
+ method: "agentStatusController",
+ module: "api/v2",
+ extractId: req.params.jobId,
+ });
+ model = "spark-1-pro"; // fall back to this value
+ }
+ }
+
let data: any = undefined;
if (agent?.is_successful) {
data = await getJobFromGCS(agent.id);
}
- const model =
- (
- agent?.options as
- | { model?: "spark-1-pro" | "spark-1-mini" }
- | null
- | undefined
- )?.model === "spark-1-mini"
- ? "spark-1-mini"
- : "spark-1-pro";
return res.status(200).json({
success: true,