Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/budgetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class BudgetManager {

constructor(options: BudgetGuardOptions) {
// Validate monthly limit
if (typeof options.monthlyLimit !== 'number' || isNaN(options.monthlyLimit) || !isFinite(options.monthlyLimit)) {
if (typeof options.monthlyLimit !== 'number' || Number.isNaN(options.monthlyLimit) || !isFinite(options.monthlyLimit)) {
throw new Error('TokenFirewall: monthlyLimit must be a valid number');
}

Expand All @@ -36,7 +36,7 @@ export class BudgetManager {
*/
public async track(cost: number): Promise<void> {
// Validate cost parameter
if (typeof cost !== 'number' || isNaN(cost) || !isFinite(cost)) {
if (typeof cost !== 'number' || Number.isNaN(cost) || !isFinite(cost)) {
throw new Error('TokenFirewall: Cost must be a valid number');
}

Expand Down Expand Up @@ -116,7 +116,7 @@ export class BudgetManager {
*/
public importState(state: { totalSpent: number }): void {
// Validate totalSpent
if (typeof state.totalSpent !== 'number' || isNaN(state.totalSpent) || !isFinite(state.totalSpent)) {
if (typeof state.totalSpent !== 'number' || Number.isNaN(state.totalSpent) || !isFinite(state.totalSpent)) {
throw new Error('TokenFirewall: Invalid budget state - totalSpent must be a valid number');
}

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export function registerPricing(provider: string, model: string, pricing: ModelP
if (!pricing || typeof pricing !== 'object') {
throw new Error('TokenFirewall: Pricing must be an object');
}
if (typeof pricing.input !== 'number' || pricing.input < 0 || !isFinite(pricing.input) || isNaN(pricing.input)) {
if (typeof pricing.input !== 'number' || pricing.input < 0 || !isFinite(pricing.input) || Number.isNaN(pricing.input)) {
throw new Error('TokenFirewall: Pricing input must be a non-negative finite number');
}
if (typeof pricing.output !== 'number' || pricing.output < 0 || !isFinite(pricing.output) || isNaN(pricing.output)) {
if (typeof pricing.output !== 'number' || pricing.output < 0 || !isFinite(pricing.output) || Number.isNaN(pricing.output)) {
throw new Error('TokenFirewall: Pricing output must be a non-negative finite number');
}

Expand All @@ -90,7 +90,7 @@ export function registerContextLimit(provider: string, model: string, contextLim
if (!model || typeof model !== 'string' || model.trim() === '') {
throw new Error('TokenFirewall: Model must be a non-empty string');
}
if (typeof contextLimit !== 'number' || contextLimit <= 0 || !isFinite(contextLimit) || isNaN(contextLimit)) {
if (typeof contextLimit !== 'number' || contextLimit <= 0 || !isFinite(contextLimit) || Number.isNaN(contextLimit)) {
throw new Error('TokenFirewall: Context limit must be a positive finite number');
}

Expand Down