ghostfill 0.1.2 → 0.2.0

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 CHANGED
@@ -28,7 +28,14 @@ import { useEffect } from "react";
28
28
 
29
29
  function GhostFill() {
30
30
  useEffect(() => {
31
- import("ghostfill").then((m) => m.init());
31
+ import("ghostfill").then((m) =>
32
+ m.init({
33
+ ai: {
34
+ endpoint: "/api/ghostfill",
35
+ provider: "openai",
36
+ },
37
+ })
38
+ );
32
39
  }, []);
33
40
  return null;
34
41
  }
@@ -51,22 +58,94 @@ await fill({ container: document.querySelector("form") });
51
58
  2. Click it to enter selection mode — hover and click a form area
52
59
  3. Click the sparkles button to fill all detected fields
53
60
  4. By default, generates random sample data locally (no API needed)
54
- 5. Optionally enable AI mode in settings for context-aware data generation
61
+ 5. Optionally enable AI mode in settings for context-aware data generation through your backend
62
+
63
+ ## Secure AI Setup
64
+
65
+ GhostFill no longer accepts provider API keys in the browser. To use OpenAI, xAI, or Moonshot safely, expose a backend route and keep provider credentials server-side.
66
+
67
+ Install a server-side SDK in your app:
68
+
69
+ ```bash
70
+ npm install openai
71
+ ```
72
+
73
+ Example Next.js route:
74
+
75
+ ```ts
76
+ // app/api/ghostfill/route.ts
77
+ import OpenAI from "openai";
78
+ import {
79
+ buildFillMessages,
80
+ parseFillDataPayload,
81
+ type GhostFillAIRequest,
82
+ type Provider,
83
+ } from "ghostfill/server";
84
+
85
+ const clients: Record<Provider, OpenAI> = {
86
+ openai: new OpenAI({
87
+ apiKey: process.env.OPENAI_API_KEY,
88
+ }),
89
+ xai: new OpenAI({
90
+ apiKey: process.env.XAI_API_KEY,
91
+ baseURL: "https://api.x.ai/v1",
92
+ }),
93
+ moonshot: new OpenAI({
94
+ apiKey: process.env.MOONSHOT_API_KEY,
95
+ baseURL: "https://api.moonshot.cn/v1",
96
+ }),
97
+ };
98
+
99
+ const models: Record<Provider, string> = {
100
+ openai: process.env.GHOSTFILL_OPENAI_MODEL || "gpt-4o-mini",
101
+ xai: process.env.GHOSTFILL_XAI_MODEL || "grok-4-fast",
102
+ moonshot: process.env.GHOSTFILL_MOONSHOT_MODEL || "moonshot-v1-8k",
103
+ };
104
+
105
+ function isProvider(value: unknown): value is Provider {
106
+ return value === "openai" || value === "xai" || value === "moonshot";
107
+ }
108
+
109
+ export async function POST(req: Request) {
110
+ const body = (await req.json()) as Partial<GhostFillAIRequest>;
111
+
112
+ if (!isProvider(body.provider) || !Array.isArray(body.fields)) {
113
+ return Response.json({ error: "Invalid GhostFill request" }, { status: 400 });
114
+ }
115
+
116
+ const completion = await clients[body.provider].chat.completions.create({
117
+ model: models[body.provider],
118
+ messages: buildFillMessages({
119
+ provider: body.provider,
120
+ prompt: typeof body.prompt === "string" ? body.prompt : "",
121
+ systemPrompt:
122
+ typeof body.systemPrompt === "string" ? body.systemPrompt : undefined,
123
+ fields: body.fields,
124
+ }),
125
+ });
126
+
127
+ const content = completion.choices[0]?.message?.content || "";
128
+ return Response.json(parseFillDataPayload(content));
129
+ }
130
+ ```
131
+
132
+ This route supports all three providers, keeps secrets server-side, and only sends non-secret field metadata to the model. If you expose it outside local development, add your app's auth, rate limits, and request-size validation.
55
133
 
56
134
  ## Settings
57
135
 
58
136
  Click the gear icon to configure:
59
137
 
60
138
  - **Highlight Colour** — pick the selection overlay color
61
- - **Use AI** — toggle AI-powered fills (requires API key)
62
- - **Provider** — cycle between OpenAI (gpt-4o-mini), xAI (Grok 4 Fast), Moonshot (Kimi K2)
63
- - **API Key** — your provider API key
64
- - **Presets** — save prompt templates for domain-specific data (e.g. D365, healthcare)
139
+ - **Use AI** — toggle AI-powered fills when a secure backend route is configured
140
+ - **Provider** — cycle between OpenAI, xAI, and Moonshot
141
+ - **Backend** — shows the secure route or handler being used for AI fills
142
+ - **Presets** — save prompt templates for domain-specific data (e.g. D365, healthcare); keep them non-secret because they are stored locally
65
143
  - **Dark/Light theme** — toggle with the sun/moon icon
66
144
 
67
145
  ## Features
68
146
 
69
147
  - **Zero config** — works out of the box with random sample data
148
+ - **Secure by default** — AI mode uses a backend route instead of browser-held provider keys
70
149
  - **Shadow DOM** — styles don't leak into your app
71
150
  - **Framework-aware** — uses native value setters so React/Vue/Angular pick up changes
72
151
  - **Smart detection** — labels from `<label>`, `aria-label`, placeholder, preceding siblings
@@ -84,9 +163,13 @@ Initialize GhostFill and add the UI to the page.
84
163
 
85
164
  ```ts
86
165
  init({
87
- apiKey?: string, // API key (can also set in UI)
88
- shortcut?: string, // Keyboard shortcut (default: "Alt+G")
89
- systemPrompt?: string // Custom system prompt to prepend
166
+ ai?: {
167
+ endpoint?: string, // Same-origin backend route (default: "/api/ghostfill")
168
+ requestFillData?: (request: GhostFillAIRequest) => Promise<FieldFillData[]>,
169
+ provider?: "openai" | "xai" | "moonshot"
170
+ },
171
+ shortcut?: string, // Keyboard shortcut (default: "Alt+G")
172
+ systemPrompt?: string // Custom system prompt to prepend
90
173
  })
91
174
  ```
92
175
 
@@ -99,7 +182,14 @@ Programmatic fill without the UI.
99
182
  ```ts
100
183
  await fill({
101
184
  container: HTMLElement, // The element containing form fields
102
- prompt?: string // Optional prompt for AI mode
185
+ prompt?: string, // Optional prompt for AI mode
186
+ ai?: {
187
+ endpoint?: string,
188
+ requestFillData?: (request: GhostFillAIRequest) => Promise<FieldFillData[]>,
189
+ provider?: "openai" | "xai" | "moonshot"
190
+ },
191
+ provider?: "openai" | "xai" | "moonshot",
192
+ systemPrompt?: string
103
193
  })
104
194
  ```
105
195
 
@@ -0,0 +1,275 @@
1
+ // src/types.ts
2
+ var PROVIDERS = {
3
+ openai: { label: "OpenAI", model: "gpt-4o-mini", baseURL: "https://api.openai.com/v1", helpText: "Uses gpt-4o-mini \u2014 fast & cheap" },
4
+ xai: { label: "xAI", model: "grok-4-fast", baseURL: "https://api.x.ai/v1", helpText: "Uses Grok 4 Fast" },
5
+ moonshot: { label: "Moonshot", model: "kimi-k2", baseURL: "https://api.moonshot.ai/v1", helpText: "Uses Kimi K2 \u2014 fast & cheap" }
6
+ };
7
+
8
+ // src/detector.ts
9
+ var INPUT_SELECTORS = [
10
+ "input:not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image])",
11
+ "textarea",
12
+ "select",
13
+ // Custom dropdown triggers (Headless UI Listbox, Radix, etc.)
14
+ "button[role=combobox]",
15
+ "[role=combobox]:not(input)",
16
+ "button[aria-haspopup=listbox]"
17
+ ].join(", ");
18
+ function findLabel(el) {
19
+ if (el.id) {
20
+ const label = document.querySelector(
21
+ `label[for="${CSS.escape(el.id)}"]`
22
+ );
23
+ if (label?.textContent?.trim()) return label.textContent.trim();
24
+ }
25
+ const parentLabel = el.closest("label");
26
+ if (parentLabel) {
27
+ const clone = parentLabel.cloneNode(true);
28
+ clone.querySelectorAll("input, textarea, select").forEach((c) => c.remove());
29
+ const text = clone.textContent?.trim();
30
+ if (text) return text;
31
+ }
32
+ const ariaLabel = el.getAttribute("aria-label");
33
+ if (ariaLabel?.trim()) return ariaLabel.trim();
34
+ const labelledBy = el.getAttribute("aria-labelledby");
35
+ if (labelledBy) {
36
+ const parts = labelledBy.split(/\s+/).map((id) => document.getElementById(id)?.textContent?.trim()).filter(Boolean);
37
+ if (parts.length) return parts.join(" ");
38
+ }
39
+ if ("placeholder" in el) {
40
+ const ph = el.placeholder;
41
+ if (ph?.trim()) return ph.trim();
42
+ }
43
+ const title = el.getAttribute("title");
44
+ if (title?.trim()) return title.trim();
45
+ const prev = el.previousElementSibling;
46
+ if (prev && !["INPUT", "TEXTAREA", "SELECT"].includes(prev.tagName)) {
47
+ const prevText = prev.textContent?.trim();
48
+ if (prevText && prevText.length < 60) return prevText;
49
+ }
50
+ const parent = el.parentElement;
51
+ if (parent) {
52
+ for (const child of Array.from(parent.children)) {
53
+ if (child === el) break;
54
+ if (["LABEL", "SPAN", "P", "H1", "H2", "H3", "H4", "H5", "H6", "LEGEND", "DIV"].includes(child.tagName)) {
55
+ const text = child.textContent?.trim();
56
+ if (text && text.length < 60 && !child.querySelector("input, textarea, select")) {
57
+ return text;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ if (el.id) return el.id.replace(/[_\-]/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim();
63
+ const name = el.getAttribute("name");
64
+ if (name) return name.replace(/[_\-[\]]/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim();
65
+ return "unknown";
66
+ }
67
+ function detectFields(container) {
68
+ const elements = container.querySelectorAll(INPUT_SELECTORS);
69
+ const fields = [];
70
+ elements.forEach((el) => {
71
+ if (el.disabled) return;
72
+ if (el.readOnly) return;
73
+ if (el.offsetParent === null && el.type !== "hidden") return;
74
+ const isCustomDropdown = el.getAttribute("role") === "combobox" && !(el instanceof HTMLInputElement) || el.getAttribute("aria-haspopup") === "listbox";
75
+ if (isCustomDropdown) {
76
+ const listboxId = el.getAttribute("aria-controls");
77
+ let listbox = listboxId ? document.getElementById(listboxId) : null;
78
+ if (!listbox) {
79
+ listbox = el.parentElement?.querySelector("[role=listbox]") || null;
80
+ }
81
+ const options = [];
82
+ if (listbox) {
83
+ listbox.querySelectorAll("[role=option]").forEach((opt) => {
84
+ const text = opt.textContent?.trim();
85
+ if (text) options.push(text);
86
+ });
87
+ }
88
+ const buttonText = el.textContent?.trim() || "";
89
+ const looksLikePlaceholder = buttonText.toLowerCase().startsWith("select") || buttonText === "";
90
+ const field2 = {
91
+ element: el,
92
+ type: "select",
93
+ name: el.id || el.getAttribute("name") || "",
94
+ label: findLabel(el),
95
+ required: el.getAttribute("aria-required") === "true",
96
+ currentValue: looksLikePlaceholder ? "" : buttonText,
97
+ options: options.length > 0 ? options : void 0
98
+ };
99
+ fields.push(field2);
100
+ return;
101
+ }
102
+ const field = {
103
+ element: el,
104
+ type: el instanceof HTMLSelectElement ? "select" : el.type || "text",
105
+ name: el.name || el.id || "",
106
+ label: findLabel(el),
107
+ required: el.required || el.getAttribute("aria-required") === "true",
108
+ currentValue: el.value
109
+ };
110
+ if (el instanceof HTMLSelectElement) {
111
+ field.options = Array.from(el.options).filter((opt) => opt.value && !opt.disabled).map((opt) => opt.textContent?.trim() || opt.value);
112
+ }
113
+ if ("min" in el && el.min) {
114
+ field.min = el.min;
115
+ }
116
+ if ("max" in el && el.max) {
117
+ field.max = el.max;
118
+ }
119
+ if ("pattern" in el && el.pattern) {
120
+ field.pattern = el.pattern;
121
+ }
122
+ fields.push(field);
123
+ });
124
+ return fields;
125
+ }
126
+ function describeFields(fields) {
127
+ return fields.map((f, i) => {
128
+ let desc = `[${i}] "${f.label}" (type: ${f.type}`;
129
+ if (f.required) desc += ", required";
130
+ if (f.options?.length) desc += `, options: [${f.options.join(", ")}]`;
131
+ if (f.min) desc += `, min: ${f.min}`;
132
+ if (f.max) desc += `, max: ${f.max}`;
133
+ if (f.pattern) desc += `, pattern: ${f.pattern}`;
134
+ desc += ")";
135
+ return desc;
136
+ }).join("\n");
137
+ }
138
+
139
+ // src/ai.ts
140
+ var SYSTEM_PROMPT = `You are a form-filling assistant. Given a list of form fields and an optional user prompt, generate realistic fake data to fill ALL fields.
141
+
142
+ Rules:
143
+ - Return ONLY a JSON object with a "fields" array of objects, each with "index" and "value" keys
144
+ - You MUST fill EVERY field \u2014 do not skip any
145
+ - Match the field type (email \u2192 valid email, phone \u2192 valid phone with country code, date \u2192 YYYY-MM-DD, datetime-local \u2192 YYYY-MM-DDTHH:MM, etc.)
146
+ - For select/dropdown fields: you MUST pick one of the listed options EXACTLY as written
147
+ - For checkboxes: add a "checked" boolean (true or false)
148
+ - For radio buttons: only fill one per group, use the option value
149
+ - Respect min/max constraints and patterns
150
+ - Generate contextually coherent data (same person's name, matching city/state/zip, etc.)
151
+ - If no user prompt is given, infer appropriate data from the field labels
152
+ - Do NOT request or rely on secrets, tokens, passwords, or existing form values
153
+ - Do NOT wrap the JSON in markdown code blocks \u2014 return raw JSON only`;
154
+ function isRecord(value) {
155
+ return typeof value === "object" && value !== null;
156
+ }
157
+ function toFieldFillData(value) {
158
+ if (!isRecord(value)) {
159
+ throw new Error("AI response item is not an object");
160
+ }
161
+ const index = value.index;
162
+ const rawValue = value.value;
163
+ const checked = value.checked;
164
+ if (typeof index !== "number" || !Number.isInteger(index)) {
165
+ throw new Error("AI response item is missing a numeric index");
166
+ }
167
+ if (typeof rawValue !== "string") {
168
+ throw new Error("AI response item is missing a string value");
169
+ }
170
+ return {
171
+ index,
172
+ value: rawValue,
173
+ checked: typeof checked === "boolean" ? checked : void 0
174
+ };
175
+ }
176
+ function toPromptFields(fields) {
177
+ return fields.map((field, index) => ({
178
+ index,
179
+ type: field.type,
180
+ name: field.name,
181
+ label: field.label,
182
+ options: field.options,
183
+ required: field.required,
184
+ min: field.min,
185
+ max: field.max,
186
+ pattern: field.pattern
187
+ }));
188
+ }
189
+ function buildFillMessages(request) {
190
+ const fieldDescription = describeFields(request.fields);
191
+ let userContent = `Form fields:
192
+ ${fieldDescription}`;
193
+ if (request.prompt) {
194
+ userContent += `
195
+
196
+ User instructions: ${request.prompt}`;
197
+ } else {
198
+ userContent += "\n\nNo specific instructions \u2014 generate realistic, contextually appropriate data for all fields.";
199
+ }
200
+ return [
201
+ {
202
+ role: "system",
203
+ content: request.systemPrompt ? `${request.systemPrompt}
204
+
205
+ ${SYSTEM_PROMPT}` : SYSTEM_PROMPT
206
+ },
207
+ {
208
+ role: "user",
209
+ content: userContent
210
+ }
211
+ ];
212
+ }
213
+ function parseFillDataPayload(payload) {
214
+ if (typeof payload === "string") {
215
+ const jsonMatch = payload.match(/```(?:json)?\s*([\s\S]*?)```/) || [null, payload];
216
+ return parseFillDataPayload(JSON.parse(jsonMatch[1].trim()));
217
+ }
218
+ if (Array.isArray(payload)) {
219
+ return payload.map(toFieldFillData);
220
+ }
221
+ if (isRecord(payload)) {
222
+ if (Array.isArray(payload.choices)) {
223
+ const content = payload.choices[0]?.message;
224
+ if (typeof content?.content === "string") {
225
+ return parseFillDataPayload(content.content);
226
+ }
227
+ }
228
+ const candidate = payload.fields ?? payload.data ?? payload.items ?? payload.result;
229
+ if (Array.isArray(candidate)) {
230
+ return candidate.map(toFieldFillData);
231
+ }
232
+ }
233
+ throw new Error("AI response is not an array of field fills");
234
+ }
235
+ function createRequest(fields, userPrompt, provider, systemPrompt) {
236
+ return {
237
+ provider,
238
+ prompt: userPrompt,
239
+ systemPrompt,
240
+ fields: toPromptFields(fields)
241
+ };
242
+ }
243
+ async function generateFillData(fields, userPrompt, provider, transport, systemPrompt) {
244
+ const request = createRequest(fields, userPrompt, provider, systemPrompt);
245
+ if (transport.requestFillData) {
246
+ return transport.requestFillData(request);
247
+ }
248
+ const endpoint = transport.endpoint ?? "/api/ghostfill";
249
+ const response = await fetch(endpoint, {
250
+ method: "POST",
251
+ headers: {
252
+ "Content-Type": "application/json"
253
+ },
254
+ body: JSON.stringify(request)
255
+ });
256
+ if (!response.ok) {
257
+ const error = await response.text();
258
+ throw new Error(`AI API error (${response.status}): ${error}`);
259
+ }
260
+ const contentType = response.headers.get("content-type") || "";
261
+ const payload = contentType.includes("application/json") ? await response.json() : await response.text();
262
+ return parseFillDataPayload(payload);
263
+ }
264
+
265
+ export {
266
+ PROVIDERS,
267
+ detectFields,
268
+ describeFields,
269
+ SYSTEM_PROMPT,
270
+ toPromptFields,
271
+ buildFillMessages,
272
+ parseFillDataPayload,
273
+ generateFillData
274
+ };
275
+ //# sourceMappingURL=chunk-VMCU3BNJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/detector.ts","../src/ai.ts"],"sourcesContent":["/** Configuration options for GhostFill */\nexport interface GhostFillOptions {\n /**\n * @deprecated Browser API keys are insecure and ignored.\n * Configure `ai` and keep provider credentials on your backend instead.\n */\n apiKey?: string;\n /** Keyboard shortcut to toggle GhostFill (default: \"Alt+G\") */\n shortcut?: string;\n /** Custom system prompt to prepend */\n systemPrompt?: string;\n /** Secure AI transport configuration */\n ai?: GhostFillAIOptions;\n}\n\nexport type Provider = \"openai\" | \"xai\" | \"moonshot\";\n\nexport const PROVIDERS: Record<Provider, { label: string; model: string; baseURL: string; helpText: string }> = {\n openai: { label: \"OpenAI\", model: \"gpt-4o-mini\", baseURL: \"https://api.openai.com/v1\", helpText: \"Uses gpt-4o-mini — fast & cheap\" },\n xai: { label: \"xAI\", model: \"grok-4-fast\", baseURL: \"https://api.x.ai/v1\", helpText: \"Uses Grok 4 Fast\" },\n moonshot: { label: \"Moonshot\", model: \"kimi-k2\", baseURL: \"https://api.moonshot.ai/v1\", helpText: \"Uses Kimi K2 — fast & cheap\" },\n};\n\n/** Non-secret field metadata sent to an AI backend */\nexport interface GhostFillPromptField {\n index: number;\n type: string;\n name: string;\n label: string;\n options?: string[];\n required: boolean;\n min?: string;\n max?: string;\n pattern?: string;\n}\n\n/** Secure AI request payload for a backend route or callback */\nexport interface GhostFillAIRequest {\n provider: Provider;\n prompt: string;\n systemPrompt?: string;\n fields: GhostFillPromptField[];\n}\n\nexport type GhostFillAIHandler = (\n request: GhostFillAIRequest\n) => Promise<FieldFillData[]>;\n\n/** Secure AI configuration. Requests must go through a backend or custom handler. */\nexport interface GhostFillAIOptions {\n /** Same-origin backend route. Defaults to `/api/ghostfill` when `ai` is enabled. */\n endpoint?: string;\n /** Optional custom transport that forwards requests to a secure backend. */\n requestFillData?: GhostFillAIHandler;\n /** Default provider shown in the UI. */\n provider?: Provider;\n}\n\n/** A saved prompt preset */\nexport interface Preset {\n id: string;\n name: string;\n prompt: string;\n}\n\n/** Persisted settings (localStorage) */\nexport interface GhostFillSettings {\n apiKey: string;\n provider: Provider;\n highlightColor: string;\n theme: \"dark\" | \"light\";\n useAI: boolean;\n presets: Preset[];\n activePresetId: string | null;\n}\n\n/** A detected form field */\nexport interface DetectedField {\n /** The DOM element */\n element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;\n /** Field type: text, email, number, select, textarea, checkbox, radio, date, etc. */\n type: string;\n /** Field name attribute */\n name: string;\n /** Field label (from <label>, aria-label, or placeholder) */\n label: string;\n /** For <select>, the available options */\n options?: string[];\n /** Whether the field is required */\n required: boolean;\n /** Current value */\n currentValue: string;\n /** Min/max for number/date fields */\n min?: string;\n max?: string;\n /** Pattern attribute */\n pattern?: string;\n}\n\n/** Field data returned by the AI */\nexport interface FieldFillData {\n /** Index matching the DetectedField array */\n index: number;\n /** Value to fill */\n value: string;\n /** For checkboxes: whether to check */\n checked?: boolean;\n}\n\n/** Internal state */\nexport interface GhostFillState {\n active: boolean;\n selecting: boolean;\n selectedBlock: HTMLElement | null;\n fields: DetectedField[];\n overlay: HTMLElement | null;\n shadowRoot: ShadowRoot | null;\n}\n","import type { DetectedField, GhostFillPromptField } from \"./types\";\n\nconst INPUT_SELECTORS = [\n \"input:not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image])\",\n \"textarea\",\n \"select\",\n // Custom dropdown triggers (Headless UI Listbox, Radix, etc.)\n \"button[role=combobox]\",\n \"[role=combobox]:not(input)\",\n \"button[aria-haspopup=listbox]\",\n].join(\", \");\n\n/** Find the label text for a form field */\nfunction findLabel(el: HTMLElement): string {\n // 1. Explicit <label for=\"id\">\n if (el.id) {\n const label = document.querySelector<HTMLLabelElement>(\n `label[for=\"${CSS.escape(el.id)}\"]`\n );\n if (label?.textContent?.trim()) return label.textContent.trim();\n }\n\n // 2. Wrapping <label>\n const parentLabel = el.closest(\"label\");\n if (parentLabel) {\n // Get text content excluding the input itself\n const clone = parentLabel.cloneNode(true) as HTMLElement;\n clone.querySelectorAll(\"input, textarea, select\").forEach((c) => c.remove());\n const text = clone.textContent?.trim();\n if (text) return text;\n }\n\n // 3. aria-label\n const ariaLabel = el.getAttribute(\"aria-label\");\n if (ariaLabel?.trim()) return ariaLabel.trim();\n\n // 4. aria-labelledby\n const labelledBy = el.getAttribute(\"aria-labelledby\");\n if (labelledBy) {\n const parts = labelledBy\n .split(/\\s+/)\n .map((id) => document.getElementById(id)?.textContent?.trim())\n .filter(Boolean);\n if (parts.length) return parts.join(\" \");\n }\n\n // 5. placeholder\n if (\"placeholder\" in el) {\n const ph = (el as HTMLInputElement).placeholder;\n if (ph?.trim()) return ph.trim();\n }\n\n // 6. title\n const title = el.getAttribute(\"title\");\n if (title?.trim()) return title.trim();\n\n // 7. Preceding sibling text (common pattern: <span>Label</span><input>)\n const prev = el.previousElementSibling;\n if (prev && ![\"INPUT\", \"TEXTAREA\", \"SELECT\"].includes(prev.tagName)) {\n const prevText = prev.textContent?.trim();\n if (prevText && prevText.length < 60) return prevText;\n }\n\n // 8. Parent's first text node or heading\n const parent = el.parentElement;\n if (parent) {\n // Look for a heading or label-like element before this input in the parent\n for (const child of Array.from(parent.children)) {\n if (child === el) break;\n if ([\"LABEL\", \"SPAN\", \"P\", \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"LEGEND\", \"DIV\"].includes(child.tagName)) {\n const text = child.textContent?.trim();\n if (text && text.length < 60 && !child.querySelector(\"input, textarea, select\")) {\n return text;\n }\n }\n }\n }\n\n // 9. id attribute humanized\n if (el.id) return el.id.replace(/[_\\-]/g, \" \").replace(/([a-z])([A-Z])/g, \"$1 $2\").trim();\n\n // 10. name attribute as fallback\n const name = el.getAttribute(\"name\");\n if (name) return name.replace(/[_\\-[\\]]/g, \" \").replace(/([a-z])([A-Z])/g, \"$1 $2\").trim();\n\n return \"unknown\";\n}\n\n/** Detect all fillable fields within a container element */\nexport function detectFields(container: HTMLElement): DetectedField[] {\n const elements = container.querySelectorAll<\n HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement\n >(INPUT_SELECTORS);\n\n const fields: DetectedField[] = [];\n\n elements.forEach((el) => {\n // Skip disabled fields\n if ((el as HTMLInputElement).disabled) return;\n if ((el as HTMLInputElement).readOnly) return;\n // Skip hidden elements\n if (el.offsetParent === null && (el as HTMLInputElement).type !== \"hidden\") return;\n\n // Custom combobox / listbox (Headless UI, Radix, etc.)\n const isCustomDropdown =\n (el.getAttribute(\"role\") === \"combobox\" && !(el instanceof HTMLInputElement)) ||\n el.getAttribute(\"aria-haspopup\") === \"listbox\";\n if (isCustomDropdown) {\n // Find listbox options: aria-controls, sibling [role=listbox], or Headless UI pattern\n const listboxId = el.getAttribute(\"aria-controls\");\n let listbox: Element | null = listboxId ? document.getElementById(listboxId) : null;\n if (!listbox) {\n // Headless UI puts the listbox as a sibling inside the same relative container\n listbox = el.parentElement?.querySelector(\"[role=listbox]\") || null;\n }\n\n const options: string[] = [];\n if (listbox) {\n listbox.querySelectorAll(\"[role=option]\").forEach((opt) => {\n const text = opt.textContent?.trim();\n if (text) options.push(text);\n });\n }\n\n // Get current display value from button text\n const buttonText = el.textContent?.trim() || \"\";\n // Check if it looks like a placeholder\n const looksLikePlaceholder = buttonText.toLowerCase().startsWith(\"select\") || buttonText === \"\";\n\n const field: DetectedField = {\n element: el as any,\n type: \"select\",\n name: el.id || el.getAttribute(\"name\") || \"\",\n label: findLabel(el),\n required: el.getAttribute(\"aria-required\") === \"true\",\n currentValue: looksLikePlaceholder ? \"\" : buttonText,\n options: options.length > 0 ? options : undefined,\n };\n fields.push(field);\n return;\n }\n\n const field: DetectedField = {\n element: el as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,\n type: el instanceof HTMLSelectElement ? \"select\" : (el as HTMLInputElement).type || \"text\",\n name: (el as HTMLInputElement).name || el.id || \"\",\n label: findLabel(el),\n required: (el as HTMLInputElement).required || el.getAttribute(\"aria-required\") === \"true\",\n currentValue: (el as HTMLInputElement).value,\n };\n\n // Collect select options\n if (el instanceof HTMLSelectElement) {\n field.options = Array.from(el.options)\n .filter((opt) => opt.value && !opt.disabled)\n .map((opt) => opt.textContent?.trim() || opt.value);\n }\n\n // Collect constraints\n if (\"min\" in el && (el as HTMLInputElement).min) {\n field.min = (el as HTMLInputElement).min;\n }\n if (\"max\" in el && (el as HTMLInputElement).max) {\n field.max = (el as HTMLInputElement).max;\n }\n if (\"pattern\" in el && (el as HTMLInputElement).pattern) {\n field.pattern = (el as HTMLInputElement).pattern;\n }\n\n fields.push(field);\n });\n\n return fields;\n}\n\n/** Build a description of fields for the AI prompt */\nexport function describeFields(\n fields: Array<\n Pick<\n DetectedField | GhostFillPromptField,\n \"type\" | \"label\" | \"required\" | \"options\" | \"min\" | \"max\" | \"pattern\"\n >\n >\n): string {\n return fields\n .map((f, i) => {\n let desc = `[${i}] \"${f.label}\" (type: ${f.type}`;\n if (f.required) desc += \", required\";\n if (f.options?.length) desc += `, options: [${f.options.join(\", \")}]`;\n if (f.min) desc += `, min: ${f.min}`;\n if (f.max) desc += `, max: ${f.max}`;\n if (f.pattern) desc += `, pattern: ${f.pattern}`;\n desc += \")\";\n return desc;\n })\n .join(\"\\n\");\n}\n","import { describeFields } from \"./detector\";\nimport type {\n DetectedField,\n FieldFillData,\n GhostFillAIOptions,\n GhostFillAIRequest,\n GhostFillPromptField,\n Provider,\n} from \"./types\";\n\nexport const SYSTEM_PROMPT = `You are a form-filling assistant. Given a list of form fields and an optional user prompt, generate realistic fake data to fill ALL fields.\n\nRules:\n- Return ONLY a JSON object with a \"fields\" array of objects, each with \"index\" and \"value\" keys\n- You MUST fill EVERY field — do not skip any\n- Match the field type (email → valid email, phone → valid phone with country code, date → YYYY-MM-DD, datetime-local → YYYY-MM-DDTHH:MM, etc.)\n- For select/dropdown fields: you MUST pick one of the listed options EXACTLY as written\n- For checkboxes: add a \"checked\" boolean (true or false)\n- For radio buttons: only fill one per group, use the option value\n- Respect min/max constraints and patterns\n- Generate contextually coherent data (same person's name, matching city/state/zip, etc.)\n- If no user prompt is given, infer appropriate data from the field labels\n- Do NOT request or rely on secrets, tokens, passwords, or existing form values\n- Do NOT wrap the JSON in markdown code blocks — return raw JSON only`;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction toFieldFillData(value: unknown): FieldFillData {\n if (!isRecord(value)) {\n throw new Error(\"AI response item is not an object\");\n }\n\n const index = value.index;\n const rawValue = value.value;\n const checked = value.checked;\n\n if (typeof index !== \"number\" || !Number.isInteger(index)) {\n throw new Error(\"AI response item is missing a numeric index\");\n }\n\n if (typeof rawValue !== \"string\") {\n throw new Error(\"AI response item is missing a string value\");\n }\n\n return {\n index,\n value: rawValue,\n checked: typeof checked === \"boolean\" ? checked : undefined,\n };\n}\n\nexport function toPromptFields(fields: DetectedField[]): GhostFillPromptField[] {\n return fields.map((field, index) => ({\n index,\n type: field.type,\n name: field.name,\n label: field.label,\n options: field.options,\n required: field.required,\n min: field.min,\n max: field.max,\n pattern: field.pattern,\n }));\n}\n\nexport function buildFillMessages(\n request: GhostFillAIRequest\n): Array<{ role: \"system\" | \"user\"; content: string }> {\n const fieldDescription = describeFields(request.fields);\n let userContent = `Form fields:\\n${fieldDescription}`;\n\n if (request.prompt) {\n userContent += `\\n\\nUser instructions: ${request.prompt}`;\n } else {\n userContent +=\n \"\\n\\nNo specific instructions — generate realistic, contextually appropriate data for all fields.\";\n }\n\n return [\n {\n role: \"system\",\n content: request.systemPrompt\n ? `${request.systemPrompt}\\n\\n${SYSTEM_PROMPT}`\n : SYSTEM_PROMPT,\n },\n {\n role: \"user\",\n content: userContent,\n },\n ];\n}\n\nexport function parseFillDataPayload(payload: unknown): FieldFillData[] {\n if (typeof payload === \"string\") {\n const jsonMatch =\n payload.match(/```(?:json)?\\s*([\\s\\S]*?)```/) || [null, payload];\n return parseFillDataPayload(JSON.parse(jsonMatch[1]!.trim()));\n }\n\n if (Array.isArray(payload)) {\n return payload.map(toFieldFillData);\n }\n\n if (isRecord(payload)) {\n if (Array.isArray(payload.choices)) {\n const content = (payload.choices[0] as Record<string, unknown> | undefined)\n ?.message as Record<string, unknown> | undefined;\n if (typeof content?.content === \"string\") {\n return parseFillDataPayload(content.content);\n }\n }\n\n const candidate =\n payload.fields ?? payload.data ?? payload.items ?? payload.result;\n if (Array.isArray(candidate)) {\n return candidate.map(toFieldFillData);\n }\n }\n\n throw new Error(\"AI response is not an array of field fills\");\n}\n\nfunction createRequest(\n fields: DetectedField[],\n userPrompt: string,\n provider: Provider,\n systemPrompt?: string\n): GhostFillAIRequest {\n return {\n provider,\n prompt: userPrompt,\n systemPrompt,\n fields: toPromptFields(fields),\n };\n}\n\n/** Call a secure backend or callback to generate fill data. */\nexport async function generateFillData(\n fields: DetectedField[],\n userPrompt: string,\n provider: Provider,\n transport: GhostFillAIOptions,\n systemPrompt?: string\n): Promise<FieldFillData[]> {\n const request = createRequest(fields, userPrompt, provider, systemPrompt);\n\n if (transport.requestFillData) {\n return transport.requestFillData(request);\n }\n\n const endpoint = transport.endpoint ?? \"/api/ghostfill\";\n const response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(request),\n });\n\n if (!response.ok) {\n const error = await response.text();\n throw new Error(`AI API error (${response.status}): ${error}`);\n }\n\n const contentType = response.headers.get(\"content-type\") || \"\";\n const payload = contentType.includes(\"application/json\")\n ? await response.json()\n : await response.text();\n\n return parseFillDataPayload(payload);\n}\n"],"mappings":";AAiBO,IAAM,YAAmG;AAAA,EAC9G,QAAQ,EAAE,OAAO,UAAU,OAAO,eAAe,SAAS,6BAA6B,UAAU,uCAAkC;AAAA,EACnI,KAAK,EAAE,OAAO,OAAO,OAAO,eAAe,SAAS,uBAAuB,UAAU,mBAAmB;AAAA,EACxG,UAAU,EAAE,OAAO,YAAY,OAAO,WAAW,SAAS,8BAA8B,UAAU,mCAA8B;AAClI;;;ACnBA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,IAAI;AAGX,SAAS,UAAU,IAAyB;AAE1C,MAAI,GAAG,IAAI;AACT,UAAM,QAAQ,SAAS;AAAA,MACrB,cAAc,IAAI,OAAO,GAAG,EAAE,CAAC;AAAA,IACjC;AACA,QAAI,OAAO,aAAa,KAAK,EAAG,QAAO,MAAM,YAAY,KAAK;AAAA,EAChE;AAGA,QAAM,cAAc,GAAG,QAAQ,OAAO;AACtC,MAAI,aAAa;AAEf,UAAM,QAAQ,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C7B,WAAO,UAAU,gBAAgB,OAAO;AAAA,EAC1C;AAEA,QAAM,WAAW,UAAU,YAAY;AACvC,QAAM,WAAW,MAAM,MAAM,UAAU;AAAA,IACrC,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAU,OAAO;AAAA,EAC9B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,QAAQ,MAAM,SAAS,KAAK;AAClC,UAAM,IAAI,MAAM,iBAAiB,SAAS,MAAM,MAAM,KAAK,EAAE;AAAA,EAC/D;AAEA,QAAM,cAAc,SAAS,QAAQ,IAAI,cAAc,KAAK;AAC5D,QAAM,UAAU,YAAY,SAAS,kBAAkB,IACnD,MAAM,SAAS,KAAK,IACpB,MAAM,SAAS,KAAK;AAExB,SAAO,qBAAqB,OAAO;AACrC;","names":["field"]}
package/dist/index.d.mts CHANGED
@@ -1,43 +1,5 @@
1
- /** Configuration options for GhostFill */
2
- interface GhostFillOptions {
3
- /** API key (optional — can be set via settings UI) */
4
- apiKey?: string;
5
- /** Keyboard shortcut to toggle GhostFill (default: "Alt+G") */
6
- shortcut?: string;
7
- /** Custom system prompt to prepend */
8
- systemPrompt?: string;
9
- }
10
- /** A detected form field */
11
- interface DetectedField {
12
- /** The DOM element */
13
- element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
14
- /** Field type: text, email, number, select, textarea, checkbox, radio, date, etc. */
15
- type: string;
16
- /** Field name attribute */
17
- name: string;
18
- /** Field label (from <label>, aria-label, or placeholder) */
19
- label: string;
20
- /** For <select>, the available options */
21
- options?: string[];
22
- /** Whether the field is required */
23
- required: boolean;
24
- /** Current value */
25
- currentValue: string;
26
- /** Min/max for number/date fields */
27
- min?: string;
28
- max?: string;
29
- /** Pattern attribute */
30
- pattern?: string;
31
- }
32
- /** Field data returned by the AI */
33
- interface FieldFillData {
34
- /** Index matching the DetectedField array */
35
- index: number;
36
- /** Value to fill */
37
- value: string;
38
- /** For checkboxes: whether to check */
39
- checked?: boolean;
40
- }
1
+ import { G as GhostFillAIOptions, P as Provider, a as GhostFillOptions } from './types-B3DGbZyx.mjs';
2
+ export { D as DetectedField, F as FieldFillData, b as GhostFillAIRequest, c as GhostFillPromptField, d as PROVIDERS } from './types-B3DGbZyx.mjs';
41
3
 
42
4
  /**
43
5
  * Initialize GhostFill — adds a floating ghost icon to the page.
@@ -57,9 +19,12 @@ declare function init(options?: GhostFillOptions): {
57
19
  declare function fill(params: {
58
20
  container: HTMLElement;
59
21
  prompt?: string;
22
+ ai?: GhostFillAIOptions;
23
+ provider?: Provider;
24
+ systemPrompt?: string;
60
25
  }): Promise<{
61
26
  filled: number;
62
27
  errors: string[];
63
28
  }>;
64
29
 
65
- export { type DetectedField, type FieldFillData, type GhostFillOptions, fill, init };
30
+ export { GhostFillAIOptions, GhostFillOptions, Provider, fill, init };
package/dist/index.d.ts CHANGED
@@ -1,43 +1,5 @@
1
- /** Configuration options for GhostFill */
2
- interface GhostFillOptions {
3
- /** API key (optional — can be set via settings UI) */
4
- apiKey?: string;
5
- /** Keyboard shortcut to toggle GhostFill (default: "Alt+G") */
6
- shortcut?: string;
7
- /** Custom system prompt to prepend */
8
- systemPrompt?: string;
9
- }
10
- /** A detected form field */
11
- interface DetectedField {
12
- /** The DOM element */
13
- element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
14
- /** Field type: text, email, number, select, textarea, checkbox, radio, date, etc. */
15
- type: string;
16
- /** Field name attribute */
17
- name: string;
18
- /** Field label (from <label>, aria-label, or placeholder) */
19
- label: string;
20
- /** For <select>, the available options */
21
- options?: string[];
22
- /** Whether the field is required */
23
- required: boolean;
24
- /** Current value */
25
- currentValue: string;
26
- /** Min/max for number/date fields */
27
- min?: string;
28
- max?: string;
29
- /** Pattern attribute */
30
- pattern?: string;
31
- }
32
- /** Field data returned by the AI */
33
- interface FieldFillData {
34
- /** Index matching the DetectedField array */
35
- index: number;
36
- /** Value to fill */
37
- value: string;
38
- /** For checkboxes: whether to check */
39
- checked?: boolean;
40
- }
1
+ import { G as GhostFillAIOptions, P as Provider, a as GhostFillOptions } from './types-B3DGbZyx.js';
2
+ export { D as DetectedField, F as FieldFillData, b as GhostFillAIRequest, c as GhostFillPromptField, d as PROVIDERS } from './types-B3DGbZyx.js';
41
3
 
42
4
  /**
43
5
  * Initialize GhostFill — adds a floating ghost icon to the page.
@@ -57,9 +19,12 @@ declare function init(options?: GhostFillOptions): {
57
19
  declare function fill(params: {
58
20
  container: HTMLElement;
59
21
  prompt?: string;
22
+ ai?: GhostFillAIOptions;
23
+ provider?: Provider;
24
+ systemPrompt?: string;
60
25
  }): Promise<{
61
26
  filled: number;
62
27
  errors: string[];
63
28
  }>;
64
29
 
65
- export { type DetectedField, type FieldFillData, type GhostFillOptions, fill, init };
30
+ export { GhostFillAIOptions, GhostFillOptions, Provider, fill, init };