commit 11917c70c4370d56054b879ed80f0a90e8884c33 Author: braginini Date: Fri Mar 13 17:40:57 2026 +0100 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53400d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +*.tsbuildinfo +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6790892 --- /dev/null +++ b/README.md @@ -0,0 +1,402 @@ +# netbird-explain + +AI-powered "Explain" assistant for React apps. Users click on UI elements and get contextual AI explanations via a chat panel. + +The package has two entry points: + +- `netbird-explain/client` — React components (provider, chat panel, floating button) +- `netbird-explain/server` — Node.js handler that proxies requests to Anthropic or OpenAI + +No CSS framework required — the package is fully self-contained with inline styles and CSS custom properties. + +## Installation + +```bash +npm install netbird-explain +``` + +Peer dependencies: `react >=18`, `react-dom >=18`. + +For local development as a workspace package, add it to your `package.json`: + +```json +{ + "dependencies": { + "netbird-explain": "file:./packages/netbird-explain" + } +} +``` + +If you're using Next.js, add to `next.config.js`: + +```js +module.exports = { + transpilePackages: ["netbird-explain"], +}; +``` + +--- + +## Client + +### Setup + +Wrap your app with `AIAssistantProvider`: + +```tsx +import { AIAssistantProvider } from "netbird-explain/client"; + +export default function App({ children }) { + return ( + + {children} + + ); +} +``` + +This renders the floating action button and chat panel automatically. No CSS imports are needed — the provider injects all required styles via CSS custom properties. + +### Props + +| Prop | Type | Required | Description | +| ---------- | ----------- | -------- | ----------------------------------- | +| `endpoint` | `string` | Yes | URL of the AI chat API | +| `apiKey` | `string` | No | Bearer token sent with each request | +| `children` | `ReactNode` | Yes | Your application | + +### Marking elements as explainable + +Add the `data-nb-explain` attribute to any element you want users to be able to click on in explain mode: + +```tsx +
+ + +
+``` + +When clicked, the library extracts a label from the element (first `