@widgetic/chat 0.1.13 → 0.1.15

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