From f80b3dc14caff9695c31f59b514bf824aecf61ae Mon Sep 17 00:00:00 2001 From: leemour Date: Tue, 17 Nov 2026 18:49:47 +0100 Subject: [PATCH] fix(transcribe): meetings transcribe answers the shared call_transcription_report shape beeline, b24 and pbx all answer `call_transcription_report`, and the family audit (WC-OUT-11) requires one schema per shared entity. b24 moved to beeline's shape in WireCatLabs/bitrix24-cli#145 after its old shape blocked beeline's pull requests; pbx had the same old shape and would block once on npm. Per WC-OUT-13 (durations in `_ms`, stored things named by `ref`): - `audio_ms` replaces the rounded `audio_seconds`; - each `failed` item has its `ref` (`meeting:/`); - a call with no recording is listed under `failed` as `recording.missing`, a reason pbx already declares; `without_recording` is gone. Co-Authored-By: Claude Opus 5.5 --- changes/fix-transcription-report-parity.md | 5 +++ docs/commands.md | 2 +- src/commands/transcribe.ts | 5 ++- src/transcribe-calls.ts | 41 ++++++++++++---------- src/transcribe.test.ts | 18 +++++++--- 5 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 changes/fix-transcription-report-parity.md diff --git a/changes/fix-transcription-report-parity.md b/changes/fix-transcription-report-parity.md new file mode 100644 index 0000000..33c7fa3 --- /dev/null +++ b/changes/fix-transcription-report-parity.md @@ -0,0 +1,5 @@ +### Changed — may break callers + +- **`meetings transcribe` answers the same report as the other phone CLIs (beeline, b24).** The audio time is + `audio_ms`, in milliseconds (was `audio_seconds`). Each failed call has its `ref`. A call with no recording is listed + under `failed` with the reason `recording.missing`, and `without_recording` is gone. diff --git a/docs/commands.md b/docs/commands.md index bd8fcc5..57ecd27 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -340,7 +340,7 @@ pbx meetings transcribe [query] [options] | `--max-meetings ` | at most this many calls transcribed, newest first. Default: `20`. | | `--model ` | local speech model, when the profile transcribes locally. Default: `gigaam-v3`. | -**Returns:** call transcription report — transcribed, audio_seconds, failed, without_recording, remaining, stopped; every field: pbx commands info meetings transcribe +**Returns:** call transcription report — transcribed, audio_ms, failed, remaining, stopped; every field: pbx commands info meetings transcribe **Example:** `pbx office meetings transcribe --max-meetings 20 --json`, `pbx office meetings transcribe duration_ms>=60000 --json`, `pbx office meetings transcribe id:12 --replace --json` diff --git a/src/commands/transcribe.ts b/src/commands/transcribe.ts index eebe532..9023b99 100644 --- a/src/commands/transcribe.ts +++ b/src/commands/transcribe.ts @@ -61,9 +61,8 @@ export const callQuery = (text: string) => { const REPORT = v.strictObject({ transcribed: v.number(), - audio_seconds: v.number(), - failed: v.array(v.strictObject({ meeting: v.number(), reason: v.string(), message: v.string() })), - without_recording: v.number(), + audio_ms: v.number(), + failed: v.array(v.strictObject({ meeting: v.number(), ref: v.string(), reason: v.string(), message: v.string() })), remaining: v.number(), stopped: v.boolean(), }) diff --git a/src/transcribe-calls.ts b/src/transcribe-calls.ts index 9734147..2c6df8c 100644 --- a/src/transcribe-calls.ts +++ b/src/transcribe-calls.ts @@ -9,6 +9,7 @@ import { isCliError } from "@wirecat/cli-base" import type { QueryAst } from "@wirecat/cli-base/query" import { type Attachment, + formatMeetingReference, type MeetingStore, type MeetingTranscriptReceiptStore, transcribeMeeting, @@ -32,15 +33,20 @@ export interface TranscribeOptions { export interface TranscribeReport { transcribed: number - audio_seconds: number - failed: { meeting: number; reason: string; message: string }[] - /** Calls the query names that have no recording attached: nothing to transcribe. */ - without_recording: number + audio_ms: number + failed: FailedCall[] remaining: number /** True when the run stopped on its signal before reaching --max-meetings. */ stopped: boolean } +export interface FailedCall { + meeting: number + ref: string + reason: string + message: string +} + export interface TranscribePorts { store: MeetingStore & MeetingTranscriptReceiptStore accountId: number @@ -106,21 +112,20 @@ export const transcribeCalls = async ( const calls = (await store.meetings({ accountId, query: options.query })).sort( (a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0), ) - const report: TranscribeReport = { - transcribed: 0, - audio_seconds: 0, - failed: [], - without_recording: 0, - remaining: 0, - stopped: false, - } + const report: TranscribeReport = { transcribed: 0, audio_ms: 0, failed: [], remaining: 0, stopped: false } + const failed = (meeting: number, reason: string, message: string): FailedCall => ({ + meeting, + ref: formatMeetingReference({ type: "meeting", accountId, meetingId: meeting }), + reason, + message, + }) const pending = [] for (const call of calls) { const details = await store.meeting(call.id) if (!details || (!options.replace && details.transcripts.length > 0)) continue const recording = recordingOf(details.attachments) if (recording) pending.push({ call, recording, speakers: speakersOf(details, ports.sides ?? null) }) - else report.without_recording++ + else report.failed.push(failed(call.id, "recording.missing", "the call has no recording")) } const shown = Math.min(pending.length, options.limit) for (const [index, { call, recording, speakers }] of pending.entries()) { @@ -150,7 +155,7 @@ export const transcribeCalls = async ( await local.dispose() } report.transcribed++ - report.audio_seconds += Math.round((call.durationMs ?? 0) / 1000) + report.audio_ms += call.durationMs ?? 0 options.progress?.(`${index + 1}/${shown} meeting ${call.id} transcribed`) } catch (error) { // The run's deadline stops a read or a recognition halfway, whatever error that throws; the calls finished @@ -162,11 +167,9 @@ export const transcribeCalls = async ( } if (isCliError(error) && error.code === "cancelled") throw error const reason = isCliError(error) ? (error.details.reason ?? error.code) : "unexpected" - report.failed.push({ - meeting: call.id, - reason: String(reason), - message: isCliError(error) ? error.message : "the call could not be transcribed", - }) + report.failed.push( + failed(call.id, String(reason), isCliError(error) ? error.message : "the call could not be transcribed"), + ) options.progress?.(`${index + 1}/${shown} meeting ${call.id} failed: ${reason}`) } } diff --git a/src/transcribe.test.ts b/src/transcribe.test.ts index 950221f..dde00e1 100644 --- a/src/transcribe.test.ts +++ b/src/transcribe.test.ts @@ -36,10 +36,18 @@ beforeEach(async () => { expect(synced.code, synced.err).toBe(0) }) -it("transcribes the calls that have a recording, counts those without, and finds what the client said", async () => { +it("transcribes the calls that have a recording, lists those without as failed, and finds what the client said", async () => { const done = await transcribe([], { speech: speech() }) expect(done.code, done.err).toBe(0) - expect(done.json().item).toMatchObject({ transcribed: 2, failed: [], without_recording: 3, remaining: 0 }) + const item = done.json().item as { transcribed: number; audio_ms: number; failed: { ref: string; reason: string }[] } + expect(item).toMatchObject({ transcribed: 2, remaining: 0 }) + expect(item.audio_ms).toBeGreaterThan(0) + expect(item.failed.map(({ reason }) => reason)).toEqual([ + "recording.missing", + "recording.missing", + "recording.missing", + ]) + expect(item.failed.every(({ ref }) => ref.startsWith("meeting:"))).toBe(true) const list = await runCli(["office", "meetings", "list", "--json"]) const call = (list.json().items as { id: string; title: string }[]).find( @@ -50,7 +58,7 @@ it("transcribes the calls that have a recording, counts those without, and finds expect(transcript.out).toContain("оплатим в пятницу") const again = await transcribe([], { speech: speech() }) - expect(again.json().item).toMatchObject({ transcribed: 0, without_recording: 3 }) + expect(again.json().item).toMatchObject({ transcribed: 0, failed: [{}, {}, {}] }) }) it("lists a recording that cannot be decoded and goes on with the rest", async () => { @@ -64,7 +72,9 @@ it("lists a recording that cannot be decoded and goes on with the rest", async ( }) const done = await transcribe([], { speech: failing }) expect(done.code, done.err).toBe(0) - expect(done.json().item).toMatchObject({ transcribed: 1, failed: [{ reason: "unexpected" }] }) + const item = done.json().item as { transcribed: number; failed: { reason: string }[] } + expect(item.transcribed).toBe(1) + expect(item.failed.filter(({ reason }) => reason !== "recording.missing")).toMatchObject([{ reason: "unexpected" }]) }) it("refuses a model that is not downloaded, and says how to get it", async () => {