@widgetic/creator 0.4.43 → 0.4.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CreatorApp.svelte +88 -37
- package/dist/CreatorApp.svelte.d.ts +1 -0
- package/dist/components/WidgetDetails.svelte +18 -4
- package/dist/creator-types.d.ts +5 -0
- package/dist/errors/toUserFriendlyError.d.ts +44 -0
- package/dist/errors/toUserFriendlyError.js +236 -0
- package/dist/i18n/language.d.ts +77 -119
- package/dist/i18n/messages.d.ts +9 -0
- package/dist/i18n/messages.js +9 -0
- package/dist/i18n/statusText.d.ts +8 -3
- package/dist/i18n/statusText.js +48 -12
- package/dist/pageHelpers.d.ts +9 -3
- package/dist/pageHelpers.js +37 -15
- package/package.json +11 -11
package/dist/i18n/statusText.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { friendlyTextFromStoredError, isLikelyTechnicalError, } from '../errors/toUserFriendlyError.js';
|
|
1
2
|
/** The texts the creator writes, one by one. */
|
|
2
3
|
const KNOWN_TEXTS = new Map([
|
|
3
4
|
['Ready', (t) => t('creator.status.ready')],
|
|
@@ -74,10 +75,34 @@ const KNOWN_TEXTS = new Map([
|
|
|
74
75
|
['An unknown error occurred.', (t) => t('creator.error.anUnknownErrorOccurred')],
|
|
75
76
|
['Could not reach the server. Try again.', (t) => t('creator.error.couldNotReachTheServer')],
|
|
76
77
|
['Build failed.', (t) => t('creator.error.buildFailed')],
|
|
78
|
+
['Code generation is not available right now. Please try again later.', (t) => t('creator.error.codeGenerationUnavailable')],
|
|
79
|
+
['This feature is not available right now. Please try again later.', (t) => t('creator.error.featureUnavailable')],
|
|
80
|
+
['This took too long. Please try again.', (t) => t('creator.error.requestTimedOut')],
|
|
81
|
+
["You don't have permission to do that.", (t) => t('creator.error.permissionDenied')],
|
|
82
|
+
['Something was wrong with the request. Please check your input and try again.', (t) => t('creator.error.invalidRequest')],
|
|
83
|
+
['Something went wrong on our side. Please try again in a moment.', (t) => t('creator.error.serverError')],
|
|
84
|
+
['Something went wrong. Please try again.', (t) => t('creator.error.somethingWentWrong')],
|
|
85
|
+
["We couldn't find this sketch. It may have been deleted.", (t) => t('creator.error.canvasNotFound')],
|
|
86
|
+
["We couldn't find that. It may have been deleted.", (t) => t('creator.error.resourceNotFound')],
|
|
77
87
|
]);
|
|
88
|
+
function resolveStoredErrorText(text, t, display) {
|
|
89
|
+
const known = sayKnown(text, t);
|
|
90
|
+
if (known !== null)
|
|
91
|
+
return known;
|
|
92
|
+
const friendly = friendlyTextFromStoredError(text, {
|
|
93
|
+
debugMode: display?.debugMode === true,
|
|
94
|
+
context: display?.context ?? 'generic',
|
|
95
|
+
});
|
|
96
|
+
return sayKnown(friendly, t) ?? friendly;
|
|
97
|
+
}
|
|
78
98
|
/** The texts that have a value inside them. */
|
|
79
99
|
const KNOWN_PATTERNS = [
|
|
80
|
-
{
|
|
100
|
+
{
|
|
101
|
+
pattern: /^Code generation failed: ([\s\S]+)$/,
|
|
102
|
+
say: (found, t, display) => t('creator.status.failedWithReason', {
|
|
103
|
+
reason: resolveStoredErrorText(found[1], t, { ...display, context: display?.context ?? 'codeGeneration' }),
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
81
106
|
{ pattern: /^Reconnected — code generation in progress\.\.\. (\d+)%$/, say: (found, t) => t('creator.status.reconnected', { progress: found[1] }) },
|
|
82
107
|
{ pattern: /^Generating code\.\.\. \((\d+)%\)$/, say: (found, t) => t('creator.status.generatingProgress', { progress: found[1] }) },
|
|
83
108
|
// The same two "already saved" lines with the commit the creator names in them
|
|
@@ -162,14 +187,14 @@ const CONVERSATION_PATTERNS = [
|
|
|
162
187
|
/** A mark before the words (`❌ `, `⚠️ `, `⏹ `): the creator writes it in front of a status line, and it needs no translation. */
|
|
163
188
|
const LEADING_MARK = /^[^\p{L}\p{N}]+\s+/u;
|
|
164
189
|
/** The text in the visitor's language, or `null` when the creator does not know the text. */
|
|
165
|
-
function sayKnown(text, t) {
|
|
190
|
+
function sayKnown(text, t, display) {
|
|
166
191
|
const known = KNOWN_TEXTS.get(text);
|
|
167
192
|
if (known)
|
|
168
193
|
return known(t);
|
|
169
194
|
for (const { pattern, say } of KNOWN_PATTERNS) {
|
|
170
195
|
const found = pattern.exec(text);
|
|
171
196
|
if (found)
|
|
172
|
-
return say(found, t);
|
|
197
|
+
return say(found, t, display);
|
|
173
198
|
}
|
|
174
199
|
return null;
|
|
175
200
|
}
|
|
@@ -190,7 +215,7 @@ export function isKnownText(text) {
|
|
|
190
215
|
* language when the host passes this through the chat's `storedLineLabel` (the widget creator does). A line the table does
|
|
191
216
|
* not know (an assistant reply from the model) is shown as it is.
|
|
192
217
|
*/
|
|
193
|
-
export function conversationLineLabel(content, t) {
|
|
218
|
+
export function conversationLineLabel(content, t, display) {
|
|
194
219
|
const text = typeof content === 'string' ? content : '';
|
|
195
220
|
if (text.trim() === '')
|
|
196
221
|
return text;
|
|
@@ -201,15 +226,20 @@ export function conversationLineLabel(content, t) {
|
|
|
201
226
|
}
|
|
202
227
|
const lines = text.split('\n');
|
|
203
228
|
if (lines.length === 1)
|
|
204
|
-
return statusLabel(text, t);
|
|
229
|
+
return statusLabel(text, t, display);
|
|
205
230
|
return lines
|
|
206
231
|
.map((line) => {
|
|
207
232
|
if (line.trim() === '')
|
|
208
233
|
return line;
|
|
209
234
|
const mark = LEADING_MARK.exec(line)?.[0] ?? '';
|
|
210
235
|
const core = line.slice(mark.length);
|
|
211
|
-
const said = sayKnown(core, t);
|
|
212
|
-
|
|
236
|
+
const said = sayKnown(core, t, display);
|
|
237
|
+
if (said !== null)
|
|
238
|
+
return `${mark}${said}`;
|
|
239
|
+
if (isLikelyTechnicalError(core)) {
|
|
240
|
+
return `${mark}${resolveStoredErrorText(core, t, display)}`;
|
|
241
|
+
}
|
|
242
|
+
return line;
|
|
213
243
|
})
|
|
214
244
|
.join('\n');
|
|
215
245
|
}
|
|
@@ -217,21 +247,27 @@ export function conversationLineLabel(content, t) {
|
|
|
217
247
|
* What the status bar of a code generation shows for a status line the creator stored. Nothing stored is `Ready`; a line
|
|
218
248
|
* the creator does not know (one that came from the server) is shown as it is.
|
|
219
249
|
*/
|
|
220
|
-
export function statusLabel(status, t) {
|
|
250
|
+
export function statusLabel(status, t, display) {
|
|
221
251
|
const text = typeof status === 'string' ? status.trim() : '';
|
|
222
252
|
if (text === '')
|
|
223
253
|
return t('creator.status.ready');
|
|
224
254
|
const mark = LEADING_MARK.exec(text)?.[0] ?? '';
|
|
225
|
-
const
|
|
226
|
-
|
|
255
|
+
const core = text.slice(mark.length);
|
|
256
|
+
const said = sayKnown(core, t, display);
|
|
257
|
+
if (said !== null)
|
|
258
|
+
return `${mark}${said}`;
|
|
259
|
+
if (isLikelyTechnicalError(core)) {
|
|
260
|
+
return `${mark}${resolveStoredErrorText(core, t, display)}`;
|
|
261
|
+
}
|
|
262
|
+
return text;
|
|
227
263
|
}
|
|
228
264
|
/**
|
|
229
265
|
* What a screen shows for an error text the creator stored. Nothing stored is an empty text (so a screen can write
|
|
230
266
|
* `errorLabel(error, t) || fallback`); an error the creator does not know is shown as it is.
|
|
231
267
|
*/
|
|
232
|
-
export function errorLabel(error, t) {
|
|
268
|
+
export function errorLabel(error, t, display) {
|
|
233
269
|
const text = typeof error === 'string' ? error.trim() : '';
|
|
234
270
|
if (text === '')
|
|
235
271
|
return '';
|
|
236
|
-
return
|
|
272
|
+
return resolveStoredErrorText(text, t, display);
|
|
237
273
|
}
|
package/dist/pageHelpers.d.ts
CHANGED
|
@@ -2,16 +2,22 @@
|
|
|
2
2
|
* Pure helper functions extracted from +page.svelte to reduce file size
|
|
3
3
|
* and prevent rollup AST recursion overflow during production builds.
|
|
4
4
|
*/
|
|
5
|
+
import { type UserFriendlyErrorContext } from './errors/toUserFriendlyError.js';
|
|
6
|
+
export { formatUserFacingErrorText, friendlyTextFromStoredError, type UserFriendlyErrorContext, } from './errors/toUserFriendlyError.js';
|
|
5
7
|
export declare function looksLikeHtmlErrorPage(raw: string | null | undefined): boolean;
|
|
6
8
|
/** Cloudflare Worker / gateway HTML dumps must never appear in chat, preview, or Edit. */
|
|
7
9
|
export declare function sanitizePreviewBuildError(raw: string | null | undefined): string;
|
|
8
10
|
export declare function isInfrastructurePreviewError(raw: string | null | undefined): boolean;
|
|
9
11
|
export declare function normalizeErrorMessage(rawError: string | Error | unknown): string;
|
|
12
|
+
export type UserFacingErrorOptions = {
|
|
13
|
+
debugMode?: boolean;
|
|
14
|
+
context?: UserFriendlyErrorContext;
|
|
15
|
+
};
|
|
10
16
|
/** A GitLab 429 is shown as that sentence, not as a generic code-generation failure. */
|
|
11
|
-
export declare function codegenFailureChatLine(errorText: string): string;
|
|
12
|
-
export declare function toErrorMessage(error: unknown, fallback: string): string;
|
|
17
|
+
export declare function codegenFailureChatLine(errorText: string, options?: UserFacingErrorOptions): string;
|
|
18
|
+
export declare function toErrorMessage(error: unknown, fallback: string, options?: UserFacingErrorOptions): string;
|
|
13
19
|
export declare function extractDetailsMessage(payload: unknown): string | null;
|
|
14
|
-
export declare function deriveApiErrorMessage(error: unknown, defaultMessage: string): Promise<string>;
|
|
20
|
+
export declare function deriveApiErrorMessage(error: unknown, defaultMessage: string, options?: UserFacingErrorOptions): Promise<string>;
|
|
15
21
|
export declare function decodeJWT(token: string): Record<string, unknown> | null;
|
|
16
22
|
export declare function isTokenExpired(token: string): boolean;
|
|
17
23
|
export declare function fileToBase64(file: File): Promise<string>;
|
package/dist/pageHelpers.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* and prevent rollup AST recursion overflow during production builds.
|
|
4
4
|
*/
|
|
5
5
|
import { ResponseError } from '@widgetic/api-sdk';
|
|
6
|
+
import { formatUserFacingErrorText, friendlyTextFromStoredError, } from './errors/toUserFriendlyError.js';
|
|
7
|
+
export { formatUserFacingErrorText, friendlyTextFromStoredError, } from './errors/toUserFriendlyError.js';
|
|
6
8
|
// ===================== Error Handling Helpers =====================
|
|
7
9
|
const HTML_ERROR_PAGE_RE = /^\s*(<!DOCTYPE\s+html|<html[\s>]|<!--\[if\s+lt\s+IE)/i;
|
|
8
10
|
const CLOUDFLARE_ERROR_PAGE_RE = /<title>\s*Page not found\s*<\/title>|workers\.cloudflare|error code:\s*1042/i;
|
|
@@ -83,25 +85,39 @@ export function normalizeErrorMessage(rawError) {
|
|
|
83
85
|
return extracted.length > 400 ? `${extracted.slice(0, 400)}…` : extracted;
|
|
84
86
|
}
|
|
85
87
|
/** A GitLab 429 is shown as that sentence, not as a generic code-generation failure. */
|
|
86
|
-
export function codegenFailureChatLine(errorText) {
|
|
88
|
+
export function codegenFailureChatLine(errorText, options = {}) {
|
|
89
|
+
const debugMode = options.debugMode === true;
|
|
90
|
+
const context = options.context ?? 'codeGeneration';
|
|
87
91
|
const text = errorText.trim();
|
|
88
|
-
if (
|
|
92
|
+
if (/^⚠️/.test(text))
|
|
89
93
|
return text;
|
|
90
94
|
if (/gitlab rate limit|gitlab refused the (save|rollback)|last status code:\s*429/i.test(text)) {
|
|
91
95
|
return `⚠️ ${text}`;
|
|
92
96
|
}
|
|
93
|
-
|
|
97
|
+
// The stored text may already start with "Code generation failed:"; the friendly text is made without that prefix.
|
|
98
|
+
const friendly = friendlyTextFromStoredError(text, { debugMode, context });
|
|
99
|
+
return `Code generation failed: ${friendly}`;
|
|
94
100
|
}
|
|
95
|
-
export function toErrorMessage(error, fallback) {
|
|
101
|
+
export function toErrorMessage(error, fallback, options = {}) {
|
|
102
|
+
const debugMode = options.debugMode === true;
|
|
103
|
+
const context = options.context ?? 'generic';
|
|
96
104
|
if (error instanceof Error && error.message) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
if (looksLikeHtmlErrorPage(error.message)) {
|
|
106
|
+
return sanitizePreviewBuildError(error.message);
|
|
107
|
+
}
|
|
108
|
+
return formatUserFacingErrorText(error, { debugMode, context });
|
|
100
109
|
}
|
|
101
110
|
if (typeof error === 'string' && error.trim().length > 0) {
|
|
102
|
-
|
|
111
|
+
if (looksLikeHtmlErrorPage(error))
|
|
112
|
+
return sanitizePreviewBuildError(error);
|
|
113
|
+
return formatUserFacingErrorText(error, { debugMode, context });
|
|
114
|
+
}
|
|
115
|
+
if (error !== undefined && error !== null) {
|
|
116
|
+
const formatted = formatUserFacingErrorText(error, { debugMode, context });
|
|
117
|
+
if (formatted)
|
|
118
|
+
return formatted;
|
|
103
119
|
}
|
|
104
|
-
return fallback;
|
|
120
|
+
return friendlyTextFromStoredError(fallback, { debugMode, context });
|
|
105
121
|
}
|
|
106
122
|
export function extractDetailsMessage(payload) {
|
|
107
123
|
if (!payload) {
|
|
@@ -136,24 +152,30 @@ export function extractDetailsMessage(payload) {
|
|
|
136
152
|
}
|
|
137
153
|
return null;
|
|
138
154
|
}
|
|
139
|
-
export async function deriveApiErrorMessage(error, defaultMessage) {
|
|
155
|
+
export async function deriveApiErrorMessage(error, defaultMessage, options = {}) {
|
|
156
|
+
const debugMode = options.debugMode === true;
|
|
157
|
+
const context = options.context ?? 'codeGeneration';
|
|
140
158
|
const response = error instanceof ResponseError
|
|
141
159
|
? error.response
|
|
142
160
|
: error?.response;
|
|
161
|
+
let detailFromBody = null;
|
|
143
162
|
if (response) {
|
|
144
163
|
try {
|
|
145
164
|
const cloned = response.clone();
|
|
146
165
|
const payload = await cloned.json();
|
|
147
|
-
|
|
148
|
-
if (derived) {
|
|
149
|
-
return derived;
|
|
150
|
-
}
|
|
166
|
+
detailFromBody = extractDetailsMessage(payload?.error ?? payload);
|
|
151
167
|
}
|
|
152
168
|
catch {
|
|
153
169
|
// ignore JSON parsing issues
|
|
154
170
|
}
|
|
155
171
|
}
|
|
156
|
-
|
|
172
|
+
const friendlyInput = detailFromBody && response
|
|
173
|
+
? { message: detailFromBody, response }
|
|
174
|
+
: detailFromBody ?? error ?? defaultMessage;
|
|
175
|
+
const formatted = formatUserFacingErrorText(friendlyInput, { debugMode, context });
|
|
176
|
+
if (formatted)
|
|
177
|
+
return formatted;
|
|
178
|
+
return friendlyTextFromStoredError(defaultMessage, { debugMode, context });
|
|
157
179
|
}
|
|
158
180
|
// ===================== JWT Helpers =====================
|
|
159
181
|
function base64UrlDecode(base64UrlString) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/creator",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.45",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@sveltejs/kit": "^2.20.0",
|
|
8
8
|
"@widgetic/api-sdk": "^2.0.0",
|
|
9
9
|
"@widgetic/cache-layer": "^0.1.2",
|
|
10
|
-
"@widgetic/canvas": "^0.5.
|
|
11
|
-
"@widgetic/chat": "^0.1.
|
|
12
|
-
"@widgetic/design-system": "^0.5.
|
|
13
|
-
"@widgetic/editor": "^4.
|
|
14
|
-
"@widgetic/file-browser": "^0.5.
|
|
10
|
+
"@widgetic/canvas": "^0.5.36",
|
|
11
|
+
"@widgetic/chat": "^0.1.36",
|
|
12
|
+
"@widgetic/design-system": "^0.5.32",
|
|
13
|
+
"@widgetic/editor": "^4.1.3",
|
|
14
|
+
"@widgetic/file-browser": "^0.5.25",
|
|
15
15
|
"svelte": "^5.25.0"
|
|
16
16
|
},
|
|
17
17
|
"svelte": "./dist/index.js",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"@types/node": "26.4.0",
|
|
75
75
|
"@widgetic/api-sdk": "^2.0.0",
|
|
76
76
|
"@widgetic/cache-layer": "^0.1.2",
|
|
77
|
-
"@widgetic/canvas": "^0.5.
|
|
78
|
-
"@widgetic/chat": "^0.1.
|
|
79
|
-
"@widgetic/design-system": "^0.5.
|
|
77
|
+
"@widgetic/canvas": "^0.5.36",
|
|
78
|
+
"@widgetic/chat": "^0.1.36",
|
|
79
|
+
"@widgetic/design-system": "^0.5.32",
|
|
80
80
|
"@widgetic/dev-tools": "^0.3.0",
|
|
81
|
-
"@widgetic/editor": "^4.
|
|
82
|
-
"@widgetic/file-browser": "^0.5.
|
|
81
|
+
"@widgetic/editor": "^4.1.3",
|
|
82
|
+
"@widgetic/file-browser": "^0.5.25",
|
|
83
83
|
"autoprefixer": "^10.4.20",
|
|
84
84
|
"eslint": "^9.0.0",
|
|
85
85
|
"eslint-config-prettier": "^9.1.0",
|