import { createLogger } from "../../logger.js";
import { isLlmConfigured, runLlmJson } from "../../integrations/cloud/llm/run.js";
const log = createLogger("extract");
const MAX_HTML_CHARS = 5e4;
const REQUEST_TIMEOUT_MS = 3e4;
function isLocalLlmEnabled() {
  return isLlmConfigured();
}
async function extractWithLocalLlm(request) {
  if (!isLocalLlmEnabled()) return null;
  const htmlSlice = request.html.length > MAX_HTML_CHARS ? request.html.slice(0, MAX_HTML_CHARS) : request.html;
  const prompt = `Extract data matching the JSON schema from the HTML below. Return only the JSON object \u2014 no prose, no markdown fences.

URL: ${request.url}

HTML:
${htmlSlice}`;
  try {
    const r = await runLlmJson({
      prompt,
      jsonSchema: request.schema,
      timeoutMs: REQUEST_TIMEOUT_MS
    });
    return r.values;
  } catch (err) {
    log.error("local llm request failed", { error: err instanceof Error ? err.message : String(err) });
    throw err;
  }
}
export {
  extractWithLocalLlm,
  isLocalLlmEnabled
};
//# sourceMappingURL=local-llm.js.map