@widgetic/creator 0.3.80 → 0.4.0
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 +157 -0
- package/dist/CreatorApp.svelte +1159 -624
- package/dist/CreatorApp.svelte.d.ts +22 -0
- package/dist/components/BrandKitPanel.svelte +48 -40
- package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
- package/dist/components/DesignQuickEdit.svelte +13 -4
- package/dist/components/EditableName.svelte +13 -8
- package/dist/components/EditableName.svelte.d.ts +2 -2
- package/dist/components/FileUrlSourceControl.svelte +21 -8
- package/dist/components/HoverTooltip.svelte +1 -1
- package/dist/components/SelectorDropdown.svelte +19 -15
- package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
- package/dist/components/VersionDropdownRow.svelte +14 -11
- package/dist/components/WidgetDetails.svelte +118 -92
- package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
- package/dist/creator-types.d.ts +96 -0
- package/dist/host/creatorHost.d.ts +176 -0
- package/dist/host/creatorHost.js +242 -0
- package/dist/host/limitRefusal.d.ts +64 -0
- package/dist/host/limitRefusal.js +109 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.js +5 -0
- package/dist/i18n/labels.d.ts +14 -0
- package/dist/i18n/labels.js +39 -0
- package/dist/i18n/language.d.ts +559 -0
- package/dist/i18n/language.js +47 -0
- package/dist/i18n/languageKit.d.ts +52 -0
- package/dist/i18n/languageKit.js +45 -0
- package/dist/i18n/messages.d.ts +526 -0
- package/dist/i18n/messages.js +548 -0
- package/dist/i18n/slots.d.ts +22 -0
- package/dist/i18n/slots.js +42 -0
- package/dist/i18n/statusText.d.ts +22 -0
- package/dist/i18n/statusText.js +223 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/stores/userSession.d.ts +8 -1
- package/dist/stores/userSession.js +18 -25
- package/dist/stores/websocketStore.d.ts +6 -0
- package/dist/stores/websocketStore.js +39 -4
- package/dist/utils/designIntentTelemetry.d.ts +8 -0
- package/dist/utils/designIntentTelemetry.js +52 -34
- package/dist/utils/directionPlacement.d.ts +51 -0
- package/dist/utils/directionPlacement.js +55 -0
- package/dist/utils/embedCode.d.ts +0 -1
- package/dist/utils/embedCode.js +0 -4
- package/dist/utils/nativeScrollbarPadding.js +1 -1
- package/dist/utils/pickedFile.d.ts +15 -0
- package/dist/utils/pickedFile.js +21 -0
- package/dist/utils/widgeticChatUpload.d.ts +9 -0
- package/dist/utils/widgeticChatUpload.js +24 -2
- package/package.json +5 -3
- package/dist/retiredSurface.test.d.ts +0 -1
- package/dist/retiredSurface.test.js +0 -113
- package/dist/utils/designIntentResolver.test.d.ts +0 -1
- package/dist/utils/designIntentResolver.test.js +0 -246
- package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
- package/dist/utils/designIntentTelemetry.test.js +0 -385
- package/dist/utils/designQuickEditValues.test.d.ts +0 -1
- package/dist/utils/designQuickEditValues.test.js +0 -100
- package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
- package/dist/utils/widgeticChatUpload.test.js +0 -257
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Translate } from '@widgetic/design-system/i18n';
|
|
2
|
+
import type { CreatorMessageKey } from './messages.js';
|
|
3
|
+
/** The texts the creator writes, one by one, as it stores them. For the tests that read the creator's source. */
|
|
4
|
+
export declare const KNOWN_ENGLISH_TEXTS: readonly string[];
|
|
5
|
+
/** Whether the creator knows this text, one by one or by a pattern. For the tests that read the creator's source. */
|
|
6
|
+
export declare function isKnownText(text: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* What the chat shows for a line the creator saved in English. The API keeps the English text; a page sees the line in its
|
|
9
|
+
* language when the host passes this through the chat's `storedLineLabel` (the widget creator does). A line the table does
|
|
10
|
+
* not know (an assistant reply from the model) is shown as it is.
|
|
11
|
+
*/
|
|
12
|
+
export declare function conversationLineLabel(content: string | null | undefined, t: Translate<CreatorMessageKey>): string;
|
|
13
|
+
/**
|
|
14
|
+
* What the status bar of a code generation shows for a status line the creator stored. Nothing stored is `Ready`; a line
|
|
15
|
+
* the creator does not know (one that came from the server) is shown as it is.
|
|
16
|
+
*/
|
|
17
|
+
export declare function statusLabel(status: string | null | undefined, t: Translate<CreatorMessageKey>): string;
|
|
18
|
+
/**
|
|
19
|
+
* What a screen shows for an error text the creator stored. Nothing stored is an empty text (so a screen can write
|
|
20
|
+
* `errorLabel(error, t) || fallback`); an error the creator does not know is shown as it is.
|
|
21
|
+
*/
|
|
22
|
+
export declare function errorLabel(error: string | null | undefined, t: Translate<CreatorMessageKey>): string;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/** The texts the creator writes, one by one. */
|
|
2
|
+
const KNOWN_TEXTS = new Map([
|
|
3
|
+
['Ready', (t) => t('creator.status.ready')],
|
|
4
|
+
['Missing reference image', (t) => t('creator.codegen.missingReferenceImage')],
|
|
5
|
+
['Code generation completed! Preview ready.', (t) => t('creator.status.completedPreviewReady')],
|
|
6
|
+
['Code generation completed! Auto-saving...', (t) => t('creator.status.completedAutoSaving')],
|
|
7
|
+
['Code generation completed! Saved to GitLab.', (t) => t('creator.status.completedSaved')],
|
|
8
|
+
['Code generation completed! Changes saved to GitLab.', (t) => t('creator.status.completedChangesSaved')],
|
|
9
|
+
['Code generation failed', (t) => t('creator.status.failed')],
|
|
10
|
+
['Generation stopped by user', (t) => t('creator.status.stoppedByUser')],
|
|
11
|
+
['Fixing compilation errors…', (t) => t('creator.status.fixingCompilationErrors')],
|
|
12
|
+
['Generating mock code...', (t) => t('creator.status.generatingMockCode')],
|
|
13
|
+
['Mock code generation complete!', (t) => t('creator.status.mockCodeComplete')],
|
|
14
|
+
['Processing queued code generation request...', (t) => t('creator.status.processingQueuedRequest')],
|
|
15
|
+
['Preparing code generation...', (t) => t('creator.status.preparingCodeGeneration')],
|
|
16
|
+
['Session expired.', (t) => t('creator.status.sessionExpired')],
|
|
17
|
+
['Repository is required to generate code.', (t) => t('creator.status.repositoryRequired')],
|
|
18
|
+
['Running queued code generation...', (t) => t('creator.status.runningQueued')],
|
|
19
|
+
['Repository ready. Starting code generation...', (t) => t('creator.status.repositoryReady')],
|
|
20
|
+
['Answered from widget details — no generation needed.', (t) => t('creator.status.answeredFromDetails')],
|
|
21
|
+
['Need a bit more detail before generating.', (t) => t('creator.status.needMoreDetail')],
|
|
22
|
+
['No generation needed — use the publish or settings control.', (t) => t('creator.status.noGenerationNeeded')],
|
|
23
|
+
['Authentication expired. Please login again.', (t) => t('creator.status.authenticationExpired')],
|
|
24
|
+
['Code generation started, but no operation ID was returned.', (t) => t('creator.status.noOperationId')],
|
|
25
|
+
['Processing queued code generation...', (t) => t('creator.status.processingQueued')],
|
|
26
|
+
['Code generation in progress...', (t) => t('creator.status.inProgress')],
|
|
27
|
+
['Generating code...', (t) => t('creator.status.generating')],
|
|
28
|
+
// The two lines of utils/versionPreviewError.js (a JavaScript file, which the node tests of the creator read)
|
|
29
|
+
['This version has a code error.', (t) => t('creator.preview.versionHasCodeError')],
|
|
30
|
+
['Could not load this version. Please try again.', (t) => t('creator.preview.versionCouldNotLoad')],
|
|
31
|
+
['Code saved — building preview…', (t) => t('creator.status.savedBuildingPreview')],
|
|
32
|
+
['Code saved — loading preview…', (t) => t('creator.status.savedLoadingPreview')],
|
|
33
|
+
['Code saved — preview rebuilt from saved code.', (t) => t('creator.status.savedPreviewRebuilt')],
|
|
34
|
+
['A code generation is already running. Please wait for it to finish.', (t) => t('creator.status.alreadyRunning')],
|
|
35
|
+
['This app needs a refresh to continue.', (t) => t('creator.status.needsRefresh')],
|
|
36
|
+
['Limit reached for now. Please try again later.', (t) => t('creator.status.limitReached')],
|
|
37
|
+
['Rate limited — too many requests. Wait ~30s and retry.', (t) => t('creator.status.rateLimited')],
|
|
38
|
+
['Generation failed while you were away.', (t) => t('creator.error.generationFailedWhileYouWere')],
|
|
39
|
+
['Unknown error', (t) => t('creator.general.unknownError')],
|
|
40
|
+
['Generation tracking lost.', (t) => t('creator.error.generationTrackingLost')],
|
|
41
|
+
['Unable to resolve repository for this widget.', (t) => t('creator.error.unableToResolveRepositoryFor')],
|
|
42
|
+
['Authentication expired. Please login again to continue.', (t) => t('creator.error.authenticationExpiredPleaseLoginAgain')],
|
|
43
|
+
['Cannot track code generation progress. No operation ID received from server.', (t) => t('creator.error.cannotTrackCodeGenerationProgress')],
|
|
44
|
+
['Usage limit exceeded', (t) => t('creator.error.usageLimitExceeded')],
|
|
45
|
+
['Too many requests, please try again later.', (t) => t('creator.error.tooManyRequestsPleaseTry')],
|
|
46
|
+
['Code generation failed.', (t) => t('creator.error.codeGenerationFailed')],
|
|
47
|
+
['Widget Builder is not reachable. Make sure the Worker is running.', (t) => t('creator.error.widgetBuilderIsNotReachable')],
|
|
48
|
+
['Build request failed', (t) => t('creator.error.buildRequestFailed')],
|
|
49
|
+
['Not authenticated', (t) => t('creator.error.notAuthenticated')],
|
|
50
|
+
['API client is not configured', (t) => t('creator.error.apiClientIsNotConfigured')],
|
|
51
|
+
['Published version is not available and source code could not be compiled. Use Rebuild code or republish.', (t) => t('creator.error.publishedVersionIsNotAvailable')],
|
|
52
|
+
['Failed to compile widget code from repository.', (t) => t('creator.error.failedToCompileWidgetCode')],
|
|
53
|
+
['Preview not ready yet. Click Rebuild or wait a moment.', (t) => t('creator.error.previewNotReadyYetClick')],
|
|
54
|
+
['Preview not ready yet. Click Rebuild to compile from GitLab.', (t) => t('creator.error.previewNotReadyYetClickRebuild')],
|
|
55
|
+
['Preview loaded but the widget did not start. Open in a new tab or tap Rebuild. If the new tab is also blank, the generated code likely failed at runtime.', (t) => t('creator.error.previewLoadedButTheWidget')],
|
|
56
|
+
['Preview timed out. The dev server may still be initializing.\nPlease wait a moment and click Retry.', (t) => t('creator.error.previewTimedOutTheDev')],
|
|
57
|
+
['Could not open preview URL. Try Rebuild again.', (t) => t('creator.error.couldNotOpenPreviewUrl')],
|
|
58
|
+
['Could not fetch the preview URL. The Worker may be unavailable.', (t) => t('creator.error.couldNotFetchThePreview')],
|
|
59
|
+
['Widget preview runtime error (HTTP 500)', (t) => t('creator.error.widgetPreviewRuntimeErrorHttp')],
|
|
60
|
+
['Preview build failed.', (t) => t('creator.error.previewBuildFailed')],
|
|
61
|
+
['Could not reach the preview builder. Try Rebuild.', (t) => t('creator.error.couldNotReachThePreview')],
|
|
62
|
+
['Preview rebuild is unavailable in this session. Try Rebuild or reload the page.', (t) => t('creator.error.previewRebuildIsUnavailableIn')],
|
|
63
|
+
['Preview builder is unavailable. The widget code was saved — use Rebuild to compile it.', (t) => t('creator.error.previewBuilderIsUnavailableThe')],
|
|
64
|
+
['Preview builder returned an unexpected error page. Try Rebuild.', (t) => t('creator.error.previewBuilderReturnedAnUnexpected')],
|
|
65
|
+
['An unknown error occurred.', (t) => t('creator.error.anUnknownErrorOccurred')],
|
|
66
|
+
['Could not reach the server. Try again.', (t) => t('creator.error.couldNotReachTheServer')],
|
|
67
|
+
['Build failed.', (t) => t('creator.error.buildFailed')],
|
|
68
|
+
]);
|
|
69
|
+
/** The texts that have a value inside them. */
|
|
70
|
+
const KNOWN_PATTERNS = [
|
|
71
|
+
{ pattern: /^Code generation failed: ([\s\S]+)$/, say: (found, t) => t('creator.status.failedWithReason', { reason: sayKnown(found[1], t) ?? found[1] }) },
|
|
72
|
+
{ pattern: /^Reconnected — code generation in progress\.\.\. (\d+)%$/, say: (found, t) => t('creator.status.reconnected', { progress: found[1] }) },
|
|
73
|
+
{ pattern: /^Generating code\.\.\. \((\d+)%\)$/, say: (found, t) => t('creator.status.generatingProgress', { progress: found[1] }) },
|
|
74
|
+
];
|
|
75
|
+
/** How a version name reads in a line the chat saved in English ("Version 4", "a previous version"). */
|
|
76
|
+
function sayVersionNameInConversation(name, t) {
|
|
77
|
+
const version = /^Version\s+(\d+)$/i.exec(name.trim());
|
|
78
|
+
if (version)
|
|
79
|
+
return t('creator.conversation.version', { number: version[1] });
|
|
80
|
+
if (/^a previous version$/i.test(name.trim()))
|
|
81
|
+
return t('creator.conversation.previousVersion');
|
|
82
|
+
return name;
|
|
83
|
+
}
|
|
84
|
+
/** Full assistant lines the creator saves into a conversation (English in the API; said in the page's language on screen). */
|
|
85
|
+
const CONVERSATION_PATTERNS = [
|
|
86
|
+
{
|
|
87
|
+
pattern: /^Restored from (.+)\n\nCommit: ([a-f0-9]{7,8})$/i,
|
|
88
|
+
say: (found, t) => t('creator.conversation.restoredFromCommit', {
|
|
89
|
+
label: sayVersionNameInConversation(found[1], t),
|
|
90
|
+
commit: found[2],
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
pattern: /^Code generation completed! Commit: ([a-f0-9]{7,8})\nPreview is loading…$/,
|
|
95
|
+
say: (found, t) => t('creator.conversation.completedCommitPreviewLoading', { commit: found[1] }),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
pattern: /^Code generation completed! Commit: ([a-f0-9]{7,8})\nPreview ready\.$/,
|
|
99
|
+
say: (found, t) => t('creator.conversation.completedCommitPreviewReady', { commit: found[1] }),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
pattern: /^Code generation completed!\nPreview is loading…$/,
|
|
103
|
+
say: (_found, t) => t('creator.conversation.completedPreviewLoading'),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
pattern: /^Code saved \(([a-f0-9]{7,8})\) — building preview…$/,
|
|
107
|
+
say: (found, t) => t('creator.conversation.codeSavedShaBuilding', { sha: found[1] }),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
pattern: /^Code saved \(([a-f0-9]{7,8})\) — loading preview…$/,
|
|
111
|
+
say: (found, t) => t('creator.conversation.codeSavedShaLoading', { sha: found[1] }),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
pattern: /^Code saved \(([a-f0-9]{7,8})\) — preview rebuilt from saved code\.$/,
|
|
115
|
+
say: (found, t) => t('creator.conversation.codeSavedShaRebuilt', { sha: found[1] }),
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
pattern: /^Code saved \(Commit: ([a-f0-9]{7,8})\), but preview build failed:\n([\s\S]+)\n\nRebuilding preview…$/,
|
|
119
|
+
say: (found, t) => t('creator.conversation.codeSavedCommitPreviewFailed', {
|
|
120
|
+
commit: found[1],
|
|
121
|
+
error: errorLabel(found[2], t) || found[2],
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
pattern: /^Generation stopped by user\. You can Retry this prompt\.$/,
|
|
126
|
+
say: (_found, t) => t('creator.conversation.stoppedRetryPrompt'),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
pattern: /^Preview recompiled(?: \(commit ([a-f0-9]{7,8})\))?(?: in (\d+)ms)?\.\nNo new codegen — same saved code\.$/,
|
|
130
|
+
say: (found, t) => t('creator.conversation.previewRecompiled', {
|
|
131
|
+
commitPart: found[1] ? t('creator.conversation.previewRecompiledCommitPart', { commit: found[1] }) : '',
|
|
132
|
+
durationPart: found[2] ? t('creator.conversation.previewRecompiledDurationPart', { ms: found[2] }) : '',
|
|
133
|
+
}),
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
pattern: /^Already done — the widget is in the state you asked for\.(?: \(Commit: ([a-f0-9]{7,8})\))?\nThat change was made earlier in this conversation, so no new generation was needed(\.|:\n((?:- .+\n?)+))$/,
|
|
137
|
+
say: (found, t) => {
|
|
138
|
+
const files = found[3]?.trim();
|
|
139
|
+
const suffix = files ? t('creator.conversation.alreadyDoneFilesSuffix', { files }) : '.';
|
|
140
|
+
return found[1]
|
|
141
|
+
? t('creator.conversation.alreadyDoneWithCommit', { commit: found[1], suffix })
|
|
142
|
+
: t('creator.conversation.alreadyDone', { suffix });
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{ pattern: /^Convert: (.+)$/, say: (found, t) => t('creator.conversation.convert', { name: found[1] }) },
|
|
146
|
+
{ pattern: /^Widget conversion$/, say: (_found, t) => t('creator.conversation.widgetConversion') },
|
|
147
|
+
];
|
|
148
|
+
/** A mark before the words (`❌ `, `⚠️ `, `⏹ `): the creator writes it in front of a status line, and it needs no translation. */
|
|
149
|
+
const LEADING_MARK = /^[^\p{L}\p{N}]+\s+/u;
|
|
150
|
+
/** The text in the visitor's language, or `null` when the creator does not know the text. */
|
|
151
|
+
function sayKnown(text, t) {
|
|
152
|
+
const known = KNOWN_TEXTS.get(text);
|
|
153
|
+
if (known)
|
|
154
|
+
return known(t);
|
|
155
|
+
for (const { pattern, say } of KNOWN_PATTERNS) {
|
|
156
|
+
const found = pattern.exec(text);
|
|
157
|
+
if (found)
|
|
158
|
+
return say(found, t);
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
/** The texts the creator writes, one by one, as it stores them. For the tests that read the creator's source. */
|
|
163
|
+
export const KNOWN_ENGLISH_TEXTS = [...KNOWN_TEXTS.keys()];
|
|
164
|
+
/** Whether the creator knows this text, one by one or by a pattern. For the tests that read the creator's source. */
|
|
165
|
+
export function isKnownText(text) {
|
|
166
|
+
if (sayKnown(text, ((key) => key)) !== null)
|
|
167
|
+
return true;
|
|
168
|
+
for (const { pattern } of CONVERSATION_PATTERNS) {
|
|
169
|
+
if (pattern.test(text))
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* What the chat shows for a line the creator saved in English. The API keeps the English text; a page sees the line in its
|
|
176
|
+
* language when the host passes this through the chat's `storedLineLabel` (the widget creator does). A line the table does
|
|
177
|
+
* not know (an assistant reply from the model) is shown as it is.
|
|
178
|
+
*/
|
|
179
|
+
export function conversationLineLabel(content, t) {
|
|
180
|
+
const text = typeof content === 'string' ? content : '';
|
|
181
|
+
if (text.trim() === '')
|
|
182
|
+
return text;
|
|
183
|
+
for (const { pattern, say } of CONVERSATION_PATTERNS) {
|
|
184
|
+
const found = pattern.exec(text);
|
|
185
|
+
if (found)
|
|
186
|
+
return say(found, t);
|
|
187
|
+
}
|
|
188
|
+
const lines = text.split('\n');
|
|
189
|
+
if (lines.length === 1)
|
|
190
|
+
return statusLabel(text, t);
|
|
191
|
+
return lines
|
|
192
|
+
.map((line) => {
|
|
193
|
+
if (line.trim() === '')
|
|
194
|
+
return line;
|
|
195
|
+
const mark = LEADING_MARK.exec(line)?.[0] ?? '';
|
|
196
|
+
const core = line.slice(mark.length);
|
|
197
|
+
const said = sayKnown(core, t);
|
|
198
|
+
return said === null ? line : `${mark}${said}`;
|
|
199
|
+
})
|
|
200
|
+
.join('\n');
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* What the status bar of a code generation shows for a status line the creator stored. Nothing stored is `Ready`; a line
|
|
204
|
+
* the creator does not know (one that came from the server) is shown as it is.
|
|
205
|
+
*/
|
|
206
|
+
export function statusLabel(status, t) {
|
|
207
|
+
const text = typeof status === 'string' ? status.trim() : '';
|
|
208
|
+
if (text === '')
|
|
209
|
+
return t('creator.status.ready');
|
|
210
|
+
const mark = LEADING_MARK.exec(text)?.[0] ?? '';
|
|
211
|
+
const said = sayKnown(text.slice(mark.length), t);
|
|
212
|
+
return said === null ? text : `${mark}${said}`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* What a screen shows for an error text the creator stored. Nothing stored is an empty text (so a screen can write
|
|
216
|
+
* `errorLabel(error, t) || fallback`); an error the creator does not know is shown as it is.
|
|
217
|
+
*/
|
|
218
|
+
export function errorLabel(error, t) {
|
|
219
|
+
const text = typeof error === 'string' ? error.trim() : '';
|
|
220
|
+
if (text === '')
|
|
221
|
+
return '';
|
|
222
|
+
return sayKnown(text, t) ?? text;
|
|
223
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as CreatorApp } from './CreatorApp.svelte';
|
|
2
2
|
export type { CreatorAppProps } from './creator-types.js';
|
|
3
3
|
export { syncSessionFromSiteAuth } from './syncSiteAuth.js';
|
|
4
|
+
export { ALL_CREATOR_MESSAGES, CREATOR_MESSAGES, checkCreatorMessages, type CreatorMessageKey } from './i18n/index.js';
|
|
4
5
|
export { mount, unmount } from 'svelte';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as CreatorApp } from './CreatorApp.svelte';
|
|
2
2
|
export { syncSessionFromSiteAuth } from './syncSiteAuth.js';
|
|
3
|
+
// The words of the creator: the catalog a page's `messages` may have keys of, and a check for them (see the README).
|
|
4
|
+
export { ALL_CREATOR_MESSAGES, CREATOR_MESSAGES, checkCreatorMessages } from './i18n/index.js';
|
|
3
5
|
// Re-export so site hosts can mount the self-contained embed with the same
|
|
4
6
|
// Svelte runtime that compiled CreatorApp (avoid dual-runtime crashes).
|
|
5
7
|
export { mount, unmount } from 'svelte';
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in visitor, as the creator knows them.
|
|
3
|
+
*
|
|
4
|
+
* Starts empty and reads nothing when this file is loaded: importing the creator into a partner's page must not look
|
|
5
|
+
* at the partner's own `jwt` and `user` keys. `restoreSession()` (the creator calls it when it starts outside a
|
|
6
|
+
* partner's page) is what loads the stored sign-in.
|
|
7
|
+
*/
|
|
1
8
|
export declare const userSession: import("svelte/store").Writable<{
|
|
2
9
|
user: any;
|
|
3
|
-
jwt: string;
|
|
10
|
+
jwt: string | null;
|
|
4
11
|
}>;
|
|
5
12
|
export declare function setSession(user: any, jwt: any): void;
|
|
6
13
|
export declare function clearSession(): void;
|
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
import { writable } from 'svelte/store';
|
|
2
2
|
import { syncLocalCacheOwner } from '../localCacheGate.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
catch { }
|
|
15
|
-
return { user, jwt };
|
|
16
|
-
}
|
|
17
|
-
const initialSession = getInitialSession();
|
|
18
|
-
export const userSession = writable(initialSession);
|
|
19
|
-
if (initialSession.user) {
|
|
20
|
-
syncLocalCacheOwner(initialSession.user);
|
|
21
|
-
}
|
|
3
|
+
import { creatorStorage } from '../host/creatorHost.js';
|
|
4
|
+
/**
|
|
5
|
+
* The signed-in visitor, as the creator knows them.
|
|
6
|
+
*
|
|
7
|
+
* Starts empty and reads nothing when this file is loaded: importing the creator into a partner's page must not look
|
|
8
|
+
* at the partner's own `jwt` and `user` keys. `restoreSession()` (the creator calls it when it starts outside a
|
|
9
|
+
* partner's page) is what loads the stored sign-in.
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the user record is whatever the sign-in endpoint (or the site's JWT) carried
|
|
12
|
+
export const userSession = writable({ user: null, jwt: null });
|
|
22
13
|
export function setSession(user, jwt) {
|
|
23
14
|
userSession.set({ user, jwt });
|
|
24
15
|
if (jwt)
|
|
25
|
-
|
|
16
|
+
creatorStorage.setItem('jwt', jwt);
|
|
26
17
|
if (user)
|
|
27
|
-
|
|
18
|
+
creatorStorage.setItem('user', JSON.stringify(user));
|
|
28
19
|
syncLocalCacheOwner(user);
|
|
29
20
|
}
|
|
30
21
|
export function clearSession() {
|
|
31
22
|
userSession.set({ user: null, jwt: null });
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
creatorStorage.removeItem('jwt');
|
|
24
|
+
creatorStorage.removeItem('user');
|
|
34
25
|
syncLocalCacheOwner(null);
|
|
35
26
|
}
|
|
36
27
|
export function restoreSession() {
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
if (typeof window === 'undefined')
|
|
29
|
+
return;
|
|
30
|
+
const jwt = creatorStorage.getItem('jwt');
|
|
31
|
+
const userStr = creatorStorage.getItem('user');
|
|
39
32
|
let user = null;
|
|
40
33
|
try {
|
|
41
34
|
if (userStr)
|
|
@@ -53,4 +53,10 @@ export declare function connectWebSocket(userId?: string): Promise<boolean>;
|
|
|
53
53
|
* Disconnect from WebSocket.
|
|
54
54
|
*/
|
|
55
55
|
export declare function disconnectWebSocket(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Forgets what this module holds about the visitor: the token, the socket, and the last operation, build and preview
|
|
58
|
+
* the stores reported. For a creator that leaves a page it shares with whoever comes next (a partner's page may start
|
|
59
|
+
* another visitor in the same tab), so nothing of the first visitor's work is on show when the next one arrives.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resetRealtimeState(): void;
|
|
56
62
|
export {};
|
|
@@ -7,21 +7,23 @@
|
|
|
7
7
|
* - Dynamic Worker preview readiness
|
|
8
8
|
*/
|
|
9
9
|
import { writable, get } from 'svelte/store';
|
|
10
|
+
import { mayUseRealtimeSocket } from '../host/creatorHost.js';
|
|
10
11
|
// =============================================================================
|
|
11
12
|
// Stores
|
|
12
13
|
// =============================================================================
|
|
13
|
-
|
|
14
|
+
/** What each store holds before anything has happened (also what a reset puts back). */
|
|
15
|
+
const emptyConnectionState = () => ({
|
|
14
16
|
connected: false,
|
|
15
17
|
joinedRooms: [],
|
|
16
18
|
error: null
|
|
17
19
|
});
|
|
18
|
-
|
|
20
|
+
const emptyDynamicWorkerPreviewStatus = () => ({
|
|
19
21
|
widgetId: null,
|
|
20
22
|
previewUrl: null,
|
|
21
23
|
buildTimeMs: null,
|
|
22
24
|
timestamp: null
|
|
23
25
|
});
|
|
24
|
-
|
|
26
|
+
const emptyWidgetPublishStatus = () => ({
|
|
25
27
|
widgetId: null,
|
|
26
28
|
status: null,
|
|
27
29
|
version: undefined,
|
|
@@ -30,7 +32,7 @@ export const widgetPublishStatus = writable({
|
|
|
30
32
|
error: undefined,
|
|
31
33
|
timestamp: null
|
|
32
34
|
});
|
|
33
|
-
|
|
35
|
+
const emptyCodeGenerationStatus = () => ({
|
|
34
36
|
operationId: null,
|
|
35
37
|
status: null,
|
|
36
38
|
previousStatus: null,
|
|
@@ -38,6 +40,10 @@ export const codeGenerationStatus = writable({
|
|
|
38
40
|
error: null,
|
|
39
41
|
timestamp: null
|
|
40
42
|
});
|
|
43
|
+
export const connectionState = writable(emptyConnectionState());
|
|
44
|
+
export const dynamicWorkerPreviewStatus = writable(emptyDynamicWorkerPreviewStatus());
|
|
45
|
+
export const widgetPublishStatus = writable(emptyWidgetPublishStatus());
|
|
46
|
+
export const codeGenerationStatus = writable(emptyCodeGenerationStatus());
|
|
41
47
|
export const agentHarnessOutput = writable(null);
|
|
42
48
|
/**
|
|
43
49
|
* Throttle for high-frequency agent harness frames. The stream used to emit one
|
|
@@ -257,6 +263,10 @@ function setupSocketListeners(sock) {
|
|
|
257
263
|
* Connect to WebSocket and join user room for receiving events.
|
|
258
264
|
*/
|
|
259
265
|
export async function connectWebSocket(userId) {
|
|
266
|
+
// The socket only knows signed-in accounts, not editor sessions: in a partner's page the creator follows its
|
|
267
|
+
// operations through the operations stream instead, and opens no socket to the API.
|
|
268
|
+
if (!mayUseRealtimeSocket())
|
|
269
|
+
return false;
|
|
260
270
|
const sock = await getSocket();
|
|
261
271
|
if (!sock) {
|
|
262
272
|
if (showLogs)
|
|
@@ -314,3 +324,28 @@ export async function disconnectWebSocket() {
|
|
|
314
324
|
joinedRooms: []
|
|
315
325
|
}));
|
|
316
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Forgets what this module holds about the visitor: the token, the socket, and the last operation, build and preview
|
|
329
|
+
* the stores reported. For a creator that leaves a page it shares with whoever comes next (a partner's page may start
|
|
330
|
+
* another visitor in the same tab), so nothing of the first visitor's work is on show when the next one arrives.
|
|
331
|
+
*/
|
|
332
|
+
export function resetRealtimeState() {
|
|
333
|
+
setAuthToken(null);
|
|
334
|
+
activeUserId = null;
|
|
335
|
+
if (socket && socket.connected) {
|
|
336
|
+
socket.disconnect();
|
|
337
|
+
}
|
|
338
|
+
socket = null;
|
|
339
|
+
socketImportPromise = null;
|
|
340
|
+
lastTokenUsed = null;
|
|
341
|
+
if (agentHarnessFlushTimer) {
|
|
342
|
+
clearTimeout(agentHarnessFlushTimer);
|
|
343
|
+
agentHarnessFlushTimer = null;
|
|
344
|
+
}
|
|
345
|
+
agentHarnessPending = null;
|
|
346
|
+
connectionState.set(emptyConnectionState());
|
|
347
|
+
dynamicWorkerPreviewStatus.set(emptyDynamicWorkerPreviewStatus());
|
|
348
|
+
widgetPublishStatus.set(emptyWidgetPublishStatus());
|
|
349
|
+
codeGenerationStatus.set(emptyCodeGenerationStatus());
|
|
350
|
+
agentHarnessOutput.set(null);
|
|
351
|
+
}
|
|
@@ -174,3 +174,11 @@ export declare function formatDesignIntentTelemetryReport(snapshot: DesignIntent
|
|
|
174
174
|
/** Recent events (last 100, newest last) — for a quick look in the console. */
|
|
175
175
|
export declare function getRecentDesignIntentEvents(): DesignIntentTelemetryEvent[];
|
|
176
176
|
export declare function resetDesignIntentTelemetry(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Dev/ops handle: inspect or reset from the console without a rebuild
|
|
179
|
+
* (`__widgeticDesignIntentTelemetry.report()`).
|
|
180
|
+
*
|
|
181
|
+
* Installed by the creator when it starts on the Widgetic site or the standalone app, not when this file is loaded
|
|
182
|
+
* and not in a partner's page: a global on the partner's `window` is theirs to name.
|
|
183
|
+
*/
|
|
184
|
+
export declare function installDesignIntentTelemetryConsoleHandle(): void;
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* total.
|
|
26
26
|
*/
|
|
27
27
|
import { collectDesignProperties, resolveDesignIntent, scoreDesignProperties } from './designIntentResolver';
|
|
28
|
+
import { creatorStorage } from '../host/creatorHost.js';
|
|
28
29
|
export const DESIGN_INTENT_BUCKETS = [
|
|
29
30
|
'literal_arithmetic',
|
|
30
31
|
'bounded_set_semantic',
|
|
@@ -228,22 +229,31 @@ export function parsePersistedTelemetry(raw) {
|
|
|
228
229
|
}
|
|
229
230
|
function loadPersisted() {
|
|
230
231
|
try {
|
|
231
|
-
if (typeof
|
|
232
|
+
if (typeof window === 'undefined')
|
|
232
233
|
return parsePersistedTelemetry(null);
|
|
233
|
-
return parsePersistedTelemetry(
|
|
234
|
+
return parsePersistedTelemetry(creatorStorage.getItem(STORAGE_KEY));
|
|
234
235
|
}
|
|
235
236
|
catch {
|
|
236
237
|
return parsePersistedTelemetry(null);
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
|
|
240
|
+
/**
|
|
241
|
+
* The counters, read from the creator's storage the first time they are needed — not when this file is loaded, so
|
|
242
|
+
* importing the creator into a partner's page does not touch that page's storage.
|
|
243
|
+
*/
|
|
244
|
+
let state = null;
|
|
245
|
+
function currentState() {
|
|
246
|
+
if (state === null)
|
|
247
|
+
state = loadPersisted();
|
|
248
|
+
return state;
|
|
249
|
+
}
|
|
240
250
|
const recent = [];
|
|
241
251
|
const RECENT_CAP = 100;
|
|
242
252
|
function persist() {
|
|
243
253
|
try {
|
|
244
|
-
if (typeof
|
|
254
|
+
if (typeof window === 'undefined')
|
|
245
255
|
return;
|
|
246
|
-
|
|
256
|
+
creatorStorage.setItem(STORAGE_KEY, JSON.stringify(currentState()));
|
|
247
257
|
}
|
|
248
258
|
catch {
|
|
249
259
|
/* a full/blocked store must never break a chat send */
|
|
@@ -259,11 +269,11 @@ export function recordDesignIntentTelemetry(message, schema) {
|
|
|
259
269
|
const classification = hasSchema
|
|
260
270
|
? classifyDesignIntent(message, schema)
|
|
261
271
|
: { bucket: 'not_design', propertyIds: [], detail: 'no design schema loaded' };
|
|
262
|
-
|
|
272
|
+
currentState().total += 1;
|
|
263
273
|
if (!hasSchema)
|
|
264
|
-
|
|
274
|
+
currentState().noSchema += 1;
|
|
265
275
|
else
|
|
266
|
-
|
|
276
|
+
currentState().buckets[classification.bucket] += 1;
|
|
267
277
|
const event = {
|
|
268
278
|
...classification,
|
|
269
279
|
messageLength: String(message ?? '').length,
|
|
@@ -273,7 +283,7 @@ export function recordDesignIntentTelemetry(message, schema) {
|
|
|
273
283
|
if (recent.length > RECENT_CAP)
|
|
274
284
|
recent.shift();
|
|
275
285
|
persist();
|
|
276
|
-
const counted =
|
|
286
|
+
const counted = currentState().total - currentState().noSchema;
|
|
277
287
|
console.log(`[DesignIntentTelemetry] bucket=${classification.bucket}` +
|
|
278
288
|
` shape=${classification.shape ?? 'n/a'}` +
|
|
279
289
|
` detail="${classification.detail}"` +
|
|
@@ -291,64 +301,64 @@ export function recordDesignIntentTelemetry(message, schema) {
|
|
|
291
301
|
* `shadow` to `enforce`.
|
|
292
302
|
*/
|
|
293
303
|
export function recordDesignIntentJevOutcome(outcome) {
|
|
294
|
-
|
|
304
|
+
currentState().jev.attempts += 1;
|
|
295
305
|
if (outcome.acted)
|
|
296
|
-
|
|
306
|
+
currentState().jev.acted += 1;
|
|
297
307
|
else
|
|
298
|
-
|
|
308
|
+
currentState().jev.fellThrough += 1;
|
|
299
309
|
const reason = outcome.reason || 'unknown';
|
|
300
|
-
|
|
310
|
+
currentState().jev.byReason[reason] = (currentState().jev.byReason[reason] ?? 0) + 1;
|
|
301
311
|
// Attribute the dial to the ask shape that produced it: this is what turns a
|
|
302
312
|
// reason count into a decision about the option strings or the confidence
|
|
303
313
|
// floor, since each shape puts a different question under load.
|
|
304
314
|
const shape = outcome.classification?.shape ?? 'unknown';
|
|
305
|
-
const slice =
|
|
315
|
+
const slice = currentState().jev.byShape[shape] ?? emptyShapeBreakdown();
|
|
306
316
|
slice.attempts += 1;
|
|
307
317
|
if (outcome.acted)
|
|
308
318
|
slice.acted += 1;
|
|
309
319
|
else
|
|
310
320
|
slice.fellThrough += 1;
|
|
311
321
|
slice.byReason[reason] = (slice.byReason[reason] ?? 0) + 1;
|
|
312
|
-
|
|
322
|
+
currentState().jev.byShape[shape] = slice;
|
|
313
323
|
// Only the bounded-set-semantic bucket is ever dialed by design, so a dial on
|
|
314
324
|
// any other bucket is counted as the anomaly it is instead of being mixed in.
|
|
315
325
|
const bucket = outcome.classification?.bucket;
|
|
316
326
|
if (bucket && bucket !== JEV_CANDIDATE_BUCKET)
|
|
317
|
-
|
|
327
|
+
currentState().jev.offBucketDials += 1;
|
|
318
328
|
persist();
|
|
319
329
|
console.log(`[DesignIntentTelemetry] jev source=${outcome.source} acted=${outcome.acted} reason=${reason}` +
|
|
320
330
|
` shape=${shape}` +
|
|
321
|
-
` resolved=${
|
|
331
|
+
` resolved=${currentState().jev.acted}/${currentState().jev.attempts}`);
|
|
322
332
|
}
|
|
323
333
|
export function getDesignIntentTelemetrySnapshot() {
|
|
324
|
-
const counted =
|
|
334
|
+
const counted = currentState().total - currentState().noSchema;
|
|
325
335
|
const fractions = emptyBuckets();
|
|
326
336
|
for (const bucket of DESIGN_INTENT_BUCKETS) {
|
|
327
|
-
fractions[bucket] = counted > 0 ?
|
|
337
|
+
fractions[bucket] = counted > 0 ? currentState().buckets[bucket] / counted : 0;
|
|
328
338
|
}
|
|
329
339
|
const modelShare = counted > 0
|
|
330
|
-
? (
|
|
340
|
+
? (currentState().buckets.bounded_set_semantic + currentState().buckets.free_text + currentState().buckets.new_property) / counted
|
|
331
341
|
: 0;
|
|
332
342
|
return {
|
|
333
|
-
total:
|
|
343
|
+
total: currentState().total,
|
|
334
344
|
counted,
|
|
335
|
-
noSchema:
|
|
336
|
-
buckets: { ...
|
|
345
|
+
noSchema: currentState().noSchema,
|
|
346
|
+
buckets: { ...currentState().buckets },
|
|
337
347
|
fractions,
|
|
338
348
|
deterministicShare: fractions.literal_arithmetic,
|
|
339
349
|
modelShare,
|
|
340
350
|
jev: {
|
|
341
|
-
attempts:
|
|
342
|
-
acted:
|
|
343
|
-
fellThrough:
|
|
344
|
-
resolvedShare: share(
|
|
345
|
-
byReason: { ...
|
|
351
|
+
attempts: currentState().jev.attempts,
|
|
352
|
+
acted: currentState().jev.acted,
|
|
353
|
+
fellThrough: currentState().jev.fellThrough,
|
|
354
|
+
resolvedShare: share(currentState().jev.acted, currentState().jev.attempts),
|
|
355
|
+
byReason: { ...currentState().jev.byReason },
|
|
346
356
|
byShape: {
|
|
347
|
-
property_named: withShare(
|
|
348
|
-
value_only: withShare(
|
|
349
|
-
unknown: withShare(
|
|
357
|
+
property_named: withShare(currentState().jev.byShape.property_named),
|
|
358
|
+
value_only: withShare(currentState().jev.byShape.value_only),
|
|
359
|
+
unknown: withShare(currentState().jev.byShape.unknown)
|
|
350
360
|
},
|
|
351
|
-
offBucketDials:
|
|
361
|
+
offBucketDials: currentState().jev.offBucketDials
|
|
352
362
|
}
|
|
353
363
|
};
|
|
354
364
|
}
|
|
@@ -459,8 +469,16 @@ export function resetDesignIntentTelemetry() {
|
|
|
459
469
|
recent.length = 0;
|
|
460
470
|
persist();
|
|
461
471
|
}
|
|
462
|
-
|
|
463
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Dev/ops handle: inspect or reset from the console without a rebuild
|
|
474
|
+
* (`__widgeticDesignIntentTelemetry.report()`).
|
|
475
|
+
*
|
|
476
|
+
* Installed by the creator when it starts on the Widgetic site or the standalone app, not when this file is loaded
|
|
477
|
+
* and not in a partner's page: a global on the partner's `window` is theirs to name.
|
|
478
|
+
*/
|
|
479
|
+
export function installDesignIntentTelemetryConsoleHandle() {
|
|
480
|
+
if (typeof window === 'undefined')
|
|
481
|
+
return;
|
|
464
482
|
window.__widgeticDesignIntentTelemetry = {
|
|
465
483
|
snapshot: getDesignIntentTelemetrySnapshot,
|
|
466
484
|
report: () => {
|