@widgetic/creator 0.4.27 → 0.4.28
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
CHANGED
|
@@ -191,6 +191,7 @@
|
|
|
191
191
|
type GenerationChannel,
|
|
192
192
|
type OperationSnapshot
|
|
193
193
|
} from './utils/generationSharing.js';
|
|
194
|
+
import { failureNoticeChanges } from './utils/failureNotice.js';
|
|
194
195
|
import { generateEmbedCode, EMBED_FORMATS, type EmbedFormat } from './utils/embedCode.js';
|
|
195
196
|
|
|
196
197
|
function openEmbedTestPage(href: string) {
|
|
@@ -12750,12 +12751,24 @@ Requirements:
|
|
|
12750
12751
|
// that rebuild ran on the same turn the generation finished.
|
|
12751
12752
|
if (statusOnly) {
|
|
12752
12753
|
const snap = widgetPanelSnapshots[widgetId];
|
|
12754
|
+
// The failure notice the panel shows right now, read before the patch lands: the focused panel is drawn from the
|
|
12755
|
+
// globals, the others from their snapshot.
|
|
12756
|
+
const failureNoticeShown = widgetId === focusedPanelWidgetId ? { lastGenerationFailed, lastGenerationError } : snap;
|
|
12757
|
+
const failureNoticeChanged = failureNoticeChanges(failureNoticeShown, nextPatch);
|
|
12753
12758
|
if (snap) Object.assign(snap, nextPatch);
|
|
12754
12759
|
if (widgetId === focusedPanelWidgetId) {
|
|
12755
12760
|
if (nextPatch.generateCodeStatus !== undefined) generateCodeStatus = nextPatch.generateCodeStatus;
|
|
12756
12761
|
if (nextPatch.lastGenerationFailed !== undefined) lastGenerationFailed = nextPatch.lastGenerationFailed;
|
|
12757
12762
|
if (nextPatch.lastGenerationError !== undefined) lastGenerationError = nextPatch.lastGenerationError;
|
|
12758
12763
|
}
|
|
12764
|
+
// A progress line stays free, but the failure notice is drawn from the display state that only a new revision reads
|
|
12765
|
+
// again. Without this bump a generation that failed or that the gateway refused left the status line on "Status: ..."
|
|
12766
|
+
// with no "Generation Failed", and the note with its message and Retry never came up (the Dismiss button of that note
|
|
12767
|
+
// moves the revision by hand for the same reason).
|
|
12768
|
+
if (failureNoticeChanged) {
|
|
12769
|
+
panelDisplayRevision += 1;
|
|
12770
|
+
if (debugMode) console.debug('[FailureNotice] The failure notice of a panel changed; its status area is drawn again', { widgetId, failed: nextPatch.lastGenerationFailed ?? null });
|
|
12771
|
+
}
|
|
12759
12772
|
return;
|
|
12760
12773
|
}
|
|
12761
12774
|
patchPanelSnapshot(widgetId, nextPatch);
|
|
@@ -14182,6 +14195,8 @@ Requirements:
|
|
|
14182
14195
|
}
|
|
14183
14196
|
|
|
14184
14197
|
function patchPanelSnapshot(widgetId: string, patch: Partial<WidgetPanelSnapshot>): void {
|
|
14198
|
+
// The failure notice the panel shows before the patch lands (a status-only patch below decides on it).
|
|
14199
|
+
const failureNoticeChanged = failureNoticeChanges(getPanelState(widgetId), patch);
|
|
14185
14200
|
widgetPanelSnapshots = {
|
|
14186
14201
|
...widgetPanelSnapshots,
|
|
14187
14202
|
[widgetId]: { ...getPanelState(widgetId), ...patch },
|
|
@@ -14192,7 +14207,11 @@ Requirements:
|
|
|
14192
14207
|
const statusOnly = patchKeys.length > 0 && patchKeys.every((key) =>
|
|
14193
14208
|
key === 'generateCodeStatus' || key === 'lastGenerationFailed' || key === 'lastGenerationError'
|
|
14194
14209
|
);
|
|
14195
|
-
if (statusOnly)
|
|
14210
|
+
if (statusOnly) {
|
|
14211
|
+
// A patch that raises or clears the failure notice moves the revision all the same (see patchCodegenUiState).
|
|
14212
|
+
if (failureNoticeChanged) panelDisplayRevision++;
|
|
14213
|
+
return;
|
|
14214
|
+
}
|
|
14196
14215
|
if (patch.publishHistoryResolved) {
|
|
14197
14216
|
if (widgetId === focusedPanelWidgetId) {
|
|
14198
14217
|
if (patch.publishHistory) publishHistory = [...patch.publishHistory];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* failureNotice: when the status area of a panel has to be drawn again because a generation failed.
|
|
3
|
+
*
|
|
4
|
+
* A panel draws its status area from a display state that is read again only when `panelDisplayRevision` moves (see
|
|
5
|
+
* `CreatorApp.svelte`). A progress line ("Generating code 40%") is patched in without moving it, on purpose: each tick used to
|
|
6
|
+
* rebuild everything that reads the panel's snapshot, the open chat included. That is right for progress and wrong for the one
|
|
7
|
+
* status that is not progress, the failure notice. A generation that failed, or that the gateway refused (no credits, over the
|
|
8
|
+
* budget), patched `lastGenerationFailed` and `lastGenerationError` the same way, so the screen kept the display state it had:
|
|
9
|
+
* the status line read "Status: ❌ ..." with no "Generation Failed" in red, and the note with the message and its Retry or Upgrade
|
|
10
|
+
* button never came up, although the chat told the visitor the generation had failed. Dismissing the note had the same trouble
|
|
11
|
+
* and moves the revision by hand (the "Dismiss" button); this is the rule for the patches that raise or clear the notice.
|
|
12
|
+
*
|
|
13
|
+
* What counts is what the notice shows, nothing else: a patch moves the revision when it changes the flag or the message, and
|
|
14
|
+
* never for a status text alone, so progress still costs nothing and a patch that repeats what is shown (a new generation
|
|
15
|
+
* clearing a notice that is already clear) does not rebuild anything.
|
|
16
|
+
*
|
|
17
|
+
* Kept free of Svelte and of the page so the rule is testable without a DOM.
|
|
18
|
+
*/
|
|
19
|
+
/** What a panel shows of a failed generation: the red "Generation Failed" line, and the note under it that carries the message. */
|
|
20
|
+
export interface FailureNotice {
|
|
21
|
+
lastGenerationFailed: boolean;
|
|
22
|
+
lastGenerationError: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** A panel's state, or a patch to it, as far as the notice goes: a key that is not there is not said. */
|
|
25
|
+
export type FailureNoticeSource = Partial<{
|
|
26
|
+
lastGenerationFailed: boolean | null;
|
|
27
|
+
lastGenerationError: string | null;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* The notice a panel state shows. A state with no flag is not failed, and a missing or empty message is no message (an empty
|
|
31
|
+
* note and no note read the same on the screen, so they are the same here).
|
|
32
|
+
*/
|
|
33
|
+
export declare function readFailureNotice(source: FailureNoticeSource | null | undefined): FailureNotice;
|
|
34
|
+
/**
|
|
35
|
+
* Whether applying `patch` to a panel that shows `shown` changes what the notice shows. A key the patch leaves out stays as it
|
|
36
|
+
* is, and a patch with no key of the notice (a progress line) never changes it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function failureNoticeChanges(shown: FailureNoticeSource | null | undefined, patch: FailureNoticeSource): boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* failureNotice: when the status area of a panel has to be drawn again because a generation failed.
|
|
3
|
+
*
|
|
4
|
+
* A panel draws its status area from a display state that is read again only when `panelDisplayRevision` moves (see
|
|
5
|
+
* `CreatorApp.svelte`). A progress line ("Generating code 40%") is patched in without moving it, on purpose: each tick used to
|
|
6
|
+
* rebuild everything that reads the panel's snapshot, the open chat included. That is right for progress and wrong for the one
|
|
7
|
+
* status that is not progress, the failure notice. A generation that failed, or that the gateway refused (no credits, over the
|
|
8
|
+
* budget), patched `lastGenerationFailed` and `lastGenerationError` the same way, so the screen kept the display state it had:
|
|
9
|
+
* the status line read "Status: ❌ ..." with no "Generation Failed" in red, and the note with the message and its Retry or Upgrade
|
|
10
|
+
* button never came up, although the chat told the visitor the generation had failed. Dismissing the note had the same trouble
|
|
11
|
+
* and moves the revision by hand (the "Dismiss" button); this is the rule for the patches that raise or clear the notice.
|
|
12
|
+
*
|
|
13
|
+
* What counts is what the notice shows, nothing else: a patch moves the revision when it changes the flag or the message, and
|
|
14
|
+
* never for a status text alone, so progress still costs nothing and a patch that repeats what is shown (a new generation
|
|
15
|
+
* clearing a notice that is already clear) does not rebuild anything.
|
|
16
|
+
*
|
|
17
|
+
* Kept free of Svelte and of the page so the rule is testable without a DOM.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The notice a panel state shows. A state with no flag is not failed, and a missing or empty message is no message (an empty
|
|
21
|
+
* note and no note read the same on the screen, so they are the same here).
|
|
22
|
+
*/
|
|
23
|
+
export function readFailureNotice(source) {
|
|
24
|
+
return {
|
|
25
|
+
lastGenerationFailed: source?.lastGenerationFailed === true,
|
|
26
|
+
lastGenerationError: source?.lastGenerationError ? source.lastGenerationError : null
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether applying `patch` to a panel that shows `shown` changes what the notice shows. A key the patch leaves out stays as it
|
|
31
|
+
* is, and a patch with no key of the notice (a progress line) never changes it.
|
|
32
|
+
*/
|
|
33
|
+
export function failureNoticeChanges(shown, patch) {
|
|
34
|
+
const before = readFailureNotice(shown);
|
|
35
|
+
const after = readFailureNotice({
|
|
36
|
+
lastGenerationFailed: patch.lastGenerationFailed === undefined
|
|
37
|
+
? before.lastGenerationFailed
|
|
38
|
+
: patch.lastGenerationFailed,
|
|
39
|
+
lastGenerationError: patch.lastGenerationError === undefined
|
|
40
|
+
? before.lastGenerationError
|
|
41
|
+
: patch.lastGenerationError
|
|
42
|
+
});
|
|
43
|
+
return (before.lastGenerationFailed !== after.lastGenerationFailed ||
|
|
44
|
+
before.lastGenerationError !== after.lastGenerationError);
|
|
45
|
+
}
|