Skip to content

Add BRAINIALL diarized transcription example - #125

Open
fasuizu-br wants to merge 1 commit into
triggerdotdev:mainfrom
fasuizu-br:agent/brainiall-diarized-transcription
Open

Add BRAINIALL diarized transcription example#125
fasuizu-br wants to merge 1 commit into
triggerdotdev:mainfrom
fasuizu-br:agent/brainiall-diarized-transcription

Conversation

@fasuizu-br

@fasuizu-br fasuizu-br commented Jul 29, 2026

Copy link
Copy Markdown

Summary

  • add a headless Trigger.dev task that transcribes one authorized PT-BR or Spanish audio file with the BRAINIALL API
  • request speaker diarization and return plain text, speaker count, SRT, and WebVTT
  • document setup, privacy, consent, retention, and metered-API boundaries
  • add focused unit tests with mocked source and API responses

Safety boundaries

  • exact HTTPS source-host allowlist with redirect revalidation
  • 25 MB limit enforced from Content-Length and while streaming
  • explicit rights-and-consent confirmation before network access
  • API key remains server-side; network and provider errors are redacted
  • maxAttempts: 1 prevents an automatic repeat of a metered request

Validation

  • npm ci --ignore-scripts
  • npm run check — 20 tests passed and TypeScript passed
  • git diff --check
  • staged secret-pattern scan — only documented empty/example values found

Dependency audit note

npm audit --omit=dev reports 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

    • Added diarized audio transcription for Portuguese and Spanish.
    • Generates speaker-labeled transcripts in SRT and WebVTT formats.
    • Supports secure processing of authorized audio URLs with consent confirmation.
    • Added a ready-to-run Trigger.dev example project.
  • Security

    • Restricts audio sources to approved HTTPS hosts and enforces size limits.
    • Protects credentials and sanitizes error messages.
  • Documentation

    • Added setup, configuration, usage, output, and security guidance.
  • Tests

    • Added coverage for transcription, captions, validation, downloads, redirects, and error handling.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds 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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a BRAINIALL diarized transcription example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fasuizu-br
fasuizu-br marked this pull request as ready for review August 7, 2026 12:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7f6fc1 and c78e6fc.

⛔ Files ignored due to path filters (1)
  • brainiall-diarized-transcription/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • README.md
  • brainiall-diarized-transcription/.env.example
  • brainiall-diarized-transcription/.gitignore
  • brainiall-diarized-transcription/README.md
  • brainiall-diarized-transcription/package.json
  • brainiall-diarized-transcription/src/lib/brainiall.ts
  • brainiall-diarized-transcription/src/lib/captions.ts
  • brainiall-diarized-transcription/src/lib/source.ts
  • brainiall-diarized-transcription/src/lib/workflow.ts
  • brainiall-diarized-transcription/src/trigger/transcribe.ts
  • brainiall-diarized-transcription/tests/brainiall.test.ts
  • brainiall-diarized-transcription/tests/captions.test.ts
  • brainiall-diarized-transcription/tests/source.test.ts
  • brainiall-diarized-transcription/tests/workflow.test.ts
  • brainiall-diarized-transcription/trigger.config.ts
  • brainiall-diarized-transcription/tsconfig.json

Comment on lines +106 to +110
if (
!result ||
/^[,.;:!?%…\)\]\}]/u.test(token) ||
/[\(\[\{]$/u.test(result)
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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.

Comment on lines +131 to +138
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.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant