import {
  getDatabase
} from "./chunk-FBGWG4N6.js";

// src/server/db/settings.ts
var SETTINGS_KEYS = {
  GLOBAL_INSTRUCTIONS: "global_instructions",
  DISPLAY_SHOW_THINKING: "display.showThinking",
  DISPLAY_SHOW_VERBOSE_TOOL_OUTPUT: "display.showVerboseToolOutput",
  DISPLAY_SHOW_STATS: "display.showStats",
  DISPLAY_SHOW_AGENT_DEFINITIONS: "display.showAgentDefinitions",
  DISPLAY_SHOW_WORKFLOW_BARS: "display.showWorkflowBars",
  DISPLAY_SHOW_SYNTAX_HIGHLIGHTING: "display.showSyntaxHighlighting",
  DISPLAY_THEME: "display.theme",
  DISPLAY_USER_PRESETS: "display.userPresets",
  DISPLAY_FOLLOW_SYSTEM_THEME: "display.followSystemTheme",
  DISPLAY_SHOW_OPEN_IN_EDITOR: "display.showOpenInEditorLinks",
  LLM_DISABLE_XML_PROTECTION: "llm.disableXmlProtection",
  LLM_DYNAMIC_SYSTEM_PROMPT: "llm.dynamicSystemPrompt",
  KEYBINDINGS: "keybindings"
};
var SETTINGS_DEFAULTS = {
  [SETTINGS_KEYS.DISPLAY_SHOW_THINKING]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_VERBOSE_TOOL_OUTPUT]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_STATS]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_AGENT_DEFINITIONS]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_WORKFLOW_BARS]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_SYNTAX_HIGHLIGHTING]: "true",
  [SETTINGS_KEYS.DISPLAY_THEME]: JSON.stringify({ preset: "dark" }),
  [SETTINGS_KEYS.DISPLAY_FOLLOW_SYSTEM_THEME]: "true",
  [SETTINGS_KEYS.DISPLAY_SHOW_OPEN_IN_EDITOR]: "false",
  [SETTINGS_KEYS.LLM_DISABLE_XML_PROTECTION]: "false",
  [SETTINGS_KEYS.LLM_DYNAMIC_SYSTEM_PROMPT]: "false",
  [SETTINGS_KEYS.KEYBINDINGS]: JSON.stringify({
    terminalToggle: { type: "double-press", key: "Control", threshold: 300 },
    quickAction: { type: "double-press", key: "Shift", threshold: 300 },
    agentSwitching: [
      { type: "chord", key: "1", modifiers: ["ctrl"] },
      { type: "chord", key: "2", modifiers: ["ctrl"] },
      { type: "chord", key: "3", modifiers: ["ctrl"] },
      { type: "chord", key: "4", modifiers: ["ctrl"] }
    ]
  })
};
function getSetting(key) {
  try {
    const db = getDatabase();
    const row = db.prepare(
      `
      SELECT value FROM settings WHERE key = ?
    `
    ).get(key);
    return row?.value ?? null;
  } catch {
    return null;
  }
}
function setSetting(key, value) {
  const db = getDatabase();
  const now = (/* @__PURE__ */ new Date()).toISOString();
  db.prepare(
    `
    INSERT INTO settings (key, value, updated_at)
    VALUES (?, ?, ?)
    ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
  `
  ).run(key, value, now);
}
function deleteSetting(key) {
  const db = getDatabase();
  db.prepare(`DELETE FROM settings WHERE key = ?`).run(key);
}
function getAllSettings() {
  const db = getDatabase();
  const rows = db.prepare(`SELECT key, value FROM settings`).all();
  const result = {};
  for (const row of rows) {
    result[row.key] = row.value;
  }
  return result;
}

export {
  SETTINGS_KEYS,
  SETTINGS_DEFAULTS,
  getSetting,
  setSetting,
  deleteSetting,
  getAllSettings
};
//# sourceMappingURL=chunk-PSJIT5LZ.js.map