-
Notifications
You must be signed in to change notification settings - Fork 125
feat: enable Kapa AI chat widget #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
df72ce7
60ab786
26a21d2
b47fc5f
316e767
88354ee
70bd599
8d1120c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,44 +315,27 @@ const plugins = [ | |
]; | ||
|
||
const scripts = [ | ||
// { | ||
// src: 'https://widget.kapa.ai/kapa-widget.bundle.js', | ||
// 'data-website-id': 'a9937f98-9c9d-44d9-a433-fec4cb1c114d', | ||
// 'data-project-name': 'Apify', | ||
// 'data-modal-title': 'Apify AI Assistant', | ||
// 'data-project-color': '#666666', | ||
// 'data-button-hide': 'true', | ||
// 'data-search-mode-enabled': 'true', | ||
// 'data-search-include-source-names': '["Docs"]', | ||
// 'data-project-logo': 'https://apify.com/img/apify-logo/logomark-32x32.svg', | ||
// 'data-modal-example-questions': 'How to run an Actor?,Create a version of an Actor?', | ||
// 'data-modal-override-open-id': 'ask-ai-input', | ||
// 'data-modal-override-open-class': 'search-input', | ||
// 'data-font-size-xs': '1.2rem', | ||
// 'data-font-size-sm': '1.4rem', | ||
// 'data-font-size-md': '1.6rem', | ||
// 'data-font-size-lg': '1.8rem', | ||
// 'data-font-size-xl': '2.0rem', | ||
// async: true, | ||
// }, | ||
// { | ||
// src: 'https://cdn.jsdelivr.net/npm/@inkeep/[email protected]/dist/embed.js', | ||
// type: 'module', | ||
// async: true, | ||
// }, | ||
{ | ||
src: 'https://widget.kapa.ai/kapa-widget.bundle.js', | ||
'data-website-id': 'a9937f98-9c9d-44d9-a433-fec4cb1c114d', | ||
'data-project-name': 'Apify', | ||
'data-modal-title': 'Apify AI Assistant', | ||
'data-project-color': '#666666', | ||
'data-button-hide': 'true', | ||
'data-project-logo': 'https://apify.com/img/apify-logo/logomark-32x32.svg', | ||
'data-modal-example-questions': 'How to run an Actor?,Create a version of an Actor?', | ||
'data-modal-override-open-id': 'ask-ai-input', | ||
'data-modal-override-open-class': 'search-input', | ||
'data-scale-factor': '1.6', | ||
'data-modal-size': '800px', | ||
async: true, | ||
}, | ||
]; | ||
|
||
const customFields = { | ||
// inkeepApiKey: process.env.LOCALHOST || process.env.DEV | ||
// ? 'bbbb9f1001a9b66f282431a80bb743a24e2bdefb85d4f1e4' // development, works with localhost | ||
// : '8af30e40009f26622237f75aab8256064c26a3063717c48a', // production, only works on apify.com (any subdomain) | ||
}; | ||
|
||
module.exports = { | ||
themeConfig, | ||
plugins, | ||
absoluteUrl, | ||
noIndex, | ||
scripts, | ||
customFields, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,9 @@ import BrowserOnly from '@docusaurus/BrowserOnly'; | |
import RouterLink from '@docusaurus/Link'; | ||
import { useHistory, useLocation } from '@docusaurus/router'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
// import clsx from 'clsx'; | ||
// import React, { useEffect, useState } from 'react'; | ||
import React, { useCallback } from 'react'; | ||
// import { useHotkeys } from 'react-hotkeys-hook'; | ||
import { useState, useCallback } from 'react'; | ||
|
||
import { ApifySearch } from '@apify/docs-search-modal'; | ||
// import { ControlKeyIcon, SearchIcon } from '@apify/docs-search-modal/dist/utils/icons'; | ||
|
||
// needs to be imported as the last thing, so that it can override the default styles | ||
// TODO: update simple-import-sort to allow importing css as last. | ||
|
@@ -67,7 +63,9 @@ export default function SearchBar({ onClick }) { | |
return ( | ||
<BrowserOnly> | ||
{() => ( | ||
<div onClick={onClick}> | ||
<div className="SearchButton-Container"> | ||
|
||
<div onClick={onClick} className="AlgoliaContainer" style={{ marginRight: '12px' }}> | ||
<ApifySearch | ||
algoliaAppId={siteConfig.themeConfig.algolia.appId} | ||
algoliaIndexName='apify_sdk_v2' | ||
|
@@ -76,169 +74,42 @@ export default function SearchBar({ onClick }) { | |
navigate={navigate} | ||
/> | ||
</div> | ||
<KapaAIButton /> | ||
</div> | ||
)} | ||
</BrowserOnly> | ||
); | ||
} | ||
|
||
// export default function SearchBar({ onClick }) { | ||
// const [variant, setVariant] = useState(null); | ||
// const [opened, setOpened] = useState(false); | ||
// const { siteConfig } = useDocusaurusContext(); | ||
// const { inkeepApiKey } = siteConfig.customFields; | ||
// | ||
// useEffect(() => { | ||
// const storedVariant = localStorage.getItem('search-provider'); | ||
// | ||
// if (storedVariant) { | ||
// setVariant(storedVariant); | ||
// } else { | ||
// const assignedVariant = Math.random() < 0.5 ? 'inkeep' : 'kapa'; | ||
// localStorage.setItem('search-provider', assignedVariant); | ||
// setVariant(assignedVariant); | ||
// } | ||
// }, []); | ||
// | ||
// onClick = () => { | ||
// if (opened) { | ||
// return; | ||
// } | ||
// | ||
// setOpened(true); | ||
// | ||
// if (variant === 'kapa') { | ||
// if (window.Kapa && typeof window.Kapa.open === 'function') { | ||
// window.Kapa.open(); | ||
// window.Kapa('onModalClose', () => { | ||
// setOpened(false); | ||
// }); | ||
// } else { | ||
// console.error('Kapa.ai widget is not available.'); | ||
// } | ||
// return; | ||
// } | ||
// | ||
// if (variant !== 'inkeep') { | ||
// console.warn('Unknown search variant:', variant); | ||
// return; | ||
// } | ||
// | ||
// if (window.Inkeep) { | ||
// const config = { | ||
// baseSettings: { | ||
// apiKey: inkeepApiKey, | ||
// organizationDisplayName: 'Apify', | ||
// primaryBrandColor: '#FF9013', | ||
// transformSource: (source) => { | ||
// function getTabForSource(src) { | ||
// if (src.url.includes('help.apify.com')) { | ||
// return 'Help'; | ||
// } | ||
// return 'Docs'; | ||
// } | ||
// | ||
// if (source.contentType === 'documentation') { | ||
// return { | ||
// ...source, | ||
// tabs: [...(source.tabs || []), getTabForSource(source)], | ||
// }; | ||
// } | ||
// return source; | ||
// }, | ||
// trigger: { | ||
// disableDefaultTrigger: true, | ||
// }, | ||
// theme: { | ||
// styles: [ | ||
// { | ||
// key: 'main', | ||
// type: 'link', | ||
// value: '/inkeep-overrides.css', | ||
// }, | ||
// ], | ||
// }, | ||
// }, | ||
// modalSettings: { | ||
// onOpenChange: handleOpenChange, | ||
// }, | ||
// searchSettings: { | ||
// tabs: [ | ||
// ['Docs', { isAlwaysVisible: true }], | ||
// 'GitHub', | ||
// 'All', | ||
// ], | ||
// }, | ||
// aiChatSettings: { | ||
// aiAssistantAvatar: 'https://intercom.help/apify/assets/favicon', | ||
// chatSubjectName: 'Apify', | ||
// exampleQuestions: [ | ||
// 'What is an Actor?', | ||
// 'How to use my own proxies?', | ||
// 'How to integrate Apify Actors with GitHub?', | ||
// 'How to share key-value stores between runs?', | ||
// ], | ||
// getHelpOptions: [ | ||
// { | ||
// action: { | ||
// type: 'open_link', | ||
// url: 'https://apify.com/contact', | ||
// }, | ||
// icon: { | ||
// builtIn: 'IoChatbubblesOutline', | ||
// }, | ||
// name: 'Contact Us', | ||
// }, | ||
// ], | ||
// }, | ||
// defaultView: 'chat', | ||
// }; | ||
// const modal = window.Inkeep.ModalSearchAndChat(config); | ||
// | ||
// function handleOpenChange(newOpen) { | ||
// modal.update({ modalSettings: { isOpen: newOpen } }); | ||
// setOpened(newOpen); | ||
// } | ||
// | ||
// modal.update({ modalSettings: { isOpen: true } }); | ||
// } else { | ||
// console.error('Inkeep widget is not available.'); | ||
// } | ||
// }; | ||
// | ||
// const [key, setKey] = useState(null); | ||
// | ||
// useEffect(() => { | ||
// if (typeof navigator !== 'undefined') { | ||
// const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); | ||
// setKey(isMac ? '⌘' : 'ctrl'); | ||
// } | ||
// }, []); | ||
// | ||
// useHotkeys('mod+k, /', () => { | ||
// onClick(); | ||
// }, { preventDefault: true }); | ||
// | ||
// return ( | ||
// <BrowserOnly> | ||
// {() => ( | ||
// <div onClick={onClick}> | ||
// <button type="button" className="DocSearch DocSearch-Button" aria-label="Search"> | ||
// <span className="DocSearch-Button-Container"> | ||
// <SearchIcon/> | ||
// <span className="DocSearch-Button-Placeholder">Search</span> | ||
// </span> | ||
// <span className="DocSearch-Button-Keys"> | ||
// {key !== null && (<> | ||
// <kbd className={clsx(key === 'ctrl' ? 'ctrl' : 'cmd', 'DocSearch-Button-Key')}> | ||
// {key === 'ctrl' ? <ControlKeyIcon/> : key} | ||
// </kbd> | ||
// <kbd className="DocSearch-Button-Key">K</kbd> | ||
// </>)} | ||
// </span> | ||
// | ||
// </button> | ||
// </div> | ||
// )} | ||
// </BrowserOnly> | ||
// ); | ||
// } | ||
function KapaAIButton({ onClick }) { | ||
barjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [opened, setOpened] = useState(false); | ||
|
||
onClick = () => { | ||
barjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (opened) { | ||
return; | ||
} | ||
|
||
setOpened(true); | ||
|
||
if (window.Kapa && typeof window.Kapa.open === 'function') { | ||
window.Kapa.open(); | ||
window.Kapa('onModalClose', () => { | ||
setOpened(false); | ||
}); | ||
} else { | ||
console.error('Kapa.ai widget is not available.'); | ||
} | ||
}; | ||
barjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<BrowserOnly> | ||
{() => ( | ||
<div onClick={onClick}> | ||
barjin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<button type="button" className="AskAI-Button" aria-label="Ask AI"> | ||
Ask AI | ||
</button> | ||
</div> | ||
)} | ||
</BrowserOnly> | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I talk to the bot, then go to search and from the search, I'll trigger the AI bot again, it will ask the question, but I'm not scrolled to it, I keep seeing the first message of my previous discussion. Could we scroll to the current question being asked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is currently possible with the Kapa AI widget API, sorry. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where exactly, but would it make sense to have the width set dynamically? On a 4K screen, it's just a narrow noodle:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the original values were for. In the last commit, I used the
data-scale-factor: '1.6'
attribute, since we're still using the base font size of10px
.This made the AI modal look much better, since we're scaling margins / paddings now as well.