mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 20:59:05 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ce7479967 | |||
| b42f7cfc60 | |||
| c546e69739 | |||
|
|
3f1fe8c9bf | ||
| 5f143fe364 | |||
|
|
79f161436e | ||
|
|
5cba5d310d | ||
| 43ea9349f5 | |||
|
|
b3a8e9739d | ||
|
|
369ecdff13 | ||
| fc363bd49b | |||
|
|
962038ee3f | ||
|
|
3b85ff3bdf | ||
|
|
cde99ca271 | ||
|
|
f81fe9948a | ||
|
|
5a5b323382 | ||
| 02a3938822 | |||
|
|
7f5a4c9ddc | ||
|
|
08d88ec349 | ||
|
|
c4d2825c81 | ||
| 0663700a61 | |||
| dc82f8bb3b | |||
| 457823e1c1 | |||
|
|
695d1a957d | ||
| ccffdba75b | |||
| 84a381220b |
45
.github/workflows/test_next_server.yml
vendored
Normal file
45
.github/workflows/test_next_server.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
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
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ server/test.sqlite
|
|||||||
CLAUDE.local.md
|
CLAUDE.local.md
|
||||||
www/.env.development
|
www/.env.development
|
||||||
www/.env.production
|
www/.env.production
|
||||||
|
.playwright-mcp
|
||||||
|
|||||||
59
CHANGELOG.md
59
CHANGELOG.md
@@ -1,5 +1,64 @@
|
|||||||
# 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)
|
## [0.8.0](https://github.com/Monadical-SAS/reflector/compare/v0.7.3...v0.8.0) (2025-08-29)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ pnpm install
|
|||||||
|
|
||||||
# Copy configuration templates
|
# Copy configuration templates
|
||||||
cp .env_template .env
|
cp .env_template .env
|
||||||
cp config-template.ts config.ts
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Development:**
|
**Development:**
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -99,11 +99,10 @@ Start with `cd www`.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm install
|
pnpm install
|
||||||
cp .env_template .env
|
cp .env.example .env
|
||||||
cp config-template.ts config.ts
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
Then, fill in the environment variables in `.env` as needed. If you are unsure on how to proceed, ask in Zulip.
|
||||||
|
|
||||||
**Run in development mode**
|
**Run in development mode**
|
||||||
|
|
||||||
@@ -168,3 +167,34 @@ 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,6 +6,7 @@ services:
|
|||||||
- 1250:1250
|
- 1250:1250
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
|
- /app/.venv
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
@@ -16,6 +17,7 @@ services:
|
|||||||
context: server
|
context: server
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
|
- /app/.venv
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
@@ -26,6 +28,7 @@ services:
|
|||||||
context: server
|
context: server
|
||||||
volumes:
|
volumes:
|
||||||
- ./server/:/app/
|
- ./server/:/app/
|
||||||
|
- /app/.venv
|
||||||
env_file:
|
env_file:
|
||||||
- ./server/.env
|
- ./server/.env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
194
server/docs/gpu/api-transcription.md
Normal file
194
server/docs/gpu/api-transcription.md
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
## 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,41 +1,78 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import sys
|
||||||
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
|
||||||
|
|
||||||
volume.reload()
|
model_cache.reload()
|
||||||
|
|
||||||
download_model(MODEL_NAME, cache_dir=MODELS_DIR)
|
download_model(MODEL_NAME, cache_dir=CACHE_PATH)
|
||||||
|
|
||||||
volume.commit()
|
model_cache.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",
|
||||||
@@ -45,19 +82,98 @@ image = (
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.run_function(download_model, volumes={MODELS_DIR: volume})
|
.apt_install("ffmpeg")
|
||||||
|
.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={MODELS_DIR: volume},
|
volumes={CACHE_PATH: model_cache, UPLOADS_PATH: upload_volume},
|
||||||
)
|
)
|
||||||
class Transcriber:
|
@modal.concurrent(max_inputs=10)
|
||||||
|
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
|
||||||
@@ -71,23 +187,28 @@ class Transcriber:
|
|||||||
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=MODELS_DIR,
|
download_root=CACHE_PATH,
|
||||||
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,
|
||||||
audio_data: str,
|
filename: str,
|
||||||
audio_suffix: str,
|
language: str = "en",
|
||||||
language: str,
|
|
||||||
):
|
):
|
||||||
with tempfile.NamedTemporaryFile("wb+", suffix=f".{audio_suffix}") as fp:
|
"""Transcribe a single uploaded audio file by filename."""
|
||||||
fp.write(audio_data)
|
upload_volume.reload()
|
||||||
|
|
||||||
|
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 self.lock:
|
||||||
|
with NoStdStreams():
|
||||||
segments, _ = self.model.transcribe(
|
segments, _ = self.model.transcribe(
|
||||||
fp.name,
|
file_path,
|
||||||
language=language,
|
language=language,
|
||||||
beam_size=5,
|
beam_size=5,
|
||||||
word_timestamps=True,
|
word_timestamps=True,
|
||||||
@@ -96,66 +217,392 @@ class Transcriber:
|
|||||||
)
|
)
|
||||||
|
|
||||||
segments = list(segments)
|
segments = list(segments)
|
||||||
text = "".join(segment.text for segment in segments)
|
text = "".join(segment.text for segment in segments).strip()
|
||||||
words = [
|
words = [
|
||||||
{"word": word.word, "start": word.start, "end": word.end}
|
{
|
||||||
|
"word": word.word,
|
||||||
|
"start": round(float(word.start), 2),
|
||||||
|
"end": round(float(word.end), 2),
|
||||||
|
}
|
||||||
for segment in segments
|
for segment in segments
|
||||||
for word in segment.words
|
for word in segment.words
|
||||||
]
|
]
|
||||||
|
|
||||||
return {"text": text, "words": 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:
|
||||||
|
segments, _ = self.model.transcribe(
|
||||||
|
segment,
|
||||||
|
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) + start_time + timestamp_offset, 2),
|
||||||
|
"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}
|
||||||
|
|
||||||
|
|
||||||
|
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=60,
|
timeout=600,
|
||||||
allow_concurrent_inputs=40,
|
|
||||||
secrets=[
|
secrets=[
|
||||||
modal.Secret.from_name("reflector-gpu"),
|
modal.Secret.from_name("reflector-gpu"),
|
||||||
],
|
],
|
||||||
volumes={MODELS_DIR: volume},
|
volumes={CACHE_PATH: model_cache, UPLOADS_PATH: upload_volume},
|
||||||
|
image=image,
|
||||||
)
|
)
|
||||||
|
@modal.concurrent(max_inputs=40)
|
||||||
@modal.asgi_app()
|
@modal.asgi_app()
|
||||||
def web():
|
def web():
|
||||||
from fastapi import Body, Depends, FastAPI, HTTPException, UploadFile, status
|
from fastapi import (
|
||||||
|
Body,
|
||||||
|
Depends,
|
||||||
|
FastAPI,
|
||||||
|
Form,
|
||||||
|
HTTPException,
|
||||||
|
UploadFile,
|
||||||
|
status,
|
||||||
|
)
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
transcriber = Transcriber()
|
transcriber_live = TranscriberWhisperLive()
|
||||||
|
transcriber_file = TranscriberWhisperFile()
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
|
|
||||||
supported_file_types = ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"]
|
|
||||||
|
|
||||||
def apikey_auth(apikey: str = Depends(oauth2_scheme)):
|
def apikey_auth(apikey: str = Depends(oauth2_scheme)):
|
||||||
if apikey != os.environ["REFLECTOR_GPU_APIKEY"]:
|
if apikey == os.environ["REFLECTOR_GPU_APIKEY"]:
|
||||||
|
return
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Invalid API key",
|
detail="Invalid API key",
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
|
|
||||||
class TranscriptResponse(BaseModel):
|
class TranscriptResponse(dict):
|
||||||
result: dict
|
pass
|
||||||
|
|
||||||
@app.post("/v1/audio/transcriptions", dependencies=[Depends(apikey_auth)])
|
@app.post("/v1/audio/transcriptions", dependencies=[Depends(apikey_auth)])
|
||||||
def transcribe(
|
def transcribe(
|
||||||
file: UploadFile,
|
file: UploadFile = None,
|
||||||
model: str = "whisper-1",
|
files: list[UploadFile] | None = None,
|
||||||
language: Annotated[str, Body(...)] = "en",
|
model: str = Form(MODEL_NAME),
|
||||||
) -> TranscriptResponse:
|
language: str = Form("en"),
|
||||||
audio_data = file.file.read()
|
batch: bool = Form(False),
|
||||||
audio_suffix = file.filename.split(".")[-1]
|
):
|
||||||
assert audio_suffix in supported_file_types
|
if not file and not files:
|
||||||
|
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'"
|
||||||
|
)
|
||||||
|
|
||||||
func = transcriber.transcribe_segment.spawn(
|
upload_files = [file] if file else files
|
||||||
audio_data=audio_data,
|
|
||||||
audio_suffix=audio_suffix,
|
uploaded_filenames: list[str] = []
|
||||||
|
for upload_file in upload_files:
|
||||||
|
audio_suffix = upload_file.filename.split(".")[-1]
|
||||||
|
if audio_suffix not in SUPPORTED_FILE_EXTENSIONS:
|
||||||
|
raise HTTPException(
|
||||||
|
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,
|
language=language,
|
||||||
)
|
)
|
||||||
result = func.get()
|
result = func.get()
|
||||||
return result
|
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()
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
"""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 ###
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
"""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
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"""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 ###
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
"""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 ###
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
"""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,7 +27,6 @@ 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",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ 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
|
||||||
@@ -18,8 +17,12 @@ 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("user_id", sa.String),
|
sa.Column(
|
||||||
sa.Column("room_id", sa.String),
|
"room_id",
|
||||||
|
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"),
|
||||||
@@ -81,8 +84,7 @@ class Meeting(BaseModel):
|
|||||||
host_room_url: str
|
host_room_url: str
|
||||||
start_date: datetime
|
start_date: datetime
|
||||||
end_date: datetime
|
end_date: datetime
|
||||||
user_id: str | None = None
|
room_id: str | 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"
|
||||||
@@ -101,12 +103,8 @@ 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,
|
||||||
@@ -114,7 +112,6 @@ 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,
|
||||||
@@ -126,19 +123,13 @@ 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:
|
) -> Meeting | None:
|
||||||
"""
|
|
||||||
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:
|
||||||
@@ -146,10 +137,7 @@ class MeetingController:
|
|||||||
|
|
||||||
return Meeting(**result)
|
return Meeting(**result)
|
||||||
|
|
||||||
async def get_active(self, room: Room, current_time: datetime) -> Meeting:
|
async def get_active(self, room: Room, current_time: datetime) -> Meeting | None:
|
||||||
"""
|
|
||||||
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()
|
||||||
@@ -169,32 +157,12 @@ 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)
|
||||||
@@ -219,7 +187,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) if result else None
|
return MeetingConsent(**result)
|
||||||
|
|
||||||
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"""
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ 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),
|
sqlalchemy.Column("webhook_url", sqlalchemy.String, nullable=True),
|
||||||
sqlalchemy.Column("webhook_secret", sqlalchemy.String),
|
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 +62,8 @@ 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 = ""
|
webhook_url: str | None = None
|
||||||
webhook_secret: str = ""
|
webhook_secret: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class RoomController:
|
class RoomController:
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ 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,
|
||||||
@@ -21,9 +23,10 @@ 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, transcripts
|
from reflector.db.transcripts import SourceKind, TranscriptStatus, 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
|
||||||
@@ -31,12 +34,13 @@ 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=0, strip_whitespace=True)
|
SearchQueryBase = constr(min_length=1, 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")
|
||||||
@@ -88,7 +92,7 @@ class WebVTTProcessor:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_snippets(
|
def generate_snippets(
|
||||||
webvtt_content: WebVTTContent,
|
webvtt_content: WebVTTContent,
|
||||||
query: str,
|
query: SearchQuery,
|
||||||
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."""
|
||||||
@@ -125,7 +129,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
|
query_text: SearchQuery | None = None
|
||||||
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
|
||||||
@@ -157,7 +161,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: str = Field(..., min_length=1)
|
status: TranscriptStatus = 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(
|
||||||
@@ -199,15 +203,13 @@ class SnippetGenerator:
|
|||||||
prev_start = start
|
prev_start = start
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def count_matches(text: str, query: str) -> NonNegativeInt:
|
def count_matches(text: str, query: SearchQuery) -> 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
|
||||||
if not query:
|
assert query is not None
|
||||||
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))
|
||||||
)
|
)
|
||||||
@@ -243,13 +245,14 @@ class SnippetGenerator:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def generate(
|
def generate(
|
||||||
text: str,
|
text: str,
|
||||||
query: str,
|
query: SearchQuery,
|
||||||
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."""
|
||||||
if not text or not query:
|
assert query is not None
|
||||||
logger.warning("Empty text or query for generate_snippets")
|
if not text:
|
||||||
|
logger.warning("Empty text for generate_snippets")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
candidates = (
|
candidates = (
|
||||||
@@ -270,7 +273,7 @@ class SnippetGenerator:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def from_summary(
|
def from_summary(
|
||||||
summary: str,
|
summary: str,
|
||||||
query: str,
|
query: SearchQuery,
|
||||||
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."""
|
||||||
@@ -278,9 +281,9 @@ class SnippetGenerator:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def combine_sources(
|
def combine_sources(
|
||||||
summary: str | None,
|
summary: NonEmptyString | None,
|
||||||
webvtt: WebVTTContent | None,
|
webvtt: WebVTTContent | None,
|
||||||
query: str,
|
query: SearchQuery,
|
||||||
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.
|
||||||
@@ -289,6 +292,11 @@ 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
|
||||||
|
|
||||||
@@ -355,8 +363,8 @@ class SearchController:
|
|||||||
else_=rooms.c.name,
|
else_=rooms.c.name,
|
||||||
).label("room_name"),
|
).label("room_name"),
|
||||||
]
|
]
|
||||||
|
search_query = None
|
||||||
if params.query_text:
|
if params.query_text is not None:
|
||||||
search_query = sqlalchemy.func.websearch_to_tsquery(
|
search_query = sqlalchemy.func.websearch_to_tsquery(
|
||||||
"english", params.query_text
|
"english", params.query_text
|
||||||
)
|
)
|
||||||
@@ -373,7 +381,9 @@ 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:
|
if params.query_text is not None:
|
||||||
|
# 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)
|
||||||
)
|
)
|
||||||
@@ -393,7 +403,7 @@ class SearchController:
|
|||||||
transcripts.c.source_kind == params.source_kind
|
transcripts.c.source_kind == params.source_kind
|
||||||
)
|
)
|
||||||
|
|
||||||
if params.query_text:
|
if params.query_text is not None:
|
||||||
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)
|
||||||
@@ -407,20 +417,30 @@ class SearchController:
|
|||||||
)
|
)
|
||||||
total = await get_database().fetch_val(count_query)
|
total = await get_database().fetch_val(count_query)
|
||||||
|
|
||||||
def _process_result(r) -> SearchResult:
|
def _process_result(r: DbRecord) -> 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)
|
||||||
|
|
||||||
snippets, total_match_count = SnippetGenerator.combine_sources(
|
at_least_one_source = webvtt is not None or long_summary is not None
|
||||||
|
has_query = params.query_text is not None
|
||||||
|
snippets, total_match_count = (
|
||||||
|
SnippetGenerator.combine_sources(
|
||||||
long_summary, webvtt, params.query_text, DEFAULT_MAX_SNIPPETS
|
long_summary, webvtt, params.query_text, DEFAULT_MAX_SNIPPETS
|
||||||
)
|
)
|
||||||
|
if has_query and at_least_one_source
|
||||||
|
else ([], 0)
|
||||||
|
)
|
||||||
|
|
||||||
return SearchResult(
|
return SearchResult(
|
||||||
**db_result.model_dump(),
|
**db_result.model_dump(),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import av
|
import av
|
||||||
import structlog
|
import structlog
|
||||||
from celery import shared_task
|
from celery import chain, shared_task
|
||||||
|
|
||||||
from reflector.asynctask import asynctask
|
from reflector.asynctask import asynctask
|
||||||
from reflector.db.rooms import rooms_controller
|
from reflector.db.rooms import rooms_controller
|
||||||
@@ -26,6 +26,8 @@ from reflector.logger import logger
|
|||||||
from reflector.pipelines.main_live_pipeline import (
|
from reflector.pipelines.main_live_pipeline import (
|
||||||
PipelineMainBase,
|
PipelineMainBase,
|
||||||
broadcast_to_sockets,
|
broadcast_to_sockets,
|
||||||
|
task_cleanup_consent,
|
||||||
|
task_pipeline_post_to_zulip,
|
||||||
)
|
)
|
||||||
from reflector.processors import (
|
from reflector.processors import (
|
||||||
AudioFileWriterProcessor,
|
AudioFileWriterProcessor,
|
||||||
@@ -379,6 +381,28 @@ 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):
|
||||||
@@ -406,16 +430,10 @@ async def task_pipeline_file_process(*, transcript_id: str):
|
|||||||
await pipeline.set_status(transcript_id, "error")
|
await pipeline.set_status(transcript_id, "error")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# Trigger webhook if this is a room recording with webhook configured
|
# Run post-processing chain: consent cleanup -> zulip -> webhook
|
||||||
if transcript.source_kind == SourceKind.ROOM and transcript.room_id:
|
post_chain = chain(
|
||||||
room = await rooms_controller.get_by_id(transcript.room_id)
|
task_cleanup_consent.si(transcript_id=transcript_id),
|
||||||
if room and room.webhook_url:
|
task_pipeline_post_to_zulip.si(transcript_id=transcript_id),
|
||||||
logger.info(
|
task_send_webhook_if_needed.si(transcript_id=transcript_id),
|
||||||
"Dispatching webhook task",
|
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
post_chain.delay()
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ 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,6 +54,7 @@ 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()
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ 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"""
|
||||||
@@ -20,9 +17,6 @@ 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
|
||||||
@@ -124,21 +118,11 @@ 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] = None
|
words: list[Word] = []
|
||||||
|
|
||||||
@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):
|
||||||
# Censored text
|
return "".join([word.text for word in self.words])
|
||||||
return self._get_censored_text(self.raw_text)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def human_timestamp(self):
|
def human_timestamp(self):
|
||||||
@@ -170,12 +154,6 @@ 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,6 +1,8 @@
|
|||||||
from pydantic.types import PositiveInt
|
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(
|
||||||
@@ -120,7 +122,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: str | None = None
|
WHEREBY_API_KEY: NonEmptyString | 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
|
||||||
|
|||||||
23
server/reflector/utils/string.py
Normal file
23
server/reflector/utils/string.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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)
|
||||||
@@ -46,8 +46,8 @@ class Room(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class RoomDetails(Room):
|
class RoomDetails(Room):
|
||||||
webhook_url: str
|
webhook_url: str | None
|
||||||
webhook_secret: str
|
webhook_secret: str | None
|
||||||
|
|
||||||
|
|
||||||
class Meeting(BaseModel):
|
class Meeting(BaseModel):
|
||||||
@@ -197,6 +197,7 @@ 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
|
||||||
@@ -208,20 +209,15 @@ 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.info(
|
|
||||||
"Race condition detected for room %s - fetching existing meeting",
|
|
||||||
room.name,
|
|
||||||
)
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Whereby meeting %s was created but not used (resource leak) for room %s",
|
"Race condition detected for room %s and meeting %s - fetching existing meeting",
|
||||||
whereby_meeting["meetingId"],
|
|
||||||
room.name,
|
room.name,
|
||||||
|
whereby_meeting["meetingId"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fetch the meeting that was created by the other request
|
# Fetch the meeting that was created by the other request
|
||||||
@@ -231,7 +227,9 @@ 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", room.name
|
"Meeting disappeared after race condition for room %s",
|
||||||
|
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"
|
||||||
|
|||||||
@@ -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, field_serializer
|
from pydantic import BaseModel, Field, constr, 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,14 +19,15 @@ 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,
|
||||||
)
|
)
|
||||||
@@ -63,7 +64,7 @@ class GetTranscriptMinimal(BaseModel):
|
|||||||
id: str
|
id: str
|
||||||
user_id: str | None
|
user_id: str | None
|
||||||
name: str
|
name: str
|
||||||
status: str
|
status: TranscriptStatus
|
||||||
locked: bool
|
locked: bool
|
||||||
duration: float
|
duration: float
|
||||||
title: str | None
|
title: str | None
|
||||||
@@ -96,6 +97,7 @@ 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):
|
||||||
@@ -114,7 +116,19 @@ class DeletionStatus(BaseModel):
|
|||||||
status: str
|
status: str
|
||||||
|
|
||||||
|
|
||||||
SearchQueryParam = Annotated[SearchQueryBase, Query(description="Search query text")]
|
SearchQueryParamBase = constr(min_length=0, strip_whitespace=True)
|
||||||
|
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")
|
||||||
@@ -124,7 +138,7 @@ SearchOffsetParam = Annotated[
|
|||||||
class SearchResponse(BaseModel):
|
class SearchResponse(BaseModel):
|
||||||
results: list[SearchResult]
|
results: list[SearchResult]
|
||||||
total: SearchTotal
|
total: SearchTotal
|
||||||
query: SearchQuery
|
query: SearchQuery | None = None
|
||||||
limit: SearchLimit
|
limit: SearchLimit
|
||||||
offset: SearchOffset
|
offset: SearchOffset
|
||||||
|
|
||||||
@@ -174,7 +188,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=q,
|
query_text=parse_search_query_param(q),
|
||||||
limit=limit,
|
limit=limit,
|
||||||
offset=offset,
|
offset=offset,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@@ -201,7 +215,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=SourceKind.LIVE,
|
source_kind=info.source_kind or 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,
|
||||||
@@ -336,8 +350,6 @@ 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
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ async def transcript_process(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if task_is_scheduled_or_active(
|
if task_is_scheduled_or_active(
|
||||||
"reflector.pipelines.main_live_pipeline.task_pipeline_process",
|
"reflector.pipelines.main_file_pipeline.task_pipeline_file_process",
|
||||||
transcript_id=transcript_id,
|
transcript_id=transcript_id,
|
||||||
):
|
):
|
||||||
return ProcessStatus(status="already running")
|
return ProcessStatus(status="already running")
|
||||||
|
|||||||
@@ -1,18 +1,60 @@
|
|||||||
|
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
|
||||||
|
|
||||||
HEADERS = {
|
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",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Authorization": f"Bearer {settings.WHEREBY_API_KEY}",
|
"Authorization": f"Bearer {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,
|
||||||
@@ -23,23 +65,26 @@ 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": settings.RECORDING_STORAGE_AWS_BUCKET_NAME,
|
"bucket": s3_bucket_name,
|
||||||
"accessKeyId": settings.AWS_WHEREBY_ACCESS_KEY_ID,
|
"accessKeyId": s3_key_id,
|
||||||
"accessKeySecret": settings.AWS_WHEREBY_ACCESS_KEY_SECRET,
|
"accessKeySecret": s3_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=HEADERS,
|
headers=_get_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()
|
||||||
|
|
||||||
@@ -48,7 +93,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=HEADERS,
|
headers=_get_headers(),
|
||||||
timeout=TIMEOUT,
|
timeout=TIMEOUT,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
if [ "${ENTRYPOINT}" = "server" ]; then
|
if [ "${ENTRYPOINT}" = "server" ]; then
|
||||||
uv run alembic upgrade head
|
uv run alembic upgrade head
|
||||||
uv run -m reflector.app
|
uv run uvicorn reflector.app:app --host 0.0.0.0 --port 1250
|
||||||
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
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ async def test_cleanup_deletes_associated_meeting_and_recording():
|
|||||||
host_room_url="https://example.com/meeting-host",
|
host_room_url="https://example.com/meeting-host",
|
||||||
start_date=old_date,
|
start_date=old_date,
|
||||||
end_date=old_date + timedelta(hours=1),
|
end_date=old_date + timedelta(hours=1),
|
||||||
user_id=None,
|
|
||||||
room_id=None,
|
room_id=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -241,7 +240,6 @@ async def test_meeting_consent_cascade_delete():
|
|||||||
host_room_url="https://example.com/cascade-test-host",
|
host_room_url="https://example.com/cascade-test-host",
|
||||||
start_date=datetime.now(timezone.utc),
|
start_date=datetime.now(timezone.utc),
|
||||||
end_date=datetime.now(timezone.utc) + timedelta(hours=1),
|
end_date=datetime.now(timezone.utc) + timedelta(hours=1),
|
||||||
user_id="test-user",
|
|
||||||
room_id=None,
|
room_id=None,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -272,6 +272,9 @@ 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()
|
||||||
|
|||||||
@@ -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="")
|
params_empty = SearchParameters(query_text=None)
|
||||||
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="")
|
params = SearchParameters(query_text=None)
|
||||||
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": "completed",
|
"status": "ended",
|
||||||
"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": "completed",
|
"status": "ended",
|
||||||
"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": "completed",
|
"status": "ended",
|
||||||
"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 == "completed"
|
assert test_result.status == "ended"
|
||||||
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": "completed",
|
"status": "ended",
|
||||||
"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="completed",
|
status="ended",
|
||||||
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 == "completed"
|
assert result.status == "ended"
|
||||||
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="completed",
|
status="ended",
|
||||||
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": "completed",
|
"status": "ended",
|
||||||
"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": "completed",
|
"status": "ended",
|
||||||
"locked": False,
|
"locked": False,
|
||||||
"duration": 1800.0,
|
"duration": 1800.0,
|
||||||
"created_at": datetime.now(timezone.utc),
|
"created_at": datetime.now(timezone.utc),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
"""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,
|
||||||
@@ -512,11 +514,9 @@ data visualization and data storage"""
|
|||||||
)
|
)
|
||||||
assert webvtt_count == 3
|
assert webvtt_count == 3
|
||||||
|
|
||||||
snippets_empty, count_empty = SnippetGenerator.combine_sources(
|
# combine_sources requires at least one source to be present
|
||||||
None, None, "data", max_total=3
|
with pytest.raises(AssertionError, match="At least one source must be present"):
|
||||||
)
|
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."""
|
||||||
|
|||||||
47
server/uv.lock
generated
47
server/uv.lock
generated
@@ -1325,15 +1325,6 @@ 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"
|
||||||
@@ -2311,18 +2302,6 @@ 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"
|
||||||
@@ -3131,7 +3110,6 @@ 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" },
|
||||||
@@ -3208,7 +3186,6 @@ 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" },
|
||||||
@@ -3954,8 +3931,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", hash = "sha256:3d05017d19bc99741288e458888283a44b0ee881d53f05f72f8b1cfea8998122" },
|
{ 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-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:a47b7986bee3f61ad217d8a8ce24605809ab425baf349f97de758815edd2ef54" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0-cp312-none-macosx_11_0_arm64.whl" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3980,16 +3957,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", hash = "sha256:2bfc013dd6efdc8f8223a0241d3529af9f315dffefb53ffa3bf14d3f10127da6" },
|
{ 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-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_aarch64.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-manylinux_2_28_x86_64.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_amd64.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-cp311-cp311-win_arm64.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-linux_s390x.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_aarch64.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-manylinux_2_28_x86_64.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_amd64.whl" },
|
||||||
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_arm64.whl", hash = "sha256:99fc421a5d234580e45957a7b02effbf3e1c884a5dd077afc85352c77bf41434" },
|
{ url = "https://download.pytorch.org/whl/cpu/torch-2.8.0%2Bcpu-cp312-cp312-win_arm64.whl" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
34
www/.env.example
Normal file
34
www/.env.example
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# 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,7 +40,6 @@ 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
|
||||||
|
|||||||
30
www/app/(app)/AuthWrapper.tsx
Normal file
30
www/app/(app)/AuthWrapper.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"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,7 +1,10 @@
|
|||||||
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 { Room, SourceKind } from "../../../api";
|
import type { components } from "../../../reflector-api";
|
||||||
|
|
||||||
|
type Room = components["schemas"]["Room"];
|
||||||
|
type SourceKind = components["schemas"]["SourceKind"];
|
||||||
|
|
||||||
interface FilterSidebarProps {
|
interface FilterSidebarProps {
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
@@ -72,7 +75,7 @@ export default function FilterSidebar({
|
|||||||
key={room.id}
|
key={room.id}
|
||||||
as={NextLink}
|
as={NextLink}
|
||||||
href="#"
|
href="#"
|
||||||
onClick={() => onFilterChange("room", room.id)}
|
onClick={() => onFilterChange("room" as SourceKind, room.id)}
|
||||||
color={
|
color={
|
||||||
selectedSourceKind === "room" && selectedRoomId === room.id
|
selectedSourceKind === "room" && selectedRoomId === room.id
|
||||||
? "blue.500"
|
? "blue.500"
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import {
|
|||||||
highlightMatches,
|
highlightMatches,
|
||||||
generateTextFragment,
|
generateTextFragment,
|
||||||
} from "../../../lib/textHighlight";
|
} from "../../../lib/textHighlight";
|
||||||
import { SearchResult } from "../../../api";
|
import type { components } from "../../../reflector-api";
|
||||||
|
|
||||||
|
type SearchResult = components["schemas"]["SearchResult"];
|
||||||
|
type SourceKind = components["schemas"]["SourceKind"];
|
||||||
|
|
||||||
interface TranscriptCardsProps {
|
interface TranscriptCardsProps {
|
||||||
results: SearchResult[];
|
results: SearchResult[];
|
||||||
@@ -120,7 +123,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"
|
result.source_kind === ("room" as SourceKind)
|
||||||
? result.room_name || result.room_id
|
? result.room_name || result.room_id
|
||||||
: result.source_kind;
|
: result.source_kind;
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import {
|
|||||||
FaMicrophone,
|
FaMicrophone,
|
||||||
FaGear,
|
FaGear,
|
||||||
} from "react-icons/fa6";
|
} from "react-icons/fa6";
|
||||||
|
import { TranscriptStatus } from "../../../lib/transcript";
|
||||||
|
|
||||||
interface TranscriptStatusIconProps {
|
interface TranscriptStatusIconProps {
|
||||||
status: string;
|
status: TranscriptStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TranscriptStatusIcon({
|
export default function TranscriptStatusIcon({
|
||||||
|
|||||||
@@ -19,37 +19,33 @@ import {
|
|||||||
parseAsStringLiteral,
|
parseAsStringLiteral,
|
||||||
} from "nuqs";
|
} from "nuqs";
|
||||||
import { LuX } from "react-icons/lu";
|
import { LuX } from "react-icons/lu";
|
||||||
import { useSearchTranscripts } from "../transcripts/useSearchTranscripts";
|
import type { components } from "../../reflector-api";
|
||||||
import useSessionUser from "../../lib/useSessionUser";
|
|
||||||
import { Room, SourceKind, SearchResult, $SourceKind } from "../../api";
|
type Room = components["schemas"]["Room"];
|
||||||
import useApi from "../../lib/useApi";
|
type SourceKind = components["schemas"]["SourceKind"];
|
||||||
import { useError } from "../../(errors)/errorContext";
|
type SearchResult = components["schemas"]["SearchResult"];
|
||||||
|
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;
|
||||||
@@ -69,7 +65,6 @@ 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) || "");
|
||||||
@@ -163,7 +158,6 @@ 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" }}
|
||||||
@@ -209,7 +203,11 @@ export default function TranscriptBrowser() {
|
|||||||
|
|
||||||
const [urlSourceKind, setUrlSourceKind] = useQueryState(
|
const [urlSourceKind, setUrlSourceKind] = useQueryState(
|
||||||
"source",
|
"source",
|
||||||
parseAsStringLiteral($SourceKind.enum).withOptions({
|
parseAsStringLiteral([
|
||||||
|
"room",
|
||||||
|
"live",
|
||||||
|
"file",
|
||||||
|
] as const satisfies SourceKind[]).withOptions({
|
||||||
shallow: false,
|
shallow: false,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -229,46 +227,40 @@ 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 {
|
||||||
results,
|
data: searchData,
|
||||||
totalCount: totalResults,
|
isLoading: searchLoading,
|
||||||
isLoading,
|
refetch: reloadSearch,
|
||||||
reload,
|
} = useTranscriptsSearch(urlSearchQuery, {
|
||||||
} = useSearchTranscripts(
|
limit: pageSize,
|
||||||
urlSearchQuery,
|
offset: paginationPageTo0Based(page) * pageSize,
|
||||||
{
|
room_id: urlRoomId || undefined,
|
||||||
roomIds: urlRoomId ? [urlRoomId] : null,
|
source_kind: urlSourceKind || undefined,
|
||||||
sourceKind: urlSourceKind,
|
});
|
||||||
},
|
|
||||||
{
|
const results = searchData?.results || [];
|
||||||
pageSize,
|
const totalResults = searchData?.total || 0;
|
||||||
page,
|
|
||||||
},
|
// Fetch rooms
|
||||||
);
|
const { data: roomsData } = useRoomsList(1);
|
||||||
|
const rooms = roomsData?.items || [];
|
||||||
|
|
||||||
const totalPages = getTotalPages(totalResults, pageSize);
|
const totalPages = getTotalPages(totalResults, pageSize);
|
||||||
|
|
||||||
const userName = useSessionUser().name;
|
const userName = useUserName();
|
||||||
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,
|
||||||
@@ -280,43 +272,36 @@ 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 (!api || deletionLoading) return;
|
if (deletionLoading) return;
|
||||||
setDeletionLoading(true);
|
setDeletionLoading(true);
|
||||||
api
|
deleteTranscript.mutate(
|
||||||
.v1TranscriptDelete({ transcriptId })
|
{
|
||||||
.then(() => {
|
params: {
|
||||||
|
path: { transcript_id: transcriptId },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
setDeletionLoading(false);
|
setDeletionLoading(false);
|
||||||
onCloseDeletion();
|
onCloseDeletion();
|
||||||
reload();
|
reloadSearch();
|
||||||
})
|
},
|
||||||
.catch((err) => {
|
onError: () => {
|
||||||
setDeletionLoading(false);
|
setDeletionLoading(false);
|
||||||
setError(err, "There was an error deleting the transcript");
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProcessTranscript = (transcriptId: string) => {
|
const handleProcessTranscript = (transcriptId: string) => {
|
||||||
if (!api) {
|
processTranscript.mutate({
|
||||||
console.error("API not available on handleProcessTranscript");
|
params: {
|
||||||
return;
|
path: { transcript_id: transcriptId },
|
||||||
}
|
},
|
||||||
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");
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -332,7 +317,7 @@ export default function TranscriptBrowser() {
|
|||||||
? transcriptToDelete.room_name || transcriptToDelete.room_id
|
? transcriptToDelete.room_name || transcriptToDelete.room_id
|
||||||
: transcriptToDelete?.source_kind;
|
: transcriptToDelete?.source_kind;
|
||||||
|
|
||||||
if (isLoading && results.length === 0) {
|
if (searchLoading && results.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
flexDir="column"
|
flexDir="column"
|
||||||
@@ -360,7 +345,7 @@ export default function TranscriptBrowser() {
|
|||||||
>
|
>
|
||||||
<Heading size="lg">
|
<Heading size="lg">
|
||||||
{userName ? `${userName}'s Transcriptions` : "Your Transcriptions"}{" "}
|
{userName ? `${userName}'s Transcriptions` : "Your Transcriptions"}{" "}
|
||||||
{(isLoading || deletionLoading) && <Spinner size="sm" />}
|
{(searchLoading || deletionLoading) && <Spinner size="sm" />}
|
||||||
</Heading>
|
</Heading>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
@@ -403,12 +388,12 @@ export default function TranscriptBrowser() {
|
|||||||
<TranscriptCards
|
<TranscriptCards
|
||||||
results={results}
|
results={results}
|
||||||
query={urlSearchQuery}
|
query={urlSearchQuery}
|
||||||
isLoading={isLoading}
|
isLoading={searchLoading}
|
||||||
onDelete={setTranscriptToDeleteId}
|
onDelete={setTranscriptToDeleteId}
|
||||||
onReprocess={handleProcessTranscript}
|
onReprocess={handleProcessTranscript}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!isLoading && results.length === 0 && (
|
{!searchLoading && results.length === 0 && (
|
||||||
<EmptyResult searchQuery={urlSearchQuery} />
|
<EmptyResult searchQuery={urlSearchQuery} />
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { Container, Flex, Link } from "@chakra-ui/react";
|
import { Container, Flex, Link } from "@chakra-ui/react";
|
||||||
import { getConfig } from "../lib/edgeConfig";
|
import { featureEnabled } from "../lib/features";
|
||||||
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({
|
||||||
@@ -12,8 +11,6 @@ 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"
|
||||||
@@ -59,7 +56,7 @@ export default async function AppLayout({
|
|||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
</Link>
|
</Link>
|
||||||
{browse ? (
|
{featureEnabled("browse") ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<Link href="/browse" as={NextLink} className="font-light px-2">
|
<Link href="/browse" as={NextLink} className="font-light px-2">
|
||||||
@@ -69,7 +66,7 @@ export default async function AppLayout({
|
|||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
{rooms ? (
|
{featureEnabled("rooms") ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<Link href="/rooms" as={NextLink} className="font-light px-2">
|
<Link href="/rooms" as={NextLink} className="font-light px-2">
|
||||||
@@ -79,7 +76,7 @@ export default async function AppLayout({
|
|||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
{requireLogin ? (
|
{featureEnabled("requireLogin") ? (
|
||||||
<>
|
<>
|
||||||
·
|
·
|
||||||
<UserInfo />
|
<UserInfo />
|
||||||
@@ -90,7 +87,7 @@ export default async function AppLayout({
|
|||||||
</div>
|
</div>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{children}
|
<AuthWrapper>{children}</AuthWrapper>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ import {
|
|||||||
HStack,
|
HStack,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuLink } from "react-icons/lu";
|
import { LuLink } from "react-icons/lu";
|
||||||
import { RoomDetails } from "../../../api";
|
import type { components } from "../../../reflector-api";
|
||||||
|
|
||||||
|
type Room = components["schemas"]["Room"];
|
||||||
import { RoomActionsMenu } from "./RoomActionsMenu";
|
import { RoomActionsMenu } from "./RoomActionsMenu";
|
||||||
|
|
||||||
interface RoomCardsProps {
|
interface RoomCardsProps {
|
||||||
rooms: RoomDetails[];
|
rooms: Room[];
|
||||||
linkCopied: string;
|
linkCopied: string;
|
||||||
onCopyUrl: (roomName: string) => void;
|
onCopyUrl: (roomName: string) => void;
|
||||||
onEdit: (roomId: string, roomData: any) => void;
|
onEdit: (roomId: string, roomData: any) => void;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Box, Heading, Text, VStack } from "@chakra-ui/react";
|
import { Box, Heading, Text, VStack } from "@chakra-ui/react";
|
||||||
import { RoomDetails } from "../../../api";
|
import type { components } from "../../../reflector-api";
|
||||||
|
|
||||||
|
type Room = components["schemas"]["Room"];
|
||||||
import { RoomTable } from "./RoomTable";
|
import { RoomTable } from "./RoomTable";
|
||||||
import { RoomCards } from "./RoomCards";
|
import { RoomCards } from "./RoomCards";
|
||||||
|
|
||||||
interface RoomListProps {
|
interface RoomListProps {
|
||||||
title: string;
|
title: string;
|
||||||
rooms: RoomDetails[];
|
rooms: Room[];
|
||||||
linkCopied: string;
|
linkCopied: string;
|
||||||
onCopyUrl: (roomName: string) => void;
|
onCopyUrl: (roomName: string) => void;
|
||||||
onEdit: (roomId: string, roomData: any) => void;
|
onEdit: (roomId: string, roomData: any) => void;
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuLink } from "react-icons/lu";
|
import { LuLink } from "react-icons/lu";
|
||||||
import { RoomDetails } from "../../../api";
|
import type { components } from "../../../reflector-api";
|
||||||
|
|
||||||
|
type Room = components["schemas"]["Room"];
|
||||||
import { RoomActionsMenu } from "./RoomActionsMenu";
|
import { RoomActionsMenu } from "./RoomActionsMenu";
|
||||||
|
|
||||||
interface RoomTableProps {
|
interface RoomTableProps {
|
||||||
rooms: RoomDetails[];
|
rooms: Room[];
|
||||||
linkCopied: string;
|
linkCopied: string;
|
||||||
onCopyUrl: (roomName: string) => void;
|
onCopyUrl: (roomName: string) => void;
|
||||||
onEdit: (roomId: string, roomData: any) => void;
|
onEdit: (roomId: string, roomData: any) => void;
|
||||||
|
|||||||
@@ -15,13 +15,24 @@ import {
|
|||||||
createListCollection,
|
createListCollection,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { LuEye, LuEyeOff } from "react-icons/lu";
|
import { LuEye, LuEyeOff } from "react-icons/lu";
|
||||||
import useApi from "../../lib/useApi";
|
|
||||||
import useRoomList from "./useRoomList";
|
import useRoomList from "./useRoomList";
|
||||||
import { ApiError, RoomDetails } from "../../api";
|
import type { components } from "../../reflector-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;
|
||||||
@@ -76,66 +87,77 @@ export default function RoomsList() {
|
|||||||
const recordingTypeCollection = createListCollection({
|
const recordingTypeCollection = createListCollection({
|
||||||
items: recordingTypeOptions,
|
items: recordingTypeOptions,
|
||||||
});
|
});
|
||||||
const [room, setRoom] = useState(roomInitialState);
|
const [roomInput, setRoomInput] = useState<null | typeof roomInitialState>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [editRoomId, setEditRoomId] = useState("");
|
const [editRoomId, setEditRoomId] = useState<string | null>(null);
|
||||||
const api = useApi();
|
const {
|
||||||
// TODO seems to be no setPage calls
|
loading,
|
||||||
const [page, setPage] = useState<number>(1);
|
response,
|
||||||
const { loading, response, refetch } = useRoomList(PaginationPage(page));
|
refetch,
|
||||||
const [streams, setStreams] = useState<Stream[]>([]);
|
error: roomListError,
|
||||||
const [topics, setTopics] = useState<Topic[]>([]);
|
} = useRoomList(PaginationPage(1));
|
||||||
const [nameError, setNameError] = useState("");
|
const [nameError, setNameError] = useState("");
|
||||||
const [linkCopied, setLinkCopied] = useState("");
|
const [linkCopied, setLinkCopied] = useState("");
|
||||||
|
const [selectedStreamId, setSelectedStreamId] = useState<number | null>(null);
|
||||||
const [testingWebhook, setTestingWebhook] = useState(false);
|
const [testingWebhook, setTestingWebhook] = useState(false);
|
||||||
const [webhookTestResult, setWebhookTestResult] = useState<string | null>(
|
const [webhookTestResult, setWebhookTestResult] = useState<string | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
const [showWebhookSecret, setShowWebhookSecret] = useState(false);
|
||||||
interface Stream {
|
|
||||||
stream_id: number;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Topic {
|
const createRoomMutation = useRoomCreate();
|
||||||
name: string;
|
const updateRoomMutation = useRoomUpdate();
|
||||||
}
|
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(() => {
|
||||||
const fetchZulipStreams = async () => {
|
if (room.zulipStream && streams.length > 0) {
|
||||||
if (!api) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await api.v1ZulipGetStreams();
|
|
||||||
setStreams(response);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching Zulip streams:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (room.zulipAutoPost) {
|
|
||||||
fetchZulipStreams();
|
|
||||||
}
|
|
||||||
}, [room.zulipAutoPost, !api]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchZulipTopics = async () => {
|
|
||||||
if (!api || !room.zulipStream) return;
|
|
||||||
try {
|
|
||||||
const selectedStream = streams.find((s) => s.name === room.zulipStream);
|
const selectedStream = streams.find((s) => s.name === room.zulipStream);
|
||||||
if (selectedStream) {
|
if (selectedStream !== undefined) {
|
||||||
const response = await api.v1ZulipGetTopics({
|
setSelectedStreamId(selectedStream.stream_id);
|
||||||
streamId: selectedStream.stream_id,
|
|
||||||
});
|
|
||||||
setTopics(response);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} else {
|
||||||
console.error("Error fetching Zulip topics:", error);
|
setSelectedStreamId(null);
|
||||||
}
|
}
|
||||||
};
|
}, [room.zulipStream, streams]);
|
||||||
|
|
||||||
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 };
|
||||||
@@ -167,35 +189,42 @@ export default function RoomsList() {
|
|||||||
const handleCloseDialog = () => {
|
const handleCloseDialog = () => {
|
||||||
setShowWebhookSecret(false);
|
setShowWebhookSecret(false);
|
||||||
setWebhookTestResult(null);
|
setWebhookTestResult(null);
|
||||||
|
setEditRoomId(null);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTestWebhook = async () => {
|
const handleTestWebhook = async () => {
|
||||||
if (!room.webhookUrl || !editRoomId) {
|
if (!room.webhookUrl) {
|
||||||
setWebhookTestResult("Please enter a webhook URL first");
|
setWebhookTestResult("Please enter a webhook URL first");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!editRoomId) {
|
||||||
|
console.error("No room ID to test webhook");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setTestingWebhook(true);
|
setTestingWebhook(true);
|
||||||
setWebhookTestResult(null);
|
setWebhookTestResult(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await api?.v1RoomsTestWebhook({
|
const response = await roomTestWebhookMutation.mutateAsync({
|
||||||
roomId: editRoomId,
|
params: {
|
||||||
|
path: {
|
||||||
|
room_id: editRoomId,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response?.success) {
|
if (response.success) {
|
||||||
setWebhookTestResult(
|
setWebhookTestResult(
|
||||||
`✅ Webhook test successful! Status: ${response.status_code}`,
|
`✅ Webhook test successful! Status: ${response.status_code}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let errorMsg = `❌ Webhook test failed`;
|
let errorMsg = `❌ Webhook test failed`;
|
||||||
if (response?.status_code) {
|
|
||||||
errorMsg += ` (Status: ${response.status_code})`;
|
errorMsg += ` (Status: ${response.status_code})`;
|
||||||
}
|
if (response.error) {
|
||||||
if (response?.error) {
|
|
||||||
errorMsg += `: ${response.error}`;
|
errorMsg += `: ${response.error}`;
|
||||||
} else if (response?.response_preview) {
|
} else if (response.response_preview) {
|
||||||
// Try to parse and extract meaningful error from response
|
// Try to parse and extract meaningful error from response
|
||||||
// Specific to N8N at the moment, as there is no specification for that
|
// 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.
|
// We could just display as is, but decided here to dig a little bit more.
|
||||||
@@ -249,27 +278,29 @@ export default function RoomsList() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
await api?.v1RoomsUpdate({
|
await updateRoomMutation.mutateAsync({
|
||||||
roomId: editRoomId,
|
params: {
|
||||||
requestBody: roomData,
|
path: { room_id: assertExists(editRoomId) },
|
||||||
|
},
|
||||||
|
body: roomData,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await api?.v1RoomsCreate({
|
await createRoomMutation.mutateAsync({
|
||||||
requestBody: roomData,
|
body: roomData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setRoom(roomInitialState);
|
setRoomInput(null);
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setEditRoomId("");
|
setEditRoomId("");
|
||||||
setNameError("");
|
setNameError("");
|
||||||
refetch();
|
refetch();
|
||||||
|
onClose();
|
||||||
handleCloseDialog();
|
handleCloseDialog();
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
if (
|
if (
|
||||||
err instanceof ApiError &&
|
err?.status === 400 &&
|
||||||
err.status === 400 &&
|
err?.body?.detail == "Room name is not unique"
|
||||||
(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.",
|
||||||
@@ -280,46 +311,11 @@ export default function RoomsList() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditRoom = async (roomId, roomData) => {
|
const handleEditRoom = async (roomId: string, roomData) => {
|
||||||
// Reset states
|
// Reset states
|
||||||
setShowWebhookSecret(false);
|
setShowWebhookSecret(false);
|
||||||
setWebhookTestResult(null);
|
setWebhookTestResult(null);
|
||||||
|
|
||||||
// Fetch full room details to get webhook fields
|
|
||||||
try {
|
|
||||||
const detailedRoom = await api?.v1RoomsGet({ roomId });
|
|
||||||
if (detailedRoom) {
|
|
||||||
setRoom({
|
|
||||||
name: detailedRoom.name,
|
|
||||||
zulipAutoPost: detailedRoom.zulip_auto_post,
|
|
||||||
zulipStream: detailedRoom.zulip_stream,
|
|
||||||
zulipTopic: detailedRoom.zulip_topic,
|
|
||||||
isLocked: detailedRoom.is_locked,
|
|
||||||
roomMode: detailedRoom.room_mode,
|
|
||||||
recordingType: detailedRoom.recording_type,
|
|
||||||
recordingTrigger: detailedRoom.recording_trigger,
|
|
||||||
isShared: detailedRoom.is_shared,
|
|
||||||
webhookUrl: detailedRoom.webhook_url || "",
|
|
||||||
webhookSecret: detailedRoom.webhook_secret || "",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch room details, using list data:", error);
|
|
||||||
// Fallback to using the data from the list
|
|
||||||
setRoom({
|
|
||||||
name: roomData.name,
|
|
||||||
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,
|
|
||||||
webhookUrl: roomData.webhook_url || "",
|
|
||||||
webhookSecret: roomData.webhook_secret || "",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setEditRoomId(roomId);
|
setEditRoomId(roomId);
|
||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
setNameError("");
|
setNameError("");
|
||||||
@@ -328,8 +324,10 @@ export default function RoomsList() {
|
|||||||
|
|
||||||
const handleDeleteRoom = async (roomId: string) => {
|
const handleDeleteRoom = async (roomId: string) => {
|
||||||
try {
|
try {
|
||||||
await api?.v1RoomsDelete({
|
await deleteRoomMutation.mutateAsync({
|
||||||
roomId,
|
params: {
|
||||||
|
path: { room_id: roomId },
|
||||||
|
},
|
||||||
});
|
});
|
||||||
refetch();
|
refetch();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -346,15 +344,15 @@ export default function RoomsList() {
|
|||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
setNameError("");
|
setNameError("");
|
||||||
}
|
}
|
||||||
setRoom({
|
setRoomInput({
|
||||||
...room,
|
...room,
|
||||||
[name]: type === "checkbox" ? checked : value,
|
[name]: type === "checkbox" ? checked : value,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const myRooms: RoomDetails[] =
|
const myRooms: Room[] =
|
||||||
response?.items.filter((roomData) => !roomData.is_shared) || [];
|
response?.items.filter((roomData) => !roomData.is_shared) || [];
|
||||||
const sharedRooms: RoomDetails[] =
|
const sharedRooms: Room[] =
|
||||||
response?.items.filter((roomData) => roomData.is_shared) || [];
|
response?.items.filter((roomData) => roomData.is_shared) || [];
|
||||||
|
|
||||||
if (loading && !response)
|
if (loading && !response)
|
||||||
@@ -369,6 +367,9 @@ export default function RoomsList() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (roomListError)
|
||||||
|
return <div>{`${roomListError.name}: ${roomListError.message}`}</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
flexDir="column"
|
flexDir="column"
|
||||||
@@ -387,7 +388,7 @@ export default function RoomsList() {
|
|||||||
colorPalette="primary"
|
colorPalette="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
setRoom(roomInitialState);
|
setRoomInput(null);
|
||||||
setNameError("");
|
setNameError("");
|
||||||
setShowWebhookSecret(false);
|
setShowWebhookSecret(false);
|
||||||
setWebhookTestResult(null);
|
setWebhookTestResult(null);
|
||||||
@@ -456,7 +457,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.roomMode]}
|
value={[room.roomMode]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoom({ ...room, roomMode: e.value[0] })
|
setRoomInput({ ...room, roomMode: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={roomModeCollection}
|
collection={roomModeCollection}
|
||||||
>
|
>
|
||||||
@@ -486,7 +487,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.recordingType]}
|
value={[room.recordingType]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoom({
|
setRoomInput({
|
||||||
...room,
|
...room,
|
||||||
recordingType: e.value[0],
|
recordingType: e.value[0],
|
||||||
recordingTrigger:
|
recordingTrigger:
|
||||||
@@ -521,7 +522,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={[room.recordingTrigger]}
|
value={[room.recordingTrigger]}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoom({ ...room, recordingTrigger: e.value[0] })
|
setRoomInput({ ...room, recordingTrigger: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={recordingTriggerCollection}
|
collection={recordingTriggerCollection}
|
||||||
disabled={room.recordingType !== "cloud"}
|
disabled={room.recordingType !== "cloud"}
|
||||||
@@ -576,7 +577,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={room.zulipStream ? [room.zulipStream] : []}
|
value={room.zulipStream ? [room.zulipStream] : []}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoom({
|
setRoomInput({
|
||||||
...room,
|
...room,
|
||||||
zulipStream: e.value[0],
|
zulipStream: e.value[0],
|
||||||
zulipTopic: "",
|
zulipTopic: "",
|
||||||
@@ -611,7 +612,7 @@ export default function RoomsList() {
|
|||||||
<Select.Root
|
<Select.Root
|
||||||
value={room.zulipTopic ? [room.zulipTopic] : []}
|
value={room.zulipTopic ? [room.zulipTopic] : []}
|
||||||
onValueChange={(e) =>
|
onValueChange={(e) =>
|
||||||
setRoom({ ...room, zulipTopic: e.value[0] })
|
setRoomInput({ ...room, zulipTopic: e.value[0] })
|
||||||
}
|
}
|
||||||
collection={topicCollection}
|
collection={topicCollection}
|
||||||
disabled={!room.zulipAutoPost}
|
disabled={!room.zulipAutoPost}
|
||||||
|
|||||||
@@ -1,48 +1,27 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useRoomsList } from "../../lib/apiHooks";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import type { components } from "../../reflector-api";
|
||||||
import useApi from "../../lib/useApi";
|
|
||||||
import { Page_RoomDetails_ } from "../../api";
|
type Page_Room_ = components["schemas"]["Page_RoomDetails_"];
|
||||||
import { PaginationPage } from "../browse/_components/Pagination";
|
import { PaginationPage } from "../browse/_components/Pagination";
|
||||||
|
|
||||||
type RoomList = {
|
type RoomList = {
|
||||||
response: Page_RoomDetails_ | null;
|
response: Page_Room_ | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: Error | null;
|
error: Error | null;
|
||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
//always protected
|
// Wrapper to maintain backward compatibility
|
||||||
const useRoomList = (page: PaginationPage): RoomList => {
|
const useRoomList = (page: PaginationPage): RoomList => {
|
||||||
const [response, setResponse] = useState<Page_RoomDetails_ | null>(null);
|
const { data, isLoading, error, refetch } = useRoomsList(page);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
return {
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
response: data || null,
|
||||||
const { setError } = useError();
|
loading: isLoading,
|
||||||
const api = useApi();
|
error: error
|
||||||
const [refetchCount, setRefetchCount] = useState(0);
|
? new Error(error.detail ? JSON.stringify(error.detail) : undefined)
|
||||||
|
: null,
|
||||||
const refetch = () => {
|
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,8 +3,10 @@ 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[];
|
||||||
@@ -14,7 +16,7 @@ type TopicListProps = {
|
|||||||
];
|
];
|
||||||
autoscroll: boolean;
|
autoscroll: boolean;
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
status: string;
|
status: TranscriptStatus | null;
|
||||||
currentTranscriptText: any;
|
currentTranscriptText: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,35 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState, use } 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 { GetTranscriptTopic } from "../../../../api";
|
import type { components } from "../../../../reflector-api";
|
||||||
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
import { SelectedText, selectedTextIsTimeSlice } from "./types";
|
import { SelectedText, selectedTextIsTimeSlice } from "./types";
|
||||||
import useApi from "../../../../lib/useApi";
|
import {
|
||||||
import useTranscript from "../../useTranscript";
|
useTranscriptGet,
|
||||||
|
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: {
|
params: Promise<{
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
};
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TranscriptCorrect({
|
export default function TranscriptCorrect(props: TranscriptCorrect) {
|
||||||
params: { transcriptId },
|
const params = use(props.params);
|
||||||
}: TranscriptCorrect) {
|
|
||||||
const api = useApi();
|
const { transcriptId } = params;
|
||||||
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>();
|
||||||
@@ -34,16 +39,21 @@ export default function TranscriptCorrect({
|
|||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const markAsDone = () => {
|
const markAsDone = async () => {
|
||||||
if (transcript.response && !transcript.response.reviewed) {
|
if (transcript.data && !transcript.data.reviewed) {
|
||||||
api
|
try {
|
||||||
?.v1TranscriptUpdate({ transcriptId, requestBody: { reviewed: true } })
|
await updateTranscriptMutation.mutateAsync({
|
||||||
.then(() => {
|
params: {
|
||||||
router.push(`/transcripts/${transcriptId}`);
|
path: {
|
||||||
})
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,7 +118,7 @@ export default function TranscriptCorrect({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
{transcript.response && !transcript.response?.reviewed && (
|
{transcript.data && !transcript.data?.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,8 +1,15 @@
|
|||||||
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 { Participant } from "../../../../api";
|
import type { components } from "../../../../reflector-api";
|
||||||
import useApi from "../../../../lib/useApi";
|
type Participant = components["schemas"]["Participant"];
|
||||||
|
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";
|
||||||
@@ -30,9 +37,19 @@ const ParticipantList = ({
|
|||||||
topicWithWords,
|
topicWithWords,
|
||||||
stateSelectedText,
|
stateSelectedText,
|
||||||
}: ParticipantList) => {
|
}: ParticipantList) => {
|
||||||
const api = useApi();
|
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const [loading, setLoading] = useState(false);
|
const speakerAssignMutation = useTranscriptSpeakerAssign();
|
||||||
|
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;
|
||||||
@@ -103,7 +120,6 @@ 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);
|
||||||
@@ -120,11 +136,14 @@ 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 api?.v1TranscriptAssignSpeaker({
|
await speakerAssignMutation.mutateAsync({
|
||||||
transcriptId,
|
params: {
|
||||||
requestBody: {
|
path: {
|
||||||
|
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,
|
||||||
@@ -132,8 +151,7 @@ const ParticipantList = ({
|
|||||||
});
|
});
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error, "There was an error assigning");
|
setError(error as Error, "There was an error assigning");
|
||||||
setLoading(false);
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -141,32 +159,38 @@ 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 api?.v1TranscriptMergeSpeaker({
|
await speakerMergeMutation.mutateAsync({
|
||||||
transcriptId,
|
params: {
|
||||||
requestBody: {
|
path: {
|
||||||
|
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, "There was an error merging");
|
setError(error as Error, "There was an error merging");
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await api?.v1TranscriptUpdateParticipant({
|
await participantUpdateMutation.mutateAsync({
|
||||||
transcriptId,
|
params: {
|
||||||
participantId: participantTo.id,
|
path: {
|
||||||
requestBody: { speaker: speakerFrom },
|
transcript_id: transcriptId,
|
||||||
|
participant_id: participantTo.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: { speaker: speakerFrom },
|
||||||
});
|
});
|
||||||
onSuccess();
|
onSuccess();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error, "There was an error merging (update)");
|
setError(error as Error, "There was an error merging (update)");
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -186,105 +210,106 @@ const ParticipantList = ({
|
|||||||
(p) => p.speaker == selectedText,
|
(p) => p.speaker == selectedText,
|
||||||
);
|
);
|
||||||
if (participant && participant.name !== participantInput) {
|
if (participant && participant.name !== participantInput) {
|
||||||
setLoading(true);
|
try {
|
||||||
api
|
await participantUpdateMutation.mutateAsync({
|
||||||
?.v1TranscriptUpdateParticipant({
|
params: {
|
||||||
transcriptId,
|
path: {
|
||||||
participantId: participant.id,
|
transcript_id: transcriptId,
|
||||||
requestBody: {
|
participant_id: participant.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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)
|
||||||
) {
|
) {
|
||||||
setLoading(true);
|
try {
|
||||||
api
|
await participantCreateMutation.mutateAsync({
|
||||||
?.v1TranscriptAddParticipant({
|
params: {
|
||||||
transcriptId,
|
path: {
|
||||||
requestBody: {
|
transcript_id: transcriptId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: {
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
speaker: selectedText,
|
speaker: selectedText,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
participants.refetch();
|
participants.refetch();
|
||||||
setParticipantInput("");
|
setParticipantInput("");
|
||||||
setOneMatch(undefined);
|
setOneMatch(undefined);
|
||||||
setLoading(false);
|
} catch (e) {
|
||||||
})
|
setError(e as Error, "There was an error creating");
|
||||||
.catch((e) => {
|
}
|
||||||
setError(e, "There was an error creating");
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
} else if (
|
} else if (
|
||||||
action == "Create and assign" &&
|
action == "Create and assign" &&
|
||||||
selectedTextIsTimeSlice(selectedText)
|
selectedTextIsTimeSlice(selectedText)
|
||||||
) {
|
) {
|
||||||
setLoading(true);
|
|
||||||
try {
|
try {
|
||||||
const participant = await api?.v1TranscriptAddParticipant({
|
const participant = await participantCreateMutation.mutateAsync({
|
||||||
transcriptId,
|
params: {
|
||||||
requestBody: {
|
path: {
|
||||||
|
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(e, "There was an error creating");
|
setError(error as Error, "There was an error creating");
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
} else if (action == "Create") {
|
} else if (action == "Create") {
|
||||||
setLoading(true);
|
try {
|
||||||
api
|
await participantCreateMutation.mutateAsync({
|
||||||
?.v1TranscriptAddParticipant({
|
params: {
|
||||||
transcriptId,
|
path: {
|
||||||
requestBody: {
|
transcript_id: transcriptId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: {
|
||||||
name: participantInput,
|
name: participantInput,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
participants.refetch();
|
participants.refetch();
|
||||||
setParticipantInput("");
|
setParticipantInput("");
|
||||||
setLoading(false);
|
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
})
|
} catch (e) {
|
||||||
.catch((e) => {
|
setError(e as Error, "There was an error creating");
|
||||||
setError(e, "There was an error creating");
|
}
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteParticipant = (participantId) => (e) => {
|
const deleteParticipant = (participantId) => async (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (loading || participants.loading || topicWithWords.loading) return;
|
if (loading || participants.loading || topicWithWords.loading) return;
|
||||||
setLoading(true);
|
|
||||||
api
|
try {
|
||||||
?.v1TranscriptDeleteParticipant({ transcriptId, participantId })
|
await participantDeleteMutation.mutateAsync({
|
||||||
.then(() => {
|
params: {
|
||||||
participants.refetch();
|
path: {
|
||||||
setLoading(false);
|
transcript_id: transcriptId,
|
||||||
})
|
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,6 +1,7 @@
|
|||||||
import useTopics from "../../useTopics";
|
import useTopics from "../../useTopics";
|
||||||
import { Dispatch, SetStateAction, useEffect } from "react";
|
import { Dispatch, SetStateAction, useEffect } from "react";
|
||||||
import { GetTranscriptTopic } from "../../../../api";
|
import type { components } from "../../../../reflector-api";
|
||||||
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
import {
|
import {
|
||||||
BoxProps,
|
BoxProps,
|
||||||
Box,
|
Box,
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ 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 {
|
import type { components } from "../../../reflector-api";
|
||||||
GetTranscript,
|
type GetTranscript = components["schemas"]["GetTranscript"];
|
||||||
GetTranscriptTopic,
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
UpdateTranscript,
|
import { useTranscriptUpdate } from "../../../lib/apiHooks";
|
||||||
} from "../../../api";
|
|
||||||
import useApi from "../../../lib/useApi";
|
|
||||||
import {
|
import {
|
||||||
Flex,
|
Flex,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -33,9 +31,8 @@ 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 || "");
|
||||||
@@ -47,12 +44,15 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
|
|
||||||
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
const updateSummary = async (newSummary: string, transcriptId: string) => {
|
||||||
try {
|
try {
|
||||||
const requestBody: UpdateTranscript = {
|
const updatedTranscript = await updateTranscriptMutation.mutateAsync({
|
||||||
|
params: {
|
||||||
|
path: {
|
||||||
|
transcript_id: transcriptId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: {
|
||||||
long_summary: newSummary,
|
long_summary: newSummary,
|
||||||
};
|
},
|
||||||
const updatedTranscript = await api?.v1TranscriptUpdate({
|
|
||||||
transcriptId,
|
|
||||||
requestBody,
|
|
||||||
});
|
});
|
||||||
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, "Failed to update long summary.");
|
setError(err as Error, "Failed to update long summary.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -114,7 +114,12 @@ export default function FinalSummary(props: FinalSummaryProps) {
|
|||||||
<Button onClick={onDiscardClick} variant="ghost">
|
<Button onClick={onDiscardClick} variant="ghost">
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={onSaveClick}>Save</Button>
|
<Button
|
||||||
|
onClick={onSaveClick}
|
||||||
|
disabled={updateTranscriptMutation.isPending}
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
{!isEditMode && (
|
{!isEditMode && (
|
||||||
|
|||||||
@@ -1,32 +1,38 @@
|
|||||||
"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 } from "react";
|
import React, { useEffect, useState, use } 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: {
|
params: Promise<{
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
};
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TranscriptDetails(details: TranscriptDetails) {
|
export default function TranscriptDetails(details: TranscriptDetails) {
|
||||||
const transcriptId = details.params.transcriptId;
|
const params = use(details.params);
|
||||||
|
const transcriptId = params.transcriptId;
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const statusToRedirect = ["idle", "recording", "processing"];
|
const statusToRedirect = [
|
||||||
|
"idle",
|
||||||
|
"recording",
|
||||||
|
"processing",
|
||||||
|
] satisfies TranscriptStatus[] as TranscriptStatus[];
|
||||||
|
|
||||||
const transcript = useTranscript(transcriptId);
|
const transcript = useTranscriptGet(transcriptId);
|
||||||
const transcriptStatus = transcript.response?.status;
|
const waiting =
|
||||||
const waiting = statusToRedirect.includes(transcriptStatus || "");
|
transcript.data && statusToRedirect.includes(transcript.data.status);
|
||||||
|
|
||||||
const mp3 = useMp3(transcriptId, waiting);
|
const mp3 = useMp3(transcriptId, waiting);
|
||||||
const topics = useTopics(transcriptId);
|
const topics = useTopics(transcriptId);
|
||||||
@@ -38,7 +44,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
const newUrl = "/transcripts/" + details.params.transcriptId + "/record";
|
const newUrl = "/transcripts/" + 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
|
||||||
@@ -56,7 +62,7 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transcript?.loading || topics?.loading) {
|
if (transcript?.isLoading || topics?.loading) {
|
||||||
return <Modal title="Loading" text={"Loading transcript..."} />;
|
return <Modal title="Loading" text={"Loading transcript..."} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +92,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.response.duration}
|
mediaDuration={transcript.data?.duration || null}
|
||||||
/>
|
/>
|
||||||
) : !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">
|
||||||
@@ -116,10 +122,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.response.title || "Unnamed Transcript"}
|
title={transcript.data?.title || "Unnamed Transcript"}
|
||||||
transcriptId={transcriptId}
|
transcriptId={transcriptId}
|
||||||
onUpdate={(newTitle) => {
|
onUpdate={(newTitle) => {
|
||||||
transcript.reload();
|
transcript.refetch().then(() => {});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -136,23 +142,23 @@ export default function TranscriptDetails(details: TranscriptDetails) {
|
|||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
autoscroll={false}
|
autoscroll={false}
|
||||||
transcriptId={transcriptId}
|
transcriptId={transcriptId}
|
||||||
status={transcript.response?.status}
|
status={transcript.data?.status || null}
|
||||||
currentTranscriptText=""
|
currentTranscriptText=""
|
||||||
/>
|
/>
|
||||||
{transcript.response && topics.topics ? (
|
{transcript.data && topics.topics ? (
|
||||||
<>
|
<>
|
||||||
<FinalSummary
|
<FinalSummary
|
||||||
transcriptResponse={transcript.response}
|
transcriptResponse={transcript.data}
|
||||||
topicsResponse={topics.topics}
|
topicsResponse={topics.topics}
|
||||||
onUpdate={(newSummary) => {
|
onUpdate={() => {
|
||||||
transcript.reload();
|
transcript.refetch();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<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.response.status == "processing" ? (
|
{transcript?.data?.status == "processing" ? (
|
||||||
<Text>Loading Transcript</Text>
|
<Text>Loading Transcript</Text>
|
||||||
) : (
|
) : (
|
||||||
<Text>
|
<Text>
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, use } 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";
|
||||||
@@ -11,26 +10,29 @@ 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: {
|
params: Promise<{
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
};
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const TranscriptRecord = (details: TranscriptDetails) => {
|
const TranscriptRecord = (details: TranscriptDetails) => {
|
||||||
const transcript = useTranscript(details.params.transcriptId);
|
const params = use(details.params);
|
||||||
|
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(details.params.transcriptId);
|
const webSockets = useWebSockets(params.transcriptId);
|
||||||
|
|
||||||
const mp3 = useMp3(details.params.transcriptId, true);
|
const mp3 = useMp3(params.transcriptId, true);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [status, setStatus] = useState(
|
const [status, setStatus] = useState<TranscriptStatus>(
|
||||||
webSockets.status.value || transcript.response?.status || "idle",
|
webSockets.status?.value || transcript.data?.status || "idle",
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -41,15 +43,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.response?.status || "idle";
|
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/" + details.params.transcriptId;
|
const newUrl = "/transcripts/" + params.transcriptId;
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
}
|
}
|
||||||
}, [webSockets.status.value, transcript.response?.status]);
|
}, [webSockets.status?.value, transcript.data?.status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
||||||
@@ -74,7 +76,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={details.params.transcriptId} status={status} />
|
<Recorder transcriptId={params.transcriptId} status={status} />
|
||||||
)}
|
)}
|
||||||
<VStack
|
<VStack
|
||||||
align={"left"}
|
align={"left"}
|
||||||
@@ -97,7 +99,7 @@ const TranscriptRecord = (details: TranscriptDetails) => {
|
|||||||
topics={webSockets.topics}
|
topics={webSockets.topics}
|
||||||
useActiveTopic={useActiveTopic}
|
useActiveTopic={useActiveTopic}
|
||||||
autoscroll={true}
|
autoscroll={true}
|
||||||
transcriptId={details.params.transcriptId}
|
transcriptId={params.transcriptId}
|
||||||
status={status}
|
status={status}
|
||||||
currentTranscriptText={webSockets.accumulatedText}
|
currentTranscriptText={webSockets.accumulatedText}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,33 +1,40 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, use } 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: {
|
params: Promise<{
|
||||||
transcriptId: string;
|
transcriptId: string;
|
||||||
};
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const TranscriptUpload = (details: TranscriptUpload) => {
|
const TranscriptUpload = (details: TranscriptUpload) => {
|
||||||
const transcript = useTranscript(details.params.transcriptId);
|
const params = use(details.params);
|
||||||
|
const transcript = useTranscriptGet(params.transcriptId);
|
||||||
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
const [transcriptStarted, setTranscriptStarted] = useState(false);
|
||||||
|
|
||||||
const webSockets = useWebSockets(details.params.transcriptId);
|
const webSockets = useWebSockets(params.transcriptId);
|
||||||
|
|
||||||
const mp3 = useMp3(details.params.transcriptId, true);
|
const mp3 = useMp3(params.transcriptId, true);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [status, setStatus] = useState(
|
const [status_, setStatus] = useState(
|
||||||
webSockets.status.value || transcript.response?.status || "idle",
|
webSockets.status?.value || transcript.data?.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);
|
||||||
@@ -35,16 +42,19 @@ 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 =
|
||||||
webSockets.status.value || transcript.response?.status || "idle";
|
transcript.data?.status === "ended"
|
||||||
|
? "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/" + details.params.transcriptId;
|
const newUrl = "/transcripts/" + params.transcriptId;
|
||||||
router.replace(newUrl);
|
router.replace(newUrl);
|
||||||
}
|
}
|
||||||
}, [webSockets.status.value, transcript.response?.status]);
|
}, [webSockets.status?.value, transcript.data?.status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
if (webSockets.waveform && webSockets.waveform) mp3.getNow();
|
||||||
@@ -75,7 +85,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={details.params.transcriptId} />
|
<FileUploadButton transcriptId={params.transcriptId} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{status && status == "uploaded" && (
|
{status && status == "uploaded" && (
|
||||||
|
|||||||
@@ -1,45 +1,33 @@
|
|||||||
import { useEffect, useState } from "react";
|
import type { components } from "../../reflector-api";
|
||||||
|
import { useTranscriptCreate } from "../../lib/apiHooks";
|
||||||
|
|
||||||
import { useError } from "../../(errors)/errorContext";
|
type CreateTranscript = components["schemas"]["CreateTranscript"];
|
||||||
import { CreateTranscript, GetTranscript } from "../../api";
|
type GetTranscript = components["schemas"]["GetTranscript"];
|
||||||
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) => void;
|
create: (transcriptCreationDetails: CreateTranscript) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useCreateTranscript = (): UseCreateTranscript => {
|
const useCreateTranscript = (): UseCreateTranscript => {
|
||||||
const [transcript, setTranscript] = useState<GetTranscript | null>(null);
|
const createMutation = useTranscriptCreate();
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
|
||||||
const { setError } = useError();
|
|
||||||
const api = useApi();
|
|
||||||
|
|
||||||
const create = (transcriptCreationDetails: CreateTranscript) => {
|
const create = async (transcriptCreationDetails: CreateTranscript) => {
|
||||||
if (loading || !api) return;
|
if (createMutation.isPending) return;
|
||||||
|
|
||||||
setLoading(true);
|
await createMutation.mutateAsync({
|
||||||
|
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 { transcript, loading, error, create };
|
return {
|
||||||
|
transcript: createMutation.data || null,
|
||||||
|
loading: createMutation.isPending,
|
||||||
|
error: createMutation.error as Error | null,
|
||||||
|
create,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useCreateTranscript;
|
export default useCreateTranscript;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import useApi from "../../lib/useApi";
|
import { useTranscriptUploadAudio } from "../../lib/apiHooks";
|
||||||
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;
|
||||||
@@ -8,13 +9,16 @@ 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 api = useApi();
|
const uploadMutation = useTranscriptUploadAudio();
|
||||||
|
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 = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFileUpload = async (
|
||||||
|
event: React.ChangeEvent<HTMLInputElement>,
|
||||||
|
) => {
|
||||||
const file = event.target.files?.[0];
|
const file = event.target.files?.[0];
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
@@ -24,37 +28,45 @@ 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) return;
|
if (chunkNumber == totalChunks) {
|
||||||
|
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);
|
||||||
|
|
||||||
await api?.v1TranscriptRecordUpload({
|
try {
|
||||||
transcriptId: props.transcriptId,
|
const formData = new FormData();
|
||||||
formData: {
|
formData.append("chunk", chunk);
|
||||||
chunk,
|
|
||||||
|
await uploadMutation.mutateAsync({
|
||||||
|
params: {
|
||||||
|
path: {
|
||||||
|
transcript_id: props.transcriptId,
|
||||||
},
|
},
|
||||||
chunkNumber,
|
query: {
|
||||||
totalChunks,
|
chunk_number: chunkNumber,
|
||||||
|
total_chunks: totalChunks,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: formData as any,
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadedSize += chunkSize;
|
uploadedSize += chunkSize;
|
||||||
|
const currentProgress = Math.floor((uploadedSize / file.size) * 100);
|
||||||
|
setProgress(currentProgress);
|
||||||
|
|
||||||
chunkNumber++;
|
chunkNumber++;
|
||||||
start = end;
|
start = end;
|
||||||
|
|
||||||
uploadNextChunk();
|
await uploadNextChunk();
|
||||||
|
} catch (error) {
|
||||||
|
setError(error as Error, "Failed to upload file");
|
||||||
|
setProgress(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uploadNextChunk();
|
uploadNextChunk();
|
||||||
|
|||||||
@@ -9,33 +9,25 @@ 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 { isLoading, isAuthenticated } = useSessionStatus();
|
const auth = useAuth();
|
||||||
|
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>("");
|
||||||
@@ -54,20 +46,32 @@ const TranscriptCreate = () => {
|
|||||||
const [loadingUpload, setLoadingUpload] = useState(false);
|
const [loadingUpload, setLoadingUpload] = useState(false);
|
||||||
|
|
||||||
const getTargetLanguage = () => {
|
const getTargetLanguage = () => {
|
||||||
if (targetLanguage === "NOTRANSLATION") return;
|
if (targetLanguage === "NOTRANSLATION") return undefined;
|
||||||
return targetLanguage;
|
return targetLanguage;
|
||||||
};
|
};
|
||||||
|
|
||||||
const send = () => {
|
const send = () => {
|
||||||
if (loadingRecord || createTranscript.loading || permissionDenied) return;
|
if (loadingRecord || createTranscript.loading || permissionDenied) return;
|
||||||
setLoadingRecord(true);
|
setLoadingRecord(true);
|
||||||
createTranscript.create({ name, target_language: getTargetLanguage() });
|
const targetLang = 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);
|
||||||
createTranscript.create({ name, target_language: getTargetLanguage() });
|
const targetLang = getTargetLanguage();
|
||||||
|
createTranscript.create({
|
||||||
|
name,
|
||||||
|
source_language: "en",
|
||||||
|
target_language: targetLang || "en",
|
||||||
|
source_kind: "file",
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -132,8 +136,8 @@ const TranscriptCreate = () => {
|
|||||||
<Center>
|
<Center>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Spinner />
|
<Spinner />
|
||||||
) : requireLogin && !isAuthenticated ? (
|
) : requireLogin && !isAuthenticated && !isAuthRefreshing ? (
|
||||||
<Button onClick={() => signIn("authentik")}>Log in</Button>
|
<Button onClick={() => auth.signIn("authentik")}>Log in</Button>
|
||||||
) : (
|
) : (
|
||||||
<Flex
|
<Flex
|
||||||
rounded="xl"
|
rounded="xl"
|
||||||
@@ -170,7 +174,7 @@ const TranscriptCreate = () => {
|
|||||||
placeholder="Choose your language"
|
placeholder="Choose your language"
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{isClient && !loading ? (
|
{!loading ? (
|
||||||
permissionOk ? (
|
permissionOk ? (
|
||||||
<Spacer />
|
<Spacer />
|
||||||
) : permissionDenied ? (
|
) : permissionDenied ? (
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ 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 { AudioWaveform } from "../../api";
|
import type { components } from "../../reflector-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";
|
||||||
@@ -18,7 +20,7 @@ type PlayerProps = {
|
|||||||
];
|
];
|
||||||
waveform: AudioWaveform;
|
waveform: AudioWaveform;
|
||||||
media: HTMLMediaElement;
|
media: HTMLMediaElement;
|
||||||
mediaDuration: number;
|
mediaDuration: number | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Player(props: PlayerProps) {
|
export default function Player(props: PlayerProps) {
|
||||||
@@ -50,7 +52,9 @@ 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: Math.floor(props.mediaDuration / 1000),
|
duration: props.mediaDuration
|
||||||
|
? 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: string;
|
status: TranscriptStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Recorder(props: RecorderProps) {
|
export default function Recorder(props: RecorderProps) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
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 { GetTranscript, GetTranscriptTopic, UpdateTranscript } from "../../api";
|
import type { components } from "../../reflector-api";
|
||||||
|
type GetTranscript = components["schemas"]["GetTranscript"];
|
||||||
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
|
type UpdateTranscript = components["schemas"]["UpdateTranscript"];
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Flex,
|
Flex,
|
||||||
@@ -15,12 +17,13 @@ import {
|
|||||||
createListCollection,
|
createListCollection,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { LuShare2 } from "react-icons/lu";
|
import { LuShare2 } from "react-icons/lu";
|
||||||
import useApi from "../../lib/useApi";
|
import { useTranscriptUpdate } from "../../lib/apiHooks";
|
||||||
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;
|
||||||
@@ -50,12 +53,9 @@ 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 api = useApi();
|
const updateTranscriptMutation = useTranscriptUpdate();
|
||||||
|
|
||||||
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,19 +67,27 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
|||||||
share_mode: selectedValue as "public" | "semi-private" | "private",
|
share_mode: selectedValue as "public" | "semi-private" | "private",
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatedTranscript = await api.v1TranscriptUpdate({
|
try {
|
||||||
transcriptId: props.transcriptResponse.id,
|
const updatedTranscript = await updateTranscriptMutation.mutateAsync({
|
||||||
requestBody,
|
params: {
|
||||||
|
path: { transcript_id: props.transcriptResponse.id },
|
||||||
|
},
|
||||||
|
body: requestBody,
|
||||||
});
|
});
|
||||||
setShareMode(
|
setShareMode(
|
||||||
shareOptionsData.find(
|
shareOptionsData.find(
|
||||||
(option) => option.value === updatedTranscript.share_mode,
|
(option) => option.value === updatedTranscript.share_mode,
|
||||||
) || shareOptionsData[0],
|
) || shareOptionsData[0],
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to update share mode:", err);
|
||||||
|
} finally {
|
||||||
setShareLoading(false);
|
setShareLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const userId = useSessionUser().id;
|
const auth = useAuth();
|
||||||
|
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));
|
||||||
@@ -124,7 +132,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 && api && (
|
{isOwner && (
|
||||||
<Select.Root
|
<Select.Root
|
||||||
key={shareMode.value}
|
key={shareMode.value}
|
||||||
value={[shareMode.value || ""]}
|
value={[shareMode.value || ""]}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { GetTranscript, GetTranscriptTopic } from "../../api";
|
import type { components } from "../../reflector-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,8 +1,9 @@
|
|||||||
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,6 +1,8 @@
|
|||||||
import { useState, useEffect, useMemo } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import { featureEnabled } from "../../domainContext";
|
import type { components } from "../../reflector-api";
|
||||||
import { GetTranscript, GetTranscriptTopic } from "../../api";
|
|
||||||
|
type GetTranscript = components["schemas"]["GetTranscript"];
|
||||||
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
import {
|
import {
|
||||||
BoxProps,
|
BoxProps,
|
||||||
Button,
|
Button,
|
||||||
@@ -12,12 +14,16 @@ import {
|
|||||||
Checkbox,
|
Checkbox,
|
||||||
Combobox,
|
Combobox,
|
||||||
Spinner,
|
Spinner,
|
||||||
Portal,
|
createListCollection,
|
||||||
useFilter,
|
|
||||||
useListCollection,
|
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { TbBrandZulip } from "react-icons/tb";
|
import { TbBrandZulip } from "react-icons/tb";
|
||||||
import useApi from "../../lib/useApi";
|
import {
|
||||||
|
useZulipStreams,
|
||||||
|
useZulipTopics,
|
||||||
|
useTranscriptPostToZulip,
|
||||||
|
} from "../../lib/apiHooks";
|
||||||
|
|
||||||
|
import { featureEnabled } from "../../lib/features";
|
||||||
|
|
||||||
type ShareZulipProps = {
|
type ShareZulipProps = {
|
||||||
transcriptResponse: GetTranscript;
|
transcriptResponse: GetTranscript;
|
||||||
@@ -30,104 +36,77 @@ 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 {
|
const { data: streams = [], isLoading: isLoadingStreams } = useZulipStreams();
|
||||||
collection: streamItemsCollection,
|
const { data: topics = [] } = useZulipTopics(selectedStreamId);
|
||||||
filter: streamItemsFilter,
|
const postToZulipMutation = useTranscriptPostToZulip();
|
||||||
set: streamItemsSet,
|
|
||||||
} = useListCollection({
|
|
||||||
initialItems: [] as { label: string; value: string }[],
|
|
||||||
filter: contains,
|
|
||||||
});
|
|
||||||
|
|
||||||
const {
|
const streamItems = useMemo(() => {
|
||||||
collection: topicItemsCollection,
|
return streams.map((stream: Stream) => ({
|
||||||
filter: topicItemsFilter,
|
|
||||||
set: topicItemsSet,
|
|
||||||
} = useListCollection({
|
|
||||||
initialItems: [] as { label: string; value: string }[],
|
|
||||||
filter: contains,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchZulipStreams = async () => {
|
|
||||||
if (!api) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await api.v1ZulipGetStreams();
|
|
||||||
setStreams(response);
|
|
||||||
|
|
||||||
streamItemsSet(
|
|
||||||
response.map((stream) => ({
|
|
||||||
label: stream.name,
|
label: stream.name,
|
||||||
value: stream.name,
|
value: stream.name,
|
||||||
})),
|
}));
|
||||||
|
}, [streams]);
|
||||||
|
|
||||||
|
const topicItems = useMemo(() => {
|
||||||
|
return topics.map(({ name }) => ({
|
||||||
|
label: name,
|
||||||
|
value: name,
|
||||||
|
}));
|
||||||
|
}, [topics]);
|
||||||
|
|
||||||
|
const streamCollection = useMemo(
|
||||||
|
() =>
|
||||||
|
createListCollection({
|
||||||
|
items: streamItems,
|
||||||
|
}),
|
||||||
|
[streamItems],
|
||||||
);
|
);
|
||||||
|
|
||||||
setIsLoading(false);
|
const topicCollection = useMemo(
|
||||||
} catch (error) {
|
() =>
|
||||||
console.error("Error fetching Zulip streams:", error);
|
createListCollection({
|
||||||
}
|
items: topicItems,
|
||||||
};
|
}),
|
||||||
|
[topicItems],
|
||||||
fetchZulipStreams();
|
);
|
||||||
}, [!api]);
|
|
||||||
|
|
||||||
|
// Update selected stream ID when stream changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchZulipTopics = async () => {
|
if (stream && streams) {
|
||||||
if (!api || !stream) return;
|
const selectedStream = streams.find((s: Stream) => s.name === stream);
|
||||||
try {
|
setSelectedStreamId(selectedStream ? selectedStream.stream_id : null);
|
||||||
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 {
|
} else {
|
||||||
topicItemsSet([]);
|
setSelectedStreamId(null);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
}, [stream, streams]);
|
||||||
console.error("Error fetching Zulip topics:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchZulipTopics();
|
|
||||||
}, [stream, streams, api]);
|
|
||||||
|
|
||||||
const handleSendToZulip = async () => {
|
const handleSendToZulip = async () => {
|
||||||
if (!api || !props.transcriptResponse) return;
|
if (!props.transcriptResponse) return;
|
||||||
|
|
||||||
if (stream && topic) {
|
if (stream && topic) {
|
||||||
try {
|
try {
|
||||||
await api.v1TranscriptPostToZulip({
|
await postToZulipMutation.mutateAsync({
|
||||||
transcriptId: props.transcriptResponse.id,
|
params: {
|
||||||
|
path: {
|
||||||
|
transcript_id: props.transcriptResponse.id,
|
||||||
|
},
|
||||||
|
query: {
|
||||||
stream,
|
stream,
|
||||||
topic,
|
topic,
|
||||||
includeTopics,
|
include_topics: includeTopics,
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error("Error posting to Zulip:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -155,7 +134,7 @@ export default function ShareZulip(props: ShareZulipProps & BoxProps) {
|
|||||||
</Dialog.CloseTrigger>
|
</Dialog.CloseTrigger>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
<Dialog.Body>
|
<Dialog.Body>
|
||||||
{isLoading ? (
|
{isLoadingStreams ? (
|
||||||
<Flex justify="center" py={8}>
|
<Flex justify="center" py={8}>
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -178,15 +157,12 @@ 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={streamItemsCollection}
|
collection={streamCollection}
|
||||||
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",
|
||||||
@@ -203,7 +179,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>
|
||||||
{streamItemsCollection.items.map((item) => (
|
{streamItems.map((item) => (
|
||||||
<Combobox.Item key={item.value} item={item}>
|
<Combobox.Item key={item.value} item={item}>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Combobox.Item>
|
</Combobox.Item>
|
||||||
@@ -219,12 +195,9 @@ 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={topicItemsCollection}
|
collection={topicCollection}
|
||||||
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}
|
||||||
@@ -244,7 +217,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>
|
||||||
{topicItemsCollection.items.map((item) => (
|
{topicItems.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,6 +1,8 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { UpdateTranscript } from "../../api";
|
import type { components } from "../../reflector-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";
|
||||||
|
|
||||||
@@ -14,24 +16,27 @@ 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 api = useApi();
|
const updateTranscriptMutation = useTranscriptUpdate();
|
||||||
|
|
||||||
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,
|
||||||
};
|
};
|
||||||
const updatedTranscript = await api?.v1TranscriptUpdate({
|
await updateTranscriptMutation.mutateAsync({
|
||||||
transcriptId,
|
params: {
|
||||||
requestBody,
|
path: { transcript_id: transcriptId },
|
||||||
|
},
|
||||||
|
body: requestBody,
|
||||||
});
|
});
|
||||||
if (props.onUpdate) {
|
if (props.onUpdate) {
|
||||||
props.onUpdate(newTitle);
|
props.onUpdate(newTitle);
|
||||||
}
|
}
|
||||||
console.log("Updated transcript:", updatedTranscript);
|
console.log("Updated transcript title:", newTitle);
|
||||||
} 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,6 +1,7 @@
|
|||||||
import { useContext, useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { DomainContext } from "../../domainContext";
|
import { useTranscriptGet } from "../../lib/apiHooks";
|
||||||
import getApi from "../../lib/useApi";
|
import { useAuth } from "../../lib/AuthProvider";
|
||||||
|
import { API_URL } from "../../lib/apiClient";
|
||||||
|
|
||||||
export type Mp3Response = {
|
export type Mp3Response = {
|
||||||
media: HTMLMediaElement | null;
|
media: HTMLMediaElement | null;
|
||||||
@@ -17,14 +18,16 @@ 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 api = getApi();
|
const auth = useAuth();
|
||||||
const { api_url } = useContext(DomainContext);
|
const accessTokenInfo =
|
||||||
const accessTokenInfo = api?.httpRequest?.config?.TOKEN;
|
auth.status === "authenticated" ? auth.accessToken : null;
|
||||||
|
|
||||||
|
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);
|
||||||
@@ -52,27 +55,17 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
|
}, [navigator.serviceWorker, !serviceWorker, accessTokenInfo]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!transcriptId || !api || later) return;
|
if (!transcriptId || later || !transcript) 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);
|
||||||
|
|
||||||
// First fetch transcript info to check if audio is deleted
|
|
||||||
api
|
|
||||||
.v1TranscriptGet({ transcriptId })
|
|
||||||
.then((transcript) => {
|
|
||||||
if (stopped) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const deleted = transcript.audio_deleted || false;
|
const deleted = transcript.audio_deleted || false;
|
||||||
setAudioDeleted(deleted);
|
setAudioDeleted(deleted);
|
||||||
setTranscriptMetadataLoadingError(null);
|
|
||||||
|
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
// Audio is deleted, don't attempt to load it
|
// Audio is deleted, don't attempt to load it
|
||||||
@@ -84,7 +77,7 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
|
|
||||||
// Audio is not deleted, proceed to load it
|
// Audio is not deleted, proceed to load it
|
||||||
audioElement = document.createElement("audio");
|
audioElement = document.createElement("audio");
|
||||||
audioElement.src = `${api_url}/v1/transcripts/${transcriptId}/audio/mp3`;
|
audioElement.src = `${API_URL}/v1/transcripts/${transcriptId}/audio/mp3`;
|
||||||
audioElement.crossOrigin = "anonymous";
|
audioElement.crossOrigin = "anonymous";
|
||||||
audioElement.preload = "auto";
|
audioElement.preload = "auto";
|
||||||
|
|
||||||
@@ -106,18 +99,6 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
if (!stopped) {
|
if (!stopped) {
|
||||||
setMedia(audioElement);
|
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;
|
||||||
@@ -128,14 +109,18 @@ const useMp3 = (transcriptId: string, waiting?: boolean): Mp3Response => {
|
|||||||
if (handleError) audioElement.removeEventListener("error", handleError);
|
if (handleError) audioElement.removeEventListener("error", handleError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [transcriptId, api, later, api_url]);
|
}, [transcriptId, transcript, later]);
|
||||||
|
|
||||||
const getNow = () => {
|
const getNow = () => {
|
||||||
setLater(false);
|
setLater(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loading = audioLoading || transcriptMetadataLoading;
|
const loading = audioLoading || transcriptMetadataLoading;
|
||||||
const error = audioLoadingError || transcriptMetadataLoadingError;
|
const error =
|
||||||
|
audioLoadingError ||
|
||||||
|
(transcriptError
|
||||||
|
? (transcriptError as any).message || String(transcriptError)
|
||||||
|
: null);
|
||||||
|
|
||||||
return { media, loading, error, getNow, audioDeleted };
|
return { media, loading, error, getNow, audioDeleted };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { useEffect, useState } from "react";
|
import type { components } from "../../reflector-api";
|
||||||
import { Participant } from "../../api";
|
type Participant = components["schemas"]["Participant"];
|
||||||
import { useError } from "../../(errors)/errorContext";
|
import { useTranscriptParticipants } from "../../lib/apiHooks";
|
||||||
import useApi from "../../lib/useApi";
|
|
||||||
import { shouldShowError } from "../../lib/errorUtils";
|
|
||||||
|
|
||||||
type ErrorParticipants = {
|
type ErrorParticipants = {
|
||||||
error: Error;
|
error: Error;
|
||||||
@@ -29,46 +27,38 @@ export type UseParticipants = (
|
|||||||
) & { refetch: () => void };
|
) & { refetch: () => void };
|
||||||
|
|
||||||
const useParticipants = (transcriptId: string): UseParticipants => {
|
const useParticipants = (transcriptId: string): UseParticipants => {
|
||||||
const [response, setResponse] = useState<Participant[] | null>(null);
|
const {
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
data: response,
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
isLoading: loading,
|
||||||
const { setError } = useError();
|
error,
|
||||||
const api = useApi();
|
refetch,
|
||||||
const [count, setCount] = useState(0);
|
} = useTranscriptParticipants(transcriptId || null);
|
||||||
|
|
||||||
const refetch = () => {
|
// Type-safe return based on state
|
||||||
if (!loading) {
|
if (error) {
|
||||||
setCount(count + 1);
|
return {
|
||||||
setLoading(true);
|
error: error as Error,
|
||||||
setErrorState(null);
|
loading: false,
|
||||||
|
response: null,
|
||||||
|
refetch,
|
||||||
|
} satisfies ErrorParticipants & { refetch: () => void };
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
if (loading || !response) {
|
||||||
if (!transcriptId || !api) return;
|
return {
|
||||||
|
response: response || null,
|
||||||
setLoading(true);
|
loading: true,
|
||||||
api
|
error: null,
|
||||||
.v1TranscriptGetParticipants({ transcriptId })
|
refetch,
|
||||||
.then((result) => {
|
} satisfies LoadingParticipants & { refetch: () => void };
|
||||||
setResponse(result);
|
|
||||||
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;
|
return {
|
||||||
|
response,
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
refetch,
|
||||||
|
} satisfies SuccessParticipants & { refetch: () => void };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useParticipants;
|
export default useParticipants;
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
// 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,9 +1,8 @@
|
|||||||
import { useEffect, useState } from "react";
|
import type { components } from "../../reflector-api";
|
||||||
|
import { useTranscriptTopicsWithWordsPerSpeaker } from "../../lib/apiHooks";
|
||||||
|
|
||||||
import { GetTranscriptTopicWithWordsPerSpeaker } from "../../api";
|
type GetTranscriptTopicWithWordsPerSpeaker =
|
||||||
import { useError } from "../../(errors)/errorContext";
|
components["schemas"]["GetTranscriptTopicWithWordsPerSpeaker"];
|
||||||
import useApi from "../../lib/useApi";
|
|
||||||
import { shouldShowError } from "../../lib/errorUtils";
|
|
||||||
|
|
||||||
type ErrorTopicWithWords = {
|
type ErrorTopicWithWords = {
|
||||||
error: Error;
|
error: Error;
|
||||||
@@ -33,47 +32,40 @@ const useTopicWithWords = (
|
|||||||
topicId: string | undefined,
|
topicId: string | undefined,
|
||||||
transcriptId: string,
|
transcriptId: string,
|
||||||
): UseTopicWithWords => {
|
): UseTopicWithWords => {
|
||||||
const [response, setResponse] =
|
const {
|
||||||
useState<GetTranscriptTopicWithWordsPerSpeaker | null>(null);
|
data: response,
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
isLoading: loading,
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
error,
|
||||||
const { setError } = useError();
|
refetch,
|
||||||
const api = useApi();
|
} = useTranscriptTopicsWithWordsPerSpeaker(
|
||||||
|
transcriptId || null,
|
||||||
|
topicId || null,
|
||||||
|
);
|
||||||
|
|
||||||
const [count, setCount] = useState(0);
|
if (error) {
|
||||||
|
return {
|
||||||
const refetch = () => {
|
error: error as Error,
|
||||||
if (!loading) {
|
loading: false,
|
||||||
setCount(count + 1);
|
response: null,
|
||||||
setLoading(true);
|
refetch,
|
||||||
setErrorState(null);
|
} satisfies ErrorTopicWithWords & { refetch: () => void };
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
if (loading || !response) {
|
||||||
if (!transcriptId || !topicId || !api) return;
|
return {
|
||||||
|
response: response || null,
|
||||||
setLoading(true);
|
loading: true,
|
||||||
|
error: false,
|
||||||
api
|
refetch,
|
||||||
.v1TranscriptGetTopicsWithWordsPerSpeaker({ transcriptId, topicId })
|
} satisfies LoadingTopicWithWords & { refetch: () => void };
|
||||||
.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;
|
return {
|
||||||
|
response,
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
refetch,
|
||||||
|
} satisfies SuccessTopicWithWords & { refetch: () => void };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useTopicWithWords;
|
export default useTopicWithWords;
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useTranscriptTopics } from "../../lib/apiHooks";
|
||||||
|
import type { components } from "../../reflector-api";
|
||||||
|
|
||||||
import { useError } from "../../(errors)/errorContext";
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
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;
|
||||||
@@ -13,34 +10,13 @@ type TranscriptTopics = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useTopics = (id: string): TranscriptTopics => {
|
const useTopics = (id: string): TranscriptTopics => {
|
||||||
const [topics, setTopics] = useState<Topic[] | null>(null);
|
const { data: topics, isLoading: loading, error } = useTranscriptTopics(id);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
|
||||||
const { setError } = useError();
|
|
||||||
const api = useApi();
|
|
||||||
useEffect(() => {
|
|
||||||
if (!id || !api) return;
|
|
||||||
|
|
||||||
setLoading(true);
|
return {
|
||||||
api
|
topics: topics || null,
|
||||||
.v1TranscriptGetTopics({ transcriptId: id })
|
loading,
|
||||||
.then((result) => {
|
error: error as Error | null,
|
||||||
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;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
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,8 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import type { components } from "../../reflector-api";
|
||||||
import { AudioWaveform } from "../../api";
|
import { useTranscriptWaveform } from "../../lib/apiHooks";
|
||||||
import { useError } from "../../(errors)/errorContext";
|
|
||||||
import useApi from "../../lib/useApi";
|
type AudioWaveform = components["schemas"]["AudioWaveform"];
|
||||||
import { shouldShowError } from "../../lib/errorUtils";
|
|
||||||
|
|
||||||
type AudioWaveFormResponse = {
|
type AudioWaveFormResponse = {
|
||||||
waveform: AudioWaveform | null;
|
waveform: AudioWaveform | null;
|
||||||
@@ -11,35 +10,17 @@ type AudioWaveFormResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useWaveform = (id: string, skip: boolean): AudioWaveFormResponse => {
|
const useWaveform = (id: string, skip: boolean): AudioWaveFormResponse => {
|
||||||
const [waveform, setWaveform] = useState<AudioWaveform | null>(null);
|
const {
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
data: waveform,
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
isLoading: loading,
|
||||||
const { setError } = useError();
|
error,
|
||||||
const api = useApi();
|
} = useTranscriptWaveform(skip ? null : id);
|
||||||
|
|
||||||
useEffect(() => {
|
return {
|
||||||
if (!id || !api || skip) {
|
waveform: waveform || null,
|
||||||
setLoading(false);
|
loading,
|
||||||
setErrorState(null);
|
error: error as Error | 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,8 +1,9 @@
|
|||||||
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 useApi from "../../lib/useApi";
|
import { useTranscriptWebRTC } from "../../lib/apiHooks";
|
||||||
import { RtcOffer } from "../../api";
|
import type { components } from "../../reflector-api";
|
||||||
|
type RtcOffer = components["schemas"]["RtcOffer"];
|
||||||
|
|
||||||
const useWebRTC = (
|
const useWebRTC = (
|
||||||
stream: MediaStream | null,
|
stream: MediaStream | null,
|
||||||
@@ -10,10 +11,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 api = useApi();
|
const { mutateAsync: mutateWebRtcTranscriptAsync } = useTranscriptWebRTC();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!stream || !transcriptId || !api) {
|
if (!stream || !transcriptId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +25,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, "Error creating WebRTC");
|
setError(error as Error, "Error creating WebRTC");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,26 +33,31 @@ const useWebRTC = (
|
|||||||
setError(new Error(`WebRTC error: ${err}`));
|
setError(new Error(`WebRTC error: ${err}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
p.on("signal", (data: any) => {
|
p.on("signal", async (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,
|
||||||
};
|
};
|
||||||
|
|
||||||
api
|
try {
|
||||||
.v1TranscriptRecordWebrtc({ transcriptId, requestBody: rtcOffer })
|
const answer = await mutateWebRtcTranscriptAsync({
|
||||||
.then((answer) => {
|
params: {
|
||||||
|
path: {
|
||||||
|
transcript_id: transcriptId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: rtcOffer,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
p.signal(answer);
|
p.signal(answer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error);
|
setError(error as Error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setError(error as Error, "Error loading WebRTCOffer");
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
setError(error, "Error loading WebRTCOffer");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,7 +69,7 @@ const useWebRTC = (
|
|||||||
return () => {
|
return () => {
|
||||||
p.destroy();
|
p.destroy();
|
||||||
};
|
};
|
||||||
}, [stream, transcriptId, !api]);
|
}, [stream, transcriptId, mutateWebRtcTranscriptAsync]);
|
||||||
|
|
||||||
return peer;
|
return peer;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { useContext, useEffect, useState } from "react";
|
import { 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 { DomainContext } from "../../domainContext";
|
import type { components } from "../../reflector-api";
|
||||||
import { AudioWaveform, GetTranscriptSegmentTopic } from "../../api";
|
type AudioWaveform = components["schemas"]["AudioWaveform"];
|
||||||
import useApi from "../../lib/useApi";
|
type GetTranscriptSegmentTopic =
|
||||||
|
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;
|
||||||
@@ -12,7 +15,7 @@ export type UseWebSockets = {
|
|||||||
title: string;
|
title: string;
|
||||||
topics: Topic[];
|
topics: Topic[];
|
||||||
finalSummary: FinalSummary;
|
finalSummary: FinalSummary;
|
||||||
status: Status;
|
status: Status | null;
|
||||||
waveform: AudioWaveform | null;
|
waveform: AudioWaveform | null;
|
||||||
duration: number | null;
|
duration: number | null;
|
||||||
};
|
};
|
||||||
@@ -30,11 +33,10 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
const [finalSummary, setFinalSummary] = useState<FinalSummary>({
|
||||||
summary: "",
|
summary: "",
|
||||||
});
|
});
|
||||||
const [status, setStatus] = useState<Status>({ value: "" });
|
const [status, setStatus] = useState<Status | null>(null);
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
|
|
||||||
const { websocket_url } = useContext(DomainContext);
|
const queryClient = useQueryClient();
|
||||||
const api = useApi();
|
|
||||||
|
|
||||||
const [accumulatedText, setAccumulatedText] = useState<string>("");
|
const [accumulatedText, setAccumulatedText] = useState<string>("");
|
||||||
|
|
||||||
@@ -105,6 +107,13 @@ 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",
|
||||||
@@ -315,11 +324,9 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!transcriptId || !api) return;
|
if (!transcriptId) return;
|
||||||
|
|
||||||
api?.v1TranscriptGetWebsocketEvents({ transcriptId }).then((result) => {});
|
const url = `${WEBSOCKET_URL}/v1/transcripts/${transcriptId}/events`;
|
||||||
|
|
||||||
const url = `${websocket_url}/v1/transcripts/${transcriptId}/events`;
|
|
||||||
let ws = new WebSocket(url);
|
let ws = new WebSocket(url);
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
@@ -361,6 +368,16 @@ 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":
|
||||||
@@ -370,6 +387,16 @@ 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;
|
||||||
|
|
||||||
@@ -377,6 +404,16 @@ 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;
|
||||||
|
|
||||||
@@ -434,6 +471,11 @@ 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}`),
|
||||||
@@ -450,7 +492,7 @@ export const useWebSockets = (transcriptId: string | null): UseWebSockets => {
|
|||||||
return () => {
|
return () => {
|
||||||
ws.close();
|
ws.close();
|
||||||
};
|
};
|
||||||
}, [transcriptId, !api]);
|
}, [transcriptId]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
transcriptTextLive,
|
transcriptTextLive,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { GetTranscriptTopic } from "../../api";
|
import type { components } from "../../reflector-api";
|
||||||
|
import type { TranscriptStatus } from "../../lib/transcript";
|
||||||
|
|
||||||
|
type GetTranscriptTopic = components["schemas"]["GetTranscriptTopic"];
|
||||||
|
|
||||||
export type Topic = GetTranscriptTopic;
|
export type Topic = GetTranscriptTopic;
|
||||||
|
|
||||||
@@ -11,7 +14,7 @@ export type FinalSummary = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Status = {
|
export type Status = {
|
||||||
value: string;
|
value: TranscriptStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TranslatedTopic = {
|
export type TranslatedTopic = {
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { signOut, signIn } from "next-auth/react";
|
|
||||||
import useSessionStatus from "../lib/useSessionStatus";
|
|
||||||
import { Spinner, Link } from "@chakra-ui/react";
|
import { Spinner, Link } from "@chakra-ui/react";
|
||||||
|
import { useAuth } from "../lib/AuthProvider";
|
||||||
|
|
||||||
export default function UserInfo() {
|
export default function UserInfo() {
|
||||||
const { isLoading, isAuthenticated } = useSessionStatus();
|
const auth = useAuth();
|
||||||
|
const status = auth.status;
|
||||||
|
const isLoading = status === "loading";
|
||||||
|
const isAuthenticated = status === "authenticated";
|
||||||
|
const isRefreshing = status === "refreshing";
|
||||||
return isLoading ? (
|
return isLoading ? (
|
||||||
<Spinner size="xs" className="mx-3" />
|
<Spinner size="xs" className="mx-3" />
|
||||||
) : !isAuthenticated ? (
|
) : !isAuthenticated && !isRefreshing ? (
|
||||||
<Link
|
<Link
|
||||||
href="/"
|
href="/"
|
||||||
className="font-light px-2"
|
className="font-light px-2"
|
||||||
onClick={() => signIn("authentik")}
|
onClick={() => auth.signIn("authentik")}
|
||||||
>
|
>
|
||||||
Log in
|
Log in
|
||||||
</Link>
|
</Link>
|
||||||
@@ -20,7 +23,7 @@ export default function UserInfo() {
|
|||||||
<Link
|
<Link
|
||||||
href="#"
|
href="#"
|
||||||
className="font-light px-2"
|
className="font-light px-2"
|
||||||
onClick={() => signOut({ callbackUrl: "/" })}
|
onClick={() => auth.signOut({ callbackUrl: "/" })}
|
||||||
>
|
>
|
||||||
Log out
|
Log out
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
useContext,
|
useContext,
|
||||||
RefObject,
|
RefObject,
|
||||||
|
use,
|
||||||
} from "react";
|
} from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
@@ -21,16 +22,18 @@ import { toaster } from "../components/ui/toaster";
|
|||||||
import useRoomMeeting from "./useRoomMeeting";
|
import useRoomMeeting from "./useRoomMeeting";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import useSessionStatus from "../lib/useSessionStatus";
|
|
||||||
import { useRecordingConsent } from "../recordingConsentContext";
|
import { useRecordingConsent } from "../recordingConsentContext";
|
||||||
import useApi from "../lib/useApi";
|
import { useMeetingAudioConsent } from "../lib/apiHooks";
|
||||||
import { Meeting } from "../api";
|
import type { components } from "../reflector-api";
|
||||||
|
|
||||||
|
type Meeting = components["schemas"]["Meeting"];
|
||||||
import { FaBars } from "react-icons/fa6";
|
import { FaBars } from "react-icons/fa6";
|
||||||
|
import { useAuth } from "../lib/AuthProvider";
|
||||||
|
|
||||||
export type RoomDetails = {
|
export type RoomDetails = {
|
||||||
params: {
|
params: Promise<{
|
||||||
roomName: string;
|
roomName: string;
|
||||||
};
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// stages: we focus on the consent, then whereby steals focus, then we focus on the consent again, then return focus to whoever stole it initially
|
// stages: we focus on the consent, then whereby steals focus, then we focus on the consent again, then return focus to whoever stole it initially
|
||||||
@@ -76,31 +79,30 @@ const useConsentDialog = (
|
|||||||
wherebyRef: RefObject<HTMLElement> /*accessibility*/,
|
wherebyRef: RefObject<HTMLElement> /*accessibility*/,
|
||||||
) => {
|
) => {
|
||||||
const { state: consentState, touch, hasConsent } = useRecordingConsent();
|
const { state: consentState, touch, hasConsent } = useRecordingConsent();
|
||||||
const [consentLoading, setConsentLoading] = useState(false);
|
|
||||||
// toast would open duplicates, even with using "id=" prop
|
// toast would open duplicates, even with using "id=" prop
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const api = useApi();
|
const audioConsentMutation = useMeetingAudioConsent();
|
||||||
|
|
||||||
const handleConsent = useCallback(
|
const handleConsent = useCallback(
|
||||||
async (meetingId: string, given: boolean) => {
|
async (meetingId: string, given: boolean) => {
|
||||||
if (!api) return;
|
|
||||||
|
|
||||||
setConsentLoading(true);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.v1MeetingAudioConsent({
|
await audioConsentMutation.mutateAsync({
|
||||||
meetingId,
|
params: {
|
||||||
requestBody: { consent_given: given },
|
path: {
|
||||||
|
meeting_id: meetingId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
consent_given: given,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
touch(meetingId);
|
touch(meetingId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error submitting consent:", error);
|
console.error("Error submitting consent:", error);
|
||||||
} finally {
|
|
||||||
setConsentLoading(false);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[api, touch],
|
[audioConsentMutation, touch],
|
||||||
);
|
);
|
||||||
|
|
||||||
const showConsentModal = useCallback(() => {
|
const showConsentModal = useCallback(() => {
|
||||||
@@ -194,7 +196,12 @@ const useConsentDialog = (
|
|||||||
return cleanup;
|
return cleanup;
|
||||||
}, [meetingId, handleConsent, wherebyRef, modalOpen]);
|
}, [meetingId, handleConsent, wherebyRef, modalOpen]);
|
||||||
|
|
||||||
return { showConsentModal, consentState, hasConsent, consentLoading };
|
return {
|
||||||
|
showConsentModal,
|
||||||
|
consentState,
|
||||||
|
hasConsent,
|
||||||
|
consentLoading: audioConsentMutation.isPending,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function ConsentDialogButton({
|
function ConsentDialogButton({
|
||||||
@@ -249,12 +256,15 @@ const useWhereby = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function Room(details: RoomDetails) {
|
export default function Room(details: RoomDetails) {
|
||||||
|
const params = use(details.params);
|
||||||
const wherebyLoaded = useWhereby();
|
const wherebyLoaded = useWhereby();
|
||||||
const wherebyRef = useRef<HTMLElement>(null);
|
const wherebyRef = useRef<HTMLElement>(null);
|
||||||
const roomName = details.params.roomName;
|
const roomName = params.roomName;
|
||||||
const meeting = useRoomMeeting(roomName);
|
const meeting = useRoomMeeting(roomName);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { isLoading, isAuthenticated } = useSessionStatus();
|
const status = useAuth().status;
|
||||||
|
const isAuthenticated = status === "authenticated";
|
||||||
|
const isLoading = status === "loading" || meeting.loading;
|
||||||
|
|
||||||
const roomUrl = meeting?.response?.host_room_url
|
const roomUrl = meeting?.response?.host_room_url
|
||||||
? meeting?.response?.host_room_url
|
? meeting?.response?.host_room_url
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useError } from "../(errors)/errorContext";
|
import { useError } from "../(errors)/errorContext";
|
||||||
import { Meeting } from "../api";
|
import type { components } from "../reflector-api";
|
||||||
import { shouldShowError } from "../lib/errorUtils";
|
import { shouldShowError } from "../lib/errorUtils";
|
||||||
import useApi from "../lib/useApi";
|
|
||||||
|
type Meeting = components["schemas"]["Meeting"];
|
||||||
|
import { useRoomsCreateMeeting } from "../lib/apiHooks";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
type ErrorMeeting = {
|
type ErrorMeeting = {
|
||||||
@@ -30,27 +32,25 @@ const useRoomMeeting = (
|
|||||||
roomName: string | null | undefined,
|
roomName: string | null | undefined,
|
||||||
): ErrorMeeting | LoadingMeeting | SuccessMeeting => {
|
): ErrorMeeting | LoadingMeeting | SuccessMeeting => {
|
||||||
const [response, setResponse] = useState<Meeting | null>(null);
|
const [response, setResponse] = useState<Meeting | null>(null);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
|
||||||
const [error, setErrorState] = useState<Error | null>(null);
|
|
||||||
const [reload, setReload] = useState(0);
|
const [reload, setReload] = useState(0);
|
||||||
const { setError } = useError();
|
const { setError } = useError();
|
||||||
const api = useApi();
|
const createMeetingMutation = useRoomsCreateMeeting();
|
||||||
const reloadHandler = () => setReload((prev) => prev + 1);
|
const reloadHandler = () => setReload((prev) => prev + 1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!roomName || !api) return;
|
if (!roomName) return;
|
||||||
|
|
||||||
if (!response) {
|
const createMeeting = async () => {
|
||||||
setLoading(true);
|
try {
|
||||||
}
|
const result = await createMeetingMutation.mutateAsync({
|
||||||
|
params: {
|
||||||
api
|
path: {
|
||||||
.v1RoomsCreateMeeting({ roomName })
|
room_name: roomName,
|
||||||
.then((result) => {
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
setResponse(result);
|
setResponse(result);
|
||||||
setLoading(false);
|
} catch (error: any) {
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
const shouldShowHuman = shouldShowError(error);
|
const shouldShowHuman = shouldShowError(error);
|
||||||
if (shouldShowHuman && error.status !== 404) {
|
if (shouldShowHuman && error.status !== 404) {
|
||||||
setError(
|
setError(
|
||||||
@@ -60,9 +60,14 @@ const useRoomMeeting = (
|
|||||||
} else {
|
} else {
|
||||||
setError(error);
|
setError(error);
|
||||||
}
|
}
|
||||||
setErrorState(error);
|
}
|
||||||
});
|
};
|
||||||
}, [roomName, !api, reload]);
|
|
||||||
|
createMeeting();
|
||||||
|
}, [roomName, reload]);
|
||||||
|
|
||||||
|
const loading = createMeetingMutation.isPending && !response;
|
||||||
|
const error = createMeetingMutation.error as Error | null;
|
||||||
|
|
||||||
return { response, loading, error, reload: reloadHandler } as
|
return { response, loading, error, reload: reloadHandler } as
|
||||||
| ErrorMeeting
|
| ErrorMeeting
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import type { BaseHttpRequest } from "./core/BaseHttpRequest";
|
|
||||||
import type { OpenAPIConfig } from "./core/OpenAPI";
|
|
||||||
import { Interceptors } from "./core/OpenAPI";
|
|
||||||
import { AxiosHttpRequest } from "./core/AxiosHttpRequest";
|
|
||||||
|
|
||||||
import { DefaultService } from "./services.gen";
|
|
||||||
|
|
||||||
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
|
|
||||||
|
|
||||||
export class OpenApi {
|
|
||||||
public readonly default: DefaultService;
|
|
||||||
|
|
||||||
public readonly request: BaseHttpRequest;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
config?: Partial<OpenAPIConfig>,
|
|
||||||
HttpRequest: HttpRequestConstructor = AxiosHttpRequest,
|
|
||||||
) {
|
|
||||||
this.request = new HttpRequest({
|
|
||||||
BASE: config?.BASE ?? "",
|
|
||||||
VERSION: config?.VERSION ?? "0.1.0",
|
|
||||||
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
||||||
CREDENTIALS: config?.CREDENTIALS ?? "include",
|
|
||||||
TOKEN: config?.TOKEN,
|
|
||||||
USERNAME: config?.USERNAME,
|
|
||||||
PASSWORD: config?.PASSWORD,
|
|
||||||
HEADERS: config?.HEADERS,
|
|
||||||
ENCODE_PATH: config?.ENCODE_PATH,
|
|
||||||
interceptors: {
|
|
||||||
request: config?.interceptors?.request ?? new Interceptors(),
|
|
||||||
response: config?.interceptors?.response ?? new Interceptors(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.default = new DefaultService(this.request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
// NextAuth route handler for Authentik
|
|
||||||
// Refresh rotation has been taken from https://next-auth.js.org/v3/tutorials/refresh-token-rotation even if we are using 4.x
|
|
||||||
|
|
||||||
import NextAuth from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import { authOptions } from "../../../lib/auth";
|
import { authOptions } from "../../../lib/authBackend";
|
||||||
|
|
||||||
const handler = NextAuth(authOptions);
|
const handler = NextAuth(authOptions());
|
||||||
|
|
||||||
export { handler as GET, handler as POST };
|
export { handler as GET, handler as POST };
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
||||||
import type { ApiResult } from "./ApiResult";
|
|
||||||
|
|
||||||
export class ApiError extends Error {
|
|
||||||
public readonly url: string;
|
|
||||||
public readonly status: number;
|
|
||||||
public readonly statusText: string;
|
|
||||||
public readonly body: unknown;
|
|
||||||
public readonly request: ApiRequestOptions;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
request: ApiRequestOptions,
|
|
||||||
response: ApiResult,
|
|
||||||
message: string,
|
|
||||||
) {
|
|
||||||
super(message);
|
|
||||||
|
|
||||||
this.name = "ApiError";
|
|
||||||
this.url = response.url;
|
|
||||||
this.status = response.status;
|
|
||||||
this.statusText = response.statusText;
|
|
||||||
this.body = response.body;
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
export type ApiRequestOptions<T = unknown> = {
|
|
||||||
readonly method:
|
|
||||||
| "GET"
|
|
||||||
| "PUT"
|
|
||||||
| "POST"
|
|
||||||
| "DELETE"
|
|
||||||
| "OPTIONS"
|
|
||||||
| "HEAD"
|
|
||||||
| "PATCH";
|
|
||||||
readonly url: string;
|
|
||||||
readonly path?: Record<string, unknown>;
|
|
||||||
readonly cookies?: Record<string, unknown>;
|
|
||||||
readonly headers?: Record<string, unknown>;
|
|
||||||
readonly query?: Record<string, unknown>;
|
|
||||||
readonly formData?: Record<string, unknown>;
|
|
||||||
readonly body?: any;
|
|
||||||
readonly mediaType?: string;
|
|
||||||
readonly responseHeader?: string;
|
|
||||||
readonly responseTransformer?: (data: unknown) => Promise<T>;
|
|
||||||
readonly errors?: Record<number | string, string>;
|
|
||||||
};
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export type ApiResult<TData = any> = {
|
|
||||||
readonly body: TData;
|
|
||||||
readonly ok: boolean;
|
|
||||||
readonly status: number;
|
|
||||||
readonly statusText: string;
|
|
||||||
readonly url: string;
|
|
||||||
};
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
||||||
import { BaseHttpRequest } from "./BaseHttpRequest";
|
|
||||||
import type { CancelablePromise } from "./CancelablePromise";
|
|
||||||
import type { OpenAPIConfig } from "./OpenAPI";
|
|
||||||
import { request as __request } from "./request";
|
|
||||||
|
|
||||||
export class AxiosHttpRequest extends BaseHttpRequest {
|
|
||||||
constructor(config: OpenAPIConfig) {
|
|
||||||
super(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request method
|
|
||||||
* @param options The request options from the service
|
|
||||||
* @returns CancelablePromise<T>
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public override request<T>(
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
): CancelablePromise<T> {
|
|
||||||
return __request(this.config, options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
||||||
import type { CancelablePromise } from "./CancelablePromise";
|
|
||||||
import type { OpenAPIConfig } from "./OpenAPI";
|
|
||||||
|
|
||||||
export abstract class BaseHttpRequest {
|
|
||||||
constructor(public readonly config: OpenAPIConfig) {}
|
|
||||||
|
|
||||||
public abstract request<T>(
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
): CancelablePromise<T>;
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
export class CancelError extends Error {
|
|
||||||
constructor(message: string) {
|
|
||||||
super(message);
|
|
||||||
this.name = "CancelError";
|
|
||||||
}
|
|
||||||
|
|
||||||
public get isCancelled(): boolean {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface OnCancel {
|
|
||||||
readonly isResolved: boolean;
|
|
||||||
readonly isRejected: boolean;
|
|
||||||
readonly isCancelled: boolean;
|
|
||||||
|
|
||||||
(cancelHandler: () => void): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CancelablePromise<T> implements Promise<T> {
|
|
||||||
private _isResolved: boolean;
|
|
||||||
private _isRejected: boolean;
|
|
||||||
private _isCancelled: boolean;
|
|
||||||
readonly cancelHandlers: (() => void)[];
|
|
||||||
readonly promise: Promise<T>;
|
|
||||||
private _resolve?: (value: T | PromiseLike<T>) => void;
|
|
||||||
private _reject?: (reason?: unknown) => void;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
executor: (
|
|
||||||
resolve: (value: T | PromiseLike<T>) => void,
|
|
||||||
reject: (reason?: unknown) => void,
|
|
||||||
onCancel: OnCancel,
|
|
||||||
) => void,
|
|
||||||
) {
|
|
||||||
this._isResolved = false;
|
|
||||||
this._isRejected = false;
|
|
||||||
this._isCancelled = false;
|
|
||||||
this.cancelHandlers = [];
|
|
||||||
this.promise = new Promise<T>((resolve, reject) => {
|
|
||||||
this._resolve = resolve;
|
|
||||||
this._reject = reject;
|
|
||||||
|
|
||||||
const onResolve = (value: T | PromiseLike<T>): void => {
|
|
||||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._isResolved = true;
|
|
||||||
if (this._resolve) this._resolve(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onReject = (reason?: unknown): void => {
|
|
||||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._isRejected = true;
|
|
||||||
if (this._reject) this._reject(reason);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onCancel = (cancelHandler: () => void): void => {
|
|
||||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.cancelHandlers.push(cancelHandler);
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.defineProperty(onCancel, "isResolved", {
|
|
||||||
get: (): boolean => this._isResolved,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(onCancel, "isRejected", {
|
|
||||||
get: (): boolean => this._isRejected,
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.defineProperty(onCancel, "isCancelled", {
|
|
||||||
get: (): boolean => this._isCancelled,
|
|
||||||
});
|
|
||||||
|
|
||||||
return executor(onResolve, onReject, onCancel as OnCancel);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get [Symbol.toStringTag]() {
|
|
||||||
return "Cancellable Promise";
|
|
||||||
}
|
|
||||||
|
|
||||||
public then<TResult1 = T, TResult2 = never>(
|
|
||||||
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
|
||||||
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
|
|
||||||
): Promise<TResult1 | TResult2> {
|
|
||||||
return this.promise.then(onFulfilled, onRejected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public catch<TResult = never>(
|
|
||||||
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,
|
|
||||||
): Promise<T | TResult> {
|
|
||||||
return this.promise.catch(onRejected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public finally(onFinally?: (() => void) | null): Promise<T> {
|
|
||||||
return this.promise.finally(onFinally);
|
|
||||||
}
|
|
||||||
|
|
||||||
public cancel(): void {
|
|
||||||
if (this._isResolved || this._isRejected || this._isCancelled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._isCancelled = true;
|
|
||||||
if (this.cancelHandlers.length) {
|
|
||||||
try {
|
|
||||||
for (const cancelHandler of this.cancelHandlers) {
|
|
||||||
cancelHandler();
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn("Cancellation threw an error", error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.cancelHandlers.length = 0;
|
|
||||||
if (this._reject) this._reject(new CancelError("Request aborted"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public get isCancelled(): boolean {
|
|
||||||
return this._isCancelled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import type { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
||||||
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
||||||
|
|
||||||
type Headers = Record<string, string>;
|
|
||||||
type Middleware<T> = (value: T) => T | Promise<T>;
|
|
||||||
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
|
|
||||||
|
|
||||||
export class Interceptors<T> {
|
|
||||||
_fns: Middleware<T>[];
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this._fns = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
eject(fn: Middleware<T>): void {
|
|
||||||
const index = this._fns.indexOf(fn);
|
|
||||||
if (index !== -1) {
|
|
||||||
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use(fn: Middleware<T>): void {
|
|
||||||
this._fns = [...this._fns, fn];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type OpenAPIConfig = {
|
|
||||||
BASE: string;
|
|
||||||
CREDENTIALS: "include" | "omit" | "same-origin";
|
|
||||||
ENCODE_PATH?: ((path: string) => string) | undefined;
|
|
||||||
HEADERS?: Headers | Resolver<Headers> | undefined;
|
|
||||||
PASSWORD?: string | Resolver<string> | undefined;
|
|
||||||
TOKEN?: string | Resolver<string> | undefined;
|
|
||||||
USERNAME?: string | Resolver<string> | undefined;
|
|
||||||
VERSION: string;
|
|
||||||
WITH_CREDENTIALS: boolean;
|
|
||||||
interceptors: {
|
|
||||||
request: Interceptors<AxiosRequestConfig>;
|
|
||||||
response: Interceptors<AxiosResponse>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const OpenAPI: OpenAPIConfig = {
|
|
||||||
BASE: "",
|
|
||||||
CREDENTIALS: "include",
|
|
||||||
ENCODE_PATH: undefined,
|
|
||||||
HEADERS: undefined,
|
|
||||||
PASSWORD: undefined,
|
|
||||||
TOKEN: undefined,
|
|
||||||
USERNAME: undefined,
|
|
||||||
VERSION: "0.1.0",
|
|
||||||
WITH_CREDENTIALS: false,
|
|
||||||
interceptors: {
|
|
||||||
request: new Interceptors(),
|
|
||||||
response: new Interceptors(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,387 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import type {
|
|
||||||
AxiosError,
|
|
||||||
AxiosRequestConfig,
|
|
||||||
AxiosResponse,
|
|
||||||
AxiosInstance,
|
|
||||||
} from "axios";
|
|
||||||
|
|
||||||
import { ApiError } from "./ApiError";
|
|
||||||
import type { ApiRequestOptions } from "./ApiRequestOptions";
|
|
||||||
import type { ApiResult } from "./ApiResult";
|
|
||||||
import { CancelablePromise } from "./CancelablePromise";
|
|
||||||
import type { OnCancel } from "./CancelablePromise";
|
|
||||||
import type { OpenAPIConfig } from "./OpenAPI";
|
|
||||||
|
|
||||||
export const isString = (value: unknown): value is string => {
|
|
||||||
return typeof value === "string";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isStringWithValue = (value: unknown): value is string => {
|
|
||||||
return isString(value) && value !== "";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isBlob = (value: any): value is Blob => {
|
|
||||||
return value instanceof Blob;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isFormData = (value: unknown): value is FormData => {
|
|
||||||
return value instanceof FormData;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isSuccess = (status: number): boolean => {
|
|
||||||
return status >= 200 && status < 300;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const base64 = (str: string): string => {
|
|
||||||
try {
|
|
||||||
return btoa(str);
|
|
||||||
} catch (err) {
|
|
||||||
// @ts-ignore
|
|
||||||
return Buffer.from(str).toString("base64");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getQueryString = (params: Record<string, unknown>): string => {
|
|
||||||
const qs: string[] = [];
|
|
||||||
|
|
||||||
const append = (key: string, value: unknown) => {
|
|
||||||
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const encodePair = (key: string, value: unknown) => {
|
|
||||||
if (value === undefined || value === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value instanceof Date) {
|
|
||||||
append(key, value.toISOString());
|
|
||||||
} else if (Array.isArray(value)) {
|
|
||||||
value.forEach((v) => encodePair(key, v));
|
|
||||||
} else if (typeof value === "object") {
|
|
||||||
Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v));
|
|
||||||
} else {
|
|
||||||
append(key, value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.entries(params).forEach(([key, value]) => encodePair(key, value));
|
|
||||||
|
|
||||||
return qs.length ? `?${qs.join("&")}` : "";
|
|
||||||
};
|
|
||||||
|
|
||||||
const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => {
|
|
||||||
const encoder = config.ENCODE_PATH || encodeURI;
|
|
||||||
|
|
||||||
const path = options.url
|
|
||||||
.replace("{api-version}", config.VERSION)
|
|
||||||
.replace(/{(.*?)}/g, (substring: string, group: string) => {
|
|
||||||
if (options.path?.hasOwnProperty(group)) {
|
|
||||||
return encoder(String(options.path[group]));
|
|
||||||
}
|
|
||||||
return substring;
|
|
||||||
});
|
|
||||||
|
|
||||||
const url = config.BASE + path;
|
|
||||||
return options.query ? url + getQueryString(options.query) : url;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFormData = (
|
|
||||||
options: ApiRequestOptions,
|
|
||||||
): FormData | undefined => {
|
|
||||||
if (options.formData) {
|
|
||||||
const formData = new FormData();
|
|
||||||
|
|
||||||
const process = (key: string, value: unknown) => {
|
|
||||||
if (isString(value) || isBlob(value)) {
|
|
||||||
formData.append(key, value);
|
|
||||||
} else {
|
|
||||||
formData.append(key, JSON.stringify(value));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.entries(options.formData)
|
|
||||||
.filter(([, value]) => value !== undefined && value !== null)
|
|
||||||
.forEach(([key, value]) => {
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
value.forEach((v) => process(key, v));
|
|
||||||
} else {
|
|
||||||
process(key, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return formData;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
|
|
||||||
|
|
||||||
export const resolve = async <T>(
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
resolver?: T | Resolver<T>,
|
|
||||||
): Promise<T | undefined> => {
|
|
||||||
if (typeof resolver === "function") {
|
|
||||||
return (resolver as Resolver<T>)(options);
|
|
||||||
}
|
|
||||||
return resolver;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getHeaders = async <T>(
|
|
||||||
config: OpenAPIConfig,
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
): Promise<Record<string, string>> => {
|
|
||||||
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
||||||
// @ts-ignore
|
|
||||||
resolve(options, config.TOKEN),
|
|
||||||
// @ts-ignore
|
|
||||||
resolve(options, config.USERNAME),
|
|
||||||
// @ts-ignore
|
|
||||||
resolve(options, config.PASSWORD),
|
|
||||||
// @ts-ignore
|
|
||||||
resolve(options, config.HEADERS),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const headers = Object.entries({
|
|
||||||
Accept: "application/json",
|
|
||||||
...additionalHeaders,
|
|
||||||
...options.headers,
|
|
||||||
})
|
|
||||||
.filter(([, value]) => value !== undefined && value !== null)
|
|
||||||
.reduce(
|
|
||||||
(headers, [key, value]) => ({
|
|
||||||
...headers,
|
|
||||||
[key]: String(value),
|
|
||||||
}),
|
|
||||||
{} as Record<string, string>,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isStringWithValue(token)) {
|
|
||||||
headers["Authorization"] = `Bearer ${token}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
||||||
const credentials = base64(`${username}:${password}`);
|
|
||||||
headers["Authorization"] = `Basic ${credentials}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.body !== undefined) {
|
|
||||||
if (options.mediaType) {
|
|
||||||
headers["Content-Type"] = options.mediaType;
|
|
||||||
} else if (isBlob(options.body)) {
|
|
||||||
headers["Content-Type"] = options.body.type || "application/octet-stream";
|
|
||||||
} else if (isString(options.body)) {
|
|
||||||
headers["Content-Type"] = "text/plain";
|
|
||||||
} else if (!isFormData(options.body)) {
|
|
||||||
headers["Content-Type"] = "application/json";
|
|
||||||
}
|
|
||||||
} else if (options.formData !== undefined) {
|
|
||||||
if (options.mediaType) {
|
|
||||||
headers["Content-Type"] = options.mediaType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getRequestBody = (options: ApiRequestOptions): unknown => {
|
|
||||||
if (options.body) {
|
|
||||||
return options.body;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const sendRequest = async <T>(
|
|
||||||
config: OpenAPIConfig,
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
url: string,
|
|
||||||
body: unknown,
|
|
||||||
formData: FormData | undefined,
|
|
||||||
headers: Record<string, string>,
|
|
||||||
onCancel: OnCancel,
|
|
||||||
axiosClient: AxiosInstance,
|
|
||||||
): Promise<AxiosResponse<T>> => {
|
|
||||||
const controller = new AbortController();
|
|
||||||
|
|
||||||
let requestConfig: AxiosRequestConfig = {
|
|
||||||
data: body ?? formData,
|
|
||||||
headers,
|
|
||||||
method: options.method,
|
|
||||||
signal: controller.signal,
|
|
||||||
url,
|
|
||||||
withCredentials: config.WITH_CREDENTIALS,
|
|
||||||
};
|
|
||||||
|
|
||||||
onCancel(() => controller.abort());
|
|
||||||
|
|
||||||
for (const fn of config.interceptors.request._fns) {
|
|
||||||
requestConfig = await fn(requestConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return await axiosClient.request(requestConfig);
|
|
||||||
} catch (error) {
|
|
||||||
const axiosError = error as AxiosError<T>;
|
|
||||||
if (axiosError.response) {
|
|
||||||
return axiosError.response;
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getResponseHeader = (
|
|
||||||
response: AxiosResponse<unknown>,
|
|
||||||
responseHeader?: string,
|
|
||||||
): string | undefined => {
|
|
||||||
if (responseHeader) {
|
|
||||||
const content = response.headers[responseHeader];
|
|
||||||
if (isString(content)) {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getResponseBody = (response: AxiosResponse<unknown>): unknown => {
|
|
||||||
if (response.status !== 204) {
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const catchErrorCodes = (
|
|
||||||
options: ApiRequestOptions,
|
|
||||||
result: ApiResult,
|
|
||||||
): void => {
|
|
||||||
const errors: Record<number, string> = {
|
|
||||||
400: "Bad Request",
|
|
||||||
401: "Unauthorized",
|
|
||||||
402: "Payment Required",
|
|
||||||
403: "Forbidden",
|
|
||||||
404: "Not Found",
|
|
||||||
405: "Method Not Allowed",
|
|
||||||
406: "Not Acceptable",
|
|
||||||
407: "Proxy Authentication Required",
|
|
||||||
408: "Request Timeout",
|
|
||||||
409: "Conflict",
|
|
||||||
410: "Gone",
|
|
||||||
411: "Length Required",
|
|
||||||
412: "Precondition Failed",
|
|
||||||
413: "Payload Too Large",
|
|
||||||
414: "URI Too Long",
|
|
||||||
415: "Unsupported Media Type",
|
|
||||||
416: "Range Not Satisfiable",
|
|
||||||
417: "Expectation Failed",
|
|
||||||
418: "Im a teapot",
|
|
||||||
421: "Misdirected Request",
|
|
||||||
422: "Unprocessable Content",
|
|
||||||
423: "Locked",
|
|
||||||
424: "Failed Dependency",
|
|
||||||
425: "Too Early",
|
|
||||||
426: "Upgrade Required",
|
|
||||||
428: "Precondition Required",
|
|
||||||
429: "Too Many Requests",
|
|
||||||
431: "Request Header Fields Too Large",
|
|
||||||
451: "Unavailable For Legal Reasons",
|
|
||||||
500: "Internal Server Error",
|
|
||||||
501: "Not Implemented",
|
|
||||||
502: "Bad Gateway",
|
|
||||||
503: "Service Unavailable",
|
|
||||||
504: "Gateway Timeout",
|
|
||||||
505: "HTTP Version Not Supported",
|
|
||||||
506: "Variant Also Negotiates",
|
|
||||||
507: "Insufficient Storage",
|
|
||||||
508: "Loop Detected",
|
|
||||||
510: "Not Extended",
|
|
||||||
511: "Network Authentication Required",
|
|
||||||
...options.errors,
|
|
||||||
};
|
|
||||||
|
|
||||||
const error = errors[result.status];
|
|
||||||
if (error) {
|
|
||||||
throw new ApiError(options, result, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const errorStatus = result.status ?? "unknown";
|
|
||||||
const errorStatusText = result.statusText ?? "unknown";
|
|
||||||
const errorBody = (() => {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(result.body, null, 2);
|
|
||||||
} catch (e) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
throw new ApiError(
|
|
||||||
options,
|
|
||||||
result,
|
|
||||||
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request method
|
|
||||||
* @param config The OpenAPI configuration object
|
|
||||||
* @param options The request options from the service
|
|
||||||
* @param axiosClient The axios client instance to use
|
|
||||||
* @returns CancelablePromise<T>
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
export const request = <T>(
|
|
||||||
config: OpenAPIConfig,
|
|
||||||
options: ApiRequestOptions<T>,
|
|
||||||
axiosClient: AxiosInstance = axios,
|
|
||||||
): CancelablePromise<T> => {
|
|
||||||
return new CancelablePromise(async (resolve, reject, onCancel) => {
|
|
||||||
try {
|
|
||||||
const url = getUrl(config, options);
|
|
||||||
const formData = getFormData(options);
|
|
||||||
const body = getRequestBody(options);
|
|
||||||
const headers = await getHeaders(config, options);
|
|
||||||
|
|
||||||
if (!onCancel.isCancelled) {
|
|
||||||
let response = await sendRequest<T>(
|
|
||||||
config,
|
|
||||||
options,
|
|
||||||
url,
|
|
||||||
body,
|
|
||||||
formData,
|
|
||||||
headers,
|
|
||||||
onCancel,
|
|
||||||
axiosClient,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const fn of config.interceptors.response._fns) {
|
|
||||||
response = await fn(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
const responseBody = getResponseBody(response);
|
|
||||||
const responseHeader = getResponseHeader(
|
|
||||||
response,
|
|
||||||
options.responseHeader,
|
|
||||||
);
|
|
||||||
|
|
||||||
let transformedBody = responseBody;
|
|
||||||
if (options.responseTransformer && isSuccess(response.status)) {
|
|
||||||
transformedBody = await options.responseTransformer(responseBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: ApiResult = {
|
|
||||||
url,
|
|
||||||
ok: isSuccess(response.status),
|
|
||||||
status: response.status,
|
|
||||||
statusText: response.statusText,
|
|
||||||
body: responseHeader ?? transformedBody,
|
|
||||||
};
|
|
||||||
|
|
||||||
catchErrorCodes(options, result);
|
|
||||||
|
|
||||||
resolve(result.body);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// This file is auto-generated by @hey-api/openapi-ts
|
|
||||||
export { OpenApi } from "./OpenApi";
|
|
||||||
export { ApiError } from "./core/ApiError";
|
|
||||||
export { BaseHttpRequest } from "./core/BaseHttpRequest";
|
|
||||||
export { CancelablePromise, CancelError } from "./core/CancelablePromise";
|
|
||||||
export { OpenAPI, type OpenAPIConfig } from "./core/OpenAPI";
|
|
||||||
export * from "./schemas.gen";
|
|
||||||
export * from "./services.gen";
|
|
||||||
export * from "./types.gen";
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,942 +0,0 @@
|
|||||||
// This file is auto-generated by @hey-api/openapi-ts
|
|
||||||
|
|
||||||
import type { CancelablePromise } from "./core/CancelablePromise";
|
|
||||||
import type { BaseHttpRequest } from "./core/BaseHttpRequest";
|
|
||||||
import type {
|
|
||||||
MetricsResponse,
|
|
||||||
V1MeetingAudioConsentData,
|
|
||||||
V1MeetingAudioConsentResponse,
|
|
||||||
V1RoomsListData,
|
|
||||||
V1RoomsListResponse,
|
|
||||||
V1RoomsCreateData,
|
|
||||||
V1RoomsCreateResponse,
|
|
||||||
V1RoomsGetData,
|
|
||||||
V1RoomsGetResponse,
|
|
||||||
V1RoomsUpdateData,
|
|
||||||
V1RoomsUpdateResponse,
|
|
||||||
V1RoomsDeleteData,
|
|
||||||
V1RoomsDeleteResponse,
|
|
||||||
V1RoomsCreateMeetingData,
|
|
||||||
V1RoomsCreateMeetingResponse,
|
|
||||||
V1RoomsTestWebhookData,
|
|
||||||
V1RoomsTestWebhookResponse,
|
|
||||||
V1TranscriptsListData,
|
|
||||||
V1TranscriptsListResponse,
|
|
||||||
V1TranscriptsCreateData,
|
|
||||||
V1TranscriptsCreateResponse,
|
|
||||||
V1TranscriptsSearchData,
|
|
||||||
V1TranscriptsSearchResponse,
|
|
||||||
V1TranscriptGetData,
|
|
||||||
V1TranscriptGetResponse,
|
|
||||||
V1TranscriptUpdateData,
|
|
||||||
V1TranscriptUpdateResponse,
|
|
||||||
V1TranscriptDeleteData,
|
|
||||||
V1TranscriptDeleteResponse,
|
|
||||||
V1TranscriptGetTopicsData,
|
|
||||||
V1TranscriptGetTopicsResponse,
|
|
||||||
V1TranscriptGetTopicsWithWordsData,
|
|
||||||
V1TranscriptGetTopicsWithWordsResponse,
|
|
||||||
V1TranscriptGetTopicsWithWordsPerSpeakerData,
|
|
||||||
V1TranscriptGetTopicsWithWordsPerSpeakerResponse,
|
|
||||||
V1TranscriptPostToZulipData,
|
|
||||||
V1TranscriptPostToZulipResponse,
|
|
||||||
V1TranscriptHeadAudioMp3Data,
|
|
||||||
V1TranscriptHeadAudioMp3Response,
|
|
||||||
V1TranscriptGetAudioMp3Data,
|
|
||||||
V1TranscriptGetAudioMp3Response,
|
|
||||||
V1TranscriptGetAudioWaveformData,
|
|
||||||
V1TranscriptGetAudioWaveformResponse,
|
|
||||||
V1TranscriptGetParticipantsData,
|
|
||||||
V1TranscriptGetParticipantsResponse,
|
|
||||||
V1TranscriptAddParticipantData,
|
|
||||||
V1TranscriptAddParticipantResponse,
|
|
||||||
V1TranscriptGetParticipantData,
|
|
||||||
V1TranscriptGetParticipantResponse,
|
|
||||||
V1TranscriptUpdateParticipantData,
|
|
||||||
V1TranscriptUpdateParticipantResponse,
|
|
||||||
V1TranscriptDeleteParticipantData,
|
|
||||||
V1TranscriptDeleteParticipantResponse,
|
|
||||||
V1TranscriptAssignSpeakerData,
|
|
||||||
V1TranscriptAssignSpeakerResponse,
|
|
||||||
V1TranscriptMergeSpeakerData,
|
|
||||||
V1TranscriptMergeSpeakerResponse,
|
|
||||||
V1TranscriptRecordUploadData,
|
|
||||||
V1TranscriptRecordUploadResponse,
|
|
||||||
V1TranscriptGetWebsocketEventsData,
|
|
||||||
V1TranscriptGetWebsocketEventsResponse,
|
|
||||||
V1TranscriptRecordWebrtcData,
|
|
||||||
V1TranscriptRecordWebrtcResponse,
|
|
||||||
V1TranscriptProcessData,
|
|
||||||
V1TranscriptProcessResponse,
|
|
||||||
V1UserMeResponse,
|
|
||||||
V1ZulipGetStreamsResponse,
|
|
||||||
V1ZulipGetTopicsData,
|
|
||||||
V1ZulipGetTopicsResponse,
|
|
||||||
V1WherebyWebhookData,
|
|
||||||
V1WherebyWebhookResponse,
|
|
||||||
} from "./types.gen";
|
|
||||||
|
|
||||||
export class DefaultService {
|
|
||||||
constructor(public readonly httpRequest: BaseHttpRequest) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Metrics
|
|
||||||
* Endpoint that serves Prometheus metrics.
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public metrics(): CancelablePromise<MetricsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/metrics",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Meeting Audio Consent
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.meetingId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1MeetingAudioConsent(
|
|
||||||
data: V1MeetingAudioConsentData,
|
|
||||||
): CancelablePromise<V1MeetingAudioConsentResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/meetings/{meeting_id}/consent",
|
|
||||||
path: {
|
|
||||||
meeting_id: data.meetingId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms List
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.page Page number
|
|
||||||
* @param data.size Page size
|
|
||||||
* @returns Page_RoomDetails_ Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsList(
|
|
||||||
data: V1RoomsListData = {},
|
|
||||||
): CancelablePromise<V1RoomsListResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/rooms",
|
|
||||||
query: {
|
|
||||||
page: data.page,
|
|
||||||
size: data.size,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Create
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns Room Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsCreate(
|
|
||||||
data: V1RoomsCreateData,
|
|
||||||
): CancelablePromise<V1RoomsCreateResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/rooms",
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Get
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.roomId
|
|
||||||
* @returns RoomDetails Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsGet(
|
|
||||||
data: V1RoomsGetData,
|
|
||||||
): CancelablePromise<V1RoomsGetResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/rooms/{room_id}",
|
|
||||||
path: {
|
|
||||||
room_id: data.roomId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Update
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.roomId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns RoomDetails Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsUpdate(
|
|
||||||
data: V1RoomsUpdateData,
|
|
||||||
): CancelablePromise<V1RoomsUpdateResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: "/v1/rooms/{room_id}",
|
|
||||||
path: {
|
|
||||||
room_id: data.roomId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Delete
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.roomId
|
|
||||||
* @returns DeletionStatus Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsDelete(
|
|
||||||
data: V1RoomsDeleteData,
|
|
||||||
): CancelablePromise<V1RoomsDeleteResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "DELETE",
|
|
||||||
url: "/v1/rooms/{room_id}",
|
|
||||||
path: {
|
|
||||||
room_id: data.roomId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Create Meeting
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.roomName
|
|
||||||
* @returns Meeting Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsCreateMeeting(
|
|
||||||
data: V1RoomsCreateMeetingData,
|
|
||||||
): CancelablePromise<V1RoomsCreateMeetingResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/rooms/{room_name}/meeting",
|
|
||||||
path: {
|
|
||||||
room_name: data.roomName,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rooms Test Webhook
|
|
||||||
* Test webhook configuration by sending a sample payload.
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.roomId
|
|
||||||
* @returns WebhookTestResult Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1RoomsTestWebhook(
|
|
||||||
data: V1RoomsTestWebhookData,
|
|
||||||
): CancelablePromise<V1RoomsTestWebhookResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/rooms/{room_id}/webhook/test",
|
|
||||||
path: {
|
|
||||||
room_id: data.roomId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcripts List
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.sourceKind
|
|
||||||
* @param data.roomId
|
|
||||||
* @param data.searchTerm
|
|
||||||
* @param data.page Page number
|
|
||||||
* @param data.size Page size
|
|
||||||
* @returns Page_GetTranscriptMinimal_ Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptsList(
|
|
||||||
data: V1TranscriptsListData = {},
|
|
||||||
): CancelablePromise<V1TranscriptsListResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts",
|
|
||||||
query: {
|
|
||||||
source_kind: data.sourceKind,
|
|
||||||
room_id: data.roomId,
|
|
||||||
search_term: data.searchTerm,
|
|
||||||
page: data.page,
|
|
||||||
size: data.size,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcripts Create
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns GetTranscript Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptsCreate(
|
|
||||||
data: V1TranscriptsCreateData,
|
|
||||||
): CancelablePromise<V1TranscriptsCreateResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts",
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcripts Search
|
|
||||||
* Full-text search across transcript titles and content.
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.q Search query text
|
|
||||||
* @param data.limit Results per page
|
|
||||||
* @param data.offset Number of results to skip
|
|
||||||
* @param data.roomId
|
|
||||||
* @param data.sourceKind
|
|
||||||
* @returns SearchResponse Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptsSearch(
|
|
||||||
data: V1TranscriptsSearchData,
|
|
||||||
): CancelablePromise<V1TranscriptsSearchResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/search",
|
|
||||||
query: {
|
|
||||||
q: data.q,
|
|
||||||
limit: data.limit,
|
|
||||||
offset: data.offset,
|
|
||||||
room_id: data.roomId,
|
|
||||||
source_kind: data.sourceKind,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns GetTranscript Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGet(
|
|
||||||
data: V1TranscriptGetData,
|
|
||||||
): CancelablePromise<V1TranscriptGetResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Update
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns GetTranscript Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptUpdate(
|
|
||||||
data: V1TranscriptUpdateData,
|
|
||||||
): CancelablePromise<V1TranscriptUpdateResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: "/v1/transcripts/{transcript_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Delete
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns DeletionStatus Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptDelete(
|
|
||||||
data: V1TranscriptDeleteData,
|
|
||||||
): CancelablePromise<V1TranscriptDeleteResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "DELETE",
|
|
||||||
url: "/v1/transcripts/{transcript_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Topics
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns GetTranscriptTopic Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetTopics(
|
|
||||||
data: V1TranscriptGetTopicsData,
|
|
||||||
): CancelablePromise<V1TranscriptGetTopicsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/topics",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Topics With Words
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns GetTranscriptTopicWithWords Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetTopicsWithWords(
|
|
||||||
data: V1TranscriptGetTopicsWithWordsData,
|
|
||||||
): CancelablePromise<V1TranscriptGetTopicsWithWordsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/topics/with-words",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Topics With Words Per Speaker
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.topicId
|
|
||||||
* @returns GetTranscriptTopicWithWordsPerSpeaker Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetTopicsWithWordsPerSpeaker(
|
|
||||||
data: V1TranscriptGetTopicsWithWordsPerSpeakerData,
|
|
||||||
): CancelablePromise<V1TranscriptGetTopicsWithWordsPerSpeakerResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/topics/{topic_id}/words-per-speaker",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
topic_id: data.topicId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Post To Zulip
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.stream
|
|
||||||
* @param data.topic
|
|
||||||
* @param data.includeTopics
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptPostToZulip(
|
|
||||||
data: V1TranscriptPostToZulipData,
|
|
||||||
): CancelablePromise<V1TranscriptPostToZulipResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/zulip",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
stream: data.stream,
|
|
||||||
topic: data.topic,
|
|
||||||
include_topics: data.includeTopics,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Audio Mp3
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.token
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptHeadAudioMp3(
|
|
||||||
data: V1TranscriptHeadAudioMp3Data,
|
|
||||||
): CancelablePromise<V1TranscriptHeadAudioMp3Response> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "HEAD",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/audio/mp3",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
token: data.token,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Audio Mp3
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.token
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetAudioMp3(
|
|
||||||
data: V1TranscriptGetAudioMp3Data,
|
|
||||||
): CancelablePromise<V1TranscriptGetAudioMp3Response> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/audio/mp3",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
token: data.token,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Audio Waveform
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns AudioWaveform Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetAudioWaveform(
|
|
||||||
data: V1TranscriptGetAudioWaveformData,
|
|
||||||
): CancelablePromise<V1TranscriptGetAudioWaveformResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/audio/waveform",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Participants
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns Participant Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetParticipants(
|
|
||||||
data: V1TranscriptGetParticipantsData,
|
|
||||||
): CancelablePromise<V1TranscriptGetParticipantsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/participants",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Add Participant
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns Participant Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptAddParticipant(
|
|
||||||
data: V1TranscriptAddParticipantData,
|
|
||||||
): CancelablePromise<V1TranscriptAddParticipantResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/participants",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Participant
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.participantId
|
|
||||||
* @returns Participant Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetParticipant(
|
|
||||||
data: V1TranscriptGetParticipantData,
|
|
||||||
): CancelablePromise<V1TranscriptGetParticipantResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/participants/{participant_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
participant_id: data.participantId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Update Participant
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.participantId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns Participant Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptUpdateParticipant(
|
|
||||||
data: V1TranscriptUpdateParticipantData,
|
|
||||||
): CancelablePromise<V1TranscriptUpdateParticipantResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/participants/{participant_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
participant_id: data.participantId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Delete Participant
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.participantId
|
|
||||||
* @returns DeletionStatus Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptDeleteParticipant(
|
|
||||||
data: V1TranscriptDeleteParticipantData,
|
|
||||||
): CancelablePromise<V1TranscriptDeleteParticipantResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "DELETE",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/participants/{participant_id}",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
participant_id: data.participantId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Assign Speaker
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns SpeakerAssignmentStatus Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptAssignSpeaker(
|
|
||||||
data: V1TranscriptAssignSpeakerData,
|
|
||||||
): CancelablePromise<V1TranscriptAssignSpeakerResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/speaker/assign",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Merge Speaker
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns SpeakerAssignmentStatus Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptMergeSpeaker(
|
|
||||||
data: V1TranscriptMergeSpeakerData,
|
|
||||||
): CancelablePromise<V1TranscriptMergeSpeakerResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "PATCH",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/speaker/merge",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Record Upload
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.chunkNumber
|
|
||||||
* @param data.totalChunks
|
|
||||||
* @param data.formData
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptRecordUpload(
|
|
||||||
data: V1TranscriptRecordUploadData,
|
|
||||||
): CancelablePromise<V1TranscriptRecordUploadResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/record/upload",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
query: {
|
|
||||||
chunk_number: data.chunkNumber,
|
|
||||||
total_chunks: data.totalChunks,
|
|
||||||
},
|
|
||||||
formData: data.formData,
|
|
||||||
mediaType: "multipart/form-data",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Get Websocket Events
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptGetWebsocketEvents(
|
|
||||||
data: V1TranscriptGetWebsocketEventsData,
|
|
||||||
): CancelablePromise<V1TranscriptGetWebsocketEventsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/events",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Record Webrtc
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptRecordWebrtc(
|
|
||||||
data: V1TranscriptRecordWebrtcData,
|
|
||||||
): CancelablePromise<V1TranscriptRecordWebrtcResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/record/webrtc",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transcript Process
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.transcriptId
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1TranscriptProcess(
|
|
||||||
data: V1TranscriptProcessData,
|
|
||||||
): CancelablePromise<V1TranscriptProcessResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/transcripts/{transcript_id}/process",
|
|
||||||
path: {
|
|
||||||
transcript_id: data.transcriptId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User Me
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1UserMe(): CancelablePromise<V1UserMeResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/me",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zulip Get Streams
|
|
||||||
* Get all Zulip streams.
|
|
||||||
* @returns Stream Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1ZulipGetStreams(): CancelablePromise<V1ZulipGetStreamsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/zulip/streams",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Zulip Get Topics
|
|
||||||
* Get all topics for a specific Zulip stream.
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.streamId
|
|
||||||
* @returns Topic Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1ZulipGetTopics(
|
|
||||||
data: V1ZulipGetTopicsData,
|
|
||||||
): CancelablePromise<V1ZulipGetTopicsResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "GET",
|
|
||||||
url: "/v1/zulip/streams/{stream_id}/topics",
|
|
||||||
path: {
|
|
||||||
stream_id: data.streamId,
|
|
||||||
},
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whereby Webhook
|
|
||||||
* @param data The data for the request.
|
|
||||||
* @param data.requestBody
|
|
||||||
* @returns unknown Successful Response
|
|
||||||
* @throws ApiError
|
|
||||||
*/
|
|
||||||
public v1WherebyWebhook(
|
|
||||||
data: V1WherebyWebhookData,
|
|
||||||
): CancelablePromise<V1WherebyWebhookResponse> {
|
|
||||||
return this.httpRequest.request({
|
|
||||||
method: "POST",
|
|
||||||
url: "/v1/whereby",
|
|
||||||
body: data.requestBody,
|
|
||||||
mediaType: "application/json",
|
|
||||||
errors: {
|
|
||||||
422: "Validation Error",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,2 +1 @@
|
|||||||
// TODO better connection with generated schema; it's duplication
|
|
||||||
export const RECORD_A_MEETING_URL = "/transcripts/new" as const;
|
export const RECORD_A_MEETING_URL = "/transcripts/new" as const;
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
"use client";
|
|
||||||
import { createContext, useContext, useEffect, useState } from "react";
|
|
||||||
import { DomainConfig } from "./lib/edgeConfig";
|
|
||||||
|
|
||||||
type DomainContextType = Omit<DomainConfig, "auth_callback_url">;
|
|
||||||
|
|
||||||
export const DomainContext = createContext<DomainContextType>({
|
|
||||||
features: {
|
|
||||||
requireLogin: false,
|
|
||||||
privacy: true,
|
|
||||||
browse: false,
|
|
||||||
sendToZulip: false,
|
|
||||||
},
|
|
||||||
api_url: "",
|
|
||||||
websocket_url: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const DomainContextProvider = ({
|
|
||||||
config,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
config: DomainConfig;
|
|
||||||
children: any;
|
|
||||||
}) => {
|
|
||||||
const [context, setContext] = useState<DomainContextType>();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!config) return;
|
|
||||||
const { auth_callback_url, ...others } = config;
|
|
||||||
setContext(others);
|
|
||||||
}, [config]);
|
|
||||||
|
|
||||||
if (!context) return;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DomainContext.Provider value={context}>{children}</DomainContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get feature config client-side with
|
|
||||||
export const featureEnabled = (
|
|
||||||
featureName: "requireLogin" | "privacy" | "browse" | "sendToZulip",
|
|
||||||
) => {
|
|
||||||
const context = useContext(DomainContext);
|
|
||||||
|
|
||||||
return context.features[featureName] as boolean | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get config server-side (out of react) : see lib/edgeConfig.
|
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
import "./styles/globals.scss";
|
import "./styles/globals.scss";
|
||||||
import { Metadata, Viewport } from "next";
|
import { Metadata, Viewport } from "next";
|
||||||
import { Poppins } from "next/font/google";
|
import { Poppins } from "next/font/google";
|
||||||
import SessionProvider from "./lib/SessionProvider";
|
|
||||||
import { ErrorProvider } from "./(errors)/errorContext";
|
import { ErrorProvider } from "./(errors)/errorContext";
|
||||||
import ErrorMessage from "./(errors)/errorMessage";
|
import ErrorMessage from "./(errors)/errorMessage";
|
||||||
import { DomainContextProvider } from "./domainContext";
|
|
||||||
import { RecordingConsentProvider } from "./recordingConsentContext";
|
import { RecordingConsentProvider } from "./recordingConsentContext";
|
||||||
import { getConfig } from "./lib/edgeConfig";
|
|
||||||
import { ErrorBoundary } from "@sentry/nextjs";
|
import { ErrorBoundary } from "@sentry/nextjs";
|
||||||
import { Providers } from "./providers";
|
import { Providers } from "./providers";
|
||||||
|
import { assertExistsAndNonEmptyString } from "./lib/utils";
|
||||||
|
|
||||||
const poppins = Poppins({
|
const poppins = Poppins({
|
||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
@@ -23,8 +21,13 @@ export const viewport: Viewport = {
|
|||||||
maximumScale: 1,
|
maximumScale: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const NEXT_PUBLIC_SITE_URL = assertExistsAndNonEmptyString(
|
||||||
|
process.env.NEXT_PUBLIC_SITE_URL,
|
||||||
|
"NEXT_PUBLIC_SITE_URL required",
|
||||||
|
);
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL!),
|
metadataBase: new URL(NEXT_PUBLIC_SITE_URL),
|
||||||
title: {
|
title: {
|
||||||
template: "%s – Reflector",
|
template: "%s – Reflector",
|
||||||
default: "Reflector - AI-Powered Meeting Transcriptions by Monadical",
|
default: "Reflector - AI-Powered Meeting Transcriptions by Monadical",
|
||||||
@@ -69,13 +72,9 @@ export default async function RootLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const config = await getConfig();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="en" className={poppins.className} suppressHydrationWarning>
|
<html lang="en" className={poppins.className} suppressHydrationWarning>
|
||||||
<body className={"h-[100svh] w-[100svw] overflow-x-hidden relative"}>
|
<body className={"h-[100svh] w-[100svw] overflow-x-hidden relative"}>
|
||||||
<SessionProvider>
|
|
||||||
<DomainContextProvider config={config}>
|
|
||||||
<RecordingConsentProvider>
|
<RecordingConsentProvider>
|
||||||
<ErrorBoundary fallback={<p>"something went really wrong"</p>}>
|
<ErrorBoundary fallback={<p>"something went really wrong"</p>}>
|
||||||
<ErrorProvider>
|
<ErrorProvider>
|
||||||
@@ -84,8 +83,6 @@ export default async function RootLayout({
|
|||||||
</ErrorProvider>
|
</ErrorProvider>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</RecordingConsentProvider>
|
</RecordingConsentProvider>
|
||||||
</DomainContextProvider>
|
|
||||||
</SessionProvider>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
132
www/app/lib/AuthProvider.tsx
Normal file
132
www/app/lib/AuthProvider.tsx
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { createContext, useContext } from "react";
|
||||||
|
import { useSession as useNextAuthSession } from "next-auth/react";
|
||||||
|
import { signOut, signIn } from "next-auth/react";
|
||||||
|
import { configureApiAuth } from "./apiClient";
|
||||||
|
import { assertCustomSession, CustomSession } from "./types";
|
||||||
|
import { Session } from "next-auth";
|
||||||
|
import { SessionAutoRefresh } from "./SessionAutoRefresh";
|
||||||
|
import { REFRESH_ACCESS_TOKEN_ERROR } from "./auth";
|
||||||
|
import { assertExists } from "./utils";
|
||||||
|
import { featureEnabled } from "./features";
|
||||||
|
|
||||||
|
type AuthContextType = (
|
||||||
|
| { status: "loading" }
|
||||||
|
| { status: "refreshing"; user: CustomSession["user"] }
|
||||||
|
| { status: "unauthenticated"; error?: string }
|
||||||
|
| {
|
||||||
|
status: "authenticated";
|
||||||
|
accessToken: string;
|
||||||
|
accessTokenExpires: number;
|
||||||
|
user: CustomSession["user"];
|
||||||
|
}
|
||||||
|
) & {
|
||||||
|
update: () => Promise<Session | null>;
|
||||||
|
signIn: typeof signIn;
|
||||||
|
signOut: typeof signOut;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
|
const isAuthEnabled = featureEnabled("requireLogin");
|
||||||
|
|
||||||
|
const noopAuthContext: AuthContextType = {
|
||||||
|
status: "unauthenticated",
|
||||||
|
update: async () => {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
signIn: async () => {
|
||||||
|
throw new Error("signIn not supposed to be called");
|
||||||
|
},
|
||||||
|
signOut: async () => {
|
||||||
|
throw new Error("signOut not supposed to be called");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
const { data: session, status, update } = useNextAuthSession();
|
||||||
|
|
||||||
|
const contextValue: AuthContextType = isAuthEnabled
|
||||||
|
? {
|
||||||
|
...(() => {
|
||||||
|
switch (status) {
|
||||||
|
case "loading": {
|
||||||
|
const sessionIsHere = !!session;
|
||||||
|
// actually exists sometimes; nextAuth types are something else
|
||||||
|
switch (sessionIsHere as boolean) {
|
||||||
|
case false: {
|
||||||
|
return { status };
|
||||||
|
}
|
||||||
|
case true: {
|
||||||
|
return {
|
||||||
|
status: "refreshing" as const,
|
||||||
|
user: assertCustomSession(
|
||||||
|
assertExists(session as unknown as Session),
|
||||||
|
).user,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new Error("unreachable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "authenticated": {
|
||||||
|
const customSession = assertCustomSession(session);
|
||||||
|
if (customSession?.error === REFRESH_ACCESS_TOKEN_ERROR) {
|
||||||
|
// token had expired but next auth still returns "authenticated" so show user unauthenticated state
|
||||||
|
return {
|
||||||
|
status: "unauthenticated" as const,
|
||||||
|
};
|
||||||
|
} else if (customSession?.accessToken) {
|
||||||
|
return {
|
||||||
|
status,
|
||||||
|
accessToken: customSession.accessToken,
|
||||||
|
accessTokenExpires: customSession.accessTokenExpires,
|
||||||
|
user: customSession.user,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
"illegal state: authenticated but have no session/or access token. ignoring",
|
||||||
|
);
|
||||||
|
return { status: "unauthenticated" as const };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "unauthenticated": {
|
||||||
|
return { status: "unauthenticated" as const };
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
const _: never = status;
|
||||||
|
throw new Error("unreachable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(),
|
||||||
|
update,
|
||||||
|
signIn,
|
||||||
|
signOut,
|
||||||
|
}
|
||||||
|
: noopAuthContext;
|
||||||
|
|
||||||
|
// not useEffect, we need it ASAP
|
||||||
|
// apparently, still no guarantee this code runs before mutations are fired
|
||||||
|
configureApiAuth(
|
||||||
|
contextValue.status === "authenticated"
|
||||||
|
? contextValue.accessToken
|
||||||
|
: contextValue.status === "loading"
|
||||||
|
? undefined
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthContext.Provider value={contextValue}>
|
||||||
|
<SessionAutoRefresh>{children}</SessionAutoRefresh>
|
||||||
|
</AuthContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAuth() {
|
||||||
|
const context = useContext(AuthContext);
|
||||||
|
if (context === undefined) {
|
||||||
|
throw new Error("useAuth must be used within an AuthProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* This is a custom hook that automatically refreshes the session when the access token is about to expire.
|
* This is a custom provider that automatically refreshes the session when the access token is about to expire.
|
||||||
* When communicating with the reflector API, we need to ensure that the access token is always valid.
|
* When communicating with the reflector API, we need to ensure that the access token is always valid.
|
||||||
*
|
*
|
||||||
* We could have implemented that as an interceptor on the API client, but not everything is using the
|
* We could have implemented that as an interceptor on the API client, but not everything is using the
|
||||||
@@ -7,30 +7,35 @@
|
|||||||
*/
|
*/
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useSession } from "next-auth/react";
|
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { CustomSession } from "./types";
|
import { useAuth } from "./AuthProvider";
|
||||||
|
import { shouldRefreshToken } from "./auth";
|
||||||
|
|
||||||
export function SessionAutoRefresh({
|
export function SessionAutoRefresh({ children }) {
|
||||||
children,
|
const auth = useAuth();
|
||||||
refreshInterval = 20 /* seconds */,
|
|
||||||
}) {
|
const accessTokenExpires =
|
||||||
const { data: session, update } = useSession();
|
auth.status === "authenticated" ? auth.accessTokenExpires : null;
|
||||||
const customSession = session as CustomSession;
|
|
||||||
const accessTokenExpires = customSession?.accessTokenExpires;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// technical value for how often the setInterval will be polling news - not too fast (no spam in case of errors)
|
||||||
|
// and not too slow (debuggable)
|
||||||
|
const INTERVAL_REFRESH_MS = 5000;
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (accessTokenExpires) {
|
if (accessTokenExpires === null) return;
|
||||||
const timeLeft = accessTokenExpires - Date.now();
|
if (shouldRefreshToken(accessTokenExpires)) {
|
||||||
if (timeLeft < refreshInterval * 1000) {
|
auth
|
||||||
update();
|
.update()
|
||||||
|
.then(() => {})
|
||||||
|
.catch((e) => {
|
||||||
|
// note: 401 won't be considered error here
|
||||||
|
console.error("error refreshing auth token", e);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}, INTERVAL_REFRESH_MS);
|
||||||
}, refreshInterval * 1000);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [accessTokenExpires, refreshInterval, update]);
|
}, [accessTokenExpires, auth.update]);
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
"use client";
|
|
||||||
import { SessionProvider as SessionProviderNextAuth } from "next-auth/react";
|
|
||||||
import { SessionAutoRefresh } from "./SessionAutoRefresh";
|
|
||||||
|
|
||||||
export default function SessionProvider({ children }) {
|
|
||||||
return (
|
|
||||||
<SessionProviderNextAuth>
|
|
||||||
<SessionAutoRefresh>{children}</SessionAutoRefresh>
|
|
||||||
</SessionProviderNextAuth>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
85
www/app/lib/__tests__/redisTokenCache.test.ts
Normal file
85
www/app/lib/__tests__/redisTokenCache.test.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import {
|
||||||
|
getTokenCache,
|
||||||
|
setTokenCache,
|
||||||
|
deleteTokenCache,
|
||||||
|
TokenCacheEntry,
|
||||||
|
KV,
|
||||||
|
} from "../redisTokenCache";
|
||||||
|
|
||||||
|
const mockKV: KV & {
|
||||||
|
clear: () => void;
|
||||||
|
} = (() => {
|
||||||
|
const data = new Map<string, string>();
|
||||||
|
return {
|
||||||
|
async get(key: string): Promise<string | null> {
|
||||||
|
return data.get(key) || null;
|
||||||
|
},
|
||||||
|
|
||||||
|
async setex(key: string, seconds_: number, value: string): Promise<"OK"> {
|
||||||
|
data.set(key, value);
|
||||||
|
return "OK";
|
||||||
|
},
|
||||||
|
|
||||||
|
async del(key: string): Promise<number> {
|
||||||
|
const existed = data.has(key);
|
||||||
|
data.delete(key);
|
||||||
|
return existed ? 1 : 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
data.clear();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
describe("Redis Token Cache", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockKV.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("basic write/read - value written equals value read", async () => {
|
||||||
|
const testKey = "token:test-user-123";
|
||||||
|
const testValue: TokenCacheEntry = {
|
||||||
|
token: {
|
||||||
|
sub: "test-user-123",
|
||||||
|
name: "Test User",
|
||||||
|
email: "test@example.com",
|
||||||
|
accessToken: "access-token-123",
|
||||||
|
accessTokenExpires: Date.now() + 3600000, // 1 hour from now
|
||||||
|
refreshToken: "refresh-token-456",
|
||||||
|
},
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
await setTokenCache(mockKV, testKey, testValue);
|
||||||
|
const retrievedValue = await getTokenCache(mockKV, testKey);
|
||||||
|
|
||||||
|
expect(retrievedValue).not.toBeNull();
|
||||||
|
expect(retrievedValue).toEqual(testValue);
|
||||||
|
expect(retrievedValue?.token.accessToken).toBe(testValue.token.accessToken);
|
||||||
|
expect(retrievedValue?.token.sub).toBe(testValue.token.sub);
|
||||||
|
expect(retrievedValue?.timestamp).toBe(testValue.timestamp);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("get returns null for non-existent key", async () => {
|
||||||
|
const result = await getTokenCache(mockKV, "non-existent-key");
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("delete removes token from cache", async () => {
|
||||||
|
const testKey = "token:delete-test";
|
||||||
|
const testValue: TokenCacheEntry = {
|
||||||
|
token: {
|
||||||
|
accessToken: "test-token",
|
||||||
|
accessTokenExpires: Date.now() + 3600000,
|
||||||
|
},
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
await setTokenCache(mockKV, testKey, testValue);
|
||||||
|
await deleteTokenCache(mockKV, testKey);
|
||||||
|
|
||||||
|
const result = await getTokenCache(mockKV, testKey);
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
72
www/app/lib/apiClient.tsx
Normal file
72
www/app/lib/apiClient.tsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import createClient from "openapi-fetch";
|
||||||
|
import type { paths } from "../reflector-api";
|
||||||
|
import createFetchClient from "openapi-react-query";
|
||||||
|
import { assertExistsAndNonEmptyString, parseNonEmptyString } from "./utils";
|
||||||
|
import { isBuildPhase } from "./next";
|
||||||
|
import { getSession } from "next-auth/react";
|
||||||
|
import { assertExtendedToken } from "./types";
|
||||||
|
|
||||||
|
export const API_URL = !isBuildPhase
|
||||||
|
? assertExistsAndNonEmptyString(
|
||||||
|
process.env.NEXT_PUBLIC_API_URL,
|
||||||
|
"NEXT_PUBLIC_API_URL required",
|
||||||
|
)
|
||||||
|
: "http://localhost";
|
||||||
|
|
||||||
|
// TODO decide strict validation or not
|
||||||
|
export const WEBSOCKET_URL =
|
||||||
|
process.env.NEXT_PUBLIC_WEBSOCKET_URL || "ws://127.0.0.1:1250";
|
||||||
|
|
||||||
|
export const client = createClient<paths>({
|
||||||
|
baseUrl: API_URL,
|
||||||
|
});
|
||||||
|
|
||||||
|
// will assert presence/absence of login initially
|
||||||
|
const initialSessionPromise = getSession();
|
||||||
|
|
||||||
|
const waitForAuthTokenDefinitivePresenceOrAbsence = async () => {
|
||||||
|
const initialSession = await initialSessionPromise;
|
||||||
|
if (currentAuthToken === undefined) {
|
||||||
|
currentAuthToken =
|
||||||
|
initialSession === null
|
||||||
|
? null
|
||||||
|
: assertExtendedToken(initialSession).accessToken;
|
||||||
|
}
|
||||||
|
// otherwise already overwritten by external forces
|
||||||
|
return currentAuthToken;
|
||||||
|
};
|
||||||
|
|
||||||
|
client.use({
|
||||||
|
async onRequest({ request }) {
|
||||||
|
const token = await waitForAuthTokenDefinitivePresenceOrAbsence();
|
||||||
|
if (token !== null) {
|
||||||
|
request.headers.set(
|
||||||
|
"Authorization",
|
||||||
|
`Bearer ${parseNonEmptyString(token)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// XXX Only set Content-Type if not already set (FormData will set its own boundary)
|
||||||
|
// This is a work around for uploading file, we're passing a formdata
|
||||||
|
// but the content type was still application/json
|
||||||
|
if (
|
||||||
|
!request.headers.has("Content-Type") &&
|
||||||
|
!(request.body instanceof FormData)
|
||||||
|
) {
|
||||||
|
request.headers.set("Content-Type", "application/json");
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const $api = createFetchClient<paths>(client);
|
||||||
|
|
||||||
|
let currentAuthToken: string | null | undefined = undefined;
|
||||||
|
|
||||||
|
// the function contract: lightweight, idempotent
|
||||||
|
export const configureApiAuth = (token: string | null | undefined) => {
|
||||||
|
// watch only for the initial loading; "reloading" state assumes token presence/absence
|
||||||
|
if (token === undefined && currentAuthToken !== undefined) return;
|
||||||
|
currentAuthToken = token;
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user