@widgetic/chat 0.1.14 → 0.1.16
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
17
|
+
getContextId(contextObject) {
|
|
66
18
|
if (typeof contextObject === 'string') {
|
|
67
19
|
return contextObject;
|
|
68
20
|
}
|
|
69
|
-
if (contextObject
|
|
21
|
+
if (contextObject?.frameId) {
|
|
70
22
|
return contextObject.frameId;
|
|
71
23
|
}
|
|
72
|
-
if (contextObject
|
|
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
|
-
|
|
32
|
+
getContextTitle(contextObject) {
|
|
81
33
|
if (typeof contextObject === 'string') {
|
|
82
|
-
return
|
|
34
|
+
return `Frame ${contextObject}`;
|
|
83
35
|
}
|
|
84
|
-
return
|
|
85
|
-
}
|
|
36
|
+
return contextObject?.title || contextObject?.name || `Frame ${this.getContextId(contextObject)}`;
|
|
37
|
+
}
|
|
86
38
|
/**
|
|
87
39
|
* Get context type
|
|
88
40
|
*/
|
|
89
|
-
|
|
41
|
+
getContextType() {
|
|
90
42
|
return 'frame';
|
|
91
|
-
}
|
|
43
|
+
}
|
|
92
44
|
/**
|
|
93
45
|
* Create a standardized chat context from a frame object
|
|
94
46
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
47
|
+
createContext(contextObject) {
|
|
48
|
+
const id = this.getContextId(contextObject);
|
|
49
|
+
const title = this.getContextTitle(contextObject);
|
|
98
50
|
return {
|
|
99
|
-
id
|
|
51
|
+
id,
|
|
100
52
|
type: ContextType.FRAME,
|
|
101
|
-
parentId:
|
|
102
|
-
title
|
|
103
|
-
thumbnail:
|
|
53
|
+
parentId: contextObject?.canvasId || 'unknown-canvas',
|
|
54
|
+
title,
|
|
55
|
+
thumbnail: contextObject?.thumbnail || contextObject?.previewUrl,
|
|
104
56
|
metadata: {
|
|
105
|
-
isPublished:
|
|
106
|
-
dimensions:
|
|
107
|
-
width:
|
|
108
|
-
height:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
248
|
-
return
|
|
249
|
-
|
|
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
|
-
|
|
258
|
-
return
|
|
259
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
|
|
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
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
-
|
|
655
|
-
var _this = this;
|
|
548
|
+
onFrameSelection(callback) {
|
|
656
549
|
this.frameSelectionCallbacks.push(callback);
|
|
657
|
-
return
|
|
658
|
-
|
|
550
|
+
return () => {
|
|
551
|
+
const index = this.frameSelectionCallbacks.indexOf(callback);
|
|
659
552
|
if (index > -1) {
|
|
660
|
-
|
|
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
|
-
|
|
668
|
-
var _this = this;
|
|
560
|
+
onFrameDeselection(callback) {
|
|
669
561
|
this.frameDeselectionCallbacks.push(callback);
|
|
670
|
-
return
|
|
671
|
-
|
|
562
|
+
return () => {
|
|
563
|
+
const index = this.frameDeselectionCallbacks.indexOf(callback);
|
|
672
564
|
if (index > -1) {
|
|
673
|
-
|
|
565
|
+
this.frameDeselectionCallbacks.splice(index, 1);
|
|
674
566
|
}
|
|
675
567
|
};
|
|
676
|
-
}
|
|
568
|
+
}
|
|
677
569
|
/**
|
|
678
570
|
* Register callback for context changes
|
|
679
571
|
*/
|
|
680
|
-
|
|
681
|
-
var _this = this;
|
|
572
|
+
onContextChange(callback) {
|
|
682
573
|
this.contextChangeCallbacks.push(callback);
|
|
683
|
-
return
|
|
684
|
-
|
|
574
|
+
return () => {
|
|
575
|
+
const index = this.contextChangeCallbacks.indexOf(callback);
|
|
685
576
|
if (index > -1) {
|
|
686
|
-
|
|
577
|
+
this.contextChangeCallbacks.splice(index, 1);
|
|
687
578
|
}
|
|
688
579
|
};
|
|
689
|
-
}
|
|
580
|
+
}
|
|
690
581
|
/**
|
|
691
582
|
* Register callback for context updates
|
|
692
583
|
*/
|
|
693
|
-
|
|
694
|
-
var _this = this;
|
|
584
|
+
onContextUpdate(callback) {
|
|
695
585
|
this.contextUpdateCallbacks.push(callback);
|
|
696
|
-
return
|
|
697
|
-
|
|
586
|
+
return () => {
|
|
587
|
+
const index = this.contextUpdateCallbacks.indexOf(callback);
|
|
698
588
|
if (index > -1) {
|
|
699
|
-
|
|
589
|
+
this.contextUpdateCallbacks.splice(index, 1);
|
|
700
590
|
}
|
|
701
591
|
};
|
|
702
|
-
}
|
|
592
|
+
}
|
|
703
593
|
/**
|
|
704
594
|
* Trigger frame selection event
|
|
705
595
|
*/
|
|
706
|
-
|
|
707
|
-
this.frameSelectionCallbacks.forEach(
|
|
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
|
-
|
|
720
|
-
this.frameDeselectionCallbacks.forEach(
|
|
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
|
-
|
|
733
|
-
this.contextChangeCallbacks.forEach(
|
|
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
|
-
|
|
746
|
-
this.contextUpdateCallbacks.forEach(
|
|
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
|
-
|
|
756
|
-
}());
|
|
757
|
-
export { WidgeticCanvasAdapter };
|
|
644
|
+
}
|
|
645
|
+
}
|
|
758
646
|
/**
|
|
759
647
|
* Create a new Widgetic adapter instance
|
|
760
648
|
*/
|