Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Update inkeep package #393

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ jobs:
uses: gravitational/shared-workflows/.github/workflows/dependency-review.yaml@main
permissions:
contents: read
with:
allow-dependencies-licenses: 'pkg:npm/%40inkeep/widgets'
116 changes: 59 additions & 57 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
name: Playwright Tests
on: [deployment_status]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
# TODO fix docs/issues/376

# name: Playwright Tests
# on: [deployment_status]
# jobs:
# test:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# if: github.event.deployment_status.state == 'success'

strategy:
matrix:
shard: ["1/3", "2/3", "3/3"]
steps:
- uses: actions/checkout@v2
- id: nvm
name: Read .nvmrc
run: echo "::set-output name=NVMRC;$(cat .nvmrc)"
- uses: actions/setup-node@v2
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache yarn cache
uses: actions/[email protected]
id: cache-yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-
- run: yarn
if: |
steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
steps.cache-node-modules.outputs.cache-hit != 'true'
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
env:
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}
run: yarn playwright test --shard=${{ matrix.shard }}
- name: Build Storybook, serve and run tests
run: yarn storybook:test-ci
- uses: actions/upload-artifact@v2
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
# strategy:
# matrix:
# shard: ["1/3", "2/3", "3/3"]
# steps:
# - uses: actions/checkout@v2
# - id: nvm
# name: Read .nvmrc
# run: echo "::set-output name=NVMRC;$(cat .nvmrc)"
# - uses: actions/setup-node@v2
# with:
# node-version: '${{ steps.nvm.outputs.NVMRC }}'
# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"
# - name: Cache yarn cache
# uses: actions/[email protected]
# id: cache-yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-${{ hashFiles('**/yarn.lock') }}
# ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-yarn-
# - name: Cache node_modules
# id: cache-node-modules
# uses: actions/cache@v2
# with:
# path: node_modules
# key: ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
# ${{ runner.os }}-${{ steps.nvm.ouputs.NVMRC }}-nodemodules-
# - run: yarn
# if: |
# steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
# steps.cache-node-modules.outputs.cache-hit != 'true'
# - name: Install Playwright Browsers
# run: npx playwright install --with-deps
# - name: Run Playwright tests
# env:
# PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}
# run: yarn playwright test
# - name: Build Storybook, serve and run tests
# run: yarn storybook:test-ci
# - uses: actions/upload-artifact@v2
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
206 changes: 105 additions & 101 deletions components/Search/InkeepSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useContext, useState, useRef, useCallback } from "react";
import dynamic from "next/dynamic";
import {
InkeepModalProps,
InkeepAIChatProps,
InkeepWidgetBaseProps,
InkeepSearchProps,
InkeepModalWidgetProps,
SearchCallableFunctions,
AIChatCallableFunctions,
} from "@inkeep/inkeep-widget-library";
InkeepAIChatSettings,
InkeepSearchSettings,
InkeepCustomTriggerProps,
InkeepWidgetBaseSettings,
RemoteErrorLogsLevel,
ConsoleDebugLevel,
AIChatFunctions,
SearchFunctions,
} from "@inkeep/widgets";

import { DocsContext } from "layouts/DocsPage/context";

Expand All @@ -18,32 +19,52 @@ import InkeepSearchIconSvg from "./inkeepIcon.svg?react";
const API_KEY = process.env.NEXT_PUBLIC_INKEEP_API_KEY;
const INTEGRATION_ID = process.env.NEXT_PUBLIC_INKEEP_INTEGRATION_ID;

const InkeepModalWidget = dynamic<InkeepModalWidgetProps>(
() =>
import("@inkeep/inkeep-widget-library").then(
(mod) => mod.InkeepModalWidget
),
const InkeepCustomTrigger = dynamic<InkeepCustomTriggerProps>(
() => import("@inkeep/widgets").then((mod) => mod.InkeepCustomTrigger),
{ ssr: false }
);

export function InkeepSearch() {
const version = useContext(DocsContext).versions.current;
const [isOpen, setIsOpen] = useState(false);
const [message, setMessage] = useState("");

const chatCallableFunctionsRef = useRef<AIChatCallableFunctions | null>(null);
const searchCallableFunctionsRef = useRef<SearchCallableFunctions | null>(
null
);
const chatCallableFunctionsRef = useRef<AIChatFunctions | null>(null);
const searchCallableFunctionsRef = useRef<SearchFunctions | null>(null);

const handleChange = useCallback(
(str: string) => {
chatCallableFunctionsRef.current?.updateInputMessage(str);
searchCallableFunctionsRef.current?.updateSearchQuery(str);
setMessage(str);
setIsOpen(true);
},
[setMessage, chatCallableFunctionsRef, searchCallableFunctionsRef]
);

const handleClose = useCallback(() => {
setIsOpen(false);
}, []);

const inkeepCustomTriggerProps: InkeepCustomTriggerProps = {
isOpen,
onClose: handleClose,
baseSettings: { ...inkeepBaseSettings, productVersion: version },
aiChatSettings: {
...inkeepAIChatSettings,
chatFunctionsRef: chatCallableFunctionsRef,
handleMessageChange: handleChange,
},
searchSettings: {
...inkeepSearchSettings,
searchFunctionsRef: searchCallableFunctionsRef,
handleSearchQueryChange: handleChange,
},
modalSettings: {
closeOnBlur: true,
},
};

return (
<div>
<div className={styles["search-input-wrapper"]}>
Expand All @@ -53,104 +74,87 @@ export function InkeepSearch() {
type="text"
className={styles["search-input"]}
onChange={(e) => handleChange(e.target.value)}
onFocus={() => setIsOpen(true)}
onClick={() => setIsOpen(true)}
placeholder="Search Docs"
value={message}
/>
</div>
<InkeepWidget
isOpen={isOpen}
onClose={() => setIsOpen(false)}
handleChange={handleChange}
chatCallableFunctionsRef={chatCallableFunctionsRef}
searchCallableFunctionsRef={searchCallableFunctionsRef}
/>
<InkeepCustomTrigger {...inkeepCustomTriggerProps} />
</div>
);
}

function InkeepWidget({
chatCallableFunctionsRef,
searchCallableFunctionsRef,
handleChange,
isOpen,
onClose,
}: {
chatCallableFunctionsRef: React.MutableRefObject<AIChatCallableFunctions>;
searchCallableFunctionsRef: React.MutableRefObject<SearchCallableFunctions>;
handleChange: (str: string) => void;
isOpen: boolean;
onClose: () => void;
}) {
const version = useContext(DocsContext).versions.current;

const inkeepBaseSettings: InkeepWidgetBaseProps = {
apiKey: API_KEY,
integrationId: INTEGRATION_ID,
organizationId: "teleport",
organizationDisplayName: "Teleport",
primaryBrandColor: "#512FC9",
productVersion: version,
product: "Teleport",
publicSearchResultSources: ["DOCUMENTATION", "GITHUB_ISSUE"],
inkeepMentionDecoratorText: "Powered by ",
searchAndChatServiceProxyDomain: "goteleport.com/inkeep-proxy",
remoteErrorLoggingLevel: 0,
isOptedOutAllAnalytics: true,
theme: {
zIndices: {
overlay: 2100,
modal: 2200,
popover: 2300,
skipLink: 2400,
toast: 2500,
tooltip: 2600,
const inkeepBaseSettings: InkeepWidgetBaseSettings = {
apiKey: API_KEY,
integrationId: INTEGRATION_ID,
organizationId: "teleport",
organizationDisplayName: "Teleport",
primaryBrandColor: "#512FC9",
product: "Teleport",
isInkeepMentionEnabled: true,
apiProxyDomain: "goteleport.com/inkeep-proxy",
remoteErrorLogsLevel: RemoteErrorLogsLevel.AnonymousErrors,
optOutAllAnalytics: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling the current PostHog analytics are messing with ours, I'll investigate more once merged.

consoleDebugLevel: ConsoleDebugLevel.None,
customCardSettings: [
{
filters: {
ContentType: "docs",
},
components: {
InkeepWidgetModal: {
ModalContent: {
styles: {
border: "2px solid #512FC9",
borderRadius: "xl",
top: "88px",
left: "12px",
},
searchTabLabel: "Docs",
icon: { builtIn: "IoDocumentTextOutline" },
},
],
theme: {
zIndices: {
overlay: "2100",
modal: "2200",
popover: "2300",
skipLink: "2400",
toast: "2500",
tooltip: "2600",
},
components: {
InkeepWidgetModal: {
ModalContent: {
styles: {
border: "2px solid #512FC9",
borderRadius: "xl",
top: "88px",
left: "12px",
},
},
},
},
};
},
};

const inkeepAIChatSettings: InkeepAIChatProps = {
botName: "Teleport",
defaultChatMode: "TURBO",
const inkeepAIChatSettings: InkeepAIChatSettings = {
botName: "Teleport",
botAvatarSrcUrl: "https://goteleport.com/static/pam-standing.svg",
isControlledMessage: true,
defaultChatMode: "AUTO",
toggleButtonSettings: {
isChatModeToggleEnabled: true,
chatModeToggleValue: "TURBO",
chatModeToggleLabel: "Turbo Mode",
chatModeToggleTooltip:
"Turbo mode provides faster responses but can be less accurate.",
},
disclaimerSettings: {
isDisclaimerEnabled: false,
chatCallableFunctionsRef: chatCallableFunctionsRef,
handleMessageChange: handleChange,
isControlledMessage: true,
};
},
};

const inkeepSearchSettings: InkeepSearchProps = {
placeholder: "Search Docs",
searchCallableFunctionsRef: searchCallableFunctionsRef,
handleSearchQueryChange: handleChange,
isControlledSearchQuery: true,
shouldOpenLinksInNewTab: false,
isAggregateResultsTabEnabled: false,
};

const inkeepModalSettings: InkeepModalProps = {
isOpen,
onClose,
};

const inkeepModalWidgetProps: InkeepModalWidgetProps = {
...inkeepModalSettings,
baseSettings: { ...inkeepBaseSettings },
aiChatSettings: { ...inkeepAIChatSettings },
searchSettings: { ...inkeepSearchSettings },
};

return <InkeepModalWidget {...inkeepModalWidgetProps} />;
}
const inkeepSearchSettings: InkeepSearchSettings = {
placeholder: "Search Docs",
tabSettings: {
isAllTabEnabled: false,
rootBreadcrumbsToUseAsTabs: ["Docs", "GitHub"],
tabOrderByLabel: ["Docs", "GitHub"],
alwaysDisplayedTabs: ["Docs", "GitHub"],
disabledDefaultTabs: undefined,
},
isControlledSearchQuery: true,
shouldOpenLinksInNewTab: true,
};
5 changes: 1 addition & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const { latest } = loadConfig();
export default withBundleAnalyzer({
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
basePath: "/docs",
transpilePackages: [
"@inkeep/inkeep-widget-library",
"react-syntax-highlighter",
],
transpilePackages: ["@inkeep/widgets", "react-syntax-highlighter"],
redirects: async () => [
...deprecatedVersionRedirects,
...getRedirects(),
Expand Down
Loading