Skip to content

Commit f9f81ae

Browse files
committed
Initial Kapa.ai chat integration.
Continue refactoring JavaScript into a component pattern and ESM. Replaces some jQuery with native DOM API. chore(ai): reference documentation and instructions for training AI chore(ai): implement Kapa AI chat widget - Move script tag to HTML template to make it obvious. - Cleanup javascript to make it more component-like - Set Kapa attributes, support setting userid chore(js): add JS dependencies, previously referenced in script tags, to package.json for JS builds. fix(api): indents chore(js): package Mermaid diagram library chore(js): refactor JS for AIChat and Theme as examples of using the component pattern for HTML/CSS/JS chore(js): Use the new local-storage API in refactored module code and in code not yet ported. Cleanup syntax in local-storage and make functions available from window.LocalStorageAPI. fix(js): theme.js name-change chore(js): fix ai-chat.js file name fix(js): refactor: - componentNames are snakecase in HTML - replace DOM selection method and jQuery eventhandler assignment - remove old theme.js references chore(ai): configure chat window overlay, size, and position: - removes overlay and scroll lock - positions chat to the right and bottom - expands sample question width to 12 cols chore(ai): edit disclaimer fix(ai): size and position chore(js): make ai-chat specific to configuration and and setting userid (for testing and future use). fix(js): copy referrerHost variable to v3-wayfinding instead of relying on influxdb-url to assign it. chore(ai): add a footer div at page bottom to contain modal triggers for custom-time and ask-ai. Still needs some CSS help. Moves tooltip text from CSS to HTML data attribute. chore(ai): dynamically load AI script tag after DOMContentLoaded to avoid race conditions. Call initialization from the modal trigger module and pass the show trigger function to the onload handler. fix(ai): fix modal triggers to viewport fix(modal-triggers): stack the triggers into a single column. restyle footer widgets updated time selector modal to use correct storage term minor style update WIP(ai-chat): get product data chore(js): Factor out pageContext module from influxdb-url.js chore(js): Refactor helpers.js out of inflluxdb-url.js WIP: refactor influxdburl - minimal changes for module conversions feat(ai): Custom AI chat example questions product and version. Ask AI example questions: - Adds support for customizing example Ask AI questions per product or version. - Configure questions in site `data/products.yml`; otherwise, it uses default questions from `ask-ai.js` Context, page, and product data: - Adds sample URLs for remaining versions in influxdb_urls - `page-context.js` consolidates and exports constants for page context (protocol, host, path, referrer) and path-to-data mappings for product and influxdb_url site data Module refactor: - Refactors some JavaScript into ES6 modules, and refactors some of those further into a Component pattern--just vanilla JS and no shadow DOM stuff. The Component pattern that uses data attributes to "bind" JavaScript modules with CSS and HTML is a popular approach in modern web development. This pattern enhances modularity, reusability, and maintainability by associating behavior (JavaScript), structure (HTML), and style (CSS) through the use of data attributes. - `assets/main.js` is the entrypoint - Passes pageParams from the Hugo page to modules that import `@params`. - Moves most external dependencies out of `script` tags and into package.json to be managed with `yarn`. - Adds `eslint`. - For modules that aren't yet components, wraps execution statements inside an `initialize()` function and calls the function from `main.js` on `DOMContentLoaded`. - For components, if the page contains the `data-component="<component-name>"`, the matching element is passed to the component function on `DOMContentLoaded`. - I tried to avoid changing logic where it wasn't necessary. Update DOC_GPT_PROFILE.md customize ai chat modal styles fix(influxdb-url): Rename to cloud_dedicated in influxdb_urls.yml, remove newly added placeholder URL and use the extant default, refactor - Rename to in influxdb_urls.yml - Fix influxdb-url.js and data provision in local-storage.js to use the new name, mapping it to to retain the existing local storage key chore(api-lib): Use local-storage import instead of window global chore(js): cleanup fix(js): Ensure feature-callout initializes on page load fix(theme): Load preferred theme before making the page visible. Execute a predefined function by specifying the function name in data-theme-callback fix(search-toggle): Restores toggling the search field when sidebar is collapsed. Moves the event handler to a new search-button component fix(ai): Fix custom attribute assignment. Rename property to ai_example_questions Include the word `Bearer` or `Token`, a space, and your **token** value (all case-sensitive). Fix TOC links. Fixes #5781 fix(api-docs): Update API reference directories and generation script for influxdb3 URL paths, update links and names in reference content fix(api-ref): Update getswagger.sh destination paths to use the new directory structure when fetching spec files. Update the redocly plugin module path. hotfix: fix hlevel bug in children shortcode Remove underline from custom time widget add color to custom time widget styling
1 parent d73e99d commit f9f81ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4087
-1665
lines changed

DOC_GPT_PROFILE.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Doc is a public custom GPT for OpenAI ChatGPT used to help write and style InfluxData and InfluxDB documentation.
2+
3+
## Introduction
4+
5+
Doc writes technical software documentation for InfluxData. The public web site is https://docs.influxdata.com and the source repository is https://github.com/influxdata/docs-v2.
6+
Documentation provides step-by-step guides and reference documentation for InfluxDB and associated clients (CLIs, client libraries (SDKs), and Telegraf (https://docs.influxdata.com/telegraf/v1/)), and the legacy v1 components Kapacitor and Chronograf.
7+
8+
## Instruction
9+
10+
When a user asks a question and doesn't include a product from the list below, ask them which product in the list they are using, along with the version and query language:
11+
12+
InfluxDB OSS 1.x (v1)
13+
- Documentation: https://docs.influxdata.com/influxdb/v1/
14+
- Query languages: v1.8+ supports InfluxQL and Flux
15+
- Clients: Telegraf, influx CLI, v1 client libraries
16+
InfluxDB Enterprise (v1)
17+
- Documentation: https://docs.influxdata.com/enterprise_influxdb/v1/
18+
- Query languages: v1.8+ supports InfluxQL and Flux
19+
- Clients: Telegraf, influx CLI, v1 client libraries
20+
InfluxDB OSS 2.x (v2)
21+
- Documentation: https://docs.influxdata.com/influxdb/v2/
22+
- Query languages: InfluxQL and Flux
23+
- Clients: Telegraf, influx CLI, v2 client libraries
24+
InfluxDB Cloud (v2, multi-tenant)
25+
- Documentation: https://docs.influxdata.com/influxdb/cloud/
26+
- Query languages: InfluxQL and Flux
27+
- Clients: Telegraf, influx CLI, v2 client libraries
28+
InfluxDB Clustered (v3, 3.0, self-managed distributed)
29+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
30+
- Query languages: SQL and InfluxQL
31+
- Clients: Telegraf, influxctl CLI, v3 client libraries
32+
InfluxDB Cloud Dedicated (3.0, v3, InfluxData-managed single tenant)
33+
- Documentation: https://docs.influxdata.com/influxdb/cloud-dedicated/
34+
- Query languages: SQL and InfluxQL
35+
- Clients: Telegraf, influxctl CLI, v3 client libraries
36+
InfluxDB Cloud Serverless (v3, 3.0, InfluxData-managed multi-tenant)
37+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
38+
- Query languages: SQL and InfluxQL
39+
- Clients: Telegraf, influx CLI, v3 client libraries
40+
41+
If I ask about a REST API or SDK (client library) and don't specify a product, ask which product.
42+
For API client libraries, refer to the documentation and to the source repositories in https://github.com/InfluxCommunity for the version-specific client library.
43+
44+
When writing documentation, always use Google Developer Documentation style guidelines and Markdown format.
45+
If writing REST API reference documentation follow YouTube Data API style and Google Developer Documentation style guidelines.
46+
47+
The project uses the Hugo static site generator to build the documentation.
48+
The site uses JavaScript and jQuery.
49+
For information about linting, tests (using pytests for codeblocks), shortcode <shortcode_name>, refer to https://github.com/influxdata/docs-v2/blob/master/README.md and https://github.com/influxdata/docs-v2/blob/master/CONTRIBUTING.md.
50+
If something in CONTRIBUTING.md needs clarification, then give me the suggested revision for CONTRIBUTING.md in Markdown.
51+
52+
The community forum is https://community.influxdata.com/ and should not be used as a primary source of information, but might contain useful suggestions or solutions to specific problems from users.

PLATFORM_REFERENCE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
When a user asks a question and doesn't include a product from the list below, ask them which product in the list they are using, along with the version and query language:
2+
3+
InfluxDB OSS 1.x (v1)
4+
- Documentation: https://docs.influxdata.com/influxdb/v1/
5+
- Query languages: v1.8+ supports InfluxQL and Flux
6+
- Clients: Telegraf, influx CLI, v1 client libraries
7+
InfluxDB Enterprise (v1)
8+
- Documentation: https://docs.influxdata.com/enterprise_influxdb/v1/
9+
- Query languages: v1.8+ supports InfluxQL and Flux
10+
- Clients: Telegraf, influx CLI, v1 client libraries
11+
InfluxDB OSS 2.x (v2)
12+
- Documentation: https://docs.influxdata.com/influxdb/v2/
13+
- Query languages: InfluxQL and Flux
14+
- Clients: Telegraf, influx CLI, v2 client libraries
15+
InfluxDB Cloud (v2, multi-tenant)
16+
- Documentation: https://docs.influxdata.com/influxdb/cloud/
17+
- Query languages: InfluxQL and Flux
18+
- Clients: Telegraf, influx CLI, v2 client libraries
19+
InfluxDB Clustered (v3, 3.0, self-managed distributed)
20+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
21+
- Query languages: SQL and InfluxQL
22+
- Clients: Telegraf, influxctl CLI, v3 client libraries
23+
InfluxDB Cloud Dedicated (3.0, v3, InfluxData-managed single tenant)
24+
- Documentation: https://docs.influxdata.com/influxdb/cloud-dedicated/
25+
- Query languages: SQL and InfluxQL
26+
- Clients: Telegraf, influxctl CLI, v3 client libraries
27+
InfluxDB Cloud Serverless (v3, 3.0, InfluxData-managed multi-tenant)
28+
- Documentation: https://docs.influxdata.com/influxdb/clustered/
29+
- Query languages: SQL and InfluxQL
30+
- Clients: Telegraf, influx CLI, v3 client libraries

api-docs/influxdb3/cloud-serverless/v2/ref.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10280,9 +10280,9 @@ components:
1028010280
properties:
1028110281
results:
1028210282
description: |
10283-
A resultset object that contains the `statement_id` and the `series` array.
10283+
A resultset object that contains the `statement_id` and the `series` array.
1028410284
10285-
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
10285+
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
1028610286
items:
1028710287
properties:
1028810288
error:
@@ -10331,12 +10331,12 @@ components:
1033110331
type: integer
1033210332
type: object
1033310333
oneOf:
10334-
- required:
10335-
- statement_id
10336-
- error
10337-
- required:
10338-
- statement_id
10339-
- series
10334+
- required:
10335+
- statement_id
10336+
- error
10337+
- required:
10338+
- statement_id
10339+
- series
1034010340
type: array
1034110341
type: object
1034210342
IntegerLiteral:

assets/js/api-libs.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
////////////////////////////////////////////////////////////////////////////////
22
///////////////// Preferred Client Library programming language ///////////////
33
////////////////////////////////////////////////////////////////////////////////
4+
import { activateTabs, updateBtnURLs } from './tabbed-content.js';
5+
import { getPreference, setPreference } from './local-storage.js';
46

5-
function getVisitedApiLib () {
7+
function getVisitedApiLib() {
68
const path = window.location.pathname.match(
79
/client-libraries\/((?:v[0-9]|flight)\/)?([a-zA-Z0-9]*)/
810
);
911
return path && path.length && path[2];
1012
}
1113

12-
function isApiLib () {
14+
function isApiLib() {
1315
return /\/client-libraries\//.test(window.location.pathname);
1416
}
1517

1618
// Set the user's programming language (client library) preference.
17-
function setApiLibPreference (preference) {
19+
function setApiLibPreference(preference) {
1820
setPreference('api_lib', preference);
1921
}
2022

2123
// Retrieve the user's programming language (client library) preference.
22-
function getApiLibPreference () {
24+
function getApiLibPreference() {
2325
return getPreference('api_lib') || '';
2426
}
2527

26-
// When visit a client library page, set the api_lib preference
27-
if (isApiLib()) {
28-
var selectedApiLib = getVisitedApiLib();
29-
setPreference('api_lib', selectedApiLib);
28+
function initialize() {
29+
// When visiting a client library page, set the api_lib preference
30+
if (isApiLib()) {
31+
var selectedApiLib = getVisitedApiLib();
32+
setPreference('api_lib', selectedApiLib);
33+
}
34+
35+
// Activate code-tabs based on the cookie then override with query param.
36+
const tab = getApiLibPreference();
37+
['.tabs, .code-tabs'].forEach(
38+
(selector) => activateTabs(selector, tab),
39+
updateBtnURLs(tab)
40+
);
3041
}
3142

32-
// Activate code-tabs based on the cookie then override with query param.
33-
var tab = getApiLibPreference();
34-
['.tabs, .code-tabs'].forEach(
35-
selector => activateTabs(selector, tab),
36-
updateBtnURLs(tab)
37-
);
43+
export { initialize };

assets/js/ask-ai-trigger.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import AskAI from './ask-ai.js';
2+
3+
function showTrigger(element) {
4+
// Remove the inline display: none style
5+
element.removeAttribute('style');
6+
}
7+
8+
export default function AskAITrigger({ component }) {
9+
const kapaContainer = document.querySelector('#kapa-widget-container');
10+
if (!component && !kapaContainer) {
11+
return;
12+
}
13+
if (!kapaContainer) {
14+
// Initialize the chat widget
15+
AskAI({ onChatLoad: () => showTrigger(component) });
16+
} else {
17+
showTrigger(component);
18+
}
19+
}

assets/js/ask-ai.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { productData } from './page-context.js';
2+
3+
function setUser(userid, email) {
4+
const NAMESPACE = 'kapaSettings';
5+
6+
// Set the user ID and email in the global settings namespace.
7+
// The chat widget will use this on subsequent chats to personalize the user's experience.
8+
window[NAMESPACE] = {
9+
user: {
10+
uniqueClientId: userid,
11+
email: email,
12+
}
13+
}
14+
}
15+
16+
// Initialize the chat widget
17+
function initializeChat({onChatLoad, chatAttributes}) {
18+
/* See https://docs.kapa.ai/integrations/website-widget/configuration for
19+
* available configuration options.
20+
* All values are strings.
21+
*/
22+
const requiredAttributes = {
23+
websiteId: 'a02bca75-1dd3-411e-95c0-79ee1139be4d',
24+
projectName: 'InfluxDB',
25+
projectColor: '#020a47',
26+
projectLogo: '/img/influx-logo-cubo-white.png',
27+
}
28+
29+
const optionalAttributes = {
30+
modalDisclaimer: 'This AI can access [documentation for InfluxDB, clients, and related tools](https://docs.influxdata.com). Information you submit is used in accordance with our [Privacy Policy](https://www.influxdata.com/legal/privacy-policy/).',
31+
modalExampleQuestions: 'Use Python to write data to InfluxDB 3,How do I query using SQL?,How do I use MQTT with Telegraf?',
32+
buttonHide: 'true',
33+
modalOpenOnCommandK: 'true',
34+
modalExampleQuestionsColSpan: '8',
35+
modalFullScreenOnMobile: 'true',
36+
modalHeaderPadding: '.5rem',
37+
modalInnerPositionRight: '0',
38+
modalInnerPositionLeft: '',
39+
modalLockScroll: 'false',
40+
modalOverrideOpenClassAskAi: 'ask-ai-open',
41+
modalSize: '500px',
42+
modalWithOverlay: 'false',
43+
modalInnerMaxWidth: '500px',
44+
modalXOffset: '1rem',
45+
modalYOffset: '10vh',
46+
userAnalyticsFingerprintEnabled: 'true',
47+
fontFamily: 'Proxima Nova, sans-serif',
48+
modalHeaderBgColor: 'linear-gradient(90deg, #d30971 0%, #9b2aff 100%)',
49+
modalHeaderBorderBottom: 'none',
50+
modalTitleColor: '#fff',
51+
modalTitleFontSize: '1.25rem',
52+
}
53+
54+
const scriptUrl = 'https://widget.kapa.ai/kapa-widget.bundle.js';
55+
const script = document.createElement('script');
56+
script.async = true;
57+
script.src = scriptUrl;
58+
script.onload = function() {
59+
onChatLoad();
60+
window.influxdatadocs.AskAI = AskAI;
61+
};
62+
script.onerror = function() {
63+
console.error('Error loading AI chat widget script');
64+
};
65+
66+
const dataset = {...requiredAttributes, ...optionalAttributes, ...chatAttributes};
67+
Object.keys(dataset).forEach(key => {
68+
// Assign dataset attributes from the object
69+
script.dataset[key] = dataset[key];
70+
});
71+
72+
// Check for an existing script element to remove
73+
const oldScript= document.querySelector(`script[src="${scriptUrl}"]`);
74+
if (oldScript) {
75+
oldScript.remove();
76+
}
77+
document.head.appendChild(script);
78+
}
79+
80+
function getProductExampleQuestions() {
81+
const questions = productData?.product?.ai_sample_questions || null;
82+
return questions?.join(',') || '';
83+
}
84+
85+
/**
86+
* chatParams: specify custom (for example, page-specific) attribute values for the chat, pass the dataset key-values (collected in ...chatParams). See https://docs.kapa.ai/integrations/website-widget/configuration for available configuration options.
87+
* onChatLoad: function to call when the chat widget has loaded
88+
* userid: optional, a unique user ID for the user (not currently used for public docs)
89+
*/
90+
export default function AskAI({ userid, email, onChatLoad, ...chatParams }) {
91+
const chatAttributes = {
92+
modalExampleQuestions: getProductExampleQuestions(),
93+
...chatParams,
94+
}
95+
initializeChat({onChatLoad, chatAttributes});
96+
97+
if (userid) {
98+
setUser(userid, email);
99+
}
100+
}

0 commit comments

Comments
 (0)