// @bun
import {
  init_useVoice,
  normalizeLanguageForSTT
} from "./chunk-2j01njj0.js";
import"./chunk-120tmt7h.js";
import {
  getShortcutDisplay,
  init_changeDetector,
  init_shortcutFormat,
  settingsChangeDetector
} from "./chunk-421yegj3.js";
import"./chunk-aaxz8a5g.js";
import"./chunk-2kcgxnvp.js";
import"./chunk-14p6wvsq.js";
import"./chunk-6s0q1s5r.js";
import"./chunk-0cpg8qh8.js";
import"./chunk-9phn5khx.js";
import"./chunk-vk9xcryd.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-ptxteaeh.js";
import"./chunk-7fcmqvbz.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-q3b4n194.js";
import"./chunk-zaqfb3tz.js";
import"./chunk-6hzx0kqr.js";
import"./chunk-71sdcaq6.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-dxa3y9vh.js";
import"./chunk-gjvhjywj.js";
import"./chunk-1w20m7gw.js";
import"./chunk-3gam18xn.js";
import"./chunk-rpmntgyh.js";
import"./chunk-24kv69g3.js";
import"./chunk-tzcrwnrf.js";
import"./chunk-k7xszak2.js";
import"./chunk-ztmb7geg.js";
import"./chunk-tbdkekz3.js";
import"./chunk-65zbgg1n.js";
import"./chunk-4spgkgr3.js";
import"./chunk-60fkafk2.js";
import"./chunk-h5zz0vxy.js";
import"./chunk-6hygvrhn.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-8gv2pjby.js";
import"./chunk-pn23dh3d.js";
import"./chunk-rpdh02rm.js";
import {
  init_voiceModeEnabled,
  isVoiceAvailable
} from "./chunk-j1wktfe2.js";
import"./chunk-fjtzfz1t.js";
import"./chunk-6hr7742d.js";
import"./chunk-xyg1sk2w.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-hem4f4gz.js";
import"./chunk-hqxp6b72.js";
import"./chunk-ccw8pse0.js";
import"./chunk-wsnxtggw.js";
import"./chunk-k8nwt8yq.js";
import"./chunk-vxbjzggp.js";
import"./chunk-d6h68rz1.js";
import"./chunk-8yvsnrkr.js";
import"./chunk-5mmhfbxb.js";
import {
  getGlobalConfig,
  getInitialSettings,
  init_config1 as init_config,
  init_settings1 as init_settings,
  saveGlobalConfig,
  updateSettingsForSource
} from "./chunk-s2t5anwv.js";
import"./chunk-ga1jkyqy.js";
import"./chunk-9hbhydvp.js";
import"./chunk-ck9r8hpf.js";
import"./chunk-k7hexw3v.js";
import"./chunk-trqrj23e.js";
import"./chunk-za3k6h2h.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-hjxqmtg5.js";
import"./chunk-bzyzrq0k.js";
import"./chunk-vwenx8ke.js";
import"./chunk-q2h79ncs.js";
import"./chunk-v4ypszbb.js";
import"./chunk-qfsn720k.js";
import"./chunk-7qx3xhv3.js";
import"./chunk-j9475b46.js";
import"./chunk-fdwabr8p.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-dbts5q5p.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-q1vrhh0q.js";
import"./chunk-hn4w9pkj.js";
import"./chunk-2g0ytd9d.js";
import"./chunk-de0qnnf7.js";
import {
  init_analytics,
  logEvent
} from "./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-92bjkrf2.js";
import"./chunk-10k5jfc5.js";
import"./chunk-n9g24mwe.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-hzmzwte2.js";
import"./chunk-pdvg91cg.js";
import"./chunk-c696122m.js";
import"./chunk-xbj5keyy.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import"./chunk-aeysytks.js";
import"./chunk-s3hafnk3.js";
import"./chunk-kb3758f7.js";
import"./chunk-9h9k5vz3.js";
import"./chunk-xmpgmeb8.js";
import"./chunk-2kz09j2s.js";
import"./chunk-c0k7b0jw.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __esm,
  __require
} from "./chunk-hhsxm2yr.js";

// src/commands/voice/voice.ts
var LANG_HINT_MAX_SHOWS = 2, call = async (args) => {
  if (!isVoiceAvailable()) {
    return {
      type: "text",
      value: "Voice mode is not available."
    };
  }
  const currentSettings = getInitialSettings();
  const isCurrentlyEnabled = currentSettings.voiceEnabled === true;
  const providerArg = args?.trim().toLowerCase();
  if (isCurrentlyEnabled && providerArg === "doubao") {
    const result2 = updateSettingsForSource("userSettings", {
      voiceProvider: "doubao"
    });
    if (result2.error) {
      return {
        type: "text",
        value: "Failed to update settings. Check your settings file for syntax errors."
      };
    }
    settingsChangeDetector.notifyChange("userSettings");
    const key2 = getShortcutDisplay("voice:pushToTalk", "Chat", "Space");
    return {
      type: "text",
      value: `Voice mode switched to Doubao ASR. Hold ${key2} to record.`
    };
  }
  if (isCurrentlyEnabled && providerArg === "anthropic") {
    const result2 = updateSettingsForSource("userSettings", {
      voiceProvider: "anthropic"
    });
    if (result2.error) {
      return {
        type: "text",
        value: "Failed to update settings. Check your settings file for syntax errors."
      };
    }
    settingsChangeDetector.notifyChange("userSettings");
    const key2 = getShortcutDisplay("voice:pushToTalk", "Chat", "Space");
    return {
      type: "text",
      value: `Voice mode switched to Anthropic STT. Hold ${key2} to record.`
    };
  }
  if (isCurrentlyEnabled) {
    const result2 = updateSettingsForSource("userSettings", {
      voiceEnabled: false
    });
    if (result2.error) {
      return {
        type: "text",
        value: "Failed to update settings. Check your settings file for syntax errors."
      };
    }
    settingsChangeDetector.notifyChange("userSettings");
    logEvent("tengu_voice_toggled", { enabled: false });
    return {
      type: "text",
      value: "Voice mode disabled."
    };
  }
  const provider = providerArg === "doubao" ? "doubao" : "anthropic";
  const { isVoiceStreamAvailable } = await import("./chunk-bbjz65q8.js");
  const { checkRecordingAvailability } = await import("./chunk-zga50181.js");
  const recording = await checkRecordingAvailability();
  if (!recording.available) {
    return {
      type: "text",
      value: recording.reason ?? "Voice mode is not available in this environment."
    };
  }
  if (provider !== "doubao" && !isVoiceStreamAvailable()) {
    return {
      type: "text",
      value: "Voice mode requires a Claude.ai account. Please run /login to sign in."
    };
  }
  const { checkVoiceDependencies, requestMicrophonePermission } = await import("./chunk-zga50181.js");
  const deps = await checkVoiceDependencies();
  if (!deps.available) {
    const hint = deps.installCommand ? `
Install audio recording tools? Run: ${deps.installCommand}` : `
Install SoX manually for audio recording.`;
    return {
      type: "text",
      value: `No audio recording tool found.${hint}`
    };
  }
  if (!await requestMicrophonePermission()) {
    let guidance;
    if (process.platform === "win32") {
      guidance = "Settings \u2192 Privacy \u2192 Microphone";
    } else if (process.platform === "linux") {
      guidance = "your system's audio settings";
    } else {
      guidance = "System Settings \u2192 Privacy & Security \u2192 Microphone";
    }
    return {
      type: "text",
      value: `Microphone access is denied. To enable it, go to ${guidance}, then run /voice again.`
    };
  }
  const result = updateSettingsForSource("userSettings", {
    voiceEnabled: true,
    ...provider === "doubao" ? { voiceProvider: "doubao" } : {}
  });
  if (result.error) {
    return {
      type: "text",
      value: "Failed to update settings. Check your settings file for syntax errors."
    };
  }
  settingsChangeDetector.notifyChange("userSettings");
  logEvent("tengu_voice_toggled", { enabled: true });
  const key = getShortcutDisplay("voice:pushToTalk", "Chat", "Space");
  let langNote = "";
  const providerLabel = provider === "doubao" ? "Doubao ASR" : "Anthropic";
  if (provider !== "doubao") {
    const stt = normalizeLanguageForSTT(currentSettings.language);
    const cfg = getGlobalConfig();
    const langChanged = cfg.voiceLangHintLastLanguage !== stt.code;
    const priorCount = langChanged ? 0 : cfg.voiceLangHintShownCount ?? 0;
    const showHint = !stt.fellBackFrom && priorCount < LANG_HINT_MAX_SHOWS;
    if (stt.fellBackFrom) {
      langNote = ` Note: "${stt.fellBackFrom}" is not a supported dictation language; using English. Change it via /config.`;
    } else if (showHint) {
      langNote = ` Dictation language: ${stt.code} (/config to change).`;
    }
    if (langChanged || showHint) {
      saveGlobalConfig((prev) => ({
        ...prev,
        voiceLangHintShownCount: priorCount + (showHint ? 1 : 0),
        voiceLangHintLastLanguage: stt.code
      }));
    }
  }
  return {
    type: "text",
    value: `Voice mode enabled (${providerLabel}). Hold ${key} to record.${langNote}`
  };
};
var init_voice = __esm(() => {
  init_useVoice();
  init_shortcutFormat();
  init_analytics();
  init_config();
  init_changeDetector();
  init_settings();
  init_voiceModeEnabled();
});
init_voice();

export {
  call
};
