rawi
Version: 
Rawi (راوي) is the developer-friendly AI CLI that brings the power of 11 major AI providers directly to your terminal. With seamless shell integration, persistent conversations, and 200+ specialized prompt templates, Rawi transforms your command line into
1 lines • 10.8 kB
Source Map (JSON)
{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-TD7NWAYB.cjs","../src/core/templates/utils.ts"],"names":["findActTemplate","id","builtIn","actTemplates","template","ActTemplateManager","getAllTemplates","customTemplates","listActTemplates","templates","a","b","totalPages","page","renderPage","pageIdx","table","Table","chalk","isCustom"],"mappings":"AAAA;AACA,wDAAwC,wDAAyC,4CCD5D,4EACH,6FACA,IAILA,CAAAA,CAAkB,MAAOC,CAAAA,EAAe,CACnD,IAAMC,CAAAA,CAAUC,mBAAAA,CAAa,IAAA,CAAMC,CAAAA,EAAaA,CAAAA,CAAS,EAAA,GAAOH,CAAE,CAAA,CAClE,OAAIC,CAAAA,EAKW,MADC,IAAIG,wBAAAA,CAAmB,CAAA,CACV,WAAA,CAAYJ,CAAE,CAAA,EAC1B,KAAA,CACnB,CAAA,CAEaK,CAAAA,aAAkB,KAAA,CAAA,CAAA,EAAY,CAEzC,IAAMC,CAAAA,CAAkB,MADR,IAAIF,wBAAAA,CAAmB,CAAA,CACD,mBAAA,CAAoB,CAAA,CAE1D,MAAO,CAAC,GAAGF,mBAAAA,CAAc,GAAGI,CAAe,CAC7C,CAAA,CAEaC,CAAAA,aAAmB,KAAA,CAAA,CAAA,EAAY,CAG1C,IAAMC,CAAAA,CAAAA,CADe,MAAMH,CAAAA,CAAgB,CAAA,CAAA,CAExC,KAAA,CAAM,CAAA,CACN,IAAA,CAAK,CAACI,CAAAA,CAAGC,CAAAA,CAAAA,EAAMD,CAAAA,CAAE,KAAA,CAAM,aAAA,CAAcC,CAAAA,CAAE,KAAK,CAAC,CAAA,CAC1CC,CAAAA,CAAa,IAAA,CAAK,IAAA,CAAKH,CAAAA,CAAU,MAAA,CAAS,EAAQ,CAAA,CACpDI,CAAAA,CAAO,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CAAA,CACH,OAAA,CAAQ,GAAA,CAAIc,eAAAA,CAAM,IAAA,CAAK,IAAA,CAAK,CAAA;AAAA,kCAAA,CAA+B,CAAC,CAAA,CAC5D,OAAA,CAAQ,GAAA,CAAIF,CAAAA,CAAM,QAAA,CAAS,CAAC,CAAA,CAC5B,OAAA,CAAQ,GAAA,CAAIE,eAAAA,CAAM,IAAA,CAAK,CAAA,KAAA,EAAQH,CAAAA,CAAU,CAAC,CAAA,IAAA,EAAOH,CAAU,CAAA,CAAA;AA+DE,iCAAA;AAkC/D,oCAAA;AA6BsB,+BAAA;AAqBC,wBAAA;ADzM8E","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-TD7NWAYB.cjs","sourcesContent":[null,"import {select} from '@inquirer/prompts';\nimport chalk from 'chalk';\nimport Table from 'cli-table3';\nimport {actTemplates} from './act.js';\nimport {ActTemplateManager} from './act-manager.js';\n\nexport const findActTemplate = async (id: string) => {\n  const builtIn = actTemplates.find((template) => template.id === id);\n  if (builtIn) {\n    return builtIn;\n  }\n\n  const manager = new ActTemplateManager();\n  const custom = await manager.getTemplate(id);\n  return custom || undefined;\n};\n\nexport const getAllTemplates = async () => {\n  const manager = new ActTemplateManager();\n  const customTemplates = await manager.listCustomTemplates();\n\n  return [...actTemplates, ...customTemplates];\n};\n\nexport const listActTemplates = async () => {\n  const pageSize = 10;\n  const allTemplates = await getAllTemplates();\n  const templates = allTemplates\n    .slice()\n    .sort((a, b) => a.label.localeCompare(b.label));\n  const totalPages = Math.ceil(templates.length / pageSize);\n  let page = 0;\n\n  const renderPage = (pageIdx: number) => {\n    const table = new Table({\n      head: [\n        chalk.cyan('ID'),\n        chalk.cyan('Label'),\n        chalk.cyan('Category'),\n        chalk.cyan('Type'),\n        chalk.cyan('Description'),\n      ],\n      style: {head: ['cyan']},\n      colWidths: [16, 22, 16, 10, 30],\n      wordWrap: true,\n    });\n    templates\n      .slice(pageIdx * pageSize, (pageIdx + 1) * pageSize)\n      .forEach((template) => {\n        const isCustom = 'isBuiltIn' in template ? !template.isBuiltIn : false;\n        table.push([\n          chalk.green(template.id),\n          template.label,\n          chalk.blue(template.category),\n          isCustom ? chalk.yellow('Custom') : chalk.gray('Built-in'),\n          template.description?.substring(0, 50) +\n            (template.description?.length > 50 ? '...' : '') || '',\n        ]);\n      });\n    console.log(chalk.bold.cyan('\\n🎭 Available Act Templates:'));\n    console.log(table.toString());\n    console.log(chalk.gray(`Page ${pageIdx + 1} of ${totalPages}`));\n  };\n\n  if (templates.length > pageSize) {\n    let exit = false;\n    while (!exit) {\n      renderPage(page);\n      const choices = [];\n      if (page > 0) choices.push({name: 'Previous', value: 'prev'});\n      if (page < totalPages - 1) choices.push({name: 'Next', value: 'next'});\n      choices.push({name: 'Exit', value: 'exit'});\n      const nav = await select({\n        message: 'Navigate pages:',\n        choices,\n        default: page < totalPages - 1 ? 'next' : 'exit',\n      });\n      if (nav === 'prev') page--;\n      else if (nav === 'next') page++;\n      else exit = true;\n      if (!exit) console.clear();\n    }\n  } else {\n    renderPage(0);\n  }\n  console.log();\n  console.log(chalk.dim('Usage: rawi ask --act <template-id> \"your question\"'));\n  console.log(chalk.dim('Show template: rawi act --show <template-id>'));\n  console.log(chalk.dim('Create custom template: rawi act --create'));\n};\n\nexport const listBuiltInTemplates = async (): Promise<void> => {\n  const pageSize = 10;\n  const templates = actTemplates\n    .slice()\n    .sort((a, b) => a.label.localeCompare(b.label));\n  const totalPages = Math.ceil(templates.length / pageSize);\n  let page = 0;\n\n  const renderPage = (pageIdx: number) => {\n    const table = new Table({\n      head: [\n        chalk.cyan('ID'),\n        chalk.cyan('Label'),\n        chalk.cyan('Category'),\n        chalk.cyan('Description'),\n      ],\n      style: {head: ['cyan']},\n      colWidths: [16, 22, 16, 36],\n      wordWrap: true,\n    });\n    templates\n      .slice(pageIdx * pageSize, (pageIdx + 1) * pageSize)\n      .forEach((template) => {\n        table.push([\n          chalk.green(template.id),\n          template.label,\n          chalk.blue(template.category),\n          template.description?.substring(0, 80) +\n            (template.description?.length > 80 ? '...' : '') || '',\n        ]);\n      });\n    console.log(chalk.bold.cyan('\\n🎭 Built-in Act Templates:'));\n    console.log(table.toString());\n    console.log(chalk.gray(`Page ${pageIdx + 1} of ${totalPages}`));\n  };\n\n  if (templates.length > pageSize) {\n    let exit = false;\n    while (!exit) {\n      renderPage(page);\n      const choices = [];\n      if (page > 0) choices.push({name: 'Previous', value: 'prev'});\n      if (page < totalPages - 1) choices.push({name: 'Next', value: 'next'});\n      choices.push({name: 'Exit', value: 'exit'});\n      const nav = await select({\n        message: 'Navigate pages:',\n        choices,\n        default: page < totalPages - 1 ? 'next' : 'exit',\n      });\n      if (nav === 'prev') page--;\n      else if (nav === 'next') page++;\n      else exit = true;\n      if (!exit) console.clear();\n    }\n  } else {\n    renderPage(0);\n  }\n};\n\nexport const listCustomTemplates = async (): Promise<void> => {\n  const manager = new ActTemplateManager();\n  const templates = await manager.listCustomTemplates();\n\n  if (templates.length === 0) {\n    console.log(chalk.yellow('\\n📝 No custom templates found.'));\n    console.log(chalk.dim('Create one with: rawi act --create'));\n    return;\n  }\n\n  const table = new Table({\n    head: [\n      chalk.cyan('ID'),\n      chalk.cyan('Label'),\n      chalk.cyan('Category'),\n      chalk.cyan('Created'),\n      chalk.cyan('Description'),\n    ],\n    style: {head: ['cyan']},\n    colWidths: [16, 22, 16, 12, 30],\n    wordWrap: true,\n  });\n\n  templates.forEach((template) => {\n    table.push([\n      chalk.green(template.id),\n      template.label,\n      chalk.blue(template.category),\n      template.createdAt.toLocaleDateString(),\n      template.description?.substring(0, 50) +\n        (template.description?.length > 50 ? '...' : '') || '',\n    ]);\n  });\n\n  console.log(chalk.bold.yellow('\\n📝 Custom Act Templates:'));\n  console.log(table.toString());\n  console.log();\n  console.log(chalk.dim('Usage: rawi ask --act <template-id> \"your question\"'));\n  console.log(chalk.dim('Show template: rawi act --show <template-id>'));\n  console.log(chalk.dim('Edit template: rawi act --edit <template-id>'));\n  console.log(chalk.dim('Delete template: rawi act --delete <template-id>'));\n};\n\nexport const showActTemplate = async (id: string): Promise<void> => {\n  const template = await findActTemplate(id);\n\n  if (!template) {\n    console.error(chalk.red(`❌ Act template '${id}' not found.`));\n    console.log(\n      chalk.yellow('💡 Use \"rawi act --list\" to see available templates.'),\n    );\n    return;\n  }\n\n  const isCustom = 'isBuiltIn' in template ? !template.isBuiltIn : false;\n\n  console.log(chalk.bold.cyan(`\\n🎭 Act Template: ${template.label}`));\n  console.log(chalk.blue(`ID: ${template.id}`));\n  console.log(chalk.blue(`Category: ${template.category}`));\n  console.log(\n    chalk.blue(\n      `Type: ${isCustom ? chalk.yellow('Custom') : chalk.gray('Built-in')}`,\n    ),\n  );\n\n  if (isCustom && 'createdAt' in template) {\n    const customTemplate = template as any;\n    console.log(\n      chalk.blue(\n        `Created: ${new Date(customTemplate.createdAt).toLocaleString()}`,\n      ),\n    );\n    console.log(\n      chalk.blue(\n        `Updated: ${new Date(customTemplate.updatedAt).toLocaleString()}`,\n      ),\n    );\n  }\n\n  console.log();\n  console.log(chalk.bold('Description:'));\n  console.log(chalk.white(template.description));\n  console.log();\n  console.log(chalk.bold('Template:'));\n  console.log(chalk.white(template.template));\n  console.log();\n  console.log(chalk.dim(`Usage: rawi ask --act ${template.id} \"{userInput}\"`));\n\n  if (isCustom) {\n    console.log(chalk.dim(`Edit: rawi act --edit ${template.id}`));\n    console.log(chalk.dim(`Delete: rawi act --delete ${template.id}`));\n  }\n};\n\nexport const applyActTemplate = async (\n  templateId: string,\n  userInput: string,\n): Promise<string> => {\n  const template = await findActTemplate(templateId);\n\n  if (!template) {\n    throw new Error(`Act template '${templateId}' not found`);\n  }\n\n  return template.template.replace('{userInput}', userInput);\n};\n"]}