From 8154c4e1cec2d2be43c885f4b65bc9488aae20b6 Mon Sep 17 00:00:00 2001 From: Vishal Narkhede Date: Mon, 23 Dec 2024 14:41:17 +0100 Subject: [PATCH] multi tenancy configuration support --- src/moderation.ts | 13 ++--- src/types.ts | 131 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 137 insertions(+), 7 deletions(-) diff --git a/src/moderation.ts b/src/moderation.ts index 0bc339d56..d9be41da4 100644 --- a/src/moderation.ts +++ b/src/moderation.ts @@ -20,6 +20,7 @@ import { Pager, CustomCheckFlag, ReviewQueueItem, + QueryConfigsResponse, } from './types'; import { StreamChat } from './client'; import { normalizeQuerySort } from './utils'; @@ -174,7 +175,7 @@ export class Moderation(this.client.baseURL + '/api/v2/moderation/config', config); } @@ -182,12 +183,12 @@ export class Moderation(this.client.baseURL + '/api/v2/moderation/config/' + key); + async getConfig(key: string, data?: { team?: string }) { + return await this.client.get(this.client.baseURL + '/api/v2/moderation/config/' + key, data); } - async deleteConfig(key: string) { - return await this.client.delete(this.client.baseURL + '/api/v2/moderation/config/' + key); + async deleteConfig(key: string, data?: { team?: string }) { + return await this.client.delete(this.client.baseURL + '/api/v2/moderation/config/' + key, data); } /** @@ -201,7 +202,7 @@ export class Moderation(this.client.baseURL + '/api/v2/moderation/configs', { filter: filterConditions, sort, ...options, diff --git a/src/types.ts b/src/types.ts index 342e40302..780ebfb0c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3466,6 +3466,8 @@ export type QueryModerationConfigsFilters = QueryFilters< created_at?: PrimitiveFilter; } & { updated_at?: PrimitiveFilter; + } & { + team?: string; } >; @@ -3535,12 +3537,30 @@ export type ReviewQueueResponse = { prev?: string; }; -export type ModerationConfig = {}; +export type ModerationConfig = { + created_at: string; + key: string; + updated_at: string; + ai_image_config?: AIImageConfig; + ai_text_config?: AITextConfig; + ai_video_config?: AIVideoConfig; + automod_platform_circumvention_config?: AutomodPlatformCircumventionConfig; + automod_semantic_filters_config?: AutomodSemanticFiltersConfig; + automod_toxicity_config?: AutomodToxicityConfig; + block_list_config?: BlockListConfig; + team?: string; +}; export type GetConfigResponse = { config: ModerationConfig; }; +export type QueryConfigsResponse = { + configs: ModerationConfig[]; + next?: string; + prev?: string; +}; + export type UpsertConfigResponse = { config: ModerationConfig; }; @@ -3567,3 +3587,112 @@ export type AIState = | 'AI_STATE_THINKING' | 'AI_STATE_GENERATING' | (string & {}); + +export type ModerationActionType = 'flag' | 'shadow' | 'remove' | 'bounce' | 'bounce_flag' | 'bounce_remove'; + +export type AutomodRule = { + action: ModerationActionType; + label: string; + threshold: number; +}; + +export type BlockListRule = { + action: ModerationActionType; + name?: string; +}; + +export type BlockListConfig = { + enabled: boolean; + rules: BlockListRule[]; + async?: boolean; +}; + +export type AutomodToxicityConfig = { + enabled: boolean; + rules: AutomodRule[]; + async?: boolean; +}; + +export type AutomodPlatformCircumventionConfig = { + enabled: boolean; + rules: AutomodRule[]; + async?: boolean; +}; + +export type AutomodSemanticFiltersRule = { + action: ModerationActionType; + name: string; + threshold: number; +}; + +export type AutomodSemanticFiltersConfig = { + enabled: boolean; + rules: AutomodSemanticFiltersRule[]; + async?: boolean; +}; + +export type AITextSeverityRule = { + action: ModerationActionType; + severity: 'low' | 'medium' | 'high' | 'critical'; +}; + +export type AITextRule = { + label: string; + action?: ModerationActionType; + severity_rules?: AITextSeverityRule[]; +}; + +export type AITextConfig = { + enabled: boolean; + rules: AITextRule[]; + async?: boolean; + profile?: string; + severity_rules?: AITextSeverityRule[]; // Deprecated: use rules instead +}; + +export type AIImageRule = { + action: ModerationActionType; + label: string; + min_confidence?: number; +}; + +export type AIImageConfig = { + enabled: boolean; + rules: AIImageRule[]; + async?: boolean; +}; + +export type AIVideoRule = { + action: ModerationActionType; + label: string; + min_confidence?: number; +}; + +export type AIVideoConfig = { + enabled: boolean; + rules: AIVideoRule[]; + async?: boolean; +}; + +export type VelocityFilterConfigRule = { + action: 'flag' | 'shadow' | 'remove' | 'ban'; + ban_duration?: number; + cascading_action?: 'flag' | 'shadow' | 'remove' | 'ban'; + cascading_threshold?: number; + check_message_context?: boolean; + fast_spam_threshold?: number; + fast_spam_ttl?: number; + ip_ban?: boolean; + shadow_ban?: boolean; + slow_spam_ban_duration?: number; + slow_spam_threshold?: number; + slow_spam_ttl?: number; +}; + +export type VelocityFilterConfig = { + cascading_actions: boolean; + enabled: boolean; + first_message_only: boolean; + rules: VelocityFilterConfigRule[]; + async?: boolean; +};