@widgetic/editor 4.1.22 → 4.1.24
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/README.md +43 -0
- package/dist/components/editors/CompositionEditorApp.svelte +228 -206
- package/dist/components/editors/EmbedAssistantPanel.svelte +270 -48
- package/dist/components/ic/AngleInputController.svelte +18 -3
- package/dist/components/ic/ColorPickerInputController.svelte +81 -49
- package/dist/components/ic/DatePickerInputController.svelte +134 -74
- package/dist/components/ic/DatePickerInputController.svelte.d.ts +2 -2
- package/dist/components/ic/NumberInputController.svelte +16 -2
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +26 -18
- package/dist/composition/compositionApi.d.ts +25 -0
- package/dist/composition/compositionApi.js +34 -4
- package/dist/composition/compositionEditorController.d.ts +63 -3
- package/dist/composition/compositionEditorController.js +207 -10
- package/dist/composition/staleGuard.d.ts +111 -0
- package/dist/composition/staleGuard.js +279 -0
- package/dist/embedAssistant/embedAssistantSuggest.d.ts +20 -0
- package/dist/embedAssistant/embedAssistantSuggest.js +29 -0
- package/dist/embedAssistant/embedAssistantTurns.d.ts +73 -0
- package/dist/embedAssistant/embedAssistantTurns.js +56 -0
- package/dist/embedAssistant/types.d.ts +15 -0
- package/dist/i18n/language.d.ts +19 -3
- package/dist/i18n/messages.d.ts +9 -0
- package/dist/i18n/messages.js +11 -0
- package/dist/i18n/translate.d.ts +1 -1
- package/package.json +8 -3
- package/dist/components/ic/NumberControls.svelte +0 -505
- package/dist/components/ic/NumberControls.svelte.d.ts +0 -37
- package/dist/components/ic/numberControlsSteps.d.ts +0 -17
- package/dist/components/ic/numberControlsSteps.js +0 -23
- package/dist/components/ic/numberControlsValueArea.d.ts +0 -29
- package/dist/components/ic/numberControlsValueArea.js +0 -51
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stale-tab guard: when a person comes back to a tab, it asks the server whether what the tab shows is still what the
|
|
3
|
+
* server holds. When the server holds something newer (an MCP client, another tab, a teammate, an automation changed it
|
|
4
|
+
* while the tab sat in the background), the tab is brought up to date on the spot, behind a dark overlay that fades in
|
|
5
|
+
* while it happens and fades out when it is done, so nothing can be edited on a copy that is out of date.
|
|
6
|
+
*
|
|
7
|
+
* It decides nothing about a product. Everything that differs is handed in:
|
|
8
|
+
* - `probe`: how to read what the server holds (a revision, a content version, an `updatedAt`), and with it what is needed
|
|
9
|
+
* to show it (a conditional GET that answers "unchanged" costs no body);
|
|
10
|
+
* - `readCurrentToken`: the version this tab shows now (an own save moves it, so an own save is never "news");
|
|
11
|
+
* - `readBlocker`: whether the tab may be replaced right now (`busy`: a save is on its way, try again in a moment;
|
|
12
|
+
* `dirty`: unsaved work that must never be overwritten; `skip`: nothing to guard at the moment);
|
|
13
|
+
* - `apply`: how to put the newer copy on the screen (the product's own "load the latest").
|
|
14
|
+
*
|
|
15
|
+
* What it does and does not do:
|
|
16
|
+
* - it wakes on `focus`, `visibilitychange` (to visible), `online` and `pageshow`, one check at a time, at most one in
|
|
17
|
+
* `minimumGapMilliseconds` (a click into an iframe and back must not ask again and again);
|
|
18
|
+
* - a check that finds the same version, or an older one than the tab has (the tab saved while the question was out),
|
|
19
|
+
* does nothing and shows nothing;
|
|
20
|
+
* - it never replaces unsaved work: with `dirty` it says `conflict` and leaves the choice to the product's own conflict
|
|
21
|
+
* screen, until `settleConflict()`;
|
|
22
|
+
* - a failed check is silent (the next wake asks again); a failed `apply` leaves the overlay and tells the log;
|
|
23
|
+
* - the overlay (`phase === 'updating'`) stays for at least `minimumOverlayMilliseconds`, so it never reads as a flicker.
|
|
24
|
+
*
|
|
25
|
+
* This file is the same in the site, in the workflows package and in the composition editor, and has no imports on purpose:
|
|
26
|
+
* a change belongs in all three copies (`src/lib/utils/staleGuard.ts`, `src/lib/editor/staleGuard.ts`,
|
|
27
|
+
* `src/lib/composition/staleGuard.ts`), and their tests say the same.
|
|
28
|
+
*/
|
|
29
|
+
export const DEFAULT_MINIMUM_GAP_MILLISECONDS = 5000;
|
|
30
|
+
export const DEFAULT_MINIMUM_OVERLAY_MILLISECONDS = 400;
|
|
31
|
+
export const DEFAULT_BUSY_RETRY_MILLISECONDS = 1500;
|
|
32
|
+
export const DEFAULT_MAXIMUM_BUSY_RETRIES = 6;
|
|
33
|
+
/** The real browser: the four ways a tab comes back (`focus`, `visibilitychange`, `online`, `pageshow`). */
|
|
34
|
+
export function createBrowserStaleGuardEnvironment() {
|
|
35
|
+
return {
|
|
36
|
+
now: () => Date.now(),
|
|
37
|
+
isVisible: () => typeof document === 'undefined' || document.visibilityState !== 'hidden',
|
|
38
|
+
onWake(listener) {
|
|
39
|
+
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
40
|
+
return () => { };
|
|
41
|
+
const handleVisibilityChange = () => {
|
|
42
|
+
if (document.visibilityState === 'visible')
|
|
43
|
+
listener();
|
|
44
|
+
};
|
|
45
|
+
window.addEventListener('focus', listener);
|
|
46
|
+
window.addEventListener('online', listener);
|
|
47
|
+
window.addEventListener('pageshow', listener);
|
|
48
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
49
|
+
return () => {
|
|
50
|
+
window.removeEventListener('focus', listener);
|
|
51
|
+
window.removeEventListener('online', listener);
|
|
52
|
+
window.removeEventListener('pageshow', listener);
|
|
53
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
setTimeout: (callback, milliseconds) => globalThis.setTimeout(callback, milliseconds),
|
|
57
|
+
clearTimeout: (handle) => globalThis.clearTimeout(handle)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Bigger numbers and later dates are newer; anything else is newer when it is not the same. A tab that shows nothing is behind. */
|
|
61
|
+
function isNewerByDefault(serverToken, currentToken) {
|
|
62
|
+
if (currentToken === null)
|
|
63
|
+
return true;
|
|
64
|
+
if (typeof serverToken === 'number' && typeof currentToken === 'number') {
|
|
65
|
+
return serverToken > currentToken;
|
|
66
|
+
}
|
|
67
|
+
if (typeof serverToken === 'string' && typeof currentToken === 'string') {
|
|
68
|
+
const serverTime = Date.parse(serverToken);
|
|
69
|
+
const currentTime = Date.parse(currentToken);
|
|
70
|
+
if (!Number.isNaN(serverTime) && !Number.isNaN(currentTime))
|
|
71
|
+
return serverTime > currentTime;
|
|
72
|
+
}
|
|
73
|
+
return !Object.is(serverToken, currentToken);
|
|
74
|
+
}
|
|
75
|
+
export function createStaleGuard(options) {
|
|
76
|
+
const environment = options.environment ?? createBrowserStaleGuardEnvironment();
|
|
77
|
+
const minimumGap = options.minimumGapMilliseconds ?? DEFAULT_MINIMUM_GAP_MILLISECONDS;
|
|
78
|
+
const minimumOverlay = options.minimumOverlayMilliseconds ?? DEFAULT_MINIMUM_OVERLAY_MILLISECONDS;
|
|
79
|
+
const busyRetryDelay = options.busyRetryMilliseconds ?? DEFAULT_BUSY_RETRY_MILLISECONDS;
|
|
80
|
+
const maximumBusyRetries = options.maximumBusyRetries ?? DEFAULT_MAXIMUM_BUSY_RETRIES;
|
|
81
|
+
const isNewer = options.isNewer ?? isNewerByDefault;
|
|
82
|
+
let phase = 'idle';
|
|
83
|
+
let isDisposed = false;
|
|
84
|
+
let stopListening = null;
|
|
85
|
+
let activeController = null;
|
|
86
|
+
let lastCheckStartedAt = Number.NEGATIVE_INFINITY;
|
|
87
|
+
let busyRetryTimer = null;
|
|
88
|
+
let busyRetries = 0;
|
|
89
|
+
let overlayTimer = null;
|
|
90
|
+
let releaseOverlayWait = null;
|
|
91
|
+
function log(event, detail) {
|
|
92
|
+
try {
|
|
93
|
+
options.log?.(event, detail);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// A log that throws must never stop a check.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function setPhase(next) {
|
|
100
|
+
if (phase === next)
|
|
101
|
+
return;
|
|
102
|
+
phase = next;
|
|
103
|
+
try {
|
|
104
|
+
options.onPhaseChange?.(next);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
log('stale-guard: onPhaseChange threw', error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function readBlocker() {
|
|
111
|
+
try {
|
|
112
|
+
return options.readBlocker();
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
log('stale-guard: readBlocker threw', error);
|
|
116
|
+
return 'skip';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function readCurrentToken() {
|
|
120
|
+
try {
|
|
121
|
+
return options.readCurrentToken();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
log('stale-guard: readCurrentToken threw', error);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function cancelBusyRetry() {
|
|
129
|
+
if (busyRetryTimer === null)
|
|
130
|
+
return;
|
|
131
|
+
environment.clearTimeout(busyRetryTimer);
|
|
132
|
+
busyRetryTimer = null;
|
|
133
|
+
}
|
|
134
|
+
/** The tab is mid-save: look again in a moment, a few times, and then leave it to the next wake. */
|
|
135
|
+
function scheduleBusyRetry() {
|
|
136
|
+
if (busyRetryTimer !== null || isDisposed)
|
|
137
|
+
return;
|
|
138
|
+
if (busyRetries >= maximumBusyRetries) {
|
|
139
|
+
log('stale-guard: still busy, left to the next wake');
|
|
140
|
+
busyRetries = 0;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
busyRetries += 1;
|
|
144
|
+
busyRetryTimer = environment.setTimeout(() => {
|
|
145
|
+
busyRetryTimer = null;
|
|
146
|
+
void check('retry', { force: true });
|
|
147
|
+
}, busyRetryDelay);
|
|
148
|
+
}
|
|
149
|
+
/** Waits out what is left of the minimum time the overlay stays; a dispose ends the wait at once. */
|
|
150
|
+
function waitForOverlayMinimum(startedAt) {
|
|
151
|
+
const remaining = minimumOverlay - (environment.now() - startedAt);
|
|
152
|
+
if (remaining <= 0)
|
|
153
|
+
return Promise.resolve();
|
|
154
|
+
return new Promise((resolve) => {
|
|
155
|
+
releaseOverlayWait = () => {
|
|
156
|
+
releaseOverlayWait = null;
|
|
157
|
+
overlayTimer = null;
|
|
158
|
+
resolve();
|
|
159
|
+
};
|
|
160
|
+
overlayTimer = environment.setTimeout(() => releaseOverlayWait?.(), remaining);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
async function applyChange(snapshot, token) {
|
|
164
|
+
setPhase('updating');
|
|
165
|
+
const startedAt = environment.now();
|
|
166
|
+
try {
|
|
167
|
+
await options.apply(snapshot, token);
|
|
168
|
+
log('stale-guard: the tab was brought up to date', { token });
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
log('stale-guard: the newer copy could not be shown', error);
|
|
172
|
+
}
|
|
173
|
+
await waitForOverlayMinimum(startedAt);
|
|
174
|
+
if (isDisposed)
|
|
175
|
+
return;
|
|
176
|
+
setPhase('idle');
|
|
177
|
+
}
|
|
178
|
+
async function check(reason = 'request', settings = {}) {
|
|
179
|
+
if (isDisposed || phase !== 'idle')
|
|
180
|
+
return;
|
|
181
|
+
// A hidden tab asks nothing; it asks when it is shown
|
|
182
|
+
if (!environment.isVisible())
|
|
183
|
+
return;
|
|
184
|
+
const startedAt = environment.now();
|
|
185
|
+
if (settings.force !== true && startedAt - lastCheckStartedAt < minimumGap)
|
|
186
|
+
return;
|
|
187
|
+
const blockerBefore = readBlocker();
|
|
188
|
+
if (blockerBefore === 'skip')
|
|
189
|
+
return;
|
|
190
|
+
if (blockerBefore === 'busy') {
|
|
191
|
+
scheduleBusyRetry();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
lastCheckStartedAt = startedAt;
|
|
195
|
+
busyRetries = 0;
|
|
196
|
+
cancelBusyRetry();
|
|
197
|
+
setPhase('checking');
|
|
198
|
+
const controller = new AbortController();
|
|
199
|
+
activeController = controller;
|
|
200
|
+
let result;
|
|
201
|
+
try {
|
|
202
|
+
result = await options.probe({ signal: controller.signal, currentToken: readCurrentToken() });
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (activeController === controller)
|
|
206
|
+
activeController = null;
|
|
207
|
+
if (isDisposed || controller.signal.aborted)
|
|
208
|
+
return;
|
|
209
|
+
// Silent for the person: the next wake asks again
|
|
210
|
+
log(`stale-guard: the check failed (${reason})`, error);
|
|
211
|
+
setPhase('idle');
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (activeController === controller)
|
|
215
|
+
activeController = null;
|
|
216
|
+
if (isDisposed || controller.signal.aborted)
|
|
217
|
+
return;
|
|
218
|
+
if (result.outcome === 'unchanged' || !isNewer(result.token, readCurrentToken())) {
|
|
219
|
+
setPhase('idle');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// The answer may have been a while coming: the tab is judged again, now
|
|
223
|
+
const blockerAfter = readBlocker();
|
|
224
|
+
if (blockerAfter === 'skip') {
|
|
225
|
+
setPhase('idle');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (blockerAfter === 'busy') {
|
|
229
|
+
setPhase('idle');
|
|
230
|
+
scheduleBusyRetry();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (blockerAfter === 'dirty') {
|
|
234
|
+
log('stale-guard: changed elsewhere, and this tab has unsaved work', { token: result.token });
|
|
235
|
+
setPhase('conflict');
|
|
236
|
+
try {
|
|
237
|
+
options.onConflict?.({ token: result.token });
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
log('stale-guard: onConflict threw', error);
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await applyChange(result.snapshot, result.token);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
start() {
|
|
248
|
+
if (isDisposed || stopListening !== null)
|
|
249
|
+
return;
|
|
250
|
+
stopListening = environment.onWake(() => {
|
|
251
|
+
void check('wake');
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
check,
|
|
255
|
+
settleConflict() {
|
|
256
|
+
if (isDisposed || phase !== 'conflict')
|
|
257
|
+
return;
|
|
258
|
+
lastCheckStartedAt = Number.NEGATIVE_INFINITY;
|
|
259
|
+
setPhase('idle');
|
|
260
|
+
},
|
|
261
|
+
dispose() {
|
|
262
|
+
if (isDisposed)
|
|
263
|
+
return;
|
|
264
|
+
isDisposed = true;
|
|
265
|
+
stopListening?.();
|
|
266
|
+
stopListening = null;
|
|
267
|
+
cancelBusyRetry();
|
|
268
|
+
if (overlayTimer !== null)
|
|
269
|
+
environment.clearTimeout(overlayTimer);
|
|
270
|
+
overlayTimer = null;
|
|
271
|
+
releaseOverlayWait?.();
|
|
272
|
+
activeController?.abort();
|
|
273
|
+
activeController = null;
|
|
274
|
+
},
|
|
275
|
+
get phase() {
|
|
276
|
+
return phase;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the embed assistant's box tells the gateway about itself when it asks how to go on: the settings the person has already set, by
|
|
3
|
+
* id, so the gateway does not suggest a setting that is set. The ids are the keys of the settings the editor holds; their values never
|
|
4
|
+
* leave the editor, and neither does anything else of the page.
|
|
5
|
+
*
|
|
6
|
+
* Plain TypeScript with no Svelte, so a test in Node can run it.
|
|
7
|
+
*/
|
|
8
|
+
/** The surface of the box, as the gateway names it in the counts of what happened to its suggestions. */
|
|
9
|
+
export declare const EMBED_ASSISTANT_SUGGEST_SURFACE = "embed_assistant";
|
|
10
|
+
/** The most ids one request names: what the gateway reads (the rest would make it refuse the whole request). */
|
|
11
|
+
export declare const EMBED_SUGGEST_MAX_SETTING_IDS = 200;
|
|
12
|
+
/** The longest id the gateway reads. */
|
|
13
|
+
export declare const EMBED_SUGGEST_MAX_SETTING_ID_LENGTH = 64;
|
|
14
|
+
/**
|
|
15
|
+
* The context of a request: the ids of the settings that have a value, sorted (the same settings are always the same request), without
|
|
16
|
+
* the ones the gateway would refuse. `undefined` when no setting is set: a box with nothing to say about itself sends no context.
|
|
17
|
+
*/
|
|
18
|
+
export declare function embedSuggestContext(currentSettings: Record<string, unknown> | null | undefined): {
|
|
19
|
+
setSettingIds: string[];
|
|
20
|
+
} | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the embed assistant's box tells the gateway about itself when it asks how to go on: the settings the person has already set, by
|
|
3
|
+
* id, so the gateway does not suggest a setting that is set. The ids are the keys of the settings the editor holds; their values never
|
|
4
|
+
* leave the editor, and neither does anything else of the page.
|
|
5
|
+
*
|
|
6
|
+
* Plain TypeScript with no Svelte, so a test in Node can run it.
|
|
7
|
+
*/
|
|
8
|
+
/** The surface of the box, as the gateway names it in the counts of what happened to its suggestions. */
|
|
9
|
+
export const EMBED_ASSISTANT_SUGGEST_SURFACE = 'embed_assistant';
|
|
10
|
+
/** The most ids one request names: what the gateway reads (the rest would make it refuse the whole request). */
|
|
11
|
+
export const EMBED_SUGGEST_MAX_SETTING_IDS = 200;
|
|
12
|
+
/** The longest id the gateway reads. */
|
|
13
|
+
export const EMBED_SUGGEST_MAX_SETTING_ID_LENGTH = 64;
|
|
14
|
+
/**
|
|
15
|
+
* The context of a request: the ids of the settings that have a value, sorted (the same settings are always the same request), without
|
|
16
|
+
* the ones the gateway would refuse. `undefined` when no setting is set: a box with nothing to say about itself sends no context.
|
|
17
|
+
*/
|
|
18
|
+
export function embedSuggestContext(currentSettings) {
|
|
19
|
+
if (!currentSettings || typeof currentSettings !== 'object')
|
|
20
|
+
return undefined;
|
|
21
|
+
const setSettingIds = Object.keys(currentSettings)
|
|
22
|
+
.filter((id) => id.length > 0 &&
|
|
23
|
+
id.length <= EMBED_SUGGEST_MAX_SETTING_ID_LENGTH &&
|
|
24
|
+
currentSettings[id] !== undefined &&
|
|
25
|
+
currentSettings[id] !== null)
|
|
26
|
+
.sort()
|
|
27
|
+
.slice(0, EMBED_SUGGEST_MAX_SETTING_IDS);
|
|
28
|
+
return setSettingIds.length > 0 ? { setSettingIds } : undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { EmbedAssistantTranscriptTurn } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The rules of the assistant's face in the panel: how the transcript is cut into turns, and what the assistant is doing at
|
|
4
|
+
* this moment, as far as its avatar cares.
|
|
5
|
+
*
|
|
6
|
+
* Plain TypeScript with no Svelte in it, so the rules can be tested in Node as they are. The panel turns a moment into the
|
|
7
|
+
* look of the avatar with the chat's own `liveAgentLook` and `settledAgentLook` (`@widgetic/chat`), so the panel follows the
|
|
8
|
+
* same choreography as the chat of the creator instead of keeping a copy of it.
|
|
9
|
+
*/
|
|
10
|
+
/** One row of the transcript as the panel draws it. */
|
|
11
|
+
export type EmbedAssistantTurn = {
|
|
12
|
+
readonly kind: 'user';
|
|
13
|
+
/** Stable while messages are added (the position in the transcript), so a row is never drawn again for nothing. */
|
|
14
|
+
readonly key: string;
|
|
15
|
+
readonly message: EmbedAssistantTranscriptTurn;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'assistant';
|
|
18
|
+
readonly key: string;
|
|
19
|
+
/** What the assistant said in a row, one after the other. Empty while it has only its live content to show. */
|
|
20
|
+
readonly messages: readonly EmbedAssistantTranscriptTurn[];
|
|
21
|
+
/**
|
|
22
|
+
* True for the last turn when it is the assistant's: the only one whose avatar moves, and the one that holds what is
|
|
23
|
+
* still live (the working line, the question, the failure). Older turns are still pictures.
|
|
24
|
+
*/
|
|
25
|
+
readonly isNewest: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Cuts the transcript into turns: a message of the person is a turn of its own, and the messages the assistant said in a row
|
|
29
|
+
* are one turn (one face for what it said, not one for each sentence).
|
|
30
|
+
*
|
|
31
|
+
* `hasLiveContent` says that something belonging to the assistant is on screen after the transcript (it is working, a
|
|
32
|
+
* question is waiting for the person, or the run failed). Then the last turn is the assistant's even when the person spoke
|
|
33
|
+
* last: it starts with that content, so the face sits beside it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function groupEmbedAssistantTurns(messages: readonly EmbedAssistantTranscriptTurn[], hasLiveContent: boolean): EmbedAssistantTurn[];
|
|
36
|
+
/** What the assistant is doing, as far as its avatar cares. */
|
|
37
|
+
export type EmbedAssistantMoment = {
|
|
38
|
+
readonly kind: 'live';
|
|
39
|
+
/**
|
|
40
|
+
* `shimmer-only`: waiting for the first word (the avatar is large and thinks). `code-only`: it is answering (the avatar
|
|
41
|
+
* is small and writes). The names are the chat's `GenerationActivityPhase`.
|
|
42
|
+
*/
|
|
43
|
+
readonly phase: 'shimmer-only' | 'code-only';
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: 'settled';
|
|
46
|
+
/** The names are the chat's `TurnOutcome`. */
|
|
47
|
+
readonly outcome: 'success' | 'error' | 'question' | 'answer';
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Whether the avatar of a moment stays small even where the chat would make it large. The panel is narrow (320 px unless the
|
|
51
|
+
* person drags it wider), and the chat's large avatar beside a question waiting for an answer would leave the card two thirds
|
|
52
|
+
* of the panel, then widen it again the moment the person answers. So a question waiting keeps the small avatar; the other
|
|
53
|
+
* large moments (waiting for the first word, the conclusion, the failure) have only words beside them and keep the chat's size.
|
|
54
|
+
*/
|
|
55
|
+
export declare function embedMomentKeepsAvatarSmall(moment: EmbedAssistantMoment): boolean;
|
|
56
|
+
/** What the panel knows about the latest run (a message sent), as plain facts. */
|
|
57
|
+
export interface EmbedAssistantRunFacts {
|
|
58
|
+
/** A stream is open (the assistant is answering). */
|
|
59
|
+
readonly isStreaming: boolean;
|
|
60
|
+
/** The assistant has already said something since the person last spoke. */
|
|
61
|
+
readonly hasReplyStarted: boolean;
|
|
62
|
+
/** The latest run brought a question that the person has not answered yet. */
|
|
63
|
+
readonly hasCardToAnswer: boolean;
|
|
64
|
+
/** The latest run failed (the request, the stream, or an error the assistant reported). */
|
|
65
|
+
readonly hasFailed: boolean;
|
|
66
|
+
/** The latest run ended with what the person asked for (it changed the settings of the embed). */
|
|
67
|
+
readonly hasSucceeded: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The moment of the assistant. A failure is looked at first (a run can change some settings and then fail, and the failure is
|
|
71
|
+
* what the person needs to see first), then the conclusion, then a question waiting for the person, then a plain answer.
|
|
72
|
+
*/
|
|
73
|
+
export declare function embedAssistantMoment(facts: EmbedAssistantRunFacts): EmbedAssistantMoment;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cuts the transcript into turns: a message of the person is a turn of its own, and the messages the assistant said in a row
|
|
3
|
+
* are one turn (one face for what it said, not one for each sentence).
|
|
4
|
+
*
|
|
5
|
+
* `hasLiveContent` says that something belonging to the assistant is on screen after the transcript (it is working, a
|
|
6
|
+
* question is waiting for the person, or the run failed). Then the last turn is the assistant's even when the person spoke
|
|
7
|
+
* last: it starts with that content, so the face sits beside it.
|
|
8
|
+
*/
|
|
9
|
+
export function groupEmbedAssistantTurns(messages, hasLiveContent) {
|
|
10
|
+
const turns = [];
|
|
11
|
+
for (const message of messages) {
|
|
12
|
+
const previousTurn = turns[turns.length - 1];
|
|
13
|
+
if (message.role === 'assistant' && previousTurn?.kind === 'assistant') {
|
|
14
|
+
turns[turns.length - 1] = { ...previousTurn, messages: [...previousTurn.messages, message] };
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const key = `turn-${turns.length}`;
|
|
18
|
+
turns.push(message.role === 'user'
|
|
19
|
+
? { kind: 'user', key, message }
|
|
20
|
+
: { kind: 'assistant', key, messages: [message], isNewest: false });
|
|
21
|
+
}
|
|
22
|
+
const lastTurn = turns[turns.length - 1];
|
|
23
|
+
if (hasLiveContent && (!lastTurn || lastTurn.kind === 'user')) {
|
|
24
|
+
turns.push({ kind: 'assistant', key: `turn-${turns.length}`, messages: [], isNewest: false });
|
|
25
|
+
}
|
|
26
|
+
const newestTurn = turns[turns.length - 1];
|
|
27
|
+
if (newestTurn?.kind === 'assistant') {
|
|
28
|
+
turns[turns.length - 1] = { ...newestTurn, isNewest: true };
|
|
29
|
+
}
|
|
30
|
+
return turns;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether the avatar of a moment stays small even where the chat would make it large. The panel is narrow (320 px unless the
|
|
34
|
+
* person drags it wider), and the chat's large avatar beside a question waiting for an answer would leave the card two thirds
|
|
35
|
+
* of the panel, then widen it again the moment the person answers. So a question waiting keeps the small avatar; the other
|
|
36
|
+
* large moments (waiting for the first word, the conclusion, the failure) have only words beside them and keep the chat's size.
|
|
37
|
+
*/
|
|
38
|
+
export function embedMomentKeepsAvatarSmall(moment) {
|
|
39
|
+
return moment.kind === 'settled' && moment.outcome === 'question';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The moment of the assistant. A failure is looked at first (a run can change some settings and then fail, and the failure is
|
|
43
|
+
* what the person needs to see first), then the conclusion, then a question waiting for the person, then a plain answer.
|
|
44
|
+
*/
|
|
45
|
+
export function embedAssistantMoment(facts) {
|
|
46
|
+
if (facts.isStreaming) {
|
|
47
|
+
return { kind: 'live', phase: facts.hasReplyStarted ? 'code-only' : 'shimmer-only' };
|
|
48
|
+
}
|
|
49
|
+
if (facts.hasFailed)
|
|
50
|
+
return { kind: 'settled', outcome: 'error' };
|
|
51
|
+
if (facts.hasSucceeded)
|
|
52
|
+
return { kind: 'settled', outcome: 'success' };
|
|
53
|
+
if (facts.hasCardToAnswer)
|
|
54
|
+
return { kind: 'settled', outcome: 'question' };
|
|
55
|
+
return { kind: 'settled', outcome: 'answer' };
|
|
56
|
+
}
|
|
@@ -19,6 +19,21 @@ export interface EmbedAssistantWireConfig {
|
|
|
19
19
|
readonly getAuthHeaders: () => Promise<Record<string, string>> | Record<string, string>;
|
|
20
20
|
readonly initialTranscript?: readonly EmbedAssistantTranscriptTurn[];
|
|
21
21
|
readonly onTranscriptChange?: (transcript: EmbedAssistantTranscriptTurn[]) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Where the box of the assistant asks how to go on (`POST /compositions/{id}/embed-assistant/suggest`): the answer is a grey
|
|
24
|
+
* suggestion after what the person has typed, which Tab takes and typing on or Esc sends away. Without it the box suggests nothing.
|
|
25
|
+
*/
|
|
26
|
+
readonly suggestUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Where the counts of what happened to the suggestions go (`POST /agent/composer/outcome`): how many were shown, taken, sent away.
|
|
29
|
+
* Counts only, never a word of the box. Without it nothing is reported (the box still suggests).
|
|
30
|
+
*/
|
|
31
|
+
readonly outcomeUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the assistant is drawn as the Scribble Mascot (the brand's animated face, beside what the assistant says).
|
|
34
|
+
* `true` when omitted; `false` draws the chat's plain round avatar instead and fetches nothing for the mascot.
|
|
35
|
+
*/
|
|
36
|
+
readonly agentMascot?: boolean;
|
|
22
37
|
}
|
|
23
38
|
export interface EmbedAssistantOptionsSetPayload {
|
|
24
39
|
readonly options: Record<string, unknown>;
|
package/dist/i18n/language.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export declare const EDITOR_CATALOGS: {
|
|
|
33
33
|
readonly 'editor.conflict.loadLatestHint': "Drops your changes and shows the newer version.";
|
|
34
34
|
readonly 'editor.conflict.working': "Working…";
|
|
35
35
|
readonly 'editor.conflict.resolveFailed': "The newer version could not be read, so nothing was changed. Check the connection and try again.";
|
|
36
|
+
readonly 'editor.stale.updating': "Updating to the latest version…";
|
|
37
|
+
readonly 'editor.stale.updatingDescription': "This composition was changed somewhere else.";
|
|
38
|
+
readonly 'editor.stale.updatingStatus': "This composition was changed somewhere else. Updating to the latest version.";
|
|
36
39
|
readonly 'editor.presence.blockedTitleNamed': "{name} is editing this composition";
|
|
37
40
|
readonly 'editor.presence.blockedTitleYou': "You are editing this composition in another window";
|
|
38
41
|
readonly 'editor.presence.blockedTitle': "Someone is editing this composition";
|
|
@@ -105,6 +108,9 @@ export declare const EDITOR_CATALOGS: {
|
|
|
105
108
|
readonly 'editor.embedAssistant.copyEmbedCode': "Copy embed code";
|
|
106
109
|
readonly 'editor.embedAssistant.errorGeneric': "The assistant could not respond. Try again.";
|
|
107
110
|
readonly 'editor.embedAssistant.errorRateLimit': "Too many messages. Try again shortly.";
|
|
111
|
+
readonly 'editor.embedAssistant.suggestionTabKey': "Tab";
|
|
112
|
+
readonly 'editor.embedAssistant.suggestionTabHint': "to accept";
|
|
113
|
+
readonly 'editor.embedAssistant.suggestionAnnouncement': "Suggestion: {text}. Press Tab to accept.";
|
|
108
114
|
readonly 'editor.preview.title': "Preview";
|
|
109
115
|
readonly 'editor.preview.dragHandle': "Drag preview";
|
|
110
116
|
readonly 'editor.preview.desktop': "Desktop preview";
|
|
@@ -342,6 +348,10 @@ export declare const EDITOR_CATALOGS: {
|
|
|
342
348
|
readonly 'toast.regionLabel': "Notifications";
|
|
343
349
|
readonly 'toast.closeLabel': "Close notification";
|
|
344
350
|
readonly 'search.placeholder': "Search\u2026";
|
|
351
|
+
readonly 'search.recentSearches': "Recent searches";
|
|
352
|
+
readonly 'search.clearRecentSearches': "Clear";
|
|
353
|
+
readonly 'search.open': "Search";
|
|
354
|
+
readonly 'search.close': "Close search";
|
|
345
355
|
readonly 'filter.by': "Filter by {type}";
|
|
346
356
|
readonly 'filterName.all': "All";
|
|
347
357
|
readonly 'filterName.image': "Image";
|
|
@@ -408,6 +418,12 @@ export declare const EDITOR_CATALOGS: {
|
|
|
408
418
|
readonly 'upload.uploading': "Uploading\u2026";
|
|
409
419
|
readonly 'upload.foldersNotAllowed': "Folders cannot be uploaded";
|
|
410
420
|
readonly 'upload.invalidType': "Invalid file type. Please use {types} files only.";
|
|
421
|
+
readonly 'upload.refusedOne': "\"{name}\" was not uploaded: {reason}";
|
|
422
|
+
readonly 'upload.refusedMany': "{count, plural, one {# file was not uploaded} other {# files were not uploaded}}: {reason}";
|
|
423
|
+
readonly 'upload.refusedType': "{type} files are not supported";
|
|
424
|
+
readonly 'upload.refusedTypeUnknown': "this type of file is not supported";
|
|
425
|
+
readonly 'upload.refusedTooLarge': "larger than {limit} MB";
|
|
426
|
+
readonly 'upload.sessionExpired': "Your session has expired. Sign in again to upload files.";
|
|
411
427
|
readonly 'upload.dropActive': "Drop to upload {types} files";
|
|
412
428
|
readonly 'upload.dropActiveAny': "Drop to upload files";
|
|
413
429
|
readonly 'upload.button': "Upload {types} files";
|
|
@@ -448,6 +464,7 @@ export declare const EDITOR_CATALOGS: {
|
|
|
448
464
|
readonly 'upload.filesTotal': "{count, plural, one {# file} other {# files}}";
|
|
449
465
|
readonly 'upload.completeCount': "{done}/{total} complete";
|
|
450
466
|
readonly 'upload.failed': "Upload failed";
|
|
467
|
+
readonly 'upload.interrupted': "Interrupted. Try again";
|
|
451
468
|
readonly 'upload.rowMeta': "{size} \u00B7 {detail}";
|
|
452
469
|
readonly 'dialog.delete.folderTitle': "Delete folder";
|
|
453
470
|
readonly 'dialog.delete.itemsTitle': "Delete items";
|
|
@@ -471,10 +488,8 @@ export declare const EDITOR_CATALOGS: {
|
|
|
471
488
|
readonly 'dialog.rename.tooShort': "Name must be at least 1 character long";
|
|
472
489
|
readonly 'dialog.rename.tooLong': "Name must be {max} characters or less";
|
|
473
490
|
readonly 'dialog.close': "Close modal";
|
|
474
|
-
readonly 'toast.rename.started': "Renaming \"{name}\"\u2026";
|
|
475
491
|
readonly 'toast.rename.done': "File renamed";
|
|
476
492
|
readonly 'toast.rename.folderDone': "Folder renamed";
|
|
477
|
-
readonly 'toast.rename.doneDetail': "Successfully renamed \"{oldName}\" to \"{newName}\"";
|
|
478
493
|
readonly 'toast.rename.failed': "Rename failed";
|
|
479
494
|
readonly 'toast.rename.noChange': "No changes were made";
|
|
480
495
|
readonly 'toast.rename.noItem': "No valid item selected";
|
|
@@ -492,6 +507,7 @@ export declare const EDITOR_CATALOGS: {
|
|
|
492
507
|
readonly 'toast.delete.failedNames': "Failed to delete: {names}";
|
|
493
508
|
readonly 'toast.delete.failedSome': "Some items could not be deleted";
|
|
494
509
|
readonly 'toast.delete.failedAll': "Failed to delete items";
|
|
510
|
+
readonly 'toast.delete.putBack': "{count, plural, one {The file is back in your library} other {The files are back in your library}}";
|
|
495
511
|
readonly 'toast.folder.created': "Folder created";
|
|
496
512
|
readonly 'toast.folder.createdDetail': "Created folder \"{name}\"";
|
|
497
513
|
readonly 'toast.folder.failed': "Failed to create folder";
|
|
@@ -672,7 +688,7 @@ export declare const ALL_EDITOR_MESSAGES: Readonly<Record<string, string>>;
|
|
|
672
688
|
* the nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
|
|
673
689
|
* is never given. An empty list means every message will be used. For a test or a build step of the page.
|
|
674
690
|
*/
|
|
675
|
-
export declare const checkEditorMessages: (messages: import("@widgetic/
|
|
691
|
+
export declare const checkEditorMessages: (messages: import("@widgetic/file-browser").MessageOverrides) => import("@widgetic/file-browser").MessageProblem[];
|
|
676
692
|
/**
|
|
677
693
|
* Called by the root component of an editor while it is created, so everything inside it speaks the page's language.
|
|
678
694
|
* The context belongs to one root component, so two editors on a page can speak two languages.
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export declare const EDITOR_MESSAGES: {
|
|
|
54
54
|
readonly 'editor.conflict.working': "Working…";
|
|
55
55
|
/** When the newer version could not be read: nothing was changed, so the person can choose again. */
|
|
56
56
|
readonly 'editor.conflict.resolveFailed': "The newer version could not be read, so nothing was changed. Check the connection and try again.";
|
|
57
|
+
/** The first line of the pill on the dark layer that covers the editor while a newer version, saved somewhere else, is taken. */
|
|
58
|
+
readonly 'editor.stale.updating': "Updating to the latest version…";
|
|
59
|
+
/** Under that line: why the editor is covered. */
|
|
60
|
+
readonly 'editor.stale.updatingDescription': "This composition was changed somewhere else.";
|
|
61
|
+
/** What a screen reader announces when the layer comes up. */
|
|
62
|
+
readonly 'editor.stale.updatingStatus': "This composition was changed somewhere else. Updating to the latest version.";
|
|
57
63
|
/** The title of the card when a teammate holds the editing of this composition. `{name}` is their name. */
|
|
58
64
|
readonly 'editor.presence.blockedTitleNamed': "{name} is editing this composition";
|
|
59
65
|
/** The same, when the person holding it is this person, in another window or tab. */
|
|
@@ -147,6 +153,9 @@ export declare const EDITOR_MESSAGES: {
|
|
|
147
153
|
readonly 'editor.embedAssistant.copyEmbedCode': "Copy embed code";
|
|
148
154
|
readonly 'editor.embedAssistant.errorGeneric': "The assistant could not respond. Try again.";
|
|
149
155
|
readonly 'editor.embedAssistant.errorRateLimit': "Too many messages. Try again shortly.";
|
|
156
|
+
readonly 'editor.embedAssistant.suggestionTabKey': "Tab";
|
|
157
|
+
readonly 'editor.embedAssistant.suggestionTabHint': "to accept";
|
|
158
|
+
readonly 'editor.embedAssistant.suggestionAnnouncement': "Suggestion: {text}. Press Tab to accept.";
|
|
150
159
|
readonly 'editor.preview.title': "Preview";
|
|
151
160
|
readonly 'editor.preview.dragHandle': "Drag preview";
|
|
152
161
|
readonly 'editor.preview.desktop': "Desktop preview";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -57,6 +57,13 @@ export const EDITOR_MESSAGES = {
|
|
|
57
57
|
'editor.conflict.working': 'Working…',
|
|
58
58
|
/** When the newer version could not be read: nothing was changed, so the person can choose again. */
|
|
59
59
|
'editor.conflict.resolveFailed': 'The newer version could not be read, so nothing was changed. Check the connection and try again.',
|
|
60
|
+
// ===== A tab that came back and found a newer version: the dark layer while it is put on the screen =====
|
|
61
|
+
/** The first line of the pill on the dark layer that covers the editor while a newer version, saved somewhere else, is taken. */
|
|
62
|
+
'editor.stale.updating': 'Updating to the latest version…',
|
|
63
|
+
/** Under that line: why the editor is covered. */
|
|
64
|
+
'editor.stale.updatingDescription': 'This composition was changed somewhere else.',
|
|
65
|
+
/** What a screen reader announces when the layer comes up. */
|
|
66
|
+
'editor.stale.updatingStatus': 'This composition was changed somewhere else. Updating to the latest version.',
|
|
60
67
|
// ===== Who else is editing: the card that asks, and the bar for looking only (a page that shows presence) =====
|
|
61
68
|
/** The title of the card when a teammate holds the editing of this composition. `{name}` is their name. */
|
|
62
69
|
'editor.presence.blockedTitleNamed': '{name} is editing this composition',
|
|
@@ -155,6 +162,10 @@ export const EDITOR_MESSAGES = {
|
|
|
155
162
|
'editor.embedAssistant.copyEmbedCode': 'Copy embed code',
|
|
156
163
|
'editor.embedAssistant.errorGeneric': 'The assistant could not respond. Try again.',
|
|
157
164
|
'editor.embedAssistant.errorRateLimit': 'Too many messages. Try again shortly.',
|
|
165
|
+
// The grey suggestion after what the person has typed: the hint beside the box while it shows, and what a screen reader hears.
|
|
166
|
+
'editor.embedAssistant.suggestionTabKey': 'Tab',
|
|
167
|
+
'editor.embedAssistant.suggestionTabHint': 'to accept',
|
|
168
|
+
'editor.embedAssistant.suggestionAnnouncement': 'Suggestion: {text}. Press Tab to accept.',
|
|
158
169
|
// ===== The preview of the widget =====
|
|
159
170
|
'editor.preview.title': 'Preview',
|
|
160
171
|
'editor.preview.dragHandle': 'Drag preview',
|