@widgetic/creator 0.4.34 → 0.4.36
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 +3 -3
- package/dist/CreatorApp.svelte +30 -92
- package/dist/components/FileUrlSourceControl.svelte.d.ts +1 -1
- package/dist/components/GenerationOptionsPanel.svelte +216 -0
- package/dist/components/GenerationOptionsPanel.svelte.d.ts +21 -0
- package/dist/components/WidgetDetails.svelte +5 -8
- package/dist/components/WidgetDetails.svelte.d.ts +1 -1
- package/dist/generation/brandKitForRequest.d.ts +16 -0
- package/dist/generation/brandKitForRequest.js +12 -0
- package/dist/i18n/language.d.ts +4 -164
- package/dist/i18n/messages.d.ts +0 -21
- package/dist/i18n/messages.js +1 -22
- package/dist/utils/generationSharing.d.ts +1 -1
- package/dist/utils/generationSharing.js +1 -1
- package/package.json +3 -3
- package/dist/components/BrandKitPanel.svelte +0 -581
- package/dist/components/BrandKitPanel.svelte.d.ts +0 -33
package/README.md
CHANGED
|
@@ -130,7 +130,7 @@ console.log(CREATOR_MESSAGES['creator.embed.codeTitle']); // 'Embed Code ({forma
|
|
|
130
130
|
| `creator.codegen.`, `creator.preview.`, `creator.version.`, `creator.versions.` | code generation, repositories and the confirm dialog, the preview banners, versions and checkpoints, and the rows of the version list |
|
|
131
131
|
| `creator.publish.`, `creator.embed.`, `creator.dialog.` | publishing (buttons, the reasons a publish is not possible, toasts), the Embed step and the sentences of the dialogs that have a name inside them |
|
|
132
132
|
| `creator.status.`, `creator.error.` | the status bar of a generation and the error texts the creator writes itself (see "What stays as it is") |
|
|
133
|
-
| `creator.details.`, `creator.brandKit.`, `creator.livePreviews.` | the widget details panel, the brand kit
|
|
133
|
+
| `creator.details.`, `creator.brandKit.`, `creator.livePreviews.` | the widget details panel, the chat's generation options (language and libraries; the `brandKit` prefix is the name they had when this panel held the brand kit, which is now account-level), and the live previews drawn on the canvas shapes |
|
|
134
134
|
| `creator.selector.`, `creator.name.`, `creator.designEdit.`, `creator.fileSource.` | the dropdown that picks a canvas or a composition, the editable name, the quick edit of design values and the control that takes a file or a web address |
|
|
135
135
|
| `chat.`, `canvas.`, `editor.`, `shadEditor.` and the File Browser's own keys | the chat, the canvas, the editor, the rich text editor of its text boxes and the File Browser that picks a file |
|
|
136
136
|
|
|
@@ -205,8 +205,8 @@ while the creator is open:
|
|
|
205
205
|
(`src/lib/utils/directionPlacement.ts`): a divider is dragged toward the end of the line (`distanceTowardEnd`), a list
|
|
206
206
|
under a cluster of controls is lined up with the end edge of the cluster (`listAlignedToEnd`), the title of a widget in
|
|
207
207
|
its panel is given the room up to the box that stands beyond it (`roomBeforeNeighbour`; measured the left to right way it
|
|
208
|
-
came out negative and the title showed as a dot), and
|
|
209
|
-
button (`popUpLeftFromAnchor
|
|
208
|
+
came out negative and the title showed as a dot), and a pop-up that hangs from a button hangs from the start edge of
|
|
209
|
+
that button (`popUpLeftFromAnchor`; nothing in the creator uses it since the brand kit pop-up went away).
|
|
210
210
|
- **What a person types** (the chat box, the text fields of the quick edit) is read by its own first letter on a right to
|
|
211
211
|
left screen, and a field with nothing in it yet takes the direction of the screen. A link (the file link field) and a
|
|
212
212
|
colour code are addresses and stay left to right on every screen.
|
package/dist/CreatorApp.svelte
CHANGED
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
import type {
|
|
32
32
|
Middleware,
|
|
33
33
|
GenerateCodeRequest,
|
|
34
|
-
|
|
34
|
+
ListLlmModels200ResponseModelsInner
|
|
35
35
|
} from '@widgetic/api-sdk';
|
|
36
36
|
import { parseVersionPreviewError } from './utils/versionPreviewError.js';
|
|
37
37
|
import { widgetBuilderRequestInit } from './utils/widgetBuilderRequest.js';
|
|
38
38
|
import { gzipRequestBodyMiddleware } from './utils/gzipRequestMiddleware.js';
|
|
39
39
|
import type { SelectedWidgetElementReference } from './utils/widgetElementSelector.js';
|
|
40
|
-
import
|
|
40
|
+
import GenerationOptionsPanel from './components/GenerationOptionsPanel.svelte';
|
|
41
|
+
import { brandKitForRequest } from './generation/brandKitForRequest.js';
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Idempotency middleware (Phase 2 hardening): the gateway rejects
|
|
@@ -768,7 +769,7 @@
|
|
|
768
769
|
// An account matter: a visitor of a partner has no trial and no balance of their own to show.
|
|
769
770
|
if (!usersClient || !mayShowAccountBilling()) return;
|
|
770
771
|
try {
|
|
771
|
-
const accepted = await usersClient.
|
|
772
|
+
const accepted = await usersClient.getPersonalBillingRaw();
|
|
772
773
|
const body = await accepted.raw.json();
|
|
773
774
|
const data = (body && typeof body === 'object' && 'data' in body ? body.data : body) as {
|
|
774
775
|
trialActive?: boolean;
|
|
@@ -1512,45 +1513,12 @@
|
|
|
1512
1513
|
// Populated via Chat's onConversationChange callback and passed to generateCode()
|
|
1513
1514
|
// so the backend can load multi-turn LLM history (Aider-style incremental edits).
|
|
1514
1515
|
let currentChatConversationId: string | null = null;
|
|
1515
|
-
let brandKitEnabled = false;
|
|
1516
1516
|
let widgetLanguage: 'svelte' | 'react' = 'react';
|
|
1517
1517
|
let librariesEnabled = false;
|
|
1518
|
-
let
|
|
1519
|
-
let brandSecondary = '#7BA668';
|
|
1520
|
-
let brandTitle = '#0F2010';
|
|
1521
|
-
let brandSub = '#5C6B58';
|
|
1522
|
-
let brandFonts = ['Inter'];
|
|
1523
|
-
let brandKitLibraries: string[] = [];
|
|
1518
|
+
let generationLibraries: string[] = [];
|
|
1524
1519
|
let libraryGitUrl = '';
|
|
1525
1520
|
let libraryFileName = '';
|
|
1526
1521
|
let libraryUploads: { name: string; content: string; encoding: string }[] = [];
|
|
1527
|
-
let fontUploads: { name: string; content: string; encoding: string }[] = [];
|
|
1528
|
-
|
|
1529
|
-
function brandKitForRequest() {
|
|
1530
|
-
const kit: {
|
|
1531
|
-
colors?: { primary: string; secondary: string; title: string; sub: string };
|
|
1532
|
-
fonts?: string[];
|
|
1533
|
-
libraries?: string[];
|
|
1534
|
-
uploads?: { name: string; content: string; encoding: string }[];
|
|
1535
|
-
fontFiles?: { name: string; content: string; encoding: string }[];
|
|
1536
|
-
} = {};
|
|
1537
|
-
if (brandKitEnabled) {
|
|
1538
|
-
kit.colors = {
|
|
1539
|
-
primary: brandPrimary,
|
|
1540
|
-
secondary: brandSecondary,
|
|
1541
|
-
title: brandTitle,
|
|
1542
|
-
sub: brandSub,
|
|
1543
|
-
};
|
|
1544
|
-
const families = brandFonts.map((family) => family.trim()).filter(Boolean).slice(0, 3);
|
|
1545
|
-
if (families.length > 0) kit.fonts = families;
|
|
1546
|
-
}
|
|
1547
|
-
// Preset libraries are a debug test. An empty list is an explicit ban.
|
|
1548
|
-
if (librariesEnabled && debugMode) kit.libraries = [...brandKitLibraries];
|
|
1549
|
-
if (brandKitEnabled && fontUploads.length > 0) kit.fontFiles = fontUploads.map((file) => ({ ...file }));
|
|
1550
|
-
if (libraryUploads.length > 0) kit.uploads = libraryUploads.map((file) => ({ ...file }));
|
|
1551
|
-
if (!kit.colors && !kit.fonts && !kit.libraries && !kit.uploads && !kit.fontFiles) return undefined;
|
|
1552
|
-
return kit;
|
|
1553
|
-
}
|
|
1554
1522
|
|
|
1555
1523
|
/** Prompt mentions a reference image but chat has no attachment (common UX mistake). */
|
|
1556
1524
|
function promptImpliesVisionReference(prompt: string): boolean {
|
|
@@ -5934,13 +5902,13 @@
|
|
|
5934
5902
|
try {
|
|
5935
5903
|
// Use AgentApi from SDK - no need for manual fetch
|
|
5936
5904
|
// Clients are initialized once via initializeAuthenticatedClients() after login
|
|
5937
|
-
const response = await agentClient.
|
|
5905
|
+
const response = await agentClient.listLlmModels();
|
|
5938
5906
|
// console.log('[WidgetCreator] Models API response:', response);
|
|
5939
5907
|
|
|
5940
5908
|
// SDK returns { success, models } directly (not nested under data)
|
|
5941
5909
|
if (response.success && Array.isArray(response.models)) {
|
|
5942
5910
|
// Transform API response to match our interface
|
|
5943
|
-
availableModels = response.models.map((m:
|
|
5911
|
+
availableModels = response.models.map((m: ListLlmModels200ResponseModelsInner) => ({
|
|
5944
5912
|
id: m.id ?? '',
|
|
5945
5913
|
name: m.displayName ?? '',
|
|
5946
5914
|
provider: (m.provider ?? '').charAt(0).toUpperCase() + (m.provider ?? '').slice(1), // Capitalize provider
|
|
@@ -6691,7 +6659,7 @@
|
|
|
6691
6659
|
try {
|
|
6692
6660
|
let snapshot: OperationSnapshot | null = null;
|
|
6693
6661
|
try {
|
|
6694
|
-
const answer = await client.
|
|
6662
|
+
const answer = await client.getOperationRaw({ id: operationId });
|
|
6695
6663
|
snapshot = readOperationBody(await answer.raw.json());
|
|
6696
6664
|
} catch (error) {
|
|
6697
6665
|
const httpStatus = httpStatusOfFailure(error);
|
|
@@ -9027,7 +8995,7 @@
|
|
|
9027
8995
|
async function fetchRepoHeadCommitSha(widgetId: string): Promise<string | null> {
|
|
9028
8996
|
if (!widgetId || !agentClient) return null;
|
|
9029
8997
|
try {
|
|
9030
|
-
const json = await agentClient.
|
|
8998
|
+
const json = await agentClient.getWidgetRepositoryHead({ widgetId });
|
|
9031
8999
|
const repoHeadEnvelope = json as unknown as {
|
|
9032
9000
|
data?: { repoHeadCommitSha?: string | null; repo_head_commit_sha?: string | null };
|
|
9033
9001
|
repoHeadCommitSha?: string | null;
|
|
@@ -9441,7 +9409,7 @@
|
|
|
9441
9409
|
try {
|
|
9442
9410
|
// The API wraps the operation in `{ success, data }`, which the generated client reads as an operation
|
|
9443
9411
|
// with every field empty (a poll could then never see the end): the raw answer is read instead.
|
|
9444
|
-
const answer = await operationsClient.
|
|
9412
|
+
const answer = await operationsClient.getOperationRaw(
|
|
9445
9413
|
{ id: operationId },
|
|
9446
9414
|
{ signal: pollAbortController.signal }
|
|
9447
9415
|
);
|
|
@@ -10643,14 +10611,7 @@ Requirements:
|
|
|
10643
10611
|
language: 'svelte' | 'react';
|
|
10644
10612
|
librariesEnabled: boolean;
|
|
10645
10613
|
libraries: string[];
|
|
10646
|
-
brandKitEnabled: boolean;
|
|
10647
|
-
primary: string;
|
|
10648
|
-
secondary: string;
|
|
10649
|
-
title: string;
|
|
10650
|
-
sub: string;
|
|
10651
|
-
fonts: string[];
|
|
10652
10614
|
libraryUploads: { name: string; content: string; encoding: string }[];
|
|
10653
|
-
fontUploads: { name: string; content: string; encoding: string }[];
|
|
10654
10615
|
};
|
|
10655
10616
|
|
|
10656
10617
|
let generationOptionsMemory: Record<string, RememberedGenerationOptions> = {};
|
|
@@ -10659,15 +10620,8 @@ Requirements:
|
|
|
10659
10620
|
return {
|
|
10660
10621
|
language: widgetLanguage === 'react' ? 'react' : 'svelte',
|
|
10661
10622
|
librariesEnabled,
|
|
10662
|
-
libraries: [...
|
|
10663
|
-
brandKitEnabled,
|
|
10664
|
-
primary: brandPrimary,
|
|
10665
|
-
secondary: brandSecondary,
|
|
10666
|
-
title: brandTitle,
|
|
10667
|
-
sub: brandSub,
|
|
10668
|
-
fonts: [...brandFonts],
|
|
10623
|
+
libraries: [...generationLibraries],
|
|
10669
10624
|
libraryUploads: libraryUploads.map((file) => ({ ...file })),
|
|
10670
|
-
fontUploads: fontUploads.map((file) => ({ ...file })),
|
|
10671
10625
|
};
|
|
10672
10626
|
}
|
|
10673
10627
|
|
|
@@ -10681,12 +10635,6 @@ Requirements:
|
|
|
10681
10635
|
language: options.language,
|
|
10682
10636
|
librariesEnabled: options.librariesEnabled,
|
|
10683
10637
|
libraries: options.libraries,
|
|
10684
|
-
brandKitEnabled: options.brandKitEnabled,
|
|
10685
|
-
primary: options.primary,
|
|
10686
|
-
secondary: options.secondary,
|
|
10687
|
-
title: options.title,
|
|
10688
|
-
sub: options.sub,
|
|
10689
|
-
fonts: options.fonts,
|
|
10690
10638
|
}));
|
|
10691
10639
|
} catch (error) {
|
|
10692
10640
|
console.warn('[WidgetCreator] Could not store generation options', error);
|
|
@@ -10764,15 +10712,8 @@ Requirements:
|
|
|
10764
10712
|
const storedLanguage = options?.language === 'svelte' || options?.language === 'react' ? options.language : null;
|
|
10765
10713
|
widgetLanguage = languageToShow(widgetId, storedLanguage);
|
|
10766
10714
|
librariesEnabled = !!options?.librariesEnabled;
|
|
10767
|
-
|
|
10768
|
-
brandKitEnabled = !!options?.brandKitEnabled;
|
|
10769
|
-
brandPrimary = options?.primary || '#314F2F';
|
|
10770
|
-
brandSecondary = options?.secondary || '#7BA668';
|
|
10771
|
-
brandTitle = options?.title || '#0F2010';
|
|
10772
|
-
brandSub = options?.sub || '#5C6B58';
|
|
10773
|
-
brandFonts = Array.isArray(options?.fonts) && options.fonts.length > 0 ? [...options.fonts] : ['Inter'];
|
|
10715
|
+
generationLibraries = Array.isArray(options?.libraries) ? [...options.libraries] : [];
|
|
10774
10716
|
libraryUploads = inMemory?.libraryUploads ? inMemory.libraryUploads.map((file) => ({ ...file })) : [];
|
|
10775
|
-
fontUploads = inMemory?.fontUploads ? inMemory.fontUploads.map((file) => ({ ...file })) : [];
|
|
10776
10717
|
}
|
|
10777
10718
|
|
|
10778
10719
|
function languageForGeneration(widgetId: string): 'svelte' | 'react' {
|
|
@@ -11113,7 +11054,7 @@ Requirements:
|
|
|
11113
11054
|
if (signal.aborted) return;
|
|
11114
11055
|
// The generated client types this call as void and drops the 202 body.
|
|
11115
11056
|
// Read the raw JSON so operationId and the intent-gate payload survive.
|
|
11116
|
-
const accepted = await agentClient.
|
|
11057
|
+
const accepted = await agentClient.generateCodeRaw({
|
|
11117
11058
|
generateCodeRequest: {
|
|
11118
11059
|
repositoryId: repoId,
|
|
11119
11060
|
prompt: options.promptForModel || prompt,
|
|
@@ -11133,7 +11074,12 @@ Requirements:
|
|
|
11133
11074
|
skipIntentGate: options.skipIntentGate === true,
|
|
11134
11075
|
chipIntent: options.chipIntent,
|
|
11135
11076
|
language: languageForGeneration(generationWidgetId),
|
|
11136
|
-
brandKit: brandKitForRequest(
|
|
11077
|
+
brandKit: brandKitForRequest({
|
|
11078
|
+
librariesEnabled,
|
|
11079
|
+
debugMode,
|
|
11080
|
+
libraries: generationLibraries,
|
|
11081
|
+
libraryUploads,
|
|
11082
|
+
}),
|
|
11137
11083
|
...(options.selectedElements && options.selectedElements.length > 0
|
|
11138
11084
|
? {
|
|
11139
11085
|
selectedElements: options.selectedElements.map((el) => ({
|
|
@@ -12255,14 +12201,14 @@ Requirements:
|
|
|
12255
12201
|
|
|
12256
12202
|
publishWidgetStatus = $t('creator.publish.publishingViaWidgetBuilder');
|
|
12257
12203
|
|
|
12258
|
-
const publishData = await agentClient.
|
|
12204
|
+
const publishData = await agentClient.publishBuiltWidget({
|
|
12259
12205
|
widgetId: capturedWidgetId,
|
|
12260
|
-
|
|
12206
|
+
publishBuiltWidgetRequest: {
|
|
12261
12207
|
commitSha: commitShaForPublish || undefined,
|
|
12262
12208
|
// Publishing a Draft the user chose: the server rebuilds from that
|
|
12263
12209
|
// version's commit and stamps it Live instead of minting a new one.
|
|
12264
12210
|
version: targetVersion ?? undefined
|
|
12265
|
-
} as unknown as Parameters<typeof agentClient.
|
|
12211
|
+
} as unknown as Parameters<typeof agentClient.publishBuiltWidget>[0]['publishBuiltWidgetRequest']
|
|
12266
12212
|
}, widgetBuilderRequestInit(widgetBuilderPreviewBaseUrl()));
|
|
12267
12213
|
// console.log('[Publish] Widget Builder publish completed:', publishData);
|
|
12268
12214
|
|
|
@@ -17854,8 +17800,8 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
17854
17800
|
// (Not in a partner's page: the gateway refuses a session this route, and the draft's name does as well.)
|
|
17855
17801
|
if (agentClient && maySuggestWidgetName() && (prompt.trim().length >= 2 || sketchForName)) {
|
|
17856
17802
|
authStatus = 'Naming widget...';
|
|
17857
|
-
const suggestedNameReply = await agentClient.
|
|
17858
|
-
|
|
17803
|
+
const suggestedNameReply = await agentClient.suggestWidgetName({
|
|
17804
|
+
suggestWidgetNameRequest: { prompt, ...(sketchForName ? { image: sketchForName } : {}) },
|
|
17859
17805
|
});
|
|
17860
17806
|
const suggestedName = typeof suggestedNameReply?.name === 'string' ? suggestedNameReply.name.trim() : '';
|
|
17861
17807
|
if (suggestedName) widgetName = suggestedName;
|
|
@@ -18214,7 +18160,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18214
18160
|
if (existingRepoId && verifiedRepositoryIds.has(existingRepoId)) {
|
|
18215
18161
|
// Repo was verified earlier in the session; ping GET /repositories/{repoId}
|
|
18216
18162
|
// in the background so the backend's GitService file/diff caches are hot.
|
|
18217
|
-
void agentClient.
|
|
18163
|
+
void agentClient.getRepository({ repoId: existingRepoId }).catch(() => {});
|
|
18218
18164
|
} else {
|
|
18219
18165
|
await ensureWidgetRepository(widget, { silent: true });
|
|
18220
18166
|
}
|
|
@@ -18273,7 +18219,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18273
18219
|
if (!repoId) return false;
|
|
18274
18220
|
try {
|
|
18275
18221
|
// get the repository details from the database
|
|
18276
|
-
const repoDetails = await agentClient.
|
|
18222
|
+
const repoDetails = await agentClient.getRepository({ repoId });
|
|
18277
18223
|
|
|
18278
18224
|
if (!repoDetails?.id) {
|
|
18279
18225
|
verifiedRepositoryIds.delete(repoId);
|
|
@@ -18319,7 +18265,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18319
18265
|
});
|
|
18320
18266
|
applySiteSessionToCreator();
|
|
18321
18267
|
try {
|
|
18322
|
-
const retryDetails = await agentClient.
|
|
18268
|
+
const retryDetails = await agentClient.getRepository({ repoId });
|
|
18323
18269
|
if (retryDetails?.id) {
|
|
18324
18270
|
verifiedRepositoryIds.add(repoId);
|
|
18325
18271
|
return true;
|
|
@@ -18379,7 +18325,7 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
18379
18325
|
try {
|
|
18380
18326
|
// console.log('Widget Creator: Creating repository for widget:', widget);
|
|
18381
18327
|
const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
|
|
18382
|
-
const response = await agentClient.
|
|
18328
|
+
const response = await agentClient.createRepository({
|
|
18383
18329
|
initRepoRequest: {
|
|
18384
18330
|
name: `Widget Project ${timestamp}`,
|
|
18385
18331
|
widgetId: widget.id
|
|
@@ -19835,22 +19781,14 @@ $: if (codeGenerationPrompt && selectedWidgetId && promptLoadedForWidgetId === s
|
|
|
19835
19781
|
/>
|
|
19836
19782
|
{/snippet}
|
|
19837
19783
|
{#snippet generationOptionChecks()}
|
|
19838
|
-
<
|
|
19784
|
+
<GenerationOptionsPanel
|
|
19839
19785
|
part="checks"
|
|
19840
19786
|
showPresetLibraries={debugMode}
|
|
19841
|
-
suspendPickers={!!generatingWidgetIds[panelWidgetId]}
|
|
19842
|
-
bind:brandKitEnabled
|
|
19843
19787
|
bind:librariesEnabled
|
|
19844
|
-
bind:libraries={
|
|
19788
|
+
bind:libraries={generationLibraries}
|
|
19845
19789
|
bind:libraryGitUrl
|
|
19846
19790
|
bind:libraryFileName
|
|
19847
19791
|
bind:libraryUploads
|
|
19848
|
-
bind:fontUploads
|
|
19849
|
-
bind:primary={brandPrimary}
|
|
19850
|
-
bind:secondary={brandSecondary}
|
|
19851
|
-
bind:title={brandTitle}
|
|
19852
|
-
bind:sub={brandSub}
|
|
19853
|
-
bind:fonts={brandFonts}
|
|
19854
19792
|
showLanguage={debugMode}
|
|
19855
19793
|
languageLocked={!!(generatingWidgetIds[panelWidgetId] || ps.lastCommitId || ps.lastPublishedVersion != null)}
|
|
19856
19794
|
bind:language={widgetLanguage}
|
|
@@ -10,6 +10,6 @@ interface Props {
|
|
|
10
10
|
urlPlaceholder?: string;
|
|
11
11
|
accept?: string;
|
|
12
12
|
}
|
|
13
|
-
declare const FileUrlSourceControl: import("svelte").Component<Props, {}, "
|
|
13
|
+
declare const FileUrlSourceControl: import("svelte").Component<Props, {}, "url" | "fileName" | "fileContent" | "fileEncoding">;
|
|
14
14
|
type FileUrlSourceControl = ReturnType<typeof FileUrlSourceControl>;
|
|
15
15
|
export default FileUrlSourceControl;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Generation options of the chat: the language of a new widget and, in debug mode, the preset and uploaded libraries.
|
|
3
|
+
The brand kit (colors, fonts, icons, spacing, corner radius and style notes) is not here: it belongs to the account
|
|
4
|
+
and is edited in the account settings, so every widget of that account uses it. (The `creator.brandKit.*` message
|
|
5
|
+
keys keep the name they had when this panel held the brand kit; they hold the texts of these options.)
|
|
6
|
+
-->
|
|
7
|
+
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { DropdownMenu } from '@widgetic/design-system';
|
|
10
|
+
import FileUrlSourceControl from './FileUrlSourceControl.svelte';
|
|
11
|
+
import HoverTooltip from './HoverTooltip.svelte';
|
|
12
|
+
import { useCreatorLanguage } from '../i18n/index.js';
|
|
13
|
+
|
|
14
|
+
const { t } = useCreatorLanguage();
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
class?: string;
|
|
18
|
+
style?: string;
|
|
19
|
+
part?: 'checks' | 'panel';
|
|
20
|
+
librariesEnabled?: boolean;
|
|
21
|
+
showPresetLibraries?: boolean;
|
|
22
|
+
libraries?: string[];
|
|
23
|
+
libraryGitUrl?: string;
|
|
24
|
+
libraryFileName?: string;
|
|
25
|
+
libraryUploads?: { name: string; content: string; encoding: string }[];
|
|
26
|
+
showLanguage?: boolean;
|
|
27
|
+
language?: string;
|
|
28
|
+
languageLocked?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
class: className = '',
|
|
33
|
+
style = '',
|
|
34
|
+
part = 'checks',
|
|
35
|
+
librariesEnabled = $bindable(false),
|
|
36
|
+
showPresetLibraries = false,
|
|
37
|
+
libraries = $bindable([] as string[]),
|
|
38
|
+
libraryGitUrl = $bindable(''),
|
|
39
|
+
libraryFileName = $bindable(''),
|
|
40
|
+
libraryUploads = $bindable([] as { name: string; content: string; encoding: string }[]),
|
|
41
|
+
showLanguage = false,
|
|
42
|
+
language = $bindable('react'),
|
|
43
|
+
languageLocked = false,
|
|
44
|
+
}: Props = $props();
|
|
45
|
+
|
|
46
|
+
const libraryChoices = [
|
|
47
|
+
{ id: 'chart.js/auto', label: 'Chart.js' },
|
|
48
|
+
{ id: 'd3', label: 'D3' },
|
|
49
|
+
{ id: 'gsap', label: 'GSAP' },
|
|
50
|
+
{ id: 'three', label: 'Three.js' },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
function toggleLibrary(id: string) {
|
|
54
|
+
const next = libraries.includes(id)
|
|
55
|
+
? libraries.filter((entry) => entry !== id)
|
|
56
|
+
: [...libraries, id];
|
|
57
|
+
libraries = next;
|
|
58
|
+
if (next.length > 0) librariesEnabled = true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type SourceRow = { id: string; fileName: string; url: string; content: string; encoding: string };
|
|
62
|
+
const emptySource = (): SourceRow => ({
|
|
63
|
+
id: crypto.randomUUID(),
|
|
64
|
+
fileName: '',
|
|
65
|
+
url: '',
|
|
66
|
+
content: '',
|
|
67
|
+
encoding: 'utf8',
|
|
68
|
+
});
|
|
69
|
+
let libraryRows = $state<SourceRow[]>([emptySource()]);
|
|
70
|
+
|
|
71
|
+
function addSourceRow() {
|
|
72
|
+
if (libraryRows.length >= 4) return;
|
|
73
|
+
libraryRows = [emptySource(), ...libraryRows];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function removeSourceRow(id: string) {
|
|
77
|
+
const next = libraryRows.filter((row) => row.id !== id);
|
|
78
|
+
libraryRows = next.length > 0 ? next : [emptySource()];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function onLibrariesChange(event: Event) {
|
|
82
|
+
librariesEnabled = (event.currentTarget as HTMLInputElement).checked;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function componentExtension() {
|
|
86
|
+
return language === 'react' ? '.jsx' : '.svelte';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function sourceAccept() {
|
|
90
|
+
return ['.js', '.ts', componentExtension(), '.zip', '.tar', '.tgz', '.gz'].join(',');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
$effect(() => {
|
|
94
|
+
libraryFileName = libraryRows[0]?.fileName || '';
|
|
95
|
+
libraryGitUrl = libraryRows[0]?.url || '';
|
|
96
|
+
libraryUploads = libraryRows
|
|
97
|
+
.filter((row) => row.fileName && row.content)
|
|
98
|
+
.map((row) => ({ name: row.fileName, content: row.content, encoding: row.encoding }));
|
|
99
|
+
});
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
{#if part === 'checks'}
|
|
103
|
+
<div class="generation-options-checks contents {className}" {style}>
|
|
104
|
+
{#if showLanguage || showPresetLibraries}
|
|
105
|
+
<div class="generation-libraries-row ms-auto flex w-full flex-col gap-2">
|
|
106
|
+
<div class="generation-libraries-checks flex flex-nowrap items-center gap-1">
|
|
107
|
+
{#if showLanguage}
|
|
108
|
+
{#if languageLocked}
|
|
109
|
+
<HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.languageIsFixedAfterThe')}>
|
|
110
|
+
<span
|
|
111
|
+
class="generation-language-select flex h-10 w-[4.75rem] shrink-0 cursor-default items-center justify-between gap-0.5 rounded-lg border border-gray-300 bg-white px-1.5 text-sm text-gray-900 opacity-60"
|
|
112
|
+
aria-disabled="true"
|
|
113
|
+
>
|
|
114
|
+
<span class="truncate">{language === 'react' ? 'React' : 'Svelte'}</span>
|
|
115
|
+
</span>
|
|
116
|
+
</HoverTooltip>
|
|
117
|
+
{:else}
|
|
118
|
+
<HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.selectLanguage')}>
|
|
119
|
+
<DropdownMenu.Root>
|
|
120
|
+
<DropdownMenu.Trigger
|
|
121
|
+
class="generation-language-select flex h-10 w-[4.75rem] shrink-0 cursor-pointer items-center justify-between gap-0.5 rounded-lg border border-gray-300 bg-white px-1.5 text-sm text-gray-900"
|
|
122
|
+
>
|
|
123
|
+
<span class="truncate">{language === 'react' ? 'React' : 'Svelte'}</span>
|
|
124
|
+
<svg class="h-3 w-3 shrink-0 text-gray-500" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
125
|
+
<path d="M3 4.5 6 7.5 9 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
|
|
126
|
+
</svg>
|
|
127
|
+
</DropdownMenu.Trigger>
|
|
128
|
+
<DropdownMenu.Content class="w-[4.75rem] min-w-0">
|
|
129
|
+
<DropdownMenu.Item
|
|
130
|
+
class="cursor-pointer {language === 'svelte' ? 'bg-[#314F2F]/15 text-[#314F2F]' : ''}"
|
|
131
|
+
onSelect={() => (language = 'svelte')}
|
|
132
|
+
>Svelte</DropdownMenu.Item>
|
|
133
|
+
<DropdownMenu.Item
|
|
134
|
+
class="cursor-pointer {language === 'react' ? 'bg-[#314F2F]/15 text-[#314F2F]' : ''}"
|
|
135
|
+
onSelect={() => (language = 'react')}
|
|
136
|
+
>React</DropdownMenu.Item>
|
|
137
|
+
</DropdownMenu.Content>
|
|
138
|
+
</DropdownMenu.Root>
|
|
139
|
+
</HoverTooltip>
|
|
140
|
+
{/if}
|
|
141
|
+
{/if}
|
|
142
|
+
{#if showPresetLibraries}
|
|
143
|
+
<label class="generation-option-toggle flex h-10 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border px-2 text-sm {librariesEnabled ? 'border-[#314F2F] bg-[#314F2F] text-white' : 'border-gray-300 bg-white text-gray-800'}">
|
|
144
|
+
<input class="generation-option-check cursor-pointer" type="checkbox" checked={librariesEnabled} onchange={onLibrariesChange} />
|
|
145
|
+
{$t('creator.brandKit.libraries')}
|
|
146
|
+
</label>
|
|
147
|
+
{/if}
|
|
148
|
+
{#if librariesEnabled && showPresetLibraries}
|
|
149
|
+
{#each libraryChoices as choice (choice.id)}
|
|
150
|
+
<label class="generation-library flex items-center gap-1 text-xs text-gray-700">
|
|
151
|
+
<input
|
|
152
|
+
class="generation-library-check cursor-pointer"
|
|
153
|
+
type="checkbox"
|
|
154
|
+
checked={libraries.includes(choice.id)}
|
|
155
|
+
onchange={() => toggleLibrary(choice.id)}
|
|
156
|
+
/>
|
|
157
|
+
{choice.label}
|
|
158
|
+
</label>
|
|
159
|
+
{/each}
|
|
160
|
+
{/if}
|
|
161
|
+
{#if librariesEnabled && showPresetLibraries}
|
|
162
|
+
<HoverTooltip class="inline-flex shrink-0" text={$t('creator.brandKit.addLibrary')}>
|
|
163
|
+
<button
|
|
164
|
+
type="button"
|
|
165
|
+
class="generation-library-add flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 bg-white text-sm text-gray-800"
|
|
166
|
+
aria-label={$t('creator.brandKit.addLibrary')}
|
|
167
|
+
onclick={addSourceRow}
|
|
168
|
+
>+</button>
|
|
169
|
+
</HoverTooltip>
|
|
170
|
+
{/if}
|
|
171
|
+
</div>
|
|
172
|
+
{#if librariesEnabled && showPresetLibraries}
|
|
173
|
+
{#each libraryRows as row (row.id)}
|
|
174
|
+
<div class="generation-source-row flex items-center gap-1">
|
|
175
|
+
<FileUrlSourceControl
|
|
176
|
+
class="min-w-0 flex-1"
|
|
177
|
+
bind:fileName={row.fileName}
|
|
178
|
+
bind:fileContent={row.content}
|
|
179
|
+
bind:fileEncoding={row.encoding}
|
|
180
|
+
bind:url={row.url}
|
|
181
|
+
fileLabel={$t('creator.brandKit.uploadLibrary')}
|
|
182
|
+
fileTitle={$t('creator.brandKit.uploadCustomLibraryTooltip')}
|
|
183
|
+
urlPlaceholder={$t('creator.brandKit.urlLibraries', { extension: componentExtension() })}
|
|
184
|
+
accept={sourceAccept()}
|
|
185
|
+
/>
|
|
186
|
+
{#if libraryRows.length > 1}
|
|
187
|
+
<button
|
|
188
|
+
type="button"
|
|
189
|
+
class="generation-source-remove flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-md border border-gray-300 text-gray-500"
|
|
190
|
+
aria-label={$t('creator.brandKit.removeLibrary')}
|
|
191
|
+
onclick={() => removeSourceRow(row.id)}
|
|
192
|
+
>
|
|
193
|
+
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
194
|
+
<path d="M4 7h16" />
|
|
195
|
+
<path d="M9 7V5h6v2" />
|
|
196
|
+
<path d="M8 7l1 13h6l1-13" />
|
|
197
|
+
</svg>
|
|
198
|
+
</button>
|
|
199
|
+
{/if}
|
|
200
|
+
</div>
|
|
201
|
+
{/each}
|
|
202
|
+
{/if}
|
|
203
|
+
</div>
|
|
204
|
+
{/if}
|
|
205
|
+
</div>
|
|
206
|
+
{/if}
|
|
207
|
+
|
|
208
|
+
<style>
|
|
209
|
+
.generation-options-checks input:focus,
|
|
210
|
+
.generation-options-checks input:focus-visible,
|
|
211
|
+
.generation-language-select:focus,
|
|
212
|
+
.generation-language-select:focus-visible {
|
|
213
|
+
outline: none;
|
|
214
|
+
box-shadow: none;
|
|
215
|
+
}
|
|
216
|
+
</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
class?: string;
|
|
3
|
+
style?: string;
|
|
4
|
+
part?: 'checks' | 'panel';
|
|
5
|
+
librariesEnabled?: boolean;
|
|
6
|
+
showPresetLibraries?: boolean;
|
|
7
|
+
libraries?: string[];
|
|
8
|
+
libraryGitUrl?: string;
|
|
9
|
+
libraryFileName?: string;
|
|
10
|
+
libraryUploads?: {
|
|
11
|
+
name: string;
|
|
12
|
+
content: string;
|
|
13
|
+
encoding: string;
|
|
14
|
+
}[];
|
|
15
|
+
showLanguage?: boolean;
|
|
16
|
+
language?: string;
|
|
17
|
+
languageLocked?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare const GenerationOptionsPanel: import("svelte").Component<Props, {}, "librariesEnabled" | "libraries" | "libraryGitUrl" | "libraryFileName" | "libraryUploads" | "language">;
|
|
20
|
+
type GenerationOptionsPanel = ReturnType<typeof GenerationOptionsPanel>;
|
|
21
|
+
export default GenerationOptionsPanel;
|
|
@@ -1437,7 +1437,10 @@
|
|
|
1437
1437
|
return anyClient.agentWidgetBuilderBuildFromRepoWidgetIdPost({ widgetId }, widgetBuilderRequestInit(widgetBuilderPublicBaseUrl));
|
|
1438
1438
|
}
|
|
1439
1439
|
const cfg = anyClient.configuration || {};
|
|
1440
|
-
|
|
1440
|
+
// The SDK writes the widget builder paths relative to the address of the API, which already ends in the version
|
|
1441
|
+
// (`https://api.widgetic.com/v1`), so the address of the shared client is used as it is. (The paths used to spell
|
|
1442
|
+
// the version themselves, so this address had its `/v1` trimmed off to avoid calling `/v1/v1/...`.)
|
|
1443
|
+
const builderBasePath = String(cfg.basePath || '') || undefined;
|
|
1441
1444
|
const builder = new WidgetBuilderApi({
|
|
1442
1445
|
basePath: builderBasePath,
|
|
1443
1446
|
accessToken: cfg.accessToken,
|
|
@@ -1447,7 +1450,7 @@
|
|
|
1447
1450
|
// console.log('[WidgetDetails] buildWidgetFromRepo', {
|
|
1448
1451
|
// widgetId: widgetId.substring(0, 8),
|
|
1449
1452
|
// builderBasePath,
|
|
1450
|
-
// sdkPath: '/
|
|
1453
|
+
// sdkPath: '/agent/widget-builder/build-from-repo/{widgetId}',
|
|
1451
1454
|
// });
|
|
1452
1455
|
return builder.buildWidgetFromRepo({ widgetId }, widgetBuilderRequestInit(widgetBuilderPublicBaseUrl));
|
|
1453
1456
|
}
|
|
@@ -4194,12 +4197,6 @@
|
|
|
4194
4197
|
.widget-details-dock-right :global(.action-label) {
|
|
4195
4198
|
font-size: 0.7rem;
|
|
4196
4199
|
}
|
|
4197
|
-
.widget-details-dock-right :global(.generation-brand-kit-toggle) {
|
|
4198
|
-
height: 2rem;
|
|
4199
|
-
gap: 0.3rem;
|
|
4200
|
-
padding-inline: 0.4rem;
|
|
4201
|
-
font-size: 0.75rem;
|
|
4202
|
-
}
|
|
4203
4200
|
.widget-details-create-models-ct :global(button:focus),
|
|
4204
4201
|
.widget-details-create-models-ct :global(button:focus-visible),
|
|
4205
4202
|
.widget-details-create-models-ct :global(select:focus),
|
|
@@ -100,7 +100,7 @@ declare const WidgetDetails: $$__sveltets_2_IsomorphicComponent<{
|
|
|
100
100
|
/** Stacking order when multiple Widget Details panels are open. */ panelZIndex?: number;
|
|
101
101
|
/** Cascade offset index (0 = centered, 1+ = shifted down-right). */ panelCascadeIndex?: number;
|
|
102
102
|
/** False when another panel has keyboard/chat focus. */ isFocusedPanel?: boolean;
|
|
103
|
-
currentStep?: "
|
|
103
|
+
currentStep?: "embed" | "create" | "edit";
|
|
104
104
|
/**
|
|
105
105
|
* Canvas Creator is code-only (chat + preview). Edit/Embed header steps stay
|
|
106
106
|
* off until composition editing lives on /composition. Keep the Edit/Embed
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Payload shape for POST /code/generate `brandKit` (account-level colors/fonts live on the gateway; chat only sends libraries). */
|
|
2
|
+
export type BrandKitUpload = {
|
|
3
|
+
name: string;
|
|
4
|
+
content: string;
|
|
5
|
+
encoding: string;
|
|
6
|
+
};
|
|
7
|
+
export type GenerationBrandKit = {
|
|
8
|
+
libraries?: string[];
|
|
9
|
+
uploads?: BrandKitUpload[];
|
|
10
|
+
};
|
|
11
|
+
export declare function brandKitForRequest(options: {
|
|
12
|
+
librariesEnabled: boolean;
|
|
13
|
+
debugMode: boolean;
|
|
14
|
+
libraries: string[];
|
|
15
|
+
libraryUploads: BrandKitUpload[];
|
|
16
|
+
}): GenerationBrandKit | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Payload shape for POST /code/generate `brandKit` (account-level colors/fonts live on the gateway; chat only sends libraries). */
|
|
2
|
+
export function brandKitForRequest(options) {
|
|
3
|
+
const kit = {};
|
|
4
|
+
// Preset libraries are a debug test. An empty list is an explicit ban.
|
|
5
|
+
if (options.librariesEnabled && options.debugMode)
|
|
6
|
+
kit.libraries = [...options.libraries];
|
|
7
|
+
if (options.libraryUploads.length > 0)
|
|
8
|
+
kit.uploads = options.libraryUploads.map((file) => ({ ...file }));
|
|
9
|
+
if (kit.libraries === undefined && kit.uploads === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
return kit;
|
|
12
|
+
}
|