@widgetic/creator 0.3.81 → 0.4.1

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.
Files changed (64) hide show
  1. package/README.md +157 -0
  2. package/dist/CreatorApp.svelte +1593 -812
  3. package/dist/CreatorApp.svelte.d.ts +22 -0
  4. package/dist/components/BrandKitPanel.svelte +48 -40
  5. package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
  6. package/dist/components/DesignQuickEdit.svelte +13 -4
  7. package/dist/components/EditableName.svelte +13 -8
  8. package/dist/components/EditableName.svelte.d.ts +2 -2
  9. package/dist/components/FileUrlSourceControl.svelte +21 -8
  10. package/dist/components/HoverTooltip.svelte +1 -1
  11. package/dist/components/SelectorDropdown.svelte +19 -15
  12. package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
  13. package/dist/components/VersionDropdownRow.svelte +14 -11
  14. package/dist/components/WidgetDetails.svelte +118 -92
  15. package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
  16. package/dist/creator-types.d.ts +96 -0
  17. package/dist/host/creatorHost.d.ts +176 -0
  18. package/dist/host/creatorHost.js +242 -0
  19. package/dist/host/limitRefusal.d.ts +64 -0
  20. package/dist/host/limitRefusal.js +109 -0
  21. package/dist/i18n/index.d.ts +5 -0
  22. package/dist/i18n/index.js +5 -0
  23. package/dist/i18n/labels.d.ts +14 -0
  24. package/dist/i18n/labels.js +39 -0
  25. package/dist/i18n/language.d.ts +559 -0
  26. package/dist/i18n/language.js +47 -0
  27. package/dist/i18n/languageKit.d.ts +52 -0
  28. package/dist/i18n/languageKit.js +45 -0
  29. package/dist/i18n/messages.d.ts +526 -0
  30. package/dist/i18n/messages.js +548 -0
  31. package/dist/i18n/slots.d.ts +22 -0
  32. package/dist/i18n/slots.js +42 -0
  33. package/dist/i18n/statusText.d.ts +22 -0
  34. package/dist/i18n/statusText.js +223 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/stores/userSession.d.ts +8 -1
  38. package/dist/stores/userSession.js +18 -25
  39. package/dist/stores/websocketStore.d.ts +6 -0
  40. package/dist/stores/websocketStore.js +39 -4
  41. package/dist/utils/designIntentTelemetry.d.ts +8 -0
  42. package/dist/utils/designIntentTelemetry.js +52 -34
  43. package/dist/utils/directionPlacement.d.ts +51 -0
  44. package/dist/utils/directionPlacement.js +55 -0
  45. package/dist/utils/embedCode.d.ts +0 -1
  46. package/dist/utils/embedCode.js +0 -4
  47. package/dist/utils/generationSharing.d.ts +122 -0
  48. package/dist/utils/generationSharing.js +188 -0
  49. package/dist/utils/nativeScrollbarPadding.js +1 -1
  50. package/dist/utils/pickedFile.d.ts +15 -0
  51. package/dist/utils/pickedFile.js +21 -0
  52. package/dist/utils/widgeticChatUpload.d.ts +9 -0
  53. package/dist/utils/widgeticChatUpload.js +24 -2
  54. package/package.json +5 -3
  55. package/dist/retiredSurface.test.d.ts +0 -1
  56. package/dist/retiredSurface.test.js +0 -113
  57. package/dist/utils/designIntentResolver.test.d.ts +0 -1
  58. package/dist/utils/designIntentResolver.test.js +0 -246
  59. package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
  60. package/dist/utils/designIntentTelemetry.test.js +0 -385
  61. package/dist/utils/designQuickEditValues.test.d.ts +0 -1
  62. package/dist/utils/designQuickEditValues.test.js +0 -100
  63. package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
  64. package/dist/utils/widgeticChatUpload.test.js +0 -257
@@ -1,113 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { HealthApi, Configuration, ResponseError, isRetiredSurfaceError, readEnvelopeErrorCode, RETIRED_SURFACE_CODES } from '@widgetic/api-sdk';
3
- /**
4
- * The SDK must recognize the API's retired-surface 410 envelope so stale
5
- * bundles can surface an upgrade prompt instead of a generic failure.
6
- *
7
- * The API answers permanently retired routes (planner endpoints, VM flows,
8
- * VM metrics) with 410 Gone and the house error envelope:
9
- *
10
- * { success: false, error: { code: 'PLANNER_REMOVED', message: '… Use POST /agent/code/generate …', timestamp: '…' } }
11
- *
12
- * Two properties are pinned:
13
- *
14
- * 1. **End to end through the real request pipeline** — a fetch mocked to
15
- * return that envelope produces a ResponseError whose `code` is the
16
- * machine-readable value and whose `message` carries the replacement
17
- * hint; `isRetiredSurfaceError` discriminates it from every lookalike
18
- * (other statuses, other codes, non-ResponseError throws).
19
- * 2. **The envelope reader is safe by contract** — null (never a throw) for
20
- * non-JSON bodies, envelopes without a code, or empty code strings.
21
- *
22
- * These tests import the package the app imports — the built `dist` when
23
- * resolved through node_modules, or the aliased sibling source in dev —
24
- * so what is tested is exactly what a stale bundle would ship.
25
- */
26
- const RETIRED_ENVELOPE = (code) => {
27
- const message = `The ${code} surface was removed. Use POST /agent/code/generate (Direct LLM + Widget Builder).`;
28
- return {
29
- success: false,
30
- message,
31
- error: {
32
- code,
33
- message,
34
- timestamp: new Date().toISOString()
35
- }
36
- };
37
- };
38
- /** 410 response whose body is the house error envelope. */
39
- function retiredResponse(code) {
40
- return new Response(JSON.stringify(RETIRED_ENVELOPE(code)), {
41
- status: 410,
42
- headers: { 'content-type': 'application/json' }
43
- });
44
- }
45
- function apiWithFetch(fetchImpl) {
46
- return new HealthApi(new Configuration({ basePath: 'https://api.test', fetchApi: fetchImpl }));
47
- }
48
- describe('retired-surface 410 envelopes surface as typed ResponseErrors', () => {
49
- it.each(RETIRED_SURFACE_CODES)('carries the machine-readable %s code end to end', async (code) => {
50
- const api = apiWithFetch((async () => retiredResponse(code)));
51
- const err = await api.checkHealth().catch((e) => e);
52
- expect(err).toBeInstanceOf(ResponseError);
53
- const responseError = err;
54
- expect(responseError.response.status).toBe(410);
55
- expect(responseError.code).toBe(code);
56
- // The replacement hint rides the envelope message, which the SDK
57
- // already surfaces as the error message.
58
- expect(responseError.message).toContain('POST /agent/code/generate');
59
- // And the public helper discriminates exactly this shape.
60
- expect(isRetiredSurfaceError(responseError)).toBe(true);
61
- });
62
- it('does not flag a 410 without a retired code', async () => {
63
- const body = JSON.stringify({ success: false, error: { code: 'SOMETHING_ELSE', message: 'gone', timestamp: 't' } });
64
- const api = apiWithFetch((async () => new Response(body, { status: 410 })));
65
- const err = await api.checkHealth().catch((e) => e);
66
- expect(err).toBeInstanceOf(ResponseError);
67
- expect(err.code).toBe('SOMETHING_ELSE');
68
- expect(isRetiredSurfaceError(err)).toBe(false);
69
- });
70
- it('does not flag a 410 whose body has no envelope code', async () => {
71
- const api = apiWithFetch((async () => new Response('{"message":"gone"}', { status: 410 })));
72
- const err = await api.checkHealth().catch((e) => e);
73
- expect(err.code).toBeNull();
74
- expect(isRetiredSurfaceError(err)).toBe(false);
75
- });
76
- it('does not flag retired codes on other statuses', async () => {
77
- const body = JSON.stringify(RETIRED_ENVELOPE('VM_REMOVED'));
78
- const api = apiWithFetch((async () => new Response(body, { status: 503 })));
79
- const err = await api.checkHealth().catch((e) => e);
80
- // The message still surfaces (the SDK parses envelope messages), but a
81
- // non-410 must not read as "your bundle is stale" — 503 means retry.
82
- expect(isRetiredSurfaceError(err)).toBe(false);
83
- });
84
- it('rejects non-ResponseError throws and unrelated values', () => {
85
- expect(isRetiredSurfaceError(new Error('boom'))).toBe(false);
86
- expect(isRetiredSurfaceError('PLANNER_REMOVED')).toBe(false);
87
- expect(isRetiredSurfaceError(null)).toBe(false);
88
- expect(isRetiredSurfaceError(undefined)).toBe(false);
89
- });
90
- });
91
- describe('readEnvelopeErrorCode', () => {
92
- it('reads the code from a house envelope', async () => {
93
- expect(await readEnvelopeErrorCode(retiredResponse('VM_METRICS_REMOVED'))).toBe('VM_METRICS_REMOVED');
94
- });
95
- it('returns null for non-JSON bodies instead of throwing', async () => {
96
- const html = new Response('<!DOCTYPE html><html><body>error</body></html>', {
97
- status: 410,
98
- headers: { 'content-type': 'text/html' }
99
- });
100
- expect(await readEnvelopeErrorCode(html)).toBeNull();
101
- });
102
- it('returns null for JSON without an envelope code', async () => {
103
- const bare = new Response(JSON.stringify({ message: 'no code here' }), { status: 410 });
104
- expect(await readEnvelopeErrorCode(bare)).toBeNull();
105
- });
106
- it('does not consume the body it reads', async () => {
107
- const response = retiredResponse('PLANNER_REMOVED');
108
- await readEnvelopeErrorCode(response);
109
- // A clone is used internally, so the original body stays readable for
110
- // later handlers (error toasts, logging).
111
- await expect(response.json()).resolves.toBeTruthy();
112
- });
113
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,246 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { collectDesignProperties, resolveDesignIntent, toDesignControlRequest } from './designIntentResolver';
3
- /**
4
- * A widget-shaped design schema (the post-codegen shape: one componentGroup,
5
- * components carrying `properties`, options under `inputController.config`).
6
- */
7
- const SCHEMA = {
8
- componentGroups: [
9
- {
10
- name: 'Design',
11
- components: [
12
- {
13
- id: 'appearance',
14
- type: 'layoutGroup',
15
- propertyGroups: [
16
- {
17
- name: 'Colors',
18
- properties: [
19
- {
20
- id: 'backgroundColor',
21
- type: 'string',
22
- defaultValue: '#ffffff',
23
- inputController: { type: 'colorPicker', description: 'Background Color' }
24
- },
25
- {
26
- id: 'titleColor',
27
- type: 'string',
28
- defaultValue: '#111827',
29
- inputController: { type: 'colorPicker', description: 'Title Color' }
30
- },
31
- {
32
- id: 'widgetBorderColor',
33
- type: 'string',
34
- defaultValue: '#e5e7eb',
35
- inputController: { type: 'colorPicker', description: 'Border Color' }
36
- }
37
- ]
38
- },
39
- {
40
- name: 'Spacing',
41
- properties: [
42
- {
43
- id: 'padding',
44
- type: 'number',
45
- defaultValue: 16,
46
- inputController: { type: 'slider', description: 'Padding', config: { min: 0, max: 64, step: 1 } }
47
- },
48
- {
49
- id: 'borderRadius',
50
- type: 'number',
51
- defaultValue: 8,
52
- inputController: { type: 'number', description: 'Border Radius', config: { min: 0, max: 40, step: 1 } }
53
- }
54
- ]
55
- },
56
- {
57
- name: 'Layout',
58
- properties: [
59
- {
60
- id: 'layout',
61
- type: 'string',
62
- defaultValue: 'grid',
63
- inputController: {
64
- type: 'dropdown',
65
- description: 'Layout Style',
66
- config: {
67
- options: [
68
- { label: 'Grid', value: 'grid' },
69
- { label: 'List', value: 'list' },
70
- { label: 'Carousel', value: 'carousel' }
71
- ]
72
- }
73
- }
74
- },
75
- {
76
- id: 'showShadow',
77
- type: 'boolean',
78
- defaultValue: true,
79
- inputController: { type: 'switch', description: 'Drop Shadow' }
80
- },
81
- {
82
- id: 'widgetTitle',
83
- type: 'string',
84
- defaultValue: 'My Widget',
85
- inputController: { type: 'textInput', description: 'Widget Title' }
86
- }
87
- ]
88
- }
89
- ]
90
- }
91
- ]
92
- }
93
- ]
94
- };
95
- const LIVE = { backgroundColor: '#ffffff', padding: 16, borderRadius: 8, showShadow: true };
96
- describe('collectDesignProperties', () => {
97
- it('flattens nested property groups into descriptors', () => {
98
- const props = collectDesignProperties(SCHEMA);
99
- expect(props.map((p) => p.id)).toEqual([
100
- 'backgroundColor',
101
- 'titleColor',
102
- 'widgetBorderColor',
103
- 'padding',
104
- 'borderRadius',
105
- 'layout',
106
- 'showShadow',
107
- 'widgetTitle'
108
- ]);
109
- });
110
- it('reads dropdown options from inputController.config.options', () => {
111
- const dropdown = collectDesignProperties(SCHEMA).find((p) => p.id === 'layout');
112
- expect(dropdown?.options).toHaveLength(3);
113
- expect(dropdown?.options[1]).toEqual({ label: 'List', value: 'list' });
114
- });
115
- it('reads numeric constraints', () => {
116
- const padding = collectDesignProperties(SCHEMA).find((p) => p.id === 'padding');
117
- expect(padding).toMatchObject({ min: 0, max: 64, step: 1 });
118
- });
119
- });
120
- describe('resolveDesignIntent — colors', () => {
121
- it('resolves an explicit hex on the named color property', () => {
122
- const r = resolveDesignIntent('make the background #1a1a2e', SCHEMA, LIVE);
123
- expect(r?.changes).toHaveLength(1);
124
- expect(r?.changes[0]).toMatchObject({
125
- propertyId: 'backgroundColor',
126
- value: '#1a1a2e',
127
- reason: 'explicit-color'
128
- });
129
- });
130
- it('expands 3-digit hex', () => {
131
- const r = resolveDesignIntent('set the background to #abc', SCHEMA, LIVE);
132
- expect(r?.changes[0].value).toBe('#aabbcc');
133
- });
134
- it('resolves a named color', () => {
135
- const r = resolveDesignIntent('change the background to red', SCHEMA, LIVE);
136
- expect(r?.changes[0]).toMatchObject({ propertyId: 'backgroundColor', value: '#ff0000', reason: 'named-color' });
137
- });
138
- it('resolves rgb()', () => {
139
- const r = resolveDesignIntent('background rgb(26, 26, 46)', SCHEMA, LIVE);
140
- expect(r?.changes[0].value).toBe('#1a1a2e');
141
- });
142
- it('does not touch a number property when only a color is given', () => {
143
- const r = resolveDesignIntent('make the padding red', SCHEMA, LIVE);
144
- expect(r).toBeNull();
145
- });
146
- });
147
- describe('resolveDesignIntent — numbers (arithmetic stays in code)', () => {
148
- it('sets an explicit number', () => {
149
- const r = resolveDesignIntent('set the border radius to 12', SCHEMA, LIVE);
150
- expect(r?.changes[0]).toMatchObject({ propertyId: 'borderRadius', value: 12, reason: 'explicit-number' });
151
- });
152
- it('increases by an absolute delta using the current value', () => {
153
- const r = resolveDesignIntent('increase the padding by 8', SCHEMA, LIVE);
154
- expect(r?.changes[0]).toMatchObject({ propertyId: 'padding', value: 24, reason: 'delta-number' });
155
- });
156
- it('applies a percentage delta', () => {
157
- const r = resolveDesignIntent('reduce the padding by 25%', SCHEMA, LIVE);
158
- expect(r?.changes[0].value).toBe(12);
159
- });
160
- it('doubles the current value', () => {
161
- const r = resolveDesignIntent('double the border radius', SCHEMA, LIVE);
162
- expect(r?.changes[0].value).toBe(16);
163
- });
164
- it('halves the current value', () => {
165
- const r = resolveDesignIntent('half the padding', SCHEMA, LIVE);
166
- expect(r?.changes[0].value).toBe(8);
167
- });
168
- it('clamps to the schema max', () => {
169
- const r = resolveDesignIntent('increase the padding by 500', SCHEMA, LIVE);
170
- expect(r?.changes[0].value).toBe(64);
171
- });
172
- it('uses the schema default when no live value is supplied', () => {
173
- const r = resolveDesignIntent('increase the padding by 4', SCHEMA);
174
- expect(r?.changes[0]).toMatchObject({ previousValue: 16, value: 20 });
175
- });
176
- });
177
- describe('resolveDesignIntent — booleans and options', () => {
178
- it('turns a switch on', () => {
179
- const r = resolveDesignIntent('turn the drop shadow off', SCHEMA, LIVE);
180
- expect(r?.changes[0]).toMatchObject({ propertyId: 'showShadow', value: false, reason: 'boolean' });
181
- });
182
- it('enables', () => {
183
- const r = resolveDesignIntent('enable the shadow', SCHEMA, LIVE);
184
- expect(r?.changes[0]).toMatchObject({ propertyId: 'showShadow', value: true });
185
- });
186
- it('selects a dropdown option by label', () => {
187
- const r = resolveDesignIntent('switch the layout to carousel', SCHEMA, LIVE);
188
- expect(r?.changes[0]).toMatchObject({ propertyId: 'layout', value: 'carousel', reason: 'option' });
189
- });
190
- });
191
- describe('resolveDesignIntent — text', () => {
192
- it('resolves only explicitly quoted text', () => {
193
- const r = resolveDesignIntent('set the widget title to "Grocery list"', SCHEMA, LIVE);
194
- expect(r?.changes[0]).toMatchObject({ propertyId: 'widgetTitle', value: 'Grocery list' });
195
- });
196
- it('refuses unquoted text (falls through to codegen)', () => {
197
- expect(resolveDesignIntent('change the title to grocery list', SCHEMA, LIVE)).toBeNull();
198
- });
199
- });
200
- describe('resolveDesignIntent — bails out (falls through to codegen/JEV)', () => {
201
- it('returns null for vague intent', () => {
202
- expect(resolveDesignIntent('make it pop', SCHEMA, LIVE)).toBeNull();
203
- expect(resolveDesignIntent('give it more breathing room', SCHEMA, LIVE)).toBeNull();
204
- expect(resolveDesignIntent('make it feel more premium', SCHEMA, LIVE)).toBeNull();
205
- });
206
- it('returns null for a color with no named property', () => {
207
- expect(resolveDesignIntent('make it red', SCHEMA, LIVE)).toBeNull();
208
- });
209
- it('returns null for a non-design ask', () => {
210
- expect(resolveDesignIntent('add a confetti animation when the timer ends', SCHEMA, LIVE)).toBeNull();
211
- });
212
- it('returns null when two properties tie on name match', () => {
213
- // "color" alone names all three color properties equally → ambiguous.
214
- expect(resolveDesignIntent('change the color to red', SCHEMA, LIVE)).toBeNull();
215
- });
216
- it('returns null for an empty schema', () => {
217
- expect(resolveDesignIntent('make the background red', {}, LIVE)).toBeNull();
218
- });
219
- });
220
- describe('toDesignControlRequest', () => {
221
- it('carries the resolved value + constraints for the inline controller', () => {
222
- const r = resolveDesignIntent('increase the padding by 8', SCHEMA, LIVE);
223
- const card = toDesignControlRequest(r, SCHEMA, LIVE);
224
- expect(card.summary).toContain('Padding');
225
- expect(card.properties[0]).toMatchObject({
226
- id: 'padding',
227
- controllerType: 'slider',
228
- value: 24,
229
- min: 0,
230
- max: 64
231
- });
232
- });
233
- it('records the composition the change landed in, so a reload can re-attach it', () => {
234
- const r = resolveDesignIntent('increase the padding by 8', SCHEMA, LIVE);
235
- expect(toDesignControlRequest(r, SCHEMA, LIVE, 'composition-1').compositionId).toBe('composition-1');
236
- });
237
- it('omits the composition rather than recording null when there is none', () => {
238
- // A card persisted before the field existed, and one authored against a
239
- // composition that was never saved, both arrive without it — and the host
240
- // treats exactly that shape as "attached".
241
- const r = resolveDesignIntent('increase the padding by 8', SCHEMA, LIVE);
242
- expect(toDesignControlRequest(r, SCHEMA, LIVE)).not.toHaveProperty('compositionId');
243
- expect(toDesignControlRequest(r, SCHEMA, LIVE, null)).not.toHaveProperty('compositionId');
244
- expect(toDesignControlRequest(r, SCHEMA, LIVE, '')).not.toHaveProperty('compositionId');
245
- });
246
- });
@@ -1 +0,0 @@
1
- export {};