From bb7755f2134b20be5b756d4d3ee0e624259fd869 Mon Sep 17 00:00:00 2001 From: hive-release-bot Date: Sun, 15 Nov 2026 15:47:28 +0000 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=94=96=20release:=20v5.266.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated release commit. Compiles changelog.d/ fragments and moves the CHANGELOG.md Unreleased section into a dated v5.266.0 entry. See src/docs/releases.md. Signed-off-by: hive-release-bot --- CHANGELOG.md | 6 ++++++ changelog.d/added-inbox-zoom-teams-recordings.md | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) delete mode 100644 changelog.d/added-inbox-zoom-teams-recordings.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a675fc2d4f..2ebc61f47d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ Hive did not historically maintain a complete changelog. This file starts a prag ## Unreleased +## 2026-11-15 (v5.266.0) + +### Added + +- Inbox: Zoom and Microsoft Teams meeting recordings as sources next to Plaud — a `zoom` connector (user-level OAuth with the hosted paste flow, or Server-to-Server) that syncs cloud recordings with topic, participants, AI summary and VTT transcript into one fact each and plays them inline through the Inbox audio endpoint, and a `teams` connector scaffold (Graph application permissions, recordings and transcripts per organizer) whose Integrations card states when Entra admin consent is still missing; both are default `inbox.sources` with Connect / Check / Sync now cards. + ## 2026-11-15 (v5.265.2) ### Fixed diff --git a/changelog.d/added-inbox-zoom-teams-recordings.md b/changelog.d/added-inbox-zoom-teams-recordings.md deleted file mode 100644 index c5c01b5680..0000000000 --- a/changelog.d/added-inbox-zoom-teams-recordings.md +++ /dev/null @@ -1 +0,0 @@ -- Inbox: Zoom and Microsoft Teams meeting recordings as sources next to Plaud — a `zoom` connector (user-level OAuth with the hosted paste flow, or Server-to-Server) that syncs cloud recordings with topic, participants, AI summary and VTT transcript into one fact each and plays them inline through the Inbox audio endpoint, and a `teams` connector scaffold (Graph application permissions, recordings and transcripts per organizer) whose Integrations card states when Entra admin consent is still missing; both are default `inbox.sources` with Connect / Check / Sync now cards. From 650b265c96f9f75052c67e77884d554bdca50c91 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sun, 15 Nov 2026 10:53:46 -0500 Subject: [PATCH 2/8] =?UTF-8?q?=E2=9C=A8=20Inception=20(spek):=20voice=20n?= =?UTF-8?q?otes=20in=20the=20session=20input=20bar=20(#18272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Inception (spek): voice notes in the session input bar Write roles get a Voice button in the Sessions input bar that dictates into the Send textarea through the browser Web Speech API. Interim text is shown live, the final transcript is an editable preview, and nothing is sent until Send / Send and run (same queued /input path). Audio never reaches the Hive backend; a first-use notice says the browser vendor's speech service transcribes it. The gateway Permissions-Policy for the dashboard document becomes microphone=(self); /terminal/ (ttyd iframe) and /api/ keep microphone=(). Signed-off-by: Andy Anderson * 🐛 Voice notes tests: load the sandbox with a write role Signed-off-by: Andy Anderson --------- Signed-off-by: Andy Anderson --- changelog.d/added-sessions-voice-notes.md | 1 + src/deploy/nginx.conf | 13 +- .../dashboard-sections/workflow-and-agents.md | 2 + src/docs/security-model.md | 11 + .../config/gateway_nginx_dualstack_test.go | 42 ++++ src/pkg/dashboard/sessions_voice_ui.test.js | 212 ++++++++++++++++++ src/pkg/dashboard/static-src/css/sessions.css | 7 + src/pkg/dashboard/static-src/js/sessions.js | 143 ++++++++++++ src/pkg/dashboard/static/index.html | 150 +++++++++++++ 9 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 changelog.d/added-sessions-voice-notes.md create mode 100644 src/pkg/dashboard/sessions_voice_ui.test.js diff --git a/changelog.d/added-sessions-voice-notes.md b/changelog.d/added-sessions-voice-notes.md new file mode 100644 index 0000000000..7f308cccbd --- /dev/null +++ b/changelog.d/added-sessions-voice-notes.md @@ -0,0 +1 @@ +- Inception (spek): voice notes in the session input bar. Write roles get a Voice button that dictates into the Send text box through the browser's Web Speech API (transcribed by the browser vendor's speech service, never by Hive), with live interim text and nothing sent until Send; the gateway Permissions-Policy now allows `microphone=(self)` for the dashboard document only. diff --git a/src/deploy/nginx.conf b/src/deploy/nginx.conf index ee1210fe4b..08487626bc 100644 --- a/src/deploy/nginx.conf +++ b/src/deploy/nginx.conf @@ -27,6 +27,17 @@ http { '' close; } + # Permissions-Policy for documents served from `location /`. The dashboard + # document gets microphone=(self) so the Sessions input bar can offer + # browser voice notes (Web Speech API; transcription is done by the browser + # vendor's speech service, audio never reaches Hive). The ttyd terminal + # iframe (/terminal/) never needs the microphone and keeps microphone=(). + # /api/ responses are not documents and keep the fully closed policy. + map $uri $hive_document_permissions_policy { + default "geolocation=(), camera=(), microphone=(self)"; + ~^/terminal/ "geolocation=(), camera=(), microphone=()"; + } + # Compress JSON API responses (70-90% reduction) gzip on; gzip_types application/json text/plain text/event-stream; @@ -141,7 +152,7 @@ http { # the upstream application layer rather than at the nginx gateway (issue #3941). add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; - add_header Permissions-Policy "geolocation=(), camera=(), microphone=()" always; + add_header Permissions-Policy "$hive_document_permissions_policy" always; } } } diff --git a/src/docs/dashboard-sections/workflow-and-agents.md b/src/docs/dashboard-sections/workflow-and-agents.md index b99998c140..f7b7f4c12d 100644 --- a/src/docs/dashboard-sections/workflow-and-agents.md +++ b/src/docs/dashboard-sections/workflow-and-agents.md @@ -182,6 +182,8 @@ Named terminal sessions where a command-line AI agent runs inside Hive; everyone **What it is good for.** Use it to run a CLI agent without leaving the dashboard, hand a long task to a teammate by sharing a tab and passing them the keyboard, or let someone who logs in later follow along. People with the `read` role watch a shared session's live terminal read-only (and can read its scrollback) but never type, Send or upload. Only `owner` and `read-write` roles can start sessions, hold the keyboard, Send or upload. +**Voice notes.** In browsers with the Web Speech API (Chrome, Edge), people who can Send also see a **Voice** button in the input bar: click it, speak, and click again (or pause) to stop. The words appear live under the bar while you speak, and the final transcript is added to the Send text box for you to edit; nothing is sent until you press Send or Send and run. Transcription is done by your browser vendor's speech service (Chrome sends the audio to Google), not by Hive, and a one-line notice says so next to the button until you first use it. The dictation language follows your browser's language. Browsers without the API (for example Firefox) do not show the button. If the microphone permission is denied, nothing was heard, or the speech service is unreachable, a toast says so. + **Example.** You start a session named "fix flaky test" in the group "ci" with the Claude CLI, paste the failing log into the input bar and press Send and run. A teammate opens the same tab and watches. **When it appears.** Whenever sessions are enabled on the hive, which is the default (`GET /api/sessions` reports `enabled: true`); with `dashboard.sessions.enabled: false` or `HIVE_SESSIONS_ENABLED=false` the section is hidden. Old `#inception-section` links open this section. diff --git a/src/docs/security-model.md b/src/docs/security-model.md index 8e433f3041..b8c5060468 100644 --- a/src/docs/security-model.md +++ b/src/docs/security-model.md @@ -467,6 +467,17 @@ importance: - **Resume ids** never start with `-` and a resume command may carry only the vendor binary, a fixed set of resume words and a flag-free id, so a planted transcript name cannot add `--dangerously-skip-permissions`. +- **Voice notes stay in the browser.** The input bar's Voice button (write + roles only) uses the browser's Web Speech API, so transcription is done by + the browser vendor's speech service (Chrome sends the audio to Google), not + by Hive; the audio never reaches the Hive backend. The transcript only fills + the Send textarea and goes through the same queued `/input` path as typed + text when the user presses Send. To allow it, the gateway's + `Permissions-Policy` for the dashboard document is + `geolocation=(), camera=(), microphone=(self)` (`src/deploy/nginx.conf`, + `map $uri $hive_document_permissions_policy`); the ttyd terminal iframe + (`/terminal/`) and `/api/` responses keep `microphone=()`, and no other origin + is ever granted the microphone. Audit: `session_created`, `session_started` (the outcome of the background start), `session_closed`, `session_renamed`, `session_input` and diff --git a/src/pkg/config/gateway_nginx_dualstack_test.go b/src/pkg/config/gateway_nginx_dualstack_test.go index 32cb593b6e..f8c96cf9ba 100644 --- a/src/pkg/config/gateway_nginx_dualstack_test.go +++ b/src/pkg/config/gateway_nginx_dualstack_test.go @@ -214,3 +214,45 @@ func TestGatewayAuthRateLimiting(t *testing.T) { }) } } + +// Permissions-Policy values the gateway emits. The dashboard document allows +// the microphone for its own origin only (Sessions voice notes use the +// browser's Web Speech API); the ttyd terminal iframe and /api/ responses keep +// the fully closed policy. +const ( + gatewayDocumentPermissionsPolicy = `geolocation=(), camera=(), microphone=(self)` + gatewayClosedPermissionsPolicy = `geolocation=(), camera=(), microphone=()` +) + +// TestGatewayPermissionsPolicyMicrophoneScope pins the microphone scope of +// the gateway's Permissions-Policy: microphone=(self) only for documents +// served by `location /` outside /terminal/, never a wildcard origin list. +func TestGatewayPermissionsPolicyMicrophoneScope(t *testing.T) { + conf := readNginxConf(t) + + mapBlock := regexp.MustCompile(`(?ms)^\s*map\s+\$uri\s+\$hive_document_permissions_policy\s*\{([^}]*)\}`).FindStringSubmatch(conf) + if mapBlock == nil { + t.Fatal("nginx.conf must define `map $uri $hive_document_permissions_policy` for the dashboard document") + } + body := mapBlock[1] + if !regexp.MustCompile(`(?m)^\s*default\s+"` + regexp.QuoteMeta(gatewayDocumentPermissionsPolicy) + `";`).MatchString(body) { + t.Errorf("dashboard document Permissions-Policy default must be %q", gatewayDocumentPermissionsPolicy) + } + if !regexp.MustCompile(`(?m)^\s*~\^/terminal/\s+"` + regexp.QuoteMeta(gatewayClosedPermissionsPolicy) + `";`).MatchString(body) { + t.Errorf("the ttyd terminal iframe (/terminal/) must keep %q", gatewayClosedPermissionsPolicy) + } + + if regexp.MustCompile(`microphone=\*|microphone=\(\s*\*`).MatchString(conf) { + t.Error("nginx.conf must never allow the microphone for every origin") + } + + apiBlock := regexp.MustCompile(`(?ms)^\s*location\s+/api/\s*\{.*?add_header\s+Permissions-Policy\s+"([^"]+)"\s+always;`).FindStringSubmatch(conf) + if apiBlock == nil || apiBlock[1] != gatewayClosedPermissionsPolicy { + t.Errorf("/api/ responses must keep Permissions-Policy %q", gatewayClosedPermissionsPolicy) + } + + rootBlock := regexp.MustCompile(`(?ms)^\s*location\s+/\s*\{.*?add_header\s+Permissions-Policy\s+"([^"]+)"\s+always;`).FindStringSubmatch(conf) + if rootBlock == nil || rootBlock[1] != `$hive_document_permissions_policy` { + t.Error("`location /` must emit Permissions-Policy from $hive_document_permissions_policy") + } +} diff --git a/src/pkg/dashboard/sessions_voice_ui.test.js b/src/pkg/dashboard/sessions_voice_ui.test.js new file mode 100644 index 0000000000..19e75afd7f --- /dev/null +++ b/src/pkg/dashboard/sessions_voice_ui.test.js @@ -0,0 +1,212 @@ +// Sessions voice notes: the browser Web Speech API dictates into the Send +// textarea as an editable preview. These tests drive the shipped code (cut out +// of the generated dashboard) with a fake SpeechRecognition: start/stop, +// interim vs final text, error toasts, role gating, the unsupported-browser +// fallback, and that a transcript is never sent on its own. +// Run: node --test src/pkg/dashboard/*.test.js +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const helpersStart = html.indexOf('const SESSIONS_API'); +const helpersEnd = html.indexOf('// ── Storage conveniences'); +assert.ok(helpersStart >= 0 && helpersEnd > helpersStart, 'sessions helper block not found in index.html'); +const voiceStart = html.indexOf('// ── Voice notes (browser Web Speech API) ──'); +const voiceEnd = html.indexOf('// Registry slot: features add entries'); +assert.ok(voiceStart > helpersEnd && voiceEnd > voiceStart, 'voice notes block not found in index.html'); + +const esc = (v) => String(v == null ? '' : v).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); + +class FakeRecognition { + constructor() { FakeRecognition.instances.push(this); this.started = 0; this.stopped = 0; } + start() { if (FakeRecognition.throwOnStart) throw new Error('busy'); this.started++; } + stop() { this.stopped++; if (this.onend) this.onend(); } + emit(results, resultIndex) { + const list = results.map(([transcript, isFinal]) => Object.assign([{ transcript }], { isFinal })); + this.onresult({ resultIndex: resultIndex || 0, results: list }); + } + fail(code) { this.onerror({ error: code }); this.onend(); } +} +FakeRecognition.instances = []; +FakeRecognition.throwOnStart = false; + +class FakeEl { + constructor(id) { this.id = id; this.value = ''; this.textContent = ''; this.title = ''; this.attrs = {}; this.focused = 0; this.isConnected = true; } + setAttribute(k, v) { this.attrs[k] = String(v); } + getAttribute(k) { return this.attrs[k]; } + focus() { this.focused++; } +} + +// Load the helper block plus the voice block into one sandbox with fakes for +// the dashboard globals those functions call. +function load(win) { + const els = {}; + const document = { getElementById: (id) => els[id] || null }; + const toasts = []; + const posts = []; + const store = {}; + const changed = []; + const body = html.slice(helpersStart, helpersEnd) + '\n' + html.slice(voiceStart, voiceEnd) + + '\nreturn { sessionsVoiceCtor, sessionsCanVoice, sessionsVoiceErrorText, sessionsVoiceJoin, sessionsVoiceResults, sessionsVoiceRecognizer, sessionsVoiceHtml, sessionsVoiceToggle, sessionsVoiceStop,' + + ' setData: (d) => { _sessionsData = d; }, setRole: (r) => { _sessionsRole = r; }, current: () => _sessionsVoice };'; + const fn = new Function('window', 'document', 'navigator', 'esc', 'showToast', 'sessionsInputChanged', 'sessionsStoreSet', 'sessionsPostInput', 'sessionsApi', 'fetch', body); + const h = fn(win, document, { language: 'en-GB' }, esc, + (msg, type) => toasts.push({ msg, type }), + (el) => changed.push(el.value), + (k, v) => { store[k] = v; }, + (...args) => { posts.push(args); return Promise.resolve({}); }, + (...args) => { posts.push(args); return Promise.resolve({}); }, + (...args) => { posts.push(args); return Promise.resolve({}); }); + const id = 'abc'; + for (const name of ['sessions-input-text-', 'sessions-voice-btn-', 'sessions-voice-interim-']) els[name + id] = new FakeEl(name + id); + h.setData({ sessions: [{ id, name: 'demo', status: 'running' }], limits: {} }); + h.setRole('owner'); + return { h, els, id, toasts, posts, store, changed, box: els['sessions-input-text-' + id], btn: els['sessions-voice-btn-' + id], interim: els['sessions-voice-interim-' + id] }; +} + +const supported = () => ({ webkitSpeechRecognition: FakeRecognition }); + +test('the constructor is detected from either the standard or the webkit name', () => { + const { h } = load({}); + assert.strictEqual(h.sessionsVoiceCtor({ SpeechRecognition: FakeRecognition }), FakeRecognition); + assert.strictEqual(h.sessionsVoiceCtor({ webkitSpeechRecognition: FakeRecognition }), FakeRecognition); + assert.strictEqual(h.sessionsVoiceCtor({}), null); + assert.strictEqual(h.sessionsVoiceCtor(null), null); +}); + +test('only the roles that can Send get the mic, and only on a running session in a supporting browser', () => { + const { h } = load({}); + const run = { id: 'a', status: 'running' }; + for (const role of ['owner', 'read-write']) assert.strictEqual(h.sessionsCanVoice(role, run, supported()), true, role); + for (const role of ['read', 'merger', '', undefined]) assert.strictEqual(h.sessionsCanVoice(role, run, supported()), false, String(role)); + assert.strictEqual(h.sessionsCanVoice('owner', { id: 'a', status: 'ended' }, supported()), false); + assert.strictEqual(h.sessionsCanVoice('owner', run, {}), false, 'no Web Speech API, no mic'); + // The mic is rendered inside the input bar, which is itself gated on sessionsCanSend. + const bar = html.slice(html.indexOf('function sessionsInputBarHtml('), html.indexOf('function sessionsRefreshQueueUI(')); + assert.match(bar, /if \(!sessionsCanSend\(_sessionsRole, s\)\) return '';/); + assert.match(bar, /sessionsVoiceHtml\(s, window,/); +}); + +test('mic button is accessible, shows the vendor notice the first time, and is hidden with a reason when unsupported', () => { + const { h } = load({}); + const s = { id: 'a"b', status: 'running' }; + const on = h.sessionsVoiceHtml(s, supported(), false); + assert.match(on, /'; + if (!supported) return btn; + return btn + + (noticeSeen ? '' : '' + esc(SESSIONS_VOICE_NOTICE) + '') + + ''; + } // ── Storage conveniences (never required) ── function sessionsStoreGet(key) { try { return localStorage.getItem(key) || ''; } catch (e) { return ''; } } @@ -429,6 +519,7 @@ + '
' + '' + '' + + sessionsVoiceHtml(s, window, !!sessionsStoreGet(SESSIONS_VOICE_NOTICE_KEY)) + '' + more + '' + (max ? '0 / ' + sessionsFormatBytes(max) : '') + '
' @@ -667,6 +758,7 @@ // ── Actions (data-action handlers) ── function sessionsSelect(id) { if (!id || id === _sessionsSelected) return; + sessionsVoiceStop(); _sessionsSelected = id; sessionsStoreSet(SESSIONS_SELECTED_KEY, id); renderSessions(); @@ -867,6 +959,57 @@ } catch (e) { showToast('Could not attach the file: ' + e.message, 'error'); } el.value = ''; } + // ── Voice notes (browser Web Speech API) ── + // Click to start, click again (or pause) to stop. Final text lands in the + // Send textarea for editing; nothing is posted until Send / Send and run. + function sessionsVoiceSyncButton(id, on) { + const btn = document.getElementById('sessions-voice-btn-' + id); + if (!btn) return; + btn.setAttribute('aria-pressed', on ? 'true' : 'false'); + btn.textContent = on ? SESSIONS_VOICE_STOP_LABEL : SESSIONS_VOICE_LABEL; + btn.title = on ? SESSIONS_VOICE_STOP_TITLE : SESSIONS_VOICE_TITLE; + } + function sessionsVoiceStop() { + const cur = _sessionsVoice; + if (!cur) return; + try { cur.rec.stop(); } catch (e) { /* already stopped */ } + } + function sessionsVoiceToggle(id) { + if (_sessionsVoice) { + const same = _sessionsVoice.id === id; + sessionsVoiceStop(); + if (same) return; + } + const s = (_sessionsData.sessions || []).find(function(x) { return x.id === id; }); + if (!sessionsCanSend(_sessionsRole, s)) return; + const Ctor = sessionsVoiceCtor(window); + if (!Ctor) { showToast(SESSIONS_VOICE_UNSUPPORTED, 'error'); return; } + const box = document.getElementById('sessions-input-text-' + id); + if (!box) return; + const interim = document.getElementById('sessions-voice-interim-' + id); + const rec = sessionsVoiceRecognizer(Ctor, (typeof navigator !== 'undefined' && navigator.language) || '', { + onFinal: function(text) { + box.value = sessionsVoiceJoin(box.value, text); + sessionsInputChanged(box); + }, + onInterim: function(text) { if (interim) interim.textContent = text || ''; }, + onError: function(msg) { showToast(msg, 'error'); }, + onEnd: function() { + if (_sessionsVoice && _sessionsVoice.rec === rec) _sessionsVoice = null; + sessionsVoiceSyncButton(id, false); + if (box.isConnected !== false && box.focus) box.focus(); + } + }); + _sessionsVoice = { id: id, rec: rec }; + try { rec.start(); } + catch (e) { + _sessionsVoice = null; + showToast('Could not start the voice note: ' + e.message, 'error'); + return; + } + sessionsStoreSet(SESSIONS_VOICE_NOTICE_KEY, '1'); + sessionsVoiceSyncButton(id, true); + } // Registry slot: features add entries to the input bar's "More" menu. function sessionsRegisterInputAction(action) { if (!action || !action.id || !action.label || typeof action.run !== 'function') return false; diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index ba08c50fa5..4401bdeaf1 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -7837,6 +7837,13 @@ .sessions-attach:focus-within { outline: var(--focus-ring-width) solid var(--accent); } .sessions-input-count { margin-left: auto; color: var(--muted); font-size: var(--fs-xs); } .sessions-input-count.over { color: var(--red); } + /* Voice notes: the mic is accented while dictating; the live interim + line and the first-use vendor notice are muted helper text. */ + .sessions-voice-btn[aria-pressed="true"] { color: var(--red); border-color: var(--red); } + .sessions-voice-btn[hidden] { display: none; } + .sessions-voice-interim { color: var(--muted); font-size: var(--fs-xs); font-style: italic; } + .sessions-voice-interim:empty { display: none; } + .sessions-voice-notice { color: var(--muted); font-size: var(--fs-xs); } /* Presence and the keyboard lease (pane header). The holder's own line is accented; a viewer without the keyboard sees the muted "watching" pill. */ .sessions-presence { color: var(--muted); font-size: var(--fs-xs); cursor: help; } @@ -50679,6 +50686,25 @@

GitHub Projects sync

// once the holder released it or has been idle for the server's grace. const SESSIONS_KEYBOARD_TAKE = 'take'; const SESSIONS_KEYBOARD_RELEASE = 'release'; + // Voice notes: the browser's Web Speech API dictates into the Send + // textarea as an editable preview. Nothing is sent until Send / Send and + // run, and the audio never reaches Hive: the browser vendor's speech + // service transcribes it. One utterance per click (silence ends it). + const SESSIONS_VOICE_NOTICE_KEY = 'hive.sessions.voiceNoticeSeen'; + const SESSIONS_VOICE_NOTICE = 'Voice notes are transcribed by your browser vendor\'s speech service (Chrome sends the audio to Google), not by Hive.'; + const SESSIONS_VOICE_TITLE = 'Dictate into the text box (click again or pause to stop). Nothing is sent until you press Send.'; + const SESSIONS_VOICE_STOP_TITLE = 'Stop dictating'; + const SESSIONS_VOICE_UNSUPPORTED = 'Voice notes are unavailable: this browser has no Web Speech API (for example Firefox).'; + const SESSIONS_VOICE_LABEL = 'Voice'; + const SESSIONS_VOICE_STOP_LABEL = 'Stop'; + const SESSIONS_VOICE_ERRORS = Object.freeze({ + 'not-allowed': 'Microphone permission was denied. Allow the microphone for this site to use voice notes.', + 'service-not-allowed': 'The browser\'s speech service is not allowed here, so voice notes are unavailable.', + 'no-speech': 'No speech was heard. Click Voice and try again.', + 'audio-capture': 'No microphone was found.', + 'network': 'The browser\'s speech service could not be reached (network error).', + 'aborted': 'Voice note stopped before any text was recognised.' + }); let _sessionsData = { enabled: false, sessions: [], vendors: [], limits: {}, workspace: {} }; let _sessionsRole = ''; @@ -50689,6 +50715,7 @@

GitHub Projects sync

let _sessionsLogTimerOn = false; let _sessionsAssertionTimerOn = false; let _sessionsPrepPollOn = false; + let _sessionsVoice = null; const _sessionsFrames = {}; const _sessionsFrameFailed = {}; // Extension slot for the input bar: other features (for example future @@ -50869,6 +50896,76 @@

GitHub Projects sync

return '/terminal/?arg=' + encodeURIComponent(sessionsTmuxName(id)) + (code ? '&code=' + encodeURIComponent(code) : ''); } function sessionsIsEnabled() { return window._sessionsEnabled === true; } + // ── Voice notes helpers (unit-tested with a fake SpeechRecognition) ── + function sessionsVoiceCtor(win) { + if (!win) return null; + return win.SpeechRecognition || win.webkitSpeechRecognition || null; + } + // Same gate as Send (read-write, owner on a running session) plus browser support. + function sessionsCanVoice(role, session, win) { + return sessionsCanSend(role, session) && !!sessionsVoiceCtor(win); + } + function sessionsVoiceErrorText(code) { + return SESSIONS_VOICE_ERRORS[code] || ('Voice note failed: ' + (code || 'unknown error') + '.'); + } + // Append dictated text to what is already in the box, one space apart. + function sessionsVoiceJoin(base, addition) { + const add = String(addition || '').trim(); + const head = String(base || ''); + if (!add) return head; + if (!head || /\s$/.test(head)) return head + add; + return head + ' ' + add; + } + // Split a SpeechRecognitionEvent into newly final text and the live interim tail. + function sessionsVoiceResults(ev) { + const out = { final: '', interim: '' }; + const results = ev && ev.results; + if (!results) return out; + for (let i = Number(ev.resultIndex) || 0; i < results.length; i++) { + const r = results[i]; + const alt = r && r[0]; + const text = alt && alt.transcript ? String(alt.transcript) : ''; + if (r && r.isFinal) out.final = sessionsVoiceJoin(out.final, text); + else out.interim = sessionsVoiceJoin(out.interim, text); + } + return out; + } + // Build (not start) a recognizer. hooks: onFinal(text), onInterim(text), + // onError(message), onEnd(). It never sends anything anywhere itself. + function sessionsVoiceRecognizer(Ctor, lang, hooks) { + const h = hooks || {}; + const rec = new Ctor(); + rec.lang = lang || ''; + rec.interimResults = true; + rec.continuous = false; + rec.maxAlternatives = 1; + rec.onresult = function(ev) { + const r = sessionsVoiceResults(ev); + if (r.final && h.onFinal) h.onFinal(r.final); + if (h.onInterim) h.onInterim(r.interim); + }; + rec.onerror = function(ev) { + if (h.onError) h.onError(sessionsVoiceErrorText(ev && ev.error)); + }; + rec.onend = function() { + if (h.onInterim) h.onInterim(''); + if (h.onEnd) h.onEnd(); + }; + return rec; + } + // The mic button, its live interim line and the first-use notice. Hidden + // (with the reason in its title) when the browser has no Web Speech API. + function sessionsVoiceHtml(s, win, noticeSeen) { + if (!s) return ''; + const id = esc(s.id); + const supported = !!sessionsVoiceCtor(win); + const btn = ''; + if (!supported) return btn; + return btn + + (noticeSeen ? '' : '' + esc(SESSIONS_VOICE_NOTICE) + '') + + ''; + } // ── Storage conveniences (never required) ── function sessionsStoreGet(key) { try { return localStorage.getItem(key) || ''; } catch (e) { return ''; } } @@ -51072,6 +51169,7 @@

GitHub Projects sync

+ '
' + '' + '' + + sessionsVoiceHtml(s, window, !!sessionsStoreGet(SESSIONS_VOICE_NOTICE_KEY)) + '' + more + '' + (max ? '0 / ' + sessionsFormatBytes(max) : '') + '
' @@ -51310,6 +51408,7 @@

GitHub Projects sync

// ── Actions (data-action handlers) ── function sessionsSelect(id) { if (!id || id === _sessionsSelected) return; + sessionsVoiceStop(); _sessionsSelected = id; sessionsStoreSet(SESSIONS_SELECTED_KEY, id); renderSessions(); @@ -51510,6 +51609,57 @@

GitHub Projects sync

} catch (e) { showToast('Could not attach the file: ' + e.message, 'error'); } el.value = ''; } + // ── Voice notes (browser Web Speech API) ── + // Click to start, click again (or pause) to stop. Final text lands in the + // Send textarea for editing; nothing is posted until Send / Send and run. + function sessionsVoiceSyncButton(id, on) { + const btn = document.getElementById('sessions-voice-btn-' + id); + if (!btn) return; + btn.setAttribute('aria-pressed', on ? 'true' : 'false'); + btn.textContent = on ? SESSIONS_VOICE_STOP_LABEL : SESSIONS_VOICE_LABEL; + btn.title = on ? SESSIONS_VOICE_STOP_TITLE : SESSIONS_VOICE_TITLE; + } + function sessionsVoiceStop() { + const cur = _sessionsVoice; + if (!cur) return; + try { cur.rec.stop(); } catch (e) { /* already stopped */ } + } + function sessionsVoiceToggle(id) { + if (_sessionsVoice) { + const same = _sessionsVoice.id === id; + sessionsVoiceStop(); + if (same) return; + } + const s = (_sessionsData.sessions || []).find(function(x) { return x.id === id; }); + if (!sessionsCanSend(_sessionsRole, s)) return; + const Ctor = sessionsVoiceCtor(window); + if (!Ctor) { showToast(SESSIONS_VOICE_UNSUPPORTED, 'error'); return; } + const box = document.getElementById('sessions-input-text-' + id); + if (!box) return; + const interim = document.getElementById('sessions-voice-interim-' + id); + const rec = sessionsVoiceRecognizer(Ctor, (typeof navigator !== 'undefined' && navigator.language) || '', { + onFinal: function(text) { + box.value = sessionsVoiceJoin(box.value, text); + sessionsInputChanged(box); + }, + onInterim: function(text) { if (interim) interim.textContent = text || ''; }, + onError: function(msg) { showToast(msg, 'error'); }, + onEnd: function() { + if (_sessionsVoice && _sessionsVoice.rec === rec) _sessionsVoice = null; + sessionsVoiceSyncButton(id, false); + if (box.isConnected !== false && box.focus) box.focus(); + } + }); + _sessionsVoice = { id: id, rec: rec }; + try { rec.start(); } + catch (e) { + _sessionsVoice = null; + showToast('Could not start the voice note: ' + e.message, 'error'); + return; + } + sessionsStoreSet(SESSIONS_VOICE_NOTICE_KEY, '1'); + sessionsVoiceSyncButton(id, true); + } // Registry slot: features add entries to the input bar's "More" menu. function sessionsRegisterInputAction(action) { if (!action || !action.id || !action.label || typeof action.run !== 'function') return false; From 4da44cf14a873d45644cce103c903adf7711746d Mon Sep 17 00:00:00 2001 From: Danathar Date: Sun, 15 Nov 2026 11:03:17 -0500 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=90=9B=20fix(ci):=20native-queue-poli?= =?UTF-8?q?cy=20names=20a=20red=20provider=20as=20a=20per-PR=20verdict=20(?= =?UTF-8?q?#18281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit native-queue-policy went red on #17512, #18273, #18275 and #18278 and the scanner filed it as one shared-CI incident (#18280). The gate was right every time: #17512 is a draft carrying do-not-merge/work-in-progress, #18273 and #18275 have probot DCO action_required, and #18278 has changelog-fragment-guard failure. The defect was the surface. A red provider was thrown as a bare `Error('DCO: action_required')` and printed as "Unhandled error" with a stack trace, which reads like a broken workflow. evidenceForHead and assertProwDCO now throw a ProviderVerdict naming the provider, its conclusion, the head, and that this is a per-PR verdict and not a shared CI incident. The evidence-wait step reports it with a job summary and core.setFailed instead of rethrowing. The conclusion stays failure: this is a required check. Hive-Run: hivecommons/hive#18280 Hive-Plan: shared-ci incident triage Hive-Spec: native-queue-policy#provider-verdict Co-Authored-By: Claude Opus 5.5 Signed-off-by: Danathar --- .github/scripts/native-queue-policy.cjs | 23 +++++++++++-- .github/scripts/native-queue-policy.test.cjs | 34 ++++++++++++++++--- .../scripts/test-native-queue-workflows.py | 12 +++++++ .github/workflows/native-queue-policy.yml | 13 ++++++- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/.github/scripts/native-queue-policy.cjs b/.github/scripts/native-queue-policy.cjs index 9bd9b8df13..b90fc0f2da 100644 --- a/.github/scripts/native-queue-policy.cjs +++ b/.github/scripts/native-queue-policy.cjs @@ -58,6 +58,23 @@ class ProviderUnavailable extends Error { } } +// A provider that completed red on this exact head is that PR's own verdict +// (a missing sign-off, a missing changelog fragment, a failed verifier), never +// a broken admission workflow. Name it as such: four PRs each red on their own +// provider read like one shared incident and got filed as one (#18280). It is +// a hard failure, deliberately not PendingEvidence: waiting cannot change a +// completed verdict, and only a new push to the PR re-runs the providers. +const PROVIDER_VERDICT_NOTE = + 'per-PR provider verdict, not a shared CI incident: fix it on this PR; the next push re-evaluates'; + +class ProviderVerdict extends Error { + constructor(provider, conclusion, head) { + super(`${provider}: ${conclusion} on ${head} (${PROVIDER_VERDICT_NOTE})`); + this.provider = provider; + this.conclusion = conclusion; + } +} + function dcoEnumerationUnavailable(run) { // This text only classifies a diagnostic, never supplies passing evidence. // Call only after validating provider, head and completed status. @@ -134,7 +151,7 @@ function evidenceForHead(runs, head, checks) { // Existing PR path scoping legitimately skips technical jobs only. Policy // proofs, especially external DCO, must have actually succeeded. const scopedSkip = Object.hasOwn(BUILD_CHECKS, name) && run.conclusion === 'skipped'; - if (run.conclusion !== 'success' && !scopedSkip) throw new Error(`${name}: ${run.conclusion}`); + if (run.conclusion !== 'success' && !scopedSkip) throw new ProviderVerdict(name, run.conclusion, head); return { run, source }; }); } @@ -229,7 +246,7 @@ async function assertProwDCO(github, repo, head) { .sort((a, b) => b.id - a.id)[0]; if (!status) throw new PendingEvidence(`Missing prow ${PROW.context} on ${head}`); if (status.state === 'pending') throw new PendingEvidence(`prow ${PROW.context} is pending`); - if (status.state !== 'success') throw new Error(`prow ${PROW.context}: ${status.state}`); + if (status.state !== 'success') throw new ProviderVerdict(`prow ${PROW.context}`, status.state, head); } async function assertEvidence(github, repo, number, head, checks, pr) { @@ -427,7 +444,7 @@ module.exports = { ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS, PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate, isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL, - ProviderUnavailable, FORWARD_MERGE, PROW, + ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW, DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK, DCO_PROVIDER_UNAVAILABLE_TEXT, DCO_PROVIDER_RUNBOOK, }; diff --git a/.github/scripts/native-queue-policy.test.cjs b/.github/scripts/native-queue-policy.test.cjs index 8e7d626d63..ea58100a1c 100644 --- a/.github/scripts/native-queue-policy.test.cjs +++ b/.github/scripts/native-queue-policy.test.cjs @@ -5,7 +5,7 @@ const { ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS, PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate, isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, - ProviderUnavailable, FORWARD_MERGE, PROW, + ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW, DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK, DCO_PROVIDER_UNAVAILABLE_TEXT, @@ -203,7 +203,30 @@ test('UNKNOWN reporting requires trusted exact-head completed DCO and the specif error => !(error instanceof ProviderUnavailable)); } assert.throws(() => evidenceForHead([{ ...dco, conclusion: 'failure' }], sha(11), { DCO: null }), - error => !(error instanceof ProviderUnavailable) && error.message === 'DCO: failure'); + error => !(error instanceof ProviderUnavailable) && error instanceof ProviderVerdict && + error.message.startsWith(`DCO: failure on ${sha(11)} `)); +}); + +test('a red provider is named as a per-PR verdict, not a shared CI incident (#18280)', async () => { + for (const [name, conclusion] of [ + ['DCO', 'action_required'], ['changelog-fragment-guard', 'failure'], + ['verify PR contents', 'cancelled'], ['Sign-off survives the squash', 'timed_out'], + ]) { + const f = fixture('pull_request_target'); + f.state.runs.get(sha(11)).find(r => r.name === name).conclusion = conclusion; + await assert.rejects(evaluate(f), error => { + assert.ok(error instanceof ProviderVerdict, `${name} must be a ProviderVerdict`); + assert.ok(!(error instanceof PendingEvidence), 'a completed verdict is not worth waiting on'); + assert.equal(error.provider, name); + assert.equal(error.conclusion, conclusion); + assert.ok(error.message.startsWith(`${name}: ${conclusion} on ${sha(11)} (`), error.message); + assert.ok(error.message.includes(PROVIDER_VERDICT_NOTE), error.message); + return true; + }); + } + // A path-scoped skip of a technical job is still not a verdict. + const runs = checks(sha(11), BUILD_CHECKS).map(r => ({ ...r, conclusion: 'skipped' })); + assert.doesNotThrow(() => evidenceForHead(runs, sha(11), BUILD_CHECKS)); }); // #17030: v6-topup.yml's PR whose probot DCO rejects a commit already on v5. @@ -277,19 +300,20 @@ test('another head branch, base, fork or author keeps requiring probot DCO', asy ]) { const f = forwardMergeFixture(); change(f.state.prs[0]); - await assert.rejects(evaluate(f), error => error.message === 'DCO: action_required'); + await assert.rejects(evaluate(f), error => error.message === `DCO: action_required on ${sha(11)} (${PROVIDER_VERDICT_NOTE})`); assert.equal(f.state.seen.length, 0); } const v5 = forwardMergeFixture(); v5.state.prs[0].base.ref = 'v5'; v5.context.payload.pull_request.base.ref = 'v5'; - await assert.rejects(evaluate(v5), error => error.message === 'DCO: action_required'); + await assert.rejects(evaluate(v5), error => error.message === `DCO: action_required on ${sha(11)} (${PROVIDER_VERDICT_NOTE})`); }); test('forward-merge path fails without a successful prow-created dco status', async () => { const failed = forwardMergeFixture(); failed.state.statuses.push({ id: 2, context: 'dco', state: 'failure', creator: { login: PROW.login, id: PROW.id } }); - await assert.rejects(evaluate(failed), /prow dco: failure.*DCO path: prow dco/); + await assert.rejects(evaluate(failed), error => error instanceof ProviderVerdict && + /prow dco: failure on .*per-PR provider verdict.*DCO path: prow dco/.test(error.message)); // Any workflow token can post a `dco` status; it never stands in for prow. const forged = forwardMergeFixture(); forged.state.statuses = [{ id: 3, context: 'dco', state: 'success', creator: { login: 'github-actions[bot]', id: 41898282 } }]; diff --git a/.github/scripts/test-native-queue-workflows.py b/.github/scripts/test-native-queue-workflows.py index 26a806b6f3..7ed06431dd 100644 --- a/.github/scripts/test-native-queue-workflows.py +++ b/.github/scripts/test-native-queue-workflows.py @@ -99,6 +99,18 @@ def test_cosmetic_label_flips_skip_the_evidence_wait(self): self.assertIn("steps.label-flip.outputs.cosmetic != 'true'", wait["if"]) self.assertLess(steps.index(gate), steps.index(wait)) + def test_red_provider_is_reported_not_thrown(self): + # A PR's own red provider must surface as a named per-PR verdict, not + # an "Unhandled error" stack trace that reads like a broken shared + # workflow and gets filed as an incident (#18280). + steps = workflow("native-queue-policy.yml")["jobs"]["policy"]["steps"] + wait = next(s for s in steps if s.get("name", "").startswith("Validate exact-head evidence")) + script = wait["with"]["script"] + self.assertIn("error instanceof ProviderVerdict", script) + verdict = script[script.index("error instanceof ProviderVerdict"):] + self.assertLess(verdict.index("core.setFailed(error.message)"), + verdict.index("instanceof PendingEvidence")) + def test_dependabot_runs_the_same_trusted_pr_verifier(self): verifier = workflow("pr-verifier.yml") events = verifier.get("on", verifier.get(True)) diff --git a/.github/workflows/native-queue-policy.yml b/.github/workflows/native-queue-policy.yml index 9469ed0203..d761e558c9 100644 --- a/.github/workflows/native-queue-policy.yml +++ b/.github/workflows/native-queue-policy.yml @@ -74,7 +74,7 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | - const { evaluate, PendingEvidence, ProviderUnavailable } = require('./.github/scripts/native-queue-policy.cjs'); + const { evaluate, PendingEvidence, ProviderUnavailable, ProviderVerdict } = require('./.github/scripts/native-queue-policy.cjs'); const attempts = 90; const intervalMs = 15000; for (let attempt = 0; attempt < attempts; attempt++) { @@ -90,6 +90,17 @@ jobs: core.setFailed(error.message); return; } + if (error instanceof ProviderVerdict) { + // The PR's own provider is red (#18280): a per-PR verdict to + // fix on the PR, reported plainly rather than as an + // unhandled exception that reads like a broken workflow. + await core.summary + .addHeading('Admission blocked: ' + error.provider + ' is ' + error.conclusion + ' on this PR') + .addRaw(error.message) + .write(); + core.setFailed(error.message); + return; + } if (!(error instanceof PendingEvidence) || attempt === attempts - 1) throw error; core.info(error.message); await new Promise(resolve => setTimeout(resolve, intervalMs)); From 9529da9c2936b37187ea103a410fd6d8e16d12a2 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sun, 15 Nov 2026 11:16:49 -0500 Subject: [PATCH 4/8] =?UTF-8?q?=E2=9C=A8=20Inbox:=20Deepgram=20transcripti?= =?UTF-8?q?on=20for=20recordings=20without=20text=20(manual)=20(#18274)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Inbox: Deepgram transcription for recordings without text (manual) Adds spoke-local machine transcription for Inbox items that arrive without text. Each hive owns its transcriptions: the owner's own Deepgram key (env var, never in hive.yaml), transcripts stored only on the spoke, per-hive budget, nothing shared or billed centrally. Off by default. - pkg/transcribe: Transcriber interface, Deepgram pre-recorded adapter (nova-3, diarize, smart_format, utterances, mip_opt_out=true, streamed body, timeout, 401/403 key error naming the env var, 429/5xx retryable), Retry wrapper, LimitReader, Fake adapter, RenderSegments/WriteLine. - Plaud transcript renderer now uses the shared line formatter. - config: inbox.transcription with named defaults, env overrides for the limits, validation and the consent gate. - inbox: transcript store (0600, atomic) under connector-state/transcripts, usage ledger, state machine, budget and size checks before upload, content fallback where upstream text wins. - dashboard: POST /api/inbox/{source}/{id}/transcribe (owner or read-write, audited per run as inbox_transcribe), settings field, Transcribe button, state pill and the settings section with the consent notice. - Docs, OpenAPI, API reference, env vars, changelog fragment. Signed-off-by: Andy Anderson * ♻️ Inbox transcription: renderVTT on the shared line formatter; fix role test - renderVTT (meeting.go, now on v5) writes its lines through transcribe.WriteLine/FormatOffset like Plaud and machine transcripts. - Zoom/Teams/Discord pending notes mention the Transcribe button too. - JS test passes an empty role instead of undefined (a default param turned undefined into owner). Signed-off-by: Andy Anderson * 🐛 config: omit an unset inbox.transcription from the JSON view (agent runtime golden) Signed-off-by: Andy Anderson --------- Signed-off-by: Andy Anderson --- .../added-inbox-deepgram-transcription.md | 1 + dashboard/openapi.json | 189 +++++++ dashboard/test/inbox-item.test.js | 5 +- src/cmd/hive/boot_inbox.go | 6 +- src/docs/api-reference/knowledge.md | 1 + src/docs/documentation-map.md | 1 + src/docs/env-vars.md | 5 + src/docs/inbox-transcription.md | 145 +++++ src/docs/inbox-voice-sources.md | 9 +- src/docs/knowledge-connectors.md | 4 +- src/pkg/config/inbox_config.go | 6 + src/pkg/config/inbox_transcription.go | 216 +++++++ src/pkg/config/inbox_transcription_test.go | 112 ++++ src/pkg/dashboard/api_inbox.go | 60 +- .../dashboard/api_inbox_transcribe_test.go | 214 +++++++ src/pkg/dashboard/inbox_transcribe.test.js | 161 ++++++ src/pkg/dashboard/static-src/css/inbox.css | 4 + .../dashboard/static-src/js/config-state.js | 2 +- src/pkg/dashboard/static-src/js/inbox.js | 134 ++++- src/pkg/dashboard/static/index.html | 140 ++++- src/pkg/inbox/inbox.go | 11 + src/pkg/inbox/service.go | 38 +- src/pkg/inbox/transcription.go | 466 ++++++++++++++++ src/pkg/inbox/transcription_test.go | 527 ++++++++++++++++++ src/pkg/inbox/transcripts.go | 241 ++++++++ src/pkg/knowledge/connector/meeting.go | 24 +- src/pkg/knowledge/connector/plaud_auth.go | 20 +- src/pkg/transcribe/deepgram.go | 267 +++++++++ src/pkg/transcribe/fake.go | 69 +++ src/pkg/transcribe/transcribe.go | 220 ++++++++ src/pkg/transcribe/transcribe_test.go | 376 +++++++++++++ 31 files changed, 3614 insertions(+), 60 deletions(-) create mode 100644 changelog.d/added-inbox-deepgram-transcription.md create mode 100644 src/docs/inbox-transcription.md create mode 100644 src/pkg/config/inbox_transcription.go create mode 100644 src/pkg/config/inbox_transcription_test.go create mode 100644 src/pkg/dashboard/api_inbox_transcribe_test.go create mode 100644 src/pkg/dashboard/inbox_transcribe.test.js create mode 100644 src/pkg/inbox/transcription.go create mode 100644 src/pkg/inbox/transcription_test.go create mode 100644 src/pkg/inbox/transcripts.go create mode 100644 src/pkg/transcribe/deepgram.go create mode 100644 src/pkg/transcribe/fake.go create mode 100644 src/pkg/transcribe/transcribe.go create mode 100644 src/pkg/transcribe/transcribe_test.go diff --git a/changelog.d/added-inbox-deepgram-transcription.md b/changelog.d/added-inbox-deepgram-transcription.md new file mode 100644 index 0000000000..43a66c1ab5 --- /dev/null +++ b/changelog.d/added-inbox-deepgram-transcription.md @@ -0,0 +1 @@ +- **Inbox: Deepgram transcription for recordings without text (manual).** A pending Inbox item with audio (for example a Plaud recording never transcribed in the Plaud app) now has a **🎧 Transcribe** button for owners and read-write sessions. The hive downloads the audio itself and streams it to Deepgram's pre-recorded API (`nova-3`, diarized, `mip_opt_out=true` so the audio is not used for training) under the hive owner's own `DEEPGRAM_API_KEY`; presigned links are never forwarded or logged. Each hive owns its transcriptions: the transcript is stored only on that spoke (`connector-state/transcripts//.json`, 0600), shown as *Transcript (machine: deepgram/nova-3)* in the shared `[mm:ss] Speaker N: text` shape, and replaced by the source's own transcript when one appears. New `inbox.transcription` config (off by default; enabling requires `consent_acknowledged: true`) with per-hive monthly minutes, daily item, duration and size limits checked before upload; every run is audited as `inbox_transcribe` with outcome and estimated cost. See `src/docs/inbox-transcription.md`. diff --git a/dashboard/openapi.json b/dashboard/openapi.json index 292355c6f1..afb37000c5 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -38265,6 +38265,195 @@ } } }, + "/api/inbox/{source}/{id}/transcribe": { + "post": { + "tags": [ + "Knowledge" + ], + "summary": "Transcribe one pending inbox item with Deepgram", + "description": "Owner or read-write. Queues a machine transcription of a pending item (no summary, no transcript) on this hive, with the hive owner's own Deepgram key (`inbox.transcription.api_key_env`, default `DEEPGRAM_API_KEY`). The hive downloads the audio itself and streams it to Deepgram; the presigned link is never forwarded, stored or logged. The transcript stays on this spoke. Checks that need no upload (no audio, too long, daily cap, monthly budget) are recorded as `skipped` and answered 200. Each run is audited as `inbox_transcribe`.", + "parameters": [ + { + "name": "source", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Source type (`plaud`, `wisprflow`, ...)" + }, + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + }, + "description": "Upstream item id (for Plaud, the file id)" + } + ], + "responses": { + "200": { + "description": "Skipped before upload (reason in state.reason)", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "source": { + "type": "string" + }, + "item_id": { + "type": "string" + }, + "state": { + "type": "object", + "properties": { + "status": { + "type": "string", + "enum": [ + "queued", + "running", + "done", + "failed", + "skipped" + ] + }, + "reason": { + "type": "string" + }, + "attempts": { + "type": "integer" + }, + "provider": { + "type": "string" + }, + "model": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + } + } + } + } + } + } + } + }, + "202": { + "description": "Queued", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "source": { + "type": "string" + }, + "item_id": { + "type": "string" + }, + "state": { + "type": "object", + "properties": { + "status": { + "type": "string", + "enum": [ + "queued", + "running", + "done", + "failed", + "skipped" + ] + }, + "reason": { + "type": "string" + }, + "attempts": { + "type": "integer" + }, + "provider": { + "type": "string" + }, + "model": { + "type": "string" + }, + "updated_at": { + "type": "string", + "format": "date-time" + } + } + } + } + } + } + } + }, + "403": { + "description": "Not owner or read-write", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + }, + "404": { + "description": "Unknown item, or the Inbox is not available", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + }, + "409": { + "description": "Already queued/running, already transcribed, or the item has text from its source", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + }, + "412": { + "description": "Transcription is disabled or not consented (inbox.transcription.enabled / consent_acknowledged)", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + } + } + } + }, "/api/inbox/settings": { "get": { "tags": [ diff --git a/dashboard/test/inbox-item.test.js b/dashboard/test/inbox-item.test.js index 01af9c7430..4ae7ef7ad1 100644 --- a/dashboard/test/inbox-item.test.js +++ b/dashboard/test/inbox-item.test.js @@ -35,6 +35,9 @@ function makeContext(role) { _inboxExpanded: new Set(), _inboxTranscriptOpen: new Set(), _inboxContent: {}, + _inboxTranscribing: new Set(), + INBOX_TX_STATUS_LABELS: { queued: 'Transcription queued', running: 'Transcribing', done: 'Machine transcript', failed: 'Transcription failed', skipped: 'Not transcribed' }, + formatDashboardDateTime: (s) => String(s), escapeHtml: (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'), viewerIsOwner: () => role === 'owner', relativeTimeShort: () => '2h ago', @@ -45,7 +48,7 @@ function makeContext(role) { Array, }; vm.createContext(ctx); - for (const fn of ['inboxSourceIcon', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxItemHtml']) { + for (const fn of ['inboxSourceIcon', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTranscriptionHtml', 'inboxItemHtml']) { vm.runInContext(extractFunction(fn), ctx); } return ctx; diff --git a/src/cmd/hive/boot_inbox.go b/src/cmd/hive/boot_inbox.go index 6236bccd7d..ddcfc4562f 100644 --- a/src/cmd/hive/boot_inbox.go +++ b/src/cmd/hive/boot_inbox.go @@ -21,7 +21,8 @@ const inboxSweepTimeout = 2 * time.Minute // plaud/wisprflow); with none configured the service still exists and lists // nothing, so the dashboard shows the empty state. Items are read from the connector vaults under /connectors; // route state persists at /connector-state/_inbox.json (connector -// names cannot start with "_", so it never collides with a connector). +// names cannot start with "_", so it never collides with a connector), and +// machine transcripts under /connector-state/transcripts. func (b *boot) bootInbox(baseDir string) { srcs := b.inboxSources(baseDir, b.cfg.Knowledge.Connectors, b.knowledgeConnectors) token := func(ctx context.Context, _ string) (string, error) { @@ -46,6 +47,9 @@ func (b *boot) bootInbox(baseDir string) { store := inbox.NewStore(filepath.Join(baseDir, "connector-state", "_inbox.json")) svc := inbox.NewService(b.cfg.Inbox, store, srcs, dashboard.NewInboxDestinations(b.cfg, token, kick), b.logger) svc.SetReadiness(dashboard.InboxReadiness(b.cfg)) + // Machine transcripts stay on this spoke's own data volume; runs only + // happen once inbox.transcription is enabled and consented to. + svc.EnableTranscription(inbox.NewTranscriptStore(filepath.Join(baseDir, "connector-state", "transcripts"))) b.inboxSvc = svc b.logger.Info("inbox started", "sources", len(srcs), "rules", len(b.cfg.Inbox.Rules)) } diff --git a/src/docs/api-reference/knowledge.md b/src/docs/api-reference/knowledge.md index 6a7463ea52..3dde449989 100644 --- a/src/docs/api-reference/knowledge.md +++ b/src/docs/api-reference/knowledge.md @@ -72,4 +72,5 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `GET` | `/api/inbox/settings` | Dashboard auth/session | Auto-routing rules, default RFC repo, dibs URL, destination readiness | `pkg/dashboard/api_inbox.go:27` | | `POST` | `/api/inbox/settings` | Owner only | Update `inbox.rules` / `inbox.spek.repo` / `inbox.dibs.url` in the runtime config (omitted fields unchanged) | `pkg/dashboard/api_inbox.go:28` | | `GET` | `/api/inbox/{source}/{id}/content` | Dashboard auth/session | Full text of one item: `{title, summary, transcript, highlights, markdown, pending, provenance}`, from the fact or live from the source while the fact has no text yet (404 unknown item, 502 source unreachable) | `pkg/dashboard/api_inbox.go:29` | +| `POST` | `/api/inbox/{source}/{id}/transcribe` | Owner or read-write | Queue a machine transcription of one pending item with the owner's own Deepgram key (202 `{source, item_id, state}`; 200 when skipped up front: no audio, too long, budget); audited per run as `inbox_transcribe` (403 role, 404 unknown item, 409 queued/running/already transcribed/has text, 412 disabled or not consented); see [inbox-transcription.md](../inbox-transcription.md) | `pkg/dashboard/api_inbox.go:32` | | `GET` | `/api/inbox/{source}/{id}/audio` | Owner or read-write | Mint a fresh short-lived audio/video link for one item (`{url, expires_at}`; Plaud: presigned, 24h; Zoom: audio-only or video `download_url` with a one-hour download token; Teams: 404, no browser-playable link); never stored by the hive, replied with `Cache-Control: no-store`, audited as `inbox_audio` (403 role, 404 unknown item or no audio, 502 source unreachable) | `pkg/dashboard/api_inbox.go:30` | diff --git a/src/docs/documentation-map.md b/src/docs/documentation-map.md index 8758279584..88eb0b0680 100644 --- a/src/docs/documentation-map.md +++ b/src/docs/documentation-map.md @@ -174,6 +174,7 @@ Documentation for the current Hive line (branch `v5`; the code and docs live und - [How Hive injects knowledge and memory into agents](agent-knowledge-and-memory.md) — the three context layers (Hive knowledge primer, CLI conversation, CLI persistent memory), the kick-primer path and its scoping/caps, why repo `AGENTS.md` is injected rather than read natively, which per-agent home directories are fleet-shared, and what survives a kick, `/clear`, pod restart or a new agent. - [Knowledge connectors](knowledge-connectors.md) — **Owner configuration:** connect, validate, and sync external document/wiki sources; includes scope and API reference. - [Inbox and voice sources](inbox-voice-sources.md) — triage Plaud/Wispr Flow recordings into spektacular RFCs, dibs ideas, or knowledge only; hosted-hive Plaud sign-in. +- [Inbox transcription](inbox-transcription.md) — spoke-local Deepgram transcription of recordings without text, with the owner's own key, budget and consent gate. - [Knowledge curator](knowledge-curator.md) — configure fact extraction, sources, vaults, document imports, code maps, and retention. - [Knowledge confidence scoring](knowledge-confidence.md) — interpret confidence badges and score explanations. - [Knowledge lifecycle states](knowledge-lifecycle.md) — approve, deprecate, or supersede facts and keep stale knowledge out of prompts. diff --git a/src/docs/env-vars.md b/src/docs/env-vars.md index 5728b6014d..6e137c3b75 100644 --- a/src/docs/env-vars.md +++ b/src/docs/env-vars.md @@ -130,6 +130,11 @@ behavior. [Maintenance limitations](#keeping-this-reference-current) still apply | `HIVE_DOSSIER_CACHE_MAX_ENTRIES` | No | `512` | Caps each public dossier cache. Bounds username-spray memory while keeping normal contributor reuse hot. | | `HIVE_CONTRIBUTOR_KNOWLEDGE_EXPORT_MAX_FACTS` | No | `80` | Caps the number of facts returned by the contributor knowledge export API. Unset, non-numeric, or non-positive values fall back to the default. | | `HIVE_PUBLIC_REPOS` | No | none | Comma-separated, case-insensitive allowlist of additional Gource project names the dashboard's public war-room view may render, beyond the always-allowed default (`hive`). | +| `DEEPGRAM_API_KEY` | No | none | The hive owner's own Deepgram API key for Inbox transcription (`inbox.transcription`, [inbox-transcription.md](inbox-transcription.md)). Read at run time; `inbox.transcription.api_key_env` names a different variable. Never stored in `hive.yaml`, never shown (the UI reports only key present / missing). | +| `HIVE_INBOX_TRANSCRIPTION_MAX_DURATION_MINUTES` | No | `120` | Overrides `inbox.transcription.max_duration_minutes`: longer recordings are skipped before upload. Non-numeric or non-positive values fall back to the config / default. | +| `HIVE_INBOX_TRANSCRIPTION_MAX_BYTES` | No | `524288000` | Overrides `inbox.transcription.max_bytes`: an audio download larger than this is cut and the item skipped as too large. | +| `HIVE_INBOX_TRANSCRIPTION_MONTHLY_BUDGET_MINUTES` | No | `600` | Overrides `inbox.transcription.monthly_budget_minutes`: audio minutes this hive may send per UTC month. | +| `HIVE_INBOX_TRANSCRIPTION_DAILY_MAX_ITEMS` | No | `20` | Overrides `inbox.transcription.daily_max_items`: transcription runs per UTC day. | ## Crux durable lanes diff --git a/src/docs/inbox-transcription.md b/src/docs/inbox-transcription.md new file mode 100644 index 0000000000..80c496876f --- /dev/null +++ b/src/docs/inbox-transcription.md @@ -0,0 +1,145 @@ +# Inbox transcription (Deepgram) + +Some recordings reach the [Inbox](inbox-voice-sources.md) without any text: +a Plaud recording that was never transcribed in the Plaud app, or a meeting +recording without captions. Inbox transcription turns the audio of such an +item into a speaker-labelled transcript with [Deepgram](https://deepgram.com) +so it can be read, routed to an RFC or dibs, and searched like any other item. + +It is **off by default**. + +## Each hive owns its transcriptions + +Transcription is spoke-local. Nothing about it is shared or central: + +- **Your key, your account.** The hive owner supplies their own Deepgram API + key through an environment variable on their hive. Audio is billed to that + account. No hive pays for, or sees, another hive's transcriptions. +- **Your data volume.** The transcript is written only to this hive's data + volume, under `connector-state/transcripts//.json` (mode + `0600`, written atomically). It is not sent to the hub, to other spokes, or + back to the recording's source. +- **Your budget.** Monthly minutes, a daily item cap and size/duration limits + are configured per hive and checked before any audio is uploaded. + +## Security and privacy model + +- **Audio leaves the hive to Deepgram.** When an item is transcribed, the + hive downloads the recording from its source (for Plaud, a fresh presigned + link minted for this run, as the ▶ Play button does) and streams the bytes + to `https://api.deepgram.com/v1/listen` under the owner's key. Deepgram + never receives the presigned link; it receives the audio itself. The link + is never stored or logged: logs name the audio host only. +- **No training.** Every request sets Deepgram's `mip_opt_out=true`, which + opts the audio out of the Deepgram Model Improvement Program. +- **Nothing else is kept.** The hive stores the transcript text and the run + state (status, attempts, provider, model, language, audio length, the + download's size and ETag). It does not keep the audio. +- **The key is never echoed.** The key is read from the environment at run + time. Settings and the UI show only whether the named variable is set + (*key present* / *key missing*). A rejected key (HTTP 401/403) fails the run + with "check the Deepgram key in `$DEEPGRAM_API_KEY`", naming the variable, + never its value. +- **Consent.** Recordings contain other people's voices. Enabling + transcription requires `consent_acknowledged: true`; the ⚙ settings panel + shows a notice that the audio is sent to Deepgram under the hive owner's + own account before the checkbox can be ticked. A config with + `enabled: true` and no consent is rejected at load and on save. +- **Untrusted text.** A machine transcript is third-party speech like any + other Inbox text. It reaches spektacular and agent prompts through the same + untrusted-data envelope as source transcripts (see + [inbox-voice-sources.md](inbox-voice-sources.md)). +- **Audit.** Every run writes one `inbox_transcribe` audit entry: actor, + source, item id, provider, model, audio seconds, estimated cost and + outcome (with the reason for a failure or skip). Never the link or key. + +## Configuration + +```yaml +inbox: + transcription: + enabled: false # off by default + mode: manual # manual | auto + provider: deepgram # the only provider today + model: nova-3 # Deepgram pre-recorded model + api_key_env: DEEPGRAM_API_KEY # env var holding the owner's key + sources: [] # auto mode only transcribes these source names + diarize: true # label speakers: Speaker 1, Speaker 2, ... + language: auto # or a language code: en, de, pt-BR + max_duration_minutes: 120 # longer recordings are skipped + max_bytes: 524288000 # uploads are cut (and skipped) past 500 MiB + monthly_budget_minutes: 600 # audio minutes per UTC month + daily_max_items: 20 # runs per UTC day + consent_acknowledged: false # required to enable +``` + +Set the key in the hive's environment (for example a Kubernetes Secret +mapped to `DEEPGRAM_API_KEY`); it never goes into `hive.yaml`. The limits can +also be overridden by environment variables, which win over `hive.yaml`: +`HIVE_INBOX_TRANSCRIPTION_MAX_DURATION_MINUTES`, +`HIVE_INBOX_TRANSCRIPTION_MAX_BYTES`, +`HIVE_INBOX_TRANSCRIPTION_MONTHLY_BUDGET_MINUTES` and +`HIVE_INBOX_TRANSCRIPTION_DAILY_MAX_ITEMS`. + +Everything above is editable in the Inbox under **⚙ Auto-routing → +Transcription** and in **Settings → Inbox** (`POST /api/inbox/settings` with +a `transcription` object). + +## Transcribing an item + +Items that are pending (no summary, no transcript) and whose source can mint +audio show a **🎧 Transcribe** button for owners and read-write sessions. It +calls `POST /api/inbox/{source}/{id}/transcribe`: + +1. Gates: transcription must be enabled and consented (`412` otherwise); an + item that is queued, running or already transcribed, or that has text + from its source, answers `409`. +2. Checks that need no upload: a source without audio (`unsupported`), a + recording longer than `max_duration_minutes` (`too long`), the daily item + cap or the monthly minutes budget (`budget`). These are recorded as + **skipped** with the reason and answered `200`. +3. Otherwise the item is **queued** (`202`) and runs in the background, one + job at a time per hive: **running** → **done**, **failed** (with the + reason), or **skipped** (`too large`, when the download is bigger than + `max_bytes`; a limit reader also cuts a stream without a length). +4. HTTP 429, 5xx and network errors are retried up to 3 attempts with + exponential backoff; each attempt downloads the audio afresh. A failed or + skipped item keeps its **Retry transcription** button. + +The item shows a pill for the state (with a spinner while queued or running, +and the failure reason). Once done, the item is no longer pending and its +*Transcript* disclosure shows the text under **Transcript (machine: +deepgram/nova-3)**, in the same `[mm:ss] Speaker N: text` line shape as Plaud +and meeting transcripts. + +## Upstream text wins + +The machine transcript is a fallback. If the source later produces its own +summary or transcript (for example the owner runs transcription in the Plaud +app), the Inbox shows the source's text and the machine transcript is no +longer used. If the source is unreachable, the stored machine transcript +still serves the item's content. + +## Cost + +Deepgram bills the owner's account per audio minute. The audit entry carries +an estimate from Deepgram's published pay-as-you-go nova-3 price; the +Deepgram invoice is authoritative. The monthly budget counts the audio length +Deepgram reports for each finished run. + +## Providers + +`src/pkg/transcribe` defines a small `Transcriber` interface (`Name`, +`Transcribe(ctx, Audio) (Result, error)`) with a Deepgram adapter and a fake +for tests. Another provider (for example an OpenAI-compatible +`/audio/transcriptions` endpoint) can be added behind the same interface. + +## API + +| Method | Path | Access | | +| --- | --- | --- | --- | +| `POST` | `/api/inbox/{source}/{id}/transcribe` | Owner or read-write | Queue a transcription (202), or report an up-front skip (200); 409 busy/done/has text, 412 disabled or not consented, 404 unknown item | +| `GET` | `/api/inbox` | Dashboard auth | Items carry `transcription` (`status`, `reason`, `attempts`, `provider`, `model`, `updated_at`) and `transcribable`; `settings.transcription` carries the effective config, `key_present`, `month_minutes_used` and `today_items` | +| `GET` | `/api/inbox/{source}/{id}/content` | Dashboard auth | Falls back to the machine transcript, with `transcript_label` | + +See also [api-reference/knowledge.md](api-reference/knowledge.md). diff --git a/src/docs/inbox-voice-sources.md b/src/docs/inbox-voice-sources.md index 32238a25a2..3e1e6da7f2 100644 --- a/src/docs/inbox-voice-sources.md +++ b/src/docs/inbox-voice-sources.md @@ -122,6 +122,12 @@ file, an event description or chat). Setup (bot token in `auth.env`, the Message Content intent, View Channel + Read Message History) is in [knowledge-connectors.md](knowledge-connectors.md#discord-meetings-type-discord). +Such a pending item can also be transcribed on the hive itself: with +`inbox.transcription` enabled, owners and read-write sessions get a +**🎧 Transcribe** button that sends the audio to Deepgram under the hive +owner's own key and stores the transcript on this hive only. See +[Inbox transcription](inbox-transcription.md). + ## Configuration ```yaml @@ -184,7 +190,8 @@ or a channel). See [api-reference/knowledge.md](api-reference/knowledge.md) for `GET /api/inbox`, `POST /api/inbox/route`, `POST /api/inbox/dismiss`, `GET|POST /api/inbox/settings`, `GET /api/inbox/{source}/{id}/content`, -`GET /api/inbox/{source}/{id}/audio` and +`GET /api/inbox/{source}/{id}/audio`, +`POST /api/inbox/{source}/{id}/transcribe` ([Inbox transcription](inbox-transcription.md)) and `POST /api/knowledge/connectors/{name}/auth/complete`. `GET /api/inbox` always answers `200`: on a hive with no voice connector diff --git a/src/docs/knowledge-connectors.md b/src/docs/knowledge-connectors.md index fceb39afee..6a5fb1d033 100644 --- a/src/docs/knowledge-connectors.md +++ b/src/docs/knowledge-connectors.md @@ -328,7 +328,9 @@ set yourself is never rewritten, so an explicit `@latest` still floats. `## Highlights` (device-button marks) sections. Audio is never downloaded; with `include_audio: true` the fact also links Plaud's 24-hour presigned URL. The Inbox plays audio through a per-click link regardless (see - [inbox-voice-sources.md](inbox-voice-sources.md)). + [inbox-voice-sources.md](inbox-voice-sources.md)). Recordings Plaud never + transcribed can be transcribed on the hive with the owner's own Deepgram + key ([inbox-transcription.md](inbox-transcription.md)). - The listing is incremental, so recordings deleted in Plaud are not tombstoned automatically; remove the fact file or the connector. - Sign-in state (`connected as`, pending authorization, last error) comes from diff --git a/src/pkg/config/inbox_config.go b/src/pkg/config/inbox_config.go index ffda38716d..76f5477e80 100644 --- a/src/pkg/config/inbox_config.go +++ b/src/pkg/config/inbox_config.go @@ -30,6 +30,9 @@ type InboxConfig struct { Rules []InboxRule `yaml:"rules,omitempty" json:"rules,omitempty"` Spek InboxSpek `yaml:"spek,omitempty" json:"spek,omitempty"` Dibs InboxDibs `yaml:"dibs,omitempty" json:"dibs,omitempty"` + // Transcription is spoke-local machine transcription of recordings that + // arrive without text (off by default; see inbox_transcription.go). + Transcription InboxTranscription `yaml:"transcription,omitempty" json:"transcription,omitzero"` } // InboxRule routes items whose source and title/tag match. @@ -105,6 +108,9 @@ func ValidateInbox(c InboxConfig) error { if c.Dibs.URL != "" && !strings.HasPrefix(c.Dibs.URL, "http://") && !strings.HasPrefix(c.Dibs.URL, "https://") { return fmt.Errorf("inbox.dibs.url %q: must start with http:// or https://", c.Dibs.URL) } + if err := ValidateInboxTranscription(c.Transcription); err != nil { + return err + } for i, r := range c.Rules { switch r.Destination { case InboxDestinationSpekRFC, InboxDestinationDibs, InboxDestinationDismiss: diff --git a/src/pkg/config/inbox_transcription.go b/src/pkg/config/inbox_transcription.go new file mode 100644 index 0000000000..aa2617a1de --- /dev/null +++ b/src/pkg/config/inbox_transcription.go @@ -0,0 +1,216 @@ +package config + +import ( + "fmt" + "os" + "regexp" + "strconv" + "strings" + "time" +) + +// Inbox transcription modes. +const ( + // InboxTranscriptionModeManual transcribes only when the owner clicks + // Transcribe on an Inbox item. + InboxTranscriptionModeManual = "manual" + // InboxTranscriptionModeAuto also transcribes new pending items from the + // sources listed in inbox.transcription.sources after each sync. + InboxTranscriptionModeAuto = "auto" +) + +// Inbox transcription defaults. Each spoke transcribes with its owner's own +// provider key; these bound what one hive spends on its own account. +const ( + // DefaultInboxTranscriptionProvider is the only provider built today. + DefaultInboxTranscriptionProvider = "deepgram" + // DefaultInboxTranscriptionModel is Deepgram's pre-recorded model. + DefaultInboxTranscriptionModel = "nova-3" + // DefaultInboxTranscriptionKeyEnv names the variable holding the key. + DefaultInboxTranscriptionKeyEnv = "DEEPGRAM_API_KEY" + // DefaultInboxTranscriptionLanguage asks the provider to detect it. + DefaultInboxTranscriptionLanguage = "auto" + // DefaultInboxTranscriptionMaxDurationMinutes skips longer recordings. + DefaultInboxTranscriptionMaxDurationMinutes = 120 + // DefaultInboxTranscriptionMaxBytes (500 MiB) cuts larger uploads. + DefaultInboxTranscriptionMaxBytes int64 = 500 << 20 + // DefaultInboxTranscriptionMonthlyBudgetMinutes caps audio minutes sent + // per calendar month (UTC). + DefaultInboxTranscriptionMonthlyBudgetMinutes = 600 + // DefaultInboxTranscriptionDailyMaxItems caps transcription runs per UTC day. + DefaultInboxTranscriptionDailyMaxItems = 20 +) + +// Environment overrides for the transcription limits (env > hive.yaml > +// default; a non-positive or malformed value falls through). +const ( + EnvInboxTranscriptionMaxDurationMinutes = "HIVE_INBOX_TRANSCRIPTION_MAX_DURATION_MINUTES" + EnvInboxTranscriptionMaxBytes = "HIVE_INBOX_TRANSCRIPTION_MAX_BYTES" + EnvInboxTranscriptionMonthlyBudgetMinutes = "HIVE_INBOX_TRANSCRIPTION_MONTHLY_BUDGET_MINUTES" + EnvInboxTranscriptionDailyMaxItems = "HIVE_INBOX_TRANSCRIPTION_DAILY_MAX_ITEMS" +) + +// InboxTranscription is `inbox.transcription`: spoke-local machine +// transcription for Inbox recordings that arrive without text. The audio is +// sent to the provider under the hive owner's own account and key; the +// transcript is stored only on this spoke. Off by default, and enabling it +// requires consent_acknowledged: true. +type InboxTranscription struct { + Enabled bool `yaml:"enabled,omitempty" json:"enabled"` + // Mode is manual (default) or auto. + Mode string `yaml:"mode,omitempty" json:"mode,omitempty"` + // Provider is deepgram (default). + Provider string `yaml:"provider,omitempty" json:"provider,omitempty"` + // Model defaults to nova-3. + Model string `yaml:"model,omitempty" json:"model,omitempty"` + // APIKeyEnv names the environment variable holding the provider key + // (default DEEPGRAM_API_KEY). The key itself never lives in hive.yaml. + APIKeyEnv string `yaml:"api_key_env,omitempty" json:"api_key_env,omitempty"` + // Sources lists the Inbox source names auto mode transcribes. + Sources []string `yaml:"sources,omitempty" json:"sources,omitempty"` + // Diarize labels speakers; nil means true. + Diarize *bool `yaml:"diarize,omitempty" json:"diarize,omitempty"` + // Language is a BCP-47 code or auto (default). + Language string `yaml:"language,omitempty" json:"language,omitempty"` + // MaxDurationMinutes skips longer recordings before uploading. + MaxDurationMinutes int `yaml:"max_duration_minutes,omitempty" json:"max_duration_minutes,omitempty"` + // MaxBytes cuts an upload that grows past this many bytes. + MaxBytes int64 `yaml:"max_bytes,omitempty" json:"max_bytes,omitempty"` + // MonthlyBudgetMinutes caps audio minutes per UTC calendar month. + MonthlyBudgetMinutes int `yaml:"monthly_budget_minutes,omitempty" json:"monthly_budget_minutes,omitempty"` + // DailyMaxItems caps transcription runs per UTC day. + DailyMaxItems int `yaml:"daily_max_items,omitempty" json:"daily_max_items,omitempty"` + // ConsentAcknowledged records that the owner read the notice: recordings + // contain other people's voices and the audio is sent to the provider. + ConsentAcknowledged bool `yaml:"consent_acknowledged,omitempty" json:"consent_acknowledged"` +} + +var ( + inboxEnvNameRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`) + inboxLanguageRe = regexp.MustCompile(`^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$`) +) + +// EffectiveMode returns the mode, defaulting to manual. +func (t InboxTranscription) EffectiveMode() string { + if m := strings.TrimSpace(t.Mode); m != "" { + return m + } + return InboxTranscriptionModeManual +} + +// EffectiveProvider returns the provider, defaulting to deepgram. +func (t InboxTranscription) EffectiveProvider() string { + if p := strings.TrimSpace(t.Provider); p != "" { + return p + } + return DefaultInboxTranscriptionProvider +} + +// EffectiveModel returns the model, defaulting to nova-3. +func (t InboxTranscription) EffectiveModel() string { + if m := strings.TrimSpace(t.Model); m != "" { + return m + } + return DefaultInboxTranscriptionModel +} + +// EffectiveAPIKeyEnv returns the key variable name, defaulting to +// DEEPGRAM_API_KEY. +func (t InboxTranscription) EffectiveAPIKeyEnv() string { + if e := strings.TrimSpace(t.APIKeyEnv); e != "" { + return e + } + return DefaultInboxTranscriptionKeyEnv +} + +// EffectiveDiarize returns Diarize, defaulting to true. +func (t InboxTranscription) EffectiveDiarize() bool { return t.Diarize == nil || *t.Diarize } + +// EffectiveLanguage returns the language, defaulting to auto. +func (t InboxTranscription) EffectiveLanguage() string { + if l := strings.TrimSpace(t.Language); l != "" { + return l + } + return DefaultInboxTranscriptionLanguage +} + +// EffectiveMaxDuration returns the longest recording that is transcribed. +func (t InboxTranscription) EffectiveMaxDuration() time.Duration { + return time.Duration(inboxLimit(EnvInboxTranscriptionMaxDurationMinutes, int64(t.MaxDurationMinutes), DefaultInboxTranscriptionMaxDurationMinutes)) * time.Minute +} + +// EffectiveMaxBytes returns the upload byte cap. +func (t InboxTranscription) EffectiveMaxBytes() int64 { + return inboxLimit(EnvInboxTranscriptionMaxBytes, t.MaxBytes, DefaultInboxTranscriptionMaxBytes) +} + +// EffectiveMonthlyBudget returns the audio allowed per UTC month. +func (t InboxTranscription) EffectiveMonthlyBudget() time.Duration { + return time.Duration(inboxLimit(EnvInboxTranscriptionMonthlyBudgetMinutes, int64(t.MonthlyBudgetMinutes), DefaultInboxTranscriptionMonthlyBudgetMinutes)) * time.Minute +} + +// EffectiveDailyMaxItems returns the runs allowed per UTC day. +func (t InboxTranscription) EffectiveDailyMaxItems() int { + return int(inboxLimit(EnvInboxTranscriptionDailyMaxItems, int64(t.DailyMaxItems), DefaultInboxTranscriptionDailyMaxItems)) +} + +// Active reports that transcription is enabled and consented to. +func (t InboxTranscription) Active() bool { return t.Enabled && t.ConsentAcknowledged } + +// AutoSource reports whether auto mode transcribes items from source. +func (t InboxTranscription) AutoSource(source string) bool { + if !t.Active() || t.EffectiveMode() != InboxTranscriptionModeAuto { + return false + } + for _, s := range t.Sources { + if strings.TrimSpace(s) == source { + return true + } + } + return false +} + +// inboxLimit resolves env > configured > def; non-positive values fall +// through to the next source. +func inboxLimit(env string, configured, def int64) int64 { + if v := strings.TrimSpace(os.Getenv(env)); v != "" { + if n, err := strconv.ParseInt(v, 10, 64); err == nil && n > 0 { + return n + } + } + if configured > 0 { + return configured + } + return def +} + +// ValidateInboxTranscription rejects unknown modes and providers, bad env +// names and languages, negative limits, and enabling without consent. +func ValidateInboxTranscription(t InboxTranscription) error { + switch t.EffectiveMode() { + case InboxTranscriptionModeManual, InboxTranscriptionModeAuto: + default: + return fmt.Errorf("inbox.transcription.mode %q: must be %s or %s", t.Mode, InboxTranscriptionModeManual, InboxTranscriptionModeAuto) + } + if p := t.EffectiveProvider(); p != DefaultInboxTranscriptionProvider { + return fmt.Errorf("inbox.transcription.provider %q: only %s is supported", p, DefaultInboxTranscriptionProvider) + } + if !inboxEnvNameRe.MatchString(t.EffectiveAPIKeyEnv()) { + return fmt.Errorf("inbox.transcription.api_key_env %q: must be an environment variable name", t.APIKeyEnv) + } + if l := t.EffectiveLanguage(); l != DefaultInboxTranscriptionLanguage && !inboxLanguageRe.MatchString(l) { + return fmt.Errorf("inbox.transcription.language %q: must be auto or a language code such as en or pt-BR", l) + } + if t.MaxDurationMinutes < 0 || t.MaxBytes < 0 || t.MonthlyBudgetMinutes < 0 || t.DailyMaxItems < 0 { + return fmt.Errorf("inbox.transcription limits must not be negative") + } + for i, s := range t.Sources { + if strings.TrimSpace(s) == "" { + return fmt.Errorf("inbox.transcription.sources[%d]: empty source name", i) + } + } + if t.Enabled && !t.ConsentAcknowledged { + return fmt.Errorf("inbox.transcription.enabled requires inbox.transcription.consent_acknowledged: true (recordings contain other people's voices and the audio is sent to the provider under the hive owner's account)") + } + return nil +} diff --git a/src/pkg/config/inbox_transcription_test.go b/src/pkg/config/inbox_transcription_test.go new file mode 100644 index 0000000000..af97213bfc --- /dev/null +++ b/src/pkg/config/inbox_transcription_test.go @@ -0,0 +1,112 @@ +package config + +import ( + "strings" + "testing" + "time" + + "gopkg.in/yaml.v3" +) + +func TestInboxTranscriptionDefaults(t *testing.T) { + var tr InboxTranscription + if tr.Enabled || tr.Active() || tr.EffectiveMode() != "manual" || tr.EffectiveProvider() != "deepgram" || tr.EffectiveModel() != "nova-3" { + t.Fatalf("defaults = %+v", tr) + } + if tr.EffectiveAPIKeyEnv() != "DEEPGRAM_API_KEY" || !tr.EffectiveDiarize() || tr.EffectiveLanguage() != "auto" { + t.Fatal("key env / diarize / language defaults") + } + if tr.EffectiveMaxDuration() != 120*time.Minute || tr.EffectiveMaxBytes() != 524288000 || tr.EffectiveMonthlyBudget() != 600*time.Minute || tr.EffectiveDailyMaxItems() != 20 { + t.Fatalf("limit defaults: %v %v %v %v", tr.EffectiveMaxDuration(), tr.EffectiveMaxBytes(), tr.EffectiveMonthlyBudget(), tr.EffectiveDailyMaxItems()) + } + if err := ValidateInboxTranscription(tr); err != nil { + t.Fatalf("zero value must validate: %v", err) + } +} + +func TestInboxTranscriptionConfiguredAndEnvOverrides(t *testing.T) { + off := false + tr := InboxTranscription{ + Enabled: true, ConsentAcknowledged: true, Mode: "auto", Provider: "deepgram", Model: "nova-2", + APIKeyEnv: "MY_DG", Sources: []string{"plaud", " zoom "}, Diarize: &off, Language: "pt-BR", + MaxDurationMinutes: 30, MaxBytes: 1000, MonthlyBudgetMinutes: 60, DailyMaxItems: 2, + } + if !tr.Active() || tr.EffectiveModel() != "nova-2" || tr.EffectiveAPIKeyEnv() != "MY_DG" || tr.EffectiveDiarize() || tr.EffectiveLanguage() != "pt-BR" { + t.Fatalf("configured = %+v", tr) + } + if tr.EffectiveMaxDuration() != 30*time.Minute || tr.EffectiveMaxBytes() != 1000 || tr.EffectiveMonthlyBudget() != time.Hour || tr.EffectiveDailyMaxItems() != 2 { + t.Fatal("configured limits") + } + if !tr.AutoSource("plaud") || !tr.AutoSource("zoom") || tr.AutoSource("wisprflow") { + t.Fatal("auto sources") + } + manual := tr + manual.Mode = "manual" + if manual.AutoSource("plaud") { + t.Fatal("manual mode never auto-transcribes") + } + if err := ValidateInboxTranscription(tr); err != nil { + t.Fatalf("valid config rejected: %v", err) + } + t.Setenv(EnvInboxTranscriptionMaxDurationMinutes, "45") + t.Setenv(EnvInboxTranscriptionMaxBytes, "2048") + t.Setenv(EnvInboxTranscriptionMonthlyBudgetMinutes, "90") + t.Setenv(EnvInboxTranscriptionDailyMaxItems, "bogus") + if tr.EffectiveMaxDuration() != 45*time.Minute || tr.EffectiveMaxBytes() != 2048 || tr.EffectiveMonthlyBudget() != 90*time.Minute { + t.Fatal("env overrides must win") + } + if tr.EffectiveDailyMaxItems() != 2 { + t.Fatal("a malformed env value falls through to the configured value") + } +} + +func TestValidateInboxTranscriptionRejects(t *testing.T) { + cases := map[string]InboxTranscription{ + "mode": {Mode: "sometimes"}, + "provider": {Provider: "whisper"}, + "key env": {APIKeyEnv: "not a name"}, + "language": {Language: "english please"}, + "negative": {MaxBytes: -1}, + "sources": {Sources: []string{" "}}, + "consent": {Enabled: true}, + } + for name, tr := range cases { + if err := ValidateInboxTranscription(tr); err == nil { + t.Errorf("%s: want error", name) + } + } + err := ValidateInbox(InboxConfig{Transcription: InboxTranscription{Enabled: true}}) + if err == nil || !strings.Contains(err.Error(), "consent_acknowledged") { + t.Fatalf("ValidateInbox must apply the consent gate: %v", err) + } +} + +func TestInboxTranscriptionYAML(t *testing.T) { + var c InboxConfig + src := ` +transcription: + enabled: true + mode: auto + provider: deepgram + model: nova-3 + api_key_env: DEEPGRAM_API_KEY + sources: [plaud] + diarize: false + language: auto + max_duration_minutes: 120 + max_bytes: 524288000 + monthly_budget_minutes: 600 + daily_max_items: 20 + consent_acknowledged: true +` + if err := yaml.Unmarshal([]byte(src), &c); err != nil { + t.Fatal(err) + } + tr := c.Transcription + if !tr.Active() || tr.EffectiveDiarize() || len(tr.Sources) != 1 || tr.MaxBytes != 524288000 || tr.DailyMaxItems != 20 { + t.Fatalf("parsed = %+v", tr) + } + if err := ValidateInbox(c); err != nil { + t.Fatal(err) + } +} diff --git a/src/pkg/dashboard/api_inbox.go b/src/pkg/dashboard/api_inbox.go index f0a68277ca..a4b8f7c124 100644 --- a/src/pkg/dashboard/api_inbox.go +++ b/src/pkg/dashboard/api_inbox.go @@ -29,6 +29,7 @@ func (s *Server) registerInboxRoutes() { s.mux.HandleFunc("GET /api/inbox/{source}/{id}/content", s.handleInboxContent) s.mux.HandleFunc("GET /api/inbox/{source}/{id}/audio", s.handleInboxAudio) s.mux.HandleFunc("POST /api/knowledge/connectors/{name}/auth/complete", s.handleKnowledgeConnectorAuthComplete) + s.mux.HandleFunc("POST /api/inbox/{source}/{id}/transcribe", s.handleInboxTranscribe) } // inboxSourceReadTimeout bounds one read that may spawn the source's MCP @@ -141,6 +142,56 @@ func (s *Server) handleInboxAudio(w http.ResponseWriter, r *http.Request) { jsonResponse(w, InboxAudioResponse{Source: it.Source, ItemID: it.ID, URL: link.URL, ExpiresAt: link.ExpiresAt}) } +// InboxTranscribeResponse is POST /api/inbox/{source}/{id}/transcribe. +type InboxTranscribeResponse struct { + Source string `json:"source"` + ItemID string `json:"item_id"` + State inbox.TranscriptionState `json:"state"` +} + +// handleInboxTranscribe (owner or read-write) queues a machine transcription +// of one pending item on this hive, with the owner's own provider key. The +// hive downloads the audio itself and streams it to the provider; the +// presigned link is never forwarded or logged. Each run is audited as +// inbox_transcribe with its outcome. 202 queued, 200 skipped up front +// (no audio, too long, budget), 409 busy/already transcribed/has text, +// 412 transcription disabled or not consented. +func (s *Server) handleInboxTranscribe(w http.ResponseWriter, r *http.Request) { + if !requireInboxPlaybackRole(w, r) { + return + } + svc, ok := s.inboxService(w) + if !ok { + return + } + it, ok := s.inboxFindItem(w, r, svc) + if !ok { + return + } + opts := inbox.TranscribeOptions{Actor: requestUser(r), Audit: func(a inbox.TranscribeAudit) { + if s.audit != nil { + s.audit.Log(a.Actor, "inbox_transcribe", auditDetail(a.Fields()...), "") + } + }} + st, err := svc.Transcribe(r.Context(), it, opts) + switch { + case errors.Is(err, inbox.ErrTranscriptionDisabled), errors.Is(err, inbox.ErrTranscriptionConsent): + jsonError(w, err.Error(), http.StatusPreconditionFailed) + return + case errors.Is(err, inbox.ErrTranscriptionBusy), errors.Is(err, inbox.ErrAlreadyTranscribed), errors.Is(err, inbox.ErrNotPending): + jsonError(w, err.Error(), http.StatusConflict) + return + case err != nil: + jsonError(w, "transcription failed: "+err.Error(), http.StatusInternalServerError) + return + } + code := http.StatusAccepted + if st.Status == inbox.TranscriptionSkipped { + code = http.StatusOK + } + jsonStatusResponse(w, code, InboxTranscribeResponse{Source: it.Source, ItemID: it.ID, State: st}) +} + // InboxSourceStatus is one configured source as the Inbox header shows it. type InboxSourceStatus struct { Type string `json:"type"` @@ -380,10 +431,12 @@ type inboxSettingsRequest struct { Rules *[]config.InboxRule `json:"rules,omitempty"` SpekRepo *string `json:"spek_repo,omitempty"` DibsURL *string `json:"dibs_url,omitempty"` + // Transcription replaces inbox.transcription whole when present. + Transcription *config.InboxTranscription `json:"transcription,omitempty"` } // handleInboxSettingsPost (owner) updates inbox.rules / inbox.spek.repo / -// inbox.dibs.url and persists hive.yaml. +// inbox.dibs.url / inbox.transcription and persists hive.yaml. func (s *Server) handleInboxSettingsPost(w http.ResponseWriter, r *http.Request) { if !requireOwnerRole(w, r) { return @@ -411,6 +464,9 @@ func (s *Server) handleInboxSettingsPost(w http.ResponseWriter, r *http.Request) if req.DibsURL != nil { next.Dibs.URL = strings.TrimRight(strings.TrimSpace(*req.DibsURL), "/") } + if req.Transcription != nil { + next.Transcription = *req.Transcription + } if err := config.ValidateInbox(next); err != nil { jsonError(w, err.Error(), http.StatusBadRequest) return @@ -421,7 +477,7 @@ func (s *Server) handleInboxSettingsPost(w http.ResponseWriter, r *http.Request) jsonError(w, "saving config: "+err.Error(), http.StatusInternalServerError) return } - s.auditFromRequest(r, "inbox_settings", auditDetail("rules", strconv.Itoa(len(next.Rules)), "spek_repo", next.Spek.Repo, "dibs_url", next.Dibs.URL), "") + s.auditFromRequest(r, "inbox_settings", auditDetail("rules", strconv.Itoa(len(next.Rules)), "spek_repo", next.Spek.Repo, "dibs_url", next.Dibs.URL, "transcription", strconv.FormatBool(next.Transcription.Active()), "transcription_mode", next.Transcription.EffectiveMode()), "") jsonResponse(w, svc.Settings()) } diff --git a/src/pkg/dashboard/api_inbox_transcribe_test.go b/src/pkg/dashboard/api_inbox_transcribe_test.go new file mode 100644 index 0000000000..742df23b81 --- /dev/null +++ b/src/pkg/dashboard/api_inbox_transcribe_test.go @@ -0,0 +1,214 @@ +package dashboard + +import ( + "bytes" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/inbox" + "github.com/hivecommons/hive/pkg/transcribe" +) + +func doPostRole(s *Server, path, role string, verified bool, body any) *httptest.ResponseRecorder { + var b bytes.Buffer + _ = json.NewEncoder(&b).Encode(body) + rec := httptest.NewRecorder() + req := httptest.NewRequest(http.MethodPost, path, &b) + req.Header.Set("Content-Type", "application/json") + if role != "" { + req.Header.Set("X-Hive-Role", role) + req.Header.Set("X-Hive-User", role+"@example.com") + } + if verified { + req.Header.Set(ownerRoleVerifiedHeader, "true") + } + s.mux.ServeHTTP(rec, req) + return rec +} + +// newTranscribeTestServer wires an Inbox with two pending recordings whose +// audio is served by a local server, and a fake provider. +func newTranscribeTestServer(t *testing.T, tx config.InboxTranscription) (*Server, *inbox.Service, *transcribe.Fake, string) { + t.Helper() + s, deps := apiServer(t) + audio := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _, _ = io.WriteString(w, "AUDIOBYTES") + })) + t.Cleanup(audio.Close) + src := &inboxAudioSource{ + items: []inbox.Item{ + {Source: "plaud", ID: "rec-1", Title: "One", Pending: true, DurationMS: 60000}, + {Source: "plaud", ID: "rec-2", Title: "Two", Pending: true, DurationMS: 120000}, + }, + link: inbox.AudioLink{URL: audio.URL + "/a.mp3?X-Amz-Signature=topsecret", ExpiresAt: time.Now().Add(time.Hour)}, + } + deps.Config.Inbox = config.InboxConfig{Transcription: tx} + svc := inbox.NewService(deps.Config.Inbox, inbox.NewStore(filepath.Join(t.TempDir(), "_inbox.json")), []inbox.Source{src}, nil, nil) + svc.Run = func(fn func()) { fn() } + svc.EnableTranscription(inbox.NewTranscriptStore(filepath.Join(t.TempDir(), "transcripts"))) + fake := &transcribe.Fake{Result: transcribe.Result{Segments: []transcribe.Segment{{Speaker: "Speaker 1", Text: "hi"}}, Duration: time.Minute}} + svc.NewTranscriber = func(config.InboxTranscription) (transcribe.Transcriber, error) { return fake, nil } + svc.Getenv = func(k string) string { + if k == "DEEPGRAM_API_KEY" { + return "dg-test-key" + } + return "" + } + deps.Inbox = svc + return s, svc, fake, audio.URL +} + +func TestInboxTranscribeRoleMatrixAndAudit(t *testing.T) { + s, _, fake, audioURL := newTranscribeTestServer(t, config.InboxTranscription{Enabled: true, ConsentAcknowledged: true}) + path := func(id string) string { return "/api/inbox/plaud/" + id + "/transcribe" } + + for _, tc := range []struct { + role string + verified bool + }{{"", false}, {"read-only", false}, {"owner", false}} { + if rec := doPostRole(s, path("rec-1"), tc.role, tc.verified, nil); rec.Code != http.StatusForbidden { + t.Fatalf("role %q verified=%v = %d, want 403", tc.role, tc.verified, rec.Code) + } + } + if fake.Calls() != 0 { + t.Fatal("a refused request must not upload") + } + if rec := doPostRole(s, path("nope"), "owner", true, nil); rec.Code != http.StatusNotFound { + t.Fatalf("unknown item = %d", rec.Code) + } + for _, tc := range []struct { + role, id string + }{{"read-write", "rec-1"}, {"owner", "rec-2"}} { + rec := doPostRole(s, path(tc.id), tc.role, tc.role == "owner", nil) + if rec.Code != http.StatusAccepted { + t.Fatalf("%s transcribe = %d: %s", tc.role, rec.Code, rec.Body.String()) + } + var got InboxTranscribeResponse + if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil || got.State.Status != inbox.TranscriptionQueued || got.ItemID != tc.id { + t.Fatalf("%s response = %+v %v", tc.role, got, err) + } + } + if fake.Calls() != 2 { + t.Fatalf("uploads = %d", fake.Calls()) + } + if rec := doPostRole(s, path("rec-1"), "owner", true, nil); rec.Code != http.StatusConflict { + t.Fatalf("already transcribed = %d", rec.Code) + } + + entries := s.audit.Recent(50) + var runs []AuditEntry + for _, e := range entries { + if e.Action == "inbox_transcribe" { + runs = append(runs, e) + } + } + if len(runs) != 2 { + t.Fatalf("inbox_transcribe entries = %+v", runs) + } + for _, e := range runs { + for _, want := range []string{"source=plaud", "provider=deepgram", "model=nova-3", "audio_seconds=60", "estimated_usd=", "outcome=done"} { + if !strings.Contains(e.Detail, want) { + t.Errorf("audit detail %q missing %q", e.Detail, want) + } + } + for _, leak := range []string{"topsecret", audioURL, "dg-test-key"} { + if strings.Contains(e.Detail, leak) { + t.Errorf("audit detail leaks %q: %q", leak, e.Detail) + } + } + } + if runs[0].User == "" { + t.Fatalf("audit entry has no actor: %+v", runs[0]) + } + + // The listing and content reflect the machine transcript. + list := decodeInboxList(t, doGet(s, "/api/inbox").Body.Bytes()) + for _, it := range list.Items { + if it.Pending || it.Transcribable || it.Transcription == nil || it.Transcription.Status != inbox.TranscriptionDone { + t.Fatalf("listed item = %+v", it) + } + } + if !list.Settings.Transcription.KeyPresent || list.Settings.Transcription.TodayItems != 2 || list.Settings.Transcription.MonthMinutesUsed != 2 { + t.Fatalf("transcription settings = %+v", list.Settings.Transcription) + } + // This source already returns text, so the upstream transcript wins + // over the machine one in the content view. + body := doGet(s, "/api/inbox/plaud/rec-1/content").Body.String() + if strings.Contains(body, "transcript_label") || !strings.Contains(body, "[00:01] A: words") { + t.Fatalf("content = %s", body) + } +} + +func TestInboxTranscribeGatesAndSkips(t *testing.T) { + s, _, _, _ := newTranscribeTestServer(t, config.InboxTranscription{}) + if rec := doPostRole(s, "/api/inbox/plaud/rec-1/transcribe", "owner", true, nil); rec.Code != http.StatusPreconditionFailed { + t.Fatalf("disabled = %d: %s", rec.Code, rec.Body.String()) + } + s, _, fake, _ := newTranscribeTestServer(t, config.InboxTranscription{Enabled: true, ConsentAcknowledged: true, MaxDurationMinutes: 1}) + rec := doPostRole(s, "/api/inbox/plaud/rec-2/transcribe", "owner", true, nil) + var got InboxTranscribeResponse + if rec.Code != http.StatusOK || json.Unmarshal(rec.Body.Bytes(), &got) != nil || got.State.Status != inbox.TranscriptionSkipped || !strings.HasPrefix(got.State.Reason, inbox.SkipTooLong) { + t.Fatalf("too long = %d %s", rec.Code, rec.Body.String()) + } + if fake.Calls() != 0 { + t.Fatal("a skipped item must not upload") + } + if e := s.audit.Recent(1); len(e) != 1 || e[0].Action != "inbox_transcribe" || !strings.Contains(e[0].Detail, "outcome=skipped") { + t.Fatalf("skip audit = %+v", e) + } + // Without a service the endpoint is a 404 like the other item routes. + s2, _ := apiServer(t) + if rec := doPostRole(s2, "/api/inbox/plaud/rec-1/transcribe", "owner", true, nil); rec.Code != http.StatusNotFound { + t.Fatalf("no inbox = %d", rec.Code) + } +} + +func TestInboxTranscribeBusyIsConflict(t *testing.T) { + s, svc, _, _ := newTranscribeTestServer(t, config.InboxTranscription{Enabled: true, ConsentAcknowledged: true}) + // Hold the run so the item stays queued. + release := make(chan struct{}) + svc.Run = func(fn func()) { go func() { <-release; fn() }() } + if rec := doPostRole(s, "/api/inbox/plaud/rec-1/transcribe", "owner", true, nil); rec.Code != http.StatusAccepted { + t.Fatalf("first = %d", rec.Code) + } + if rec := doPostRole(s, "/api/inbox/plaud/rec-1/transcribe", "read-write", false, nil); rec.Code != http.StatusConflict { + t.Fatalf("busy = %d", rec.Code) + } + close(release) + svc.Wait() +} + +func TestInboxSettingsTranscriptionConsentGate(t *testing.T) { + s, deps := apiServer(t) + deps.Inbox = newInboxTestService(t, config.InboxConfig{}) + rec := doPost(s, "/api/inbox/settings", map[string]any{"transcription": map[string]any{"enabled": true}}) + if rec.Code != http.StatusBadRequest || !strings.Contains(rec.Body.String(), "consent_acknowledged") { + t.Fatalf("enable without consent = %d: %s", rec.Code, rec.Body.String()) + } + rec = doPost(s, "/api/inbox/settings", map[string]any{"transcription": map[string]any{ + "enabled": true, "consent_acknowledged": true, "mode": "manual", "api_key_env": "MY_DG_KEY", "monthly_budget_minutes": 300, + }}) + if rec.Code != http.StatusOK { + t.Fatalf("enable = %d: %s", rec.Code, rec.Body.String()) + } + var st inbox.Settings + if err := json.Unmarshal(rec.Body.Bytes(), &st); err != nil { + t.Fatal(err) + } + if !st.Transcription.Enabled || st.Transcription.APIKeyEnv != "MY_DG_KEY" || st.Transcription.MonthlyBudgetMinutes != 300 || st.Transcription.KeyPresent { + t.Fatalf("settings = %+v", st.Transcription) + } + if !deps.Config.Inbox.Transcription.Active() || !deps.Inbox.Config().Transcription.Active() { + t.Fatalf("config not updated: %+v", deps.Config.Inbox.Transcription) + } + if strings.Contains(rec.Body.String(), "dg-") { + t.Fatal("settings must never carry a key value") + } +} diff --git a/src/pkg/dashboard/inbox_transcribe.test.js b/src/pkg/dashboard/inbox_transcribe.test.js new file mode 100644 index 0000000000..ff4385fd22 --- /dev/null +++ b/src/pkg/dashboard/inbox_transcribe.test.js @@ -0,0 +1,161 @@ +// Inbox machine transcription UI: the 🎧 Transcribe button and state pill on +// items, the POST handler, and the ⚙ settings section with its consent gate. +// Functions are extracted from the generated page and run in a sandbox. +// Run: node --test src/pkg/dashboard/*.test.js +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const ASYNC_PREFIX = 'async '; +const fnSrc = name => { + let start = html.indexOf('function ' + name + '('); + assert.ok(start >= 0, name + ' not found'); + if (html.slice(start - ASYNC_PREFIX.length, start) === ASYNC_PREFIX) start -= ASYNC_PREFIX.length; + let depth = 0; + for (let i = html.indexOf('{', start); i < html.length; i++) { + if (html[i] === '{') depth++; + else if (html[i] === '}' && --depth === 0) return html.slice(start, i + 1); + } + throw new Error('unbalanced ' + name); +}; + +const BYTES_PER_MB = 1048576; +const escapeHtml = s => String(s == null ? '' : s).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); +const LABELS = { queued: 'Transcription queued', running: 'Transcribing', done: 'Machine transcript', failed: 'Transcription failed', skipped: 'Not transcribed' }; + +// itemHarness builds inboxTranscriptionHtml + inboxTranscribe with the +// helpers they call injected. +const itemHarness = ({ role = 'owner', status = 202, body = { state: { status: 'queued' } } } = {}) => { + const calls = { fetches: [], toasts: [], renders: 0, refreshes: 0 }; + const fetch = async (url, opts) => { + calls.fetches.push({ url, opts }); + return { ok: status >= 200 && status < 300, status, json: async () => body }; + }; + const ctx = { + window: { _hiveRole: role }, + _inboxTranscribing: new Set(), + _inboxContent: { 'plaud/r1': { transcript: 'old' } }, + }; + const h = new Function('ctx', 'fetch', 'escapeHtml', 'formatDashboardDateTime', 'showToast', 'renderInbox', 'fetchInbox', 'INBOX_TX_STATUS_LABELS', + 'const window = ctx.window; const _inboxTranscribing = ctx._inboxTranscribing; const _inboxContent = ctx._inboxContent;\n' + + fnSrc('inboxViewerCanPlay') + '\n' + fnSrc('inboxApiPath') + '\n' + fnSrc('inboxTranscriptionHtml') + '\n' + fnSrc('inboxTranscribe') + '\n' + + 'return { inboxTranscriptionHtml, inboxTranscribe };'); + const api = h(ctx, fetch, escapeHtml, s => 'at ' + s, (msg, kind) => calls.toasts.push([msg, kind]), + () => { calls.renders++; }, async () => { calls.refreshes++; }, LABELS); + return { api, ctx, calls }; +}; + +test('Transcribe button shows on transcribable items for owner and read-write only', () => { + const it = { source: 'plaud', id: 'r1', pending: true, transcribable: true }; + for (const [role, want] of [['owner', true], ['read-write', true], ['read-only', false], ['', false]]) { + const { api } = itemHarness({ role }); + const out = api.inboxTranscriptionHtml(it, 'plaud/r1'); + assert.strictEqual(/data-action="inboxTranscribe" data-arg0="plaud" data-arg1="r1"/.test(out), want, 'role ' + role); + } + const { api } = itemHarness(); + assert.strictEqual(api.inboxTranscriptionHtml({ source: 'plaud', id: 'r2', pending: true }, 'plaud/r2'), '', 'no button without transcribable'); + assert.match(api.inboxTranscriptionHtml(it, 'plaud/r1'), /🎧 Transcribe { + const { api, ctx } = itemHarness(); + let out = api.inboxTranscriptionHtml({ source: 'plaud', id: 'r1', transcription: { status: 'running', updated_at: '2026-11-15T10:00:00Z' } }, 'plaud/r1'); + assert.match(out, /inbox-tx-spinner/); + assert.match(out, /data-status="syncing"/); + assert.match(out, /Transcribing/); + assert.match(out, /title="Updated at 2026-11-15T10:00:00Z"/); + assert.doesNotMatch(out, /inboxTranscribe/, 'no button while running'); + out = api.inboxTranscriptionHtml({ source: 'plaud', id: 'r1', transcribable: true, transcription: { status: 'failed', reason: 'check the Deepgram key in $DEEPGRAM_API_KEY ' } }, 'plaud/r1'); + assert.match(out, /data-status="error"/); + assert.match(out, /check the Deepgram key in \$DEEPGRAM_API_KEY <x>/); + assert.match(out, /Retry transcription/); + out = api.inboxTranscriptionHtml({ source: 'plaud', id: 'r1', transcription: { status: 'done', provider: 'deepgram', model: 'nova-3' } }, 'plaud/r1'); + assert.match(out, /Machine transcript \(deepgram\/nova-3\)/); + assert.match(out, /data-status="ok"/); + ctx._inboxTranscribing.add('plaud/r1'); + out = api.inboxTranscriptionHtml({ source: 'plaud', id: 'r1', transcribable: true }, 'plaud/r1'); + assert.match(out, /disabled aria-busy="true"/); + assert.match(out, /Sending…/); +}); + +test('inboxTranscribe posts to the item endpoint, toasts and refreshes', async () => { + const { api, ctx, calls } = itemHarness(); + await api.inboxTranscribe('plaud', 'a/b'); + assert.strictEqual(calls.fetches.length, 1); + assert.strictEqual(calls.fetches[0].url, '/api/inbox/plaud/a%2Fb/transcribe'); + assert.strictEqual(calls.fetches[0].opts.method, 'POST'); + assert.strictEqual(calls.toasts[0][1], 'success'); + assert.strictEqual(calls.refreshes, 1); + assert.strictEqual(ctx._inboxTranscribing.size, 0, 'spinner cleared'); + + const skipped = itemHarness({ body: { state: { status: 'skipped', reason: 'budget: 600 of 600 minutes used' } } }); + await skipped.api.inboxTranscribe('plaud', 'r1'); + assert.deepStrictEqual(skipped.calls.toasts[0], ['Not transcribed: budget: 600 of 600 minutes used', 'error']); + + const denied = itemHarness({ status: 412, body: { error: 'transcription is not enabled on this hive' } }); + await denied.api.inboxTranscribe('plaud', 'r1'); + assert.deepStrictEqual(denied.calls.toasts[0], ['Transcription failed: transcription is not enabled on this hive', 'error']); + assert.strictEqual(denied.calls.refreshes, 1); + assert.ok(denied.ctx._inboxContent['plaud/r1'], 'cached content kept on failure'); + + const busy = itemHarness(); + busy.ctx._inboxTranscribing.add('plaud/r1'); + await busy.api.inboxTranscribe('plaud', 'r1'); + assert.strictEqual(busy.calls.fetches.length, 0, 'a second click while in flight is ignored'); +}); + +// formRoot fakes the settings form: querySelector by data attribute. +const formRoot = fields => ({ + querySelector: sel => { + if (sel === '[data-inbox-tx-section]') return {}; + const m = /data-inbox-tx-field="([^"]+)"/.exec(sel); + return m && fields[m[1]] !== undefined ? fields[m[1]] : null; + }, +}); + +const settingsHarness = () => new Function('escapeHtml', 'yamlHint', 'INBOX_TX_BYTES_PER_MB', + fnSrc('inboxTranscriptionFormHtml') + '\n' + fnSrc('inboxReadTranscription') + '\nreturn { inboxTranscriptionFormHtml, inboxReadTranscription };', +)(escapeHtml, p => '' + p + '', BYTES_PER_MB); + +test('settings section shows the consent notice, key status and every yaml key', () => { + const { inboxTranscriptionFormHtml } = settingsHarness(); + let out = inboxTranscriptionFormHtml({ enabled: false, api_key_env: 'MY_DG', key_present: false, max_bytes: 524288000, sources: ['plaud'] }); + assert.match(out, /other people's voices/); + assert.match(out, /Deepgram under the hive owner's Deepgram account and key/); + assert.match(out, /data-inbox-tx-field="consent_acknowledged">/); + assert.match(out, /\$MY_DG<\/code>: key missing/); + assert.match(out, /value="500"/, 'max_bytes shown in MB'); + assert.match(out, /value="plaud"/); + for (const key of ['enabled', 'mode', 'sources[]', 'api_key_env', 'provider', 'model', 'diarize', 'language', 'max_duration_minutes', 'max_bytes', 'monthly_budget_minutes', 'daily_max_items', 'consent_acknowledged']) { + assert.ok(out.includes('inbox.transcription.' + key), 'yaml hint for ' + key); + } + out = inboxTranscriptionFormHtml({ enabled: true, consent_acknowledged: true, key_present: true, mode: 'auto' }); + assert.match(out, /key present/); + assert.match(out, /data-inbox-tx-field="enabled" checked|data-inbox-tx-field="enabled"[^>]* checked/); + assert.match(out, /