@inkeep/agents-ui 0.15.18 → 0.15.19
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/primitives/components/chat-history/index.cjs +1 -1
- package/dist/primitives/components/chat-history/index.d.ts +1 -1
- package/dist/primitives/components/chat-history/index.js +65 -64
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +156 -145
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/types/events.d.ts +8 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),a=require("react"),e=require("../factory.cjs"),s=require("../../providers/chat-history-provider.cjs"),x=require("../../utils/misc.cjs"),m=require("../../utils/compose-event-handlers.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),a=require("react"),e=require("../factory.cjs"),s=require("../../providers/chat-history-provider.cjs"),x=require("../../providers/chat-form-provider.cjs"),E=require("../../utils/misc.cjs"),m=require("../../utils/compose-event-handlers.cjs"),T=require("../../atoms/icons/custom-icon.cjs"),w=e.ikp("div",{_id:"aiChatHistory"}),H=t=>{const{isOpen:i}=s.useChatHistory(),{form:o}=x.useChatForm();return o?null:r.jsx(w,{"data-hidden":E.dataAttr(!i),...t})},d=e.ikp("div",{_id:"aiChatHistory__Header"}),R=e.ikp(T.CustomIcon,{_id:"aiChatHistory__BackButtonIcon"}),l=a.memo(t=>r.jsx(R,{...t,iconKey:"backToChat"})),q=e.ikp("button",{_id:"aiChatHistory__BackButton"}),P=({onClick:t,...i})=>{const{setIsOpen:o}=s.useChatHistory();return r.jsx(q,{type:"button",onClick:m.composeEventHandlers(t,()=>o(!1)),...i})},_=e.ikp("h2",{_id:"aiChatHistory__Title"}),F=e.ikp("div",{_id:"aiChatHistory__List"}),p=a.forwardRef(({children:t,...i},o)=>{const{hasMore:n,loadMore:u,isLoading:h,sessions:b}=s.useChatHistory(),y=a.useRef(null),c=b.length>0&&n;return a.useEffect(()=>{const C=y.current;if(!C||!c)return;const v=new IntersectionObserver(j=>{j[0]?.isIntersecting&&n&&!h&&u()},{threshold:.1});return v.observe(C),()=>v.disconnect()},[n,h,u,c]),r.jsxs(F,{ref:o,...i,children:[t,c&&r.jsx("div",{ref:y,"data-part":"sentinel","aria-hidden":"true",style:{height:1}})]})}),N=e.ikp("button",{_id:"aiChatHistory__Item"}),k=a.memo(({sessionId:t,onClick:i,...o})=>{const{loadSession:n}=s.useChatHistory();return r.jsx(N,{type:"button",onClick:m.composeEventHandlers(i,()=>n(t)),...o})}),B=e.ikp("span",{_id:"aiChatHistory__ItemTitle"}),I=e.ikp("span",{_id:"aiChatHistory__ItemDate"}),D=e.ikp("div",{_id:"aiChatHistory__EmptyState"}),f=t=>{const{sessions:i,isLoading:o}=s.useChatHistory();return i.length>0||o?null:r.jsx(D,{...t})},O=e.ikp("div",{_id:"aiChatHistory__LoadingState"}),g=t=>{const{isLoading:i}=s.useChatHistory();return i?r.jsx(O,{...t}):null},S=e.ikp("div",{_id:"aiChatHistory__Footer"}),M=e.ikp("button",{_id:"aiChatHistory__NewConversationButton"}),L=({onClick:t,...i})=>{const{startNewConversation:o}=s.useChatHistory();return r.jsx(M,{type:"button",onClick:m.composeEventHandlers(t,o),...i})};exports.BackButton=P;exports.BackButtonIcon=l;exports.ChatHistoryPrimitiveBackButton=P;exports.ChatHistoryPrimitiveBackButtonIcon=l;exports.ChatHistoryPrimitiveEmptyState=f;exports.ChatHistoryPrimitiveFooter=S;exports.ChatHistoryPrimitiveHeader=d;exports.ChatHistoryPrimitiveItem=k;exports.ChatHistoryPrimitiveItemDate=I;exports.ChatHistoryPrimitiveItemTitle=B;exports.ChatHistoryPrimitiveList=p;exports.ChatHistoryPrimitiveLoadingState=g;exports.ChatHistoryPrimitiveNewConversationButton=L;exports.ChatHistoryPrimitiveRoot=H;exports.ChatHistoryPrimitiveTitle=_;exports.EmptyState=f;exports.Footer=S;exports.Header=d;exports.Item=k;exports.ItemDate=I;exports.ItemTitle=B;exports.List=p;exports.LoadingState=g;exports.NewConversationButton=L;exports.Root=H;exports.Title=_;
|
|
@@ -2,7 +2,7 @@ import { ComponentPropsWithRef, ForwardRefExoticComponent, DetailedHTMLProps, HT
|
|
|
2
2
|
import { PolymorphicProps } from '..';
|
|
3
3
|
import { CustomIconProps } from '../..';
|
|
4
4
|
declare const PrimitiveRoot: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
5
|
-
export declare const ChatHistoryPrimitiveRoot: (props: ComponentPropsWithRef<typeof PrimitiveRoot>) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const ChatHistoryPrimitiveRoot: (props: ComponentPropsWithRef<typeof PrimitiveRoot>) => import("react/jsx-runtime").JSX.Element | null;
|
|
6
6
|
export declare const ChatHistoryPrimitiveHeader: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id"> & Partial<Pick< DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "_id">>>;
|
|
7
7
|
declare const PrimitiveBackButtonIcon: ForwardRefExoticComponent< PolymorphicProps & Omit< CustomIconProps, "_id"> & Partial<Pick< CustomIconProps, "_id">>>;
|
|
8
8
|
export declare const ChatHistoryPrimitiveBackButtonIcon: MemoExoticComponent<(props: ComponentPropsWithRef<typeof PrimitiveBackButtonIcon>) => import("react/jsx-runtime").JSX.Element>;
|
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { memo as
|
|
1
|
+
import { jsx as r, jsxs as H } from "react/jsx-runtime";
|
|
2
|
+
import { memo as v, forwardRef as l, useRef as p, useEffect as f } from "react";
|
|
3
3
|
import { ikp as o } from "../factory.js";
|
|
4
|
-
import { useChatHistory as
|
|
4
|
+
import { useChatHistory as s } from "../../providers/chat-history-provider.js";
|
|
5
|
+
import { useChatForm as P } from "../../providers/chat-form-provider.js";
|
|
5
6
|
import { dataAttr as B } from "../../utils/misc.js";
|
|
6
7
|
import { composeEventHandlers as c } from "../../utils/compose-event-handlers.js";
|
|
7
|
-
import { CustomIcon as
|
|
8
|
-
const
|
|
9
|
-
const { isOpen: i } =
|
|
10
|
-
return /* @__PURE__ */
|
|
11
|
-
},
|
|
8
|
+
import { CustomIcon as I } from "../../atoms/icons/custom-icon.js";
|
|
9
|
+
const k = o("div", { _id: "aiChatHistory" }), A = (t) => {
|
|
10
|
+
const { isOpen: i } = s(), { form: e } = P();
|
|
11
|
+
return e ? null : /* @__PURE__ */ r(k, { "data-hidden": B(!i), ...t });
|
|
12
|
+
}, K = o("div", { _id: "aiChatHistory__Header" }), g = o(I, {
|
|
12
13
|
_id: "aiChatHistory__BackButtonIcon"
|
|
13
|
-
}),
|
|
14
|
-
(t) => /* @__PURE__ */
|
|
15
|
-
),
|
|
14
|
+
}), q = v(
|
|
15
|
+
(t) => /* @__PURE__ */ r(g, { ...t, iconKey: "backToChat" })
|
|
16
|
+
), L = o("button", { _id: "aiChatHistory__BackButton" }), z = ({
|
|
16
17
|
onClick: t,
|
|
17
18
|
...i
|
|
18
19
|
}) => {
|
|
19
|
-
const { setIsOpen: e } =
|
|
20
|
-
return /* @__PURE__ */
|
|
21
|
-
|
|
20
|
+
const { setIsOpen: e } = s();
|
|
21
|
+
return /* @__PURE__ */ r(
|
|
22
|
+
L,
|
|
22
23
|
{
|
|
23
24
|
type: "button",
|
|
24
25
|
onClick: c(t, () => e(!1)),
|
|
25
26
|
...i
|
|
26
27
|
}
|
|
27
28
|
);
|
|
28
|
-
},
|
|
29
|
-
const { hasMore: n, loadMore: m, isLoading: d, sessions: _ } =
|
|
30
|
-
return
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
29
|
+
}, G = o("h2", { _id: "aiChatHistory__Title" }), b = o("div", { _id: "aiChatHistory__List" }), J = l(({ children: t, ...i }, e) => {
|
|
30
|
+
const { hasMore: n, loadMore: m, isLoading: d, sessions: _ } = s(), u = p(null), a = _.length > 0 && n;
|
|
31
|
+
return f(() => {
|
|
32
|
+
const h = u.current;
|
|
33
|
+
if (!h || !a) return;
|
|
34
|
+
const C = new IntersectionObserver(
|
|
34
35
|
(y) => {
|
|
35
36
|
y[0]?.isIntersecting && n && !d && m();
|
|
36
37
|
},
|
|
37
38
|
{ threshold: 0.1 }
|
|
38
39
|
);
|
|
39
|
-
return
|
|
40
|
-
}, [n, d, m, a]), /* @__PURE__ */ H(
|
|
40
|
+
return C.observe(h), () => C.disconnect();
|
|
41
|
+
}, [n, d, m, a]), /* @__PURE__ */ H(b, { ref: e, ...i, children: [
|
|
41
42
|
t,
|
|
42
|
-
a && /* @__PURE__ */
|
|
43
|
+
a && /* @__PURE__ */ r("div", { ref: u, "data-part": "sentinel", "aria-hidden": "true", style: { height: 1 } })
|
|
43
44
|
] });
|
|
44
|
-
}),
|
|
45
|
+
}), S = o("button", { _id: "aiChatHistory__Item" }), Q = v(
|
|
45
46
|
({ sessionId: t, onClick: i, ...e }) => {
|
|
46
|
-
const { loadSession: n } =
|
|
47
|
-
return /* @__PURE__ */
|
|
48
|
-
|
|
47
|
+
const { loadSession: n } = s();
|
|
48
|
+
return /* @__PURE__ */ r(
|
|
49
|
+
S,
|
|
49
50
|
{
|
|
50
51
|
type: "button",
|
|
51
52
|
onClick: c(i, () => n(t)),
|
|
@@ -53,21 +54,21 @@ const I = o("div", { _id: "aiChatHistory" }), j = (t) => {
|
|
|
53
54
|
}
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
|
-
),
|
|
57
|
-
const { sessions: i, isLoading: e } =
|
|
58
|
-
return i.length > 0 || e ? null : /* @__PURE__ */
|
|
59
|
-
},
|
|
60
|
-
const { isLoading: i } =
|
|
61
|
-
return i ? /* @__PURE__ */
|
|
62
|
-
},
|
|
57
|
+
), U = o("span", { _id: "aiChatHistory__ItemTitle" }), V = o("span", { _id: "aiChatHistory__ItemDate" }), w = o("div", { _id: "aiChatHistory__EmptyState" }), W = (t) => {
|
|
58
|
+
const { sessions: i, isLoading: e } = s();
|
|
59
|
+
return i.length > 0 || e ? null : /* @__PURE__ */ r(w, { ...t });
|
|
60
|
+
}, T = o("div", { _id: "aiChatHistory__LoadingState" }), X = (t) => {
|
|
61
|
+
const { isLoading: i } = s();
|
|
62
|
+
return i ? /* @__PURE__ */ r(T, { ...t }) : null;
|
|
63
|
+
}, Y = o("div", { _id: "aiChatHistory__Footer" }), E = o("button", {
|
|
63
64
|
_id: "aiChatHistory__NewConversationButton"
|
|
64
|
-
}),
|
|
65
|
+
}), Z = ({
|
|
65
66
|
onClick: t,
|
|
66
67
|
...i
|
|
67
68
|
}) => {
|
|
68
|
-
const { startNewConversation: e } =
|
|
69
|
-
return /* @__PURE__ */
|
|
70
|
-
|
|
69
|
+
const { startNewConversation: e } = s();
|
|
70
|
+
return /* @__PURE__ */ r(
|
|
71
|
+
E,
|
|
71
72
|
{
|
|
72
73
|
type: "button",
|
|
73
74
|
onClick: c(t, e),
|
|
@@ -76,30 +77,30 @@ const I = o("div", { _id: "aiChatHistory" }), j = (t) => {
|
|
|
76
77
|
);
|
|
77
78
|
};
|
|
78
79
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
80
|
+
z as BackButton,
|
|
81
|
+
q as BackButtonIcon,
|
|
82
|
+
z as ChatHistoryPrimitiveBackButton,
|
|
83
|
+
q as ChatHistoryPrimitiveBackButtonIcon,
|
|
84
|
+
W as ChatHistoryPrimitiveEmptyState,
|
|
85
|
+
Y as ChatHistoryPrimitiveFooter,
|
|
86
|
+
K as ChatHistoryPrimitiveHeader,
|
|
87
|
+
Q as ChatHistoryPrimitiveItem,
|
|
88
|
+
V as ChatHistoryPrimitiveItemDate,
|
|
89
|
+
U as ChatHistoryPrimitiveItemTitle,
|
|
90
|
+
J as ChatHistoryPrimitiveList,
|
|
91
|
+
X as ChatHistoryPrimitiveLoadingState,
|
|
92
|
+
Z as ChatHistoryPrimitiveNewConversationButton,
|
|
93
|
+
A as ChatHistoryPrimitiveRoot,
|
|
94
|
+
G as ChatHistoryPrimitiveTitle,
|
|
95
|
+
W as EmptyState,
|
|
96
|
+
Y as Footer,
|
|
97
|
+
K as Header,
|
|
98
|
+
Q as Item,
|
|
99
|
+
V as ItemDate,
|
|
100
|
+
U as ItemTitle,
|
|
101
|
+
J as List,
|
|
102
|
+
X as LoadingState,
|
|
103
|
+
Z as NewConversationButton,
|
|
104
|
+
A as Root,
|
|
105
|
+
G as Title
|
|
105
106
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
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 Ne=require("@ai-sdk/react"),Pe=require("ai"),t=require("react"),Oe=require("../modal/modal-provider.cjs"),Fe=require("../../providers/chat-bubble-provider.cjs"),Ue=require("../../providers/sidebar-chat-provider.cjs"),Be=require("../../providers/config-provider.cjs"),De=require("./use-captcha.cjs"),Le=require("../../hooks/use-media-query.cjs"),He=require("../../hooks/use-anonymous-session.cjs"),$e=require("../../hooks/use-conversation-loader.cjs"),w=require("../../utils/generate-uid.cjs"),ze=require("../../providers/base-events-provider.cjs"),We=require("../../providers/chat-form-provider.cjs"),Ke=require("../../providers/widget-provider.cjs"),je=require("@radix-ui/react-use-controllable-state"),Ge=require("../../hooks/use-streaming-events.cjs"),Je=require("../../hooks/use-inkeep-api-client.cjs");function Qe(g){const l=g.message??"";let s=Number(g.code)||Number(g.statusCode);if(Number.isNaN(s))try{s=Number(JSON.parse(l).status)}catch{}const d=Je.parseAuthError(s,{detail:l});return d!==null?d:s===401?"session":null}const $=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,Ve=()=>{const{baseSettings:g,aiChatSettings:l}=Be.useInkeepConfig(),[s="",d]=je.useControllableState({prop:l.conversationId,defaultProp:l.conversationId??""}),ue=Oe.useModal(),le=Fe.useOptionalChatBubble(),de=Ue.useOptionalSidebarChat(),{logEvent:p}=ze.useBaseEvents(),{setConversationId:pe,emitToParent:C}=Ge.useStreamingEvents(),z=t.useRef(s);t.useEffect(()=>{const e=z.current;z.current=s,e!==s&&p({eventName:"chat_conversation_changed",properties:{conversationId:s,previousConversationId:e}})},[s,p]);const[v,k]=t.useState(""),fe=e=>k(e.target.value),{shouldBypassCaptcha:W,filters:K,privacyPreferences:ge}=g,{onInputMessageChange:he,filters:j,baseUrl:S,agentUrl:me,context:G,headers:J,appId:y,apiKey:f}=l,ve=ue?.isOpen??le?.isOpen??de?.isOpen??!0,{getCaptchaHeader:b,invalidate:u}=De.useCaptcha({baseUrl:S,shouldBypassCaptcha:W||!!f,shouldMakeInitialRequest:ve}),Q=t.useRef(b);Q.current=b;const V=me||`${S}/run/api/chat`,{sessionToken:q,refreshSession:x}=He.useAnonymousSession({baseUrl:S,appId:y,getCaptchaHeader:b,invalidateCaptcha:u,optOutAllAnalytics:ge?.optOutAllAnalytics}),{loadConversation:Z}=$e.useConversationLoader({baseUrl:S,appId:y,authToken:f??q,getCaptchaHeader:b,invalidateCaptcha:u,refreshSession:f?void 0:x}),[ye,X]=t.useState(!1),R=t.useRef(null);R.current=q;const h=t.useRef(0),Y=t.useRef(null),T=t.useRef(null),ee=t.useRef(J);ee.current=J;const _=t.useRef(void 0);_.current=K||j?JSON.stringify({...K,...j}):void 0;const be=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${g.organizationDisplayName??"Administrator"}`;default:return $}},[Ce,I]=t.useState([]),[Se,N]=t.useState(null),Re=t.useMemo(()=>new Pe.DefaultChatTransport({api:V,headers:()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...y?{"x-inkeep-app-id":y}:{},...R.current?{Authorization:`Bearer ${R.current}`}:{},...f?{Authorization:`Bearer ${f}`}:{},..._.current?{"inkeep-filters":_.current}:{},...ee.current}),prepareSendMessagesRequest:async e=>{const r=await Q.current();return{body:{...e.body,id:e.id,messages:e.messages,trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...r}}},body:{requestContext:G}}),[V,G,y,f]),{messages:A,sendMessage:P,addToolApprovalResponse:O,status:te,setMessages:m,stop:se,error:F}=Ne.useChat({transport:Re,onData(e){C(e.type,e.data)},async onFinish(){C("completion",{conversationId:s}),await p({eventName:"assistant_message_received",properties:{conversationId:s}}),p({eventName:"assistant_answer_displayed",properties:{conversationId:s}})},onError(e){console.error("onError",{code:e.code,message:e.message});const r=W||f?null:Qe(e);if(r!==null&&h.current<1){h.current++;const a=T.current,n=Y.current;(async()=>{if(r==="session"){const c=await x();c&&(R.current=c)}else u();if(a){O(a);return}n&&(m(c=>{let i=[...c];return i.at(-1)?.role==="assistant"&&(i=i.slice(0,-1)),i.at(-1)?.role==="user"&&(i=i.slice(0,-1)),i}),P({text:n.content},{body:n.body}))})().catch(()=>{h.current=0,u(),m(c=>{const i=[...c],H=i[i.length-1];if(!H)return i;const ce=$;return H.role==="user"?i.push({id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:ce}]}):H.parts=[{type:"text",text:ce}],i})});return}h.current=0,r!==null&&u(),p({eventName:"chat_error",properties:{conversationId:s,error:e.message}}),m(a=>{const n=[...a],o=n[n.length-1];if(o){const c=be(e);o.role==="user"?n.push({id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:c}]}):o.parts=[{type:"text",text:c}]}return n})}}),re=te==="submitted",U=te==="streaming",Ie=t.useMemo(()=>{const e=o=>{if(!o||typeof o!="object")return!1;const c=o;return typeof c.type=="string"&&c.type.startsWith("tool-")},a=[...A??[]].reverse().find(o=>o.role==="assistant");if(!a)return!1;const n=a.parts?.at(-1);return!(!e(n)||n.state!=="output-available"||!n.approval?.id||U)},[A,U]),ne=U||Ie,ae=re||ne,Ae=A.length===0,B=!v.trim()||ae,Ee=Le.useMediaQuery("(max-width: 768px)"),[Me,E]=t.useState(null);t.useEffect(()=>{F&&E(F)},[F]);const we=()=>E(null),oe=t.useRef(null);t.useEffect(()=>{he?.(v)},[v]);const ke=e=>{e.key==="Enter"&&!e.shiftKey&&!B&&!e.nativeEvent.isComposing&&(e.preventDefault(),D())},D=async(e=v)=>{if(B&&(!e||e.trim().length===0))return;I([]),k(""),h.current=0,T.current=null,await p({eventName:"user_message_submitted",properties:{conversationId:s}});let r=s;r||(r=`conv_${w.generateUid(16)}`,d(r)),pe(r),Y.current={content:e,body:{conversationId:r}},P({text:e},{body:{conversationId:r}})},qe=t.useCallback(e=>{h.current=0,T.current=e,O(e)},[O]),L=t.useCallback(()=>{se().then(()=>{C("aborted",{conversationId:s})})},[se,s,C]),ie=()=>{we(),m([]),d(""),I([]),N(null),u(),p({eventName:"chat_clear_button_clicked",properties:{conversationId:s}})},M=t.useCallback((e,r)=>{E(null),m(r),d(e),I([]),N(null),u()},[m,d,u]),xe=t.useCallback(async(e,r)=>{L(),M(e,[]),X(!0);try{const a=await Z(e,r),n=a?.[a.length-1],o=a!==null&&n?.role==="user"?[...a,{id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:a;o!==null&&M(e,o)}finally{r?.aborted||X(!1)}},[M,Z,L]),{openForm:Te}=We.useChatForm(),_e=Ke.useWidget();return t.useImperativeHandle(l.chatFunctionsRef,()=>({submitMessage:D,updateInputMessage(e){k(e)},clearChat:ie,openForm:e=>{_e?.setView("chat"),Te(e,void 0)},focusInput:()=>{oe.current?.focus()}})),{messages:A,sendMessage:P,addToolApprovalResponse:qe,isLoading:re,isStreaming:ne,isBusy:ae,error:Me,setError:E,isSubmitDisabled:B,input:v,handleInputChange:fe,handleInputKeyDown:ke,handleSubmit:D,stop:L,clear:ie,inputRef:oe,isMobile:Ee,messageAttachments:Ce,setMessageAttachments:I,selectedWorkflow:Se,setSelectedWorkflow:N,isNewChat:Ae,conversationId:s,restoreSession:M,loadAndRestoreSession:xe,isSessionLoading:ye,sessionToken:q,refreshSession:x,getCaptchaHeader:b,invalidateCaptcha:u}};exports.DEFAULT_ERROR_MESSAGE=$;exports.useInkeepChat=Ve;
|
|
@@ -1,97 +1,108 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { DefaultChatTransport as
|
|
4
|
-
import {
|
|
5
|
-
import { useModal as
|
|
6
|
-
import { useOptionalChatBubble as
|
|
7
|
-
import { useOptionalSidebarChat as
|
|
8
|
-
import { useInkeepConfig as
|
|
9
|
-
import { useCaptcha as
|
|
10
|
-
import { useMediaQuery as
|
|
11
|
-
import { useAnonymousSession as
|
|
12
|
-
import { useConversationLoader as
|
|
2
|
+
import { useChat as Pe } from "@ai-sdk/react";
|
|
3
|
+
import { DefaultChatTransport as He } from "ai";
|
|
4
|
+
import { useRef as l, useEffect as q, useState as C, useMemo as pe, useCallback as E, useImperativeHandle as Le } from "react";
|
|
5
|
+
import { useModal as Ue } from "../modal/modal-provider.js";
|
|
6
|
+
import { useOptionalChatBubble as $e } from "../../providers/chat-bubble-provider.js";
|
|
7
|
+
import { useOptionalSidebarChat as ze } from "../../providers/sidebar-chat-provider.js";
|
|
8
|
+
import { useInkeepConfig as We } from "../../providers/config-provider.js";
|
|
9
|
+
import { useCaptcha as qe } from "./use-captcha.js";
|
|
10
|
+
import { useMediaQuery as Ke } from "../../hooks/use-media-query.js";
|
|
11
|
+
import { useAnonymousSession as Je } from "../../hooks/use-anonymous-session.js";
|
|
12
|
+
import { useConversationLoader as je } from "../../hooks/use-conversation-loader.js";
|
|
13
13
|
import { generateUid as k } from "../../utils/generate-uid.js";
|
|
14
|
-
import { useBaseEvents as
|
|
15
|
-
import { useChatForm as
|
|
16
|
-
import { useWidget as
|
|
17
|
-
import { useControllableState as
|
|
18
|
-
import { useStreamingEvents as
|
|
19
|
-
import { parseAuthError as
|
|
20
|
-
function
|
|
21
|
-
const u =
|
|
22
|
-
let
|
|
23
|
-
if (Number.isNaN(
|
|
14
|
+
import { useBaseEvents as Ge } from "../../providers/base-events-provider.js";
|
|
15
|
+
import { useChatForm as Qe } from "../../providers/chat-form-provider.js";
|
|
16
|
+
import { useWidget as Ve } from "../../providers/widget-provider.js";
|
|
17
|
+
import { useControllableState as Ze } from "@radix-ui/react-use-controllable-state";
|
|
18
|
+
import { useStreamingEvents as Xe } from "../../hooks/use-streaming-events.js";
|
|
19
|
+
import { parseAuthError as Ye } from "../../hooks/use-inkeep-api-client.js";
|
|
20
|
+
function et(f) {
|
|
21
|
+
const u = f.message ?? "";
|
|
22
|
+
let t = Number(f.code) || Number(f.statusCode);
|
|
23
|
+
if (Number.isNaN(t))
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
t = Number(JSON.parse(u).status);
|
|
26
26
|
} catch {
|
|
27
27
|
}
|
|
28
|
-
const p =
|
|
29
|
-
return p !== null ? p :
|
|
28
|
+
const p = Ye(t, { detail: u });
|
|
29
|
+
return p !== null ? p : t === 401 ? "session" : null;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const me = `Hmm..
|
|
32
32
|
|
|
33
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
34
|
-
const { baseSettings:
|
|
33
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, bt = () => {
|
|
34
|
+
const { baseSettings: f, aiChatSettings: u } = We(), [t = "", p] = Ze({
|
|
35
35
|
prop: u.conversationId,
|
|
36
36
|
defaultProp: u.conversationId ?? ""
|
|
37
|
-
}),
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
}), de = Ue(), fe = $e(), ge = ze(), { logEvent: m } = Ge(), { setConversationId: he, emitToParent: S } = Xe(), K = l(t);
|
|
38
|
+
q(() => {
|
|
39
|
+
const e = K.current;
|
|
40
|
+
K.current = t, e !== t && m({
|
|
41
|
+
eventName: "chat_conversation_changed",
|
|
42
|
+
properties: {
|
|
43
|
+
conversationId: t,
|
|
44
|
+
previousConversationId: e
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [t, m]);
|
|
48
|
+
const [v, N] = C(""), ve = (e) => N(e.target.value), { shouldBypassCaptcha: J, filters: j, privacyPreferences: ye } = f, {
|
|
49
|
+
onInputMessageChange: be,
|
|
50
|
+
filters: G,
|
|
40
51
|
baseUrl: I,
|
|
41
|
-
agentUrl:
|
|
42
|
-
context:
|
|
43
|
-
headers:
|
|
44
|
-
appId:
|
|
45
|
-
apiKey:
|
|
46
|
-
} = u,
|
|
52
|
+
agentUrl: Ce,
|
|
53
|
+
context: Q,
|
|
54
|
+
headers: V,
|
|
55
|
+
appId: y,
|
|
56
|
+
apiKey: d
|
|
57
|
+
} = u, Se = de?.isOpen ?? fe?.isOpen ?? ge?.isOpen ?? !0, { getCaptchaHeader: b, invalidate: c } = qe({
|
|
47
58
|
baseUrl: I,
|
|
48
|
-
shouldBypassCaptcha:
|
|
49
|
-
shouldMakeInitialRequest:
|
|
50
|
-
}),
|
|
51
|
-
|
|
52
|
-
const
|
|
59
|
+
shouldBypassCaptcha: J || !!d,
|
|
60
|
+
shouldMakeInitialRequest: Se
|
|
61
|
+
}), Z = l(b);
|
|
62
|
+
Z.current = b;
|
|
63
|
+
const X = Ce || `${I}/run/api/chat`, { sessionToken: T, refreshSession: _ } = Je({
|
|
53
64
|
baseUrl: I,
|
|
54
|
-
appId:
|
|
65
|
+
appId: y,
|
|
55
66
|
getCaptchaHeader: b,
|
|
56
67
|
invalidateCaptcha: c,
|
|
57
68
|
optOutAllAnalytics: ye?.optOutAllAnalytics
|
|
58
|
-
}), { loadConversation:
|
|
69
|
+
}), { loadConversation: Y } = je({
|
|
59
70
|
baseUrl: I,
|
|
60
|
-
appId:
|
|
61
|
-
authToken:
|
|
71
|
+
appId: y,
|
|
72
|
+
authToken: d ?? T,
|
|
62
73
|
getCaptchaHeader: b,
|
|
63
74
|
invalidateCaptcha: c,
|
|
64
75
|
// Only pass refreshSession for anonymous-session flows; API key auth has no token to refresh.
|
|
65
|
-
refreshSession:
|
|
66
|
-
}), [
|
|
76
|
+
refreshSession: d ? void 0 : _
|
|
77
|
+
}), [Ie, ee] = C(!1), w = l(null);
|
|
67
78
|
w.current = T;
|
|
68
|
-
const
|
|
69
|
-
|
|
79
|
+
const g = l(0), te = l(null), O = l(null), se = l(V);
|
|
80
|
+
se.current = V;
|
|
70
81
|
const F = l(void 0);
|
|
71
|
-
F.current =
|
|
72
|
-
const
|
|
82
|
+
F.current = j || G ? JSON.stringify({ ...j, ...G }) : void 0;
|
|
83
|
+
const we = (e) => {
|
|
73
84
|
switch (e.code) {
|
|
74
85
|
case 400:
|
|
75
86
|
return e.message;
|
|
76
87
|
case 403:
|
|
77
|
-
return `There seems to be a configuration error. Please contact ${
|
|
88
|
+
return `There seems to be a configuration error. Please contact ${f.organizationDisplayName ?? "Administrator"}`;
|
|
78
89
|
default:
|
|
79
|
-
return
|
|
90
|
+
return me;
|
|
80
91
|
}
|
|
81
|
-
}, [
|
|
82
|
-
() => new
|
|
83
|
-
api:
|
|
92
|
+
}, [Ae, A] = C([]), [Re, B] = C(null), Me = pe(
|
|
93
|
+
() => new He({
|
|
94
|
+
api: X,
|
|
84
95
|
headers: () => ({
|
|
85
96
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
86
97
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
87
|
-
...
|
|
98
|
+
...y ? { "x-inkeep-app-id": y } : {},
|
|
88
99
|
...w.current ? { Authorization: `Bearer ${w.current}` } : {},
|
|
89
|
-
...
|
|
100
|
+
...d ? { Authorization: `Bearer ${d}` } : {},
|
|
90
101
|
...F.current ? { "inkeep-filters": F.current } : {},
|
|
91
|
-
...
|
|
102
|
+
...se.current
|
|
92
103
|
}),
|
|
93
104
|
prepareSendMessagesRequest: async (e) => {
|
|
94
|
-
const
|
|
105
|
+
const s = await Z.current();
|
|
95
106
|
return {
|
|
96
107
|
body: {
|
|
97
108
|
...e.body,
|
|
@@ -102,50 +113,50 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
102
113
|
},
|
|
103
114
|
headers: {
|
|
104
115
|
...e.headers,
|
|
105
|
-
...
|
|
116
|
+
...s
|
|
106
117
|
}
|
|
107
118
|
};
|
|
108
119
|
},
|
|
109
120
|
body: {
|
|
110
|
-
requestContext:
|
|
121
|
+
requestContext: Q
|
|
111
122
|
}
|
|
112
123
|
}),
|
|
113
|
-
[
|
|
124
|
+
[X, Q, y, d]
|
|
114
125
|
), {
|
|
115
|
-
messages:
|
|
126
|
+
messages: R,
|
|
116
127
|
sendMessage: D,
|
|
117
128
|
addToolApprovalResponse: P,
|
|
118
|
-
status:
|
|
119
|
-
setMessages:
|
|
120
|
-
stop:
|
|
129
|
+
status: re,
|
|
130
|
+
setMessages: h,
|
|
131
|
+
stop: ne,
|
|
121
132
|
error: H
|
|
122
|
-
} =
|
|
133
|
+
} = Pe({
|
|
123
134
|
transport: Me,
|
|
124
135
|
onData(e) {
|
|
125
136
|
S(e.type, e.data);
|
|
126
137
|
},
|
|
127
138
|
async onFinish() {
|
|
128
|
-
S("completion", { conversationId:
|
|
139
|
+
S("completion", { conversationId: t }), await m({
|
|
129
140
|
eventName: "assistant_message_received",
|
|
130
141
|
properties: {
|
|
131
|
-
conversationId:
|
|
142
|
+
conversationId: t
|
|
132
143
|
}
|
|
133
|
-
}),
|
|
144
|
+
}), m({
|
|
134
145
|
eventName: "assistant_answer_displayed",
|
|
135
146
|
properties: {
|
|
136
|
-
conversationId:
|
|
147
|
+
conversationId: t
|
|
137
148
|
}
|
|
138
149
|
});
|
|
139
150
|
},
|
|
140
151
|
onError(e) {
|
|
141
152
|
console.error("onError", { code: e.code, message: e.message });
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
const n =
|
|
153
|
+
const s = J || d ? null : et(e);
|
|
154
|
+
if (s !== null && g.current < 1) {
|
|
155
|
+
g.current++;
|
|
156
|
+
const n = O.current, r = te.current;
|
|
146
157
|
(async () => {
|
|
147
|
-
if (
|
|
148
|
-
const i = await
|
|
158
|
+
if (s === "session") {
|
|
159
|
+
const i = await _();
|
|
149
160
|
i && (w.current = i);
|
|
150
161
|
} else
|
|
151
162
|
c();
|
|
@@ -153,34 +164,34 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
153
164
|
P(n);
|
|
154
165
|
return;
|
|
155
166
|
}
|
|
156
|
-
r && (
|
|
167
|
+
r && (h((i) => {
|
|
157
168
|
let a = [...i];
|
|
158
169
|
return a.at(-1)?.role === "assistant" && (a = a.slice(0, -1)), a.at(-1)?.role === "user" && (a = a.slice(0, -1)), a;
|
|
159
170
|
}), D({ text: r.content }, { body: r.body }));
|
|
160
171
|
})().catch(() => {
|
|
161
|
-
|
|
172
|
+
g.current = 0, c(), h((i) => {
|
|
162
173
|
const a = [...i], W = a[a.length - 1];
|
|
163
174
|
if (!W) return a;
|
|
164
|
-
const
|
|
175
|
+
const ue = me;
|
|
165
176
|
return W.role === "user" ? a.push({
|
|
166
177
|
id: k(16),
|
|
167
178
|
role: "assistant",
|
|
168
|
-
parts: [{ type: "text", text:
|
|
169
|
-
}) : W.parts = [{ type: "text", text:
|
|
179
|
+
parts: [{ type: "text", text: ue }]
|
|
180
|
+
}) : W.parts = [{ type: "text", text: ue }], a;
|
|
170
181
|
});
|
|
171
182
|
});
|
|
172
183
|
return;
|
|
173
184
|
}
|
|
174
|
-
|
|
185
|
+
g.current = 0, s !== null && c(), m({
|
|
175
186
|
eventName: "chat_error",
|
|
176
187
|
properties: {
|
|
177
|
-
conversationId:
|
|
188
|
+
conversationId: t,
|
|
178
189
|
error: e.message
|
|
179
190
|
}
|
|
180
|
-
}),
|
|
191
|
+
}), h((n) => {
|
|
181
192
|
const r = [...n], o = r[r.length - 1];
|
|
182
193
|
if (o) {
|
|
183
|
-
const i =
|
|
194
|
+
const i = we(e);
|
|
184
195
|
o.role === "user" ? r.push({
|
|
185
196
|
id: k(16),
|
|
186
197
|
role: "assistant",
|
|
@@ -190,127 +201,127 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
190
201
|
return r;
|
|
191
202
|
});
|
|
192
203
|
}
|
|
193
|
-
}),
|
|
204
|
+
}), oe = re === "submitted", L = re === "streaming", xe = pe(() => {
|
|
194
205
|
const e = (o) => {
|
|
195
206
|
if (!o || typeof o != "object") return !1;
|
|
196
207
|
const i = o;
|
|
197
208
|
return typeof i.type == "string" && i.type.startsWith("tool-");
|
|
198
|
-
}, n = [...
|
|
209
|
+
}, n = [...R ?? []].reverse().find((o) => o.role === "assistant");
|
|
199
210
|
if (!n) return !1;
|
|
200
211
|
const r = n.parts?.at(-1);
|
|
201
212
|
return !(!e(r) || r.state !== "output-available" || !r.approval?.id || L);
|
|
202
|
-
}, [
|
|
203
|
-
|
|
204
|
-
H &&
|
|
213
|
+
}, [R, L]), ae = L || xe, ie = oe || ae, Ee = R.length === 0, U = !v.trim() || ie, ke = Ke("(max-width: 768px)"), [Ne, M] = C(null);
|
|
214
|
+
q(() => {
|
|
215
|
+
H && M(H);
|
|
205
216
|
}, [H]);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}, [
|
|
210
|
-
const
|
|
217
|
+
const Te = () => M(null), ce = l(null);
|
|
218
|
+
q(() => {
|
|
219
|
+
be?.(v);
|
|
220
|
+
}, [v]);
|
|
221
|
+
const _e = (e) => {
|
|
211
222
|
e.key === "Enter" && !e.shiftKey && !U && !e.nativeEvent.isComposing && (e.preventDefault(), $());
|
|
212
|
-
}, $ = async (e =
|
|
223
|
+
}, $ = async (e = v) => {
|
|
213
224
|
if (U && (!e || e.trim().length === 0)) return;
|
|
214
|
-
A([]), N(""),
|
|
225
|
+
A([]), N(""), g.current = 0, O.current = null, await m({
|
|
215
226
|
eventName: "user_message_submitted",
|
|
216
227
|
properties: {
|
|
217
|
-
conversationId:
|
|
228
|
+
conversationId: t
|
|
218
229
|
}
|
|
219
230
|
});
|
|
220
|
-
let
|
|
221
|
-
|
|
231
|
+
let s = t;
|
|
232
|
+
s || (s = `conv_${k(16)}`, p(s)), he(s), te.current = {
|
|
222
233
|
content: e,
|
|
223
|
-
body: { conversationId:
|
|
234
|
+
body: { conversationId: s }
|
|
224
235
|
}, D(
|
|
225
236
|
{ text: e },
|
|
226
237
|
{
|
|
227
|
-
body: { conversationId:
|
|
238
|
+
body: { conversationId: s }
|
|
228
239
|
}
|
|
229
240
|
);
|
|
230
241
|
}, Oe = E(
|
|
231
242
|
(e) => {
|
|
232
|
-
|
|
243
|
+
g.current = 0, O.current = e, P(e);
|
|
233
244
|
},
|
|
234
245
|
[P]
|
|
235
246
|
), z = E(() => {
|
|
236
|
-
|
|
237
|
-
S("aborted", { conversationId:
|
|
247
|
+
ne().then(() => {
|
|
248
|
+
S("aborted", { conversationId: t });
|
|
238
249
|
});
|
|
239
|
-
}, [
|
|
240
|
-
|
|
250
|
+
}, [ne, t, S]), le = () => {
|
|
251
|
+
Te(), h([]), p(""), A([]), B(null), c(), m({
|
|
241
252
|
eventName: "chat_clear_button_clicked",
|
|
242
253
|
properties: {
|
|
243
|
-
conversationId:
|
|
254
|
+
conversationId: t
|
|
244
255
|
}
|
|
245
256
|
});
|
|
246
257
|
}, x = E(
|
|
247
|
-
(e,
|
|
248
|
-
|
|
258
|
+
(e, s) => {
|
|
259
|
+
M(null), h(s), p(e), A([]), B(null), c();
|
|
249
260
|
},
|
|
250
|
-
[
|
|
251
|
-
),
|
|
252
|
-
async (e,
|
|
253
|
-
z(), x(e, []),
|
|
261
|
+
[h, p, c]
|
|
262
|
+
), Fe = E(
|
|
263
|
+
async (e, s) => {
|
|
264
|
+
z(), x(e, []), ee(!0);
|
|
254
265
|
try {
|
|
255
|
-
const n = await
|
|
266
|
+
const n = await Y(e, s), r = n?.[n.length - 1], o = n !== null && r?.role === "user" ? [...n, {
|
|
256
267
|
id: k(16),
|
|
257
268
|
role: "assistant",
|
|
258
269
|
parts: [{ type: "text", text: "This session was interrupted. Please check back in a few minutes or start a new conversation." }]
|
|
259
270
|
}] : n;
|
|
260
271
|
o !== null && x(e, o);
|
|
261
272
|
} finally {
|
|
262
|
-
|
|
273
|
+
s?.aborted || ee(!1);
|
|
263
274
|
}
|
|
264
275
|
},
|
|
265
|
-
[x,
|
|
266
|
-
), { openForm:
|
|
267
|
-
return
|
|
276
|
+
[x, Y, z]
|
|
277
|
+
), { openForm: Be } = Qe(), De = Ve();
|
|
278
|
+
return Le(u.chatFunctionsRef, () => ({
|
|
268
279
|
submitMessage: $,
|
|
269
280
|
updateInputMessage(e) {
|
|
270
281
|
N(e);
|
|
271
282
|
},
|
|
272
|
-
clearChat:
|
|
283
|
+
clearChat: le,
|
|
273
284
|
openForm: (e) => {
|
|
274
|
-
|
|
285
|
+
De?.setView("chat"), Be(e, void 0);
|
|
275
286
|
},
|
|
276
287
|
focusInput: () => {
|
|
277
|
-
|
|
288
|
+
ce.current?.focus();
|
|
278
289
|
}
|
|
279
290
|
})), {
|
|
280
|
-
messages:
|
|
291
|
+
messages: R,
|
|
281
292
|
sendMessage: D,
|
|
282
293
|
addToolApprovalResponse: Oe,
|
|
283
|
-
isLoading:
|
|
284
|
-
isStreaming:
|
|
285
|
-
isBusy:
|
|
286
|
-
error:
|
|
287
|
-
setError:
|
|
294
|
+
isLoading: oe,
|
|
295
|
+
isStreaming: ae,
|
|
296
|
+
isBusy: ie,
|
|
297
|
+
error: Ne,
|
|
298
|
+
setError: M,
|
|
288
299
|
isSubmitDisabled: U,
|
|
289
|
-
input:
|
|
290
|
-
handleInputChange:
|
|
291
|
-
handleInputKeyDown:
|
|
300
|
+
input: v,
|
|
301
|
+
handleInputChange: ve,
|
|
302
|
+
handleInputKeyDown: _e,
|
|
292
303
|
handleSubmit: $,
|
|
293
304
|
stop: z,
|
|
294
|
-
clear:
|
|
295
|
-
inputRef:
|
|
296
|
-
isMobile:
|
|
305
|
+
clear: le,
|
|
306
|
+
inputRef: ce,
|
|
307
|
+
isMobile: ke,
|
|
297
308
|
// Additional state for attachments and workflow
|
|
298
|
-
messageAttachments:
|
|
309
|
+
messageAttachments: Ae,
|
|
299
310
|
setMessageAttachments: A,
|
|
300
|
-
selectedWorkflow:
|
|
311
|
+
selectedWorkflow: Re,
|
|
301
312
|
setSelectedWorkflow: B,
|
|
302
|
-
isNewChat:
|
|
303
|
-
conversationId:
|
|
313
|
+
isNewChat: Ee,
|
|
314
|
+
conversationId: t,
|
|
304
315
|
restoreSession: x,
|
|
305
|
-
loadAndRestoreSession:
|
|
306
|
-
isSessionLoading:
|
|
316
|
+
loadAndRestoreSession: Fe,
|
|
317
|
+
isSessionLoading: Ie,
|
|
307
318
|
sessionToken: T,
|
|
308
|
-
refreshSession:
|
|
319
|
+
refreshSession: _,
|
|
309
320
|
getCaptchaHeader: b,
|
|
310
321
|
invalidateCaptcha: c
|
|
311
322
|
};
|
|
312
323
|
};
|
|
313
324
|
export {
|
|
314
|
-
|
|
315
|
-
|
|
325
|
+
me as DEFAULT_ERROR_MESSAGE,
|
|
326
|
+
bt as useInkeepChat
|
|
316
327
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.19",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
|
|
@@ -5,7 +5,7 @@ import { useInkeepConfig as g } from "./config-provider.js";
|
|
|
5
5
|
const a = d(void 0), P = ({ children: e }) => {
|
|
6
6
|
const { baseSettings: t, componentType: o } = g(), { tags: s, analyticsProperties: n } = t, r = u(
|
|
7
7
|
() => ({
|
|
8
|
-
widgetLibraryVersion: "0.15.
|
|
8
|
+
widgetLibraryVersion: "0.15.19",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|
package/dist/types/events.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ type ExtendPropertiesWithCommon<T> = T extends {
|
|
|
43
43
|
export type InkeepEventWithCommon = ExtendPropertiesWithCommon<InkeepEvent>;
|
|
44
44
|
export type InkeepCallbackEvent = InkeepEventWithCommon;
|
|
45
45
|
export type SearchEvent = SearchQueryResponseReceivedEvent | SearchQuerySubmittedEvent | SearchResultClickedEvent;
|
|
46
|
-
export type ChatEvent = AssistantMessageReceivedEvent | AssistantAnswerDisplayedEvent | UserMessageSubmittedEvent | UserEscalationIndicatedEvent | SharedChatLoadedEvent | AssistantPositiveFeedbackSubmittedEvent | AssistantNegativeFeedbackSubmittedEvent | ChatClearButtonClickedEvent | AssistantMessageCopiedEvent | GetHelpOptionClickedEvent | ChatShareButtonClickedEvent | AssistantSourceItemClickedEvent | AssistantMessageLinkOpenedEvent | AssistantCodeBlockCopiedEvent | ChatErrorEvent;
|
|
46
|
+
export type ChatEvent = AssistantMessageReceivedEvent | AssistantAnswerDisplayedEvent | UserMessageSubmittedEvent | UserEscalationIndicatedEvent | SharedChatLoadedEvent | AssistantPositiveFeedbackSubmittedEvent | AssistantNegativeFeedbackSubmittedEvent | ChatClearButtonClickedEvent | ChatConversationChangedEvent | AssistantMessageCopiedEvent | GetHelpOptionClickedEvent | ChatShareButtonClickedEvent | AssistantSourceItemClickedEvent | AssistantMessageLinkOpenedEvent | AssistantCodeBlockCopiedEvent | ChatErrorEvent;
|
|
47
47
|
export type WidgetEvent = ModalOpenedEvent | ModalClosedEvent | ChatBubbleOpenedEvent | ChatBubbleClosedEvent;
|
|
48
48
|
export type InkeepEvent = SearchEvent | ChatEvent | WidgetEvent;
|
|
49
49
|
export interface AssistantMessageReceivedEvent {
|
|
@@ -104,6 +104,13 @@ export interface ChatClearButtonClickedEvent {
|
|
|
104
104
|
conversationId: string;
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
+
export interface ChatConversationChangedEvent {
|
|
108
|
+
eventName: 'chat_conversation_changed';
|
|
109
|
+
properties: {
|
|
110
|
+
conversationId: string;
|
|
111
|
+
previousConversationId: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
107
114
|
export interface ChatShareButtonClickedEvent {
|
|
108
115
|
eventName: 'chat_share_button_clicked';
|
|
109
116
|
properties: {
|