glin-profanity 3.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/{types-Dj5vaoch.d.cts → Filter-BGcyIAvO.d.ts} +2 -162
  2. package/dist/{types-Dj5vaoch.d.ts → Filter-D34Wsmrj.d.cts} +2 -162
  3. package/dist/frameworks/index.cjs +5257 -0
  4. package/dist/frameworks/index.d.cts +2 -0
  5. package/dist/frameworks/index.d.ts +2 -0
  6. package/dist/frameworks/index.js +5252 -0
  7. package/dist/frameworks/nextjs.cjs +5257 -0
  8. package/dist/frameworks/nextjs.d.cts +173 -0
  9. package/dist/frameworks/nextjs.d.ts +173 -0
  10. package/dist/frameworks/nextjs.js +5252 -0
  11. package/dist/index.cjs +0 -28
  12. package/dist/index.d.cts +5 -29
  13. package/dist/index.d.ts +5 -29
  14. package/dist/index.js +1 -28
  15. package/dist/integrations/index.cjs +6110 -0
  16. package/dist/integrations/index.d.cts +5 -0
  17. package/dist/integrations/index.d.ts +5 -0
  18. package/dist/integrations/index.js +6082 -0
  19. package/dist/integrations/langchain.cjs +5252 -0
  20. package/dist/integrations/langchain.d.cts +231 -0
  21. package/dist/integrations/langchain.d.ts +231 -0
  22. package/dist/integrations/langchain.js +5239 -0
  23. package/dist/integrations/openai.cjs +5367 -0
  24. package/dist/integrations/openai.d.cts +167 -0
  25. package/dist/integrations/openai.d.ts +167 -0
  26. package/dist/integrations/openai.js +5362 -0
  27. package/dist/integrations/semantic.cjs +5314 -0
  28. package/dist/integrations/semantic.d.cts +268 -0
  29. package/dist/integrations/semantic.d.ts +268 -0
  30. package/dist/integrations/semantic.js +5309 -0
  31. package/dist/integrations/vercel-ai.cjs +5282 -0
  32. package/dist/integrations/vercel-ai.d.cts +224 -0
  33. package/dist/integrations/vercel-ai.d.ts +224 -0
  34. package/dist/integrations/vercel-ai.js +5273 -0
  35. package/dist/ml/index.cjs +207 -0
  36. package/dist/ml/index.d.cts +5 -2
  37. package/dist/ml/index.d.ts +5 -2
  38. package/dist/ml/index.js +203 -1
  39. package/dist/ml/transformers.cjs +5237 -0
  40. package/dist/ml/transformers.d.cts +232 -0
  41. package/dist/ml/transformers.d.ts +232 -0
  42. package/dist/ml/transformers.js +5231 -0
  43. package/dist/multimodal/audio.cjs +5269 -0
  44. package/dist/multimodal/audio.d.cts +255 -0
  45. package/dist/multimodal/audio.d.ts +255 -0
  46. package/dist/multimodal/audio.js +5264 -0
  47. package/dist/multimodal/index.cjs +5432 -0
  48. package/dist/multimodal/index.d.cts +4 -0
  49. package/dist/multimodal/index.d.ts +4 -0
  50. package/dist/multimodal/index.js +5422 -0
  51. package/dist/multimodal/ocr.cjs +5193 -0
  52. package/dist/multimodal/ocr.d.cts +157 -0
  53. package/dist/multimodal/ocr.d.ts +157 -0
  54. package/dist/multimodal/ocr.js +5187 -0
  55. package/dist/react.cjs +5133 -0
  56. package/dist/react.d.cts +13 -0
  57. package/dist/react.d.ts +13 -0
  58. package/dist/react.js +5131 -0
  59. package/dist/types-B9c_ik4k.d.cts +88 -0
  60. package/dist/types-B9c_ik4k.d.ts +88 -0
  61. package/dist/types-BuKh9tvV.d.ts +20 -0
  62. package/dist/types-Ct_ueYqw.d.cts +76 -0
  63. package/dist/types-Ct_ueYqw.d.ts +76 -0
  64. package/dist/types-DI8nzwWc.d.cts +20 -0
  65. package/package.json +170 -3
@@ -0,0 +1,255 @@
1
+ import { F as Filter } from '../Filter-D34Wsmrj.cjs';
2
+ import { L as Language, F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.cjs';
3
+
4
+ /**
5
+ * Audio Pipeline Utilities for glin-profanity
6
+ *
7
+ * Provides utilities for checking profanity in audio content.
8
+ * This module does NOT include speech-to-text - users bring their own
9
+ * transcription from Whisper, Google STT, Azure Speech, etc.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { createAudioPipeline } from 'glin-profanity/audio';
14
+ * import OpenAI from 'openai';
15
+ *
16
+ * const openai = new OpenAI();
17
+ * const pipeline = createAudioPipeline({
18
+ * transcriber: async (audioBuffer) => {
19
+ * const response = await openai.audio.transcriptions.create({
20
+ * file: audioBuffer,
21
+ * model: 'whisper-1',
22
+ * });
23
+ * return response.text;
24
+ * },
25
+ * });
26
+ *
27
+ * const result = await pipeline.checkAudio(audioFile);
28
+ * console.log(result.containsProfanity);
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @module glin-profanity/audio
33
+ */
34
+
35
+ /**
36
+ * Transcription function type
37
+ * Users provide their own transcription implementation
38
+ */
39
+ type TranscriberFunction = (audio: AudioInput) => Promise<string>;
40
+ /**
41
+ * Audio input types
42
+ */
43
+ type AudioInput = Buffer | Uint8Array | Blob | File | string;
44
+ /**
45
+ * Audio pipeline configuration
46
+ */
47
+ interface AudioPipelineConfig {
48
+ /** Custom transcription function (REQUIRED) */
49
+ transcriber: TranscriberFunction;
50
+ /** Languages for profanity detection */
51
+ languages?: Language[];
52
+ /** Enable leetspeak detection */
53
+ detectLeetspeak?: boolean;
54
+ /** Enable Unicode normalization */
55
+ normalizeUnicode?: boolean;
56
+ /** Custom filter configuration */
57
+ filterConfig?: Partial<FilterConfig>;
58
+ }
59
+ /**
60
+ * Audio check result
61
+ */
62
+ interface AudioCheckResult {
63
+ /** Whether profanity was found */
64
+ containsProfanity: boolean;
65
+ /** Transcribed text from audio */
66
+ transcribedText: string;
67
+ /** Profane words found */
68
+ profaneWords: string[];
69
+ /** Full profanity check result */
70
+ profanityResult: CheckProfanityResult;
71
+ /** Processing time in milliseconds */
72
+ processingTimeMs: number;
73
+ /** Transcription time in milliseconds */
74
+ transcriptionTimeMs: number;
75
+ /** Profanity check time in milliseconds */
76
+ checkTimeMs: number;
77
+ }
78
+ /**
79
+ * Segment result for timestamped audio
80
+ */
81
+ interface AudioSegmentResult {
82
+ /** Segment index */
83
+ index: number;
84
+ /** Start time in seconds */
85
+ startTime: number;
86
+ /** End time in seconds */
87
+ endTime: number;
88
+ /** Transcribed text for this segment */
89
+ text: string;
90
+ /** Whether this segment contains profanity */
91
+ containsProfanity: boolean;
92
+ /** Profane words in this segment */
93
+ profaneWords: string[];
94
+ }
95
+ /**
96
+ * Creates an audio profanity checking pipeline
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // With OpenAI Whisper
101
+ * const pipeline = createAudioPipeline({
102
+ * transcriber: async (audio) => {
103
+ * const formData = new FormData();
104
+ * formData.append('file', audio);
105
+ * formData.append('model', 'whisper-1');
106
+ *
107
+ * const response = await fetch('https://api.openai.com/v1/audio/transcriptions', {
108
+ * method: 'POST',
109
+ * headers: { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` },
110
+ * body: formData,
111
+ * });
112
+ * const data = await response.json();
113
+ * return data.text;
114
+ * },
115
+ * });
116
+ *
117
+ * // With Google Cloud Speech-to-Text
118
+ * const pipeline = createAudioPipeline({
119
+ * transcriber: async (audio) => {
120
+ * // Your Google STT implementation
121
+ * return transcribedText;
122
+ * },
123
+ * });
124
+ * ```
125
+ */
126
+ declare function createAudioPipeline(config: AudioPipelineConfig): {
127
+ /**
128
+ * Check audio for profanity
129
+ */
130
+ checkAudio(audio: AudioInput): Promise<AudioCheckResult>;
131
+ /**
132
+ * Check multiple audio files
133
+ */
134
+ checkMultiple(audios: AudioInput[]): Promise<AudioCheckResult[]>;
135
+ /**
136
+ * Check pre-transcribed text (if you already have transcription)
137
+ */
138
+ checkTranscript(text: string): CheckProfanityResult;
139
+ /**
140
+ * Check timestamped segments (for Whisper with timestamps)
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const segments = [
145
+ * { startTime: 0, endTime: 5, text: 'Hello everyone' },
146
+ * { startTime: 5, endTime: 10, text: 'This is a test' },
147
+ * ];
148
+ * const results = pipeline.checkSegments(segments);
149
+ * const flaggedSegments = results.filter(s => s.containsProfanity);
150
+ * ```
151
+ */
152
+ checkSegments(segments: Array<{
153
+ startTime: number;
154
+ endTime: number;
155
+ text: string;
156
+ }>): AudioSegmentResult[];
157
+ /**
158
+ * Censor transcribed text
159
+ */
160
+ censorTranscript(text: string, replacement?: string): string;
161
+ /**
162
+ * Get the underlying filter instance
163
+ */
164
+ getFilter(): Filter;
165
+ };
166
+ /**
167
+ * Creates a transcriber function for OpenAI Whisper API
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const transcriber = createWhisperTranscriber({
172
+ * apiKey: process.env.OPENAI_API_KEY,
173
+ * model: 'whisper-1',
174
+ * });
175
+ *
176
+ * const pipeline = createAudioPipeline({ transcriber });
177
+ * ```
178
+ */
179
+ declare function createWhisperTranscriber(config: {
180
+ apiKey: string;
181
+ model?: string;
182
+ baseUrl?: string;
183
+ language?: string;
184
+ }): TranscriberFunction;
185
+ /**
186
+ * Creates a transcriber function for Google Cloud Speech-to-Text
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const transcriber = createGoogleSTTTranscriber({
191
+ * apiKey: process.env.GOOGLE_API_KEY,
192
+ * languageCode: 'en-US',
193
+ * });
194
+ *
195
+ * const pipeline = createAudioPipeline({ transcriber });
196
+ * ```
197
+ */
198
+ declare function createGoogleSTTTranscriber(config: {
199
+ apiKey: string;
200
+ languageCode?: string;
201
+ enableAutomaticPunctuation?: boolean;
202
+ profanityFilter?: boolean;
203
+ }): TranscriberFunction;
204
+ /**
205
+ * Real-time audio stream checker
206
+ * For live audio moderation (e.g., voice chat, podcasts)
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const streamChecker = createRealtimeChecker({
211
+ * transcriber: myTranscriber,
212
+ * onProfanityDetected: (result) => {
213
+ * console.log('Profanity detected:', result.profaneWords);
214
+ * // Trigger beep, mute, or warning
215
+ * },
216
+ * });
217
+ *
218
+ * // Feed audio chunks as they arrive
219
+ * audioStream.on('data', (chunk) => {
220
+ * streamChecker.processChunk(chunk);
221
+ * });
222
+ *
223
+ * // Get summary when done
224
+ * const summary = streamChecker.getSummary();
225
+ * ```
226
+ */
227
+ declare function createRealtimeChecker(config: {
228
+ transcriber: TranscriberFunction;
229
+ onProfanityDetected?: (result: AudioCheckResult) => void;
230
+ bufferDurationMs?: number;
231
+ languages?: Language[];
232
+ detectLeetspeak?: boolean;
233
+ }): {
234
+ /**
235
+ * Process an audio chunk
236
+ */
237
+ processChunk(chunk: AudioInput): Promise<AudioCheckResult>;
238
+ /**
239
+ * Get summary of all processed chunks
240
+ */
241
+ getSummary(): {
242
+ totalChunks: number;
243
+ flaggedChunks: number;
244
+ cleanChunks: number;
245
+ flagRate: number;
246
+ allProfaneWords: string[];
247
+ fullTranscript: string;
248
+ };
249
+ /**
250
+ * Reset the checker state
251
+ */
252
+ reset(): void;
253
+ };
254
+
255
+ export { type AudioCheckResult, type AudioInput, type AudioPipelineConfig, type AudioSegmentResult, CheckProfanityResult, FilterConfig, Language, type TranscriberFunction, createAudioPipeline, createGoogleSTTTranscriber, createRealtimeChecker, createWhisperTranscriber };
@@ -0,0 +1,255 @@
1
+ import { F as Filter } from '../Filter-BGcyIAvO.js';
2
+ import { L as Language, F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.js';
3
+
4
+ /**
5
+ * Audio Pipeline Utilities for glin-profanity
6
+ *
7
+ * Provides utilities for checking profanity in audio content.
8
+ * This module does NOT include speech-to-text - users bring their own
9
+ * transcription from Whisper, Google STT, Azure Speech, etc.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { createAudioPipeline } from 'glin-profanity/audio';
14
+ * import OpenAI from 'openai';
15
+ *
16
+ * const openai = new OpenAI();
17
+ * const pipeline = createAudioPipeline({
18
+ * transcriber: async (audioBuffer) => {
19
+ * const response = await openai.audio.transcriptions.create({
20
+ * file: audioBuffer,
21
+ * model: 'whisper-1',
22
+ * });
23
+ * return response.text;
24
+ * },
25
+ * });
26
+ *
27
+ * const result = await pipeline.checkAudio(audioFile);
28
+ * console.log(result.containsProfanity);
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @module glin-profanity/audio
33
+ */
34
+
35
+ /**
36
+ * Transcription function type
37
+ * Users provide their own transcription implementation
38
+ */
39
+ type TranscriberFunction = (audio: AudioInput) => Promise<string>;
40
+ /**
41
+ * Audio input types
42
+ */
43
+ type AudioInput = Buffer | Uint8Array | Blob | File | string;
44
+ /**
45
+ * Audio pipeline configuration
46
+ */
47
+ interface AudioPipelineConfig {
48
+ /** Custom transcription function (REQUIRED) */
49
+ transcriber: TranscriberFunction;
50
+ /** Languages for profanity detection */
51
+ languages?: Language[];
52
+ /** Enable leetspeak detection */
53
+ detectLeetspeak?: boolean;
54
+ /** Enable Unicode normalization */
55
+ normalizeUnicode?: boolean;
56
+ /** Custom filter configuration */
57
+ filterConfig?: Partial<FilterConfig>;
58
+ }
59
+ /**
60
+ * Audio check result
61
+ */
62
+ interface AudioCheckResult {
63
+ /** Whether profanity was found */
64
+ containsProfanity: boolean;
65
+ /** Transcribed text from audio */
66
+ transcribedText: string;
67
+ /** Profane words found */
68
+ profaneWords: string[];
69
+ /** Full profanity check result */
70
+ profanityResult: CheckProfanityResult;
71
+ /** Processing time in milliseconds */
72
+ processingTimeMs: number;
73
+ /** Transcription time in milliseconds */
74
+ transcriptionTimeMs: number;
75
+ /** Profanity check time in milliseconds */
76
+ checkTimeMs: number;
77
+ }
78
+ /**
79
+ * Segment result for timestamped audio
80
+ */
81
+ interface AudioSegmentResult {
82
+ /** Segment index */
83
+ index: number;
84
+ /** Start time in seconds */
85
+ startTime: number;
86
+ /** End time in seconds */
87
+ endTime: number;
88
+ /** Transcribed text for this segment */
89
+ text: string;
90
+ /** Whether this segment contains profanity */
91
+ containsProfanity: boolean;
92
+ /** Profane words in this segment */
93
+ profaneWords: string[];
94
+ }
95
+ /**
96
+ * Creates an audio profanity checking pipeline
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // With OpenAI Whisper
101
+ * const pipeline = createAudioPipeline({
102
+ * transcriber: async (audio) => {
103
+ * const formData = new FormData();
104
+ * formData.append('file', audio);
105
+ * formData.append('model', 'whisper-1');
106
+ *
107
+ * const response = await fetch('https://api.openai.com/v1/audio/transcriptions', {
108
+ * method: 'POST',
109
+ * headers: { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` },
110
+ * body: formData,
111
+ * });
112
+ * const data = await response.json();
113
+ * return data.text;
114
+ * },
115
+ * });
116
+ *
117
+ * // With Google Cloud Speech-to-Text
118
+ * const pipeline = createAudioPipeline({
119
+ * transcriber: async (audio) => {
120
+ * // Your Google STT implementation
121
+ * return transcribedText;
122
+ * },
123
+ * });
124
+ * ```
125
+ */
126
+ declare function createAudioPipeline(config: AudioPipelineConfig): {
127
+ /**
128
+ * Check audio for profanity
129
+ */
130
+ checkAudio(audio: AudioInput): Promise<AudioCheckResult>;
131
+ /**
132
+ * Check multiple audio files
133
+ */
134
+ checkMultiple(audios: AudioInput[]): Promise<AudioCheckResult[]>;
135
+ /**
136
+ * Check pre-transcribed text (if you already have transcription)
137
+ */
138
+ checkTranscript(text: string): CheckProfanityResult;
139
+ /**
140
+ * Check timestamped segments (for Whisper with timestamps)
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const segments = [
145
+ * { startTime: 0, endTime: 5, text: 'Hello everyone' },
146
+ * { startTime: 5, endTime: 10, text: 'This is a test' },
147
+ * ];
148
+ * const results = pipeline.checkSegments(segments);
149
+ * const flaggedSegments = results.filter(s => s.containsProfanity);
150
+ * ```
151
+ */
152
+ checkSegments(segments: Array<{
153
+ startTime: number;
154
+ endTime: number;
155
+ text: string;
156
+ }>): AudioSegmentResult[];
157
+ /**
158
+ * Censor transcribed text
159
+ */
160
+ censorTranscript(text: string, replacement?: string): string;
161
+ /**
162
+ * Get the underlying filter instance
163
+ */
164
+ getFilter(): Filter;
165
+ };
166
+ /**
167
+ * Creates a transcriber function for OpenAI Whisper API
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const transcriber = createWhisperTranscriber({
172
+ * apiKey: process.env.OPENAI_API_KEY,
173
+ * model: 'whisper-1',
174
+ * });
175
+ *
176
+ * const pipeline = createAudioPipeline({ transcriber });
177
+ * ```
178
+ */
179
+ declare function createWhisperTranscriber(config: {
180
+ apiKey: string;
181
+ model?: string;
182
+ baseUrl?: string;
183
+ language?: string;
184
+ }): TranscriberFunction;
185
+ /**
186
+ * Creates a transcriber function for Google Cloud Speech-to-Text
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const transcriber = createGoogleSTTTranscriber({
191
+ * apiKey: process.env.GOOGLE_API_KEY,
192
+ * languageCode: 'en-US',
193
+ * });
194
+ *
195
+ * const pipeline = createAudioPipeline({ transcriber });
196
+ * ```
197
+ */
198
+ declare function createGoogleSTTTranscriber(config: {
199
+ apiKey: string;
200
+ languageCode?: string;
201
+ enableAutomaticPunctuation?: boolean;
202
+ profanityFilter?: boolean;
203
+ }): TranscriberFunction;
204
+ /**
205
+ * Real-time audio stream checker
206
+ * For live audio moderation (e.g., voice chat, podcasts)
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * const streamChecker = createRealtimeChecker({
211
+ * transcriber: myTranscriber,
212
+ * onProfanityDetected: (result) => {
213
+ * console.log('Profanity detected:', result.profaneWords);
214
+ * // Trigger beep, mute, or warning
215
+ * },
216
+ * });
217
+ *
218
+ * // Feed audio chunks as they arrive
219
+ * audioStream.on('data', (chunk) => {
220
+ * streamChecker.processChunk(chunk);
221
+ * });
222
+ *
223
+ * // Get summary when done
224
+ * const summary = streamChecker.getSummary();
225
+ * ```
226
+ */
227
+ declare function createRealtimeChecker(config: {
228
+ transcriber: TranscriberFunction;
229
+ onProfanityDetected?: (result: AudioCheckResult) => void;
230
+ bufferDurationMs?: number;
231
+ languages?: Language[];
232
+ detectLeetspeak?: boolean;
233
+ }): {
234
+ /**
235
+ * Process an audio chunk
236
+ */
237
+ processChunk(chunk: AudioInput): Promise<AudioCheckResult>;
238
+ /**
239
+ * Get summary of all processed chunks
240
+ */
241
+ getSummary(): {
242
+ totalChunks: number;
243
+ flaggedChunks: number;
244
+ cleanChunks: number;
245
+ flagRate: number;
246
+ allProfaneWords: string[];
247
+ fullTranscript: string;
248
+ };
249
+ /**
250
+ * Reset the checker state
251
+ */
252
+ reset(): void;
253
+ };
254
+
255
+ export { type AudioCheckResult, type AudioInput, type AudioPipelineConfig, type AudioSegmentResult, CheckProfanityResult, FilterConfig, Language, type TranscriberFunction, createAudioPipeline, createGoogleSTTTranscriber, createRealtimeChecker, createWhisperTranscriber };