Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat: consume and enforce organization policy
Gabriel Steindc7984e6e079
diff --git a/preload.js b/preload.jsindex b40f9b4cf..dd9e48cec 100644--- a/preload.js+++ b/preload.js@@ -605,6 +605,7 @@ contextBridge.exposeInMainWorld("electronAPI", {cloudPreviewSwitch: (opts) => ipcRenderer.invoke("cloud-preview-switch", opts),cloudApiRequest: (opts) => ipcRenderer.invoke("cloud-api-request", opts),getSttConfig: () => ipcRenderer.invoke("get-stt-config"),+ getWorkspacePolicy: () => ipcRenderer.invoke("get-workspace-policy"),getNoteRecordingConfig: () => ipcRenderer.invoke("get-note-recording-config"),// Cloud audio file transcriptiondiff --git a/src/components/SettingsModal.tsx b/src/components/SettingsModal.tsxindex 31540f05e..722cbdc05 100644--- a/src/components/SettingsModal.tsx+++ b/src/components/SettingsModal.tsx@@ -1,5 +1,6 @@import React, { useMemo, useState } from "react";import { useTranslation } from "react-i18next";+import { usePolicyStore } from "../stores/policyStore";import {Sliders,Mic,@@ -55,6 +56,7 @@ interface SettingsModalProps {export default function SettingsModal({ open, onOpenChange, initialSection }: SettingsModalProps) {const { t } = useTranslation();const { isSignedIn } = useAuth();+ const policyManaged = usePolicyStore((s) => s.managed);const sidebarItems: SidebarItem<SettingsSectionType>[] = useMemo(() => {const items: SidebarItem<SettingsSectionType>[] = [{@@ -160,6 +162,11 @@ export default function SettingsModal({ open, onOpenChange, initialSection }: SeactiveSection={activeSection}onSectionChange={handleSectionChange}>+ {policyManaged && (+ <div className="mx-4 mt-4 rounded-md border border-blue-200 bg-blue-50 px-3 py-2 text-sm text-blue-800 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-200">+ {t("settingsModal.managedByOrg", "Some settings are managed by your organization.")}+ </div>+ )}<SettingsPageactiveSection={activeSection}onNavigateToSection={handleSectionChange}diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsxindex 2928ed3ee..c01a0fcd9 100644--- a/src/components/SettingsPage.tsx+++ b/src/components/SettingsPage.tsx@@ -108,6 +108,7 @@ import { syncService } from "../services/SyncService.js";import { formatBytes } from "../utils/formatBytes";import { clearMissingLocalModelSelections, useSettingsStore } from "../stores/settingsStore";import { useWorkspaceStore } from "../stores/workspaceStore";+import { usePolicyStore, enforceModeOptions } from "../stores/policyStore";import { canManageSystemAudioInApp } from "../utils/systemAudioAccess";import WorkspaceSection from "./settings/WorkspaceSection";import WorkspaceBillingOverview from "./settings/WorkspaceBillingOverview";@@ -269,35 +270,42 @@ function TranscriptionSection({toast,}: TranscriptionSectionProps) {const { t } = useTranslation();-- const transcriptionModes: InferenceModeOption[] = [- {- id: "openwhispr",- label: t("settingsPage.transcription.modes.openwhispr"),- description: t("settingsPage.transcription.modes.openwhisprDesc"),- icon: <Cloud className="w-4 h-4" />,- disabled: !isSignedIn,- badge: !isSignedIn ? t("common.freeAccountRequired") : undefined,- },- {- id: "providers",- label: t("settingsPage.transcription.modes.providers"),- description: t("settingsPage.transcription.modes.providersDesc"),- icon: <Key className="w-4 h-4" />,- },- {- id: "local",- label: t("settingsPage.transcription.modes.local"),- description: t("settingsPage.transcription.modes.localDesc"),- icon: <Cpu className="w-4 h-4" />,- },- {- id: "self-hosted",- label: t("settingsPage.transcription.modes.selfHosted"),- description: t("settingsPage.transcription.modes.selfHostedDesc"),- icon: <Network className="w-4 h-4" />,- },- ];+ const policyManaged = usePolicyStore((s) => s.managed);+ const policyDoc = usePolicyStore((s) => s.policy);++ const transcriptionModes: InferenceModeOption[] = enforceModeOptions(+ [+ {+ id: "openwhispr",+ label: t("settingsPage.transcription.modes.openwhispr"),+ description: t("settingsPage.transcription.modes.openwhisprDesc"),+ icon: <Cloud className="w-4 h-4" />,+ disabled: !isSignedIn,+ badge: !isSignedIn ? t("common.freeAccountRequired") : undefined,+ },+ {+ id: "providers",+ label: t("settingsPage.transcription.modes.providers"),+ description: t("settingsPage.transcription.modes.providersDesc"),+ icon: <Key className="w-4 h-4" />,+ },+ {+ id: "local",+ label: t("settingsPage.transcription.modes.local"),+ description: t("settingsPage.transcription.modes.localDesc"),+ icon: <Cpu className="w-4 h-4" />,+ },+ {+ id: "self-hosted",+ label: t("settingsPage.transcription.modes.selfHosted"),+ description: t("settingsPage.transcription.modes.selfHostedDesc"),+ icon: <Network className="w-4 h-4" />,+ },+ ],+ "transcription",+ { managed: policyManaged, policy: policyDoc },+ t("settingsPage.managedByOrg", "Managed by your organization"),+ );const handleTranscriptionModeSelect = (mode: InferenceMode) => {if (mode === "openwhispr" && !isSignedIn) {diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex b08f7d654..fbc8cbb46 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -7641,7 +7641,7 @@ class IPCHandlers {if (!Object.keys(authHeader).length) throw new Error("Not authenticated");const response = await proxyFetch(`${apiUrl}/api/stt-config`, {- headers: authHeader,+ headers: { ...authHeader, "x-openwhispr-version": app.getVersion() },});if (!response.ok) {@@ -7662,6 +7662,54 @@ class IPCHandlers {}});+ // Org policy delivered by the API and enforced by the app. Cached to disk so+ // enforcement survives a network failure (fail-closed): on error we keep+ // serving the last policy rather than falling back to unmanaged. An+ // authoritative `managed: false` clears the cache so leaving a workspace+ // unlocks settings.+ ipcMain.handle("get-workspace-policy", async (event) => {+ const cachePath = path.join(app.getPath("userData"), "workspace-policy.json");+ try {+ const apiUrl = getApiUrl();+ if (!apiUrl) throw new Error("OpenWhispr API URL not configured");++ const authHeader = await getAuthHeader(event);+ if (!Object.keys(authHeader).length) throw new Error("Not authenticated");++ const response = await proxyFetch(`${apiUrl}/api/workspace-policy`, {+ headers: { ...authHeader, "x-openwhispr-version": app.getVersion() },+ });+ if (!response.ok) throw new Error(`API error: ${response.status}`);++ const json = await response.json();+ const data = json?.data ?? null;+ if (data && data.managed) {+ try {+ fs.writeFileSync(cachePath, JSON.stringify(data), { mode: 0o600 });+ } catch (err) {+ debugLogger.error("Policy cache write failed:", err);+ }+ } else {+ try {+ if (fs.existsSync(cachePath)) fs.unlinkSync(cachePath);+ } catch {+ /* ignore */+ }+ }+ return { success: true, status: "ok", ...data };+ } catch (error) {+ try {+ if (fs.existsSync(cachePath)) {+ const cached = JSON.parse(fs.readFileSync(cachePath, "utf8"));+ return { success: true, status: "cached", ...cached };+ }+ } catch (err) {+ debugLogger.error("Policy cache read failed:", err);+ }+ return { success: false, status: "error", error: error.message };+ }+ });+ipcMain.handle("get-note-recording-config", async (event) => {try {const apiUrl = getApiUrl();diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.tsindex 372d3d14f..36044823d 100644--- a/src/hooks/useAuth.ts+++ b/src/hooks/useAuth.ts@@ -27,6 +27,7 @@ import {} from "../lib/authRequestContext";import logger from "../utils/logger";import { useSettingsStore } from "../stores/settingsStore";+import { usePolicyStore } from "../stores/policyStore";const useStaticSession = () => ({data: null,@@ -191,6 +192,7 @@ export function useAuth() {if (!cancelled) {logger.debug("Auth state sync", { isSignedIn: true, userId: resolvedUserId }, "auth");useSettingsStore.getState().setIsSignedIn(true);+ void usePolicyStore.getState().fetchPolicy();}} else {invalidateValidatedAuthContext();diff --git a/src/stores/policyStore.ts b/src/stores/policyStore.tsnew file mode 100644index 000000000..6e77be03b--- /dev/null+++ b/src/stores/policyStore.ts@@ -0,0 +1,86 @@+import { create } from "zustand";+import logger from "../utils/logger";+import type { InferenceMode } from "../types/electron";+import type { OrgPolicy, PolicyScope } from "../types/policy";++interface PolicyState {+ /** True once the org enforces a policy on this user. */+ managed: boolean;+ /** The resolved policy, or null when unmanaged. */+ policy: OrgPolicy | null;+ /** True after the first fetch resolves (success or fail-closed cache). */+ loaded: boolean;+ fetchPolicy: () => Promise<void>;+}++export const usePolicyStore = create<PolicyState>()((set) => ({+ managed: false,+ policy: null,+ loaded: false,+ fetchPolicy: async () => {+ try {+ const result = await window.electronAPI.getWorkspacePolicy?.();+ if (result?.success) {+ set({+ managed: Boolean(result.managed),+ policy: result.policy ?? null,+ loaded: true,+ });+ return;+ }+ // Fetch failed with no cache: treat as unmanaged until a later fetch+ // succeeds. The stt-config `managed` bootstrap flag locks provider+ // settings in the meantime for a fresh managed install.+ set({ loaded: true });+ } catch (error) {+ logger.error("Failed to fetch workspace policy:", error);+ set({ loaded: true });+ }+ },+}));++/** Whether a transcription/LLM mode is allowed. Unmanaged users allow everything. */+export function isModeAllowed(+ state: Pick<PolicyState, "managed" | "policy">,+ scope: PolicyScope,+ mode: InferenceMode+): boolean {+ if (!state.managed || !state.policy) return true;+ return state.policy[scope].allowedModes.includes(mode);+}++/** Whether a BYOK provider id is allowed for a scope. Unmanaged users allow everything. */+export function isProviderAllowed(+ state: Pick<PolicyState, "managed" | "policy">,+ scope: PolicyScope,+ providerId: string+): boolean {+ if (!state.managed || !state.policy) return true;+ return state.policy[scope].allowedByokProviders.includes(providerId);+}++/** Whether an enterprise-cloud provider id is allowed. Unmanaged users allow everything. */+export function isEnterpriseProviderAllowed(+ state: Pick<PolicyState, "managed" | "policy">,+ providerId: string+): boolean {+ if (!state.managed || !state.policy) return true;+ return state.policy.llm.allowedEnterpriseProviders.includes(providerId);+}++/** Mark policy-disallowed mode options disabled with a "managed" badge. */+export function enforceModeOptions<+ T extends { id: InferenceMode; disabled?: boolean; badge?: string },+>(+ options: T[],+ scope: PolicyScope,+ state: Pick<PolicyState, "managed" | "policy">,+ managedBadge: string+): T[] {+ if (!state.managed || !state.policy) return options;+ return options.map((option) =>+ isModeAllowed(state, scope, option.id)+ ? option+ : { ...option, disabled: true, badge: managedBadge }+ );+}diff --git a/src/types/electron.ts b/src/types/electron.tsindex b3dd927c2..8ea11279b 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -1,6 +1,7 @@import type { ModelDefinition } from "../models/ModelRegistry";import type { TinfoilCatalogModel } from "../models/tinfoilModels";import type { UsageResponse } from "../lib/usageStore";+import type { OrgPolicy } from "./policy";export type LocalTranscriptionProvider = "whisper" | "nvidia";@@ -768,8 +769,19 @@ declare global {dictation: { mode: string };notes: { mode: string };streamingProvider: string;+ managed?: boolean;} | null>;+ // Org policy (see src/types/policy.ts)+ getWorkspacePolicy?: () => Promise<{+ success: boolean;+ status?: "ok" | "cached" | "error";+ managed?: boolean;+ policy?: OrgPolicy | null;+ policyUpdatedAt?: string | null;+ error?: string;+ }>;+getNoteRecordingConfig?: () => Promise<{success: boolean;providers: Array<{diff --git a/src/types/policy.ts b/src/types/policy.tsnew file mode 100644index 000000000..8d93b25f3--- /dev/null+++ b/src/types/policy.ts@@ -0,0 +1,41 @@+import type { InferenceMode } from "./electron";++/**+ * Organization policy delivered by the OpenWhispr API and enforced by the app.+ *+ * Mirrors the canonical schema in `openwhispr-api/lib/policy-schema.ts` and+ * `openwhispr-admin/lib/policy-schema.ts` — keep the three in sync. Provider and+ * mode ids match the model registry exactly.+ */++export type LocalHistoryMode = "user_choice" | "always_on" | "always_off";+export type ExternalSharingMode = "allowed" | "domain_only" | "disabled";++export interface OrgPolicy {+ version: number;+ transcription: {+ allowedModes: InferenceMode[];+ allowedByokProviders: string[];+ };+ llm: {+ allowedModes: InferenceMode[];+ allowedByokProviders: string[];+ allowedEnterpriseProviders: string[];+ };+ features: {+ agentEnabled: boolean;+ webSearchEnabled: boolean;+ };+ sharing: {+ externalLinkSharing: ExternalSharingMode;+ };+ dataRetention: {+ audioRetentionMaxDays: number | null;+ localHistoryMode: LocalHistoryMode;+ cloudBackupAllowed: boolean;+ };+ minAppVersion: string | null;+}++/** Which allowlist a mode/provider check applies to. */+export type PolicyScope = "transcription" | "llm";