@patchedcodes/hackathon-widget 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/devloyed-widget.js +5941 -0
- package/dist/devloyed-widget.js.map +1 -0
- package/dist/index.d.ts +270 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the screenshot capture.
|
|
3
|
+
*/
|
|
4
|
+
export declare interface CaptureOptions {
|
|
5
|
+
/** Maximum width for the captured image (downscaled if larger) */
|
|
6
|
+
maxWidth?: number;
|
|
7
|
+
/** Maximum height for the captured image */
|
|
8
|
+
maxHeight?: number;
|
|
9
|
+
/** JPEG quality (0-1) if using JPEG format. Default: PNG */
|
|
10
|
+
quality?: number;
|
|
11
|
+
/** Elements to exclude from the capture (e.g. the widget itself) */
|
|
12
|
+
ignoreElements?: (element: Element) => boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Capture-related types.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* The result of a page capture operation.
|
|
20
|
+
*/
|
|
21
|
+
export declare interface CaptureResult {
|
|
22
|
+
/** Base64-encoded PNG screenshot */
|
|
23
|
+
screenshot: string;
|
|
24
|
+
/** Viewport dimensions at time of capture */
|
|
25
|
+
viewport: {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
/** Timestamp of capture */
|
|
30
|
+
timestamp: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A message in the chat conversation.
|
|
35
|
+
*/
|
|
36
|
+
export declare interface ChatMessage {
|
|
37
|
+
id: string;
|
|
38
|
+
role: "user" | "assistant";
|
|
39
|
+
content: string;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The payload sent to the backend when the user issues a command.
|
|
45
|
+
*/
|
|
46
|
+
export declare interface CommandRequest {
|
|
47
|
+
/** API key for authenticating with the backend */
|
|
48
|
+
apiKey: string;
|
|
49
|
+
/** The user's natural language prompt */
|
|
50
|
+
prompt: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The response from the backend after processing a command.
|
|
55
|
+
* The backend only responds once the deploy is complete.
|
|
56
|
+
*/
|
|
57
|
+
export declare interface CommandResponse {
|
|
58
|
+
/** The commit SHA that was pushed to main */
|
|
59
|
+
commitId: string;
|
|
60
|
+
/** AI's explanation of what was changed */
|
|
61
|
+
transcript: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Widget-specific types for the chat UI.
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Deployment info received from the backend.
|
|
69
|
+
*/
|
|
70
|
+
export declare interface DeploymentInfo {
|
|
71
|
+
/** The feature branch name */
|
|
72
|
+
branch: string;
|
|
73
|
+
/** The preview URL (may be same domain after redeploy) */
|
|
74
|
+
previewUrl: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The <devloyed-widget> custom element.
|
|
79
|
+
*
|
|
80
|
+
* Renders a chat-based AI editing interface in a Shadow DOM.
|
|
81
|
+
* When the user issues a command:
|
|
82
|
+
* 1. Captures a screenshot of the page
|
|
83
|
+
* 2. Shows a multi-step loader with randomized labels
|
|
84
|
+
* 3. Sends command + screenshot to the backend (single POST)
|
|
85
|
+
* 4. On response, completes all loader steps and shows the result
|
|
86
|
+
* 5. If branch exists, shows a deploy toast with "Apply" button
|
|
87
|
+
* 6. On "Apply", reloads the page to pick up the redeployed changes
|
|
88
|
+
*/
|
|
89
|
+
export declare class DevloyedWidget extends HTMLElement {
|
|
90
|
+
private shadow;
|
|
91
|
+
private config;
|
|
92
|
+
private transport;
|
|
93
|
+
private state;
|
|
94
|
+
private panelEl;
|
|
95
|
+
private messagesEl;
|
|
96
|
+
private inputEl;
|
|
97
|
+
private sendBtn;
|
|
98
|
+
private toggleBtn;
|
|
99
|
+
private loaderTimer;
|
|
100
|
+
constructor();
|
|
101
|
+
/**
|
|
102
|
+
* Initializes the widget with resolved configuration.
|
|
103
|
+
*/
|
|
104
|
+
initialize(config: ResolvedConfig): void;
|
|
105
|
+
private render;
|
|
106
|
+
private bindEvents;
|
|
107
|
+
/**
|
|
108
|
+
* Opens the chat panel.
|
|
109
|
+
*/
|
|
110
|
+
open(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Closes the chat panel.
|
|
113
|
+
*/
|
|
114
|
+
close(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Toggles the chat panel open/closed.
|
|
117
|
+
*/
|
|
118
|
+
toggle(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Handles sending a user message.
|
|
121
|
+
*
|
|
122
|
+
* Flow:
|
|
123
|
+
* 1. Add user message to chat
|
|
124
|
+
* 2. Generate randomized loader steps
|
|
125
|
+
* 3. Replace messages area with the loader
|
|
126
|
+
* 4. Capture screenshot — mark step 0 as completed
|
|
127
|
+
* 5. Auto-advance remaining steps on a timer (~1.2s each)
|
|
128
|
+
* 6. Fire transport.send() — returns Promise<CommandResponse>
|
|
129
|
+
* 7. When response arrives, cascade-complete all remaining steps
|
|
130
|
+
* 8. After a ~600ms beat, remove loader and show response
|
|
131
|
+
*/
|
|
132
|
+
private handleSend;
|
|
133
|
+
/**
|
|
134
|
+
* Sets the data-state attribute of a loader step element.
|
|
135
|
+
*/
|
|
136
|
+
private setStepState;
|
|
137
|
+
/**
|
|
138
|
+
* Cascade-completes all steps from `fromStep` to `total - 1`,
|
|
139
|
+
* with a short delay between each to create a satisfying visual cascade.
|
|
140
|
+
*/
|
|
141
|
+
private cascadeCompleteSteps;
|
|
142
|
+
/**
|
|
143
|
+
* Restores the messages area to show all prior chat messages
|
|
144
|
+
* (called after loader is removed).
|
|
145
|
+
*/
|
|
146
|
+
private restoreMessages;
|
|
147
|
+
/**
|
|
148
|
+
* Applies the deployed changes by reloading the page.
|
|
149
|
+
* The backend has already redeployed to the same domain.
|
|
150
|
+
*/
|
|
151
|
+
private handleApply;
|
|
152
|
+
/**
|
|
153
|
+
* Adds a message to the chat and renders it.
|
|
154
|
+
*/
|
|
155
|
+
private addMessage;
|
|
156
|
+
/**
|
|
157
|
+
* Scrolls the messages container to the bottom.
|
|
158
|
+
*/
|
|
159
|
+
private scrollToBottom;
|
|
160
|
+
/**
|
|
161
|
+
* Auto-resizes the textarea based on content.
|
|
162
|
+
*/
|
|
163
|
+
private autoResizeInput;
|
|
164
|
+
/**
|
|
165
|
+
* Promise-based delay utility.
|
|
166
|
+
*/
|
|
167
|
+
private delay;
|
|
168
|
+
/**
|
|
169
|
+
* Cleans up when the widget is removed from the DOM.
|
|
170
|
+
*/
|
|
171
|
+
disconnectedCallback(): void;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Initializes the Devloyed widget and mounts it to the page.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { init } from '@devloyed/widget';
|
|
180
|
+
*
|
|
181
|
+
* init({
|
|
182
|
+
* endpoint: 'https://api.devloyed.com/command',
|
|
183
|
+
* projectId: 'my-project',
|
|
184
|
+
* apiKey: 'your-api-key',
|
|
185
|
+
* position: 'bottom-right',
|
|
186
|
+
* theme: 'light',
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare function init(config: WidgetConfig): DevloyedWidget;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Internal resolved configuration with defaults applied.
|
|
194
|
+
*/
|
|
195
|
+
export declare interface ResolvedConfig extends Required<Pick<WidgetConfig, "endpoint" | "projectId" | "apiKey" | "position" | "theme">> {
|
|
196
|
+
headers: Record<string, string>;
|
|
197
|
+
onDeployReady?: (branch: string, previewUrl: string) => void;
|
|
198
|
+
onError?: (error: Error) => void;
|
|
199
|
+
onOpen?: () => void;
|
|
200
|
+
onClose?: () => void;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* HTTP client for communicating with the Devloyed backend.
|
|
205
|
+
* Sends commands + screenshots and returns the response once the
|
|
206
|
+
* backend has finished processing and deploying.
|
|
207
|
+
*/
|
|
208
|
+
export declare class TransportClient {
|
|
209
|
+
private endpoint;
|
|
210
|
+
private headers;
|
|
211
|
+
private abortController;
|
|
212
|
+
constructor(endpoint: string, headers?: Record<string, string>);
|
|
213
|
+
/**
|
|
214
|
+
* Sends a command request to the backend.
|
|
215
|
+
* Returns the response once the backend has deployed the changes.
|
|
216
|
+
*/
|
|
217
|
+
send(request: CommandRequest): Promise<CommandResponse>;
|
|
218
|
+
/**
|
|
219
|
+
* Aborts the current in-flight request, if any.
|
|
220
|
+
*/
|
|
221
|
+
abort(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Updates the headers (e.g. for token refresh).
|
|
224
|
+
*/
|
|
225
|
+
setHeaders(headers: Record<string, string>): void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Configuration for the Devloyed widget.
|
|
230
|
+
*/
|
|
231
|
+
export declare interface WidgetConfig {
|
|
232
|
+
/** Backend endpoint URL for sending commands (POST) */
|
|
233
|
+
endpoint: string;
|
|
234
|
+
/** Project identifier — sent with each request so the backend knows which repo to modify */
|
|
235
|
+
projectId: string;
|
|
236
|
+
/** API key sent in the request body to authenticate with the backend */
|
|
237
|
+
apiKey: string;
|
|
238
|
+
/** Position of the floating widget button */
|
|
239
|
+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
240
|
+
/** Widget color theme */
|
|
241
|
+
theme?: "light" | "dark";
|
|
242
|
+
/** Custom headers sent with backend requests (e.g. auth tokens) */
|
|
243
|
+
headers?: Record<string, string>;
|
|
244
|
+
/** Called when a deployment is ready (before the user clicks "Apply") */
|
|
245
|
+
onDeployReady?: (branch: string, previewUrl: string) => void;
|
|
246
|
+
/** Called when an error occurs */
|
|
247
|
+
onError?: (error: Error) => void;
|
|
248
|
+
/** Called when the widget is opened */
|
|
249
|
+
onOpen?: () => void;
|
|
250
|
+
/** Called when the widget is closed */
|
|
251
|
+
onClose?: () => void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The state of the widget.
|
|
256
|
+
*/
|
|
257
|
+
export declare interface WidgetState {
|
|
258
|
+
/** Whether the chat panel is open */
|
|
259
|
+
isOpen: boolean;
|
|
260
|
+
/** Chat messages */
|
|
261
|
+
messages: ChatMessage[];
|
|
262
|
+
/** Whether a request is currently in flight */
|
|
263
|
+
isLoading: boolean;
|
|
264
|
+
/** Current conversation ID for multi-turn context */
|
|
265
|
+
conversationId?: string;
|
|
266
|
+
/** Info about the latest deployment (set when "deployed" event arrives) */
|
|
267
|
+
deploymentInfo?: DeploymentInfo;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { }
|
package/package.json
CHANGED