diff --git a/packages/console/app/src/routes/stripe/webhook.ts b/packages/console/app/src/routes/stripe/webhook.ts index c468d2d0c6b..6f16376416c 100644 --- a/packages/console/app/src/routes/stripe/webhook.ts +++ b/packages/console/app/src/routes/stripe/webhook.ts @@ -1,8 +1,7 @@ import { Billing } from "@opencode-ai/console-core/billing.js" import type { APIEvent } from "@solidjs/start/server" import { and, Database, eq, sql } from "@opencode-ai/console-core/drizzle/index.js" -import { BillingTable, PaymentTable } from "@opencode-ai/console-core/schema/billing.sql.js" -import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js" +import { BillingTable, PaymentTable, SubscriptionTable } from "@opencode-ai/console-core/schema/billing.sql.js" import { Identifier } from "@opencode-ai/console-core/identifier.js" import { centsToMicroCents } from "@opencode-ai/console-core/util/price.js" import { Actor } from "@opencode-ai/console-core/actor.js" @@ -380,7 +379,7 @@ export async function POST(input: APIEvent) { await Database.transaction(async (tx) => { await tx.update(BillingTable).set({ subscriptionID: null }).where(eq(BillingTable.workspaceID, workspaceID)) - await tx.update(UserTable).set({ timeSubscribed: null }).where(eq(UserTable.workspaceID, workspaceID)) + await tx.delete(SubscriptionTable).where(eq(SubscriptionTable.workspaceID, workspaceID)) }) } })() diff --git a/packages/console/app/src/routes/zen/util/handler.ts b/packages/console/app/src/routes/zen/util/handler.ts index 71dd6c009c8..56efe451ca1 100644 --- a/packages/console/app/src/routes/zen/util/handler.ts +++ b/packages/console/app/src/routes/zen/util/handler.ts @@ -1,8 +1,9 @@ import type { APIEvent } from "@solidjs/start/server" import { and, Database, eq, isNull, lt, or, sql } from "@opencode-ai/console-core/drizzle/index.js" import { KeyTable } from "@opencode-ai/console-core/schema/key.sql.js" -import { BillingTable, UsageTable } from "@opencode-ai/console-core/schema/billing.sql.js" +import { BillingTable, SubscriptionTable, UsageTable } from "@opencode-ai/console-core/schema/billing.sql.js" import { centsToMicroCents } from "@opencode-ai/console-core/util/price.js" +import { getWeekBounds } from "@opencode-ai/console-core/util/date.js" import { Identifier } from "@opencode-ai/console-core/identifier.js" import { Billing } from "@opencode-ai/console-core/billing.js" import { Actor } from "@opencode-ai/console-core/actor.js" @@ -415,11 +416,11 @@ export async function handler( timeMonthlyUsageUpdated: UserTable.timeMonthlyUsageUpdated, }, subscription: { - timeSubscribed: UserTable.timeSubscribed, - subIntervalUsage: UserTable.subIntervalUsage, - subMonthlyUsage: UserTable.subMonthlyUsage, - timeSubIntervalUsageUpdated: UserTable.timeSubIntervalUsageUpdated, - timeSubMonthlyUsageUpdated: UserTable.timeSubMonthlyUsageUpdated, + id: SubscriptionTable.id, + rollingUsage: SubscriptionTable.rollingUsage, + fixedUsage: SubscriptionTable.fixedUsage, + timeRollingUpdated: SubscriptionTable.timeRollingUpdated, + timeFixedUpdated: SubscriptionTable.timeFixedUpdated, }, provider: { credentials: ProviderTable.credentials, @@ -440,6 +441,14 @@ export async function handler( ) : sql`false`, ) + .leftJoin( + SubscriptionTable, + and( + eq(SubscriptionTable.workspaceID, KeyTable.workspaceID), + eq(SubscriptionTable.userID, KeyTable.userID), + isNull(SubscriptionTable.timeDeleted), + ), + ) .where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted))) .then((rows) => rows[0]), ) @@ -448,7 +457,7 @@ export async function handler( logger.metric({ api_key: data.apiKey, workspace: data.workspaceID, - isSubscription: data.subscription.timeSubscribed ? true : false, + isSubscription: data.subscription ? true : false, }) return { @@ -456,7 +465,7 @@ export async function handler( workspaceID: data.workspaceID, billing: data.billing, user: data.user, - subscription: data.subscription.timeSubscribed ? data.subscription : undefined, + subscription: data.subscription, provider: data.provider, isFree: FREE_WORKSPACES.includes(data.workspaceID), isDisabled: !!data.timeDisabled, @@ -484,23 +493,11 @@ export async function handler( return `${minutes}min` } - // Check monthly limit (based on subscription billing cycle) - if ( - sub.subMonthlyUsage && - sub.timeSubMonthlyUsageUpdated && - sub.subMonthlyUsage >= centsToMicroCents(black.monthlyLimit * 100) - ) { - const subscribeDay = sub.timeSubscribed!.getUTCDate() - const cycleStart = new Date( - Date.UTC( - now.getUTCFullYear(), - now.getUTCDate() >= subscribeDay ? now.getUTCMonth() : now.getUTCMonth() - 1, - subscribeDay, - ), - ) - const cycleEnd = new Date(Date.UTC(cycleStart.getUTCFullYear(), cycleStart.getUTCMonth() + 1, subscribeDay)) - if (sub.timeSubMonthlyUsageUpdated >= cycleStart && sub.timeSubMonthlyUsageUpdated < cycleEnd) { - const retryAfter = Math.ceil((cycleEnd.getTime() - now.getTime()) / 1000) + // Check weekly limit + if (sub.fixedUsage && sub.timeFixedUpdated) { + const week = getWeekBounds(now) + if (sub.timeFixedUpdated >= week.start && sub.fixedUsage >= centsToMicroCents(black.fixedLimit * 100)) { + const retryAfter = Math.ceil((week.end.getTime() - now.getTime()) / 1000) throw new SubscriptionError( `Subscription quota exceeded. Retry in ${formatRetryTime(retryAfter)}.`, retryAfter, @@ -508,14 +505,12 @@ export async function handler( } } - // Check interval limit - const intervalMs = black.intervalLength * 3600 * 1000 - if (sub.subIntervalUsage && sub.timeSubIntervalUsageUpdated) { - const currentInterval = Math.floor(now.getTime() / intervalMs) - const usageInterval = Math.floor(sub.timeSubIntervalUsageUpdated.getTime() / intervalMs) - if (currentInterval === usageInterval && sub.subIntervalUsage >= centsToMicroCents(black.intervalLimit * 100)) { - const nextInterval = (currentInterval + 1) * intervalMs - const retryAfter = Math.ceil((nextInterval - now.getTime()) / 1000) + // Check rolling limit + if (sub.rollingUsage && sub.timeRollingUpdated) { + const rollingWindowMs = black.rollingWindow * 3600 * 1000 + const windowStart = new Date(now.getTime() - rollingWindowMs) + if (sub.timeRollingUpdated >= windowStart && sub.rollingUsage >= centsToMicroCents(black.rollingLimit * 100)) { + const retryAfter = Math.ceil((sub.timeRollingUpdated.getTime() + rollingWindowMs - now.getTime()) / 1000) throw new SubscriptionError( `Subscription quota exceeded. Retry in ${formatRetryTime(retryAfter)}.`, retryAfter, @@ -661,38 +656,39 @@ export async function handler( .where(and(eq(KeyTable.workspaceID, authInfo.workspaceID), eq(KeyTable.id, authInfo.apiKeyId))), ...(authInfo.subscription ? (() => { - const now = new Date() - const subscribeDay = authInfo.subscription.timeSubscribed!.getUTCDate() - const cycleStart = new Date( - Date.UTC( - now.getUTCFullYear(), - now.getUTCDate() >= subscribeDay ? now.getUTCMonth() : now.getUTCMonth() - 1, - subscribeDay, - ), - ) - const cycleEnd = new Date( - Date.UTC(cycleStart.getUTCFullYear(), cycleStart.getUTCMonth() + 1, subscribeDay), - ) + const black = BlackData.get() + const week = getWeekBounds(new Date()) + const rollingWindowSeconds = black.rollingWindow * 3600 return [ db - .update(UserTable) + .update(SubscriptionTable) .set({ - subMonthlyUsage: sql` + fixedUsage: sql` CASE - WHEN ${UserTable.timeSubMonthlyUsageUpdated} >= ${cycleStart} AND ${UserTable.timeSubMonthlyUsageUpdated} < ${cycleEnd} THEN ${UserTable.subMonthlyUsage} + ${cost} + WHEN ${SubscriptionTable.timeFixedUpdated} >= ${week.start} THEN ${SubscriptionTable.fixedUsage} + ${cost} ELSE ${cost} END `, - timeSubMonthlyUsageUpdated: sql`now()`, - subIntervalUsage: sql` + timeFixedUpdated: sql`now()`, + rollingUsage: sql` CASE - WHEN FLOOR(UNIX_TIMESTAMP(${UserTable.timeSubIntervalUsageUpdated}) / (${BlackData.get().intervalLength} * 3600)) = FLOOR(UNIX_TIMESTAMP(now()) / (${BlackData.get().intervalLength} * 3600)) THEN ${UserTable.subIntervalUsage} + ${cost} + WHEN UNIX_TIMESTAMP(${SubscriptionTable.timeRollingUpdated}) >= UNIX_TIMESTAMP(now()) - ${rollingWindowSeconds} THEN ${SubscriptionTable.rollingUsage} + ${cost} ELSE ${cost} END `, - timeSubIntervalUsageUpdated: sql`now()`, + timeRollingUpdated: sql` + CASE + WHEN UNIX_TIMESTAMP(${SubscriptionTable.timeRollingUpdated}) >= UNIX_TIMESTAMP(now()) - ${rollingWindowSeconds} THEN ${SubscriptionTable.timeRollingUpdated} + ELSE now() + END + `, }) - .where(and(eq(UserTable.workspaceID, authInfo.workspaceID), eq(UserTable.id, authInfo.user.id))), + .where( + and( + eq(SubscriptionTable.workspaceID, authInfo.workspaceID), + eq(SubscriptionTable.userID, authInfo.user.id), + ), + ), ] })() : [ diff --git a/packages/console/core/migrations/0046_charming_black_bolt.sql b/packages/console/core/migrations/0046_charming_black_bolt.sql new file mode 100644 index 00000000000..607300db865 --- /dev/null +++ b/packages/console/core/migrations/0046_charming_black_bolt.sql @@ -0,0 +1,13 @@ +CREATE TABLE `subscription` ( + `id` varchar(30) NOT NULL, + `workspace_id` varchar(30) NOT NULL, + `time_created` timestamp(3) NOT NULL DEFAULT (now()), + `time_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3), + `time_deleted` timestamp(3), + `user_id` varchar(30) NOT NULL, + `rolling_usage` bigint, + `fixed_usage` bigint, + `time_rolling_updated` timestamp(3), + `time_fixed_updated` timestamp(3), + CONSTRAINT `subscription_workspace_id_id_pk` PRIMARY KEY(`workspace_id`,`id`) +); diff --git a/packages/console/core/migrations/0047_huge_omega_red.sql b/packages/console/core/migrations/0047_huge_omega_red.sql new file mode 100644 index 00000000000..d5086f05a15 --- /dev/null +++ b/packages/console/core/migrations/0047_huge_omega_red.sql @@ -0,0 +1,6 @@ +CREATE INDEX `workspace_user_id` ON `subscription` (`workspace_id`,`user_id`);--> statement-breakpoint +ALTER TABLE `user` DROP COLUMN `time_subscribed`;--> statement-breakpoint +ALTER TABLE `user` DROP COLUMN `sub_interval_usage`;--> statement-breakpoint +ALTER TABLE `user` DROP COLUMN `sub_monthly_usage`;--> statement-breakpoint +ALTER TABLE `user` DROP COLUMN `sub_time_interval_usage_updated`;--> statement-breakpoint +ALTER TABLE `user` DROP COLUMN `sub_time_monthly_usage_updated`; \ No newline at end of file diff --git a/packages/console/core/migrations/0048_mean_frank_castle.sql b/packages/console/core/migrations/0048_mean_frank_castle.sql new file mode 100644 index 00000000000..c2cf5ee47ea --- /dev/null +++ b/packages/console/core/migrations/0048_mean_frank_castle.sql @@ -0,0 +1,2 @@ +DROP INDEX `workspace_user_id` ON `subscription`;--> statement-breakpoint +ALTER TABLE `subscription` ADD CONSTRAINT `workspace_user_id` UNIQUE(`workspace_id`,`user_id`); \ No newline at end of file diff --git a/packages/console/core/migrations/meta/0046_snapshot.json b/packages/console/core/migrations/meta/0046_snapshot.json new file mode 100644 index 00000000000..46ff73e263a --- /dev/null +++ b/packages/console/core/migrations/meta/0046_snapshot.json @@ -0,0 +1,1236 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "f3725f6d-5f33-4497-b4ba-cf05c46fb873", + "prevId": "27c1a3eb-b125-46d4-b436-abe5764fe4b7", + "tables": { + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "account_id_pk": { + "name": "account_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "auth": { + "name": "auth", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "enum('email','github','google')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "provider": { + "name": "provider", + "columns": ["provider", "subject"], + "isUnique": true + }, + "account_id": { + "name": "account_id", + "columns": ["account_id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "auth_id_pk": { + "name": "auth_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "benchmark": { + "name": "benchmark", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "agent": { + "name": "agent", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "mediumtext", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "time_created": { + "name": "time_created", + "columns": ["time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "benchmark_id_pk": { + "name": "benchmark_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "billing": { + "name": "billing", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_id": { + "name": "payment_method_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_type": { + "name": "payment_method_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_last4": { + "name": "payment_method_last4", + "type": "varchar(4)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "balance": { + "name": "balance", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload": { + "name": "reload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_trigger": { + "name": "reload_trigger", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_amount": { + "name": "reload_amount", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_error": { + "name": "reload_error", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_error": { + "name": "time_reload_error", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_locked_till": { + "name": "time_reload_locked_till", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subscription_id": { + "name": "subscription_id", + "type": "varchar(28)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_customer_id": { + "name": "global_customer_id", + "columns": ["customer_id"], + "isUnique": true + }, + "global_subscription_id": { + "name": "global_subscription_id", + "columns": ["subscription_id"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "billing_workspace_id_id_pk": { + "name": "billing_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "payment": { + "name": "payment", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "invoice_id": { + "name": "invoice_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_id": { + "name": "payment_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_refunded": { + "name": "time_refunded", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "payment_workspace_id_id_pk": { + "name": "payment_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "subscription": { + "name": "subscription", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rolling_usage": { + "name": "rolling_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fixed_usage": { + "name": "fixed_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_rolling_updated": { + "name": "time_rolling_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_fixed_updated": { + "name": "time_fixed_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "subscription_workspace_id_id_pk": { + "name": "subscription_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "usage": { + "name": "usage", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reasoning_tokens": { + "name": "reasoning_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_read_tokens": { + "name": "cache_read_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_5m_tokens": { + "name": "cache_write_5m_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_1h_tokens": { + "name": "cache_write_1h_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost": { + "name": "cost", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key_id": { + "name": "key_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enrichment": { + "name": "enrichment", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "usage_time_created": { + "name": "usage_time_created", + "columns": ["workspace_id", "time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "usage_workspace_id_id_pk": { + "name": "usage_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip_rate_limit": { + "name": "ip_rate_limit", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "interval": { + "name": "interval", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "count": { + "name": "count", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_rate_limit_ip_interval_pk": { + "name": "ip_rate_limit_ip_interval_pk", + "columns": ["ip", "interval"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip": { + "name": "ip", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage": { + "name": "usage", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_ip_pk": { + "name": "ip_ip_pk", + "columns": ["ip"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "key": { + "name": "key", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_used": { + "name": "time_used", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_key": { + "name": "global_key", + "columns": ["key"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "key_workspace_id_id_pk": { + "name": "key_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "model": { + "name": "model", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "model_workspace_model": { + "name": "model_workspace_model", + "columns": ["workspace_id", "model"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "model_workspace_id_id_pk": { + "name": "model_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "provider": { + "name": "provider", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentials": { + "name": "credentials", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspace_provider": { + "name": "workspace_provider", + "columns": ["workspace_id", "provider"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "provider_workspace_id_id_pk": { + "name": "provider_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_seen": { + "name": "time_seen", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "enum('admin','member')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_subscribed": { + "name": "time_subscribed", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sub_interval_usage": { + "name": "sub_interval_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sub_monthly_usage": { + "name": "sub_monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sub_time_interval_usage_updated": { + "name": "sub_time_interval_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sub_time_monthly_usage_updated": { + "name": "sub_time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_account_id": { + "name": "user_account_id", + "columns": ["workspace_id", "account_id"], + "isUnique": true + }, + "user_email": { + "name": "user_email", + "columns": ["workspace_id", "email"], + "isUnique": true + }, + "global_account_id": { + "name": "global_account_id", + "columns": ["account_id"], + "isUnique": false + }, + "global_email": { + "name": "global_email", + "columns": ["email"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "user_workspace_id_id_pk": { + "name": "user_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "workspace": { + "name": "workspace", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "slug": { + "name": "slug", + "columns": ["slug"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "workspace_id": { + "name": "workspace_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + } + }, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "tables": {}, + "indexes": {} + } +} diff --git a/packages/console/core/migrations/meta/0047_snapshot.json b/packages/console/core/migrations/meta/0047_snapshot.json new file mode 100644 index 00000000000..f8002bd8bb6 --- /dev/null +++ b/packages/console/core/migrations/meta/0047_snapshot.json @@ -0,0 +1,1207 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "fec4cb15-6f13-465d-a902-b76b026872f4", + "prevId": "f3725f6d-5f33-4497-b4ba-cf05c46fb873", + "tables": { + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "account_id_pk": { + "name": "account_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "auth": { + "name": "auth", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "enum('email','github','google')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "provider": { + "name": "provider", + "columns": ["provider", "subject"], + "isUnique": true + }, + "account_id": { + "name": "account_id", + "columns": ["account_id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "auth_id_pk": { + "name": "auth_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "benchmark": { + "name": "benchmark", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "agent": { + "name": "agent", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "mediumtext", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "time_created": { + "name": "time_created", + "columns": ["time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "benchmark_id_pk": { + "name": "benchmark_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "billing": { + "name": "billing", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_id": { + "name": "payment_method_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_type": { + "name": "payment_method_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_last4": { + "name": "payment_method_last4", + "type": "varchar(4)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "balance": { + "name": "balance", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload": { + "name": "reload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_trigger": { + "name": "reload_trigger", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_amount": { + "name": "reload_amount", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_error": { + "name": "reload_error", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_error": { + "name": "time_reload_error", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_locked_till": { + "name": "time_reload_locked_till", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subscription_id": { + "name": "subscription_id", + "type": "varchar(28)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_customer_id": { + "name": "global_customer_id", + "columns": ["customer_id"], + "isUnique": true + }, + "global_subscription_id": { + "name": "global_subscription_id", + "columns": ["subscription_id"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "billing_workspace_id_id_pk": { + "name": "billing_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "payment": { + "name": "payment", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "invoice_id": { + "name": "invoice_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_id": { + "name": "payment_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_refunded": { + "name": "time_refunded", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "payment_workspace_id_id_pk": { + "name": "payment_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "subscription": { + "name": "subscription", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rolling_usage": { + "name": "rolling_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fixed_usage": { + "name": "fixed_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_rolling_updated": { + "name": "time_rolling_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_fixed_updated": { + "name": "time_fixed_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "workspace_user_id": { + "name": "workspace_user_id", + "columns": ["workspace_id", "user_id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "subscription_workspace_id_id_pk": { + "name": "subscription_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "usage": { + "name": "usage", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reasoning_tokens": { + "name": "reasoning_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_read_tokens": { + "name": "cache_read_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_5m_tokens": { + "name": "cache_write_5m_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_1h_tokens": { + "name": "cache_write_1h_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost": { + "name": "cost", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key_id": { + "name": "key_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enrichment": { + "name": "enrichment", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "usage_time_created": { + "name": "usage_time_created", + "columns": ["workspace_id", "time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "usage_workspace_id_id_pk": { + "name": "usage_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip_rate_limit": { + "name": "ip_rate_limit", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "interval": { + "name": "interval", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "count": { + "name": "count", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_rate_limit_ip_interval_pk": { + "name": "ip_rate_limit_ip_interval_pk", + "columns": ["ip", "interval"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip": { + "name": "ip", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage": { + "name": "usage", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_ip_pk": { + "name": "ip_ip_pk", + "columns": ["ip"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "key": { + "name": "key", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_used": { + "name": "time_used", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_key": { + "name": "global_key", + "columns": ["key"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "key_workspace_id_id_pk": { + "name": "key_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "model": { + "name": "model", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "model_workspace_model": { + "name": "model_workspace_model", + "columns": ["workspace_id", "model"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "model_workspace_id_id_pk": { + "name": "model_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "provider": { + "name": "provider", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentials": { + "name": "credentials", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspace_provider": { + "name": "workspace_provider", + "columns": ["workspace_id", "provider"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "provider_workspace_id_id_pk": { + "name": "provider_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_seen": { + "name": "time_seen", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "enum('admin','member')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_account_id": { + "name": "user_account_id", + "columns": ["workspace_id", "account_id"], + "isUnique": true + }, + "user_email": { + "name": "user_email", + "columns": ["workspace_id", "email"], + "isUnique": true + }, + "global_account_id": { + "name": "global_account_id", + "columns": ["account_id"], + "isUnique": false + }, + "global_email": { + "name": "global_email", + "columns": ["email"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "user_workspace_id_id_pk": { + "name": "user_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "workspace": { + "name": "workspace", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "slug": { + "name": "slug", + "columns": ["slug"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "workspace_id": { + "name": "workspace_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + } + }, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "tables": {}, + "indexes": {} + } +} diff --git a/packages/console/core/migrations/meta/0048_snapshot.json b/packages/console/core/migrations/meta/0048_snapshot.json new file mode 100644 index 00000000000..e0593749b38 --- /dev/null +++ b/packages/console/core/migrations/meta/0048_snapshot.json @@ -0,0 +1,1207 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "bb90bb3e-fd08-439a-b92f-5f433807480e", + "prevId": "fec4cb15-6f13-465d-a902-b76b026872f4", + "tables": { + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "account_id_pk": { + "name": "account_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "auth": { + "name": "auth", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "enum('email','github','google')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "provider": { + "name": "provider", + "columns": ["provider", "subject"], + "isUnique": true + }, + "account_id": { + "name": "account_id", + "columns": ["account_id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "auth_id_pk": { + "name": "auth_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "benchmark": { + "name": "benchmark", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "agent": { + "name": "agent", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "mediumtext", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "time_created": { + "name": "time_created", + "columns": ["time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "benchmark_id_pk": { + "name": "benchmark_id_pk", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "billing": { + "name": "billing", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_id": { + "name": "payment_method_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_type": { + "name": "payment_method_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_method_last4": { + "name": "payment_method_last4", + "type": "varchar(4)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "balance": { + "name": "balance", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload": { + "name": "reload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_trigger": { + "name": "reload_trigger", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_amount": { + "name": "reload_amount", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reload_error": { + "name": "reload_error", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_error": { + "name": "time_reload_error", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_reload_locked_till": { + "name": "time_reload_locked_till", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "subscription_id": { + "name": "subscription_id", + "type": "varchar(28)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_customer_id": { + "name": "global_customer_id", + "columns": ["customer_id"], + "isUnique": true + }, + "global_subscription_id": { + "name": "global_subscription_id", + "columns": ["subscription_id"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "billing_workspace_id_id_pk": { + "name": "billing_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "payment": { + "name": "payment", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customer_id": { + "name": "customer_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "invoice_id": { + "name": "invoice_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payment_id": { + "name": "payment_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "amount": { + "name": "amount", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_refunded": { + "name": "time_refunded", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "payment_workspace_id_id_pk": { + "name": "payment_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "subscription": { + "name": "subscription", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rolling_usage": { + "name": "rolling_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fixed_usage": { + "name": "fixed_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_rolling_updated": { + "name": "time_rolling_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_fixed_updated": { + "name": "time_fixed_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "workspace_user_id": { + "name": "workspace_user_id", + "columns": ["workspace_id", "user_id"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "subscription_workspace_id_id_pk": { + "name": "subscription_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "usage": { + "name": "usage", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reasoning_tokens": { + "name": "reasoning_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_read_tokens": { + "name": "cache_read_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_5m_tokens": { + "name": "cache_write_5m_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cache_write_1h_tokens": { + "name": "cache_write_1h_tokens", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost": { + "name": "cost", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key_id": { + "name": "key_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enrichment": { + "name": "enrichment", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "usage_time_created": { + "name": "usage_time_created", + "columns": ["workspace_id", "time_created"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "usage_workspace_id_id_pk": { + "name": "usage_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip_rate_limit": { + "name": "ip_rate_limit", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "interval": { + "name": "interval", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "count": { + "name": "count", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_rate_limit_ip_interval_pk": { + "name": "ip_rate_limit_ip_interval_pk", + "columns": ["ip", "interval"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "ip": { + "name": "ip", + "columns": { + "ip": { + "name": "ip", + "type": "varchar(45)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "usage": { + "name": "usage", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "ip_ip_pk": { + "name": "ip_ip_pk", + "columns": ["ip"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "key": { + "name": "key", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_used": { + "name": "time_used", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "global_key": { + "name": "global_key", + "columns": ["key"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "key_workspace_id_id_pk": { + "name": "key_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "model": { + "name": "model", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "model_workspace_model": { + "name": "model_workspace_model", + "columns": ["workspace_id", "model"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "model_workspace_id_id_pk": { + "name": "model_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "provider": { + "name": "provider", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentials": { + "name": "credentials", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "workspace_provider": { + "name": "workspace_provider", + "columns": ["workspace_id", "provider"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "provider_workspace_id_id_pk": { + "name": "provider_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_seen": { + "name": "time_seen", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "enum('admin','member')", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monthly_limit": { + "name": "monthly_limit", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "monthly_usage": { + "name": "monthly_usage", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_monthly_usage_updated": { + "name": "time_monthly_usage_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_account_id": { + "name": "user_account_id", + "columns": ["workspace_id", "account_id"], + "isUnique": true + }, + "user_email": { + "name": "user_email", + "columns": ["workspace_id", "email"], + "isUnique": true + }, + "global_account_id": { + "name": "global_account_id", + "columns": ["account_id"], + "isUnique": false + }, + "global_email": { + "name": "global_email", + "columns": ["email"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "user_workspace_id_id_pk": { + "name": "user_workspace_id_id_pk", + "columns": ["workspace_id", "id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "workspace": { + "name": "workspace", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "slug": { + "name": "slug", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "time_created": { + "name": "time_created", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "time_updated": { + "name": "time_updated", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)" + }, + "time_deleted": { + "name": "time_deleted", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "slug": { + "name": "slug", + "columns": ["slug"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "workspace_id": { + "name": "workspace_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + } + }, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "tables": {}, + "indexes": {} + } +} diff --git a/packages/console/core/migrations/meta/_journal.json b/packages/console/core/migrations/meta/_journal.json index 7925a46a5d8..c534aaa590c 100644 --- a/packages/console/core/migrations/meta/_journal.json +++ b/packages/console/core/migrations/meta/_journal.json @@ -323,6 +323,27 @@ "when": 1767765497502, "tag": "0045_cuddly_diamondback", "breakpoints": true + }, + { + "idx": 46, + "version": "5", + "when": 1767912262458, + "tag": "0046_charming_black_bolt", + "breakpoints": true + }, + { + "idx": 47, + "version": "5", + "when": 1767916965243, + "tag": "0047_huge_omega_red", + "breakpoints": true + }, + { + "idx": 48, + "version": "5", + "when": 1767917785224, + "tag": "0048_mean_frank_castle", + "breakpoints": true } ] } diff --git a/packages/console/core/script/batch-onboard.ts b/packages/console/core/script/batch-onboard.ts new file mode 100644 index 00000000000..a1a2cf50f31 --- /dev/null +++ b/packages/console/core/script/batch-onboard.ts @@ -0,0 +1,91 @@ +#!/usr/bin/env bun +import { $ } from "bun" + +async function done() { + await $`bun script/onboard-zen-black.ts wrk_01KBDW4XQQA03M9WRVG13WC4KV johnnymiranda@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KB09PA9KRGNWQC6SAPDK72FC chris@nuwavecommerce.com` + await $`bun script/onboard-zen-black.ts wrk_01KD47Y1TV6H25TH4FE8J9Z96C coniferconcepts@protonmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K5PBX9DTMVWYWSQN825PX5JD ccptmd@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJ5W695YB7QXYBF17JGE3K synhex@proton.me` + await $`bun script/onboard-zen-black.ts wrk_01KDQ5A7D4E1XZ67NKTWX6PQQY joel97montano@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K6VZ9R6Q85G86KP99WJJFNCS gpstrucha@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KD75TGR57YJPSFWDBZ4WVTMW velazcod@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KDRG9HBMQCXPPV5TTMPKMKR2 scott@scopestar.com` + await $`bun script/onboard-zen-black.ts wrk_01K6KZNC7FHJ3RF989Y22EFFK2 andrew.rentschler@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K59FHPX0GR51YQG2CT9DAF5M rtorresware@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJAFSJ3SA52EENSGGWY7K3 connorksmith@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K5M7F0S3G93MJNBG6DG8THAE williamtracyadams@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K4CPKRNP4CWK2D5BYKMMKTXQ christoph@schmatzler.com` + await $`bun script/onboard-zen-black.ts wrk_01K5GYKMHJG6G172D944MCDJ70 fabian.rodrez@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KD4Q2FAT1465AYQPY03R82JG kylep91@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K5HFPPJ67MZSEE8AAMHECR1Q michael@mabbott.dev` + await $`bun script/onboard-zen-black.ts wrk_01KAE92ACV5AEQ2QJ173W26CTF sam_roehrich@icloud.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJ4BZKCFKWDTJN95X8BBSN roee@bellum.dev` + await $`bun script/onboard-zen-black.ts wrk_01KEAFNZA1T20QY91FZPBWM2ED hendrik@mans.de` + await $`bun script/onboard-zen-black.ts wrk_01KD85CQXVH5G390J8Z69NQ01G rob@anchorwatch.com` + await $`bun script/onboard-zen-black.ts wrk_01KE7XH09S7KJ5F6SW9QQ4YZQ3 seangherardi@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KDGJQSKFXMW9YWWB2SDW4D2C magimetal@pm.me` + await $`bun script/onboard-zen-black.ts wrk_01KCCP5C49JZS4HSRBX7XJX25P matthijswolting@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K4DHK0YHZ40B7QWA5T9QD5CM faisal@hulayyil.com` + await $`bun script/onboard-zen-black.ts wrk_01K59KJHXBJYJ5D7NMKVEBQK12 redwood.cogent5b@icloud.com` + await $`bun script/onboard-zen-black.ts wrk_01K58NJXNDYCMN6MZAH5GBA2V9 mail@wobbat.com` + await $`bun script/onboard-zen-black.ts wrk_01K6AR1ZET89H8NB691FQ2C2VB anthony.kroe@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K6ZMFSTFYWPACV2QNFAVBBVC torbjon@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K5HX50C744YRF5MFJVCQ5784 rishabh@getgale.app` + await $`bun script/onboard-zen-black.ts wrk_01K5AXKDXK6P705ZE1RGJ54DJG skastr052@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJ5PXJDMAW7VDB223J6VED jason.larsen@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KC2QDEGSR07GZ18A5FHV68K4 jeremy@thegollys.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAE40B947397VKVY9JZPQZZ micah@waldste.in` + await $`bun script/onboard-zen-black.ts wrk_01KEAHWCP8710GEAVF8NGY2B8S sid@finchlegal.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAHW437Q6SQZBVXS480SVAX soma.eas@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAE1HJ37GY9K8YTHHE0WBDS steve@seguin.email` + await $`bun script/onboard-zen-black.ts wrk_01K48XKJA60YH8YNSHR1TAV8JB zainxwania@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KDP0E4FG325PFK0HTC9BBPNK peter.houghton@outlook.com` + await $`bun script/onboard-zen-black.ts wrk_01K7ARJD3S9DS84RXKGK7RNJ1G leventyuksel93@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEBZKFKGMXWDYHYQPE5HV2DK james@corbettonline.co.uk` + await $`bun script/onboard-zen-black.ts wrk_01K4PNZCG496059QVVN2W8BKH5 gdiaz@qswarm.com` + await $`bun script/onboard-zen-black.ts wrk_01K4CH29P0HKTRPNWFX6V3K4ZK artmore@protonmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K971RFTA2H8A181F7GV0M2KG nikita@frolov.fi` + await $`bun script/onboard-zen-black.ts wrk_01KAWXVSWGT7M0FZKRK7J96C40 jakob@endform.dev` + await $`bun script/onboard-zen-black.ts wrk_01KEBAHA1C5MD5W2N8RYEVH8B8 richlyelks@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K57NR05JNBV9FYWN8V4PE74X shahmurtaza5@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAEDXMYF8FFDRJS3129BHXZ me@tophergroenink.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJN0Q972162MCAKN5MYXV0 ajcwebdev@pm.me` + await $`bun script/onboard-zen-black.ts wrk_01KDWKNN6JVH49CNQF7Y6T77TS d.camata@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEANMCW8H8MX7NXN9QRBC2JY andrew.ds.choi@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K9DJ10EJ1JQ8QE83G2BZTCAT max@marze.dev` + await $`bun script/onboard-zen-black.ts wrk_01KEB67HYXGHSA19KKYQWANWYC ervin@canigur.com` + await $`bun script/onboard-zen-black.ts wrk_01KBMQ66RB7RYY4MBE69MYQY0J sakhnyukmikhail@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KECJH7FG2GHFK1J1MF73W63R isaac.dobbins@icloud.com` + await $`bun script/onboard-zen-black.ts wrk_01KAFPM94SV343J8SS8ESEHMYG mrkordell@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KBDKY5JHT84Y3K8G9Q4MGAX7 pirnay@deveytan.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAKBCAKKR33T3F0A33EP9W6 1mrtemeck1@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEANHV7AEMFP5RY6KWXCA1T6 github@emilebangma.com` + await $`bun script/onboard-zen-black.ts wrk_01KEARQYY8JRY2HSYX7BR5ATMY hi@henryzoo.com` + await $`bun script/onboard-zen-black.ts wrk_01K9BT5FEF19STHX5HBQGDXAD4 cameron@harderhutton.dev` + await $`bun script/onboard-zen-black.ts wrk_01K5814NN9C8MCQ3W9269GQPX1 niccholaspage@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KBR4P09M7524ME1Z250WM2XT stephen.patrick.murray@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K6JVB4J0QG979YD790XPZSSX jcummings5@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KA94MDGKNTAKB6P0B3RRCVR0 matt@eatsleeprepeat.net` + await $`bun script/onboard-zen-black.ts wrk_01KEB55FEX2ZTK13PYK3YEJSBE hello@trmcnvn.dev` + await $`bun script/onboard-zen-black.ts wrk_01K58YHW99X2T2EDPM2ZNAWM97 ashakdwipeea@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAJKB8BSAF3FQJH1MD6J1WV ben@cinematicsoftware.com` + await $`bun script/onboard-zen-black.ts wrk_01KCS98AJ0SJG6SQY845D0A7XQ ndejesus1227@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KDC8ZCR2021GEMP4G0AA4D4M cmz1023@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K59G802MEFN7AWRPM2QMP4PC chrhicks@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K4EVHWGY50JXFEAM8FT12B17 fahimanwer.08@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEA9RZT7A5K55G8EQQ2V1EWF sandro@scorp.dev` + await $`bun script/onboard-zen-black.ts wrk_01K63V94DSDX76Y21PG98M0GV1 franklin-in-mars@pm.me` + await $`bun script/onboard-zen-black.ts wrk_01KDNXT802CFWR10XSK35PWVG9 alexander.vikman@informationsgruppen.se` + await $`bun script/onboard-zen-black.ts wrk_01K7M79KFFD63S177YPY7Z1QTF me@lozanojoseph.com` + await $`bun script/onboard-zen-black.ts wrk_01KEC9ARJZ12X6CW23HKHNMTVP charlieirish@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K4M9Q5NXP6MT29W1186V0HPK foldvarszki@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K6JKWYXB7KNKWFWXFAV0PD3S johnlindquist@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K4GEQTAHZR28B76DG6F2QX2G mail@justin-vogt.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAK4F15VVPHQH8MSY0GR7XP felix@trulsson.co` + await $`bun script/onboard-zen-black.ts wrk_01K6DSE6F44YNE7AFA4PTF8JA0 jorge.villalobos2809@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAK10BVRFVN1WSXYMR3DQJM jaskyle4@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01KEAE0JEXTVCWEKKB7MAGP37W themindoverall@gmail.com` + await $`bun script/onboard-zen-black.ts wrk_01K7Q7J930ZS4P8088NBW0QTRY dpshadey22@gmail.com` // dylan.shade@hey.com + await $`bun script/onboard-zen-black.ts wrk_01KC22GWVQXVJ15B2K88YNVGJJ maxstevens2708@gmail.com` // mail@maxstevens.nl +} diff --git a/packages/console/core/script/lookup-user.ts b/packages/console/core/script/lookup-user.ts index 0b8e864409d..33a18ebfcba 100644 --- a/packages/console/core/script/lookup-user.ts +++ b/packages/console/core/script/lookup-user.ts @@ -1,8 +1,11 @@ -import { Database, eq, sql, inArray } from "../src/drizzle/index.js" +import { Database, and, eq, sql } from "../src/drizzle/index.js" import { AuthTable } from "../src/schema/auth.sql.js" import { UserTable } from "../src/schema/user.sql.js" -import { BillingTable, PaymentTable, UsageTable } from "../src/schema/billing.sql.js" +import { BillingTable, PaymentTable, SubscriptionTable, UsageTable } from "../src/schema/billing.sql.js" import { WorkspaceTable } from "../src/schema/workspace.sql.js" +import { BlackData } from "../src/black.js" +import { centsToMicroCents } from "../src/util/price.js" +import { getWeekBounds } from "../src/util/date.js" // get input from command line const identifier = process.argv[2] @@ -56,6 +59,44 @@ async function printWorkspace(workspaceID: string) { printHeader(`Workspace "${workspace.name}" (${workspace.id})`) + await printTable("Users", (tx) => + tx + .select({ + authEmail: AuthTable.subject, + inviteEmail: UserTable.email, + role: UserTable.role, + timeSeen: UserTable.timeSeen, + monthlyLimit: UserTable.monthlyLimit, + monthlyUsage: UserTable.monthlyUsage, + timeDeleted: UserTable.timeDeleted, + fixedUsage: SubscriptionTable.fixedUsage, + rollingUsage: SubscriptionTable.rollingUsage, + timeFixedUpdated: SubscriptionTable.timeFixedUpdated, + timeRollingUpdated: SubscriptionTable.timeRollingUpdated, + timeSubscriptionCreated: SubscriptionTable.timeCreated, + }) + .from(UserTable) + .leftJoin(AuthTable, and(eq(UserTable.accountID, AuthTable.accountID), eq(AuthTable.provider, "email"))) + .leftJoin(SubscriptionTable, eq(SubscriptionTable.userID, UserTable.id)) + .where(eq(UserTable.workspaceID, workspace.id)) + .then((rows) => + rows.map((row) => { + const subStatus = getSubscriptionStatus(row) + return { + email: (row.timeDeleted ? "❌ " : "") + (row.authEmail ?? row.inviteEmail), + role: row.role, + timeSeen: formatDate(row.timeSeen), + monthly: formatMonthlyUsage(row.monthlyUsage, row.monthlyLimit), + subscribed: formatDate(row.timeSubscriptionCreated), + subWeekly: subStatus.weekly, + subRolling: subStatus.rolling, + rateLimited: subStatus.rateLimited, + retryIn: subStatus.retryIn, + } + }), + ), + ) + await printTable("Billing", (tx) => tx .select({ @@ -124,6 +165,80 @@ async function printWorkspace(workspaceID: string) { ) } +function formatMicroCents(value: number | null | undefined) { + if (value === null || value === undefined) return null + return `$${(value / 100000000).toFixed(2)}` +} + +function formatDate(value: Date | null | undefined) { + if (!value) return null + return value.toISOString().split("T")[0] +} + +function formatMonthlyUsage(usage: number | null | undefined, limit: number | null | undefined) { + const usageText = formatMicroCents(usage) ?? "$0.00" + if (limit === null || limit === undefined) return `${usageText} / no limit` + return `${usageText} / $${limit.toFixed(2)}` +} + +function formatRetryTime(seconds: number) { + const days = Math.floor(seconds / 86400) + if (days >= 1) return `${days} day${days > 1 ? "s" : ""}` + const hours = Math.floor(seconds / 3600) + const minutes = Math.ceil((seconds % 3600) / 60) + if (hours >= 1) return `${hours}hr ${minutes}min` + return `${minutes}min` +} + +function getSubscriptionStatus(row: { + timeSubscriptionCreated: Date | null + fixedUsage: number | null + rollingUsage: number | null + timeFixedUpdated: Date | null + timeRollingUpdated: Date | null +}) { + if (!row.timeSubscriptionCreated) { + return { weekly: null, rolling: null, rateLimited: null, retryIn: null } + } + + const black = BlackData.get() + const now = new Date() + const week = getWeekBounds(now) + + const fixedLimit = black.fixedLimit ? centsToMicroCents(black.fixedLimit * 100) : null + const rollingLimit = black.rollingLimit ? centsToMicroCents(black.rollingLimit * 100) : null + const rollingWindowMs = (black.rollingWindow ?? 5) * 3600 * 1000 + + // Calculate current weekly usage (reset if outside current week) + const currentWeekly = + row.fixedUsage && row.timeFixedUpdated && row.timeFixedUpdated >= week.start ? row.fixedUsage : 0 + + // Calculate current rolling usage + const windowStart = new Date(now.getTime() - rollingWindowMs) + const currentRolling = + row.rollingUsage && row.timeRollingUpdated && row.timeRollingUpdated >= windowStart ? row.rollingUsage : 0 + + // Check rate limiting + const isWeeklyLimited = fixedLimit !== null && currentWeekly >= fixedLimit + const isRollingLimited = rollingLimit !== null && currentRolling >= rollingLimit + + let retryIn: string | null = null + if (isWeeklyLimited) { + const retryAfter = Math.ceil((week.end.getTime() - now.getTime()) / 1000) + retryIn = formatRetryTime(retryAfter) + } else if (isRollingLimited && row.timeRollingUpdated) { + const retryAfter = Math.ceil((row.timeRollingUpdated.getTime() + rollingWindowMs - now.getTime()) / 1000) + retryIn = formatRetryTime(retryAfter) + } + + return { + weekly: fixedLimit !== null ? `${formatMicroCents(currentWeekly)} / $${black.fixedLimit}` : null, + rolling: rollingLimit !== null ? `${formatMicroCents(currentRolling)} / $${black.rollingLimit}` : null, + rateLimited: isWeeklyLimited || isRollingLimited ? "yes" : "no", + retryIn, + } +} + function printHeader(title: string) { console.log() console.log("─".repeat(title.length)) diff --git a/packages/console/core/script/onboard-zen-black.ts b/packages/console/core/script/onboard-zen-black.ts index 15418af2fca..06e5afe1225 100644 --- a/packages/console/core/script/onboard-zen-black.ts +++ b/packages/console/core/script/onboard-zen-black.ts @@ -1,35 +1,35 @@ import { Billing } from "../src/billing.js" -import { Database, eq, and, sql } from "../src/drizzle/index.js" -import { AuthTable } from "../src/schema/auth.sql.js" +import { and, Database, eq, isNull, sql } from "../src/drizzle/index.js" import { UserTable } from "../src/schema/user.sql.js" -import { BillingTable, PaymentTable } from "../src/schema/billing.sql.js" +import { BillingTable, PaymentTable, SubscriptionTable } from "../src/schema/billing.sql.js" import { Identifier } from "../src/identifier.js" import { centsToMicroCents } from "../src/util/price.js" +import { AuthTable } from "../src/schema/auth.sql.js" const workspaceID = process.argv[2] const email = process.argv[3] +console.log(`Onboarding workspace ${workspaceID} for email ${email}`) + if (!workspaceID || !email) { console.error("Usage: bun onboard-zen-black.ts ") process.exit(1) } // Look up the Stripe customer by email -const customers = await Billing.stripe().customers.list({ email, limit: 1 }) -const customer = customers.data[0] -if (!customer) { +const customers = await Billing.stripe().customers.list({ email, limit: 10, expand: ["data.subscriptions"] }) +if (!customers.data) { console.error(`Error: No Stripe customer found for email ${email}`) process.exit(1) } -const customerID = customer.id - -// Get the subscription id -const subscriptions = await Billing.stripe().subscriptions.list({ customer: customerID, limit: 1 }) -const subscription = subscriptions.data[0] -if (!subscription) { - console.error(`Error: Customer ${customerID} does not have a subscription`) +const customer = customers.data.find((c) => c.subscriptions?.data[0]?.items.data[0]?.price.unit_amount === 20000) +if (!customer) { + console.error(`Error: No Stripe customer found for email ${email} with $200 subscription`) process.exit(1) } + +const customerID = customer.id +const subscription = customer.subscriptions!.data[0] const subscriptionID = subscription.id // Validate the subscription is $200 @@ -90,29 +90,21 @@ const paymentMethod = paymentMethodID ? await Billing.stripe().paymentMethods.re const paymentMethodLast4 = paymentMethod?.card?.last4 ?? null const paymentMethodType = paymentMethod?.type ?? null -// Look up the user by email via AuthTable -const auth = await Database.use((tx) => - tx - .select({ accountID: AuthTable.accountID }) - .from(AuthTable) - .where(and(eq(AuthTable.provider, "email"), eq(AuthTable.subject, email))) - .then((rows) => rows[0]), -) -if (!auth) { - console.error(`Error: No user found with email ${email}`) - process.exit(1) -} - // Look up the user in the workspace -const user = await Database.use((tx) => +const users = await Database.use((tx) => tx - .select({ id: UserTable.id }) + .select({ id: UserTable.id, email: AuthTable.subject }) .from(UserTable) - .where(and(eq(UserTable.workspaceID, workspaceID), eq(UserTable.accountID, auth.accountID))) - .then((rows) => rows[0]), + .innerJoin(AuthTable, and(eq(AuthTable.accountID, UserTable.accountID), eq(AuthTable.provider, "email"))) + .where(and(eq(UserTable.workspaceID, workspaceID), isNull(UserTable.timeDeleted))), ) +if (users.length === 0) { + console.error(`Error: No users found in workspace ${workspaceID}`) + process.exit(1) +} +const user = users.length === 1 ? users[0] : users.find((u) => u.email === email) if (!user) { - console.error(`Error: User with email ${email} is not a member of workspace ${workspaceID}`) + console.error(`Error: User with email ${email} not found in workspace ${workspaceID}`) process.exit(1) } @@ -136,13 +128,12 @@ await Database.transaction(async (tx) => { }) .where(eq(BillingTable.workspaceID, workspaceID)) - // Set current time as timeSubscribed on user - await tx - .update(UserTable) - .set({ - timeSubscribed: sql`now()`, - }) - .where(eq(UserTable.id, user.id)) + // Create a row in subscription table + await tx.insert(SubscriptionTable).values({ + workspaceID, + id: Identifier.create("subscription"), + userID: user.id, + }) // Create a row in payments table await tx.insert(PaymentTable).values({ diff --git a/packages/console/core/src/black.ts b/packages/console/core/src/black.ts index a4c44aea56e..0ecbc94a45f 100644 --- a/packages/console/core/src/black.ts +++ b/packages/console/core/src/black.ts @@ -4,9 +4,9 @@ import { Resource } from "@opencode-ai/console-resource" export namespace BlackData { const Schema = z.object({ - monthlyLimit: z.number().int(), - intervalLimit: z.number().int(), - intervalLength: z.number().int(), + fixedLimit: z.number().int(), + rollingLimit: z.number().int(), + rollingWindow: z.number().int(), }) export const validate = fn(Schema, (input) => { diff --git a/packages/console/core/src/identifier.ts b/packages/console/core/src/identifier.ts index f94765ec702..b10bf32f6f1 100644 --- a/packages/console/core/src/identifier.ts +++ b/packages/console/core/src/identifier.ts @@ -11,6 +11,7 @@ export namespace Identifier { model: "mod", payment: "pay", provider: "prv", + subscription: "sub", usage: "usg", user: "usr", workspace: "wrk", diff --git a/packages/console/core/src/schema/billing.sql.ts b/packages/console/core/src/schema/billing.sql.ts index 42da1377691..f56cf4182d0 100644 --- a/packages/console/core/src/schema/billing.sql.ts +++ b/packages/console/core/src/schema/billing.sql.ts @@ -30,6 +30,20 @@ export const BillingTable = mysqlTable( ], ) +export const SubscriptionTable = mysqlTable( + "subscription", + { + ...workspaceColumns, + ...timestamps, + userID: ulid("user_id").notNull(), + rollingUsage: bigint("rolling_usage", { mode: "number" }), + fixedUsage: bigint("fixed_usage", { mode: "number" }), + timeRollingUpdated: utc("time_rolling_updated"), + timeFixedUpdated: utc("time_fixed_updated"), + }, + (table) => [...workspaceIndexes(table), uniqueIndex("workspace_user_id").on(table.workspaceID, table.userID)], +) + export const PaymentTable = mysqlTable( "payment", { diff --git a/packages/console/core/src/schema/user.sql.ts b/packages/console/core/src/schema/user.sql.ts index 46d02c4a857..7fd7f5e1ed0 100644 --- a/packages/console/core/src/schema/user.sql.ts +++ b/packages/console/core/src/schema/user.sql.ts @@ -18,12 +18,6 @@ export const UserTable = mysqlTable( monthlyLimit: int("monthly_limit"), monthlyUsage: bigint("monthly_usage", { mode: "number" }), timeMonthlyUsageUpdated: utc("time_monthly_usage_updated"), - // subscription - timeSubscribed: utc("time_subscribed"), - subIntervalUsage: bigint("sub_interval_usage", { mode: "number" }), - subMonthlyUsage: bigint("sub_monthly_usage", { mode: "number" }), - timeSubIntervalUsageUpdated: utc("sub_time_interval_usage_updated"), - timeSubMonthlyUsageUpdated: utc("sub_time_monthly_usage_updated"), }, (table) => [ ...workspaceIndexes(table), diff --git a/packages/console/core/src/util/date.ts b/packages/console/core/src/util/date.ts new file mode 100644 index 00000000000..7f34c9bb5eb --- /dev/null +++ b/packages/console/core/src/util/date.ts @@ -0,0 +1,9 @@ +export function getWeekBounds(date: Date) { + const dayOfWeek = date.getUTCDay() + const start = new Date(date) + start.setUTCDate(date.getUTCDate() - dayOfWeek + 1) + start.setUTCHours(0, 0, 0, 0) + const end = new Date(start) + end.setUTCDate(start.getUTCDate() + 7) + return { start, end } +} diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index be234948424..7d2408a08b6 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -754,9 +754,25 @@ export namespace Config { ) .optional() .describe("Variant-specific configuration"), + excludeDefaultOptions: z + .boolean() + .optional() + .describe( + "Exclude all default provider options for this model (useful for custom APIs that don't support them). " + + "When true, disables automatic parameter injection like thinkingConfig, reasoningEffort, promptCacheKey, etc. " + + "Example: { 'models': { 'my-model': { 'excludeDefaultOptions': true } } }", + ), }), ) .optional(), + excludeDefaultOptions: z + .boolean() + .optional() + .describe( + "Exclude all default provider options for all models in this provider (useful for custom APIs that don't support them). " + + "When true, disables automatic parameter injection for all models. Model-level setting overrides this. " + + "Example: { 'provider': { 'myapi': { 'excludeDefaultOptions': true } } }", + ), options: z .object({ apiKey: z.string().optional(), diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index 9f14b5464c9..54fb098e2f4 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -504,6 +504,7 @@ export namespace Provider { headers: z.record(z.string(), z.string()), release_date: z.string(), variants: z.record(z.string(), z.record(z.string(), z.any())).optional(), + excludeDefaultOptions: z.boolean().optional(), }) .meta({ ref: "Model", @@ -867,6 +868,13 @@ export namespace Provider { (v) => omit(v, ["disabled"]), ) } + + // Apply excludeDefaultOptions from config + // Priority: model-level > provider-level > default (undefined/false) + // When true, disables all default parameters to avoid API compatibility issues + const modelConfig = configProvider?.models?.[modelID] + model.excludeDefaultOptions = + modelConfig?.excludeDefaultOptions ?? configProvider?.excludeDefaultOptions ?? false } if (Object.keys(provider.models).length === 0) { diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 080da63784e..8ee14b851ce 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -436,6 +436,13 @@ export namespace ProviderTransform { sessionID: string, providerOptions?: Record, ): Record { + // When excludeDefaultOptions is true, skip all default parameter injection + // This is useful for custom APIs that may not support provider-specific options + // like thinkingConfig, reasoningEffort, promptCacheKey, chat_template_args, etc. + if (model.excludeDefaultOptions) { + return {} + } + const result: Record = {} if (model.api.npm === "@openrouter/ai-sdk-provider") { @@ -490,6 +497,11 @@ export namespace ProviderTransform { } export function smallOptions(model: Provider.Model) { + // When excludeDefaultOptions is true, skip all default parameter injection for small models + if (model.excludeDefaultOptions) { + return {} + } + if (model.providerID === "openai" || model.api.id.includes("gpt-5")) { if (model.api.id.includes("5.")) { return { reasoningEffort: "low" } diff --git a/packages/opencode/src/session/llm.ts b/packages/opencode/src/session/llm.ts index 0db453a2229..4a2fb88177e 100644 --- a/packages/opencode/src/session/llm.ts +++ b/packages/opencode/src/session/llm.ts @@ -99,11 +99,14 @@ export namespace LLM { message: input.user, }, { - temperature: input.model.capabilities.temperature - ? (input.agent.temperature ?? ProviderTransform.temperature(input.model)) - : undefined, - topP: input.agent.topP ?? ProviderTransform.topP(input.model), - topK: ProviderTransform.topK(input.model), + // When excludeDefaultOptions is true, only use explicitly configured values + temperature: input.model.excludeDefaultOptions + ? input.agent.temperature + : input.model.capabilities.temperature + ? (input.agent.temperature ?? ProviderTransform.temperature(input.model)) + : undefined, + topP: input.model.excludeDefaultOptions ? input.agent.topP : (input.agent.topP ?? ProviderTransform.topP(input.model)), + topK: input.model.excludeDefaultOptions ? undefined : ProviderTransform.topK(input.model), options, }, ) @@ -154,7 +157,9 @@ export namespace LLM { providerOptions: ProviderTransform.providerOptions(input.model, params.options), activeTools: Object.keys(tools).filter((x) => x !== "invalid"), tools, - maxOutputTokens, + // When excludeDefaultOptions is true, don't send maxOutputTokens parameter + // This allows the API to use its own default or handle it according to its requirements + maxOutputTokens: input.model.excludeDefaultOptions ? undefined : maxOutputTokens, abortSignal: input.abort, headers: { ...(input.model.providerID.startsWith("opencode") diff --git a/packages/opencode/test/provider/provider.test.ts b/packages/opencode/test/provider/provider.test.ts index f6d2df9dd5b..d7439183d2a 100644 --- a/packages/opencode/test/provider/provider.test.ts +++ b/packages/opencode/test/provider/provider.test.ts @@ -2031,6 +2031,92 @@ test("variant config merges with generated variants", async () => { }) }) +test("excludeDefaultOptions disables default parameters", async () => { + await using tmp = await tmpdir({ + init: async (dir) => { + await Bun.write( + path.join(dir, "opencode.json"), + JSON.stringify({ + $schema: "https://opencode.ai/config.json", + provider: { + "custom-api": { + name: "Custom API", + npm: "@ai-sdk/openai-compatible", + excludeDefaultOptions: true, + env: [], + models: { + "custom-model": { + name: "Custom Model", + tool_call: true, + limit: { context: 128000, output: 8192 }, + }, + }, + options: { + apiKey: "test-key", + baseURL: "https://api.custom.com/v1", + }, + }, + }, + }), + ) + }, + }) + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const providers = await Provider.list() + expect(providers["custom-api"]).toBeDefined() + const model = providers["custom-api"].models["custom-model"] + expect(model.excludeDefaultOptions).toBe(true) + }, + }) +}) + +test("model-level excludeDefaultOptions overrides provider-level", async () => { + await using tmp = await tmpdir({ + init: async (dir) => { + await Bun.write( + path.join(dir, "opencode.json"), + JSON.stringify({ + $schema: "https://opencode.ai/config.json", + provider: { + "custom-api": { + name: "Custom API", + npm: "@ai-sdk/openai-compatible", + excludeDefaultOptions: true, + env: [], + models: { + "model-1": { + name: "Model 1", + tool_call: true, + limit: { context: 8000, output: 2000 }, + }, + "model-2": { + name: "Model 2", + excludeDefaultOptions: false, + tool_call: true, + limit: { context: 8000, output: 2000 }, + }, + }, + options: { apiKey: "test" }, + }, + }, + }), + ) + }, + }) + await Instance.provide({ + directory: tmp.path, + fn: async () => { + const providers = await Provider.list() + const model1 = providers["custom-api"].models["model-1"] + const model2 = providers["custom-api"].models["model-2"] + expect(model1.excludeDefaultOptions).toBe(true) + expect(model2.excludeDefaultOptions).toBe(false) + }, + }) +}) + test("variants filtered in second pass for database models", async () => { await using tmp = await tmpdir({ init: async (dir) => { diff --git a/packages/opencode/test/provider/transform.test.ts b/packages/opencode/test/provider/transform.test.ts index 32b1ecb2444..835bb2fc0a9 100644 --- a/packages/opencode/test/provider/transform.test.ts +++ b/packages/opencode/test/provider/transform.test.ts @@ -3,6 +3,86 @@ import { ProviderTransform } from "../../src/provider/transform" const OUTPUT_TOKEN_MAX = 32000 +describe("ProviderTransform.options - excludeDefaultOptions", () => { + const sessionID = "test-session-123" + + const mockModel = { + id: "custom/custom-model", + providerID: "custom", + api: { + id: "custom-model", + url: "https://api.custom.com", + npm: "@ai-sdk/openai-compatible", + }, + name: "Custom Model", + capabilities: { + temperature: true, + reasoning: false, + attachment: false, + toolcall: true, + input: { text: true, audio: false, image: false, video: false, pdf: false }, + output: { text: true, audio: false, image: false, video: false, pdf: false }, + interleaved: false, + }, + cost: { + input: 0.001, + output: 0.002, + cache: { read: 0, write: 0 }, + }, + limit: { + context: 128000, + output: 8192, + }, + status: "active", + options: {}, + headers: {}, + excludeDefaultOptions: false, + } as any + + test("should return empty object when excludeDefaultOptions is true", () => { + const model = { ...mockModel, excludeDefaultOptions: true } + const result = ProviderTransform.options(model, sessionID) + expect(result).toEqual({}) + }) + + test("should return default options when excludeDefaultOptions is false", () => { + const model = { ...mockModel, providerID: "openai", excludeDefaultOptions: false } + const result = ProviderTransform.options(model, sessionID) + expect(result.promptCacheKey).toBe(sessionID) + }) + + test("should return default options when excludeDefaultOptions is undefined", () => { + const model = { ...mockModel, providerID: "openai", excludeDefaultOptions: undefined } + const result = ProviderTransform.options(model, sessionID) + expect(result.promptCacheKey).toBe(sessionID) + }) +}) + +describe("ProviderTransform.smallOptions - excludeDefaultOptions", () => { + const mockModel = { + id: "custom/custom-model", + providerID: "custom", + api: { + id: "custom-model", + url: "https://api.custom.com", + npm: "@ai-sdk/openai-compatible", + }, + excludeDefaultOptions: false, + } as any + + test("should return empty object when excludeDefaultOptions is true", () => { + const model = { ...mockModel, excludeDefaultOptions: true } + const result = ProviderTransform.smallOptions(model) + expect(result).toEqual({}) + }) + + test("should return default options when excludeDefaultOptions is false for OpenAI", () => { + const model = { ...mockModel, providerID: "openai", excludeDefaultOptions: false } + const result = ProviderTransform.smallOptions(model) + expect(result.reasoningEffort).toBe("minimal") + }) +}) + describe("ProviderTransform.options - setCacheKey", () => { const sessionID = "test-session-123" @@ -585,6 +665,154 @@ describe("ProviderTransform.message - anthropic empty content filtering", () => }) }) +describe("ProviderTransform.excludeDefaultOptions", () => { + const sessionID = "test-session-123" + + const mockModel = { + id: "custom/custom-model", + providerID: "custom", + api: { + id: "custom-model", + url: "https://api.custom.com", + npm: "@ai-sdk/openai-compatible", + }, + name: "Custom Model", + capabilities: { + temperature: true, + reasoning: false, + attachment: true, + toolcall: true, + input: { text: true, audio: false, image: true, video: false, pdf: false }, + output: { text: true, audio: false, image: false, video: false, pdf: false }, + interleaved: false, + }, + cost: { + input: 0.001, + output: 0.002, + cache: { read: 0.0001, write: 0.0002 }, + }, + limit: { + context: 128000, + output: 8192, + }, + status: "active", + options: {}, + headers: {}, + } as any + + test("should return empty object when excludeDefaultOptions is true", () => { + const modelWithExclude = { ...mockModel, excludeDefaultOptions: true } + const result = ProviderTransform.options(modelWithExclude, sessionID, {}) + expect(result).toEqual({}) + }) + + test("should return default options when excludeDefaultOptions is false", () => { + const modelWithExclude = { ...mockModel, excludeDefaultOptions: false } + const result = ProviderTransform.options(modelWithExclude, sessionID, {}) + // Should return empty for this provider, but the function should run normally + expect(result).toEqual({}) + }) + + test("should return default options when excludeDefaultOptions is undefined", () => { + const result = ProviderTransform.options(mockModel, sessionID, {}) + expect(result).toEqual({}) + }) + + test("should skip promptCacheKey when excludeDefaultOptions is true", () => { + const openaiModel = { + ...mockModel, + providerID: "openai", + api: { ...mockModel.api, npm: "@ai-sdk/openai" }, + excludeDefaultOptions: true, + } + const result = ProviderTransform.options(openaiModel, sessionID, {}) + expect(result).toEqual({}) + expect(result.promptCacheKey).toBeUndefined() + }) + + test("should include promptCacheKey when excludeDefaultOptions is false for openai", () => { + const openaiModel = { + ...mockModel, + providerID: "openai", + api: { ...mockModel.api, npm: "@ai-sdk/openai" }, + excludeDefaultOptions: false, + } + const result = ProviderTransform.options(openaiModel, sessionID, {}) + expect(result.promptCacheKey).toBe(sessionID) + }) + + test("should skip thinkingConfig when excludeDefaultOptions is true for google", () => { + const googleModel = { + ...mockModel, + providerID: "google", + api: { ...mockModel.api, npm: "@ai-sdk/google", id: "gemini-3-pro" }, + excludeDefaultOptions: true, + } + const result = ProviderTransform.options(googleModel, sessionID, {}) + expect(result).toEqual({}) + expect(result.thinkingConfig).toBeUndefined() + }) + + test("should include thinkingConfig when excludeDefaultOptions is false for google", () => { + const googleModel = { + ...mockModel, + providerID: "google", + api: { ...mockModel.api, npm: "@ai-sdk/google", id: "gemini-3-pro" }, + excludeDefaultOptions: false, + } + const result = ProviderTransform.options(googleModel, sessionID, {}) + expect(result.thinkingConfig).toBeDefined() + expect(result.thinkingConfig.includeThoughts).toBe(true) + }) + + test("smallOptions should return empty object when excludeDefaultOptions is true", () => { + const openaiModel = { + ...mockModel, + providerID: "openai", + api: { ...mockModel.api, npm: "@ai-sdk/openai", id: "gpt-5" }, + excludeDefaultOptions: true, + } + const result = ProviderTransform.smallOptions(openaiModel) + expect(result).toEqual({}) + }) + + test("smallOptions should return default options when excludeDefaultOptions is false", () => { + const openaiModel = { + ...mockModel, + providerID: "openai", + api: { ...mockModel.api, npm: "@ai-sdk/openai", id: "gpt-5" }, + excludeDefaultOptions: false, + } + const result = ProviderTransform.smallOptions(openaiModel) + expect(result.reasoningEffort).toBeDefined() + }) + + test("should skip all provider-specific options when excludeDefaultOptions is true", () => { + const openrouterModel = { + ...mockModel, + providerID: "openrouter", + api: { ...mockModel.api, npm: "@openrouter/ai-sdk-provider", id: "gemini-3-pro" }, + excludeDefaultOptions: true, + } + const result = ProviderTransform.options(openrouterModel, sessionID, {}) + expect(result).toEqual({}) + expect(result.usage).toBeUndefined() + expect(result.reasoning).toBeUndefined() + }) + + test("should include provider-specific options when excludeDefaultOptions is false", () => { + const openrouterModel = { + ...mockModel, + providerID: "openrouter", + api: { ...mockModel.api, npm: "@openrouter/ai-sdk-provider", id: "gemini-3-pro" }, + excludeDefaultOptions: false, + } + const result = ProviderTransform.options(openrouterModel, sessionID, {}) + expect(result.usage).toBeDefined() + expect(result.reasoning).toBeDefined() + }) +}) + describe("ProviderTransform.variants", () => { const createMockModel = (overrides: Partial = {}): any => ({ id: "test/test-model", diff --git a/packages/sdk/js/src/gen/types.gen.ts b/packages/sdk/js/src/gen/types.gen.ts index 32f33f66219..b3ed671d60c 100644 --- a/packages/sdk/js/src/gen/types.gen.ts +++ b/packages/sdk/js/src/gen/types.gen.ts @@ -1067,10 +1067,18 @@ export type ProviderConfig = { provider?: { npm: string } + /** + * Exclude all default provider options for this model (useful for custom APIs that don't support them) + */ + excludeDefaultOptions?: boolean } } whitelist?: Array blacklist?: Array + /** + * Exclude all default provider options for all models in this provider (useful for custom APIs that don't support them) + */ + excludeDefaultOptions?: boolean options?: { apiKey?: string baseURL?: string diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts index 9cb7222aa5f..c66d92818e8 100644 --- a/packages/sdk/js/src/v2/gen/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/types.gen.ts @@ -1434,10 +1434,18 @@ export type ProviderConfig = { [key: string]: unknown | boolean | undefined } } + /** + * Exclude all default provider options for this model (useful for custom APIs that don't support them) + */ + excludeDefaultOptions?: boolean } } whitelist?: Array blacklist?: Array + /** + * Exclude all default provider options for all models in this provider (useful for custom APIs that don't support them) + */ + excludeDefaultOptions?: boolean options?: { apiKey?: string baseURL?: string