diff --git a/changelog.d/added-18393-meetings-tts-quorum-020.md b/changelog.d/added-18393-meetings-tts-quorum-020.md new file mode 100644 index 0000000000..8fd29c1913 --- /dev/null +++ b/changelog.d/added-18393-meetings-tts-quorum-020.md @@ -0,0 +1 @@ +- Meetings: hive ships Quorum v0.2.0 and passes it a text-to-speech service for Discord speech (`meetings.tts_url`, a write-only **TTS token** in Settings, Meetings, and the persona's voice as `QUORUM_TTS_VOICE` and `voice_id` on every join); hive never speaks in a Discord meeting whose voice is off (#18393). diff --git a/dashboard/openapi.json b/dashboard/openapi.json index 9866891443..69e0b8afa1 100644 --- a/dashboard/openapi.json +++ b/dashboard/openapi.json @@ -298,7 +298,7 @@ "Meetings" ], "summary": "Get meetings settings", - "description": "meetings.enabled, the Vexa gateway URL, whether the Vexa tenant key, Discord bot token and transcription service token are set (never their values), and the effective values of the other meetings keys. Owner only.", + "description": "meetings.enabled, the Vexa gateway URL, whether the Vexa tenant key, Discord bot token, transcription service token and TTS service token are set (never their values), and the effective values of the other meetings keys. Owner only.", "responses": { "200": { "description": "Settings", @@ -328,6 +328,9 @@ "transcribe_token_set": { "type": "boolean" }, + "tts_token_set": { + "type": "boolean" + }, "restart_required": { "type": "boolean" }, @@ -355,7 +358,7 @@ "Meetings" ], "summary": "Update meetings settings", - "description": "Sets meetings.enabled and meetings.vexa.url in hive.yaml and writes the Vexa tenant key, Discord bot token and transcription service token to keystore-sealed secret files (an empty string clears one). Takes effect after a restart. Owner only.", + "description": "Sets meetings.enabled and meetings.vexa.url in hive.yaml and writes the Vexa tenant key, Discord bot token, transcription service token and TTS service token to keystore-sealed secret files (an empty string clears one). Takes effect after a restart. Owner only.", "requestBody": { "required": true, "content": { @@ -378,6 +381,10 @@ "transcribe_token": { "type": "string", "description": "Transcription service token Quorum posts Discord audio with (write-only)" + }, + "tts_token": { + "type": "string", + "description": "TTS service token Quorum speaks Discord replies with (write-only)" } } } @@ -407,6 +414,9 @@ "transcribe_token_set": { "type": "boolean" }, + "tts_token_set": { + "type": "boolean" + }, "restart_required": { "type": "boolean" } diff --git a/src/Dockerfile b/src/Dockerfile index f29564a2f2..2e96bef3bc 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -528,8 +528,8 @@ RUN ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" && \ # Bump note: see src/docs/cli-pins.md (quorum row); update QUORUM_VERSION and # QUORUM_SHA256 together from the release's quorum.mjs.sha256, and # QUORUM_DAVEY_VERSION from quorum's package-lock.json. -ARG QUORUM_VERSION=v0.1.0 -ARG QUORUM_SHA256=917aee456e5c87a6b531f1c7c09040fa60d04a39609a1c2755cfdd20d63d7c95 +ARG QUORUM_VERSION=v0.2.0 +ARG QUORUM_SHA256=9233653115baffcd884c3181a0bf7714145ca858e84abb1d2411a4f255e75e03 ARG QUORUM_DAVEY_VERSION=0.1.12 RUN if [ -n "${QUORUM_VERSION}" ]; then \ test -n "${QUORUM_SHA256}" || { echo "QUORUM_SHA256 is required with QUORUM_VERSION" >&2; exit 1; } && \ diff --git a/src/cmd/hive/meetingswire.go b/src/cmd/hive/meetingswire.go index ea073bac87..580b5596bb 100644 --- a/src/cmd/hive/meetingswire.go +++ b/src/cmd/hive/meetingswire.go @@ -35,7 +35,7 @@ var newQuorumSupervisor = func(opts quorumproc.Options) (quorumSupervisor, error // meetingsQuorumOptions builds the Quorum child options from the meetings // config, resolving the Vexa tenant key, the optional Discord bot token and -// the optional transcription service token from the keystore. A secret that cannot be read is logged and left unset: +// the optional transcription and TTS service tokens from the keystore. A secret that cannot be read is logged and left unset: // Quorum then answers platform_unavailable for that platform instead of the // hive failing to boot. func meetingsQuorumOptions(ctx context.Context, m config.MeetingsConfig, logger *slog.Logger) quorumproc.Options { @@ -51,6 +51,10 @@ func meetingsQuorumOptions(ctx context.Context, m config.MeetingsConfig, logger if err != nil && logger != nil { logger.Warn("[meetings] transcription service token unreadable; Discord audio is not transcribed", "error", err) } + ttsToken, err := m.TTSToken(ctx) + if err != nil && logger != nil { + logger.Warn("[meetings] TTS service token unreadable; Discord replies are not spoken", "error", err) + } return quorumproc.Options{ Binary: m.QuorumBinary(), Listen: m.QuorumListen(), @@ -59,7 +63,11 @@ func meetingsQuorumOptions(ctx context.Context, m config.MeetingsConfig, logger DiscordToken: discordToken, TranscribeURL: m.TranscribeURLOrEmpty(), TranscribeToken: transcribeToken, - Logger: logger, + TTSURL: m.TTSURLOrEmpty(), + TTSToken: ttsToken, + // Discord speaks in the persona's voice by default. + TTSVoice: m.Persona.Resolve().Voice, + Logger: logger, } } @@ -123,6 +131,8 @@ func wireMeetingsManager(cfg *config.Config, sup quorumSupervisor, logger *slog. BotName: cfg.Meetings.BotNameOrDefault(), ConsentText: cfg.Meetings.ConsentTextOrDefault(), LeavePhrases: cfg.Meetings.Persona.Resolve().LeavePhrases, + // meeting.join's voice_id: the persona's voice on every platform. + VoiceID: cfg.Meetings.Persona.Resolve().Voice, LobbyTimeout: time.Duration(cfg.Meetings.LobbyTimeoutSOrDefault()) * time.Second, Logger: logger, // Vexa fixes speaking ability at join time, so with voice-on-address diff --git a/src/cmd/hive/meetingswire_test.go b/src/cmd/hive/meetingswire_test.go index 627a4178b4..4ebac9866c 100644 --- a/src/cmd/hive/meetingswire_test.go +++ b/src/cmd/hive/meetingswire_test.go @@ -63,6 +63,10 @@ func TestWireMeetingsStarts(t *testing.T) { if err := os.WriteFile(txFile, []byte("tx-secret\n"), 0o600); err != nil { t.Fatal(err) } + ttsFile := filepath.Join(dir, "tts") + if err := os.WriteFile(ttsFile, []byte("tts-secret\n"), 0o600); err != nil { + t.Fatal(err) + } fake := &fakeQuorumSup{} var got quorumproc.Options withQuorumSupervisor(t, func(o quorumproc.Options) (quorumSupervisor, error) { @@ -80,6 +84,8 @@ func TestWireMeetingsStarts(t *testing.T) { Discord: config.MeetingsDiscordConfig{TokenFile: filepath.Join(dir, "missing")}, TranscribeURL: "http://vexa-transcription.meetings.svc.cluster.local:8000", TranscribeTokenFile: txFile, + TTSURL: "http://vexa-tts.meetings.svc.cluster.local:8880", + TTSTokenFile: ttsFile, }} var logs bytes.Buffer sup := wireMeetings(context.Background(), cfg, slog.New(slog.NewTextHandler(&logs, nil))) @@ -91,8 +97,11 @@ func TestWireMeetingsStarts(t *testing.T) { got.TranscribeToken != "tx-secret" || got.TranscribeURL != "http://vexa-transcription.meetings.svc.cluster.local:8000" { t.Fatalf("options %+v", got) } - if strings.Contains(logs.String(), "tenant") || strings.Contains(logs.String(), "tx-secret") { - t.Fatal("the tenant key and transcription token must never be logged") + if got.TTSToken != "tts-secret" || got.TTSURL != "http://vexa-tts.meetings.svc.cluster.local:8880" || got.TTSVoice != "af_heart" { + t.Fatalf("tts options url=%q voice=%q token set=%v", got.TTSURL, got.TTSVoice, got.TTSToken != "") + } + if strings.Contains(logs.String(), "tenant") || strings.Contains(logs.String(), "tx-secret") || strings.Contains(logs.String(), "tts-secret") { + t.Fatal("the tenant key and service tokens must never be logged") } } @@ -130,14 +139,15 @@ func TestMeetingsQuorumOptionsUnreadableSecrets(t *testing.T) { Vexa: config.MeetingsVexaConfig{APIKeyFile: dir}, Discord: config.MeetingsDiscordConfig{TokenFile: dir}, TranscribeTokenFile: dir, + TTSTokenFile: dir, } var logs bytes.Buffer o := meetingsQuorumOptions(context.Background(), m, slog.New(slog.NewTextHandler(&logs, nil))) - if o.VexaAPIKey != "" || o.DiscordToken != "" || o.TranscribeToken != "" { + if o.VexaAPIKey != "" || o.DiscordToken != "" || o.TranscribeToken != "" || o.TTSToken != "" { t.Fatal("unreadable secrets must be left unset") } if !strings.Contains(logs.String(), "Vexa tenant key unreadable") || !strings.Contains(logs.String(), "Discord bot token unreadable") || - !strings.Contains(logs.String(), "transcription service token unreadable") { + !strings.Contains(logs.String(), "transcription service token unreadable") || !strings.Contains(logs.String(), "TTS service token unreadable") { t.Fatalf("logs %q", logs.String()) } } diff --git a/src/docs/api-reference/knowledge.md b/src/docs/api-reference/knowledge.md index 7c1782c20a..8521c5a4e6 100644 --- a/src/docs/api-reference/knowledge.md +++ b/src/docs/api-reference/knowledge.md @@ -82,8 +82,8 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f | `POST` | `/api/inbox/recordings/{id}/finalize` | The recorder | End a recording: `{duration_ms?}` (the recorder's count, pauses excluded). The chunks are concatenated in order into `audio.webm` or `audio.mp4`, a pending Knowledge fact (personal layer) is written and the item appears in the Inbox. 200 `{id, state, title, duration_ms, bytes, chunks, transcribes}`; audited as `inbox_recording_finalize` (400 no chunk received, 403, 404, 409 already ended) | `pkg/dashboard/api_inbox_recordings.go:22` | | `DELETE` | `/api/inbox/recordings/{id}` | The recorder, or an owner | Abort an in-progress recording and delete its chunks; audited as `inbox_recording_abort` (403, 404, 409 already ended) | `pkg/dashboard/api_inbox_recordings.go:23` | | `GET` | `/api/inbox/recordings/{id}/audio` | Owner or read-write | Play a finished recording from this hive's disk on the dashboard origin: `http.ServeContent` (Range, 206), `Content-Type` audio/webm or audio/mp4, `Cache-Control: no-store`, `Cross-Origin-Resource-Policy: same-origin`. Opening a playback is audited as `inbox_recording_audio` (seeks are not). `GET /api/inbox/hive-recording/{id}/audio/stream` serves the same file (404 unknown or not finished, 410 audio expired after `inbox.recording.retention_days`) | `pkg/dashboard/api_inbox_recordings.go:24` | -| `GET` | `/api/meetings/settings` | Owner only | Meetings settings: `enabled`, `enabled_env_override`, `running`, `vexa_url`, `vexa_key_set`, `discord_token_set`, `transcribe_token_set` (secrets are never returned) and `effective` values of the other `meetings.*` keys ([env vars](../env-vars.md#meetings-quorum)) | `pkg/dashboard/api_meetings.go:123` | -| `POST` | `/api/meetings/settings` | Owner only | Update `meetings.enabled` and `meetings.vexa.url`, and write the Vexa tenant key, Discord bot token and transcription service token to keystore-sealed secret files (`""` clears one): `{enabled?, vexa_url?, vexa_api_key?, discord_token?, transcribe_token?}`. Returns the settings with `restart_required`; 400 on an invalid value. Audited as `meetings_settings` | `pkg/dashboard/api_meetings.go:124` | +| `GET` | `/api/meetings/settings` | Owner only | Meetings settings: `enabled`, `enabled_env_override`, `running`, `vexa_url`, `vexa_key_set`, `discord_token_set`, `transcribe_token_set`, `tts_token_set` (secrets are never returned) and `effective` values of the other `meetings.*` keys ([env vars](../env-vars.md#meetings-quorum)) | `pkg/dashboard/api_meetings.go:123` | +| `POST` | `/api/meetings/settings` | Owner only | Update `meetings.enabled` and `meetings.vexa.url`, and write the Vexa tenant key, Discord bot token, transcription service token and TTS service token to keystore-sealed secret files (`""` clears one): `{enabled?, vexa_url?, vexa_api_key?, discord_token?, transcribe_token?, tts_token?}`. Returns the settings with `restart_required`; 400 on an invalid value. Audited as `meetings_settings` | `pkg/dashboard/api_meetings.go:124` | | `POST` | `/api/meetings` | Owner only | Send hive to a meeting: `{url}` for Google Meet, Teams or Zoom, or `{platform: "discord", guild_id, channel_id}`, plus `title?` and `voice?`. Returns the meeting record; 400 invalid request, 502 Quorum refused, 503 meetings off. Audited as `meeting_join` | `pkg/dashboard/api_meetings.go:125` | | `GET` | `/api/meetings` | Owner only | `{meetings: [...]}`, newest first | `pkg/dashboard/api_meetings.go:126` | | `GET` | `/api/meetings/{id}` | Owner only | `{meeting, transcript, live}`: the record, stored final segments and chat, and the live-loop state (notes, research, asks, budget); 404 unknown | `pkg/dashboard/api_meetings.go:127` | diff --git a/src/docs/env-vars.md b/src/docs/env-vars.md index 9614921c4e..fbf1afec75 100644 --- a/src/docs/env-vars.md +++ b/src/docs/env-vars.md @@ -390,6 +390,9 @@ Hive as a live meeting participant ([#18284](https://github.com/hivecommons/hive | `HIVE_MEETINGS_TRANSCRIBE_URL` | No | none | Shared transcription service for Discord audio (passed as `QUORUM_TRANSCRIBE_URL`). Overrides `meetings.transcribe_url`. In-cluster: `http://vexa-transcription.meetings.svc.cluster.local:8000`. | | `HIVE_MEETINGS_TRANSCRIBE_TOKEN` | No | none | Transcription service token. Secret. Wins over the secret file. Hive passes it to Quorum as `QUORUM_TRANSCRIBE_TOKEN_FILE`; without it Discord audio is not transcribed. | | `HIVE_MEETINGS_TRANSCRIBE_TOKEN_FILE` | No | `/data/secrets/meetings_transcribe_token` | Keystore-sealed secret file holding the transcription service token. Overrides `meetings.transcribe_token_file`. | +| `HIVE_MEETINGS_TTS_URL` | No | none | Text-to-speech service Quorum speaks Discord replies with (passed as `QUORUM_TTS_URL`). Overrides `meetings.tts_url`. In-cluster on hive-oke: `http://vexa-tts.meetings.svc.cluster.local:8880`. | +| `HIVE_MEETINGS_TTS_TOKEN` | No | none | TTS service token. Secret. Wins over the secret file. Hive passes it to Quorum as `QUORUM_TTS_TOKEN_FILE`, with `QUORUM_TTS_VOICE` set to the persona's voice; without it Discord replies stay in chat. On hive-oke, copied by the operator from Secret `vexa-tts` in namespace `meetings`. | +| `HIVE_MEETINGS_TTS_TOKEN_FILE` | No | `/data/secrets/meetings_tts_token` | Keystore-sealed secret file holding the TTS service token. Overrides `meetings.tts_token_file`. | | `HIVE_MEETINGS_DELIVERY` | No | `chat` | Default delivery for meeting output. Only `chat` is supported. | | `HIVE_MEETINGS_VOICE_ON_ADDRESS` | No | `true` | Lets hive speak when addressed by name in a meeting whose voice is enabled; otherwise it answers in chat. | | `HIVE_MEETINGS_BOT_NAME` | No | the persona's display name (`Betty Bee from the hive`), or `hive (notes)` with the persona off | Display name the meeting bot joins with. | @@ -414,7 +417,7 @@ Hive as a live meeting participant ([#18284](https://github.com/hivecommons/hive | `HIVE_MEETINGS_PERSONA_ALIASES` | No | `betty,betty bee,hive` | Comma-separated names that address the persona at the start or end of a line. | | `HIVE_MEETINGS_PERSONA_PRONOUNS` | No | `she/her` | Pronouns used in the intro and self-description only. | | `HIVE_MEETINGS_PERSONA_LANGUAGE` | No | `en-US` | BCP-47 tag; replies use its language and regional conventions. | -| `HIVE_MEETINGS_PERSONA_VOICE` | No | `af_heart` | TTS voice id for spoken replies (Kokoro; stored for spoken replies, not used yet). | +| `HIVE_MEETINGS_PERSONA_VOICE` | No | `af_heart` | TTS voice id for spoken replies (a Kokoro voice id), passed to Quorum as `QUORUM_TTS_VOICE` and as `voice_id` on `meeting.join`. | | `HIVE_MEETINGS_PERSONA_VOICE_TYPE` | No | `female` | `female`, `male` or `bot`; descriptive only. | | `HIVE_MEETINGS_PERSONA_ACCENT` | No | `American` | Free text; descriptive only. | | `HIVE_MEETINGS_PERSONA_INTRO_TEMPLATE` | No | the preset's intro | Intro posted when someone asks the persona to introduce itself. Placeholders `{name}`, `{display_name}`, `{pronouns}`, `{leave}`, `{accent}`, `{voice_type}`, `{language}`. | diff --git a/src/docs/meetings.md b/src/docs/meetings.md index 1cd2d2978b..0842e51fe2 100644 --- a/src/docs/meetings.md +++ b/src/docs/meetings.md @@ -44,7 +44,7 @@ Hive attends meetings as a persona: **Betty** ("Betty Bee from the hive", she/he A persona is a preset (`meetings.persona.preset`, default `betty`) plus any field set explicitly; every field also has an `HIVE_MEETINGS_PERSONA_*` override ([env-vars.md](env-vars.md#meetings-quorum)). - `language` is a BCP-47 tag (default `en-US`). Betty replies in that language and its regional conventions (American spelling for `en-US`). -- `voice` is the text-to-speech voice id (default `af_heart`, a Kokoro voice) kept for spoken replies, which are not built yet. Kokoro voice ids encode accent and gender: `af_*` is American female, `am_*` American male, `bf_*` and `bm_*` British female and male. A future persona picks a different voice id. A "bot-type" voice would be a different TTS voice or an effect, which is not built yet. +- `voice` is the text-to-speech voice id (default `af_heart`, a Kokoro voice) her spoken replies use: hive passes it to Quorum as `QUORUM_TTS_VOICE` for Discord and as `voice_id` on every `meeting.join`. Kokoro voice ids encode accent and gender: `af_*` is American female, `am_*` American male, `bf_*` and `bm_*` British female and male. A future persona picks a different voice id. A "bot-type" voice would be a different TTS voice or an effect, which is not built yet. - `voice_type` (`female`, `male` or `bot`, default `female`), `accent` (free text, default `American`) and `pronouns` (default `she/her`) describe the persona in the intro and her self-description only; they do not change behaviour. - `intro_template` placeholders: `{name}`, `{display_name}`, `{pronouns}`, `{leave}` (the first leave phrase), `{accent}`, `{voice_type}`, `{language}`. - `searxng_url` is reserved for web search (phase B) and unused for now. @@ -135,6 +135,15 @@ Discord audio is transcribed by the shared transcription service, which needs tw Without the URL and token Discord meetings join but nothing is transcribed. All three (bot token, transcribe URL, transcription token) apply after a restart. +Spoken replies on Discord (Quorum v0.2.0 and later) go through a text-to-speech service, Kokoro's `/v1/audio/speech`, which needs two settings of its own: + +- the TTS URL, `meetings.tts_url` (or `HIVE_MEETINGS_TTS_URL`). On hive-oke the `vexa-tts` Service in the `meetings` namespace answers in-cluster at `http://vexa-tts.meetings.svc.cluster.local:8880`; +- the TTS token. Paste it in the **TTS token** field in **Settings, Meetings** (or set `HIVE_MEETINGS_TTS_TOKEN`). Like the transcription token it is write-only: hive stores it keystore-sealed at `meetings.tts_token_file` (`/data/secrets/meetings_tts_token`), the API reports only `tts_token_set`, and at boot hive writes the plaintext to an owner-only file in Quorum's private runtime directory and passes it as `QUORUM_TTS_TOKEN_FILE`. On hive-oke the operator copies the token from the Secret `vexa-tts` in the `meetings` namespace. + +Hive also passes `QUORUM_TTS_VOICE` (the persona's voice, `meetings.persona.voice`, default `af_heart`) and sends the same voice as `voice_id` on every `meeting.join`, so Betty sounds the same on Discord and on the Vexa platforms. Without the TTS URL and token, Discord replies stay in chat. Both apply after a restart. + +Quorum v0.2.0 ignores `voice: false` on Discord (a Discord bot can always speak), so hive's own policy is the gate: it never calls `say` for a meeting whose voice is off, on any platform, and answers in chat instead. + Discord voice also needs the native `@snazzah/davey` module next to the Quorum bundle; the hive image installs it. Anyone in the Discord server can ask for hive with `/hive join`. The request shows in **Meetings** as a join request with **Approve** and **Decline**; hive joins only when the owner approves it. (No Discord account is mapped to the hive owner yet, so no request is approved automatically.) @@ -153,6 +162,8 @@ Every key has an environment override that wins over `hive.yaml`. The full list | `meetings.discord.token_file` | `/data/secrets/meetings_discord_token` | Keystore-sealed Discord bot token file. | | `meetings.transcribe_url` | none | Transcription service for Discord audio. | | `meetings.transcribe_token_file` | `/data/secrets/meetings_transcribe_token` | Keystore-sealed transcription service token file. | +| `meetings.tts_url` | none | Text-to-speech service for Discord speech (`QUORUM_TTS_URL`). | +| `meetings.tts_token_file` | `/data/secrets/meetings_tts_token` | Keystore-sealed TTS service token file. | | `meetings.delivery` | `chat` | Where meeting output goes. | | `meetings.voice_on_address` | `true` | Allow speaking when addressed in a voice-enabled meeting. | | `meetings.bot_name` | the persona's display name | Bot display name; `hive (notes)` with the persona off. | diff --git a/src/pkg/config/meetings_config.go b/src/pkg/config/meetings_config.go index aa6526041a..bfbbb9af7e 100644 --- a/src/pkg/config/meetings_config.go +++ b/src/pkg/config/meetings_config.go @@ -23,7 +23,8 @@ import ( // call time so a hosted hive's operator can turn meetings on from the // deployment without editing hive.yaml. Precedence is env, then hive.yaml, // then the default. Secrets (the Vexa tenant key, the optional Discord bot -// token and the transcription service token) are never stored in hive.yaml: +// token, the transcription service token and the TTS token) are never +// stored in hive.yaml: // they live in keystore-sealed secret files under /data/secrets, or arrive // through an environment variable. @@ -87,6 +88,10 @@ const ( // that holds the bearer token for the shared transcription service // Discord audio is posted to (QUORUM_TRANSCRIBE_TOKEN_FILE). DefaultMeetingsTranscribeTokenFile = WritableSecretsDir + "/meetings_transcribe_token" + // DefaultMeetingsTTSTokenFile is the keystore-sealed secret file that + // holds the bearer token for the text-to-speech service Quorum speaks + // Discord replies with (QUORUM_TTS_TOKEN_FILE). + DefaultMeetingsTTSTokenFile = WritableSecretsDir + "/meetings_tts_token" // MeetingsDeliveryChat posts meeting output in the meeting chat. MeetingsDeliveryChat = "chat" @@ -113,6 +118,9 @@ const ( MeetingsTranscribeURLEnv = "HIVE_MEETINGS_TRANSCRIBE_URL" MeetingsTranscribeTokenEnv = "HIVE_MEETINGS_TRANSCRIBE_TOKEN" MeetingsTranscribeTokenFileEnv = "HIVE_MEETINGS_TRANSCRIBE_TOKEN_FILE" + MeetingsTTSURLEnv = "HIVE_MEETINGS_TTS_URL" + MeetingsTTSTokenEnv = "HIVE_MEETINGS_TTS_TOKEN" + MeetingsTTSTokenFileEnv = "HIVE_MEETINGS_TTS_TOKEN_FILE" MeetingsDeliveryEnv = "HIVE_MEETINGS_DELIVERY" MeetingsVoiceOnAddressEnv = "HIVE_MEETINGS_VOICE_ON_ADDRESS" MeetingsBotNameEnv = "HIVE_MEETINGS_BOT_NAME" @@ -147,6 +155,13 @@ type MeetingsConfig struct { // transcription service token (QUORUM_TRANSCRIBE_TOKEN_FILE). A path, // never the token. TranscribeTokenFile string `yaml:"transcribe_token_file,omitempty" json:"transcribe_token_file,omitempty"` + // TTSURL is the text-to-speech service Quorum speaks Discord replies + // with (QUORUM_TTS_URL, a Kokoro /v1/audio/speech endpoint). Empty + // leaves Discord without speech. + TTSURL string `yaml:"tts_url,omitempty" json:"tts_url,omitempty"` + // TTSTokenFile is the keystore-sealed secret file holding the TTS + // service token (QUORUM_TTS_TOKEN_FILE). A path, never the token. + TTSTokenFile string `yaml:"tts_token_file,omitempty" json:"tts_token_file,omitempty"` // Delivery is where meeting output goes by default. Only "chat". Delivery string `yaml:"delivery,omitempty" json:"delivery,omitempty"` // VoiceOnAddress lets hive speak when the meeting addresses it by name @@ -426,6 +441,17 @@ func (m MeetingsConfig) TranscribeTokenFileOrDefault() string { return meetingsEnvString(MeetingsTranscribeTokenFileEnv, m.TranscribeTokenFile, DefaultMeetingsTranscribeTokenFile) } +// TTSTokenFileOrDefault returns the secret file path for the TTS service +// token. +func (m MeetingsConfig) TTSTokenFileOrDefault() string { + return meetingsEnvString(MeetingsTTSTokenFileEnv, m.TTSTokenFile, DefaultMeetingsTTSTokenFile) +} + +// TTSURLOrEmpty returns the text-to-speech service URL. +func (m MeetingsConfig) TTSURLOrEmpty() string { + return strings.TrimRight(meetingsEnvString(MeetingsTTSURLEnv, m.TTSURL, ""), "/") +} + // TranscribeURLOrEmpty returns the transcription service URL. func (m MeetingsConfig) TranscribeURLOrEmpty() string { return strings.TrimRight(meetingsEnvString(MeetingsTranscribeURLEnv, m.TranscribeURL, ""), "/") @@ -554,6 +580,12 @@ func (m MeetingsConfig) TranscribeToken(ctx context.Context) (string, error) { return meetingsSecret(ctx, MeetingsTranscribeTokenEnv, m.TranscribeTokenFileOrDefault()) } +// TTSToken returns the optional TTS service token: HIVE_MEETINGS_TTS_TOKEN, +// then the secret file. A secret; never log it. +func (m MeetingsConfig) TTSToken(ctx context.Context) (string, error) { + return meetingsSecret(ctx, MeetingsTTSTokenEnv, m.TTSTokenFileOrDefault()) +} + // WriteMeetingsSecret seals value into the secret file at path through the // keystore (owner-only mode). An empty value removes the file. func WriteMeetingsSecret(ctx context.Context, path, value string) error { @@ -590,6 +622,11 @@ func (m MeetingsConfig) Validate() error { return err } } + if u := m.TTSURLOrEmpty(); u != "" { + if err := validateMeetingsURL("meetings.tts_url", u); err != nil { + return err + } + } switch strings.ToLower(meetingsEnvString(MeetingsLLMModeEnv, m.LLM.Mode, MeetingsLLMModeAuto)) { case MeetingsLLMModeAuto, MeetingsLLMModeOpenAI, MeetingsLLMModeAnthropic, MeetingsLLMModeNone: default: diff --git a/src/pkg/config/meetings_tts_test.go b/src/pkg/config/meetings_tts_test.go new file mode 100644 index 0000000000..1a09f38f5e --- /dev/null +++ b/src/pkg/config/meetings_tts_test.go @@ -0,0 +1,51 @@ +package config + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" +) + +// TestMeetingsTTS pins the Discord speech settings (hivecommons/hive#18393): +// meetings.tts_url and the write-only, keystore-sealed TTS token, each with +// an env override. +func TestMeetingsTTS(t *testing.T) { + ctx := context.Background() + var m MeetingsConfig + if m.TTSURLOrEmpty() != "" || m.TTSTokenFileOrDefault() != DefaultMeetingsTTSTokenFile { + t.Fatalf("defaults %q %q", m.TTSURLOrEmpty(), m.TTSTokenFileOrDefault()) + } + tok := filepath.Join(t.TempDir(), "secrets", "tts") + m = MeetingsConfig{TTSURL: "http://vexa-tts.meetings.svc.cluster.local:8880/", TTSTokenFile: tok} + if m.TTSURLOrEmpty() != "http://vexa-tts.meetings.svc.cluster.local:8880" || m.TTSTokenFileOrDefault() != tok { + t.Fatalf("yaml %q %q", m.TTSURLOrEmpty(), m.TTSTokenFileOrDefault()) + } + if v, err := m.TTSToken(ctx); err != nil || v != "" { + t.Fatalf("missing token file: %q, %v", v, err) + } + if err := WriteMeetingsSecret(ctx, tok, " tts-token\n"); err != nil { + t.Fatal(err) + } + if fi, err := os.Stat(tok); err != nil || fi.Mode().Perm() != 0o600 { + t.Fatalf("token file mode: %v, %v", fi, err) + } + if v, err := m.TTSToken(ctx); err != nil || v != "tts-token" { + t.Fatalf("TTSToken = %q, %v", v, err) + } + t.Setenv(MeetingsTTSURLEnv, "http://env-tts:8880") + t.Setenv(MeetingsTTSTokenEnv, "env-token") + t.Setenv(MeetingsTTSTokenFileEnv, "/env/tts") + if m.TTSURLOrEmpty() != "http://env-tts:8880" || m.TTSTokenFileOrDefault() != "/env/tts" { + t.Fatal("env overrides") + } + if v, _ := m.TTSToken(ctx); v != "env-token" { + t.Fatalf("env token must win, got %q", v) + } + t.Setenv(MeetingsTTSURLEnv, "") + bad := MeetingsConfig{Enabled: true, TTSURL: "kokoro"} + if err := bad.Validate(); err == nil || !strings.Contains(err.Error(), "tts_url") { + t.Fatalf("validate %v", err) + } +} diff --git a/src/pkg/dashboard/api_meetings.go b/src/pkg/dashboard/api_meetings.go index 0fc1eb7373..ff77d92990 100644 --- a/src/pkg/dashboard/api_meetings.go +++ b/src/pkg/dashboard/api_meetings.go @@ -387,7 +387,8 @@ func (s *Server) handleMeetingsWS(w http.ResponseWriter, r *http.Request) { // meetings.enabled, meetings.vexa.url, the Vexa tenant key // (meetings.vexa.api_key_file), the Discord bot token // (meetings.discord.token_file) and the transcription service token -// (meetings.transcribe_token_file); the other meetings keys are shown +// (meetings.transcribe_token_file) and the TTS service token +// (meetings.tts_token_file); the other meetings keys are shown // read-only. type MeetingsSettings struct { Enabled bool `json:"enabled"` @@ -397,6 +398,7 @@ type MeetingsSettings struct { VexaKeySet bool `json:"vexa_key_set"` DiscordTokenSet bool `json:"discord_token_set"` TranscribeTokenSet bool `json:"transcribe_token_set"` + TTSTokenSet bool `json:"tts_token_set"` RestartRequired bool `json:"restart_required,omitempty"` // SpekModel is the model Spektacular live mode would use (never a key). SpekModel string `json:"spek_model"` @@ -411,6 +413,9 @@ type meetingsSettingsRequest struct { // TranscribeToken is the transcription service token Quorum posts // Discord audio with (QUORUM_TRANSCRIBE_TOKEN_FILE). TranscribeToken *string `json:"transcribe_token,omitempty"` + // TTSToken is the TTS service token Quorum speaks Discord replies + // with (QUORUM_TTS_TOKEN_FILE). + TTSToken *string `json:"tts_token,omitempty"` } // meetingsSecretSet reports whether a secret resolves to a value, without @@ -433,11 +438,13 @@ func (s *Server) meetingsSettings(ctx context.Context, m config.MeetingsConfig) VexaKeySet: meetingsSecretSet(ctx, m.VexaAPIKey), DiscordTokenSet: meetingsSecretSet(ctx, m.DiscordToken), TranscribeTokenSet: meetingsSecretSet(ctx, m.TranscribeToken), + TTSTokenSet: meetingsSecretSet(ctx, m.TTSToken), SpekModel: s.meetingsSpekModel(ctx), Effective: map[string]string{ "meetings.quorum.binary": m.QuorumBinary(), "meetings.quorum.listen": m.QuorumListen(), "meetings.transcribe_url": m.TranscribeURLOrEmpty(), + "meetings.tts_url": m.TTSURLOrEmpty(), "meetings.delivery": m.DeliveryOrDefault(), "meetings.voice_on_address": boolString(m.VoiceOnAddressEnabled()), "meetings.bot_name": m.BotNameOrDefault(), @@ -559,6 +566,13 @@ func (s *Server) handleMeetingsSettingsPost(w http.ResponseWriter, r *http.Reque } changed = true } + if req.TTSToken != nil { + if err := config.WriteMeetingsSecret(r.Context(), next.TTSTokenFileOrDefault(), *req.TTSToken); err != nil { + jsonError(w, "saving the TTS token: "+err.Error(), http.StatusInternalServerError) + return + } + changed = true + } s.deps.Config.Meetings = next if err := s.saveConfig(); err != nil { jsonError(w, "saving config: "+err.Error(), http.StatusInternalServerError) @@ -566,7 +580,7 @@ func (s *Server) handleMeetingsSettingsPost(w http.ResponseWriter, r *http.Reque } s.auditFromRequest(r, "meetings_settings", auditDetail("enabled", boolString(next.Enabled), "vexa_url", next.Vexa.URL, "vexa_key_changed", boolString(req.VexaAPIKey != nil), "discord_token_changed", boolString(req.DiscordToken != nil), - "transcribe_token_changed", boolString(req.TranscribeToken != nil)), "") + "transcribe_token_changed", boolString(req.TranscribeToken != nil), "tts_token_changed", boolString(req.TTSToken != nil)), "") out := s.meetingsSettings(r.Context(), next) out.RestartRequired = changed jsonResponse(w, out) diff --git a/src/pkg/dashboard/meetings_tts_token_test.go b/src/pkg/dashboard/meetings_tts_token_test.go new file mode 100644 index 0000000000..ff7ffa21be --- /dev/null +++ b/src/pkg/dashboard/meetings_tts_token_test.go @@ -0,0 +1,96 @@ +package dashboard + +import ( + "context" + "encoding/json" + "net/http" + "os" + "path/filepath" + "strings" + "testing" +) + +// TestMeetingsSettingsTTSToken pins the write-only TTS token +// (hivecommons/hive#18393): the API reports only tts_token_set, the token +// is sealed into meetings.tts_token_file, and an empty string clears it. +func TestMeetingsSettingsTTSToken(t *testing.T) { + s, deps := apiServer(t) + dir := t.TempDir() + tokFile := filepath.Join(dir, "tts") + deps.Config.Meetings.TTSTokenFile = tokFile + deps.Config.Meetings.TTSURL = "http://vexa-tts.meetings.svc.cluster.local:8880" + var got MeetingsSettings + rec := doOwnerGet(s, "/api/meetings/settings") + if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil || rec.Code != http.StatusOK { + t.Fatalf("get = %d %s", rec.Code, rec.Body.String()) + } + if got.TTSTokenSet || got.Effective["meetings.tts_url"] != "http://vexa-tts.meetings.svc.cluster.local:8880" { + t.Fatalf("defaults %+v", got) + } + const secret = "tts-secret-value" + rec = meetingsOwnerPost(s, "/api/meetings/settings", `{"tts_token":"`+secret+`"}`) + if rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), secret) { + t.Fatalf("post = %d %s", rec.Code, rec.Body.String()) + } + _ = json.Unmarshal(rec.Body.Bytes(), &got) + if !got.TTSTokenSet || !got.RestartRequired { + t.Fatalf("after post %+v", got) + } + if fi, err := os.Stat(tokFile); err != nil || fi.Mode().Perm() != 0o600 { + t.Fatalf("token file: %v, %v", fi, err) + } + if v, err := deps.Config.Meetings.TTSToken(context.Background()); err != nil || v != secret { + t.Fatalf("stored token = %q, %v", v, err) + } + if rec := doOwnerGet(s, "/api/meetings/settings"); strings.Contains(rec.Body.String(), secret) { + t.Fatal("GET must never echo the TTS token") + } + rec = meetingsOwnerPost(s, "/api/meetings/settings", `{"tts_token":""}`) + _ = json.Unmarshal(rec.Body.Bytes(), &got) + if got.TTSTokenSet { + t.Fatal("an empty TTS token clears it") + } + if _, err := os.Stat(tokFile); !os.IsNotExist(err) { + t.Fatalf("cleared token file still present: %v", err) + } + blocker := filepath.Join(dir, "file") + if err := os.WriteFile(blocker, []byte("x"), 0o600); err != nil { + t.Fatal(err) + } + deps.Config.Meetings.TTSTokenFile = filepath.Join(blocker, "t") + if rec := meetingsOwnerPost(s, "/api/meetings/settings", `{"tts_token":"x"}`); rec.Code != http.StatusInternalServerError { + t.Fatalf("unwritable token = %d", rec.Code) + } +} + +// TestSettingsMeetingsTTSTokenField pins the Settings → Meetings TTS token +// field: write-only, after the transcription token, sent only when filled, +// and the Discord hint names the in-cluster TTS URL. +func TestSettingsMeetingsTTSTokenField(t *testing.T) { + raw, err := staticFS.ReadFile("static/index.html") + if err != nil { + t.Fatal(err) + } + page := string(raw) + for _, want := range []string{ + `TTS token ' + (s.tts_token_set ? '(set)'`, + `type="password" data-meetings-setting="tts_token" placeholder="leave blank to keep" autocomplete="new-password"`, + `meetingsSetting('tts_token')`, + `if (tts) body.tts_token = tts;`, + `http://vexa-tts.meetings.svc.cluster.local:8880`, + "yamlHint('meetings.tts_token_file')", + } { + if !strings.Contains(page, want) { + t.Errorf("Settings → Meetings TTS token wiring missing %q", want) + } + } + tx := strings.Index(page, `data-meetings-setting="transcribe_token"`) + tts := strings.Index(page, `data-meetings-setting="tts_token"`) + hint := strings.Index(page, `data-meetings-setting="discord_hint"`) + if tx < 0 || tts < tx || hint < tts { + t.Fatalf("field order transcribe=%d tts=%d hint=%d", tx, tts, hint) + } + if strings.Contains(page, "s.tts_token +") || strings.Contains(page, "s.tts_token)") { + t.Fatal("the TTS token must never be rendered back into the form") + } +} diff --git a/src/pkg/dashboard/static-src/js/meetings.js b/src/pkg/dashboard/static-src/js/meetings.js index 6ce18a28ee..671e1ff7e2 100644 --- a/src/pkg/dashboard/static-src/js/meetings.js +++ b/src/pkg/dashboard/static-src/js/meetings.js @@ -246,7 +246,7 @@ function renderGovMeetings() { return '
Send hive into Google Meet, Teams, Zoom or Discord meetings to take notes, ask clarifying questions and run research. ' + - yamlHint('meetings.enabled') + ' ' + yamlHint('meetings.vexa.url') + ' ' + yamlHint('meetings.vexa.api_key_file') + ' ' + yamlHint('meetings.discord.token_file') + ' ' + yamlHint('meetings.transcribe_url') + ' ' + yamlHint('meetings.transcribe_token_file') + ' Changes apply after a restart.
' + + yamlHint('meetings.enabled') + ' ' + yamlHint('meetings.vexa.url') + ' ' + yamlHint('meetings.vexa.api_key_file') + ' ' + yamlHint('meetings.discord.token_file') + ' ' + yamlHint('meetings.transcribe_url') + ' ' + yamlHint('meetings.transcribe_token_file') + ' ' + yamlHint('meetings.tts_url') + ' ' + yamlHint('meetings.tts_token_file') + ' Changes apply after a restart.' + 'Loading…
Discord needs three things: the Discord bot token, the transcribe URL (meetings.transcribe_url or HIVE_MEETINGS_TRANSCRIBE_URL; where the shared service runs in the same cluster, the in-cluster http://vexa-transcription.meetings.svc.cluster.local:8000) and the transcription token. Transcribe URL now: ' +
- (eff['meetings.transcribe_url'] ? '' + escapeHtml(eff['meetings.transcribe_url']) + '' : 'not set') + '.
' + escapeHtml(eff['meetings.transcribe_url']) + '' : 'not set') + '. Discord speech also needs the TTS URL (meetings.tts_url or HIVE_MEETINGS_TTS_URL; in-cluster http://vexa-tts.meetings.svc.cluster.local:8880) and the TTS token. TTS URL now: ' +
+ (eff['meetings.tts_url'] ? '' + escapeHtml(eff['meetings.tts_url']) + '' : 'not set') + '.' +
'Send hive into Google Meet, Teams, Zoom or Discord meetings to take notes, ask clarifying questions and run research. ' + - yamlHint('meetings.enabled') + ' ' + yamlHint('meetings.vexa.url') + ' ' + yamlHint('meetings.vexa.api_key_file') + ' ' + yamlHint('meetings.discord.token_file') + ' ' + yamlHint('meetings.transcribe_url') + ' ' + yamlHint('meetings.transcribe_token_file') + ' Changes apply after a restart.
' + + yamlHint('meetings.enabled') + ' ' + yamlHint('meetings.vexa.url') + ' ' + yamlHint('meetings.vexa.api_key_file') + ' ' + yamlHint('meetings.discord.token_file') + ' ' + yamlHint('meetings.transcribe_url') + ' ' + yamlHint('meetings.transcribe_token_file') + ' ' + yamlHint('meetings.tts_url') + ' ' + yamlHint('meetings.tts_token_file') + ' Changes apply after a restart.' + 'Loading…
Discord needs three things: the Discord bot token, the transcribe URL (meetings.transcribe_url or HIVE_MEETINGS_TRANSCRIBE_URL; where the shared service runs in the same cluster, the in-cluster http://vexa-transcription.meetings.svc.cluster.local:8000) and the transcription token. Transcribe URL now: ' +
- (eff['meetings.transcribe_url'] ? '' + escapeHtml(eff['meetings.transcribe_url']) + '' : 'not set') + '.
' + escapeHtml(eff['meetings.transcribe_url']) + '' : 'not set') + '. Discord speech also needs the TTS URL (meetings.tts_url or HIVE_MEETINGS_TTS_URL; in-cluster http://vexa-tts.meetings.svc.cluster.local:8880) and the TTS token. TTS URL now: ' +
+ (eff['meetings.tts_url'] ? '' + escapeHtml(eff['meetings.tts_url']) + '' : 'not set') + '.' +
'