okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-ui2 baeb4533b (approved UI designs, context fix, workspace default with rename, autotune progress) into f-split-intc5755ed83

main
3.3 KiB64 linesraw
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 {
8  const p = (ask.params ?? []).map(String);
9  switch (ask.id) {
10    case 'open-known-folder': return tr("Open your {0} folder in File Explorer?", p);
11    case 'open-folder': return tr("Open the folder {0} in File Explorer?", p);
12    case 'open-file': return tr("Open the file {0}?", p);
13    case 'open-explorer': return tr("Open File Explorer?");
14    case 'run-program': return tr("Run a program: {0}?", p);
15    case 'run-script': return tr("Run the script {0}?", p);
16    case 'run-steps': return tr("Run {0} steps on your computer?", p);
17    case 'run-command': return tr("Run a command on your computer?");
18    case 'delete': return tr("Delete {0}?", p);
19    case 'create-file': return tr("Create the file {0}?", p);
20    case 'create-folder': return tr("Create the folder {0}?", p);
21    case 'write-file': return tr("Write to the file {0}?", p);
22    case 'change-file': return tr("Change the file {0}?", p);
23    case 'copy': return tr("Copy {0}?", p);
24    case 'move': return tr("Move {0}?", p);
25    case 'rename': return tr("Rename {0}?", p);
26    case 'git': return tr("Run git {0}?", p);
27    case 'install': return tr("Install packages with {0}?", p);
28    case 'stop-task': return tr("Stop a background task?");
29    case 'open-page': return tr("Open the web page {0}?", p);
30    case 'use-tool': return tr("Use the connected tool {0}?", p);
31    default: return tr("Use the tool {0}?", p);
32  }
33}
34
35function askWhy(id?: string): string | null {
36  switch (id) {
37    case 'opens-window': return tr("A window will open. Nothing is changed.");
38    case 'run-program-why': return tr("It can change your computer.");
39    case 'delete-why': return tr("It is removed from your computer.");
40    case 'replaces-if-exists': return tr("Replaces the file if it already exists.");
41    case 'changes-repo': return tr("It changes the project's files or history.");
42    case 'install-why': return tr("It downloads software and changes your computer.");
43    case 'run-steps-why': return tr("More than one thing happens. Details shows each step.");
44    case 'run-command-why': return tr("Details shows exactly what it does.");
45    case 'use-tool-why': return tr("It can act on the service you connected.");
46    default: 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 {
52  const why = askWhy(ask.why);
53  if (ask.id.startsWith('open-') && ask.detail) return ask.detail;
54  return why ?? ask.detail ?? '';
55}
56
57export function askIcon(ask: Ask): IconName {
58  if (ask.id.startsWith('open-')) return ask.id === 'open-page' ? 'link' : 'folder';
59  if (ask.id === 'delete') return 'trash';
60  if (['create-file', 'write-file', 'change-file', 'copy', 'move', 'rename'].includes(ask.id)) return 'file';
61  if (ask.id === 'create-folder') return 'folder-plus';
62  if (['run-program', 'run-script', 'run-steps', 'run-command', 'git', 'install'].includes(ask.id)) return 'bolt';
63  return 'tool';
64}