"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// tools/compact/core.ts
var core_exports = {};
__export(core_exports, {
  CompactClient: () => CompactClient
});
module.exports = __toCommonJS(core_exports);
var import_openai = __toESM(require("openai"), 1);
var DEFAULT_API_URL = "https://api.morphllm.com";
var DEFAULT_TIMEOUT = 12e4;
var CompactClient = class {
  config;
  constructor(config = {}) {
    this.config = {
      morphApiUrl: DEFAULT_API_URL,
      timeout: DEFAULT_TIMEOUT,
      ...config
    };
  }
  /**
   * Compact conversation context using Morph compactor
   *
   * @param input - Compact parameters including input content and optional prompt
   * @returns Compact result with compacted output and usage stats
   *
   * @example
   * ```typescript
   * const client = new CompactClient({ morphApiKey: 'sk-...' });
   * const result = await client.compact({
   *   input: 'Long conversation context to compact...',
   *   prompt: 'Focus on the code review feedback',
   * });
   * console.log(result.output);
   * ```
   */
  async compact(input) {
    const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
    const debug = this.config.debug || false;
    if (!apiKey) {
      throw new Error(
        "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
      );
    }
    const client = new import_openai.default({
      apiKey,
      baseURL: `${this.config.morphApiUrl}/v1`,
      timeout: this.config.timeout,
      maxRetries: this.config.retryConfig?.maxRetries ?? 3
    });
    const instructions = input.prompt ? `The user's next message will be: "${input.prompt}"
Prioritize keeping context relevant to this query.` : void 0;
    if (debug) {
      console.log(`[Compact] Calling ${this.config.morphApiUrl}/v1/responses`);
      console.log(`[Compact] Model: ${input.model || "morph-compactor"}`);
    }
    const startTime = Date.now();
    const response = await client.responses.create({
      model: input.model || "morph-compactor",
      input: input.input,
      ...instructions && { instructions },
      ...input.temperature != null && { temperature: input.temperature },
      ...input.max_output_tokens != null && { max_output_tokens: input.max_output_tokens },
      stream: false
    });
    const elapsed = Date.now() - startTime;
    if (debug) {
      console.log(`[Compact] Success in ${elapsed}ms`);
    }
    return {
      id: response.id,
      output: response.output,
      usage: response.usage,
      status: response.status ?? "completed",
      model: response.model
    };
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CompactClient
});
//# sourceMappingURL=core.cjs.map