1fdeda904b
* feat: add voice mode for chat input Adds a voice input button to the chat composer with three transcription engines: in-browser Web Speech API, in-browser Whisper via @huggingface/transformers, and a server-side OpenAI Whisper fallback gated on KANDEV_VOICE_OPENAI_API_KEY. User-configurable from a new /settings/voice-mode page: - Master on/off toggle (defaults to on; opt-out, not opt-in) - Engine preference (auto / Web Speech / Whisper Web / Whisper Server) - Language hint (auto-detect or BCP-47 pinned) - Activation mode (click-to-toggle or hold-to-talk) - Auto-send after transcription - Whisper Web model size (tiny / base / small) - Editable Cmd+Shift+M keyboard shortcut Voice settings live under user_settings.voice_mode as a nested JSON object — no schema migration. Setting changes broadcast via the existing user.settings.updated WS event so any open chat tab updates live. The mic button is rendered on the right of the composer alongside the send button (round primary fill; destructive fill with pulse ring while recording). On browsers without a usable engine (e.g. iOS Chrome over HTTP) the button stays visible as a muted greyed icon — tapping it surfaces a toast with the reason (typically a missing secure context). Whisper Web runs in a Web Worker with fp16 decoder weights (avoids the MatMulNBits scale-missing crash that q4/q8 hit on WASM). Models are pulled from the onnx-community/* mirror and cached by transformers.js in the Cache Storage on first use. * fix: address voice mode PR review feedback and E2E selector clash Bot-review fixes from #1159: - Map http.MaxBytesError from c.FormFile to 413 instead of bare 400. - Strip BCP-47 region suffix before passing language hint to Whisper Web. - Recover from worker crash: terminate + null worker + reset ready flag so next init/transcribe creates a fresh worker instead of hanging. - Read live store state via storeApi.getState() in voice-mode settings savers to avoid stale-closure clobbering concurrent settings updates. - Detach Web Speech callbacks before abort() so trailing onend/onerror events don't mutate hook state after cancel(). - Spread caller init before method/body in voice-api fetch so a caller- supplied init can't override the multipart POST. - Replace t.Fatalf with t.Errorf+return inside test HTTP handler goroutine (FailNow from non-test goroutine is unsafe). - Add Enabled/AutoSend zeroing assertions in partial-update test so the bool-overwrite-on-PATCH behavior is locked in explicitly. E2E fix: - toolbar-overflow spec used button.rounded-full which now matches both the send and voice buttons (strict-mode violation). Switched to the submit-message-button testid for an unambiguous locator. * fix: scope voice settings rollback + whisper worker error to changed keys Round 2 of PR review feedback on #1159: - voice-mode settings rollback now restores only the keys patched by the failing request (not the whole snapshot), preserving concurrent edits to unrelated voiceMode fields. - Shortcut rollback diffs previous vs next and reverts only the changed keys (restore prior value or delete if absent), preserving other concurrent shortcut edits. - Whisper worker error handler captures the worker reference at attach time and only clears refs when this.worker still matches it — a stale error from a previously replaced worker no longer nukes the active one. - Update stale whisper-web-models JSDoc that still pointed at Xenova mirrors. * fix: voice mode progress scale, hold-mode race, race-aware rollback Round 3 of PR review feedback on #1159: - Normalise Whisper progress to 0–1 in ensureWhisperClient (transformers.js emits 0–100, the button's display + the `ready: 1` convention expect 0–1 — fixes the 5000% mid-download display). - Claim driverRef synchronously at the top of finishCapture so concurrent pointerup + pointerleave invocations early-return instead of racing and clobbering a freshly-started recording's ref. - Race-aware rollback: voice-mode and shortcut catch branches now skip reverting a key when latest[key] !== next[key]. A failed earlier request no longer overwrites a later successful save to the same key. - Update the Worker wire-protocol comment to show onnx-community/whisper-base instead of the stale Xenova/* example. --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
452 lines
15 KiB
TypeScript
452 lines
15 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import Link from "next/link";
|
|
import { usePathname } from "next/navigation";
|
|
import {
|
|
IconSettings,
|
|
IconFolder,
|
|
IconRobot,
|
|
IconBell,
|
|
IconCode,
|
|
IconCpu,
|
|
IconKey,
|
|
IconMicrophone,
|
|
IconMessageCircle,
|
|
IconBrandGithub,
|
|
IconBrandGitlab,
|
|
IconBrandSlack,
|
|
IconHexagon,
|
|
IconWand,
|
|
IconGitBranch,
|
|
IconArrowsShuffle,
|
|
IconTicket,
|
|
IconPlugConnected,
|
|
IconBolt,
|
|
IconActivity,
|
|
IconDatabase,
|
|
IconArchive,
|
|
IconFileText,
|
|
IconRefresh,
|
|
IconScale,
|
|
IconInfoCircle,
|
|
IconServerCog,
|
|
} from "@tabler/icons-react";
|
|
import {
|
|
Sidebar,
|
|
SidebarContent,
|
|
SidebarGroup,
|
|
SidebarGroupLabel,
|
|
SidebarGroupContent,
|
|
SidebarMenu,
|
|
SidebarMenuItem,
|
|
SidebarMenuButton,
|
|
SidebarMenuSub,
|
|
SidebarMenuSubItem,
|
|
SidebarMenuSubButton,
|
|
SidebarHeader,
|
|
useSidebar,
|
|
} from "@kandev/ui/sidebar";
|
|
import { ScrollArea } from "@kandev/ui/scroll-area";
|
|
import { ScrollOnOverflow } from "@kandev/ui/scroll-on-overflow";
|
|
import { useAppStore } from "@/components/state-provider";
|
|
import { useAvailableAgents } from "@/hooks/domains/settings/use-available-agents";
|
|
|
|
import { AgentLogo } from "@/components/agent-logo";
|
|
import { getExecutorIcon } from "@/lib/executor-icons";
|
|
import { getCapabilityWarning } from "@/lib/capability-warning";
|
|
import type { Agent, AgentProfile, Executor } from "@/lib/types/http";
|
|
import type { WorkspaceState } from "@/lib/state/slices";
|
|
|
|
type WorkspaceItem = WorkspaceState["items"][number];
|
|
|
|
type GeneralSidebarSectionProps = {
|
|
pathname: string;
|
|
};
|
|
|
|
function GeneralSidebarSection({ pathname }: GeneralSidebarSectionProps) {
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="General">
|
|
<Link href="/settings/general">
|
|
<IconSettings className="h-4 w-4" />
|
|
<span>General</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
<SidebarMenuSubItem>
|
|
<SidebarMenuSubButton
|
|
asChild
|
|
size="sm"
|
|
isActive={pathname === "/settings/general/notifications"}
|
|
>
|
|
<Link href="/settings/general/notifications">
|
|
<IconBell className="h-4 w-4" />
|
|
<span>Notifications</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
<SidebarMenuSubItem>
|
|
<SidebarMenuSubButton
|
|
asChild
|
|
size="sm"
|
|
isActive={pathname === "/settings/general/editors"}
|
|
>
|
|
<Link href="/settings/general/editors">
|
|
<IconCode className="h-4 w-4" />
|
|
<span>Editors</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
</SidebarMenuSub>
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
type WorkspacesSidebarSectionProps = {
|
|
pathname: string;
|
|
workspaces: WorkspaceItem[];
|
|
};
|
|
|
|
function WorkspacesSidebarSection({ pathname, workspaces }: WorkspacesSidebarSectionProps) {
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="Workspaces">
|
|
<Link href="/settings/workspace">
|
|
<IconFolder className="h-4 w-4" />
|
|
<span>Workspaces</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
{workspaces.length > 0 && (
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
{workspaces.map((workspace) => {
|
|
const workspacePath = `/settings/workspace/${workspace.id}`;
|
|
const workflowsPath = `${workspacePath}/workflows`;
|
|
const repositoriesPath = `${workspacePath}/repositories`;
|
|
|
|
return (
|
|
<SidebarMenuSubItem key={workspace.id}>
|
|
<SidebarMenuSubButton asChild isActive={pathname === workspacePath}>
|
|
<Link href={workspacePath}>
|
|
<span>{workspace.name}</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
<SidebarMenuSub className="ml-3">
|
|
<SidebarMenuSubItem>
|
|
<SidebarMenuSubButton
|
|
asChild
|
|
size="sm"
|
|
isActive={pathname === repositoriesPath}
|
|
>
|
|
<Link href={repositoriesPath}>
|
|
<IconGitBranch className="h-3.5 w-3.5" />
|
|
<span>Repositories</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
<SidebarMenuSubItem>
|
|
<SidebarMenuSubButton asChild size="sm" isActive={pathname === workflowsPath}>
|
|
<Link href={workflowsPath}>
|
|
<IconArrowsShuffle className="h-3.5 w-3.5" />
|
|
<span>Workflows</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
</SidebarMenuSub>
|
|
</SidebarMenuSubItem>
|
|
);
|
|
})}
|
|
</SidebarMenuSub>
|
|
)}
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
function SystemSidebarSection({ pathname }: { pathname: string }) {
|
|
const items: Array<{ href: string; label: string; Icon: typeof IconBrandGithub }> = [
|
|
{ href: "/settings/system/status", label: "Status", Icon: IconActivity },
|
|
{ href: "/settings/system/database", label: "Database", Icon: IconDatabase },
|
|
{ href: "/settings/system/backups", label: "Backups", Icon: IconArchive },
|
|
{ href: "/settings/system/logs", label: "Logs", Icon: IconFileText },
|
|
{ href: "/settings/system/updates", label: "Updates", Icon: IconRefresh },
|
|
{ href: "/settings/system/about", label: "About", Icon: IconInfoCircle },
|
|
{ href: "/settings/system/licenses", label: "Licenses", Icon: IconScale },
|
|
];
|
|
const isSystem = pathname.startsWith("/settings/system");
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="System" isActive={isSystem}>
|
|
<Link href="/settings/system/status">
|
|
<IconServerCog className="h-4 w-4" />
|
|
<span>System</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
{items.map(({ href, label, Icon }) => (
|
|
<SidebarMenuSubItem key={href}>
|
|
<SidebarMenuSubButton asChild size="sm" isActive={pathname === href}>
|
|
<Link href={href}>
|
|
<Icon className="h-3.5 w-3.5" />
|
|
<span>{label}</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
))}
|
|
</SidebarMenuSub>
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
function IntegrationsSidebarSection({ pathname }: { pathname: string }) {
|
|
const items: Array<{ href: string; label: string; Icon: typeof IconBrandGithub }> = [
|
|
{ href: "/settings/integrations/github", label: "GitHub", Icon: IconBrandGithub },
|
|
{ href: "/settings/integrations/gitlab", label: "GitLab", Icon: IconBrandGitlab },
|
|
{ href: "/settings/integrations/jira", label: "Jira", Icon: IconTicket },
|
|
{ href: "/settings/integrations/linear", label: "Linear", Icon: IconHexagon },
|
|
{ href: "/settings/integrations/slack", label: "Slack", Icon: IconBrandSlack },
|
|
];
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="Integrations">
|
|
<Link href="/settings/integrations">
|
|
<IconPlugConnected className="h-4 w-4" />
|
|
<span>Integrations</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
{items.map(({ href, label, Icon }) => (
|
|
<SidebarMenuSubItem key={href}>
|
|
<SidebarMenuSubButton asChild size="sm" isActive={pathname === href}>
|
|
<Link href={href}>
|
|
<Icon className="h-3.5 w-3.5" />
|
|
<span>{label}</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
))}
|
|
</SidebarMenuSub>
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
type AgentsSidebarSectionProps = {
|
|
pathname: string;
|
|
agents: Agent[];
|
|
};
|
|
|
|
function AgentsSidebarSection({ pathname, agents }: AgentsSidebarSectionProps) {
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="Agents">
|
|
<Link href="/settings/agents">
|
|
<IconRobot className="h-4 w-4" />
|
|
<span>Agents</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
{agents.length > 0 && (
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
{agents.flatMap((agent: Agent) =>
|
|
agent.profiles.map((profile: AgentProfile) => {
|
|
const encodedAgent = encodeURIComponent(agent.name);
|
|
const profilePath = `/settings/agents/${encodedAgent}/profiles/${profile.id}`;
|
|
const agentLabel = profile.agentDisplayName || agent.name;
|
|
const warning = getCapabilityWarning(agent.capability_status, agent.capability_error);
|
|
return (
|
|
<SidebarMenuSubItem key={profile.id} className="min-w-0">
|
|
<SidebarMenuSubButton asChild isActive={pathname === profilePath}>
|
|
<Link
|
|
href={profilePath}
|
|
className="!flex min-w-0 items-center gap-1.5"
|
|
title={warning?.title || `${agentLabel} • ${profile.name}`}
|
|
>
|
|
<AgentLogo agentName={agent.name} className="shrink-0" />
|
|
<ScrollOnOverflow className="min-w-0">
|
|
{agentLabel} • {profile.name}
|
|
</ScrollOnOverflow>
|
|
{warning && <warning.Icon className={`size-3.5 shrink-0 ${warning.color}`} />}
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
);
|
|
}),
|
|
)}
|
|
</SidebarMenuSub>
|
|
)}
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
type ExecutorsSidebarSectionProps = {
|
|
pathname: string;
|
|
executors: Executor[];
|
|
};
|
|
|
|
function ExecutorsSidebarSection({ pathname, executors }: ExecutorsSidebarSectionProps) {
|
|
const allProfiles = executors.flatMap((e) =>
|
|
(e.profiles ?? []).map((p) => ({ ...p, executorType: e.type })),
|
|
);
|
|
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild tooltip="Executors" isActive={pathname === "/settings/executors"}>
|
|
<Link href="/settings/executors">
|
|
<IconCpu className="h-4 w-4" />
|
|
<span>Executors</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
{allProfiles.length > 0 && (
|
|
<SidebarMenuSub className="ml-3 mt-1">
|
|
{allProfiles.map((profile) => {
|
|
const Icon = getExecutorIcon(profile.executorType);
|
|
const profilePath = `/settings/executors/${profile.id}`;
|
|
return (
|
|
<SidebarMenuSubItem key={profile.id}>
|
|
<SidebarMenuSubButton asChild size="sm" isActive={pathname === profilePath}>
|
|
<Link href={profilePath} className="!flex items-center gap-1.5">
|
|
<Icon className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
|
|
<span>{profile.name}</span>
|
|
</Link>
|
|
</SidebarMenuSubButton>
|
|
</SidebarMenuSubItem>
|
|
);
|
|
})}
|
|
</SidebarMenuSub>
|
|
)}
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
type SimpleSidebarEntry = {
|
|
href: string;
|
|
label: string;
|
|
Icon: typeof IconBrandGithub;
|
|
};
|
|
|
|
/**
|
|
* A short row of single-link sidebar entries (Automations, Prompts, Voice
|
|
* Mode, Utility Agents, External MCP) — extracted from `SettingsAppSidebar`
|
|
* so the parent function stays under the 100-line lint limit.
|
|
*/
|
|
function SimpleSidebarRows({
|
|
pathname,
|
|
entries,
|
|
}: {
|
|
pathname: string;
|
|
entries: SimpleSidebarEntry[];
|
|
}) {
|
|
return (
|
|
<>
|
|
{entries.map(({ href, label, Icon }) => (
|
|
<SidebarMenuItem key={href}>
|
|
<SidebarMenuButton
|
|
asChild
|
|
isActive={
|
|
href === "/settings/automations"
|
|
? pathname.includes("/automations")
|
|
: pathname === href
|
|
}
|
|
>
|
|
<Link href={href}>
|
|
<Icon className="h-4 w-4" />
|
|
<span>{label}</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
))}
|
|
</>
|
|
);
|
|
}
|
|
|
|
function SecretsSidebarSection({ pathname }: { pathname: string }) {
|
|
return (
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton asChild isActive={pathname === "/settings/general/secrets"}>
|
|
<Link href="/settings/general/secrets">
|
|
<IconKey className="h-4 w-4" />
|
|
<span>Secrets</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
);
|
|
}
|
|
|
|
export function SettingsAppSidebar() {
|
|
const pathname = usePathname();
|
|
const { setOpenMobile, isMobile } = useSidebar();
|
|
const workspaces = useAppStore((state) => state.workspaces.items);
|
|
const executors = useAppStore((state) => state.executors.items);
|
|
const agents = useAppStore((state) => state.settingsAgents.items);
|
|
useAvailableAgents();
|
|
|
|
// Close mobile sidebar when navigating to a new page
|
|
useEffect(() => {
|
|
if (isMobile) {
|
|
setOpenMobile(false);
|
|
}
|
|
}, [pathname, isMobile, setOpenMobile]);
|
|
|
|
return (
|
|
<Sidebar variant="inset">
|
|
<SidebarHeader className="h-16 justify-center">
|
|
<SidebarMenu>
|
|
<SidebarMenuItem>
|
|
<SidebarMenuButton size="lg" asChild>
|
|
<Link href="/">
|
|
<span className="text-2xl font-bold">Kandev</span>
|
|
</Link>
|
|
</SidebarMenuButton>
|
|
</SidebarMenuItem>
|
|
</SidebarMenu>
|
|
</SidebarHeader>
|
|
<SidebarContent className="overflow-hidden">
|
|
<ScrollArea
|
|
className="h-full [&_[data-slot=scroll-area-viewport]>div]:!block [&_[data-slot=scroll-area-viewport]>div]:!min-w-0"
|
|
type="always"
|
|
>
|
|
<SidebarGroup>
|
|
<SidebarGroupLabel>Settings</SidebarGroupLabel>
|
|
<SidebarGroupContent>
|
|
<SidebarMenu>
|
|
<GeneralSidebarSection pathname={pathname} />
|
|
<WorkspacesSidebarSection pathname={pathname} workspaces={workspaces} />
|
|
<IntegrationsSidebarSection pathname={pathname} />
|
|
|
|
<SimpleSidebarRows
|
|
pathname={pathname}
|
|
entries={[
|
|
{ href: "/settings/automations", label: "Automations", Icon: IconBolt },
|
|
]}
|
|
/>
|
|
<AgentsSidebarSection pathname={pathname} agents={agents} />
|
|
<SimpleSidebarRows
|
|
pathname={pathname}
|
|
entries={[
|
|
{ href: "/settings/prompts", label: "Prompts", Icon: IconMessageCircle },
|
|
{ href: "/settings/voice-mode", label: "Voice Mode", Icon: IconMicrophone },
|
|
{ href: "/settings/utility-agents", label: "Utility Agents", Icon: IconWand },
|
|
]}
|
|
/>
|
|
<ExecutorsSidebarSection pathname={pathname} executors={executors} />
|
|
<SecretsSidebarSection pathname={pathname} />
|
|
<SimpleSidebarRows
|
|
pathname={pathname}
|
|
entries={[
|
|
{
|
|
href: "/settings/external-mcp",
|
|
label: "External MCP",
|
|
Icon: IconPlugConnected,
|
|
},
|
|
]}
|
|
/>
|
|
|
|
{/* System */}
|
|
<SystemSidebarSection pathname={pathname} />
|
|
</SidebarMenu>
|
|
</SidebarGroupContent>
|
|
</SidebarGroup>
|
|
</ScrollArea>
|
|
</SidebarContent>
|
|
</Sidebar>
|
|
);
|
|
}
|