@inkeep/cxkit-primitives 0.5.2 → 0.5.4
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/dist/atoms/link.cjs +1 -1
- package/dist/atoms/link.js +5 -5
- package/dist/components/chat-button.cjs +1 -1
- package/dist/components/chat-button.js +21 -21
- package/dist/components/embedded-chat/use-captcha.cjs +1 -1
- package/dist/components/embedded-chat/use-captcha.d.cts +2 -2
- package/dist/components/embedded-chat/use-captcha.d.ts +2 -2
- package/dist/components/embedded-chat/use-captcha.js +1 -1
- package/dist/components/embedded-chat/use-chat-action.cjs +1 -1
- package/dist/components/embedded-chat/use-chat-action.js +9 -9
- package/dist/components/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/components/embedded-chat/use-inkeep-chat.js +39 -39
- package/dist/components/embedded-chat.cjs +4 -4
- package/dist/components/embedded-chat.d.cts +6 -6
- package/dist/components/embedded-chat.d.ts +6 -6
- package/dist/components/embedded-chat.js +707 -708
- package/dist/components/embedded-search/transform-results.cjs +1 -1
- package/dist/components/embedded-search/transform-results.js +3 -3
- package/dist/components/embedded-search/use-inkeep-search.cjs +1 -1
- package/dist/components/embedded-search/use-inkeep-search.js +36 -36
- package/dist/components/embedded-search.cjs +1 -1
- package/dist/components/embedded-search.js +60 -60
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.cjs +1 -1
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.js +35 -35
- package/dist/components/intelligent-form.cjs +1 -1
- package/dist/components/intelligent-form.d.cts +3 -3
- package/dist/components/intelligent-form.d.ts +3 -3
- package/dist/components/intelligent-form.js +106 -106
- package/dist/components/modal/modal-provider.d.cts +1 -1
- package/dist/components/modal/modal-provider.d.ts +1 -1
- package/dist/components/modal/use-inkeep-modal.cjs +1 -1
- package/dist/components/modal/use-inkeep-modal.d.cts +1 -1
- package/dist/components/modal/use-inkeep-modal.d.ts +1 -1
- package/dist/components/modal/use-inkeep-modal.js +4 -4
- package/dist/components/modal.cjs +1 -1
- package/dist/components/modal.js +5 -5
- package/dist/hooks/use-browser-storage.cjs +1 -1
- package/dist/hooks/use-browser-storage.js +6 -6
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +22 -22
- package/dist/providers/chat-events-provider.cjs +1 -1
- package/dist/providers/chat-events-provider.js +46 -39
- package/dist/providers/chat-form-provider.cjs +1 -1
- package/dist/providers/chat-form-provider.js +40 -40
- package/dist/providers/config-provider.cjs +1 -1
- package/dist/providers/config-provider.d.cts +7 -7
- package/dist/providers/config-provider.d.ts +7 -7
- package/dist/providers/config-provider.js +24 -24
- package/dist/providers/feedback-provider.cjs +1 -1
- package/dist/providers/feedback-provider.js +10 -10
- package/dist/providers/root-provider.cjs +1 -1
- package/dist/providers/root-provider.d.cts +1 -1
- package/dist/providers/root-provider.d.ts +1 -1
- package/dist/providers/root-provider.js +2 -2
- package/dist/providers/theme-provider.cjs +1 -1
- package/dist/providers/theme-provider.js +32 -30
- package/dist/providers/user-provider.cjs +1 -1
- package/dist/providers/user-provider.js +14 -14
- package/dist/utils/default-settings.cjs +1 -1
- package/dist/utils/default-settings.d.cts +20 -20
- package/dist/utils/default-settings.d.ts +20 -20
- package/dist/utils/default-settings.js +32 -31
- package/dist/utils/form.cjs +1 -1
- package/dist/utils/form.js +11 -11
- package/package.json +5 -5
package/dist/atoms/link.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),o=require("react"),f=require("../providers/config-provider.cjs"),i=o.forwardRef(({isExternal:e,...r},n)=>s.jsx("a",{target:e?"_blank":void 0,rel:e?"noopener":void 0,...r,ref:n}));i.displayName="Link";const a=o.forwardRef(({href:e,appendToUrl:r,...n},t)=>{const{baseSettings:c}=f.useInkeepConfig(),u=Object.assign({},c.urlQueryParamsToAppend,r),d=e&&p(e,u);return s.jsx(i,{ref:t,href:d,...n})});a.displayName="LinkWithQueryParams";function p(e,r){if(!r)return e;try{const n=new URL(e);for(const t of Object.keys(r))r[t]&&n.searchParams.append(t,r[t]);return n.href}catch{return e}}exports.Link=i;exports.LinkWithQueryParams=a;
|
package/dist/atoms/link.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as o } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef as a } from "react";
|
|
4
4
|
import { useInkeepConfig as d } from "../providers/config-provider.js";
|
|
5
|
-
const
|
|
5
|
+
const i = a(({ isExternal: e, ...r }, n) => /* @__PURE__ */ o(
|
|
6
6
|
"a",
|
|
7
7
|
{
|
|
8
8
|
target: e ? "_blank" : void 0,
|
|
@@ -11,10 +11,10 @@ const s = a(({ isExternal: e, ...r }, n) => /* @__PURE__ */ o(
|
|
|
11
11
|
ref: n
|
|
12
12
|
}
|
|
13
13
|
));
|
|
14
|
-
|
|
14
|
+
i.displayName = "Link";
|
|
15
15
|
const f = a(({ href: e, appendToUrl: r, ...n }, t) => {
|
|
16
|
-
const { baseSettings:
|
|
17
|
-
return /* @__PURE__ */ o(
|
|
16
|
+
const { baseSettings: s } = d(), c = Object.assign({}, s.urlQueryParamsToAppend, r), p = e && m(e, c);
|
|
17
|
+
return /* @__PURE__ */ o(i, { ref: t, href: p, ...n });
|
|
18
18
|
});
|
|
19
19
|
f.displayName = "LinkWithQueryParams";
|
|
20
20
|
function m(e, r) {
|
|
@@ -30,6 +30,6 @@ function m(e, r) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
i as Link,
|
|
34
34
|
f as LinkWithQueryParams
|
|
35
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),u=require("react"),h=require("@radix-ui/react-avatar"),n=require("./factory.cjs"),l=require("../atoms/avatars/ai.cjs"),B=require("../providers/config-provider.cjs"),f=require("../utils/compose-event-handlers.cjs");function _(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(a,e,o.get?o:{enumerable:!0,get:()=>t[e]})}}return a.default=t,Object.freeze(a)}const d=_(h),p=n.ikp("div",{_id:"chatButton__Container"}),A=n.ikp("button",{_id:"chatButton__Button"}),P=n.ikp("div",{_id:"chatButton__Text"}),b=n.ikp(d.Root,{_id:"chatButton__AvatarContent"}),k=n.ikp(d.Image,{_id:"chatButton__AvatarImage"}),m=u.memo(t=>{const{onLoadingStatusChange:a,...e}=t,{aiChatSettings:o}=B.useInkeepConfig(),{aiAssistantAvatar:i}=o??{},r=typeof i=="string"?i:i?.dark,[s,c]=u.useState(r);u.useEffect(()=>{c(r)},[r]);const g=C=>{C==="error"&&c(null)};return s?v.jsx(k,{src:s,"data-type":"image",onLoadingStatusChange:f.composeEventHandlers(a,g),...e}):v.jsx(l.default,{"data-type":"icon",...t})});exports.ChatButton=A;exports.ChatButtonAvatarContent=b;exports.ChatButtonAvatarImage=m;exports.ChatButtonContainer=p;exports.ChatButtonPrimitiveAvatarImage=m;exports.ChatButtonText=P;
|
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { memo as
|
|
4
|
-
import * as
|
|
2
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { memo as c, useState as v, useEffect as d } from "react";
|
|
4
|
+
import * as s from "@radix-ui/react-avatar";
|
|
5
5
|
import { ikp as t } from "./factory.js";
|
|
6
6
|
import g from "../atoms/avatars/ai.js";
|
|
7
|
-
import { useInkeepConfig as
|
|
8
|
-
import { composeEventHandlers as
|
|
7
|
+
import { useInkeepConfig as B } from "../providers/config-provider.js";
|
|
8
|
+
import { composeEventHandlers as _ } from "../utils/compose-event-handlers.js";
|
|
9
9
|
const k = t("div", {
|
|
10
10
|
_id: "chatButton__Container"
|
|
11
11
|
}), L = t("button", {
|
|
12
12
|
_id: "chatButton__Button"
|
|
13
|
-
}),
|
|
13
|
+
}), y = t("div", {
|
|
14
14
|
_id: "chatButton__Text"
|
|
15
|
-
}), T = t(
|
|
15
|
+
}), T = t(s.Root, {
|
|
16
16
|
_id: "chatButton__AvatarContent"
|
|
17
|
-
}), f = t(
|
|
17
|
+
}), f = t(s.Image, {
|
|
18
18
|
_id: "chatButton__AvatarImage"
|
|
19
|
-
}),
|
|
20
|
-
const { onLoadingStatusChange:
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
}, [
|
|
19
|
+
}), U = c((n) => {
|
|
20
|
+
const { onLoadingStatusChange: m, ...u } = n, { aiChatSettings: h } = B(), { aiAssistantAvatar: a } = h ?? {}, o = typeof a == "string" ? a : a?.dark, [i, e] = v(o);
|
|
21
|
+
return d(() => {
|
|
22
|
+
e(o);
|
|
23
|
+
}, [o]), i ? /* @__PURE__ */ r(
|
|
24
24
|
f,
|
|
25
25
|
{
|
|
26
|
-
src:
|
|
26
|
+
src: i,
|
|
27
27
|
"data-type": "image",
|
|
28
|
-
onLoadingStatusChange:
|
|
29
|
-
|
|
28
|
+
onLoadingStatusChange: _(m, (C) => {
|
|
29
|
+
C === "error" && e(null);
|
|
30
30
|
}),
|
|
31
|
-
...
|
|
31
|
+
...u
|
|
32
32
|
}
|
|
33
|
-
) : /* @__PURE__ */
|
|
33
|
+
) : /* @__PURE__ */ r(g, { "data-type": "icon", ...n });
|
|
34
34
|
});
|
|
35
35
|
export {
|
|
36
36
|
L as ChatButton,
|
|
37
37
|
T as ChatButtonAvatarContent,
|
|
38
|
-
|
|
38
|
+
U as ChatButtonAvatarImage,
|
|
39
39
|
k as ChatButtonContainer,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
U as ChatButtonPrimitiveAvatarImage,
|
|
41
|
+
y as ChatButtonText
|
|
42
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("altcha-lib"),l=require("react"),f={getSolution:async()=>{},prefetchSolution:()=>{},invalidateSolution:()=>{}},u=async n=>{try{const t=await fetch(n,{method:"GET"});if(!t.ok)throw new Error(`Failed to fetch challenge: ${t.statusText}`);const o=await t.json(),{challenge:e,algorithm:r,salt:c,maxnumber:s}=o,{promise:a}=await h.solveChallenge(e,c,r,s),i=await a||void 0;if(!i)throw new Error("Challenge not solved");return{number:i.number,...o}}catch(t){console.error("Error solving captcha:",t)}},g=({fetchUrl:n,
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("altcha-lib"),l=require("react"),f={getSolution:async()=>{},prefetchSolution:()=>{},invalidateSolution:()=>{}},u=async n=>{try{const t=await fetch(n,{method:"GET"});if(!t.ok)throw new Error(`Failed to fetch challenge: ${t.statusText}`);const o=await t.json(),{challenge:e,algorithm:r,salt:c,maxnumber:s}=o,{promise:a}=await h.solveChallenge(e,c,r,s),i=await a||void 0;if(!i)throw new Error("Challenge not solved");return{number:i.number,...o}}catch(t){console.error("Error solving captcha:",t)}},g=({fetchUrl:n,shouldBypassCaptcha:t=!1,shouldMakeInitialRequest:o=!0})=>{if(t)return f;const e=l.useRef(null),r=l.useCallback(()=>{e.current||(e.current=u(n))},[n]),c=l.useCallback(async()=>{let a=await e.current;return a||(e.current=u(n),a=await e.current),e.current=null,a},[n]),s=l.useCallback(()=>{e.current=null},[]);return l.useEffect(()=>{o&&r()},[r,o]),{getSolution:c,prefetchSolution:r,invalidateSolution:s}};exports.fetchAndSolveChallenge=u;exports.useCaptcha=g;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Payload } from 'altcha-lib/types';
|
|
2
2
|
interface UseCaptchaOptions {
|
|
3
3
|
fetchUrl: string;
|
|
4
|
-
|
|
4
|
+
shouldBypassCaptcha?: boolean;
|
|
5
5
|
shouldMakeInitialRequest?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare const fetchAndSolveChallenge: (fetchUrl: string) => Promise<Payload | undefined>;
|
|
8
|
-
export declare const useCaptcha: ({ fetchUrl,
|
|
8
|
+
export declare const useCaptcha: ({ fetchUrl, shouldBypassCaptcha, shouldMakeInitialRequest, }: UseCaptchaOptions) => {
|
|
9
9
|
getSolution: () => Promise<Payload | undefined>;
|
|
10
10
|
prefetchSolution: () => void;
|
|
11
11
|
invalidateSolution: () => void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Payload } from 'altcha-lib/types';
|
|
2
2
|
interface UseCaptchaOptions {
|
|
3
3
|
fetchUrl: string;
|
|
4
|
-
|
|
4
|
+
shouldBypassCaptcha?: boolean;
|
|
5
5
|
shouldMakeInitialRequest?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare const fetchAndSolveChallenge: (fetchUrl: string) => Promise<Payload | undefined>;
|
|
8
|
-
export declare const useCaptcha: ({ fetchUrl,
|
|
8
|
+
export declare const useCaptcha: ({ fetchUrl, shouldBypassCaptcha, shouldMakeInitialRequest, }: UseCaptchaOptions) => {
|
|
9
9
|
getSolution: () => Promise<Payload | undefined>;
|
|
10
10
|
prefetchSolution: () => void;
|
|
11
11
|
invalidateSolution: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../providers/conversation-provider.cjs"),u=require("../../providers/chat-events-provider.cjs"),d=require("../../providers/chat-form-provider.cjs"),p=require("../modal/modal-provider.cjs"),v=e=>{const{logEvent:t}=u.useChatEvents(),{conversation:o}=c.useInkeepConversation(),{openForm:r}=d.useChatForm(),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../providers/conversation-provider.cjs"),u=require("../../providers/chat-events-provider.cjs"),d=require("../../providers/chat-form-provider.cjs"),p=require("../modal/modal-provider.cjs"),v=e=>{const{logEvent:t}=u.useChatEvents(),{conversation:o}=c.useInkeepConversation(),{openForm:r}=d.useChatForm(),i=p.useModal(),s=a=>{e.action.type==="open_form"?(a?.onOpenForm?.(),r?.(e.action.formConfig)):e.action.type==="invoke_callback"&&(e.action.callback({conversation:o}),e.action.shouldCloseModal&&i?.closeModal())},n=e.action.type,l=n==="open_link"?e.action.url:void 0;return{handleAction:s,logHelpAction:()=>{"name"in e&&t({eventName:"get_help_option_clicked",properties:{actionType:n,name:e.name,url:l,conversationId:o.id}})}}};exports.useChatAction=v;
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
import { useInkeepConversation as a } from "../../providers/conversation-provider.js";
|
|
3
3
|
import { useChatEvents as m } from "../../providers/chat-events-provider.js";
|
|
4
4
|
import { useChatForm as c } from "../../providers/chat-form-provider.js";
|
|
5
|
-
import { useModal as
|
|
6
|
-
const
|
|
7
|
-
const { logEvent: t } = m(), { conversation: e } = a(), { openForm:
|
|
8
|
-
o.action.type === "
|
|
5
|
+
import { useModal as f } from "../modal/modal-provider.js";
|
|
6
|
+
const _ = (o) => {
|
|
7
|
+
const { logEvent: t } = m(), { conversation: e } = a(), { openForm: i } = c(), r = f(), l = (p) => {
|
|
8
|
+
o.action.type === "open_form" ? (p?.onOpenForm?.(), i?.(o.action.formConfig)) : o.action.type === "invoke_callback" && (o.action.callback({
|
|
9
9
|
conversation: e
|
|
10
|
-
}), o.action.shouldCloseModal &&
|
|
11
|
-
}, n = o.action.type,
|
|
12
|
-
return { handleAction:
|
|
10
|
+
}), o.action.shouldCloseModal && r?.closeModal());
|
|
11
|
+
}, n = o.action.type, s = n === "open_link" ? o.action.url : void 0;
|
|
12
|
+
return { handleAction: l, logHelpAction: () => {
|
|
13
13
|
"name" in o && t({
|
|
14
14
|
eventName: "get_help_option_clicked",
|
|
15
15
|
properties: {
|
|
16
16
|
actionType: n,
|
|
17
17
|
name: o.name,
|
|
18
|
-
url:
|
|
18
|
+
url: s,
|
|
19
19
|
conversationId: e.id
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
} };
|
|
23
23
|
};
|
|
24
24
|
export {
|
|
25
|
-
|
|
25
|
+
_ as useChatAction
|
|
26
26
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("openai"),t=require("react"),qe=require("../../atoms/api/analytics/conversation.cjs"),Pe=require("../../providers/config-provider.cjs"),Ee=require("../../providers/conversation-provider.cjs"),_e=require("../../providers/chat-events-provider.cjs"),$=require("../../utils/get-message-metadata.cjs"),V=require("../../utils/misc.cjs"),X=require("../../utils/reset-query-params.cjs"),Ne=require("../../providers/chat-form-provider.cjs"),Re=require("../../providers/widget-provider.cjs"),Ae=require("../../hooks/use-media-query.cjs"),Le=require("./use-captcha.cjs"),$e=require("../modal/modal-provider.cjs"),xe=()=>{const{chatId:m,setConversation:Y,conversation:Z,resetConversation:ee}=Ee.useInkeepConversation(),{baseSettings:k,aiChatSettings:x}=Pe.useInkeepConfig(),{
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const be=require("openai"),t=require("react"),qe=require("../../atoms/api/analytics/conversation.cjs"),Pe=require("../../providers/config-provider.cjs"),Ee=require("../../providers/conversation-provider.cjs"),_e=require("../../providers/chat-events-provider.cjs"),$=require("../../utils/get-message-metadata.cjs"),V=require("../../utils/misc.cjs"),X=require("../../utils/reset-query-params.cjs"),Ne=require("../../providers/chat-form-provider.cjs"),Re=require("../../providers/widget-provider.cjs"),Ae=require("../../hooks/use-media-query.cjs"),Le=require("./use-captcha.cjs"),$e=require("../modal/modal-provider.cjs"),xe=()=>{const{chatId:m,setConversation:Y,conversation:Z,resetConversation:ee}=Ee.useInkeepConversation(),{baseSettings:k,aiChatSettings:x}=Pe.useInkeepConfig(),{aiApiBaseUrl:D,shouldBypassCaptcha:O}=k,U=$e.useModal(),{getSolution:te,prefetchSolution:b,invalidateSolution:K}=Le.useCaptcha({fetchUrl:`${D}/v1/challenge`,shouldBypassCaptcha:O,shouldMakeInitialRequest:U?U.isOpen:!0}),se=new be({baseURL:`${D}/v1`,apiKey:k.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:ne,tools:oe,prompts:ae,model:re,onToolCall:ie}=x,[h,_]=t.useState(""),T=t.useRef(null);t.useEffect(()=>{ne?.(h)},[h]);const[u,l]=t.useState([]),[B,p]=t.useState(!1),[ce,f]=t.useState(!1),[le,F]=t.useState(null),[v,Q]=t.useState(null),[I,y]=t.useState([]),ue=e=>{y(n=>[...n,e])},[de,W]=t.useState({}),i=t.useRef([]),S=t.useRef(null),{logEvent:q}=_e.useChatEvents(),z=ae?.map((e,n)=>({id:`system-${n}`,role:"system",content:e})),[ge,me]=t.useState(!!m);t.useEffect(()=>{if(m){const{apiKey:e,analyticsApiBaseUrl:n}=k;q({eventName:"chat_shared_session_loaded",properties:{conversationId:m}}),qe.getConversation(m,e,n).then(o=>{if(o){me(!1),Y({...o,id:""});const a=o.messages.map(c=>({id:Date.now().toString()+c.id,content:V.parseIfJson(c.content),role:c.role,links:c.links}));l(a),i.current=a}})}},[m]);const he=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${k.organizationDisplayName??"Administrator"}`;default:return`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`}},H=e=>{
|
|
4
|
-
${$.serializeWorkflow(e)}`},...
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},H=e=>{F(e),l(n=>{const o=[...n],a=o[o.length-1];return a&&(a.content=he(e)),o}),p(!1),f(!1),K(),b()},N=!h.trim()&&!I.length||B,pe=e=>{e.key==="Enter"&&!e.shiftKey&&!N&&!e.nativeEvent.isComposing&&(e.preventDefault(),R())},fe=e=>{const n=e.target.value;_(n)},R=async(e=h)=>{if(N&&(!e||e.trim().length===0))return;p(!0);const n=v?u.length===2:u.length===0,o=$.getMessageMetadata(v,I,n);let a;const c=$.serializeAttachments(I);I.length&&c?a=[{type:"text",text:c}]:a=e;const P={id:`${Date.now().toString()}1`,role:"user",content:a,metadata:o},E=[...u.length?[]:z,P];m&&X.resetQueryParams(),l(C=>[...C,...E]),i.current=[...i.current,...E],y([]),_(""),q({eventName:"chat_message_submitted",properties:{messages:i.current,messageId:P.id,content:e,workflowId:v?.id}});try{const C={model:re,messages:i.current,stream:!0,tools:oe,tool_choice:"auto"},j=await te(),Me=j?btoa(JSON.stringify(j)):null,G=O?void 0:{"X-INKEEP-CHALLENGE-SOLUTION":Me},M=se.beta.chat.completions.stream(C,G?{headers:G}:void 0),s={id:`${Date.now().toString()}2`,role:"assistant",content:"",links:[]};l(d=>[...d,s]),M.on("content",(d,A)=>{f(!0),s.content=A,l(L=>{const r=[...L],g=r.findIndex(w=>w.id===s.id);return g===-1?[...r,s]:(r[g]={...s},r)})}),M.on("tool_calls.function.arguments.done",d=>{const{name:A,arguments:L}=d;if(A==="provideLinks"){const r=JSON.parse(L);r.links?.length>0&&(s.links=r.links,l(g=>{const w=[...g],we=w.findIndex(ke=>ke.id===s.id);return w[we]={...s},w}))}else{const r=ie?.(d);r&&W(g=>({...g,[s.id]:[...g[s.id]||[],r]}))}}),M.on("error",d=>{H(d)}),M.finalChatCompletion().then(()=>{i.current=[...i.current,s],S.current=null,p(!1),f(!1),b(),q({eventName:"chat_message_bot_response_received",properties:{messages:i.current,messageId:s.id,question:V.getMessageContent(P),responseMessage:s,linksUsedInResponse:s.links,workflowId:v?.id}})}),S.current=M.controller}catch(C){H(C),p(!1),f(!1)}},ve=()=>{S.current&&(S.current.abort(),S.current=null),p(!1),f(!1),b()},J=()=>{F(null),l([]),i.current=[],ee(),W({}),y([]),X.resetQueryParams(),Q(null),K(),b(),q({eventName:"chat_history_cleared",properties:{conversationId:Z.id}})},Ie=e=>{Q(e);const{initialReplyMessage:n,displayName:o}=e,a={id:u.length.toString(),role:"user",content:o},c={id:(u.length+1).toString(),role:"assistant",content:n,links:[]},E=[{id:`system-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
|
+
${$.serializeWorkflow(e)}`},...z,a,c];l(E),y([])},{openForm:ye}=Ne.useChatForm(),Se=Re.useWidget();t.useImperativeHandle(x.chatFunctionsRef,()=>({submitMessage:R,updateInputMessage(e){_(e)},clearChat:J,openForm:e=>{Se?.setView("chat"),ye(e)},focusInput:()=>{T.current?.focus()}}));const Ce=Ae.useMediaQuery("(max-width: 768px)");return{messages:u,input:h,isLoading:B,isStreaming:ce,isLoadingConversation:ge,error:le,isSubmitDisabled:N,handleInputChange:fe,handleInputKeyDown:pe,handleSubmit:R,stop:ve,clear:J,handleWorkflow:Ie,selectedWorkflow:v,messageAttachments:I,setMessageAttachments:y,addAttachment:ue,messageToolCalls:de,isEmpty:u.length===0,inputRef:T,isMobile:Ce}};exports.useInkeepChat=xe;
|
|
@@ -3,39 +3,39 @@ import be from "openai";
|
|
|
3
3
|
import { useState as c, useRef as D, useEffect as X, useImperativeHandle as _e } from "react";
|
|
4
4
|
import { getConversation as Ee } from "../../atoms/api/analytics/conversation.js";
|
|
5
5
|
import { useInkeepConfig as Ne } from "../../providers/config-provider.js";
|
|
6
|
-
import { useInkeepConversation as
|
|
7
|
-
import { useChatEvents as
|
|
6
|
+
import { useInkeepConversation as Ae } from "../../providers/conversation-provider.js";
|
|
7
|
+
import { useChatEvents as xe } from "../../providers/chat-events-provider.js";
|
|
8
8
|
import { getMessageMetadata as Le, serializeAttachments as Re, serializeWorkflow as $e } from "../../utils/get-message-metadata.js";
|
|
9
9
|
import { parseIfJson as De, getMessageContent as Pe } from "../../utils/misc.js";
|
|
10
10
|
import { resetQueryParams as j } from "../../utils/reset-query-params.js";
|
|
11
11
|
import { useChatForm as Ue } from "../../providers/chat-form-provider.js";
|
|
12
12
|
import { useWidget as Ke } from "../../providers/widget-provider.js";
|
|
13
13
|
import { useMediaQuery as Oe } from "../../hooks/use-media-query.js";
|
|
14
|
-
import { useCaptcha as
|
|
15
|
-
import { useModal as
|
|
14
|
+
import { useCaptcha as Be } from "./use-captcha.js";
|
|
15
|
+
import { useModal as Te } from "../modal/modal-provider.js";
|
|
16
16
|
const tt = () => {
|
|
17
|
-
const { chatId: g, setConversation: Y, conversation: Z, resetConversation: ee } =
|
|
17
|
+
const { chatId: g, setConversation: Y, conversation: Z, resetConversation: ee } = Ae(), { baseSettings: S, aiChatSettings: P } = Ne(), { aiApiBaseUrl: U, shouldBypassCaptcha: K } = S, O = Te(), { getSolution: te, prefetchSolution: b, invalidateSolution: B } = Be({
|
|
18
18
|
fetchUrl: `${U}/v1/challenge`,
|
|
19
|
-
|
|
20
|
-
shouldMakeInitialRequest: O ? O.
|
|
19
|
+
shouldBypassCaptcha: K,
|
|
20
|
+
shouldMakeInitialRequest: O ? O.isOpen : !0
|
|
21
21
|
}), se = new be({
|
|
22
22
|
baseURL: `${U}/v1`,
|
|
23
23
|
apiKey: S.apiKey,
|
|
24
24
|
dangerouslyAllowBrowser: !0
|
|
25
|
-
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } = P, [p,
|
|
25
|
+
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } = P, [p, A] = c(""), T = D(null);
|
|
26
26
|
X(() => {
|
|
27
27
|
ne?.(p);
|
|
28
28
|
}, [p]);
|
|
29
|
-
const [
|
|
29
|
+
const [u, l] = c([]), [W, f] = c(!1), [ce, h] = c(!1), [le, F] = c(null), [I, z] = c(null), [w, y] = c([]), ue = (e) => {
|
|
30
30
|
y((s) => [...s, e]);
|
|
31
|
-
}, [
|
|
31
|
+
}, [me, H] = c({}), r = D([]), C = D(null), { logEvent: _ } = xe(), J = ae?.map((e, s) => ({
|
|
32
32
|
id: `system-${s}`,
|
|
33
33
|
role: "system",
|
|
34
34
|
content: e
|
|
35
35
|
})), [de, ge] = c(!!g);
|
|
36
36
|
X(() => {
|
|
37
37
|
if (g) {
|
|
38
|
-
const { apiKey: e,
|
|
38
|
+
const { apiKey: e, analyticsApiBaseUrl: s } = S;
|
|
39
39
|
_({
|
|
40
40
|
eventName: "chat_shared_session_loaded",
|
|
41
41
|
properties: {
|
|
@@ -67,19 +67,19 @@ const tt = () => {
|
|
|
67
67
|
It seems I might be having some issues right now. Please clear the chat and try again.`;
|
|
68
68
|
}
|
|
69
69
|
}, q = (e) => {
|
|
70
|
-
|
|
70
|
+
F(e), l((s) => {
|
|
71
71
|
const n = [...s], o = n[n.length - 1];
|
|
72
72
|
return o && (o.content = pe(e)), n;
|
|
73
|
-
}), f(!1), h(!1),
|
|
74
|
-
},
|
|
75
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
73
|
+
}), f(!1), h(!1), B(), b();
|
|
74
|
+
}, x = !p.trim() && !w.length || W, fe = (e) => {
|
|
75
|
+
e.key === "Enter" && !e.shiftKey && !x && !e.nativeEvent.isComposing && (e.preventDefault(), L());
|
|
76
76
|
}, he = (e) => {
|
|
77
77
|
const s = e.target.value;
|
|
78
|
-
|
|
78
|
+
A(s);
|
|
79
79
|
}, L = async (e = p) => {
|
|
80
|
-
if (
|
|
80
|
+
if (x && (!e || e.trim().length === 0)) return;
|
|
81
81
|
f(!0);
|
|
82
|
-
const s = I ?
|
|
82
|
+
const s = I ? u.length === 2 : u.length === 0, n = Le(I, w, s);
|
|
83
83
|
let o;
|
|
84
84
|
const i = Re(w);
|
|
85
85
|
w.length && i ? o = [{ type: "text", text: i }] : o = e;
|
|
@@ -88,8 +88,8 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
88
88
|
role: "user",
|
|
89
89
|
content: o,
|
|
90
90
|
metadata: n
|
|
91
|
-
}, N = [...
|
|
92
|
-
g && j(), l((v) => [...v, ...N]), r.current = [...r.current, ...N], y([]),
|
|
91
|
+
}, N = [...u.length ? [] : J, E];
|
|
92
|
+
g && j(), l((v) => [...v, ...N]), r.current = [...r.current, ...N], y([]), A(""), _({
|
|
93
93
|
eventName: "chat_message_submitted",
|
|
94
94
|
properties: {
|
|
95
95
|
messages: r.current,
|
|
@@ -116,13 +116,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
116
116
|
content: "",
|
|
117
117
|
links: []
|
|
118
118
|
};
|
|
119
|
-
l((
|
|
119
|
+
l((m) => [...m, t]), M.on("content", (m, R) => {
|
|
120
120
|
h(!0), t.content = R, l(($) => {
|
|
121
121
|
const a = [...$], d = a.findIndex((k) => k.id === t.id);
|
|
122
122
|
return d === -1 ? [...a, t] : (a[d] = { ...t }, a);
|
|
123
123
|
});
|
|
124
|
-
}), M.on("tool_calls.function.arguments.done", (
|
|
125
|
-
const { name: R, arguments: $ } =
|
|
124
|
+
}), M.on("tool_calls.function.arguments.done", (m) => {
|
|
125
|
+
const { name: R, arguments: $ } = m;
|
|
126
126
|
if (R === "provideLinks") {
|
|
127
127
|
const a = JSON.parse($);
|
|
128
128
|
a.links?.length > 0 && (t.links = a.links, l((d) => {
|
|
@@ -130,14 +130,14 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
130
130
|
return k[ke] = { ...t }, k;
|
|
131
131
|
}));
|
|
132
132
|
} else {
|
|
133
|
-
const a = ie?.(
|
|
133
|
+
const a = ie?.(m);
|
|
134
134
|
a && H((d) => ({
|
|
135
135
|
...d,
|
|
136
136
|
[t.id]: [...d[t.id] || [], a]
|
|
137
137
|
}));
|
|
138
138
|
}
|
|
139
|
-
}), M.on("error", (
|
|
140
|
-
q(
|
|
139
|
+
}), M.on("error", (m) => {
|
|
140
|
+
q(m);
|
|
141
141
|
}), M.finalChatCompletion().then(() => {
|
|
142
142
|
r.current = [...r.current, t], C.current = null, f(!1), h(!1), b(), _({
|
|
143
143
|
eventName: "chat_message_bot_response_received",
|
|
@@ -157,20 +157,20 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
157
157
|
}, Ie = () => {
|
|
158
158
|
C.current && (C.current.abort(), C.current = null), f(!1), h(!1), b();
|
|
159
159
|
}, Q = () => {
|
|
160
|
-
|
|
160
|
+
F(null), l([]), r.current = [], ee(), H({}), y([]), j(), z(null), B(), b(), _({
|
|
161
161
|
eventName: "chat_history_cleared",
|
|
162
162
|
properties: {
|
|
163
163
|
conversationId: Z.id
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
}, we = (e) => {
|
|
167
|
-
|
|
167
|
+
z(e);
|
|
168
168
|
const { initialReplyMessage: s, displayName: n } = e, o = {
|
|
169
|
-
id:
|
|
169
|
+
id: u.length.toString(),
|
|
170
170
|
role: "user",
|
|
171
171
|
content: n
|
|
172
172
|
}, i = {
|
|
173
|
-
id: (
|
|
173
|
+
id: (u.length + 1).toString(),
|
|
174
174
|
role: "assistant",
|
|
175
175
|
content: s,
|
|
176
176
|
links: []
|
|
@@ -187,25 +187,25 @@ ${$e(
|
|
|
187
187
|
_e(P.chatFunctionsRef, () => ({
|
|
188
188
|
submitMessage: L,
|
|
189
189
|
updateInputMessage(e) {
|
|
190
|
-
|
|
190
|
+
A(e);
|
|
191
191
|
},
|
|
192
192
|
clearChat: Q,
|
|
193
193
|
openForm: (e) => {
|
|
194
194
|
Ce?.setView("chat"), ye(e);
|
|
195
195
|
},
|
|
196
196
|
focusInput: () => {
|
|
197
|
-
|
|
197
|
+
T.current?.focus();
|
|
198
198
|
}
|
|
199
199
|
}));
|
|
200
200
|
const ve = Oe("(max-width: 768px)");
|
|
201
201
|
return {
|
|
202
|
-
messages:
|
|
202
|
+
messages: u,
|
|
203
203
|
input: p,
|
|
204
|
-
isLoading:
|
|
204
|
+
isLoading: W,
|
|
205
205
|
isStreaming: ce,
|
|
206
206
|
isLoadingConversation: de,
|
|
207
207
|
error: le,
|
|
208
|
-
isSubmitDisabled:
|
|
208
|
+
isSubmitDisabled: x,
|
|
209
209
|
handleInputChange: he,
|
|
210
210
|
handleInputKeyDown: fe,
|
|
211
211
|
handleSubmit: L,
|
|
@@ -215,10 +215,10 @@ ${$e(
|
|
|
215
215
|
selectedWorkflow: I,
|
|
216
216
|
messageAttachments: w,
|
|
217
217
|
setMessageAttachments: y,
|
|
218
|
-
addAttachment:
|
|
219
|
-
messageToolCalls:
|
|
220
|
-
isEmpty:
|
|
221
|
-
inputRef:
|
|
218
|
+
addAttachment: ue,
|
|
219
|
+
messageToolCalls: me,
|
|
220
|
+
isEmpty: u.length === 0,
|
|
221
|
+
inputRef: T,
|
|
222
222
|
isMobile: ve
|
|
223
223
|
};
|
|
224
224
|
};
|