Skip to content

Commit

Permalink
Merge pull request #31 from nlxai/generate-api-docs
Browse files Browse the repository at this point in the history
generate api docs from tsdoc
  • Loading branch information
peterszerzo authored Mar 26, 2024
2 parents 2e91693 + b1ab8c7 commit 900db39
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 43 deletions.
1 change: 1 addition & 0 deletions packages/voice-compass/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
11 changes: 11 additions & 0 deletions packages/voice-compass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# VoiceCompass SDK

The API for creating multi-modal integrations with a voice assistant.

## Installation

`npm install --save @nlxai/voice-compass`

## Usage

see: https://developers.nlx.ai/#/multimodal-getting-started
4 changes: 4 additions & 0 deletions packages/voice-compass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"types": "lib/index.d.ts",
"scripts": {
"build": "rm -rf lib && rollup -c",
"docs": "typedoc",
"publish-docs": "npm run docs && concat-md --decrease-title-levels --dir-name-as-title docs/ > ../website/src/content/06-03-multimodal-api-reference.md",
"prepublish": "npm run build",
"test": "jest"
},
Expand All @@ -26,13 +28,15 @@
"@types/jest": "^29.5.12",
"@types/node": "^11.15.11",
"@types/ramda": "0.29.1",
"concat-md": "^0.5.1",
"fast-check": "^3.16.0",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"rollup": "^4.3.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typedoc": "^0.25.12",
"typescript": "^5.2.2"
},
"dependencies": {
Expand Down
124 changes: 102 additions & 22 deletions packages/voice-compass/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import fetch from "isomorphic-fetch";

// Initial configuration used when creating a journey manager
export interface Config {
apiKey: string;
workspaceId: string;
conversationId: string;
journeyId: string;
languageCode: string;
debug?: boolean;
dev?: boolean;
}

export type Context = Record<string, any>;

// The journey manager object
export interface VoiceCompass {
sendStep: (stepId: string, context?: Context) => Promise<void>;
}

export const stepIdRegex =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;

/**
* The starting point of the package. Call create to create a `VoiceCompass` client.
*
* @example
* ```typescript
* const client = nlxai.voiceCompass.create({
* // hard-coded params
* apiKey: "REPLACE_WITH_API_KEY",
* workspaceId: "REPLACE_WITH_WORKSPACE_ID",
* journeyId: "REPLACE_WITH_JOURNEY_ID",
* // dynamic params
* conversationId: "REPLACE_WITH_CONVERSATION_ID",
* languageCode: "en-US",
* });
*
* client.sendStep("REPLACE_WITH_STEP_ID");
* ```
*
* @category Setup
*
* @param options - the configuration object
*
* @returns a Voice Compass client
*/
export const create = ({
apiKey,
workspaceId,
Expand All @@ -29,7 +32,7 @@ export const create = ({
languageCode,
debug = false,
dev = false,
}: Config): VoiceCompass => {
}: Config): Client => {
if (!conversationId) {
console.warn(
'No conversation ID provided. Please call the Voice Compass client `create` method with a `conversationId` field extracted from the URL. Example code: `new URLSearchParams(window.location.search).get("cid")`',
Expand Down Expand Up @@ -72,3 +75,80 @@ export const create = ({

return { sendStep };
};

/**
* The VoiceCompass client
* @category Client
*/
export interface Client {
/**
*
* * @example
* ```typescript
* const client = nlxai.voiceCompass.create({
* // hard-coded params
* apiKey: "REPLACE_WITH_API_KEY",
* workspaceId: "REPLACE_WITH_WORKSPACE_ID",
* journeyId: "REPLACE_WITH_JOURNEY_ID",
* // dynamic params
* conversationId: "REPLACE_WITH_CONVERSATION_ID",
* languageCode: "en-US",
* });
*
* client.sendStep("REPLACE_WITH_STEP_ID", {selectedSeat: "4a"});
* ```
* sends a step to the voice bot
* @param stepId - the next step to transition to.
*
*
* _Note: Must be a valid UUID_
*
* @param context - context to send back to the voice bot, for usage later in the intent.
*/
sendStep: (stepId: string, context?: Context) => Promise<void>;
}

/**
* context to send back to the voice bot, for usage later in the intent.
* @category Client
*/
export type Context = Record<string, any>;

/**
* Initial configuration used when creating a journey manager
* @category Setup
*/
export interface Config {
/** * the API key generated for the journey. **/
apiKey: string;
/** the ID of the journey. */
journeyId: string;

/** your workspace id */
workspaceId: string;

/** the conversation id, passed from the active voice bot.
*
* _Note: This must be dynamically set by the voice bot._
* */
conversationId: string;

/** the user's language code.
*
* In the browser may be fetched from `navigator.language`, or if the journey doesn't support multiple languages, can be hardcoded.
* */
languageCode: string;

/** set to true to help debug issues or errors. Defaults to false */
debug?: boolean;

/** used for library testing @internal @hidden */
dev?: boolean;
}

/**
* @internal @hidden
* this is exported so we can test it. Should be equivalent to a UUID v4 regex.
*/
export const stepIdRegex =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
1 change: 0 additions & 1 deletion packages/voice-compass/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"moduleResolution": "bundler",
"declaration": true,
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"strictNullChecks": true,
"esModuleInterop": true,
Expand Down
12 changes: 12 additions & 0 deletions packages/voice-compass/typedoc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('typedoc').TypeDocOptions} */
module.exports = {
sort: ["source-order", "kind", "instance-first", "alphabetical"],
entryPoints: ["./src/index.ts"],
out: "docs",
validation: { notExported: true, invalidLink: true, notDocumented: true },
treatWarningsAsErrors: true,
treatValidationWarningsAsErrors: true,
categoryOrder: ["Setup", "Client"],
plugin: ["typedoc-plugin-markdown"],
readme: "none",
};
2 changes: 2 additions & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"react-dom": "^18.2.0",
"react-markdown": "^9.0.0",
"react-router-dom": "^6.17.0",
"rehype-raw": "^7.0.0",
"rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0",
"tinycolor2": "^1.4.1"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/website/src/components/PageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { CheckIcon, ContentCopyIcon } from "./Icons";
import remarkGfm from "remark-gfm";
import rehypeRaw from "rehype-raw";
import rehypeSlug from "rehype-slug";

const CopyToClipboardButton: FC<{ text: string; className?: string }> = ({
text,
Expand Down Expand Up @@ -45,6 +47,7 @@ export const PageContent: FC<{ md: string }> = ({ md }) => (
<Prose>
<Markdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw, rehypeSlug]}
components={{
pre(props) {
return (
Expand Down
Loading

0 comments on commit 900db39

Please sign in to comment.