Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: reuse code between transcription and reasoning settings

Gabriel Stein2b0b8e5a274d
diff --git a/.claude/settings.json b/.claude/settings.json
new file mode 100644
index 000000000..1f0c65ee0
--- /dev/null
+++ b/.claude/settings.json
@@ -0,0 +1,7 @@
+{
+ "permissions": {
+ "allow": [
+ "Bash(npm run typecheck:*)"
+ ]
+ }
+}
diff --git a/src/components/AIModelSelectorEnhanced.tsx b/src/components/AIModelSelectorEnhanced.tsx
index 19145c8b4..1c7409f5d 100644
--- a/src/components/AIModelSelectorEnhanced.tsx
+++ b/src/components/AIModelSelectorEnhanced.tsx
@@ -1,9 +1,11 @@
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import { Button } from './ui/button';
import { Input } from './ui/input';
-import { Cloud, Lock, Brain, Zap, Globe, Cpu, Download, Check, Wrench } from 'lucide-react';
+import { Cloud, Lock, Download, Check } from 'lucide-react';
import ApiKeyInput from './ui/ApiKeyInput';
import { UnifiedModelPickerCompact } from './UnifiedModelPicker';
+import { ProviderIcon } from './ui/ProviderIcon';
+import { ProviderTabs } from './ui/ProviderTabs';
import { API_ENDPOINTS, buildApiUrl, normalizeBaseUrl } from '../config/constants';
import { REASONING_PROVIDERS } from '../models/ModelRegistry';
import { modelRegistry } from '../models/ModelRegistry';
@@ -76,52 +78,6 @@ interface AIModelSelectorEnhancedProps {
showAlertDialog: (dialog: { title: string; description: string }) => void;
}
-// Provider Icon Component
-const ProviderIcon = ({ provider }: { provider: string }) => {
- const iconClass = "w-5 h-5";
- const [svgError, setSvgError] = React.useState(false);
-
- if (provider === 'custom') {
- return <Wrench className={iconClass} />;
- }
-
- // Default fallback icons for each provider
- const getFallbackIcon = () => {
- switch (provider) {
- // Cloud providers
- case 'openai': return <Brain className={iconClass} />;
- case 'anthropic': return <Zap className={iconClass} />;
- case 'gemini': return <Globe className={iconClass} />;
- case 'groq': return <Zap className={iconClass} />; // Lightning fast inference
- // Local providers
- case 'qwen': return <Brain className={iconClass} />;
- case 'mistral': return <Zap className={iconClass} />;
- case 'llama': return <Cpu className={iconClass} />;
- case 'openai-oss': return <Globe className={iconClass} />;
- case 'custom': return <Wrench className={iconClass} />;
- default: return <Brain className={iconClass} />;
- }
- };
-
- // Try to load SVG if it exists and we haven't had an error
- if (!svgError) {
- return (
- <>
- <img
- src={`/assets/icons/providers/${provider}.svg`}
- alt={`${provider} icon`}
- className={iconClass}
- onError={() => setSvgError(true)}
- style={{ display: svgError ? 'none' : 'block' }}
- />
- {svgError && getFallbackIcon()}
- </>
- );
- }
-
- return getFallbackIcon();
-};
-
export default function AIModelSelectorEnhanced({
useReasoningModel,
setUseReasoningModel,
@@ -335,8 +291,16 @@ export default function AIModelSelectorEnhanced({
return customModelOptions;
}, [isCustomBaseDirty, customModelOptions]);
- const cloudProviders = ['openai', 'anthropic', 'gemini', 'groq', 'custom'];
- const localProviders = modelRegistry.getAllProviders().map((p) => p.id);
+ const cloudProviderIds = ['openai', 'anthropic', 'gemini', 'groq', 'custom'];
+ const cloudProviders = cloudProviderIds.map(id => ({
+ id,
+ name: id === 'custom' ? 'Custom' : REASONING_PROVIDERS[id as keyof typeof REASONING_PROVIDERS]?.name || id,
+ }));
+ const localProviderIds = modelRegistry.getAllProviders().map((p) => p.id);
+ const localProviders = localProviderIds.map(id => {
+ const provider = modelRegistry.getProvider(id);
+ return { id, name: provider?.name || id };
+ });
const openaiModelOptions = useMemo<CloudModelOption[]>(() => {
const iconPath = getProviderIconPath('openai');
@@ -628,34 +592,12 @@ export default function AIModelSelectorEnhanced({
<div className="space-y-4">
{/* Cloud Provider Tabs */}
<div className="border border-gray-200 rounded-xl overflow-hidden">
- <div className="flex bg-gray-50 border-b border-gray-200">
- {cloudProviders.map((provider) => {
- const isSelected = selectedCloudProvider === provider;
- const color = getProviderColor(provider);
- const providerDisplayName =
- provider === 'custom'
- ? 'Custom'
- : REASONING_PROVIDERS[provider as keyof typeof REASONING_PROVIDERS]?.name || provider;
- return (
- <button
- key={provider}
- onClick={() => handleCloudProviderChange(provider)}
- className={`flex-1 flex items-center justify-center gap-2 px-4 py-3 font-medium transition-all ${
- isSelected
- ? `text-${color}-700 border-b-2`
- : 'text-gray-600 hover:bg-gray-100'
- }`}
- style={isSelected ? {
- borderBottomColor: `rgb(99 102 241)`,
- backgroundColor: 'rgb(238 242 255)'
- } : {}}
- >
- <ProviderIcon provider={provider} />
- <span>{providerDisplayName}</span>
- </button>
- );
- })}
- </div>
+ <ProviderTabs
+ providers={cloudProviders}
+ selectedId={selectedCloudProvider}
+ onSelect={handleCloudProviderChange}
+ colorScheme="indigo"
+ />
<div className="p-4">
{/* Use UnifiedModelPickerCompact for cloud models */}
@@ -854,30 +796,13 @@ export default function AIModelSelectorEnhanced({
<div className="space-y-4">
{/* Local Provider Tabs */}
<div className="border border-gray-200 rounded-xl overflow-hidden">
- <div className="flex bg-gray-50 border-b border-gray-200 overflow-x-auto">
- {localProviders.map((provider) => {
- const isSelected = selectedLocalProvider === provider;
- const providerData = modelRegistry.getProvider(provider);
- return (
- <button
- key={provider}
- onClick={() => handleLocalProviderChange(provider)}
- className={`flex items-center justify-center gap-2 px-4 py-3 font-medium transition-all whitespace-nowrap ${
- isSelected
- ? 'text-purple-700 border-b-2'
- : 'text-gray-600 hover:bg-gray-100'
- }`}
- style={isSelected ? {
- borderBottomColor: 'rgb(147 51 234)',
- backgroundColor: 'rgb(250 245 255)'
- } : {}}
- >
- <ProviderIcon provider={provider} />
- <span>{providerData?.name}</span>
- </button>
- );
- })}
- </div>
+ <ProviderTabs
+ providers={localProviders}
+ selectedId={selectedLocalProvider}
+ onSelect={handleLocalProviderChange}
+ colorScheme="purple"
+ scrollable
+ />
{/* Local Model List with Download */}
<div className="p-4">
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index 6a8bdc7d7..19201a433 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -6,13 +6,14 @@ import WhisperModelPicker from "./WhisperModelPicker";
import ProcessingModeSelector from "./ui/ProcessingModeSelector";
import ApiKeyInput from "./ui/ApiKeyInput";
import { ConfirmDialog, AlertDialog } from "./ui/dialog";
+import { ProviderTabs } from "./ui/ProviderTabs";
import { useSettings } from "../hooks/useSettings";
import { useDialogs } from "../hooks/useDialogs";
import { useAgentName } from "../utils/agentName";
import { useWhisper } from "../hooks/useWhisper";
import { usePermissions } from "../hooks/usePermissions";
import { useClipboard } from "../hooks/useClipboard";
-import { REASONING_PROVIDERS } from "../models/ModelRegistry";
+import { REASONING_PROVIDERS, getTranscriptionProviders, getTranscriptionModels } from "../models/ModelRegistry";
import { formatHotkeyLabel } from "../utils/hotkeys";
import LanguageSelector from "./ui/LanguageSelector";
import PromptStudio from "./ui/PromptStudio";
@@ -21,6 +22,14 @@ import AIModelSelectorEnhanced from "./AIModelSelectorEnhanced";
import type { UpdateInfoResult } from "../types/electron";
const InteractiveKeyboard = React.lazy(() => import("./ui/Keyboard"));
+// Custom transcription provider constant
+const CUSTOM_TRANSCRIPTION_PROVIDER = {
+ id: 'custom',
+ name: 'Custom',
+ baseUrl: '',
+ models: []
+} as const;
+
export type SettingsSectionType =
| "general"
| "transcription"
@@ -52,6 +61,8 @@ export default function SettingsPage({
allowLocalFallback,
fallbackWhisperModel,
preferredLanguage,
+ cloudTranscriptionProvider,
+ cloudTranscriptionModel,
cloudTranscriptionBaseUrl,
cloudReasoningBaseUrl,
useReasoningModel,
@@ -68,6 +79,8 @@ export default function SettingsPage({
setAllowLocalFallback,
setFallbackWhisperModel,
setPreferredLanguage,
+ setCloudTranscriptionProvider,
+ setCloudTranscriptionModel,
setCloudTranscriptionBaseUrl,
setCloudReasoningBaseUrl,
setUseReasoningModel,
@@ -956,50 +969,145 @@ export default function SettingsPage({
</div>
{!useLocalWhisper && (
- <div className="space-y-4 p-4 bg-blue-50 border border-blue-200 rounded-xl">
- <h4 className="font-medium text-blue-900">OpenAI-Compatible Cloud Setup</h4>
- <ApiKeyInput
- apiKey={openaiApiKey}
- setApiKey={setOpenaiApiKey}
- helpText={
- <>
- Supports OpenAI or compatible endpoints.{" "}
- <a
- href="https://platform.openai.com"
- target="_blank"
- rel="noopener noreferrer"
- className="text-blue-600 underline"
- >
- Get an API key
- </a>
- .
- </>
- }
- />
- <div className="space-y-2">
- <label className="block text-sm font-medium text-blue-900">
- Custom Base URL (optional)
- </label>
- <Input
- value={cloudTranscriptionBaseUrl}
- onChange={(event) => setCloudTranscriptionBaseUrl(event.target.value)}
- placeholder="https://api.openai.com/v1"
- className="text-sm"
+ <div className="space-y-4">
+ <h4 className="font-medium text-gray-900">Cloud Transcription Provider</h4>
+
+ {/* Provider Tabs */}
+ <div className="border border-gray-200 rounded-xl overflow-hidden">
+ <ProviderTabs
+ providers={[...getTranscriptionProviders(), CUSTOM_TRANSCRIPTION_PROVIDER]}
+ selectedId={cloudTranscriptionProvider}
+ onSelect={(providerId) => {
+ setCloudTranscriptionProvider(providerId);
+ if (providerId !== 'custom') {
+ const provider = getTranscriptionProviders().find(p => p.id === providerId);
+ const models = getTranscriptionModels(providerId);
+ setCloudTranscriptionModel(models[0]?.id || '');
+ if (provider) {
+ setCloudTranscriptionBaseUrl(provider.baseUrl);
+ }
+ }
+ }}
+ colorScheme="indigo"
/>
- <div className="flex items-center gap-2">
- <Button
- type="button"
- variant="outline"
- size="sm"
- onClick={() => setCloudTranscriptionBaseUrl(API_ENDPOINTS.TRANSCRIPTION_BASE)}
- >
- Reset to Default
- </Button>
+
+ <div className="p-4">
+ {cloudTranscriptionProvider === 'custom' ? (
+ <>
+ {/* Custom Endpoint Settings */}
+ <div className="space-y-3">
+ <h4 className="font-medium text-gray-900">Endpoint Settings</h4>
+ <Input
+ value={cloudTranscriptionBaseUrl}
+ onChange={(event) => setCloudTranscriptionBaseUrl(event.target.value)}
+ placeholder="https://api.openai.com/v1"
+ className="text-sm"
+ />
+ <div className="flex flex-wrap gap-2">
+ <Button
+ type="button"
+ size="sm"
+ variant="outline"
+ onClick={() => {
+ setCloudTranscriptionBaseUrl(API_ENDPOINTS.TRANSCRIPTION_BASE);
+ }}
+ >
+ Reset to Default
+ </Button>
+ </div>
+ <p className="text-xs text-gray-600">
+ Use a custom OpenAI-compatible endpoint for transcription.
+ </p>
+ </div>
+
+ <div className="space-y-3 pt-4 border-t border-gray-200">
+ <h4 className="font-medium text-gray-900">Authentication</h4>
+ <ApiKeyInput
+ apiKey={openaiApiKey}
+ setApiKey={setOpenaiApiKey}
+ helpText="Optional. Added as a Bearer token for your custom endpoint."
+ />
+ </div>
+
+ <div className="space-y-3 pt-4 border-t border-gray-200">
+ <h4 className="font-medium text-gray-900">Model Name</h4>
+ <Input
+ value={cloudTranscriptionModel}
+ onChange={(event) => setCloudTranscriptionModel(event.target.value)}
+ placeholder="whisper-1"
+ className="text-sm"
+ />
+ <p className="text-xs text-gray-600">
+ Enter the model name supported by your custom endpoint.
+ </p>
+ </div>
+ </>
+ ) : (
+ <>
+ {/* Model Selection */}
+ <div className="space-y-3">
+ <h4 className="text-sm font-medium text-gray-700">Select Model</h4>
+ <div className="space-y-2">
+ {getTranscriptionModels(cloudTranscriptionProvider).map((model) => {
+ const isSelected = cloudTranscriptionModel === model.id;
+ return (
+ <button
+ key={model.id}
+ onClick={() => setCloudTranscriptionModel(model.id)}
+ className={`w-full p-3 rounded-lg border-2 transition-all text-left ${
+ isSelected
+ ? 'border-indigo-500 bg-indigo-50'
+ : 'border-gray-200 bg-white hover:border-gray-300'
+ }`}
+ >
+ <div className="font-medium text-gray-900">{model.name}</div>
+ <div className="text-xs text-gray-600 mt-1">{model.description}</div>
+ </button>
+ );
+ })}
+ </div>
+ </div>
+
+ {/* API Key Configuration */}
+ <div className="mt-4 pt-4 border-t border-gray-200">
+ <div className="space-y-3">
+ <h4 className="font-medium text-gray-900">API Configuration</h4>
+ <ApiKeyInput
+ apiKey={cloudTranscriptionProvider === "groq" ? groqApiKey : openaiApiKey}
+ setApiKey={cloudTranscriptionProvider === "groq" ? setGroqApiKey : setOpenaiApiKey}
+ helpText={
+ cloudTranscriptionProvider === "groq" ? (
+ <>
+ Need an API key?{" "}
+ <a
+ href="https://console.groq.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ console.groq.com
+ </a>
+ </>
+ ) : (
+ <>
+ Need an API key?{" "}
+ <a
+ href="https://platform.openai.com"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-blue-600 underline"
+ >
+ platform.openai.com
+ </a>
+ </>
+ )
+ }
+ />
+ </div>
+ </div>
+ </>
+ )}
</div>
- <p className="text-xs text-blue-800">
- Requests for cloud transcription use this OpenAI-compatible base URL. Leave empty to fall back to
- <code className="ml-1">{API_ENDPOINTS.TRANSCRIPTION_BASE}</code>.
- </p>
</div>
</div>
)}
diff --git a/src/components/ui/ProviderIcon.tsx b/src/components/ui/ProviderIcon.tsx
new file mode 100644
index 000000000..bb4201506
--- /dev/null
+++ b/src/components/ui/ProviderIcon.tsx
@@ -0,0 +1,46 @@
+import React, { useState } from 'react';
+import { Brain, Zap, Globe, Cpu, Wrench } from 'lucide-react';
+
+interface ProviderIconProps {
+ provider: string;
+ className?: string;
+}
+
+export function ProviderIcon({ provider, className = "w-5 h-5" }: ProviderIconProps) {
+ const [svgError, setSvgError] = useState(false);
+
+ if (provider === 'custom') {
+ return <Wrench className={className} />;
+ }
+
+ const getFallbackIcon = () => {
+ switch (provider) {
+ // Cloud providers
+ case 'openai': return <Brain className={className} />;
+ case 'anthropic': return <Zap className={className} />;
+ case 'gemini': return <Globe className={className} />;
+ case 'groq': return <Zap className={className} />;
+ // Local providers
+ case 'qwen': return <Brain className={className} />;
+ case 'mistral': return <Zap className={className} />;
+ case 'llama': return <Cpu className={className} />;
+ case 'openai-oss': return <Globe className={className} />;
+ default: return <Brain className={className} />;
+ }
+ };
+
+ if (svgError) {
+ return getFallbackIcon();
+ }
+
+ return (
+ <img
+ src={`/assets/icons/providers/${provider}.svg`}
+ alt={`${provider} icon`}
+ className={className}
+ onError={() => setSvgError(true)}
+ />
+ );
+}
+
+export default ProviderIcon;
diff --git a/src/components/ui/ProviderTabs.tsx b/src/components/ui/ProviderTabs.tsx
new file mode 100644
index 000000000..a02d935a5
--- /dev/null
+++ b/src/components/ui/ProviderTabs.tsx
@@ -0,0 +1,76 @@
+import React, { ReactNode } from 'react';
+import { ProviderIcon } from './ProviderIcon';
+
+export interface ProviderTabItem {
+ id: string;
+ name: string;
+}
+
+type ColorScheme = 'indigo' | 'purple' | 'dynamic';
+
+interface ProviderTabsProps {
+ providers: ProviderTabItem[];
+ selectedId: string;
+ onSelect: (id: string) => void;
+ renderIcon?: (providerId: string) => ReactNode;
+ colorScheme?: ColorScheme;
+ /** Allow horizontal scrolling for many providers */
+ scrollable?: boolean;
+}
+
+const COLOR_CONFIG: Record<Exclude<ColorScheme, 'dynamic'>, { text: string; border: string; bg: string }> = {
+ indigo: {
+ text: 'text-indigo-700',
+ border: 'rgb(99 102 241)',
+ bg: 'rgb(238 242 255)',
+ },
+ purple: {
+ text: 'text-purple-700',
+ border: 'rgb(147 51 234)',
+ bg: 'rgb(250 245 255)',
+ },
+};
+
+export function ProviderTabs({
+ providers,
+ selectedId,
+ onSelect,
+ renderIcon,
+ colorScheme = 'indigo',
+ scrollable = false,
+}: ProviderTabsProps) {
+ const colors = colorScheme !== 'dynamic' ? COLOR_CONFIG[colorScheme] : null;
+
+ return (
+ <div className={`flex bg-gray-50 border-b border-gray-200 ${scrollable ? 'overflow-x-auto' : ''}`}>
+ {providers.map((provider) => {
+ const isSelected = selectedId === provider.id;
+
+ // Get styles based on color scheme
+ const selectedStyles = colors
+ ? { borderBottomColor: colors.border, backgroundColor: colors.bg }
+ : { borderBottomColor: 'rgb(99 102 241)', backgroundColor: 'rgb(238 242 255)' };
+
+ const textClass = isSelected
+ ? (colors?.text || 'text-indigo-700')
+ : 'text-gray-600';
+
+ return (
+ <button
+ key={provider.id}
+ onClick={() => onSelect(provider.id)}
+ className={`flex-1 flex items-center justify-center gap-2 px-4 py-3 font-medium transition-all ${
+ scrollable ? 'whitespace-nowrap' : ''
+ } ${textClass} ${isSelected ? 'border-b-2' : 'hover:bg-gray-100'}`}
+ style={isSelected ? selectedStyles : undefined}
+ >
+ {renderIcon ? renderIcon(provider.id) : <ProviderIcon provider={provider.id} />}
+ <span>{provider.name}</span>
+ </button>
+ );
+ })}
+ </div>
+ );
+}
+
+export default ProviderTabs;
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index 9b41c7cde..61b24ae30 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -5,6 +5,17 @@ import logger from "../utils/logger";
const SHORT_CLIP_DURATION_SECONDS = 2.5;
const REASONING_CACHE_TTL = 30000; // 30 seconds
+const PLACEHOLDER_KEYS = {
+ openai: "your_openai_api_key_here",
+ groq: "your_groq_api_key_here",
+};
+
+const isValidApiKey = (key, provider = "openai") => {
+ if (!key || key.trim() === "") return false;
+ const placeholder = PLACEHOLDER_KEYS[provider] || PLACEHOLDER_KEYS.openai;
+ return key !== placeholder;
+};
+
class AudioManager {
constructor() {
@@ -16,7 +27,10 @@ class AudioManager {
this.onError = null;
this.onTranscriptionComplete = null;
this.cachedApiKey = null;
+ this.cachedApiKeyProvider = null;
this.cachedTranscriptionEndpoint = null;
+ this.cachedEndpointProvider = null;
+ this.cachedEndpointBaseUrl = null;
this.recordingStartTime = null;
this.reasoningAvailabilityCache = { value: false, expiresAt: 0 };
this.cachedReasoningPreference = null;
@@ -40,6 +54,7 @@ class AudioManager {
this.mediaRecorder = new MediaRecorder(stream);
this.audioChunks = [];
this.recordingStartTime = Date.now();
+ this.recordingMimeType = this.mediaRecorder.mimeType || 'audio/webm';
this.mediaRecorder.ondataavailable = (event) => {
this.audioChunks.push(event.data);
@@ -50,7 +65,7 @@ class AudioManager {
this.isProcessing = true;
this.onStateChange?.({ isRecording: false, isProcessing: true });
- const audioBlob = new Blob(this.audioChunks, { type: "audio/wav" });
+ const audioBlob = new Blob(this.audioChunks, { type: this.recordingMimeType });
if (audioBlob.size === 0) {
}
@@ -181,30 +196,55 @@ class AudioManager {
}
async getAPIKey() {
- if (this.cachedApiKey) {
+ // Get the current transcription provider
+ const provider = typeof localStorage !== "undefined"
+ ? localStorage.getItem("cloudTranscriptionProvider") || "openai"
+ : "openai";
+
+ // Check cache (invalidate if provider changed)
+ if (this.cachedApiKey !== null && this.cachedApiKeyProvider === provider) {
return this.cachedApiKey;
}
- let apiKey = await window.electronAPI.getOpenAIKey();
- if (
- !apiKey ||
- apiKey.trim() === "" ||
- apiKey === "your_openai_api_key_here"
- ) {
- apiKey = localStorage.getItem("openaiApiKey");
- }
+ let apiKey = null;
- if (
- !apiKey ||
- apiKey.trim() === "" ||
- apiKey === "your_openai_api_key_here"
- ) {
- throw new Error(
- "OpenAI API key not found. Please set your API key in the .env file or Control Panel."
- );
+ if (provider === "custom") {
+ // Custom endpoints: API key is optional
+ // Try OpenAI key first as it's commonly used for compatible endpoints
+ apiKey = await window.electronAPI.getOpenAIKey();
+ if (!isValidApiKey(apiKey, "openai")) {
+ apiKey = localStorage.getItem("openaiApiKey");
+ }
+ // For custom, we allow null/empty - the endpoint may not require auth
+ if (!isValidApiKey(apiKey, "openai")) {
+ apiKey = null;
+ }
+ } else if (provider === "groq") {
+ // Try to get Groq API key
+ apiKey = await window.electronAPI.getGroqKey?.();
+ if (!isValidApiKey(apiKey, "groq")) {
+ apiKey = localStorage.getItem("groqApiKey");
+ }
+ if (!isValidApiKey(apiKey, "groq")) {
+ throw new Error(
+ "Groq API key not found. Please set your API key in the Control Panel."
+ );
+ }
+ } else {
+ // Default to OpenAI
+ apiKey = await window.electronAPI.getOpenAIKey();
+ if (!isValidApiKey(apiKey, "openai")) {
+ apiKey = localStorage.getItem("openaiApiKey");
+ }
+ if (!isValidApiKey(apiKey, "openai")) {
+ throw new Error(
+ "OpenAI API key not found. Please set your API key in the .env file or Control Panel."
+ );
+ }
}
this.cachedApiKey = apiKey;
+ this.cachedApiKeyProvider = provider;
return apiKey;
}
@@ -462,6 +502,141 @@ class AudioManager {
return normalizedText;
}
+ shouldStreamTranscription(model, provider) {
+ if (provider !== "openai") {
+ return false;
+ }
+ const normalized = typeof model === "string" ? model.trim() : "";
+ if (!normalized || normalized === "whisper-1") {
+ return false;
+ }
+ if (normalized === "gpt-4o-transcribe" || normalized === "gpt-4o-transcribe-diarize") {
+ return true;
+ }
+ return normalized.startsWith("gpt-4o-mini-transcribe");
+ }
+
+ async readTranscriptionStream(response) {
+ const reader = response.body?.getReader();
+ if (!reader) {
+ logger.error("Streaming response body not available", {}, "transcription");
+ throw new Error("Streaming response body not available");
+ }
+
+ const decoder = new TextDecoder("utf-8");
+ let buffer = "";
+ let collectedText = "";
+ let finalText = null;
+ let eventCount = 0;
+ const eventTypes = {};
+
+ const handleEvent = (payload) => {
+ if (!payload || typeof payload !== "object") {
+ return;
+ }
+ eventCount++;
+ const eventType = payload.type || "unknown";
+ eventTypes[eventType] = (eventTypes[eventType] || 0) + 1;
+
+ logger.debug("Stream event received", {
+ type: eventType,
+ eventNumber: eventCount,
+ payloadKeys: Object.keys(payload),
+ }, "transcription");
+
+ if (payload.type === "transcript.text.delta" && typeof payload.delta === "string") {
+ collectedText += payload.delta;
+ return;
+ }
+ if (payload.type === "transcript.text.segment" && typeof payload.text === "string") {
+ collectedText += payload.text;
+ return;
+ }
+ if (payload.type === "transcript.text.done" && typeof payload.text === "string") {
+ finalText = payload.text;
+ logger.debug("Final transcript received", {
+ textLength: payload.text.length,
+ }, "transcription");
+ }
+ };
+
+ logger.debug("Starting to read transcription stream", {}, "transcription");
+
+ while (true) {
+ const { value, done } = await reader.read();
+ if (done) {
+ logger.debug("Stream reading complete", {
+ eventCount,
+ eventTypes,
+ collectedTextLength: collectedText.length,
+ hasFinalText: finalText !== null,
+ }, "transcription");
+ break;
+ }
+ const chunk = decoder.decode(value, { stream: true });
+ buffer += chunk;
+
+ // Log first chunk to see format
+ if (eventCount === 0 && chunk.length > 0) {
+ logger.debug("First stream chunk received", {
+ chunkLength: chunk.length,
+ chunkPreview: chunk.substring(0, 500),
+ }, "transcription");
+ }
+
+ // Process complete lines from the buffer
+ // Each SSE event is "data: <json>\n" followed by empty line
+ const lines = buffer.split('\n');
+ buffer = '';
+
+ for (const line of lines) {
+ const trimmedLine = line.trim();
+
+ // Skip empty lines
+ if (!trimmedLine) {
+ continue;
+ }
+
+ // Extract data from "data: " prefix
+ let data = '';
+ if (trimmedLine.startsWith('data: ')) {
+ data = trimmedLine.slice(6);
+ } else if (trimmedLine.startsWith('data:')) {
+ data = trimmedLine.slice(5).trim();
+ } else {
+ // Not a data line, could be leftover - keep in buffer
+ buffer += line + '\n';
+ continue;
+ }
+
+ // Handle [DONE] marker
+ if (data === '[DONE]') {
+ finalText = finalText ?? collectedText;
+ continue;
+ }
+
+ // Try to parse JSON
+ try {
+ const parsed = JSON.parse(data);
+ handleEvent(parsed);
+ } catch (error) {
+ // Incomplete JSON - put back in buffer for next iteration
+ buffer += line + '\n';
+ }
+ }
+ }
+
+ const result = finalText ?? collectedText;
+ logger.debug("Stream processing complete", {
+ resultLength: result.length,
+ usedFinalText: finalText !== null,
+ eventCount,
+ eventTypes,
+ }, "transcription");
+
+ return result;
+ }
+
async processWithOpenAIAPI(audioBlob, metadata = {}) {
const language = localStorage.getItem("preferredLanguage");
const allowLocalFallback =
@@ -476,46 +651,169 @@ class AudioManager {
durationSeconds > 0 &&
durationSeconds < SHORT_CLIP_DURATION_SECONDS;
- const shouldOptimize =
+ const model = this.getTranscriptionModel();
+ const provider = localStorage.getItem("cloudTranscriptionProvider") || "openai";
+
+ logger.debug("Transcription request starting", {
+ provider,
+ model,
+ blobSize: audioBlob.size,
+ blobType: audioBlob.type,
+ durationSeconds,
+ language,
+ }, "transcription");
+
+ // gpt-4o-transcribe models don't support WAV format - they need webm, mp3, mp4, etc.
+ // Only use WAV optimization for whisper-1 and groq models
+ const is4oModel = model.includes('gpt-4o');
+ const shouldOptimize = !is4oModel &&
!shouldSkipOptimizationForDuration && audioBlob.size > 1024 * 1024;
+ logger.debug("Audio optimization decision", {
+ is4oModel,
+ shouldOptimize,
+ shouldSkipOptimizationForDuration,
+ }, "transcription");
+
const [apiKey, optimizedAudio] = await Promise.all([
this.getAPIKey(),
shouldOptimize ? this.optimizeAudio(audioBlob) : Promise.resolve(audioBlob),
]);
const formData = new FormData();
- formData.append("file", optimizedAudio, "audio.wav");
- formData.append("model", this.getTranscriptionModel());
+ // Determine the correct file extension based on the blob type
+ const mimeType = optimizedAudio.type || 'audio/webm';
+ const extension = mimeType.includes('webm') ? 'webm'
+ : mimeType.includes('ogg') ? 'ogg'
+ : mimeType.includes('mp4') ? 'mp4'
+ : mimeType.includes('mpeg') ? 'mp3'
+ : mimeType.includes('wav') ? 'wav'
+ : 'webm';
+
+ logger.debug("FormData preparation", {
+ mimeType,
+ extension,
+ optimizedSize: optimizedAudio.size,
+ hasApiKey: !!apiKey,
+ }, "transcription");
+
+ formData.append("file", optimizedAudio, `audio.${extension}`);
+ formData.append("model", model);
if (language && language !== "auto") {
formData.append("language", language);
}
+ const shouldStream = this.shouldStreamTranscription(model, provider);
+ if (shouldStream) {
+ formData.append("stream", "true");
+ }
+
+ const endpoint = this.getTranscriptionEndpoint();
+
+ logger.debug("Making transcription API request", {
+ endpoint,
+ shouldStream,
+ model,
+ }, "transcription");
+
+ // Build headers - only include Authorization if we have an API key
+ const headers = {};
+ if (apiKey) {
+ headers.Authorization = `Bearer ${apiKey}`;
+ }
+
const response = await fetch(
- this.getTranscriptionEndpoint(),
+ endpoint,
{
method: "POST",
- headers: {
- Authorization: `Bearer ${apiKey}`,
- },
+ headers,
body: formData,
}
);
+ const responseContentType = response.headers.get("content-type") || "";
+
+ logger.debug("Transcription API response received", {
+ status: response.status,
+ statusText: response.statusText,
+ contentType: responseContentType,
+ ok: response.ok,
+ }, "transcription");
+
if (!response.ok) {
const errorText = await response.text();
+ logger.error("Transcription API error response", {
+ status: response.status,
+ errorText,
+ }, "transcription");
throw new Error(`API Error: ${response.status} ${errorText}`);
}
- const result = await response.json();
+ let result;
+ const contentType = responseContentType;
+
+ if (shouldStream && contentType.includes("text/event-stream")) {
+ logger.debug("Processing streaming response", { contentType }, "transcription");
+ const streamedText = await this.readTranscriptionStream(response);
+ result = { text: streamedText };
+ logger.debug("Streaming response parsed", {
+ hasText: !!streamedText,
+ textLength: streamedText?.length
+ }, "transcription");
+ } else {
+ const rawText = await response.text();
+ logger.debug("Raw API response body", {
+ rawText: rawText.substring(0, 1000),
+ fullLength: rawText.length,
+ }, "transcription");
+
+ try {
+ result = JSON.parse(rawText);
+ } catch (parseError) {
+ logger.error("Failed to parse JSON response", {
+ parseError: parseError.message,
+ rawText: rawText.substring(0, 500),
+ }, "transcription");
+ throw new Error(`Failed to parse API response: ${parseError.message}`);
+ }
+
+ logger.debug("Parsed transcription result", {
+ hasText: !!result.text,
+ textLength: result.text?.length,
+ resultKeys: Object.keys(result),
+ fullResult: result,
+ }, "transcription");
+ }
- if (result.text) {
+ // Check for text - handle both empty string and missing field
+ if (result.text && result.text.trim().length > 0) {
const text = await this.processTranscription(result.text, "openai");
const source = await this.isReasoningAvailable() ? "openai-reasoned" : "openai";
+ logger.debug("Transcription successful", {
+ originalLength: result.text.length,
+ processedLength: text.length,
+ source,
+ }, "transcription");
return { success: true, text, source };
} else {
- throw new Error("No text transcribed");
+ // Log at info level so it shows without debug mode
+ logger.info("Transcription returned empty - check audio input", {
+ model,
+ provider,
+ endpoint,
+ blobSize: audioBlob.size,
+ blobType: audioBlob.type,
+ mimeType,
+ extension,
+ resultText: result.text,
+ resultKeys: Object.keys(result),
+ }, "transcription");
+ logger.error("No text in transcription result", {
+ result,
+ resultKeys: Object.keys(result),
+ }, "transcription");
+ throw new Error("No text transcribed - audio may be too short, silent, or in an unsupported format");
}
} catch (error) {
const isOpenAIMode = localStorage.getItem("useLocalWhisper") !== "true";
@@ -553,54 +851,82 @@ class AudioManager {
getTranscriptionModel() {
try {
- // Check if a custom model is configured
- const customModel = typeof localStorage !== "undefined"
+ const provider = typeof localStorage !== "undefined"
+ ? localStorage.getItem("cloudTranscriptionProvider") || "openai"
+ : "openai";
+
+ const model = typeof localStorage !== "undefined"
? localStorage.getItem("cloudTranscriptionModel") || ""
: "";
- if (customModel.trim()) {
- return customModel.trim();
+ const trimmedModel = model.trim();
+
+ // For custom provider, use whatever model is set (or fallback to whisper-1)
+ if (provider === "custom") {
+ return trimmedModel || "whisper-1";
}
- // Auto-detect model based on endpoint
- const endpoint = typeof localStorage !== "undefined"
- ? localStorage.getItem("cloudTranscriptionBaseUrl") || ""
- : "";
+ // Validate model matches provider to handle settings migration
+ if (trimmedModel) {
+ const isGroqModel = trimmedModel.startsWith("whisper-large-v3");
+ const isOpenAIModel = trimmedModel.startsWith("gpt-4o") || trimmedModel === "whisper-1";
- if (endpoint.includes("groq.com")) {
- return "whisper-large-v3-turbo"; // Groq's fast model
+ if (provider === "groq" && isGroqModel) {
+ return trimmedModel;
+ }
+ if (provider === "openai" && isOpenAIModel) {
+ return trimmedModel;
+ }
+ // Model doesn't match provider - fall through to default
}
- // Default to OpenAI's model
- return "whisper-1";
+ // Return provider-appropriate default
+ return provider === "groq" ? "whisper-large-v3-turbo" : "gpt-4o-mini-transcribe";
} catch (error) {
- return "whisper-1";
+ return "gpt-4o-mini-transcribe";
}
}
getTranscriptionEndpoint() {
+ // Get current provider and base URL to check if cache is valid
+ const currentProvider = typeof localStorage !== "undefined"
+ ? localStorage.getItem("cloudTranscriptionProvider") || "openai"
+ : "openai";
+ const currentBaseUrl = typeof localStorage !== "undefined"
+ ? localStorage.getItem("cloudTranscriptionBaseUrl") || ""
+ : "";
+
+ // Invalidate cache if provider or base URL changed
+ if (this.cachedTranscriptionEndpoint && (
+ this.cachedEndpointProvider !== currentProvider ||
+ this.cachedEndpointBaseUrl !== currentBaseUrl
+ )) {
+ this.cachedTranscriptionEndpoint = null;
+ }
+
if (this.cachedTranscriptionEndpoint) {
return this.cachedTranscriptionEndpoint;
}
try {
- const stored = typeof localStorage !== "undefined"
- ? localStorage.getItem("cloudTranscriptionBaseUrl") || ""
- : "";
- const trimmed = stored.trim();
- const base = trimmed ? trimmed : API_ENDPOINTS.TRANSCRIPTION_BASE;
+ const base = currentBaseUrl.trim() || API_ENDPOINTS.TRANSCRIPTION_BASE;
const normalizedBase = normalizeBaseUrl(base);
+ const cacheResult = (endpoint) => {
+ this.cachedTranscriptionEndpoint = endpoint;
+ this.cachedEndpointProvider = currentProvider;
+ this.cachedEndpointBaseUrl = currentBaseUrl;
+ return endpoint;
+ };
+
if (!normalizedBase) {
- this.cachedTranscriptionEndpoint = API_ENDPOINTS.TRANSCRIPTION;
- return API_ENDPOINTS.TRANSCRIPTION;
+ return cacheResult(API_ENDPOINTS.TRANSCRIPTION);
}
const isLocalhost = normalizedBase.includes('://localhost') || normalizedBase.includes('://127.0.0.1');
if (!normalizedBase.startsWith('https://') && !isLocalhost) {
console.warn('Non-HTTPS endpoint rejected for security. Using default.');
- this.cachedTranscriptionEndpoint = API_ENDPOINTS.TRANSCRIPTION;
- return API_ENDPOINTS.TRANSCRIPTION;
+ return cacheResult(API_ENDPOINTS.TRANSCRIPTION);
}
let endpoint;
@@ -610,11 +936,12 @@ class AudioManager {
endpoint = buildApiUrl(normalizedBase, '/audio/transcriptions');
}
- this.cachedTranscriptionEndpoint = endpoint;
- return endpoint;
+ return cacheResult(endpoint);
} catch (error) {
console.warn('Failed to resolve transcription endpoint:', error);
this.cachedTranscriptionEndpoint = API_ENDPOINTS.TRANSCRIPTION;
+ this.cachedEndpointProvider = currentProvider;
+ this.cachedEndpointBaseUrl = currentBaseUrl;
return API_ENDPOINTS.TRANSCRIPTION;
}
}
diff --git a/src/helpers/windowManager.js b/src/helpers/windowManager.js
index be52d70dc..35d490869 100644
--- a/src/helpers/windowManager.js
+++ b/src/helpers/windowManager.js
@@ -90,7 +90,6 @@ class WindowManager {
} else {
this.mainWindow.setIgnoreMouseEvents(true, { forward: true });
}
-
this.isMainWindowInteractive = shouldCapture;
}
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index 4466d8531..17de32342 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -10,6 +10,8 @@ export interface TranscriptionSettings {
allowLocalFallback: boolean;
fallbackWhisperModel: string;
preferredLanguage: string;
+ cloudTranscriptionProvider: string;
+ cloudTranscriptionModel: string;
cloudTranscriptionBaseUrl?: string;
}
@@ -86,6 +88,24 @@ export function useSettings() {
}
);
+ const [cloudTranscriptionProvider, setCloudTranscriptionProvider] = useLocalStorage(
+ "cloudTranscriptionProvider",
+ "openai",
+ {
+ serialize: String,
+ deserialize: String,
+ }
+ );
+
+ const [cloudTranscriptionModel, setCloudTranscriptionModel] = useLocalStorage(
+ "cloudTranscriptionModel",
+ "gpt-4o-mini-transcribe",
+ {
+ serialize: String,
+ deserialize: String,
+ }
+ );
+
const [cloudTranscriptionBaseUrl, setCloudTranscriptionBaseUrl] = useLocalStorage(
"cloudTranscriptionBaseUrl",
API_ENDPOINTS.TRANSCRIPTION_BASE,
@@ -180,6 +200,10 @@ export function useSettings() {
setFallbackWhisperModel(settings.fallbackWhisperModel);
if (settings.preferredLanguage !== undefined)
setPreferredLanguage(settings.preferredLanguage);
+ if (settings.cloudTranscriptionProvider !== undefined)
+ setCloudTranscriptionProvider(settings.cloudTranscriptionProvider);
+ if (settings.cloudTranscriptionModel !== undefined)
+ setCloudTranscriptionModel(settings.cloudTranscriptionModel);
if (settings.cloudTranscriptionBaseUrl !== undefined)
setCloudTranscriptionBaseUrl(settings.cloudTranscriptionBaseUrl);
},
@@ -190,6 +214,8 @@ export function useSettings() {
setAllowLocalFallback,
setFallbackWhisperModel,
setPreferredLanguage,
+ setCloudTranscriptionProvider,
+ setCloudTranscriptionModel,
setCloudTranscriptionBaseUrl,
]
);
@@ -227,6 +253,8 @@ export function useSettings() {
allowLocalFallback,
fallbackWhisperModel,
preferredLanguage,
+ cloudTranscriptionProvider,
+ cloudTranscriptionModel,
cloudTranscriptionBaseUrl,
cloudReasoningBaseUrl,
useReasoningModel,
@@ -243,6 +271,8 @@ export function useSettings() {
setAllowLocalFallback,
setFallbackWhisperModel,
setPreferredLanguage,
+ setCloudTranscriptionProvider,
+ setCloudTranscriptionModel,
setCloudTranscriptionBaseUrl,
setCloudReasoningBaseUrl,
setUseReasoningModel,
diff --git a/src/models/ModelRegistry.ts b/src/models/ModelRegistry.ts
index 23db4b698..670d44270 100644
--- a/src/models/ModelRegistry.ts
+++ b/src/models/ModelRegistry.ts
@@ -1,4 +1,4 @@
-import modelData from './modelRegistryData.json';
+import modelDataRaw from './modelRegistryData.json';
// Types for local models (downloadable GGUF files)
export interface ModelDefinition {
@@ -44,6 +44,29 @@ export interface CloudProviderData {
models: CloudModelDefinition[];
}
+// Types for transcription providers (speech-to-text)
+export interface TranscriptionModelDefinition {
+ id: string;
+ name: string;
+ description: string;
+}
+
+export interface TranscriptionProviderData {
+ id: string;
+ name: string;
+ baseUrl: string;
+ models: TranscriptionModelDefinition[];
+}
+
+// Type-safe model registry data structure
+interface ModelRegistryData {
+ transcriptionProviders: TranscriptionProviderData[];
+ cloudProviders: CloudProviderData[];
+ localProviders: LocalProviderData[];
+}
+
+const modelData: ModelRegistryData = modelDataRaw as ModelRegistryData;
+
function createPromptFormatter(template: string): (text: string, systemPrompt: string) => string {
return (text: string, systemPrompt: string) => {
return template.replace('{system}', systemPrompt).replace('{user}', text);
@@ -98,11 +121,15 @@ class ModelRegistry {
}
getCloudProviders(): CloudProviderData[] {
- return modelData.cloudProviders as CloudProviderData[];
+ return modelData.cloudProviders;
+ }
+
+ getTranscriptionProviders(): TranscriptionProviderData[] {
+ return modelData.transcriptionProviders;
}
private registerProvidersFromData() {
- const localProviders = modelData.localProviders as LocalProviderData[];
+ const localProviders = modelData.localProviders;
for (const providerData of localProviders) {
const formatPrompt = createPromptFormatter(providerData.promptTemplate);
@@ -207,3 +234,22 @@ export function getModelProvider(modelId: string): string {
return model?.provider || "openai";
}
+
+// Transcription provider helpers
+export function getTranscriptionProviders(): TranscriptionProviderData[] {
+ return modelRegistry.getTranscriptionProviders();
+}
+
+export function getTranscriptionProvider(providerId: string): TranscriptionProviderData | undefined {
+ return getTranscriptionProviders().find(p => p.id === providerId);
+}
+
+export function getTranscriptionModels(providerId: string): TranscriptionModelDefinition[] {
+ const provider = getTranscriptionProvider(providerId);
+ return provider?.models || [];
+}
+
+export function getDefaultTranscriptionModel(providerId: string): string {
+ const models = getTranscriptionModels(providerId);
+ return models[0]?.id || 'gpt-4o-mini-transcribe';
+}
diff --git a/src/models/modelRegistryData.json b/src/models/modelRegistryData.json
index 730deb878..258cb9040 100644
--- a/src/models/modelRegistryData.json
+++ b/src/models/modelRegistryData.json
@@ -1,4 +1,40 @@
{
+ "transcriptionProviders": [
+ {
+ "id": "openai",
+ "name": "OpenAI",
+ "baseUrl": "https://api.openai.com/v1",
+ "models": [
+ {
+ "id": "gpt-4o-mini-transcribe",
+ "name": "GPT-4o Mini Transcribe",
+ "description": "Fast and accurate transcription"
+ },
+ {
+ "id": "gpt-4o-transcribe",
+ "name": "GPT-4o Transcribe",
+ "description": "Most accurate transcription"
+ },
+ {
+ "id": "whisper-1",
+ "name": "Whisper",
+ "description": "Original Whisper model"
+ }
+ ]
+ },
+ {
+ "id": "groq",
+ "name": "Groq",
+ "baseUrl": "https://api.groq.com/openai/v1",
+ "models": [
+ {
+ "id": "whisper-large-v3-turbo",
+ "name": "Whisper Large v3 Turbo",
+ "description": "216x real-time speed"
+ }
+ ]
+ }
+ ],
"cloudProviders": [
{
"id": "openai",
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index 01702128b..1e60d8323 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -30,8 +30,30 @@ class ReasoningService extends BaseReasoningService {
try {
const stored = window.localStorage.getItem('cloudReasoningBaseUrl') || '';
const trimmed = stored.trim();
- const candidate = trimmed || API_ENDPOINTS.OPENAI_BASE;
- const normalized = normalizeBaseUrl(candidate) || API_ENDPOINTS.OPENAI_BASE;
+
+ // If no custom URL is stored, use the default
+ if (!trimmed) {
+ return API_ENDPOINTS.OPENAI_BASE;
+ }
+
+ const normalized = normalizeBaseUrl(trimmed) || API_ENDPOINTS.OPENAI_BASE;
+
+ // Don't use the custom URL if it's a known non-OpenAI provider URL
+ // These should be handled by their dedicated provider methods
+ const knownNonOpenAIUrls = [
+ 'api.groq.com',
+ 'api.anthropic.com',
+ 'generativelanguage.googleapis.com',
+ ];
+
+ const isKnownNonOpenAI = knownNonOpenAIUrls.some(url => normalized.includes(url));
+ if (isKnownNonOpenAI) {
+ logger.logReasoning('OPENAI_BASE_REJECTED', {
+ reason: 'Custom URL is a known non-OpenAI provider, using default OpenAI endpoint',
+ attempted: normalized
+ });
+ return API_ENDPOINTS.OPENAI_BASE;
+ }
// Security: Only allow HTTPS endpoints (except localhost for development)
const isLocalhost = normalized.includes('://localhost') || normalized.includes('://127.0.0.1');
@@ -395,25 +417,14 @@ class ReasoningService extends BaseReasoningService {
const systemPrompt = "You are a dictation assistant. Clean up text by fixing grammar and punctuation. Output ONLY the cleaned text without any explanations, options, or commentary.";
const userPrompt = this.getReasoningPrompt(text, agentName, config);
- // Build input array for Responses API
- const input = [
+ // Build messages array (used by both APIs)
+ const messages = [
{ role: "system", content: systemPrompt },
{ role: "user", content: userPrompt }
];
- // Build request body for Responses API
- const requestBody: any = {
- model,
- input,
- messages: input, // include both for Responses and Chat Completions compatibility
- store: false, // Don't store responses for privacy
- };
-
// Add temperature for older models (GPT-4 and earlier)
const isOlderModel = model && (model.startsWith('gpt-4') || model.startsWith('gpt-3'));
- if (isOlderModel) {
- requestBody.temperature = config.temperature || 0.3;
- }
const openAiBase = this.getConfiguredOpenAIBase();
const endpointCandidates = this.getOpenAIEndpointCandidates(openAiBase);
@@ -430,6 +441,21 @@ class ReasoningService extends BaseReasoningService {
for (const { url: endpoint, type } of endpointCandidates) {
try {
+ // Build request body based on endpoint type
+ const requestBody: any = { model };
+
+ if (type === 'responses') {
+ // Responses API uses 'input' parameter
+ requestBody.input = messages;
+ requestBody.store = false;
+ } else {
+ // Chat Completions API uses 'messages' parameter
+ requestBody.messages = messages;
+ if (isOlderModel) {
+ requestBody.temperature = config.temperature || 0.3;
+ }
+ }
+
const res = await fetch(endpoint, {
method: "POST",
headers: {