Add BRAINIALL diarized transcription example - #125
Conversation
WalkthroughAdds a Trigger.dev example for Portuguese and Spanish diarized transcription through BRAINIALL. The workflow validates consent, language, API credentials, source hosts, redirects, media types, and a 25 MB streaming limit. It uploads audio for transcription, generates speaker-labelled SRT and WebVTT captions, and returns transcript metadata. The project also adds configuration, setup documentation, environment templates, and tests for source validation, API handling, caption formatting, and workflow validation. Estimated code review effort: 4 (Complex) | ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@brainiall-diarized-transcription/src/lib/captions.ts`:
- Around line 106-110: Update the token-joining condition in the captions join
logic to treat Spanish inverted question and exclamation marks (¿ and ¡) as
opening punctuation, preventing a space after them while preserving existing
punctuation behavior. Add a regression test covering separate Spanish
punctuation tokens, including joinTokens(["¿", "Cómo", "estás", "?"]) and the
equivalent exclamation case.
In `@brainiall-diarized-transcription/src/lib/source.ts`:
- Around line 131-138: Wrap the response-body reading and cancellation flow
around reader.read() and reader.cancel() in the relevant download function with
error handling that replaces any rejection, including errors containing signed
URL query data, with the existing generic download error used by the later fetch
error path. Ensure the reader is still cancelled when the size limit is
exceeded, and add a regression test using a ReadableStream that throws a fake
query secret to verify the redacted error is returned.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 49665272-8316-44b9-85ae-aa90258bbd4e
⛔ Files ignored due to path filters (1)
brainiall-diarized-transcription/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (16)
README.mdbrainiall-diarized-transcription/.env.examplebrainiall-diarized-transcription/.gitignorebrainiall-diarized-transcription/README.mdbrainiall-diarized-transcription/package.jsonbrainiall-diarized-transcription/src/lib/brainiall.tsbrainiall-diarized-transcription/src/lib/captions.tsbrainiall-diarized-transcription/src/lib/source.tsbrainiall-diarized-transcription/src/lib/workflow.tsbrainiall-diarized-transcription/src/trigger/transcribe.tsbrainiall-diarized-transcription/tests/brainiall.test.tsbrainiall-diarized-transcription/tests/captions.test.tsbrainiall-diarized-transcription/tests/source.test.tsbrainiall-diarized-transcription/tests/workflow.test.tsbrainiall-diarized-transcription/trigger.config.tsbrainiall-diarized-transcription/tsconfig.json
| if ( | ||
| !result || | ||
| /^[,.;:!?%…\)\]\}]/u.test(token) || | ||
| /[\(\[\{]$/u.test(result) | ||
| ) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve Spanish inverted punctuation.
joinTokens(["¿", "Cómo", "estás", "?"]) returns "¿ Cómo estás?". The current condition inserts a space after ¿ and ¡. Add both characters to the opening-punctuation expression. Add a regression test for separate Spanish punctuation tokens.
Proposed fix
- /[\(\[\{]$/u.test(result)
+ /[\(\[\{¿¡]$/u.test(result)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if ( | |
| !result || | |
| /^[,.;:!?%…\)\]\}]/u.test(token) || | |
| /[\(\[\{]$/u.test(result) | |
| ) { | |
| if ( | |
| !result || | |
| /^[,.;:!?%…\)\]\}]/u.test(token) || | |
| /[\(\[\{¿¡]$/u.test(result) | |
| ) { |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@brainiall-diarized-transcription/src/lib/captions.ts` around lines 106 - 110,
Update the token-joining condition in the captions join logic to treat Spanish
inverted question and exclamation marks (¿ and ¡) as opening punctuation,
preventing a space after them while preserving existing punctuation behavior.
Add a regression test covering separate Spanish punctuation tokens, including
joinTokens(["¿", "Cómo", "estás", "?"]) and the equivalent exclamation case.
| const { value, done } = await reader.read(); | ||
| if (done) { | ||
| break; | ||
| } | ||
| total += value.byteLength; | ||
| if (total > MAX_AUDIO_BYTES) { | ||
| await reader.cancel(); | ||
| throw new Error("Audio exceeds the 25 MB example limit."); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Redact errors from response-body reads.
Line 131 can reject after fetcher() returns a Response. Line 137 can also reject during cancellation. Both errors bypass the redaction at lines 165-174 and can expose a signed audioUrl query string in task failure history.
Catch and replace body-read and cancellation errors with the same generic download error. Add a regression test with a ReadableStream that throws an error containing a fake query secret.
Proposed fix
- const { value, done } = await reader.read();
+ let result: ReadableStreamReadResult<Uint8Array>;
+ try {
+ result = await reader.read();
+ } catch {
+ try {
+ await reader.cancel();
+ } catch {}
+ throw new Error("Could not download audio from the configured source.");
+ }
+ const { value, done } = result;
...
if (total > MAX_AUDIO_BYTES) {
- await reader.cancel();
+ try {
+ await reader.cancel();
+ } catch {}
throw new Error("Audio exceeds the 25 MB example limit.");
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const { value, done } = await reader.read(); | |
| if (done) { | |
| break; | |
| } | |
| total += value.byteLength; | |
| if (total > MAX_AUDIO_BYTES) { | |
| await reader.cancel(); | |
| throw new Error("Audio exceeds the 25 MB example limit."); | |
| let result: ReadableStreamReadResult<Uint8Array>; | |
| try { | |
| result = await reader.read(); | |
| } catch { | |
| try { | |
| await reader.cancel(); | |
| } catch {} | |
| throw new Error("Could not download audio from the configured source."); | |
| } | |
| const { value, done } = result; | |
| if (done) { | |
| break; | |
| } | |
| total += value.byteLength; | |
| if (total > MAX_AUDIO_BYTES) { | |
| try { | |
| await reader.cancel(); | |
| } catch {} | |
| throw new Error("Audio exceeds the 25 MB example limit."); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@brainiall-diarized-transcription/src/lib/source.ts` around lines 131 - 138,
Wrap the response-body reading and cancellation flow around reader.read() and
reader.cancel() in the relevant download function with error handling that
replaces any rejection, including errors containing signed URL query data, with
the existing generic download error used by the later fetch error path. Ensure
the reader is still cancelled when the size limit is exceeded, and add a
regression test using a ReadableStream that throws a fake query secret to verify
the redacted error is returned.
Summary
Safety boundaries
Content-Lengthand while streamingmaxAttempts: 1prevents an automatic repeat of a metered requestValidation
npm ci --ignore-scriptsnpm run check— 20 tests passed and TypeScript passedgit diff --checkDependency audit note
npm audit --omit=devreports 19 advisories (1 low, 14 moderate, 4 high, 0 critical), all in the current Trigger.dev 4.5.8 transitive dependency tree. No forced or breaking dependency rewrite was applied in this example.Summary by CodeRabbit
New Features
Security
Documentation
Tests