okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c5755ed83
main
1import { tr } from './i18n' ; 2import type { IconName } from '../components/ui' ; 3 4/** The question and its one muted line for an approval card. The host names a sentence (server/agent/ask.mjs); the words are here, translated. */ 5export interface Ask { id :string ; params ?:( string | number )[]; why ?:string ; detail ?:string } 6 7export function askQuestion ( ask :Ask ) :string { 8const p = ( ask . params ?? []). map ( String ); 9switch ( ask . id ) { 10case 'open-known-folder' :return tr ( "Open your {0} folder in File Explorer?" , p ); 11case 'open-folder' :return tr ( "Open the folder {0} in File Explorer?" , p ); 12case 'open-file' :return tr ( "Open the file {0}?" , p ); 13case 'open-explorer' :return tr ( "Open File Explorer?" ); 14case 'run-program' :return tr ( "Run a program: {0}?" , p ); 15case 'run-script' :return tr ( "Run the script {0}?" , p ); 16case 'run-steps' :return tr ( "Run {0} steps on your computer?" , p ); 17case 'run-command' :return tr ( "Run a command on your computer?" ); 18case 'delete' :return tr ( "Delete {0}?" , p ); 19case 'create-file' :return tr ( "Create the file {0}?" , p ); 20case 'create-folder' :return tr ( "Create the folder {0}?" , p ); 21case 'write-file' :return tr ( "Write to the file {0}?" , p ); 22case 'change-file' :return tr ( "Change the file {0}?" , p ); 23case 'copy' :return tr ( "Copy {0}?" , p ); 24case 'move' :return tr ( "Move {0}?" , p ); 25case 'rename' :return tr ( "Rename {0}?" , p ); 26case 'git' :return tr ( "Run git {0}?" , p ); 27case 'install' :return tr ( "Install packages with {0}?" , p ); 28case 'stop-task' :return tr ( "Stop a background task?" ); 29case 'open-page' :return tr ( "Open the web page {0}?" , p ); 30case 'use-tool' :return tr ( "Use the connected tool {0}?" , p ); 31default :return tr ( "Use the tool {0}?" , p ); 32} 33} 34 35function askWhy ( id ?:string ) :string | null { 36switch ( id ) { 37case 'opens-window' :return tr ( "A window will open. Nothing is changed." ); 38case 'run-program-why' :return tr ( "It can change your computer." ); 39case 'delete-why' :return tr ( "It is removed from your computer." ); 40case 'replaces-if-exists' :return tr ( "Replaces the file if it already exists." ); 41case 'changes-repo' :return tr ( "It changes the project's files or history." ); 42case 'install-why' :return tr ( "It downloads software and changes your computer." ); 43case 'run-steps-why' :return tr ( "More than one thing happens. Details shows each step." ); 44case 'run-command-why' :return tr ( "Details shows exactly what it does." ); 45case 'use-tool-why' :return tr ( "It can act on the service you connected." ); 46default :return null ; 47} 48} 49 50/** The muted line under the question: the folder or file for "open" questions, otherwise what to know before answering. */ 51export function askSub ( ask :Ask ) :string { 52const why = askWhy ( ask . why ); 53if ( ask . id . startsWith ( 'open-' ) && ask . detail ) return ask . detail ; 54return why ?? ask . detail ?? '' ; 55} 56 57export function askIcon ( ask :Ask ) :IconName { 58if ( ask . id . startsWith ( 'open-' )) return ask . id === 'open-page' ?'link' :'folder' ; 59if ( ask . id === 'delete' ) return 'trash' ; 60if ([ 'create-file' , 'write-file' , 'change-file' , 'copy' , 'move' , 'rename' ]. includes ( ask . id )) return 'file' ; 61if ( ask . id === 'create-folder' ) return 'folder-plus' ; 62if ([ 'run-program' , 'run-script' , 'run-steps' , 'run-command' , 'git' , 'install' ]. includes ( ask . id )) return 'bolt' ; 63return 'tool' ; 64}