Skip to content

Conversation

@dylantientcheu
Copy link
Collaborator

@dylantientcheu dylantientcheu commented Nov 12, 2025

Add Sidepanel Ask AI Experience

Adds a sidepanel chat experience for Algolia Ask AI that opens from the right without blocking the page.

Features

  • sidepanel: Opens from the right; page remains interactive
  • shortcuts: Cmd+I (Mac) / Ctrl+I (Windows) to toggle
  • auto-resizing input: Textarea grows with content (max 20 rows)
  • smooth animations: 280ms transitions with custom easing
  • Mobile responsive: Full-width on mobile, fixed width on desktop
  • a11y: Keyboard navigation, focus management, ARIA labels

Implementation

  • new component: sidepanel-askai/components/sidepanel-ai.tsx
  • reuses useAskai hook from search-askai experience
  • added to registry with dependencies and CSS animations
  • documentation with usage examples and API reference
  • preview component for docs site

Use Cases

  • documentation site AI assistant
  • help center chat support
  • non-intrusive AI chat interface

@netlify
Copy link

netlify bot commented Nov 12, 2025

Deploy Preview for sitesearch-docs ready!

Name Link
🔨 Latest commit 2ef63a7
🔍 Latest deploy log https://app.netlify.com/projects/sitesearch-docs/deploys/6916ef9d80d44f00089d2f86
😎 Deploy Preview https://deploy-preview-3--sitesearch-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dylantientcheu dylantientcheu self-assigned this Nov 12, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +136
const BASE_ASKAI_URL = "https://askai.algolia.com";
const TOKEN_KEY = "askai_token";

type TokenPayload = { exp: number };

const decode = (token: string): TokenPayload => {
const [b64] = token.split(".");
return JSON.parse(atob(b64));
};

const isExpired = (token?: string | null): boolean => {
if (!token) return true;
try {
const { exp } = decode(token);
// refresh 30 s before the backend rejects it
return Date.now() / 1000 > exp - 30;
} catch {
return true;
}
};

let inflight: Promise<string> | null = null;

// call /token once, cache the promise while it’s running
// eslint-disable-next-line require-await
export const getValidToken = async ({
assistantId,
}: {
assistantId: string;
}): Promise<string> => {
const cached = sessionStorage.getItem(TOKEN_KEY);
if (!isExpired(cached)) return cached as string;

if (!inflight) {
inflight = fetch(`${BASE_ASKAI_URL}/chat/token`, {
method: "POST",
headers: {
"x-algolia-assistant-id": assistantId,
"content-type": "application/json",
},
})
.then((r) => r.json())
.then(({ token }) => {
sessionStorage.setItem(TOKEN_KEY, token);
return token;
})
.finally(() => {
inflight = null;
});
}

return inflight;
};

export const postFeedback = async ({
assistantId,
thumbs,
messageId,
appId,
}: {
assistantId: string;
thumbs: 0 | 1;
messageId: string;
appId: string;
}): Promise<Response> => {
const headers = new Headers();
headers.set("x-algolia-assistant-id", assistantId);
headers.set("content-type", "application/json");

const token = await getValidToken({ assistantId });
headers.set("authorization", `TOKEN ${token}`);

return fetch(`${BASE_ASKAI_URL}/chat/feedback`, {
method: "POST",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Respect custom Ask AI base URL for token & feedback requests

The hook accepts baseAskaiUrl and uses it to construct the chat transport, but the helper utilities still hit the hard‑coded https://askai.algolia.com for /chat/token and /chat/feedback. If a consumer points baseAskaiUrl at a staging or self‑hosted Ask AI backend, chat requests go to the custom base while token and feedback requests are sent to production and will fail with 401s. These helpers should derive their URLs from the same baseAskaiUrl value (or expose a way to override them) to keep all calls pointed at the same environment.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants