Skip to content

An open-source, faster Devin alternative

TypeScript

api-edge: billing admission reports usagePlan (base | pro | max)

Slack U06GFN8DJ7Pacd913b5a267
diff --git a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts
index 76db72a6..2c1b5a3c 100644
--- a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.test.ts
@@ -94,6 +94,7 @@ describe("managed-agent credit admission", () => {
reason: "insufficient_credits",
paid: false,
modelAccess: null,
+ usagePlan: "base",
});
await expect(
getManagedAgentBillingAdmission(env(null), "org_test"),
@@ -104,6 +105,7 @@ describe("managed-agent credit admission", () => {
reason: null,
paid: false,
modelAccess: "full",
+ usagePlan: null,
});
await expect(
getManagedAgentBillingAdmission(env(0, null, "pro"), "org_test"),
@@ -114,6 +116,7 @@ describe("managed-agent credit admission", () => {
reason: null,
paid: true,
modelAccess: "full",
+ usagePlan: "pro",
});
});
@@ -129,6 +132,7 @@ describe("managed-agent credit admission", () => {
reason: null,
paid: true,
modelAccess: "fallback",
+ usagePlan: plan,
});
const request = new Request(
"https://mo-oc-dev.com/api/managed-agents/sessions/session_1/turns",
@@ -153,9 +157,28 @@ describe("managed-agent credit admission", () => {
reason: null,
paid: true,
modelAccess: "fallback",
+ usagePlan: "pro",
});
});
+ it("reports the usage plan the computer sizes by", async () => {
+ const usagePlan = async (usage: string | null, plan = "free") =>
+ (
+ await getManagedAgentBillingAdmission(
+ env(0, null, usage as string, plan),
+ "org_test",
+ )
+ ).usagePlan;
+ await expect(usagePlan("max")).resolves.toBe("max");
+ await expect(usagePlan("pro")).resolves.toBe("pro");
+ await expect(usagePlan("base")).resolves.toBe("base");
+ await expect(usagePlan(null)).resolves.toBe("base");
+ // Legacy Pro org before its Autumn projection.
+ await expect(usagePlan("base", "pro")).resolves.toBe("pro");
+ await expect(usagePlan(null, "pro")).resolves.toBe("pro");
+ await expect(usagePlan("enterprise")).resolves.toBeNull();
+ });
+
it("hard-stops an exhausted base org with the upgrade 402", async () => {
const request = new Request(
"https://mo-oc-dev.com/api/managed-agents/sessions/session_1/turns",
diff --git a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.ts b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.ts
index b0b2c0c8..6f18ac3c 100644
--- a/cloudflare-workers/api-edge/src/managed_agent_credit_gate.ts
+++ b/cloudflare-workers/api-edge/src/managed_agent_credit_gate.ts
@@ -17,6 +17,10 @@ interface ManagedAgentCreditRow {
// org is denied (base plan out of credits).
export type ManagedAgentModelAccess = "full" | "fallback";
+// The Autumn usage plan: "max" ($200), "pro" ($20, being retired), "base"
+// (free). null: no org row, or a value this edge does not know.
+export type ManagedAgentUsagePlan = "base" | "pro" | "max";
+
export interface ManagedAgentBillingAdmission {
allowed: boolean;
isHalted: boolean;
@@ -24,6 +28,23 @@ export interface ManagedAgentBillingAdmission {
reason: "insufficient_credits" | null;
paid: boolean;
modelAccess: ManagedAgentModelAccess | null;
+ /**
+ * Additive (work 052): the computer sizes by it, and only "max" gets the
+ * bigger VM. Same legacy rule as `paid`: a plan='pro' org still on the
+ * 'base' default reads as "pro".
+ */
+ usagePlan: ManagedAgentUsagePlan | null;
+}
+
+function normalizedUsagePlan(
+ row: ManagedAgentCreditRow | null,
+): ManagedAgentUsagePlan | null {
+ if (!row) return null;
+ if (row.usage_plan === "pro" || row.usage_plan === "max") {
+ return row.usage_plan;
+ }
+ if (row.plan === "pro") return "pro";
+ return row.usage_plan === "base" || row.usage_plan === null ? "base" : null;
}
export function isManagedAgentBillableRequest(
@@ -67,6 +88,7 @@ export async function getManagedAgentBillingAdmission(
reason: allowed ? null : "insufficient_credits",
paid,
modelAccess: !isHalted ? "full" : paid ? "fallback" : null,
+ usagePlan: normalizedUsagePlan(row),
};
}