okami.mom/strata

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

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
7.0 KiB96 linesraw
1/**
2 * Plain words for the app. Whatever the updater says (HTTP codes, hash names, exit codes, file names) stays in `details`, which the UI
3 * shows behind the existing "Details" disclosure; the main text says what happened and the one next step (`next`). The Terminal keeps
4 * the precise messages: this module is only used on the app side.
5 */
6
7export const PHASE_TEXT = {
8  feed: 'Looking for updates…',
9  download: 'Downloading…',
10  verify: 'Checking the download…',
11  test: 'Making sure it works…',
12  switch: 'Finishing up…',
13  done: 'Done.',
14};
15
16/** The job line while an update waits for Control's update lock (another update or the app's own check holds it). Wording awaits the owner (lane APP-LIN item 4). */
17export const UPDATE_WAITING_FOR_LOCK = 'Waiting for the update check to finish…';
18
19/** True when the failure looks like a computer with no internet (no DNS, no route, refused), not a slow or broken server. */
20export function looksOffline(error) {
21  const text = [error?.message, error?.cause?.message, error?.cause?.code, error?.code, error].filter(x => typeof x === 'string').join(' ');
22  return /ENOTFOUND|EAI_AGAIN|ENETUNREACH|ENETDOWN|EHOSTUNREACH|ECONNREFUSED|getaddrinfo|fetch failed|network is unreachable|name or service not known|temporary failure in name resolution|nodename nor servname|No address associated|URLError/i.test(text);
23}
24export const OFFLINE_MESSAGE = "No internet connection. Try again when you're online.";
25
26/** { message, details, next } for an error thrown by Control's update calls (or the shell bridge). `subject` is "engine" or "Strata".
27 * `retry` names the button of a screen that has no Settings page yet (the first-run card's Continue): the next step then says that button. */
28export function plainUpdateError(error, subject = 'engine', retry = undefined) {
29  const raw = String(error?.message ?? error ?? '');
30  const code = error?.code ?? '';
31  const exit = error?.exitCode ?? null;
32  const button = `Update ${subject === 'engine' ? 'engine' : 'Strata'}`;
33  const keep = 'Your current version still works.';
34  let message = `The update didn't finish and nothing was changed. ${keep}`;
35  let next = `Press ${button} in Settings to try again.`;
36  // Exit 7 is also the update lock (another update or a check holds it): told by its text, and checked first (QAGUI 0213 finding 3).
37  if (code === 'update_busy' || /another update is already running/i.test(raw)) {
38    message = 'An update is already running.';
39    next = `Wait a moment, then press ${button} in Settings.`;
40  } else if (code === 'engine_serving' || exit === 7 || /is serving/i.test(raw)) {
41    message = 'A model is running, so nothing was changed.';
42    next = `Unload the model in Models, then press ${button} in Settings.`;
43  } else if (/test start|did not start correctly|did not answer a one-token|did not become ready/i.test(raw)) {
44    message = `The new ${subject} didn't start correctly, so nothing was changed. ${keep}`;
45  } else if (looksOffline(error) || looksOffline(raw)) {
46    message = 'No internet connection.';
47    next = "Try again when you're online.";
48  } else if (/could not be read|interrupted|timed out|timeout|ECONN|ENOTFOUND|fetch failed|could not reach|server answered|not answer within/i.test(raw)) {
49    message = "Couldn't reach the update server.";
50    next = `Check your internet connection, then press ${button} in Settings.`;
51  } else if (/free space|not enough|no space left|disk is full/i.test(raw)) {
52    message = 'There is not enough free disk space for the update.';
53    next = `Free some disk space, then press ${button} in Settings.`;
54  } else if (/could not be moved into place|could not be unpacked|not accepted after the switch/i.test(raw)) {
55    // The files were downloaded and checked; Windows or a virus scanner would not let Strata put them in place (#4853). Not a download problem.
56    const long = /longer than Windows allows|path.*too long/i.test(raw);
57    message = long
58      ? "The engine's folder is too deep for Windows, so it could not be put in place."
59      : 'The engine was downloaded and checked, but Windows or a security program would not let Strata put it in place.';
60    next = long
61      ? `Open Details, then follow the folder advice there, and press ${button} in Settings.`
62      : `Wait a minute, then press ${button} in Settings. If it happens again, pause your virus scanner's live scanning for a few minutes while it runs.`;
63  } else if (/no engine for this PC|has no engine|no package/i.test(raw)) {
64    message = "There isn't an engine for this PC's graphics card yet.";
65    next = 'Check for updates again later.';
66  } else if (/trusts no update key/i.test(raw)) {
67    message = "Updates aren't available in this version of Strata yet.";
68    next = 'They will be after the next version.';
69  } else if (/signature|SHA-256|does not match|not trusted|expired|older than|replayed|integrity|refused/i.test(raw) || exit === 5) {
70    message = `The update didn't pass its safety check, so it was not installed. ${keep}`;
71    next = 'Try again later.';
72  }
73  if (retry) next = next.split(`${button} in Settings`).join(retry).replace(/in Settings/g, '').replace(/ {2,}/g, ' ').replace(/ ([.,])/g, '$1');
74  return { message: `${message} ${next}`.trim(), headline: message, next, details: raw || undefined };
75}
76
77/** Plain words for a switch or a delete in Settings > Engine: { message, details }. Control's own sentence for "the engine in use" is already plain and is kept. */
78export function plainEngineError(error, action = 'switch') {
79  const raw = String(error?.message ?? error ?? '');
80  const exit = error?.exitCode ?? null;
81  let message = action === 'delete' ? "The engine wasn't deleted. Nothing else was changed." : "The engine wasn't switched. Nothing was changed.";
82  if (/another update is already running/i.test(raw)) message = 'An update is running. Wait for it to finish, then try again.';
83  else if (exit === 7 || /is serving|model is running/i.test(raw)) message = 'A model is running, so nothing was changed. Unload the model in Models, then try again.';
84  else if (/engine in use/i.test(raw)) message = 'This is the engine in use. Switch to another one first, then delete it.';
85  else if (/running program is using|something is using it/i.test(raw)) message = 'A program is still using this engine, so it was not deleted. Unload your models and try again.';
86  else if (/not installed|already been deleted/i.test(raw)) message = 'That engine is already gone. The list has been refreshed.';
87  else if (/another update is already running/i.test(raw)) message = 'An update is running. Wait for it to finish, then try again.';
88  else if (exit === 5 || /can no longer be used|does not fit|cannot run/i.test(raw)) message = "This engine can't run on this computer, so nothing was changed.";
89  return { message, details: raw || undefined };
90}
91
92/** An Error carrying the plain message and, behind it, the technical reason. */
93export function plainError(error, subject, retry = undefined) {
94  const { message, details } = plainUpdateError(error, subject, retry);
95  return Object.assign(new Error(message), { details, code: error?.code });
96}