Skip to content

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

Nick:

Nicolasee3e5dc69cbd
diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts
index 7774823af..c8981024b 100644
--- a/apps/api/src/controllers/v1/types.ts
+++ b/apps/api/src/controllers/v1/types.ts
@@ -312,12 +312,12 @@ export function legacyScrapeOptions(x: ScrapeOptions): PageOptions {
};
}
-export function legacyExtractorOptions(x: ExtractOptions): ExtractorOptions {
+export function legacyExtractorOptions(x?: ExtractOptions): ExtractorOptions {
return {
- mode: x.mode ? "llm-extraction" : "markdown",
- extractionPrompt: x.prompt ?? "Based on the information on the page, extract the information from the schema.",
- extractionSchema: x.schema,
- userPrompt: x.prompt ?? "",
+ mode: x?.mode ? "llm-extraction" : "markdown",
+ extractionPrompt: x?.prompt ?? "Based on the information on the page, extract the information from the schema.",
+ extractionSchema: x?.schema,
+ userPrompt: x?.prompt ?? "",
};
}
diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts
index 8e4e21d31..22dc72df3 100644
--- a/apps/api/src/services/billing/credit_billing.ts
+++ b/apps/api/src/services/billing/credit_billing.ts
@@ -199,27 +199,44 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
);
}
- if(subscriptionError) {
- Logger.error(`Subscription error: ${subscriptionError}`);
- throw new Error(`Subscription error: ${subscriptionError}`);
- }
+
// Free credits, no coupons
- if (!subscription) {
+ if (!subscription || subscriptionError) {
+
// If there is no active subscription but there are available coupons
if (couponCredits >= credits) {
return { success: true, message: "Sufficient credits available", remainingCredits: couponCredits };
}
- const { data: creditUsages, error: creditUsageError } =
- await supabase_service
+ let creditUsages;
+ let creditUsageError;
+ let retries = 0;
+ const maxRetries = 3;
+ const retryInterval = 2000; // 2 seconds
+
+ while (retries < maxRetries) {
+ const result = await supabase_service
.from("credit_usage")
.select("credits_used")
.is("subscription_id", null)
.eq("team_id", team_id);
+ creditUsages = result.data;
+ creditUsageError = result.error;
+
+ if (!creditUsageError) {
+ break;
+ }
+
+ retries++;
+ if (retries < maxRetries) {
+ await new Promise(resolve => setTimeout(resolve, retryInterval));
+ }
+ }
+
if (creditUsageError) {
- Logger.error(`Credit usage error: ${creditUsageError}`);
+ Logger.error(`Credit usage error after ${maxRetries} attempts: ${creditUsageError}`);
throw new Error(
`Failed to retrieve credit usage for team_id: ${team_id}`
);