@docshound/chat-react 0.8.5 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -21
- package/dist/index.d.ts +16 -4
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -21,20 +21,19 @@ To ensure the DocsHoundChat component remains mounted and does not unmount with
|
|
|
21
21
|
Here is a simple example of how to use the DocsHoundChat component in your React project:
|
|
22
22
|
|
|
23
23
|
```jsx
|
|
24
|
-
import React from
|
|
25
|
-
import { DocsHoundChat } from
|
|
24
|
+
import React from "react";
|
|
25
|
+
import { DocsHoundChat } from "@docshound/chat-react";
|
|
26
26
|
|
|
27
27
|
const App = () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
return (
|
|
29
|
+
<div>
|
|
30
|
+
<h1>My Application</h1>
|
|
31
|
+
<DocsHoundChat src="https://your-docshound-portal.com" />
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export default App;
|
|
37
|
-
|
|
38
37
|
```
|
|
39
38
|
|
|
40
39
|
### Props
|
|
@@ -54,6 +53,7 @@ The DocsHoundChat component accepts the following props:
|
|
|
54
53
|
- `position`: The position of the chat widget on the screen ('center' or 'right'). Optional. Defaults to 'right'.
|
|
55
54
|
- `accentColor`: The accent color of the chat interface. Optional.
|
|
56
55
|
- `triggerLabel`: The label for the trigger button that starts the chat. Optional.
|
|
56
|
+
- `token`: Authentication token for jwt / password / basic protected guides. Optional.
|
|
57
57
|
|
|
58
58
|
## Hooks
|
|
59
59
|
|
|
@@ -62,19 +62,19 @@ This package also provides a custom hook, `useDocsHoundChat`, to programmaticall
|
|
|
62
62
|
### Example
|
|
63
63
|
|
|
64
64
|
```jsx
|
|
65
|
-
import React from
|
|
66
|
-
import { useDocsHoundChat } from
|
|
65
|
+
import React from "react";
|
|
66
|
+
import { useDocsHoundChat } from "@docshound/chat-react";
|
|
67
67
|
|
|
68
68
|
const ChatControls = () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
const { show, clear } = useDocsHoundChat();
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div>
|
|
73
|
+
<button onClick={() => show(true)}>Show Chat</button>
|
|
74
|
+
<button onClick={() => show(false)}>Hide Chat</button>
|
|
75
|
+
<button onClick={() => clear()}>Clear Chat</button>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
export default ChatControls;
|
|
@@ -84,9 +84,10 @@ export default ChatControls;
|
|
|
84
84
|
|
|
85
85
|
Hook's API:
|
|
86
86
|
|
|
87
|
+
- `sendQuestion(question: string)`: Programmatically clear thread and send question on behalf of the user.
|
|
87
88
|
- `show(show: boolean)`: Programmatically show or hide the chat widget.
|
|
88
89
|
- `clear()`: Clears the chat history.
|
|
89
90
|
|
|
90
91
|
## License
|
|
91
92
|
|
|
92
|
-
MIT
|
|
93
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ type DocsHoundChatProps = {
|
|
|
47
47
|
*
|
|
48
48
|
* Optional field, defaults to 'app'.
|
|
49
49
|
*/
|
|
50
|
-
platform?:
|
|
50
|
+
platform?: "site" | "app" | "docs";
|
|
51
51
|
/**
|
|
52
52
|
* The URL for the avatar image of the user interacting with the chat.
|
|
53
53
|
*
|
|
@@ -65,13 +65,13 @@ type DocsHoundChatProps = {
|
|
|
65
65
|
*
|
|
66
66
|
* Optional field. Defaults to value set in DocsHound.
|
|
67
67
|
*/
|
|
68
|
-
theme?:
|
|
68
|
+
theme?: "light" | "dark";
|
|
69
69
|
/**
|
|
70
70
|
* Defines the position of the chat widget on the screen. Can be either 'center' or 'right'.
|
|
71
71
|
*
|
|
72
72
|
* Optional field. Defaults to 'right'
|
|
73
73
|
*/
|
|
74
|
-
position?:
|
|
74
|
+
position?: "center" | "right";
|
|
75
75
|
/**
|
|
76
76
|
* Sets the accent color of the chat interface (e.g., for buttons or highlights).
|
|
77
77
|
*
|
|
@@ -84,10 +84,22 @@ type DocsHoundChatProps = {
|
|
|
84
84
|
* Optional field. Defaults to value set in DocsHound.
|
|
85
85
|
*/
|
|
86
86
|
triggerLabel?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Authentication token for jwt / password / basic protected guides
|
|
89
|
+
*
|
|
90
|
+
* Optional field.
|
|
91
|
+
*/
|
|
92
|
+
token?: string;
|
|
87
93
|
};
|
|
88
|
-
declare const DocsHoundChat: ({ src, agentName, agentAvatarUrl, accentColor, platform, position, theme, triggerLabel, userAvatarUrl, userId, userEmail, userName, firstMessage }: DocsHoundChatProps) => react_jsx_runtime.JSX.Element
|
|
94
|
+
declare const DocsHoundChat: ({ src, agentName, agentAvatarUrl, accentColor, platform, position, theme, triggerLabel, userAvatarUrl, userId, userEmail, userName, firstMessage, token, }: DocsHoundChatProps) => react_jsx_runtime.JSX.Element;
|
|
89
95
|
|
|
90
96
|
type UseDocsHoundChat = {
|
|
97
|
+
/**
|
|
98
|
+
* Method to clear thread and send a query on behalf of the user
|
|
99
|
+
*
|
|
100
|
+
* @param question - user query
|
|
101
|
+
*/
|
|
102
|
+
sendQuestion: (question: string) => void;
|
|
91
103
|
/**
|
|
92
104
|
* Method to show or hide the chat component
|
|
93
105
|
*
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useEffect as t,useCallback as o}from"react";const n=({src:o,agentName:n,agentAvatarUrl:r,accentColor:c,platform:s,position:a,theme:d,triggerLabel:i,userAvatarUrl:u,userId:m,userEmail:l,userName:h,firstMessage:p,token:g})=>{const f="__DH_CHAT_SCRIPT__";return t((()=>{if(!customElements.get("docshound-chat")){if(!document.getElementById(f)){let e="";e=o.endsWith("/-/chat.js")?o:o.endsWith("/")?`${o}-/chat.js`:`${o}/-/chat.js`;const t=document.createElement("script");t.src=e,t.id=f,t.type="text/javascript",t.async=!0,t.defer=!0,document.head.appendChild(t)}}}),[]),e("docshound-chat",{"agent-name":n,"agent-avatar-url":r,"accent-color":c,platform:s,position:a,theme:d,"trigger-label":i,"user-id":m,"user-email":l,"user-name":h,"user-avatar-url":u,"first-message":p,token:g})};function r(...e){"development"===process.env.NODE_ENV&&console.warn(...e)}function c(){return{show:o((e=>{const t=document.querySelector("docshound-chat");t&&t.show?t.show(e):r("DocsHound Chat component not mounted or not initialized")}),[]),clear:o((()=>{const e=document.querySelector("docshound-chat");e&&e.clear?e.clear():r("DocsHound Chat component not mounted or not initialized")}),[]),sendQuestion:o((e=>{const t=document.querySelector("docshound-chat");t&&t.sendQuestion?t.sendQuestion(e):r("DocsHound Chat component not mounted or not initialized")}),[])}}export{n as DocsHoundChat,c as useDocsHoundChat};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/components/DocsHoundChat.tsx","../src/hooks/useDocsHoundChat.tsx"],"sourcesContent":["import React, { useEffect } from
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/components/DocsHoundChat.tsx","../src/utils/devLog.ts","../src/hooks/useDocsHoundChat.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\n\nexport type DocsHoundChatProps = {\n\t/**\n\t * Domain where the guide is published. Eg: https://docs.docshound.com\n\t *\n\t * This field is not reactive, so if you change it, you need to reload the page.\n\t *\n\t * Required field;\n\t */\n\tsrc: string;\n\n\t/**\n\t * The name of the agent responding in the chat.\n\t *\n\t * Optional field. Defaults to value set in the DocsHound.\n\t */\n\tagentName?: string;\n\n\t/**\n\t * The URL for the avatar image of the agent.\n\t *\n\t * Optional field. Defaults to value set in the DocsHound.\n\t */\n\tagentAvatarUrl?: string;\n\n\t/**\n\t * A unique identifier for the user interacting with the chat.\n\t * This should be unique identifier coming from your system.\n\t * Used to identify the user and their support tickets.\n\t *\n\t * Optional field. Defaults to undefined.\n\t */\n\tuserId?: string;\n\n\t/**\n\t * The email address of the user interacting with the chat.\n\t * Will be pre-filled for the user when they decide to submit a support ticket.\n\t *\n\t * Optional field. Defaults to undefined.\n\t */\n\tuserEmail?: string;\n\n\t/**\n\t * The display name of the user interacting with the chat.\n\t *\n\t * Optional field. Defaults to 'You'.\n\t */\n\tuserName?: string;\n\n\t/**\n\t * The platform where the chat is being used. Could be either 'site' (marketing site), 'app' (application), or 'docs' (documentation site / platform).\n\t *\n\t * Optional field, defaults to 'app'.\n\t */\n\tplatform?: \"site\" | \"app\" | \"docs\";\n\n\t/**\n\t * The URL for the avatar image of the user interacting with the chat.\n\t *\n\t * Optional field. Defaults to generic user avatar.\n\t */\n\tuserAvatarUrl?: string;\n\n\t/**\n\t * The initial agent message that will be prepopulated when user opens the chatbot widget.\n\t *\n\t * Optional field. Default to value set in DocsHound.\n\t */\n\tfirstMessage?: string;\n\n\t/**\n\t * Defines the theme of the chat interface, either 'light' or 'dark'.\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\ttheme?: \"light\" | \"dark\";\n\n\t/**\n\t * Defines the position of the chat widget on the screen. Can be either 'center' or 'right'.\n\t *\n\t * Optional field. Defaults to 'right'\n\t */\n\tposition?: \"center\" | \"right\";\n\n\t/**\n\t * Sets the accent color of the chat interface (e.g., for buttons or highlights).\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\taccentColor?: string;\n\n\t/**\n\t * The label for the trigger button that starts the chat.\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\ttriggerLabel?: string;\n\n\t/**\n\t * Authentication token for jwt / password / basic protected guides\n\t *\n\t * Optional field.\n\t */\n\ttoken?: string;\n};\n\nexport const DocsHoundChat = ({\n\tsrc,\n\tagentName,\n\tagentAvatarUrl,\n\taccentColor,\n\tplatform,\n\tposition,\n\ttheme,\n\ttriggerLabel,\n\tuserAvatarUrl,\n\tuserId,\n\tuserEmail,\n\tuserName,\n\tfirstMessage,\n\ttoken,\n}: DocsHoundChatProps) => {\n\tconst id = `__DH_CHAT_SCRIPT__`;\n\n\tuseEffect(() => {\n\t\tif (!customElements.get(\"docshound-chat\")) {\n\t\t\tlet existingScript = document.getElementById(\n\t\t\t\tid\n\t\t\t) as HTMLScriptElement | null;\n\n\t\t\tif (!existingScript) {\n\t\t\t\tlet finalSrc = \"\";\n\n\t\t\t\tif (src.endsWith(\"/-/chat.js\")) {\n\t\t\t\t\tfinalSrc = src;\n\t\t\t\t} else if (src.endsWith(\"/\")) {\n\t\t\t\t\tfinalSrc = `${src}-/chat.js`;\n\t\t\t\t} else {\n\t\t\t\t\tfinalSrc = `${src}/-/chat.js`;\n\t\t\t\t}\n\n\t\t\t\tconst script = document.createElement(\"script\");\n\t\t\t\tscript.src = finalSrc;\n\t\t\t\tscript.id = id;\n\t\t\t\tscript.type = \"text/javascript\";\n\t\t\t\tscript.async = true;\n\t\t\t\tscript.defer = true;\n\t\t\t\tdocument.head.appendChild(script);\n\t\t\t}\n\t\t}\n\t}, []);\n\n\treturn (\n\t\t<docshound-chat\n\t\t\tagent-name={agentName}\n\t\t\tagent-avatar-url={agentAvatarUrl}\n\t\t\taccent-color={accentColor}\n\t\t\tplatform={platform}\n\t\t\tposition={position}\n\t\t\ttheme={theme}\n\t\t\ttrigger-label={triggerLabel}\n\t\t\tuser-id={userId}\n\t\t\tuser-email={userEmail}\n\t\t\tuser-name={userName}\n\t\t\tuser-avatar-url={userAvatarUrl}\n\t\t\tfirst-message={firstMessage}\n\t\t\ttoken={token}\n\t\t/>\n\t);\n};\n","export function devWarn(...args: Parameters<typeof console.warn>) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(...args);\n }\n}","import { useCallback } from \"react\";\nimport { devWarn } from \"../utils/devLog\";\n\ntype UseDocsHoundChat = {\n\t/**\n\t * Method to clear thread and send a query on behalf of the user\n\t *\n\t * @param question - user query\n\t */\n\tsendQuestion: (question: string) => void;\n\n\t/**\n\t * Method to show or hide the chat component\n\t *\n\t * @param show - Whether to show or hide the chat component\n\t */\n\tshow: (show: boolean) => void;\n\n\t/**\n\t * Method to clear history of the chat component\n\t */\n\tclear: () => void;\n};\n\nexport function useDocsHoundChat(): UseDocsHoundChat {\n\tconst show = useCallback((show: boolean) => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.show) {\n\t\t\telement.show(show);\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\tconst clear = useCallback(() => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.clear) {\n\t\t\telement.clear();\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\tconst sendQuestion = useCallback((question: string) => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.sendQuestion) {\n\t\t\telement.sendQuestion(question);\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\t// Return the show and clear methods\n\treturn { show, clear, sendQuestion };\n}\n\nexport default useDocsHoundChat;\n"],"names":["DocsHoundChat","src","agentName","agentAvatarUrl","accentColor","platform","position","theme","triggerLabel","userAvatarUrl","userId","userEmail","userName","firstMessage","token","id","useEffect","customElements","get","document","getElementById","finalSrc","endsWith","script","createElement","type","async","defer","head","appendChild","_jsx","devWarn","args","process","env","NODE_ENV","console","warn","useDocsHoundChat","show","useCallback","element","querySelector","clear","sendQuestion","question"],"mappings":"2FA2GO,MAAMA,EAAgB,EAC5BC,MACAC,YACAC,iBACAC,cACAC,WACAC,WACAC,QACAC,eACAC,gBACAC,SACAC,YACAC,WACAC,eACAC,YAEA,MAAMC,EAAK,qBA8BX,OA5BAC,GAAU,KACT,IAAKC,eAAeC,IAAI,kBAAmB,CAK1C,IAJqBC,SAASC,eAC7BL,GAGoB,CACpB,IAAIM,EAAW,GAGdA,EADGpB,EAAIqB,SAAS,cACLrB,EACDA,EAAIqB,SAAS,KACZ,GAAGrB,aAEH,GAAGA,cAGf,MAAMsB,EAASJ,SAASK,cAAc,UACtCD,EAAOtB,IAAMoB,EACbE,EAAOR,GAAKA,EACZQ,EAAOE,KAAO,kBACdF,EAAOG,OAAQ,EACfH,EAAOI,OAAQ,EACfR,SAASS,KAAKC,YAAYN,OAG1B,IAGFO,EACa,iBAAA,CAAA,aAAA5B,EACM,mBAAAC,iBACJC,EACdC,SAAUA,EACVC,SAAUA,EACVC,MAAOA,EAAK,gBACGC,EACN,UAAAE,EACG,aAAAC,cACDC,EAAQ,kBACFH,EAAa,gBACfI,EACfC,MAAOA,GACN,ECxKY,SAAAiB,KAAWC,GACI,gBAAzBC,QAAQC,IAAIC,UACdC,QAAQC,QAAQL,EAEpB,UCoBgBM,IAmCf,MAAO,CAAEC,KAlCIC,GAAaD,IACzB,MAAME,EAAUtB,SAASuB,cACxB,kBAEGD,GAAWA,EAAQF,KACtBE,EAAQF,KAAKA,GAEbR,EAAQ,6DAEP,IAyBYY,MAvBDH,GAAY,KACzB,MAAMC,EAAUtB,SAASuB,cACxB,kBAEGD,GAAWA,EAAQE,MACtBF,EAAQE,QAERZ,EAAQ,6DAEP,IAcmBa,aAZDJ,GAAaK,IACjC,MAAMJ,EAAUtB,SAASuB,cACxB,kBAEGD,GAAWA,EAAQG,aACtBH,EAAQG,aAAaC,GAErBd,EAAQ,6DAEP,IAIJ"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react");exports.DocsHoundChat=({src:
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react");function o(...e){"development"===process.env.NODE_ENV&&console.warn(...e)}exports.DocsHoundChat=({src:o,agentName:n,agentAvatarUrl:s,accentColor:a,platform:c,position:r,theme:u,triggerLabel:d,userAvatarUrl:i,userId:l,userEmail:m,userName:h,firstMessage:p,token:g})=>{const C="__DH_CHAT_SCRIPT__";return t.useEffect((()=>{if(!customElements.get("docshound-chat")){if(!document.getElementById(C)){let e="";e=o.endsWith("/-/chat.js")?o:o.endsWith("/")?`${o}-/chat.js`:`${o}/-/chat.js`;const t=document.createElement("script");t.src=e,t.id=C,t.type="text/javascript",t.async=!0,t.defer=!0,document.head.appendChild(t)}}}),[]),e.jsx("docshound-chat",{"agent-name":n,"agent-avatar-url":s,"accent-color":a,platform:c,position:r,theme:u,"trigger-label":d,"user-id":l,"user-email":m,"user-name":h,"user-avatar-url":i,"first-message":p,token:g})},exports.useDocsHoundChat=function(){return{show:t.useCallback((e=>{const t=document.querySelector("docshound-chat");t&&t.show?t.show(e):o("DocsHound Chat component not mounted or not initialized")}),[]),clear:t.useCallback((()=>{const e=document.querySelector("docshound-chat");e&&e.clear?e.clear():o("DocsHound Chat component not mounted or not initialized")}),[]),sendQuestion:t.useCallback((e=>{const t=document.querySelector("docshound-chat");t&&t.sendQuestion?t.sendQuestion(e):o("DocsHound Chat component not mounted or not initialized")}),[])}};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/components/DocsHoundChat.tsx","../src/hooks/useDocsHoundChat.tsx"],"sourcesContent":["import React, { useEffect } from
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils/devLog.ts","../src/components/DocsHoundChat.tsx","../src/hooks/useDocsHoundChat.tsx"],"sourcesContent":["export function devWarn(...args: Parameters<typeof console.warn>) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(...args);\n }\n}","import React, { useEffect } from \"react\";\n\nexport type DocsHoundChatProps = {\n\t/**\n\t * Domain where the guide is published. Eg: https://docs.docshound.com\n\t *\n\t * This field is not reactive, so if you change it, you need to reload the page.\n\t *\n\t * Required field;\n\t */\n\tsrc: string;\n\n\t/**\n\t * The name of the agent responding in the chat.\n\t *\n\t * Optional field. Defaults to value set in the DocsHound.\n\t */\n\tagentName?: string;\n\n\t/**\n\t * The URL for the avatar image of the agent.\n\t *\n\t * Optional field. Defaults to value set in the DocsHound.\n\t */\n\tagentAvatarUrl?: string;\n\n\t/**\n\t * A unique identifier for the user interacting with the chat.\n\t * This should be unique identifier coming from your system.\n\t * Used to identify the user and their support tickets.\n\t *\n\t * Optional field. Defaults to undefined.\n\t */\n\tuserId?: string;\n\n\t/**\n\t * The email address of the user interacting with the chat.\n\t * Will be pre-filled for the user when they decide to submit a support ticket.\n\t *\n\t * Optional field. Defaults to undefined.\n\t */\n\tuserEmail?: string;\n\n\t/**\n\t * The display name of the user interacting with the chat.\n\t *\n\t * Optional field. Defaults to 'You'.\n\t */\n\tuserName?: string;\n\n\t/**\n\t * The platform where the chat is being used. Could be either 'site' (marketing site), 'app' (application), or 'docs' (documentation site / platform).\n\t *\n\t * Optional field, defaults to 'app'.\n\t */\n\tplatform?: \"site\" | \"app\" | \"docs\";\n\n\t/**\n\t * The URL for the avatar image of the user interacting with the chat.\n\t *\n\t * Optional field. Defaults to generic user avatar.\n\t */\n\tuserAvatarUrl?: string;\n\n\t/**\n\t * The initial agent message that will be prepopulated when user opens the chatbot widget.\n\t *\n\t * Optional field. Default to value set in DocsHound.\n\t */\n\tfirstMessage?: string;\n\n\t/**\n\t * Defines the theme of the chat interface, either 'light' or 'dark'.\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\ttheme?: \"light\" | \"dark\";\n\n\t/**\n\t * Defines the position of the chat widget on the screen. Can be either 'center' or 'right'.\n\t *\n\t * Optional field. Defaults to 'right'\n\t */\n\tposition?: \"center\" | \"right\";\n\n\t/**\n\t * Sets the accent color of the chat interface (e.g., for buttons or highlights).\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\taccentColor?: string;\n\n\t/**\n\t * The label for the trigger button that starts the chat.\n\t *\n\t * Optional field. Defaults to value set in DocsHound.\n\t */\n\ttriggerLabel?: string;\n\n\t/**\n\t * Authentication token for jwt / password / basic protected guides\n\t *\n\t * Optional field.\n\t */\n\ttoken?: string;\n};\n\nexport const DocsHoundChat = ({\n\tsrc,\n\tagentName,\n\tagentAvatarUrl,\n\taccentColor,\n\tplatform,\n\tposition,\n\ttheme,\n\ttriggerLabel,\n\tuserAvatarUrl,\n\tuserId,\n\tuserEmail,\n\tuserName,\n\tfirstMessage,\n\ttoken,\n}: DocsHoundChatProps) => {\n\tconst id = `__DH_CHAT_SCRIPT__`;\n\n\tuseEffect(() => {\n\t\tif (!customElements.get(\"docshound-chat\")) {\n\t\t\tlet existingScript = document.getElementById(\n\t\t\t\tid\n\t\t\t) as HTMLScriptElement | null;\n\n\t\t\tif (!existingScript) {\n\t\t\t\tlet finalSrc = \"\";\n\n\t\t\t\tif (src.endsWith(\"/-/chat.js\")) {\n\t\t\t\t\tfinalSrc = src;\n\t\t\t\t} else if (src.endsWith(\"/\")) {\n\t\t\t\t\tfinalSrc = `${src}-/chat.js`;\n\t\t\t\t} else {\n\t\t\t\t\tfinalSrc = `${src}/-/chat.js`;\n\t\t\t\t}\n\n\t\t\t\tconst script = document.createElement(\"script\");\n\t\t\t\tscript.src = finalSrc;\n\t\t\t\tscript.id = id;\n\t\t\t\tscript.type = \"text/javascript\";\n\t\t\t\tscript.async = true;\n\t\t\t\tscript.defer = true;\n\t\t\t\tdocument.head.appendChild(script);\n\t\t\t}\n\t\t}\n\t}, []);\n\n\treturn (\n\t\t<docshound-chat\n\t\t\tagent-name={agentName}\n\t\t\tagent-avatar-url={agentAvatarUrl}\n\t\t\taccent-color={accentColor}\n\t\t\tplatform={platform}\n\t\t\tposition={position}\n\t\t\ttheme={theme}\n\t\t\ttrigger-label={triggerLabel}\n\t\t\tuser-id={userId}\n\t\t\tuser-email={userEmail}\n\t\t\tuser-name={userName}\n\t\t\tuser-avatar-url={userAvatarUrl}\n\t\t\tfirst-message={firstMessage}\n\t\t\ttoken={token}\n\t\t/>\n\t);\n};\n","import { useCallback } from \"react\";\nimport { devWarn } from \"../utils/devLog\";\n\ntype UseDocsHoundChat = {\n\t/**\n\t * Method to clear thread and send a query on behalf of the user\n\t *\n\t * @param question - user query\n\t */\n\tsendQuestion: (question: string) => void;\n\n\t/**\n\t * Method to show or hide the chat component\n\t *\n\t * @param show - Whether to show or hide the chat component\n\t */\n\tshow: (show: boolean) => void;\n\n\t/**\n\t * Method to clear history of the chat component\n\t */\n\tclear: () => void;\n};\n\nexport function useDocsHoundChat(): UseDocsHoundChat {\n\tconst show = useCallback((show: boolean) => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.show) {\n\t\t\telement.show(show);\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\tconst clear = useCallback(() => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.clear) {\n\t\t\telement.clear();\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\tconst sendQuestion = useCallback((question: string) => {\n\t\tconst element = document.querySelector(\n\t\t\t\"docshound-chat\"\n\t\t) as DocsHoundChatElement | null;\n\t\tif (element && element.sendQuestion) {\n\t\t\telement.sendQuestion(question);\n\t\t} else {\n\t\t\tdevWarn(\"DocsHound Chat component not mounted or not initialized\");\n\t\t}\n\t}, []);\n\n\t// Return the show and clear methods\n\treturn { show, clear, sendQuestion };\n}\n\nexport default useDocsHoundChat;\n"],"names":["devWarn","args","process","env","NODE_ENV","console","warn","src","agentName","agentAvatarUrl","accentColor","platform","position","theme","triggerLabel","userAvatarUrl","userId","userEmail","userName","firstMessage","token","id","useEffect","customElements","get","document","getElementById","finalSrc","endsWith","script","createElement","type","async","defer","head","appendChild","_jsx","jsx","show","useCallback","element","querySelector","clear","sendQuestion","question"],"mappings":"mEAAgB,SAAAA,KAAWC,GACI,gBAAzBC,QAAQC,IAAIC,UACdC,QAAQC,QAAQL,EAEpB,uBCuG6B,EAC5BM,MACAC,YACAC,iBACAC,cACAC,WACAC,WACAC,QACAC,eACAC,gBACAC,SACAC,YACAC,WACAC,eACAC,YAEA,MAAMC,EAAK,qBA8BX,OA5BAC,EAAAA,WAAU,KACT,IAAKC,eAAeC,IAAI,kBAAmB,CAK1C,IAJqBC,SAASC,eAC7BL,GAGoB,CACpB,IAAIM,EAAW,GAGdA,EADGpB,EAAIqB,SAAS,cACLrB,EACDA,EAAIqB,SAAS,KACZ,GAAGrB,aAEH,GAAGA,cAGf,MAAMsB,EAASJ,SAASK,cAAc,UACtCD,EAAOtB,IAAMoB,EACbE,EAAOR,GAAKA,EACZQ,EAAOE,KAAO,kBACdF,EAAOG,OAAQ,EACfH,EAAOI,OAAQ,EACfR,SAASS,KAAKC,YAAYN,OAG1B,IAGFO,EACaC,IAAA,iBAAA,CAAA,aAAA7B,EACM,mBAAAC,iBACJC,EACdC,SAAUA,EACVC,SAAUA,EACVC,MAAOA,EAAK,gBACGC,EACN,UAAAE,EACG,aAAAC,cACDC,EAAQ,kBACFH,EAAa,gBACfI,EACfC,MAAOA,GACN,sCC7GH,MAAO,CAAEkB,KAlCIC,eAAaD,IACzB,MAAME,EAAUf,SAASgB,cACxB,kBAEGD,GAAWA,EAAQF,KACtBE,EAAQF,KAAKA,GAEbtC,EAAQ,6DAEP,IAyBY0C,MAvBDH,EAAAA,aAAY,KACzB,MAAMC,EAAUf,SAASgB,cACxB,kBAEGD,GAAWA,EAAQE,MACtBF,EAAQE,QAER1C,EAAQ,6DAEP,IAcmB2C,aAZDJ,eAAaK,IACjC,MAAMJ,EAAUf,SAASgB,cACxB,kBAEGD,GAAWA,EAAQG,aACtBH,EAAQG,aAAaC,GAErB5C,EAAQ,6DAEP,IAIJ"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docshound/chat-react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"description": "React component library for integrating the DocsHound chat widget into React and Next.js applications.",
|
|
6
|
-
"keywords": [
|
|
6
|
+
"keywords": [
|
|
7
|
+
"React",
|
|
8
|
+
"Next.js",
|
|
9
|
+
"DocsHound",
|
|
10
|
+
"Chat Widget",
|
|
11
|
+
"AI",
|
|
12
|
+
"Customer Support",
|
|
13
|
+
"Documentation",
|
|
14
|
+
"Knowledge Base"
|
|
15
|
+
],
|
|
7
16
|
"author": "DocsHound",
|
|
8
|
-
"files": [
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
9
20
|
"main": "./dist/index.js",
|
|
10
21
|
"module": "./dist/index.esm.js",
|
|
11
22
|
"types": "./dist/index.d.ts",
|
|
@@ -19,6 +30,7 @@
|
|
|
19
30
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
20
31
|
"@rollup/plugin-terser": "^0.4.4",
|
|
21
32
|
"@rollup/plugin-typescript": "^12.1.1",
|
|
33
|
+
"@types/node": "^22.7.8",
|
|
22
34
|
"@types/react": "^18",
|
|
23
35
|
"rollup": "^4.24.0",
|
|
24
36
|
"rollup-plugin-dts": "^6.1.1",
|