@widgetic/chat 0.1.4
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 +440 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/widgeticAdapter.d.ts +185 -0
- package/dist/adapters/widgeticAdapter.js +766 -0
- package/dist/components/ActionBar.svelte +342 -0
- package/dist/components/ActionBar.svelte.d.ts +37 -0
- package/dist/components/AttachmentDisplay.svelte +547 -0
- package/dist/components/AttachmentDisplay.svelte.d.ts +12 -0
- package/dist/components/Chat.svelte +1253 -0
- package/dist/components/Chat.svelte.d.ts +112 -0
- package/dist/components/ChatHeader.svelte +182 -0
- package/dist/components/ChatHeader.svelte.d.ts +12 -0
- package/dist/components/ChatInput.svelte +290 -0
- package/dist/components/ChatInput.svelte.d.ts +15 -0
- package/dist/components/ChatMessages.svelte +996 -0
- package/dist/components/ChatMessages.svelte.d.ts +28 -0
- package/dist/components/CodeBlock.svelte +286 -0
- package/dist/components/CodeBlock.svelte.d.ts +10 -0
- package/dist/components/ContextPreview.svelte +66 -0
- package/dist/components/ContextPreview.svelte.d.ts +8 -0
- package/dist/components/LoadingIndicator.svelte +151 -0
- package/dist/components/LoadingIndicator.svelte.d.ts +9 -0
- package/dist/components/StatusIndicator.svelte +116 -0
- package/dist/components/StatusIndicator.svelte.d.ts +9 -0
- package/dist/components/SuggestionButtons.svelte +244 -0
- package/dist/components/SuggestionButtons.svelte.d.ts +26 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/components/index.js +12 -0
- package/dist/config.d.ts +43 -0
- package/dist/config.js +67 -0
- package/dist/constants/colors.d.ts +20 -0
- package/dist/constants/colors.js +16 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +20 -0
- package/dist/services/chatService.d.ts +72 -0
- package/dist/services/chatService.js +355 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/stores/chatStore.d.ts +46 -0
- package/dist/stores/chatStore.js +219 -0
- package/dist/stores/index.d.ts +2 -0
- package/dist/stores/index.js +2 -0
- package/dist/types/adapter.d.ts +86 -0
- package/dist/types/adapter.js +1 -0
- package/dist/types/api-temp.d.ts +61 -0
- package/dist/types/api-temp.js +42 -0
- package/dist/types/attachment.d.ts +84 -0
- package/dist/types/attachment.js +33 -0
- package/dist/types/chat.d.ts +114 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/config.d.ts +89 -0
- package/dist/types/config.js +63 -0
- package/dist/types/context.d.ts +108 -0
- package/dist/types/context.js +11 -0
- package/dist/types/conversation.d.ts +45 -0
- package/dist/types/conversation.js +1 -0
- package/dist/types/events.d.ts +141 -0
- package/dist/types/events.js +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.js +10 -0
- package/dist/types/message.d.ts +82 -0
- package/dist/types/message.js +1 -0
- package/dist/types/state.d.ts +117 -0
- package/dist/types/state.js +1 -0
- package/dist/utils/fileUtils.d.ts +93 -0
- package/dist/utils/fileUtils.js +299 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/logger.d.ts +4 -0
- package/dist/utils/logger.js +28 -0
- package/package.json +104 -0
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { chatLog } from '../utils/logger.js';
|
|
49
|
+
import { ContextType } from '../types/index.js';
|
|
50
|
+
/**
|
|
51
|
+
* Widgetic Canvas Platform Adapter
|
|
52
|
+
* Handles frame-based contexts for the Widgetic canvas system
|
|
53
|
+
*/
|
|
54
|
+
var WidgeticCanvasAdapter = /** @class */ (function () {
|
|
55
|
+
function WidgeticCanvasAdapter() {
|
|
56
|
+
this.name = 'widgetic';
|
|
57
|
+
this.version = '1.0.0';
|
|
58
|
+
this.frameSelectionCallbacks = [];
|
|
59
|
+
this.frameDeselectionCallbacks = [];
|
|
60
|
+
this.contextChangeCallbacks = [];
|
|
61
|
+
this.contextUpdateCallbacks = [];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Extract frame ID from context object
|
|
65
|
+
*/
|
|
66
|
+
WidgeticCanvasAdapter.prototype.getContextId = function (contextObject) {
|
|
67
|
+
if (typeof contextObject === 'string') {
|
|
68
|
+
return contextObject;
|
|
69
|
+
}
|
|
70
|
+
if (contextObject === null || contextObject === void 0 ? void 0 : contextObject.frameId) {
|
|
71
|
+
return contextObject.frameId;
|
|
72
|
+
}
|
|
73
|
+
if (contextObject === null || contextObject === void 0 ? void 0 : contextObject.id) {
|
|
74
|
+
return contextObject.id;
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Invalid context object: missing frameId or id');
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Get human-readable title for the frame
|
|
80
|
+
*/
|
|
81
|
+
WidgeticCanvasAdapter.prototype.getContextTitle = function (contextObject) {
|
|
82
|
+
if (typeof contextObject === 'string') {
|
|
83
|
+
return "Frame ".concat(contextObject);
|
|
84
|
+
}
|
|
85
|
+
return (contextObject === null || contextObject === void 0 ? void 0 : contextObject.title) || (contextObject === null || contextObject === void 0 ? void 0 : contextObject.name) || "Frame ".concat(this.getContextId(contextObject));
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Get context type
|
|
89
|
+
*/
|
|
90
|
+
WidgeticCanvasAdapter.prototype.getContextType = function () {
|
|
91
|
+
return 'frame';
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Create a standardized chat context from a frame object
|
|
95
|
+
*/
|
|
96
|
+
WidgeticCanvasAdapter.prototype.createContext = function (contextObject) {
|
|
97
|
+
var id = this.getContextId(contextObject);
|
|
98
|
+
var title = this.getContextTitle(contextObject);
|
|
99
|
+
return {
|
|
100
|
+
id: id,
|
|
101
|
+
type: ContextType.FRAME,
|
|
102
|
+
parentId: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.canvasId) || 'unknown-canvas',
|
|
103
|
+
title: title,
|
|
104
|
+
thumbnail: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.thumbnail) || (contextObject === null || contextObject === void 0 ? void 0 : contextObject.previewUrl),
|
|
105
|
+
metadata: {
|
|
106
|
+
isPublished: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.isPublished) || false,
|
|
107
|
+
dimensions: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.dimensions) || {
|
|
108
|
+
width: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.width) || 320,
|
|
109
|
+
height: (contextObject === null || contextObject === void 0 ? void 0 : contextObject.height) || 240
|
|
110
|
+
},
|
|
111
|
+
frameTitle: title,
|
|
112
|
+
canvasId: contextObject === null || contextObject === void 0 ? void 0 : contextObject.canvasId
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Returns the capabilities supported by the Widgetic platform adapter.
|
|
118
|
+
*
|
|
119
|
+
* Capabilities explained:
|
|
120
|
+
* - supportsScreenshot: Can capture static images of frame content
|
|
121
|
+
* - supportsRecording: Can record video of user interactions within frames
|
|
122
|
+
* - supportsFileUpload: Can handle file uploads via drag-and-drop or file picker
|
|
123
|
+
* - supportsTextInput: Can handle text-based chat messages
|
|
124
|
+
* - supportsMediaCapture: Can handle general media input (camera access, microphone,
|
|
125
|
+
* file uploads, reference images) beyond just screenshots and recordings
|
|
126
|
+
*/
|
|
127
|
+
WidgeticCanvasAdapter.prototype.getCapabilities = function () {
|
|
128
|
+
return {
|
|
129
|
+
supportsScreenshot: true,
|
|
130
|
+
supportsRecording: true,
|
|
131
|
+
supportsFileUpload: true,
|
|
132
|
+
supportsTextInput: true,
|
|
133
|
+
supportsMediaCapture: true
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Get AI suggestions based on frame context
|
|
138
|
+
*/
|
|
139
|
+
WidgeticCanvasAdapter.prototype.getSuggestions = function (context) {
|
|
140
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
141
|
+
var frameType;
|
|
142
|
+
var _a;
|
|
143
|
+
return __generator(this, function (_b) {
|
|
144
|
+
frameType = ((_a = context.metadata) === null || _a === void 0 ? void 0 : _a.frameTitle) || 'frame';
|
|
145
|
+
return [2 /*return*/, [
|
|
146
|
+
"What does this ".concat(frameType, " do?"),
|
|
147
|
+
"How can I improve this design?",
|
|
148
|
+
"Can you explain this component?",
|
|
149
|
+
"What are some best practices for this?",
|
|
150
|
+
"How do I customize this further?"
|
|
151
|
+
]];
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Get available actions for this frame
|
|
157
|
+
*/
|
|
158
|
+
WidgeticCanvasAdapter.prototype.getActions = function (context) {
|
|
159
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
160
|
+
var _this = this;
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
return [2 /*return*/, [
|
|
163
|
+
{
|
|
164
|
+
id: 'screenshot',
|
|
165
|
+
label: 'Take Screenshot',
|
|
166
|
+
icon: 'camera',
|
|
167
|
+
handler: function () { return _this.captureFrameScreenshot(context.id); }
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: 'record',
|
|
171
|
+
label: 'Record Video',
|
|
172
|
+
icon: 'video',
|
|
173
|
+
handler: function () { return _this.startFrameRecording(context.id); }
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: 'inspect',
|
|
177
|
+
label: 'Inspect Frame',
|
|
178
|
+
icon: 'search',
|
|
179
|
+
handler: function () { return _this.getFrameContent(context.id); }
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: 'select-element',
|
|
183
|
+
label: 'Select Element',
|
|
184
|
+
icon: 'cursor-pointer',
|
|
185
|
+
handler: function () { return _this.enableElementSelection(context.id); }
|
|
186
|
+
}
|
|
187
|
+
]];
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Capture screenshot of a specific frame
|
|
193
|
+
*/
|
|
194
|
+
WidgeticCanvasAdapter.prototype.captureFrameScreenshot = function (frameId) {
|
|
195
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
196
|
+
var canvas_1, ctx;
|
|
197
|
+
return __generator(this, function (_a) {
|
|
198
|
+
try {
|
|
199
|
+
canvas_1 = document.createElement('canvas');
|
|
200
|
+
canvas_1.width = 320;
|
|
201
|
+
canvas_1.height = 240;
|
|
202
|
+
ctx = canvas_1.getContext('2d');
|
|
203
|
+
if (ctx) {
|
|
204
|
+
// Draw a placeholder
|
|
205
|
+
ctx.fillStyle = '#f3f4f6';
|
|
206
|
+
ctx.fillRect(0, 0, canvas_1.width, canvas_1.height);
|
|
207
|
+
ctx.fillStyle = '#6b7280';
|
|
208
|
+
ctx.font = '16px Arial';
|
|
209
|
+
ctx.textAlign = 'center';
|
|
210
|
+
ctx.fillText("Frame ".concat(frameId), canvas_1.width / 2, canvas_1.height / 2);
|
|
211
|
+
}
|
|
212
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
213
|
+
canvas_1.toBlob(function (blob) {
|
|
214
|
+
resolve(blob || new Blob());
|
|
215
|
+
}, 'image/png');
|
|
216
|
+
})];
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.error('Failed to capture frame screenshot:', error);
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
return [2 /*return*/];
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Start recording a frame
|
|
228
|
+
*/
|
|
229
|
+
WidgeticCanvasAdapter.prototype.startFrameRecording = function (frameId) {
|
|
230
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
try {
|
|
233
|
+
chatLog("Starting recording for frame: ".concat(frameId));
|
|
234
|
+
// Implementation would integrate with the canvas recording system
|
|
235
|
+
// For now, just log the action
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
console.error('Failed to start frame recording:', error);
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
return [2 /*return*/];
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Capture screenshot of any frame context
|
|
247
|
+
*/
|
|
248
|
+
WidgeticCanvasAdapter.prototype.captureScreenshot = function (contextId) {
|
|
249
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
250
|
+
return __generator(this, function (_a) {
|
|
251
|
+
return [2 /*return*/, this.captureFrameScreenshot(contextId)];
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Start recording for any context
|
|
257
|
+
*/
|
|
258
|
+
WidgeticCanvasAdapter.prototype.startRecording = function (contextId) {
|
|
259
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
260
|
+
return __generator(this, function (_a) {
|
|
261
|
+
return [2 /*return*/, this.startFrameRecording(contextId)];
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Stop recording (placeholder)
|
|
267
|
+
*/
|
|
268
|
+
WidgeticCanvasAdapter.prototype.stopRecording = function () {
|
|
269
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
// Implementation would stop the recording and return the video blob
|
|
272
|
+
chatLog('Stopping recording...');
|
|
273
|
+
return [2 /*return*/, new Blob([], { type: 'video/webm' })];
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Get frame content and metadata with optional element-specific inspection.
|
|
279
|
+
*
|
|
280
|
+
* This method retrieves detailed information about a frame's structure, components,
|
|
281
|
+
* and optionally focuses on a specific element within the frame. It's used by the
|
|
282
|
+
* AI to understand the frame's composition and provide targeted suggestions.
|
|
283
|
+
*
|
|
284
|
+
* @param frameId - The unique identifier of the frame to inspect
|
|
285
|
+
* @param elementId - Optional. The specific element within the frame to focus on
|
|
286
|
+
* @returns Promise containing frame content, structure, and metadata
|
|
287
|
+
*
|
|
288
|
+
* Use cases:
|
|
289
|
+
* - General frame analysis: getFrameContent('frame-123')
|
|
290
|
+
* - Specific element targeting: getFrameContent('frame-123', 'button-456')
|
|
291
|
+
* - AI code generation based on existing components
|
|
292
|
+
* - Providing context for design suggestions
|
|
293
|
+
*/
|
|
294
|
+
WidgeticCanvasAdapter.prototype.getFrameContent = function (frameId, elementId) {
|
|
295
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
296
|
+
var baseFrameData, _a, _b, error_1;
|
|
297
|
+
var _c, _d;
|
|
298
|
+
return __generator(this, function (_e) {
|
|
299
|
+
switch (_e.label) {
|
|
300
|
+
case 0:
|
|
301
|
+
_e.trys.push([0, 5, , 6]);
|
|
302
|
+
baseFrameData = {
|
|
303
|
+
frameId: frameId,
|
|
304
|
+
type: 'frame',
|
|
305
|
+
metadata: {
|
|
306
|
+
width: 320,
|
|
307
|
+
height: 240,
|
|
308
|
+
isPublished: false,
|
|
309
|
+
canvasId: "canvas-".concat(frameId)
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
if (!elementId) return [3 /*break*/, 2];
|
|
313
|
+
_a = [__assign({}, baseFrameData)];
|
|
314
|
+
_c = {};
|
|
315
|
+
return [4 /*yield*/, this.getElementDetails(frameId, elementId)];
|
|
316
|
+
case 1:
|
|
317
|
+
// Return element-specific data for targeted AI assistance
|
|
318
|
+
return [2 /*return*/, __assign.apply(void 0, _a.concat([(_c.selectedElement = _e.sent(), _c.content = "Frame containing selected element: ".concat(elementId), _c.context = 'element-specific-inspection', _c)]))];
|
|
319
|
+
case 2:
|
|
320
|
+
_b = [__assign({}, baseFrameData)];
|
|
321
|
+
_d = {};
|
|
322
|
+
return [4 /*yield*/, this.getFrameStructure(frameId)];
|
|
323
|
+
case 3:
|
|
324
|
+
_d.content = _e.sent();
|
|
325
|
+
return [4 /*yield*/, this.getFrameComponents(frameId)];
|
|
326
|
+
case 4:
|
|
327
|
+
// Return full frame structure for general inspection
|
|
328
|
+
return [2 /*return*/, __assign.apply(void 0, _b.concat([(_d.components = _e.sent(), _d.context = 'full-frame-inspection', _d)]))];
|
|
329
|
+
case 5:
|
|
330
|
+
error_1 = _e.sent();
|
|
331
|
+
console.error('Failed to get frame content:', error_1);
|
|
332
|
+
throw error_1;
|
|
333
|
+
case 6: return [2 /*return*/];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Get detailed information about a specific element within a frame.
|
|
340
|
+
*
|
|
341
|
+
* This method provides comprehensive data about a selected element, including
|
|
342
|
+
* its properties, styling, position, and relationships to other elements.
|
|
343
|
+
* Used when the user wants to make changes to a specific component.
|
|
344
|
+
*
|
|
345
|
+
* @param frameId - The frame containing the element
|
|
346
|
+
* @param elementId - The unique identifier of the element to inspect
|
|
347
|
+
* @returns Element details including properties, styling, and context
|
|
348
|
+
*/
|
|
349
|
+
WidgeticCanvasAdapter.prototype.getElementDetails = function (frameId, elementId) {
|
|
350
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
351
|
+
return __generator(this, function (_a) {
|
|
352
|
+
try {
|
|
353
|
+
// In a real implementation, this would:
|
|
354
|
+
// 1. Query the canvas API for the specific element
|
|
355
|
+
// 2. Extract element properties (type, content, styling)
|
|
356
|
+
// 3. Get element position and dimensions
|
|
357
|
+
// 4. Identify parent/child relationships
|
|
358
|
+
// 5. Extract event handlers and interactions
|
|
359
|
+
return [2 /*return*/, {
|
|
360
|
+
elementId: elementId,
|
|
361
|
+
type: 'button', // Would be dynamically determined
|
|
362
|
+
properties: {
|
|
363
|
+
text: 'Click Me',
|
|
364
|
+
variant: 'primary',
|
|
365
|
+
size: 'medium',
|
|
366
|
+
disabled: false
|
|
367
|
+
},
|
|
368
|
+
styling: {
|
|
369
|
+
backgroundColor: '#3b82f6',
|
|
370
|
+
color: '#ffffff',
|
|
371
|
+
borderRadius: '6px',
|
|
372
|
+
padding: '8px 16px',
|
|
373
|
+
fontSize: '14px'
|
|
374
|
+
},
|
|
375
|
+
position: {
|
|
376
|
+
x: 50,
|
|
377
|
+
y: 100,
|
|
378
|
+
width: 120,
|
|
379
|
+
height: 40
|
|
380
|
+
},
|
|
381
|
+
interactions: {
|
|
382
|
+
onClick: 'handleButtonClick',
|
|
383
|
+
onHover: 'showTooltip'
|
|
384
|
+
},
|
|
385
|
+
hierarchy: {
|
|
386
|
+
parent: 'container-789',
|
|
387
|
+
children: [],
|
|
388
|
+
siblings: ['input-101', 'label-102']
|
|
389
|
+
},
|
|
390
|
+
metadata: {
|
|
391
|
+
createdAt: new Date().toISOString(),
|
|
392
|
+
lastModified: new Date().toISOString(),
|
|
393
|
+
component: 'Button',
|
|
394
|
+
library: 'widgetic-ui'
|
|
395
|
+
}
|
|
396
|
+
}];
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
console.error('Failed to get element details:', error);
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
402
|
+
return [2 /*return*/];
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
/**
|
|
407
|
+
* Get the hierarchical structure of all components within a frame.
|
|
408
|
+
*
|
|
409
|
+
* This method provides a tree-like representation of the frame's content,
|
|
410
|
+
* showing how components are nested and organized. Useful for understanding
|
|
411
|
+
* the overall layout and suggesting structural improvements.
|
|
412
|
+
*
|
|
413
|
+
* @param frameId - The frame to analyze
|
|
414
|
+
* @returns Hierarchical structure of frame components
|
|
415
|
+
*/
|
|
416
|
+
WidgeticCanvasAdapter.prototype.getFrameStructure = function (frameId) {
|
|
417
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
418
|
+
return __generator(this, function (_a) {
|
|
419
|
+
try {
|
|
420
|
+
// In a real implementation, this would:
|
|
421
|
+
// 1. Traverse the frame's DOM or component tree
|
|
422
|
+
// 2. Build a hierarchical representation
|
|
423
|
+
// 3. Include layout information (flexbox, grid, etc.)
|
|
424
|
+
// 4. Identify component relationships and dependencies
|
|
425
|
+
return [2 /*return*/, {
|
|
426
|
+
root: {
|
|
427
|
+
type: 'container',
|
|
428
|
+
id: 'root-container',
|
|
429
|
+
layout: 'flexbox',
|
|
430
|
+
direction: 'column',
|
|
431
|
+
children: [
|
|
432
|
+
{
|
|
433
|
+
type: 'header',
|
|
434
|
+
id: 'header-123',
|
|
435
|
+
children: [
|
|
436
|
+
{ type: 'title', id: 'title-124', content: 'Widget Title' },
|
|
437
|
+
{ type: 'subtitle', id: 'subtitle-125', content: 'Description' }
|
|
438
|
+
]
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
type: 'content',
|
|
442
|
+
id: 'content-126',
|
|
443
|
+
layout: 'grid',
|
|
444
|
+
children: [
|
|
445
|
+
{ type: 'button', id: 'button-127', content: 'Primary Action' },
|
|
446
|
+
{ type: 'input', id: 'input-128', content: '' },
|
|
447
|
+
{ type: 'text', id: 'text-129', content: 'Help text' }
|
|
448
|
+
]
|
|
449
|
+
}
|
|
450
|
+
]
|
|
451
|
+
},
|
|
452
|
+
layoutInfo: {
|
|
453
|
+
totalElements: 7,
|
|
454
|
+
maxDepth: 3,
|
|
455
|
+
layoutTypes: ['flexbox', 'grid'],
|
|
456
|
+
responsiveBreakpoints: ['mobile', 'tablet', 'desktop']
|
|
457
|
+
}
|
|
458
|
+
}];
|
|
459
|
+
}
|
|
460
|
+
catch (error) {
|
|
461
|
+
console.error('Failed to get frame structure:', error);
|
|
462
|
+
throw error;
|
|
463
|
+
}
|
|
464
|
+
return [2 /*return*/];
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Get a list of all components within a frame with their basic properties.
|
|
470
|
+
*
|
|
471
|
+
* This method provides a flat list of all components for quick reference
|
|
472
|
+
* and bulk operations. Useful for inventory, search, and batch modifications.
|
|
473
|
+
*
|
|
474
|
+
* @param frameId - The frame to analyze
|
|
475
|
+
* @returns Array of component summaries
|
|
476
|
+
*/
|
|
477
|
+
WidgeticCanvasAdapter.prototype.getFrameComponents = function (frameId) {
|
|
478
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
479
|
+
return __generator(this, function (_a) {
|
|
480
|
+
try {
|
|
481
|
+
// In a real implementation, this would:
|
|
482
|
+
// 1. Query all components in the frame
|
|
483
|
+
// 2. Extract basic information for each
|
|
484
|
+
// 3. Include component states and variants
|
|
485
|
+
// 4. Provide quick access properties
|
|
486
|
+
return [2 /*return*/, [
|
|
487
|
+
{
|
|
488
|
+
id: 'title-124',
|
|
489
|
+
type: 'title',
|
|
490
|
+
content: 'Widget Title',
|
|
491
|
+
editable: true,
|
|
492
|
+
visible: true
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
id: 'subtitle-125',
|
|
496
|
+
type: 'subtitle',
|
|
497
|
+
content: 'Description',
|
|
498
|
+
editable: true,
|
|
499
|
+
visible: true
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
id: 'button-127',
|
|
503
|
+
type: 'button',
|
|
504
|
+
content: 'Primary Action',
|
|
505
|
+
variant: 'primary',
|
|
506
|
+
interactive: true
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
id: 'input-128',
|
|
510
|
+
type: 'input',
|
|
511
|
+
placeholder: 'Enter text...',
|
|
512
|
+
required: false,
|
|
513
|
+
interactive: true
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
id: 'text-129',
|
|
517
|
+
type: 'text',
|
|
518
|
+
content: 'Help text',
|
|
519
|
+
editable: false,
|
|
520
|
+
visible: true
|
|
521
|
+
}
|
|
522
|
+
]];
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
console.error('Failed to get frame components:', error);
|
|
526
|
+
throw error;
|
|
527
|
+
}
|
|
528
|
+
return [2 /*return*/];
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* Enable element selection mode for a frame.
|
|
534
|
+
*
|
|
535
|
+
* This method puts the frame into a special selection mode where users can
|
|
536
|
+
* click on individual elements to select them for targeted AI assistance.
|
|
537
|
+
* When an element is selected, it becomes the focus for subsequent AI interactions.
|
|
538
|
+
*
|
|
539
|
+
* @param frameId - The frame to enable selection mode for
|
|
540
|
+
* @returns Promise that resolves when selection mode is active
|
|
541
|
+
*
|
|
542
|
+
* Behavior:
|
|
543
|
+
* - Highlights hoverable elements
|
|
544
|
+
* - Shows selection cursor
|
|
545
|
+
* - Captures element clicks
|
|
546
|
+
* - Provides visual feedback for selection
|
|
547
|
+
* - Automatically focuses chat on selected element
|
|
548
|
+
*/
|
|
549
|
+
WidgeticCanvasAdapter.prototype.enableElementSelection = function (frameId) {
|
|
550
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
551
|
+
var frameElement, selectableElements;
|
|
552
|
+
var _this = this;
|
|
553
|
+
return __generator(this, function (_a) {
|
|
554
|
+
try {
|
|
555
|
+
chatLog("Enabling element selection for frame: ".concat(frameId));
|
|
556
|
+
frameElement = document.querySelector("[data-frame-id=\"".concat(frameId, "\"]"));
|
|
557
|
+
if (frameElement) {
|
|
558
|
+
frameElement.classList.add('element-selection-mode');
|
|
559
|
+
selectableElements = frameElement.querySelectorAll('[data-element-id]');
|
|
560
|
+
selectableElements.forEach(function (element) {
|
|
561
|
+
element.addEventListener('click', function (event) {
|
|
562
|
+
event.stopPropagation();
|
|
563
|
+
var elementId = event.target.getAttribute('data-element-id');
|
|
564
|
+
if (elementId) {
|
|
565
|
+
_this.selectElement(frameId, elementId);
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
// Add hover effects
|
|
569
|
+
element.addEventListener('mouseenter', function () {
|
|
570
|
+
element.classList.add('element-hover');
|
|
571
|
+
});
|
|
572
|
+
element.addEventListener('mouseleave', function () {
|
|
573
|
+
element.classList.remove('element-hover');
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
// Notify that selection mode is active
|
|
578
|
+
this.triggerContextUpdate({
|
|
579
|
+
id: frameId,
|
|
580
|
+
type: ContextType.FRAME,
|
|
581
|
+
parentId: 'canvas',
|
|
582
|
+
title: "Frame ".concat(frameId),
|
|
583
|
+
metadata: {
|
|
584
|
+
selectionMode: true,
|
|
585
|
+
instruction: 'Click on an element to select it for AI assistance'
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
console.error('Failed to enable element selection:', error);
|
|
591
|
+
throw error;
|
|
592
|
+
}
|
|
593
|
+
return [2 /*return*/];
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* Select a specific element within a frame for targeted AI assistance.
|
|
599
|
+
*
|
|
600
|
+
* This method is called when a user clicks on an element during selection mode.
|
|
601
|
+
* It highlights the selected element and prepares it for AI interaction.
|
|
602
|
+
*
|
|
603
|
+
* @param frameId - The frame containing the element
|
|
604
|
+
* @param elementId - The element that was selected
|
|
605
|
+
* @returns Promise that resolves when element is selected
|
|
606
|
+
*/
|
|
607
|
+
WidgeticCanvasAdapter.prototype.selectElement = function (frameId, elementId) {
|
|
608
|
+
return __awaiter(this, void 0, Promise, function () {
|
|
609
|
+
var frameElement, selectedElement, elementDetails, error_2;
|
|
610
|
+
var _a;
|
|
611
|
+
return __generator(this, function (_b) {
|
|
612
|
+
switch (_b.label) {
|
|
613
|
+
case 0:
|
|
614
|
+
_b.trys.push([0, 2, , 3]);
|
|
615
|
+
chatLog("Selected element ".concat(elementId, " in frame ").concat(frameId));
|
|
616
|
+
frameElement = document.querySelector("[data-frame-id=\"".concat(frameId, "\"]"));
|
|
617
|
+
if (frameElement) {
|
|
618
|
+
frameElement.querySelectorAll('.element-selected').forEach(function (el) {
|
|
619
|
+
el.classList.remove('element-selected');
|
|
620
|
+
});
|
|
621
|
+
selectedElement = frameElement.querySelector("[data-element-id=\"".concat(elementId, "\"]"));
|
|
622
|
+
if (selectedElement) {
|
|
623
|
+
selectedElement.classList.add('element-selected');
|
|
624
|
+
}
|
|
625
|
+
// Exit selection mode
|
|
626
|
+
frameElement.classList.remove('element-selection-mode');
|
|
627
|
+
}
|
|
628
|
+
return [4 /*yield*/, this.getElementDetails(frameId, elementId)];
|
|
629
|
+
case 1:
|
|
630
|
+
elementDetails = _b.sent();
|
|
631
|
+
// Trigger context update with selected element
|
|
632
|
+
this.triggerContextUpdate({
|
|
633
|
+
id: frameId,
|
|
634
|
+
type: ContextType.FRAME,
|
|
635
|
+
parentId: 'canvas',
|
|
636
|
+
title: "Frame ".concat(frameId, " - ").concat(elementDetails.type),
|
|
637
|
+
metadata: {
|
|
638
|
+
selectedElement: elementId,
|
|
639
|
+
elementType: elementDetails.type,
|
|
640
|
+
selectionMode: false,
|
|
641
|
+
aiContext: "Selected ".concat(elementDetails.type, " for modification: ").concat(((_a = elementDetails.properties) === null || _a === void 0 ? void 0 : _a.text) || elementId)
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
return [3 /*break*/, 3];
|
|
645
|
+
case 2:
|
|
646
|
+
error_2 = _b.sent();
|
|
647
|
+
console.error('Failed to select element:', error_2);
|
|
648
|
+
throw error_2;
|
|
649
|
+
case 3: return [2 /*return*/];
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Register callback for frame selection events
|
|
656
|
+
*/
|
|
657
|
+
WidgeticCanvasAdapter.prototype.onFrameSelection = function (callback) {
|
|
658
|
+
var _this = this;
|
|
659
|
+
this.frameSelectionCallbacks.push(callback);
|
|
660
|
+
return function () {
|
|
661
|
+
var index = _this.frameSelectionCallbacks.indexOf(callback);
|
|
662
|
+
if (index > -1) {
|
|
663
|
+
_this.frameSelectionCallbacks.splice(index, 1);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
};
|
|
667
|
+
/**
|
|
668
|
+
* Register callback for frame deselection events
|
|
669
|
+
*/
|
|
670
|
+
WidgeticCanvasAdapter.prototype.onFrameDeselection = function (callback) {
|
|
671
|
+
var _this = this;
|
|
672
|
+
this.frameDeselectionCallbacks.push(callback);
|
|
673
|
+
return function () {
|
|
674
|
+
var index = _this.frameDeselectionCallbacks.indexOf(callback);
|
|
675
|
+
if (index > -1) {
|
|
676
|
+
_this.frameDeselectionCallbacks.splice(index, 1);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
/**
|
|
681
|
+
* Register callback for context changes
|
|
682
|
+
*/
|
|
683
|
+
WidgeticCanvasAdapter.prototype.onContextChange = function (callback) {
|
|
684
|
+
var _this = this;
|
|
685
|
+
this.contextChangeCallbacks.push(callback);
|
|
686
|
+
return function () {
|
|
687
|
+
var index = _this.contextChangeCallbacks.indexOf(callback);
|
|
688
|
+
if (index > -1) {
|
|
689
|
+
_this.contextChangeCallbacks.splice(index, 1);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* Register callback for context updates
|
|
695
|
+
*/
|
|
696
|
+
WidgeticCanvasAdapter.prototype.onContextUpdate = function (callback) {
|
|
697
|
+
var _this = this;
|
|
698
|
+
this.contextUpdateCallbacks.push(callback);
|
|
699
|
+
return function () {
|
|
700
|
+
var index = _this.contextUpdateCallbacks.indexOf(callback);
|
|
701
|
+
if (index > -1) {
|
|
702
|
+
_this.contextUpdateCallbacks.splice(index, 1);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Trigger frame selection event
|
|
708
|
+
*/
|
|
709
|
+
WidgeticCanvasAdapter.prototype.triggerFrameSelection = function (frameId) {
|
|
710
|
+
this.frameSelectionCallbacks.forEach(function (callback) {
|
|
711
|
+
try {
|
|
712
|
+
callback(frameId);
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
console.error('Error in frame selection callback:', error);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* Trigger frame deselection event
|
|
721
|
+
*/
|
|
722
|
+
WidgeticCanvasAdapter.prototype.triggerFrameDeselection = function (frameId) {
|
|
723
|
+
this.frameDeselectionCallbacks.forEach(function (callback) {
|
|
724
|
+
try {
|
|
725
|
+
callback(frameId);
|
|
726
|
+
}
|
|
727
|
+
catch (error) {
|
|
728
|
+
console.error('Error in frame deselection callback:', error);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* Trigger context change event
|
|
734
|
+
*/
|
|
735
|
+
WidgeticCanvasAdapter.prototype.triggerContextChange = function (context) {
|
|
736
|
+
this.contextChangeCallbacks.forEach(function (callback) {
|
|
737
|
+
try {
|
|
738
|
+
callback(context);
|
|
739
|
+
}
|
|
740
|
+
catch (error) {
|
|
741
|
+
console.error('Error in context change callback:', error);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
/**
|
|
746
|
+
* Trigger context update event
|
|
747
|
+
*/
|
|
748
|
+
WidgeticCanvasAdapter.prototype.triggerContextUpdate = function (context) {
|
|
749
|
+
this.contextUpdateCallbacks.forEach(function (callback) {
|
|
750
|
+
try {
|
|
751
|
+
callback(context);
|
|
752
|
+
}
|
|
753
|
+
catch (error) {
|
|
754
|
+
console.error('Error in context update callback:', error);
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
};
|
|
758
|
+
return WidgeticCanvasAdapter;
|
|
759
|
+
}());
|
|
760
|
+
export { WidgeticCanvasAdapter };
|
|
761
|
+
/**
|
|
762
|
+
* Create a new Widgetic adapter instance
|
|
763
|
+
*/
|
|
764
|
+
export function createWidgeticAdapter() {
|
|
765
|
+
return new WidgeticCanvasAdapter();
|
|
766
|
+
}
|