The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(usage-limit) - create usageLimit entity (#24708)
Etienne5592713eea87
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphqlindex dbe2c784c2c..d67f939c789 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql@@ -1734,6 +1734,47 @@ type SendInvitations {result: [WorkspaceInvitation!]!}+type UsageLimit {+ id: UUID!+ resourceType: UsageResourceType!+ operationType: UsageOperationType!+ spenderType: String!+ spenderId: String!+ limitKind: String!+ windowSeconds: Int!+ limitValueType: String!+ limitValue: BigInt!+ burstValue: BigInt+ createdAt: DateTime!+ updatedAt: DateTime!+}++enum UsageResourceType {+ AI+ WORKFLOW+ APP+ STORAGE+ API+ LOGIC_FUNCTION+}++enum UsageOperationType {+ AI_CHAT_TOKEN+ AI_WORKFLOW_TOKEN+ WORKFLOW_EXECUTION+ CODE_EXECUTION+ WEB_SEARCH+ CALL_RECORDING+ EMAIL_SEND+ API_REQUEST+}++"""+The `BigInt` scalar type represents non-fractional signed whole numeric values.+"""+scalar BigInt+type FeatureFlag {key: FeatureFlagKey!value: Boolean!@@ -3342,6 +3383,7 @@ type Query {enterprisePortalSession(returnUrlPath: String): StringenterpriseCheckoutSession(billingInterval: String): StringenterpriseSubscriptionStatus: EnterpriseSubscriptionStatusDTO+ usageLimits: [UsageLimit!]!getViewFilterGroups(viewId: String): [ViewFilterGroup!]!getViewFilterGroup(id: String!): ViewFilterGroupgetViewFilters(viewId: String): [ViewFilter!]!@@ -3576,16 +3618,6 @@ input UsageAnalyticsInput {operationTypes: [UsageOperationType!]}-enum UsageOperationType {- AI_CHAT_TOKEN- AI_WORKFLOW_TOKEN- WORKFLOW_EXECUTION- CODE_EXECUTION- WEB_SEARCH- CALL_RECORDING- EMAIL_SEND-}-type Mutation {addQueryToEventStream(input: AddQuerySubscriptionInput!): Boolean!removeQueryFromEventStream(input: RemoveQueryFromEventStreamInput!): Boolean!@@ -3607,6 +3639,8 @@ type Mutation {uploadWorkspaceMemberProfilePicture(file: Upload!): FileWithSignedUrl!uploadFilesFieldFile(file: Upload!, fieldMetadataId: String!): FileWithSignedUrl!uploadFilesFieldFileByUniversalIdentifier(file: Upload!, fieldMetadataUniversalIdentifier: String!): FileWithSignedUrl!+ upsertUsageLimit(input: UpsertUsageLimitInput!): UsageLimit!+ deleteUsageLimit(usageLimitId: UUID!): Boolean!createViewFilterGroup(input: CreateViewFilterGroupInput!): ViewFilterGroup!updateViewFilterGroup(id: String!, input: UpdateViewFilterGroupInput!): ViewFilterGroup!deleteViewFilterGroup(id: String!): Boolean!@@ -3883,6 +3917,17 @@ input UpdateNavigationMenuItemInput {"""The `Upload` scalar type represents a file upload."""scalar Upload+input UpsertUsageLimitInput {+ resourceType: UsageResourceType!+ operationType: UsageOperationType!+ spenderType: String!+ spenderId: String+ limitKind: String!+ windowSeconds: Int! = 0+ limitValue: BigInt!+ burstValue: BigInt+}+input CreateViewFilterGroupInput {id: UUIDparentViewFilterGroupId: UUIDdiff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.tsindex 1bfef97ca12..1e3d31ad96e 100644--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts@@ -9,6 +9,7 @@ export type Scalars = {Int: number,ConnectionCursor: any,JSONObject: any,+ BigInt: any,ID: string,Upload: File,}@@ -1403,6 +1404,26 @@ export interface SendInvitations {__typename: 'SendInvitations'}+export interface UsageLimit {+ id: Scalars['UUID']+ resourceType: UsageResourceType+ operationType: UsageOperationType+ spenderType: Scalars['String']+ spenderId: Scalars['String']+ limitKind: Scalars['String']+ windowSeconds: Scalars['Int']+ limitValueType: Scalars['String']+ limitValue: Scalars['BigInt']+ burstValue?: Scalars['BigInt']+ createdAt: Scalars['DateTime']+ updatedAt: Scalars['DateTime']+ __typename: 'UsageLimit'+}++export type UsageResourceType = 'AI' | 'WORKFLOW' | 'APP' | 'STORAGE' | 'API' | 'LOGIC_FUNCTION' | 'EMAIL'++export type UsageOperationType = 'AI_CHAT_TOKEN' | 'AI_WORKFLOW_TOKEN' | 'WORKFLOW_EXECUTION' | 'CODE_EXECUTION' | 'WEB_SEARCH' | 'CALL_RECORDING' | 'EMAIL_SEND' | 'API_REQUEST'+export interface FeatureFlag {key: FeatureFlagKeyvalue: Scalars['Boolean']@@ -2957,6 +2978,7 @@ export interface Query {enterprisePortalSession?: Scalars['String']enterpriseCheckoutSession?: Scalars['String']enterpriseSubscriptionStatus?: EnterpriseSubscriptionStatusDTO+ usageLimits: UsageLimit[]getViewFilterGroups: ViewFilterGroup[]getViewFilterGroup?: ViewFilterGroupgetViewFilters: ViewFilter[]@@ -3073,8 +3095,6 @@ export interface Query {export type EventLogTable = 'WORKSPACE_EVENT' | 'PAGEVIEW' | 'OBJECT_EVENT' | 'USAGE_EVENT' | 'APPLICATION_LOG'-export type UsageOperationType = 'AI_CHAT_TOKEN' | 'AI_WORKFLOW_TOKEN' | 'WORKFLOW_EXECUTION' | 'CODE_EXECUTION' | 'WEB_SEARCH' | 'CALL_RECORDING' | 'EMAIL_SEND'-export interface Mutation {addQueryToEventStream: Scalars['Boolean']removeQueryFromEventStream: Scalars['Boolean']@@ -3096,6 +3116,8 @@ export interface Mutation {uploadWorkspaceMemberProfilePicture: FileWithSignedUrluploadFilesFieldFile: FileWithSignedUrluploadFilesFieldFileByUniversalIdentifier: FileWithSignedUrl+ upsertUsageLimit: UsageLimit+ deleteUsageLimit: Scalars['Boolean']createViewFilterGroup: ViewFilterGroupupdateViewFilterGroup: ViewFilterGroupdeleteViewFilterGroup: Scalars['Boolean']@@ -4790,6 +4812,23 @@ export interface SendInvitationsGenqlSelection{__scalar?: boolean | number}+export interface UsageLimitGenqlSelection{+ id?: boolean | number+ resourceType?: boolean | number+ operationType?: boolean | number+ spenderType?: boolean | number+ spenderId?: boolean | number+ limitKind?: boolean | number+ windowSeconds?: boolean | number+ limitValueType?: boolean | number+ limitValue?: boolean | number+ burstValue?: boolean | number+ createdAt?: boolean | number+ updatedAt?: boolean | number+ __typename?: boolean | number+ __scalar?: boolean | number+}+export interface FeatureFlagGenqlSelection{key?: boolean | numbervalue?: boolean | number@@ -6431,6 +6470,7 @@ export interface QueryGenqlSelection{enterprisePortalSession?: { __args: {returnUrlPath?: (Scalars['String'] | null)} } | boolean | numberenterpriseCheckoutSession?: { __args: {billingInterval?: (Scalars['String'] | null)} } | boolean | numberenterpriseSubscriptionStatus?: EnterpriseSubscriptionStatusDTOGenqlSelection+ usageLimits?: UsageLimitGenqlSelectiongetViewFilterGroups?: (ViewFilterGroupGenqlSelection & { __args?: {viewId?: (Scalars['String'] | null)} })getViewFilterGroup?: (ViewFilterGroupGenqlSelection & { __args: {id: Scalars['String']} })getViewFilters?: (ViewFilterGenqlSelection & { __args?: {viewId?: (Scalars['String'] | null)} })@@ -6613,6 +6653,8 @@ export interface MutationGenqlSelection{uploadWorkspaceMemberProfilePicture?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload']} })uploadFilesFieldFile?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload'], fieldMetadataId: Scalars['String']} })uploadFilesFieldFileByUniversalIdentifier?: (FileWithSignedUrlGenqlSelection & { __args: {file: Scalars['Upload'], fieldMetadataUniversalIdentifier: Scalars['String']} })+ upsertUsageLimit?: (UsageLimitGenqlSelection & { __args: {input: UpsertUsageLimitInput} })+ deleteUsageLimit?: { __args: {usageLimitId: Scalars['UUID']} }createViewFilterGroup?: (ViewFilterGroupGenqlSelection & { __args: {input: CreateViewFilterGroupInput} })updateViewFilterGroup?: (ViewFilterGroupGenqlSelection & { __args: {id: Scalars['String'], input: UpdateViewFilterGroupInput} })deleteViewFilterGroup?: { __args: {id: Scalars['String']} }@@ -6859,6 +6901,8 @@ update: UpdateNavigationMenuItemInput}export interface UpdateNavigationMenuItemInput {folderId?: (Scalars['UUID'] | null),position?: (Scalars['Float'] | null),name?: (Scalars['String'] | null),link?: (Scalars['String'] | null),icon?: (Scalars['String'] | null),color?: (Scalars['String'] | null),pageLayoutId?: (Scalars['UUID'] | null)}+export interface UpsertUsageLimitInput {resourceType: UsageResourceType,operationType: UsageOperationType,spenderType: Scalars['String'],spenderId?: (Scalars['String'] | null),limitKind: Scalars['String'],windowSeconds: Scalars['Int'],limitValue: Scalars['BigInt'],burstValue?: (Scalars['BigInt'] | null)}+export interface CreateViewFilterGroupInput {id?: (Scalars['UUID'] | null),parentViewFilterGroupId?: (Scalars['UUID'] | null),logicalOperator?: (ViewFilterGroupLogicalOperator | null),positionInViewFilterGroup?: (Scalars['Float'] | null),viewId: Scalars['UUID']}export interface UpdateViewFilterGroupInput {id?: (Scalars['UUID'] | null),parentViewFilterGroupId?: (Scalars['UUID'] | null),logicalOperator?: (ViewFilterGroupLogicalOperator | null),positionInViewFilterGroup?: (Scalars['Float'] | null),viewId?: (Scalars['UUID'] | null)}@@ -8171,6 +8215,14 @@ export interface LogicFunctionLogsInput {applicationId?: (Scalars['UUID'] | null+ const UsageLimit_possibleTypes: string[] = ['UsageLimit']+ export const isUsageLimit = (obj?: { __typename?: any } | null): obj is UsageLimit => {+ if (!obj?.__typename) throw new Error('__typename is missing in "isUsageLimit"')+ return UsageLimit_possibleTypes.includes(obj.__typename)+ }+++const FeatureFlag_possibleTypes: string[] = ['FeatureFlag']export const isFeatureFlag = (obj?: { __typename?: any } | null): obj is FeatureFlag => {if (!obj?.__typename) throw new Error('__typename is missing in "isFeatureFlag"')@@ -9976,6 +10028,27 @@ export const enumDatabaseEventAction = {UPSERTED: 'UPSERTED' as const}+export const enumUsageResourceType = {+ AI: 'AI' as const,+ WORKFLOW: 'WORKFLOW' as const,+ APP: 'APP' as const,+ STORAGE: 'STORAGE' as const,+ API: 'API' as const,+ LOGIC_FUNCTION: 'LOGIC_FUNCTION' as const,+ EMAIL: 'EMAIL' as const+}++export const enumUsageOperationType = {+ AI_CHAT_TOKEN: 'AI_CHAT_TOKEN' as const,+ AI_WORKFLOW_TOKEN: 'AI_WORKFLOW_TOKEN' as const,+ WORKFLOW_EXECUTION: 'WORKFLOW_EXECUTION' as const,+ CODE_EXECUTION: 'CODE_EXECUTION' as const,+ WEB_SEARCH: 'WEB_SEARCH' as const,+ CALL_RECORDING: 'CALL_RECORDING' as const,+ EMAIL_SEND: 'EMAIL_SEND' as const,+ API_REQUEST: 'API_REQUEST' as const+}+export const enumFeatureFlagKey = {IS_APP_CLAIMING_ENABLED: 'IS_APP_CLAIMING_ENABLED' as const,IS_UNIQUE_INDEXES_ENABLED: 'IS_UNIQUE_INDEXES_ENABLED' as const,@@ -10267,16 +10340,6 @@ export const enumEventLogTable = {APPLICATION_LOG: 'APPLICATION_LOG' as const}-export const enumUsageOperationType = {- AI_CHAT_TOKEN: 'AI_CHAT_TOKEN' as const,- AI_WORKFLOW_TOKEN: 'AI_WORKFLOW_TOKEN' as const,- WORKFLOW_EXECUTION: 'WORKFLOW_EXECUTION' as const,- CODE_EXECUTION: 'CODE_EXECUTION' as const,- WEB_SEARCH: 'WEB_SEARCH' as const,- CALL_RECORDING: 'CALL_RECORDING' as const,- EMAIL_SEND: 'EMAIL_SEND' as const-}-export const enumRunAgentMessageRole = {user: 'user' as const,assistant: 'assistant' as constdiff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.tsindex b0a97eb124c..800d12d47a6 100644--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts@@ -54,45 +54,47 @@ export default {154,156,172,- 179,- 180,- 187,- 190,- 193,- 205,- 222,- 223,- 225,- 230,- 233,- 242,- 248,- 282,- 290,- 292,- 293,+ 173,+ 174,+ 176,+ 183,+ 184,+ 191,+ 194,+ 197,+ 209,+ 226,+ 227,+ 229,+ 234,+ 237,+ 246,+ 252,+ 286,294,- 295,296,297,298,- 305,- 306,+ 299,+ 300,+ 301,+ 302,309,- 346,- 353,- 355,- 356,+ 310,+ 313,+ 350,357,- 358,+ 359,360,+ 361,362,- 367,- 381,- 388,- 395,- 508,- 532+ 364,+ 366,+ 371,+ 385,+ 398,+ 512,+ 536],"types": {"BillingProductDTO": {@@ -559,7 +561,7 @@ export default {1],"fields": [- 237,+ 241,{"paging": [25,@@ -572,7 +574,7 @@ export default {}],"indexMetadatas": [- 238,+ 242,{"paging": [25,@@ -585,13 +587,13 @@ export default {}],"fieldsList": [- 224+ 228],"indexMetadataList": [- 232+ 236],"searchFieldMetadataList": [- 240+ 244],"__typename": [1@@ -1629,7 +1631,7 @@ export default {47],"featureFlags": [- 171+ 175],"billingSubscriptions": [140@@ -1644,7 +1646,7 @@ export default {139],"billingEntitlements": [- 241+ 245],"hasValidSignedEnterpriseKey": [8@@ -1653,7 +1655,7 @@ export default {8],"workspaceUrls": [- 173+ 177],"workspaceCustomApplicationId": [1@@ -1726,7 +1728,7 @@ export default {33],"deletedWorkspaceMembers": [- 215+ 219],"hasPassword": [8@@ -1741,7 +1743,7 @@ export default {49],"availableWorkspaces": [- 214+ 218],"__typename": [1@@ -3368,9 +3370,53 @@ export default {1]},+ "UsageLimit": {+ "id": [+ 3+ ],+ "resourceType": [+ 172+ ],+ "operationType": [+ 173+ ],+ "spenderType": [+ 1+ ],+ "spenderId": [+ 1+ ],+ "limitKind": [+ 1+ ],+ "windowSeconds": [+ 26+ ],+ "limitValueType": [+ 1+ ],+ "limitValue": [+ 174+ ],+ "burstValue": [+ 174+ ],+ "createdAt": [+ 4+ ],+ "updatedAt": [+ 4+ ],+ "__typename": [+ 1+ ]+ },+ "UsageResourceType": {},+ "UsageOperationType": {},+ "BigInt": {},"FeatureFlag": {"key": [- 172+ 176],"value": [8@@ -3451,7 +3497,7 @@ export default {1],"versionDistribution": [- 175+ 179],"__typename": [1@@ -3476,10 +3522,10 @@ export default {1],"type": [- 179+ 183],"status": [- 180+ 184],"issuer": [1@@ -3492,7 +3538,7 @@ export default {"SSOIdentityProviderStatus": {},"AuthProviders": {"sso": [- 178+ 182],"google": [8@@ -3529,10 +3575,10 @@ export default {3],"authProviders": [- 181+ 185],"authBypassProviders": [- 182+ 186],"logo": [1@@ -3541,7 +3587,7 @@ export default {1],"workspaceUrls": [- 173+ 177],"__typename": [1@@ -3580,7 +3626,7 @@ export default {1],"modelFamily": [- 187+ 191],"modelFamilyLabel": [1@@ -3595,7 +3641,7 @@ export default {15],"nativeCapabilities": [- 185+ 189],"isDeprecated": [8@@ -3634,7 +3680,7 @@ export default {1],"trialPeriods": [- 177+ 181],"__typename": [1@@ -3642,7 +3688,7 @@ export default {},"Support": {"supportDriver": [- 190+ 194],"supportFrontChatId": [1@@ -3671,7 +3717,7 @@ export default {},"Captcha": {"provider": [- 193+ 197],"siteKey": [1@@ -3708,10 +3754,10 @@ export default {},"PublicFeatureFlag": {"key": [- 172+ 176],"metadata": [- 195+ 199],"__typename": [1@@ -3736,13 +3782,13 @@ export default {1],"authProviders": [- 181+ 185],"billing": [- 188+ 192],"aiModels": [- 186+ 190],"signInPrefilled": [8@@ -3766,25 +3812,25 @@ export default {8],"support": [- 189+ 193],"isAttachmentPreviewEnabled": [8],"sentry": [- 191+ 195],"captcha": [- 192+ 196],"api": [- 194+ 198],"canManageFeatureFlags": [8],"publicFeatureFlags": [- 196+ 200],"isCookieSessionEnabled": [8@@ -3838,7 +3884,7 @@ export default {1],"maintenance": [- 197+ 201],"__typename": [1@@ -3928,7 +3974,7 @@ export default {},"AppConnection": {"id": [- 205+ 209],"providerName": [1@@ -3980,7 +4026,7 @@ export default {3],"type": [- 179+ 183],"issuer": [1@@ -3989,7 +4035,7 @@ export default {1],"status": [- 180+ 184],"__typename": [1@@ -4008,7 +4054,7 @@ export default {},"FindAvailableSSOIDP": {"type": [- 179+ 183],"id": [3@@ -4020,10 +4066,10 @@ export default {1],"status": [- 180+ 184],"workspace": [- 209+ 213],"__typename": [1@@ -4034,7 +4080,7 @@ export default {3],"type": [- 179+ 183],"issuer": [1@@ -4043,7 +4089,7 @@ export default {1],"status": [- 180+ 184],"__typename": [1@@ -4051,7 +4097,7 @@ export default {},"SSOConnection": {"type": [- 179+ 183],"id": [3@@ -4063,7 +4109,7 @@ export default {1],"status": [- 180+ 184],"__typename": [1@@ -4086,13 +4132,13 @@ export default {1],"workspaceUrls": [- 173+ 177],"logo": [1],"sso": [- 212+ 216],"__typename": [1@@ -4100,10 +4146,10 @@ export default {},"AvailableWorkspaces": {"availableWorkspacesForSignIn": [- 213+ 217],"availableWorkspacesForSignUp": [- 213+ 217],"__typename": [1@@ -4236,10 +4282,10 @@ export default {1],"objectPermissions": [- 217+ 221],"fieldPermissions": [- 218+ 222],"__typename": [1@@ -4307,7 +4353,7 @@ export default {1],"roles": [- 219+ 223],"manifest": [9@@ -4318,13 +4364,13 @@ export default {},"WorkspaceCompanyEnrichmentResult": {"outcome": [- 222+ 226],"enrichment": [9],"personOutcome": [- 223+ 227],"personEnrichment": [9@@ -4346,7 +4392,7 @@ export default {1],"type": [- 225+ 229],"name": [1@@ -4409,10 +4455,10 @@ export default {23],"relation": [- 229+ 233],"morphRelations": [- 229+ 233],"__typename": [1@@ -4438,7 +4484,7 @@ export default {},"FieldEdge": {"node": [- 224+ 228],"cursor": [27@@ -4449,10 +4495,10 @@ export default {},"FieldConnection": {"pageInfo": [- 226+ 230],"edges": [- 227+ 231],"__typename": [1@@ -4460,7 +4506,7 @@ export default {},"Relation": {"type": [- 230+ 234],"sourceObjectMetadata": [23@@ -4469,10 +4515,10 @@ export default {23],"sourceFieldMetadata": [- 224+ 228],"targetFieldMetadata": [- 224+ 228],"__typename": [1@@ -4519,7 +4565,7 @@ export default {1],"indexType": [- 233+ 237],"createdAt": [4@@ -4528,7 +4574,7 @@ export default {4],"indexFieldMetadataList": [- 231+ 235],"__typename": [1@@ -4537,7 +4583,7 @@ export default {"IndexType": {},"IndexEdge": {"node": [- 232+ 236],"cursor": [27@@ -4559,10 +4605,10 @@ export default {},"ObjectConnection": {"pageInfo": [- 226+ 230],"edges": [- 235+ 239],"__typename": [1@@ -4570,10 +4616,10 @@ export default {},"ObjectFieldsConnection": {"pageInfo": [- 226+ 230],"edges": [- 227+ 231],"__typename": [1@@ -4581,10 +4627,10 @@ export default {},"ObjectIndexMetadatasConnection": {"pageInfo": [- 226+ 230],"edges": [- 234+ 238],"__typename": [1@@ -4626,7 +4672,7 @@ export default {},"BillingEntitlement": {"key": [- 242+ 246],"value": [8@@ -4664,7 +4710,7 @@ export default {1],"records": [- 243+ 247],"isCustomDomainEnabled": [8@@ -4703,7 +4749,7 @@ export default {1],"connectionSecurity": [- 248+ 252],"__typename": [1@@ -4712,13 +4758,13 @@ export default {"EmailConnectionSecurity": {},"PublicImapSmtpCaldavConnectionParameters": {"IMAP": [- 247+ 251],"SMTP": [- 247+ 251],"CALDAV": [- 247+ 251],"__typename": [1@@ -4774,7 +4820,7 @@ export default {4],"connectionParameters": [- 249+ 253],"__typename": [1@@ -4825,10 +4871,10 @@ export default {},"AvailableWorkspacesAndAccessTokens": {"tokens": [- 255+ 259],"availableWorkspaces": [- 214+ 218],"__typename": [1@@ -4866,7 +4912,7 @@ export default {},"WorkspaceUrlsAndId": {"workspaceUrls": [- 173+ 177],"id": [3@@ -4880,7 +4926,7 @@ export default {11],"workspace": [- 260+ 264],"__typename": [1@@ -4913,7 +4959,7 @@ export default {11],"workspaceUrls": [- 173+ 177],"__typename": [1@@ -4957,7 +5003,7 @@ export default {},"AuthTokens": {"tokens": [- 255+ 259],"__typename": [1@@ -4998,7 +5044,7 @@ export default {11],"workspace": [- 260+ 264],"__typename": [1@@ -5028,7 +5074,7 @@ export default {1],"dailyUsage": [- 274+ 278],"__typename": [1@@ -5036,16 +5082,16 @@ export default {},"UsageAnalytics": {"usageByUser": [- 199+ 203],"usageByOperationType": [- 199+ 203],"usageByModel": [- 199+ 203],"timeSeries": [- 274+ 278],"periodStart": [4@@ -5054,7 +5100,7 @@ export default {4],"userDailyUsage": [- 275+ 279],"__typename": [1@@ -5122,10 +5168,10 @@ export default {},"CompleteApplicationFileUploadsResult": {"files": [- 278+ 282],"errors": [- 279+ 283],"__typename": [1@@ -5136,7 +5182,7 @@ export default {3],"fileFolder": [- 282+ 286],"filePath": [1@@ -5157,7 +5203,7 @@ export default {"FileFolder": {},"ApplicationFileUploadError": {"fileFolder": [- 282+ 286],"filePath": [1@@ -5171,10 +5217,10 @@ export default {},"CreateApplicationFileUploadsResult": {"targets": [- 281+ 285],"errors": [- 283+ 287],"__typename": [1@@ -5256,10 +5302,10 @@ export default {1],"status": [- 290+ 294],"verificationRecords": [- 288+ 292],"verifiedAt": [4@@ -5274,7 +5320,7 @@ export default {3],"visibility": [- 292+ 296],"handle": [1@@ -5283,16 +5329,16 @@ export default {1],"type": [- 293+ 297],"isContactAutoCreationEnabled": [8],"contactAutoCreationPolicy": [- 294+ 298],"messageFolderImportPolicy": [- 295+ 299],"excludeNonProfessionalEmails": [8@@ -5301,7 +5347,7 @@ export default {8],"pendingGroupEmailsAction": [- 296+ 300],"isSyncEnabled": [8@@ -5310,10 +5356,10 @@ export default {4],"syncStatus": [- 297+ 301],"syncStage": [- 298+ 302],"syncStageStartedAt": [4@@ -5334,7 +5380,7 @@ export default {4],"connectedAccount": [- 250+ 254],"__typename": [1@@ -5349,7 +5395,7 @@ export default {"MessageChannelSyncStage": {},"CreateEmailGroupChannelOutput": {"messageChannel": [- 291+ 295],"forwardingAddress": [1@@ -5411,7 +5457,7 @@ export default {26],"skipped": [- 302+ 306],"__typename": [1@@ -5428,10 +5474,10 @@ export default {1],"reason": [- 305+ 309],"source": [- 306+ 310],"unsubscribeTopicId": [3@@ -5444,7 +5490,7 @@ export default {"MessageSuppressionSource": {},"MessageSuppressionList": {"records": [- 304+ 308],"totalCount": [26@@ -5470,7 +5516,7 @@ export default {1],"visibility": [- 309+ 313],"__typename": [1@@ -5516,7 +5562,7 @@ export default {1],"location": [- 311+ 315],"__typename": [1@@ -5533,7 +5579,7 @@ export default {1],"connectionSecurity": [- 248+ 252],"__typename": [1@@ -5544,13 +5590,13 @@ export default {1],"IMAP": [- 313+ 317],"SMTP": [- 313+ 317],"CALDAV": [- 313+ 317],"__typename": [1@@ -5570,7 +5616,7 @@ export default {3],"connectionParameters": [- 314+ 318],"__typename": [1@@ -5792,7 +5838,7 @@ export default {1],"series": [- 323+ 327],"xAxisLabel": [1@@ -5841,7 +5887,7 @@ export default {1],"data": [- 325+ 329],"__typename": [1@@ -5849,7 +5895,7 @@ export default {},"LineChartData": {"series": [- 326+ 330],"xAxisLabel": [1@@ -5886,7 +5932,7 @@ export default {},"PieChartData": {"data": [- 328+ 332],"showLegend": [8@@ -5991,13 +6037,13 @@ export default {},"EventLogQueryResult": {"records": [- 333+ 337],"totalCount": [26],"pageInfo": [- 334+ 338],"__typename": [1@@ -6061,7 +6107,7 @@ export default {1],"parts": [- 319+ 323],"processedAt": [4@@ -6075,7 +6121,7 @@ export default {},"AgentChatThread": {"id": [- 205+ 209],"title": [1@@ -6130,7 +6176,7 @@ export default {},"AiSystemPromptPreview": {"sections": [- 339+ 343],"estimatedTokenCount": [26@@ -6158,7 +6204,7 @@ export default {26],"error": [- 341+ 345],"__typename": [1@@ -6191,10 +6237,10 @@ export default {},"StartWorkspaceSetupChatResult": {"outcome": [- 346+ 350],"thread": [- 338+ 342],"__typename": [1@@ -6232,10 +6278,10 @@ export default {3],"evaluations": [- 347+ 351],"messages": [- 337+ 341],"createdAt": [4@@ -6291,7 +6337,7 @@ export default {9],"scope": [- 353+ 357],"__typename": [1@@ -6306,19 +6352,19 @@ export default {1],"syncStatus": [- 355+ 359],"syncStage": [- 356+ 360],"visibility": [- 357+ 361],"isContactAutoCreationEnabled": [8],"contactAutoCreationPolicy": [- 358+ 362],"isSyncEnabled": [8@@ -6369,7 +6415,7 @@ export default {1],"pendingSyncAction": [- 360+ 364],"messageChannelId": [3@@ -6411,7 +6457,7 @@ export default {1],"provenance": [- 362+ 366],"__typename": [1@@ -6437,7 +6483,7 @@ export default {3],"through": [- 363+ 367],"__typename": [1@@ -6457,7 +6503,7 @@ export default {1],"emit": [- 364+ 368],"action": [1@@ -6492,7 +6538,7 @@ export default {},"CollectionHash": {"collectionName": [- 367+ 371],"hash": [1@@ -6556,13 +6602,13 @@ export default {},"MinimalMetadata": {"objectMetadataItems": [- 368+ 372],"views": [- 369+ 373],"collectionHashes": [- 366+ 370],"__typename": [1@@ -6618,6 +6664,9 @@ export default {"enterpriseSubscriptionStatus": [145],+ "usageLimits": [+ 171+ ],"getViewFilterGroups": [53,{@@ -6736,7 +6785,7 @@ export default {2,{"input": [- 372,+ 376,"GetApiKeyInput!"]}@@ -6842,20 +6891,20 @@ export default {10,{"input": [- 373,+ 377,"AgentIdInput!"]}],"objects": [- 236,+ 240,{"paging": [25,"CursorPaging!"],"filter": [- 374,+ 378,"ObjectFilter!"]}@@ -6870,7 +6919,7 @@ export default {}],"objectRecordCounts": [- 239+ 243],"mostlyEmptyFieldMetadataIds": [3,@@ -6885,7 +6934,7 @@ export default {21,{"input": [- 375,+ 379,"LogicFunctionIdInput!"]}@@ -6897,7 +6946,7 @@ export default {9,{"input": [- 375,+ 379,"LogicFunctionIdInput!"]}@@ -6906,7 +6955,7 @@ export default {1,{"input": [- 375,+ 379,"LogicFunctionIdInput!"]}@@ -6939,7 +6988,7 @@ export default {67],"getPublicWorkspaceDataByDomain": [- 183,+ 187,{"origin": [1@@ -6947,7 +6996,7 @@ export default {}],"getPublicWorkspaceDataById": [- 184,+ 188,{"id": [3,@@ -6956,7 +7005,7 @@ export default {}],"findApplicationRegistrationByClientId": [- 202,+ 206,{"clientId": [1,@@ -6986,7 +7035,7 @@ export default {}],"findApplicationRegistrationStats": [- 176,+ 180,{"id": [1,@@ -6995,7 +7044,7 @@ export default {}],"findApplicationRegistrationVariables": [- 174,+ 178,{"applicationRegistrationId": [1,@@ -7013,7 +7062,7 @@ export default {}],"findClaimableApplicationRegistration": [- 200,+ 204,{"sourcePackage": [1@@ -7047,7 +7096,7 @@ export default {}],"findManyMarketplaceApps": [- 216,+ 220,{"universalIdentifiers": [1,@@ -7056,7 +7105,7 @@ export default {}],"findMarketplaceAppDetail": [- 220,+ 224,{"universalIdentifier": [1,@@ -7065,7 +7114,7 @@ export default {}],"publicMarketplaceApps": [- 216,+ 220,{"isVetted": [8,@@ -7074,7 +7123,7 @@ export default {}],"publicMarketplaceAppDetail": [- 220,+ 224,{"universalIdentifier": [1,@@ -7083,7 +7132,7 @@ export default {}],"fields": [- 228,+ 232,{"paging": [25,@@ -7096,7 +7145,7 @@ export default {}],"field": [- 224,+ 228,{"id": [3,@@ -7125,28 +7174,28 @@ export default {46],"previewMessageCampaignAudience": [- 300,+ 304,{"input": [- 376,+ 380,"PreviewMessageCampaignAudienceInput!"]}],"messageSuppressions": [- 307,+ 311,{"input": [- 377,+ 381,"FindMessageSuppressionsInput!"]}],"unsubscribeTopics": [- 308+ 312],"myMessageChannels": [- 291,+ 295,{"connectedAccountId": [3@@ -7154,13 +7203,13 @@ export default {}],"getEmailingDomains": [- 289+ 293],"myConnectedAccounts": [- 250+ 254],"getToolIndex": [- 318+ 322],"getToolInputSchema": [9,@@ -7172,10 +7221,10 @@ export default {}],"webhooks": [- 317+ 321],"webhook": [- 317,+ 321,{"id": [3,@@ -7184,7 +7233,7 @@ export default {}],"myMessageFolders": [- 359,+ 363,{"messageChannelId": [3@@ -7192,7 +7241,7 @@ export default {}],"myCalendarChannels": [- 354,+ 358,{"connectedAccountId": [3@@ -7200,45 +7249,45 @@ export default {}],"minimalMetadata": [- 370+ 374],"appKeyValue": [- 352,+ 356,{"key": [1,"String!"],"scope": [- 353+ 357]}],"appConnections": [- 204,+ 208,{"filter": [- 378+ 382]}],"appConnection": [- 204,+ 208,{"id": [- 205,+ 209,"ID!"]}],"findWorkspaceAiStats": [- 349+ 353],"chatThreads": [- 338+ 342],"chatThread": [- 338,+ 342,{"id": [3,@@ -7247,7 +7296,7 @@ export default {}],"chatMessages": [- 337,+ 341,{"threadId": [3,@@ -7256,7 +7305,7 @@ export default {}],"chatStreamCatchupChunks": [- 342,+ 346,{"threadId": [3,@@ -7265,13 +7314,13 @@ export default {}],"getAiSystemPromptPreview": [- 340+ 344],"skills": [- 336+ 340],"skill": [- 336,+ 340,{"id": [3,@@ -7280,7 +7329,7 @@ export default {}],"agentTurns": [- 348,+ 352,{"agentId": [3,@@ -7289,19 +7338,19 @@ export default {}],"timelineActivityTypes": [- 365+ 369],"metadataTranslations": [- 361,+ 365,{"input": [- 379,+ 383,"MetadataTranslationsInput!"]}],"checkUserExists": [- 270,+ 274,{"email": [1,@@ -7313,7 +7362,7 @@ export default {}],"checkWorkspaceInviteHashIsValid": [- 271,+ 275,{"inviteHash": [1,@@ -7331,7 +7380,7 @@ export default {}],"checkWorkspaceSubdomainAvailability": [- 265,+ 269,{"subdomain": [1,@@ -7340,10 +7389,10 @@ export default {}],"getWorkspaceCreationDefaults": [- 266+ 270],"validatePasswordResetToken": [- 263,+ 267,{"passwordResetToken": [1,@@ -7355,46 +7404,46 @@ export default {70],"getSSOIdentityProviders": [- 210+ 214],"eventLogs": [- 335,+ 339,{"input": [- 380,+ 384,"EventLogQueryInput!"]}],"pieChartData": [- 329,+ 333,{"input": [- 384,+ 388,"PieChartDataInput!"]}],"lineChartData": [- 327,+ 331,{"input": [- 385,+ 389,"LineChartDataInput!"]}],"barChartData": [- 324,+ 328,{"input": [- 386,+ 390,"BarChartDataInput!"]}],"getConnectedImapSmtpCaldavAccount": [- 315,+ 319,{"id": [3,@@ -7403,7 +7452,7 @@ export default {}],"getAutoCompleteAddress": [- 310,+ 314,{"address": [1,@@ -7422,7 +7471,7 @@ export default {}],"getAddressDetails": [- 312,+ 316,{"placeId": [1,@@ -7435,18 +7484,18 @@ export default {}],"getUsageAnalytics": [- 276,+ 280,{"input": [- 387+ 391]}],"findManyPublicDomains": [- 287+ 291],"currentUserApplicationAuthorizations": [- 277+ 281],"__typename": [1@@ -7470,10 +7519,10 @@ export default {},"ObjectFilter": {"and": [- 374+ 378],"or": [- 374+ 378],"id": [29@@ -7508,7 +7557,7 @@ export default {},"LogicFunctionIdInput": {"id": [- 205+ 209],"__typename": [1@@ -7527,7 +7576,7 @@ export default {},"FindMessageSuppressionsInput": {"reason": [- 305+ 309],"searchTerm": [1@@ -7575,10 +7624,10 @@ export default {},"EventLogQueryInput": {"table": [- 381+ 385],"filters": [- 382+ 386],"first": [26@@ -7599,7 +7648,7 @@ export default {1],"dateRange": [- 383+ 387],"recordId": [1@@ -7666,19 +7715,18 @@ export default {1],"operationTypes": [- 388+ 173],"__typename": [1]},- "UsageOperationType": {},"Mutation": {"addQueryToEventStream": [8,{"input": [- 390,+ 393,"AddQuerySubscriptionInput!"]}@@ -7687,7 +7735,7 @@ export default {8,{"input": [- 391,+ 394,"RemoveQueryFromEventStreamInput!"]}@@ -7696,7 +7744,7 @@ export default {150,{"inputs": [- 392,+ 395,"[CreateNavigationMenuItemInput!]!"]}@@ -7705,7 +7753,7 @@ export default {150,{"input": [- 392,+ 395,"CreateNavigationMenuItemInput!"]}@@ -7714,7 +7762,7 @@ export default {150,{"inputs": [- 393,+ 396,"[UpdateOneNavigationMenuItemInput!]!"]}@@ -7723,7 +7771,7 @@ export default {150,{"input": [- 393,+ 396,"UpdateOneNavigationMenuItemInput!"]}@@ -7758,7 +7806,7 @@ export default {"Float!"],"fileFolder": [- 282,+ 286,"FileFolder!"],"fieldMetadataId": [@@ -7797,7 +7845,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"]}@@ -7806,7 +7854,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"]}@@ -7815,7 +7863,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"]}@@ -7824,7 +7872,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"]}@@ -7833,7 +7881,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"]}@@ -7842,7 +7890,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"],"fieldMetadataId": [@@ -7855,7 +7903,7 @@ export default {147,{"file": [- 395,+ 398,"Upload!"],"fieldMetadataUniversalIdentifier": [@@ -7864,11 +7912,29 @@ export default {]}],+ "upsertUsageLimit": [+ 171,+ {+ "input": [+ 399,+ "UpsertUsageLimitInput!"+ ]+ }+ ],+ "deleteUsageLimit": [+ 8,+ {+ "usageLimitId": [+ 3,+ "UUID!"+ ]+ }+ ],"createViewFilterGroup": [53,{"input": [- 396,+ 400,"CreateViewFilterGroupInput!"]}@@ -7881,7 +7947,7 @@ export default {"String!"],"input": [- 397,+ 401,"UpdateViewFilterGroupInput!"]}@@ -7908,7 +7974,7 @@ export default {55,{"input": [- 398,+ 402,"CreateViewFilterInput!"]}@@ -7917,7 +7983,7 @@ export default {55,{"input": [- 399,+ 403,"UpdateViewFilterInput!"]}@@ -7926,7 +7992,7 @@ export default {55,{"input": [- 401,+ 405,"DeleteViewFilterInput!"]}@@ -7935,7 +8001,7 @@ export default {55,{"input": [- 402,+ 406,"DestroyViewFilterInput!"]}@@ -7944,7 +8010,7 @@ export default {61,{"input": [- 403,+ 407,"CreateViewInput!"]}@@ -7957,7 +8023,7 @@ export default {"String!"],"input": [- 404,+ 408,"UpdateViewInput!"]}@@ -7984,7 +8050,7 @@ export default {61,{"input": [- 405,+ 409,"UpsertViewWidgetInput!"]}@@ -7993,7 +8059,7 @@ export default {58,{"input": [- 411,+ 415,"CreateViewSortInput!"]}@@ -8002,7 +8068,7 @@ export default {58,{"input": [- 412,+ 416,"UpdateViewSortInput!"]}@@ -8011,7 +8077,7 @@ export default {8,{"input": [- 414,+ 418,"DeleteViewSortInput!"]}@@ -8020,7 +8086,7 @@ export default {8,{"input": [- 415,+ 419,"DestroyViewSortInput!"]}@@ -8029,7 +8095,7 @@ export default {51,{"input": [- 416,+ 420,"UpdateViewFieldInput!"]}@@ -8038,7 +8104,7 @@ export default {51,{"input": [- 418,+ 422,"CreateViewFieldInput!"]}@@ -8047,7 +8113,7 @@ export default {51,{"inputs": [- 418,+ 422,"[CreateViewFieldInput!]!"]}@@ -8056,7 +8122,7 @@ export default {51,{"input": [- 419,+ 423,"DeleteViewFieldInput!"]}@@ -8065,7 +8131,7 @@ export default {51,{"input": [- 420,+ 424,"DestroyViewFieldInput!"]}@@ -8074,7 +8140,7 @@ export default {60,{"input": [- 421,+ 425,"UpdateViewFieldGroupInput!"]}@@ -8083,7 +8149,7 @@ export default {60,{"input": [- 423,+ 427,"CreateViewFieldGroupInput!"]}@@ -8092,7 +8158,7 @@ export default {60,{"inputs": [- 423,+ 427,"[CreateViewFieldGroupInput!]!"]}@@ -8101,7 +8167,7 @@ export default {60,{"input": [- 424,+ 428,"DeleteViewFieldGroupInput!"]}@@ -8110,7 +8176,7 @@ export default {60,{"input": [- 425,+ 429,"DestroyViewFieldGroupInput!"]}@@ -8119,7 +8185,7 @@ export default {61,{"input": [- 426,+ 430,"UpsertFieldsWidgetInput!"]}@@ -8128,7 +8194,7 @@ export default {2,{"input": [- 429,+ 433,"CreateApiKeyInput!"]}@@ -8137,7 +8203,7 @@ export default {2,{"input": [- 430,+ 434,"UpdateApiKeyInput!"]}@@ -8146,7 +8212,7 @@ export default {2,{"input": [- 431,+ 435,"RevokeApiKeyInput!"]}@@ -8339,7 +8405,7 @@ export default {146,{"input": [- 432,+ 436,"CreateApprovedAccessDomainInput!"]}@@ -8348,7 +8414,7 @@ export default {8,{"input": [- 433,+ 437,"DeleteApprovedAccessDomainInput!"]}@@ -8357,7 +8423,7 @@ export default {146,{"input": [- 434,+ 438,"ValidateApprovedAccessDomainInput!"]}@@ -8366,7 +8432,7 @@ export default {120,{"input": [- 435,+ 439,"CreatePageLayoutTabInput!"]}@@ -8379,7 +8445,7 @@ export default {"String!"],"input": [- 436,+ 440,"UpdatePageLayoutTabInput!"]}@@ -8397,7 +8463,7 @@ export default {121,{"input": [- 437,+ 441,"CreatePageLayoutInput!"]}@@ -8410,7 +8476,7 @@ export default {"String!"],"input": [- 438,+ 442,"UpdatePageLayoutInput!"]}@@ -8432,7 +8498,7 @@ export default {"String!"],"input": [- 439,+ 443,"UpdatePageLayoutWithTabsInput!"]}@@ -8468,7 +8534,7 @@ export default {78,{"input": [- 443,+ 447,"CreatePageLayoutWidgetInput!"]}@@ -8481,7 +8547,7 @@ export default {"String!"],"input": [- 444,+ 448,"UpdatePageLayoutWidgetInput!"]}@@ -8499,7 +8565,7 @@ export default {10,{"input": [- 445,+ 449,"CreateAgentInput!"]}@@ -8508,7 +8574,7 @@ export default {10,{"input": [- 446,+ 450,"UpdateAgentInput!"]}@@ -8517,7 +8583,7 @@ export default {10,{"input": [- 373,+ 377,"AgentIdInput!"]}@@ -8526,7 +8592,7 @@ export default {23,{"input": [- 447,+ 451,"CreateOneObjectInput!"]}@@ -8535,7 +8601,7 @@ export default {23,{"input": [- 449,+ 453,"DeleteOneObjectInput!"]}@@ -8544,25 +8610,25 @@ export default {23,{"input": [- 450,+ 454,"UpdateOneObjectInput!"]}],"createOneIndex": [- 232,+ 236,{"input": [- 453,+ 457,"CreateOneIndexInput!"]}],"deleteOneIndex": [- 232,+ 236,{"input": [- 456,+ 460,"DeleteOneIndexInput!"]}@@ -8571,7 +8637,7 @@ export default {21,{"input": [- 375,+ 379,"LogicFunctionIdInput!"]}@@ -8580,7 +8646,7 @@ export default {21,{"input": [- 457,+ 461,"CreateLogicFunctionFromSourceInput!"]}@@ -8589,7 +8655,7 @@ export default {142,{"input": [- 458,+ 462,"ExecuteOneLogicFunctionInput!"]}@@ -8598,7 +8664,7 @@ export default {8,{"input": [- 459,+ 463,"UpdateLogicFunctionFromSourceInput!"]}@@ -8607,7 +8673,7 @@ export default {14,{"input": [- 461,+ 465,"CreateCommandMenuItemInput!"]}@@ -8616,7 +8682,7 @@ export default {14,{"input": [- 462,+ 466,"UpdateCommandMenuItemInput!"]}@@ -8643,7 +8709,7 @@ export default {13,{"input": [- 463,+ 467,"CreateFrontComponentInput!"]}@@ -8652,7 +8718,7 @@ export default {13,{"input": [- 464,+ 468,"UpdateFrontComponentInput!"]}@@ -8670,7 +8736,7 @@ export default {67,{"data": [- 466,+ 470,"ActivateWorkspaceInput!"]}@@ -8679,7 +8745,7 @@ export default {67,{"data": [- 467,+ 471,"UpdateWorkspaceInput!"]}@@ -8688,10 +8754,10 @@ export default {67],"checkCustomDomainValidRecords": [- 244+ 248],"enrichWorkspaceCompany": [- 221+ 225],"upgradeApplication": [8,@@ -8707,10 +8773,10 @@ export default {}],"createApplicationRegistration": [- 201,+ 205,{"input": [- 468,+ 472,"CreateApplicationRegistrationInput!"]}@@ -8719,7 +8785,7 @@ export default {73,{"input": [- 469,+ 473,"UpdateApplicationRegistrationInput!"]}@@ -8734,7 +8800,7 @@ export default {}],"rotateApplicationRegistrationClientSecret": [- 203,+ 207,{"id": [1,@@ -8743,19 +8809,19 @@ export default {}],"createApplicationRegistrationVariable": [- 174,+ 178,{"input": [- 471,+ 475,"CreateApplicationRegistrationVariableInput!"]}],"updateApplicationRegistrationVariable": [- 174,+ 178,{"input": [- 472,+ 476,"UpdateApplicationRegistrationVariableInput!"]}@@ -8773,7 +8839,7 @@ export default {73,{"file": [- 395,+ 398,"Upload!"],"universalIdentifier": [@@ -8835,7 +8901,7 @@ export default {"UUID!"],"input": [- 474,+ 478,"UpdateApplicationInput!"]}@@ -8853,28 +8919,28 @@ export default {8],"createOneField": [- 224,+ 228,{"input": [- 475,+ 479,"CreateOneFieldMetadataInput!"]}],"updateOneField": [- 224,+ 228,{"input": [- 477,+ 481,"UpdateOneFieldMetadataInput!"]}],"deleteOneField": [- 224,+ 228,{"input": [- 479,+ 483,"DeleteOneFieldInput!"]}@@ -8883,7 +8949,7 @@ export default {57,{"input": [- 480,+ 484,"CreateViewGroupInput!"]}@@ -8892,7 +8958,7 @@ export default {57,{"inputs": [- 480,+ 484,"[CreateViewGroupInput!]!"]}@@ -8901,7 +8967,7 @@ export default {57,{"input": [- 481,+ 485,"UpdateViewGroupInput!"]}@@ -8910,7 +8976,7 @@ export default {57,{"inputs": [- 481,+ 485,"[UpdateViewGroupInput!]!"]}@@ -8919,7 +8985,7 @@ export default {57,{"input": [- 483,+ 487,"DeleteViewGroupInput!"]}@@ -8928,7 +8994,7 @@ export default {57,{"input": [- 484,+ 488,"DestroyViewGroupInput!"]}@@ -8950,7 +9016,7 @@ export default {46,{"createRoleInput": [- 485,+ 489,"CreateRoleInput!"]}@@ -8959,7 +9025,7 @@ export default {46,{"updateRoleInput": [- 486,+ 490,"UpdateRoleInput!"]}@@ -8977,7 +9043,7 @@ export default {43,{"upsertObjectPermissionsInput": [- 488,+ 492,"UpsertObjectPermissionsInput!"]}@@ -8986,7 +9052,7 @@ export default {44,{"upsertPermissionFlagsInput": [- 490,+ 494,"UpsertPermissionFlagsInput!"]}@@ -8995,16 +9061,16 @@ export default {38,{"upsertFieldPermissionsInput": [- 491,+ 495,"UpsertFieldPermissionsInput!"]}],"upsertRowLevelPermissionPredicates": [- 245,+ 249,{"input": [- 493,+ 497,"UpsertRowLevelPermissionPredicatesInput!"]}@@ -9032,46 +9098,46 @@ export default {}],"sendEmailViaEmailingDomain": [- 301,+ 305,{"input": [- 496,+ 500,"SendEmailViaDomainInput!"]}],"sendMessageCampaign": [- 303,+ 307,{"input": [- 497,+ 501,"SendMessageCampaignInput!"]}],"sendMessageCampaignTest": [- 301,+ 305,{"input": [- 498,+ 502,"SendMessageCampaignTestInput!"]}],"createUnsubscribeTopic": [- 308,+ 312,{"input": [- 499,+ 503,"CreateUnsubscribeTopicInput!"]}],"updateUnsubscribeTopic": [- 308,+ 312,{"input": [- 500,+ 504,"UpdateUnsubscribeTopicInput!"]}@@ -9086,34 +9152,34 @@ export default {}],"updateMessageChannel": [- 291,+ 295,{"input": [- 501,+ 505,"UpdateMessageChannelInput!"]}],"createEmailGroupChannel": [- 299,+ 303,{"input": [- 503,+ 507,"CreateEmailGroupChannelInput!"]}],"updateEmailGroupChannel": [- 291,+ 295,{"input": [- 504,+ 508,"UpdateEmailGroupChannelInput!"]}],"deleteEmailGroupChannel": [- 291,+ 295,{"id": [3,@@ -9122,10 +9188,10 @@ export default {}],"createEmailingDomain": [- 289,+ 293,{"input": [- 505,+ 509,"CreateEmailingDomainInput!"]}@@ -9140,7 +9206,7 @@ export default {}],"verifyEmailingDomain": [- 289,+ 293,{"id": [1,@@ -9149,7 +9215,7 @@ export default {}],"deleteConnectedAccount": [- 250,+ 254,{"id": [3,@@ -9158,34 +9224,34 @@ export default {}],"runAgent": [- 320,+ 324,{"input": [- 506,+ 510,"RunAgentInput!"]}],"createWebhook": [- 317,+ 321,{"input": [- 509,+ 513,"CreateWebhookInput!"]}],"updateWebhook": [- 317,+ 321,{"input": [- 510,+ 514,"UpdateWebhookInput!"]}],"deleteWebhook": [- 317,+ 321,{"id": [3,@@ -9194,37 +9260,37 @@ export default {}],"updateMessageFolder": [- 359,+ 363,{"input": [- 512,+ 516,"UpdateMessageFolderInput!"]}],"updateMessageFolders": [- 359,+ 363,{"input": [- 514,+ 518,"UpdateMessageFoldersInput!"]}],"updateCalendarChannel": [- 354,+ 358,{"input": [- 515,+ 519,"UpdateCalendarChannelInput!"]}],"setAppKeyValue": [- 352,+ 356,{"input": [- 517,+ 521,"SetAppKeyValueInput!"]}@@ -9237,33 +9303,33 @@ export default {"String!"],"scope": [- 353+ 357]}],"enqueueJob": [- 350,+ 354,{"input": [- 518,+ 522,"EnqueueJobInput!"]}],"enqueueJobs": [- 351,+ 355,{"input": [- 519,+ 523,"EnqueueJobsInput!"]}],"createChatThread": [- 338+ 342],"sendChatMessage": [- 343,+ 347,{"threadId": [3,@@ -9284,13 +9350,13 @@ export default {1],"fileAttachments": [- 520,+ 524,"[FileAttachmentInput!]"]}],"retryChatMessage": [- 343,+ 347,{"threadId": [3,@@ -9302,7 +9368,7 @@ export default {}],"answerAgentChatQuestion": [- 343,+ 347,{"threadId": [3,@@ -9313,14 +9379,14 @@ export default {"UUID!"],"answers": [- 521,+ 525,"[AgentChatQuestionAnswerInput!]!"],"modelId": [1],"fileAttachments": [- 520,+ 524,"[FileAttachmentInput!]"]}@@ -9335,7 +9401,7 @@ export default {}],"renameChatThread": [- 338,+ 342,{"id": [3,@@ -9348,7 +9414,7 @@ export default {}],"archiveChatThread": [- 338,+ 342,{"id": [3,@@ -9357,7 +9423,7 @@ export default {}],"unarchiveChatThread": [- 338,+ 342,{"id": [3,@@ -9384,7 +9450,7 @@ export default {}],"startWorkspaceSetupChat": [- 345,+ 349,{"companyContext": [9@@ -9395,25 +9461,25 @@ export default {}],"createSkill": [- 336,+ 340,{"input": [- 522,+ 526,"CreateSkillInput!"]}],"updateSkill": [- 336,+ 340,{"input": [- 523,+ 527,"UpdateSkillInput!"]}],"deleteSkill": [- 336,+ 340,{"id": [3,@@ -9422,7 +9488,7 @@ export default {}],"activateSkill": [- 336,+ 340,{"id": [3,@@ -9431,7 +9497,7 @@ export default {}],"deactivateSkill": [- 336,+ 340,{"id": [3,@@ -9440,7 +9506,7 @@ export default {}],"evaluateAgentTurn": [- 347,+ 351,{"turnId": [3,@@ -9449,7 +9515,7 @@ export default {}],"runEvaluationInput": [- 348,+ 352,{"agentId": [3,@@ -9462,16 +9528,16 @@ export default {}],"updateTimelineActivityType": [- 365,+ 369,{"input": [- 524,+ 528,"UpdateTimelineActivityTypeInput!"]}],"resetTimelineActivityType": [- 365,+ 369,{"id": [3,@@ -9480,16 +9546,16 @@ export default {}],"getAuthorizationUrlForSSO": [- 258,+ 262,{"input": [- 525,+ 529,"GetAuthorizationUrlForSSOInput!"]}],"getLoginTokenFromCredentials": [- 269,+ 273,{"email": [1,@@ -9515,7 +9581,7 @@ export default {}],"signIn": [- 256,+ 260,{"email": [1,@@ -9537,7 +9603,7 @@ export default {}],"verifyEmailAndGetLoginToken": [- 264,+ 268,{"emailVerificationToken": [1,@@ -9557,7 +9623,7 @@ export default {}],"verifyEmailAndGetWorkspaceAgnosticToken": [- 256,+ 260,{"emailVerificationToken": [1,@@ -9573,7 +9639,7 @@ export default {}],"getAuthTokensFromOTP": [- 268,+ 272,{"otp": [1,@@ -9593,7 +9659,7 @@ export default {}],"signUp": [- 256,+ 260,{"email": [1,@@ -9615,7 +9681,7 @@ export default {}],"signUpInWorkspace": [- 261,+ 265,{"email": [1,@@ -9646,10 +9712,10 @@ export default {}],"signUpInNewWorkspace": [- 261,+ 265,{"input": [- 526+ 530]}],@@ -9661,16 +9727,16 @@ export default {"String!"],"file": [- 395,+ 398,"Upload!"]}],"generateTransientToken": [- 262+ 266],"getAuthTokensFromLoginToken": [- 268,+ 272,{"loginToken": [1,@@ -9683,7 +9749,7 @@ export default {}],"getAuthTokensFromSSOExchangeToken": [- 268,+ 272,{"ssoExchangeToken": [1,@@ -9692,7 +9758,7 @@ export default {}],"authorizeApp": [- 254,+ 258,{"clientId": [1,@@ -9717,7 +9783,7 @@ export default {}],"renewToken": [- 268,+ 272,{"appToken": [1,@@ -9734,7 +9800,7 @@ export default {}],"generateApiKeyToken": [- 267,+ 271,{"apiKeyId": [3,@@ -9750,7 +9816,7 @@ export default {11],"emailPasswordResetLink": [- 257,+ 261,{"email": [1,@@ -9765,7 +9831,7 @@ export default {}],"updatePasswordViaResetToken": [- 259,+ 263,{"passwordResetToken": [1,@@ -9778,7 +9844,7 @@ export default {}],"initiateOTPProvisioning": [- 252,+ 256,{"loginToken": [1,@@ -9791,10 +9857,10 @@ export default {}],"initiateOTPProvisioningForAuthenticatedUser": [- 252+ 256],"deleteTwoFactorAuthenticationMethod": [- 251,+ 255,{"twoFactorAuthenticationMethodId": [3,@@ -9803,7 +9869,7 @@ export default {}],"verifyTwoFactorAuthenticationMethodForAuthenticatedUser": [- 253,+ 257,{"otp": [1,@@ -9827,7 +9893,7 @@ export default {8,{"input": [- 527,+ 531,"UpdateWorkspaceMemberSettingsInput!"]}@@ -9845,7 +9911,7 @@ export default {}],"resendEmailVerificationToken": [- 206,+ 210,{"email": [1,@@ -9858,43 +9924,43 @@ export default {}],"createOIDCIdentityProvider": [- 211,+ 215,{"input": [- 528,+ 532,"SetupOIDCSsoInput!"]}],"createSAMLIdentityProvider": [- 211,+ 215,{"input": [- 529,+ 533,"SetupSAMLSsoInput!"]}],"deleteSSOIdentityProvider": [- 207,+ 211,{"input": [- 530,+ 534,"DeleteSsoInput!"]}],"editSSOIdentityProvider": [- 208,+ 212,{"input": [- 531,+ 535,"EditSsoInput!"]}],"createObjectEvent": [- 332,+ 336,{"event": [1,@@ -9914,10 +9980,10 @@ export default {}],"trackAnalytics": [- 332,+ 336,{"type": [- 532,+ 536,"AnalyticsType!"],"name": [@@ -9932,7 +9998,7 @@ export default {}],"duplicateDashboard": [- 330,+ 334,{"id": [3,@@ -9941,7 +10007,7 @@ export default {}],"impersonate": [- 272,+ 276,{"userId": [3,@@ -9954,28 +10020,28 @@ export default {}],"stopImpersonation": [- 273+ 277],"createCalendarEvent": [- 322,+ 326,{"input": [- 533,+ 537,"CreateCalendarEventInput!"]}],"sendEmail": [- 331,+ 335,{"input": [- 534,+ 538,"SendEmailInput!"]}],"startChannelSync": [- 321,+ 325,{"connectedAccountId": [3,@@ -9984,14 +10050,14 @@ export default {}],"saveImapSmtpCaldavAccount": [- 316,+ 320,{"handle": [1,"String!"],"connectionParameters": [- 536,+ 540,"EmailAccountConnectionParameters!"],"id": [@@ -10000,16 +10066,16 @@ export default {}],"updateLabPublicFeatureFlag": [- 171,+ 175,{"input": [- 538,+ 542,"UpdateLabPublicFeatureFlagInput!"]}],"createPublicDomain": [- 287,+ 291,{"domain": [1,@@ -10031,7 +10097,7 @@ export default {}],"checkPublicDomainValidRecords": [- 244,+ 248,{"domain": [1,@@ -10040,7 +10106,7 @@ export default {}],"createDevelopmentApplication": [- 285,+ 289,{"universalIdentifier": [1,@@ -10053,7 +10119,7 @@ export default {}],"syncApplication": [- 286,+ 290,{"manifest": [9,@@ -10065,10 +10131,10 @@ export default {}],"uploadApplicationFile": [- 278,+ 282,{"file": [- 395,+ 398,"Upload!"],"applicationUniversalIdentifier": [@@ -10076,7 +10142,7 @@ export default {"String!"],"fileFolder": [- 282,+ 286,"FileFolder!"],"filePath": [@@ -10086,20 +10152,20 @@ export default {}],"createApplicationFileUploads": [- 284,+ 288,{"applicationUniversalIdentifier": [1,"String!"],"files": [- 539,+ 543,"[ApplicationFileUploadRequestInput!]!"]}],"completeApplicationFileUploads": [- 280,+ 284,{"applicationUniversalIdentifier": [1,@@ -10216,7 +10282,7 @@ export default {3],"update": [- 394+ 397],"__typename": [1@@ -10249,6 +10315,35 @@ export default {]},"Upload": {},+ "UpsertUsageLimitInput": {+ "resourceType": [+ 172+ ],+ "operationType": [+ 173+ ],+ "spenderType": [+ 1+ ],+ "spenderId": [+ 1+ ],+ "limitKind": [+ 1+ ],+ "windowSeconds": [+ 26+ ],+ "limitValue": [+ 174+ ],+ "burstValue": [+ 174+ ],+ "__typename": [+ 1+ ]+ },"CreateViewFilterGroupInput": {"id": [3@@ -10326,7 +10421,7 @@ export default {3],"update": [- 400+ 404],"__typename": [1@@ -10497,19 +10592,19 @@ export default {3],"view": [- 406+ 410],"viewFields": [- 407+ 411],"viewFilters": [- 408+ 412],"viewFilterGroups": [- 409+ 413],"viewSorts": [- 410+ 414],"__typename": [1@@ -10658,7 +10753,7 @@ export default {3],"update": [- 413+ 417],"__typename": [1@@ -10696,7 +10791,7 @@ export default {3],"update": [- 417+ 421],"__typename": [1@@ -10772,7 +10867,7 @@ export default {3],"update": [- 422+ 426],"__typename": [1@@ -10836,10 +10931,10 @@ export default {3],"groups": [- 427+ 431],"fields": [- 428+ 432],"__typename": [1@@ -10859,7 +10954,7 @@ export default {8],"fields": [- 428+ 432],"__typename": [1@@ -11027,7 +11122,7 @@ export default {3],"tabs": [- 440+ 444],"__typename": [1@@ -11050,7 +11145,7 @@ export default {82],"widgets": [- 441+ 445],"__typename": [1@@ -11073,7 +11168,7 @@ export default {3],"gridPosition": [- 442+ 446],"position": [9@@ -11122,7 +11217,7 @@ export default {3],"gridPosition": [- 442+ 446],"position": [9@@ -11148,7 +11243,7 @@ export default {3],"gridPosition": [- 442+ 446],"position": [9@@ -11241,7 +11336,7 @@ export default {},"CreateOneObjectInput": {"object": [- 448+ 452],"__typename": [1@@ -11301,7 +11396,7 @@ export default {},"UpdateOneObjectInput": {"update": [- 451+ 455],"id": [3@@ -11354,7 +11449,7 @@ export default {24],"translations": [- 452+ 456],"__typename": [1@@ -11376,7 +11471,7 @@ export default {},"CreateOneIndexInput": {"index": [- 454+ 458],"__typename": [1@@ -11387,10 +11482,10 @@ export default {3],"fields": [- 455+ 459],"indexType": [- 233+ 237],"__typename": [1@@ -11472,7 +11567,7 @@ export default {3],"update": [- 460+ 464],"__typename": [1@@ -11632,7 +11727,7 @@ export default {3],"update": [- 465+ 469],"__typename": [1@@ -11759,7 +11854,7 @@ export default {1],"update": [- 470+ 474],"__typename": [1@@ -11813,7 +11908,7 @@ export default {1],"update": [- 473+ 477],"__typename": [1@@ -11843,7 +11938,7 @@ export default {},"CreateOneFieldMetadataInput": {"field": [- 476+ 480],"__typename": [1@@ -11851,7 +11946,7 @@ export default {},"CreateFieldInput": {"type": [- 225+ 229],"name": [1@@ -11916,7 +12011,7 @@ export default {3],"update": [- 478+ 482],"__typename": [1@@ -11975,7 +12070,7 @@ export default {9],"translations": [- 452+ 456],"__typename": [1@@ -12014,7 +12109,7 @@ export default {3],"update": [- 482+ 486],"__typename": [1@@ -12099,7 +12194,7 @@ export default {},"UpdateRoleInput": {"update": [- 487+ 491],"id": [3@@ -12154,7 +12249,7 @@ export default {3],"objectPermissions": [- 489+ 493],"__typename": [1@@ -12196,7 +12291,7 @@ export default {3],"fieldPermissions": [- 492+ 496],"__typename": [1@@ -12227,10 +12322,10 @@ export default {3],"predicates": [- 494+ 498],"predicateGroups": [- 495+ 499],"__typename": [1@@ -12356,7 +12451,7 @@ export default {1],"visibility": [- 309+ 313],"__typename": [1@@ -12373,7 +12468,7 @@ export default {1],"visibility": [- 309+ 313],"__typename": [1@@ -12384,7 +12479,7 @@ export default {3],"update": [- 502+ 506],"__typename": [1@@ -12392,16 +12487,16 @@ export default {},"UpdateMessageChannelInputUpdates": {"visibility": [- 292+ 296],"isContactAutoCreationEnabled": [8],"contactAutoCreationPolicy": [- 294+ 298],"messageFolderImportPolicy": [- 295+ 299],"isSyncEnabled": [8@@ -12457,7 +12552,7 @@ export default {3],"messages": [- 507+ 511],"__typename": [1@@ -12465,7 +12560,7 @@ export default {},"RunAgentMessageInput": {"role": [- 508+ 512],"content": [1@@ -12500,7 +12595,7 @@ export default {3],"update": [- 511+ 515],"__typename": [1@@ -12528,7 +12623,7 @@ export default {3],"update": [- 513+ 517],"__typename": [1@@ -12547,7 +12642,7 @@ export default {3],"update": [- 513+ 517],"__typename": [1@@ -12558,7 +12653,7 @@ export default {3],"update": [- 516+ 520],"__typename": [1@@ -12566,13 +12661,13 @@ export default {},"UpdateCalendarChannelInputUpdates": {"visibility": [- 357+ 361],"isContactAutoCreationEnabled": [8],"contactAutoCreationPolicy": [- 358+ 362],"isSyncEnabled": [8@@ -12589,7 +12684,7 @@ export default {9],"scope": [- 353+ 357],"__typename": [1@@ -12717,7 +12812,7 @@ export default {8],"translations": [- 452+ 456],"__typename": [1@@ -12809,7 +12904,7 @@ export default {3],"status": [- 180+ 184],"__typename": [1@@ -12883,7 +12978,7 @@ export default {1],"files": [- 535+ 539],"__typename": [1@@ -12905,13 +13000,13 @@ export default {1],"IMAP": [- 537+ 541],"SMTP": [- 537+ 541],"CALDAV": [- 537+ 541],"__typename": [1@@ -12931,7 +13026,7 @@ export default {1],"connectionSecurity": [- 248+ 252],"__typename": [1@@ -12950,7 +13045,7 @@ export default {},"ApplicationFileUploadRequestInput": {"fileFolder": [- 282+ 286],"filePath": [1@@ -12973,16 +13068,16 @@ export default {}],"logicFunctionLogs": [- 246,+ 250,{"input": [- 541,+ 545,"LogicFunctionLogsInput!"]}],"onAgentChatEvent": [- 344,+ 348,{"threadId": [3,@@ -12991,10 +13086,10 @@ export default {}],"eventLogsLive": [- 333,+ 337,{"table": [- 381,+ 385,"EventLogTable!"]}diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.tsindex ffc334bedff..97794766efe 100644--- a/packages/twenty-front/src/generated-metadata/graphql.ts+++ b/packages/twenty-front/src/generated-metadata/graphql.ts@@ -13,6 +13,7 @@ export type Scalars = {Boolean: { input: boolean; output: boolean; }Int: { input: number; output: number; }Float: { input: number; output: number; }+ BigInt: { input: any; output: any; }ConnectionCursor: { input: any; output: any; }DateTime: { input: string; output: string; }JSON: { input: any; output: any; }@@ -2775,6 +2776,7 @@ export type Mutation = {deleteSkill: Skill;deleteTwoFactorAuthenticationMethod: DeleteTwoFactorAuthenticationMethod;deleteUnsubscribeTopic: Scalars['Boolean']['output'];+ deleteUsageLimit: Scalars['Boolean']['output'];deleteUser: User;deleteUserFromWorkspace: UserWorkspace;deleteView: Scalars['Boolean']['output'];@@ -2930,6 +2932,7 @@ export type Mutation = {upsertObjectPermissions: Array<ObjectPermission>;upsertPermissionFlags: Array<RolePermissionFlag>;upsertRowLevelPermissionPredicates: UpsertRowLevelPermissionPredicatesResult;+ upsertUsageLimit: UsageLimit;upsertViewWidget: View;validateApprovedAccessDomain: ApprovedAccessDomain;verifyEmailAndGetLoginToken: VerifyEmailAndGetLoginToken;@@ -3370,6 +3373,11 @@ export type MutationDeleteUnsubscribeTopicArgs = {};+export type MutationDeleteUsageLimitArgs = {+ usageLimitId: Scalars['UUID']['input'];+};++export type MutationDeleteUserFromWorkspaceArgs = {workspaceMemberIdToDelete: Scalars['String']['input'];};@@ -4135,6 +4143,11 @@ export type MutationUpsertRowLevelPermissionPredicatesArgs = {};+export type MutationUpsertUsageLimitArgs = {+ input: UpsertUsageLimitInput;+};++export type MutationUpsertViewWidgetArgs = {input: UpsertViewWidgetInput;};@@ -4790,6 +4803,7 @@ export type Query = {skills: Array<Skill>;timelineActivityTypes: Array<TimelineActivityType>;unsubscribeTopics: Array<UnsubscribeTopic>;+ usageLimits: Array<UsageLimit>;validatePasswordResetToken: ValidatePasswordResetToken;webhook?: Maybe<Webhook>;webhooks: Array<Webhook>;@@ -6288,6 +6302,17 @@ export type UpsertRowLevelPermissionPredicatesResult = {predicates: Array<RowLevelPermissionPredicate>;};+export type UpsertUsageLimitInput = {+ burstValue?: InputMaybe<Scalars['BigInt']['input']>;+ limitKind: Scalars['String']['input'];+ limitValue: Scalars['BigInt']['input'];+ operationType: UsageOperationType;+ resourceType: UsageResourceType;+ spenderId?: InputMaybe<Scalars['String']['input']>;+ spenderType: Scalars['String']['input'];+ windowSeconds?: Scalars['Int']['input'];+};+export type UpsertViewWidgetInput = {/** View-level settings (layout type, group by, kanban and calendar settings) to apply to the widget view. */view?: InputMaybe<UpsertViewWidgetViewSettingsInput>;@@ -6378,9 +6403,26 @@ export type UsageBreakdownItem = {label?: Maybe<Scalars['String']['output']>;};+export type UsageLimit = {+ __typename?: 'UsageLimit';+ burstValue?: Maybe<Scalars['BigInt']['output']>;+ createdAt: Scalars['DateTime']['output'];+ id: Scalars['UUID']['output'];+ limitKind: Scalars['String']['output'];+ limitValue: Scalars['BigInt']['output'];+ limitValueType: Scalars['String']['output'];+ operationType: UsageOperationType;+ resourceType: UsageResourceType;+ spenderId: Scalars['String']['output'];+ spenderType: Scalars['String']['output'];+ updatedAt: Scalars['DateTime']['output'];+ windowSeconds: Scalars['Int']['output'];+};+export enum UsageOperationType {AI_CHAT_TOKEN = 'AI_CHAT_TOKEN',AI_WORKFLOW_TOKEN = 'AI_WORKFLOW_TOKEN',+ API_REQUEST = 'API_REQUEST',CALL_RECORDING = 'CALL_RECORDING',CODE_EXECUTION = 'CODE_EXECUTION',EMAIL_SEND = 'EMAIL_SEND',@@ -6388,6 +6430,16 @@ export enum UsageOperationType {WORKFLOW_EXECUTION = 'WORKFLOW_EXECUTION'}+export enum UsageResourceType {+ AI = 'AI',+ API = 'API',+ APP = 'APP',+ EMAIL = 'EMAIL',+ LOGIC_FUNCTION = 'LOGIC_FUNCTION',+ STORAGE = 'STORAGE',+ WORKFLOW = 'WORKFLOW'+}+export type UsageTimeSeries = {__typename?: 'UsageTimeSeries';creditsUsed: Scalars['Float']['output'];diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-36/2-36-instance-command-fast-1787821567133-add-usage-limit.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-36/2-36-instance-command-fast-1787821567133-add-usage-limit.tsnew file mode 100644index 00000000000..a3f5d438ef0--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-36/2-36-instance-command-fast-1787821567133-add-usage-limit.ts@@ -0,0 +1,17 @@+import { QueryRunner } from 'typeorm';++import { RegisteredInstanceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-instance-command.decorator';+import { FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/fast-instance-command.interface';++@RegisteredInstanceCommand('2.36.0', 1787821567133)+export class AddUsageLimitFastInstanceCommand implements FastInstanceCommand {+ public async up(queryRunner: QueryRunner): Promise<void> {+ await queryRunner.query('CREATE TABLE "core"."usageLimit" ("workspaceId" uuid NOT NULL, "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "resourceType" character varying NOT NULL, "operationType" character varying NOT NULL, "spenderType" character varying NOT NULL, "spenderId" character varying NOT NULL DEFAULT \'\', "limitKind" character varying NOT NULL, "windowSeconds" integer NOT NULL DEFAULT \'0\', "limitValueType" character varying NOT NULL DEFAULT \'absolute\', "limitValue" bigint NOT NULL, "burstValue" bigint, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), CONSTRAINT "UQ_USAGE_LIMIT_SCOPE" UNIQUE ("workspaceId", "resourceType", "operationType", "spenderType", "spenderId", "limitKind", "windowSeconds"), CONSTRAINT "PK_aa789af8757d2ef28a0416df290" PRIMARY KEY ("id"))');+ await queryRunner.query('ALTER TABLE "core"."usageLimit" ADD CONSTRAINT "FK_262e7eabfa66b9724f7bf45628e" FOREIGN KEY ("workspaceId") REFERENCES "core"."workspace"("id") ON DELETE CASCADE ON UPDATE NO ACTION');+ }++ public async down(queryRunner: QueryRunner): Promise<void> {+ await queryRunner.query('ALTER TABLE "core"."usageLimit" DROP CONSTRAINT "FK_262e7eabfa66b9724f7bf45628e"');+ await queryRunner.query('DROP TABLE "core"."usageLimit"');+ }+}diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.tsindex 06bc883fbc5..6272a2e15bf 100644--- a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts@@ -158,6 +158,7 @@ import { EnforceTimelineActivityTypeEmitUniquenessFastInstanceCommand } from 'srimport { AddCommandMenuItemTargetObjectMetadataFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-35/2-35-instance-command-fast-1787573269955-add-command-menu-item-target-object-metadata';import { DropTimelineActivityTypeRendererFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-35/2-35-instance-command-fast-1787648000001-drop-timeline-activity-type-renderer';import { AddLabelToApplicationVariableFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-36/2-36-instance-command-fast-1787761629092-add-label-to-application-variable';+import { AddUsageLimitFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-36/2-36-instance-command-fast-1787821567133-add-usage-limit';export const INSTANCE_COMMANDS = [AddViewFieldGroupIdIndexOnViewFieldFastInstanceCommand,@@ -318,4 +319,5 @@ export const INSTANCE_COMMANDS = [AddCommandMenuItemTargetObjectMetadataFastInstanceCommand,DropTimelineActivityTypeRendererFastInstanceCommand,AddLabelToApplicationVariableFastInstanceCommand,+ AddUsageLimitFastInstanceCommand,];diff --git a/packages/twenty-server/src/engine/api/common/core-common-api.module.ts b/packages/twenty-server/src/engine/api/common/core-common-api.module.tsindex 24c4bd7d4b5..3de72860db9 100644--- a/packages/twenty-server/src/engine/api/common/core-common-api.module.ts+++ b/packages/twenty-server/src/engine/api/common/core-common-api.module.ts@@ -17,6 +17,7 @@ import { MetricsModule } from 'src/engine/core-modules/metrics/metrics.module';import { RecordPositionModule } from 'src/engine/core-modules/record-position/record-position.module';import { RecordTransformerModule } from 'src/engine/core-modules/record-transformer/record-transformer.module';import { ThrottlerModule } from 'src/engine/core-modules/throttler/throttler.module';+import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limit.module';import { WorkspaceManyOrAllFlatEntityMapsCacheModule } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.module';import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';import { RoleTargetEntity } from 'src/engine/metadata-modules/role-target/role-target.entity';@@ -39,6 +40,7 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cacheViewFilterModule,ViewFilterGroupModule,ThrottlerModule,+ UsageLimitModule,MetricsModule,RecordPositionModule,RecordTransformerModule,diff --git a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.tsindex bb6715fd392..b311119d155 100644--- a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts@@ -23,6 +23,7 @@ const USAGE_UNIT_BY_OPERATION_TYPE: Record<UsageOperationType, UsageUnit> = {[UsageOperationType.WEB_SEARCH]: UsageUnit.INVOCATION,[UsageOperationType.CALL_RECORDING]: UsageUnit.MINUTE,[UsageOperationType.EMAIL_SEND]: UsageUnit.INVOCATION,+ [UsageOperationType.API_REQUEST]: UsageUnit.REQUEST,};// `workspaceId` + `applicationId` come from the application-access token,diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-kinds.constant.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-kinds.constant.tsnew file mode 100644index 00000000000..edab95433b5--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-kinds.constant.ts@@ -0,0 +1 @@+export const LIMIT_KINDS = ['speed'] as const;diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-value-types.constant.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-value-types.constant.tsnew file mode 100644index 00000000000..ca7e83b94e9--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/limit-value-types.constant.ts@@ -0,0 +1 @@+export const LIMIT_VALUE_TYPES = ['absolute'] as const;diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/constants/operator-only-spender-types.constant.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/operator-only-spender-types.constant.tsnew file mode 100644index 00000000000..7d2f0a68621--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/operator-only-spender-types.constant.ts@@ -0,0 +1,3 @@+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';++export const OPERATOR_ONLY_SPENDER_TYPES: SpenderType[] = ['workspace'];diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/constants/spender-types.constant.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/spender-types.constant.tsnew file mode 100644index 00000000000..1153c7962eb--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/spender-types.constant.ts@@ -0,0 +1,9 @@+export const SPENDER_TYPES = [+ 'workspace',+ 'userWorkspace',+ 'apiKey',+ 'application',+ 'agent',+ 'workflow',+ 'logicFunction',+] as const;diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/constants/usage-limit-definitions.constant.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/usage-limit-definitions.constant.tsnew file mode 100644index 00000000000..f57d0473427--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/constants/usage-limit-definitions.constant.ts@@ -0,0 +1,42 @@+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type UsageLimitDefinition } from 'src/engine/core-modules/usage-limit/types/usage-limit-definition.type';+import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';+import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';++export const USAGE_LIMIT_DEFINITIONS: Record<+ UsageResourceType,+ Partial<Record<LimitKind, UsageLimitDefinition>>+> = {+ [UsageResourceType.API]: {+ speed: {+ allowedOperationTypes: [UsageOperationType.API_REQUEST],+ allowedSpenderTypes: ['workspace', 'apiKey', 'application'],+ fallbacks: [+ {+ spenderType: 'workspace',+ counterScope: 'perWorkspace',+ maxTokensConfigVariable: 'API_RATE_LIMITING_SHORT_LIMIT',+ windowMsConfigVariable: 'API_RATE_LIMITING_SHORT_TTL_IN_MS',+ },+ {+ spenderType: 'workspace',+ counterScope: 'perWorkspace',+ maxTokensConfigVariable: 'API_RATE_LIMITING_LONG_LIMIT',+ windowMsConfigVariable: 'API_RATE_LIMITING_LONG_TTL_IN_MS',+ },+ {+ spenderType: 'application',+ counterScope: 'crossWorkspace',+ maxTokensConfigVariable: 'APPLICATION_API_RATE_LIMITING_LIMIT',+ windowMsConfigVariable: 'APPLICATION_API_RATE_LIMITING_TTL_IN_MS',+ },+ ],+ },+ },+ [UsageResourceType.AI]: {},+ [UsageResourceType.WORKFLOW]: {},+ [UsageResourceType.APP]: {},+ [UsageResourceType.STORAGE]: {},+ [UsageResourceType.LOGIC_FUNCTION]: {},+ [UsageResourceType.EMAIL]: {},+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input.tsnew file mode 100644index 00000000000..a0580f42f0e--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input.ts@@ -0,0 +1,59 @@+import { Field, InputType, Int } from '@nestjs/graphql';++import { GraphQLBigInt } from 'graphql-scalars';++import {+ IsEnum,+ IsIn,+ IsInt,+ IsOptional,+ IsString,+ Min,+} from 'class-validator';++import { LIMIT_KINDS } from 'src/engine/core-modules/usage-limit/constants/limit-kinds.constant';+import { SPENDER_TYPES } from 'src/engine/core-modules/usage-limit/constants/spender-types.constant';+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';+import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';+import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';++@InputType()+export class UpsertUsageLimitInput {+ @Field(() => UsageResourceType)+ @IsEnum(UsageResourceType)+ resourceType: UsageResourceType;++ @Field(() => UsageOperationType)+ @IsEnum(UsageOperationType)+ operationType: UsageOperationType;++ @Field(() => String)+ @IsIn(SPENDER_TYPES)+ spenderType: SpenderType;++ @Field(() => String, { nullable: true })+ @IsString()+ @IsOptional()+ spenderId?: string | null;++ @Field(() => String)+ @IsIn(LIMIT_KINDS)+ limitKind: LimitKind;++ @Field(() => Int, { defaultValue: 0 })+ @IsInt()+ @Min(0)+ windowSeconds: number;++ @Field(() => GraphQLBigInt)+ @IsInt()+ @Min(1)+ limitValue: number;++ @Field(() => GraphQLBigInt, { nullable: true })+ @IsInt()+ @Min(1)+ @IsOptional()+ burstValue?: number | null;+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/exceptions/usage-limit.exception.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/exceptions/usage-limit.exception.tsnew file mode 100644index 00000000000..1edd9a7959d--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/exceptions/usage-limit.exception.ts@@ -0,0 +1,50 @@+import { type MessageDescriptor } from '@lingui/core';+import { msg } from '@lingui/core/macro';+import { assertUnreachable } from 'twenty-shared/utils';++import { CustomException } from 'src/utils/custom-exception';++import { type ExhaustedScope } from 'src/engine/core-modules/usage-limit/types/exhausted-scope.type';++export enum UsageLimitExceptionCode {+ RATE_LIMITED = 'RATE_LIMITED',+ QUOTA_EXHAUSTED = 'QUOTA_EXHAUSTED',+ LIMIT_RULE_INVALID = 'LIMIT_RULE_INVALID',+}++const getUsageLimitExceptionUserFriendlyMessage = (+ code: UsageLimitExceptionCode,+) => {+ switch (code) {+ case UsageLimitExceptionCode.RATE_LIMITED:+ return msg`Rate limit reached. Please try again later.`;+ case UsageLimitExceptionCode.QUOTA_EXHAUSTED:+ return msg`Usage quota exhausted for this period.`;+ case UsageLimitExceptionCode.LIMIT_RULE_INVALID:+ return msg`This limit cannot be saved.`;+ default:+ assertUnreachable(code);+ }+};++export class UsageLimitException extends CustomException<UsageLimitExceptionCode> {+ readonly exhaustedScope?: ExhaustedScope;++ constructor(+ message: string,+ code: UsageLimitExceptionCode,+ {+ userFriendlyMessage,+ exhaustedScope,+ }: {+ userFriendlyMessage?: MessageDescriptor;+ exhaustedScope?: ExhaustedScope;+ } = {},+ ) {+ super(message, code, {+ userFriendlyMessage:+ userFriendlyMessage ?? getUsageLimitExceptionUserFriendlyMessage(code),+ });+ this.exhaustedScope = exhaustedScope;+ }+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/filters/__tests__/usage-limit-graphql-api-exception.filter.spec.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/filters/__tests__/usage-limit-graphql-api-exception.filter.spec.tsnew file mode 100644index 00000000000..fdfd191bf1d--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/filters/__tests__/usage-limit-graphql-api-exception.filter.spec.ts@@ -0,0 +1,48 @@+import {+ type BaseGraphQLError,+ ErrorCode,+} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';+import {+ UsageLimitException,+ UsageLimitExceptionCode,+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';+import { UsageLimitGraphqlApiExceptionFilter } from 'src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter';++const catchAsGraphQLError = (exception: UsageLimitException) => {+ const filter = new UsageLimitGraphqlApiExceptionFilter();++ try {+ filter.catch(exception);+ } catch (graphqlError) {+ return graphqlError as BaseGraphQLError;+ }++ throw new Error('UsageLimitGraphqlApiExceptionFilter did not throw');+};++describe('UsageLimitGraphqlApiExceptionFilter', () => {+ it('surfaces an invalid limit rule as a user input error rather than a server error', () => {+ const graphqlError = catchAsGraphQLError(+ new UsageLimitException(+ 'API speed limits cannot target the EMAIL_SEND operation',+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ ),+ );++ expect(graphqlError.extensions.code).toBe(ErrorCode.BAD_USER_INPUT);+ expect(graphqlError.message).toBe(+ 'API speed limits cannot target the EMAIL_SEND operation',+ );+ });++ it('surfaces an exhausted quota as forbidden', () => {+ const graphqlError = catchAsGraphQLError(+ new UsageLimitException(+ 'Quota exhausted',+ UsageLimitExceptionCode.QUOTA_EXHAUSTED,+ ),+ );++ expect(graphqlError.extensions.code).toBe(ErrorCode.FORBIDDEN);+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter.tsnew file mode 100644index 00000000000..da3456d1797--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter.ts@@ -0,0 +1,27 @@+import { Catch, type ExceptionFilter } from '@nestjs/common';++import { assertUnreachable } from 'twenty-shared/utils';++import {+ ForbiddenError,+ UserInputError,+} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';+import {+ UsageLimitException,+ UsageLimitExceptionCode,+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';++@Catch(UsageLimitException)+export class UsageLimitGraphqlApiExceptionFilter implements ExceptionFilter {+ catch(exception: UsageLimitException) {+ switch (exception.code) {+ case UsageLimitExceptionCode.LIMIT_RULE_INVALID:+ case UsageLimitExceptionCode.RATE_LIMITED:+ throw new UserInputError(exception);+ case UsageLimitExceptionCode.QUOTA_EXHAUSTED:+ throw new ForbiddenError(exception);+ default:+ assertUnreachable(exception.code);+ }+ }+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit-rules-cache.service.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit-rules-cache.service.tsnew file mode 100644index 00000000000..e3101e43714--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit-rules-cache.service.ts@@ -0,0 +1,39 @@+import { Injectable } from '@nestjs/common';++import { WorkspaceCacheProvider } from 'src/engine/workspace-cache/interfaces/workspace-cache-provider.service';++import { UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';+import { fromUsageLimitEntityToFlat } from 'src/engine/core-modules/usage-limit/utils/from-usage-limit-entity-to-flat.util';+import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';+import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';+import { WorkspaceCache } from 'src/engine/workspace-cache/decorators/workspace-cache.decorator';+import { type UsageLimitRules } from 'src/engine/core-modules/usage-limit/types/usage-limit-rules.type';++@Injectable()+@WorkspaceCache('usageLimitRules', { packingPonderation: 1 })+export class UsageLimitRulesCacheService extends WorkspaceCacheProvider<UsageLimitRules> {+ constructor(+ @InjectWorkspaceScopedRepository(UsageLimitEntity)+ private readonly usageLimitRepository: WorkspaceScopedRepository<UsageLimitEntity>,+ ) {+ super();+ }++ async computeForCache(workspaceId: string): Promise<UsageLimitRules> {+ const usageLimits = await this.usageLimitRepository.find(workspaceId);++ return usageLimits.reduce<UsageLimitRules>(+ (rules, usageLimit) => {+ const flat = fromUsageLimitEntityToFlat(usageLimit);++ rules.byResourceType[flat.resourceType] = [+ ...(rules.byResourceType[flat.resourceType] ?? []),+ flat,+ ];++ return rules;+ },+ { byResourceType: {} },+ );+ }+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit.service.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit.service.tsnew file mode 100644index 00000000000..fb8ea50dfbd--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/services/usage-limit.service.ts@@ -0,0 +1,170 @@+import { Injectable } from '@nestjs/common';++import { isNonEmptyString } from '@sniptt/guards';+import { isDefined } from 'twenty-shared/utils';++import { ApiKeyEntity } from 'src/engine/core-modules/api-key/api-key.entity';+import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';+import { type UpsertUsageLimitInput } from 'src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input';+import {+ UsageLimitException,+ UsageLimitExceptionCode,+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';+import { UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';+import { validateUsageLimitAgainstDefinition } from 'src/engine/core-modules/usage-limit/utils/validate-usage-limit-against-definition.util';+import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';+import { AgentEntity } from 'src/engine/metadata-modules/ai/ai-agent/entities/agent.entity';+import { LogicFunctionEntity } from 'src/engine/metadata-modules/logic-function/logic-function.entity';+import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';+import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';++@Injectable()+export class UsageLimitService {+ constructor(+ @InjectWorkspaceScopedRepository(UsageLimitEntity)+ private readonly usageLimitRepository: WorkspaceScopedRepository<UsageLimitEntity>,+ @InjectWorkspaceScopedRepository(ApiKeyEntity)+ private readonly apiKeyRepository: WorkspaceScopedRepository<ApiKeyEntity>,+ @InjectWorkspaceScopedRepository(ApplicationEntity)+ private readonly applicationRepository: WorkspaceScopedRepository<ApplicationEntity>,+ @InjectWorkspaceScopedRepository(UserWorkspaceEntity)+ private readonly userWorkspaceRepository: WorkspaceScopedRepository<UserWorkspaceEntity>,+ @InjectWorkspaceScopedRepository(AgentEntity)+ private readonly agentRepository: WorkspaceScopedRepository<AgentEntity>,+ @InjectWorkspaceScopedRepository(LogicFunctionEntity)+ private readonly logicFunctionRepository: WorkspaceScopedRepository<LogicFunctionEntity>,+ private readonly workspaceCacheService: WorkspaceCacheService,+ ) {}++ async findAll(workspaceId: string): Promise<UsageLimitEntity[]> {+ return this.usageLimitRepository.find(workspaceId);+ }++ async upsert({+ workspaceId,+ input,+ }: {+ workspaceId: string;+ input: UpsertUsageLimitInput;+ }): Promise<UsageLimitEntity> {+ validateUsageLimitAgainstDefinition(input);++ if (isNonEmptyString(input.spenderId)) {+ await this.validateSpenderBelongsToWorkspace({+ workspaceId,+ spenderType: input.spenderType,+ spenderId: input.spenderId,+ });+ }++ const scope = {+ resourceType: input.resourceType,+ operationType: input.operationType,+ spenderType: input.spenderType,+ spenderId: input.spenderId ?? '',+ limitKind: input.limitKind,+ windowSeconds: input.windowSeconds,+ };++ await this.usageLimitRepository.upsert(+ workspaceId,+ {+ workspaceId,+ ...scope,+ limitValueType: 'absolute',+ limitValue: input.limitValue,+ burstValue: input.burstValue ?? null,+ },+ { conflictPaths: ['workspaceId', ...Object.keys(scope)] },+ );++ await this.workspaceCacheService.invalidateAndRecompute(workspaceId, [+ 'usageLimitRules',+ ]);++ return this.usageLimitRepository.findOneOrFail(workspaceId, {+ where: scope,+ });+ }++ async delete({+ workspaceId,+ usageLimitId,+ }: {+ workspaceId: string;+ usageLimitId: string;+ }): Promise<boolean> {+ const { affected } = await this.usageLimitRepository.delete(workspaceId, {+ id: usageLimitId,+ });++ if (!isDefined(affected) || affected === 0) {+ return false;+ }++ await this.workspaceCacheService.invalidateAndRecompute(workspaceId, [+ 'usageLimitRules',+ ]);++ return true;+ }++ private async validateSpenderBelongsToWorkspace({+ workspaceId,+ spenderType,+ spenderId,+ }: {+ workspaceId: string;+ spenderType: SpenderType;+ spenderId: string;+ }): Promise<void> {+ const spenderExists = await this.spenderExists({+ workspaceId,+ spenderType,+ spenderId,+ });++ if (!spenderExists) {+ throw new UsageLimitException(+ `No ${spenderType} ${spenderId} in this workspace`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }+ }++ private async spenderExists({+ workspaceId,+ spenderType,+ spenderId,+ }: {+ workspaceId: string;+ spenderType: SpenderType;+ spenderId: string;+ }): Promise<boolean> {+ switch (spenderType) {+ case 'apiKey':+ return this.apiKeyRepository.existsBy(workspaceId, { id: spenderId });+ case 'application':+ return this.applicationRepository.existsBy(workspaceId, {+ id: spenderId,+ });+ case 'userWorkspace':+ return this.userWorkspaceRepository.existsBy(workspaceId, {+ id: spenderId,+ });+ case 'agent':+ return this.agentRepository.existsBy(workspaceId, { id: spenderId });+ case 'logicFunction':+ return this.logicFunctionRepository.existsBy(workspaceId, {+ id: spenderId,+ });+ default:+ throw new UsageLimitException(+ `A ${spenderType} spender id cannot be checked against the workspace`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }+ }+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/exhausted-scope.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/exhausted-scope.type.tsnew file mode 100644index 00000000000..75202e4e03a--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/exhausted-scope.type.ts@@ -0,0 +1,14 @@+import { type UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';++export type ExhaustedScope = {+ resourceType: UsageResourceType;+ limitKind: LimitKind;+ spenderType: SpenderType;+ spenderId: string | null;+ limitValue: number;+ remaining: number;+ windowSeconds: number;+ retryAfterMs: number;+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/flat-usage-limit.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/flat-usage-limit.type.tsnew file mode 100644index 00000000000..fbd91bf6110--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/flat-usage-limit.type.ts@@ -0,0 +1,18 @@+import { type UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';+import { type UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type LimitValueType } from 'src/engine/core-modules/usage-limit/types/limit-value-type.type';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';++export type FlatUsageLimit = {+ id: string;+ resourceType: UsageResourceType;+ operationType: UsageOperationType;+ spenderType: SpenderType;+ spenderId: string;+ limitKind: LimitKind;+ windowSeconds: number;+ limitValueType: LimitValueType;+ limitValue: number;+ burstValue: number | null;+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-kind.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-kind.type.tsnew file mode 100644index 00000000000..9b1c37c09f7--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-kind.type.ts@@ -0,0 +1,3 @@+import { type LIMIT_KINDS } from 'src/engine/core-modules/usage-limit/constants/limit-kinds.constant';++export type LimitKind = (typeof LIMIT_KINDS)[number];diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-value-type.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-value-type.type.tsnew file mode 100644index 00000000000..e223e3bd41c--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/limit-value-type.type.ts@@ -0,0 +1,3 @@+import { type LIMIT_VALUE_TYPES } from 'src/engine/core-modules/usage-limit/constants/limit-value-types.constant';++export type LimitValueType = (typeof LIMIT_VALUE_TYPES)[number];diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/spender-type.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/spender-type.type.tsnew file mode 100644index 00000000000..7890fcd3a2d--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/spender-type.type.ts@@ -0,0 +1,3 @@+import { type SPENDER_TYPES } from 'src/engine/core-modules/usage-limit/constants/spender-types.constant';++export type SpenderType = (typeof SPENDER_TYPES)[number];diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-definition.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-definition.type.tsnew file mode 100644index 00000000000..4ffab1bb620--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-definition.type.ts@@ -0,0 +1,9 @@+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';+import { type UsageLimitFallback } from 'src/engine/core-modules/usage-limit/types/usage-limit-fallback.type';+import { type UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';++export type UsageLimitDefinition = {+ allowedOperationTypes: UsageOperationType[];+ allowedSpenderTypes: SpenderType[];+ fallbacks: UsageLimitFallback[];+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-fallback.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-fallback.type.tsnew file mode 100644index 00000000000..a4845b68028--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-fallback.type.ts@@ -0,0 +1,9 @@+import { type ConfigVariables } from 'src/engine/core-modules/twenty-config/config-variables';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';++export type UsageLimitFallback = {+ spenderType: SpenderType;+ counterScope: 'perWorkspace' | 'crossWorkspace';+ maxTokensConfigVariable: keyof ConfigVariables;+ windowMsConfigVariable: keyof ConfigVariables;+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-rules.type.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-rules.type.tsnew file mode 100644index 00000000000..4ab9e039719--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/types/usage-limit-rules.type.ts@@ -0,0 +1,6 @@+import { type UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';+import { type FlatUsageLimit } from 'src/engine/core-modules/usage-limit/types/flat-usage-limit.type';++export type UsageLimitRules = {+ byResourceType: Partial<Record<UsageResourceType, FlatUsageLimit[]>>;+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.entity.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.entity.tsnew file mode 100644index 00000000000..27e8349eb0f--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.entity.ts@@ -0,0 +1,86 @@+import { Field, Int, ObjectType } from '@nestjs/graphql';++import { GraphQLBigInt } from 'graphql-scalars';++import {+ Column,+ CreateDateColumn,+ Entity,+ PrimaryGeneratedColumn,+ Unique,+ UpdateDateColumn,+} from 'typeorm';++import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type LimitValueType } from 'src/engine/core-modules/usage-limit/types/limit-value-type.type';+import { type SpenderType } from 'src/engine/core-modules/usage-limit/types/spender-type.type';+import { nullableBigintColumnTransformer } from 'src/engine/core-modules/usage-limit/utils/nullable-bigint-column-transformer.util';+import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';+import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';+import { WorkspaceRelatedEntity } from 'src/engine/workspace-manager/types/workspace-related-entity';++@Unique('UQ_USAGE_LIMIT_SCOPE', [+ 'workspaceId',+ 'resourceType',+ 'operationType',+ 'spenderType',+ 'spenderId',+ 'limitKind',+ 'windowSeconds',+])+@Entity({ name: 'usageLimit', schema: 'core' })+@ObjectType('UsageLimit')+export class UsageLimitEntity extends WorkspaceRelatedEntity {+ @Field(() => UUIDScalarType)+ @PrimaryGeneratedColumn('uuid')+ id: string;++ @Field(() => UsageResourceType)+ @Column({ type: 'varchar' })+ resourceType: UsageResourceType;++ @Field(() => UsageOperationType)+ @Column({ type: 'varchar' })+ operationType: UsageOperationType;++ @Field(() => String)+ @Column({ type: 'varchar' })+ spenderType: SpenderType;++ @Field(() => String)+ @Column({ type: 'varchar', default: '' })+ spenderId: string;++ @Field(() => String)+ @Column({ type: 'varchar' })+ limitKind: LimitKind;++ @Field(() => Int)+ @Column({ type: 'int', default: 0 })+ windowSeconds: number;++ @Field(() => String)+ @Column({ type: 'varchar', default: 'absolute' })+ limitValueType: LimitValueType;++ @Field(() => GraphQLBigInt)+ @Column({ type: 'bigint', transformer: nullableBigintColumnTransformer })+ limitValue: number;++ @Field(() => GraphQLBigInt, { nullable: true })+ @Column({+ type: 'bigint',+ nullable: true,+ transformer: nullableBigintColumnTransformer,+ })+ burstValue: number | null;++ @Field(() => Date)+ @CreateDateColumn({ type: 'timestamptz' })+ createdAt: Date;++ @Field(() => Date)+ @UpdateDateColumn({ type: 'timestamptz' })+ updatedAt: Date;+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.module.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.module.tsnew file mode 100644index 00000000000..9ba9f07b37f--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.module.ts@@ -0,0 +1,43 @@+import { Module } from '@nestjs/common';+import { TypeOrmModule } from '@nestjs/typeorm';++import { ApiKeyEntity } from 'src/engine/core-modules/api-key/api-key.entity';+import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';+import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';+import { AgentEntity } from 'src/engine/metadata-modules/ai/ai-agent/entities/agent.entity';+import { LogicFunctionEntity } from 'src/engine/metadata-modules/logic-function/logic-function.entity';+import { UsageLimitResolver } from 'src/engine/core-modules/usage-limit/usage-limit.resolver';+import { UsageLimitService } from 'src/engine/core-modules/usage-limit/services/usage-limit.service';+import { UsageLimitRulesCacheService } from 'src/engine/core-modules/usage-limit/services/usage-limit-rules-cache.service';+import { UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';+import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';+import { provideWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/provide-workspace-scoped-repository';+import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';++@Module({+ imports: [+ TypeOrmModule.forFeature([+ UsageLimitEntity,+ ApiKeyEntity,+ ApplicationEntity,+ UserWorkspaceEntity,+ AgentEntity,+ LogicFunctionEntity,+ ]),+ WorkspaceCacheModule,+ PermissionsModule,+ ],+ providers: [+ UsageLimitRulesCacheService,+ UsageLimitService,+ UsageLimitResolver,+ provideWorkspaceScopedRepository(UsageLimitEntity),+ provideWorkspaceScopedRepository(ApiKeyEntity),+ provideWorkspaceScopedRepository(ApplicationEntity),+ provideWorkspaceScopedRepository(UserWorkspaceEntity),+ provideWorkspaceScopedRepository(AgentEntity),+ provideWorkspaceScopedRepository(LogicFunctionEntity),+ ],+ exports: [UsageLimitRulesCacheService],+})+export class UsageLimitModule {}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.resolver.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.resolver.tsnew file mode 100644index 00000000000..f8c54666ec0--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/usage-limit.resolver.ts@@ -0,0 +1,57 @@+import { UseFilters, UseGuards, UsePipes } from '@nestjs/common';+import { Args, Mutation, Query } from '@nestjs/graphql';++import { PermissionFlagType } from 'twenty-shared/constants';++import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';+import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';+import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';+import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';+import { UpsertUsageLimitInput } from 'src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input';+import { UsageLimitGraphqlApiExceptionFilter } from 'src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter';+import { UsageLimitService } from 'src/engine/core-modules/usage-limit/services/usage-limit.service';+import { UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';+import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';+import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';+import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';+import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';++@MetadataResolver(() => UsageLimitEntity)+@UseFilters(+ UsageLimitGraphqlApiExceptionFilter,+ PreventNestToAutoLogGraphqlErrorsFilter,+)+@UsePipes(ResolverValidationPipe)+@UseGuards(+ WorkspaceAuthGuard,+ SettingsPermissionGuard(PermissionFlagType.WORKSPACE),+)+export class UsageLimitResolver {+ constructor(private readonly usageLimitService: UsageLimitService) {}++ @Query(() => [UsageLimitEntity])+ async usageLimits(+ @AuthWorkspace() workspace: WorkspaceEntity,+ ): Promise<UsageLimitEntity[]> {+ return this.usageLimitService.findAll(workspace.id);+ }++ @Mutation(() => UsageLimitEntity)+ async upsertUsageLimit(+ @AuthWorkspace() workspace: WorkspaceEntity,+ @Args('input') input: UpsertUsageLimitInput,+ ): Promise<UsageLimitEntity> {+ return this.usageLimitService.upsert({ workspaceId: workspace.id, input });+ }++ @Mutation(() => Boolean)+ async deleteUsageLimit(+ @AuthWorkspace() workspace: WorkspaceEntity,+ @Args('usageLimitId', { type: () => UUIDScalarType }) usageLimitId: string,+ ): Promise<boolean> {+ return this.usageLimitService.delete({+ workspaceId: workspace.id,+ usageLimitId,+ });+ }+}diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/utils/__tests__/validate-usage-limit-against-definition.util.spec.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/__tests__/validate-usage-limit-against-definition.util.spec.tsnew file mode 100644index 00000000000..03b9bb30bb8--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/__tests__/validate-usage-limit-against-definition.util.spec.ts@@ -0,0 +1,111 @@+import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';+import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';+import { type UpsertUsageLimitInput } from 'src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input';+import { UsageLimitExceptionCode } from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';+import { validateUsageLimitAgainstDefinition } from 'src/engine/core-modules/usage-limit/utils/validate-usage-limit-against-definition.util';++const validSpeedRule: UpsertUsageLimitInput = {+ resourceType: UsageResourceType.API,+ operationType: UsageOperationType.API_REQUEST,+ spenderType: 'apiKey',+ spenderId: '20202020-1c25-4d02-bf25-6aeccf7ea419',+ limitKind: 'speed',+ windowSeconds: 60,+ limitValue: 100,+};++describe('validateUsageLimitAgainstDefinition', () => {+ it('accepts a rule the definition allows', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition(validSpeedRule),+ ).not.toThrow();+ });++ it('rejects a resource that has no definition', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ resourceType: UsageResourceType.STORAGE,+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('rejects an operation the resource does not meter', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ operationType: UsageOperationType.EMAIL_SEND,+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('refuses to rate-limit a human, because the definition does not allow that scope', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ spenderType: 'userWorkspace',+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('rejects a speed rule with no window', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ windowSeconds: 0,+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('rejects a workspace rule, since the instance operator owns that scope', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ spenderType: 'workspace',+ spenderId: null,+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('rejects a spender id that is not a uuid', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ spenderId: 'key-1',+ }),+ ).toThrow(+ expect.objectContaining({+ code: UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ }),+ );+ });++ it('accepts a rule targeting every spender of a type', () => {+ expect(() =>+ validateUsageLimitAgainstDefinition({+ ...validSpeedRule,+ spenderId: null,+ }),+ ).not.toThrow();+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/utils/find-usage-limit-definition.util.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/find-usage-limit-definition.util.tsnew file mode 100644index 00000000000..c7783d51a8f--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/find-usage-limit-definition.util.ts@@ -0,0 +1,13 @@+import { USAGE_LIMIT_DEFINITIONS } from 'src/engine/core-modules/usage-limit/constants/usage-limit-definitions.constant';+import { type LimitKind } from 'src/engine/core-modules/usage-limit/types/limit-kind.type';+import { type UsageLimitDefinition } from 'src/engine/core-modules/usage-limit/types/usage-limit-definition.type';+import { type UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';++export const findUsageLimitDefinition = ({+ resourceType,+ limitKind,+}: {+ resourceType: UsageResourceType;+ limitKind: LimitKind;+}): UsageLimitDefinition | undefined =>+ USAGE_LIMIT_DEFINITIONS[resourceType]?.[limitKind];diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/utils/from-usage-limit-entity-to-flat.util.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/from-usage-limit-entity-to-flat.util.tsnew file mode 100644index 00000000000..e678e740345--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/from-usage-limit-entity-to-flat.util.ts@@ -0,0 +1,17 @@+import { type UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';+import { type FlatUsageLimit } from 'src/engine/core-modules/usage-limit/types/flat-usage-limit.type';++export const fromUsageLimitEntityToFlat = (+ usageLimit: UsageLimitEntity,+): FlatUsageLimit => ({+ id: usageLimit.id,+ resourceType: usageLimit.resourceType,+ operationType: usageLimit.operationType,+ spenderType: usageLimit.spenderType,+ spenderId: usageLimit.spenderId,+ limitKind: usageLimit.limitKind,+ windowSeconds: usageLimit.windowSeconds,+ limitValueType: usageLimit.limitValueType,+ limitValue: usageLimit.limitValue,+ burstValue: usageLimit.burstValue,+});diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/utils/nullable-bigint-column-transformer.util.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/nullable-bigint-column-transformer.util.tsnew file mode 100644index 00000000000..7f8ff704e11--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/nullable-bigint-column-transformer.util.ts@@ -0,0 +1,7 @@+import { isString } from '@sniptt/guards';++export const nullableBigintColumnTransformer = {+ to: (value: number | null) => value,+ from: (value: string | number | null) =>+ isString(value) ? Number(value) : value,+};diff --git a/packages/twenty-server/src/engine/core-modules/usage-limit/utils/validate-usage-limit-against-definition.util.ts b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/validate-usage-limit-against-definition.util.tsnew file mode 100644index 00000000000..06ac1980472--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/usage-limit/utils/validate-usage-limit-against-definition.util.ts@@ -0,0 +1,61 @@+import { isNonEmptyString } from '@sniptt/guards';+import { isDefined, isValidUuid } from 'twenty-shared/utils';++import { OPERATOR_ONLY_SPENDER_TYPES } from 'src/engine/core-modules/usage-limit/constants/operator-only-spender-types.constant';+import { type UpsertUsageLimitInput } from 'src/engine/core-modules/usage-limit/dtos/upsert-usage-limit.input';+import {+ UsageLimitException,+ UsageLimitExceptionCode,+} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';+import { findUsageLimitDefinition } from 'src/engine/core-modules/usage-limit/utils/find-usage-limit-definition.util';++export const validateUsageLimitAgainstDefinition = (+ input: UpsertUsageLimitInput,+): void => {+ const definition = findUsageLimitDefinition({+ resourceType: input.resourceType,+ limitKind: input.limitKind,+ });++ if (!isDefined(definition)) {+ throw new UsageLimitException(+ `No ${input.limitKind} limit is defined for ${input.resourceType}`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }++ if (!definition.allowedOperationTypes.includes(input.operationType)) {+ throw new UsageLimitException(+ `${input.resourceType} ${input.limitKind} limits cannot target the ${input.operationType} operation`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }++ if (!definition.allowedSpenderTypes.includes(input.spenderType)) {+ throw new UsageLimitException(+ `${input.resourceType} ${input.limitKind} limits cannot be scoped to ${input.spenderType}`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }++ if (OPERATOR_ONLY_SPENDER_TYPES.includes(input.spenderType)) {+ throw new UsageLimitException(+ `${input.spenderType} limits are set by the instance operator`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }++ if (isNonEmptyString(input.spenderId) && !isValidUuid(input.spenderId)) {+ throw new UsageLimitException(+ `${input.spenderId} is not a valid ${input.spenderType} id`,+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }++ if (input.limitKind === 'speed' && input.windowSeconds <= 0) {+ throw new UsageLimitException(+ 'A speed limit needs a window longer than zero seconds',+ UsageLimitExceptionCode.LIMIT_RULE_INVALID,+ );+ }+};diff --git a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-operation-type.enum.ts b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-operation-type.enum.tsindex d5c5aa691df..7db0b65e06d 100644--- a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-operation-type.enum.ts+++ b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-operation-type.enum.ts@@ -10,6 +10,7 @@ export enum UsageOperationType {WEB_SEARCH = 'WEB_SEARCH',CALL_RECORDING = 'CALL_RECORDING',EMAIL_SEND = 'EMAIL_SEND',+ API_REQUEST = 'API_REQUEST',}registerEnumType(UsageOperationType, {diff --git a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-resource-type.enum.ts b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-resource-type.enum.tsindex cea2d5a54fb..5212fa167e4 100644--- a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-resource-type.enum.ts+++ b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-resource-type.enum.ts@@ -1,5 +1,7 @@/* @license Enterprise */+import { registerEnumType } from '@nestjs/graphql';+export enum UsageResourceType {AI = 'AI',WORKFLOW = 'WORKFLOW',@@ -9,3 +11,7 @@ export enum UsageResourceType {LOGIC_FUNCTION = 'LOGIC_FUNCTION',EMAIL = 'EMAIL',}++registerEnumType(UsageResourceType, {+ name: 'UsageResourceType',+});diff --git a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-unit.enum.ts b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-unit.enum.tsindex 9fa895aebe1..4df51c8349f 100644--- a/packages/twenty-server/src/engine/core-modules/usage/enums/usage-unit.enum.ts+++ b/packages/twenty-server/src/engine/core-modules/usage/enums/usage-unit.enum.ts@@ -6,4 +6,5 @@ export enum UsageUnit {INVOCATION = 'INVOCATION',MINUTE = 'MINUTE',BYTE = 'BYTE',+ REQUEST = 'REQUEST',}diff --git a/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts b/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.tsindex 695b3760eb2..350d16341bb 100644--- a/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts+++ b/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts@@ -12,6 +12,7 @@ import { type FlatApiKey } from 'src/engine/core-modules/api-key/types/flat-api-import { type ApplicationVariableCacheMaps } from 'src/engine/core-modules/application/application-variable/types/application-variable-cache-maps.type';import { type FlatApplicationCacheMaps } from 'src/engine/core-modules/application/types/flat-application-cache-maps.type';import { type CurrentBillingSubscription } from 'src/engine/core-modules/billing/types/flat-billing-subscription.type';+import { type FlatWorkspaceMemberMaps } from 'src/engine/core-modules/user/types/flat-workspace-member-maps.type';import { type WorkflowAutomatedTriggerMaps } from 'src/engine/core-modules/workflow/types/workflow-automated-trigger-maps.type';import { type FlatRoleTargetByAgentIdMaps } from 'src/engine/metadata-modules/flat-agent/types/flat-role-target-by-agent-id-maps.type';@@ -19,6 +20,7 @@ import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/import { type UserWorkspaceRoleMap } from 'src/engine/metadata-modules/role-target/types/user-workspace-role-map';import { type FlatRowLevelPermissionPredicateGroupMaps } from 'src/engine/metadata-modules/row-level-permission-predicate/types/flat-row-level-permission-predicate-group-maps.type';import { type FlatRowLevelPermissionPredicateMaps } from 'src/engine/metadata-modules/row-level-permission-predicate/types/flat-row-level-permission-predicate-maps.type';+import { type UsageLimitRules } from 'src/engine/core-modules/usage-limit/types/usage-limit-rules.type';export type AdditionalCacheDataMaps = {featureFlagsMap: Record<FeatureFlagKey, boolean>;@@ -37,6 +39,7 @@ export type AdditionalCacheDataMaps = {graphQLResolverNameMap: Record<string, ResolverNameMapEntry>;currentBillingSubscription: CurrentBillingSubscription;workflowAutomatedTriggerMaps: WorkflowAutomatedTriggerMaps;+ usageLimitRules: UsageLimitRules;};export type WorkspaceCacheDataMap = AllFlatEntityMaps<true> &