- The self-review follow-up sends intent:'review' + review_image_ids instead of putting the render in mockup_ids, so the backend builds a critique+patch instruction instead of 'build toward this mockup'. Render still deleted after. - types/sitesmith.ts: SitesmithStatus = server statuses (adds IMAGES_BUSY, TOO_MANY_JOBS, SERVER_BUSY, ...) + client statuses (TIMEOUT, ABORTED, ...); network status strings are narrowed with a type guard (unknown -> ERROR); the hook builds SendResultErr without casts. - statusMessages.ts: one specific message per status (a Record over the union, so a new status without a message fails tsc), used by the modal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
4.3 KiB
TypeScript
51 lines
4.3 KiB
TypeScript
/**
|
|
* One specific, plain-language message per Sitesmith failure status (backend statuses from
|
|
* WHP docs/sitesmith-backend.md + the editor transport's own). `preferServer`: the server's text
|
|
* for that status carries the useful detail (which image, why), so it is shown when present.
|
|
* A Record over the full union, so adding a status without a message fails `tsc`.
|
|
*/
|
|
import type { SendResultErr, SitesmithStatus } from '../../types/sitesmith';
|
|
import { MSG_LOST, MSG_NETWORK, MSG_TIMEOUT } from '../../hooks/useSitesmith';
|
|
|
|
export const STATUS_MESSAGES: Record<SitesmithStatus, { text: string; preferServer?: boolean }> = {
|
|
OK_BONUS: { text: 'Sitesmith is ready (using a bonus credit).' },
|
|
OK_MONTHLY: { text: 'Sitesmith is ready (using this month\'s allowance).' },
|
|
DISABLED: { text: 'Sitesmith is not enabled for your account. Contact support to turn it on.' },
|
|
CAP_REACHED: { text: 'You have used all of this month\'s Sitesmith requests. They reset at the start of next month.' },
|
|
USER_KILLSWITCH: { text: 'You have reached today\'s Sitesmith spending limit. It resets tomorrow.' },
|
|
SERVER_KILLSWITCH: { text: 'Sitesmith has reached this server\'s daily limit. Please try again tomorrow.' },
|
|
RATE_LIMITED: { text: 'Too many Sitesmith requests in a short time. Wait a minute and try again.' },
|
|
BLOCKED: { text: 'Your message was blocked by the content guard. Please rephrase it and try again.', preferServer: true },
|
|
AI_ERROR: { text: 'The AI service had a problem answering. Please try again in a moment.', preferServer: true },
|
|
AI_INVALID: { text: 'The AI returned something Sitesmith could not use. Please try again, perhaps with a simpler request.' },
|
|
BAD_ATTACHMENT: { text: 'One of the attached images or example sites could not be used. Remove it and try again.', preferServer: true },
|
|
IMAGES_BUSY: { text: 'The server is busy preparing other images, so your attached images could not be prepared. Try again in a moment.' },
|
|
INTERRUPTED: { text: 'Sitesmith stopped unexpectedly (the server may have restarted). Nothing was changed; please try again.' },
|
|
CANCELLED: { text: 'Cancelled. Nothing was changed on your page.' },
|
|
JOB_IN_PROGRESS: { text: 'Sitesmith is still working on your previous request for this site. Wait for it to finish, or reopen Sitesmith to follow it.' },
|
|
TOO_MANY_JOBS: { text: 'Sitesmith is already working on your other requests. Wait for one of them to finish, then try again.' },
|
|
SERVER_BUSY: { text: 'Sitesmith is busy on this server right now. Please try again in a minute.' },
|
|
NETWORK: { text: MSG_NETWORK },
|
|
TIMEOUT: { text: MSG_TIMEOUT },
|
|
ABORTED: { text: 'Stopped waiting for Sitesmith. It may still finish in the background; reopen Sitesmith to see the result.' },
|
|
LOST_CONNECTION: { text: MSG_LOST },
|
|
AUTH_REQUIRED: { text: 'Your session has expired. Refresh the page and sign in again, then retry.' },
|
|
FORBIDDEN: { text: 'The request was blocked by a security filter or proxy before it reached Sitesmith. Try again; if it keeps happening, contact support.', preferServer: true },
|
|
TOO_LARGE: { text: 'That request was too large for the server to accept. Try a shorter message or a smaller image.', preferServer: true },
|
|
SERVER_ERROR: { text: 'The server had a problem handling the request. Try again in a minute.', preferServer: true },
|
|
BAD_RESPONSE: { text: 'The server sent a reply Sitesmith could not read. Try again, and refresh the page if it persists.', preferServer: true },
|
|
JOB_NOT_FOUND: { text: 'That Sitesmith request was not found; it may have expired. Check the history.', preferServer: true },
|
|
ERROR: { text: 'Something went wrong while talking to Sitesmith. Please try again.', preferServer: true },
|
|
};
|
|
|
|
const BROWSER_ERROR = /NetworkError|Failed to fetch|Load failed|network request failed|AbortError/i;
|
|
|
|
/** The message to show for a failed send/poll result. */
|
|
export function failureMessage(res: SendResultErr): string {
|
|
const entry = STATUS_MESSAGES[res.status] ?? STATUS_MESSAGES.ERROR;
|
|
const server = (res.message ?? '').trim();
|
|
if (BROWSER_ERROR.test(server)) return STATUS_MESSAGES.NETWORK.text;
|
|
if (entry.preferServer && server && server.length <= 600 && !/<\/?[a-z][^>]*>/i.test(server)) return server;
|
|
return entry.text;
|
|
}
|