import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

// src/platform/prompts/markdown-assets.ts
var PACKAGE_JSON_FILE_NAME = "package.json";
function findPackageRoot(moduleFilePath) {
  let currentDirectoryPath = path.dirname(moduleFilePath);
  while (!fs.existsSync(path.join(currentDirectoryPath, PACKAGE_JSON_FILE_NAME))) {
    const parentDirectoryPath = path.dirname(currentDirectoryPath);
    if (parentDirectoryPath === currentDirectoryPath) {
      throw new Error(`markdown \uC790\uC0B0 package root\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4. start=${moduleFilePath}`);
    }
    currentDirectoryPath = parentDirectoryPath;
  }
  return currentDirectoryPath;
}
function resolvePromptPackageFilePath(importMetaUrl, packageRelativeFilePath) {
  const moduleFilePath = fileURLToPath(importMetaUrl);
  const packageRoot = findPackageRoot(moduleFilePath);
  return path.normalize(path.resolve(packageRoot, packageRelativeFilePath));
}
function createPromptMarkdownFileAsset(importMetaUrl, packageRelativeFilePath) {
  return {
    filePath: resolvePromptPackageFilePath(importMetaUrl, packageRelativeFilePath),
    kind: "file-reference"
  };
}

// src/platform/prompts/build-common-prompt.ts
var commonInstructionAsset = createPromptMarkdownFileAsset(
  import.meta.url,
  "src/platform/prompts/assets/common/base-instructions.md"
);
function buildCommonPrompt(options) {
  return {
    autoYes: options.autoYes,
    forms: options.forms,
    historyReferences: options.historyReferences,
    instructions: options.instructions,
    rules: options.rules,
    sections: options.sections,
    service: options.service,
    title: options.title,
    workspaceSnapshot: options.workspaceSnapshot
  };
}

// src/platform/prompts/index.ts
var chatFormAsset = createPromptMarkdownFileAsset(import.meta.url, "src/platform/prompts/assets/chat/forms/chat-response.md");
var chatInstructionAsset = createPromptMarkdownFileAsset(
  import.meta.url,
  "src/platform/prompts/assets/chat/instructions/chat-request.md"
);
function buildChatPrompt(options) {
  return buildCommonPrompt({
    autoYes: options.autoYes,
    forms: [chatFormAsset],
    historyReferences: options.historyReferences,
    instructions: [commonInstructionAsset, chatInstructionAsset],
    sections: [
      {
        heading: "\uC0AC\uC6A9\uC790 \uC694\uCCAD",
        markdown: options.userInput
      }
    ],
    service: options.service,
    title: "Ju-hong-e Chat",
    workspaceSnapshot: options.workspaceSnapshot
  });
}

export { buildChatPrompt };
