mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 10:16:03 +00:00
zen: cost multiplier
This commit is contained in:
@@ -1168,28 +1168,29 @@ export async function handler(
|
|||||||
const week = getWeekBounds(new Date())
|
const week = getWeekBounds(new Date())
|
||||||
const month = getMonthlyBounds(new Date(), authInfo.lite!.timeCreated)
|
const month = getMonthlyBounds(new Date(), authInfo.lite!.timeCreated)
|
||||||
const rollingWindowSeconds = lite.rollingWindow * 3600
|
const rollingWindowSeconds = lite.rollingWindow * 3600
|
||||||
|
const quotaCost = Math.round(cost * modelInfo.costMultiplier)
|
||||||
return [
|
return [
|
||||||
db
|
db
|
||||||
.update(LiteTable)
|
.update(LiteTable)
|
||||||
.set({
|
.set({
|
||||||
monthlyUsage: sql`
|
monthlyUsage: sql`
|
||||||
CASE
|
CASE
|
||||||
WHEN ${LiteTable.timeMonthlyUpdated} >= ${month.start} THEN ${LiteTable.monthlyUsage} + ${cost}
|
WHEN ${LiteTable.timeMonthlyUpdated} >= ${month.start} THEN ${LiteTable.monthlyUsage} + ${quotaCost}
|
||||||
ELSE ${cost}
|
ELSE ${quotaCost}
|
||||||
END
|
END
|
||||||
`,
|
`,
|
||||||
timeMonthlyUpdated: sql`now()`,
|
timeMonthlyUpdated: sql`now()`,
|
||||||
weeklyUsage: sql`
|
weeklyUsage: sql`
|
||||||
CASE
|
CASE
|
||||||
WHEN ${LiteTable.timeWeeklyUpdated} >= ${week.start} THEN ${LiteTable.weeklyUsage} + ${cost}
|
WHEN ${LiteTable.timeWeeklyUpdated} >= ${week.start} THEN ${LiteTable.weeklyUsage} + ${quotaCost}
|
||||||
ELSE ${cost}
|
ELSE ${quotaCost}
|
||||||
END
|
END
|
||||||
`,
|
`,
|
||||||
timeWeeklyUpdated: sql`now()`,
|
timeWeeklyUpdated: sql`now()`,
|
||||||
rollingUsage: sql`
|
rollingUsage: sql`
|
||||||
CASE
|
CASE
|
||||||
WHEN UNIX_TIMESTAMP(${LiteTable.timeRollingUpdated}) >= UNIX_TIMESTAMP(now()) - ${rollingWindowSeconds} THEN ${LiteTable.rollingUsage} + ${cost}
|
WHEN UNIX_TIMESTAMP(${LiteTable.timeRollingUpdated}) >= UNIX_TIMESTAMP(now()) - ${rollingWindowSeconds} THEN ${LiteTable.rollingUsage} + ${quotaCost}
|
||||||
ELSE ${cost}
|
ELSE ${quotaCost}
|
||||||
END
|
END
|
||||||
`,
|
`,
|
||||||
timeRollingUpdated: sql`
|
timeRollingUpdated: sql`
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export namespace ZenData {
|
|||||||
const ModelSchema = z.object({
|
const ModelSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
cost: ModelCostSchema,
|
cost: ModelCostSchema,
|
||||||
|
costMultiplier: z.number().default(1),
|
||||||
cost200K: ModelCostSchema.optional(),
|
cost200K: ModelCostSchema.optional(),
|
||||||
allowAnonymous: z.boolean().optional(),
|
allowAnonymous: z.boolean().optional(),
|
||||||
byokProvider: z.enum(["openai", "anthropic", "google"]).optional(),
|
byokProvider: z.enum(["openai", "anthropic", "google"]).optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user