-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from giselles-ai/implement-free-plan-agent-us…
…age-limit Check agent time is available before performFlowExecution
- Loading branch information
Showing
6 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class AgentTimeNotAvailableError extends Error { | ||
constructor( | ||
message = "Your agent time has been depleted. Please upgrade your plan to continue using this feature.", | ||
) { | ||
super(message); | ||
this.name = this.constructor.name; | ||
|
||
// Ensure proper stack trace in modern environments | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, AgentTimeNotAvailableError); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export { calculateAgentTimeUsageMs } from "./agent-time-usage"; | ||
export { AGENT_TIME_CHARGE_LIMIT_MINUTES } from "./constants"; | ||
export { AgentActivity } from "./deprecated-agent-activity"; | ||
export { hasEnoughAgentTimeCharge } from "./has-enough-agent-time-charge"; | ||
export { hasEnoughAgentTimeCharge } from "./deprecated-has-enough-agent-time-charge"; | ||
export { isAgentTimeAvailable } from "./is-agent-time-available"; | ||
export { recordAgentUsage } from "./record-agent-usage"; | ||
export { saveAgentActivity } from "./save-agent-activity"; | ||
export { getMonthlyBillingCycle } from "./utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isProPlan } from "@/services/teams"; | ||
import type { CurrentTeam } from "@/services/teams/types"; | ||
import { calculateAgentTimeUsageMs } from "./agent-time-usage"; | ||
import { AGENT_TIME_CHARGE_LIMIT_MINUTES } from "./constants"; | ||
|
||
export async function isAgentTimeAvailable(currentTeam: CurrentTeam) { | ||
// If team is on a pro plan, proceed | ||
if (isProPlan(currentTeam)) { | ||
return true; | ||
} | ||
|
||
// If team is on a free plan, check agent time usage | ||
const timeUsageMs = await calculateAgentTimeUsageMs(currentTeam.dbId); | ||
const limitsInMs = AGENT_TIME_CHARGE_LIMIT_MINUTES.FREE * 60 * 1000; | ||
if (timeUsageMs >= limitsInMs) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |