'use strict';

var fs = require('fs');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var fs__default = /*#__PURE__*/_interopDefault(fs);

// src/platform/ai-services/stream-output.ts
var DEFAULT_STREAM_OUTPUT_STATE = {
  enabled: false
};
var streamOutputRuntimeState = globalThis.__JU_HONG_E_STREAM_OUTPUT_STATE__ ?? (globalThis.__JU_HONG_E_STREAM_OUTPUT_STATE__ = {
  ...DEFAULT_STREAM_OUTPUT_STATE
});
function normalizeStreamOutputState(value) {
  if (!value || typeof value !== "object") {
    return { ...DEFAULT_STREAM_OUTPUT_STATE };
  }
  const enabled = "enabled" in value ? Boolean(value.enabled) : DEFAULT_STREAM_OUTPUT_STATE.enabled;
  return {
    enabled
  };
}
function readStreamOutputConfig(paths) {
  if (!fs__default.default.existsSync(paths.streamOutputConfigPath)) {
    return { ...DEFAULT_STREAM_OUTPUT_STATE };
  }
  try {
    const parsed = JSON.parse(fs__default.default.readFileSync(paths.streamOutputConfigPath, "utf8"));
    return normalizeStreamOutputState(parsed);
  } catch {
    return { ...DEFAULT_STREAM_OUTPUT_STATE };
  }
}
function hydrateStreamOutputState(paths) {
  const nextState = readStreamOutputConfig(paths);
  streamOutputRuntimeState.enabled = nextState.enabled;
  return streamOutputRuntimeState.enabled;
}
function isStreamOutputEnabled(paths) {
  if (paths) {
    return hydrateStreamOutputState(paths);
  }
  return streamOutputRuntimeState.enabled;
}
function saveStreamOutputConfig(paths, enabled) {
  const nextState = {
    enabled: Boolean(enabled)
  };
  fs__default.default.writeFileSync(paths.streamOutputConfigPath, `${JSON.stringify(nextState, null, 2)}
`, "utf8");
  streamOutputRuntimeState.enabled = nextState.enabled;
  return nextState;
}

exports.hydrateStreamOutputState = hydrateStreamOutputState;
exports.isStreamOutputEnabled = isStreamOutputEnabled;
exports.saveStreamOutputConfig = saveStreamOutputConfig;
