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.

Potentially problematic release.


This version of ghostfill might be problematic. Click here for more details.

@@ -0,0 +1,12 @@
1
+ import { b as GhostFillAIRequest, F as FieldFillData, D as DetectedField, c as GhostFillPromptField } from './types-B3DGbZyx.mjs';
2
+ export { d as PROVIDERS, P as Provider } from './types-B3DGbZyx.mjs';
3
+
4
+ declare 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 \u2014 do not skip any\n- 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.)\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 \u2014 return raw JSON only";
5
+ declare function toPromptFields(fields: DetectedField[]): GhostFillPromptField[];
6
+ declare function buildFillMessages(request: GhostFillAIRequest): Array<{
7
+ role: "system" | "user";
8
+ content: string;
9
+ }>;
10
+ declare function parseFillDataPayload(payload: unknown): FieldFillData[];
11
+
12
+ export { FieldFillData, GhostFillAIRequest, GhostFillPromptField, SYSTEM_PROMPT, buildFillMessages, parseFillDataPayload, toPromptFields };
@@ -0,0 +1,12 @@
1
+ import { b as GhostFillAIRequest, F as FieldFillData, D as DetectedField, c as GhostFillPromptField } from './types-B3DGbZyx.js';
2
+ export { d as PROVIDERS, P as Provider } from './types-B3DGbZyx.js';
3
+
4
+ declare 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 \u2014 do not skip any\n- 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.)\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 \u2014 return raw JSON only";
5
+ declare function toPromptFields(fields: DetectedField[]): GhostFillPromptField[];
6
+ declare function buildFillMessages(request: GhostFillAIRequest): Array<{
7
+ role: "system" | "user";
8
+ content: string;
9
+ }>;
10
+ declare function parseFillDataPayload(payload: unknown): FieldFillData[];
11
+
12
+ export { FieldFillData, GhostFillAIRequest, GhostFillPromptField, SYSTEM_PROMPT, buildFillMessages, parseFillDataPayload, toPromptFields };
package/dist/server.js ADDED
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/server.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ PROVIDERS: () => PROVIDERS,
24
+ SYSTEM_PROMPT: () => SYSTEM_PROMPT,
25
+ buildFillMessages: () => buildFillMessages,
26
+ parseFillDataPayload: () => parseFillDataPayload,
27
+ toPromptFields: () => toPromptFields
28
+ });
29
+ module.exports = __toCommonJS(server_exports);
30
+
31
+ // src/detector.ts
32
+ var INPUT_SELECTORS = [
33
+ "input:not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]):not([type=image])",
34
+ "textarea",
35
+ "select",
36
+ // Custom dropdown triggers (Headless UI Listbox, Radix, etc.)
37
+ "button[role=combobox]",
38
+ "[role=combobox]:not(input)",
39
+ "button[aria-haspopup=listbox]"
40
+ ].join(", ");
41
+ function describeFields(fields) {
42
+ return fields.map((f, i) => {
43
+ let desc = `[${i}] "${f.label}" (type: ${f.type}`;
44
+ if (f.required) desc += ", required";
45
+ if (f.options?.length) desc += `, options: [${f.options.join(", ")}]`;
46
+ if (f.min) desc += `, min: ${f.min}`;
47
+ if (f.max) desc += `, max: ${f.max}`;
48
+ if (f.pattern) desc += `, pattern: ${f.pattern}`;
49
+ desc += ")";
50
+ return desc;
51
+ }).join("\n");
52
+ }
53
+
54
+ // src/ai.ts
55
+ 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.
56
+
57
+ Rules:
58
+ - Return ONLY a JSON object with a "fields" array of objects, each with "index" and "value" keys
59
+ - You MUST fill EVERY field \u2014 do not skip any
60
+ - 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.)
61
+ - For select/dropdown fields: you MUST pick one of the listed options EXACTLY as written
62
+ - For checkboxes: add a "checked" boolean (true or false)
63
+ - For radio buttons: only fill one per group, use the option value
64
+ - Respect min/max constraints and patterns
65
+ - Generate contextually coherent data (same person's name, matching city/state/zip, etc.)
66
+ - If no user prompt is given, infer appropriate data from the field labels
67
+ - Do NOT request or rely on secrets, tokens, passwords, or existing form values
68
+ - Do NOT wrap the JSON in markdown code blocks \u2014 return raw JSON only`;
69
+ function isRecord(value) {
70
+ return typeof value === "object" && value !== null;
71
+ }
72
+ function toFieldFillData(value) {
73
+ if (!isRecord(value)) {
74
+ throw new Error("AI response item is not an object");
75
+ }
76
+ const index = value.index;
77
+ const rawValue = value.value;
78
+ const checked = value.checked;
79
+ if (typeof index !== "number" || !Number.isInteger(index)) {
80
+ throw new Error("AI response item is missing a numeric index");
81
+ }
82
+ if (typeof rawValue !== "string") {
83
+ throw new Error("AI response item is missing a string value");
84
+ }
85
+ return {
86
+ index,
87
+ value: rawValue,
88
+ checked: typeof checked === "boolean" ? checked : void 0
89
+ };
90
+ }
91
+ function toPromptFields(fields) {
92
+ return fields.map((field, index) => ({
93
+ index,
94
+ type: field.type,
95
+ name: field.name,
96
+ label: field.label,
97
+ options: field.options,
98
+ required: field.required,
99
+ min: field.min,
100
+ max: field.max,
101
+ pattern: field.pattern
102
+ }));
103
+ }
104
+ function buildFillMessages(request) {
105
+ const fieldDescription = describeFields(request.fields);
106
+ let userContent = `Form fields:
107
+ ${fieldDescription}`;
108
+ if (request.prompt) {
109
+ userContent += `
110
+
111
+ User instructions: ${request.prompt}`;
112
+ } else {
113
+ userContent += "\n\nNo specific instructions \u2014 generate realistic, contextually appropriate data for all fields.";
114
+ }
115
+ return [
116
+ {
117
+ role: "system",
118
+ content: request.systemPrompt ? `${request.systemPrompt}
119
+
120
+ ${SYSTEM_PROMPT}` : SYSTEM_PROMPT
121
+ },
122
+ {
123
+ role: "user",
124
+ content: userContent
125
+ }
126
+ ];
127
+ }
128
+ function parseFillDataPayload(payload) {
129
+ if (typeof payload === "string") {
130
+ const jsonMatch = payload.match(/```(?:json)?\s*([\s\S]*?)```/) || [null, payload];
131
+ return parseFillDataPayload(JSON.parse(jsonMatch[1].trim()));
132
+ }
133
+ if (Array.isArray(payload)) {
134
+ return payload.map(toFieldFillData);
135
+ }
136
+ if (isRecord(payload)) {
137
+ if (Array.isArray(payload.choices)) {
138
+ const content = payload.choices[0]?.message;
139
+ if (typeof content?.content === "string") {
140
+ return parseFillDataPayload(content.content);
141
+ }
142
+ }
143
+ const candidate = payload.fields ?? payload.data ?? payload.items ?? payload.result;
144
+ if (Array.isArray(candidate)) {
145
+ return candidate.map(toFieldFillData);
146
+ }
147
+ }
148
+ throw new Error("AI response is not an array of field fills");
149
+ }
150
+
151
+ // src/types.ts
152
+ var PROVIDERS = {
153
+ openai: { label: "OpenAI", model: "gpt-4o-mini", baseURL: "https://api.openai.com/v1", helpText: "Uses gpt-4o-mini \u2014 fast & cheap" },
154
+ xai: { label: "xAI", model: "grok-4-fast", baseURL: "https://api.x.ai/v1", helpText: "Uses Grok 4 Fast" },
155
+ moonshot: { label: "Moonshot", model: "kimi-k2", baseURL: "https://api.moonshot.ai/v1", helpText: "Uses Kimi K2 \u2014 fast & cheap" }
156
+ };
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ PROVIDERS,
160
+ SYSTEM_PROMPT,
161
+ buildFillMessages,
162
+ parseFillDataPayload,
163
+ toPromptFields
164
+ });
165
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server.ts","../src/detector.ts","../src/ai.ts","../src/types.ts"],"sourcesContent":["export {\n SYSTEM_PROMPT,\n buildFillMessages,\n parseFillDataPayload,\n toPromptFields,\n} from \"./ai\";\nexport { PROVIDERS } from \"./types\";\nexport type {\n FieldFillData,\n GhostFillAIRequest,\n GhostFillPromptField,\n Provider,\n} from \"./types\";\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","/** 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AACF,EAAE,KAAK,IAAI;AAsKJ,SAAS,eACd,QAMQ;AACR,SAAO,OACJ,IAAI,CAAC,GAAG,MAAM;AACb,QAAI,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,YAAY,EAAE,IAAI;AAC/C,QAAI,EAAE,SAAU,SAAQ;AACxB,QAAI,EAAE,SAAS,OAAQ,SAAQ,eAAe,EAAE,QAAQ,KAAK,IAAI,CAAC;AAClE,QAAI,EAAE,IAAK,SAAQ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B,UAAU,mCAA8B;AAClI;","names":[]}
@@ -0,0 +1,15 @@
1
+ import {
2
+ PROVIDERS,
3
+ SYSTEM_PROMPT,
4
+ buildFillMessages,
5
+ parseFillDataPayload,
6
+ toPromptFields
7
+ } from "./chunk-VMCU3BNJ.mjs";
8
+ export {
9
+ PROVIDERS,
10
+ SYSTEM_PROMPT,
11
+ buildFillMessages,
12
+ parseFillDataPayload,
13
+ toPromptFields
14
+ };
15
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,83 @@
1
+ /** Configuration options for GhostFill */
2
+ interface GhostFillOptions {
3
+ /**
4
+ * @deprecated Browser API keys are insecure and ignored.
5
+ * Configure `ai` and keep provider credentials on your backend instead.
6
+ */
7
+ apiKey?: string;
8
+ /** Keyboard shortcut to toggle GhostFill (default: "Alt+G") */
9
+ shortcut?: string;
10
+ /** Custom system prompt to prepend */
11
+ systemPrompt?: string;
12
+ /** Secure AI transport configuration */
13
+ ai?: GhostFillAIOptions;
14
+ }
15
+ type Provider = "openai" | "xai" | "moonshot";
16
+ declare const PROVIDERS: Record<Provider, {
17
+ label: string;
18
+ model: string;
19
+ baseURL: string;
20
+ helpText: string;
21
+ }>;
22
+ /** Non-secret field metadata sent to an AI backend */
23
+ interface GhostFillPromptField {
24
+ index: number;
25
+ type: string;
26
+ name: string;
27
+ label: string;
28
+ options?: string[];
29
+ required: boolean;
30
+ min?: string;
31
+ max?: string;
32
+ pattern?: string;
33
+ }
34
+ /** Secure AI request payload for a backend route or callback */
35
+ interface GhostFillAIRequest {
36
+ provider: Provider;
37
+ prompt: string;
38
+ systemPrompt?: string;
39
+ fields: GhostFillPromptField[];
40
+ }
41
+ type GhostFillAIHandler = (request: GhostFillAIRequest) => Promise<FieldFillData[]>;
42
+ /** Secure AI configuration. Requests must go through a backend or custom handler. */
43
+ interface GhostFillAIOptions {
44
+ /** Same-origin backend route. Defaults to `/api/ghostfill` when `ai` is enabled. */
45
+ endpoint?: string;
46
+ /** Optional custom transport that forwards requests to a secure backend. */
47
+ requestFillData?: GhostFillAIHandler;
48
+ /** Default provider shown in the UI. */
49
+ provider?: Provider;
50
+ }
51
+ /** A detected form field */
52
+ interface DetectedField {
53
+ /** The DOM element */
54
+ element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
55
+ /** Field type: text, email, number, select, textarea, checkbox, radio, date, etc. */
56
+ type: string;
57
+ /** Field name attribute */
58
+ name: string;
59
+ /** Field label (from <label>, aria-label, or placeholder) */
60
+ label: string;
61
+ /** For <select>, the available options */
62
+ options?: string[];
63
+ /** Whether the field is required */
64
+ required: boolean;
65
+ /** Current value */
66
+ currentValue: string;
67
+ /** Min/max for number/date fields */
68
+ min?: string;
69
+ max?: string;
70
+ /** Pattern attribute */
71
+ pattern?: string;
72
+ }
73
+ /** Field data returned by the AI */
74
+ interface FieldFillData {
75
+ /** Index matching the DetectedField array */
76
+ index: number;
77
+ /** Value to fill */
78
+ value: string;
79
+ /** For checkboxes: whether to check */
80
+ checked?: boolean;
81
+ }
82
+
83
+ export { type DetectedField as D, type FieldFillData as F, type GhostFillAIOptions as G, type Provider as P, type GhostFillOptions as a, type GhostFillAIRequest as b, type GhostFillPromptField as c, PROVIDERS as d };
@@ -0,0 +1,83 @@
1
+ /** Configuration options for GhostFill */
2
+ interface GhostFillOptions {
3
+ /**
4
+ * @deprecated Browser API keys are insecure and ignored.
5
+ * Configure `ai` and keep provider credentials on your backend instead.
6
+ */
7
+ apiKey?: string;
8
+ /** Keyboard shortcut to toggle GhostFill (default: "Alt+G") */
9
+ shortcut?: string;
10
+ /** Custom system prompt to prepend */
11
+ systemPrompt?: string;
12
+ /** Secure AI transport configuration */
13
+ ai?: GhostFillAIOptions;
14
+ }
15
+ type Provider = "openai" | "xai" | "moonshot";
16
+ declare const PROVIDERS: Record<Provider, {
17
+ label: string;
18
+ model: string;
19
+ baseURL: string;
20
+ helpText: string;
21
+ }>;
22
+ /** Non-secret field metadata sent to an AI backend */
23
+ interface GhostFillPromptField {
24
+ index: number;
25
+ type: string;
26
+ name: string;
27
+ label: string;
28
+ options?: string[];
29
+ required: boolean;
30
+ min?: string;
31
+ max?: string;
32
+ pattern?: string;
33
+ }
34
+ /** Secure AI request payload for a backend route or callback */
35
+ interface GhostFillAIRequest {
36
+ provider: Provider;
37
+ prompt: string;
38
+ systemPrompt?: string;
39
+ fields: GhostFillPromptField[];
40
+ }
41
+ type GhostFillAIHandler = (request: GhostFillAIRequest) => Promise<FieldFillData[]>;
42
+ /** Secure AI configuration. Requests must go through a backend or custom handler. */
43
+ interface GhostFillAIOptions {
44
+ /** Same-origin backend route. Defaults to `/api/ghostfill` when `ai` is enabled. */
45
+ endpoint?: string;
46
+ /** Optional custom transport that forwards requests to a secure backend. */
47
+ requestFillData?: GhostFillAIHandler;
48
+ /** Default provider shown in the UI. */
49
+ provider?: Provider;
50
+ }
51
+ /** A detected form field */
52
+ interface DetectedField {
53
+ /** The DOM element */
54
+ element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
55
+ /** Field type: text, email, number, select, textarea, checkbox, radio, date, etc. */
56
+ type: string;
57
+ /** Field name attribute */
58
+ name: string;
59
+ /** Field label (from <label>, aria-label, or placeholder) */
60
+ label: string;
61
+ /** For <select>, the available options */
62
+ options?: string[];
63
+ /** Whether the field is required */
64
+ required: boolean;
65
+ /** Current value */
66
+ currentValue: string;
67
+ /** Min/max for number/date fields */
68
+ min?: string;
69
+ max?: string;
70
+ /** Pattern attribute */
71
+ pattern?: string;
72
+ }
73
+ /** Field data returned by the AI */
74
+ interface FieldFillData {
75
+ /** Index matching the DetectedField array */
76
+ index: number;
77
+ /** Value to fill */
78
+ value: string;
79
+ /** For checkboxes: whether to check */
80
+ checked?: boolean;
81
+ }
82
+
83
+ export { type DetectedField as D, type FieldFillData as F, type GhostFillAIOptions as G, type Provider as P, type GhostFillOptions as a, type GhostFillAIRequest as b, type GhostFillPromptField as c, PROVIDERS as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ghostfill",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Dev tool that fills form fields with relevant sample data — select a block, click fill, done",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.mjs",
12
12
  "require": "./dist/index.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server.d.ts",
16
+ "import": "./dist/server.mjs",
17
+ "require": "./dist/server.js"
13
18
  }
14
19
  },
15
20
  "files": [