{"_id":"@aicontextgateway/search-react","name":"@aicontextgateway/search-react","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@aicontextgateway/search-react","version":"0.0.1","description":"Embeddable AiContextGateway smart search bar: deterministic (no-AI) fuzzy/facet search as a React component and a self-contained <aicontextgateway-search> web component, with an optional AI answer layer.","license":"MIT","type":"module","main":"./dist/search-react.umd.cjs","module":"./dist/search-react.js","exports":{".":{"import":"./dist/search-react.js","require":"./dist/search-react.umd.cjs"},"./styles.css":"./dist/search-react.css","./core":"./src/searchCore.js","./element":"./dist/aicontextgateway-search.iife.js","./loader":"./loader/loader.js"},"scripts":{"build":"vite build -c vite.config.react.js && vite build -c vite.config.element.js","test":"node src/searchCore.test.mjs"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0","react-dom":"^18.0.0 || ^19.0.0"},"gitHead":"b952debd06715746a86549fa2eeffaa096f85bea","_id":"@aicontextgateway/search-react@0.0.1","_nodeVersion":"22.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-i4hZQdvipggbXHr240xtta5N5630pac8tUys5HiITyOZFjg0CFQ5/2/R/i9TcUf71al2xKVX//ud1vW2nPrrhg==","shasum":"2c433d46aac705e6d080fa15ba2907a5a52d0512","tarball":"https://registry.npmjs.org/@aicontextgateway/search-react/-/search-react-0.0.1.tgz","fileCount":8,"unpackedSize":253971,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHlHn9gozv9+CwzClZIozl0BEClC9P1h3ZU7Uv6xR/KbAiBti7/KABtoIsdPm3KDT2nZiK4gDFr1OPegY9Dkx45PZg=="}]},"_npmUser":{"name":"mertcanmerkit","email":"mertcanmerkit@gmail.com"},"directories":{},"maintainers":[{"name":"mertcanmerkit","email":"mertcanmerkit@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/search-react_0.0.1_1784535146797_0.8971803885746075"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-20T08:12:26.655Z","0.0.1":"2026-07-20T08:12:26.952Z","modified":"2026-07-20T08:12:27.213Z"},"maintainers":[{"name":"mertcanmerkit","email":"mertcanmerkit@gmail.com"}],"description":"Embeddable AiContextGateway smart search bar: deterministic (no-AI) fuzzy/facet search as a React component and a self-contained <aicontextgateway-search> web component, with an optional AI answer layer.","license":"MIT","readme":"# @aicontextgateway/search-react\n\nEmbeddable **smart search bar** for vendor/admin menus, catalogs, and any list —\n**deterministic by default, no AI required**. Ships two ways:\n\n1. **React component** (npm) — `react`/`react-dom` are peer dependencies.\n2. **`<script>` web component** — one self-contained IIFE, React bundled, styles isolated in a Shadow DOM.\n\nThe deterministic core (ranking, typo tolerance, synonyms, facets, highlighting) runs entirely\nclient-side over data you provide. The **AI layer is optional and off by default**; enable it to stream\na grounded answer from the AiContextGateway chat API.\n\n## What \"smart\" means here (all deterministic, zero AI)\n\n- Prefix + **fuzzy** matching — Damerau-Levenshtein, so transpositions like `shose → shoes` cost one edit.\n- **Synonyms** — `{ shoes: ['sneaker', 'trainer'] }` expands queries bidirectionally.\n- **Field weighting** — rank title hits above tag/brand hits.\n- **Facets** — counts over the matched set + one-click filtering.\n- **Highlighting**, keyboard navigation, and stable, deterministic ordering.\n\n## React component\n\n```bash\nnpm install @aicontextgateway/search-react react react-dom\n```\n\n```jsx\nimport { AiContextGatewaySearch } from '@aicontextgateway/search-react';\nimport '@aicontextgateway/search-react/styles.css';\n\n<AiContextGatewaySearch\n    items={products}                       // or fetchUrl=\"/api/catalog.json\"\n    fields={['title', 'brand', 'tags']}\n    fieldWeights={{ title: 3, tags: 2 }}\n    synonyms={{ shoes: ['sneaker', 'trainer'] }}\n    facets={['category', 'brand']}\n    placeholder=\"Search products…\"\n    onSelect={(item) => navigate(item.url)}\n/>\n```\n\nProps: `items` **or** `fetchUrl` (JSON array), `fields`, `fieldWeights`, `synonyms`, `facets`\n(facet keys), `fuzzy` (bool | max-edits), `limit`, `placeholder`, `titleField`, `subtitleField`,\n`onSelect`. Optional AI: `aiMode`, `token`, `baseUrl`.\n\n### Framework-free core\n\nThe ranking engine has no React/DOM dependency and is exported on its own:\n\n```js\nimport { search } from '@aicontextgateway/search-react/core';\nconst { results, facets } = search(products, 'runing shoes', { fields: ['title'], facets: ['brand'] });\n```\n\n## `<script>` web component\n\n```html\n<script src=\"https://YOUR-CDN/loader.js\"\n        data-fetch-url=\"/api/catalog.json\"\n        data-placeholder=\"Search…\"\n        data-facets=\"category,brand\" defer></script>\n```\n\nOr register the element and place it yourself:\n\n```html\n<script src=\"https://YOUR-CDN/aicontextgateway-search.iife.js\" defer></script>\n<aicontextgateway-search fetch-url=\"/api/catalog.json\" facets=\"category,brand\"></aicontextgateway-search>\n```\n\nStyles live inside the element's Shadow DOM, so host-page CSS cannot restyle the widget and widget CSS\nnever leaks out. Retheme via `--pa-search-*` custom properties set on the element or any ancestor.\n\n## Optional AI layer\n\nSet `aiMode` + `token` + `baseUrl` (React) or `ai-mode` + `token` + `base-url` (element) to show an\n\"Ask AI\" affordance that streams a grounded answer from `POST {baseUrl}/api/chat/{token}` (the token\nmust have the `chat:read` ability, and the gateway must have a model configured — BYO key on self-host\nor a paid Cloud plan). With AI off, the widget makes **no network calls** beyond an optional `fetchUrl`.\n\n## Build\n\nnpm workspaces monorepo. Build from the repository root:\n\n```bash\nnpm run build --workspace=@aicontextgateway/search-react\n```\n\nOutputs to `dist/`: `search-react.js` (ES), `search-react.umd.cjs` (UMD), `search-react.css`, and\n`aicontextgateway-search.iife.js` (self-contained element). The optional AI path reuses the app's SSE\nclient (`resources/js/lib/sseChat.js`), which is why the full build runs from the monorepo root; the\ndeterministic core (`src/searchCore.js`) is standalone and unit-tested with `npm test`.\n\n## Boundaries\n\n- Deterministic search bundles **no model** and makes **no network calls** (unless you pass `fetchUrl`).\n- The optional AI answer is grounded in the token's approved, audience-scoped context; it holds no keys.\n- No customer product APIs are called (no order/inventory/account actions).\n","readmeFilename":"README.md","_rev":"1-55d1e52e0ab17e514f25d32726e8b89c"}