=============== LIBRARY RULES =============== From library maintainers: - Read llms.txt for the import per framework: CDN script or ask-ai-widget/element for plain HTML, ask-ai-widget/react, ask-ai-widget/vue, ask-ai-widget/svelte. - Prompt options are strings or synchronous functions, never async. - The lite entries have no built-in services: pass objects imported from ask-ai-widget/services. - With SSR import ask-ai-widget/style.css once and pass page={{ url, title }}. - Style with --aai-* custom properties or the variant/size/shape/theme options; never copy the library CSS. ### Install dependencies and start dev server Source: https://github.com/agilek/ask-ai-widget/blob/main/examples/nextjs/README.md Run this command in the example directory to install dependencies and start the Next.js development server. ```sh npm i && npm run dev ``` -------------------------------- ### Worked example of full configuration with services, instructions, prompt, references, vars, and page Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md This example shows a complete configuration for mounting the widget with two services, custom instructions, a fixed prompt, relative references, custom variables, and page metadata. The output text sent to Claude is shown below, demonstrating how the parts are assembled with the default template. ```javascript mount("#w", { services: ["claude", "gemini"], instructions: "You are a helpful {product} support engineer. Answer concisely.", prompt: "Explain this page to a beginner.", references: ["/llms.txt", "/docs/api"], vars: { product: "Example" }, page: { url: "https://example.com/docs/quickstart", title: "Quickstart | Docs" }, }); ``` ```text You are a helpful Example support engineer. Answer concisely. Explain this page to a beginner. Context: Quickstart | Docs — https://example.com/docs/quickstart Use these sources: - https://example.com/llms.txt - https://example.com/docs/api ``` -------------------------------- ### Install ask-ai-widget with npm, pnpm, or yarn Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Install the package using your preferred package manager. React, Vue, and Svelte are optional peer dependencies; only install the one you use. The package ships ESM, CJS, and .d.ts files for every entry. ```bash npm install ask-ai-widget # pnpm add ask-ai-widget # yarn add ask-ai-widget ``` -------------------------------- ### Development and build commands Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Commands for installing dependencies, building the package, running tests, checking bundle size, verifying contrast, and regenerating icons. ```bash npm install npm run build # tsup (ESM, CJS, d.ts, CDN IIFE) + style.css npm test # vitest + happy-dom npm run size # real consumer bundle sizes, fails on budget or tree-shaking regressions npm run check:contrast # Chromium state matrix: contrast of text, placeholder and icons in every variant, theme and state node scripts/compact-icons.mjs # regenerate src/icons.ts from scripts/icons-src/*.svg ``` -------------------------------- ### Vue: component Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Vue component usage with script setup and template, passing services as an array and label as a string. ```vue ``` -------------------------------- ### Prompt for AI Coding Agents to Integrate ask-ai-widget Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Copy this prompt into Claude Code, Cursor, Copilot, Codex, or any other coding agent. It instructs the agent to install ask-ai-widget, read llms.txt for framework-specific imports, place the widget, and follow constraints like using string or synchronous function prompts (never await inside them) and styling only via --aai-* CSS variables or .aai__* classes. ```text Add the ask-ai-widget "Ask AI" button row to this project. 1. Install it with this project's package manager: npm install ask-ai-widget (For a plain HTML site with no build step, use the CDN script instead: https://cdn.jsdelivr.net/npm/ask-ai-widget@0/dist/ask-ai.min.js) 2. Read node_modules/ask-ai-widget/llms.txt before writing any code. It lists the right import for each framework, every option, and the common mistakes. 3. Detect the framework and use its entry: React/Next.js -> ask-ai-widget/react, Vue/Nuxt -> ask-ai-widget/vue, Svelte/SvelteKit -> ask-ai-widget/svelte, anything else -> the element from ask-ai-widget/element. 4. Place the widget where I ask below (or suggest a spot, e.g. under the docs page title). Use label "Ask AI about " and keep the default page context (title + URL) unless I say otherwise. 5. Prompts must be strings or synchronous functions. Never await inside them, or browsers block the new tab. 6. With SSR (Next.js, Nuxt, SvelteKit), import "ask-ai-widget/style.css" in the root layout, and pass page={{ url, title }} so server and client links match. 7. Style it only through --aai-* CSS variables or the .aai__* classes; don't copy or edit the library CSS. 8. Show me the diff and how to see it running. Where and how I want it: ``` -------------------------------- ### HTML page with CSS theme and AskAI mount points Source: https://github.com/agilek/ask-ai-widget/blob/main/examples/html/index.html HTML document that loads the ask-ai-widget from a CDN, defines a theme using --aai-* CSS variables, and includes three sections for different widget configurations. The CSS sets the page layout and the .brand-demo class customizes the widget's appearance. ```html ask-ai-widget example (CDN)

Docs

1. Predefined prompt

2. User question

3. Zero JS (`data-ask-ai`), custom CSS

``` -------------------------------- ### Listen for ask-ai:open event and send analytics Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Adds a document-level listener for the bubbling 'ask-ai:open' CustomEvent. The event detail contains 'service', 'prompt', and 'url'. Use this to send analytics events; the example shows Plausible and Google Analytics 4 calls. ```JavaScript document.addEventListener("ask-ai:open", (e) => { const { service } = e.detail; // Plausible plausible("Ask AI", { props: { service } }); // Google Analytics 4 gtag("event", "ask_ai_open", { service }); }); ``` -------------------------------- ### HTML: Input field with placeholder Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Adds a built-in input field with a placeholder. The input attribute is read as a selector only when it starts with # or .; otherwise the built-in field is rendered. ```html ``` -------------------------------- ### Set label position with mount() in React/Vue Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Pass `labelPosition` as a prop to `mount()` for React or Vue. The label is always the first element in the DOM and the root gets `data-label-position`. ```javascript mount("#w", { label: "Ask AI about this page", labelPosition: "right" }); // React / Vue: the labelPosition prop ``` -------------------------------- ### Set label position with HTML attributes Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the `label-position` attribute on the `` element or `data-label-position` on the CDN auto-mount div. The label is always the first element in the DOM and the root gets `data-label-position`. ```html
``` -------------------------------- ### activate(root, key, options, question) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Programmatically opens a service. Returns false if no service was opened. ```APIDOC ## activate(root, key, options, question) ### Description Programmatically opens a service. Returns false if no service was opened. ### Method activate ### Parameters - **root** (Element) - Required - The root element to activate from. - **key** (string) - Required - The service key to activate. - **options** (object) - Required - Configuration options. - **question** (string) - Required - The question to send. ### Returns - **boolean** - `true` if a service was opened, `false` otherwise. ### Example ```js const opened = activate(root, 'chatgpt', options, 'Hello'); ``` ``` -------------------------------- ### Vanilla JS: mount() with services and label Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Imports mount from 'ask-ai-widget' and mounts the widget to a selector. The target element must exist before mount() runs; it returns null otherwise. ```javascript import { mount } from "ask-ai-widget"; mount("#ask-ai", { services: ["claude", "chatgpt"], label: "Ask AI about Acme" }); ``` -------------------------------- ### Import lite mount with selected services Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the lite entry to include only the logos you display. Import service objects from ask-ai-widget/services and pass them to mount. String keys do not resolve unless registerService() is called first. ```javascript import { mount } from "ask-ai-widget/lite"; import { claude, chatgpt } from "ask-ai-widget/services"; mount("#w", { services: [claude, chatgpt] }); ``` -------------------------------- ### Vanilla JS mount with options Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Imports the mount function and creates a widget on an element with services, label, prompt, and onOpen options. Returns an object with update and destroy methods; mounting the same element twice replaces the first instance. ```javascript import { mount } from "ask-ai-widget"; const widget = mount("#ask-ai", { services: ["claude", "chatgpt"], label: "Ask AI about this page", prompt: (ctx) => `Summarize ${ctx.title} in 3 bullets.`, onOpen: ({ service, prompt }) => console.log(service, prompt), }); widget.update({ variant: "outline" }); // merges options and re-renders widget.destroy(); // removes DOM, listeners, classes ``` -------------------------------- ### JavaScript mount for menu layout Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Import mount from ask-ai-widget and call it with layout: "menu" to enable the dropdown. The label and menuAlign options configure the trigger text and menu alignment. ```js import { mount } from "ask-ai-widget"; mount("#w", { layout: "menu", label: "Ask AI", menuAlign: "end" }); ``` -------------------------------- ### Configure prompt with functions for prompt and references Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use functions for prompt and references to compute values at click time. The functions run synchronously and their return values are used as-is without placeholder expansion. The context object `ctx` contains `service`, `question`, `url`, `title`, `description`, `selection`, and `vars`. ```javascript mount("#w", { prompt: (ctx) => `Compare ${ctx.title} with the alternatives.`, references: (ctx) => ["/llms.txt", ctx.url], }); ``` -------------------------------- ### buildPrompt(options, ctx) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Builds the final prompt text from options and context. ```APIDOC ## buildPrompt(options, ctx) ### Description Builds the final prompt text from options and context. ### Method buildPrompt ### Parameters - **options** (object) - Required - Configuration options. - **ctx** (PromptContext) - Required - The context object. ### Returns - **string** - The final prompt text. ### Example ```js const prompt = buildPrompt(options, ctx); ``` ``` -------------------------------- ### Instance Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md The instance object returned by mount(). ```APIDOC ## Instance ### Description The instance object returned by `mount()`. ### Properties - **element** (Element) - The mounted element. - **update(partialOptions)** (function) - Updates the instance with partial options. - **destroy()** (function) - Destroys the instance. ### Example ```js const instance = mount('#root'); instance.update({ theme: 'dark' }); instance.destroy(); ``` ``` -------------------------------- ### Lite: tree-shaken mount with imported logos Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Uses the lite build to import only the needed service logos, reducing bundle size. ```javascript import { mount } from "ask-ai-widget/lite"; import { claude, chatgpt } from "ask-ai-widget/services"; mount("#ask-ai", { services: [claude, chatgpt] }); ``` -------------------------------- ### mount(target, options?) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Renders the widget into a DOM element or selector. Returns an Instance object or null if mounting fails. ```APIDOC ## mount(target, options?) ### Description Renders the widget into a DOM element or selector. Returns an Instance object or null if mounting fails. ### Method mount ### Parameters - **target** (Element | string) - Required - The DOM element or CSS selector to mount the widget into. - **options** (object) - Optional - Configuration options for the widget. ### Returns - **Instance | null** - The mounted instance, or null if mounting failed. ### Example ```js const instance = mount('#root', { /* options */ }); ``` ``` -------------------------------- ### mount(target, options) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md The mount function creates a widget instance in vanilla JS. It accepts an element or selector and returns an object with update and destroy methods. ```APIDOC ## mount(target, options) ### Description The `mount` function creates a widget instance in vanilla JS. It accepts an element or selector and returns an object with `update` and `destroy` methods. ### Parameters - `target` (Element|string) - Required - The target element or CSS selector. - `options` (object) - Required - Configuration options (same as the web component properties). ### Returns - `{ element, update, destroy }` - The widget instance, or `null` if the target does not exist. ### Example ```js import { mount } from "ask-ai-widget"; const widget = mount("#ask-ai", { services: ["claude", "chatgpt"], label: "Ask AI about this page", prompt: (ctx) => `Summarize ${ctx.title} in 3 bullets.`, onOpen: ({ service, prompt }) => console.log(service, prompt), }); widget.update({ variant: "outline" }); // merges options and re-renders widget.destroy(); // removes DOM, listeners, classes ``` ``` -------------------------------- ### withBuiltins(options) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Normalizer that resolves string keys to built-in services. Only available in the default entry. ```APIDOC ## withBuiltins(options) ### Description Normalizer that resolves string keys to built-in services. Only available in the default entry. ### Method withBuiltins ### Parameters - **options** (object) - Required - Configuration options. ### Returns - **object** - Normalized options with built-in services resolved. ### Example ```js const normalized = withBuiltins(options); ``` ``` -------------------------------- ### Basic CDN Integration with ask-ai-widget Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Loads the widget from jsDelivr CDN and adds an 'Ask AI about this page' button. Every button opens its service with a prompt containing the page title and URL. For production, pin an exact version like ask-ai-widget@0.1.0 because @0 can receive breaking changes while the major version is 0. ```html ``` -------------------------------- ### React: AskAI component with services, label, variant, and onOpen Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Import AskAI from 'ask-ai-widget/react' and render it with services, label, variant, and onOpen. The component renders real elements on the server, forwards ref to the root
, passes DOM props through, and needs no memoisation for inline function props. ```tsx import { AskAI } from "ask-ai-widget/react"; export function Share() { return ( track(service)} /> ); } ``` -------------------------------- ### Import lite React AskAI with selected services Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the lite React entry to include only the logos you display. Import service objects from ask-ai-widget/services and pass them to the AskAI component. String keys do not resolve unless registerService() is called first. ```tsx import { AskAI } from "ask-ai-widget/lite/react"; import { claude, chatgpt } from "ask-ai-widget/services"; ``` -------------------------------- ### JS: mount() with input options for ask-ai Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Shows the `mount()` API for enabling user question input. Options include a built-in field, a textarea with placeholder and multiline, an existing field by selector or element, and a custom field with `required: false` to allow empty questions. ```js mount("#w", { input: true }); // built-in field mount("#w", { input: { placeholder: "Ask...", multiline: true } }); // textarea, required defaults to true mount("#w", { input: "#q" }); // existing field, by selector mount("#w", { input: document.querySelector("#q") }); // existing field, by element mount("#w", { input: { target: "#q", required: false } }); // existing field, empty question allowed ``` -------------------------------- ### onOpen callback Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Called right before a service opens. Receives an OpenDetail object with service, prompt, and url. ```APIDOC ## onOpen(detail) ### Description Called right before a service opens. Receives an OpenDetail object with service, prompt, and url. ### Parameters - **detail** (OpenDetail) - Required - Object containing `service`, `prompt`, and `url`. ### Example ```js onOpen: ({ service }) => { console.log(service); } ``` ``` -------------------------------- ### HTML Web Component with CDN script Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Loads the widget from jsDelivr and mounts an element with services, label, variant, and show-labels attributes. The component renders into its own light DOM so your CSS applies. ```html ``` -------------------------------- ### Register custom service and mount widget Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use registerService to add a custom service for the whole page, then mount the widget with a services list. The ServiceDef object requires key, label, url, and param; icon and color are optional. Set prefill: false for services that ignore the parameter to enable copy-to-clipboard behavior. ```javascript import { mount, registerService } from "ask-ai-widget"; registerService({ key: "kagi", label: "Kagi", url: "https://kagi.com/assistant", param: "q", icon: "M12 2 L22 22 H2 Z", // path data for a 24x24 viewBox, filled with currentColor color: "#FFB319", // used by variant="brand" }); mount("#w", { services: ["claude", "kagi"] }); mount("#w", { services: ["claude", { key: "me", label: "My AI", url: "https://ai.example.com/", param: "prompt" }] }); ``` -------------------------------- ### render(template, ctx) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Expands {placeholders} in a string using the provided context. ```APIDOC ## render(template, ctx) ### Description Expands `{placeholders}` in a string using the provided context. ### Method render ### Parameters - **template** (string) - Required - The template string with placeholders. - **ctx** (object) - Required - The context object containing values for placeholders. ### Returns - **string** - The expanded string. ### Example ```js const result = render('Hello {name}', { name: 'World' }); ``` ``` -------------------------------- ### JS: Dropdown layout with mount() Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt JavaScript equivalent for the dropdown layout using mount(). ```javascript mount("#w", { layout: "menu" }) ``` -------------------------------- ### HTML: Basic ask-ai widget with script tag Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Loads the widget from jsDelivr CDN and renders an element with services and label attributes. ```html ``` -------------------------------- ### getContext(options, question?, service?) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Builds a PromptContext from the page, optionally for a specific service. ```APIDOC ## getContext(options, question?, service?) ### Description Builds a PromptContext from the page, optionally for a specific service. ### Method getContext ### Parameters - **options** (object) - Required - Configuration options. - **question** (string) - Optional - The question to include. - **service** (ServiceDef) - Optional - The service definition. ### Returns - **PromptContext** - The context object. ### Example ```js const ctx = getContext(options, 'Hello', chatgpt); ``` ``` -------------------------------- ### Vue: AskAI component with services, label, input, v-model:question, and @open Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Import AskAI from 'ask-ai-widget/vue' and use it in a Vue SFC. The component renders real anchors during SSR, emits 'open' before a service opens and 'update:question' for the built-in input, and lets class, style, and id fall through. Use show-labels or :show-labels="true" for showLabels. ```vue ``` -------------------------------- ### version Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Package version string. ```APIDOC ## version ### Description Package version string. ### Type - **string** - Version number. ### Example ```js console.log(version); ``` ``` -------------------------------- ### askAI (Svelte action) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Svelte action to use with use:askAI={options}. ```APIDOC ## askAI (Svelte action) ### Description Svelte action to use with `use:askAI={options}`. ### Usage ```svelte
``` ``` -------------------------------- ### Svelte action for menu layout Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the askAI action with layout: "menu" and menuAlign: "end" to enable the dropdown menu in Svelte. ```svelte
``` -------------------------------- ### AskAI (Vue) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Vue component with props equal to options plus question, emits 'open' and 'update:question'. ```APIDOC ## AskAI (Vue) ### Description Vue component with props equal to options plus `question`, emits `open` and `update:question`. ### Props - **question** (string) - Optional - The question value. ### Events - **open** - Emitted when the widget opens. - **update:question** - Emitted when the question changes. ### Usage ```vue ``` ``` -------------------------------- ### getInput(options, root?) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Returns the question input element. ```APIDOC ## getInput(options, root?) ### Description Returns the question input element. ### Method getInput ### Parameters - **options** (object) - Required - Configuration options. - **root** (Element) - Optional - The root element to search within. ### Returns - **HTMLInputElement | null** - The input element, or null if not found. ### Example ```js const input = getInput(options, root); ``` ``` -------------------------------- ### buildUrl({ url, param }, prompt) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Builds a URL with the encoded prompt appended as a query parameter. ```APIDOC ## buildUrl({ url, param }, prompt) ### Description Builds a URL with the encoded prompt appended as a query parameter. ### Method buildUrl ### Parameters - **url** (string) - Required - The base URL. - **param** (string) - Required - The query parameter name. - **prompt** (string) - Required - The prompt text to encode. ### Returns - **string** - The full URL with the encoded prompt. ### Example ```js const url = buildUrl({ url: 'https://example.com', param: 'q' }, 'Hello'); ``` ``` -------------------------------- ### Svelte: use:askAI action with services and label Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Import askAI from 'ask-ai-widget/svelte' and use it as an action on a div. Works in Svelte 3, 4, and 5. Updating the options object re-renders; keys you remove fall back to defaults. The action runs in the browser, so the server sends an empty
. ```svelte
``` -------------------------------- ### Set JS properties on ask-ai element Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Shows how to set function properties like prompt and onOpen on an element. Properties are batched into one render and take precedence over attributes. ```javascript const el = document.querySelector("ask-ai"); el.prompt = (ctx) => `Explain ${ctx.title} to a beginner`; el.onOpen = ({ service }) => console.log(service); ``` -------------------------------- ### ask-ai:open DOM event Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Dispatched as a bubbling CustomEvent from the root when a service opens. The detail contains service, prompt, and url. ```APIDOC ## ask-ai:open CustomEvent ### Description Dispatched as a bubbling CustomEvent from the root when a service opens. The detail contains service, prompt, and url. ### Event Detail - **service** (string) - The service key. - **prompt** (string) - The prompt text. - **url** (string) - The current page URL. ### Example ```js document.addEventListener("ask-ai:open", (e) => { const { service } = e.detail; }); ``` ``` -------------------------------- ### PromptContext Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Context object passed to prompt, instructions, context, and references functions. ```APIDOC ## PromptContext ### Description Context object passed to prompt, instructions, context, and references functions. ### Properties - **service** (string) - The service key. - **question** (string) - The user's question. - **url** (string) - The current page URL. - **title** (string) - The page title. - **description** (string) - The page description. - **selection** (string) - The selected text. - **vars** (Record) - Extra variables. ### Example ```js const ctx = { service: 'chatgpt', question: 'What is this?', url: 'https://example.com', title: 'Example', description: 'A page', selection: 'text', vars: {} }; ``` ``` -------------------------------- ### builtinInput(options) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Returns built-in field options for renderers. ```APIDOC ## builtinInput(options) ### Description Returns built-in field options for renderers. ### Method builtinInput ### Parameters - **options** (object) - Required - Configuration options. ### Returns - **object** - Built-in field options. ### Example ```js const inputOptions = builtinInput(options); ``` ``` -------------------------------- ### Svelte: use:askAI action Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Svelte action usage with the askAI directive, passing services and label as an object. ```svelte
``` -------------------------------- ### plugin (Vue) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Vue plugin that registers AskAI globally when used with app.use(). ```APIDOC ## plugin (Vue) ### Description Vue plugin that registers `AskAI` globally when used with `app.use()`. ### Usage ```js import { plugin } from 'ask-ai-widget/vue'; app.use(plugin); ``` ``` -------------------------------- ### AskAI (React) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md React component that accepts all options as props, plus question, defaultQuestion, onQuestionChange, and any div attribute. ```APIDOC ## AskAI (React) ### Description React component that accepts all options as props, plus `question`, `defaultQuestion`, `onQuestionChange`, and any `div` attribute. ### Props - **question** (string) - Optional - The question value. - **defaultQuestion** (string) - Optional - Default question value. - **onQuestionChange** (function) - Optional - Callback when question changes. - **...div attributes** - Any standard div attributes. ### Usage ```jsx import { AskAI } from 'ask-ai-widget/react'; ``` ``` -------------------------------- ### css Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md The stylesheet text for the widget. ```APIDOC ## css ### Description The stylesheet text for the widget. ### Type - **string** - CSS text. ### Example ```js console.log(css); ``` ``` -------------------------------- ### getItems(options, question?) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Pure and SSR-safe function that returns an array of items with precomputed hrefs. Useful for server-side rendering or generating links without mounting. ```APIDOC ## getItems(options, question?) ### Description Pure and SSR-safe function that returns an array of items with precomputed hrefs. Useful for server-side rendering or generating links without mounting. ### Method getItems ### Parameters - **options** (object) - Required - Configuration options. - **question** (string) - Optional - The question to prefill in the generated links. ### Returns - **Item[]** - Array of items, each with `key`, `label`, `href`, `icon`, `color`, and `prefill` properties. ### Example ```js const items = getItems(options, 'How do I reset my password?'); ``` ``` -------------------------------- ### Vue component for menu layout Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the AskAI component with layout="menu" and menu-align="end" to render the dropdown menu in Vue. ```vue ``` -------------------------------- ### OpenDetail Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Object passed to onOpen and included in the ask-ai:open event detail. ```APIDOC ## OpenDetail ### Description Object passed to onOpen and included in the ask-ai:open event detail. ### Properties - **service** (string) - The service key. - **prompt** (string) - The prompt text. - **url** (string) - The current page URL. ### Example ```js const detail = { service: 'chatgpt', prompt: 'Summarize this page', url: 'https://example.com' }; ``` ``` -------------------------------- ### rootAttrs(options) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Returns root class and data attributes for renderers. ```APIDOC ## rootAttrs(options) ### Description Returns root class and data attributes for renderers. ### Method rootAttrs ### Parameters - **options** (object) - Required - Configuration options. ### Returns - **object** - Root attributes object. ### Example ```js const attrs = rootAttrs(options); ``` ``` -------------------------------- ### React: Dropdown layout Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt React equivalent for the dropdown layout. ```tsx ``` -------------------------------- ### Svelte: Dropdown layout Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Svelte equivalent for the dropdown layout. ```svelte use:askAI={{ layout: "menu" }} ``` -------------------------------- ### Styling recipes for brand, pill buttons, icons, layout, and responsive Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md A collection of CSS recipes to customize the widget: match your brand site-wide, create pill buttons with labels, enlarge icons, use a vertical layout, and tighten spacing on small screens. Each recipe is a separate CSS rule or media query. ```css /* Match your brand, site-wide */ :root { --aai-bg: #0a2540; --aai-bg-hover: #143a63; --aai-fg: #fff; --aai-focus: #ffb703; } ``` ```css /* Pill buttons with labels: */ ask-ai { --aai-radius: 999px; --aai-gap: 6px; } ``` ```css /* Bigger icons */ ask-ai { --aai-btn-size: 56px; --aai-icon-size: 28px; } ``` ```css /* Vertical layout */ ask-ai, ask-ai .aai__list { flex-direction: column; align-items: flex-start; } ``` ```css /* Tighter on small screens */ @media (max-width: 480px) { ask-ai { --aai-btn-size: 32px; --aai-gap: 6px; } } ``` -------------------------------- ### AskAIOptions Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Configuration options for the AskAI widget. All entries share these types. ```APIDOC ## AskAIOptions ### Description Configuration options for the AskAI widget. All entries share these types. ### Properties - **services** (Array) - Optional - Keys and/or inline service definitions, in display order. Default: all built-ins. - **prompt** (string | (ctx) => string) - Optional - The ask. Default: see Prompt composition. - **instructions** (string | (ctx) => string) - Optional - Placed before the prompt. Default: none. - **context** (string | (ctx) => string | false) - Optional - Placed after the prompt. Default: `Context: {title} — {url}`. - **references** (string[] | (ctx) => string[]) - Optional - Source URLs; relative ones resolve against the page. Default: none. - **template** (string) - Optional - How parts are joined. Default: `{instructions}\n\n{prompt}\n\n{context}\n\n{references}`. - **page** ({ url?, title?, description? }) - Optional - Overrides detected values; use for SSR. Default: live document. - **vars** (Record) - Optional - Extra `{placeholders}`. Default: `{}`. - **label** (string) - Optional - Text next to the buttons. In the menu layout: the trigger text. Default: none. - **labelPosition** ("left" | "top" | "right" | "bottom" | "none") - Optional - Where the visible label goes. Default: "left". - **variant** ("soft" | "outline" | "solid" | "ghost" | "brand" | string) - Optional - Visual preset. Default: "soft". - **shape** ("circle" | "rounded" | "square") - Optional - Button shape. Default: "circle". - **size** ("sm" | "md" | "lg") - Optional - Button size. Default: "md". - **theme** ("light" | "dark" | "auto") - Optional - Color scheme. Default: "light". - **layout** ("row" | "menu") - Optional - "menu" renders one trigger button that opens a dropdown of all services. Default: "row". - **menuAlign** ("start" | "end") - Optional - Menu layout: which edge of the trigger the dropdown lines up with. Default: "start". - **menuIcons** ("stack" | "none") - Optional - Menu layout: logo stack in the trigger, or label only. Default: "stack". - **showLabels** (boolean) - Optional - Service name next to each logo. Default: false. - **unstyled** (boolean) - Optional - Skip the default CSS. Default: false. - **maxLength** (number) - Optional - Max prompt characters. Default: 4000. - **input** (boolean | InputOptions | string | HTMLInputElement | HTMLTextAreaElement) - Optional - Question field: built-in, or an existing one. Default: off. - **strings** ({ ask?, question?, copied?, menu? }) - Optional - Translations of the widget's own texts. Default: English. - **submitService** (string) - Optional - Opened by Enter in the input. Default: first service. - **className** (string) - Optional - Extra classes on the root. Default: none. - **onOpen** ((detail: OpenDetail) => void) - Optional - Called right before a service opens. ### Example ```js const options = { services: ['chatgpt', 'claude'], prompt: 'Summarize this page', onOpen: ({ service }) => console.log(service) }; ``` ``` -------------------------------- ### CDN global AskAI Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Global object with everything from ask-ai-widget plus AskAIElement, defineAskAI, parseAttrs, and init(). ```APIDOC ## CDN global AskAI ### Description Global object with everything from `ask-ai-widget` plus `AskAIElement`, `defineAskAI`, `parseAttrs`, and `init()`. ### Methods - **init(root = document)** - Mounts every `[data-ask-ai]` element once. ### Usage ```js AskAI.init(); ``` ``` -------------------------------- ### Astro: Custom element with services and label Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the custom element in Astro. Import the element script to register it. Booleans are attributes (show-labels), objects are JSON attributes or element properties. ```astro ``` -------------------------------- ### React component for menu layout Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use the AskAI component from ask-ai-widget/react with layout="menu" and menuAlign="end" to render the dropdown menu in React. ```tsx import { AskAI } from "ask-ai-widget/react"; ``` -------------------------------- ### registerService(def) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Adds or overrides a service definition in the registry. ```APIDOC ## registerService(def) ### Description Adds or overrides a service definition in the registry. ### Method registerService ### Parameters - **def** (ServiceDef) - Required - The service definition to register. ### Returns - **void** ### Example ```js registerService({ key: 'myService', label: 'My Service', ... }); ``` ``` -------------------------------- ### Markup structure for all renderers Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md The widget's markup is identical in every renderer. It includes the root with data attributes, label, optional form, list of buttons, and a polite live region for hints. ```html
``` -------------------------------- ### Visitor Question Input with ask-ai-widget Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Adds an input field so visitors can ask their own question instead of using a predefined prompt. The services attribute specifies which AI services are available (claude, chatgpt, perplexity). ```html ``` -------------------------------- ### React: component Source: https://github.com/agilek/ask-ai-widget/blob/main/llms.txt Renders the widget as a React component with services and label props. ```tsx import { AskAI } from "ask-ai-widget/react"; ``` -------------------------------- ### HTML usage for menu layout Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Use layout="menu" to replace the logo row with an Ask AI button that opens a dropdown menu. The menu-align and menu-icons attributes control alignment and icon display. The data-ask-ai div enables CDN auto-mount. ```html ``` ```html ``` ```html
``` -------------------------------- ### InputOptions Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Configuration for the input field, either built-in or bound to an existing element. ```APIDOC ## InputOptions ### Description Configuration for the input field, either built-in or bound to an existing element. ### Properties - **target** (string | HTMLInputElement | HTMLTextAreaElement) - Optional - Selector or element to bind an existing field. - **placeholder** (string) - Optional - Placeholder text for the built-in field. - **required** (boolean) - Optional - Whether the field is required. - **multiline** (boolean) - Optional - Whether the built-in field is multiline. ### Example ```js const inputOptions = { target: '#my-input', required: true }; ``` ``` -------------------------------- ### resolveServices(list?) Source: https://github.com/agilek/ask-ai-widget/blob/main/README.md Resolves a list of service keys and/or definitions into an array of ServiceDef objects. ```APIDOC ## resolveServices(list?) ### Description Resolves a list of service keys and/or definitions into an array of ServiceDef objects. ### Method resolveServices ### Parameters - **list** (Array) - Optional - List of service keys or definitions. If omitted, uses the default registry. ### Returns - **ServiceDef[]** - Array of resolved service definitions. ### Example ```js const services = resolveServices(['chatgpt', customService]); ``` ```