@widgetic/creator 0.4.42 → 0.4.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CreatorApp.svelte +507 -71
- package/dist/CreatorApp.svelte.d.ts +1 -0
- package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
- package/dist/components/EmbeddedSketchViewportShell.svelte +49 -0
- package/dist/components/EmbeddedSketchViewportShell.svelte.d.ts +13 -0
- package/dist/components/WidgetDetails.svelte +40 -13
- package/dist/components/WidgetDetails.svelte.d.ts +4 -0
- package/dist/creator-types.d.ts +5 -0
- package/dist/embeddedSketchLayout.d.ts +9 -0
- package/dist/embeddedSketchLayout.js +17 -0
- package/dist/errors/toUserFriendlyError.d.ts +44 -0
- package/dist/errors/toUserFriendlyError.js +236 -0
- package/dist/i18n/language.d.ts +19 -8
- package/dist/i18n/messages.d.ts +10 -2
- package/dist/i18n/messages.js +11 -2
- package/dist/i18n/statusText.d.ts +8 -3
- package/dist/i18n/statusText.js +48 -12
- package/dist/pageHelpers.d.ts +9 -3
- package/dist/pageHelpers.js +37 -15
- package/dist/sketchBoardVisibility.d.ts +17 -0
- package/dist/sketchBoardVisibility.js +22 -0
- package/dist/sketchChatDraftPrefill.d.ts +25 -0
- package/dist/sketchChatDraftPrefill.js +82 -0
- package/dist/utils/codegenStatusTails.d.ts +23 -0
- package/dist/utils/codegenStatusTails.js +77 -0
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MessageOverrides } from '@widgetic/design-system/i18n';
|
|
2
|
+
export type SketchDraftPrefillAction = 'none' | 'apply' | 'clear';
|
|
3
|
+
/** Board object serialized in canvas JSON — widget shape / linked frame, not visitor sketch art. */
|
|
4
|
+
export declare function isWidgetBoardObject(obj: Record<string, unknown> | null | undefined): boolean;
|
|
5
|
+
/** Objects the person drew (strokes, frames, text, images), excluding widget shapes on the board. */
|
|
6
|
+
export declare function countDrawnCanvasObjectsInSerializedObjects(objects: unknown): number;
|
|
7
|
+
export declare function countDrawnCanvasObjectsInJson(json: string | null | undefined): number;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a canvas-dirty event is worth serializing the whole board for. The scan exists only to notice the FIRST drawn object sooner than
|
|
10
|
+
* the debounced autosave; once a drawing is known (or the widget is built, whose board carries its screenshot) the autosave is enough,
|
|
11
|
+
* so a person dragging or drawing on a busy board never pays for a serialization per event.
|
|
12
|
+
*/
|
|
13
|
+
export declare function shouldScanBoardForSketchPrefill(input: {
|
|
14
|
+
lastDrawnObjectCount: number;
|
|
15
|
+
widgetBuilt: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
export declare function decideSketchDraftPrefill(input: {
|
|
18
|
+
drawnObjectCount: number;
|
|
19
|
+
widgetBuilt: boolean;
|
|
20
|
+
draft: string;
|
|
21
|
+
prefillMessage: string;
|
|
22
|
+
prefillAppliedForSketch: boolean;
|
|
23
|
+
}): SketchDraftPrefillAction;
|
|
24
|
+
/** Prefill sentence from the merged chat catalog (never a hard-coded English string). */
|
|
25
|
+
export declare function resolveSketchGenerateCodePrompt(locale: string | null | undefined, chatOverrides: MessageOverrides | null | undefined): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createTranslator } from '@widgetic/design-system/i18n';
|
|
2
|
+
import { CHAT_MESSAGES } from '@widgetic/chat';
|
|
3
|
+
const GENERATE_CODE_KEY = 'chat.suggestions.frame.generateCode';
|
|
4
|
+
/** Board object serialized in canvas JSON — widget shape / linked frame, not visitor sketch art. */
|
|
5
|
+
export function isWidgetBoardObject(obj) {
|
|
6
|
+
if (!obj)
|
|
7
|
+
return false;
|
|
8
|
+
const widgetId = obj._widgetId;
|
|
9
|
+
if (typeof widgetId === 'string' && widgetId.length > 0) {
|
|
10
|
+
if (obj._isWidgetImage === true)
|
|
11
|
+
return true;
|
|
12
|
+
if (obj._customType === 'frame')
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (obj.type === 'WidgetShape')
|
|
16
|
+
return true;
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
/** Objects the person drew (strokes, frames, text, images), excluding widget shapes on the board. */
|
|
20
|
+
export function countDrawnCanvasObjectsInSerializedObjects(objects) {
|
|
21
|
+
if (!Array.isArray(objects))
|
|
22
|
+
return 0;
|
|
23
|
+
let count = 0;
|
|
24
|
+
for (const entry of objects) {
|
|
25
|
+
if (!entry || typeof entry !== 'object')
|
|
26
|
+
continue;
|
|
27
|
+
const obj = entry;
|
|
28
|
+
if (obj.visible === false || obj.excludeFromExport === true)
|
|
29
|
+
continue;
|
|
30
|
+
if (isWidgetBoardObject(obj))
|
|
31
|
+
continue;
|
|
32
|
+
count += 1;
|
|
33
|
+
}
|
|
34
|
+
return count;
|
|
35
|
+
}
|
|
36
|
+
export function countDrawnCanvasObjectsInJson(json) {
|
|
37
|
+
if (!json)
|
|
38
|
+
return 0;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(json);
|
|
41
|
+
const objects = parsed?.canvas?.objects ?? parsed?.objects ?? [];
|
|
42
|
+
return countDrawnCanvasObjectsInSerializedObjects(objects);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether a canvas-dirty event is worth serializing the whole board for. The scan exists only to notice the FIRST drawn object sooner than
|
|
50
|
+
* the debounced autosave; once a drawing is known (or the widget is built, whose board carries its screenshot) the autosave is enough,
|
|
51
|
+
* so a person dragging or drawing on a busy board never pays for a serialization per event.
|
|
52
|
+
*/
|
|
53
|
+
export function shouldScanBoardForSketchPrefill(input) {
|
|
54
|
+
if (input.widgetBuilt)
|
|
55
|
+
return false;
|
|
56
|
+
return input.lastDrawnObjectCount <= 0;
|
|
57
|
+
}
|
|
58
|
+
export function decideSketchDraftPrefill(input) {
|
|
59
|
+
if (input.widgetBuilt)
|
|
60
|
+
return 'none';
|
|
61
|
+
if (input.drawnObjectCount <= 0) {
|
|
62
|
+
if (input.draft === input.prefillMessage)
|
|
63
|
+
return 'clear';
|
|
64
|
+
return 'none';
|
|
65
|
+
}
|
|
66
|
+
if (input.prefillAppliedForSketch)
|
|
67
|
+
return 'none';
|
|
68
|
+
if (input.draft !== '' && input.draft !== input.prefillMessage)
|
|
69
|
+
return 'none';
|
|
70
|
+
if (input.draft === '')
|
|
71
|
+
return 'apply';
|
|
72
|
+
return 'none';
|
|
73
|
+
}
|
|
74
|
+
/** Prefill sentence from the merged chat catalog (never a hard-coded English string). */
|
|
75
|
+
export function resolveSketchGenerateCodePrompt(locale, chatOverrides) {
|
|
76
|
+
const translator = createTranslator({
|
|
77
|
+
catalog: CHAT_MESSAGES,
|
|
78
|
+
locale: locale ?? 'en',
|
|
79
|
+
messages: chatOverrides ?? {},
|
|
80
|
+
});
|
|
81
|
+
return translator.t(GENERATE_CODE_KEY);
|
|
82
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status metadata tails pushed while widget codegen runs (see gateway operation.metadata).
|
|
3
|
+
*/
|
|
4
|
+
export declare function readGenerationStreamTail(metadata?: Record<string, unknown>): string;
|
|
5
|
+
export declare function readThinkingTail(metadata?: Record<string, unknown>): string;
|
|
6
|
+
export type WidgetPlanTaskStatusWire = 'pending' | 'in_progress' | 'done' | 'failed';
|
|
7
|
+
/** Wire shape of `operation.metadata.plan` (display fields only; matches `@widgetic/chat`). */
|
|
8
|
+
export type GenerationPlanWire = {
|
|
9
|
+
title: string;
|
|
10
|
+
tasks: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
kind?: string;
|
|
14
|
+
status: WidgetPlanTaskStatusWire;
|
|
15
|
+
}>;
|
|
16
|
+
completed?: number;
|
|
17
|
+
activeIndex?: number | null;
|
|
18
|
+
decisions?: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Reads `metadata.plan`. Missing key → `undefined` (leave UI as-is); `null` → hide; bad shape → `null`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readPlanFromMetadata(metadata?: Record<string, unknown>): GenerationPlanWire | null | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status metadata tails pushed while widget codegen runs (see gateway operation.metadata).
|
|
3
|
+
*/
|
|
4
|
+
export function readGenerationStreamTail(metadata) {
|
|
5
|
+
if (!metadata)
|
|
6
|
+
return '';
|
|
7
|
+
const raw = metadata.streamTail ?? metadata.stream_tail;
|
|
8
|
+
return typeof raw === 'string' ? raw.slice(-1600) : '';
|
|
9
|
+
}
|
|
10
|
+
export function readThinkingTail(metadata) {
|
|
11
|
+
if (!metadata)
|
|
12
|
+
return '';
|
|
13
|
+
const raw = metadata.thinkingTail ?? metadata.thinking_tail;
|
|
14
|
+
return typeof raw === 'string' ? raw.slice(-2400) : '';
|
|
15
|
+
}
|
|
16
|
+
const MAX_PLAN_TASKS = 20;
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function coerceLabel(label) {
|
|
21
|
+
if (typeof label === 'string')
|
|
22
|
+
return label;
|
|
23
|
+
if (label == null)
|
|
24
|
+
return '';
|
|
25
|
+
return String(label);
|
|
26
|
+
}
|
|
27
|
+
function parseWidgetPlan(value) {
|
|
28
|
+
if (!isRecord(value))
|
|
29
|
+
return null;
|
|
30
|
+
if (!Array.isArray(value.tasks))
|
|
31
|
+
return null;
|
|
32
|
+
const tasks = [];
|
|
33
|
+
for (const raw of value.tasks) {
|
|
34
|
+
if (!isRecord(raw))
|
|
35
|
+
continue;
|
|
36
|
+
if (typeof raw.id !== 'string' || raw.id.trim() === '')
|
|
37
|
+
continue;
|
|
38
|
+
tasks.push({
|
|
39
|
+
id: raw.id,
|
|
40
|
+
label: coerceLabel(raw.label),
|
|
41
|
+
...(typeof raw.kind === 'string' ? { kind: raw.kind } : {}),
|
|
42
|
+
status: ['pending', 'in_progress', 'done', 'failed'].includes(raw.status)
|
|
43
|
+
? raw.status
|
|
44
|
+
: 'pending',
|
|
45
|
+
});
|
|
46
|
+
if (tasks.length >= MAX_PLAN_TASKS)
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (tasks.length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const title = typeof value.title === 'string' ? value.title : '';
|
|
52
|
+
const completed = typeof value.completed === 'number' && Number.isFinite(value.completed)
|
|
53
|
+
? Math.max(0, Math.floor(value.completed))
|
|
54
|
+
: undefined;
|
|
55
|
+
const activeIndex = value.activeIndex === null
|
|
56
|
+
? null
|
|
57
|
+
: typeof value.activeIndex === 'number' && Number.isFinite(value.activeIndex)
|
|
58
|
+
? Math.floor(value.activeIndex)
|
|
59
|
+
: undefined;
|
|
60
|
+
return {
|
|
61
|
+
title,
|
|
62
|
+
tasks,
|
|
63
|
+
...(completed !== undefined ? { completed } : {}),
|
|
64
|
+
...(activeIndex !== undefined ? { activeIndex } : {}),
|
|
65
|
+
...(value.decisions !== undefined ? { decisions: value.decisions } : {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reads `metadata.plan`. Missing key → `undefined` (leave UI as-is); `null` → hide; bad shape → `null`.
|
|
70
|
+
*/
|
|
71
|
+
export function readPlanFromMetadata(metadata) {
|
|
72
|
+
if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, 'plan'))
|
|
73
|
+
return undefined;
|
|
74
|
+
if (metadata.plan === null)
|
|
75
|
+
return null;
|
|
76
|
+
return parseWidgetPlan(metadata.plan);
|
|
77
|
+
}
|