mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
Compare commits
1 Commits
v0.11.0
...
mathieu/fi
| Author | SHA1 | Date | |
|---|---|---|---|
| 5aed513c47 |
5
.github/workflows/db_migrations.yml
vendored
5
.github/workflows/db_migrations.yml
vendored
@@ -2,8 +2,6 @@ name: Test Database Migrations
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths:
|
paths:
|
||||||
- "server/migrations/**"
|
- "server/migrations/**"
|
||||||
- "server/reflector/db/**"
|
- "server/reflector/db/**"
|
||||||
@@ -19,9 +17,6 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test-migrations:
|
test-migrations:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
concurrency:
|
|
||||||
group: db-ubuntu-latest-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17
|
image: postgres:17
|
||||||
|
|||||||
45
.github/workflows/test_next_server.yml
vendored
45
.github/workflows/test_next_server.yml
vendored
@@ -1,45 +0,0 @@
|
|||||||
name: Test Next Server
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- "www/**"
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths:
|
|
||||||
- "www/**"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test-next-server:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./www
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
|
|
||||||
- name: Install pnpm
|
|
||||||
uses: pnpm/action-setup@v4
|
|
||||||
with:
|
|
||||||
version: 8
|
|
||||||
|
|
||||||
- name: Setup Node.js cache
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
cache: 'pnpm'
|
|
||||||
cache-dependency-path: './www/pnpm-lock.yaml'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: pnpm test
|
|
||||||
11
.github/workflows/test_server.yml
vendored
11
.github/workflows/test_server.yml
vendored
@@ -5,17 +5,12 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- "server/**"
|
- "server/**"
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths:
|
paths:
|
||||||
- "server/**"
|
- "server/**"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pytest:
|
pytest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
concurrency:
|
|
||||||
group: pytest-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
image: redis:6
|
image: redis:6
|
||||||
@@ -35,9 +30,6 @@ jobs:
|
|||||||
|
|
||||||
docker-amd64:
|
docker-amd64:
|
||||||
runs-on: linux-amd64
|
runs-on: linux-amd64
|
||||||
concurrency:
|
|
||||||
group: docker-amd64-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -53,9 +45,6 @@ jobs:
|
|||||||
|
|
||||||
docker-arm64:
|
docker-arm64:
|
||||||
runs-on: linux-arm64
|
runs-on: linux-arm64
|
||||||
concurrency:
|
|
||||||
group: docker-arm64-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,6 +15,3 @@ www/REFACTOR.md
|
|||||||
www/reload-frontend
|
www/reload-frontend
|
||||||
server/test.sqlite
|
server/test.sqlite
|
||||||
CLAUDE.local.md
|
CLAUDE.local.md
|
||||||
www/.env.development
|
|
||||||
www/.env.production
|
|
||||||
.playwright-mcp
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
b9d891d3424f371642cb032ecfd0e2564470a72c:server/tests/test_transcripts_recording_deletion.py:generic-api-key:15
|
|
||||||
@@ -27,8 +27,3 @@ repos:
|
|||||||
files: ^server/
|
files: ^server/
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
files: ^server/
|
files: ^server/
|
||||||
|
|
||||||
- repo: https://github.com/gitleaks/gitleaks
|
|
||||||
rev: v8.28.0
|
|
||||||
hooks:
|
|
||||||
- id: gitleaks
|
|
||||||
|
|||||||
82
CHANGELOG.md
82
CHANGELOG.md
@@ -1,87 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.11.0](https://github.com/Monadical-SAS/reflector/compare/v0.10.0...v0.11.0) (2025-09-16)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* remove profanity filter that was there for conference ([#652](https://github.com/Monadical-SAS/reflector/issues/652)) ([b42f7cf](https://github.com/Monadical-SAS/reflector/commit/b42f7cfc606783afcee792590efcc78b507468ab))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* zulip and consent handler on the file pipeline ([#645](https://github.com/Monadical-SAS/reflector/issues/645)) ([5f143fe](https://github.com/Monadical-SAS/reflector/commit/5f143fe3640875dcb56c26694254a93189281d17))
|
|
||||||
* zulip stream and topic selection in share dialog ([#644](https://github.com/Monadical-SAS/reflector/issues/644)) ([c546e69](https://github.com/Monadical-SAS/reflector/commit/c546e69739e68bb74fbc877eb62609928e5b8de6))
|
|
||||||
|
|
||||||
## [0.10.0](https://github.com/Monadical-SAS/reflector/compare/v0.9.0...v0.10.0) (2025-09-11)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* replace nextjs-config with environment variables ([#632](https://github.com/Monadical-SAS/reflector/issues/632)) ([369ecdf](https://github.com/Monadical-SAS/reflector/commit/369ecdff13f3862d926a9c0b87df52c9d94c4dde))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* anonymous users transcript permissions ([#621](https://github.com/Monadical-SAS/reflector/issues/621)) ([f81fe99](https://github.com/Monadical-SAS/reflector/commit/f81fe9948a9237b3e0001b2d8ca84f54d76878f9))
|
|
||||||
* auth post ([#624](https://github.com/Monadical-SAS/reflector/issues/624)) ([cde99ca](https://github.com/Monadical-SAS/reflector/commit/cde99ca2716f84ba26798f289047732f0448742e))
|
|
||||||
* auth post ([#626](https://github.com/Monadical-SAS/reflector/issues/626)) ([3b85ff3](https://github.com/Monadical-SAS/reflector/commit/3b85ff3bdf4fb053b103070646811bc990c0e70a))
|
|
||||||
* auth post ([#627](https://github.com/Monadical-SAS/reflector/issues/627)) ([962038e](https://github.com/Monadical-SAS/reflector/commit/962038ee3f2a555dc3c03856be0e4409456e0996))
|
|
||||||
* missing follow_redirects=True on modal endpoint ([#630](https://github.com/Monadical-SAS/reflector/issues/630)) ([fc363bd](https://github.com/Monadical-SAS/reflector/commit/fc363bd49b17b075e64f9186e5e0185abc325ea7))
|
|
||||||
* sync backend and frontend token refresh logic ([#614](https://github.com/Monadical-SAS/reflector/issues/614)) ([5a5b323](https://github.com/Monadical-SAS/reflector/commit/5a5b3233820df9536da75e87ce6184a983d4713a))
|
|
||||||
|
|
||||||
## [0.9.0](https://github.com/Monadical-SAS/reflector/compare/v0.8.2...v0.9.0) (2025-09-06)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* frontend openapi react query ([#606](https://github.com/Monadical-SAS/reflector/issues/606)) ([c4d2825](https://github.com/Monadical-SAS/reflector/commit/c4d2825c81f81ad8835629fbf6ea8c7383f8c31b))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* align whisper transcriber api with parakeet ([#602](https://github.com/Monadical-SAS/reflector/issues/602)) ([0663700](https://github.com/Monadical-SAS/reflector/commit/0663700a615a4af69a03c96c410f049e23ec9443))
|
|
||||||
* kv use tls explicit ([#610](https://github.com/Monadical-SAS/reflector/issues/610)) ([08d88ec](https://github.com/Monadical-SAS/reflector/commit/08d88ec349f38b0d13e0fa4cb73486c8dfd31836))
|
|
||||||
* source kind for file processing ([#601](https://github.com/Monadical-SAS/reflector/issues/601)) ([dc82f8b](https://github.com/Monadical-SAS/reflector/commit/dc82f8bb3bdf3ab3d4088e592a30fd63907319e1))
|
|
||||||
* token refresh locking ([#613](https://github.com/Monadical-SAS/reflector/issues/613)) ([7f5a4c9](https://github.com/Monadical-SAS/reflector/commit/7f5a4c9ddc7fd098860c8bdda2ca3b57f63ded2f))
|
|
||||||
|
|
||||||
## [0.8.2](https://github.com/Monadical-SAS/reflector/compare/v0.8.1...v0.8.2) (2025-08-29)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* search-logspam ([#593](https://github.com/Monadical-SAS/reflector/issues/593)) ([695d1a9](https://github.com/Monadical-SAS/reflector/commit/695d1a957d4cd862753049f9beed88836cabd5ab))
|
|
||||||
|
|
||||||
## [0.8.1](https://github.com/Monadical-SAS/reflector/compare/v0.8.0...v0.8.1) (2025-08-29)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* make webhook secret/url allowing null ([#590](https://github.com/Monadical-SAS/reflector/issues/590)) ([84a3812](https://github.com/Monadical-SAS/reflector/commit/84a381220bc606231d08d6f71d4babc818fa3c75))
|
|
||||||
|
|
||||||
## [0.8.0](https://github.com/Monadical-SAS/reflector/compare/v0.7.3...v0.8.0) (2025-08-29)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **cleanup:** add automatic data retention for public instances ([#574](https://github.com/Monadical-SAS/reflector/issues/574)) ([6f0c7c1](https://github.com/Monadical-SAS/reflector/commit/6f0c7c1a5e751713366886c8e764c2009e12ba72))
|
|
||||||
* **rooms:** add webhook for transcript completion ([#578](https://github.com/Monadical-SAS/reflector/issues/578)) ([88ed7cf](https://github.com/Monadical-SAS/reflector/commit/88ed7cfa7804794b9b54cad4c3facc8a98cf85fd))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* file pipeline status reporting and websocket updates ([#589](https://github.com/Monadical-SAS/reflector/issues/589)) ([9dfd769](https://github.com/Monadical-SAS/reflector/commit/9dfd76996f851cc52be54feea078adbc0816dc57))
|
|
||||||
* Igor/evaluation ([#575](https://github.com/Monadical-SAS/reflector/issues/575)) ([124ce03](https://github.com/Monadical-SAS/reflector/commit/124ce03bf86044c18313d27228a25da4bc20c9c5))
|
|
||||||
* optimize parakeet transcription batching algorithm ([#577](https://github.com/Monadical-SAS/reflector/issues/577)) ([7030e0f](https://github.com/Monadical-SAS/reflector/commit/7030e0f23649a8cf6c1eb6d5889684a41ce849ec))
|
|
||||||
|
|
||||||
## [0.7.3](https://github.com/Monadical-SAS/reflector/compare/v0.7.2...v0.7.3) (2025-08-22)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* cleaned repo, and get git-leaks clean ([359280d](https://github.com/Monadical-SAS/reflector/commit/359280dd340433ba4402ed69034094884c825e67))
|
|
||||||
* restore previous behavior on live pipeline + audio downscaler ([#561](https://github.com/Monadical-SAS/reflector/issues/561)) ([9265d20](https://github.com/Monadical-SAS/reflector/commit/9265d201b590d23c628c5f19251b70f473859043))
|
|
||||||
|
|
||||||
## [0.7.2](https://github.com/Monadical-SAS/reflector/compare/v0.7.1...v0.7.2) (2025-08-21)
|
## [0.7.2](https://github.com/Monadical-SAS/reflector/compare/v0.7.1...v0.7.2) (2025-08-21)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ pnpm install
|
|||||||
|
|
||||||
# Copy configuration templates
|
# Copy configuration templates
|
||||||
cp .env_template .env
|
cp .env_template .env
|
||||||
|
cp config-template.ts config.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
**Development:**
|
**Development:**
|
||||||
|
|||||||
81
README.md
81
README.md
@@ -1,60 +1,43 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<img width="100" alt="image" src="https://github.com/user-attachments/assets/66fb367b-2c89-4516-9912-f47ac59c6a7f"/>
|
|
||||||
|
|
||||||
# Reflector
|
# Reflector
|
||||||
|
|
||||||
Reflector is an AI-powered audio transcription and meeting analysis platform that provides real-time transcription, speaker diarization, translation and summarization for audio content and live meetings. It works 100% with local models (whisper/parakeet, pyannote, seamless-m4t, and your local llm like phi-4).
|
Reflector Audio Management and Analysis is a cutting-edge web application under development by Monadical. It utilizes AI to record meetings, providing a permanent record with transcripts, translations, and automated summaries.
|
||||||
|
|
||||||
[](https://github.com/monadical-sas/reflector/actions/workflows/test_server.yml)
|
[](https://github.com/monadical-sas/reflector/actions/workflows/pytests.yml)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
## Screenshots
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="https://github.com/user-attachments/assets/21f5597c-2930-4899-a154-f7bd61a59e97">
|
<a href="https://github.com/user-attachments/assets/3a976930-56c1-47ef-8c76-55d3864309e3">
|
||||||
<img width="700" alt="image" src="https://github.com/user-attachments/assets/21f5597c-2930-4899-a154-f7bd61a59e97" />
|
<img width="700" alt="image" src="https://github.com/user-attachments/assets/3a976930-56c1-47ef-8c76-55d3864309e3" />
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="https://github.com/user-attachments/assets/f6b9399a-5e51-4bae-b807-59128d0a940c">
|
<a href="https://github.com/user-attachments/assets/bfe3bde3-08af-4426-a9a1-11ad5cd63b33">
|
||||||
<img width="700" alt="image" src="https://github.com/user-attachments/assets/f6b9399a-5e51-4bae-b807-59128d0a940c" />
|
<img width="700" alt="image" src="https://github.com/user-attachments/assets/bfe3bde3-08af-4426-a9a1-11ad5cd63b33" />
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="https://github.com/user-attachments/assets/a42ce460-c1fd-4489-a995-270516193897">
|
<a href="https://github.com/user-attachments/assets/7b60c9d0-efe4-474f-a27b-ea13bd0fabdc">
|
||||||
<img width="700" alt="image" src="https://github.com/user-attachments/assets/a42ce460-c1fd-4489-a995-270516193897" />
|
<img width="700" alt="image" src="https://github.com/user-attachments/assets/7b60c9d0-efe4-474f-a27b-ea13bd0fabdc" />
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="https://github.com/user-attachments/assets/21929f6d-c309-42fe-9c11-f1299e50fbd4">
|
|
||||||
<img width="700" alt="image" src="https://github.com/user-attachments/assets/21929f6d-c309-42fe-9c11-f1299e50fbd4" />
|
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
## What is Reflector?
|
|
||||||
|
|
||||||
Reflector is a web application that utilizes local models to process audio content, providing:
|
|
||||||
|
|
||||||
- **Real-time Transcription**: Convert speech to text using [Whisper](https://github.com/openai/whisper) (multi-language) or [Parakeet](https://huggingface.co/nvidia/parakeet-tdt-0.6b-v2) (English) models
|
|
||||||
- **Speaker Diarization**: Identify and label different speakers using [Pyannote](https://github.com/pyannote/pyannote-audio) 3.1
|
|
||||||
- **Live Translation**: Translate audio content in real-time to many languages with [Facebook Seamless-M4T](https://github.com/facebookresearch/seamless_communication)
|
|
||||||
- **Topic Detection & Summarization**: Extract key topics and generate concise summaries using LLMs
|
|
||||||
- **Meeting Recording**: Create permanent records of meetings with searchable transcripts
|
|
||||||
|
|
||||||
Currently we provide [modal.com](https://modal.com/) gpu template to deploy.
|
|
||||||
|
|
||||||
## Background
|
## Background
|
||||||
|
|
||||||
The project architecture consists of three primary components:
|
The project architecture consists of three primary components:
|
||||||
|
|
||||||
- **Back-End**: Python server that offers an API and data persistence, found in `server/`.
|
|
||||||
- **Front-End**: NextJS React project hosted on Vercel, located in `www/`.
|
- **Front-End**: NextJS React project hosted on Vercel, located in `www/`.
|
||||||
- **GPU implementation**: Providing services such as speech-to-text transcription, topic generation, automated summaries, and translations.
|
- **Back-End**: Python server that offers an API and data persistence, found in `server/`.
|
||||||
|
- **GPU implementation**: Providing services such as speech-to-text transcription, topic generation, automated summaries, and translations. Most reliable option is Modal deployment
|
||||||
|
|
||||||
It also uses authentik for authentication if activated.
|
It also uses authentik for authentication if activated, and Vercel for deployment and configuration of the front-end.
|
||||||
|
|
||||||
## Contribution Guidelines
|
## Contribution Guidelines
|
||||||
|
|
||||||
@@ -89,8 +72,6 @@ Note: We currently do not have instructions for Windows users.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
*Note: we're working toward better installation, theses instructions are not accurate for now*
|
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
Start with `cd www`.
|
Start with `cd www`.
|
||||||
@@ -99,10 +80,11 @@ Start with `cd www`.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm install
|
pnpm install
|
||||||
cp .env.example .env
|
cp .env_template .env
|
||||||
|
cp config-template.ts config.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, fill in the environment variables in `.env` as needed. If you are unsure on how to proceed, ask in Zulip.
|
Then, fill in the environment variables in `.env` and the configuration in `config.ts` as needed. If you are unsure on how to proceed, ask in Zulip.
|
||||||
|
|
||||||
**Run in development mode**
|
**Run in development mode**
|
||||||
|
|
||||||
@@ -167,34 +149,3 @@ You can manually process an audio file by calling the process tool:
|
|||||||
```bash
|
```bash
|
||||||
uv run python -m reflector.tools.process path/to/audio.wav
|
uv run python -m reflector.tools.process path/to/audio.wav
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Feature Flags
|
|
||||||
|
|
||||||
Reflector uses environment variable-based feature flags to control application functionality. These flags allow you to enable or disable features without code changes.
|
|
||||||
|
|
||||||
### Available Feature Flags
|
|
||||||
|
|
||||||
| Feature Flag | Environment Variable |
|
|
||||||
|-------------|---------------------|
|
|
||||||
| `requireLogin` | `NEXT_PUBLIC_FEATURE_REQUIRE_LOGIN` |
|
|
||||||
| `privacy` | `NEXT_PUBLIC_FEATURE_PRIVACY` |
|
|
||||||
| `browse` | `NEXT_PUBLIC_FEATURE_BROWSE` |
|
|
||||||
| `sendToZulip` | `NEXT_PUBLIC_FEATURE_SEND_TO_ZULIP` |
|
|
||||||
| `rooms` | `NEXT_PUBLIC_FEATURE_ROOMS` |
|
|
||||||
|
|
||||||
### Setting Feature Flags
|
|
||||||
|
|
||||||
Feature flags are controlled via environment variables using the pattern `NEXT_PUBLIC_FEATURE_{FEATURE_NAME}` where `{FEATURE_NAME}` is the SCREAMING_SNAKE_CASE version of the feature name.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
```bash
|
|
||||||
# Enable user authentication requirement
|
|
||||||
NEXT_PUBLIC_FEATURE_REQUIRE_LOGIN=true
|
|
||||||
|
|
||||||
# Disable browse functionality
|
|
||||||
NEXT_PUBLIC_FEATURE_BROWSE=false
|
|
||||||
|
|
||||||
# Enable Zulip integration
|
|
||||||
NEXT_PUBLIC_FEATURE_SEND_TO_ZULIP=true
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ services:
|
|||||||
- 1250:1250
|
- 1250:1250
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
- /app/.venv
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
@@ -17,7 +16,6 @@ services:
|
|||||||
context: server
|
context: server
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
- /app/.venv
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
@@ -28,7 +26,6 @@ services:
|
|||||||
context: server
|
context: server
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
- /app/.venv
|
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
# Data Retention and Cleanup
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
For public instances of Reflector, a data retention policy is automatically enforced to delete anonymous user data after a configurable period (default: 7 days). This ensures compliance with privacy expectations and prevents unbounded storage growth.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
- `PUBLIC_MODE` (bool): Must be set to `true` to enable automatic cleanup
|
|
||||||
- `PUBLIC_DATA_RETENTION_DAYS` (int): Number of days to retain anonymous data (default: 7)
|
|
||||||
|
|
||||||
### What Gets Deleted
|
|
||||||
|
|
||||||
When data reaches the retention period, the following items are automatically removed:
|
|
||||||
|
|
||||||
1. **Transcripts** from anonymous users (where `user_id` is NULL):
|
|
||||||
- Database records
|
|
||||||
- Local files (audio.wav, audio.mp3, audio.json waveform)
|
|
||||||
- Storage files (cloud storage if configured)
|
|
||||||
|
|
||||||
## Automatic Cleanup
|
|
||||||
|
|
||||||
### Celery Beat Schedule
|
|
||||||
|
|
||||||
When `PUBLIC_MODE=true`, a Celery beat task runs daily at 3 AM to clean up old data:
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Automatically scheduled when PUBLIC_MODE=true
|
|
||||||
"cleanup_old_public_data": {
|
|
||||||
"task": "reflector.worker.cleanup.cleanup_old_public_data",
|
|
||||||
"schedule": crontab(hour=3, minute=0), # Daily at 3 AM
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running the Worker
|
|
||||||
|
|
||||||
Ensure both Celery worker and beat scheduler are running:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Start Celery worker
|
|
||||||
uv run celery -A reflector.worker.app worker --loglevel=info
|
|
||||||
|
|
||||||
# Start Celery beat scheduler (in another terminal)
|
|
||||||
uv run celery -A reflector.worker.app beat
|
|
||||||
```
|
|
||||||
|
|
||||||
## Manual Cleanup
|
|
||||||
|
|
||||||
For testing or manual intervention, use the cleanup tool:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Delete data older than 7 days (default)
|
|
||||||
uv run python -m reflector.tools.cleanup_old_data
|
|
||||||
|
|
||||||
# Delete data older than 30 days
|
|
||||||
uv run python -m reflector.tools.cleanup_old_data --days 30
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: The manual tool uses the same implementation as the Celery worker task to ensure consistency.
|
|
||||||
|
|
||||||
## Important Notes
|
|
||||||
|
|
||||||
1. **User Data Deletion**: Only anonymous data (where `user_id` is NULL) is deleted. Authenticated user data is preserved.
|
|
||||||
|
|
||||||
2. **Storage Cleanup**: The system properly cleans up both local files and cloud storage when configured.
|
|
||||||
|
|
||||||
3. **Error Handling**: If individual deletions fail, the cleanup continues and logs errors. Failed deletions are reported in the task output.
|
|
||||||
|
|
||||||
4. **Public Instance Only**: The automatic cleanup task only runs when `PUBLIC_MODE=true` to prevent accidental data loss in private deployments.
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
Run the cleanup tests:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uv run pytest tests/test_cleanup.py -v
|
|
||||||
```
|
|
||||||
|
|
||||||
## Monitoring
|
|
||||||
|
|
||||||
Check Celery logs for cleanup task execution:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Look for cleanup task logs
|
|
||||||
grep "cleanup_old_public_data" celery.log
|
|
||||||
grep "Starting cleanup of old public data" celery.log
|
|
||||||
```
|
|
||||||
|
|
||||||
Task statistics are logged after each run:
|
|
||||||
- Number of transcripts deleted
|
|
||||||
- Number of meetings deleted
|
|
||||||
- Number of orphaned recordings deleted
|
|
||||||
- Any errors encountered
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
## Reflector GPU Transcription API (Specification)
|
|
||||||
|
|
||||||
This document defines the Reflector GPU transcription API that all implementations must adhere to. Current implementations include NVIDIA Parakeet (NeMo) and Whisper (faster-whisper), both deployed on Modal.com. The API surface and response shapes are OpenAI/Whisper-compatible, so clients can switch implementations by changing only the base URL.
|
|
||||||
|
|
||||||
### Base URL and Authentication
|
|
||||||
|
|
||||||
- Example base URLs (Modal web endpoints):
|
|
||||||
|
|
||||||
- Parakeet: `https://<account>--reflector-transcriber-parakeet-web.modal.run`
|
|
||||||
- Whisper: `https://<account>--reflector-transcriber-web.modal.run`
|
|
||||||
|
|
||||||
- All endpoints are served under `/v1` and require a Bearer token:
|
|
||||||
|
|
||||||
```
|
|
||||||
Authorization: Bearer <REFLECTOR_GPU_APIKEY>
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: To switch implementations, deploy the desired variant and point `TRANSCRIPT_URL` to its base URL. The API is identical.
|
|
||||||
|
|
||||||
### Supported file types
|
|
||||||
|
|
||||||
`mp3, mp4, mpeg, mpga, m4a, wav, webm`
|
|
||||||
|
|
||||||
### Models and languages
|
|
||||||
|
|
||||||
- Parakeet (NVIDIA NeMo): default `nvidia/parakeet-tdt-0.6b-v2`
|
|
||||||
- Language support: only `en`. Other languages return HTTP 400.
|
|
||||||
- Whisper (faster-whisper): default `large-v2` (or deployment-specific)
|
|
||||||
- Language support: multilingual (per Whisper model capabilities).
|
|
||||||
|
|
||||||
Note: The `model` parameter is accepted by all implementations for interface parity. Some backends may treat it as informational.
|
|
||||||
|
|
||||||
### Endpoints
|
|
||||||
|
|
||||||
#### POST /v1/audio/transcriptions
|
|
||||||
|
|
||||||
Transcribe one or more uploaded audio files.
|
|
||||||
|
|
||||||
Request: multipart/form-data
|
|
||||||
|
|
||||||
- `file` (File) — optional. Single file to transcribe.
|
|
||||||
- `files` (File[]) — optional. One or more files to transcribe.
|
|
||||||
- `model` (string) — optional. Defaults to the implementation-specific model (see above).
|
|
||||||
- `language` (string) — optional, defaults to `en`.
|
|
||||||
- Parakeet: only `en` is accepted; other values return HTTP 400
|
|
||||||
- Whisper: model-dependent; typically multilingual
|
|
||||||
- `batch` (boolean) — optional, defaults to `false`.
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
|
|
||||||
- Provide either `file` or `files`, not both. If neither is provided, HTTP 400.
|
|
||||||
- `batch` requires `files`; using `batch=true` without `files` returns HTTP 400.
|
|
||||||
- Response shape for multiple files is the same regardless of `batch`.
|
|
||||||
- Files sent to this endpoint are processed in a single pass (no VAD/chunking). This is intended for short clips (roughly ≤ 30s; depends on GPU memory/model). For longer audio, prefer `/v1/audio/transcriptions-from-url` which supports VAD-based chunking.
|
|
||||||
|
|
||||||
Responses
|
|
||||||
|
|
||||||
Single file response:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"text": "transcribed text",
|
|
||||||
"words": [
|
|
||||||
{ "word": "hello", "start": 0.0, "end": 0.5 },
|
|
||||||
{ "word": "world", "start": 0.5, "end": 1.0 }
|
|
||||||
],
|
|
||||||
"filename": "audio.mp3"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Multiple files response:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"results": [
|
|
||||||
{"filename": "a1.mp3", "text": "...", "words": [...]},
|
|
||||||
{"filename": "a2.mp3", "text": "...", "words": [...]}]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
|
|
||||||
- Word objects always include keys: `word`, `start`, `end`.
|
|
||||||
- Some implementations may include a trailing space in `word` to match Whisper tokenization behavior; clients should trim if needed.
|
|
||||||
|
|
||||||
Example curl (single file):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST \
|
|
||||||
-H "Authorization: Bearer $REFLECTOR_GPU_APIKEY" \
|
|
||||||
-F "file=@/path/to/audio.mp3" \
|
|
||||||
-F "language=en" \
|
|
||||||
"$BASE_URL/v1/audio/transcriptions"
|
|
||||||
```
|
|
||||||
|
|
||||||
Example curl (multiple files, batch):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST \
|
|
||||||
-H "Authorization: Bearer $REFLECTOR_GPU_APIKEY" \
|
|
||||||
-F "files=@/path/a1.mp3" -F "files=@/path/a2.mp3" \
|
|
||||||
-F "batch=true" -F "language=en" \
|
|
||||||
"$BASE_URL/v1/audio/transcriptions"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### POST /v1/audio/transcriptions-from-url
|
|
||||||
|
|
||||||
Transcribe a single remote audio file by URL.
|
|
||||||
|
|
||||||
Request: application/json
|
|
||||||
|
|
||||||
Body parameters:
|
|
||||||
|
|
||||||
- `audio_file_url` (string) — required. URL of the audio file to transcribe.
|
|
||||||
- `model` (string) — optional. Defaults to the implementation-specific model (see above).
|
|
||||||
- `language` (string) — optional, defaults to `en`. Parakeet only accepts `en`.
|
|
||||||
- `timestamp_offset` (number) — optional, defaults to `0.0`. Added to each word's `start`/`end` in the response.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"audio_file_url": "https://example.com/audio.mp3",
|
|
||||||
"model": "nvidia/parakeet-tdt-0.6b-v2",
|
|
||||||
"language": "en",
|
|
||||||
"timestamp_offset": 0.0
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Response:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"text": "transcribed text",
|
|
||||||
"words": [
|
|
||||||
{ "word": "hello", "start": 10.0, "end": 10.5 },
|
|
||||||
{ "word": "world", "start": 10.5, "end": 11.0 }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Notes:
|
|
||||||
|
|
||||||
- `timestamp_offset` is added to each word’s `start`/`end` in the response.
|
|
||||||
- Implementations may perform VAD-based chunking and batching for long-form audio; word timings are adjusted accordingly.
|
|
||||||
|
|
||||||
Example curl:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST \
|
|
||||||
-H "Authorization: Bearer $REFLECTOR_GPU_APIKEY" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"audio_file_url": "https://example.com/audio.mp3",
|
|
||||||
"language": "en",
|
|
||||||
"timestamp_offset": 0
|
|
||||||
}' \
|
|
||||||
"$BASE_URL/v1/audio/transcriptions-from-url"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Error handling
|
|
||||||
|
|
||||||
- 400 Bad Request
|
|
||||||
- Parakeet: `language` other than `en`
|
|
||||||
- Missing required parameters (`file`/`files` for upload; `audio_file_url` for URL endpoint)
|
|
||||||
- Unsupported file extension
|
|
||||||
- 401 Unauthorized
|
|
||||||
- Missing or invalid Bearer token
|
|
||||||
- 404 Not Found
|
|
||||||
- `audio_file_url` does not exist
|
|
||||||
|
|
||||||
### Implementation details
|
|
||||||
|
|
||||||
- GPUs: A10G for small-file/live, L40S for large-file URL transcription (subject to deployment)
|
|
||||||
- VAD chunking and segment batching; word timings adjusted and overlapping ends constrained
|
|
||||||
- Pads very short segments (< 0.5s) to avoid model crashes on some backends
|
|
||||||
|
|
||||||
### Server configuration (Reflector API)
|
|
||||||
|
|
||||||
Set the Reflector server to use the Modal backend and point `TRANSCRIPT_URL` to your chosen deployment:
|
|
||||||
|
|
||||||
```
|
|
||||||
TRANSCRIPT_BACKEND=modal
|
|
||||||
TRANSCRIPT_URL=https://<account>--reflector-transcriber-parakeet-web.modal.run
|
|
||||||
TRANSCRIPT_MODAL_API_KEY=<REFLECTOR_GPU_APIKEY>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Conformance tests
|
|
||||||
|
|
||||||
Use the pytest-based conformance tests to validate any new implementation (including self-hosted) against this spec:
|
|
||||||
|
|
||||||
```
|
|
||||||
TRANSCRIPT_URL=https://<your-deployment-base> \
|
|
||||||
TRANSCRIPT_MODAL_API_KEY=your-api-key \
|
|
||||||
uv run -m pytest -m gpu_modal --no-cov server/tests/test_gpu_modal_transcript.py
|
|
||||||
```
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
# Reflector Webhook Documentation
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
Reflector supports webhook notifications to notify external systems when transcript processing is completed. Webhooks can be configured per room and are triggered automatically after a transcript is successfully processed.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Webhooks are configured at the room level with two fields:
|
|
||||||
- `webhook_url`: The HTTPS endpoint to receive webhook notifications
|
|
||||||
- `webhook_secret`: Optional secret key for HMAC signature verification (auto-generated if not provided)
|
|
||||||
|
|
||||||
## Events
|
|
||||||
|
|
||||||
### `transcript.completed`
|
|
||||||
|
|
||||||
Triggered when a transcript has been fully processed, including transcription, diarization, summarization, and topic detection.
|
|
||||||
|
|
||||||
### `test`
|
|
||||||
|
|
||||||
A test event that can be triggered manually to verify webhook configuration.
|
|
||||||
|
|
||||||
## Webhook Request Format
|
|
||||||
|
|
||||||
### Headers
|
|
||||||
|
|
||||||
All webhook requests include the following headers:
|
|
||||||
|
|
||||||
| Header | Description | Example |
|
|
||||||
|--------|-------------|---------|
|
|
||||||
| `Content-Type` | Always `application/json` | `application/json` |
|
|
||||||
| `User-Agent` | Identifies Reflector as the source | `Reflector-Webhook/1.0` |
|
|
||||||
| `X-Webhook-Event` | The event type | `transcript.completed` or `test` |
|
|
||||||
| `X-Webhook-Retry` | Current retry attempt number | `0`, `1`, `2`... |
|
|
||||||
| `X-Webhook-Signature` | HMAC signature (if secret configured) | `t=1735306800,v1=abc123...` |
|
|
||||||
|
|
||||||
### Signature Verification
|
|
||||||
|
|
||||||
If a webhook secret is configured, Reflector includes an HMAC-SHA256 signature in the `X-Webhook-Signature` header to verify the webhook authenticity.
|
|
||||||
|
|
||||||
The signature format is: `t={timestamp},v1={signature}`
|
|
||||||
|
|
||||||
To verify the signature:
|
|
||||||
1. Extract the timestamp and signature from the header
|
|
||||||
2. Create the signed payload: `{timestamp}.{request_body}`
|
|
||||||
3. Compute HMAC-SHA256 of the signed payload using your webhook secret
|
|
||||||
4. Compare the computed signature with the received signature
|
|
||||||
|
|
||||||
Example verification (Python):
|
|
||||||
```python
|
|
||||||
import hmac
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
def verify_webhook_signature(payload: bytes, signature_header: str, secret: str) -> bool:
|
|
||||||
# Parse header: "t=1735306800,v1=abc123..."
|
|
||||||
parts = dict(part.split("=") for part in signature_header.split(","))
|
|
||||||
timestamp = parts["t"]
|
|
||||||
received_signature = parts["v1"]
|
|
||||||
|
|
||||||
# Create signed payload
|
|
||||||
signed_payload = f"{timestamp}.{payload.decode('utf-8')}"
|
|
||||||
|
|
||||||
# Compute expected signature
|
|
||||||
expected_signature = hmac.new(
|
|
||||||
secret.encode("utf-8"),
|
|
||||||
signed_payload.encode("utf-8"),
|
|
||||||
hashlib.sha256
|
|
||||||
).hexdigest()
|
|
||||||
|
|
||||||
# Compare signatures
|
|
||||||
return hmac.compare_digest(expected_signature, received_signature)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Event Payloads
|
|
||||||
|
|
||||||
### `transcript.completed` Event
|
|
||||||
|
|
||||||
This event includes a convenient URL for accessing the transcript:
|
|
||||||
- `frontend_url`: Direct link to view the transcript in the web interface
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"event": "transcript.completed",
|
|
||||||
"event_id": "transcript.completed-abc-123-def-456",
|
|
||||||
"timestamp": "2025-08-27T12:34:56.789012Z",
|
|
||||||
"transcript": {
|
|
||||||
"id": "abc-123-def-456",
|
|
||||||
"room_id": "room-789",
|
|
||||||
"created_at": "2025-08-27T12:00:00Z",
|
|
||||||
"duration": 1800.5,
|
|
||||||
"title": "Q3 Product Planning Meeting",
|
|
||||||
"short_summary": "Team discussed Q3 product roadmap, prioritizing mobile app features and API improvements.",
|
|
||||||
"long_summary": "The product team met to finalize the Q3 roadmap. Key decisions included...",
|
|
||||||
"webvtt": "WEBVTT\n\n00:00:00.000 --> 00:00:05.000\n<v Speaker 1>Welcome everyone to today's meeting...",
|
|
||||||
"topics": [
|
|
||||||
{
|
|
||||||
"title": "Introduction and Agenda",
|
|
||||||
"summary": "Meeting kickoff with agenda review",
|
|
||||||
"timestamp": 0.0,
|
|
||||||
"duration": 120.0,
|
|
||||||
"webvtt": "WEBVTT\n\n00:00:00.000 --> 00:00:05.000\n<v Speaker 1>Welcome everyone..."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Mobile App Features Discussion",
|
|
||||||
"summary": "Team reviewed proposed mobile app features for Q3",
|
|
||||||
"timestamp": 120.0,
|
|
||||||
"duration": 600.0,
|
|
||||||
"webvtt": "WEBVTT\n\n00:02:00.000 --> 00:02:10.000\n<v Speaker 2>Let's talk about the mobile app..."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"participants": [
|
|
||||||
{
|
|
||||||
"id": "participant-1",
|
|
||||||
"name": "John Doe",
|
|
||||||
"speaker": "Speaker 1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "participant-2",
|
|
||||||
"name": "Jane Smith",
|
|
||||||
"speaker": "Speaker 2"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source_language": "en",
|
|
||||||
"target_language": "en",
|
|
||||||
"status": "completed",
|
|
||||||
"frontend_url": "https://app.reflector.com/transcripts/abc-123-def-456"
|
|
||||||
},
|
|
||||||
"room": {
|
|
||||||
"id": "room-789",
|
|
||||||
"name": "Product Team Room"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `test` Event
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"event": "test",
|
|
||||||
"event_id": "test.2025-08-27T12:34:56.789012Z",
|
|
||||||
"timestamp": "2025-08-27T12:34:56.789012Z",
|
|
||||||
"message": "This is a test webhook from Reflector",
|
|
||||||
"room": {
|
|
||||||
"id": "room-789",
|
|
||||||
"name": "Product Team Room"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Retry Policy
|
|
||||||
|
|
||||||
Webhooks are delivered with automatic retry logic to handle transient failures. When a webhook delivery fails due to server errors or network issues, Reflector will automatically retry the delivery multiple times over an extended period.
|
|
||||||
|
|
||||||
### Retry Mechanism
|
|
||||||
|
|
||||||
Reflector implements an exponential backoff strategy for webhook retries:
|
|
||||||
|
|
||||||
- **Initial retry delay**: 60 seconds after the first failure
|
|
||||||
- **Exponential backoff**: Each subsequent retry waits approximately twice as long as the previous one
|
|
||||||
- **Maximum retry interval**: 1 hour (backoff is capped at this duration)
|
|
||||||
- **Maximum retry attempts**: 30 attempts total
|
|
||||||
- **Total retry duration**: Retries continue for approximately 24 hours
|
|
||||||
|
|
||||||
### How Retries Work
|
|
||||||
|
|
||||||
When a webhook fails, Reflector will:
|
|
||||||
1. Wait 60 seconds, then retry (attempt #1)
|
|
||||||
2. If it fails again, wait ~2 minutes, then retry (attempt #2)
|
|
||||||
3. Continue doubling the wait time up to a maximum of 1 hour between attempts
|
|
||||||
4. Keep retrying at 1-hour intervals until successful or 30 attempts are exhausted
|
|
||||||
|
|
||||||
The `X-Webhook-Retry` header indicates the current retry attempt number (0 for the initial attempt, 1 for first retry, etc.), allowing your endpoint to track retry attempts.
|
|
||||||
|
|
||||||
### Retry Behavior by HTTP Status Code
|
|
||||||
|
|
||||||
| Status Code | Behavior |
|
|
||||||
|-------------|----------|
|
|
||||||
| 2xx (Success) | No retry, webhook marked as delivered |
|
|
||||||
| 4xx (Client Error) | No retry, request is considered permanently failed |
|
|
||||||
| 5xx (Server Error) | Automatic retry with exponential backoff |
|
|
||||||
| Network/Timeout Error | Automatic retry with exponential backoff |
|
|
||||||
|
|
||||||
**Important Notes:**
|
|
||||||
- Webhooks timeout after 30 seconds. If your endpoint takes longer to respond, it will be considered a timeout error and retried.
|
|
||||||
- During the retry period (~24 hours), you may receive the same webhook multiple times if your endpoint experiences intermittent failures.
|
|
||||||
- There is no mechanism to manually retry failed webhooks after the retry period expires.
|
|
||||||
|
|
||||||
## Testing Webhooks
|
|
||||||
|
|
||||||
You can test your webhook configuration before processing transcripts:
|
|
||||||
|
|
||||||
```http
|
|
||||||
POST /v1/rooms/{room_id}/webhook/test
|
|
||||||
```
|
|
||||||
|
|
||||||
Response:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"status_code": 200,
|
|
||||||
"message": "Webhook test successful",
|
|
||||||
"response_preview": "OK"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Or in case of failure:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": false,
|
|
||||||
"error": "Webhook request timed out (10 seconds)"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1,78 +1,41 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import uuid
|
|
||||||
from typing import Generator, Mapping, NamedTuple, NewType, TypedDict
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import modal
|
import modal
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
MODELS_DIR = "/models"
|
||||||
|
|
||||||
MODEL_NAME = "large-v2"
|
MODEL_NAME = "large-v2"
|
||||||
MODEL_COMPUTE_TYPE: str = "float16"
|
MODEL_COMPUTE_TYPE: str = "float16"
|
||||||
MODEL_NUM_WORKERS: int = 1
|
MODEL_NUM_WORKERS: int = 1
|
||||||
|
|
||||||
MINUTES = 60 # seconds
|
MINUTES = 60 # seconds
|
||||||
SAMPLERATE = 16000
|
|
||||||
UPLOADS_PATH = "/uploads"
|
|
||||||
CACHE_PATH = "/models"
|
|
||||||
SUPPORTED_FILE_EXTENSIONS = ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"]
|
|
||||||
VAD_CONFIG = {
|
|
||||||
"batch_max_duration": 30.0,
|
|
||||||
"silence_padding": 0.5,
|
|
||||||
"window_size": 512,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
volume = modal.Volume.from_name("models", create_if_missing=True)
|
||||||
WhisperUniqFilename = NewType("WhisperUniqFilename", str)
|
|
||||||
AudioFileExtension = NewType("AudioFileExtension", str)
|
|
||||||
|
|
||||||
app = modal.App("reflector-transcriber")
|
app = modal.App("reflector-transcriber")
|
||||||
|
|
||||||
model_cache = modal.Volume.from_name("models", create_if_missing=True)
|
|
||||||
upload_volume = modal.Volume.from_name("whisper-uploads", create_if_missing=True)
|
|
||||||
|
|
||||||
|
|
||||||
class TimeSegment(NamedTuple):
|
|
||||||
"""Represents a time segment with start and end times."""
|
|
||||||
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
|
|
||||||
|
|
||||||
class AudioSegment(NamedTuple):
|
|
||||||
"""Represents an audio segment with timing and audio data."""
|
|
||||||
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
audio: any
|
|
||||||
|
|
||||||
|
|
||||||
class TranscriptResult(NamedTuple):
|
|
||||||
"""Represents a transcription result with text and word timings."""
|
|
||||||
|
|
||||||
text: str
|
|
||||||
words: list["WordTiming"]
|
|
||||||
|
|
||||||
|
|
||||||
class WordTiming(TypedDict):
|
|
||||||
"""Represents a word with its timing information."""
|
|
||||||
|
|
||||||
word: str
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
|
|
||||||
|
|
||||||
def download_model():
|
def download_model():
|
||||||
from faster_whisper import download_model
|
from faster_whisper import download_model
|
||||||
|
|
||||||
model_cache.reload()
|
volume.reload()
|
||||||
|
|
||||||
download_model(MODEL_NAME, cache_dir=CACHE_PATH)
|
download_model(MODEL_NAME, cache_dir=MODELS_DIR)
|
||||||
|
|
||||||
model_cache.commit()
|
volume.commit()
|
||||||
|
|
||||||
|
|
||||||
image = (
|
image = (
|
||||||
modal.Image.debian_slim(python_version="3.12")
|
modal.Image.debian_slim(python_version="3.12")
|
||||||
|
.pip_install(
|
||||||
|
"huggingface_hub==0.27.1",
|
||||||
|
"hf-transfer==0.1.9",
|
||||||
|
"torch==2.5.1",
|
||||||
|
"faster-whisper==1.1.1",
|
||||||
|
)
|
||||||
.env(
|
.env(
|
||||||
{
|
{
|
||||||
"HF_HUB_ENABLE_HF_TRANSFER": "1",
|
"HF_HUB_ENABLE_HF_TRANSFER": "1",
|
||||||
@@ -82,98 +45,19 @@ image = (
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.apt_install("ffmpeg")
|
.run_function(download_model, volumes={MODELS_DIR: volume})
|
||||||
.pip_install(
|
|
||||||
"huggingface_hub==0.27.1",
|
|
||||||
"hf-transfer==0.1.9",
|
|
||||||
"torch==2.5.1",
|
|
||||||
"faster-whisper==1.1.1",
|
|
||||||
"fastapi==0.115.12",
|
|
||||||
"requests",
|
|
||||||
"librosa==0.10.1",
|
|
||||||
"numpy<2",
|
|
||||||
"silero-vad==5.1.0",
|
|
||||||
)
|
|
||||||
.run_function(download_model, volumes={CACHE_PATH: model_cache})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def detect_audio_format(url: str, headers: Mapping[str, str]) -> AudioFileExtension:
|
|
||||||
parsed_url = urlparse(url)
|
|
||||||
url_path = parsed_url.path
|
|
||||||
|
|
||||||
for ext in SUPPORTED_FILE_EXTENSIONS:
|
|
||||||
if url_path.lower().endswith(f".{ext}"):
|
|
||||||
return AudioFileExtension(ext)
|
|
||||||
|
|
||||||
content_type = headers.get("content-type", "").lower()
|
|
||||||
if "audio/mpeg" in content_type or "audio/mp3" in content_type:
|
|
||||||
return AudioFileExtension("mp3")
|
|
||||||
if "audio/wav" in content_type:
|
|
||||||
return AudioFileExtension("wav")
|
|
||||||
if "audio/mp4" in content_type:
|
|
||||||
return AudioFileExtension("mp4")
|
|
||||||
|
|
||||||
raise ValueError(
|
|
||||||
f"Unsupported audio format for URL: {url}. "
|
|
||||||
f"Supported extensions: {', '.join(SUPPORTED_FILE_EXTENSIONS)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def download_audio_to_volume(
|
|
||||||
audio_file_url: str,
|
|
||||||
) -> tuple[WhisperUniqFilename, AudioFileExtension]:
|
|
||||||
import requests
|
|
||||||
from fastapi import HTTPException
|
|
||||||
|
|
||||||
response = requests.head(audio_file_url, allow_redirects=True)
|
|
||||||
if response.status_code == 404:
|
|
||||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
|
||||||
|
|
||||||
response = requests.get(audio_file_url, allow_redirects=True)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
audio_suffix = detect_audio_format(audio_file_url, response.headers)
|
|
||||||
unique_filename = WhisperUniqFilename(f"{uuid.uuid4()}.{audio_suffix}")
|
|
||||||
file_path = f"{UPLOADS_PATH}/{unique_filename}"
|
|
||||||
|
|
||||||
with open(file_path, "wb") as f:
|
|
||||||
f.write(response.content)
|
|
||||||
|
|
||||||
upload_volume.commit()
|
|
||||||
return unique_filename, audio_suffix
|
|
||||||
|
|
||||||
|
|
||||||
def pad_audio(audio_array, sample_rate: int = SAMPLERATE):
|
|
||||||
"""Add 0.5s of silence if audio is shorter than the silence_padding window.
|
|
||||||
|
|
||||||
Whisper does not require this strictly, but aligning behavior with Parakeet
|
|
||||||
avoids edge-case crashes on extremely short inputs and makes comparisons easier.
|
|
||||||
"""
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
audio_duration = len(audio_array) / sample_rate
|
|
||||||
if audio_duration < VAD_CONFIG["silence_padding"]:
|
|
||||||
silence_samples = int(sample_rate * VAD_CONFIG["silence_padding"])
|
|
||||||
silence = np.zeros(silence_samples, dtype=np.float32)
|
|
||||||
return np.concatenate([audio_array, silence])
|
|
||||||
return audio_array
|
|
||||||
|
|
||||||
|
|
||||||
@app.cls(
|
@app.cls(
|
||||||
gpu="A10G",
|
gpu="A10G",
|
||||||
timeout=5 * MINUTES,
|
timeout=5 * MINUTES,
|
||||||
scaledown_window=5 * MINUTES,
|
scaledown_window=5 * MINUTES,
|
||||||
|
allow_concurrent_inputs=6,
|
||||||
image=image,
|
image=image,
|
||||||
volumes={CACHE_PATH: model_cache, UPLOADS_PATH: upload_volume},
|
volumes={MODELS_DIR: volume},
|
||||||
)
|
)
|
||||||
@modal.concurrent(max_inputs=10)
|
class Transcriber:
|
||||||
class TranscriberWhisperLive:
|
|
||||||
"""Live transcriber class for small audio segments (A10G).
|
|
||||||
|
|
||||||
Mirrors the Parakeet live class API but uses Faster-Whisper under the hood.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@modal.enter()
|
@modal.enter()
|
||||||
def enter(self):
|
def enter(self):
|
||||||
import faster_whisper
|
import faster_whisper
|
||||||
@@ -187,200 +71,23 @@ class TranscriberWhisperLive:
|
|||||||
device=self.device,
|
device=self.device,
|
||||||
compute_type=MODEL_COMPUTE_TYPE,
|
compute_type=MODEL_COMPUTE_TYPE,
|
||||||
num_workers=MODEL_NUM_WORKERS,
|
num_workers=MODEL_NUM_WORKERS,
|
||||||
download_root=CACHE_PATH,
|
download_root=MODELS_DIR,
|
||||||
local_files_only=True,
|
local_files_only=True,
|
||||||
)
|
)
|
||||||
print(f"Model is on device: {self.device}")
|
|
||||||
|
|
||||||
@modal.method()
|
@modal.method()
|
||||||
def transcribe_segment(
|
def transcribe_segment(
|
||||||
self,
|
self,
|
||||||
filename: str,
|
audio_data: str,
|
||||||
language: str = "en",
|
audio_suffix: str,
|
||||||
|
language: str,
|
||||||
):
|
):
|
||||||
"""Transcribe a single uploaded audio file by filename."""
|
with tempfile.NamedTemporaryFile("wb+", suffix=f".{audio_suffix}") as fp:
|
||||||
upload_volume.reload()
|
fp.write(audio_data)
|
||||||
|
|
||||||
file_path = f"{UPLOADS_PATH}/{filename}"
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
raise FileNotFoundError(f"File not found: {file_path}")
|
|
||||||
|
|
||||||
with self.lock:
|
|
||||||
with NoStdStreams():
|
|
||||||
segments, _ = self.model.transcribe(
|
|
||||||
file_path,
|
|
||||||
language=language,
|
|
||||||
beam_size=5,
|
|
||||||
word_timestamps=True,
|
|
||||||
vad_filter=True,
|
|
||||||
vad_parameters={"min_silence_duration_ms": 500},
|
|
||||||
)
|
|
||||||
|
|
||||||
segments = list(segments)
|
|
||||||
text = "".join(segment.text for segment in segments).strip()
|
|
||||||
words = [
|
|
||||||
{
|
|
||||||
"word": word.word,
|
|
||||||
"start": round(float(word.start), 2),
|
|
||||||
"end": round(float(word.end), 2),
|
|
||||||
}
|
|
||||||
for segment in segments
|
|
||||||
for word in segment.words
|
|
||||||
]
|
|
||||||
|
|
||||||
return {"text": text, "words": words}
|
|
||||||
|
|
||||||
@modal.method()
|
|
||||||
def transcribe_batch(
|
|
||||||
self,
|
|
||||||
filenames: list[str],
|
|
||||||
language: str = "en",
|
|
||||||
):
|
|
||||||
"""Transcribe multiple uploaded audio files and return per-file results."""
|
|
||||||
upload_volume.reload()
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for filename in filenames:
|
|
||||||
file_path = f"{UPLOADS_PATH}/{filename}"
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
raise FileNotFoundError(f"Batch file not found: {file_path}")
|
|
||||||
|
|
||||||
with self.lock:
|
|
||||||
with NoStdStreams():
|
|
||||||
segments, _ = self.model.transcribe(
|
|
||||||
file_path,
|
|
||||||
language=language,
|
|
||||||
beam_size=5,
|
|
||||||
word_timestamps=True,
|
|
||||||
vad_filter=True,
|
|
||||||
vad_parameters={"min_silence_duration_ms": 500},
|
|
||||||
)
|
|
||||||
|
|
||||||
segments = list(segments)
|
|
||||||
text = "".join(seg.text for seg in segments).strip()
|
|
||||||
words = [
|
|
||||||
{
|
|
||||||
"word": w.word,
|
|
||||||
"start": round(float(w.start), 2),
|
|
||||||
"end": round(float(w.end), 2),
|
|
||||||
}
|
|
||||||
for seg in segments
|
|
||||||
for w in seg.words
|
|
||||||
]
|
|
||||||
|
|
||||||
results.append(
|
|
||||||
{
|
|
||||||
"filename": filename,
|
|
||||||
"text": text,
|
|
||||||
"words": words,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
@app.cls(
|
|
||||||
gpu="L40S",
|
|
||||||
timeout=15 * MINUTES,
|
|
||||||
image=image,
|
|
||||||
volumes={CACHE_PATH: model_cache, UPLOADS_PATH: upload_volume},
|
|
||||||
)
|
|
||||||
class TranscriberWhisperFile:
|
|
||||||
"""File transcriber for larger/longer audio, using VAD-driven batching (L40S)."""
|
|
||||||
|
|
||||||
@modal.enter()
|
|
||||||
def enter(self):
|
|
||||||
import faster_whisper
|
|
||||||
import torch
|
|
||||||
from silero_vad import load_silero_vad
|
|
||||||
|
|
||||||
self.lock = threading.Lock()
|
|
||||||
self.use_gpu = torch.cuda.is_available()
|
|
||||||
self.device = "cuda" if self.use_gpu else "cpu"
|
|
||||||
self.model = faster_whisper.WhisperModel(
|
|
||||||
MODEL_NAME,
|
|
||||||
device=self.device,
|
|
||||||
compute_type=MODEL_COMPUTE_TYPE,
|
|
||||||
num_workers=MODEL_NUM_WORKERS,
|
|
||||||
download_root=CACHE_PATH,
|
|
||||||
local_files_only=True,
|
|
||||||
)
|
|
||||||
self.vad_model = load_silero_vad(onnx=False)
|
|
||||||
|
|
||||||
@modal.method()
|
|
||||||
def transcribe_segment(
|
|
||||||
self, filename: str, timestamp_offset: float = 0.0, language: str = "en"
|
|
||||||
):
|
|
||||||
import librosa
|
|
||||||
import numpy as np
|
|
||||||
from silero_vad import VADIterator
|
|
||||||
|
|
||||||
def vad_segments(
|
|
||||||
audio_array,
|
|
||||||
sample_rate: int = SAMPLERATE,
|
|
||||||
window_size: int = VAD_CONFIG["window_size"],
|
|
||||||
) -> Generator[TimeSegment, None, None]:
|
|
||||||
"""Generate speech segments as TimeSegment using Silero VAD."""
|
|
||||||
iterator = VADIterator(self.vad_model, sampling_rate=sample_rate)
|
|
||||||
start = None
|
|
||||||
for i in range(0, len(audio_array), window_size):
|
|
||||||
chunk = audio_array[i : i + window_size]
|
|
||||||
if len(chunk) < window_size:
|
|
||||||
chunk = np.pad(
|
|
||||||
chunk, (0, window_size - len(chunk)), mode="constant"
|
|
||||||
)
|
|
||||||
speech = iterator(chunk)
|
|
||||||
if not speech:
|
|
||||||
continue
|
|
||||||
if "start" in speech:
|
|
||||||
start = speech["start"]
|
|
||||||
continue
|
|
||||||
if "end" in speech and start is not None:
|
|
||||||
end = speech["end"]
|
|
||||||
yield TimeSegment(
|
|
||||||
start / float(SAMPLERATE), end / float(SAMPLERATE)
|
|
||||||
)
|
|
||||||
start = None
|
|
||||||
iterator.reset_states()
|
|
||||||
|
|
||||||
upload_volume.reload()
|
|
||||||
file_path = f"{UPLOADS_PATH}/{filename}"
|
|
||||||
if not os.path.exists(file_path):
|
|
||||||
raise FileNotFoundError(f"File not found: {file_path}")
|
|
||||||
|
|
||||||
audio_array, _sr = librosa.load(file_path, sr=SAMPLERATE, mono=True)
|
|
||||||
|
|
||||||
# Batch segments up to ~30s windows by merging contiguous VAD segments
|
|
||||||
merged_batches: list[TimeSegment] = []
|
|
||||||
batch_start = None
|
|
||||||
batch_end = None
|
|
||||||
max_duration = VAD_CONFIG["batch_max_duration"]
|
|
||||||
for segment in vad_segments(audio_array):
|
|
||||||
seg_start, seg_end = segment.start, segment.end
|
|
||||||
if batch_start is None:
|
|
||||||
batch_start, batch_end = seg_start, seg_end
|
|
||||||
continue
|
|
||||||
if seg_end - batch_start <= max_duration:
|
|
||||||
batch_end = seg_end
|
|
||||||
else:
|
|
||||||
merged_batches.append(TimeSegment(batch_start, batch_end))
|
|
||||||
batch_start, batch_end = seg_start, seg_end
|
|
||||||
if batch_start is not None and batch_end is not None:
|
|
||||||
merged_batches.append(TimeSegment(batch_start, batch_end))
|
|
||||||
|
|
||||||
all_text = []
|
|
||||||
all_words = []
|
|
||||||
|
|
||||||
for segment in merged_batches:
|
|
||||||
start_time, end_time = segment.start, segment.end
|
|
||||||
s_idx = int(start_time * SAMPLERATE)
|
|
||||||
e_idx = int(end_time * SAMPLERATE)
|
|
||||||
segment = audio_array[s_idx:e_idx]
|
|
||||||
segment = pad_audio(segment, SAMPLERATE)
|
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
segments, _ = self.model.transcribe(
|
segments, _ = self.model.transcribe(
|
||||||
segment,
|
fp.name,
|
||||||
language=language,
|
language=language,
|
||||||
beam_size=5,
|
beam_size=5,
|
||||||
word_timestamps=True,
|
word_timestamps=True,
|
||||||
@@ -389,220 +96,66 @@ class TranscriberWhisperFile:
|
|||||||
)
|
)
|
||||||
|
|
||||||
segments = list(segments)
|
segments = list(segments)
|
||||||
text = "".join(seg.text for seg in segments).strip()
|
text = "".join(segment.text for segment in segments)
|
||||||
words = [
|
words = [
|
||||||
{
|
{"word": word.word, "start": word.start, "end": word.end}
|
||||||
"word": w.word,
|
for segment in segments
|
||||||
"start": round(float(w.start) + start_time + timestamp_offset, 2),
|
for word in segment.words
|
||||||
"end": round(float(w.end) + start_time + timestamp_offset, 2),
|
|
||||||
}
|
|
||||||
for seg in segments
|
|
||||||
for w in seg.words
|
|
||||||
]
|
]
|
||||||
if text:
|
|
||||||
all_text.append(text)
|
|
||||||
all_words.extend(words)
|
|
||||||
|
|
||||||
return {"text": " ".join(all_text), "words": all_words}
|
return {"text": text, "words": words}
|
||||||
|
|
||||||
|
|
||||||
def detect_audio_format(url: str, headers: dict) -> str:
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
from fastapi import HTTPException
|
|
||||||
|
|
||||||
url_path = urlparse(url).path
|
|
||||||
for ext in SUPPORTED_FILE_EXTENSIONS:
|
|
||||||
if url_path.lower().endswith(f".{ext}"):
|
|
||||||
return ext
|
|
||||||
|
|
||||||
content_type = headers.get("content-type", "").lower()
|
|
||||||
if "audio/mpeg" in content_type or "audio/mp3" in content_type:
|
|
||||||
return "mp3"
|
|
||||||
if "audio/wav" in content_type:
|
|
||||||
return "wav"
|
|
||||||
if "audio/mp4" in content_type:
|
|
||||||
return "mp4"
|
|
||||||
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=400,
|
|
||||||
detail=(
|
|
||||||
f"Unsupported audio format for URL. Supported extensions: {', '.join(SUPPORTED_FILE_EXTENSIONS)}"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def download_audio_to_volume(audio_file_url: str) -> tuple[str, str]:
|
|
||||||
import requests
|
|
||||||
from fastapi import HTTPException
|
|
||||||
|
|
||||||
response = requests.head(audio_file_url, allow_redirects=True)
|
|
||||||
if response.status_code == 404:
|
|
||||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
|
||||||
|
|
||||||
response = requests.get(audio_file_url, allow_redirects=True)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
audio_suffix = detect_audio_format(audio_file_url, response.headers)
|
|
||||||
unique_filename = f"{uuid.uuid4()}.{audio_suffix}"
|
|
||||||
file_path = f"{UPLOADS_PATH}/{unique_filename}"
|
|
||||||
|
|
||||||
with open(file_path, "wb") as f:
|
|
||||||
f.write(response.content)
|
|
||||||
|
|
||||||
upload_volume.commit()
|
|
||||||
return unique_filename, audio_suffix
|
|
||||||
|
|
||||||
|
|
||||||
@app.function(
|
@app.function(
|
||||||
scaledown_window=60,
|
scaledown_window=60,
|
||||||
timeout=600,
|
timeout=60,
|
||||||
|
allow_concurrent_inputs=40,
|
||||||
secrets=[
|
secrets=[
|
||||||
modal.Secret.from_name("reflector-gpu"),
|
modal.Secret.from_name("reflector-gpu"),
|
||||||
],
|
],
|
||||||
volumes={CACHE_PATH: model_cache, UPLOADS_PATH: upload_volume},
|
volumes={MODELS_DIR: volume},
|
||||||
image=image,
|
|
||||||
)
|
)
|
||||||
@modal.concurrent(max_inputs=40)
|
|
||||||
@modal.asgi_app()
|
@modal.asgi_app()
|
||||||
def web():
|
def web():
|
||||||
from fastapi import (
|
from fastapi import Body, Depends, FastAPI, HTTPException, UploadFile, status
|
||||||
Body,
|
|
||||||
Depends,
|
|
||||||
FastAPI,
|
|
||||||
Form,
|
|
||||||
HTTPException,
|
|
||||||
UploadFile,
|
|
||||||
status,
|
|
||||||
)
|
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
transcriber_live = TranscriberWhisperLive()
|
transcriber = Transcriber()
|
||||||
transcriber_file = TranscriberWhisperFile()
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
|
|
||||||
def apikey_auth(apikey: str = Depends(oauth2_scheme)):
|
supported_file_types = ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"]
|
||||||
if apikey == os.environ["REFLECTOR_GPU_APIKEY"]:
|
|
||||||
return
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail="Invalid API key",
|
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
|
||||||
)
|
|
||||||
|
|
||||||
class TranscriptResponse(dict):
|
def apikey_auth(apikey: str = Depends(oauth2_scheme)):
|
||||||
pass
|
if apikey != os.environ["REFLECTOR_GPU_APIKEY"]:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="Invalid API key",
|
||||||
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
|
)
|
||||||
|
|
||||||
|
class TranscriptResponse(BaseModel):
|
||||||
|
result: dict
|
||||||
|
|
||||||
@app.post("/v1/audio/transcriptions", dependencies=[Depends(apikey_auth)])
|
@app.post("/v1/audio/transcriptions", dependencies=[Depends(apikey_auth)])
|
||||||
def transcribe(
|
def transcribe(
|
||||||
file: UploadFile = None,
|
file: UploadFile,
|
||||||
files: list[UploadFile] | None = None,
|
model: str = "whisper-1",
|
||||||
model: str = Form(MODEL_NAME),
|
language: Annotated[str, Body(...)] = "en",
|
||||||
language: str = Form("en"),
|
) -> TranscriptResponse:
|
||||||
batch: bool = Form(False),
|
audio_data = file.file.read()
|
||||||
):
|
audio_suffix = file.filename.split(".")[-1]
|
||||||
if not file and not files:
|
assert audio_suffix in supported_file_types
|
||||||
raise HTTPException(
|
|
||||||
status_code=400, detail="Either 'file' or 'files' parameter is required"
|
|
||||||
)
|
|
||||||
if batch and not files:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=400, detail="Batch transcription requires 'files'"
|
|
||||||
)
|
|
||||||
|
|
||||||
upload_files = [file] if file else files
|
func = transcriber.transcribe_segment.spawn(
|
||||||
|
audio_data=audio_data,
|
||||||
uploaded_filenames: list[str] = []
|
audio_suffix=audio_suffix,
|
||||||
for upload_file in upload_files:
|
language=language,
|
||||||
audio_suffix = upload_file.filename.split(".")[-1]
|
)
|
||||||
if audio_suffix not in SUPPORTED_FILE_EXTENSIONS:
|
result = func.get()
|
||||||
raise HTTPException(
|
return result
|
||||||
status_code=400,
|
|
||||||
detail=(
|
|
||||||
f"Unsupported audio format. Supported extensions: {', '.join(SUPPORTED_FILE_EXTENSIONS)}"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
unique_filename = f"{uuid.uuid4()}.{audio_suffix}"
|
|
||||||
file_path = f"{UPLOADS_PATH}/{unique_filename}"
|
|
||||||
with open(file_path, "wb") as f:
|
|
||||||
content = upload_file.file.read()
|
|
||||||
f.write(content)
|
|
||||||
uploaded_filenames.append(unique_filename)
|
|
||||||
|
|
||||||
upload_volume.commit()
|
|
||||||
|
|
||||||
try:
|
|
||||||
if batch and len(upload_files) > 1:
|
|
||||||
func = transcriber_live.transcribe_batch.spawn(
|
|
||||||
filenames=uploaded_filenames,
|
|
||||||
language=language,
|
|
||||||
)
|
|
||||||
results = func.get()
|
|
||||||
return {"results": results}
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for filename in uploaded_filenames:
|
|
||||||
func = transcriber_live.transcribe_segment.spawn(
|
|
||||||
filename=filename,
|
|
||||||
language=language,
|
|
||||||
)
|
|
||||||
result = func.get()
|
|
||||||
result["filename"] = filename
|
|
||||||
results.append(result)
|
|
||||||
|
|
||||||
return {"results": results} if len(results) > 1 else results[0]
|
|
||||||
finally:
|
|
||||||
for filename in uploaded_filenames:
|
|
||||||
try:
|
|
||||||
file_path = f"{UPLOADS_PATH}/{filename}"
|
|
||||||
os.remove(file_path)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
upload_volume.commit()
|
|
||||||
|
|
||||||
@app.post("/v1/audio/transcriptions-from-url", dependencies=[Depends(apikey_auth)])
|
|
||||||
def transcribe_from_url(
|
|
||||||
audio_file_url: str = Body(
|
|
||||||
..., description="URL of the audio file to transcribe"
|
|
||||||
),
|
|
||||||
model: str = Body(MODEL_NAME),
|
|
||||||
language: str = Body("en"),
|
|
||||||
timestamp_offset: float = Body(0.0),
|
|
||||||
):
|
|
||||||
unique_filename, _audio_suffix = download_audio_to_volume(audio_file_url)
|
|
||||||
try:
|
|
||||||
func = transcriber_file.transcribe_segment.spawn(
|
|
||||||
filename=unique_filename,
|
|
||||||
timestamp_offset=timestamp_offset,
|
|
||||||
language=language,
|
|
||||||
)
|
|
||||||
result = func.get()
|
|
||||||
return result
|
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
file_path = f"{UPLOADS_PATH}/{unique_filename}"
|
|
||||||
os.remove(file_path)
|
|
||||||
upload_volume.commit()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
class NoStdStreams:
|
|
||||||
def __init__(self):
|
|
||||||
self.devnull = open(os.devnull, "w")
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
self._stdout, self._stderr = sys.stdout, sys.stderr
|
|
||||||
self._stdout.flush()
|
|
||||||
self._stderr.flush()
|
|
||||||
sys.stdout, sys.stderr = self.devnull, self.devnull
|
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
|
||||||
sys.stdout, sys.stderr = self._stdout, self._stderr
|
|
||||||
self.devnull.close()
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Generator, Mapping, NamedTuple, NewType, TypedDict
|
from typing import Mapping, NewType
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import modal
|
import modal
|
||||||
@@ -14,7 +14,10 @@ SAMPLERATE = 16000
|
|||||||
UPLOADS_PATH = "/uploads"
|
UPLOADS_PATH = "/uploads"
|
||||||
CACHE_PATH = "/cache"
|
CACHE_PATH = "/cache"
|
||||||
VAD_CONFIG = {
|
VAD_CONFIG = {
|
||||||
"batch_max_duration": 30.0,
|
"max_segment_duration": 30.0,
|
||||||
|
"batch_max_files": 10,
|
||||||
|
"batch_max_duration": 5.0,
|
||||||
|
"min_segment_duration": 0.02,
|
||||||
"silence_padding": 0.5,
|
"silence_padding": 0.5,
|
||||||
"window_size": 512,
|
"window_size": 512,
|
||||||
}
|
}
|
||||||
@@ -22,37 +25,6 @@ VAD_CONFIG = {
|
|||||||
ParakeetUniqFilename = NewType("ParakeetUniqFilename", str)
|
ParakeetUniqFilename = NewType("ParakeetUniqFilename", str)
|
||||||
AudioFileExtension = NewType("AudioFileExtension", str)
|
AudioFileExtension = NewType("AudioFileExtension", str)
|
||||||
|
|
||||||
|
|
||||||
class TimeSegment(NamedTuple):
|
|
||||||
"""Represents a time segment with start and end times."""
|
|
||||||
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
|
|
||||||
|
|
||||||
class AudioSegment(NamedTuple):
|
|
||||||
"""Represents an audio segment with timing and audio data."""
|
|
||||||
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
audio: any
|
|
||||||
|
|
||||||
|
|
||||||
class TranscriptResult(NamedTuple):
|
|
||||||
"""Represents a transcription result with text and word timings."""
|
|
||||||
|
|
||||||
text: str
|
|
||||||
words: list["WordTiming"]
|
|
||||||
|
|
||||||
|
|
||||||
class WordTiming(TypedDict):
|
|
||||||
"""Represents a word with its timing information."""
|
|
||||||
|
|
||||||
word: str
|
|
||||||
start: float
|
|
||||||
end: float
|
|
||||||
|
|
||||||
|
|
||||||
app = modal.App("reflector-transcriber-parakeet")
|
app = modal.App("reflector-transcriber-parakeet")
|
||||||
|
|
||||||
# Volume for caching model weights
|
# Volume for caching model weights
|
||||||
@@ -198,14 +170,12 @@ class TranscriberParakeetLive:
|
|||||||
(output,) = self.model.transcribe([padded_audio], timestamps=True)
|
(output,) = self.model.transcribe([padded_audio], timestamps=True)
|
||||||
|
|
||||||
text = output.text.strip()
|
text = output.text.strip()
|
||||||
words: list[WordTiming] = [
|
words = [
|
||||||
WordTiming(
|
{
|
||||||
# XXX the space added here is to match the output of whisper
|
"word": word_info["word"] + " ",
|
||||||
# whisper add space to each words, while parakeet don't
|
"start": round(word_info["start"], 2),
|
||||||
word=word_info["word"] + " ",
|
"end": round(word_info["end"], 2),
|
||||||
start=round(word_info["start"], 2),
|
}
|
||||||
end=round(word_info["end"], 2),
|
|
||||||
)
|
|
||||||
for word_info in output.timestamp["word"]
|
for word_info in output.timestamp["word"]
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -241,12 +211,12 @@ class TranscriberParakeetLive:
|
|||||||
for i, (filename, output) in enumerate(zip(filenames, outputs)):
|
for i, (filename, output) in enumerate(zip(filenames, outputs)):
|
||||||
text = output.text.strip()
|
text = output.text.strip()
|
||||||
|
|
||||||
words: list[WordTiming] = [
|
words = [
|
||||||
WordTiming(
|
{
|
||||||
word=word_info["word"] + " ",
|
"word": word_info["word"] + " ",
|
||||||
start=round(word_info["start"], 2),
|
"start": round(word_info["start"], 2),
|
||||||
end=round(word_info["end"], 2),
|
"end": round(word_info["end"], 2),
|
||||||
)
|
}
|
||||||
for word_info in output.timestamp["word"]
|
for word_info in output.timestamp["word"]
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -301,9 +271,7 @@ class TranscriberParakeetFile:
|
|||||||
audio_array, sample_rate = librosa.load(file_path, sr=SAMPLERATE, mono=True)
|
audio_array, sample_rate = librosa.load(file_path, sr=SAMPLERATE, mono=True)
|
||||||
return audio_array
|
return audio_array
|
||||||
|
|
||||||
def vad_segment_generator(
|
def vad_segment_generator(audio_array):
|
||||||
audio_array,
|
|
||||||
) -> Generator[TimeSegment, None, None]:
|
|
||||||
"""Generate speech segments using VAD with start/end sample indices"""
|
"""Generate speech segments using VAD with start/end sample indices"""
|
||||||
vad_iterator = VADIterator(self.vad_model, sampling_rate=SAMPLERATE)
|
vad_iterator = VADIterator(self.vad_model, sampling_rate=SAMPLERATE)
|
||||||
window_size = VAD_CONFIG["window_size"]
|
window_size = VAD_CONFIG["window_size"]
|
||||||
@@ -329,121 +297,107 @@ class TranscriberParakeetFile:
|
|||||||
start_time = start / float(SAMPLERATE)
|
start_time = start / float(SAMPLERATE)
|
||||||
end_time = end / float(SAMPLERATE)
|
end_time = end / float(SAMPLERATE)
|
||||||
|
|
||||||
yield TimeSegment(start_time, end_time)
|
# Extract the actual audio segment
|
||||||
|
audio_segment = audio_array[start:end]
|
||||||
|
|
||||||
|
yield (start_time, end_time, audio_segment)
|
||||||
start = None
|
start = None
|
||||||
|
|
||||||
vad_iterator.reset_states()
|
vad_iterator.reset_states()
|
||||||
|
|
||||||
def batch_speech_segments(
|
def vad_segment_filter(segments):
|
||||||
segments: Generator[TimeSegment, None, None], max_duration: int
|
"""Filter VAD segments by duration and chunk large segments"""
|
||||||
) -> Generator[TimeSegment, None, None]:
|
min_dur = VAD_CONFIG["min_segment_duration"]
|
||||||
"""
|
max_dur = VAD_CONFIG["max_segment_duration"]
|
||||||
Input segments:
|
|
||||||
[0-2] [3-5] [6-8] [10-11] [12-15] [17-19] [20-22]
|
|
||||||
|
|
||||||
↓ (max_duration=10)
|
for start_time, end_time, audio_segment in segments:
|
||||||
|
segment_duration = end_time - start_time
|
||||||
|
|
||||||
Output batches:
|
# Skip very small segments
|
||||||
[0-8] [10-19] [20-22]
|
if segment_duration < min_dur:
|
||||||
|
|
||||||
Note: silences are kept for better transcription, previous implementation was
|
|
||||||
passing segments separatly, but the output was less accurate.
|
|
||||||
"""
|
|
||||||
batch_start_time = None
|
|
||||||
batch_end_time = None
|
|
||||||
|
|
||||||
for segment in segments:
|
|
||||||
start_time, end_time = segment.start, segment.end
|
|
||||||
if batch_start_time is None or batch_end_time is None:
|
|
||||||
batch_start_time = start_time
|
|
||||||
batch_end_time = end_time
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
total_duration = end_time - batch_start_time
|
# If segment is within max duration, yield as-is
|
||||||
|
if segment_duration <= max_dur:
|
||||||
if total_duration <= max_duration:
|
yield (start_time, end_time, audio_segment)
|
||||||
batch_end_time = end_time
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield TimeSegment(batch_start_time, batch_end_time)
|
# Chunk large segments into smaller pieces
|
||||||
batch_start_time = start_time
|
chunk_samples = int(max_dur * SAMPLERATE)
|
||||||
batch_end_time = end_time
|
current_start = start_time
|
||||||
|
|
||||||
if batch_start_time is None or batch_end_time is None:
|
for chunk_offset in range(0, len(audio_segment), chunk_samples):
|
||||||
return
|
chunk_audio = audio_segment[
|
||||||
|
chunk_offset : chunk_offset + chunk_samples
|
||||||
|
]
|
||||||
|
if len(chunk_audio) == 0:
|
||||||
|
break
|
||||||
|
|
||||||
yield TimeSegment(batch_start_time, batch_end_time)
|
chunk_duration = len(chunk_audio) / float(SAMPLERATE)
|
||||||
|
chunk_end = current_start + chunk_duration
|
||||||
|
|
||||||
def batch_segment_to_audio_segment(
|
# Only yield chunks that meet minimum duration
|
||||||
segments: Generator[TimeSegment, None, None],
|
if chunk_duration >= min_dur:
|
||||||
audio_array,
|
yield (current_start, chunk_end, chunk_audio)
|
||||||
) -> Generator[AudioSegment, None, None]:
|
|
||||||
"""Extract audio segments and apply padding for Parakeet compatibility.
|
|
||||||
|
|
||||||
Uses pad_audio to ensure segments are at least 0.5s long, preventing
|
current_start = chunk_end
|
||||||
Parakeet crashes. This padding may cause slight timing overlaps between
|
|
||||||
segments, which are corrected by enforce_word_timing_constraints.
|
|
||||||
"""
|
|
||||||
for segment in segments:
|
|
||||||
start_time, end_time = segment.start, segment.end
|
|
||||||
start_sample = int(start_time * SAMPLERATE)
|
|
||||||
end_sample = int(end_time * SAMPLERATE)
|
|
||||||
audio_segment = audio_array[start_sample:end_sample]
|
|
||||||
|
|
||||||
padded_segment = pad_audio(audio_segment, SAMPLERATE)
|
def batch_segments(segments, max_files=10, max_duration=5.0):
|
||||||
|
batch = []
|
||||||
|
batch_duration = 0.0
|
||||||
|
|
||||||
yield AudioSegment(start_time, end_time, padded_segment)
|
for start_time, end_time, audio_segment in segments:
|
||||||
|
segment_duration = end_time - start_time
|
||||||
|
|
||||||
def transcribe_batch(model, audio_segments: list) -> list:
|
if segment_duration < VAD_CONFIG["silence_padding"]:
|
||||||
|
silence_samples = int(
|
||||||
|
(VAD_CONFIG["silence_padding"] - segment_duration) * SAMPLERATE
|
||||||
|
)
|
||||||
|
padding = np.zeros(silence_samples, dtype=np.float32)
|
||||||
|
audio_segment = np.concatenate([audio_segment, padding])
|
||||||
|
segment_duration = VAD_CONFIG["silence_padding"]
|
||||||
|
|
||||||
|
batch.append((start_time, end_time, audio_segment))
|
||||||
|
batch_duration += segment_duration
|
||||||
|
|
||||||
|
if len(batch) >= max_files or batch_duration >= max_duration:
|
||||||
|
yield batch
|
||||||
|
batch = []
|
||||||
|
batch_duration = 0.0
|
||||||
|
|
||||||
|
if batch:
|
||||||
|
yield batch
|
||||||
|
|
||||||
|
def transcribe_batch(model, audio_segments):
|
||||||
with NoStdStreams():
|
with NoStdStreams():
|
||||||
outputs = model.transcribe(audio_segments, timestamps=True)
|
outputs = model.transcribe(audio_segments, timestamps=True)
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def enforce_word_timing_constraints(
|
|
||||||
words: list[WordTiming],
|
|
||||||
) -> list[WordTiming]:
|
|
||||||
"""Enforce that word end times don't exceed the start time of the next word.
|
|
||||||
|
|
||||||
Due to silence padding added in batch_segment_to_audio_segment for better
|
|
||||||
transcription accuracy, word timings from different segments may overlap.
|
|
||||||
This function ensures there are no overlaps by adjusting end times.
|
|
||||||
"""
|
|
||||||
if len(words) <= 1:
|
|
||||||
return words
|
|
||||||
|
|
||||||
enforced_words = []
|
|
||||||
for i, word in enumerate(words):
|
|
||||||
enforced_word = word.copy()
|
|
||||||
|
|
||||||
if i < len(words) - 1:
|
|
||||||
next_start = words[i + 1]["start"]
|
|
||||||
if enforced_word["end"] > next_start:
|
|
||||||
enforced_word["end"] = next_start
|
|
||||||
|
|
||||||
enforced_words.append(enforced_word)
|
|
||||||
|
|
||||||
return enforced_words
|
|
||||||
|
|
||||||
def emit_results(
|
def emit_results(
|
||||||
results: list,
|
results,
|
||||||
segments_info: list[AudioSegment],
|
segments_info,
|
||||||
) -> Generator[TranscriptResult, None, None]:
|
batch_index,
|
||||||
|
total_batches,
|
||||||
|
):
|
||||||
"""Yield transcribed text and word timings from model output, adjusting timestamps to absolute positions."""
|
"""Yield transcribed text and word timings from model output, adjusting timestamps to absolute positions."""
|
||||||
for i, (output, segment) in enumerate(zip(results, segments_info)):
|
for i, (output, (start_time, end_time, _)) in enumerate(
|
||||||
start_time, end_time = segment.start, segment.end
|
zip(results, segments_info)
|
||||||
|
):
|
||||||
text = output.text.strip()
|
text = output.text.strip()
|
||||||
words: list[WordTiming] = [
|
words = [
|
||||||
WordTiming(
|
{
|
||||||
word=word_info["word"] + " ",
|
"word": word_info["word"] + " ",
|
||||||
start=round(
|
"start": round(
|
||||||
word_info["start"] + start_time + timestamp_offset, 2
|
word_info["start"] + start_time + timestamp_offset, 2
|
||||||
),
|
),
|
||||||
end=round(word_info["end"] + start_time + timestamp_offset, 2),
|
"end": round(
|
||||||
)
|
word_info["end"] + start_time + timestamp_offset, 2
|
||||||
|
),
|
||||||
|
}
|
||||||
for word_info in output.timestamp["word"]
|
for word_info in output.timestamp["word"]
|
||||||
]
|
]
|
||||||
|
|
||||||
yield TranscriptResult(text, words)
|
yield text, words
|
||||||
|
|
||||||
upload_volume.reload()
|
upload_volume.reload()
|
||||||
|
|
||||||
@@ -453,31 +407,41 @@ class TranscriberParakeetFile:
|
|||||||
|
|
||||||
audio_array = load_and_convert_audio(file_path)
|
audio_array = load_and_convert_audio(file_path)
|
||||||
total_duration = len(audio_array) / float(SAMPLERATE)
|
total_duration = len(audio_array) / float(SAMPLERATE)
|
||||||
|
processed_duration = 0.0
|
||||||
|
|
||||||
all_text_parts: list[str] = []
|
all_text_parts = []
|
||||||
all_words: list[WordTiming] = []
|
all_words = []
|
||||||
|
|
||||||
raw_segments = vad_segment_generator(audio_array)
|
raw_segments = vad_segment_generator(audio_array)
|
||||||
speech_segments = batch_speech_segments(
|
filtered_segments = vad_segment_filter(raw_segments)
|
||||||
raw_segments,
|
batches = batch_segments(
|
||||||
|
filtered_segments,
|
||||||
|
VAD_CONFIG["batch_max_files"],
|
||||||
VAD_CONFIG["batch_max_duration"],
|
VAD_CONFIG["batch_max_duration"],
|
||||||
)
|
)
|
||||||
audio_segments = batch_segment_to_audio_segment(speech_segments, audio_array)
|
|
||||||
|
|
||||||
for batch in audio_segments:
|
batch_index = 0
|
||||||
audio_segment = batch.audio
|
total_batches = max(
|
||||||
results = transcribe_batch(self.model, [audio_segment])
|
1, int(total_duration / VAD_CONFIG["batch_max_duration"]) + 1
|
||||||
|
)
|
||||||
|
|
||||||
for result in emit_results(
|
for batch in batches:
|
||||||
|
batch_index += 1
|
||||||
|
audio_segments = [seg[2] for seg in batch]
|
||||||
|
results = transcribe_batch(self.model, audio_segments)
|
||||||
|
|
||||||
|
for text, words in emit_results(
|
||||||
results,
|
results,
|
||||||
[batch],
|
batch,
|
||||||
|
batch_index,
|
||||||
|
total_batches,
|
||||||
):
|
):
|
||||||
if not result.text:
|
if not text:
|
||||||
continue
|
continue
|
||||||
all_text_parts.append(result.text)
|
all_text_parts.append(text)
|
||||||
all_words.extend(result.words)
|
all_words.extend(words)
|
||||||
|
|
||||||
all_words = enforce_word_timing_constraints(all_words)
|
processed_duration += sum(len(seg[2]) / float(SAMPLERATE) for seg in batch)
|
||||||
|
|
||||||
combined_text = " ".join(all_text_parts)
|
combined_text = " ".join(all_text_parts)
|
||||||
return {"text": combined_text, "words": all_words}
|
return {"text": combined_text, "words": all_words}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
"""Add webhook fields to rooms
|
|
||||||
|
|
||||||
Revision ID: 0194f65cd6d3
|
|
||||||
Revises: 5a8907fd1d78
|
|
||||||
Create Date: 2025-08-27 09:03:19.610995
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "0194f65cd6d3"
|
|
||||||
down_revision: Union[str, None] = "5a8907fd1d78"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("room", schema=None) as batch_op:
|
|
||||||
batch_op.add_column(sa.Column("webhook_url", sa.String(), nullable=True))
|
|
||||||
batch_op.add_column(sa.Column("webhook_secret", sa.String(), nullable=True))
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("room", schema=None) as batch_op:
|
|
||||||
batch_op.drop_column("webhook_secret")
|
|
||||||
batch_op.drop_column("webhook_url")
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
"""remove user_id from meeting table
|
|
||||||
|
|
||||||
Revision ID: 0ce521cda2ee
|
|
||||||
Revises: 6dec9fb5b46c
|
|
||||||
Create Date: 2025-09-10 12:40:55.688899
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "0ce521cda2ee"
|
|
||||||
down_revision: Union[str, None] = "6dec9fb5b46c"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.drop_column("user_id")
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.add_column(
|
|
||||||
sa.Column("user_id", sa.VARCHAR(), autoincrement=False, nullable=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
"""clean up orphaned room_id references in meeting table
|
|
||||||
|
|
||||||
Revision ID: 2ae3db106d4e
|
|
||||||
Revises: def1b5867d4c
|
|
||||||
Create Date: 2025-09-11 10:35:15.759967
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "2ae3db106d4e"
|
|
||||||
down_revision: Union[str, None] = "def1b5867d4c"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# Set room_id to NULL for meetings that reference non-existent rooms
|
|
||||||
op.execute("""
|
|
||||||
UPDATE meeting
|
|
||||||
SET room_id = NULL
|
|
||||||
WHERE room_id IS NOT NULL
|
|
||||||
AND room_id NOT IN (SELECT id FROM room WHERE id IS NOT NULL)
|
|
||||||
""")
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# Cannot restore orphaned references - no operation needed
|
|
||||||
pass
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
"""add cascade delete to meeting consent foreign key
|
|
||||||
|
|
||||||
Revision ID: 5a8907fd1d78
|
|
||||||
Revises: 0ab2d7ffaa16
|
|
||||||
Create Date: 2025-08-26 17:26:50.945491
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "5a8907fd1d78"
|
|
||||||
down_revision: Union[str, None] = "0ab2d7ffaa16"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting_consent", schema=None) as batch_op:
|
|
||||||
batch_op.drop_constraint(
|
|
||||||
batch_op.f("meeting_consent_meeting_id_fkey"), type_="foreignkey"
|
|
||||||
)
|
|
||||||
batch_op.create_foreign_key(
|
|
||||||
batch_op.f("meeting_consent_meeting_id_fkey"),
|
|
||||||
"meeting",
|
|
||||||
["meeting_id"],
|
|
||||||
["id"],
|
|
||||||
ondelete="CASCADE",
|
|
||||||
)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting_consent", schema=None) as batch_op:
|
|
||||||
batch_op.drop_constraint(
|
|
||||||
batch_op.f("meeting_consent_meeting_id_fkey"), type_="foreignkey"
|
|
||||||
)
|
|
||||||
batch_op.create_foreign_key(
|
|
||||||
batch_op.f("meeting_consent_meeting_id_fkey"),
|
|
||||||
"meeting",
|
|
||||||
["meeting_id"],
|
|
||||||
["id"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
"""webhook url and secret null by default
|
|
||||||
|
|
||||||
|
|
||||||
Revision ID: 61882a919591
|
|
||||||
Revises: 0194f65cd6d3
|
|
||||||
Create Date: 2025-08-29 11:46:36.738091
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "61882a919591"
|
|
||||||
down_revision: Union[str, None] = "0194f65cd6d3"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
pass
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
"""make meeting room_id required and add foreign key
|
|
||||||
|
|
||||||
Revision ID: 6dec9fb5b46c
|
|
||||||
Revises: 61882a919591
|
|
||||||
Create Date: 2025-09-10 10:47:06.006819
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "6dec9fb5b46c"
|
|
||||||
down_revision: Union[str, None] = "61882a919591"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.alter_column("room_id", existing_type=sa.VARCHAR(), nullable=False)
|
|
||||||
batch_op.create_foreign_key(
|
|
||||||
None, "room", ["room_id"], ["id"], ondelete="CASCADE"
|
|
||||||
)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.drop_constraint("meeting_room_id_fkey", type_="foreignkey")
|
|
||||||
batch_op.alter_column("room_id", existing_type=sa.VARCHAR(), nullable=True)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
"""make meeting room_id nullable but keep foreign key
|
|
||||||
|
|
||||||
Revision ID: def1b5867d4c
|
|
||||||
Revises: 0ce521cda2ee
|
|
||||||
Create Date: 2025-09-11 09:42:18.697264
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = "def1b5867d4c"
|
|
||||||
down_revision: Union[str, None] = "0ce521cda2ee"
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.alter_column("room_id", existing_type=sa.VARCHAR(), nullable=True)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
with op.batch_alter_table("meeting", schema=None) as batch_op:
|
|
||||||
batch_op.alter_column("room_id", existing_type=sa.VARCHAR(), nullable=False)
|
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
@@ -27,6 +27,7 @@ dependencies = [
|
|||||||
"prometheus-fastapi-instrumentator>=6.1.0",
|
"prometheus-fastapi-instrumentator>=6.1.0",
|
||||||
"sentencepiece>=0.1.99",
|
"sentencepiece>=0.1.99",
|
||||||
"protobuf>=4.24.3",
|
"protobuf>=4.24.3",
|
||||||
|
"profanityfilter>=2.0.6",
|
||||||
"celery>=5.3.4",
|
"celery>=5.3.4",
|
||||||
"redis>=5.0.1",
|
"redis>=5.0.1",
|
||||||
"python-jose[cryptography]>=3.3.0",
|
"python-jose[cryptography]>=3.3.0",
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
import functools
|
|
||||||
|
|
||||||
from reflector.db import get_database
|
|
||||||
|
|
||||||
|
|
||||||
def asynctask(f):
|
|
||||||
@functools.wraps(f)
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
async def run_with_db():
|
|
||||||
database = get_database()
|
|
||||||
await database.connect()
|
|
||||||
try:
|
|
||||||
return await f(*args, **kwargs)
|
|
||||||
finally:
|
|
||||||
await database.disconnect()
|
|
||||||
|
|
||||||
coro = run_with_db()
|
|
||||||
try:
|
|
||||||
loop = asyncio.get_running_loop()
|
|
||||||
except RuntimeError:
|
|
||||||
loop = None
|
|
||||||
if loop and loop.is_running():
|
|
||||||
return loop.run_until_complete(coro)
|
|
||||||
return asyncio.run(coro)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
@@ -2,6 +2,7 @@ from datetime import datetime
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from fastapi import HTTPException
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from reflector.db import get_database, metadata
|
from reflector.db import get_database, metadata
|
||||||
@@ -17,12 +18,8 @@ meetings = sa.Table(
|
|||||||
sa.Column("host_room_url", sa.String),
|
sa.Column("host_room_url", sa.String),
|
||||||
sa.Column("start_date", sa.DateTime(timezone=True)),
|
sa.Column("start_date", sa.DateTime(timezone=True)),
|
||||||
sa.Column("end_date", sa.DateTime(timezone=True)),
|
sa.Column("end_date", sa.DateTime(timezone=True)),
|
||||||
sa.Column(
|
sa.Column("user_id", sa.String),
|
||||||
"room_id",
|
sa.Column("room_id", sa.String),
|
||||||
sa.String,
|
|
||||||
sa.ForeignKey("room.id", ondelete="CASCADE"),
|
|
||||||
nullable=True,
|
|
||||||
),
|
|
||||||
sa.Column("is_locked", sa.Boolean, nullable=False, server_default=sa.false()),
|
sa.Column("is_locked", sa.Boolean, nullable=False, server_default=sa.false()),
|
||||||
sa.Column("room_mode", sa.String, nullable=False, server_default="normal"),
|
sa.Column("room_mode", sa.String, nullable=False, server_default="normal"),
|
||||||
sa.Column("recording_type", sa.String, nullable=False, server_default="cloud"),
|
sa.Column("recording_type", sa.String, nullable=False, server_default="cloud"),
|
||||||
@@ -57,12 +54,7 @@ meeting_consent = sa.Table(
|
|||||||
"meeting_consent",
|
"meeting_consent",
|
||||||
metadata,
|
metadata,
|
||||||
sa.Column("id", sa.String, primary_key=True),
|
sa.Column("id", sa.String, primary_key=True),
|
||||||
sa.Column(
|
sa.Column("meeting_id", sa.String, sa.ForeignKey("meeting.id"), nullable=False),
|
||||||
"meeting_id",
|
|
||||||
sa.String,
|
|
||||||
sa.ForeignKey("meeting.id", ondelete="CASCADE"),
|
|
||||||
nullable=False,
|
|
||||||
),
|
|
||||||
sa.Column("user_id", sa.String),
|
sa.Column("user_id", sa.String),
|
||||||
sa.Column("consent_given", sa.Boolean, nullable=False),
|
sa.Column("consent_given", sa.Boolean, nullable=False),
|
||||||
sa.Column("consent_timestamp", sa.DateTime(timezone=True), nullable=False),
|
sa.Column("consent_timestamp", sa.DateTime(timezone=True), nullable=False),
|
||||||
@@ -84,7 +76,8 @@ class Meeting(BaseModel):
|
|||||||
host_room_url: str
|
host_room_url: str
|
||||||
start_date: datetime
|
start_date: datetime
|
||||||
end_date: datetime
|
end_date: datetime
|
||||||
room_id: str | None
|
user_id: str | None = None
|
||||||
|
room_id: str | None = None
|
||||||
is_locked: bool = False
|
is_locked: bool = False
|
||||||
room_mode: Literal["normal", "group"] = "normal"
|
room_mode: Literal["normal", "group"] = "normal"
|
||||||
recording_type: Literal["none", "local", "cloud"] = "cloud"
|
recording_type: Literal["none", "local", "cloud"] = "cloud"
|
||||||
@@ -103,8 +96,12 @@ class MeetingController:
|
|||||||
host_room_url: str,
|
host_room_url: str,
|
||||||
start_date: datetime,
|
start_date: datetime,
|
||||||
end_date: datetime,
|
end_date: datetime,
|
||||||
|
user_id: str,
|
||||||
room: Room,
|
room: Room,
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Create a new meeting
|
||||||
|
"""
|
||||||
meeting = Meeting(
|
meeting = Meeting(
|
||||||
id=id,
|
id=id,
|
||||||
room_name=room_name,
|
room_name=room_name,
|
||||||
@@ -112,6 +109,7 @@ class MeetingController:
|
|||||||
host_room_url=host_room_url,
|
host_room_url=host_room_url,
|
||||||
start_date=start_date,
|
start_date=start_date,
|
||||||
end_date=end_date,
|
end_date=end_date,
|
||||||
|
user_id=user_id,
|
||||||
room_id=room.id,
|
room_id=room.id,
|
||||||
is_locked=room.is_locked,
|
is_locked=room.is_locked,
|
||||||
room_mode=room.room_mode,
|
room_mode=room.room_mode,
|
||||||
@@ -123,13 +121,19 @@ class MeetingController:
|
|||||||
return meeting
|
return meeting
|
||||||
|
|
||||||
async def get_all_active(self) -> list[Meeting]:
|
async def get_all_active(self) -> list[Meeting]:
|
||||||
|
"""
|
||||||
|
Get active meetings.
|
||||||
|
"""
|
||||||
query = meetings.select().where(meetings.c.is_active)
|
query = meetings.select().where(meetings.c.is_active)
|
||||||
return await get_database().fetch_all(query)
|
return await get_database().fetch_all(query)
|
||||||
|
|
||||||
async def get_by_room_name(
|
async def get_by_room_name(
|
||||||
self,
|
self,
|
||||||
room_name: str,
|
room_name: str,
|
||||||
) -> Meeting | None:
|
) -> Meeting:
|
||||||
|
"""
|
||||||
|
Get a meeting by room name.
|
||||||
|
"""
|
||||||
query = meetings.select().where(meetings.c.room_name == room_name)
|
query = meetings.select().where(meetings.c.room_name == room_name)
|
||||||
result = await get_database().fetch_one(query)
|
result = await get_database().fetch_one(query)
|
||||||
if not result:
|
if not result:
|
||||||
@@ -137,7 +141,10 @@ class MeetingController:
|
|||||||
|
|
||||||
return Meeting(**result)
|
return Meeting(**result)
|
||||||
|
|
||||||
async def get_active(self, room: Room, current_time: datetime) -> Meeting | None:
|
async def get_active(self, room: Room, current_time: datetime) -> Meeting:
|
||||||
|
"""
|
||||||
|
Get latest active meeting for a room.
|
||||||
|
"""
|
||||||
end_date = getattr(meetings.c, "end_date")
|
end_date = getattr(meetings.c, "end_date")
|
||||||
query = (
|
query = (
|
||||||
meetings.select()
|
meetings.select()
|
||||||
@@ -157,12 +164,32 @@ class MeetingController:
|
|||||||
return Meeting(**result)
|
return Meeting(**result)
|
||||||
|
|
||||||
async def get_by_id(self, meeting_id: str, **kwargs) -> Meeting | None:
|
async def get_by_id(self, meeting_id: str, **kwargs) -> Meeting | None:
|
||||||
|
"""
|
||||||
|
Get a meeting by id
|
||||||
|
"""
|
||||||
query = meetings.select().where(meetings.c.id == meeting_id)
|
query = meetings.select().where(meetings.c.id == meeting_id)
|
||||||
result = await get_database().fetch_one(query)
|
result = await get_database().fetch_one(query)
|
||||||
if not result:
|
if not result:
|
||||||
return None
|
return None
|
||||||
return Meeting(**result)
|
return Meeting(**result)
|
||||||
|
|
||||||
|
async def get_by_id_for_http(self, meeting_id: str, user_id: str | None) -> Meeting:
|
||||||
|
"""
|
||||||
|
Get a meeting by ID for HTTP request.
|
||||||
|
|
||||||
|
If not found, it will raise a 404 error.
|
||||||
|
"""
|
||||||
|
query = meetings.select().where(meetings.c.id == meeting_id)
|
||||||
|
result = await get_database().fetch_one(query)
|
||||||
|
if not result:
|
||||||
|
raise HTTPException(status_code=404, detail="Meeting not found")
|
||||||
|
|
||||||
|
meeting = Meeting(**result)
|
||||||
|
if result["user_id"] != user_id:
|
||||||
|
meeting.host_room_url = ""
|
||||||
|
|
||||||
|
return meeting
|
||||||
|
|
||||||
async def update_meeting(self, meeting_id: str, **kwargs):
|
async def update_meeting(self, meeting_id: str, **kwargs):
|
||||||
query = meetings.update().where(meetings.c.id == meeting_id).values(**kwargs)
|
query = meetings.update().where(meetings.c.id == meeting_id).values(**kwargs)
|
||||||
await get_database().execute(query)
|
await get_database().execute(query)
|
||||||
@@ -187,7 +214,7 @@ class MeetingConsentController:
|
|||||||
result = await get_database().fetch_one(query)
|
result = await get_database().fetch_one(query)
|
||||||
if result is None:
|
if result is None:
|
||||||
return None
|
return None
|
||||||
return MeetingConsent(**result)
|
return MeetingConsent(**result) if result else None
|
||||||
|
|
||||||
async def upsert(self, consent: MeetingConsent) -> MeetingConsent:
|
async def upsert(self, consent: MeetingConsent) -> MeetingConsent:
|
||||||
"""Create new consent or update existing one for authenticated users"""
|
"""Create new consent or update existing one for authenticated users"""
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import secrets
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from sqlite3 import IntegrityError
|
from sqlite3 import IntegrityError
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
@@ -41,8 +40,6 @@ rooms = sqlalchemy.Table(
|
|||||||
sqlalchemy.Column(
|
sqlalchemy.Column(
|
||||||
"is_shared", sqlalchemy.Boolean, nullable=False, server_default=false()
|
"is_shared", sqlalchemy.Boolean, nullable=False, server_default=false()
|
||||||
),
|
),
|
||||||
sqlalchemy.Column("webhook_url", sqlalchemy.String, nullable=True),
|
|
||||||
sqlalchemy.Column("webhook_secret", sqlalchemy.String, nullable=True),
|
|
||||||
sqlalchemy.Index("idx_room_is_shared", "is_shared"),
|
sqlalchemy.Index("idx_room_is_shared", "is_shared"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,8 +59,6 @@ class Room(BaseModel):
|
|||||||
"none", "prompt", "automatic", "automatic-2nd-participant"
|
"none", "prompt", "automatic", "automatic-2nd-participant"
|
||||||
] = "automatic-2nd-participant"
|
] = "automatic-2nd-participant"
|
||||||
is_shared: bool = False
|
is_shared: bool = False
|
||||||
webhook_url: str | None = None
|
|
||||||
webhook_secret: str | None = None
|
|
||||||
|
|
||||||
|
|
||||||
class RoomController:
|
class RoomController:
|
||||||
@@ -112,15 +107,10 @@ class RoomController:
|
|||||||
recording_type: str,
|
recording_type: str,
|
||||||
recording_trigger: str,
|
recording_trigger: str,
|
||||||
is_shared: bool,
|
is_shared: bool,
|
||||||
webhook_url: str = "",
|
|
||||||
webhook_secret: str = "",
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add a new room
|
Add a new room
|
||||||
"""
|
"""
|
||||||
if webhook_url and not webhook_secret:
|
|
||||||
webhook_secret = secrets.token_urlsafe(32)
|
|
||||||
|
|
||||||
room = Room(
|
room = Room(
|
||||||
name=name,
|
name=name,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@@ -132,8 +122,6 @@ class RoomController:
|
|||||||
recording_type=recording_type,
|
recording_type=recording_type,
|
||||||
recording_trigger=recording_trigger,
|
recording_trigger=recording_trigger,
|
||||||
is_shared=is_shared,
|
is_shared=is_shared,
|
||||||
webhook_url=webhook_url,
|
|
||||||
webhook_secret=webhook_secret,
|
|
||||||
)
|
)
|
||||||
query = rooms.insert().values(**room.model_dump())
|
query = rooms.insert().values(**room.model_dump())
|
||||||
try:
|
try:
|
||||||
@@ -146,9 +134,6 @@ class RoomController:
|
|||||||
"""
|
"""
|
||||||
Update a room fields with key/values in values
|
Update a room fields with key/values in values
|
||||||
"""
|
"""
|
||||||
if values.get("webhook_url") and not values.get("webhook_secret"):
|
|
||||||
values["webhook_secret"] = secrets.token_urlsafe(32)
|
|
||||||
|
|
||||||
query = rooms.update().where(rooms.c.id == room.id).values(**values)
|
query = rooms.update().where(rooms.c.id == room.id).values(**values)
|
||||||
try:
|
try:
|
||||||
await get_database().execute(query)
|
await get_database().execute(query)
|
||||||
|
|||||||
@@ -8,14 +8,12 @@ from typing import Annotated, Any, Dict, Iterator
|
|||||||
|
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import webvtt
|
import webvtt
|
||||||
from databases.interfaces import Record as DbRecord
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
Field,
|
Field,
|
||||||
NonNegativeFloat,
|
NonNegativeFloat,
|
||||||
NonNegativeInt,
|
NonNegativeInt,
|
||||||
TypeAdapter,
|
|
||||||
ValidationError,
|
ValidationError,
|
||||||
constr,
|
constr,
|
||||||
field_serializer,
|
field_serializer,
|
||||||
@@ -23,10 +21,9 @@ from pydantic import (
|
|||||||
|
|
||||||
from reflector.db import get_database
|
from reflector.db import get_database
|
||||||
from reflector.db.rooms import rooms
|
from reflector.db.rooms import rooms
|
||||||
from reflector.db.transcripts import SourceKind, TranscriptStatus, transcripts
|
from reflector.db.transcripts import SourceKind, transcripts
|
||||||
from reflector.db.utils import is_postgresql
|
from reflector.db.utils import is_postgresql
|
||||||
from reflector.logger import logger
|
from reflector.logger import logger
|
||||||
from reflector.utils.string import NonEmptyString, try_parse_non_empty_string
|
|
||||||
|
|
||||||
DEFAULT_SEARCH_LIMIT = 20
|
DEFAULT_SEARCH_LIMIT = 20
|
||||||
SNIPPET_CONTEXT_LENGTH = 50 # Characters before/after match to include
|
SNIPPET_CONTEXT_LENGTH = 50 # Characters before/after match to include
|
||||||
@@ -34,13 +31,12 @@ DEFAULT_SNIPPET_MAX_LENGTH = NonNegativeInt(150)
|
|||||||
DEFAULT_MAX_SNIPPETS = NonNegativeInt(3)
|
DEFAULT_MAX_SNIPPETS = NonNegativeInt(3)
|
||||||
LONG_SUMMARY_MAX_SNIPPETS = 2
|
LONG_SUMMARY_MAX_SNIPPETS = 2
|
||||||
|
|
||||||
SearchQueryBase = constr(min_length=1, strip_whitespace=True)
|
SearchQueryBase = constr(min_length=0, strip_whitespace=True)
|
||||||
SearchLimitBase = Annotated[int, Field(ge=1, le=100)]
|
SearchLimitBase = Annotated[int, Field(ge=1, le=100)]
|
||||||
SearchOffsetBase = Annotated[int, Field(ge=0)]
|
SearchOffsetBase = Annotated[int, Field(ge=0)]
|
||||||
SearchTotalBase = Annotated[int, Field(ge=0)]
|
SearchTotalBase = Annotated[int, Field(ge=0)]
|
||||||
|
|
||||||
SearchQuery = Annotated[SearchQueryBase, Field(description="Search query text")]
|
SearchQuery = Annotated[SearchQueryBase, Field(description="Search query text")]
|
||||||
search_query_adapter = TypeAdapter(SearchQuery)
|
|
||||||
SearchLimit = Annotated[SearchLimitBase, Field(description="Results per page")]
|
SearchLimit = Annotated[SearchLimitBase, Field(description="Results per page")]
|
||||||
SearchOffset = Annotated[
|
SearchOffset = Annotated[
|
||||||
SearchOffsetBase, Field(description="Number of results to skip")
|
SearchOffsetBase, Field(description="Number of results to skip")
|
||||||
@@ -92,7 +88,7 @@ class WebVTTProcessor:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_snippets(
|
def generate_snippets(
|
||||||
webvtt_content: WebVTTContent,
|
webvtt_content: WebVTTContent,
|
||||||
query: SearchQuery,
|
query: str,
|
||||||
max_snippets: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
max_snippets: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Generate snippets from WebVTT content."""
|
"""Generate snippets from WebVTT content."""
|
||||||
@@ -129,7 +125,7 @@ class SnippetCandidate:
|
|||||||
class SearchParameters(BaseModel):
|
class SearchParameters(BaseModel):
|
||||||
"""Validated search parameters for full-text search."""
|
"""Validated search parameters for full-text search."""
|
||||||
|
|
||||||
query_text: SearchQuery | None = None
|
query_text: SearchQuery
|
||||||
limit: SearchLimit = DEFAULT_SEARCH_LIMIT
|
limit: SearchLimit = DEFAULT_SEARCH_LIMIT
|
||||||
offset: SearchOffset = 0
|
offset: SearchOffset = 0
|
||||||
user_id: str | None = None
|
user_id: str | None = None
|
||||||
@@ -161,7 +157,7 @@ class SearchResult(BaseModel):
|
|||||||
room_name: str | None = None
|
room_name: str | None = None
|
||||||
source_kind: SourceKind
|
source_kind: SourceKind
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
status: TranscriptStatus = Field(..., min_length=1)
|
status: str = Field(..., min_length=1)
|
||||||
rank: float = Field(..., ge=0, le=1)
|
rank: float = Field(..., ge=0, le=1)
|
||||||
duration: NonNegativeFloat | None = Field(..., description="Duration in seconds")
|
duration: NonNegativeFloat | None = Field(..., description="Duration in seconds")
|
||||||
search_snippets: list[str] = Field(
|
search_snippets: list[str] = Field(
|
||||||
@@ -203,13 +199,15 @@ class SnippetGenerator:
|
|||||||
prev_start = start
|
prev_start = start
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def count_matches(text: str, query: SearchQuery) -> NonNegativeInt:
|
def count_matches(text: str, query: str) -> NonNegativeInt:
|
||||||
"""Count total number of matches for a query in text."""
|
"""Count total number of matches for a query in text."""
|
||||||
ZERO = NonNegativeInt(0)
|
ZERO = NonNegativeInt(0)
|
||||||
if not text:
|
if not text:
|
||||||
logger.warning("Empty text for search query in count_matches")
|
logger.warning("Empty text for search query in count_matches")
|
||||||
return ZERO
|
return ZERO
|
||||||
assert query is not None
|
if not query:
|
||||||
|
logger.warning("Empty query for search text in count_matches")
|
||||||
|
return ZERO
|
||||||
return NonNegativeInt(
|
return NonNegativeInt(
|
||||||
sum(1 for _ in SnippetGenerator.find_all_matches(text, query))
|
sum(1 for _ in SnippetGenerator.find_all_matches(text, query))
|
||||||
)
|
)
|
||||||
@@ -245,14 +243,13 @@ class SnippetGenerator:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def generate(
|
def generate(
|
||||||
text: str,
|
text: str,
|
||||||
query: SearchQuery,
|
query: str,
|
||||||
max_length: NonNegativeInt = DEFAULT_SNIPPET_MAX_LENGTH,
|
max_length: NonNegativeInt = DEFAULT_SNIPPET_MAX_LENGTH,
|
||||||
max_snippets: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
max_snippets: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Generate snippets from text."""
|
"""Generate snippets from text."""
|
||||||
assert query is not None
|
if not text or not query:
|
||||||
if not text:
|
logger.warning("Empty text or query for generate_snippets")
|
||||||
logger.warning("Empty text for generate_snippets")
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
candidates = (
|
candidates = (
|
||||||
@@ -273,7 +270,7 @@ class SnippetGenerator:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_summary(
|
def from_summary(
|
||||||
summary: str,
|
summary: str,
|
||||||
query: SearchQuery,
|
query: str,
|
||||||
max_snippets: NonNegativeInt = LONG_SUMMARY_MAX_SNIPPETS,
|
max_snippets: NonNegativeInt = LONG_SUMMARY_MAX_SNIPPETS,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Generate snippets from summary text."""
|
"""Generate snippets from summary text."""
|
||||||
@@ -281,9 +278,9 @@ class SnippetGenerator:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def combine_sources(
|
def combine_sources(
|
||||||
summary: NonEmptyString | None,
|
summary: str | None,
|
||||||
webvtt: WebVTTContent | None,
|
webvtt: WebVTTContent | None,
|
||||||
query: SearchQuery,
|
query: str,
|
||||||
max_total: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
max_total: NonNegativeInt = DEFAULT_MAX_SNIPPETS,
|
||||||
) -> tuple[list[str], NonNegativeInt]:
|
) -> tuple[list[str], NonNegativeInt]:
|
||||||
"""Combine snippets from multiple sources and return total match count.
|
"""Combine snippets from multiple sources and return total match count.
|
||||||
@@ -292,11 +289,6 @@ class SnippetGenerator:
|
|||||||
|
|
||||||
snippets can be empty for real in case of e.g. title match
|
snippets can be empty for real in case of e.g. title match
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert (
|
|
||||||
summary is not None or webvtt is not None
|
|
||||||
), "At least one source must be present"
|
|
||||||
|
|
||||||
webvtt_matches = 0
|
webvtt_matches = 0
|
||||||
summary_matches = 0
|
summary_matches = 0
|
||||||
|
|
||||||
@@ -363,8 +355,8 @@ class SearchController:
|
|||||||
else_=rooms.c.name,
|
else_=rooms.c.name,
|
||||||
).label("room_name"),
|
).label("room_name"),
|
||||||
]
|
]
|
||||||
search_query = None
|
|
||||||
if params.query_text is not None:
|
if params.query_text:
|
||||||
search_query = sqlalchemy.func.websearch_to_tsquery(
|
search_query = sqlalchemy.func.websearch_to_tsquery(
|
||||||
"english", params.query_text
|
"english", params.query_text
|
||||||
)
|
)
|
||||||
@@ -381,9 +373,7 @@ class SearchController:
|
|||||||
transcripts.join(rooms, transcripts.c.room_id == rooms.c.id, isouter=True)
|
transcripts.join(rooms, transcripts.c.room_id == rooms.c.id, isouter=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
if params.query_text is not None:
|
if params.query_text:
|
||||||
# because already initialized based on params.query_text presence above
|
|
||||||
assert search_query is not None
|
|
||||||
base_query = base_query.where(
|
base_query = base_query.where(
|
||||||
transcripts.c.search_vector_en.op("@@")(search_query)
|
transcripts.c.search_vector_en.op("@@")(search_query)
|
||||||
)
|
)
|
||||||
@@ -403,7 +393,7 @@ class SearchController:
|
|||||||
transcripts.c.source_kind == params.source_kind
|
transcripts.c.source_kind == params.source_kind
|
||||||
)
|
)
|
||||||
|
|
||||||
if params.query_text is not None:
|
if params.query_text:
|
||||||
order_by = sqlalchemy.desc(sqlalchemy.text("rank"))
|
order_by = sqlalchemy.desc(sqlalchemy.text("rank"))
|
||||||
else:
|
else:
|
||||||
order_by = sqlalchemy.desc(transcripts.c.created_at)
|
order_by = sqlalchemy.desc(transcripts.c.created_at)
|
||||||
@@ -417,29 +407,19 @@ class SearchController:
|
|||||||
)
|
)
|
||||||
total = await get_database().fetch_val(count_query)
|
total = await get_database().fetch_val(count_query)
|
||||||
|
|
||||||
def _process_result(r: DbRecord) -> SearchResult:
|
def _process_result(r) -> SearchResult:
|
||||||
r_dict: Dict[str, Any] = dict(r)
|
r_dict: Dict[str, Any] = dict(r)
|
||||||
|
|
||||||
webvtt_raw: str | None = r_dict.pop("webvtt", None)
|
webvtt_raw: str | None = r_dict.pop("webvtt", None)
|
||||||
webvtt: WebVTTContent | None
|
|
||||||
if webvtt_raw:
|
if webvtt_raw:
|
||||||
webvtt = WebVTTProcessor.parse(webvtt_raw)
|
webvtt = WebVTTProcessor.parse(webvtt_raw)
|
||||||
else:
|
else:
|
||||||
webvtt = None
|
webvtt = None
|
||||||
|
long_summary: str | None = r_dict.pop("long_summary", None)
|
||||||
long_summary_r: str | None = r_dict.pop("long_summary", None)
|
|
||||||
long_summary: NonEmptyString = try_parse_non_empty_string(long_summary_r)
|
|
||||||
room_name: str | None = r_dict.pop("room_name", None)
|
room_name: str | None = r_dict.pop("room_name", None)
|
||||||
db_result = SearchResultDB.model_validate(r_dict)
|
db_result = SearchResultDB.model_validate(r_dict)
|
||||||
|
|
||||||
at_least_one_source = webvtt is not None or long_summary is not None
|
snippets, total_match_count = SnippetGenerator.combine_sources(
|
||||||
has_query = params.query_text is not None
|
long_summary, webvtt, params.query_text, DEFAULT_MAX_SNIPPETS
|
||||||
snippets, total_match_count = (
|
|
||||||
SnippetGenerator.combine_sources(
|
|
||||||
long_summary, webvtt, params.query_text, DEFAULT_MAX_SNIPPETS
|
|
||||||
)
|
|
||||||
if has_query and at_least_one_source
|
|
||||||
else ([], 0)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return SearchResult(
|
return SearchResult(
|
||||||
|
|||||||
@@ -122,15 +122,6 @@ def generate_transcript_name() -> str:
|
|||||||
return f"Transcript {now.strftime('%Y-%m-%d %H:%M:%S')}"
|
return f"Transcript {now.strftime('%Y-%m-%d %H:%M:%S')}"
|
||||||
|
|
||||||
|
|
||||||
TranscriptStatus = Literal[
|
|
||||||
"idle", "uploaded", "recording", "processing", "error", "ended"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class StrValue(BaseModel):
|
|
||||||
value: str
|
|
||||||
|
|
||||||
|
|
||||||
class AudioWaveform(BaseModel):
|
class AudioWaveform(BaseModel):
|
||||||
data: list[float]
|
data: list[float]
|
||||||
|
|
||||||
@@ -194,7 +185,7 @@ class Transcript(BaseModel):
|
|||||||
id: str = Field(default_factory=generate_uuid4)
|
id: str = Field(default_factory=generate_uuid4)
|
||||||
user_id: str | None = None
|
user_id: str | None = None
|
||||||
name: str = Field(default_factory=generate_transcript_name)
|
name: str = Field(default_factory=generate_transcript_name)
|
||||||
status: TranscriptStatus = "idle"
|
status: str = "idle"
|
||||||
duration: float = 0
|
duration: float = 0
|
||||||
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||||
title: str | None = None
|
title: str | None = None
|
||||||
@@ -741,27 +732,5 @@ class TranscriptController:
|
|||||||
transcript.delete_participant(participant_id)
|
transcript.delete_participant(participant_id)
|
||||||
await self.update(transcript, {"participants": transcript.participants_dump()})
|
await self.update(transcript, {"participants": transcript.participants_dump()})
|
||||||
|
|
||||||
async def set_status(
|
|
||||||
self, transcript_id: str, status: TranscriptStatus
|
|
||||||
) -> TranscriptEvent | None:
|
|
||||||
"""
|
|
||||||
Update the status of a transcript
|
|
||||||
|
|
||||||
Will add an event STATUS + update the status field of transcript
|
|
||||||
"""
|
|
||||||
async with self.transaction():
|
|
||||||
transcript = await self.get_by_id(transcript_id)
|
|
||||||
if not transcript:
|
|
||||||
raise Exception(f"Transcript {transcript_id} not found")
|
|
||||||
if transcript.status == status:
|
|
||||||
return
|
|
||||||
resp = await self.append_event(
|
|
||||||
transcript=transcript,
|
|
||||||
event="STATUS",
|
|
||||||
data=StrValue(value=status),
|
|
||||||
)
|
|
||||||
await self.update(transcript, {"status": status})
|
|
||||||
return resp
|
|
||||||
|
|
||||||
|
|
||||||
transcripts_controller = TranscriptController()
|
transcripts_controller = TranscriptController()
|
||||||
|
|||||||
@@ -7,28 +7,18 @@ Uses parallel processing for transcription, diarization, and waveform generation
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import uuid
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import av
|
import av
|
||||||
import structlog
|
import structlog
|
||||||
from celery import chain, shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
from reflector.asynctask import asynctask
|
|
||||||
from reflector.db.rooms import rooms_controller
|
|
||||||
from reflector.db.transcripts import (
|
from reflector.db.transcripts import (
|
||||||
SourceKind,
|
|
||||||
Transcript,
|
Transcript,
|
||||||
TranscriptStatus,
|
|
||||||
transcripts_controller,
|
transcripts_controller,
|
||||||
)
|
)
|
||||||
from reflector.logger import logger
|
from reflector.logger import logger
|
||||||
from reflector.pipelines.main_live_pipeline import (
|
from reflector.pipelines.main_live_pipeline import PipelineMainBase, asynctask
|
||||||
PipelineMainBase,
|
|
||||||
broadcast_to_sockets,
|
|
||||||
task_cleanup_consent,
|
|
||||||
task_pipeline_post_to_zulip,
|
|
||||||
)
|
|
||||||
from reflector.processors import (
|
from reflector.processors import (
|
||||||
AudioFileWriterProcessor,
|
AudioFileWriterProcessor,
|
||||||
TranscriptFinalSummaryProcessor,
|
TranscriptFinalSummaryProcessor,
|
||||||
@@ -53,7 +43,6 @@ from reflector.processors.types import (
|
|||||||
)
|
)
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
from reflector.storage import get_transcripts_storage
|
from reflector.storage import get_transcripts_storage
|
||||||
from reflector.worker.webhook import send_transcript_webhook
|
|
||||||
|
|
||||||
|
|
||||||
class EmptyPipeline:
|
class EmptyPipeline:
|
||||||
@@ -94,27 +83,12 @@ class PipelineMainFile(PipelineMainBase):
|
|||||||
exc_info=result,
|
exc_info=result,
|
||||||
)
|
)
|
||||||
|
|
||||||
@broadcast_to_sockets
|
|
||||||
async def set_status(self, transcript_id: str, status: TranscriptStatus):
|
|
||||||
async with self.lock_transaction():
|
|
||||||
return await transcripts_controller.set_status(transcript_id, status)
|
|
||||||
|
|
||||||
async def process(self, file_path: Path):
|
async def process(self, file_path: Path):
|
||||||
"""Main entry point for file processing"""
|
"""Main entry point for file processing"""
|
||||||
self.logger.info(f"Starting file pipeline for {file_path}")
|
self.logger.info(f"Starting file pipeline for {file_path}")
|
||||||
|
|
||||||
transcript = await self.get_transcript()
|
transcript = await self.get_transcript()
|
||||||
|
|
||||||
# Clear transcript as we're going to regenerate everything
|
|
||||||
async with self.transaction():
|
|
||||||
await transcripts_controller.update(
|
|
||||||
transcript,
|
|
||||||
{
|
|
||||||
"events": [],
|
|
||||||
"topics": [],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
# Extract audio and write to transcript location
|
# Extract audio and write to transcript location
|
||||||
audio_path = await self.extract_and_write_audio(file_path, transcript)
|
audio_path = await self.extract_and_write_audio(file_path, transcript)
|
||||||
|
|
||||||
@@ -131,8 +105,6 @@ class PipelineMainFile(PipelineMainBase):
|
|||||||
|
|
||||||
self.logger.info("File pipeline complete")
|
self.logger.info("File pipeline complete")
|
||||||
|
|
||||||
await transcripts_controller.set_status(transcript.id, "ended")
|
|
||||||
|
|
||||||
async def extract_and_write_audio(
|
async def extract_and_write_audio(
|
||||||
self, file_path: Path, transcript: Transcript
|
self, file_path: Path, transcript: Transcript
|
||||||
) -> Path:
|
) -> Path:
|
||||||
@@ -381,28 +353,6 @@ class PipelineMainFile(PipelineMainBase):
|
|||||||
await processor.flush()
|
await processor.flush()
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
|
||||||
@asynctask
|
|
||||||
async def task_send_webhook_if_needed(*, transcript_id: str):
|
|
||||||
"""Send webhook if this is a room recording with webhook configured"""
|
|
||||||
transcript = await transcripts_controller.get_by_id(transcript_id)
|
|
||||||
if not transcript:
|
|
||||||
return
|
|
||||||
|
|
||||||
if transcript.source_kind == SourceKind.ROOM and transcript.room_id:
|
|
||||||
room = await rooms_controller.get_by_id(transcript.room_id)
|
|
||||||
if room and room.webhook_url:
|
|
||||||
logger.info(
|
|
||||||
"Dispatching webhook",
|
|
||||||
transcript_id=transcript_id,
|
|
||||||
room_id=room.id,
|
|
||||||
webhook_url=room.webhook_url,
|
|
||||||
)
|
|
||||||
send_transcript_webhook.delay(
|
|
||||||
transcript_id, room.id, event_id=uuid.uuid4().hex
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
@asynctask
|
@asynctask
|
||||||
async def task_pipeline_file_process(*, transcript_id: str):
|
async def task_pipeline_file_process(*, transcript_id: str):
|
||||||
@@ -412,28 +362,14 @@ async def task_pipeline_file_process(*, transcript_id: str):
|
|||||||
if not transcript:
|
if not transcript:
|
||||||
raise Exception(f"Transcript {transcript_id} not found")
|
raise Exception(f"Transcript {transcript_id} not found")
|
||||||
|
|
||||||
|
# Find the file to process
|
||||||
|
audio_file = next(transcript.data_path.glob("upload.*"), None)
|
||||||
|
if not audio_file:
|
||||||
|
audio_file = next(transcript.data_path.glob("audio.*"), None)
|
||||||
|
|
||||||
|
if not audio_file:
|
||||||
|
raise Exception("No audio file found to process")
|
||||||
|
|
||||||
|
# Run file pipeline
|
||||||
pipeline = PipelineMainFile(transcript_id=transcript_id)
|
pipeline = PipelineMainFile(transcript_id=transcript_id)
|
||||||
try:
|
await pipeline.process(audio_file)
|
||||||
await pipeline.set_status(transcript_id, "processing")
|
|
||||||
|
|
||||||
# Find the file to process
|
|
||||||
audio_file = next(transcript.data_path.glob("upload.*"), None)
|
|
||||||
if not audio_file:
|
|
||||||
audio_file = next(transcript.data_path.glob("audio.*"), None)
|
|
||||||
|
|
||||||
if not audio_file:
|
|
||||||
raise Exception("No audio file found to process")
|
|
||||||
|
|
||||||
await pipeline.process(audio_file)
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
await pipeline.set_status(transcript_id, "error")
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Run post-processing chain: consent cleanup -> zulip -> webhook
|
|
||||||
post_chain = chain(
|
|
||||||
task_cleanup_consent.si(transcript_id=transcript_id),
|
|
||||||
task_pipeline_post_to_zulip.si(transcript_id=transcript_id),
|
|
||||||
task_send_webhook_if_needed.si(transcript_id=transcript_id),
|
|
||||||
)
|
|
||||||
post_chain.delay()
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from celery import chord, current_task, group, shared_task
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from structlog import BoundLogger as Logger
|
from structlog import BoundLogger as Logger
|
||||||
|
|
||||||
from reflector.asynctask import asynctask
|
from reflector.db import get_database
|
||||||
from reflector.db.meetings import meeting_consent_controller, meetings_controller
|
from reflector.db.meetings import meeting_consent_controller, meetings_controller
|
||||||
from reflector.db.recordings import recordings_controller
|
from reflector.db.recordings import recordings_controller
|
||||||
from reflector.db.rooms import rooms_controller
|
from reflector.db.rooms import rooms_controller
|
||||||
@@ -32,7 +32,6 @@ from reflector.db.transcripts import (
|
|||||||
TranscriptFinalLongSummary,
|
TranscriptFinalLongSummary,
|
||||||
TranscriptFinalShortSummary,
|
TranscriptFinalShortSummary,
|
||||||
TranscriptFinalTitle,
|
TranscriptFinalTitle,
|
||||||
TranscriptStatus,
|
|
||||||
TranscriptText,
|
TranscriptText,
|
||||||
TranscriptTopic,
|
TranscriptTopic,
|
||||||
TranscriptWaveform,
|
TranscriptWaveform,
|
||||||
@@ -70,6 +69,29 @@ from reflector.zulip import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def asynctask(f):
|
||||||
|
@functools.wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
async def run_with_db():
|
||||||
|
database = get_database()
|
||||||
|
await database.connect()
|
||||||
|
try:
|
||||||
|
return await f(*args, **kwargs)
|
||||||
|
finally:
|
||||||
|
await database.disconnect()
|
||||||
|
|
||||||
|
coro = run_with_db()
|
||||||
|
try:
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
except RuntimeError:
|
||||||
|
loop = None
|
||||||
|
if loop and loop.is_running():
|
||||||
|
return loop.run_until_complete(coro)
|
||||||
|
return asyncio.run(coro)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def broadcast_to_sockets(func):
|
def broadcast_to_sockets(func):
|
||||||
"""
|
"""
|
||||||
Decorator to broadcast transcript event to websockets
|
Decorator to broadcast transcript event to websockets
|
||||||
@@ -165,16 +187,9 @@ class PipelineMainBase(PipelineRunner[PipelineMessage], Generic[PipelineMessage]
|
|||||||
for topic in topics
|
for topic in topics
|
||||||
]
|
]
|
||||||
|
|
||||||
@asynccontextmanager
|
|
||||||
async def lock_transaction(self):
|
|
||||||
# This lock is to prevent multiple processor starting adding
|
|
||||||
# into event array at the same time
|
|
||||||
async with self._lock:
|
|
||||||
yield
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def transaction(self):
|
async def transaction(self):
|
||||||
async with self.lock_transaction():
|
async with self._lock:
|
||||||
async with transcripts_controller.transaction():
|
async with transcripts_controller.transaction():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@@ -183,14 +198,14 @@ class PipelineMainBase(PipelineRunner[PipelineMessage], Generic[PipelineMessage]
|
|||||||
# if it's the first part, update the status of the transcript
|
# if it's the first part, update the status of the transcript
|
||||||
# but do not set the ended status yet.
|
# but do not set the ended status yet.
|
||||||
if isinstance(self, PipelineMainLive):
|
if isinstance(self, PipelineMainLive):
|
||||||
status_mapping: dict[str, TranscriptStatus] = {
|
status_mapping = {
|
||||||
"started": "recording",
|
"started": "recording",
|
||||||
"push": "recording",
|
"push": "recording",
|
||||||
"flush": "processing",
|
"flush": "processing",
|
||||||
"error": "error",
|
"error": "error",
|
||||||
}
|
}
|
||||||
elif isinstance(self, PipelineMainFinalSummaries):
|
elif isinstance(self, PipelineMainFinalSummaries):
|
||||||
status_mapping: dict[str, TranscriptStatus] = {
|
status_mapping = {
|
||||||
"push": "processing",
|
"push": "processing",
|
||||||
"flush": "processing",
|
"flush": "processing",
|
||||||
"error": "error",
|
"error": "error",
|
||||||
@@ -206,8 +221,22 @@ class PipelineMainBase(PipelineRunner[PipelineMessage], Generic[PipelineMessage]
|
|||||||
return
|
return
|
||||||
|
|
||||||
# when the status of the pipeline changes, update the transcript
|
# when the status of the pipeline changes, update the transcript
|
||||||
async with self._lock:
|
async with self.transaction():
|
||||||
return await transcripts_controller.set_status(self.transcript_id, status)
|
transcript = await self.get_transcript()
|
||||||
|
if status == transcript.status:
|
||||||
|
return
|
||||||
|
resp = await transcripts_controller.append_event(
|
||||||
|
transcript=transcript,
|
||||||
|
event="STATUS",
|
||||||
|
data=StrValue(value=status),
|
||||||
|
)
|
||||||
|
await transcripts_controller.update(
|
||||||
|
transcript,
|
||||||
|
{
|
||||||
|
"status": status,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return resp
|
||||||
|
|
||||||
@broadcast_to_sockets
|
@broadcast_to_sockets
|
||||||
async def on_transcript(self, data):
|
async def on_transcript(self, data):
|
||||||
@@ -765,7 +794,7 @@ def pipeline_post(*, transcript_id: str):
|
|||||||
chain_final_summaries,
|
chain_final_summaries,
|
||||||
) | task_pipeline_post_to_zulip.si(transcript_id=transcript_id)
|
) | task_pipeline_post_to_zulip.si(transcript_id=transcript_id)
|
||||||
|
|
||||||
return chain.delay()
|
chain.delay()
|
||||||
|
|
||||||
|
|
||||||
@get_transcript
|
@get_transcript
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ from reflector.processors.audio_chunker_auto import AudioChunkerAutoProcessor
|
|||||||
|
|
||||||
class AudioChunkerSileroProcessor(AudioChunkerProcessor):
|
class AudioChunkerSileroProcessor(AudioChunkerProcessor):
|
||||||
"""
|
"""
|
||||||
Assemble audio frames into chunks with VAD-based speech detection using Silero VAD
|
Assemble audio frames into chunks with VAD-based speech detection using Silero VAD.
|
||||||
|
|
||||||
|
Expects input audio to be already downscaled to 16kHz mono s16 format
|
||||||
|
(handled by AudioDownscaleProcessor in the pipeline).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -31,12 +34,13 @@ class AudioChunkerSileroProcessor(AudioChunkerProcessor):
|
|||||||
self._init_vad(use_onnx)
|
self._init_vad(use_onnx)
|
||||||
|
|
||||||
def _init_vad(self, use_onnx=False):
|
def _init_vad(self, use_onnx=False):
|
||||||
"""Initialize Silero VAD model"""
|
"""Initialize Silero VAD model for 16kHz audio"""
|
||||||
try:
|
try:
|
||||||
torch.set_num_threads(1)
|
torch.set_num_threads(1)
|
||||||
self.vad_model = load_silero_vad(onnx=use_onnx)
|
self.vad_model = load_silero_vad(onnx=use_onnx)
|
||||||
|
# VAD expects 16kHz audio (guaranteed by AudioDownscaleProcessor)
|
||||||
self.vad_iterator = VADIterator(self.vad_model, sampling_rate=16000)
|
self.vad_iterator = VADIterator(self.vad_model, sampling_rate=16000)
|
||||||
self.logger.info("Silero VAD initialized successfully")
|
self.logger.info("Silero VAD initialized for 16kHz audio")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Failed to initialize Silero VAD: {e}")
|
self.logger.error(f"Failed to initialize Silero VAD: {e}")
|
||||||
@@ -75,7 +79,7 @@ class AudioChunkerSileroProcessor(AudioChunkerProcessor):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Processing block with current buffer size
|
# Processing block with current buffer size
|
||||||
print(f"Processing block: {len(self.frames)} frames in buffer")
|
# print(f"Processing block: {len(self.frames)} frames in buffer")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Convert frames to numpy array for VAD
|
# Convert frames to numpy array for VAD
|
||||||
@@ -189,38 +193,29 @@ class AudioChunkerSileroProcessor(AudioChunkerProcessor):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _frames_to_numpy(self, frames: list[av.AudioFrame]) -> Optional[np.ndarray]:
|
def _frames_to_numpy(self, frames: list[av.AudioFrame]) -> Optional[np.ndarray]:
|
||||||
"""Convert av.AudioFrame list to numpy array for VAD processing"""
|
"""Convert av.AudioFrame list to numpy array for VAD processing
|
||||||
|
|
||||||
|
Input frames are already 16kHz mono s16 format from AudioDownscaleProcessor.
|
||||||
|
Only need to convert s16 to float32 for Silero VAD.
|
||||||
|
"""
|
||||||
if not frames:
|
if not frames:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
audio_data = []
|
# Concatenate all frame arrays
|
||||||
for frame in frames:
|
audio_arrays = [frame.to_ndarray().flatten() for frame in frames]
|
||||||
frame_array = frame.to_ndarray()
|
if not audio_arrays:
|
||||||
|
|
||||||
if len(frame_array.shape) == 2:
|
|
||||||
frame_array = frame_array.flatten()
|
|
||||||
|
|
||||||
audio_data.append(frame_array)
|
|
||||||
|
|
||||||
if not audio_data:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
combined_audio = np.concatenate(audio_data)
|
combined_audio = np.concatenate(audio_arrays)
|
||||||
|
|
||||||
# Ensure float32 format
|
# Convert s16 to float32 (Silero VAD requires float32 in range [-1.0, 1.0])
|
||||||
if combined_audio.dtype == np.int16:
|
# Input is guaranteed to be s16 from AudioDownscaleProcessor
|
||||||
# Normalize int16 audio to float32 in range [-1.0, 1.0]
|
return combined_audio.astype(np.float32) / 32768.0
|
||||||
combined_audio = combined_audio.astype(np.float32) / 32768.0
|
|
||||||
elif combined_audio.dtype != np.float32:
|
|
||||||
combined_audio = combined_audio.astype(np.float32)
|
|
||||||
|
|
||||||
return combined_audio
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error converting frames to numpy: {e}")
|
self.logger.error(f"Error converting frames to numpy: {e}")
|
||||||
|
return None
|
||||||
return None
|
|
||||||
|
|
||||||
def _find_speech_segment_end(self, audio_array: np.ndarray) -> Optional[int]:
|
def _find_speech_segment_end(self, audio_array: np.ndarray) -> Optional[int]:
|
||||||
"""Find complete speech segments and return frame index at segment end"""
|
"""Find complete speech segments and return frame index at segment end"""
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class FileDiarizationModalProcessor(FileDiarizationProcessor):
|
|||||||
"audio_file_url": data.audio_url,
|
"audio_file_url": data.audio_url,
|
||||||
"timestamp": 0,
|
"timestamp": 0,
|
||||||
},
|
},
|
||||||
follow_redirects=True,
|
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
diarization_data = response.json()["diarization"]
|
diarization_data = response.json()["diarization"]
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class FileTranscriptModalProcessor(FileTranscriptProcessor):
|
|||||||
"language": data.language,
|
"language": data.language,
|
||||||
"batch": True,
|
"batch": True,
|
||||||
},
|
},
|
||||||
follow_redirects=True,
|
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
result = response.json()
|
result = response.json()
|
||||||
@@ -68,9 +67,6 @@ class FileTranscriptModalProcessor(FileTranscriptProcessor):
|
|||||||
for word_info in result.get("words", [])
|
for word_info in result.get("words", [])
|
||||||
]
|
]
|
||||||
|
|
||||||
# words come not in order
|
|
||||||
words.sort(key=lambda w: w.start)
|
|
||||||
|
|
||||||
return Transcript(words=words)
|
return Transcript(words=words)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Annotated, TypedDict
|
from typing import Annotated, TypedDict
|
||||||
|
|
||||||
|
from profanityfilter import ProfanityFilter
|
||||||
from pydantic import BaseModel, Field, PrivateAttr
|
from pydantic import BaseModel, Field, PrivateAttr
|
||||||
|
|
||||||
|
from reflector.redis_cache import redis_cache
|
||||||
|
|
||||||
|
|
||||||
class DiarizationSegment(TypedDict):
|
class DiarizationSegment(TypedDict):
|
||||||
"""Type definition for diarization segment containing speaker information"""
|
"""Type definition for diarization segment containing speaker information"""
|
||||||
@@ -17,6 +20,9 @@ class DiarizationSegment(TypedDict):
|
|||||||
|
|
||||||
PUNC_RE = re.compile(r"[.;:?!…]")
|
PUNC_RE = re.compile(r"[.;:?!…]")
|
||||||
|
|
||||||
|
profanity_filter = ProfanityFilter()
|
||||||
|
profanity_filter.set_censor("*")
|
||||||
|
|
||||||
|
|
||||||
class AudioFile(BaseModel):
|
class AudioFile(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
@@ -118,11 +124,21 @@ def words_to_segments(words: list[Word]) -> list[TranscriptSegment]:
|
|||||||
|
|
||||||
class Transcript(BaseModel):
|
class Transcript(BaseModel):
|
||||||
translation: str | None = None
|
translation: str | None = None
|
||||||
words: list[Word] = []
|
words: list[Word] = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def raw_text(self):
|
||||||
|
# Uncensored text
|
||||||
|
return "".join([word.text for word in self.words])
|
||||||
|
|
||||||
|
@redis_cache(prefix="profanity", duration=3600 * 24 * 7)
|
||||||
|
def _get_censored_text(self, text: str):
|
||||||
|
return profanity_filter.censor(text).strip()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
return "".join([word.text for word in self.words])
|
# Censored text
|
||||||
|
return self._get_censored_text(self.raw_text)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def human_timestamp(self):
|
def human_timestamp(self):
|
||||||
@@ -154,6 +170,12 @@ class Transcript(BaseModel):
|
|||||||
word.start += offset
|
word.start += offset
|
||||||
word.end += offset
|
word.end += offset
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
words = [
|
||||||
|
Word(text=word.text, start=word.start, end=word.end) for word in self.words
|
||||||
|
]
|
||||||
|
return Transcript(text=self.text, translation=self.translation, words=words)
|
||||||
|
|
||||||
def as_segments(self) -> list[TranscriptSegment]:
|
def as_segments(self) -> list[TranscriptSegment]:
|
||||||
return words_to_segments(self.words)
|
return words_to_segments(self.words)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
from pydantic.types import PositiveInt
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
from reflector.utils.string import NonEmptyString
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
@@ -93,8 +90,9 @@ class Settings(BaseSettings):
|
|||||||
AUTH_JWT_PUBLIC_KEY: str | None = "authentik.monadical.com_public.pem"
|
AUTH_JWT_PUBLIC_KEY: str | None = "authentik.monadical.com_public.pem"
|
||||||
AUTH_JWT_AUDIENCE: str | None = None
|
AUTH_JWT_AUDIENCE: str | None = None
|
||||||
|
|
||||||
|
# API public mode
|
||||||
|
# if set, all anonymous record will be public
|
||||||
PUBLIC_MODE: bool = False
|
PUBLIC_MODE: bool = False
|
||||||
PUBLIC_DATA_RETENTION_DAYS: PositiveInt = 7
|
|
||||||
|
|
||||||
# Min transcript length to generate topic + summary
|
# Min transcript length to generate topic + summary
|
||||||
MIN_TRANSCRIPT_LENGTH: int = 750
|
MIN_TRANSCRIPT_LENGTH: int = 750
|
||||||
@@ -122,7 +120,7 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# Whereby integration
|
# Whereby integration
|
||||||
WHEREBY_API_URL: str = "https://api.whereby.dev/v1"
|
WHEREBY_API_URL: str = "https://api.whereby.dev/v1"
|
||||||
WHEREBY_API_KEY: NonEmptyString | None = None
|
WHEREBY_API_KEY: str | None = None
|
||||||
WHEREBY_WEBHOOK_SECRET: str | None = None
|
WHEREBY_WEBHOOK_SECRET: str | None = None
|
||||||
AWS_WHEREBY_ACCESS_KEY_ID: str | None = None
|
AWS_WHEREBY_ACCESS_KEY_ID: str | None = None
|
||||||
AWS_WHEREBY_ACCESS_KEY_SECRET: str | None = None
|
AWS_WHEREBY_ACCESS_KEY_SECRET: str | None = None
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
"""
|
|
||||||
Manual cleanup tool for old public data.
|
|
||||||
Uses the same implementation as the Celery worker task.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import asyncio
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import structlog
|
|
||||||
|
|
||||||
from reflector.settings import settings
|
|
||||||
from reflector.worker.cleanup import _cleanup_old_public_data
|
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
async def cleanup_old_data(days: int = 7):
|
|
||||||
logger.info(
|
|
||||||
"Starting manual cleanup",
|
|
||||||
retention_days=days,
|
|
||||||
public_mode=settings.PUBLIC_MODE,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not settings.PUBLIC_MODE:
|
|
||||||
logger.critical(
|
|
||||||
"WARNING: PUBLIC_MODE is False. "
|
|
||||||
"This tool is intended for public instances only."
|
|
||||||
)
|
|
||||||
raise Exception("Tool intended for public instances only")
|
|
||||||
|
|
||||||
result = await _cleanup_old_public_data(days=days)
|
|
||||||
|
|
||||||
if result:
|
|
||||||
logger.info(
|
|
||||||
"Cleanup completed",
|
|
||||||
transcripts_deleted=result.get("transcripts_deleted", 0),
|
|
||||||
meetings_deleted=result.get("meetings_deleted", 0),
|
|
||||||
recordings_deleted=result.get("recordings_deleted", 0),
|
|
||||||
errors_count=len(result.get("errors", [])),
|
|
||||||
)
|
|
||||||
if result.get("errors"):
|
|
||||||
logger.warning(
|
|
||||||
"Errors encountered during cleanup:", errors=result["errors"][:10]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.info("Cleanup skipped or completed without results")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Clean up old transcripts and meetings"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--days",
|
|
||||||
type=int,
|
|
||||||
default=7,
|
|
||||||
help="Number of days to keep data (default: 7)",
|
|
||||||
)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.days < 1:
|
|
||||||
logger.error("Days must be at least 1")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
asyncio.run(cleanup_old_data(days=args.days))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,204 +1,294 @@
|
|||||||
"""
|
"""
|
||||||
Process audio file with diarization support
|
Process audio file with diarization support
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
Extended version of process.py that includes speaker diarization.
|
||||||
|
This tool processes audio files locally without requiring the full server infrastructure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import tempfile
|
||||||
import shutil
|
import uuid
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Literal
|
from typing import List
|
||||||
|
|
||||||
|
import av
|
||||||
|
|
||||||
from reflector.db.transcripts import SourceKind, TranscriptTopic, transcripts_controller
|
|
||||||
from reflector.logger import logger
|
from reflector.logger import logger
|
||||||
from reflector.pipelines.main_file_pipeline import (
|
from reflector.processors import (
|
||||||
task_pipeline_file_process as task_pipeline_file_process,
|
AudioChunkerAutoProcessor,
|
||||||
|
AudioDownscaleProcessor,
|
||||||
|
AudioFileWriterProcessor,
|
||||||
|
AudioMergeProcessor,
|
||||||
|
AudioTranscriptAutoProcessor,
|
||||||
|
Pipeline,
|
||||||
|
PipelineEvent,
|
||||||
|
TranscriptFinalSummaryProcessor,
|
||||||
|
TranscriptFinalTitleProcessor,
|
||||||
|
TranscriptLinerProcessor,
|
||||||
|
TranscriptTopicDetectorProcessor,
|
||||||
|
TranscriptTranslatorAutoProcessor,
|
||||||
)
|
)
|
||||||
from reflector.pipelines.main_live_pipeline import pipeline_post as live_pipeline_post
|
from reflector.processors.base import BroadcastProcessor, Processor
|
||||||
from reflector.pipelines.main_live_pipeline import (
|
from reflector.processors.types import (
|
||||||
pipeline_process as live_pipeline_process,
|
AudioDiarizationInput,
|
||||||
|
TitleSummary,
|
||||||
|
TitleSummaryWithId,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def serialize_topics(topics: List[TranscriptTopic]) -> List[Dict[str, Any]]:
|
class TopicCollectorProcessor(Processor):
|
||||||
"""Convert TranscriptTopic objects to JSON-serializable dicts"""
|
"""Collect topics for diarization"""
|
||||||
serialized = []
|
|
||||||
for topic in topics:
|
|
||||||
topic_dict = topic.model_dump()
|
|
||||||
serialized.append(topic_dict)
|
|
||||||
return serialized
|
|
||||||
|
|
||||||
|
INPUT_TYPE = TitleSummary
|
||||||
|
OUTPUT_TYPE = TitleSummary
|
||||||
|
|
||||||
def debug_print_speakers(serialized_topics: List[Dict[str, Any]]) -> None:
|
def __init__(self, **kwargs):
|
||||||
"""Print debug info about speakers found in topics"""
|
super().__init__(**kwargs)
|
||||||
all_speakers = set()
|
self.topics: List[TitleSummaryWithId] = []
|
||||||
for topic_dict in serialized_topics:
|
self._topic_id = 0
|
||||||
for word in topic_dict.get("words", []):
|
|
||||||
all_speakers.add(word.get("speaker", 0))
|
|
||||||
|
|
||||||
print(
|
async def _push(self, data: TitleSummary):
|
||||||
f"Found {len(serialized_topics)} topics with speakers: {all_speakers}",
|
# Convert to TitleSummaryWithId and collect
|
||||||
file=sys.stderr,
|
self._topic_id += 1
|
||||||
)
|
topic_with_id = TitleSummaryWithId(
|
||||||
|
id=str(self._topic_id),
|
||||||
|
title=data.title,
|
||||||
TranscriptId = str
|
summary=data.summary,
|
||||||
|
timestamp=data.timestamp,
|
||||||
|
duration=data.duration,
|
||||||
# common interface for every flow: it needs an Entry in db with specific ceremony (file path + status + actual file in file system)
|
transcript=data.transcript,
|
||||||
# ideally we want to get rid of it at some point
|
|
||||||
async def prepare_entry(
|
|
||||||
source_path: str,
|
|
||||||
source_language: str,
|
|
||||||
target_language: str,
|
|
||||||
) -> TranscriptId:
|
|
||||||
file_path = Path(source_path)
|
|
||||||
|
|
||||||
transcript = await transcripts_controller.add(
|
|
||||||
file_path.name,
|
|
||||||
# note that the real file upload has SourceKind: LIVE for the reason of it's an error
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
source_language=source_language,
|
|
||||||
target_language=target_language,
|
|
||||||
user_id=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
f"Created empty transcript {transcript.id} for file {file_path.name} because technically we need an empty transcript before we start transcript"
|
|
||||||
)
|
|
||||||
|
|
||||||
# pipelines expect files as upload.*
|
|
||||||
|
|
||||||
extension = file_path.suffix
|
|
||||||
upload_path = transcript.data_path / f"upload{extension}"
|
|
||||||
upload_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
shutil.copy2(source_path, upload_path)
|
|
||||||
logger.info(f"Copied {source_path} to {upload_path}")
|
|
||||||
|
|
||||||
# pipelines expect entity status "uploaded"
|
|
||||||
await transcripts_controller.update(transcript, {"status": "uploaded"})
|
|
||||||
|
|
||||||
return transcript.id
|
|
||||||
|
|
||||||
|
|
||||||
# same reason as prepare_entry
|
|
||||||
async def extract_result_from_entry(
|
|
||||||
transcript_id: TranscriptId, output_path: str
|
|
||||||
) -> None:
|
|
||||||
post_final_transcript = await transcripts_controller.get_by_id(transcript_id)
|
|
||||||
|
|
||||||
# assert post_final_transcript.status == "ended"
|
|
||||||
# File pipeline doesn't set status to "ended", only live pipeline does https://github.com/Monadical-SAS/reflector/issues/582
|
|
||||||
topics = post_final_transcript.topics
|
|
||||||
if not topics:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"No topics found for transcript {transcript_id} after processing"
|
|
||||||
)
|
)
|
||||||
|
self.topics.append(topic_with_id)
|
||||||
|
|
||||||
serialized_topics = serialize_topics(topics)
|
# Pass through the original topic
|
||||||
|
await self.emit(data)
|
||||||
|
|
||||||
if output_path:
|
def get_topics(self) -> List[TitleSummaryWithId]:
|
||||||
# Write to JSON file
|
return self.topics
|
||||||
with open(output_path, "w") as f:
|
|
||||||
for topic_dict in serialized_topics:
|
|
||||||
json.dump(topic_dict, f)
|
|
||||||
f.write("\n")
|
|
||||||
print(f"Results written to {output_path}", file=sys.stderr)
|
|
||||||
else:
|
|
||||||
# Write to stdout as JSONL
|
|
||||||
for topic_dict in serialized_topics:
|
|
||||||
print(json.dumps(topic_dict))
|
|
||||||
|
|
||||||
debug_print_speakers(serialized_topics)
|
|
||||||
|
|
||||||
|
|
||||||
async def process_live_pipeline(
|
async def process_audio_file(
|
||||||
transcript_id: TranscriptId,
|
filename,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=False,
|
||||||
|
source_language="en",
|
||||||
|
target_language="en",
|
||||||
|
enable_diarization=True,
|
||||||
|
diarization_backend="pyannote",
|
||||||
):
|
):
|
||||||
"""Process transcript_id with transcription and diarization"""
|
# Create temp file for audio if diarization is enabled
|
||||||
|
audio_temp_path = None
|
||||||
|
if enable_diarization:
|
||||||
|
audio_temp_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
||||||
|
audio_temp_path = audio_temp_file.name
|
||||||
|
audio_temp_file.close()
|
||||||
|
|
||||||
print(f"Processing transcript_id {transcript_id}...", file=sys.stderr)
|
# Create processor for collecting topics
|
||||||
await live_pipeline_process(transcript_id=transcript_id)
|
topic_collector = TopicCollectorProcessor()
|
||||||
print(f"Processing complete for transcript {transcript_id}", file=sys.stderr)
|
|
||||||
|
|
||||||
pre_final_transcript = await transcripts_controller.get_by_id(transcript_id)
|
# Build pipeline for audio processing
|
||||||
|
processors = []
|
||||||
|
|
||||||
# assert documented behaviour: after process, the pipeline isn't ended. this is the reason of calling pipeline_post
|
# Add audio file writer at the beginning if diarization is enabled
|
||||||
assert pre_final_transcript.status != "ended"
|
if enable_diarization:
|
||||||
|
processors.append(AudioFileWriterProcessor(audio_temp_path))
|
||||||
|
|
||||||
# at this point, diarization is running but we have no access to it. run diarization in parallel - one will hopefully win after polling
|
# Add the rest of the processors
|
||||||
result = live_pipeline_post(transcript_id=transcript_id)
|
processors += [
|
||||||
|
AudioDownscaleProcessor(),
|
||||||
|
AudioChunkerAutoProcessor(),
|
||||||
|
AudioMergeProcessor(),
|
||||||
|
AudioTranscriptAutoProcessor.as_threaded(),
|
||||||
|
TranscriptLinerProcessor(),
|
||||||
|
TranscriptTranslatorAutoProcessor.as_threaded(),
|
||||||
|
]
|
||||||
|
|
||||||
# result.ready() blocks even without await; it mutates result also
|
if not only_transcript:
|
||||||
while not result.ready():
|
processors += [
|
||||||
print(f"Status: {result.state}")
|
TranscriptTopicDetectorProcessor.as_threaded(),
|
||||||
time.sleep(2)
|
# Collect topics for diarization
|
||||||
|
topic_collector,
|
||||||
|
BroadcastProcessor(
|
||||||
|
processors=[
|
||||||
|
TranscriptFinalTitleProcessor.as_threaded(),
|
||||||
|
TranscriptFinalSummaryProcessor.as_threaded(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Create main pipeline
|
||||||
|
pipeline = Pipeline(*processors)
|
||||||
|
pipeline.set_pref("audio:source_language", source_language)
|
||||||
|
pipeline.set_pref("audio:target_language", target_language)
|
||||||
|
pipeline.describe()
|
||||||
|
pipeline.on(event_callback)
|
||||||
|
|
||||||
|
# Start processing audio
|
||||||
|
logger.info(f"Opening {filename}")
|
||||||
|
container = av.open(filename)
|
||||||
|
try:
|
||||||
|
logger.info("Start pushing audio into the pipeline")
|
||||||
|
for frame in container.decode(audio=0):
|
||||||
|
await pipeline.push(frame)
|
||||||
|
finally:
|
||||||
|
logger.info("Flushing the pipeline")
|
||||||
|
await pipeline.flush()
|
||||||
|
|
||||||
|
# Run diarization if enabled and we have topics
|
||||||
|
if enable_diarization and not only_transcript and audio_temp_path:
|
||||||
|
topics = topic_collector.get_topics()
|
||||||
|
|
||||||
|
if topics:
|
||||||
|
logger.info(f"Starting diarization with {len(topics)} topics")
|
||||||
|
|
||||||
|
try:
|
||||||
|
from reflector.processors import AudioDiarizationAutoProcessor
|
||||||
|
|
||||||
|
diarization_processor = AudioDiarizationAutoProcessor(
|
||||||
|
name=diarization_backend
|
||||||
|
)
|
||||||
|
|
||||||
|
diarization_processor.set_pipeline(pipeline)
|
||||||
|
|
||||||
|
# For Modal backend, we need to upload the file to S3 first
|
||||||
|
if diarization_backend == "modal":
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from reflector.storage import get_transcripts_storage
|
||||||
|
from reflector.utils.s3_temp_file import S3TemporaryFile
|
||||||
|
|
||||||
|
storage = get_transcripts_storage()
|
||||||
|
|
||||||
|
# Generate a unique filename in evaluation folder
|
||||||
|
timestamp = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
||||||
|
audio_filename = f"evaluation/diarization_temp/{timestamp}_{uuid.uuid4().hex}.wav"
|
||||||
|
|
||||||
|
# Use context manager for automatic cleanup
|
||||||
|
async with S3TemporaryFile(storage, audio_filename) as s3_file:
|
||||||
|
# Read and upload the audio file
|
||||||
|
with open(audio_temp_path, "rb") as f:
|
||||||
|
audio_data = f.read()
|
||||||
|
|
||||||
|
audio_url = await s3_file.upload(audio_data)
|
||||||
|
logger.info(f"Uploaded audio to S3: {audio_filename}")
|
||||||
|
|
||||||
|
# Create diarization input with S3 URL
|
||||||
|
diarization_input = AudioDiarizationInput(
|
||||||
|
audio_url=audio_url, topics=topics
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run diarization
|
||||||
|
await diarization_processor.push(diarization_input)
|
||||||
|
await diarization_processor.flush()
|
||||||
|
|
||||||
|
logger.info("Diarization complete")
|
||||||
|
# File will be automatically cleaned up when exiting the context
|
||||||
|
else:
|
||||||
|
# For local backend, use local file path
|
||||||
|
audio_url = audio_temp_path
|
||||||
|
|
||||||
|
# Create diarization input
|
||||||
|
diarization_input = AudioDiarizationInput(
|
||||||
|
audio_url=audio_url, topics=topics
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run diarization
|
||||||
|
await diarization_processor.push(diarization_input)
|
||||||
|
await diarization_processor.flush()
|
||||||
|
|
||||||
|
logger.info("Diarization complete")
|
||||||
|
|
||||||
|
except ImportError as e:
|
||||||
|
logger.error(f"Failed to import diarization dependencies: {e}")
|
||||||
|
logger.error(
|
||||||
|
"Install with: uv pip install pyannote.audio torch torchaudio"
|
||||||
|
)
|
||||||
|
logger.error(
|
||||||
|
"And set HF_TOKEN environment variable for pyannote models"
|
||||||
|
)
|
||||||
|
raise SystemExit(1)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Diarization failed: {e}")
|
||||||
|
raise SystemExit(1)
|
||||||
|
else:
|
||||||
|
logger.warning("Skipping diarization: no topics available")
|
||||||
|
|
||||||
|
# Clean up temp file
|
||||||
|
if audio_temp_path:
|
||||||
|
try:
|
||||||
|
Path(audio_temp_path).unlink()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to clean up temp file {audio_temp_path}: {e}")
|
||||||
|
|
||||||
|
logger.info("All done!")
|
||||||
|
|
||||||
|
|
||||||
async def process_file_pipeline(
|
async def process_file_pipeline(
|
||||||
transcript_id: TranscriptId,
|
filename: str,
|
||||||
|
event_callback,
|
||||||
|
source_language="en",
|
||||||
|
target_language="en",
|
||||||
|
enable_diarization=True,
|
||||||
|
diarization_backend="modal",
|
||||||
):
|
):
|
||||||
"""Process audio/video file using the optimized file pipeline"""
|
"""Process audio/video file using the optimized file pipeline"""
|
||||||
|
|
||||||
# task_pipeline_file_process is a Celery task, need to use .delay() for async execution
|
|
||||||
result = task_pipeline_file_process.delay(transcript_id=transcript_id)
|
|
||||||
|
|
||||||
# Wait for the Celery task to complete
|
|
||||||
while not result.ready():
|
|
||||||
print(f"File pipeline status: {result.state}", file=sys.stderr)
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
logger.info("File pipeline processing complete")
|
|
||||||
|
|
||||||
|
|
||||||
async def process(
|
|
||||||
source_path: str,
|
|
||||||
source_language: str,
|
|
||||||
target_language: str,
|
|
||||||
pipeline: Literal["live", "file"],
|
|
||||||
output_path: str = None,
|
|
||||||
):
|
|
||||||
from reflector.db import get_database
|
|
||||||
|
|
||||||
database = get_database()
|
|
||||||
# db connect is a part of ceremony
|
|
||||||
await database.connect()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
transcript_id = await prepare_entry(
|
from reflector.db import database
|
||||||
source_path,
|
from reflector.db.transcripts import SourceKind, transcripts_controller
|
||||||
source_language,
|
from reflector.pipelines.main_file_pipeline import PipelineMainFile
|
||||||
target_language,
|
|
||||||
|
await database.connect()
|
||||||
|
try:
|
||||||
|
# Create a temporary transcript for processing
|
||||||
|
transcript = await transcripts_controller.add(
|
||||||
|
"",
|
||||||
|
source_kind=SourceKind.FILE,
|
||||||
|
source_language=source_language,
|
||||||
|
target_language=target_language,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Process the file
|
||||||
|
pipeline = PipelineMainFile(transcript_id=transcript.id)
|
||||||
|
await pipeline.process(Path(filename))
|
||||||
|
|
||||||
|
logger.info("File pipeline processing complete")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
await database.disconnect()
|
||||||
|
except ImportError as e:
|
||||||
|
logger.error(f"File pipeline not available: {e}")
|
||||||
|
logger.info("Falling back to stream pipeline")
|
||||||
|
# Fall back to stream pipeline
|
||||||
|
await process_audio_file(
|
||||||
|
filename,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=False,
|
||||||
|
source_language=source_language,
|
||||||
|
target_language=target_language,
|
||||||
|
enable_diarization=enable_diarization,
|
||||||
|
diarization_backend=diarization_backend,
|
||||||
)
|
)
|
||||||
|
|
||||||
pipeline_handlers = {
|
|
||||||
"live": process_live_pipeline,
|
|
||||||
"file": process_file_pipeline,
|
|
||||||
}
|
|
||||||
|
|
||||||
handler = pipeline_handlers.get(pipeline)
|
|
||||||
if not handler:
|
|
||||||
raise ValueError(f"Unknown pipeline type: {pipeline}")
|
|
||||||
|
|
||||||
await handler(transcript_id)
|
|
||||||
|
|
||||||
await extract_result_from_entry(transcript_id, output_path)
|
|
||||||
finally:
|
|
||||||
await database.disconnect()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Process audio files with speaker diarization"
|
description="Process audio files with optional speaker diarization"
|
||||||
)
|
)
|
||||||
parser.add_argument("source", help="Source file (mp3, wav, mp4...)")
|
parser.add_argument("source", help="Source file (mp3, wav, mp4...)")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--pipeline",
|
"--stream",
|
||||||
required=True,
|
action="store_true",
|
||||||
choices=["live", "file"],
|
help="Use streaming pipeline (original frame-based processing)",
|
||||||
help="Pipeline type to use for processing (live: streaming/incremental, file: batch/parallel)",
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--only-transcript",
|
||||||
|
"-t",
|
||||||
|
action="store_true",
|
||||||
|
help="Only generate transcript without topics/summaries",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--source-language", default="en", help="Source language code (default: en)"
|
"--source-language", default="en", help="Source language code (default: en)"
|
||||||
@@ -207,14 +297,82 @@ if __name__ == "__main__":
|
|||||||
"--target-language", default="en", help="Target language code (default: en)"
|
"--target-language", default="en", help="Target language code (default: en)"
|
||||||
)
|
)
|
||||||
parser.add_argument("--output", "-o", help="Output file (output.jsonl)")
|
parser.add_argument("--output", "-o", help="Output file (output.jsonl)")
|
||||||
|
parser.add_argument(
|
||||||
|
"--enable-diarization",
|
||||||
|
"-d",
|
||||||
|
action="store_true",
|
||||||
|
help="Enable speaker diarization",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--diarization-backend",
|
||||||
|
default="pyannote",
|
||||||
|
choices=["pyannote", "modal"],
|
||||||
|
help="Diarization backend to use (default: pyannote)",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
asyncio.run(
|
if "REDIS_HOST" not in os.environ:
|
||||||
process(
|
os.environ["REDIS_HOST"] = "localhost"
|
||||||
args.source,
|
|
||||||
args.source_language,
|
output_fd = None
|
||||||
args.target_language,
|
if args.output:
|
||||||
args.pipeline,
|
output_fd = open(args.output, "w")
|
||||||
args.output,
|
|
||||||
|
async def event_callback(event: PipelineEvent):
|
||||||
|
processor = event.processor
|
||||||
|
data = event.data
|
||||||
|
|
||||||
|
# Ignore internal processors
|
||||||
|
if processor in (
|
||||||
|
"AudioDownscaleProcessor",
|
||||||
|
"AudioChunkerAutoProcessor",
|
||||||
|
"AudioMergeProcessor",
|
||||||
|
"AudioFileWriterProcessor",
|
||||||
|
"TopicCollectorProcessor",
|
||||||
|
"BroadcastProcessor",
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
# If diarization is enabled, skip the original topic events from the pipeline
|
||||||
|
# The diarization processor will emit the same topics but with speaker info
|
||||||
|
if processor == "TranscriptTopicDetectorProcessor" and args.enable_diarization:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Log all events
|
||||||
|
logger.info(f"Event: {processor} - {type(data).__name__}")
|
||||||
|
|
||||||
|
# Write to output
|
||||||
|
if output_fd:
|
||||||
|
output_fd.write(event.model_dump_json())
|
||||||
|
output_fd.write("\n")
|
||||||
|
output_fd.flush()
|
||||||
|
|
||||||
|
if args.stream:
|
||||||
|
# Use original streaming pipeline
|
||||||
|
asyncio.run(
|
||||||
|
process_audio_file(
|
||||||
|
args.source,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=args.only_transcript,
|
||||||
|
source_language=args.source_language,
|
||||||
|
target_language=args.target_language,
|
||||||
|
enable_diarization=args.enable_diarization,
|
||||||
|
diarization_backend=args.diarization_backend,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
|
# Use optimized file pipeline (default)
|
||||||
|
asyncio.run(
|
||||||
|
process_file_pipeline(
|
||||||
|
args.source,
|
||||||
|
event_callback,
|
||||||
|
source_language=args.source_language,
|
||||||
|
target_language=args.target_language,
|
||||||
|
enable_diarization=args.enable_diarization,
|
||||||
|
diarization_backend=args.diarization_backend,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if output_fd:
|
||||||
|
output_fd.close()
|
||||||
|
logger.info(f"Output written to {args.output}")
|
||||||
|
|||||||
318
server/reflector/tools/process_with_diarization.py
Normal file
318
server/reflector/tools/process_with_diarization.py
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
"""
|
||||||
|
@vibe-generated
|
||||||
|
Process audio file with diarization support
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
Extended version of process.py that includes speaker diarization.
|
||||||
|
This tool processes audio files locally without requiring the full server infrastructure.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import tempfile
|
||||||
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import av
|
||||||
|
|
||||||
|
from reflector.logger import logger
|
||||||
|
from reflector.processors import (
|
||||||
|
AudioChunkerAutoProcessor,
|
||||||
|
AudioDownscaleProcessor,
|
||||||
|
AudioFileWriterProcessor,
|
||||||
|
AudioMergeProcessor,
|
||||||
|
AudioTranscriptAutoProcessor,
|
||||||
|
Pipeline,
|
||||||
|
PipelineEvent,
|
||||||
|
TranscriptFinalSummaryProcessor,
|
||||||
|
TranscriptFinalTitleProcessor,
|
||||||
|
TranscriptLinerProcessor,
|
||||||
|
TranscriptTopicDetectorProcessor,
|
||||||
|
TranscriptTranslatorAutoProcessor,
|
||||||
|
)
|
||||||
|
from reflector.processors.base import BroadcastProcessor, Processor
|
||||||
|
from reflector.processors.types import (
|
||||||
|
AudioDiarizationInput,
|
||||||
|
TitleSummary,
|
||||||
|
TitleSummaryWithId,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TopicCollectorProcessor(Processor):
|
||||||
|
"""Collect topics for diarization"""
|
||||||
|
|
||||||
|
INPUT_TYPE = TitleSummary
|
||||||
|
OUTPUT_TYPE = TitleSummary
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.topics: List[TitleSummaryWithId] = []
|
||||||
|
self._topic_id = 0
|
||||||
|
|
||||||
|
async def _push(self, data: TitleSummary):
|
||||||
|
# Convert to TitleSummaryWithId and collect
|
||||||
|
self._topic_id += 1
|
||||||
|
topic_with_id = TitleSummaryWithId(
|
||||||
|
id=str(self._topic_id),
|
||||||
|
title=data.title,
|
||||||
|
summary=data.summary,
|
||||||
|
timestamp=data.timestamp,
|
||||||
|
duration=data.duration,
|
||||||
|
transcript=data.transcript,
|
||||||
|
)
|
||||||
|
self.topics.append(topic_with_id)
|
||||||
|
|
||||||
|
# Pass through the original topic
|
||||||
|
await self.emit(data)
|
||||||
|
|
||||||
|
def get_topics(self) -> List[TitleSummaryWithId]:
|
||||||
|
return self.topics
|
||||||
|
|
||||||
|
|
||||||
|
async def process_audio_file_with_diarization(
|
||||||
|
filename,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=False,
|
||||||
|
source_language="en",
|
||||||
|
target_language="en",
|
||||||
|
enable_diarization=True,
|
||||||
|
diarization_backend="modal",
|
||||||
|
):
|
||||||
|
# Create temp file for audio if diarization is enabled
|
||||||
|
audio_temp_path = None
|
||||||
|
if enable_diarization:
|
||||||
|
audio_temp_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
||||||
|
audio_temp_path = audio_temp_file.name
|
||||||
|
audio_temp_file.close()
|
||||||
|
|
||||||
|
# Create processor for collecting topics
|
||||||
|
topic_collector = TopicCollectorProcessor()
|
||||||
|
|
||||||
|
# Build pipeline for audio processing
|
||||||
|
processors = []
|
||||||
|
|
||||||
|
# Add audio file writer at the beginning if diarization is enabled
|
||||||
|
if enable_diarization:
|
||||||
|
processors.append(AudioFileWriterProcessor(audio_temp_path))
|
||||||
|
|
||||||
|
# Add the rest of the processors
|
||||||
|
processors += [
|
||||||
|
AudioDownscaleProcessor(),
|
||||||
|
AudioChunkerAutoProcessor(),
|
||||||
|
AudioMergeProcessor(),
|
||||||
|
AudioTranscriptAutoProcessor.as_threaded(),
|
||||||
|
]
|
||||||
|
|
||||||
|
processors += [
|
||||||
|
TranscriptLinerProcessor(),
|
||||||
|
TranscriptTranslatorAutoProcessor.as_threaded(),
|
||||||
|
]
|
||||||
|
|
||||||
|
if not only_transcript:
|
||||||
|
processors += [
|
||||||
|
TranscriptTopicDetectorProcessor.as_threaded(),
|
||||||
|
# Collect topics for diarization
|
||||||
|
topic_collector,
|
||||||
|
BroadcastProcessor(
|
||||||
|
processors=[
|
||||||
|
TranscriptFinalTitleProcessor.as_threaded(),
|
||||||
|
TranscriptFinalSummaryProcessor.as_threaded(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Create main pipeline
|
||||||
|
pipeline = Pipeline(*processors)
|
||||||
|
pipeline.set_pref("audio:source_language", source_language)
|
||||||
|
pipeline.set_pref("audio:target_language", target_language)
|
||||||
|
pipeline.describe()
|
||||||
|
pipeline.on(event_callback)
|
||||||
|
|
||||||
|
# Start processing audio
|
||||||
|
logger.info(f"Opening {filename}")
|
||||||
|
container = av.open(filename)
|
||||||
|
try:
|
||||||
|
logger.info("Start pushing audio into the pipeline")
|
||||||
|
for frame in container.decode(audio=0):
|
||||||
|
await pipeline.push(frame)
|
||||||
|
finally:
|
||||||
|
logger.info("Flushing the pipeline")
|
||||||
|
await pipeline.flush()
|
||||||
|
|
||||||
|
# Run diarization if enabled and we have topics
|
||||||
|
if enable_diarization and not only_transcript and audio_temp_path:
|
||||||
|
topics = topic_collector.get_topics()
|
||||||
|
|
||||||
|
if topics:
|
||||||
|
logger.info(f"Starting diarization with {len(topics)} topics")
|
||||||
|
|
||||||
|
try:
|
||||||
|
from reflector.processors import AudioDiarizationAutoProcessor
|
||||||
|
|
||||||
|
diarization_processor = AudioDiarizationAutoProcessor(
|
||||||
|
name=diarization_backend
|
||||||
|
)
|
||||||
|
|
||||||
|
diarization_processor.set_pipeline(pipeline)
|
||||||
|
|
||||||
|
# For Modal backend, we need to upload the file to S3 first
|
||||||
|
if diarization_backend == "modal":
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from reflector.storage import get_transcripts_storage
|
||||||
|
from reflector.utils.s3_temp_file import S3TemporaryFile
|
||||||
|
|
||||||
|
storage = get_transcripts_storage()
|
||||||
|
|
||||||
|
# Generate a unique filename in evaluation folder
|
||||||
|
timestamp = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
||||||
|
audio_filename = f"evaluation/diarization_temp/{timestamp}_{uuid.uuid4().hex}.wav"
|
||||||
|
|
||||||
|
# Use context manager for automatic cleanup
|
||||||
|
async with S3TemporaryFile(storage, audio_filename) as s3_file:
|
||||||
|
# Read and upload the audio file
|
||||||
|
with open(audio_temp_path, "rb") as f:
|
||||||
|
audio_data = f.read()
|
||||||
|
|
||||||
|
audio_url = await s3_file.upload(audio_data)
|
||||||
|
logger.info(f"Uploaded audio to S3: {audio_filename}")
|
||||||
|
|
||||||
|
# Create diarization input with S3 URL
|
||||||
|
diarization_input = AudioDiarizationInput(
|
||||||
|
audio_url=audio_url, topics=topics
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run diarization
|
||||||
|
await diarization_processor.push(diarization_input)
|
||||||
|
await diarization_processor.flush()
|
||||||
|
|
||||||
|
logger.info("Diarization complete")
|
||||||
|
# File will be automatically cleaned up when exiting the context
|
||||||
|
else:
|
||||||
|
# For local backend, use local file path
|
||||||
|
audio_url = audio_temp_path
|
||||||
|
|
||||||
|
# Create diarization input
|
||||||
|
diarization_input = AudioDiarizationInput(
|
||||||
|
audio_url=audio_url, topics=topics
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run diarization
|
||||||
|
await diarization_processor.push(diarization_input)
|
||||||
|
await diarization_processor.flush()
|
||||||
|
|
||||||
|
logger.info("Diarization complete")
|
||||||
|
|
||||||
|
except ImportError as e:
|
||||||
|
logger.error(f"Failed to import diarization dependencies: {e}")
|
||||||
|
logger.error(
|
||||||
|
"Install with: uv pip install pyannote.audio torch torchaudio"
|
||||||
|
)
|
||||||
|
logger.error(
|
||||||
|
"And set HF_TOKEN environment variable for pyannote models"
|
||||||
|
)
|
||||||
|
raise SystemExit(1)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Diarization failed: {e}")
|
||||||
|
raise SystemExit(1)
|
||||||
|
else:
|
||||||
|
logger.warning("Skipping diarization: no topics available")
|
||||||
|
|
||||||
|
# Clean up temp file
|
||||||
|
if audio_temp_path:
|
||||||
|
try:
|
||||||
|
Path(audio_temp_path).unlink()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to clean up temp file {audio_temp_path}: {e}")
|
||||||
|
|
||||||
|
logger.info("All done!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Process audio files with optional speaker diarization"
|
||||||
|
)
|
||||||
|
parser.add_argument("source", help="Source file (mp3, wav, mp4...)")
|
||||||
|
parser.add_argument(
|
||||||
|
"--only-transcript",
|
||||||
|
"-t",
|
||||||
|
action="store_true",
|
||||||
|
help="Only generate transcript without topics/summaries",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--source-language", default="en", help="Source language code (default: en)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--target-language", default="en", help="Target language code (default: en)"
|
||||||
|
)
|
||||||
|
parser.add_argument("--output", "-o", help="Output file (output.jsonl)")
|
||||||
|
parser.add_argument(
|
||||||
|
"--enable-diarization",
|
||||||
|
"-d",
|
||||||
|
action="store_true",
|
||||||
|
help="Enable speaker diarization",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--diarization-backend",
|
||||||
|
default="modal",
|
||||||
|
choices=["modal"],
|
||||||
|
help="Diarization backend to use (default: modal)",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Set REDIS_HOST to localhost if not provided
|
||||||
|
if "REDIS_HOST" not in os.environ:
|
||||||
|
os.environ["REDIS_HOST"] = "localhost"
|
||||||
|
logger.info("REDIS_HOST not set, defaulting to localhost")
|
||||||
|
|
||||||
|
output_fd = None
|
||||||
|
if args.output:
|
||||||
|
output_fd = open(args.output, "w")
|
||||||
|
|
||||||
|
async def event_callback(event: PipelineEvent):
|
||||||
|
processor = event.processor
|
||||||
|
data = event.data
|
||||||
|
|
||||||
|
# Ignore internal processors
|
||||||
|
if processor in (
|
||||||
|
"AudioDownscaleProcessor",
|
||||||
|
"AudioChunkerAutoProcessor",
|
||||||
|
"AudioMergeProcessor",
|
||||||
|
"AudioFileWriterProcessor",
|
||||||
|
"TopicCollectorProcessor",
|
||||||
|
"BroadcastProcessor",
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
# If diarization is enabled, skip the original topic events from the pipeline
|
||||||
|
# The diarization processor will emit the same topics but with speaker info
|
||||||
|
if processor == "TranscriptTopicDetectorProcessor" and args.enable_diarization:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Log all events
|
||||||
|
logger.info(f"Event: {processor} - {type(data).__name__}")
|
||||||
|
|
||||||
|
# Write to output
|
||||||
|
if output_fd:
|
||||||
|
output_fd.write(event.model_dump_json())
|
||||||
|
output_fd.write("\n")
|
||||||
|
output_fd.flush()
|
||||||
|
|
||||||
|
asyncio.run(
|
||||||
|
process_audio_file_with_diarization(
|
||||||
|
args.source,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=args.only_transcript,
|
||||||
|
source_language=args.source_language,
|
||||||
|
target_language=args.target_language,
|
||||||
|
enable_diarization=args.enable_diarization,
|
||||||
|
diarization_backend=args.diarization_backend,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if output_fd:
|
||||||
|
output_fd.close()
|
||||||
|
logger.info(f"Output written to {args.output}")
|
||||||
96
server/reflector/tools/test_diarization.py
Normal file
96
server/reflector/tools/test_diarization.py
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
@vibe-generated
|
||||||
|
Test script for the diarization CLI tool
|
||||||
|
=========================================
|
||||||
|
|
||||||
|
This script helps test the diarization functionality with sample audio files.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from reflector.logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diarization(audio_file: str):
|
||||||
|
"""Test the diarization functionality"""
|
||||||
|
|
||||||
|
# Import the processing function
|
||||||
|
from process_with_diarization import process_audio_file_with_diarization
|
||||||
|
|
||||||
|
# Collect events
|
||||||
|
events = []
|
||||||
|
|
||||||
|
async def event_callback(event):
|
||||||
|
events.append({"processor": event.processor, "data": event.data})
|
||||||
|
logger.info(f"Event from {event.processor}")
|
||||||
|
|
||||||
|
# Process the audio file
|
||||||
|
logger.info(f"Processing audio file: {audio_file}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
await process_audio_file_with_diarization(
|
||||||
|
audio_file,
|
||||||
|
event_callback,
|
||||||
|
only_transcript=False,
|
||||||
|
source_language="en",
|
||||||
|
target_language="en",
|
||||||
|
enable_diarization=True,
|
||||||
|
diarization_backend="modal",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Analyze results
|
||||||
|
logger.info(f"Processing complete. Received {len(events)} events")
|
||||||
|
|
||||||
|
# Look for diarization results
|
||||||
|
diarized_topics = []
|
||||||
|
for event in events:
|
||||||
|
if "TitleSummary" in event["processor"]:
|
||||||
|
# Check if words have speaker information
|
||||||
|
if hasattr(event["data"], "transcript") and event["data"].transcript:
|
||||||
|
words = event["data"].transcript.words
|
||||||
|
if words and hasattr(words[0], "speaker"):
|
||||||
|
speakers = set(
|
||||||
|
w.speaker for w in words if hasattr(w, "speaker")
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
f"Found {len(speakers)} speakers in topic: {event['data'].title}"
|
||||||
|
)
|
||||||
|
diarized_topics.append(event["data"])
|
||||||
|
|
||||||
|
if diarized_topics:
|
||||||
|
logger.info(f"Successfully diarized {len(diarized_topics)} topics")
|
||||||
|
|
||||||
|
# Print sample output
|
||||||
|
sample_topic = diarized_topics[0]
|
||||||
|
logger.info("Sample diarized output:")
|
||||||
|
for i, word in enumerate(sample_topic.transcript.words[:10]):
|
||||||
|
logger.info(f" Word {i}: '{word.text}' - Speaker {word.speaker}")
|
||||||
|
else:
|
||||||
|
logger.warning("No diarization results found in output")
|
||||||
|
|
||||||
|
return events
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during processing: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("Usage: python test_diarization.py <audio_file>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
audio_file = sys.argv[1]
|
||||||
|
if not Path(audio_file).exists():
|
||||||
|
print(f"Error: Audio file '{audio_file}' not found")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Run the test
|
||||||
|
asyncio.run(test_diarization(audio_file))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
from typing import Annotated
|
|
||||||
|
|
||||||
from pydantic import Field, TypeAdapter, constr
|
|
||||||
|
|
||||||
NonEmptyStringBase = constr(min_length=1, strip_whitespace=False)
|
|
||||||
NonEmptyString = Annotated[
|
|
||||||
NonEmptyStringBase,
|
|
||||||
Field(description="A non-empty string", min_length=1),
|
|
||||||
]
|
|
||||||
non_empty_string_adapter = TypeAdapter(NonEmptyString)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_non_empty_string(s: str, error: str | None = None) -> NonEmptyString:
|
|
||||||
try:
|
|
||||||
return non_empty_string_adapter.validate_python(s)
|
|
||||||
except Exception as e:
|
|
||||||
raise ValueError(f"{e}: {error}" if error else e) from e
|
|
||||||
|
|
||||||
|
|
||||||
def try_parse_non_empty_string(s: str) -> NonEmptyString | None:
|
|
||||||
if not s:
|
|
||||||
return None
|
|
||||||
return parse_non_empty_string(s)
|
|
||||||
@@ -15,7 +15,6 @@ from reflector.db.meetings import meetings_controller
|
|||||||
from reflector.db.rooms import rooms_controller
|
from reflector.db.rooms import rooms_controller
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
from reflector.whereby import create_meeting, upload_logo
|
from reflector.whereby import create_meeting, upload_logo
|
||||||
from reflector.worker.webhook import test_webhook
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -45,11 +44,6 @@ class Room(BaseModel):
|
|||||||
is_shared: bool
|
is_shared: bool
|
||||||
|
|
||||||
|
|
||||||
class RoomDetails(Room):
|
|
||||||
webhook_url: str | None
|
|
||||||
webhook_secret: str | None
|
|
||||||
|
|
||||||
|
|
||||||
class Meeting(BaseModel):
|
class Meeting(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
room_name: str
|
room_name: str
|
||||||
@@ -70,8 +64,6 @@ class CreateRoom(BaseModel):
|
|||||||
recording_type: str
|
recording_type: str
|
||||||
recording_trigger: str
|
recording_trigger: str
|
||||||
is_shared: bool
|
is_shared: bool
|
||||||
webhook_url: str
|
|
||||||
webhook_secret: str
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateRoom(BaseModel):
|
class UpdateRoom(BaseModel):
|
||||||
@@ -84,26 +76,16 @@ class UpdateRoom(BaseModel):
|
|||||||
recording_type: str
|
recording_type: str
|
||||||
recording_trigger: str
|
recording_trigger: str
|
||||||
is_shared: bool
|
is_shared: bool
|
||||||
webhook_url: str
|
|
||||||
webhook_secret: str
|
|
||||||
|
|
||||||
|
|
||||||
class DeletionStatus(BaseModel):
|
class DeletionStatus(BaseModel):
|
||||||
status: str
|
status: str
|
||||||
|
|
||||||
|
|
||||||
class WebhookTestResult(BaseModel):
|
@router.get("/rooms", response_model=Page[Room])
|
||||||
success: bool
|
|
||||||
message: str = ""
|
|
||||||
error: str = ""
|
|
||||||
status_code: int | None = None
|
|
||||||
response_preview: str | None = None
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/rooms", response_model=Page[RoomDetails])
|
|
||||||
async def rooms_list(
|
async def rooms_list(
|
||||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
||||||
) -> list[RoomDetails]:
|
) -> list[Room]:
|
||||||
if not user and not settings.PUBLIC_MODE:
|
if not user and not settings.PUBLIC_MODE:
|
||||||
raise HTTPException(status_code=401, detail="Not authenticated")
|
raise HTTPException(status_code=401, detail="Not authenticated")
|
||||||
|
|
||||||
@@ -117,18 +99,6 @@ async def rooms_list(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/rooms/{room_id}", response_model=RoomDetails)
|
|
||||||
async def rooms_get(
|
|
||||||
room_id: str,
|
|
||||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
|
||||||
):
|
|
||||||
user_id = user["sub"] if user else None
|
|
||||||
room = await rooms_controller.get_by_id_for_http(room_id, user_id=user_id)
|
|
||||||
if not room:
|
|
||||||
raise HTTPException(status_code=404, detail="Room not found")
|
|
||||||
return room
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/rooms", response_model=Room)
|
@router.post("/rooms", response_model=Room)
|
||||||
async def rooms_create(
|
async def rooms_create(
|
||||||
room: CreateRoom,
|
room: CreateRoom,
|
||||||
@@ -147,12 +117,10 @@ async def rooms_create(
|
|||||||
recording_type=room.recording_type,
|
recording_type=room.recording_type,
|
||||||
recording_trigger=room.recording_trigger,
|
recording_trigger=room.recording_trigger,
|
||||||
is_shared=room.is_shared,
|
is_shared=room.is_shared,
|
||||||
webhook_url=room.webhook_url,
|
|
||||||
webhook_secret=room.webhook_secret,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.patch("/rooms/{room_id}", response_model=RoomDetails)
|
@router.patch("/rooms/{room_id}", response_model=Room)
|
||||||
async def rooms_update(
|
async def rooms_update(
|
||||||
room_id: str,
|
room_id: str,
|
||||||
info: UpdateRoom,
|
info: UpdateRoom,
|
||||||
@@ -197,7 +165,6 @@ async def rooms_create_meeting(
|
|||||||
end_date = current_time + timedelta(hours=8)
|
end_date = current_time + timedelta(hours=8)
|
||||||
|
|
||||||
whereby_meeting = await create_meeting("", end_date=end_date, room=room)
|
whereby_meeting = await create_meeting("", end_date=end_date, room=room)
|
||||||
|
|
||||||
await upload_logo(whereby_meeting["roomName"], "./images/logo.png")
|
await upload_logo(whereby_meeting["roomName"], "./images/logo.png")
|
||||||
|
|
||||||
# Now try to save to database
|
# Now try to save to database
|
||||||
@@ -209,15 +176,20 @@ async def rooms_create_meeting(
|
|||||||
host_room_url=whereby_meeting["hostRoomUrl"],
|
host_room_url=whereby_meeting["hostRoomUrl"],
|
||||||
start_date=parse_datetime_with_timezone(whereby_meeting["startDate"]),
|
start_date=parse_datetime_with_timezone(whereby_meeting["startDate"]),
|
||||||
end_date=parse_datetime_with_timezone(whereby_meeting["endDate"]),
|
end_date=parse_datetime_with_timezone(whereby_meeting["endDate"]),
|
||||||
|
user_id=user_id,
|
||||||
room=room,
|
room=room,
|
||||||
)
|
)
|
||||||
except (asyncpg.exceptions.UniqueViolationError, sqlite3.IntegrityError):
|
except (asyncpg.exceptions.UniqueViolationError, sqlite3.IntegrityError):
|
||||||
# Another request already created a meeting for this room
|
# Another request already created a meeting for this room
|
||||||
# Log this race condition occurrence
|
# Log this race condition occurrence
|
||||||
logger.warning(
|
logger.info(
|
||||||
"Race condition detected for room %s and meeting %s - fetching existing meeting",
|
"Race condition detected for room %s - fetching existing meeting",
|
||||||
room.name,
|
room.name,
|
||||||
|
)
|
||||||
|
logger.warning(
|
||||||
|
"Whereby meeting %s was created but not used (resource leak) for room %s",
|
||||||
whereby_meeting["meetingId"],
|
whereby_meeting["meetingId"],
|
||||||
|
room.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fetch the meeting that was created by the other request
|
# Fetch the meeting that was created by the other request
|
||||||
@@ -227,9 +199,7 @@ async def rooms_create_meeting(
|
|||||||
if meeting is None:
|
if meeting is None:
|
||||||
# Edge case: meeting was created but expired/deleted between checks
|
# Edge case: meeting was created but expired/deleted between checks
|
||||||
logger.error(
|
logger.error(
|
||||||
"Meeting disappeared after race condition for room %s",
|
"Meeting disappeared after race condition for room %s", room.name
|
||||||
room.name,
|
|
||||||
exc_info=True,
|
|
||||||
)
|
)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=503, detail="Unable to join meeting - please try again"
|
status_code=503, detail="Unable to join meeting - please try again"
|
||||||
@@ -239,24 +209,3 @@ async def rooms_create_meeting(
|
|||||||
meeting.host_room_url = ""
|
meeting.host_room_url = ""
|
||||||
|
|
||||||
return meeting
|
return meeting
|
||||||
|
|
||||||
|
|
||||||
@router.post("/rooms/{room_id}/webhook/test", response_model=WebhookTestResult)
|
|
||||||
async def rooms_test_webhook(
|
|
||||||
room_id: str,
|
|
||||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
|
||||||
):
|
|
||||||
"""Test webhook configuration by sending a sample payload."""
|
|
||||||
user_id = user["sub"] if user else None
|
|
||||||
|
|
||||||
room = await rooms_controller.get_by_id(room_id)
|
|
||||||
if not room:
|
|
||||||
raise HTTPException(status_code=404, detail="Room not found")
|
|
||||||
|
|
||||||
if user_id and room.user_id != user_id:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=403, detail="Not authorized to test this room's webhook"
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await test_webhook(room_id)
|
|
||||||
return WebhookTestResult(**result)
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query
|
|||||||
from fastapi_pagination import Page
|
from fastapi_pagination import Page
|
||||||
from fastapi_pagination.ext.databases import apaginate
|
from fastapi_pagination.ext.databases import apaginate
|
||||||
from jose import jwt
|
from jose import jwt
|
||||||
from pydantic import BaseModel, Field, constr, field_serializer
|
from pydantic import BaseModel, Field, field_serializer
|
||||||
|
|
||||||
import reflector.auth as auth
|
import reflector.auth as auth
|
||||||
from reflector.db import get_database
|
from reflector.db import get_database
|
||||||
@@ -19,15 +19,14 @@ from reflector.db.search import (
|
|||||||
SearchOffsetBase,
|
SearchOffsetBase,
|
||||||
SearchParameters,
|
SearchParameters,
|
||||||
SearchQuery,
|
SearchQuery,
|
||||||
|
SearchQueryBase,
|
||||||
SearchResult,
|
SearchResult,
|
||||||
SearchTotal,
|
SearchTotal,
|
||||||
search_controller,
|
search_controller,
|
||||||
search_query_adapter,
|
|
||||||
)
|
)
|
||||||
from reflector.db.transcripts import (
|
from reflector.db.transcripts import (
|
||||||
SourceKind,
|
SourceKind,
|
||||||
TranscriptParticipant,
|
TranscriptParticipant,
|
||||||
TranscriptStatus,
|
|
||||||
TranscriptTopic,
|
TranscriptTopic,
|
||||||
transcripts_controller,
|
transcripts_controller,
|
||||||
)
|
)
|
||||||
@@ -64,7 +63,7 @@ class GetTranscriptMinimal(BaseModel):
|
|||||||
id: str
|
id: str
|
||||||
user_id: str | None
|
user_id: str | None
|
||||||
name: str
|
name: str
|
||||||
status: TranscriptStatus
|
status: str
|
||||||
locked: bool
|
locked: bool
|
||||||
duration: float
|
duration: float
|
||||||
title: str | None
|
title: str | None
|
||||||
@@ -97,7 +96,6 @@ class CreateTranscript(BaseModel):
|
|||||||
name: str
|
name: str
|
||||||
source_language: str = Field("en")
|
source_language: str = Field("en")
|
||||||
target_language: str = Field("en")
|
target_language: str = Field("en")
|
||||||
source_kind: SourceKind | None = None
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateTranscript(BaseModel):
|
class UpdateTranscript(BaseModel):
|
||||||
@@ -116,19 +114,7 @@ class DeletionStatus(BaseModel):
|
|||||||
status: str
|
status: str
|
||||||
|
|
||||||
|
|
||||||
SearchQueryParamBase = constr(min_length=0, strip_whitespace=True)
|
SearchQueryParam = Annotated[SearchQueryBase, Query(description="Search query text")]
|
||||||
SearchQueryParam = Annotated[
|
|
||||||
SearchQueryParamBase, Query(description="Search query text")
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# http and api standards accept "q="; we would like to handle it as the absence of query, not as "empty string query"
|
|
||||||
def parse_search_query_param(q: SearchQueryParam) -> SearchQuery | None:
|
|
||||||
if q == "":
|
|
||||||
return None
|
|
||||||
return search_query_adapter.validate_python(q)
|
|
||||||
|
|
||||||
|
|
||||||
SearchLimitParam = Annotated[SearchLimitBase, Query(description="Results per page")]
|
SearchLimitParam = Annotated[SearchLimitBase, Query(description="Results per page")]
|
||||||
SearchOffsetParam = Annotated[
|
SearchOffsetParam = Annotated[
|
||||||
SearchOffsetBase, Query(description="Number of results to skip")
|
SearchOffsetBase, Query(description="Number of results to skip")
|
||||||
@@ -138,7 +124,7 @@ SearchOffsetParam = Annotated[
|
|||||||
class SearchResponse(BaseModel):
|
class SearchResponse(BaseModel):
|
||||||
results: list[SearchResult]
|
results: list[SearchResult]
|
||||||
total: SearchTotal
|
total: SearchTotal
|
||||||
query: SearchQuery | None = None
|
query: SearchQuery
|
||||||
limit: SearchLimit
|
limit: SearchLimit
|
||||||
offset: SearchOffset
|
offset: SearchOffset
|
||||||
|
|
||||||
@@ -188,7 +174,7 @@ async def transcripts_search(
|
|||||||
user_id = user["sub"] if user else None
|
user_id = user["sub"] if user else None
|
||||||
|
|
||||||
search_params = SearchParameters(
|
search_params = SearchParameters(
|
||||||
query_text=parse_search_query_param(q),
|
query_text=q,
|
||||||
limit=limit,
|
limit=limit,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@@ -215,7 +201,7 @@ async def transcripts_create(
|
|||||||
user_id = user["sub"] if user else None
|
user_id = user["sub"] if user else None
|
||||||
return await transcripts_controller.add(
|
return await transcripts_controller.add(
|
||||||
info.name,
|
info.name,
|
||||||
source_kind=info.source_kind or SourceKind.LIVE,
|
source_kind=SourceKind.LIVE,
|
||||||
source_language=info.source_language,
|
source_language=info.source_language,
|
||||||
target_language=info.target_language,
|
target_language=info.target_language,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@@ -350,6 +336,8 @@ async def transcript_update(
|
|||||||
transcript = await transcripts_controller.get_by_id_for_http(
|
transcript = await transcripts_controller.get_by_id_for_http(
|
||||||
transcript_id, user_id=user_id
|
transcript_id, user_id=user_id
|
||||||
)
|
)
|
||||||
|
if not transcript:
|
||||||
|
raise HTTPException(status_code=404, detail="Transcript not found")
|
||||||
values = info.dict(exclude_unset=True)
|
values = info.dict(exclude_unset=True)
|
||||||
updated_transcript = await transcripts_controller.update(transcript, values)
|
updated_transcript = await transcripts_controller.update(transcript, values)
|
||||||
return updated_transcript
|
return updated_transcript
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
import reflector.auth as auth
|
import reflector.auth as auth
|
||||||
from reflector.db.transcripts import transcripts_controller
|
from reflector.db.transcripts import transcripts_controller
|
||||||
from reflector.pipelines.main_file_pipeline import task_pipeline_file_process
|
from reflector.pipelines.main_live_pipeline import task_pipeline_process
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -34,13 +34,13 @@ async def transcript_process(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if task_is_scheduled_or_active(
|
if task_is_scheduled_or_active(
|
||||||
"reflector.pipelines.main_file_pipeline.task_pipeline_file_process",
|
"reflector.pipelines.main_live_pipeline.task_pipeline_process",
|
||||||
transcript_id=transcript_id,
|
transcript_id=transcript_id,
|
||||||
):
|
):
|
||||||
return ProcessStatus(status="already running")
|
return ProcessStatus(status="already running")
|
||||||
|
|
||||||
# schedule a background task process the file
|
# schedule a background task process the file
|
||||||
task_pipeline_file_process.delay(transcript_id=transcript_id)
|
task_pipeline_process.delay(transcript_id=transcript_id)
|
||||||
|
|
||||||
return ProcessStatus(status="ok")
|
return ProcessStatus(status="ok")
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
import reflector.auth as auth
|
import reflector.auth as auth
|
||||||
from reflector.db.transcripts import transcripts_controller
|
from reflector.db.transcripts import transcripts_controller
|
||||||
from reflector.pipelines.main_file_pipeline import task_pipeline_file_process
|
from reflector.pipelines.main_live_pipeline import task_pipeline_process
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -92,6 +92,6 @@ async def transcript_record_upload(
|
|||||||
await transcripts_controller.update(transcript, {"status": "uploaded"})
|
await transcripts_controller.update(transcript, {"status": "uploaded"})
|
||||||
|
|
||||||
# launch a background task to process the file
|
# launch a background task to process the file
|
||||||
task_pipeline_file_process.delay(transcript_id=transcript_id)
|
task_pipeline_process.delay(transcript_id=transcript_id)
|
||||||
|
|
||||||
return UploadStatus(status="ok")
|
return UploadStatus(status="ok")
|
||||||
|
|||||||
@@ -1,60 +1,18 @@
|
|||||||
import logging
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from reflector.db.rooms import Room
|
from reflector.db.rooms import Room
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
from reflector.utils.string import parse_non_empty_string
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_headers():
|
|
||||||
api_key = parse_non_empty_string(
|
|
||||||
settings.WHEREBY_API_KEY, "WHEREBY_API_KEY value is required."
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
|
||||||
"Authorization": f"Bearer {api_key}",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
|
"Authorization": f"Bearer {settings.WHEREBY_API_KEY}",
|
||||||
|
}
|
||||||
TIMEOUT = 10 # seconds
|
TIMEOUT = 10 # seconds
|
||||||
|
|
||||||
|
|
||||||
def _get_whereby_s3_auth():
|
|
||||||
errors = []
|
|
||||||
try:
|
|
||||||
bucket_name = parse_non_empty_string(
|
|
||||||
settings.RECORDING_STORAGE_AWS_BUCKET_NAME,
|
|
||||||
"RECORDING_STORAGE_AWS_BUCKET_NAME value is required.",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
errors.append(e)
|
|
||||||
try:
|
|
||||||
key_id = parse_non_empty_string(
|
|
||||||
settings.AWS_WHEREBY_ACCESS_KEY_ID,
|
|
||||||
"AWS_WHEREBY_ACCESS_KEY_ID value is required.",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
errors.append(e)
|
|
||||||
try:
|
|
||||||
key_secret = parse_non_empty_string(
|
|
||||||
settings.AWS_WHEREBY_ACCESS_KEY_SECRET,
|
|
||||||
"AWS_WHEREBY_ACCESS_KEY_SECRET value is required.",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
errors.append(e)
|
|
||||||
if len(errors) > 0:
|
|
||||||
raise Exception(
|
|
||||||
f"Failed to get Whereby auth settings: {', '.join(str(e) for e in errors)}"
|
|
||||||
)
|
|
||||||
return bucket_name, key_id, key_secret
|
|
||||||
|
|
||||||
|
|
||||||
async def create_meeting(room_name_prefix: str, end_date: datetime, room: Room):
|
async def create_meeting(room_name_prefix: str, end_date: datetime, room: Room):
|
||||||
s3_bucket_name, s3_key_id, s3_key_secret = _get_whereby_s3_auth()
|
|
||||||
data = {
|
data = {
|
||||||
"isLocked": room.is_locked,
|
"isLocked": room.is_locked,
|
||||||
"roomNamePrefix": room_name_prefix,
|
"roomNamePrefix": room_name_prefix,
|
||||||
@@ -65,26 +23,23 @@ async def create_meeting(room_name_prefix: str, end_date: datetime, room: Room):
|
|||||||
"type": room.recording_type,
|
"type": room.recording_type,
|
||||||
"destination": {
|
"destination": {
|
||||||
"provider": "s3",
|
"provider": "s3",
|
||||||
"bucket": s3_bucket_name,
|
"bucket": settings.RECORDING_STORAGE_AWS_BUCKET_NAME,
|
||||||
"accessKeyId": s3_key_id,
|
"accessKeyId": settings.AWS_WHEREBY_ACCESS_KEY_ID,
|
||||||
"accessKeySecret": s3_key_secret,
|
"accessKeySecret": settings.AWS_WHEREBY_ACCESS_KEY_SECRET,
|
||||||
"fileFormat": "mp4",
|
"fileFormat": "mp4",
|
||||||
},
|
},
|
||||||
"startTrigger": room.recording_trigger,
|
"startTrigger": room.recording_trigger,
|
||||||
},
|
},
|
||||||
"fields": ["hostRoomUrl"],
|
"fields": ["hostRoomUrl"],
|
||||||
}
|
}
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"{settings.WHEREBY_API_URL}/meetings",
|
f"{settings.WHEREBY_API_URL}/meetings",
|
||||||
headers=_get_headers(),
|
headers=HEADERS,
|
||||||
json=data,
|
json=data,
|
||||||
timeout=TIMEOUT,
|
timeout=TIMEOUT,
|
||||||
)
|
)
|
||||||
if response.status_code == 403:
|
|
||||||
logger.warning(
|
|
||||||
f"Failed to create meeting: access denied on Whereby: {response.text}"
|
|
||||||
)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
@@ -93,7 +48,7 @@ async def get_room_sessions(room_name: str):
|
|||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
f"{settings.WHEREBY_API_URL}/insights/room-sessions?roomName={room_name}",
|
f"{settings.WHEREBY_API_URL}/insights/room-sessions?roomName={room_name}",
|
||||||
headers=_get_headers(),
|
headers=HEADERS,
|
||||||
timeout=TIMEOUT,
|
timeout=TIMEOUT,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ else:
|
|||||||
"reflector.pipelines.main_live_pipeline",
|
"reflector.pipelines.main_live_pipeline",
|
||||||
"reflector.worker.healthcheck",
|
"reflector.worker.healthcheck",
|
||||||
"reflector.worker.process",
|
"reflector.worker.process",
|
||||||
"reflector.worker.cleanup",
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,16 +38,6 @@ else:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.PUBLIC_MODE:
|
|
||||||
app.conf.beat_schedule["cleanup_old_public_data"] = {
|
|
||||||
"task": "reflector.worker.cleanup.cleanup_old_public_data_task",
|
|
||||||
"schedule": crontab(hour=3, minute=0),
|
|
||||||
}
|
|
||||||
logger.info(
|
|
||||||
"Public mode cleanup enabled",
|
|
||||||
retention_days=settings.PUBLIC_DATA_RETENTION_DAYS,
|
|
||||||
)
|
|
||||||
|
|
||||||
if settings.HEALTHCHECK_URL:
|
if settings.HEALTHCHECK_URL:
|
||||||
app.conf.beat_schedule["healthcheck_ping"] = {
|
app.conf.beat_schedule["healthcheck_ping"] = {
|
||||||
"task": "reflector.worker.healthcheck.healthcheck_ping",
|
"task": "reflector.worker.healthcheck.healthcheck_ping",
|
||||||
|
|||||||
@@ -1,156 +0,0 @@
|
|||||||
"""
|
|
||||||
Main task for cleanup old public data.
|
|
||||||
|
|
||||||
Deletes old anonymous transcripts and their associated meetings/recordings.
|
|
||||||
Transcripts are the main entry point - any associated data is also removed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
from typing import TypedDict
|
|
||||||
|
|
||||||
import structlog
|
|
||||||
from celery import shared_task
|
|
||||||
from databases import Database
|
|
||||||
from pydantic.types import PositiveInt
|
|
||||||
|
|
||||||
from reflector.asynctask import asynctask
|
|
||||||
from reflector.db import get_database
|
|
||||||
from reflector.db.meetings import meetings
|
|
||||||
from reflector.db.recordings import recordings
|
|
||||||
from reflector.db.transcripts import transcripts, transcripts_controller
|
|
||||||
from reflector.settings import settings
|
|
||||||
from reflector.storage import get_recordings_storage
|
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CleanupStats(TypedDict):
|
|
||||||
"""Statistics for cleanup operation."""
|
|
||||||
|
|
||||||
transcripts_deleted: int
|
|
||||||
meetings_deleted: int
|
|
||||||
recordings_deleted: int
|
|
||||||
errors: list[str]
|
|
||||||
|
|
||||||
|
|
||||||
async def delete_single_transcript(
|
|
||||||
db: Database, transcript_data: dict, stats: CleanupStats
|
|
||||||
):
|
|
||||||
transcript_id = transcript_data["id"]
|
|
||||||
meeting_id = transcript_data["meeting_id"]
|
|
||||||
recording_id = transcript_data["recording_id"]
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with db.transaction(isolation="serializable"):
|
|
||||||
if meeting_id:
|
|
||||||
await db.execute(meetings.delete().where(meetings.c.id == meeting_id))
|
|
||||||
stats["meetings_deleted"] += 1
|
|
||||||
logger.info("Deleted associated meeting", meeting_id=meeting_id)
|
|
||||||
|
|
||||||
if recording_id:
|
|
||||||
recording = await db.fetch_one(
|
|
||||||
recordings.select().where(recordings.c.id == recording_id)
|
|
||||||
)
|
|
||||||
if recording:
|
|
||||||
try:
|
|
||||||
await get_recordings_storage().delete_file(
|
|
||||||
recording["object_key"]
|
|
||||||
)
|
|
||||||
except Exception as storage_error:
|
|
||||||
logger.warning(
|
|
||||||
"Failed to delete recording from storage",
|
|
||||||
recording_id=recording_id,
|
|
||||||
object_key=recording["object_key"],
|
|
||||||
error=str(storage_error),
|
|
||||||
)
|
|
||||||
|
|
||||||
await db.execute(
|
|
||||||
recordings.delete().where(recordings.c.id == recording_id)
|
|
||||||
)
|
|
||||||
stats["recordings_deleted"] += 1
|
|
||||||
logger.info(
|
|
||||||
"Deleted associated recording", recording_id=recording_id
|
|
||||||
)
|
|
||||||
|
|
||||||
await transcripts_controller.remove_by_id(transcript_id)
|
|
||||||
stats["transcripts_deleted"] += 1
|
|
||||||
logger.info(
|
|
||||||
"Deleted transcript",
|
|
||||||
transcript_id=transcript_id,
|
|
||||||
created_at=transcript_data["created_at"].isoformat(),
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
error_msg = f"Failed to delete transcript {transcript_id}: {str(e)}"
|
|
||||||
logger.error(error_msg, exc_info=e)
|
|
||||||
stats["errors"].append(error_msg)
|
|
||||||
|
|
||||||
|
|
||||||
async def cleanup_old_transcripts(
|
|
||||||
db: Database, cutoff_date: datetime, stats: CleanupStats
|
|
||||||
):
|
|
||||||
"""Delete old anonymous transcripts and their associated recordings/meetings."""
|
|
||||||
query = transcripts.select().where(
|
|
||||||
(transcripts.c.created_at < cutoff_date) & (transcripts.c.user_id.is_(None))
|
|
||||||
)
|
|
||||||
old_transcripts = await db.fetch_all(query)
|
|
||||||
|
|
||||||
logger.info(f"Found {len(old_transcripts)} old transcripts to delete")
|
|
||||||
|
|
||||||
for transcript_data in old_transcripts:
|
|
||||||
await delete_single_transcript(db, transcript_data, stats)
|
|
||||||
|
|
||||||
|
|
||||||
def log_cleanup_results(stats: CleanupStats):
|
|
||||||
logger.info(
|
|
||||||
"Cleanup completed",
|
|
||||||
transcripts_deleted=stats["transcripts_deleted"],
|
|
||||||
meetings_deleted=stats["meetings_deleted"],
|
|
||||||
recordings_deleted=stats["recordings_deleted"],
|
|
||||||
errors_count=len(stats["errors"]),
|
|
||||||
)
|
|
||||||
|
|
||||||
if stats["errors"]:
|
|
||||||
logger.warning(
|
|
||||||
"Cleanup completed with errors",
|
|
||||||
errors=stats["errors"][:10],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def cleanup_old_public_data(
|
|
||||||
days: PositiveInt | None = None,
|
|
||||||
) -> CleanupStats | None:
|
|
||||||
if days is None:
|
|
||||||
days = settings.PUBLIC_DATA_RETENTION_DAYS
|
|
||||||
|
|
||||||
if not settings.PUBLIC_MODE:
|
|
||||||
logger.info("Skipping cleanup - not a public instance")
|
|
||||||
return None
|
|
||||||
|
|
||||||
cutoff_date = datetime.now(timezone.utc) - timedelta(days=days)
|
|
||||||
logger.info(
|
|
||||||
"Starting cleanup of old public data",
|
|
||||||
cutoff_date=cutoff_date.isoformat(),
|
|
||||||
)
|
|
||||||
|
|
||||||
stats: CleanupStats = {
|
|
||||||
"transcripts_deleted": 0,
|
|
||||||
"meetings_deleted": 0,
|
|
||||||
"recordings_deleted": 0,
|
|
||||||
"errors": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
db = get_database()
|
|
||||||
await cleanup_old_transcripts(db, cutoff_date, stats)
|
|
||||||
|
|
||||||
log_cleanup_results(stats)
|
|
||||||
return stats
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task(
|
|
||||||
autoretry_for=(Exception,),
|
|
||||||
retry_kwargs={"max_retries": 3, "countdown": 300},
|
|
||||||
)
|
|
||||||
@asynctask
|
|
||||||
def cleanup_old_public_data_task(days: int | None = None):
|
|
||||||
asyncio.run(cleanup_old_public_data(days=days))
|
|
||||||
@@ -1,258 +0,0 @@
|
|||||||
"""Webhook task for sending transcript notifications."""
|
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import hmac
|
|
||||||
import json
|
|
||||||
import uuid
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
import httpx
|
|
||||||
import structlog
|
|
||||||
from celery import shared_task
|
|
||||||
from celery.utils.log import get_task_logger
|
|
||||||
|
|
||||||
from reflector.db.rooms import rooms_controller
|
|
||||||
from reflector.db.transcripts import transcripts_controller
|
|
||||||
from reflector.pipelines.main_live_pipeline import asynctask
|
|
||||||
from reflector.settings import settings
|
|
||||||
from reflector.utils.webvtt import topics_to_webvtt
|
|
||||||
|
|
||||||
logger = structlog.wrap_logger(get_task_logger(__name__))
|
|
||||||
|
|
||||||
|
|
||||||
def generate_webhook_signature(payload: bytes, secret: str, timestamp: str) -> str:
|
|
||||||
"""Generate HMAC signature for webhook payload."""
|
|
||||||
signed_payload = f"{timestamp}.{payload.decode('utf-8')}"
|
|
||||||
hmac_obj = hmac.new(
|
|
||||||
secret.encode("utf-8"),
|
|
||||||
signed_payload.encode("utf-8"),
|
|
||||||
hashlib.sha256,
|
|
||||||
)
|
|
||||||
return hmac_obj.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task(
|
|
||||||
bind=True,
|
|
||||||
max_retries=30,
|
|
||||||
default_retry_delay=60,
|
|
||||||
retry_backoff=True,
|
|
||||||
retry_backoff_max=3600, # Max 1 hour between retries
|
|
||||||
)
|
|
||||||
@asynctask
|
|
||||||
async def send_transcript_webhook(
|
|
||||||
self,
|
|
||||||
transcript_id: str,
|
|
||||||
room_id: str,
|
|
||||||
event_id: str,
|
|
||||||
):
|
|
||||||
log = logger.bind(
|
|
||||||
transcript_id=transcript_id,
|
|
||||||
room_id=room_id,
|
|
||||||
retry_count=self.request.retries,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Fetch transcript and room
|
|
||||||
transcript = await transcripts_controller.get_by_id(transcript_id)
|
|
||||||
if not transcript:
|
|
||||||
log.error("Transcript not found, skipping webhook")
|
|
||||||
return
|
|
||||||
|
|
||||||
room = await rooms_controller.get_by_id(room_id)
|
|
||||||
if not room:
|
|
||||||
log.error("Room not found, skipping webhook")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not room.webhook_url:
|
|
||||||
log.info("No webhook URL configured for room, skipping")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Generate WebVTT content from topics
|
|
||||||
topics_data = []
|
|
||||||
|
|
||||||
if transcript.topics:
|
|
||||||
# Build topics data with diarized content per topic
|
|
||||||
for topic in transcript.topics:
|
|
||||||
topic_webvtt = topics_to_webvtt([topic]) if topic.words else ""
|
|
||||||
topics_data.append(
|
|
||||||
{
|
|
||||||
"title": topic.title,
|
|
||||||
"summary": topic.summary,
|
|
||||||
"timestamp": topic.timestamp,
|
|
||||||
"duration": topic.duration,
|
|
||||||
"webvtt": topic_webvtt,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Build webhook payload
|
|
||||||
frontend_url = f"{settings.UI_BASE_URL}/transcripts/{transcript.id}"
|
|
||||||
participants = [
|
|
||||||
{"id": p.id, "name": p.name, "speaker": p.speaker}
|
|
||||||
for p in (transcript.participants or [])
|
|
||||||
]
|
|
||||||
payload_data = {
|
|
||||||
"event": "transcript.completed",
|
|
||||||
"event_id": event_id,
|
|
||||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
||||||
"transcript": {
|
|
||||||
"id": transcript.id,
|
|
||||||
"room_id": transcript.room_id,
|
|
||||||
"created_at": transcript.created_at.isoformat(),
|
|
||||||
"duration": transcript.duration,
|
|
||||||
"title": transcript.title,
|
|
||||||
"short_summary": transcript.short_summary,
|
|
||||||
"long_summary": transcript.long_summary,
|
|
||||||
"webvtt": transcript.webvtt,
|
|
||||||
"topics": topics_data,
|
|
||||||
"participants": participants,
|
|
||||||
"source_language": transcript.source_language,
|
|
||||||
"target_language": transcript.target_language,
|
|
||||||
"status": transcript.status,
|
|
||||||
"frontend_url": frontend_url,
|
|
||||||
},
|
|
||||||
"room": {
|
|
||||||
"id": room.id,
|
|
||||||
"name": room.name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
# Convert to JSON
|
|
||||||
payload_json = json.dumps(payload_data, separators=(",", ":"))
|
|
||||||
payload_bytes = payload_json.encode("utf-8")
|
|
||||||
|
|
||||||
# Generate signature if secret is configured
|
|
||||||
headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": "Reflector-Webhook/1.0",
|
|
||||||
"X-Webhook-Event": "transcript.completed",
|
|
||||||
"X-Webhook-Retry": str(self.request.retries),
|
|
||||||
}
|
|
||||||
|
|
||||||
if room.webhook_secret:
|
|
||||||
timestamp = str(int(datetime.now(timezone.utc).timestamp()))
|
|
||||||
signature = generate_webhook_signature(
|
|
||||||
payload_bytes, room.webhook_secret, timestamp
|
|
||||||
)
|
|
||||||
headers["X-Webhook-Signature"] = f"t={timestamp},v1={signature}"
|
|
||||||
|
|
||||||
# Send webhook with timeout
|
|
||||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
||||||
log.info(
|
|
||||||
"Sending webhook",
|
|
||||||
url=room.webhook_url,
|
|
||||||
payload_size=len(payload_bytes),
|
|
||||||
)
|
|
||||||
|
|
||||||
response = await client.post(
|
|
||||||
room.webhook_url,
|
|
||||||
content=payload_bytes,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
"Webhook sent successfully",
|
|
||||||
status_code=response.status_code,
|
|
||||||
response_size=len(response.content),
|
|
||||||
)
|
|
||||||
|
|
||||||
except httpx.HTTPStatusError as e:
|
|
||||||
log.error(
|
|
||||||
"Webhook failed with HTTP error",
|
|
||||||
status_code=e.response.status_code,
|
|
||||||
response_text=e.response.text[:500], # First 500 chars
|
|
||||||
)
|
|
||||||
|
|
||||||
# Don't retry on client errors (4xx)
|
|
||||||
if 400 <= e.response.status_code < 500:
|
|
||||||
log.error("Client error, not retrying")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Retry on server errors (5xx)
|
|
||||||
raise self.retry(exc=e)
|
|
||||||
|
|
||||||
except (httpx.ConnectError, httpx.TimeoutException) as e:
|
|
||||||
# Retry on network errors
|
|
||||||
log.error("Webhook failed with connection error", error=str(e))
|
|
||||||
raise self.retry(exc=e)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
# Retry on unexpected errors
|
|
||||||
log.exception("Unexpected error in webhook task", error=str(e))
|
|
||||||
raise self.retry(exc=e)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_webhook(room_id: str) -> dict:
|
|
||||||
"""
|
|
||||||
Test webhook configuration by sending a sample payload.
|
|
||||||
Returns immediately with success/failure status.
|
|
||||||
This is the shared implementation used by both the API endpoint and Celery task.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
room = await rooms_controller.get_by_id(room_id)
|
|
||||||
if not room:
|
|
||||||
return {"success": False, "error": "Room not found"}
|
|
||||||
|
|
||||||
if not room.webhook_url:
|
|
||||||
return {"success": False, "error": "No webhook URL configured"}
|
|
||||||
|
|
||||||
now = (datetime.now(timezone.utc).isoformat(),)
|
|
||||||
payload_data = {
|
|
||||||
"event": "test",
|
|
||||||
"event_id": uuid.uuid4().hex,
|
|
||||||
"timestamp": now,
|
|
||||||
"message": "This is a test webhook from Reflector",
|
|
||||||
"room": {
|
|
||||||
"id": room.id,
|
|
||||||
"name": room.name,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
payload_json = json.dumps(payload_data, separators=(",", ":"))
|
|
||||||
payload_bytes = payload_json.encode("utf-8")
|
|
||||||
|
|
||||||
# Generate headers with signature
|
|
||||||
headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": "Reflector-Webhook/1.0",
|
|
||||||
"X-Webhook-Event": "test",
|
|
||||||
}
|
|
||||||
|
|
||||||
if room.webhook_secret:
|
|
||||||
timestamp = str(int(datetime.now(timezone.utc).timestamp()))
|
|
||||||
signature = generate_webhook_signature(
|
|
||||||
payload_bytes, room.webhook_secret, timestamp
|
|
||||||
)
|
|
||||||
headers["X-Webhook-Signature"] = f"t={timestamp},v1={signature}"
|
|
||||||
|
|
||||||
# Send test webhook with short timeout
|
|
||||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
||||||
response = await client.post(
|
|
||||||
room.webhook_url,
|
|
||||||
content=payload_bytes,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"success": response.is_success,
|
|
||||||
"status_code": response.status_code,
|
|
||||||
"message": f"Webhook test {'successful' if response.is_success else 'failed'}",
|
|
||||||
"response_preview": response.text if response.text else None,
|
|
||||||
}
|
|
||||||
|
|
||||||
except httpx.TimeoutException:
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"error": "Webhook request timed out (10 seconds)",
|
|
||||||
}
|
|
||||||
except httpx.ConnectError as e:
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"error": f"Could not connect to webhook URL: {str(e)}",
|
|
||||||
}
|
|
||||||
except Exception as e:
|
|
||||||
return {
|
|
||||||
"success": False,
|
|
||||||
"error": f"Unexpected error: {str(e)}",
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
if [ "${ENTRYPOINT}" = "server" ]; then
|
if [ "${ENTRYPOINT}" = "server" ]; then
|
||||||
uv run alembic upgrade head
|
uv run alembic upgrade head
|
||||||
uv run uvicorn reflector.app:app --host 0.0.0.0 --port 1250
|
uv run -m reflector.app
|
||||||
elif [ "${ENTRYPOINT}" = "worker" ]; then
|
elif [ "${ENTRYPOINT}" = "worker" ]; then
|
||||||
uv run celery -A reflector.worker.app worker --loglevel=info
|
uv run celery -A reflector.worker.app worker --loglevel=info
|
||||||
elif [ "${ENTRYPOINT}" = "beat" ]; then
|
elif [ "${ENTRYPOINT}" = "beat" ]; then
|
||||||
|
|||||||
@@ -178,63 +178,6 @@ async def dummy_diarization():
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
async def dummy_file_transcript():
|
|
||||||
from reflector.processors.file_transcript import FileTranscriptProcessor
|
|
||||||
from reflector.processors.types import Transcript, Word
|
|
||||||
|
|
||||||
class TestFileTranscriptProcessor(FileTranscriptProcessor):
|
|
||||||
async def _transcript(self, data):
|
|
||||||
return Transcript(
|
|
||||||
text="Hello world. How are you today?",
|
|
||||||
words=[
|
|
||||||
Word(start=0.0, end=0.5, text="Hello", speaker=0),
|
|
||||||
Word(start=0.5, end=0.6, text=" ", speaker=0),
|
|
||||||
Word(start=0.6, end=1.0, text="world", speaker=0),
|
|
||||||
Word(start=1.0, end=1.1, text=".", speaker=0),
|
|
||||||
Word(start=1.1, end=1.2, text=" ", speaker=0),
|
|
||||||
Word(start=1.2, end=1.5, text="How", speaker=0),
|
|
||||||
Word(start=1.5, end=1.6, text=" ", speaker=0),
|
|
||||||
Word(start=1.6, end=1.8, text="are", speaker=0),
|
|
||||||
Word(start=1.8, end=1.9, text=" ", speaker=0),
|
|
||||||
Word(start=1.9, end=2.1, text="you", speaker=0),
|
|
||||||
Word(start=2.1, end=2.2, text=" ", speaker=0),
|
|
||||||
Word(start=2.2, end=2.5, text="today", speaker=0),
|
|
||||||
Word(start=2.5, end=2.6, text="?", speaker=0),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"reflector.processors.file_transcript_auto.FileTranscriptAutoProcessor.__new__"
|
|
||||||
) as mock_auto:
|
|
||||||
mock_auto.return_value = TestFileTranscriptProcessor()
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
async def dummy_file_diarization():
|
|
||||||
from reflector.processors.file_diarization import (
|
|
||||||
FileDiarizationOutput,
|
|
||||||
FileDiarizationProcessor,
|
|
||||||
)
|
|
||||||
from reflector.processors.types import DiarizationSegment
|
|
||||||
|
|
||||||
class TestFileDiarizationProcessor(FileDiarizationProcessor):
|
|
||||||
async def _diarize(self, data):
|
|
||||||
return FileDiarizationOutput(
|
|
||||||
diarization=[
|
|
||||||
DiarizationSegment(start=0.0, end=1.1, speaker=0),
|
|
||||||
DiarizationSegment(start=1.2, end=2.6, speaker=1),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"reflector.processors.file_diarization_auto.FileDiarizationAutoProcessor.__new__"
|
|
||||||
) as mock_auto:
|
|
||||||
mock_auto.return_value = TestFileDiarizationProcessor()
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def dummy_transcript_translator():
|
async def dummy_transcript_translator():
|
||||||
from reflector.processors.transcript_translator import TranscriptTranslatorProcessor
|
from reflector.processors.transcript_translator import TranscriptTranslatorProcessor
|
||||||
@@ -295,13 +238,9 @@ async def dummy_storage():
|
|||||||
with (
|
with (
|
||||||
patch("reflector.storage.base.Storage.get_instance") as mock_storage,
|
patch("reflector.storage.base.Storage.get_instance") as mock_storage,
|
||||||
patch("reflector.storage.get_transcripts_storage") as mock_get_transcripts,
|
patch("reflector.storage.get_transcripts_storage") as mock_get_transcripts,
|
||||||
patch(
|
|
||||||
"reflector.pipelines.main_file_pipeline.get_transcripts_storage"
|
|
||||||
) as mock_get_transcripts2,
|
|
||||||
):
|
):
|
||||||
mock_storage.return_value = dummy
|
mock_storage.return_value = dummy
|
||||||
mock_get_transcripts.return_value = dummy
|
mock_get_transcripts.return_value = dummy
|
||||||
mock_get_transcripts2.return_value = dummy
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
@@ -321,10 +260,7 @@ def celery_config():
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def celery_includes():
|
def celery_includes():
|
||||||
return [
|
return ["reflector.pipelines.main_live_pipeline"]
|
||||||
"reflector.pipelines.main_live_pipeline",
|
|
||||||
"reflector.pipelines.main_file_pipeline",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -366,7 +302,7 @@ async def fake_transcript_with_topics(tmpdir, client):
|
|||||||
transcript = await transcripts_controller.get_by_id(tid)
|
transcript = await transcripts_controller.get_by_id(tid)
|
||||||
assert transcript is not None
|
assert transcript is not None
|
||||||
|
|
||||||
await transcripts_controller.update(transcript, {"status": "ended"})
|
await transcripts_controller.update(transcript, {"status": "finished"})
|
||||||
|
|
||||||
# manually copy a file at the expected location
|
# manually copy a file at the expected location
|
||||||
audio_filename = transcript.audio_mp3_filename
|
audio_filename = transcript.audio_mp3_filename
|
||||||
|
|||||||
@@ -1,285 +0,0 @@
|
|||||||
from datetime import datetime, timedelta, timezone
|
|
||||||
from unittest.mock import AsyncMock, patch
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from reflector.db.recordings import Recording, recordings_controller
|
|
||||||
from reflector.db.transcripts import SourceKind, transcripts_controller
|
|
||||||
from reflector.worker.cleanup import cleanup_old_public_data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_cleanup_old_public_data_skips_when_not_public():
|
|
||||||
"""Test that cleanup is skipped when PUBLIC_MODE is False."""
|
|
||||||
with patch("reflector.worker.cleanup.settings") as mock_settings:
|
|
||||||
mock_settings.PUBLIC_MODE = False
|
|
||||||
|
|
||||||
result = await cleanup_old_public_data()
|
|
||||||
|
|
||||||
# Should return early without doing anything
|
|
||||||
assert result is None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_cleanup_old_public_data_deletes_old_anonymous_transcripts():
|
|
||||||
"""Test that old anonymous transcripts are deleted."""
|
|
||||||
# Create old and new anonymous transcripts
|
|
||||||
old_date = datetime.now(timezone.utc) - timedelta(days=8)
|
|
||||||
new_date = datetime.now(timezone.utc) - timedelta(days=2)
|
|
||||||
|
|
||||||
# Create old anonymous transcript (should be deleted)
|
|
||||||
old_transcript = await transcripts_controller.add(
|
|
||||||
name="Old Anonymous Transcript",
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
user_id=None, # Anonymous
|
|
||||||
)
|
|
||||||
# Manually update created_at to be old
|
|
||||||
from reflector.db import get_database
|
|
||||||
from reflector.db.transcripts import transcripts
|
|
||||||
|
|
||||||
await get_database().execute(
|
|
||||||
transcripts.update()
|
|
||||||
.where(transcripts.c.id == old_transcript.id)
|
|
||||||
.values(created_at=old_date)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create new anonymous transcript (should NOT be deleted)
|
|
||||||
new_transcript = await transcripts_controller.add(
|
|
||||||
name="New Anonymous Transcript",
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
user_id=None, # Anonymous
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create old transcript with user (should NOT be deleted)
|
|
||||||
old_user_transcript = await transcripts_controller.add(
|
|
||||||
name="Old User Transcript",
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
user_id="user123",
|
|
||||||
)
|
|
||||||
await get_database().execute(
|
|
||||||
transcripts.update()
|
|
||||||
.where(transcripts.c.id == old_user_transcript.id)
|
|
||||||
.values(created_at=old_date)
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("reflector.worker.cleanup.settings") as mock_settings:
|
|
||||||
mock_settings.PUBLIC_MODE = True
|
|
||||||
mock_settings.PUBLIC_DATA_RETENTION_DAYS = 7
|
|
||||||
|
|
||||||
# Mock the storage deletion
|
|
||||||
with patch("reflector.db.transcripts.get_transcripts_storage") as mock_storage:
|
|
||||||
mock_storage.return_value.delete_file = AsyncMock()
|
|
||||||
|
|
||||||
result = await cleanup_old_public_data()
|
|
||||||
|
|
||||||
# Check results
|
|
||||||
assert result["transcripts_deleted"] == 1
|
|
||||||
assert result["errors"] == []
|
|
||||||
|
|
||||||
# Verify old anonymous transcript was deleted
|
|
||||||
assert await transcripts_controller.get_by_id(old_transcript.id) is None
|
|
||||||
|
|
||||||
# Verify new anonymous transcript still exists
|
|
||||||
assert await transcripts_controller.get_by_id(new_transcript.id) is not None
|
|
||||||
|
|
||||||
# Verify user transcript still exists
|
|
||||||
assert await transcripts_controller.get_by_id(old_user_transcript.id) is not None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_cleanup_deletes_associated_meeting_and_recording():
|
|
||||||
"""Test that meetings and recordings associated with old transcripts are deleted."""
|
|
||||||
from reflector.db import get_database
|
|
||||||
from reflector.db.meetings import meetings
|
|
||||||
from reflector.db.transcripts import transcripts
|
|
||||||
|
|
||||||
old_date = datetime.now(timezone.utc) - timedelta(days=8)
|
|
||||||
|
|
||||||
# Create a meeting
|
|
||||||
meeting_id = "test-meeting-for-transcript"
|
|
||||||
await get_database().execute(
|
|
||||||
meetings.insert().values(
|
|
||||||
id=meeting_id,
|
|
||||||
room_name="Meeting with Transcript",
|
|
||||||
room_url="https://example.com/meeting",
|
|
||||||
host_room_url="https://example.com/meeting-host",
|
|
||||||
start_date=old_date,
|
|
||||||
end_date=old_date + timedelta(hours=1),
|
|
||||||
room_id=None,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create a recording
|
|
||||||
recording = await recordings_controller.create(
|
|
||||||
Recording(
|
|
||||||
bucket_name="test-bucket",
|
|
||||||
object_key="test-recording.mp4",
|
|
||||||
recorded_at=old_date,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create an old transcript with both meeting and recording
|
|
||||||
old_transcript = await transcripts_controller.add(
|
|
||||||
name="Old Transcript with Meeting and Recording",
|
|
||||||
source_kind=SourceKind.ROOM,
|
|
||||||
user_id=None,
|
|
||||||
meeting_id=meeting_id,
|
|
||||||
recording_id=recording.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update created_at to be old
|
|
||||||
await get_database().execute(
|
|
||||||
transcripts.update()
|
|
||||||
.where(transcripts.c.id == old_transcript.id)
|
|
||||||
.values(created_at=old_date)
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("reflector.worker.cleanup.settings") as mock_settings:
|
|
||||||
mock_settings.PUBLIC_MODE = True
|
|
||||||
mock_settings.PUBLIC_DATA_RETENTION_DAYS = 7
|
|
||||||
|
|
||||||
# Mock storage deletion
|
|
||||||
with patch("reflector.db.transcripts.get_transcripts_storage") as mock_storage:
|
|
||||||
mock_storage.return_value.delete_file = AsyncMock()
|
|
||||||
with patch(
|
|
||||||
"reflector.worker.cleanup.get_recordings_storage"
|
|
||||||
) as mock_rec_storage:
|
|
||||||
mock_rec_storage.return_value.delete_file = AsyncMock()
|
|
||||||
|
|
||||||
result = await cleanup_old_public_data()
|
|
||||||
|
|
||||||
# Check results
|
|
||||||
assert result["transcripts_deleted"] == 1
|
|
||||||
assert result["meetings_deleted"] == 1
|
|
||||||
assert result["recordings_deleted"] == 1
|
|
||||||
assert result["errors"] == []
|
|
||||||
|
|
||||||
# Verify transcript was deleted
|
|
||||||
assert await transcripts_controller.get_by_id(old_transcript.id) is None
|
|
||||||
|
|
||||||
# Verify meeting was deleted
|
|
||||||
query = meetings.select().where(meetings.c.id == meeting_id)
|
|
||||||
meeting_result = await get_database().fetch_one(query)
|
|
||||||
assert meeting_result is None
|
|
||||||
|
|
||||||
# Verify recording was deleted
|
|
||||||
assert await recordings_controller.get_by_id(recording.id) is None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_cleanup_handles_errors_gracefully():
|
|
||||||
"""Test that cleanup continues even when individual deletions fail."""
|
|
||||||
old_date = datetime.now(timezone.utc) - timedelta(days=8)
|
|
||||||
|
|
||||||
# Create multiple old transcripts
|
|
||||||
transcript1 = await transcripts_controller.add(
|
|
||||||
name="Transcript 1",
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
user_id=None,
|
|
||||||
)
|
|
||||||
transcript2 = await transcripts_controller.add(
|
|
||||||
name="Transcript 2",
|
|
||||||
source_kind=SourceKind.FILE,
|
|
||||||
user_id=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update created_at to be old
|
|
||||||
from reflector.db import get_database
|
|
||||||
from reflector.db.transcripts import transcripts
|
|
||||||
|
|
||||||
for t_id in [transcript1.id, transcript2.id]:
|
|
||||||
await get_database().execute(
|
|
||||||
transcripts.update()
|
|
||||||
.where(transcripts.c.id == t_id)
|
|
||||||
.values(created_at=old_date)
|
|
||||||
)
|
|
||||||
|
|
||||||
with patch("reflector.worker.cleanup.settings") as mock_settings:
|
|
||||||
mock_settings.PUBLIC_MODE = True
|
|
||||||
mock_settings.PUBLIC_DATA_RETENTION_DAYS = 7
|
|
||||||
|
|
||||||
# Mock remove_by_id to fail for the first transcript
|
|
||||||
original_remove = transcripts_controller.remove_by_id
|
|
||||||
call_count = 0
|
|
||||||
|
|
||||||
async def mock_remove_by_id(transcript_id, user_id=None):
|
|
||||||
nonlocal call_count
|
|
||||||
call_count += 1
|
|
||||||
if call_count == 1:
|
|
||||||
raise Exception("Simulated deletion error")
|
|
||||||
return await original_remove(transcript_id, user_id)
|
|
||||||
|
|
||||||
with patch.object(
|
|
||||||
transcripts_controller, "remove_by_id", side_effect=mock_remove_by_id
|
|
||||||
):
|
|
||||||
result = await cleanup_old_public_data()
|
|
||||||
|
|
||||||
# Should have one successful deletion and one error
|
|
||||||
assert result["transcripts_deleted"] == 1
|
|
||||||
assert len(result["errors"]) == 1
|
|
||||||
assert "Failed to delete transcript" in result["errors"][0]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_meeting_consent_cascade_delete():
|
|
||||||
"""Test that meeting_consent records are automatically deleted when meeting is deleted."""
|
|
||||||
from reflector.db import get_database
|
|
||||||
from reflector.db.meetings import (
|
|
||||||
meeting_consent,
|
|
||||||
meeting_consent_controller,
|
|
||||||
meetings,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create a meeting
|
|
||||||
meeting_id = "test-cascade-meeting"
|
|
||||||
await get_database().execute(
|
|
||||||
meetings.insert().values(
|
|
||||||
id=meeting_id,
|
|
||||||
room_name="Test Meeting for CASCADE",
|
|
||||||
room_url="https://example.com/cascade-test",
|
|
||||||
host_room_url="https://example.com/cascade-test-host",
|
|
||||||
start_date=datetime.now(timezone.utc),
|
|
||||||
end_date=datetime.now(timezone.utc) + timedelta(hours=1),
|
|
||||||
room_id=None,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create consent records for this meeting
|
|
||||||
consent1_id = "consent-1"
|
|
||||||
consent2_id = "consent-2"
|
|
||||||
|
|
||||||
await get_database().execute(
|
|
||||||
meeting_consent.insert().values(
|
|
||||||
id=consent1_id,
|
|
||||||
meeting_id=meeting_id,
|
|
||||||
user_id="user1",
|
|
||||||
consent_given=True,
|
|
||||||
consent_timestamp=datetime.now(timezone.utc),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
await get_database().execute(
|
|
||||||
meeting_consent.insert().values(
|
|
||||||
id=consent2_id,
|
|
||||||
meeting_id=meeting_id,
|
|
||||||
user_id="user2",
|
|
||||||
consent_given=False,
|
|
||||||
consent_timestamp=datetime.now(timezone.utc),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify consent records exist
|
|
||||||
consents = await meeting_consent_controller.get_by_meeting_id(meeting_id)
|
|
||||||
assert len(consents) == 2
|
|
||||||
|
|
||||||
# Delete the meeting
|
|
||||||
await get_database().execute(meetings.delete().where(meetings.c.id == meeting_id))
|
|
||||||
|
|
||||||
# Verify meeting is deleted
|
|
||||||
query = meetings.select().where(meetings.c.id == meeting_id)
|
|
||||||
result = await get_database().fetch_one(query)
|
|
||||||
assert result is None
|
|
||||||
|
|
||||||
# Verify consent records are automatically deleted (CASCADE DELETE)
|
|
||||||
consents_after = await meeting_consent_controller.get_by_meeting_id(meeting_id)
|
|
||||||
assert len(consents_after) == 0
|
|
||||||
@@ -272,9 +272,6 @@ class TestGPUModalTranscript:
|
|||||||
for f in temp_files:
|
for f in temp_files:
|
||||||
Path(f).unlink(missing_ok=True)
|
Path(f).unlink(missing_ok=True)
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
not "parakeet" in get_model_name(), reason="Parakeet only supports English"
|
|
||||||
)
|
|
||||||
def test_transcriptions_error_handling(self):
|
def test_transcriptions_error_handling(self):
|
||||||
"""Test error handling for invalid requests."""
|
"""Test error handling for invalid requests."""
|
||||||
url = get_modal_transcript_url()
|
url = get_modal_transcript_url()
|
||||||
|
|||||||
61
server/tests/test_processors_pipeline.py
Normal file
61
server/tests/test_processors_pipeline.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize("enable_diarization", [False, True])
|
||||||
|
async def test_basic_process(
|
||||||
|
dummy_transcript,
|
||||||
|
dummy_llm,
|
||||||
|
dummy_processors,
|
||||||
|
enable_diarization,
|
||||||
|
dummy_diarization,
|
||||||
|
):
|
||||||
|
# goal is to start the server, and send rtc audio to it
|
||||||
|
# validate the events received
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from reflector.settings import settings
|
||||||
|
from reflector.tools.process import process_audio_file
|
||||||
|
|
||||||
|
# LLM_BACKEND no longer exists in settings
|
||||||
|
# settings.LLM_BACKEND = "test"
|
||||||
|
settings.TRANSCRIPT_BACKEND = "whisper"
|
||||||
|
|
||||||
|
# event callback
|
||||||
|
marks = {}
|
||||||
|
|
||||||
|
async def event_callback(event):
|
||||||
|
if event.processor not in marks:
|
||||||
|
marks[event.processor] = 0
|
||||||
|
marks[event.processor] += 1
|
||||||
|
|
||||||
|
# invoke the process and capture events
|
||||||
|
path = Path(__file__).parent / "records" / "test_mathieu_hello.wav"
|
||||||
|
|
||||||
|
if enable_diarization:
|
||||||
|
# Test with diarization - may fail if pyannote.audio is not installed
|
||||||
|
try:
|
||||||
|
await process_audio_file(
|
||||||
|
path.as_posix(), event_callback, enable_diarization=True
|
||||||
|
)
|
||||||
|
except SystemExit:
|
||||||
|
pytest.skip("pyannote.audio not installed - skipping diarization test")
|
||||||
|
else:
|
||||||
|
# Test without diarization - should always work
|
||||||
|
await process_audio_file(
|
||||||
|
path.as_posix(), event_callback, enable_diarization=False
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Diarization: {enable_diarization}, Marks: {marks}")
|
||||||
|
|
||||||
|
# validate the events
|
||||||
|
# Each processor should be called for each audio segment processed
|
||||||
|
# The final processors (Topic, Title, Summary) should be called once at the end
|
||||||
|
assert marks["TranscriptLinerProcessor"] > 0
|
||||||
|
assert marks["TranscriptTranslatorPassthroughProcessor"] > 0
|
||||||
|
assert marks["TranscriptTopicDetectorProcessor"] == 1
|
||||||
|
assert marks["TranscriptFinalSummaryProcessor"] == 1
|
||||||
|
assert marks["TranscriptFinalTitleProcessor"] == 1
|
||||||
|
|
||||||
|
if enable_diarization:
|
||||||
|
assert marks["TestAudioDiarizationProcessor"] == 1
|
||||||
@@ -23,7 +23,7 @@ async def test_search_postgresql_only():
|
|||||||
assert results == []
|
assert results == []
|
||||||
assert total == 0
|
assert total == 0
|
||||||
|
|
||||||
params_empty = SearchParameters(query_text=None)
|
params_empty = SearchParameters(query_text="")
|
||||||
results_empty, total_empty = await search_controller.search_transcripts(
|
results_empty, total_empty = await search_controller.search_transcripts(
|
||||||
params_empty
|
params_empty
|
||||||
)
|
)
|
||||||
@@ -34,7 +34,7 @@ async def test_search_postgresql_only():
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_search_with_empty_query():
|
async def test_search_with_empty_query():
|
||||||
"""Test that empty query returns all transcripts."""
|
"""Test that empty query returns all transcripts."""
|
||||||
params = SearchParameters(query_text=None)
|
params = SearchParameters(query_text="")
|
||||||
results, total = await search_controller.search_transcripts(params)
|
results, total = await search_controller.search_transcripts(params)
|
||||||
|
|
||||||
assert isinstance(results, list)
|
assert isinstance(results, list)
|
||||||
@@ -58,7 +58,7 @@ async def test_empty_transcript_title_only_match():
|
|||||||
"id": test_id,
|
"id": test_id,
|
||||||
"name": "Empty Transcript",
|
"name": "Empty Transcript",
|
||||||
"title": "Empty Meeting",
|
"title": "Empty Meeting",
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 0.0,
|
"duration": 0.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
@@ -109,7 +109,7 @@ async def test_search_with_long_summary():
|
|||||||
"id": test_id,
|
"id": test_id,
|
||||||
"name": "Test Long Summary",
|
"name": "Test Long Summary",
|
||||||
"title": "Regular Meeting",
|
"title": "Regular Meeting",
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 1800.0,
|
"duration": 1800.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
@@ -165,7 +165,7 @@ async def test_postgresql_search_with_data():
|
|||||||
"id": test_id,
|
"id": test_id,
|
||||||
"name": "Test Search Transcript",
|
"name": "Test Search Transcript",
|
||||||
"title": "Engineering Planning Meeting Q4 2024",
|
"title": "Engineering Planning Meeting Q4 2024",
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 1800.0,
|
"duration": 1800.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
@@ -221,7 +221,7 @@ We need to implement PostgreSQL tsvector for better performance.""",
|
|||||||
test_result = next((r for r in results if r.id == test_id), None)
|
test_result = next((r for r in results if r.id == test_id), None)
|
||||||
if test_result:
|
if test_result:
|
||||||
assert test_result.title == "Engineering Planning Meeting Q4 2024"
|
assert test_result.title == "Engineering Planning Meeting Q4 2024"
|
||||||
assert test_result.status == "ended"
|
assert test_result.status == "completed"
|
||||||
assert test_result.duration == 1800.0
|
assert test_result.duration == 1800.0
|
||||||
assert 0 <= test_result.rank <= 1, "Rank should be normalized to 0-1"
|
assert 0 <= test_result.rank <= 1, "Rank should be normalized to 0-1"
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ def mock_db_result():
|
|||||||
"title": "Test Transcript",
|
"title": "Test Transcript",
|
||||||
"created_at": datetime(2024, 6, 15, tzinfo=timezone.utc),
|
"created_at": datetime(2024, 6, 15, tzinfo=timezone.utc),
|
||||||
"duration": 3600.0,
|
"duration": 3600.0,
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"user_id": "test-user",
|
"user_id": "test-user",
|
||||||
"room_id": "room1",
|
"room_id": "room1",
|
||||||
"source_kind": SourceKind.LIVE,
|
"source_kind": SourceKind.LIVE,
|
||||||
@@ -433,7 +433,7 @@ class TestSearchResultModel:
|
|||||||
room_id="room-456",
|
room_id="room-456",
|
||||||
source_kind=SourceKind.ROOM,
|
source_kind=SourceKind.ROOM,
|
||||||
created_at=datetime(2024, 6, 15, tzinfo=timezone.utc),
|
created_at=datetime(2024, 6, 15, tzinfo=timezone.utc),
|
||||||
status="ended",
|
status="completed",
|
||||||
rank=0.85,
|
rank=0.85,
|
||||||
duration=1800.5,
|
duration=1800.5,
|
||||||
search_snippets=["snippet 1", "snippet 2"],
|
search_snippets=["snippet 1", "snippet 2"],
|
||||||
@@ -443,7 +443,7 @@ class TestSearchResultModel:
|
|||||||
assert result.title == "Test Title"
|
assert result.title == "Test Title"
|
||||||
assert result.user_id == "user-123"
|
assert result.user_id == "user-123"
|
||||||
assert result.room_id == "room-456"
|
assert result.room_id == "room-456"
|
||||||
assert result.status == "ended"
|
assert result.status == "completed"
|
||||||
assert result.rank == 0.85
|
assert result.rank == 0.85
|
||||||
assert result.duration == 1800.5
|
assert result.duration == 1800.5
|
||||||
assert len(result.search_snippets) == 2
|
assert len(result.search_snippets) == 2
|
||||||
@@ -474,7 +474,7 @@ class TestSearchResultModel:
|
|||||||
id="test-id",
|
id="test-id",
|
||||||
source_kind=SourceKind.LIVE,
|
source_kind=SourceKind.LIVE,
|
||||||
created_at=datetime(2024, 6, 15, 12, 30, 45, tzinfo=timezone.utc),
|
created_at=datetime(2024, 6, 15, 12, 30, 45, tzinfo=timezone.utc),
|
||||||
status="ended",
|
status="completed",
|
||||||
rank=0.9,
|
rank=0.9,
|
||||||
duration=None,
|
duration=None,
|
||||||
search_snippets=[],
|
search_snippets=[],
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ async def test_long_summary_snippet_prioritization():
|
|||||||
"id": test_id,
|
"id": test_id,
|
||||||
"name": "Test Snippet Priority",
|
"name": "Test Snippet Priority",
|
||||||
"title": "Meeting About Projects",
|
"title": "Meeting About Projects",
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 1800.0,
|
"duration": 1800.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
@@ -106,7 +106,7 @@ async def test_long_summary_only_search():
|
|||||||
"id": test_id,
|
"id": test_id,
|
||||||
"name": "Test Long Only",
|
"name": "Test Long Only",
|
||||||
"title": "Standard Meeting",
|
"title": "Standard Meeting",
|
||||||
"status": "ended",
|
"status": "completed",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 1800.0,
|
"duration": 1800.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"""Unit tests for search snippet generation."""
|
"""Unit tests for search snippet generation."""
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from reflector.db.search import (
|
from reflector.db.search import (
|
||||||
SnippetCandidate,
|
SnippetCandidate,
|
||||||
SnippetGenerator,
|
SnippetGenerator,
|
||||||
@@ -514,9 +512,11 @@ data visualization and data storage"""
|
|||||||
)
|
)
|
||||||
assert webvtt_count == 3
|
assert webvtt_count == 3
|
||||||
|
|
||||||
# combine_sources requires at least one source to be present
|
snippets_empty, count_empty = SnippetGenerator.combine_sources(
|
||||||
with pytest.raises(AssertionError, match="At least one source must be present"):
|
None, None, "data", max_total=3
|
||||||
SnippetGenerator.combine_sources(None, None, "data", max_total=3)
|
)
|
||||||
|
assert snippets_empty == []
|
||||||
|
assert count_empty == 0
|
||||||
|
|
||||||
def test_edge_cases(self):
|
def test_edge_cases(self):
|
||||||
"""Test edge cases for the pure functions."""
|
"""Test edge cases for the pure functions."""
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ async def fake_transcript(tmpdir, client):
|
|||||||
transcript = await transcripts_controller.get_by_id(tid)
|
transcript = await transcripts_controller.get_by_id(tid)
|
||||||
assert transcript is not None
|
assert transcript is not None
|
||||||
|
|
||||||
await transcripts_controller.update(transcript, {"status": "ended"})
|
await transcripts_controller.update(transcript, {"status": "finished"})
|
||||||
|
|
||||||
# manually copy a file at the expected location
|
# manually copy a file at the expected location
|
||||||
audio_filename = transcript.audio_mp3_filename
|
audio_filename = transcript.audio_mp3_filename
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ async def client(app_lifespan):
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_transcript_process(
|
async def test_transcript_process(
|
||||||
tmpdir,
|
tmpdir,
|
||||||
|
whisper_transcript,
|
||||||
dummy_llm,
|
dummy_llm,
|
||||||
dummy_processors,
|
dummy_processors,
|
||||||
dummy_file_transcript,
|
dummy_diarization,
|
||||||
dummy_file_diarization,
|
|
||||||
dummy_storage,
|
dummy_storage,
|
||||||
client,
|
client,
|
||||||
):
|
):
|
||||||
@@ -56,8 +56,8 @@ async def test_transcript_process(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["status"] == "ok"
|
assert response.json()["status"] == "ok"
|
||||||
|
|
||||||
# wait for processing to finish (max 1 minute)
|
# wait for processing to finish (max 10 minutes)
|
||||||
timeout_seconds = 60
|
timeout_seconds = 600 # 10 minutes
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
while (time.monotonic() - start_time) < timeout_seconds:
|
while (time.monotonic() - start_time) < timeout_seconds:
|
||||||
# fetch the transcript and check if it is ended
|
# fetch the transcript and check if it is ended
|
||||||
@@ -75,10 +75,9 @@ async def test_transcript_process(
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["status"] == "ok"
|
assert response.json()["status"] == "ok"
|
||||||
await asyncio.sleep(2)
|
|
||||||
|
|
||||||
# wait for processing to finish (max 1 minute)
|
# wait for processing to finish (max 10 minutes)
|
||||||
timeout_seconds = 60
|
timeout_seconds = 600 # 10 minutes
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
while (time.monotonic() - start_time) < timeout_seconds:
|
while (time.monotonic() - start_time) < timeout_seconds:
|
||||||
# fetch the transcript and check if it is ended
|
# fetch the transcript and check if it is ended
|
||||||
@@ -100,4 +99,4 @@ async def test_transcript_process(
|
|||||||
response = await client.get(f"/transcripts/{tid}/topics")
|
response = await client.get(f"/transcripts/{tid}/topics")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert len(response.json()) == 1
|
assert len(response.json()) == 1
|
||||||
assert "Hello world. How are you today?" in response.json()[0]["transcript"]
|
assert "want to share" in response.json()[0]["transcript"]
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ async def test_transcript_upload_file(
|
|||||||
tmpdir,
|
tmpdir,
|
||||||
dummy_llm,
|
dummy_llm,
|
||||||
dummy_processors,
|
dummy_processors,
|
||||||
dummy_file_transcript,
|
dummy_diarization,
|
||||||
dummy_file_diarization,
|
|
||||||
dummy_storage,
|
dummy_storage,
|
||||||
client,
|
client,
|
||||||
):
|
):
|
||||||
@@ -37,8 +36,8 @@ async def test_transcript_upload_file(
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["status"] == "ok"
|
assert response.json()["status"] == "ok"
|
||||||
|
|
||||||
# wait the processing to finish (max 1 minute)
|
# wait the processing to finish (max 10 minutes)
|
||||||
timeout_seconds = 60
|
timeout_seconds = 600 # 10 minutes
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
while (time.monotonic() - start_time) < timeout_seconds:
|
while (time.monotonic() - start_time) < timeout_seconds:
|
||||||
# fetch the transcript and check if it is ended
|
# fetch the transcript and check if it is ended
|
||||||
@@ -48,7 +47,7 @@ async def test_transcript_upload_file(
|
|||||||
break
|
break
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
else:
|
else:
|
||||||
return pytest.fail(f"Processing timed out after {timeout_seconds} seconds")
|
pytest.fail(f"Processing timed out after {timeout_seconds} seconds")
|
||||||
|
|
||||||
# check the transcript is ended
|
# check the transcript is ended
|
||||||
transcript = resp.json()
|
transcript = resp.json()
|
||||||
@@ -60,4 +59,4 @@ async def test_transcript_upload_file(
|
|||||||
response = await client.get(f"/transcripts/{tid}/topics")
|
response = await client.get(f"/transcripts/{tid}/topics")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert len(response.json()) == 1
|
assert len(response.json()) == 1
|
||||||
assert "Hello world. How are you today?" in response.json()[0]["transcript"]
|
assert "want to share" in response.json()[0]["transcript"]
|
||||||
|
|||||||
47
server/uv.lock
generated
47
server/uv.lock
generated
@@ -1325,6 +1325,15 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/9c/1f/19ebc343cc71a7ffa78f17018535adc5cbdd87afb31d7c34874680148b32/ifaddr-0.2.0-py3-none-any.whl", hash = "sha256:085e0305cfe6f16ab12d72e2024030f5d52674afad6911bb1eee207177b8a748", size = 12314, upload-time = "2022-06-15T21:40:25.756Z" },
|
{ url = "https://files.pythonhosted.org/packages/9c/1f/19ebc343cc71a7ffa78f17018535adc5cbdd87afb31d7c34874680148b32/ifaddr-0.2.0-py3-none-any.whl", hash = "sha256:085e0305cfe6f16ab12d72e2024030f5d52674afad6911bb1eee207177b8a748", size = 12314, upload-time = "2022-06-15T21:40:25.756Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inflection"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/e1/7e/691d061b7329bc8d54edbf0ec22fbfb2afe61facb681f9aaa9bff7a27d04/inflection-0.5.1.tar.gz", hash = "sha256:1a29730d366e996aaacffb2f1f1cb9593dc38e2ddd30c91250c6dde09ea9b417", size = 15091, upload-time = "2020-08-22T08:16:29.139Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/59/91/aa6bde563e0085a02a435aa99b49ef75b0a4b062635e606dab23ce18d720/inflection-0.5.1-py2.py3-none-any.whl", hash = "sha256:f38b2b640938a4f35ade69ac3d053042959b62a0f1076a5bbaa1b9526605a8a2", size = 9454, upload-time = "2020-08-22T08:16:27.816Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iniconfig"
|
name = "iniconfig"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@@ -2302,6 +2311,18 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/74/c1/bb7e334135859c3a92ec399bc89293ea73f28e815e35b43929c8db6af030/primePy-1.3-py3-none-any.whl", hash = "sha256:5ed443718765be9bf7e2ff4c56cdff71b42140a15b39d054f9d99f0009e2317a", size = 4040, upload-time = "2018-05-29T17:18:17.53Z" },
|
{ url = "https://files.pythonhosted.org/packages/74/c1/bb7e334135859c3a92ec399bc89293ea73f28e815e35b43929c8db6af030/primePy-1.3-py3-none-any.whl", hash = "sha256:5ed443718765be9bf7e2ff4c56cdff71b42140a15b39d054f9d99f0009e2317a", size = 4040, upload-time = "2018-05-29T17:18:17.53Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "profanityfilter"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "inflection" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/8d/03/08740b5e0800f9eb9f675c149a497a3f3735e7b04e414bcce64136e7e487/profanityfilter-2.1.0.tar.gz", hash = "sha256:0ede04e92a9d7255faa52b53776518edc6586dda828aca677c74b5994dfdd9d8", size = 7910, upload-time = "2024-11-25T22:31:51.194Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/88/03/eb18f72dc6e6398e75e3762677f18ab3a773a384b18efd3ed9119844e892/profanityfilter-2.1.0-py2.py3-none-any.whl", hash = "sha256:e1bc07012760fd74512a335abb93a36877831ed26abab78bfe31bebb68f8c844", size = 7483, upload-time = "2024-11-25T22:31:50.129Z" },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prometheus-client"
|
name = "prometheus-client"
|
||||||
version = "0.22.1"
|
version = "0.22.1"
|
||||||
@@ -3110,6 +3131,7 @@ dependencies = [
|
|||||||
{ name = "loguru" },
|
{ name = "loguru" },
|
||||||
{ name = "nltk" },
|
{ name = "nltk" },
|
||||||
{ name = "openai" },
|
{ name = "openai" },
|
||||||
|
{ name = "profanityfilter" },
|
||||||
{ name = "prometheus-fastapi-instrumentator" },
|
{ name = "prometheus-fastapi-instrumentator" },
|
||||||
{ name = "protobuf" },
|
{ name = "protobuf" },
|
||||||
{ name = "psycopg2-binary" },
|
{ name = "psycopg2-binary" },
|
||||||
@@ -3186,6 +3208,7 @@ requires-dist = [
|
|||||||
{ name = "loguru", specifier = ">=0.7.0" },
|
{ name = "loguru", specifier = ">=0.7.0" },
|
||||||
{ name = "nltk", specifier = ">=3.8.1" },
|
{ name = "nltk", specifier = ">=3.8.1" },
|
||||||
{ name = "openai", specifier = ">=1.59.7" },
|
{ name = "openai", specifier = ">=1.59.7" },
|
||||||
|
{ name = "profanityfilter", specifier = ">=2.0.6" },
|
||||||
{ name = "prometheus-fastapi-instrumentator", specifier = ">=6.1.0" },
|
{ name = "prometheus-fastapi-instrumentator", specifier = ">=6.1.0" },
|
||||||
{ name = "protobuf", specifier = ">=4.24.3" },
|
{ name = "protobuf", specifier = ">=4.24.3" },
|
||||||
{ name = "psycopg2-binary", specifier = ">=2.9.10" },
|
{ name = "psycopg2-binary", specifier = ">=2.9.10" },
|
||||||
@@ -3931,8 +3954,8 @@ dependencies = [
|
|||||||
{ name = "typing-extensions", marker = "platform_python_implementation != 'PyPy' and sys_platform == 'darwin'" },
|
{ name = "typing-extensions", marker = "platform_python_implementation != 'PyPy' and sys_platform == 'darwin'" },
|
||||||
]
|
]
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0-cp311-none-macosx_11_0_arm64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:3d05017d19bc99741288e458888283a44b0ee881d53f05f72f8b1cfea8998122" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0-cp312-none-macosx_11_0_arm64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:a47b7986bee3f61ad217d8a8ce24605809ab425baf349f97de758815edd2ef54" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3957,16 +3980,16 @@ dependencies = [
|
|||||||
{ name = "typing-extensions", marker = "platform_python_implementation == 'PyPy' or sys_platform != 'darwin'" },
|
{ name = "typing-extensions", marker = "platform_python_implementation == 'PyPy' or sys_platform != 'darwin'" },
|
||||||
]
|
]
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-linux_s390x.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-linux_s390x.whl", hash = "sha256:2bfc013dd6efdc8f8223a0241d3529af9f315dffefb53ffa3bf14d3f10127da6" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-manylinux_2_28_aarch64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:680129efdeeec3db5da3f88ee5d28c1b1e103b774aef40f9d638e2cce8f8d8d8" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-manylinux_2_28_x86_64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:cb06175284673a581dd91fb1965662ae4ecaba6e5c357aa0ea7bb8b84b6b7eeb" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-win_amd64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-win_amd64.whl", hash = "sha256:7631ef49fbd38d382909525b83696dc12a55d68492ade4ace3883c62b9fc140f" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-win_arm64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp311-cp311-win_arm64.whl", hash = "sha256:41e6fc5ec0914fcdce44ccf338b1d19a441b55cafdd741fd0bf1af3f9e4cfd14" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-linux_s390x.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-linux_s390x.whl", hash = "sha256:0e34e276722ab7dd0dffa9e12fe2135a9b34a0e300c456ed7ad6430229404eb5" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-manylinux_2_28_aarch64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:610f600c102386e581327d5efc18c0d6edecb9820b4140d26163354a99cd800d" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:cb9a8ba8137ab24e36bf1742cb79a1294bd374db570f09fc15a5e1318160db4e" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_amd64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_amd64.whl", hash = "sha256:2be20b2c05a0cce10430cc25f32b689259640d273232b2de357c35729132256d" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_arm64.whl" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_arm64.whl", hash = "sha256:99fc421a5d234580e45957a7b02effbf3e1c884a5dd077afc85352c77bf41434" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
# Environment
|
|
||||||
ENVIRONMENT=development
|
|
||||||
NEXT_PUBLIC_ENV=development
|
|
||||||
|
|
||||||
# Site Configuration
|
|
||||||
NEXT_PUBLIC_SITE_URL=http://localhost:3000
|
|
||||||
|
|
||||||
# Nextauth envs
|
|
||||||
# not used in app code but in lib code
|
|
||||||
NEXTAUTH_URL=http://localhost:3000
|
|
||||||
NEXTAUTH_SECRET=your-nextauth-secret-here
|
|
||||||
# / Nextauth envs
|
|
||||||
|
|
||||||
# Authentication (Authentik OAuth/OIDC)
|
|
||||||
AUTHENTIK_ISSUER=https://authentik.example.com/application/o/reflector
|
|
||||||
AUTHENTIK_REFRESH_TOKEN_URL=https://authentik.example.com/application/o/token/
|
|
||||||
AUTHENTIK_CLIENT_ID=your-client-id-here
|
|
||||||
AUTHENTIK_CLIENT_SECRET=your-client-secret-here
|
|
||||||
|
|
||||||
# Feature Flags
|
|
||||||
# NEXT_PUBLIC_FEATURE_REQUIRE_LOGIN=true
|
|
||||||
# NEXT_PUBLIC_FEATURE_PRIVACY=false
|
|
||||||
# NEXT_PUBLIC_FEATURE_BROWSE=true
|
|
||||||
# NEXT_PUBLIC_FEATURE_SEND_TO_ZULIP=true
|
|
||||||
# NEXT_PUBLIC_FEATURE_ROOMS=true
|
|
||||||
|
|
||||||
# API URLs
|
|
||||||
NEXT_PUBLIC_API_URL=http://127.0.0.1:1250
|
|
||||||
NEXT_PUBLIC_WEBSOCKET_URL=ws://127.0.0.1:1250
|
|
||||||
NEXT_PUBLIC_AUTH_CALLBACK_URL=http://localhost:3000/auth-callback
|
|
||||||
|
|
||||||
# Sentry
|
|
||||||
# SENTRY_DSN=https://your-dsn@sentry.io/project-id
|
|
||||||
# SENTRY_IGNORE_API_RESOLUTION_ERROR=1
|
|
||||||
1
www/.gitignore
vendored
1
www/.gitignore
vendored
@@ -40,6 +40,7 @@ next-env.d.ts
|
|||||||
# Sentry Auth Token
|
# Sentry Auth Token
|
||||||
.sentryclirc
|
.sentryclirc
|
||||||
|
|
||||||
|
config.ts
|
||||||
|
|
||||||
# openapi logs
|
# openapi logs
|
||||||
openapi-ts-error-*.log
|
openapi-ts-error-*.log
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Flex, Spinner } from "@chakra-ui/react";
|
|
||||||
import { useAuth } from "../lib/AuthProvider";
|
|
||||||
import { useLoginRequiredPages } from "../lib/useLoginRequiredPages";
|
|
||||||
|
|
||||||
export default function AuthWrapper({
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) {
|
|
||||||
const auth = useAuth();
|
|
||||||
const redirectPath = useLoginRequiredPages();
|
|
||||||
const redirectHappens = !!redirectPath;
|
|
||||||
|
|
||||||
if (auth.status === "loading" || redirectHappens) {
|
|
||||||
return (
|
|
||||||
<Flex
|
|
||||||
flexDir="column"
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
h="calc(100vh - 80px)" // Account for header height
|
|
||||||
>
|
|
||||||
<Spinner size="xl" color="blue.500" />
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <>{children}</>;
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Box, Stack, Link, Heading } from "@chakra-ui/react";
|
import { Box, Stack, Link, Heading } from "@chakra-ui/react";
|
||||||
import NextLink from "next/link";
|
import NextLink from "next/link";
|
||||||
import type { components } from "../../../reflector-api";
|
import { Room, SourceKind } from "../../../api";
|
||||||
|
|
||||||
type Room = components["schemas"]["Room"];
|
|
||||||
type SourceKind = components["schemas"]["SourceKind"];
|
|
||||||
|
|
||||||
interface FilterSidebarProps {
|
interface FilterSidebarProps {
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
@@ -75,7 +72,7 @@ export default function FilterSidebar({
|
|||||||
key={room.id}
|
key={room.id}
|
||||||
as={NextLink}
|
as={NextLink}
|
||||||
href="#"
|
href="#"
|
||||||
onClick={() => onFilterChange("room" as SourceKind, room.id)}
|
onClick={() => onFilterChange("room", room.id)}
|
||||||
color={
|
color={
|
||||||
selectedSourceKind === "room" && selectedRoomId === room.id
|
selectedSourceKind === "room" && selectedRoomId === room.id
|
||||||
? "blue.500"
|
? "blue.500"
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ import {
|
|||||||
highlightMatches,
|
highlightMatches,
|
||||||
generateTextFragment,
|
generateTextFragment,
|
||||||
} from "../../../lib/textHighlight";
|
} from "../../../lib/textHighlight";
|
||||||
import type { components } from "../../../reflector-api";
|
import { SearchResult } from "../../../api";
|
||||||
|
|
||||||
type SearchResult = components["schemas"]["SearchResult"];
|
|
||||||
type SourceKind = components["schemas"]["SourceKind"];
|
|
||||||
|
|
||||||
interface TranscriptCardsProps {
|
interface TranscriptCardsProps {
|
||||||
results: SearchResult[];
|
results: SearchResult[];
|
||||||
@@ -123,7 +120,7 @@ function TranscriptCard({
|
|||||||
: "N/A";
|
: "N/A";
|
||||||
const formattedDate = formatLocalDate(result.created_at);
|
const formattedDate = formatLocalDate(result.created_at);
|
||||||
const source =
|
const source =
|
||||||
result.source_kind === ("room" as SourceKind)
|
result.source_kind === "room"
|
||||||
? result.room_name || result.room_id
|
? result.room_name || result.room_id
|
||||||
: result.source_kind;
|
: result.source_kind;
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ import {
|
|||||||
FaMicrophone,
|
FaMicrophone,
|
||||||
FaGear,
|
FaGear,
|
||||||
} from "react-icons/fa6";
|
} from "react-icons/fa6";
|
||||||
import { TranscriptStatus } from "../../../lib/transcript";
|
|
||||||
|
|
||||||
interface TranscriptStatusIconProps {
|
interface TranscriptStatusIconProps {
|
||||||
status: TranscriptStatus;
|
status: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TranscriptStatusIcon({
|
export default function TranscriptStatusIcon({
|
||||||
|
|||||||
@@ -19,33 +19,37 @@ import {
|
|||||||
parseAsStringLiteral,
|
parseAsStringLiteral,
|
||||||
} from "nuqs";
|
} from "nuqs";
|
||||||
import { LuX } from "react-icons/lu";
|
import { LuX } from "react-icons/lu";
|
||||||
import type { components } from "../../reflector-api";
|
import { useSearchTranscripts } from "../transcripts/useSearchTranscripts";
|
||||||
|
import useSessionUser from "../../lib/useSessionUser";
|
||||||
type Room = components["schemas"]["Room"];
|
import { Room, SourceKind, SearchResult, $SourceKind } from "../../api";
|
||||||
type SourceKind = components["schemas"]["SourceKind"];
|
import useApi from "../../lib/useApi";
|
||||||
type SearchResult = components["schemas"]["SearchResult"];
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import {
|
|
||||||
useRoomsList,
|
|
||||||
useTranscriptsSearch,
|
|
||||||
useTranscriptDelete,
|
|
||||||
useTranscriptProcess,
|
|
||||||
} from "../../lib/apiHooks";
|
|
||||||
import FilterSidebar from "./_components/FilterSidebar";
|
import FilterSidebar from "./_components/FilterSidebar";
|
||||||
import Pagination, {
|
import Pagination, {
|
||||||
FIRST_PAGE,
|
FIRST_PAGE,
|
||||||
PaginationPage,
|
PaginationPage,
|
||||||
parsePaginationPage,
|
parsePaginationPage,
|
||||||
totalPages as getTotalPages,
|
totalPages as getTotalPages,
|
||||||
paginationPageTo0Based,
|
|
||||||
} from "./_components/Pagination";
|
} from "./_components/Pagination";
|
||||||
import TranscriptCards from "./_components/TranscriptCards";
|
import TranscriptCards from "./_components/TranscriptCards";
|
||||||
import DeleteTranscriptDialog from "./_components/DeleteTranscriptDialog";
|
import DeleteTranscriptDialog from "./_components/DeleteTranscriptDialog";
|
||||||
import { formatLocalDate } from "../../lib/time";
|
import { formatLocalDate } from "../../lib/time";
|
||||||
import { RECORD_A_MEETING_URL } from "../../api/urls";
|
import { RECORD_A_MEETING_URL } from "../../api/urls";
|
||||||
import { useUserName } from "../../lib/useUserName";
|
|
||||||
|
|
||||||
const SEARCH_FORM_QUERY_INPUT_NAME = "query" as const;
|
const SEARCH_FORM_QUERY_INPUT_NAME = "query" as const;
|
||||||
|
|
||||||
|
const usePrefetchRooms = (setRooms: (rooms: Room[]) => void): void => {
|
||||||
|
const { setError } = useError();
|
||||||
|
const api = useApi();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!api) return;
|
||||||
|
api
|
||||||
|
.v1RoomsList({ page: 1 })
|
||||||
|
.then((rooms) => setRooms(rooms.items))
|
||||||
|
.catch((err) => setError(err, "There was an error fetching the rooms"));
|
||||||
|
}, [api, setError]);
|
||||||
|
};
|
||||||
|
|
||||||
const SearchForm: React.FC<{
|
const SearchForm: React.FC<{
|
||||||
setPage: (page: PaginationPage) => void;
|
setPage: (page: PaginationPage) => void;
|
||||||
sourceKind: SourceKind | null;
|
sourceKind: SourceKind | null;
|
||||||
@@ -65,6 +69,7 @@ const SearchForm: React.FC<{
|
|||||||
searchQuery,
|
searchQuery,
|
||||||
setSearchQuery,
|
setSearchQuery,
|
||||||
}) => {
|
}) => {
|
||||||
|
// to keep the search input controllable + more fine grained control (urlSearchQuery is updated on submits)
|
||||||
const [searchInputValue, setSearchInputValue] = useState(searchQuery || "");
|
const [searchInputValue, setSearchInputValue] = useState(searchQuery || "");
|
||||||
const handleSearchQuerySubmit = async (d: FormData) => {
|
const handleSearchQuerySubmit = async (d: FormData) => {
|
||||||
await setSearchQuery((d.get(SEARCH_FORM_QUERY_INPUT_NAME) as string) || "");
|
await setSearchQuery((d.get(SEARCH_FORM_QUERY_INPUT_NAME) as string) || "");
|
||||||
@@ -158,6 +163,7 @@ const UnderSearchFormFilterIndicators: React.FC<{
|
|||||||
p="1px"
|
p="1px"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSourceKind(null);
|
setSourceKind(null);
|
||||||
|
// TODO questionable
|
||||||
setRoomId(null);
|
setRoomId(null);
|
||||||
}}
|
}}
|
||||||
_hover={{ bg: "blue.200" }}
|
_hover={{ bg: "blue.200" }}
|
||||||
@@ -203,11 +209,7 @@ export default function TranscriptBrowser() {
|
|||||||
|
|
||||||
const [urlSourceKind, setUrlSourceKind] = useQueryState(
|
const [urlSourceKind, setUrlSourceKind] = useQueryState(
|
||||||
"source",
|
"source",
|
||||||
parseAsStringLiteral([
|
parseAsStringLiteral($SourceKind.enum).withOptions({
|
||||||
"room",
|
|
||||||
"live",
|
|
||||||
"file",
|
|
||||||
] as const satisfies SourceKind[]).withOptions({
|
|
||||||
shallow: false,
|
shallow: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -227,40 +229,46 @@ export default function TranscriptBrowser() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const maybePage = parsePaginationPage(urlPage);
|
const maybePage = parsePaginationPage(urlPage);
|
||||||
if ("error" in maybePage) {
|
if ("error" in maybePage) {
|
||||||
setPage(FIRST_PAGE).then(() => {});
|
setPage(FIRST_PAGE).then(() => {
|
||||||
|
/*may be called n times we dont care*/
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_setSafePage(maybePage.value);
|
_setSafePage(maybePage.value);
|
||||||
}, [urlPage]);
|
}, [urlPage]);
|
||||||
|
|
||||||
|
const [rooms, setRooms] = useState<Room[]>([]);
|
||||||
|
|
||||||
const pageSize = 20;
|
const pageSize = 20;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: searchData,
|
results,
|
||||||
isLoading: searchLoading,
|
totalCount: totalResults,
|
||||||
refetch: reloadSearch,
|
isLoading,
|
||||||
} = useTranscriptsSearch(urlSearchQuery, {
|
reload,
|
||||||
limit: pageSize,
|
} = useSearchTranscripts(
|
||||||
offset: paginationPageTo0Based(page) * pageSize,
|
urlSearchQuery,
|
||||||
room_id: urlRoomId || undefined,
|
{
|
||||||
source_kind: urlSourceKind || undefined,
|
roomIds: urlRoomId ? [urlRoomId] : null,
|
||||||
});
|
sourceKind: urlSourceKind,
|
||||||
|
},
|
||||||
const results = searchData?.results || [];
|
{
|
||||||
const totalResults = searchData?.total || 0;
|
pageSize,
|
||||||
|
page,
|
||||||
// Fetch rooms
|
},
|
||||||
const { data: roomsData } = useRoomsList(1);
|
);
|
||||||
const rooms = roomsData?.items || [];
|
|
||||||
|
|
||||||
const totalPages = getTotalPages(totalResults, pageSize);
|
const totalPages = getTotalPages(totalResults, pageSize);
|
||||||
|
|
||||||
const userName = useUserName();
|
const userName = useSessionUser().name;
|
||||||
const [deletionLoading, setDeletionLoading] = useState(false);
|
const [deletionLoading, setDeletionLoading] = useState(false);
|
||||||
|
const api = useApi();
|
||||||
|
const { setError } = useError();
|
||||||
const cancelRef = React.useRef(null);
|
const cancelRef = React.useRef(null);
|
||||||
const [transcriptToDeleteId, setTranscriptToDeleteId] =
|
const [transcriptToDeleteId, setTranscriptToDeleteId] =
|
||||||
React.useState<string>();
|
React.useState<string>();
|
||||||
|
|
||||||
|
usePrefetchRooms(setRooms);
|
||||||
|
|
||||||
const handleFilterTranscripts = (
|
const handleFilterTranscripts = (
|
||||||
sourceKind: SourceKind | null,
|
sourceKind: SourceKind | null,
|
||||||
roomId: string,
|
roomId: string,
|
||||||
@@ -272,37 +280,44 @@ export default function TranscriptBrowser() {
|
|||||||
|
|
||||||
const onCloseDeletion = () => setTranscriptToDeleteId(undefined);
|
const onCloseDeletion = () => setTranscriptToDeleteId(undefined);
|
||||||
|
|
||||||
const deleteTranscript = useTranscriptDelete();
|
|
||||||
const processTranscript = useTranscriptProcess();
|
|
||||||
|
|
||||||
const confirmDeleteTranscript = (transcriptId: string) => {
|
const confirmDeleteTranscript = (transcriptId: string) => {
|
||||||
if (deletionLoading) return;
|
if (!api || deletionLoading) return;
|
||||||
setDeletionLoading(true);
|
setDeletionLoading(true);
|
||||||
deleteTranscript.mutate(
|
api
|
||||||
{
|
.v1TranscriptDelete({ transcriptId })
|
||||||
params: {
|
.then(() => {
|
||||||
path: { transcript_id: transcriptId },
|
setDeletionLoading(false);
|
||||||
},
|
onCloseDeletion();
|
||||||
},
|
reload();
|
||||||
{
|
})
|
||||||
onSuccess: () => {
|
.catch((err) => {
|
||||||
setDeletionLoading(false);
|
setDeletionLoading(false);
|
||||||
onCloseDeletion();
|
setError(err, "There was an error deleting the transcript");
|
||||||
reloadSearch();
|
});
|
||||||
},
|
|
||||||
onError: () => {
|
|
||||||
setDeletionLoading(false);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProcessTranscript = (transcriptId: string) => {
|
const handleProcessTranscript = (transcriptId: string) => {
|
||||||
processTranscript.mutate({
|
if (!api) {
|
||||||
params: {
|
console.error("API not available on handleProcessTranscript");
|
||||||
path: { transcript_id: transcriptId },
|
return;
|
||||||
},
|
}
|
||||||
});
|
api
|
||||||
|
.v1TranscriptProcess({ transcriptId })
|
||||||
|
.then((result) => {
|
||||||
|
const status =
|
||||||
|
result && typeof result === "object" && "status" in result
|
||||||
|
? (result as { status: string }).status
|
||||||
|
: undefined;
|
||||||
|
if (status === "already running") {
|
||||||
|
setError(
|
||||||
|
new Error("Processing is already running, please wait"),
|
||||||
|
"Processing is already running, please wait",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setError(err, "There was an error processing the transcript");
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const transcriptToDelete = results?.find(
|
const transcriptToDelete = results?.find(
|
||||||
@@ -317,7 +332,7 @@ export default function TranscriptBrowser() {
|
|||||||
? transcriptToDelete.room_name || transcriptToDelete.room_id
|
? transcriptToDelete.room_name || transcriptToDelete.room_id
|
||||||
: transcriptToDelete?.source_kind;
|
: transcriptToDelete?.source_kind;
|
||||||
|
|
||||||
if (searchLoading && results.length === 0) {
|
if (isLoading && results.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
flexDir="column"
|
flexDir="column"
|
||||||
@@ -345,7 +360,7 @@ export default function TranscriptBrowser() {
|
|||||||
>
|
>
|
||||||
<Heading size="lg">
|
<Heading size="lg">
|
||||||
{userName ? `${userName}'s Transcriptions` : "Your Transcriptions"}{" "}
|
{userName ? `${userName}'s Transcriptions` : "Your Transcriptions"}{" "}
|
||||||
{(searchLoading || deletionLoading) && <Spinner size="sm" />}
|
{(isLoading || deletionLoading) && <Spinner size="sm" />}
|
||||||
</Heading>
|
</Heading>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
@@ -388,12 +403,12 @@ export default function TranscriptBrowser() {
|
|||||||
<TranscriptCards
|
<TranscriptCards
|
||||||
results={results}
|
results={results}
|
||||||
query={urlSearchQuery}
|
query={urlSearchQuery}
|
||||||
isLoading={searchLoading}
|
isLoading={isLoading}
|
||||||
onDelete={setTranscriptToDeleteId}
|
onDelete={setTranscriptToDeleteId}
|
||||||
onReprocess={handleProcessTranscript}
|
onReprocess={handleProcessTranscript}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!searchLoading && results.length === 0 && (
|
{!isLoading && results.length === 0 && (
|
||||||
<EmptyResult searchQuery={urlSearchQuery} />
|
<EmptyResult searchQuery={urlSearchQuery} />
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Container, Flex, Link } from "@chakra-ui/react";
|
import { Container, Flex, Link } from "@chakra-ui/react";
|
||||||
import { featureEnabled } from "../lib/features";
|
import { getConfig } from "../lib/edgeConfig";
|
||||||
import NextLink from "next/link";
|
import NextLink from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
import About from "../(aboutAndPrivacy)/about";
|
||||||
|
import Privacy from "../(aboutAndPrivacy)/privacy";
|
||||||
import UserInfo from "../(auth)/userInfo";
|
import UserInfo from "../(auth)/userInfo";
|
||||||
import AuthWrapper from "./AuthWrapper";
|
|
||||||
import { RECORD_A_MEETING_URL } from "../api/urls";
|
import { RECORD_A_MEETING_URL } from "../api/urls";
|
||||||
|
|
||||||
export default async function AppLayout({
|
export default async function AppLayout({
|
||||||
@@ -11,6 +12,8 @@ export default async function AppLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
|
const config = await getConfig();
|
||||||
|
const { requireLogin, privacy, browse, rooms } = config.features;
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
minW="100vw"
|
minW="100vw"
|
||||||
@@ -56,7 +59,7 @@ export default async function AppLayout({
|
|||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
</Link>
|
</Link>
|
||||||
{featureEnabled("browse") ? (
|
{browse ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<Link href="/browse" as={NextLink} className="font-light px-2">
|
<Link href="/browse" as={NextLink} className="font-light px-2">
|
||||||
@@ -66,7 +69,7 @@ export default async function AppLayout({
|
|||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
{featureEnabled("rooms") ? (
|
{rooms ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<Link href="/rooms" as={NextLink} className="font-light px-2">
|
<Link href="/rooms" as={NextLink} className="font-light px-2">
|
||||||
@@ -76,7 +79,7 @@ export default async function AppLayout({
|
|||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
{featureEnabled("requireLogin") ? (
|
{requireLogin ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<UserInfo />
|
<UserInfo />
|
||||||
@@ -87,7 +90,7 @@ export default async function AppLayout({
|
|||||||
</div>
|
</div>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<AuthWrapper>{children}</AuthWrapper>
|
{children}
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuLink } from "react-icons/lu";
|
import { LuLink } from "react-icons/lu";
|
||||||
import type { components } from "../../../reflector-api";
|
import { Room } from "../../../api";
|
||||||
|
|
||||||
type Room = components["schemas"]["Room"];
|
|
||||||
import { RoomActionsMenu } from "./RoomActionsMenu";
|
import { RoomActionsMenu } from "./RoomActionsMenu";
|
||||||
|
|
||||||
interface RoomCardsProps {
|
interface RoomCardsProps {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { Box, Heading, Text, VStack } from "@chakra-ui/react";
|
import { Box, Heading, Text, VStack } from "@chakra-ui/react";
|
||||||
import type { components } from "../../../reflector-api";
|
import { Room } from "../../../api";
|
||||||
|
|
||||||
type Room = components["schemas"]["Room"];
|
|
||||||
import { RoomTable } from "./RoomTable";
|
import { RoomTable } from "./RoomTable";
|
||||||
import { RoomCards } from "./RoomCards";
|
import { RoomCards } from "./RoomCards";
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuLink } from "react-icons/lu";
|
import { LuLink } from "react-icons/lu";
|
||||||
import type { components } from "../../../reflector-api";
|
import { Room } from "../../../api";
|
||||||
|
|
||||||
type Room = components["schemas"]["Room"];
|
|
||||||
import { RoomActionsMenu } from "./RoomActionsMenu";
|
import { RoomActionsMenu } from "./RoomActionsMenu";
|
||||||
|
|
||||||
interface RoomTableProps {
|
interface RoomTableProps {
|
||||||
|
|||||||
@@ -11,28 +11,15 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
Select,
|
Select,
|
||||||
Spinner,
|
Spinner,
|
||||||
IconButton,
|
|
||||||
createListCollection,
|
createListCollection,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { LuEye, LuEyeOff } from "react-icons/lu";
|
import useApi from "../../lib/useApi";
|
||||||
import useRoomList from "./useRoomList";
|
import useRoomList from "./useRoomList";
|
||||||
import type { components } from "../../reflector-api";
|
import { ApiError, Room } from "../../api";
|
||||||
import {
|
|
||||||
useRoomCreate,
|
|
||||||
useRoomUpdate,
|
|
||||||
useRoomDelete,
|
|
||||||
useZulipStreams,
|
|
||||||
useZulipTopics,
|
|
||||||
useRoomGet,
|
|
||||||
useRoomTestWebhook,
|
|
||||||
} from "../../lib/apiHooks";
|
|
||||||
import { RoomList } from "./_components/RoomList";
|
import { RoomList } from "./_components/RoomList";
|
||||||
import { PaginationPage } from "../browse/_components/Pagination";
|
import { PaginationPage } from "../browse/_components/Pagination";
|
||||||
import { assertExists } from "../../lib/utils";
|
|
||||||
|
|
||||||
type Room = components["schemas"]["Room"];
|
|
||||||
|
|
||||||
interface SelectOption {
|
interface SelectOption {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -68,8 +55,6 @@ const roomInitialState = {
|
|||||||
recordingType: "cloud",
|
recordingType: "cloud",
|
||||||
recordingTrigger: "automatic-2nd-participant",
|
recordingTrigger: "automatic-2nd-participant",
|
||||||
isShared: false,
|
isShared: false,
|
||||||
webhookUrl: "",
|
|
||||||
webhookSecret: "",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RoomsList() {
|
export default function RoomsList() {
|
||||||
@@ -87,77 +72,61 @@ export default function RoomsList() {
|
|||||||
const recordingTypeCollection = createListCollection({
|
const recordingTypeCollection = createListCollection({
|
||||||
items: recordingTypeOptions,
|
items: recordingTypeOptions,
|
||||||
});
|
});
|
||||||
const [roomInput, setRoomInput] = useState<null | typeof roomInitialState>(
|
const [room, setRoom] = useState(roomInitialState);
|
||||||
null,
|
|
||||||
);
|
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [editRoomId, setEditRoomId] = useState<string | null>(null);
|
const [editRoomId, setEditRoomId] = useState("");
|
||||||
const {
|
const api = useApi();
|
||||||
loading,
|
// TODO seems to be no setPage calls
|
||||||
response,
|
const [page, setPage] = useState<number>(1);
|
||||||
refetch,
|
const { loading, response, refetch } = useRoomList(PaginationPage(page));
|
||||||
error: roomListError,
|
const [streams, setStreams] = useState<Stream[]>([]);
|
||||||
} = useRoomList(PaginationPage(1));
|
const [topics, setTopics] = useState<Topic[]>([]);
|
||||||
const [nameError, setNameError] = useState("");
|
const [nameError, setNameError] = useState("");
|
||||||
const [linkCopied, setLinkCopied] = useState("");
|
const [linkCopied, setLinkCopied] = useState("");
|
||||||
const [selectedStreamId, setSelectedStreamId] = useState<number | null>(null);
|
interface Stream {
|
||||||
const [testingWebhook, setTestingWebhook] = useState(false);
|
stream_id: number;
|
||||||
const [webhookTestResult, setWebhookTestResult] = useState<string | null>(
|
name: string;
|
||||||
null,
|
}
|
||||||
);
|
|
||||||
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
|
||||||
|
|
||||||
const createRoomMutation = useRoomCreate();
|
interface Topic {
|
||||||
const updateRoomMutation = useRoomUpdate();
|
name: string;
|
||||||
const deleteRoomMutation = useRoomDelete();
|
}
|
||||||
const { data: streams = [] } = useZulipStreams();
|
|
||||||
const { data: topics = [] } = useZulipTopics(selectedStreamId);
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: detailedEditedRoom,
|
|
||||||
isLoading: isDetailedEditedRoomLoading,
|
|
||||||
error: detailedEditedRoomError,
|
|
||||||
} = useRoomGet(editRoomId);
|
|
||||||
|
|
||||||
const error = roomListError || detailedEditedRoomError;
|
|
||||||
|
|
||||||
// room being edited, as fetched from the server
|
|
||||||
const editedRoom: typeof roomInitialState | null = useMemo(
|
|
||||||
() =>
|
|
||||||
detailedEditedRoom
|
|
||||||
? {
|
|
||||||
name: detailedEditedRoom.name,
|
|
||||||
zulipAutoPost: detailedEditedRoom.zulip_auto_post,
|
|
||||||
zulipStream: detailedEditedRoom.zulip_stream,
|
|
||||||
zulipTopic: detailedEditedRoom.zulip_topic,
|
|
||||||
isLocked: detailedEditedRoom.is_locked,
|
|
||||||
roomMode: detailedEditedRoom.room_mode,
|
|
||||||
recordingType: detailedEditedRoom.recording_type,
|
|
||||||
recordingTrigger: detailedEditedRoom.recording_trigger,
|
|
||||||
isShared: detailedEditedRoom.is_shared,
|
|
||||||
webhookUrl: detailedEditedRoom.webhook_url || "",
|
|
||||||
webhookSecret: detailedEditedRoom.webhook_secret || "",
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
[detailedEditedRoom],
|
|
||||||
);
|
|
||||||
|
|
||||||
// a room input value or a last api room state
|
|
||||||
const room = roomInput || editedRoom || roomInitialState;
|
|
||||||
|
|
||||||
const roomTestWebhookMutation = useRoomTestWebhook();
|
|
||||||
|
|
||||||
// Update selected stream ID when zulip stream changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (room.zulipStream && streams.length > 0) {
|
const fetchZulipStreams = async () => {
|
||||||
const selectedStream = streams.find((s) => s.name === room.zulipStream);
|
if (!api) return;
|
||||||
if (selectedStream !== undefined) {
|
|
||||||
setSelectedStreamId(selectedStream.stream_id);
|
try {
|
||||||
|
const response = await api.v1ZulipGetStreams();
|
||||||
|
setStreams(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching Zulip streams:", error);
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
setSelectedStreamId(null);
|
|
||||||
|
if (room.zulipAutoPost) {
|
||||||
|
fetchZulipStreams();
|
||||||
}
|
}
|
||||||
}, [room.zulipStream, streams]);
|
}, [room.zulipAutoPost, !api]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchZulipTopics = async () => {
|
||||||
|
if (!api || !room.zulipStream) return;
|
||||||
|
try {
|
||||||
|
const selectedStream = streams.find((s) => s.name === room.zulipStream);
|
||||||
|
if (selectedStream) {
|
||||||
|
const response = await api.v1ZulipGetTopics({
|
||||||
|
streamId: selectedStream.stream_id,
|
||||||
|
});
|
||||||
|
setTopics(response);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching Zulip topics:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchZulipTopics();
|
||||||
|
}, [room.zulipStream, streams, api]);
|
||||||
|
|
||||||
const streamOptions: SelectOption[] = streams.map((stream) => {
|
const streamOptions: SelectOption[] = streams.map((stream) => {
|
||||||
return { label: stream.name, value: stream.name };
|
return { label: stream.name, value: stream.name };
|
||||||
@@ -186,76 +155,6 @@ export default function RoomsList() {
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseDialog = () => {
|
|
||||||
setShowWebhookSecret(false);
|
|
||||||
setWebhookTestResult(null);
|
|
||||||
setEditRoomId(null);
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTestWebhook = async () => {
|
|
||||||
if (!room.webhookUrl) {
|
|
||||||
setWebhookTestResult("Please enter a webhook URL first");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!editRoomId) {
|
|
||||||
console.error("No room ID to test webhook");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTestingWebhook(true);
|
|
||||||
setWebhookTestResult(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await roomTestWebhookMutation.mutateAsync({
|
|
||||||
params: {
|
|
||||||
path: {
|
|
||||||
room_id: editRoomId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.success) {
|
|
||||||
setWebhookTestResult(
|
|
||||||
`✅ Webhook test successful! Status: ${response.status_code}`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
let errorMsg = `❌ Webhook test failed`;
|
|
||||||
errorMsg += ` (Status: ${response.status_code})`;
|
|
||||||
if (response.error) {
|
|
||||||
errorMsg += `: ${response.error}`;
|
|
||||||
} else if (response.response_preview) {
|
|
||||||
// Try to parse and extract meaningful error from response
|
|
||||||
// Specific to N8N at the moment, as there is no specification for that
|
|
||||||
// We could just display as is, but decided here to dig a little bit more.
|
|
||||||
try {
|
|
||||||
const preview = JSON.parse(response.response_preview);
|
|
||||||
if (preview.message) {
|
|
||||||
errorMsg += `: ${preview.message}`;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// If not JSON, just show the preview text (truncated)
|
|
||||||
const previewText = response.response_preview.substring(0, 150);
|
|
||||||
errorMsg += `: ${previewText}`;
|
|
||||||
}
|
|
||||||
} else if (response?.message) {
|
|
||||||
errorMsg += `: ${response.message}`;
|
|
||||||
}
|
|
||||||
setWebhookTestResult(errorMsg);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error testing webhook:", error);
|
|
||||||
setWebhookTestResult("❌ Failed to test webhook. Please check your URL.");
|
|
||||||
} finally {
|
|
||||||
setTestingWebhook(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear result after 5 seconds
|
|
||||||
setTimeout(() => {
|
|
||||||
setWebhookTestResult(null);
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveRoom = async () => {
|
const handleSaveRoom = async () => {
|
||||||
try {
|
try {
|
||||||
if (RESERVED_PATHS.includes(room.name)) {
|
if (RESERVED_PATHS.includes(room.name)) {
|
||||||
@@ -273,34 +172,30 @@ export default function RoomsList() {
|
|||||||
recording_type: room.recordingType,
|
recording_type: room.recordingType,
|
||||||
recording_trigger: room.recordingTrigger,
|
recording_trigger: room.recordingTrigger,
|
||||||
is_shared: room.isShared,
|
is_shared: room.isShared,
|
||||||
webhook_url: room.webhookUrl,
|
|
||||||
webhook_secret: room.webhookSecret,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
await updateRoomMutation.mutateAsync({
|
await api?.v1RoomsUpdate({
|
||||||
params: {
|
roomId: editRoomId,
|
||||||
path: { room_id: assertExists(editRoomId) },
|
requestBody: roomData,
|
||||||
},
|
|
||||||
body: roomData,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await createRoomMutation.mutateAsync({
|
await api?.v1RoomsCreate({
|
||||||
body: roomData,
|
requestBody: roomData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setRoomInput(null);
|
setRoom(roomInitialState);
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setEditRoomId("");
|
setEditRoomId("");
|
||||||
setNameError("");
|
setNameError("");
|
||||||
refetch();
|
refetch();
|
||||||
onClose();
|
onClose();
|
||||||
handleCloseDialog();
|
} catch (err) {
|
||||||
} catch (err: any) {
|
|
||||||
if (
|
if (
|
||||||
err?.status === 400 &&
|
err instanceof ApiError &&
|
||||||
err?.body?.detail == "Room name is not unique"
|
err.status === 400 &&
|
||||||
|
(err.body as any).detail == "Room name is not unique"
|
||||||
) {
|
) {
|
||||||
setNameError(
|
setNameError(
|
||||||
"This room name is already taken. Please choose a different name.",
|
"This room name is already taken. Please choose a different name.",
|
||||||
@@ -311,11 +206,18 @@ export default function RoomsList() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditRoom = async (roomId: string, roomData) => {
|
const handleEditRoom = (roomId, roomData) => {
|
||||||
// Reset states
|
setRoom({
|
||||||
setShowWebhookSecret(false);
|
name: roomData.name,
|
||||||
setWebhookTestResult(null);
|
zulipAutoPost: roomData.zulip_auto_post,
|
||||||
|
zulipStream: roomData.zulip_stream,
|
||||||
|
zulipTopic: roomData.zulip_topic,
|
||||||
|
isLocked: roomData.is_locked,
|
||||||
|
roomMode: roomData.room_mode,
|
||||||
|
recordingType: roomData.recording_type,
|
||||||
|
recordingTrigger: roomData.recording_trigger,
|
||||||
|
isShared: roomData.is_shared,
|
||||||
|
});
|
||||||
setEditRoomId(roomId);
|
setEditRoomId(roomId);
|
||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
setNameError("");
|
setNameError("");
|
||||||
@@ -324,10 +226,8 @@ export default function RoomsList() {
|
|||||||
|
|
||||||
const handleDeleteRoom = async (roomId: string) => {
|
const handleDeleteRoom = async (roomId: string) => {
|
||||||
try {
|
try {
|
||||||
await deleteRoomMutation.mutateAsync({
|
await api?.v1RoomsDelete({
|
||||||
params: {
|
roomId,
|
||||||
path: { room_id: roomId },
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
refetch();
|
refetch();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -344,7 +244,7 @@ export default function RoomsList() {
|
|||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
setNameError("");
|
setNameError("");
|
||||||
}
|
}
|
||||||
setRoomInput({
|
setRoom({
|
||||||
...room,
|
...room,
|
||||||
[name]: type === "checkbox" ? checked : value,
|
[name]: type === "checkbox" ? checked : value,
|
||||||
});
|
});
|
||||||
@@ -367,9 +267,6 @@ export default function RoomsList() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (roomListError)
|
|
||||||
return <div>{`${roomListError.name}: ${roomListError.message}`}</div>;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
flexDir="column"
|
flexDir="column"
|
||||||
@@ -388,10 +285,8 @@ export default function RoomsList() {
|
|||||||
colorPalette="primary"
|
colorPalette="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setRoomInput(null);
|
setRoom(roomInitialState);
|
||||||
setNameError("");
|
setNameError("");
|
||||||
setShowWebhookSecret(false);
|
|
||||||
setWebhookTestResult(null);
|
|
||||||
onOpen();
|
onOpen();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -401,7 +296,7 @@ export default function RoomsList() {
|
|||||||
|
|
||||||
<Dialog.Root
|
<Dialog.Root
|
||||||
open={open}
|
open={open}
|
||||||
onOpenChange={(e) => (e.open ? onOpen() : handleCloseDialog())}
|
onOpenChange={(e) => (e.open ? onOpen() : onClose())}
|
||||||
size="lg"
|
size="lg"
|
||||||
>
|
>
|
||||||
<Dialog.Backdrop />
|
<Dialog.Backdrop />
|
||||||
@@ -457,7 +352,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.roomMode]}
|
value={[room.roomMode]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoomInput({ ...room, roomMode: e.value[0] })
|
setRoom({ ...room, roomMode: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={roomModeCollection}
|
collection={roomModeCollection}
|
||||||
>
|
>
|
||||||
@@ -487,7 +382,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.recordingType]}
|
value={[room.recordingType]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoomInput({
|
setRoom({
|
||||||
...room,
|
...room,
|
||||||
recordingType: e.value[0],
|
recordingType: e.value[0],
|
||||||
recordingTrigger:
|
recordingTrigger:
|
||||||
@@ -522,7 +417,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.recordingTrigger]}
|
value={[room.recordingTrigger]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoomInput({ ...room, recordingTrigger: e.value[0] })
|
setRoom({ ...room, recordingTrigger: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={recordingTriggerCollection}
|
collection={recordingTriggerCollection}
|
||||||
disabled={room.recordingType !== "cloud"}
|
disabled={room.recordingType !== "cloud"}
|
||||||
@@ -577,7 +472,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={room.zulipStream ? [room.zulipStream] : []}
|
value={room.zulipStream ? [room.zulipStream] : []}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoomInput({
|
setRoom({
|
||||||
...room,
|
...room,
|
||||||
zulipStream: e.value[0],
|
zulipStream: e.value[0],
|
||||||
zulipTopic: "",
|
zulipTopic: "",
|
||||||
@@ -612,7 +507,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={room.zulipTopic ? [room.zulipTopic] : []}
|
value={room.zulipTopic ? [room.zulipTopic] : []}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoomInput({ ...room, zulipTopic: e.value[0] })
|
setRoom({ ...room, zulipTopic: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={topicCollection}
|
collection={topicCollection}
|
||||||
disabled={!room.zulipAutoPost}
|
disabled={!room.zulipAutoPost}
|
||||||
@@ -638,109 +533,6 @@ export default function RoomsList() {
|
|||||||
</Select.Positioner>
|
</Select.Positioner>
|
||||||
</Select.Root>
|
</Select.Root>
|
||||||
</Field.Root>
|
</Field.Root>
|
||||||
|
|
||||||
{/* Webhook Configuration Section */}
|
|
||||||
<Field.Root mt={8}>
|
|
||||||
<Field.Label>Webhook URL</Field.Label>
|
|
||||||
<Input
|
|
||||||
name="webhookUrl"
|
|
||||||
type="url"
|
|
||||||
placeholder="https://example.com/webhook"
|
|
||||||
value={room.webhookUrl}
|
|
||||||
onChange={handleRoomChange}
|
|
||||||
/>
|
|
||||||
<Field.HelperText>
|
|
||||||
Optional: URL to receive notifications when transcripts are
|
|
||||||
ready
|
|
||||||
</Field.HelperText>
|
|
||||||
</Field.Root>
|
|
||||||
|
|
||||||
{room.webhookUrl && (
|
|
||||||
<>
|
|
||||||
<Field.Root mt={4}>
|
|
||||||
<Field.Label>Webhook Secret</Field.Label>
|
|
||||||
<Flex gap={2}>
|
|
||||||
<Input
|
|
||||||
name="webhookSecret"
|
|
||||||
type={showWebhookSecret ? "text" : "password"}
|
|
||||||
value={room.webhookSecret}
|
|
||||||
onChange={handleRoomChange}
|
|
||||||
placeholder={
|
|
||||||
isEditing && room.webhookSecret
|
|
||||||
? "••••••••"
|
|
||||||
: "Leave empty to auto-generate"
|
|
||||||
}
|
|
||||||
flex="1"
|
|
||||||
/>
|
|
||||||
{isEditing && room.webhookSecret && (
|
|
||||||
<IconButton
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
aria-label={
|
|
||||||
showWebhookSecret ? "Hide secret" : "Show secret"
|
|
||||||
}
|
|
||||||
onClick={() =>
|
|
||||||
setShowWebhookSecret(!showWebhookSecret)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{showWebhookSecret ? <LuEyeOff /> : <LuEye />}
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
<Field.HelperText>
|
|
||||||
Used for HMAC signature verification (auto-generated if
|
|
||||||
left empty)
|
|
||||||
</Field.HelperText>
|
|
||||||
</Field.Root>
|
|
||||||
|
|
||||||
{isEditing && (
|
|
||||||
<>
|
|
||||||
<Flex
|
|
||||||
mt={2}
|
|
||||||
gap={2}
|
|
||||||
alignItems="flex-start"
|
|
||||||
direction="column"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
onClick={handleTestWebhook}
|
|
||||||
disabled={testingWebhook || !room.webhookUrl}
|
|
||||||
>
|
|
||||||
{testingWebhook ? (
|
|
||||||
<>
|
|
||||||
<Spinner size="xs" mr={2} />
|
|
||||||
Testing...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
"Test Webhook"
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
{webhookTestResult && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
fontSize: "14px",
|
|
||||||
wordBreak: "break-word",
|
|
||||||
maxWidth: "100%",
|
|
||||||
padding: "8px",
|
|
||||||
borderRadius: "4px",
|
|
||||||
backgroundColor: webhookTestResult.startsWith(
|
|
||||||
"✅",
|
|
||||||
)
|
|
||||||
? "#f0fdf4"
|
|
||||||
: "#fef2f2",
|
|
||||||
border: `1px solid ${webhookTestResult.startsWith("✅") ? "#86efac" : "#fca5a5"}`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{webhookTestResult}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Field.Root mt={4}>
|
<Field.Root mt={4}>
|
||||||
<Checkbox.Root
|
<Checkbox.Root
|
||||||
name="isShared"
|
name="isShared"
|
||||||
@@ -765,7 +557,7 @@ export default function RoomsList() {
|
|||||||
</Field.Root>
|
</Field.Root>
|
||||||
</Dialog.Body>
|
</Dialog.Body>
|
||||||
<Dialog.Footer>
|
<Dialog.Footer>
|
||||||
<Button variant="ghost" onClick={handleCloseDialog}>
|
<Button variant="ghost" onClick={onClose}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useRoomsList } from "../../lib/apiHooks";
|
import { useEffect, useState } from "react";
|
||||||
import type { components } from "../../reflector-api";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
type Page_Room_ = components["schemas"]["Page_RoomDetails_"];
|
import { Page_Room_ } from "../../api";
|
||||||
import { PaginationPage } from "../browse/_components/Pagination";
|
import { PaginationPage } from "../browse/_components/Pagination";
|
||||||
|
|
||||||
type RoomList = {
|
type RoomList = {
|
||||||
@@ -11,17 +11,38 @@ type RoomList = {
|
|||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wrapper to maintain backward compatibility
|
//always protected
|
||||||
const useRoomList = (page: PaginationPage): RoomList => {
|
const useRoomList = (page: PaginationPage): RoomList => {
|
||||||
const { data, isLoading, error, refetch } = useRoomsList(page);
|
const [response, setResponse] = useState<Page_Room_ | null>(null);
|
||||||
return {
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
response: data || null,
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
loading: isLoading,
|
const { setError } = useError();
|
||||||
error: error
|
const api = useApi();
|
||||||
? new Error(error.detail ? JSON.stringify(error.detail) : undefined)
|
const [refetchCount, setRefetchCount] = useState(0);
|
||||||
: null,
|
|
||||||
refetch,
|
const refetch = () => {
|
||||||
|
setLoading(true);
|
||||||
|
setRefetchCount(refetchCount + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!api) return;
|
||||||
|
setLoading(true);
|
||||||
|
api
|
||||||
|
.v1RoomsList({ page })
|
||||||
|
.then((response) => {
|
||||||
|
setResponse(response);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setResponse(null);
|
||||||
|
setLoading(false);
|
||||||
|
setError(err);
|
||||||
|
setErrorState(err);
|
||||||
|
});
|
||||||
|
}, [!api, page, refetchCount]);
|
||||||
|
|
||||||
|
return { response, loading, error, refetch };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useRoomList;
|
export default useRoomList;
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ import ScrollToBottom from "../../scrollToBottom";
|
|||||||
import { Topic } from "../../webSocketTypes";
|
import { Topic } from "../../webSocketTypes";
|
||||||
import useParticipants from "../../useParticipants";
|
import useParticipants from "../../useParticipants";
|
||||||
import { Box, Flex, Text, Accordion } from "@chakra-ui/react";
|
import { Box, Flex, Text, Accordion } from "@chakra-ui/react";
|
||||||
|
import { featureEnabled } from "../../../../domainContext";
|
||||||
import { TopicItem } from "./TopicItem";
|
import { TopicItem } from "./TopicItem";
|
||||||
import { TranscriptStatus } from "../../../../lib/transcript";
|
|
||||||
|
|
||||||
import { featureEnabled } from "../../../../lib/features";
|
|
||||||
|
|
||||||
type TopicListProps = {
|
type TopicListProps = {
|
||||||
topics: Topic[];
|
topics: Topic[];
|
||||||
@@ -16,7 +14,7 @@ type TopicListProps = {
|
|||||||
];
|
];
|
||||||
autoscroll: boolean;
|
autoscroll: boolean;
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
status: TranscriptStatus | null;
|
status: string;
|
||||||
currentTranscriptText: any;
|
currentTranscriptText: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,30 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useState, use } from "react";
|
import { useState } from "react";
|
||||||
import TopicHeader from "./topicHeader";
|
import TopicHeader from "./topicHeader";
|
||||||
import TopicWords from "./topicWords";
|
import TopicWords from "./topicWords";
|
||||||
import TopicPlayer from "./topicPlayer";
|
import TopicPlayer from "./topicPlayer";
|
||||||
import useParticipants from "../../useParticipants";
|
import useParticipants from "../../useParticipants";
|
||||||
import useTopicWithWords from "../../useTopicWithWords";
|
import useTopicWithWords from "../../useTopicWithWords";
|
||||||
import ParticipantList from "./participantList";
|
import ParticipantList from "./participantList";
|
||||||
import type { components } from "../../../../reflector-api";
|
import { GetTranscriptTopic } from "../../../../api";
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
|
||||||
import { SelectedText, selectedTextIsTimeSlice } from "./types";
|
import { SelectedText, selectedTextIsTimeSlice } from "./types";
|
||||||
import {
|
import useApi from "../../../../lib/useApi";
|
||||||
useTranscriptGet,
|
import useTranscript from "../../useTranscript";
|
||||||
useTranscriptUpdate,
|
|
||||||
} from "../../../../lib/apiHooks";
|
|
||||||
import { useError } from "../../../../(errors)/errorContext";
|
import { useError } from "../../../../(errors)/errorContext";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Box, Grid } from "@chakra-ui/react";
|
import { Box, Grid } from "@chakra-ui/react";
|
||||||
|
|
||||||
export type TranscriptCorrect = {
|
export type TranscriptCorrect = {
|
||||||
params: Promise<{
|
params: {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
}>;
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TranscriptCorrect(props: TranscriptCorrect) {
|
export default function TranscriptCorrect({
|
||||||
const params = use(props.params);
|
params: { transcriptId },
|
||||||
|
}: TranscriptCorrect) {
|
||||||
const { transcriptId } = params;
|
const api = useApi();
|
||||||
|
const transcript = useTranscript(transcriptId);
|
||||||
const updateTranscriptMutation = useTranscriptUpdate();
|
|
||||||
const transcript = useTranscriptGet(transcriptId);
|
|
||||||
const stateCurrentTopic = useState<GetTranscriptTopic>();
|
const stateCurrentTopic = useState<GetTranscriptTopic>();
|
||||||
const [currentTopic, _sct] = stateCurrentTopic;
|
const [currentTopic, _sct] = stateCurrentTopic;
|
||||||
const stateSelectedText = useState<SelectedText>();
|
const stateSelectedText = useState<SelectedText>();
|
||||||
@@ -39,21 +34,16 @@ export default function TranscriptCorrect(props: TranscriptCorrect) {
|
|||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const markAsDone = async () => {
|
const markAsDone = () => {
|
||||||
if (transcript.data && !transcript.data.reviewed) {
|
if (transcript.response && !transcript.response.reviewed) {
|
||||||
try {
|
api
|
||||||
await updateTranscriptMutation.mutateAsync({
|
?.v1TranscriptUpdate({ transcriptId, requestBody: { reviewed: true } })
|
||||||
params: {
|
.then(() => {
|
||||||
path: {
|
router.push(`/transcripts/${transcriptId}`);
|
||||||
transcript_id: transcriptId,
|
})
|
||||||
},
|
.catch((e) => {
|
||||||
},
|
setError(e, "Error marking as done");
|
||||||
body: { reviewed: true },
|
|
||||||
});
|
});
|
||||||
router.push(`/transcripts/${transcriptId}`);
|
|
||||||
} catch (e) {
|
|
||||||
setError(e as Error, "Error marking as done");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,7 +108,7 @@ export default function TranscriptCorrect(props: TranscriptCorrect) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
{transcript.data && !transcript.data?.reviewed && (
|
{transcript.response && !transcript.response?.reviewed && (
|
||||||
<div className="flex flex-row justify-end">
|
<div className="flex flex-row justify-end">
|
||||||
<button
|
<button
|
||||||
className="p-2 px-4 rounded bg-green-400"
|
className="p-2 px-4 rounded bg-green-400"
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import { faArrowTurnDown } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowTurnDown } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { ChangeEvent, useEffect, useRef, useState } from "react";
|
import { ChangeEvent, useEffect, useRef, useState } from "react";
|
||||||
import type { components } from "../../../../reflector-api";
|
import { Participant } from "../../../../api";
|
||||||
type Participant = components["schemas"]["Participant"];
|
import useApi from "../../../../lib/useApi";
|
||||||
import {
|
|
||||||
useTranscriptSpeakerAssign,
|
|
||||||
useTranscriptSpeakerMerge,
|
|
||||||
useTranscriptParticipantUpdate,
|
|
||||||
useTranscriptParticipantCreate,
|
|
||||||
useTranscriptParticipantDelete,
|
|
||||||
} from "../../../../lib/apiHooks";
|
|
||||||
import { UseParticipants } from "../../useParticipants";
|
import { UseParticipants } from "../../useParticipants";
|
||||||
import { selectedTextIsSpeaker, selectedTextIsTimeSlice } from "./types";
|
import { selectedTextIsSpeaker, selectedTextIsTimeSlice } from "./types";
|
||||||
import { useError } from "../../../../(errors)/errorContext";
|
import { useError } from "../../../../(errors)/errorContext";
|
||||||
@@ -37,19 +30,9 @@ const ParticipantList = ({
|
|||||||
topicWithWords,
|
topicWithWords,
|
||||||
stateSelectedText,
|
stateSelectedText,
|
||||||
}: ParticipantList) => {
|
}: ParticipantList) => {
|
||||||
|
const api = useApi();
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const speakerAssignMutation = useTranscriptSpeakerAssign();
|
const [loading, setLoading] = useState(false);
|
||||||
const speakerMergeMutation = useTranscriptSpeakerMerge();
|
|
||||||
const participantUpdateMutation = useTranscriptParticipantUpdate();
|
|
||||||
const participantCreateMutation = useTranscriptParticipantCreate();
|
|
||||||
const participantDeleteMutation = useTranscriptParticipantDelete();
|
|
||||||
|
|
||||||
const loading =
|
|
||||||
speakerAssignMutation.isPending ||
|
|
||||||
speakerMergeMutation.isPending ||
|
|
||||||
participantUpdateMutation.isPending ||
|
|
||||||
participantCreateMutation.isPending ||
|
|
||||||
participantDeleteMutation.isPending;
|
|
||||||
const [participantInput, setParticipantInput] = useState("");
|
const [participantInput, setParticipantInput] = useState("");
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [selectedText, setSelectedText] = stateSelectedText;
|
const [selectedText, setSelectedText] = stateSelectedText;
|
||||||
@@ -120,6 +103,7 @@ const ParticipantList = ({
|
|||||||
const onSuccess = () => {
|
const onSuccess = () => {
|
||||||
topicWithWords.refetch();
|
topicWithWords.refetch();
|
||||||
participants.refetch();
|
participants.refetch();
|
||||||
|
setLoading(false);
|
||||||
setAction(null);
|
setAction(null);
|
||||||
setSelectedText(undefined);
|
setSelectedText(undefined);
|
||||||
setSelectedParticipant(undefined);
|
setSelectedParticipant(undefined);
|
||||||
@@ -136,14 +120,11 @@ const ParticipantList = ({
|
|||||||
if (loading || participants.loading || topicWithWords.loading) return;
|
if (loading || participants.loading || topicWithWords.loading) return;
|
||||||
if (!selectedTextIsTimeSlice(selectedText)) return;
|
if (!selectedTextIsTimeSlice(selectedText)) return;
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await speakerAssignMutation.mutateAsync({
|
await api?.v1TranscriptAssignSpeaker({
|
||||||
params: {
|
transcriptId,
|
||||||
path: {
|
requestBody: {
|
||||||
transcript_id: transcriptId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
participant: participant.id,
|
participant: participant.id,
|
||||||
timestamp_from: selectedText.start,
|
timestamp_from: selectedText.start,
|
||||||
timestamp_to: selectedText.end,
|
timestamp_to: selectedText.end,
|
||||||
@@ -151,7 +132,8 @@ const ParticipantList = ({
|
|||||||
});
|
});
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error as Error, "There was an error assigning");
|
setError(error, "There was an error assigning");
|
||||||
|
setLoading(false);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -159,38 +141,32 @@ const ParticipantList = ({
|
|||||||
const mergeSpeaker =
|
const mergeSpeaker =
|
||||||
(speakerFrom, participantTo: Participant) => async () => {
|
(speakerFrom, participantTo: Participant) => async () => {
|
||||||
if (loading || participants.loading || topicWithWords.loading) return;
|
if (loading || participants.loading || topicWithWords.loading) return;
|
||||||
|
setLoading(true);
|
||||||
if (participantTo.speaker) {
|
if (participantTo.speaker) {
|
||||||
try {
|
try {
|
||||||
await speakerMergeMutation.mutateAsync({
|
await api?.v1TranscriptMergeSpeaker({
|
||||||
params: {
|
transcriptId,
|
||||||
path: {
|
requestBody: {
|
||||||
transcript_id: transcriptId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
speaker_from: speakerFrom,
|
speaker_from: speakerFrom,
|
||||||
speaker_to: participantTo.speaker,
|
speaker_to: participantTo.speaker,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error as Error, "There was an error merging");
|
setError(error, "There was an error merging");
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await participantUpdateMutation.mutateAsync({
|
await api?.v1TranscriptUpdateParticipant({
|
||||||
params: {
|
transcriptId,
|
||||||
path: {
|
participantId: participantTo.id,
|
||||||
transcript_id: transcriptId,
|
requestBody: { speaker: speakerFrom },
|
||||||
participant_id: participantTo.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: { speaker: speakerFrom },
|
|
||||||
});
|
});
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error as Error, "There was an error merging (update)");
|
setError(error, "There was an error merging (update)");
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -210,106 +186,105 @@ const ParticipantList = ({
|
|||||||
(p) => p.speaker == selectedText,
|
(p) => p.speaker == selectedText,
|
||||||
);
|
);
|
||||||
if (participant && participant.name !== participantInput) {
|
if (participant && participant.name !== participantInput) {
|
||||||
try {
|
setLoading(true);
|
||||||
await participantUpdateMutation.mutateAsync({
|
api
|
||||||
params: {
|
?.v1TranscriptUpdateParticipant({
|
||||||
path: {
|
transcriptId,
|
||||||
transcript_id: transcriptId,
|
participantId: participant.id,
|
||||||
participant_id: participant.id,
|
requestBody: {
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
participants.refetch();
|
||||||
|
setLoading(false);
|
||||||
|
setAction(null);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
setError(e, "There was an error renaming");
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
participants.refetch();
|
|
||||||
setAction(null);
|
|
||||||
} catch (e) {
|
|
||||||
setError(e as Error, "There was an error renaming");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
action == "Create to rename" &&
|
action == "Create to rename" &&
|
||||||
selectedTextIsSpeaker(selectedText)
|
selectedTextIsSpeaker(selectedText)
|
||||||
) {
|
) {
|
||||||
try {
|
setLoading(true);
|
||||||
await participantCreateMutation.mutateAsync({
|
api
|
||||||
params: {
|
?.v1TranscriptAddParticipant({
|
||||||
path: {
|
transcriptId,
|
||||||
transcript_id: transcriptId,
|
requestBody: {
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
speaker: selectedText,
|
speaker: selectedText,
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
participants.refetch();
|
||||||
|
setParticipantInput("");
|
||||||
|
setOneMatch(undefined);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
setError(e, "There was an error creating");
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
participants.refetch();
|
|
||||||
setParticipantInput("");
|
|
||||||
setOneMatch(undefined);
|
|
||||||
} catch (e) {
|
|
||||||
setError(e as Error, "There was an error creating");
|
|
||||||
}
|
|
||||||
} else if (
|
} else if (
|
||||||
action == "Create and assign" &&
|
action == "Create and assign" &&
|
||||||
selectedTextIsTimeSlice(selectedText)
|
selectedTextIsTimeSlice(selectedText)
|
||||||
) {
|
) {
|
||||||
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const participant = await participantCreateMutation.mutateAsync({
|
const participant = await api?.v1TranscriptAddParticipant({
|
||||||
params: {
|
transcriptId,
|
||||||
path: {
|
requestBody: {
|
||||||
transcript_id: transcriptId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
setLoading(false);
|
||||||
assignTo(participant)().catch(() => {
|
assignTo(participant)().catch(() => {
|
||||||
// error and loading are handled by assignTo catch
|
// error and loading are handled by assignTo catch
|
||||||
participants.refetch();
|
participants.refetch();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error as Error, "There was an error creating");
|
setError(e, "There was an error creating");
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else if (action == "Create") {
|
} else if (action == "Create") {
|
||||||
try {
|
setLoading(true);
|
||||||
await participantCreateMutation.mutateAsync({
|
api
|
||||||
params: {
|
?.v1TranscriptAddParticipant({
|
||||||
path: {
|
transcriptId,
|
||||||
transcript_id: transcriptId,
|
requestBody: {
|
||||||
},
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
participants.refetch();
|
||||||
|
setParticipantInput("");
|
||||||
|
setLoading(false);
|
||||||
|
inputRef.current?.focus();
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
setError(e, "There was an error creating");
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
participants.refetch();
|
|
||||||
setParticipantInput("");
|
|
||||||
inputRef.current?.focus();
|
|
||||||
} catch (e) {
|
|
||||||
setError(e as Error, "There was an error creating");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteParticipant = (participantId) => async (e) => {
|
const deleteParticipant = (participantId) => (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (loading || participants.loading || topicWithWords.loading) return;
|
if (loading || participants.loading || topicWithWords.loading) return;
|
||||||
|
setLoading(true);
|
||||||
try {
|
api
|
||||||
await participantDeleteMutation.mutateAsync({
|
?.v1TranscriptDeleteParticipant({ transcriptId, participantId })
|
||||||
params: {
|
.then(() => {
|
||||||
path: {
|
participants.refetch();
|
||||||
transcript_id: transcriptId,
|
setLoading(false);
|
||||||
participant_id: participantId,
|
})
|
||||||
},
|
.catch((e) => {
|
||||||
},
|
setError(e, "There was an error deleting");
|
||||||
|
setLoading(false);
|
||||||
});
|
});
|
||||||
participants.refetch();
|
|
||||||
} catch (e) {
|
|
||||||
setError(e as Error, "There was an error deleting");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectParticipant = (participant) => (e) => {
|
const selectParticipant = (participant) => (e) => {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import useTopics from "../../useTopics";
|
import useTopics from "../../useTopics";
|
||||||
import { Dispatch, SetStateAction, useEffect } from "react";
|
import { Dispatch, SetStateAction, useEffect } from "react";
|
||||||
import type { components } from "../../../../reflector-api";
|
import { GetTranscriptTopic } from "../../../../api";
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
|
||||||
import {
|
import {
|
||||||
BoxProps,
|
BoxProps,
|
||||||
Box,
|
Box,
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ import { useEffect, useRef, useState } from "react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Markdown from "react-markdown";
|
import Markdown from "react-markdown";
|
||||||
import "../../../styles/markdown.css";
|
import "../../../styles/markdown.css";
|
||||||
import type { components } from "../../../reflector-api";
|
import {
|
||||||
type GetTranscript = components["schemas"]["GetTranscript"];
|
GetTranscript,
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
GetTranscriptTopic,
|
||||||
import { useTranscriptUpdate } from "../../../lib/apiHooks";
|
UpdateTranscript,
|
||||||
|
} from "../../../api";
|
||||||
|
import useApi from "../../../lib/useApi";
|
||||||
import {
|
import {
|
||||||
Flex,
|
Flex,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -31,8 +33,9 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
const [preEditSummary, setPreEditSummary] = useState("");
|
const [preEditSummary, setPreEditSummary] = useState("");
|
||||||
const [editedSummary, setEditedSummary] = useState("");
|
const [editedSummary, setEditedSummary] = useState("");
|
||||||
|
|
||||||
|
const api = useApi();
|
||||||
|
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const updateTranscriptMutation = useTranscriptUpdate();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEditedSummary(props.transcriptResponse?.long_summary || "");
|
setEditedSummary(props.transcriptResponse?.long_summary || "");
|
||||||
@@ -44,15 +47,12 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
|
|
||||||
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
||||||
try {
|
try {
|
||||||
const updatedTranscript = await updateTranscriptMutation.mutateAsync({
|
const requestBody: UpdateTranscript = {
|
||||||
params: {
|
long_summary: newSummary,
|
||||||
path: {
|
};
|
||||||
transcript_id: transcriptId,
|
const updatedTranscript = await api?.v1TranscriptUpdate({
|
||||||
},
|
transcriptId,
|
||||||
},
|
requestBody,
|
||||||
body: {
|
|
||||||
long_summary: newSummary,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (props.onUpdate) {
|
if (props.onUpdate) {
|
||||||
props.onUpdate(newSummary);
|
props.onUpdate(newSummary);
|
||||||
@@ -60,7 +60,7 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
console.log("Updated long summary:", updatedTranscript);
|
console.log("Updated long summary:", updatedTranscript);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to update long summary:", err);
|
console.error("Failed to update long summary:", err);
|
||||||
setError(err as Error, "Failed to update long summary.");
|
setError(err, "Failed to update long summary.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,12 +114,7 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
<Button onClick={onDiscardClick} variant="ghost">
|
<Button onClick={onDiscardClick} variant="ghost">
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button onClick={onSaveClick}>Save</Button>
|
||||||
onClick={onSaveClick}
|
|
||||||
disabled={updateTranscriptMutation.isPending}
|
|
||||||
>
|
|
||||||
Save
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
{!isEditMode && (
|
{!isEditMode && (
|
||||||
|
|||||||
@@ -1,38 +1,32 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import Modal from "../modal";
|
import Modal from "../modal";
|
||||||
|
import useTranscript from "../useTranscript";
|
||||||
import useTopics from "../useTopics";
|
import useTopics from "../useTopics";
|
||||||
import useWaveform from "../useWaveform";
|
import useWaveform from "../useWaveform";
|
||||||
import useMp3 from "../useMp3";
|
import useMp3 from "../useMp3";
|
||||||
import { TopicList } from "./_components/TopicList";
|
import { TopicList } from "./_components/TopicList";
|
||||||
import { Topic } from "../webSocketTypes";
|
import { Topic } from "../webSocketTypes";
|
||||||
import React, { useEffect, useState, use } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import FinalSummary from "./finalSummary";
|
import FinalSummary from "./finalSummary";
|
||||||
import TranscriptTitle from "../transcriptTitle";
|
import TranscriptTitle from "../transcriptTitle";
|
||||||
import Player from "../player";
|
import Player from "../player";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Box, Flex, Grid, GridItem, Skeleton, Text } from "@chakra-ui/react";
|
import { Box, Flex, Grid, GridItem, Skeleton, Text } from "@chakra-ui/react";
|
||||||
import { useTranscriptGet } from "../../../lib/apiHooks";
|
|
||||||
import { TranscriptStatus } from "../../../lib/transcript";
|
|
||||||
|
|
||||||
type TranscriptDetails = {
|
type TranscriptDetails = {
|
||||||
params: Promise<{
|
params: {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
}>;
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TranscriptDetails(details: TranscriptDetails) {
|
export default function TranscriptDetails(details: TranscriptDetails) {
|
||||||
const params = use(details.params);
|
const transcriptId = details.params.transcriptId;
|
||||||
const transcriptId = params.transcriptId;
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const statusToRedirect = [
|
const statusToRedirect = ["idle", "recording", "processing"];
|
||||||
"idle",
|
|
||||||
"recording",
|
|
||||||
"processing",
|
|
||||||
] satisfies TranscriptStatus[] as TranscriptStatus[];
|
|
||||||
|
|
||||||
const transcript = useTranscriptGet(transcriptId);
|
const transcript = useTranscript(transcriptId);
|
||||||
const waiting =
|
const transcriptStatus = transcript.response?.status;
|
||||||
transcript.data && statusToRedirect.includes(transcript.data.status);
|
const waiting = statusToRedirect.includes(transcriptStatus || "");
|
||||||
|
|
||||||
const mp3 = useMp3(transcriptId, waiting);
|
const mp3 = useMp3(transcriptId, waiting);
|
||||||
const topics = useTopics(transcriptId);
|
const topics = useTopics(transcriptId);
|
||||||
@@ -44,7 +38,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
const newUrl = "/transcripts/" + params.transcriptId + "/record";
|
const newUrl = "/transcripts/" + details.params.transcriptId + "/record";
|
||||||
// Shallow redirection does not work on NextJS 13
|
// Shallow redirection does not work on NextJS 13
|
||||||
// https://github.com/vercel/next.js/discussions/48110
|
// https://github.com/vercel/next.js/discussions/48110
|
||||||
// https://github.com/vercel/next.js/discussions/49540
|
// https://github.com/vercel/next.js/discussions/49540
|
||||||
@@ -62,7 +56,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transcript?.isLoading || topics?.loading) {
|
if (transcript?.loading || topics?.loading) {
|
||||||
return <Modal title="Loading" text={"Loading transcript..."} />;
|
return <Modal title="Loading" text={"Loading transcript..."} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +86,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
waveform={waveform.waveform}
|
waveform={waveform.waveform}
|
||||||
media={mp3.media}
|
media={mp3.media}
|
||||||
mediaDuration={transcript.data?.duration || null}
|
mediaDuration={transcript.response.duration}
|
||||||
/>
|
/>
|
||||||
) : !mp3.loading && (waveform.error || mp3.error) ? (
|
) : !mp3.loading && (waveform.error || mp3.error) ? (
|
||||||
<Box p={4} bg="red.100" borderRadius="md">
|
<Box p={4} bg="red.100" borderRadius="md">
|
||||||
@@ -122,10 +116,10 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
<Flex direction="column" gap={0}>
|
<Flex direction="column" gap={0}>
|
||||||
<Flex alignItems="center" gap={2}>
|
<Flex alignItems="center" gap={2}>
|
||||||
<TranscriptTitle
|
<TranscriptTitle
|
||||||
title={transcript.data?.title || "Unnamed Transcript"}
|
title={transcript.response.title || "Unnamed Transcript"}
|
||||||
transcriptId={transcriptId}
|
transcriptId={transcriptId}
|
||||||
onUpdate={(newTitle) => {
|
onUpdate={(newTitle) => {
|
||||||
transcript.refetch().then(() => {});
|
transcript.reload();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -142,23 +136,23 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
autoscroll={false}
|
autoscroll={false}
|
||||||
transcriptId={transcriptId}
|
transcriptId={transcriptId}
|
||||||
status={transcript.data?.status || null}
|
status={transcript.response?.status}
|
||||||
currentTranscriptText=""
|
currentTranscriptText=""
|
||||||
/>
|
/>
|
||||||
{transcript.data && topics.topics ? (
|
{transcript.response && topics.topics ? (
|
||||||
<>
|
<>
|
||||||
<FinalSummary
|
<FinalSummary
|
||||||
transcriptResponse={transcript.data}
|
transcriptResponse={transcript.response}
|
||||||
topicsResponse={topics.topics}
|
topicsResponse={topics.topics}
|
||||||
onUpdate={() => {
|
onUpdate={(newSummary) => {
|
||||||
transcript.refetch();
|
transcript.reload();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Flex justify={"center"} alignItems={"center"} h={"100%"}>
|
<Flex justify={"center"} alignItems={"center"} h={"100%"}>
|
||||||
<div className="flex flex-col h-full justify-center content-center">
|
<div className="flex flex-col h-full justify-center content-center">
|
||||||
{transcript?.data?.status == "processing" ? (
|
{transcript.response.status == "processing" ? (
|
||||||
<Text>Loading Transcript</Text>
|
<Text>Loading Transcript</Text>
|
||||||
) : (
|
) : (
|
||||||
<Text>
|
<Text>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState, use } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Recorder from "../../recorder";
|
import Recorder from "../../recorder";
|
||||||
import { TopicList } from "../_components/TopicList";
|
import { TopicList } from "../_components/TopicList";
|
||||||
|
import useTranscript from "../../useTranscript";
|
||||||
import { useWebSockets } from "../../useWebSockets";
|
import { useWebSockets } from "../../useWebSockets";
|
||||||
import { Topic } from "../../webSocketTypes";
|
import { Topic } from "../../webSocketTypes";
|
||||||
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
||||||
@@ -10,29 +11,26 @@ import useMp3 from "../../useMp3";
|
|||||||
import WaveformLoading from "../../waveformLoading";
|
import WaveformLoading from "../../waveformLoading";
|
||||||
import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react";
|
import { Box, Text, Grid, Heading, VStack, Flex } from "@chakra-ui/react";
|
||||||
import LiveTrancription from "../../liveTranscription";
|
import LiveTrancription from "../../liveTranscription";
|
||||||
import { useTranscriptGet } from "../../../../lib/apiHooks";
|
|
||||||
import { TranscriptStatus } from "../../../../lib/transcript";
|
|
||||||
|
|
||||||
type TranscriptDetails = {
|
type TranscriptDetails = {
|
||||||
params: Promise<{
|
params: {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
}>;
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const TranscriptRecord = (details: TranscriptDetails) => {
|
const TranscriptRecord = (details: TranscriptDetails) => {
|
||||||
const params = use(details.params);
|
const transcript = useTranscript(details.params.transcriptId);
|
||||||
const transcript = useTranscriptGet(params.transcriptId);
|
|
||||||
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
||||||
const useActiveTopic = useState<Topic | null>(null);
|
const useActiveTopic = useState<Topic | null>(null);
|
||||||
|
|
||||||
const webSockets = useWebSockets(params.transcriptId);
|
const webSockets = useWebSockets(details.params.transcriptId);
|
||||||
|
|
||||||
const mp3 = useMp3(params.transcriptId, true);
|
const mp3 = useMp3(details.params.transcriptId, true);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [status, setStatus] = useState<TranscriptStatus>(
|
const [status, setStatus] = useState(
|
||||||
webSockets.status?.value || transcript.data?.status || "idle",
|
webSockets.status.value || transcript.response?.status || "idle",
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -43,15 +41,15 @@ const TranscriptRecord = (details: TranscriptDetails) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//TODO HANDLE ERROR STATUS BETTER
|
//TODO HANDLE ERROR STATUS BETTER
|
||||||
const newStatus =
|
const newStatus =
|
||||||
webSockets.status?.value || transcript.data?.status || "idle";
|
webSockets.status.value || transcript.response?.status || "idle";
|
||||||
setStatus(newStatus);
|
setStatus(newStatus);
|
||||||
if (newStatus && (newStatus == "ended" || newStatus == "error")) {
|
if (newStatus && (newStatus == "ended" || newStatus == "error")) {
|
||||||
console.log(newStatus, "redirecting");
|
console.log(newStatus, "redirecting");
|
||||||
|
|
||||||
const newUrl = "/transcripts/" + params.transcriptId;
|
const newUrl = "/transcripts/" + details.params.transcriptId;
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
}
|
}
|
||||||
}, [webSockets.status?.value, transcript.data?.status]);
|
}, [webSockets.status.value, transcript.response?.status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
||||||
@@ -76,7 +74,7 @@ const TranscriptRecord = (details: TranscriptDetails) => {
|
|||||||
<WaveformLoading />
|
<WaveformLoading />
|
||||||
) : (
|
) : (
|
||||||
// todo: only start recording animation when you get "recorded" status
|
// todo: only start recording animation when you get "recorded" status
|
||||||
<Recorder transcriptId={params.transcriptId} status={status} />
|
<Recorder transcriptId={details.params.transcriptId} status={status} />
|
||||||
)}
|
)}
|
||||||
<VStack
|
<VStack
|
||||||
align={"left"}
|
align={"left"}
|
||||||
@@ -99,7 +97,7 @@ const TranscriptRecord = (details: TranscriptDetails) => {
|
|||||||
topics={webSockets.topics}
|
topics={webSockets.topics}
|
||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
autoscroll={true}
|
autoscroll={true}
|
||||||
transcriptId={params.transcriptId}
|
transcriptId={details.params.transcriptId}
|
||||||
status={status}
|
status={status}
|
||||||
currentTranscriptText={webSockets.accumulatedText}
|
currentTranscriptText={webSockets.accumulatedText}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,40 +1,33 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState, use } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import useTranscript from "../../useTranscript";
|
||||||
import { useWebSockets } from "../../useWebSockets";
|
import { useWebSockets } from "../../useWebSockets";
|
||||||
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
import { lockWakeState, releaseWakeState } from "../../../../lib/wakeLock";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import useMp3 from "../../useMp3";
|
import useMp3 from "../../useMp3";
|
||||||
import { Center, VStack, Text, Heading, Button } from "@chakra-ui/react";
|
import { Center, VStack, Text, Heading, Button } from "@chakra-ui/react";
|
||||||
import FileUploadButton from "../../fileUploadButton";
|
import FileUploadButton from "../../fileUploadButton";
|
||||||
import { useTranscriptGet } from "../../../../lib/apiHooks";
|
|
||||||
|
|
||||||
type TranscriptUpload = {
|
type TranscriptUpload = {
|
||||||
params: Promise<{
|
params: {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
}>;
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const TranscriptUpload = (details: TranscriptUpload) => {
|
const TranscriptUpload = (details: TranscriptUpload) => {
|
||||||
const params = use(details.params);
|
const transcript = useTranscript(details.params.transcriptId);
|
||||||
const transcript = useTranscriptGet(params.transcriptId);
|
|
||||||
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
||||||
|
|
||||||
const webSockets = useWebSockets(params.transcriptId);
|
const webSockets = useWebSockets(details.params.transcriptId);
|
||||||
|
|
||||||
const mp3 = useMp3(params.transcriptId, true);
|
const mp3 = useMp3(details.params.transcriptId, true);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [status_, setStatus] = useState(
|
const [status, setStatus] = useState(
|
||||||
webSockets.status?.value || transcript.data?.status || "idle",
|
webSockets.status.value || transcript.response?.status || "idle",
|
||||||
);
|
);
|
||||||
|
|
||||||
// status is obviously done if we have transcript
|
|
||||||
const status =
|
|
||||||
!transcript.isLoading && transcript.data?.status === "ended"
|
|
||||||
? transcript.data?.status
|
|
||||||
: status_;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!transcriptStarted && webSockets.transcriptTextLive.length !== 0)
|
if (!transcriptStarted && webSockets.transcriptTextLive.length !== 0)
|
||||||
setTranscriptStarted(true);
|
setTranscriptStarted(true);
|
||||||
@@ -42,19 +35,16 @@ const TranscriptUpload = (details: TranscriptUpload) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//TODO HANDLE ERROR STATUS BETTER
|
//TODO HANDLE ERROR STATUS BETTER
|
||||||
// TODO deprecate webSockets.status.value / depend on transcript.response?.status from query lib
|
|
||||||
const newStatus =
|
const newStatus =
|
||||||
transcript.data?.status === "ended"
|
webSockets.status.value || transcript.response?.status || "idle";
|
||||||
? "ended"
|
|
||||||
: webSockets.status?.value || transcript.data?.status || "idle";
|
|
||||||
setStatus(newStatus);
|
setStatus(newStatus);
|
||||||
if (newStatus && (newStatus == "ended" || newStatus == "error")) {
|
if (newStatus && (newStatus == "ended" || newStatus == "error")) {
|
||||||
console.log(newStatus, "redirecting");
|
console.log(newStatus, "redirecting");
|
||||||
|
|
||||||
const newUrl = "/transcripts/" + params.transcriptId;
|
const newUrl = "/transcripts/" + details.params.transcriptId;
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
}
|
}
|
||||||
}, [webSockets.status?.value, transcript.data?.status]);
|
}, [webSockets.status.value, transcript.response?.status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
||||||
@@ -85,7 +75,7 @@ const TranscriptUpload = (details: TranscriptUpload) => {
|
|||||||
Please select the file, supported formats: .mp3, m4a, .wav,
|
Please select the file, supported formats: .mp3, m4a, .wav,
|
||||||
.mp4, .mov or .webm
|
.mp4, .mov or .webm
|
||||||
</Text>
|
</Text>
|
||||||
<FileUploadButton transcriptId={params.transcriptId} />
|
<FileUploadButton transcriptId={details.params.transcriptId} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{status && status == "uploaded" && (
|
{status && status == "uploaded" && (
|
||||||
|
|||||||
@@ -1,33 +1,45 @@
|
|||||||
import type { components } from "../../reflector-api";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranscriptCreate } from "../../lib/apiHooks";
|
|
||||||
|
|
||||||
type CreateTranscript = components["schemas"]["CreateTranscript"];
|
import { useError } from "../../(errors)/errorContext";
|
||||||
type GetTranscript = components["schemas"]["GetTranscript"];
|
import { CreateTranscript, GetTranscript } from "../../api";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
|
||||||
type UseCreateTranscript = {
|
type UseCreateTranscript = {
|
||||||
transcript: GetTranscript | null;
|
transcript: GetTranscript | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: Error | null;
|
error: Error | null;
|
||||||
create: (transcriptCreationDetails: CreateTranscript) => Promise<void>;
|
create: (transcriptCreationDetails: CreateTranscript) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useCreateTranscript = (): UseCreateTranscript => {
|
const useCreateTranscript = (): UseCreateTranscript => {
|
||||||
const createMutation = useTranscriptCreate();
|
const [transcript, setTranscript] = useState<GetTranscript | null>(null);
|
||||||
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
|
const { setError } = useError();
|
||||||
|
const api = useApi();
|
||||||
|
|
||||||
const create = async (transcriptCreationDetails: CreateTranscript) => {
|
const create = (transcriptCreationDetails: CreateTranscript) => {
|
||||||
if (createMutation.isPending) return;
|
if (loading || !api) return;
|
||||||
|
|
||||||
await createMutation.mutateAsync({
|
setLoading(true);
|
||||||
body: transcriptCreationDetails,
|
|
||||||
});
|
api
|
||||||
|
.v1TranscriptsCreate({ requestBody: transcriptCreationDetails })
|
||||||
|
.then((transcript) => {
|
||||||
|
setTranscript(transcript);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setError(
|
||||||
|
err,
|
||||||
|
"There was an issue creating a transcript, please try again.",
|
||||||
|
);
|
||||||
|
setErrorState(err);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return { transcript, loading, error, create };
|
||||||
transcript: createMutation.data || null,
|
|
||||||
loading: createMutation.isPending,
|
|
||||||
error: createMutation.error as Error | null,
|
|
||||||
create,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useCreateTranscript;
|
export default useCreateTranscript;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranscriptUploadAudio } from "../../lib/apiHooks";
|
import useApi from "../../lib/useApi";
|
||||||
import { Button, Spinner } from "@chakra-ui/react";
|
import { Button, Spinner } from "@chakra-ui/react";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
|
||||||
|
|
||||||
type FileUploadButton = {
|
type FileUploadButton = {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
@@ -9,16 +8,13 @@ type FileUploadButton = {
|
|||||||
|
|
||||||
export default function FileUploadButton(props: FileUploadButton) {
|
export default function FileUploadButton(props: FileUploadButton) {
|
||||||
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
const uploadMutation = useTranscriptUploadAudio();
|
const api = useApi();
|
||||||
const { setError } = useError();
|
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
const triggerFileUpload = () => {
|
const triggerFileUpload = () => {
|
||||||
fileInputRef.current?.click();
|
fileInputRef.current?.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFileUpload = async (
|
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
event: React.ChangeEvent<HTMLInputElement>,
|
|
||||||
) => {
|
|
||||||
const file = event.target.files?.[0];
|
const file = event.target.files?.[0];
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
@@ -28,45 +24,37 @@ export default function FileUploadButton(props: FileUploadButton) {
|
|||||||
let start = 0;
|
let start = 0;
|
||||||
let uploadedSize = 0;
|
let uploadedSize = 0;
|
||||||
|
|
||||||
|
api?.httpRequest.config.interceptors.request.use((request) => {
|
||||||
|
request.onUploadProgress = (progressEvent) => {
|
||||||
|
const currentProgress = Math.floor(
|
||||||
|
((uploadedSize + progressEvent.loaded) / file.size) * 100,
|
||||||
|
);
|
||||||
|
setProgress(currentProgress);
|
||||||
|
};
|
||||||
|
return request;
|
||||||
|
});
|
||||||
|
|
||||||
const uploadNextChunk = async () => {
|
const uploadNextChunk = async () => {
|
||||||
if (chunkNumber == totalChunks) {
|
if (chunkNumber == totalChunks) return;
|
||||||
setProgress(0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const chunkSize = Math.min(maxChunkSize, file.size - start);
|
const chunkSize = Math.min(maxChunkSize, file.size - start);
|
||||||
const end = start + chunkSize;
|
const end = start + chunkSize;
|
||||||
const chunk = file.slice(start, end);
|
const chunk = file.slice(start, end);
|
||||||
|
|
||||||
try {
|
await api?.v1TranscriptRecordUpload({
|
||||||
const formData = new FormData();
|
transcriptId: props.transcriptId,
|
||||||
formData.append("chunk", chunk);
|
formData: {
|
||||||
|
chunk,
|
||||||
|
},
|
||||||
|
chunkNumber,
|
||||||
|
totalChunks,
|
||||||
|
});
|
||||||
|
|
||||||
await uploadMutation.mutateAsync({
|
uploadedSize += chunkSize;
|
||||||
params: {
|
chunkNumber++;
|
||||||
path: {
|
start = end;
|
||||||
transcript_id: props.transcriptId,
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
chunk_number: chunkNumber,
|
|
||||||
total_chunks: totalChunks,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
body: formData as any,
|
|
||||||
});
|
|
||||||
|
|
||||||
uploadedSize += chunkSize;
|
uploadNextChunk();
|
||||||
const currentProgress = Math.floor((uploadedSize / file.size) * 100);
|
|
||||||
setProgress(currentProgress);
|
|
||||||
|
|
||||||
chunkNumber++;
|
|
||||||
start = end;
|
|
||||||
|
|
||||||
await uploadNextChunk();
|
|
||||||
} catch (error) {
|
|
||||||
setError(error as Error, "Failed to upload file");
|
|
||||||
setProgress(0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uploadNextChunk();
|
uploadNextChunk();
|
||||||
|
|||||||
@@ -9,25 +9,33 @@ import { useRouter } from "next/navigation";
|
|||||||
import useCreateTranscript from "../createTranscript";
|
import useCreateTranscript from "../createTranscript";
|
||||||
import SelectSearch from "react-select-search";
|
import SelectSearch from "react-select-search";
|
||||||
import { supportedLanguages } from "../../../supportedLanguages";
|
import { supportedLanguages } from "../../../supportedLanguages";
|
||||||
|
import useSessionStatus from "../../../lib/useSessionStatus";
|
||||||
|
import { featureEnabled } from "../../../domainContext";
|
||||||
|
import { signIn } from "next-auth/react";
|
||||||
import {
|
import {
|
||||||
Flex,
|
Flex,
|
||||||
Box,
|
Box,
|
||||||
Spinner,
|
Spinner,
|
||||||
Heading,
|
Heading,
|
||||||
Button,
|
Button,
|
||||||
|
Card,
|
||||||
Center,
|
Center,
|
||||||
|
Link,
|
||||||
|
CardBody,
|
||||||
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
|
Icon,
|
||||||
|
Grid,
|
||||||
|
IconButton,
|
||||||
Spacer,
|
Spacer,
|
||||||
|
Menu,
|
||||||
|
Tooltip,
|
||||||
|
Input,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useAuth } from "../../../lib/AuthProvider";
|
|
||||||
import { featureEnabled } from "../../../lib/features";
|
|
||||||
|
|
||||||
const TranscriptCreate = () => {
|
const TranscriptCreate = () => {
|
||||||
|
const isClient = typeof window !== "undefined";
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const auth = useAuth();
|
const { isLoading, isAuthenticated } = useSessionStatus();
|
||||||
const isAuthenticated = auth.status === "authenticated";
|
|
||||||
const isAuthRefreshing = auth.status === "refreshing";
|
|
||||||
const isLoading = auth.status === "loading";
|
|
||||||
const requireLogin = featureEnabled("requireLogin");
|
const requireLogin = featureEnabled("requireLogin");
|
||||||
|
|
||||||
const [name, setName] = useState<string>("");
|
const [name, setName] = useState<string>("");
|
||||||
@@ -46,32 +54,20 @@ const TranscriptCreate = () => {
|
|||||||
const [loadingUpload, setLoadingUpload] = useState(false);
|
const [loadingUpload, setLoadingUpload] = useState(false);
|
||||||
|
|
||||||
const getTargetLanguage = () => {
|
const getTargetLanguage = () => {
|
||||||
if (targetLanguage === "NOTRANSLATION") return undefined;
|
if (targetLanguage === "NOTRANSLATION") return;
|
||||||
return targetLanguage;
|
return targetLanguage;
|
||||||
};
|
};
|
||||||
|
|
||||||
const send = () => {
|
const send = () => {
|
||||||
if (loadingRecord || createTranscript.loading || permissionDenied) return;
|
if (loadingRecord || createTranscript.loading || permissionDenied) return;
|
||||||
setLoadingRecord(true);
|
setLoadingRecord(true);
|
||||||
const targetLang = getTargetLanguage();
|
createTranscript.create({ name, target_language: getTargetLanguage() });
|
||||||
createTranscript.create({
|
|
||||||
name,
|
|
||||||
source_language: "en",
|
|
||||||
target_language: targetLang || "en",
|
|
||||||
source_kind: "live",
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadFile = () => {
|
const uploadFile = () => {
|
||||||
if (loadingUpload || createTranscript.loading || permissionDenied) return;
|
if (loadingUpload || createTranscript.loading || permissionDenied) return;
|
||||||
setLoadingUpload(true);
|
setLoadingUpload(true);
|
||||||
const targetLang = getTargetLanguage();
|
createTranscript.create({ name, target_language: getTargetLanguage() });
|
||||||
createTranscript.create({
|
|
||||||
name,
|
|
||||||
source_language: "en",
|
|
||||||
target_language: targetLang || "en",
|
|
||||||
source_kind: "file",
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -136,8 +132,8 @@ const TranscriptCreate = () => {
|
|||||||
<Center>
|
<Center>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : requireLogin && !isAuthenticated && !isAuthRefreshing ? (
|
) : requireLogin && !isAuthenticated ? (
|
||||||
<Button onClick={() => auth.signIn("authentik")}>Log in</Button>
|
<Button onClick={() => signIn("authentik")}>Log in</Button>
|
||||||
) : (
|
) : (
|
||||||
<Flex
|
<Flex
|
||||||
rounded="xl"
|
rounded="xl"
|
||||||
@@ -174,7 +170,7 @@ const TranscriptCreate = () => {
|
|||||||
placeholder="Choose your language"
|
placeholder="Choose your language"
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{!loading ? (
|
{isClient && !loading ? (
|
||||||
permissionOk ? (
|
permissionOk ? (
|
||||||
<Spacer />
|
<Spacer />
|
||||||
) : permissionDenied ? (
|
) : permissionDenied ? (
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import RegionsPlugin from "wavesurfer.js/dist/plugins/regions.esm.js";
|
|||||||
|
|
||||||
import { formatTime, formatTimeMs } from "../../lib/time";
|
import { formatTime, formatTimeMs } from "../../lib/time";
|
||||||
import { Topic } from "./webSocketTypes";
|
import { Topic } from "./webSocketTypes";
|
||||||
import type { components } from "../../reflector-api";
|
import { AudioWaveform } from "../../api";
|
||||||
|
|
||||||
type AudioWaveform = components["schemas"]["AudioWaveform"];
|
|
||||||
import { waveSurferStyles } from "../../styles/recorder";
|
import { waveSurferStyles } from "../../styles/recorder";
|
||||||
import { Box, Flex, IconButton } from "@chakra-ui/react";
|
import { Box, Flex, IconButton } from "@chakra-ui/react";
|
||||||
import { LuPause, LuPlay } from "react-icons/lu";
|
import { LuPause, LuPlay } from "react-icons/lu";
|
||||||
@@ -20,7 +18,7 @@ type PlayerProps = {
|
|||||||
];
|
];
|
||||||
waveform: AudioWaveform;
|
waveform: AudioWaveform;
|
||||||
media: HTMLMediaElement;
|
media: HTMLMediaElement;
|
||||||
mediaDuration: number | null;
|
mediaDuration: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Player(props: PlayerProps) {
|
export default function Player(props: PlayerProps) {
|
||||||
@@ -52,9 +50,7 @@ export default function Player(props: PlayerProps) {
|
|||||||
container: waveformRef.current,
|
container: waveformRef.current,
|
||||||
peaks: [props.waveform.data],
|
peaks: [props.waveform.data],
|
||||||
height: "auto",
|
height: "auto",
|
||||||
duration: props.mediaDuration
|
duration: Math.floor(props.mediaDuration / 1000),
|
||||||
? Math.floor(props.mediaDuration / 1000)
|
|
||||||
: undefined,
|
|
||||||
media: props.media,
|
media: props.media,
|
||||||
|
|
||||||
...waveSurferStyles.playerSettings,
|
...waveSurferStyles.playerSettings,
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import RecordPlugin from "../../lib/custom-plugins/record";
|
|||||||
import { formatTime, formatTimeMs } from "../../lib/time";
|
import { formatTime, formatTimeMs } from "../../lib/time";
|
||||||
import { waveSurferStyles } from "../../styles/recorder";
|
import { waveSurferStyles } from "../../styles/recorder";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import FileUploadButton from "./fileUploadButton";
|
||||||
import useWebRTC from "./useWebRTC";
|
import useWebRTC from "./useWebRTC";
|
||||||
import useAudioDevice from "./useAudioDevice";
|
import useAudioDevice from "./useAudioDevice";
|
||||||
import { Box, Flex, IconButton, Menu, RadioGroup } from "@chakra-ui/react";
|
import { Box, Flex, IconButton, Menu, RadioGroup } from "@chakra-ui/react";
|
||||||
import { LuScreenShare, LuMic, LuPlay, LuCircleStop } from "react-icons/lu";
|
import { LuScreenShare, LuMic, LuPlay, LuCircleStop } from "react-icons/lu";
|
||||||
import { RECORD_A_MEETING_URL } from "../../api/urls";
|
import { RECORD_A_MEETING_URL } from "../../api/urls";
|
||||||
import { TranscriptStatus } from "../../lib/transcript";
|
|
||||||
|
|
||||||
type RecorderProps = {
|
type RecorderProps = {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
status: TranscriptStatus;
|
status: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Recorder(props: RecorderProps) {
|
export default function Recorder(props: RecorderProps) {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { featureEnabled } from "../../domainContext";
|
||||||
|
|
||||||
import { ShareMode, toShareMode } from "../../lib/shareMode";
|
import { ShareMode, toShareMode } from "../../lib/shareMode";
|
||||||
import type { components } from "../../reflector-api";
|
import { GetTranscript, GetTranscriptTopic, UpdateTranscript } from "../../api";
|
||||||
type GetTranscript = components["schemas"]["GetTranscript"];
|
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
|
||||||
type UpdateTranscript = components["schemas"]["UpdateTranscript"];
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Flex,
|
Flex,
|
||||||
@@ -17,13 +15,12 @@ import {
|
|||||||
createListCollection,
|
createListCollection,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuShare2 } from "react-icons/lu";
|
import { LuShare2 } from "react-icons/lu";
|
||||||
import { useTranscriptUpdate } from "../../lib/apiHooks";
|
import useApi from "../../lib/useApi";
|
||||||
|
import useSessionUser from "../../lib/useSessionUser";
|
||||||
|
import { CustomSession } from "../../lib/types";
|
||||||
import ShareLink from "./shareLink";
|
import ShareLink from "./shareLink";
|
||||||
import ShareCopy from "./shareCopy";
|
import ShareCopy from "./shareCopy";
|
||||||
import ShareZulip from "./shareZulip";
|
import ShareZulip from "./shareZulip";
|
||||||
import { useAuth } from "../../lib/AuthProvider";
|
|
||||||
|
|
||||||
import { featureEnabled } from "../../lib/features";
|
|
||||||
|
|
||||||
type ShareAndPrivacyProps = {
|
type ShareAndPrivacyProps = {
|
||||||
finalSummaryRef: any;
|
finalSummaryRef: any;
|
||||||
@@ -53,9 +50,12 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
|||||||
);
|
);
|
||||||
const [shareLoading, setShareLoading] = useState(false);
|
const [shareLoading, setShareLoading] = useState(false);
|
||||||
const requireLogin = featureEnabled("requireLogin");
|
const requireLogin = featureEnabled("requireLogin");
|
||||||
const updateTranscriptMutation = useTranscriptUpdate();
|
const api = useApi();
|
||||||
|
|
||||||
const updateShareMode = async (selectedValue: string) => {
|
const updateShareMode = async (selectedValue: string) => {
|
||||||
|
if (!api)
|
||||||
|
throw new Error("ShareLink's API should always be ready at this point");
|
||||||
|
|
||||||
const selectedOption = shareOptionsData.find(
|
const selectedOption = shareOptionsData.find(
|
||||||
(option) => option.value === selectedValue,
|
(option) => option.value === selectedValue,
|
||||||
);
|
);
|
||||||
@@ -67,27 +67,19 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
|||||||
share_mode: selectedValue as "public" | "semi-private" | "private",
|
share_mode: selectedValue as "public" | "semi-private" | "private",
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const updatedTranscript = await api.v1TranscriptUpdate({
|
||||||
const updatedTranscript = await updateTranscriptMutation.mutateAsync({
|
transcriptId: props.transcriptResponse.id,
|
||||||
params: {
|
requestBody,
|
||||||
path: { transcript_id: props.transcriptResponse.id },
|
});
|
||||||
},
|
setShareMode(
|
||||||
body: requestBody,
|
shareOptionsData.find(
|
||||||
});
|
(option) => option.value === updatedTranscript.share_mode,
|
||||||
setShareMode(
|
) || shareOptionsData[0],
|
||||||
shareOptionsData.find(
|
);
|
||||||
(option) => option.value === updatedTranscript.share_mode,
|
setShareLoading(false);
|
||||||
) || shareOptionsData[0],
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Failed to update share mode:", err);
|
|
||||||
} finally {
|
|
||||||
setShareLoading(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const auth = useAuth();
|
const userId = useSessionUser().id;
|
||||||
const userId = auth.status === "authenticated" ? auth.user?.id : null;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsOwner(!!(requireLogin && userId === props.transcriptResponse.user_id));
|
setIsOwner(!!(requireLogin && userId === props.transcriptResponse.user_id));
|
||||||
@@ -132,7 +124,7 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
|||||||
"This transcript is public. Everyone can access it."}
|
"This transcript is public. Everyone can access it."}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{isOwner && (
|
{isOwner && api && (
|
||||||
<Select.Root
|
<Select.Root
|
||||||
key={shareMode.value}
|
key={shareMode.value}
|
||||||
value={[shareMode.value || ""]}
|
value={[shareMode.value || ""]}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { components } from "../../reflector-api";
|
import { GetTranscript, GetTranscriptTopic } from "../../api";
|
||||||
type GetTranscript = components["schemas"]["GetTranscript"];
|
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
|
||||||
import { Button, BoxProps, Box } from "@chakra-ui/react";
|
import { Button, BoxProps, Box } from "@chakra-ui/react";
|
||||||
|
|
||||||
type ShareCopyProps = {
|
type ShareCopyProps = {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import React, { useState, useRef, useEffect, use } from "react";
|
import React, { useState, useRef, useEffect, use } from "react";
|
||||||
|
import { featureEnabled } from "../../domainContext";
|
||||||
import { Button, Flex, Input, Text } from "@chakra-ui/react";
|
import { Button, Flex, Input, Text } from "@chakra-ui/react";
|
||||||
import QRCode from "react-qr-code";
|
import QRCode from "react-qr-code";
|
||||||
|
|
||||||
import { featureEnabled } from "../../lib/features";
|
|
||||||
|
|
||||||
type ShareLinkProps = {
|
type ShareLinkProps = {
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { useState, useEffect, useMemo } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import type { components } from "../../reflector-api";
|
import { featureEnabled } from "../../domainContext";
|
||||||
|
import { GetTranscript, GetTranscriptTopic } from "../../api";
|
||||||
type GetTranscript = components["schemas"]["GetTranscript"];
|
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
|
||||||
import {
|
import {
|
||||||
BoxProps,
|
BoxProps,
|
||||||
Button,
|
Button,
|
||||||
@@ -14,16 +12,12 @@ import {
|
|||||||
Checkbox,
|
Checkbox,
|
||||||
Combobox,
|
Combobox,
|
||||||
Spinner,
|
Spinner,
|
||||||
createListCollection,
|
Portal,
|
||||||
|
useFilter,
|
||||||
|
useListCollection,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { TbBrandZulip } from "react-icons/tb";
|
import { TbBrandZulip } from "react-icons/tb";
|
||||||
import {
|
import useApi from "../../lib/useApi";
|
||||||
useZulipStreams,
|
|
||||||
useZulipTopics,
|
|
||||||
useTranscriptPostToZulip,
|
|
||||||
} from "../../lib/apiHooks";
|
|
||||||
|
|
||||||
import { featureEnabled } from "../../lib/features";
|
|
||||||
|
|
||||||
type ShareZulipProps = {
|
type ShareZulipProps = {
|
||||||
transcriptResponse: GetTranscript;
|
transcriptResponse: GetTranscript;
|
||||||
@@ -36,77 +30,104 @@ interface Stream {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Topic {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [stream, setStream] = useState<string | undefined>(undefined);
|
const [stream, setStream] = useState<string | undefined>(undefined);
|
||||||
const [selectedStreamId, setSelectedStreamId] = useState<number | null>(null);
|
|
||||||
const [topic, setTopic] = useState<string | undefined>(undefined);
|
const [topic, setTopic] = useState<string | undefined>(undefined);
|
||||||
const [includeTopics, setIncludeTopics] = useState(false);
|
const [includeTopics, setIncludeTopics] = useState(false);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [streams, setStreams] = useState<Stream[]>([]);
|
||||||
|
const [topics, setTopics] = useState<Topic[]>([]);
|
||||||
|
const api = useApi();
|
||||||
|
const { contains } = useFilter({ sensitivity: "base" });
|
||||||
|
|
||||||
const { data: streams = [], isLoading: isLoadingStreams } = useZulipStreams();
|
const {
|
||||||
const { data: topics = [] } = useZulipTopics(selectedStreamId);
|
collection: streamItemsCollection,
|
||||||
const postToZulipMutation = useTranscriptPostToZulip();
|
filter: streamItemsFilter,
|
||||||
|
set: streamItemsSet,
|
||||||
|
} = useListCollection({
|
||||||
|
initialItems: [] as { label: string; value: string }[],
|
||||||
|
filter: contains,
|
||||||
|
});
|
||||||
|
|
||||||
const streamItems = useMemo(() => {
|
const {
|
||||||
return streams.map((stream: Stream) => ({
|
collection: topicItemsCollection,
|
||||||
label: stream.name,
|
filter: topicItemsFilter,
|
||||||
value: stream.name,
|
set: topicItemsSet,
|
||||||
}));
|
} = useListCollection({
|
||||||
}, [streams]);
|
initialItems: [] as { label: string; value: string }[],
|
||||||
|
filter: contains,
|
||||||
|
});
|
||||||
|
|
||||||
const topicItems = useMemo(() => {
|
|
||||||
return topics.map(({ name }) => ({
|
|
||||||
label: name,
|
|
||||||
value: name,
|
|
||||||
}));
|
|
||||||
}, [topics]);
|
|
||||||
|
|
||||||
const streamCollection = useMemo(
|
|
||||||
() =>
|
|
||||||
createListCollection({
|
|
||||||
items: streamItems,
|
|
||||||
}),
|
|
||||||
[streamItems],
|
|
||||||
);
|
|
||||||
|
|
||||||
const topicCollection = useMemo(
|
|
||||||
() =>
|
|
||||||
createListCollection({
|
|
||||||
items: topicItems,
|
|
||||||
}),
|
|
||||||
[topicItems],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update selected stream ID when stream changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (stream && streams) {
|
const fetchZulipStreams = async () => {
|
||||||
const selectedStream = streams.find((s: Stream) => s.name === stream);
|
if (!api) return;
|
||||||
setSelectedStreamId(selectedStream ? selectedStream.stream_id : null);
|
|
||||||
} else {
|
try {
|
||||||
setSelectedStreamId(null);
|
const response = await api.v1ZulipGetStreams();
|
||||||
}
|
setStreams(response);
|
||||||
}, [stream, streams]);
|
|
||||||
|
streamItemsSet(
|
||||||
|
response.map((stream) => ({
|
||||||
|
label: stream.name,
|
||||||
|
value: stream.name,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
setIsLoading(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching Zulip streams:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchZulipStreams();
|
||||||
|
}, [!api]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchZulipTopics = async () => {
|
||||||
|
if (!api || !stream) return;
|
||||||
|
try {
|
||||||
|
const selectedStream = streams.find((s) => s.name === stream);
|
||||||
|
if (selectedStream) {
|
||||||
|
const response = await api.v1ZulipGetTopics({
|
||||||
|
streamId: selectedStream.stream_id,
|
||||||
|
});
|
||||||
|
setTopics(response);
|
||||||
|
topicItemsSet(
|
||||||
|
response.map((topic) => ({
|
||||||
|
label: topic.name,
|
||||||
|
value: topic.name,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
topicItemsSet([]);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching Zulip topics:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchZulipTopics();
|
||||||
|
}, [stream, streams, api]);
|
||||||
|
|
||||||
const handleSendToZulip = async () => {
|
const handleSendToZulip = async () => {
|
||||||
if (!props.transcriptResponse) return;
|
if (!api || !props.transcriptResponse) return;
|
||||||
|
|
||||||
if (stream && topic) {
|
if (stream && topic) {
|
||||||
try {
|
try {
|
||||||
await postToZulipMutation.mutateAsync({
|
await api.v1TranscriptPostToZulip({
|
||||||
params: {
|
transcriptId: props.transcriptResponse.id,
|
||||||
path: {
|
stream,
|
||||||
transcript_id: props.transcriptResponse.id,
|
topic,
|
||||||
},
|
includeTopics,
|
||||||
query: {
|
|
||||||
stream,
|
|
||||||
topic,
|
|
||||||
include_topics: includeTopics,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error posting to Zulip:", error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -134,7 +155,7 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
</Dialog.CloseTrigger>
|
</Dialog.CloseTrigger>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
<Dialog.Body>
|
<Dialog.Body>
|
||||||
{isLoadingStreams ? (
|
{isLoading ? (
|
||||||
<Flex justify="center" py={8}>
|
<Flex justify="center" py={8}>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -157,12 +178,15 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
<Flex align="center" gap={2}>
|
<Flex align="center" gap={2}>
|
||||||
<Text>#</Text>
|
<Text>#</Text>
|
||||||
<Combobox.Root
|
<Combobox.Root
|
||||||
collection={streamCollection}
|
collection={streamItemsCollection}
|
||||||
value={stream ? [stream] : []}
|
value={stream ? [stream] : []}
|
||||||
onValueChange={(e) => {
|
onValueChange={(e) => {
|
||||||
setTopic(undefined);
|
setTopic(undefined);
|
||||||
setStream(e.value[0]);
|
setStream(e.value[0]);
|
||||||
}}
|
}}
|
||||||
|
onInputValueChange={(e) =>
|
||||||
|
streamItemsFilter(e.inputValue)
|
||||||
|
}
|
||||||
openOnClick={true}
|
openOnClick={true}
|
||||||
positioning={{
|
positioning={{
|
||||||
strategy: "fixed",
|
strategy: "fixed",
|
||||||
@@ -179,7 +203,7 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
<Combobox.Positioner>
|
<Combobox.Positioner>
|
||||||
<Combobox.Content>
|
<Combobox.Content>
|
||||||
<Combobox.Empty>No streams found</Combobox.Empty>
|
<Combobox.Empty>No streams found</Combobox.Empty>
|
||||||
{streamItems.map((item) => (
|
{streamItemsCollection.items.map((item) => (
|
||||||
<Combobox.Item key={item.value} item={item}>
|
<Combobox.Item key={item.value} item={item}>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Combobox.Item>
|
</Combobox.Item>
|
||||||
@@ -195,9 +219,12 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
<Flex align="center" gap={2}>
|
<Flex align="center" gap={2}>
|
||||||
<Text visibility="hidden">#</Text>
|
<Text visibility="hidden">#</Text>
|
||||||
<Combobox.Root
|
<Combobox.Root
|
||||||
collection={topicCollection}
|
collection={topicItemsCollection}
|
||||||
value={topic ? [topic] : []}
|
value={topic ? [topic] : []}
|
||||||
onValueChange={(e) => setTopic(e.value[0])}
|
onValueChange={(e) => setTopic(e.value[0])}
|
||||||
|
onInputValueChange={(e) =>
|
||||||
|
topicItemsFilter(e.inputValue)
|
||||||
|
}
|
||||||
openOnClick
|
openOnClick
|
||||||
selectionBehavior="replace"
|
selectionBehavior="replace"
|
||||||
skipAnimationOnMount={true}
|
skipAnimationOnMount={true}
|
||||||
@@ -217,7 +244,7 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
<Combobox.Positioner>
|
<Combobox.Positioner>
|
||||||
<Combobox.Content>
|
<Combobox.Content>
|
||||||
<Combobox.Empty>No topics found</Combobox.Empty>
|
<Combobox.Empty>No topics found</Combobox.Empty>
|
||||||
{topicItems.map((item) => (
|
{topicItemsCollection.items.map((item) => (
|
||||||
<Combobox.Item key={item.value} item={item}>
|
<Combobox.Item key={item.value} item={item}>
|
||||||
{item.label}
|
{item.label}
|
||||||
<Combobox.ItemIndicator />
|
<Combobox.ItemIndicator />
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import type { components } from "../../reflector-api";
|
import { UpdateTranscript } from "../../api";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
type UpdateTranscript = components["schemas"]["UpdateTranscript"];
|
|
||||||
import { useTranscriptUpdate } from "../../lib/apiHooks";
|
|
||||||
import { Heading, IconButton, Input, Flex, Spacer } from "@chakra-ui/react";
|
import { Heading, IconButton, Input, Flex, Spacer } from "@chakra-ui/react";
|
||||||
import { LuPen } from "react-icons/lu";
|
import { LuPen } from "react-icons/lu";
|
||||||
|
|
||||||
@@ -16,27 +14,24 @@ const TranscriptTitle = (props: TranscriptTitle) => {
|
|||||||
const [displayedTitle, setDisplayedTitle] = useState(props.title);
|
const [displayedTitle, setDisplayedTitle] = useState(props.title);
|
||||||
const [preEditTitle, setPreEditTitle] = useState(props.title);
|
const [preEditTitle, setPreEditTitle] = useState(props.title);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const updateTranscriptMutation = useTranscriptUpdate();
|
const api = useApi();
|
||||||
|
|
||||||
const updateTitle = async (newTitle: string, transcriptId: string) => {
|
const updateTitle = async (newTitle: string, transcriptId: string) => {
|
||||||
|
if (!api) return;
|
||||||
try {
|
try {
|
||||||
const requestBody: UpdateTranscript = {
|
const requestBody: UpdateTranscript = {
|
||||||
title: newTitle,
|
title: newTitle,
|
||||||
};
|
};
|
||||||
await updateTranscriptMutation.mutateAsync({
|
const updatedTranscript = await api?.v1TranscriptUpdate({
|
||||||
params: {
|
transcriptId,
|
||||||
path: { transcript_id: transcriptId },
|
requestBody,
|
||||||
},
|
|
||||||
body: requestBody,
|
|
||||||
});
|
});
|
||||||
if (props.onUpdate) {
|
if (props.onUpdate) {
|
||||||
props.onUpdate(newTitle);
|
props.onUpdate(newTitle);
|
||||||
}
|
}
|
||||||
console.log("Updated transcript title:", newTitle);
|
console.log("Updated transcript:", updatedTranscript);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to update transcript:", err);
|
console.error("Failed to update transcript:", err);
|
||||||
// Revert title on error
|
|
||||||
setDisplayedTitle(preEditTitle);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { useTranscriptGet } from "../../lib/apiHooks";
|
import { DomainContext } from "../../domainContext";
|
||||||
import { useAuth } from "../../lib/AuthProvider";
|
import getApi from "../../lib/useApi";
|
||||||
import { API_URL } from "../../lib/apiClient";
|
|
||||||
|
|
||||||
export type Mp3Response = {
|
export type Mp3Response = {
|
||||||
media: HTMLMediaElement | null;
|
media: HTMLMediaElement | null;
|
||||||
@@ -18,16 +17,14 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
const [audioLoadingError, setAudioLoadingError] = useState<null | string>(
|
const [audioLoadingError, setAudioLoadingError] = useState<null | string>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
const [transcriptMetadataLoading, setTranscriptMetadataLoading] =
|
||||||
|
useState<boolean>(true);
|
||||||
|
const [transcriptMetadataLoadingError, setTranscriptMetadataLoadingError] =
|
||||||
|
useState<string | null>(null);
|
||||||
const [audioDeleted, setAudioDeleted] = useState<boolean | null>(null);
|
const [audioDeleted, setAudioDeleted] = useState<boolean | null>(null);
|
||||||
const auth = useAuth();
|
const api = getApi();
|
||||||
const accessTokenInfo =
|
const { api_url } = useContext(DomainContext);
|
||||||
auth.status === "authenticated" ? auth.accessToken : null;
|
const accessTokenInfo = api?.httpRequest?.config?.TOKEN;
|
||||||
|
|
||||||
const {
|
|
||||||
data: transcript,
|
|
||||||
isLoading: transcriptMetadataLoading,
|
|
||||||
error: transcriptError,
|
|
||||||
} = useTranscriptGet(later ? null : transcriptId);
|
|
||||||
|
|
||||||
const [serviceWorker, setServiceWorker] =
|
const [serviceWorker, setServiceWorker] =
|
||||||
useState<ServiceWorkerRegistration | null>(null);
|
useState<ServiceWorkerRegistration | null>(null);
|
||||||
@@ -55,50 +52,72 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
|
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!transcriptId || later || !transcript) return;
|
if (!transcriptId || !api || later) return;
|
||||||
|
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
let audioElement: HTMLAudioElement | null = null;
|
let audioElement: HTMLAudioElement | null = null;
|
||||||
let handleCanPlay: (() => void) | null = null;
|
let handleCanPlay: (() => void) | null = null;
|
||||||
let handleError: (() => void) | null = null;
|
let handleError: (() => void) | null = null;
|
||||||
|
|
||||||
|
setTranscriptMetadataLoading(true);
|
||||||
setAudioLoading(true);
|
setAudioLoading(true);
|
||||||
|
|
||||||
const deleted = transcript.audio_deleted || false;
|
// First fetch transcript info to check if audio is deleted
|
||||||
setAudioDeleted(deleted);
|
api
|
||||||
|
.v1TranscriptGet({ transcriptId })
|
||||||
|
.then((transcript) => {
|
||||||
|
if (stopped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (deleted) {
|
const deleted = transcript.audio_deleted || false;
|
||||||
// Audio is deleted, don't attempt to load it
|
setAudioDeleted(deleted);
|
||||||
setMedia(null);
|
setTranscriptMetadataLoadingError(null);
|
||||||
setAudioLoadingError(null);
|
|
||||||
setAudioLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Audio is not deleted, proceed to load it
|
if (deleted) {
|
||||||
audioElement = document.createElement("audio");
|
// Audio is deleted, don't attempt to load it
|
||||||
audioElement.src = `${API_URL}/v1/transcripts/${transcriptId}/audio/mp3`;
|
setMedia(null);
|
||||||
audioElement.crossOrigin = "anonymous";
|
setAudioLoadingError(null);
|
||||||
audioElement.preload = "auto";
|
setAudioLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
handleCanPlay = () => {
|
// Audio is not deleted, proceed to load it
|
||||||
if (stopped) return;
|
audioElement = document.createElement("audio");
|
||||||
setAudioLoading(false);
|
audioElement.src = `${api_url}/v1/transcripts/${transcriptId}/audio/mp3`;
|
||||||
setAudioLoadingError(null);
|
audioElement.crossOrigin = "anonymous";
|
||||||
};
|
audioElement.preload = "auto";
|
||||||
|
|
||||||
handleError = () => {
|
handleCanPlay = () => {
|
||||||
if (stopped) return;
|
if (stopped) return;
|
||||||
setAudioLoading(false);
|
setAudioLoading(false);
|
||||||
setAudioLoadingError("Failed to load audio");
|
setAudioLoadingError(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
audioElement.addEventListener("canplay", handleCanPlay);
|
handleError = () => {
|
||||||
audioElement.addEventListener("error", handleError);
|
if (stopped) return;
|
||||||
|
setAudioLoading(false);
|
||||||
|
setAudioLoadingError("Failed to load audio");
|
||||||
|
};
|
||||||
|
|
||||||
if (!stopped) {
|
audioElement.addEventListener("canplay", handleCanPlay);
|
||||||
setMedia(audioElement);
|
audioElement.addEventListener("error", handleError);
|
||||||
}
|
|
||||||
|
if (!stopped) {
|
||||||
|
setMedia(audioElement);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (stopped) return;
|
||||||
|
console.error("Failed to fetch transcript:", error);
|
||||||
|
setAudioDeleted(null);
|
||||||
|
setTranscriptMetadataLoadingError(error.message);
|
||||||
|
setAudioLoading(false);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (stopped) return;
|
||||||
|
setTranscriptMetadataLoading(false);
|
||||||
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
stopped = true;
|
stopped = true;
|
||||||
@@ -109,18 +128,14 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
if (handleError) audioElement.removeEventListener("error", handleError);
|
if (handleError) audioElement.removeEventListener("error", handleError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [transcriptId, transcript, later]);
|
}, [transcriptId, api, later, api_url]);
|
||||||
|
|
||||||
const getNow = () => {
|
const getNow = () => {
|
||||||
setLater(false);
|
setLater(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loading = audioLoading || transcriptMetadataLoading;
|
const loading = audioLoading || transcriptMetadataLoading;
|
||||||
const error =
|
const error = audioLoadingError || transcriptMetadataLoadingError;
|
||||||
audioLoadingError ||
|
|
||||||
(transcriptError
|
|
||||||
? (transcriptError as any).message || String(transcriptError)
|
|
||||||
: null);
|
|
||||||
|
|
||||||
return { media, loading, error, getNow, audioDeleted };
|
return { media, loading, error, getNow, audioDeleted };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { components } from "../../reflector-api";
|
import { useEffect, useState } from "react";
|
||||||
type Participant = components["schemas"]["Participant"];
|
import { Participant } from "../../api";
|
||||||
import { useTranscriptParticipants } from "../../lib/apiHooks";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type ErrorParticipants = {
|
type ErrorParticipants = {
|
||||||
error: Error;
|
error: Error;
|
||||||
@@ -27,38 +29,46 @@ export type UseParticipants = (
|
|||||||
) & { refetch: () => void };
|
) & { refetch: () => void };
|
||||||
|
|
||||||
const useParticipants = (transcriptId: string): UseParticipants => {
|
const useParticipants = (transcriptId: string): UseParticipants => {
|
||||||
const {
|
const [response, setResponse] = useState<Participant[] | null>(null);
|
||||||
data: response,
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
isLoading: loading,
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
error,
|
const { setError } = useError();
|
||||||
refetch,
|
const api = useApi();
|
||||||
} = useTranscriptParticipants(transcriptId || null);
|
const [count, setCount] = useState(0);
|
||||||
|
|
||||||
// Type-safe return based on state
|
const refetch = () => {
|
||||||
if (error) {
|
if (!loading) {
|
||||||
return {
|
setCount(count + 1);
|
||||||
error: error as Error,
|
setLoading(true);
|
||||||
loading: false,
|
setErrorState(null);
|
||||||
response: null,
|
}
|
||||||
refetch,
|
};
|
||||||
} satisfies ErrorParticipants & { refetch: () => void };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loading || !response) {
|
useEffect(() => {
|
||||||
return {
|
if (!transcriptId || !api) return;
|
||||||
response: response || null,
|
|
||||||
loading: true,
|
|
||||||
error: null,
|
|
||||||
refetch,
|
|
||||||
} satisfies LoadingParticipants & { refetch: () => void };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
setLoading(true);
|
||||||
response,
|
api
|
||||||
loading: false,
|
.v1TranscriptGetParticipants({ transcriptId })
|
||||||
error: null,
|
.then((result) => {
|
||||||
refetch,
|
setResponse(result);
|
||||||
} satisfies SuccessParticipants & { refetch: () => void };
|
setLoading(false);
|
||||||
|
console.debug("Participants Loaded:", result);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const shouldShowHuman = shouldShowError(error);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(error, "There was an error loading the participants");
|
||||||
|
} else {
|
||||||
|
setError(error);
|
||||||
|
}
|
||||||
|
setErrorState(error);
|
||||||
|
setResponse(null);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
}, [transcriptId, !api, count]);
|
||||||
|
|
||||||
|
return { response, loading, error, refetch } as UseParticipants;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useParticipants;
|
export default useParticipants;
|
||||||
|
|||||||
123
www/app/(app)/transcripts/useSearchTranscripts.ts
Normal file
123
www/app/(app)/transcripts/useSearchTranscripts.ts
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
// this hook is not great, we want to substitute it with a proper state management solution that is also not re-invention
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { SearchResult, SourceKind } from "../../api";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
import {
|
||||||
|
PaginationPage,
|
||||||
|
paginationPageTo0Based,
|
||||||
|
} from "../browse/_components/Pagination";
|
||||||
|
|
||||||
|
interface SearchFilters {
|
||||||
|
roomIds: readonly string[] | null;
|
||||||
|
sourceKind: SourceKind | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EMPTY_SEARCH_FILTERS: SearchFilters = {
|
||||||
|
roomIds: null,
|
||||||
|
sourceKind: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
type UseSearchTranscriptsOptions = {
|
||||||
|
pageSize: number;
|
||||||
|
page: PaginationPage;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface UseSearchTranscriptsReturn {
|
||||||
|
results: SearchResult[];
|
||||||
|
totalCount: number;
|
||||||
|
isLoading: boolean;
|
||||||
|
error: unknown;
|
||||||
|
reload: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashEffectFilters(filters: SearchFilters): string {
|
||||||
|
return JSON.stringify(filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSearchTranscripts(
|
||||||
|
query: string = "",
|
||||||
|
filters: SearchFilters = EMPTY_SEARCH_FILTERS,
|
||||||
|
options: UseSearchTranscriptsOptions = {
|
||||||
|
pageSize: 20,
|
||||||
|
page: PaginationPage(1),
|
||||||
|
},
|
||||||
|
): UseSearchTranscriptsReturn {
|
||||||
|
const { pageSize, page } = options;
|
||||||
|
|
||||||
|
const [reloadCount, setReloadCount] = useState(0);
|
||||||
|
|
||||||
|
const api = useApi();
|
||||||
|
const abortControllerRef = useRef<AbortController>();
|
||||||
|
|
||||||
|
const [data, setData] = useState<{ results: SearchResult[]; total: number }>({
|
||||||
|
results: [],
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const [error, setError] = useState<any>();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const filterHash = hashEffectFilters(filters);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!api) {
|
||||||
|
setData({ results: [], total: 0 });
|
||||||
|
setError(undefined);
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
const abortController = new AbortController();
|
||||||
|
abortControllerRef.current = abortController;
|
||||||
|
|
||||||
|
const performSearch = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await api.v1TranscriptsSearch({
|
||||||
|
q: query || "",
|
||||||
|
limit: pageSize,
|
||||||
|
offset: paginationPageTo0Based(page) * pageSize,
|
||||||
|
roomId: filters.roomIds?.[0],
|
||||||
|
sourceKind: filters.sourceKind || undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (abortController.signal.aborted) return;
|
||||||
|
setData(response);
|
||||||
|
setError(undefined);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
if ((err as Error).name === "AbortError") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (abortController.signal.aborted) {
|
||||||
|
console.error("Aborted search but error", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
if (!abortController.signal.aborted) {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
performSearch().then(() => {});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
abortController.abort();
|
||||||
|
};
|
||||||
|
}, [api, query, page, filterHash, pageSize, reloadCount]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
results: data.results,
|
||||||
|
totalCount: data.total,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
reload: () => setReloadCount(reloadCount + 1),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import type { components } from "../../reflector-api";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranscriptTopicsWithWordsPerSpeaker } from "../../lib/apiHooks";
|
|
||||||
|
|
||||||
type GetTranscriptTopicWithWordsPerSpeaker =
|
import { GetTranscriptTopicWithWordsPerSpeaker } from "../../api";
|
||||||
components["schemas"]["GetTranscriptTopicWithWordsPerSpeaker"];
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type ErrorTopicWithWords = {
|
type ErrorTopicWithWords = {
|
||||||
error: Error;
|
error: Error;
|
||||||
@@ -32,40 +33,47 @@ const useTopicWithWords = (
|
|||||||
topicId: string | undefined,
|
topicId: string | undefined,
|
||||||
transcriptId: string,
|
transcriptId: string,
|
||||||
): UseTopicWithWords => {
|
): UseTopicWithWords => {
|
||||||
const {
|
const [response, setResponse] =
|
||||||
data: response,
|
useState<GetTranscriptTopicWithWordsPerSpeaker | null>(null);
|
||||||
isLoading: loading,
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
error,
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
refetch,
|
const { setError } = useError();
|
||||||
} = useTranscriptTopicsWithWordsPerSpeaker(
|
const api = useApi();
|
||||||
transcriptId || null,
|
|
||||||
topicId || null,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
const [count, setCount] = useState(0);
|
||||||
return {
|
|
||||||
error: error as Error,
|
|
||||||
loading: false,
|
|
||||||
response: null,
|
|
||||||
refetch,
|
|
||||||
} satisfies ErrorTopicWithWords & { refetch: () => void };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loading || !response) {
|
const refetch = () => {
|
||||||
return {
|
if (!loading) {
|
||||||
response: response || null,
|
setCount(count + 1);
|
||||||
loading: true,
|
setLoading(true);
|
||||||
error: false,
|
setErrorState(null);
|
||||||
refetch,
|
}
|
||||||
} satisfies LoadingTopicWithWords & { refetch: () => void };
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
useEffect(() => {
|
||||||
response,
|
if (!transcriptId || !topicId || !api) return;
|
||||||
loading: false,
|
|
||||||
error: null,
|
setLoading(true);
|
||||||
refetch,
|
|
||||||
} satisfies SuccessTopicWithWords & { refetch: () => void };
|
api
|
||||||
|
.v1TranscriptGetTopicsWithWordsPerSpeaker({ transcriptId, topicId })
|
||||||
|
.then((result) => {
|
||||||
|
setResponse(result);
|
||||||
|
setLoading(false);
|
||||||
|
console.debug("Topics with words Loaded:", result);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const shouldShowHuman = shouldShowError(error);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(error, "There was an error loading the topics with words");
|
||||||
|
} else {
|
||||||
|
setError(error);
|
||||||
|
}
|
||||||
|
setErrorState(error);
|
||||||
|
});
|
||||||
|
}, [transcriptId, !api, topicId, count]);
|
||||||
|
|
||||||
|
return { response, loading, error, refetch } as UseTopicWithWords;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useTopicWithWords;
|
export default useTopicWithWords;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { useTranscriptTopics } from "../../lib/apiHooks";
|
import { useEffect, useState } from "react";
|
||||||
import type { components } from "../../reflector-api";
|
|
||||||
|
|
||||||
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import { Topic } from "./webSocketTypes";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
import { GetTranscriptTopic } from "../../api";
|
||||||
|
|
||||||
type TranscriptTopics = {
|
type TranscriptTopics = {
|
||||||
topics: GetTranscriptTopic[] | null;
|
topics: GetTranscriptTopic[] | null;
|
||||||
@@ -10,13 +13,34 @@ type TranscriptTopics = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useTopics = (id: string): TranscriptTopics => {
|
const useTopics = (id: string): TranscriptTopics => {
|
||||||
const { data: topics, isLoading: loading, error } = useTranscriptTopics(id);
|
const [topics, setTopics] = useState<Topic[] | null>(null);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
|
const { setError } = useError();
|
||||||
|
const api = useApi();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id || !api) return;
|
||||||
|
|
||||||
return {
|
setLoading(true);
|
||||||
topics: topics || null,
|
api
|
||||||
loading,
|
.v1TranscriptGetTopics({ transcriptId: id })
|
||||||
error: error as Error | null,
|
.then((result) => {
|
||||||
};
|
setTopics(result);
|
||||||
|
setLoading(false);
|
||||||
|
console.debug("Transcript topics loaded:", result);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setErrorState(err);
|
||||||
|
const shouldShowHuman = shouldShowError(err);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(err, "There was an error loading the topics");
|
||||||
|
} else {
|
||||||
|
setError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [id, !api]);
|
||||||
|
|
||||||
|
return { topics, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useTopics;
|
export default useTopics;
|
||||||
|
|||||||
70
www/app/(app)/transcripts/useTranscript.ts
Normal file
70
www/app/(app)/transcripts/useTranscript.ts
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { GetTranscript } from "../../api";
|
||||||
|
import { useError } from "../../(errors)/errorContext";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
import useApi from "../../lib/useApi";
|
||||||
|
|
||||||
|
type ErrorTranscript = {
|
||||||
|
error: Error;
|
||||||
|
loading: false;
|
||||||
|
response: null;
|
||||||
|
reload: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type LoadingTranscript = {
|
||||||
|
response: null;
|
||||||
|
loading: true;
|
||||||
|
error: false;
|
||||||
|
reload: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SuccessTranscript = {
|
||||||
|
response: GetTranscript;
|
||||||
|
loading: false;
|
||||||
|
error: null;
|
||||||
|
reload: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const useTranscript = (
|
||||||
|
id: string | null,
|
||||||
|
): ErrorTranscript | LoadingTranscript | SuccessTranscript => {
|
||||||
|
const [response, setResponse] = useState<GetTranscript | null>(null);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
|
const [reload, setReload] = useState(0);
|
||||||
|
const { setError } = useError();
|
||||||
|
const api = useApi();
|
||||||
|
const reloadHandler = () => setReload((prev) => prev + 1);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!id || !api) return;
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
setLoading(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
api
|
||||||
|
.v1TranscriptGet({ transcriptId: id })
|
||||||
|
.then((result) => {
|
||||||
|
setResponse(result);
|
||||||
|
setLoading(false);
|
||||||
|
console.debug("Transcript Loaded:", result);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const shouldShowHuman = shouldShowError(error);
|
||||||
|
if (shouldShowHuman) {
|
||||||
|
setError(error, "There was an error loading the transcript");
|
||||||
|
} else {
|
||||||
|
setError(error);
|
||||||
|
}
|
||||||
|
setErrorState(error);
|
||||||
|
});
|
||||||
|
}, [id, !api, reload]);
|
||||||
|
|
||||||
|
return { response, loading, error, reload: reloadHandler } as
|
||||||
|
| ErrorTranscript
|
||||||
|
| LoadingTranscript
|
||||||
|
| SuccessTranscript;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useTranscript;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import type { components } from "../../reflector-api";
|
import { useEffect, useState } from "react";
|
||||||
import { useTranscriptWaveform } from "../../lib/apiHooks";
|
import { AudioWaveform } from "../../api";
|
||||||
|
import { useError } from "../../(errors)/errorContext";
|
||||||
type AudioWaveform = components["schemas"]["AudioWaveform"];
|
import useApi from "../../lib/useApi";
|
||||||
|
import { shouldShowError } from "../../lib/errorUtils";
|
||||||
|
|
||||||
type AudioWaveFormResponse = {
|
type AudioWaveFormResponse = {
|
||||||
waveform: AudioWaveform | null;
|
waveform: AudioWaveform | null;
|
||||||
@@ -10,17 +11,35 @@ type AudioWaveFormResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useWaveform = (id: string, skip: boolean): AudioWaveFormResponse => {
|
const useWaveform = (id: string, skip: boolean): AudioWaveFormResponse => {
|
||||||
const {
|
const [waveform, setWaveform] = useState<AudioWaveform | null>(null);
|
||||||
data: waveform,
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
isLoading: loading,
|
const [error, setErrorState] = useState<Error | null>(null);
|
||||||
error,
|
const { setError } = useError();
|
||||||
} = useTranscriptWaveform(skip ? null : id);
|
const api = useApi();
|
||||||
|
|
||||||
return {
|
useEffect(() => {
|
||||||
waveform: waveform || null,
|
if (!id || !api || skip) {
|
||||||
loading,
|
setLoading(false);
|
||||||
error: error as Error | null,
|
setErrorState(null);
|
||||||
};
|
setWaveform(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoading(true);
|
||||||
|
setErrorState(null);
|
||||||
|
api
|
||||||
|
.v1TranscriptGetAudioWaveform({ transcriptId: id })
|
||||||
|
.then((result) => {
|
||||||
|
setWaveform(result);
|
||||||
|
setLoading(false);
|
||||||
|
console.debug("Transcript waveform loaded:", result);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
setErrorState(err);
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
}, [id, api, skip]);
|
||||||
|
|
||||||
|
return { waveform, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useWaveform;
|
export default useWaveform;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Peer from "simple-peer";
|
import Peer from "simple-peer";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import { useTranscriptWebRTC } from "../../lib/apiHooks";
|
import useApi from "../../lib/useApi";
|
||||||
import type { components } from "../../reflector-api";
|
import { RtcOffer } from "../../api";
|
||||||
type RtcOffer = components["schemas"]["RtcOffer"];
|
|
||||||
|
|
||||||
const useWebRTC = (
|
const useWebRTC = (
|
||||||
stream: MediaStream | null,
|
stream: MediaStream | null,
|
||||||
@@ -11,10 +10,10 @@ const useWebRTC = (
|
|||||||
): Peer => {
|
): Peer => {
|
||||||
const [peer, setPeer] = useState<Peer | null>(null);
|
const [peer, setPeer] = useState<Peer | null>(null);
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const { mutateAsync: mutateWebRtcTranscriptAsync } = useTranscriptWebRTC();
|
const api = useApi();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!stream || !transcriptId) {
|
if (!stream || !transcriptId || !api) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ const useWebRTC = (
|
|||||||
try {
|
try {
|
||||||
p = new Peer({ initiator: true, stream: stream });
|
p = new Peer({ initiator: true, stream: stream });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error as Error, "Error creating WebRTC");
|
setError(error, "Error creating WebRTC");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,31 +32,26 @@ const useWebRTC = (
|
|||||||
setError(new Error(`WebRTC error: ${err}`));
|
setError(new Error(`WebRTC error: ${err}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
p.on("signal", async (data: any) => {
|
p.on("signal", (data: any) => {
|
||||||
|
if (!api) return;
|
||||||
if ("sdp" in data) {
|
if ("sdp" in data) {
|
||||||
const rtcOffer: RtcOffer = {
|
const rtcOffer: RtcOffer = {
|
||||||
sdp: data.sdp,
|
sdp: data.sdp,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
api
|
||||||
const answer = await mutateWebRtcTranscriptAsync({
|
.v1TranscriptRecordWebrtc({ transcriptId, requestBody: rtcOffer })
|
||||||
params: {
|
.then((answer) => {
|
||||||
path: {
|
try {
|
||||||
transcript_id: transcriptId,
|
p.signal(answer);
|
||||||
},
|
} catch (error) {
|
||||||
},
|
setError(error);
|
||||||
body: rtcOffer,
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setError(error, "Error loading WebRTCOffer");
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
p.signal(answer);
|
|
||||||
} catch (error) {
|
|
||||||
setError(error as Error);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
setError(error as Error, "Error loading WebRTCOffer");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,7 +63,7 @@ const useWebRTC = (
|
|||||||
return () => {
|
return () => {
|
||||||
p.destroy();
|
p.destroy();
|
||||||
};
|
};
|
||||||
}, [stream, transcriptId, mutateWebRtcTranscriptAsync]);
|
}, [stream, transcriptId, !api]);
|
||||||
|
|
||||||
return peer;
|
return peer;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { Topic, FinalSummary, Status } from "./webSocketTypes";
|
import { Topic, FinalSummary, Status } from "./webSocketTypes";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useError } from "../../(errors)/errorContext";
|
||||||
import type { components } from "../../reflector-api";
|
import { DomainContext } from "../../domainContext";
|
||||||
type AudioWaveform = components["schemas"]["AudioWaveform"];
|
import { AudioWaveform, GetTranscriptSegmentTopic } from "../../api";
|
||||||
type GetTranscriptSegmentTopic =
|
import useApi from "../../lib/useApi";
|
||||||
components["schemas"]["GetTranscriptSegmentTopic"];
|
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
|
||||||
import { $api, WEBSOCKET_URL } from "../../lib/apiClient";
|
|
||||||
|
|
||||||
export type UseWebSockets = {
|
export type UseWebSockets = {
|
||||||
transcriptTextLive: string;
|
transcriptTextLive: string;
|
||||||
@@ -15,7 +12,7 @@ export type UseWebSockets = {
|
|||||||
title: string;
|
title: string;
|
||||||
topics: Topic[];
|
topics: Topic[];
|
||||||
finalSummary: FinalSummary;
|
finalSummary: FinalSummary;
|
||||||
status: Status | null;
|
status: Status;
|
||||||
waveform: AudioWaveform | null;
|
waveform: AudioWaveform | null;
|
||||||
duration: number | null;
|
duration: number | null;
|
||||||
};
|
};
|
||||||
@@ -33,10 +30,11 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
||||||
summary: "",
|
summary: "",
|
||||||
});
|
});
|
||||||
const [status, setStatus] = useState<Status | null>(null);
|
const [status, setStatus] = useState<Status>({ value: "" });
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const { websocket_url } = useContext(DomainContext);
|
||||||
|
const api = useApi();
|
||||||
|
|
||||||
const [accumulatedText, setAccumulatedText] = useState<string>("");
|
const [accumulatedText, setAccumulatedText] = useState<string>("");
|
||||||
|
|
||||||
@@ -107,13 +105,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
title: "Topic 1: Introduction to Quantum Mechanics",
|
title: "Topic 1: Introduction to Quantum Mechanics",
|
||||||
transcript:
|
transcript:
|
||||||
"A brief overview of quantum mechanics and its principles.",
|
"A brief overview of quantum mechanics and its principles.",
|
||||||
segments: [
|
|
||||||
{
|
|
||||||
speaker: 1,
|
|
||||||
start: 0,
|
|
||||||
text: "This is the transcription of an example title",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "2",
|
id: "2",
|
||||||
@@ -324,9 +315,11 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!transcriptId) return;
|
if (!transcriptId || !api) return;
|
||||||
|
|
||||||
const url = `${WEBSOCKET_URL}/v1/transcripts/${transcriptId}/events`;
|
api?.v1TranscriptGetWebsocketEvents({ transcriptId }).then((result) => {});
|
||||||
|
|
||||||
|
const url = `${websocket_url}/v1/transcripts/${transcriptId}/events`;
|
||||||
let ws = new WebSocket(url);
|
let ws = new WebSocket(url);
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
@@ -368,16 +361,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
return [...prevTopics, topic];
|
return [...prevTopics, topic];
|
||||||
});
|
});
|
||||||
console.debug("TOPIC event:", message.data);
|
console.debug("TOPIC event:", message.data);
|
||||||
// Invalidate topics query to sync with WebSocket data
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: $api.queryOptions(
|
|
||||||
"get",
|
|
||||||
"/v1/transcripts/{transcript_id}/topics",
|
|
||||||
{
|
|
||||||
params: { path: { transcript_id: transcriptId } },
|
|
||||||
},
|
|
||||||
).queryKey,
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "FINAL_SHORT_SUMMARY":
|
case "FINAL_SHORT_SUMMARY":
|
||||||
@@ -387,16 +370,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
case "FINAL_LONG_SUMMARY":
|
case "FINAL_LONG_SUMMARY":
|
||||||
if (message.data) {
|
if (message.data) {
|
||||||
setFinalSummary(message.data);
|
setFinalSummary(message.data);
|
||||||
// Invalidate transcript query to sync summary
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: $api.queryOptions(
|
|
||||||
"get",
|
|
||||||
"/v1/transcripts/{transcript_id}",
|
|
||||||
{
|
|
||||||
params: { path: { transcript_id: transcriptId } },
|
|
||||||
},
|
|
||||||
).queryKey,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -404,16 +377,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
console.debug("FINAL_TITLE event:", message.data);
|
console.debug("FINAL_TITLE event:", message.data);
|
||||||
if (message.data) {
|
if (message.data) {
|
||||||
setTitle(message.data.title);
|
setTitle(message.data.title);
|
||||||
// Invalidate transcript query to sync title
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: $api.queryOptions(
|
|
||||||
"get",
|
|
||||||
"/v1/transcripts/{transcript_id}",
|
|
||||||
{
|
|
||||||
params: { path: { transcript_id: transcriptId } },
|
|
||||||
},
|
|
||||||
).queryKey,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -471,11 +434,6 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
break;
|
break;
|
||||||
case 1001: // Navigate away
|
case 1001: // Navigate away
|
||||||
break;
|
break;
|
||||||
case 1006: // Closed by client Chrome
|
|
||||||
console.warn(
|
|
||||||
"WebSocket closed by client, likely duplicated connection in react dev mode",
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
setError(
|
setError(
|
||||||
new Error(`WebSocket closed unexpectedly with code: ${event.code}`),
|
new Error(`WebSocket closed unexpectedly with code: ${event.code}`),
|
||||||
@@ -492,7 +450,7 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
return () => {
|
return () => {
|
||||||
ws.close();
|
ws.close();
|
||||||
};
|
};
|
||||||
}, [transcriptId]);
|
}, [transcriptId, !api]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
transcriptTextLive,
|
transcriptTextLive,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user