@intelligo-dev/core 1.0.0-beta.1 → 1.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +6 -0
- package/README.md +102 -0
- package/dist/attachments/errors.d.ts +7 -0
- package/dist/attachments/errors.d.ts.map +1 -0
- package/dist/attachments/errors.js +11 -0
- package/dist/attachments/errors.js.map +1 -0
- package/dist/attachments/index.d.ts +8 -0
- package/dist/attachments/index.d.ts.map +1 -0
- package/dist/attachments/index.js +7 -0
- package/dist/attachments/index.js.map +1 -0
- package/dist/attachments/service.d.ts +45 -0
- package/dist/attachments/service.d.ts.map +1 -0
- package/dist/attachments/service.js +100 -0
- package/dist/attachments/service.js.map +1 -0
- package/dist/attachments/types.d.ts +6 -0
- package/dist/attachments/types.d.ts.map +1 -0
- package/dist/attachments/types.js +2 -0
- package/dist/attachments/types.js.map +1 -0
- package/dist/conversations/errors.d.ts +2 -8
- package/dist/conversations/errors.d.ts.map +1 -1
- package/dist/conversations/errors.js +2 -8
- package/dist/conversations/errors.js.map +1 -1
- package/dist/conversations/index.d.ts +4 -12
- package/dist/conversations/index.d.ts.map +1 -1
- package/dist/conversations/index.js +2 -11
- package/dist/conversations/index.js.map +1 -1
- package/dist/conversations/service.d.ts +49 -61
- package/dist/conversations/service.d.ts.map +1 -1
- package/dist/conversations/service.js +110 -83
- package/dist/conversations/service.js.map +1 -1
- package/dist/conversations/types.d.ts +1 -4
- package/dist/conversations/types.d.ts.map +1 -1
- package/dist/conversations/types.js +0 -3
- package/dist/conversations/types.js.map +1 -1
- package/dist/db/client.d.ts +21 -10
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +43 -18
- package/dist/db/client.js.map +1 -1
- package/dist/db/index.d.ts +3 -3
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +3 -7
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema/agents.d.ts +14 -51
- package/dist/db/schema/agents.d.ts.map +1 -1
- package/dist/db/schema/agents.js +9 -21
- package/dist/db/schema/agents.js.map +1 -1
- package/dist/db/schema/ai.d.ts +86 -1556
- package/dist/db/schema/ai.d.ts.map +1 -1
- package/dist/db/schema/ai.js +32 -236
- package/dist/db/schema/ai.js.map +1 -1
- package/dist/db/schema/auth.d.ts +5 -34
- package/dist/db/schema/auth.d.ts.map +1 -1
- package/dist/db/schema/auth.js +25 -56
- package/dist/db/schema/auth.js.map +1 -1
- package/dist/db/schema/billing.d.ts +339 -105
- package/dist/db/schema/billing.d.ts.map +1 -1
- package/dist/db/schema/billing.js +99 -58
- package/dist/db/schema/billing.js.map +1 -1
- package/dist/db/schema/feature-flags.d.ts +3 -12
- package/dist/db/schema/feature-flags.d.ts.map +1 -1
- package/dist/db/schema/feature-flags.js +3 -12
- package/dist/db/schema/feature-flags.js.map +1 -1
- package/dist/db/schema/identity.d.ts +12 -274
- package/dist/db/schema/identity.d.ts.map +1 -1
- package/dist/db/schema/identity.js +19 -104
- package/dist/db/schema/identity.js.map +1 -1
- package/dist/db/schema/index.d.ts +8 -15
- package/dist/db/schema/index.d.ts.map +1 -1
- package/dist/db/schema/index.js +12 -42
- package/dist/db/schema/index.js.map +1 -1
- package/dist/db/schema/notifications.d.ts +3 -17
- package/dist/db/schema/notifications.d.ts.map +1 -1
- package/dist/db/schema/notifications.js +3 -17
- package/dist/db/schema/notifications.js.map +1 -1
- package/dist/db/schema/usage.d.ts +94 -77
- package/dist/db/schema/usage.d.ts.map +1 -1
- package/dist/db/schema/usage.js +59 -89
- package/dist/db/schema/usage.js.map +1 -1
- package/dist/db/validate.d.ts +2 -11
- package/dist/db/validate.d.ts.map +1 -1
- package/dist/db/validate.js +6 -17
- package/dist/db/validate.js.map +1 -1
- package/dist/db/workspace-queries.d.ts +5 -29
- package/dist/db/workspace-queries.d.ts.map +1 -1
- package/dist/db/workspace-queries.js +5 -29
- package/dist/db/workspace-queries.js.map +1 -1
- package/dist/documents/classifier.d.ts +5 -12
- package/dist/documents/classifier.d.ts.map +1 -1
- package/dist/documents/classifier.js +16 -16
- package/dist/documents/classifier.js.map +1 -1
- package/dist/documents/errors.d.ts +2 -10
- package/dist/documents/errors.d.ts.map +1 -1
- package/dist/documents/errors.js +2 -10
- package/dist/documents/errors.js.map +1 -1
- package/dist/documents/index.d.ts +4 -13
- package/dist/documents/index.d.ts.map +1 -1
- package/dist/documents/index.js +3 -12
- package/dist/documents/index.js.map +1 -1
- package/dist/documents/service.d.ts +19 -26
- package/dist/documents/service.d.ts.map +1 -1
- package/dist/documents/service.js +44 -38
- package/dist/documents/service.js.map +1 -1
- package/dist/documents/types.d.ts +6 -10
- package/dist/documents/types.d.ts.map +1 -1
- package/dist/documents/types.js +0 -3
- package/dist/documents/types.js.map +1 -1
- package/dist/email/brand.d.ts +17 -0
- package/dist/email/brand.d.ts.map +1 -0
- package/dist/email/brand.js +9 -0
- package/dist/email/brand.js.map +1 -0
- package/dist/email/index.d.ts +4 -4
- package/dist/email/index.js +4 -4
- package/dist/email/provider.d.ts +1 -7
- package/dist/email/provider.d.ts.map +1 -1
- package/dist/email/provider.js +10 -19
- package/dist/email/provider.js.map +1 -1
- package/dist/email/send.d.ts +12 -12
- package/dist/email/send.d.ts.map +1 -1
- package/dist/email/send.js +5 -19
- package/dist/email/send.js.map +1 -1
- package/dist/email/senders.d.ts +17 -30
- package/dist/email/senders.d.ts.map +1 -1
- package/dist/email/senders.js +33 -47
- package/dist/email/senders.js.map +1 -1
- package/dist/email/templates/base-layout.d.ts +1 -1
- package/dist/email/templates/base-layout.d.ts.map +1 -1
- package/dist/email/templates/base-layout.js +4 -6
- package/dist/email/templates/base-layout.js.map +1 -1
- package/dist/email/templates/index.d.ts +10 -10
- package/dist/email/templates/index.d.ts.map +1 -1
- package/dist/email/templates/index.js +10 -16
- package/dist/email/templates/index.js.map +1 -1
- package/dist/email/templates/password-reset.d.ts +2 -2
- package/dist/email/templates/password-reset.d.ts.map +1 -1
- package/dist/email/templates/password-reset.js +10 -22
- package/dist/email/templates/password-reset.js.map +1 -1
- package/dist/email/templates/payment-failed.d.ts +2 -2
- package/dist/email/templates/payment-failed.d.ts.map +1 -1
- package/dist/email/templates/payment-failed.js +11 -24
- package/dist/email/templates/payment-failed.js.map +1 -1
- package/dist/email/templates/quota-warning.d.ts +4 -4
- package/dist/email/templates/quota-warning.d.ts.map +1 -1
- package/dist/email/templates/quota-warning.js +19 -39
- package/dist/email/templates/quota-warning.js.map +1 -1
- package/dist/email/templates/subscription-confirmed.d.ts +2 -2
- package/dist/email/templates/subscription-confirmed.d.ts.map +1 -1
- package/dist/email/templates/subscription-confirmed.js +13 -28
- package/dist/email/templates/subscription-confirmed.js.map +1 -1
- package/dist/email/templates/trial-expiry.d.ts +2 -2
- package/dist/email/templates/trial-expiry.d.ts.map +1 -1
- package/dist/email/templates/trial-expiry.js +12 -36
- package/dist/email/templates/trial-expiry.js.map +1 -1
- package/dist/email/templates/trial-warning.d.ts +2 -2
- package/dist/email/templates/trial-warning.d.ts.map +1 -1
- package/dist/email/templates/trial-warning.js +15 -32
- package/dist/email/templates/trial-warning.js.map +1 -1
- package/dist/email/templates/verify-email.d.ts +2 -2
- package/dist/email/templates/verify-email.d.ts.map +1 -1
- package/dist/email/templates/verify-email.js +10 -22
- package/dist/email/templates/verify-email.js.map +1 -1
- package/dist/email/templates/welcome.d.ts +2 -2
- package/dist/email/templates/welcome.d.ts.map +1 -1
- package/dist/email/templates/welcome.js +13 -20
- package/dist/email/templates/welcome.js.map +1 -1
- package/dist/email/templates/workspace-invitation.d.ts +2 -2
- package/dist/email/templates/workspace-invitation.d.ts.map +1 -1
- package/dist/email/templates/workspace-invitation.js +12 -26
- package/dist/email/templates/workspace-invitation.js.map +1 -1
- package/dist/env.d.ts +5 -10
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +41 -31
- package/dist/env.js.map +1 -1
- package/dist/identity/audit.d.ts +11 -24
- package/dist/identity/audit.d.ts.map +1 -1
- package/dist/identity/audit.js +13 -27
- package/dist/identity/audit.js.map +1 -1
- package/dist/identity/errors.d.ts +4 -12
- package/dist/identity/errors.d.ts.map +1 -1
- package/dist/identity/errors.js +2 -8
- package/dist/identity/errors.js.map +1 -1
- package/dist/identity/index.d.ts +6 -13
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +5 -12
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/service.d.ts +29 -47
- package/dist/identity/service.d.ts.map +1 -1
- package/dist/identity/service.js +107 -79
- package/dist/identity/service.js.map +1 -1
- package/dist/identity/types.d.ts +28 -4
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/identity/types.js +0 -3
- package/dist/identity/types.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -10
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +7 -18
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +45 -49
- package/dist/logger.js.map +1 -1
- package/dist/money.d.ts +95 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +208 -0
- package/dist/money.js.map +1 -0
- package/dist/notifications/index.d.ts +9 -43
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +9 -49
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications/triggers.d.ts +9 -32
- package/dist/notifications/triggers.d.ts.map +1 -1
- package/dist/notifications/triggers.js +21 -58
- package/dist/notifications/triggers.js.map +1 -1
- package/dist/notifications/types.d.ts +6 -8
- package/dist/notifications/types.d.ts.map +1 -1
- package/dist/notifications/types.js +0 -9
- package/dist/notifications/types.js.map +1 -1
- package/dist/prompt.d.ts +38 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +118 -0
- package/dist/prompt.js.map +1 -0
- package/dist/registry.d.ts +32 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +60 -0
- package/dist/registry.js.map +1 -0
- package/dist/request-context.d.ts +49 -0
- package/dist/request-context.d.ts.map +1 -0
- package/dist/request-context.js +100 -0
- package/dist/request-context.js.map +1 -0
- package/dist/storage/index.d.ts +65 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +109 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +74 -24
- package/src/attachments/errors.ts +18 -0
- package/src/attachments/index.ts +22 -0
- package/src/attachments/service.ts +178 -0
- package/src/attachments/types.ts +6 -0
- package/src/conversations/errors.ts +45 -0
- package/src/conversations/index.ts +39 -0
- package/src/conversations/service.ts +594 -0
- package/src/conversations/types.ts +15 -0
- package/src/db/client.ts +91 -0
- package/src/db/index.ts +3 -0
- package/src/db/migrations/0000_baseline.sql +652 -0
- package/src/db/migrations/0001_reconcile_chain_built_databases.sql +53 -0
- package/src/db/migrations/0002_webhook_claim_lease.sql +1 -0
- package/src/db/migrations/0003_local_payments.sql +18 -0
- package/src/db/migrations/README.md +103 -36
- package/src/db/migrations/legacy-chain.json +206 -0
- package/src/db/migrations/meta/0000_snapshot.json +4182 -157
- package/src/db/migrations/meta/0002_snapshot.json +2478 -368
- package/src/db/migrations/meta/0003_snapshot.json +2567 -554
- package/src/db/migrations/meta/_journal.json +8 -274
- package/src/db/schema/agents.ts +57 -0
- package/src/db/schema/ai.ts +174 -0
- package/src/db/schema/auth.ts +183 -0
- package/src/db/schema/billing.ts +245 -0
- package/src/db/schema/feature-flags.ts +20 -0
- package/src/db/schema/identity.ts +250 -0
- package/src/db/schema/index.ts +12 -0
- package/src/db/schema/notifications.ts +31 -0
- package/src/db/schema/usage.ts +269 -0
- package/src/db/validate.ts +63 -0
- package/src/db/workspace-queries.ts +64 -0
- package/src/documents/classifier.ts +61 -0
- package/src/documents/errors.ts +44 -0
- package/src/documents/index.ts +24 -0
- package/src/documents/service.ts +256 -0
- package/src/documents/types.ts +24 -0
- package/src/email/brand.ts +24 -0
- package/src/email/index.ts +19 -0
- package/src/email/provider.ts +278 -0
- package/src/email/send.ts +169 -0
- package/src/email/senders.ts +292 -0
- package/src/email/templates/base-layout.tsx +145 -0
- package/src/email/templates/index.ts +28 -0
- package/src/email/templates/password-reset.tsx +72 -0
- package/src/email/templates/payment-failed.tsx +77 -0
- package/src/email/templates/quota-warning.tsx +118 -0
- package/src/email/templates/subscription-confirmed.tsx +91 -0
- package/src/email/templates/trial-expiry.tsx +124 -0
- package/src/email/templates/trial-warning.tsx +104 -0
- package/src/email/templates/verify-email.tsx +72 -0
- package/src/email/templates/welcome.tsx +64 -0
- package/src/email/templates/workspace-invitation.tsx +105 -0
- package/src/env.ts +180 -0
- package/src/identity/audit.ts +65 -0
- package/src/identity/errors.ts +44 -0
- package/src/identity/index.ts +29 -0
- package/src/identity/service.ts +303 -0
- package/src/identity/types.ts +58 -0
- package/src/index.ts +4 -0
- package/src/logger.ts +198 -0
- package/src/money.ts +270 -0
- package/src/notifications/index.ts +112 -0
- package/src/notifications/triggers.ts +158 -0
- package/src/notifications/types.ts +26 -0
- package/src/prompt.ts +142 -0
- package/src/registry.ts +75 -0
- package/src/request-context.ts +137 -0
- package/src/storage/index.ts +153 -0
- package/dist/db/schema/rag.d.ts +0 -171
- package/dist/db/schema/rag.d.ts.map +0 -1
- package/dist/db/schema/rag.js +0 -42
- package/dist/db/schema/rag.js.map +0 -1
- package/src/db/migrations/0000_sharp_night_nurse.sql +0 -52
- package/src/db/migrations/0001_hesitant_vapor.sql +0 -40
- package/src/db/migrations/0002_numerous_lady_vermin.sql +0 -235
- package/src/db/migrations/0003_mighty_jean_grey.sql +0 -37
- package/src/db/migrations/0004_cynical_grandmaster.sql +0 -2
- package/src/db/migrations/0005_careful_switch.sql +0 -8
- package/src/db/migrations/0006_tense_blue_marvel.sql +0 -16
- package/src/db/migrations/0007_next_squadron_sinister.sql +0 -1
- package/src/db/migrations/0008_powerful_scream.sql +0 -39
- package/src/db/migrations/0009_sad_ink.sql +0 -1
- package/src/db/migrations/0010_shocking_omega_flight.sql +0 -2
- package/src/db/migrations/0011_ambiguous_otto_octavius.sql +0 -151
- package/src/db/migrations/0011_hnsw_vector_index.sql +0 -17
- package/src/db/migrations/0012_user_profiles.sql +0 -30
- package/src/db/migrations/0013_trending_seasonal_columns.sql +0 -9
- package/src/db/migrations/0014_add_product_type_to_agents.sql +0 -6
- package/src/db/migrations/0015_new_v1_tables.sql +0 -149
- package/src/db/migrations/0016_document_types.sql +0 -30
- package/src/db/migrations/0017_document_metadata.sql +0 -2
- package/src/db/migrations/0018_identity_graph.sql +0 -200
- package/src/db/migrations/0019_db_driven_prompts.sql +0 -20
- package/src/db/migrations/0020_pending_extractions.sql +0 -35
- package/src/db/migrations/0021_rag_documents.sql +0 -39
- package/src/db/migrations/0022_user_quotas_usage_jsonb.sql +0 -70
- package/src/db/migrations/0023_user_facts_user_scoped_unique.sql +0 -17
- package/src/db/migrations/0024_user_memories_hnsw.sql +0 -23
- package/src/db/migrations/0025_audit_trigger_errcode.sql +0 -21
- package/src/db/migrations/0026_user_profile_snapshots_composite_pk.sql +0 -17
- package/src/db/migrations/0027_billing_settings_mnt_columns.sql +0 -54
- package/src/db/migrations/0028_trial_credits_normalized_email.sql +0 -37
- package/src/db/migrations/0029_usage_records_conversation_idx.sql +0 -13
- package/src/db/migrations/0030_pending_extractions_composite_idx.sql +0 -11
- package/src/db/migrations/0031_rag_documents_hnsw.sql +0 -16
- package/src/db/migrations/0032_rate_limit_unique_idx.sql +0 -16
- package/src/db/migrations/0033_pending_extractions_partial_idx.sql +0 -18
- package/src/db/migrations/0034_rate_limit_count.sql +0 -9
- package/src/db/migrations/0035_credit_reservations.sql +0 -24
- package/src/db/migrations/0036_executions_audit_jobs.sql +0 -96
- package/src/db/migrations/0037_rate_limit_minute_bucket.sql +0 -46
- package/src/db/migrations/0038_user_quotas_generic_usage.sql +0 -25
- package/src/db/migrations/0039_platform_admin_impersonation.sql +0 -27
- package/src/db/migrations/0040_ee_audit_chain.sql +0 -23
- package/src/db/migrations/meta/0001_snapshot.json +0 -631
- package/src/db/migrations/meta/0004_snapshot.json +0 -2500
- package/src/db/migrations/meta/0005_snapshot.json +0 -2548
- package/src/db/migrations/meta/0006_snapshot.json +0 -2650
- package/src/db/migrations/meta/0007_snapshot.json +0 -2657
- package/src/db/migrations/meta/0008_snapshot.json +0 -2719
- package/src/db/migrations/meta/0009_snapshot.json +0 -2726
- package/src/db/migrations/meta/0010_snapshot.json +0 -2739
- package/src/db/migrations/meta/0011_snapshot.json +0 -3886
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Tables for tracking per-request token consumption and aggregated monthly usage.
|
|
5
|
-
* Used by the quota enforcement engine to check limits before AI requests
|
|
6
|
-
* and record consumption atomically after completion.
|
|
7
|
-
*
|
|
8
|
-
* Pattern: snake_case columns in PostgreSQL, camelCase TypeScript API (via Drizzle mapping)
|
|
2
|
+
* Token consumption per request and aggregated per period, which the quota
|
|
3
|
+
* engine checks before AI requests and records into after them.
|
|
9
4
|
*/
|
|
10
5
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Every AI request creates one record with input/output/total tokens,
|
|
14
|
-
* the model used, and the agent that handled it. This provides the
|
|
15
|
-
* detailed breakdown for per-model and per-agent reporting (QUOTA-07).
|
|
6
|
+
* One row per AI request: tokens, model and agent, for per-model and
|
|
7
|
+
* per-agent reporting.
|
|
16
8
|
*/
|
|
17
9
|
export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
18
10
|
name: "usage_records";
|
|
@@ -171,11 +163,11 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
171
163
|
identity: undefined;
|
|
172
164
|
generated: undefined;
|
|
173
165
|
}, {}, {}>;
|
|
174
|
-
|
|
175
|
-
name: "
|
|
166
|
+
providerCostMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
167
|
+
name: "provider_cost_micros";
|
|
176
168
|
tableName: "usage_records";
|
|
177
169
|
dataType: "number";
|
|
178
|
-
columnType: "
|
|
170
|
+
columnType: "PgBigInt53";
|
|
179
171
|
data: number;
|
|
180
172
|
driverParam: string | number;
|
|
181
173
|
notNull: true;
|
|
@@ -188,11 +180,11 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
188
180
|
identity: undefined;
|
|
189
181
|
generated: undefined;
|
|
190
182
|
}, {}, {}>;
|
|
191
|
-
|
|
192
|
-
name: "
|
|
183
|
+
marginBp: import("drizzle-orm/pg-core").PgColumn<{
|
|
184
|
+
name: "margin_bp";
|
|
193
185
|
tableName: "usage_records";
|
|
194
186
|
dataType: "number";
|
|
195
|
-
columnType: "
|
|
187
|
+
columnType: "PgInteger";
|
|
196
188
|
data: number;
|
|
197
189
|
driverParam: string | number;
|
|
198
190
|
notNull: true;
|
|
@@ -205,11 +197,11 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
205
197
|
identity: undefined;
|
|
206
198
|
generated: undefined;
|
|
207
199
|
}, {}, {}>;
|
|
208
|
-
|
|
209
|
-
name: "
|
|
200
|
+
usdRateMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
201
|
+
name: "usd_rate_micros";
|
|
210
202
|
tableName: "usage_records";
|
|
211
203
|
dataType: "number";
|
|
212
|
-
columnType: "
|
|
204
|
+
columnType: "PgBigInt53";
|
|
213
205
|
data: number;
|
|
214
206
|
driverParam: string | number;
|
|
215
207
|
notNull: true;
|
|
@@ -222,11 +214,11 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
222
214
|
identity: undefined;
|
|
223
215
|
generated: undefined;
|
|
224
216
|
}, {}, {}>;
|
|
225
|
-
|
|
226
|
-
name: "
|
|
217
|
+
chargedMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
218
|
+
name: "charged_micros";
|
|
227
219
|
tableName: "usage_records";
|
|
228
220
|
dataType: "number";
|
|
229
|
-
columnType: "
|
|
221
|
+
columnType: "PgBigInt53";
|
|
230
222
|
data: number;
|
|
231
223
|
driverParam: string | number;
|
|
232
224
|
notNull: true;
|
|
@@ -239,6 +231,23 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
239
231
|
identity: undefined;
|
|
240
232
|
generated: undefined;
|
|
241
233
|
}, {}, {}>;
|
|
234
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
235
|
+
name: "currency";
|
|
236
|
+
tableName: "usage_records";
|
|
237
|
+
dataType: "string";
|
|
238
|
+
columnType: "PgText";
|
|
239
|
+
data: string;
|
|
240
|
+
driverParam: string;
|
|
241
|
+
notNull: true;
|
|
242
|
+
hasDefault: true;
|
|
243
|
+
isPrimaryKey: false;
|
|
244
|
+
isAutoincrement: false;
|
|
245
|
+
hasRuntimeDefault: false;
|
|
246
|
+
enumValues: [string, ...string[]];
|
|
247
|
+
baseColumn: never;
|
|
248
|
+
identity: undefined;
|
|
249
|
+
generated: undefined;
|
|
250
|
+
}, {}, {}>;
|
|
242
251
|
requestId: import("drizzle-orm/pg-core").PgColumn<{
|
|
243
252
|
name: "request_id";
|
|
244
253
|
tableName: "usage_records";
|
|
@@ -328,11 +337,8 @@ export declare const usageRecords: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
328
337
|
dialect: "pg";
|
|
329
338
|
}>;
|
|
330
339
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
* Instead of SUM(totalTokens) on every request, we increment a counter atomically.
|
|
334
|
-
* One row per workspace per billing period. The usage_records table provides
|
|
335
|
-
* the detailed breakdown for reporting; this table provides O(1) quota checks.
|
|
340
|
+
* One row per workspace per billing period, incremented atomically, so a
|
|
341
|
+
* quota check is O(1) instead of a SUM over usage_records.
|
|
336
342
|
*/
|
|
337
343
|
export declare const monthlyUsage: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
338
344
|
name: "monthly_usage";
|
|
@@ -423,11 +429,11 @@ export declare const monthlyUsage: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
423
429
|
identity: undefined;
|
|
424
430
|
generated: undefined;
|
|
425
431
|
}, {}, {}>;
|
|
426
|
-
|
|
427
|
-
name: "
|
|
432
|
+
allowanceUsedMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
433
|
+
name: "allowance_used_micros";
|
|
428
434
|
tableName: "monthly_usage";
|
|
429
435
|
dataType: "number";
|
|
430
|
-
columnType: "
|
|
436
|
+
columnType: "PgBigInt53";
|
|
431
437
|
data: number;
|
|
432
438
|
driverParam: string | number;
|
|
433
439
|
notNull: true;
|
|
@@ -440,6 +446,23 @@ export declare const monthlyUsage: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
440
446
|
identity: undefined;
|
|
441
447
|
generated: undefined;
|
|
442
448
|
}, {}, {}>;
|
|
449
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
450
|
+
name: "currency";
|
|
451
|
+
tableName: "monthly_usage";
|
|
452
|
+
dataType: "string";
|
|
453
|
+
columnType: "PgText";
|
|
454
|
+
data: string;
|
|
455
|
+
driverParam: string;
|
|
456
|
+
notNull: true;
|
|
457
|
+
hasDefault: true;
|
|
458
|
+
isPrimaryKey: false;
|
|
459
|
+
isAutoincrement: false;
|
|
460
|
+
hasRuntimeDefault: false;
|
|
461
|
+
enumValues: [string, ...string[]];
|
|
462
|
+
baseColumn: never;
|
|
463
|
+
identity: undefined;
|
|
464
|
+
generated: undefined;
|
|
465
|
+
}, {}, {}>;
|
|
443
466
|
requestCount: import("drizzle-orm/pg-core").PgColumn<{
|
|
444
467
|
name: "request_count";
|
|
445
468
|
tableName: "monthly_usage";
|
|
@@ -478,14 +501,9 @@ export declare const monthlyUsage: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
478
501
|
dialect: "pg";
|
|
479
502
|
}>;
|
|
480
503
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* The unique constraint on workspace_id enforces one trial per workspace (TRIAL-07).
|
|
485
|
-
* Trial credits are separate from purchased credits (credit_balances).
|
|
486
|
-
* They act as a fallback when plan quota is exceeded or credit balance is zero.
|
|
487
|
-
*
|
|
488
|
-
* Status flow: active → depleted (credits hit 0) or active → converted (paid plan)
|
|
504
|
+
* One-time trial grant, one per workspace (unique constraint). Separate from
|
|
505
|
+
* purchased credits; used when the plan quota is exceeded or the credit
|
|
506
|
+
* balance is zero. Status: active → depleted, converted or expired.
|
|
489
507
|
*/
|
|
490
508
|
export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
491
509
|
name: "trial_credits";
|
|
@@ -576,11 +594,11 @@ export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
576
594
|
identity: undefined;
|
|
577
595
|
generated: undefined;
|
|
578
596
|
}, {}, {}>;
|
|
579
|
-
|
|
580
|
-
name: "
|
|
597
|
+
initialMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
598
|
+
name: "initial_micros";
|
|
581
599
|
tableName: "trial_credits";
|
|
582
600
|
dataType: "number";
|
|
583
|
-
columnType: "
|
|
601
|
+
columnType: "PgBigInt53";
|
|
584
602
|
data: number;
|
|
585
603
|
driverParam: string | number;
|
|
586
604
|
notNull: true;
|
|
@@ -593,11 +611,11 @@ export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
593
611
|
identity: undefined;
|
|
594
612
|
generated: undefined;
|
|
595
613
|
}, {}, {}>;
|
|
596
|
-
|
|
597
|
-
name: "
|
|
614
|
+
usedMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
615
|
+
name: "used_micros";
|
|
598
616
|
tableName: "trial_credits";
|
|
599
617
|
dataType: "number";
|
|
600
|
-
columnType: "
|
|
618
|
+
columnType: "PgBigInt53";
|
|
601
619
|
data: number;
|
|
602
620
|
driverParam: string | number;
|
|
603
621
|
notNull: true;
|
|
@@ -610,11 +628,11 @@ export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
610
628
|
identity: undefined;
|
|
611
629
|
generated: undefined;
|
|
612
630
|
}, {}, {}>;
|
|
613
|
-
|
|
614
|
-
name: "
|
|
631
|
+
remainingMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
632
|
+
name: "remaining_micros";
|
|
615
633
|
tableName: "trial_credits";
|
|
616
634
|
dataType: "number";
|
|
617
|
-
columnType: "
|
|
635
|
+
columnType: "PgBigInt53";
|
|
618
636
|
data: number;
|
|
619
637
|
driverParam: string | number;
|
|
620
638
|
notNull: true;
|
|
@@ -627,6 +645,23 @@ export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
627
645
|
identity: undefined;
|
|
628
646
|
generated: undefined;
|
|
629
647
|
}, {}, {}>;
|
|
648
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
649
|
+
name: "currency";
|
|
650
|
+
tableName: "trial_credits";
|
|
651
|
+
dataType: "string";
|
|
652
|
+
columnType: "PgText";
|
|
653
|
+
data: string;
|
|
654
|
+
driverParam: string;
|
|
655
|
+
notNull: true;
|
|
656
|
+
hasDefault: true;
|
|
657
|
+
isPrimaryKey: false;
|
|
658
|
+
isAutoincrement: false;
|
|
659
|
+
hasRuntimeDefault: false;
|
|
660
|
+
enumValues: [string, ...string[]];
|
|
661
|
+
baseColumn: never;
|
|
662
|
+
identity: undefined;
|
|
663
|
+
generated: undefined;
|
|
664
|
+
}, {}, {}>;
|
|
630
665
|
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
631
666
|
name: "status";
|
|
632
667
|
tableName: "trial_credits";
|
|
@@ -767,20 +802,10 @@ export declare const trialCredits: import("drizzle-orm/pg-core").PgTableWithColu
|
|
|
767
802
|
dialect: "pg";
|
|
768
803
|
}>;
|
|
769
804
|
/**
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
* concurrent requests observe 1..N and exactly `limit` are admitted.
|
|
775
|
-
*
|
|
776
|
-
* An earlier version used ON CONFLICT DO NOTHING, which admitted
|
|
777
|
-
* exactly ONE request per minute on every plan — the per-plan limit was
|
|
778
|
-
* never consulted. See packages/billing/src/rate-limit.ts.
|
|
779
|
-
*
|
|
780
|
-
* Old buckets are deleted by the billing-maintenance cron.
|
|
781
|
-
*
|
|
782
|
-
* Database-backed rate limiting is the correct choice for <10K users
|
|
783
|
-
* (no Redis dependency, per architecture decisions).
|
|
805
|
+
* One row per (workspace, endpoint, minute bucket). Each request upserts the
|
|
806
|
+
* row and atomically increments `count`, so N concurrent requests observe
|
|
807
|
+
* 1..N and exactly `limit` are admitted. Old buckets are deleted by the
|
|
808
|
+
* billing-maintenance job.
|
|
784
809
|
*/
|
|
785
810
|
export declare const rateLimitEntries: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
786
811
|
name: "rate_limit_entries";
|
|
@@ -892,15 +917,9 @@ export declare const rateLimitEntries: import("drizzle-orm/pg-core").PgTableWith
|
|
|
892
917
|
dialect: "pg";
|
|
893
918
|
}>;
|
|
894
919
|
/**
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
* period-based deduplication key. The unique constraint on
|
|
899
|
-
* (workspaceId, type, periodKey) prevents sending the same notification
|
|
900
|
-
* twice in the same billing period.
|
|
901
|
-
*
|
|
902
|
-
* Phase 14 will update the channel from "console" to "email" and use
|
|
903
|
-
* Resend for actual delivery. For now, notifications are logged to console.
|
|
920
|
+
* Sent quota and trial notifications. The unique constraint on
|
|
921
|
+
* (workspaceId, type, periodKey) keeps one notification from being sent
|
|
922
|
+
* twice in a billing period.
|
|
904
923
|
*/
|
|
905
924
|
export declare const notificationHistory: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
906
925
|
name: "notification_history";
|
|
@@ -1029,11 +1048,9 @@ export declare const notificationHistory: import("drizzle-orm/pg-core").PgTableW
|
|
|
1029
1048
|
dialect: "pg";
|
|
1030
1049
|
}>;
|
|
1031
1050
|
/**
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
* live in the `usage` JSONB map and increment atomically in SQL, so a
|
|
1036
|
-
* quota check is O(1) with no SUM over usage_records.
|
|
1051
|
+
* Per-user, per-action usage counters, one row per user and workspace (not
|
|
1052
|
+
* per period). Counters live in the `usage` JSONB map and increment
|
|
1053
|
+
* atomically in SQL, so a quota check is O(1).
|
|
1037
1054
|
*/
|
|
1038
1055
|
export declare const userQuotas: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
1039
1056
|
name: "user_quotas";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/db/schema/usage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/db/schema/usage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBxB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,YAAY,CAAC;AAC5D,MAAM,MAAM,kBAAkB,GAAG,OAAO,YAAY,CAAC,YAAY,CAAC;AAClE,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,YAAY,CAAC;AAC3D,MAAM,MAAM,iBAAiB,GAAG,OAAO,YAAY,CAAC,YAAY,CAAC;AACjE,MAAM,MAAM,cAAc,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAC;AAClE,MAAM,MAAM,oBAAoB,GAAG,OAAO,gBAAgB,CAAC,YAAY,CAAC;AACxE,MAAM,MAAM,yBAAyB,GAAG,OAAO,mBAAmB,CAAC,YAAY,CAAC;AAChF,MAAM,MAAM,+BAA+B,GACzC,OAAO,mBAAmB,CAAC,YAAY,CAAC"}
|
package/dist/db/schema/usage.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Tables for tracking per-request token consumption and aggregated monthly usage.
|
|
5
|
-
* Used by the quota enforcement engine to check limits before AI requests
|
|
6
|
-
* and record consumption atomically after completion.
|
|
7
|
-
*
|
|
8
|
-
* Pattern: snake_case columns in PostgreSQL, camelCase TypeScript API (via Drizzle mapping)
|
|
2
|
+
* Token consumption per request and aggregated per period, which the quota
|
|
3
|
+
* engine checks before AI requests and records into after them.
|
|
9
4
|
*/
|
|
10
|
-
import { pgTable, text, timestamp, integer, real, index, unique, jsonb, } from "drizzle-orm/pg-core";
|
|
11
|
-
import { organization, users } from "./auth";
|
|
5
|
+
import { pgTable, text, timestamp, integer, bigint, real, index, unique, jsonb, } from "drizzle-orm/pg-core";
|
|
6
|
+
import { organization, users } from "./auth.js";
|
|
12
7
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* Every AI request creates one record with input/output/total tokens,
|
|
16
|
-
* the model used, and the agent that handled it. This provides the
|
|
17
|
-
* detailed breakdown for per-model and per-agent reporting (QUOTA-07).
|
|
8
|
+
* One row per AI request: tokens, model and agent, for per-model and
|
|
9
|
+
* per-agent reporting.
|
|
18
10
|
*/
|
|
19
11
|
export const usageRecords = pgTable("usage_records", {
|
|
20
12
|
id: text("id").primaryKey(),
|
|
@@ -26,22 +18,27 @@ export const usageRecords = pgTable("usage_records", {
|
|
|
26
18
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
27
19
|
type: text("type").notNull(), // "ai_tokens", "api_call"
|
|
28
20
|
model: text("model"), // "gpt-4o", "gpt-4o-mini"
|
|
29
|
-
agent: text("agent"), //
|
|
21
|
+
agent: text("agent"), // the product's agent slug
|
|
30
22
|
inputTokens: integer("input_tokens").notNull().default(0),
|
|
31
23
|
outputTokens: integer("output_tokens").notNull().default(0),
|
|
32
24
|
totalTokens: integer("total_tokens").notNull().default(0),
|
|
33
25
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* discrepancies over many records. Use chargedMnt (integer MNT) for all math.
|
|
26
|
+
* What the provider charged, in USD micros. Integer on purpose: float
|
|
27
|
+
* arithmetic accumulates sub-cent error over many records.
|
|
37
28
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
providerCostMicros: bigint("provider_cost_micros", { mode: "number" })
|
|
30
|
+
.notNull()
|
|
31
|
+
.default(0),
|
|
32
|
+
/** Snapshots of the rate and margin this charge was computed with. */
|
|
33
|
+
marginBp: integer("margin_bp").notNull().default(0),
|
|
34
|
+
usdRateMicros: bigint("usd_rate_micros", { mode: "number" })
|
|
35
|
+
.notNull()
|
|
36
|
+
.default(0),
|
|
37
|
+
/** Authoritative charge, in micros of `currency`. */
|
|
38
|
+
chargedMicros: bigint("charged_micros", { mode: "number" })
|
|
39
|
+
.notNull()
|
|
40
|
+
.default(0),
|
|
41
|
+
currency: text("currency").notNull().default("USD"),
|
|
45
42
|
/** Request correlation id for log tracing */
|
|
46
43
|
requestId: text("request_id"),
|
|
47
44
|
/**
|
|
@@ -63,11 +60,8 @@ export const usageRecords = pgTable("usage_records", {
|
|
|
63
60
|
index("usage_records_execution_id_idx").on(table.executionId),
|
|
64
61
|
]);
|
|
65
62
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Instead of SUM(totalTokens) on every request, we increment a counter atomically.
|
|
69
|
-
* One row per workspace per billing period. The usage_records table provides
|
|
70
|
-
* the detailed breakdown for reporting; this table provides O(1) quota checks.
|
|
63
|
+
* One row per workspace per billing period, incremented atomically, so a
|
|
64
|
+
* quota check is O(1) instead of a SUM over usage_records.
|
|
71
65
|
*/
|
|
72
66
|
export const monthlyUsage = pgTable("monthly_usage", {
|
|
73
67
|
id: text("id").primaryKey(),
|
|
@@ -77,8 +71,11 @@ export const monthlyUsage = pgTable("monthly_usage", {
|
|
|
77
71
|
periodStart: timestamp("period_start").notNull(),
|
|
78
72
|
periodEnd: timestamp("period_end").notNull(),
|
|
79
73
|
tokensUsed: integer("tokens_used").notNull().default(0),
|
|
80
|
-
/**
|
|
81
|
-
|
|
74
|
+
/** The plan allowance spent this period, in micros of `currency`. */
|
|
75
|
+
allowanceUsedMicros: bigint("allowance_used_micros", { mode: "number" })
|
|
76
|
+
.notNull()
|
|
77
|
+
.default(0),
|
|
78
|
+
currency: text("currency").notNull().default("USD"),
|
|
82
79
|
requestCount: integer("request_count").notNull().default(0),
|
|
83
80
|
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
84
81
|
}, (table) => [
|
|
@@ -86,16 +83,10 @@ export const monthlyUsage = pgTable("monthly_usage", {
|
|
|
86
83
|
index("monthly_usage_workspace_id_idx").on(table.workspaceId),
|
|
87
84
|
]);
|
|
88
85
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* The unique constraint on workspace_id enforces one trial per workspace (TRIAL-07).
|
|
93
|
-
* Trial credits are separate from purchased credits (credit_balances).
|
|
94
|
-
* They act as a fallback when plan quota is exceeded or credit balance is zero.
|
|
95
|
-
*
|
|
96
|
-
* Status flow: active → depleted (credits hit 0) or active → converted (paid plan)
|
|
86
|
+
* One-time trial grant, one per workspace (unique constraint). Separate from
|
|
87
|
+
* purchased credits; used when the plan quota is exceeded or the credit
|
|
88
|
+
* balance is zero. Status: active → depleted, converted or expired.
|
|
97
89
|
*/
|
|
98
|
-
// Run drizzle-kit push to apply index
|
|
99
90
|
export const trialCredits = pgTable("trial_credits", {
|
|
100
91
|
id: text("id").primaryKey(),
|
|
101
92
|
workspaceId: text("workspace_id")
|
|
@@ -105,12 +96,15 @@ export const trialCredits = pgTable("trial_credits", {
|
|
|
105
96
|
initialCredits: integer("initial_credits").notNull().default(100000),
|
|
106
97
|
creditsUsed: integer("credits_used").notNull().default(0),
|
|
107
98
|
creditsRemaining: integer("credits_remaining").notNull().default(100000),
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
/** The grant, in micros of `currency`. */
|
|
100
|
+
initialMicros: bigint("initial_micros", { mode: "number" })
|
|
101
|
+
.notNull()
|
|
102
|
+
.default(0),
|
|
103
|
+
usedMicros: bigint("used_micros", { mode: "number" }).notNull().default(0),
|
|
104
|
+
remainingMicros: bigint("remaining_micros", { mode: "number" })
|
|
112
105
|
.notNull()
|
|
113
|
-
.default(
|
|
106
|
+
.default(0),
|
|
107
|
+
currency: text("currency").notNull().default("USD"),
|
|
114
108
|
status: text("status").notNull().default("active"), // active|depleted|converted|expired
|
|
115
109
|
provisionedAt: timestamp("provisioned_at").notNull().defaultNow(),
|
|
116
110
|
trialEndDate: timestamp("trial_end_date"), // 14 days from provisioning
|
|
@@ -119,10 +113,8 @@ export const trialCredits = pgTable("trial_credits", {
|
|
|
119
113
|
createdByIp: text("created_by_ip"),
|
|
120
114
|
createdByEmail: text("created_by_email"),
|
|
121
115
|
/**
|
|
122
|
-
* Canonical form of createdByEmail
|
|
123
|
-
*
|
|
124
|
-
* can use an index instead of a full-table scan + JS filter.
|
|
125
|
-
* See packages/billing/src/trial.ts:normalizeEmailForAbuseCheck.
|
|
116
|
+
* Canonical form of createdByEmail for the per-email abuse check,
|
|
117
|
+
* stored so the count can use an index instead of a full-table scan.
|
|
126
118
|
*/
|
|
127
119
|
normalizedEmail: text("normalized_email"),
|
|
128
120
|
}, (table) => [
|
|
@@ -130,20 +122,10 @@ export const trialCredits = pgTable("trial_credits", {
|
|
|
130
122
|
index("trial_credits_normalized_email_idx").on(table.normalizedEmail),
|
|
131
123
|
]);
|
|
132
124
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* concurrent requests observe 1..N and exactly `limit` are admitted.
|
|
138
|
-
*
|
|
139
|
-
* An earlier version used ON CONFLICT DO NOTHING, which admitted
|
|
140
|
-
* exactly ONE request per minute on every plan — the per-plan limit was
|
|
141
|
-
* never consulted. See packages/billing/src/rate-limit.ts.
|
|
142
|
-
*
|
|
143
|
-
* Old buckets are deleted by the billing-maintenance cron.
|
|
144
|
-
*
|
|
145
|
-
* Database-backed rate limiting is the correct choice for <10K users
|
|
146
|
-
* (no Redis dependency, per architecture decisions).
|
|
125
|
+
* One row per (workspace, endpoint, minute bucket). Each request upserts the
|
|
126
|
+
* row and atomically increments `count`, so N concurrent requests observe
|
|
127
|
+
* 1..N and exactly `limit` are admitted. Old buckets are deleted by the
|
|
128
|
+
* billing-maintenance job.
|
|
147
129
|
*/
|
|
148
130
|
export const rateLimitEntries = pgTable("rate_limit_entries", {
|
|
149
131
|
id: text("id").primaryKey(),
|
|
@@ -161,15 +143,9 @@ export const rateLimitEntries = pgTable("rate_limit_entries", {
|
|
|
161
143
|
unique("rate_limit_entries_unique_bucket_idx").on(table.workspaceId, table.endpoint, table.minuteBucket),
|
|
162
144
|
]);
|
|
163
145
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* period-based deduplication key. The unique constraint on
|
|
168
|
-
* (workspaceId, type, periodKey) prevents sending the same notification
|
|
169
|
-
* twice in the same billing period.
|
|
170
|
-
*
|
|
171
|
-
* Phase 14 will update the channel from "console" to "email" and use
|
|
172
|
-
* Resend for actual delivery. For now, notifications are logged to console.
|
|
146
|
+
* Sent quota and trial notifications. The unique constraint on
|
|
147
|
+
* (workspaceId, type, periodKey) keeps one notification from being sent
|
|
148
|
+
* twice in a billing period.
|
|
173
149
|
*/
|
|
174
150
|
export const notificationHistory = pgTable("notification_history", {
|
|
175
151
|
id: text("id").primaryKey(),
|
|
@@ -179,39 +155,30 @@ export const notificationHistory = pgTable("notification_history", {
|
|
|
179
155
|
type: text("type").notNull(), // "quota_warning_80", "quota_warning_100", "trial_warning_20", "trial_depleted"
|
|
180
156
|
periodKey: text("period_key").notNull(), // "2026-02" for monthly, "trial" for one-time
|
|
181
157
|
sentAt: timestamp("sent_at").notNull().defaultNow(),
|
|
182
|
-
channel: text("channel").notNull().default("console"), // "console"
|
|
158
|
+
channel: text("channel").notNull().default("console"), // "console" | "email"
|
|
183
159
|
metadata: text("metadata"), // JSON string for additional context
|
|
184
160
|
}, (table) => [
|
|
185
161
|
unique("notification_history_dedup_unique").on(table.workspaceId, table.type, table.periodKey),
|
|
186
162
|
index("notification_history_workspace_id_idx").on(table.workspaceId),
|
|
187
163
|
]);
|
|
188
164
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* live in the `usage` JSONB map and increment atomically in SQL, so a
|
|
193
|
-
* quota check is O(1) with no SUM over usage_records.
|
|
165
|
+
* Per-user, per-action usage counters, one row per user and workspace (not
|
|
166
|
+
* per period). Counters live in the `usage` JSONB map and increment
|
|
167
|
+
* atomically in SQL, so a quota check is O(1).
|
|
194
168
|
*/
|
|
195
169
|
export const userQuotas = pgTable("user_quotas", {
|
|
196
170
|
id: text("id").primaryKey(),
|
|
197
171
|
userId: text("user_id")
|
|
198
172
|
.notNull()
|
|
199
|
-
.unique()
|
|
200
173
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
201
174
|
workspaceId: text("workspace_id")
|
|
202
175
|
.notNull()
|
|
203
176
|
.references(() => organization.id, { onDelete: "cascade" }),
|
|
204
177
|
plan: text("plan").notNull().default("free"), // free | standard | pro
|
|
205
178
|
/**
|
|
206
|
-
* Per-action
|
|
207
|
-
* (`usage["chat"] = 42`)
|
|
208
|
-
*
|
|
209
|
-
* Three career-specific integer columns — chat_messages_used,
|
|
210
|
-
* assessments_used, reports_used — used to sit beside it, written
|
|
211
|
-
* by every product and read in preference to this map. Migration
|
|
212
|
-
* 0038 backfilled them into the map and dropped them: a public
|
|
213
|
-
* schema naming one vertical's actions meant no other vertical
|
|
214
|
-
* could add a counter without a migration to Intelligo (ADR-0004).
|
|
179
|
+
* Per-action counters keyed by the product's own action slugs
|
|
180
|
+
* (`usage["chat"] = 42`), so a product adds a counter without a
|
|
181
|
+
* migration.
|
|
215
182
|
*/
|
|
216
183
|
usage: jsonb("usage").notNull().default({}),
|
|
217
184
|
totalCostUsd: real("total_cost_usd").notNull().default(0),
|
|
@@ -220,5 +187,8 @@ export const userQuotas = pgTable("user_quotas", {
|
|
|
220
187
|
}, (table) => [
|
|
221
188
|
index("user_quotas_user_id_idx").on(table.userId),
|
|
222
189
|
index("user_quotas_workspace_id_idx").on(table.workspaceId),
|
|
190
|
+
// Unique per (user, workspace), not per user: a user in a paid and a
|
|
191
|
+
// free workspace must not share one plan and one set of counters.
|
|
192
|
+
unique("user_quotas_user_workspace_unique").on(table.userId, table.workspaceId),
|
|
223
193
|
]);
|
|
224
194
|
//# sourceMappingURL=usage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/db/schema/usage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/db/schema/usage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,OAAO,EACP,IAAI,EACJ,SAAS,EACT,OAAO,EACP,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*
|
|
4
|
-
* Validates that the database is connected and tables exist before allowing the app to start.
|
|
5
|
-
*/
|
|
6
1
|
export interface DatabaseValidationResult {
|
|
7
2
|
isConnected: boolean;
|
|
8
3
|
tablesExist: boolean;
|
|
9
4
|
error?: string;
|
|
10
5
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Check if database connection is valid and tables exist
|
|
13
|
-
*/
|
|
6
|
+
/** Checks that the database answers and the four auth tables exist. */
|
|
14
7
|
export declare function validateDatabaseConnection(): Promise<DatabaseValidationResult>;
|
|
15
|
-
/**
|
|
16
|
-
* Validate database or throw error (for startup validation)
|
|
17
|
-
*/
|
|
8
|
+
/** Startup check: throws with setup instructions when validation fails. */
|
|
18
9
|
export declare function requireDatabaseConnection(): Promise<void>;
|
|
19
10
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/db/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/db/validate.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,uEAAuE;AACvE,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,wBAAwB,CAAC,CA4BpF;AAED,2EAA2E;AAC3E,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAqB/D"}
|