{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/index.cjs","../src/index.ts"],"names":["notifier","updateNotifier","packageInfo","suggestClosestCommand","input","commands","minDistance","closest","cmd","dist","leven","current","latest","type","packageName","releaseNotesUrl"],"mappings":"AAAA;AACA;AACA,gCAA4B,wDAAyC,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,wDAAyC,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA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":"/home/mkabumattar/work/withrawi/rawi/dist/index.cjs","sourcesContent":[null,"#!/usr/bin/env node\n\nimport boxen from 'boxen';\nimport chalk, {type ChalkInstance} from 'chalk';\nimport leven from 'leven';\nimport updateNotifier from 'update-notifier';\nimport {packageInfo} from './core/index.js';\n\nconst notifier = await updateNotifier({\n  pkg: packageInfo,\n  updateCheckInterval: 1000 * 60 * 60 * 2,\n  shouldNotifyInNpmScript: true,\n  distTag: 'latest',\n});\n\nnotifier.notify();\n\nfunction suggestClosestCommand(\n  input: string,\n  commands: string[],\n): string | null {\n  let minDistance = Number.POSITIVE_INFINITY;\n  let closest: string | null = null;\n  for (const cmd of commands) {\n    const dist = leven(input, cmd);\n    if (dist < minDistance) {\n      minDistance = dist;\n      closest = cmd;\n    }\n  }\n  return minDistance <= 2 ? closest : null;\n}\n\nif (notifier.update) {\n  const {current, latest, type} = notifier.update;\n  const packageName = packageInfo.name;\n  const releaseNotesUrl = packageInfo?.repository?.url\n    ? `${packageInfo.repository.url.replace(/^git\\+/, '').replace(/\\.git$/, '')}/releases/latest`\n    : null;\n\n  let typeColorFn: ChalkInstance;\n  let typePrefix = '';\n  let emoji = '';\n\n  switch (type) {\n    case 'major':\n      typeColorFn = chalk.red.bold;\n      typePrefix = 'Major ';\n      emoji = '🔥';\n      break;\n    case 'minor':\n    case 'patch':\n      typeColorFn = chalk.yellow.bold;\n      typePrefix = '';\n      emoji = '✨';\n      break;\n    case 'prerelease':\n    case 'build':\n      typeColorFn = chalk.cyan.italic;\n      typePrefix = 'Pre-release ';\n      emoji = '🧪';\n      break;\n    default:\n      typeColorFn = chalk.gray;\n      typePrefix = '';\n      emoji = 'ℹ️';\n  }\n\n  const header = chalk\n    .hex('#32CD32')\n    .bold(`${emoji}  UPDATE AVAILABLE  ${emoji}`);\n  const updateTypeInfo = `${chalk.bold(typePrefix)}${typeColorFn(type.toUpperCase())} Update`;\n  const versionComparison = `${chalk.dim('Current:')} ${chalk.white(current)} ${chalk.dim('→')} ${chalk.green(latest)} ${chalk.dim('(Latest)')}`;\n  const benefitStatement = chalk.whiteBright(\n    `Unlock the latest features and bug fixes for ${chalk.bold(packageName)}!`,\n  );\n  const callToAction = chalk.yellow.bold(\n    'Upgrade by running one of these commands:',\n  );\n  const installCommands = [\n    `npm install -g ${packageName} `,\n    `pnpm install -g ${packageName}`,\n    `yarn global add ${packageName}`,\n    `bun add -g ${packageName}     `,\n  ]\n    .map((cmd) => chalk.blue.bold(`  $ ${cmd}`))\n    .join('\\n');\n\n  const releaseNotesLine = releaseNotesUrl\n    ? `\\n${chalk.underline.blue('See release notes:')} ${chalk.dim(releaseNotesUrl)}\\n`\n    : '';\n\n  const nextSteps = chalk.dim(\n    '\\nTip: Restart your terminal or IDE after upgrade for changes to take effect.',\n  );\n\n  const fullMessage = [\n    header,\n    '',\n    updateTypeInfo,\n    '',\n    versionComparison,\n    '',\n    benefitStatement,\n    '',\n    callToAction,\n    installCommands,\n    releaseNotesLine,\n    nextSteps,\n  ].join('\\n');\n\n  console.log(\n    boxen(fullMessage, {\n      padding: 1,\n      margin: 1,\n      borderColor: '#FF4500',\n      borderStyle: 'round',\n      backgroundColor: '#1A1A1A',\n      textAlignment: 'center',\n      title: chalk.bold.white(` ${packageName} Update `),\n      titleAlignment: 'center',\n      float: 'center',\n    }),\n  );\n}\n\nimport {createProgram} from './cli/index.js';\n\nprocess.on('uncaughtException', (error) => {\n  if (error instanceof Error && error.name === 'ExitPromptError') {\n    console.log('\\n👋 Exiting Rawi. Until next time!');\n    process.exit(0);\n  }\n  if (error instanceof Error) {\n    const msg = error.message || '';\n    if (msg.includes('Unknown command')) {\n      const inputMatch = msg.match(/Unknown command '([^']+)'/);\n      const inputCmd = inputMatch ? inputMatch[1] : null;\n      const commands = [\n        'ask',\n        'act',\n        'configure',\n        'provider',\n        'history',\n        'info',\n      ];\n      let suggestion = null;\n      if (inputCmd) {\n        suggestion = suggestClosestCommand(inputCmd, commands);\n      }\n      console.error(`\\n${chalk.red(`❌ Unknown command: ${inputCmd || msg}`)}`);\n      if (suggestion) {\n        console.info(chalk.yellowBright(`Did you mean '${suggestion}'?`));\n      } else {\n        const close = commands.find(\n          (cmd) => inputCmd && cmd.startsWith(inputCmd[0]),\n        );\n        if (close) {\n          console.info(chalk.yellowBright(`Did you mean '${close}'?`));\n        }\n      }\n      console.info(\n        chalk.gray('Run `rawi --help` to see all available commands.'),\n      );\n      process.exit(1);\n    }\n    if (msg.includes('Missing required argument')) {\n      console.error(`\\n${chalk.red(`❌ ${msg}`)}`);\n      console.info(\n        chalk.gray('Use `--help` with the command for usage details.'),\n      );\n      process.exit(1);\n    }\n    if (msg.includes('Invalid option')) {\n      console.error(`\\n${chalk.red(`❌ ${msg}`)}`);\n      console.info(chalk.gray('Check available options with `--help`.'));\n      process.exit(1);\n    }\n    if (msg.includes('not configured') || msg.includes('credentials')) {\n      console.error(`\\n${chalk.red(`❌ ${msg}`)}`);\n      console.info(\n        chalk.yellow(\n          'Run `rawi configure` to set up your provider and credentials.',\n        ),\n      );\n      process.exit(2);\n    }\n    if (msg.includes('network') || msg.includes('timeout')) {\n      console.error(`\\n${chalk.red(`❌ ${msg}`)}`);\n      console.info(\n        chalk.yellow('Check your internet connection or provider status.'),\n      );\n      process.exit(3);\n    }\n    if (msg.includes('authentication') || msg.includes('API key')) {\n      console.error(`\\n${chalk.red(`❌ ${msg}`)}`);\n      console.info(\n        chalk.yellow('Check your API key and provider configuration.'),\n      );\n      process.exit(4);\n    }\n    console.error(`\\n${chalk.red(`❌ Unexpected error: ${msg}`)}`);\n    console.info(\n      chalk.gray(\n        'If this issue persists, run `rawi info` for diagnostics or see the Troubleshooting guide.',\n      ),\n    );\n    process.exit(1);\n  }\n  console.error('\\n❌ An unknown error occurred.');\n  process.exit(1);\n});\n\nconst program = createProgram();\n\nif (process.argv.length <= 2) {\n  program.outputHelp();\n  process.exit(0);\n}\n\nprogram.parse(process.argv);\n"]}