Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
- Audio pipeline progress keeps updating after temporary network failures, and interrupted Ask AI answers reconnect without duplicating text.
- Transcript searches refresh after re-transcription, and browser transcription progress and notifications follow the interface language.

- Recordings with multiple transcript sources show every source in the transcript switcher, with the preferred source first. The detail API includes all transcripts while keeping the singular `transcription` field for existing clients.
- Library text search matches every transcript source available for a recording, including older sources, without duplicate results.

- A failure to open or lock the Mac app's instance-lock file now shows a startup error instead of silently exiting as if another copy were running.
- Launch at Login keeps its tray check mark in sync after an interface-language change rebuilds the menu.
- Changing the Mac app's locale through desktop preferences no longer hangs while rebuilding the tray menu.
Expand Down
73 changes: 73 additions & 0 deletions contract-tests/tests/transcript-sources.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { expect, test } from "@playwright/test";
import { randomUUID } from "node:crypto";
import { newUserContext, uploadRecording } from "../helpers/api";
import { fakeControl } from "../helpers/plaud-extra";

test("detail exposes empty and single-source arrays and preserves missing-recording errors", async () => {
const api = await newUserContext("transcript-empty");
try {
const id = await uploadRecording(api);
const detail = () => api.get(`/api/recordings/${id}`);
expect(await (await detail()).json()).toMatchObject({ transcription: null, transcriptions: [] });
expect((await api.post(`/api/recordings/${id}/transcription/from-browser`, {
data: { text: "Only source", model: "whisper-base" },
})).status()).toBe(200);
const single = await (await detail()).json();
expect(single.transcriptions).toHaveLength(1);
expect(single.transcriptions[0]).toEqual(single.transcription);
expect(single.transcription).toMatchObject({ text: "Only source", source: "openaudiohub" });
const other = await newUserContext("transcript-other");
try { expect((await other.get(`/api/recordings/${id}`)).status()).toBe(404); } finally { await other.dispose(); }
expect((await api.delete(`/api/recordings/${id}`)).status()).toBe(200);
expect((await detail()).status()).toBe(404);
expect((await api.get("/api/recordings/missing-transcript-recording")).status()).toBe(404);
} finally {
await api.dispose();
}
});

test("detail orders all sources by preference and search matches older sources", async () => {
const api = await newUserContext("transcript-sources");
try {
const email = `sources-${randomUUID()}@example.test`;
const plaudId = `sources-${randomUUID()}`;
expect((await api.put("/api/settings/user", { data: { importPlaudContent: true } })).status()).toBe(200);
await fakeControl("/account", { email, recordings: [{ id: plaudId, is_trans: true }] });
const sent = await api.post("/api/plaud/auth/send-code", { data: { email } });
expect(sent.status()).toBe(200);
const { otpToken, apiBase } = await sent.json();
expect((await api.post("/api/plaud/auth/verify", { data: { email, otpToken, apiBase, code: "123456" } })).status()).toBe(200);
const sync = await api.post("/api/plaud/sync");
expect(sync.status()).toBe(200);
expect((await sync.json()).errors).toEqual([]);
const { recordings } = await (await api.get("/api/recordings")).json();
const id = recordings.find((row: { plaudFileId: string }) => row.plaudFileId === plaudId)?.id;
expect(id).toBeTruthy();
const detail = async () => {
const response = await api.get(`/api/recordings/${id}`);
expect(response.status()).toBe(200);
return response.json();
};
const imported = await detail();
expect(imported.transcriptions).toHaveLength(1);
expect(imported.transcription.source).toBe("plaud");
expect((await api.post(`/api/recordings/${id}/transcription/from-browser`, {
data: { text: "Unique browser words", model: "whisper-base" },
})).status()).toBe(200);
for (const preferred of ["plaud", "openaudiohub"] as const) {
expect((await api.put("/api/settings/user", { data: { preferredTranscriptSource: preferred } })).status()).toBe(200);
const body = await detail();
expect(body.transcriptions.map((row: { source: string }) => row.source)).toEqual(
preferred === "plaud" ? ["plaud", "openaudiohub"] : ["openaudiohub", "plaud"],
);
expect(body.transcription).toEqual(body.transcriptions[0]);
}
for (const query of [`Fake transcript line for ${plaudId}`, "Unique browser words"]) {
const search = await api.get("/api/recordings/search", { params: { q: query } });
expect(search.status()).toBe(200);
expect(await search.json()).toEqual({ recordingIds: [id] });
}
} finally {
await api.dispose();
}
});
152 changes: 144 additions & 8 deletions crates/oah/src/routes/recordings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,22 +557,28 @@ async fn detail(
UrlPath(id): UrlPath<String>,
) -> ApiResult<Json<Value>> {
let row = find(&state, &user.id, &id).await?;
let transcript = sqlx::query_as::<_, TranscriptRow>(
let settings = crate::routes::settings::effective(&state, &user.id).await?;
let preferred = settings["preferredTranscriptSource"]
.as_str()
.unwrap_or("plaud");
let transcripts = sqlx::query_as::<_, TranscriptRow>(
"SELECT id, recording_id, user_id, text, detected_language, transcription_type, provider, model, timeline, timeline_source, \
source, created_at FROM transcriptions WHERE recording_id = ? AND user_id = ? \
ORDER BY created_at DESC LIMIT 1",
ORDER BY CASE WHEN source = ? THEN 0 ELSE 1 END, created_at DESC, id DESC",
)
.bind(id.as_str())
.bind(user.id.as_str())
.fetch_optional(&state.db)
.bind(preferred)
.fetch_all(&state.db)
.await?;
let transcription = match transcript {
Some(t) => transcript_json(&state.config.field_key, t)?,
None => Value::Null,
};
let transcriptions = transcripts
.into_iter()
.map(|t| transcript_json(&state.config.field_key, t))
.collect::<ApiResult<Vec<_>>>()?;
let transcription = transcriptions.first().cloned().unwrap_or(Value::Null);
let recording = row_json(&state.config.field_key, row)?;
Ok(Json(
json!({ "recording": recording, "transcription": transcription }),
json!({ "recording": recording, "transcription": transcription, "transcriptions": transcriptions }),
))
}

Expand Down Expand Up @@ -2016,6 +2022,136 @@ mod tests {
.to_vec()
}

#[tokio::test]
async fn detail_returns_all_sources_in_preferred_order() {
let dir = tempfile::tempdir().unwrap();
let config = crate::config::Config::for_tests(dir.path());
let state = AppState::new(config, crate::db::open_memory().await.unwrap());
for id in ["u1", "u2"] {
sqlx::query(
"INSERT INTO users (id, email, created_at, updated_at) VALUES (?, ?, 0, 0)",
)
.bind(id)
.bind(format!("{id}@example.test"))
.execute(&state.db)
.await
.unwrap();
}
insert(
&state.db,
&state.config.field_key,
NewRecording {
id: "rec",
user_id: "u1",
plaud_file_id: "rec",
title: "Meeting",
duration: 3_000,
start: 0,
filesize: 10,
file_md5: "00000000000000000000000000000000",
storage_type: "local",
storage_path: "u1/rec.mp3",
title_source: "original",
auto_export_eligible: false,
waveform_peaks: None,
},
)
.await
.unwrap();
let user = |id: &str| CurrentUser {
id: id.into(),
email: format!("{id}@example.test"),
name: None,
session_id: "session".into(),
};
let read = || detail(State(state.clone()), user("u1"), UrlPath("rec".into()));
let Json(empty) = read().await.unwrap();
assert_eq!(empty["transcriptions"], json!([]));
assert_eq!(empty["transcription"], Value::Null);

let timeline = json!([{ "start_ms": 0, "end_ms": 1000, "text": "Hello" }]);
for (id, owner, source, created) in [
("p", "u1", "plaud", 10),
("a", "u1", "openaudiohub", 20),
("m", "u1", "mixed", 20),
("foreign", "u2", "plaud", 100),
] {
sqlx::query(
"INSERT INTO transcriptions (id, recording_id, user_id, text, provider, model, timeline, timeline_source, source, created_at) \
VALUES (?, 'rec', ?, ?, 'provider', 'model', ?, 'native', ?, ?)",
)
.bind(id)
.bind(owner)
.bind(state.config.field_key.encrypt(&format!("Text from {source}")))
.bind(state.config.field_key.encrypt_json(&timeline).to_string())
.bind(source)
.bind(created)
.execute(&state.db)
.await
.unwrap();
}
let sources = |data: &Value| -> Vec<String> {
data["transcriptions"]
.as_array()
.unwrap()
.iter()
.map(|t| t["source"].as_str().unwrap().to_owned())
.collect()
};
let Json(default) = read().await.unwrap();
assert_eq!(sources(&default), ["plaud", "mixed", "openaudiohub"]);
assert_eq!(default["transcription"], default["transcriptions"][0]);
assert_eq!(default["transcription"]["text"], "Text from plaud");
assert_eq!(default["transcription"]["timeline"], timeline);
for row in default["transcriptions"].as_array().unwrap() {
assert_eq!(row["userId"], "u1");
assert_eq!(row["timeline"], timeline);
}
sqlx::query("INSERT INTO user_settings (user_id, data, updated_at) VALUES ('u1', ?, 0)")
.bind(json!({ "preferredTranscriptSource": "openaudiohub" }).to_string())
.execute(&state.db)
.await
.unwrap();
let Json(preferred) = read().await.unwrap();
assert_eq!(sources(&preferred), ["openaudiohub", "mixed", "plaud"]);
assert_eq!(preferred["transcription"], preferred["transcriptions"][0]);

sqlx::query("DELETE FROM transcriptions WHERE id = 'a'")
.execute(&state.db)
.await
.unwrap();
let Json(absent) = read().await.unwrap();
assert_eq!(sources(&absent), ["mixed", "plaud"]);
assert_eq!(absent["transcription"]["source"], "mixed");
sqlx::query("DELETE FROM transcriptions WHERE id = 'm'")
.execute(&state.db)
.await
.unwrap();
let Json(single) = read().await.unwrap();
assert_eq!(sources(&single), ["plaud"]);
assert_eq!(single["transcription"], single["transcriptions"][0]);

for (owner, id) in [("u2", "rec"), ("u1", "missing")] {
let error = detail(State(state.clone()), user(owner), UrlPath(id.into()))
.await
.unwrap_err();
assert_eq!(error.code, "RECORDING_NOT_FOUND");
}
sqlx::query("UPDATE transcriptions SET text = 'v1:invalid' WHERE id = 'p'")
.execute(&state.db)
.await
.unwrap();
assert_eq!(
read().await.unwrap_err().status,
StatusCode::INTERNAL_SERVER_ERROR
);
sqlx::query("UPDATE recordings SET deleted_at = 1 WHERE id = 'rec'")
.execute(&state.db)
.await
.unwrap();
assert_eq!(read().await.unwrap_err().code, "RECORDING_NOT_FOUND");
}

#[tokio::test]
async fn mixed_library_streams_ranges_zips_and_deletes() {
use crate::config::{Config, StorageType};
Expand Down
42 changes: 21 additions & 21 deletions crates/oah/src/routes/recordings/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,16 @@ pub async fn search(
}
}

// A recording's own transcript is the one the detail page shows: the newest one for the
// recording. Matching any older transcript would show a recording that no longer contains
// the text the user searched for.
// The transcript a search is about is the one the detail page shows: the newest for the
// recording, with the same tie-break so two rows of one timestamp cannot disagree. Grouping
// keeps it to one row per recording.
let transcripts: Vec<(String, String)> = sqlx::query_as(
"SELECT recording_id, text FROM (
SELECT recording_id, text,
ROW_NUMBER() OVER (PARTITION BY recording_id ORDER BY created_at DESC, id DESC) AS rank
FROM transcriptions WHERE user_id = ?
) WHERE rank = 1
AND EXISTS (SELECT 1 FROM recordings r WHERE r.id = recording_id AND r.user_id = ? AND r.deleted_at IS NULL)",
"SELECT t.recording_id, t.text FROM transcriptions t
JOIN recordings r ON r.id = t.recording_id
WHERE t.user_id = ? AND r.user_id = ? AND r.deleted_at IS NULL",
)
.bind(&user.id)
.bind(&user.id)
.fetch_all(&state.db)
.await?;
for (recording_id, text) in transcripts {
if matched.contains(&recording_id) {
continue;
}
let plain = state
.config
.field_key
Expand Down Expand Up @@ -305,11 +293,9 @@ mod tests {
}

#[tokio::test]
async fn only_the_newest_transcript_is_searched() {
async fn all_transcript_sources_are_searched_once_per_recording() {
let (state, _dir) = state().await;
recording(&state, "r1", "u", "name").await;
// Two transcripts of different sources: the newest one is what the detail page shows, so
// it is the text a search is about.
sqlx::query(
"INSERT INTO transcriptions (id, recording_id, user_id, text, transcription_type, provider, model, source, created_at)
VALUES ('old', 'r1', 'u', ?, 'server', 'Plaud', 'plaud-native', 'plaud', 0)",
Expand All @@ -326,11 +312,25 @@ mod tests {
.execute(&state.db)
.await
.unwrap();
transcript(&state, "r1", "other", "foreign secret").await;
assert_eq!(ids_for(&state, "u", "old words").await.unwrap(), ["r1"]);
assert_eq!(ids_for(&state, "u", "new words").await.unwrap(), ["r1"]);
assert_eq!(ids_for(&state, "u", "words").await.unwrap(), ["r1"]);
assert!(
ids_for(&state, "u", "old words").await.unwrap().is_empty(),
"an older transcript is not what a search is about"
ids_for(&state, "u", "foreign secret")
.await
.unwrap()
.is_empty()
);
assert!(ids_for(&state, "u", "absent").await.unwrap().is_empty());
sqlx::query("UPDATE transcriptions SET text = 'v1:invalid' WHERE id = 'old'")
.execute(&state.db)
.await
.unwrap();
assert_eq!(
ids_for(&state, "u", "new words").await.unwrap_err().code,
"SEARCH_FAILED"
);
assert_eq!(ids_for(&state, "u", "new words").await.unwrap(), ["r1"]);
}

/// A stored value that cannot be read makes the search an error. Reporting it as a complete
Expand Down
23 changes: 14 additions & 9 deletions spec/recordings.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This file covers recordings as a client sees them over HTTP: the list, one
recording, edits, deletion, starring, upload, audio streaming, waveform peaks,
batch download, and merge. Transcripts and summaries live in
`transcription.md` and `ai.md`. The detail response includes a `transcription`
field; its shape is described there.
`transcription.md` and `ai.md`. The detail response includes `transcriptions`
and a compatible singular `transcription` field; their row shape is described there.

Tests: `contract-tests/tests/recordings.spec.ts`.

Expand Down Expand Up @@ -80,9 +80,9 @@ Response: `200`
```json
{ "recordingIds": ["abc", "def"] }
```
The caller's non-deleted recordings whose name, or whose newest transcript text, contains
`q`. A recording appears once, whether the name or the text matched. Only the newest
transcript of a recording is searched: it is the one the detail page shows. The ids are
The caller's non-deleted recordings whose name, or any of the caller's transcript sources, contains
`q`. A recording appears once, whether its name or one or more transcripts matched. Every
source available in the detail switcher is searched, not only the newest or preferred one. The ids are
returned in no particular order, and the list the client already has is what sorts and
filters them.

Expand All @@ -106,12 +106,17 @@ Response: `200`
```json
{
"recording": { "id": "abc", "filename": "Standup", "duration": 3096 },
"transcription": null
"transcription": null,
"transcriptions": []
}
```
`recording` has the full field set above. `transcription` is the caller's
transcript row for this recording, with its text in plaintext, or `null` when
none exists. See `transcription.md` for its fields.
`recording` has the full field set above. `transcriptions` contains all of the
caller's transcript rows for this recording, with text and timelines decrypted.
Rows matching the caller's `preferredTranscriptSource` setting (default `plaud`)
come first, then rows are ordered by `created_at` descending and `id` descending
to break ties. If the preferred source is absent, the newest available row comes
first. `transcription` is the first row, or `null` when the array is empty, for
clients that read only one transcript. See `transcription.md` for row fields.
Errors: `401` `AUTH_SESSION_MISSING`; `404` `RECORDING_NOT_FOUND` (unknown, deleted, or not the caller's)
Side effects: none

Expand Down
1 change: 1 addition & 0 deletions spec/ui-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ Body:
- Source switcher (`source-switcher`): one button per transcript source ("Plaud",
"Mix", "Your provider"). Shown only when there is more than one transcript.
Selecting one switches the text. The primary source comes first.
The detail response's `transcriptions` array supplies every source in preferred-source order. With no explicit selection, the first transcript is shown; if a selected source is removed, the view and active switcher button fall back to the first remaining transcript. Older servers returning only `transcription` remain supported.
- Toolbar (`transcript-toolbar`): "Download transcript as TXT", "Download transcript as JSON"
(both download a file built in the browser), and "Delete" (`DELETE /api/recordings/{id}/transcription?source=<source>`
after a confirmation titled "Delete this transcript?"; the summary is removed with it).
Expand Down
Loading
Loading