@inkeep/agents-ui 0.15.24 → 0.15.26
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/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +92 -92
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const We=require("@ai-sdk/react"),ze=require("ai"),t=require("react"),Je=require("../modal/modal-provider.cjs"),Ge=require("../../providers/chat-bubble-provider.cjs"),Qe=require("../../providers/sidebar-chat-provider.cjs"),Ve=require("../../providers/config-provider.cjs"),Ze=require("./use-captcha.cjs"),Xe=require("../../hooks/use-media-query.cjs"),Ye=require("../../hooks/use-anonymous-session.cjs"),et=require("../../hooks/use-auth-token.cjs"),tt=require("../../hooks/use-conversation-loader.cjs"),N=require("../../utils/generate-uid.cjs"),st=require("../../providers/base-events-provider.cjs"),nt=require("../../providers/chat-form-provider.cjs"),rt=require("../../providers/widget-provider.cjs"),at=require("@radix-ui/react-use-controllable-state"),ot=require("../../hooks/use-streaming-events.cjs"),it=require("../../hooks/use-inkeep-api-client.cjs");function ut(f){const h=f.message??"";let
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const We=require("@ai-sdk/react"),ze=require("ai"),t=require("react"),Je=require("../modal/modal-provider.cjs"),Ge=require("../../providers/chat-bubble-provider.cjs"),Qe=require("../../providers/sidebar-chat-provider.cjs"),Ve=require("../../providers/config-provider.cjs"),Ze=require("./use-captcha.cjs"),Xe=require("../../hooks/use-media-query.cjs"),Ye=require("../../hooks/use-anonymous-session.cjs"),et=require("../../hooks/use-auth-token.cjs"),tt=require("../../hooks/use-conversation-loader.cjs"),N=require("../../utils/generate-uid.cjs"),st=require("../../providers/base-events-provider.cjs"),nt=require("../../providers/chat-form-provider.cjs"),rt=require("../../providers/widget-provider.cjs"),at=require("@radix-ui/react-use-controllable-state"),ot=require("../../hooks/use-streaming-events.cjs"),it=require("../../hooks/use-inkeep-api-client.cjs");function ut(f){const h=f.message??"";let n=Number(f.code)||Number(f.statusCode);if(Number.isNaN(n))try{n=Number(JSON.parse(h).status)}catch{}const l=it.parseAuthError(n,{detail:h});return l!==null?l:n===401?"session":null}const O=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,ct=()=>{const{baseSettings:f,aiChatSettings:h}=Ve.useInkeepConfig(),[
|
|
4
|
-
`)??"";t.useEffect(()=>{R.current=C?.length?C:void 0},[xe]);const le=t.useRef(re);le.current=re;const H=t.useRef(void 0);H.current=Y||se?JSON.stringify({...Y,...se}):void 0;const qe=e=>{switch(e.code){case 400:return e.message;case 401:return te?"Authentication failed. Please try again.":O;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return O}},[Pe,A]=t.useState([]),[Ne,M]=t.useState(null),Oe=t.useMemo(()=>new ze.DefaultChatTransport({api:oe,headers:()=>{const e=m??B.current??D.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...b?{"x-inkeep-app-id":b}:{},...e?{Authorization:`Bearer ${e}`}:{},...H.current?{"inkeep-filters":H.current}:{},...L.current?{"x-inkeep-user-properties":L.current}:{},...le.current}},prepareSendMessagesRequest:async e=>{const
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ct=()=>{const{baseSettings:f,aiChatSettings:h}=Ve.useInkeepConfig(),[n="",l]=at.useControllableState({prop:h.conversationId,defaultProp:h.conversationId??""}),be=Je.useModal(),Ce=Ge.useOptionalChatBubble(),Se=Qe.useOptionalSidebarChat(),{logEvent:g}=st.useBaseEvents(),{setConversationId:Re,emitToParent:I}=ot.useStreamingEvents(),Z=t.useRef(n);t.useEffect(()=>{const e=Z.current;Z.current=n,e!==n&&g({eventName:"chat_conversation_changed",properties:{conversationId:n,previousConversationId:e}})},[n,g]);const[y,w]=t.useState(""),Ae=e=>w(e.target.value),{shouldBypassCaptcha:X,filters:Y,privacyPreferences:ke,userProperties:_}=f,{authToken:E,isLoading:Ie,refreshToken:ee}=et.useAuthToken(),te=!!f.getAuthToken,d=!!E,{onInputMessageChange:we,filters:se,baseUrl:T,agentUrl:Ee,context:ne,headers:re,appId:b,apiKey:m,files:C}=h,Te=be?.isOpen??Ce?.isOpen??Se?.isOpen??!0,{getCaptchaHeader:S,invalidate:c}=Ze.useCaptcha({baseUrl:T,shouldBypassCaptcha:X||!!m,shouldMakeInitialRequest:Te}),ae=t.useRef(S);ae.current=S;const oe=Ee||`${T}/run/api/chat`,{sessionToken:F,refreshSession:U}=Ye.useAnonymousSession({baseUrl:T,appId:b,getCaptchaHeader:S,invalidateCaptcha:c,optOutAllAnalytics:ke?.optOutAllAnalytics,enabled:!d&&!Ie}),{loadConversation:ie}=tt.useConversationLoader({baseUrl:T,appId:b,authToken:m??(d?E:F),getCaptchaHeader:S,invalidateCaptcha:c,refreshSession:m||d?void 0:U}),[Me,ue]=t.useState(!1),D=t.useRef(null);D.current=F;const B=t.useRef(null);B.current=E;const L=t.useRef(void 0);L.current=_&&Object.keys(_).length>0?JSON.stringify(_):void 0;const v=t.useRef(0),ce=t.useRef(null),$=t.useRef(null),R=t.useRef(void 0),xe=C?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
4
|
+
`)??"";t.useEffect(()=>{R.current=C?.length?C:void 0},[xe]);const le=t.useRef(re);le.current=re;const H=t.useRef(void 0);H.current=Y||se?JSON.stringify({...Y,...se}):void 0;const qe=e=>{switch(e.code){case 400:return e.message;case 401:return te?"Authentication failed. Please try again.":O;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return O}},[Pe,A]=t.useState([]),[Ne,M]=t.useState(null),Oe=t.useMemo(()=>new ze.DefaultChatTransport({api:oe,headers:()=>{const e=m??B.current??D.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...b?{"x-inkeep-app-id":b}:{},...e?{Authorization:`Bearer ${e}`}:{},...H.current?{"inkeep-filters":H.current}:{},...L.current?{"x-inkeep-user-properties":L.current}:{},...le.current}},prepareSendMessagesRequest:async e=>{const r=await ae.current(),s=e.messages[e.messages.length-1];return s||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:s?[s]:[],trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...r}}},body:{requestContext:ne}}),[oe,ne,b,m]),{messages:x,sendMessage:j,addToolApprovalResponse:K,status:de,setMessages:p,stop:q,error:W}=We.useChat({transport:Oe,onData(e){I(e.type,e.data)},async onFinish(){I("completion",{conversationId:n}),await g({eventName:"assistant_message_received",properties:{conversationId:n}}),g({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.error("onError",{code:e.code,message:e.message});const r=X||m?null:ut(e);if(r!==null&&v.current<1){v.current++;const s=$.current,a=ce.current;(async()=>{if(r==="session"&&te){const o=await ee();if(!o)throw new Error("Auth token refresh failed");B.current=o}else if(r==="session"){const o=await U();o&&(D.current=o)}else c();if(s){K(s);return}a&&(p(o=>{let u=[...o];return u.at(-1)?.role==="assistant"&&(u=u.slice(0,-1)),u.at(-1)?.role==="user"&&(u=u.slice(0,-1)),u}),j(a.files?.length?{parts:[{type:"text",text:a.content},...a.files]}:{text:a.content},{body:a.body}))})().catch(()=>{v.current=0,c(),p(o=>{const u=[...o],V=u[u.length-1];if(!V)return u;const ye=O;return V.role==="user"?u.push({id:N.generateUid(16),role:"assistant",parts:[{type:"text",text:ye}]}):V.parts=[{type:"text",text:ye}],u})});return}v.current=0,r!==null&&c(),g({eventName:"chat_error",properties:{conversationId:n,error:e.message}}),p(s=>{const a=[...s],i=a[a.length-1];if(i){const o=qe(e);i.role==="user"?a.push({id:N.generateUid(16),role:"assistant",parts:[{type:"text",text:o}]}):i.parts=[{type:"text",text:o}]}return a})}}),pe=t.useRef(d);t.useEffect(()=>{const e=pe.current;pe.current=d,e!==d&&(q(),k(null),p([]),l(""),w(""),A([]),M(null),c())},[d,q,p,l,c]);const fe=de==="submitted",z=de==="streaming",_e=t.useMemo(()=>{const e=i=>{if(!i||typeof i!="object")return!1;const o=i;return typeof o.type=="string"&&o.type.startsWith("tool-")},s=[...x??[]].reverse().find(i=>i.role==="assistant");if(!s)return!1;const a=s.parts?.at(-1);return!(!e(a)||a.state!=="output-available"||!a.approval?.id||z)},[x,z]),he=z||_e,ge=fe||he,Fe=x.length===0,J=!y.trim()||ge,Ue=Xe.useMediaQuery("(max-width: 768px)"),[De,k]=t.useState(null);t.useEffect(()=>{W&&k(W)},[W]);const Be=()=>k(null),me=t.useRef(null);t.useEffect(()=>{we?.(y)},[y]);const Le=e=>{e.key==="Enter"&&!e.shiftKey&&!J&&!e.nativeEvent.isComposing&&(e.preventDefault(),G())},G=async(e=y)=>{if(J&&(!e||e.trim().length===0))return;A([]),w(""),v.current=0,$.current=null,await g({eventName:"user_message_submitted",properties:{conversationId:n}});let r=n;r||(r=`conv_${N.generateUid(16)}`,l(r)),Re(r);const s=R.current;R.current=void 0,ce.current={content:e,body:{conversationId:r},files:s},j(s?{parts:[{type:"text",text:e},...s]}:{text:e},{body:{conversationId:r}})},$e=t.useCallback(e=>{v.current=0,$.current=e,K(e)},[K]),Q=t.useCallback(()=>{q().then(()=>{I("aborted",{conversationId:n})})},[q,n,I]),ve=()=>{Be(),p([]),l(""),A([]),M(null),c(),R.current=C?.length?C:void 0,g({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},P=t.useCallback((e,r)=>{k(null),p(r),l(e),A([]),M(null),c(),R.current=void 0},[p,l,c]),He=t.useCallback(async(e,r)=>{Q(),P(e,[]),ue(!0);try{const s=await ie(e,r),a=s?.[s.length-1],i=s!==null&&a?.role==="user"?[...s,{id:N.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:s;i!==null&&P(e,i)}finally{r?.aborted||ue(!1)}},[P,ie,Q]),{openForm:je}=nt.useChatForm(),Ke=rt.useWidget();return t.useImperativeHandle(h.chatFunctionsRef,()=>({submitMessage:G,updateInputMessage(e){w(e)},clearChat:ve,openForm:e=>{Ke?.setView("chat"),je(e,void 0)},focusInput:()=>{me.current?.focus()}})),{messages:x,sendMessage:j,addToolApprovalResponse:$e,isLoading:fe,isStreaming:he,isBusy:ge,error:De,setError:k,isSubmitDisabled:J,input:y,handleInputChange:Ae,handleInputKeyDown:Le,handleSubmit:G,stop:Q,clear:ve,inputRef:me,isMobile:Ue,messageAttachments:Pe,setMessageAttachments:A,selectedWorkflow:Ne,setSelectedWorkflow:M,isNewChat:Fe,conversationId:n,restoreSession:P,loadAndRestoreSession:He,isSessionLoading:Me,authToken:d?E:F,refreshSession:d?ee:U,getCaptchaHeader:S,invalidateCaptcha:c}};exports.DEFAULT_ERROR_MESSAGE=O;exports.useInkeepChat=ct;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useChat as Qe } from "@ai-sdk/react";
|
|
3
3
|
import { DefaultChatTransport as Ve } from "ai";
|
|
4
|
-
import { useRef as c, useEffect as
|
|
4
|
+
import { useRef as c, useEffect as I, useState as R, useMemo as Ae, useCallback as P, useImperativeHandle as Ze } from "react";
|
|
5
5
|
import { useModal as Xe } from "../modal/modal-provider.js";
|
|
6
6
|
import { useOptionalChatBubble as Ye } from "../../providers/chat-bubble-provider.js";
|
|
7
7
|
import { useOptionalSidebarChat as et } from "../../providers/sidebar-chat-provider.js";
|
|
@@ -20,32 +20,32 @@ import { useStreamingEvents as pt } from "../../hooks/use-streaming-events.js";
|
|
|
20
20
|
import { parseAuthError as dt } from "../../hooks/use-inkeep-api-client.js";
|
|
21
21
|
function mt(m) {
|
|
22
22
|
const f = m.message ?? "";
|
|
23
|
-
let
|
|
24
|
-
if (Number.isNaN(
|
|
23
|
+
let s = Number(m.code) || Number(m.statusCode);
|
|
24
|
+
if (Number.isNaN(s))
|
|
25
25
|
try {
|
|
26
|
-
|
|
26
|
+
s = Number(JSON.parse(f).status);
|
|
27
27
|
} catch {
|
|
28
28
|
}
|
|
29
|
-
const u = dt(
|
|
30
|
-
return u !== null ? u :
|
|
29
|
+
const u = dt(s, { detail: f });
|
|
30
|
+
return u !== null ? u : s === 401 ? "session" : null;
|
|
31
31
|
}
|
|
32
32
|
const Y = `Hmm..
|
|
33
33
|
|
|
34
34
|
It seems I might be having some issues right now. Please clear the chat and try again.`, _t = () => {
|
|
35
|
-
const { baseSettings: m, aiChatSettings: f } = tt(), [
|
|
35
|
+
const { baseSettings: m, aiChatSettings: f } = tt(), [s = "", u] = ut({
|
|
36
36
|
prop: f.conversationId,
|
|
37
37
|
defaultProp: f.conversationId ?? ""
|
|
38
|
-
}), ke = Xe(),
|
|
39
|
-
|
|
38
|
+
}), ke = Xe(), we = Ye(), Ie = et(), { logEvent: h } = it(), { setConversationId: Re, emitToParent: T } = pt(), ee = c(s);
|
|
39
|
+
I(() => {
|
|
40
40
|
const e = ee.current;
|
|
41
|
-
ee.current =
|
|
41
|
+
ee.current = s, e !== s && h({
|
|
42
42
|
eventName: "chat_conversation_changed",
|
|
43
43
|
properties: {
|
|
44
|
-
conversationId:
|
|
44
|
+
conversationId: s,
|
|
45
45
|
previousConversationId: e
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
}, [
|
|
48
|
+
}, [s, h]);
|
|
49
49
|
const [y, x] = R(""), Te = (e) => x(e.target.value), { shouldBypassCaptcha: te, filters: se, privacyPreferences: xe, userProperties: $ } = m, { authToken: M, isLoading: Me, refreshToken: re } = ot(), ne = !!m.getAuthToken, p = !!M, {
|
|
50
50
|
onInputMessageChange: Ee,
|
|
51
51
|
filters: oe,
|
|
@@ -56,16 +56,16 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
56
56
|
appId: b,
|
|
57
57
|
apiKey: g,
|
|
58
58
|
files: C
|
|
59
|
-
} = f, Oe = ke?.isOpen ??
|
|
59
|
+
} = f, Oe = ke?.isOpen ?? we?.isOpen ?? Ie?.isOpen ?? !0, { getCaptchaHeader: S, invalidate: l } = st({
|
|
60
60
|
baseUrl: E,
|
|
61
61
|
shouldBypassCaptcha: te || !!g,
|
|
62
62
|
shouldMakeInitialRequest: Oe
|
|
63
|
-
}), ce = c(
|
|
64
|
-
ce.current =
|
|
63
|
+
}), ce = c(S);
|
|
64
|
+
ce.current = S;
|
|
65
65
|
const le = Ne || `${E}/run/api/chat`, { sessionToken: B, refreshSession: L } = nt({
|
|
66
66
|
baseUrl: E,
|
|
67
67
|
appId: b,
|
|
68
|
-
getCaptchaHeader:
|
|
68
|
+
getCaptchaHeader: S,
|
|
69
69
|
invalidateCaptcha: l,
|
|
70
70
|
optOutAllAnalytics: xe?.optOutAllAnalytics,
|
|
71
71
|
enabled: !p && !Me
|
|
@@ -73,24 +73,24 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
73
73
|
baseUrl: E,
|
|
74
74
|
appId: b,
|
|
75
75
|
authToken: g ?? (p ? M : B),
|
|
76
|
-
getCaptchaHeader:
|
|
76
|
+
getCaptchaHeader: S,
|
|
77
77
|
invalidateCaptcha: l,
|
|
78
78
|
refreshSession: g || p ? void 0 : L
|
|
79
79
|
}), [_e, pe] = R(!1), H = c(null);
|
|
80
80
|
H.current = B;
|
|
81
81
|
const U = c(null);
|
|
82
82
|
U.current = M;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const v = c(0), de = c(null),
|
|
83
|
+
const q = c(void 0);
|
|
84
|
+
q.current = $ && Object.keys($).length > 0 ? JSON.stringify($) : void 0;
|
|
85
|
+
const v = c(0), de = c(null), K = c(null), A = c(void 0), Fe = C?.map((e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`).join(`
|
|
86
86
|
`) ?? "";
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
I(() => {
|
|
88
|
+
A.current = C?.length ? C : void 0;
|
|
89
89
|
}, [Fe]);
|
|
90
90
|
const me = c(ie);
|
|
91
91
|
me.current = ie;
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
const W = c(void 0);
|
|
93
|
+
W.current = se || oe ? JSON.stringify({ ...se, ...oe }) : void 0;
|
|
94
94
|
const Pe = (e) => {
|
|
95
95
|
switch (e.code) {
|
|
96
96
|
case 400:
|
|
@@ -102,7 +102,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
102
102
|
default:
|
|
103
103
|
return Y;
|
|
104
104
|
}
|
|
105
|
-
}, [De, k] = R([]), [$e, N] = R(null), Be =
|
|
105
|
+
}, [De, k] = R([]), [$e, N] = R(null), Be = Ae(
|
|
106
106
|
() => new Ve({
|
|
107
107
|
api: le,
|
|
108
108
|
headers: () => {
|
|
@@ -112,24 +112,24 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
112
112
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
113
113
|
...b ? { "x-inkeep-app-id": b } : {},
|
|
114
114
|
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
115
|
-
...
|
|
116
|
-
...
|
|
115
|
+
...W.current ? { "inkeep-filters": W.current } : {},
|
|
116
|
+
...q.current ? { "x-inkeep-user-properties": q.current } : {},
|
|
117
117
|
...me.current
|
|
118
118
|
};
|
|
119
119
|
},
|
|
120
120
|
prepareSendMessagesRequest: async (e) => {
|
|
121
|
-
const
|
|
122
|
-
return {
|
|
121
|
+
const r = await ce.current(), t = e.messages[e.messages.length - 1];
|
|
122
|
+
return t || console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"), {
|
|
123
123
|
body: {
|
|
124
124
|
...e.body,
|
|
125
125
|
id: e.id,
|
|
126
|
-
messages:
|
|
126
|
+
messages: t ? [t] : [],
|
|
127
127
|
trigger: e.trigger,
|
|
128
128
|
messageId: e.messageId
|
|
129
129
|
},
|
|
130
130
|
headers: {
|
|
131
131
|
...e.headers,
|
|
132
|
-
...
|
|
132
|
+
...r
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
},
|
|
@@ -140,7 +140,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
140
140
|
[le, ae, b, g]
|
|
141
141
|
), {
|
|
142
142
|
messages: O,
|
|
143
|
-
sendMessage:
|
|
143
|
+
sendMessage: j,
|
|
144
144
|
addToolApprovalResponse: z,
|
|
145
145
|
status: fe,
|
|
146
146
|
setMessages: d,
|
|
@@ -152,42 +152,42 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
152
152
|
T(e.type, e.data);
|
|
153
153
|
},
|
|
154
154
|
async onFinish() {
|
|
155
|
-
T("completion", { conversationId:
|
|
155
|
+
T("completion", { conversationId: s }), await h({
|
|
156
156
|
eventName: "assistant_message_received",
|
|
157
157
|
properties: {
|
|
158
|
-
conversationId:
|
|
158
|
+
conversationId: s
|
|
159
159
|
}
|
|
160
160
|
}), h({
|
|
161
161
|
eventName: "assistant_answer_displayed",
|
|
162
162
|
properties: {
|
|
163
|
-
conversationId:
|
|
163
|
+
conversationId: s
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
},
|
|
167
167
|
onError(e) {
|
|
168
168
|
console.error("onError", { code: e.code, message: e.message });
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
169
|
+
const r = te || g ? null : mt(e);
|
|
170
|
+
if (r !== null && v.current < 1) {
|
|
171
171
|
v.current++;
|
|
172
|
-
const
|
|
172
|
+
const t = K.current, n = de.current;
|
|
173
173
|
(async () => {
|
|
174
|
-
if (
|
|
174
|
+
if (r === "session" && ne) {
|
|
175
175
|
const o = await re();
|
|
176
176
|
if (!o) throw new Error("Auth token refresh failed");
|
|
177
177
|
U.current = o;
|
|
178
|
-
} else if (
|
|
178
|
+
} else if (r === "session") {
|
|
179
179
|
const o = await L();
|
|
180
180
|
o && (H.current = o);
|
|
181
181
|
} else
|
|
182
182
|
l();
|
|
183
|
-
if (
|
|
184
|
-
z(
|
|
183
|
+
if (t) {
|
|
184
|
+
z(t);
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
n && (d((o) => {
|
|
188
188
|
let i = [...o];
|
|
189
189
|
return i.at(-1)?.role === "assistant" && (i = i.slice(0, -1)), i.at(-1)?.role === "user" && (i = i.slice(0, -1)), i;
|
|
190
|
-
}),
|
|
190
|
+
}), j(
|
|
191
191
|
n.files?.length ? { parts: [{ type: "text", text: n.content }, ...n.files] } : { text: n.content },
|
|
192
192
|
{ body: n.body }
|
|
193
193
|
));
|
|
@@ -195,24 +195,24 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
195
195
|
v.current = 0, l(), d((o) => {
|
|
196
196
|
const i = [...o], X = i[i.length - 1];
|
|
197
197
|
if (!X) return i;
|
|
198
|
-
const
|
|
198
|
+
const Se = Y;
|
|
199
199
|
return X.role === "user" ? i.push({
|
|
200
200
|
id: D(16),
|
|
201
201
|
role: "assistant",
|
|
202
|
-
parts: [{ type: "text", text:
|
|
203
|
-
}) : X.parts = [{ type: "text", text:
|
|
202
|
+
parts: [{ type: "text", text: Se }]
|
|
203
|
+
}) : X.parts = [{ type: "text", text: Se }], i;
|
|
204
204
|
});
|
|
205
205
|
});
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
-
v.current = 0,
|
|
208
|
+
v.current = 0, r !== null && l(), h({
|
|
209
209
|
eventName: "chat_error",
|
|
210
210
|
properties: {
|
|
211
|
-
conversationId:
|
|
211
|
+
conversationId: s,
|
|
212
212
|
error: e.message
|
|
213
213
|
}
|
|
214
|
-
}), d((
|
|
215
|
-
const n = [...
|
|
214
|
+
}), d((t) => {
|
|
215
|
+
const n = [...t], a = n[n.length - 1];
|
|
216
216
|
if (a) {
|
|
217
217
|
const o = Pe(e);
|
|
218
218
|
a.role === "user" ? n.push({
|
|
@@ -225,83 +225,83 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
}), he = c(p);
|
|
228
|
-
|
|
228
|
+
I(() => {
|
|
229
229
|
const e = he.current;
|
|
230
|
-
he.current = p, e !== p && (_(),
|
|
230
|
+
he.current = p, e !== p && (_(), w(null), d([]), u(""), x(""), k([]), N(null), l());
|
|
231
231
|
}, [p, _, d, u, l]);
|
|
232
|
-
const ge = fe === "submitted", G = fe === "streaming", Le =
|
|
232
|
+
const ge = fe === "submitted", G = fe === "streaming", Le = Ae(() => {
|
|
233
233
|
const e = (a) => {
|
|
234
234
|
if (!a || typeof a != "object") return !1;
|
|
235
235
|
const o = a;
|
|
236
236
|
return typeof o.type == "string" && o.type.startsWith("tool-");
|
|
237
|
-
},
|
|
238
|
-
if (!
|
|
239
|
-
const n =
|
|
237
|
+
}, t = [...O ?? []].reverse().find((a) => a.role === "assistant");
|
|
238
|
+
if (!t) return !1;
|
|
239
|
+
const n = t.parts?.at(-1);
|
|
240
240
|
return !(!e(n) || n.state !== "output-available" || !n.approval?.id || G);
|
|
241
|
-
}, [O, G]), ve = G || Le, ye = ge || ve, He = O.length === 0, Q = !y.trim() || ye, Ue = rt("(max-width: 768px)"), [
|
|
242
|
-
|
|
243
|
-
J &&
|
|
241
|
+
}, [O, G]), ve = G || Le, ye = ge || ve, He = O.length === 0, Q = !y.trim() || ye, Ue = rt("(max-width: 768px)"), [qe, w] = R(null);
|
|
242
|
+
I(() => {
|
|
243
|
+
J && w(J);
|
|
244
244
|
}, [J]);
|
|
245
|
-
const
|
|
246
|
-
|
|
245
|
+
const Ke = () => w(null), be = c(null);
|
|
246
|
+
I(() => {
|
|
247
247
|
Ee?.(y);
|
|
248
248
|
}, [y]);
|
|
249
|
-
const
|
|
249
|
+
const We = (e) => {
|
|
250
250
|
e.key === "Enter" && !e.shiftKey && !Q && !e.nativeEvent.isComposing && (e.preventDefault(), V());
|
|
251
251
|
}, V = async (e = y) => {
|
|
252
252
|
if (Q && (!e || e.trim().length === 0)) return;
|
|
253
|
-
k([]), x(""), v.current = 0,
|
|
253
|
+
k([]), x(""), v.current = 0, K.current = null, await h({
|
|
254
254
|
eventName: "user_message_submitted",
|
|
255
255
|
properties: {
|
|
256
|
-
conversationId:
|
|
256
|
+
conversationId: s
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
|
-
let
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
259
|
+
let r = s;
|
|
260
|
+
r || (r = `conv_${D(16)}`, u(r)), Re(r);
|
|
261
|
+
const t = A.current;
|
|
262
|
+
A.current = void 0, de.current = {
|
|
263
263
|
content: e,
|
|
264
|
-
body: { conversationId:
|
|
265
|
-
files:
|
|
266
|
-
},
|
|
267
|
-
|
|
264
|
+
body: { conversationId: r },
|
|
265
|
+
files: t
|
|
266
|
+
}, j(
|
|
267
|
+
t ? { parts: [{ type: "text", text: e }, ...t] } : { text: e },
|
|
268
268
|
{
|
|
269
|
-
body: { conversationId:
|
|
269
|
+
body: { conversationId: r }
|
|
270
270
|
}
|
|
271
271
|
);
|
|
272
|
-
},
|
|
272
|
+
}, je = P(
|
|
273
273
|
(e) => {
|
|
274
|
-
v.current = 0,
|
|
274
|
+
v.current = 0, K.current = e, z(e);
|
|
275
275
|
},
|
|
276
276
|
[z]
|
|
277
277
|
), Z = P(() => {
|
|
278
278
|
_().then(() => {
|
|
279
|
-
T("aborted", { conversationId:
|
|
279
|
+
T("aborted", { conversationId: s });
|
|
280
280
|
});
|
|
281
|
-
}, [_,
|
|
282
|
-
|
|
281
|
+
}, [_, s, T]), Ce = () => {
|
|
282
|
+
Ke(), d([]), u(""), k([]), N(null), l(), A.current = C?.length ? C : void 0, h({
|
|
283
283
|
eventName: "chat_clear_button_clicked",
|
|
284
284
|
properties: {
|
|
285
|
-
conversationId:
|
|
285
|
+
conversationId: s
|
|
286
286
|
}
|
|
287
287
|
});
|
|
288
288
|
}, F = P(
|
|
289
|
-
(e,
|
|
290
|
-
|
|
289
|
+
(e, r) => {
|
|
290
|
+
w(null), d(r), u(e), k([]), N(null), l(), A.current = void 0;
|
|
291
291
|
},
|
|
292
292
|
[d, u, l]
|
|
293
293
|
), ze = P(
|
|
294
|
-
async (e,
|
|
294
|
+
async (e, r) => {
|
|
295
295
|
Z(), F(e, []), pe(!0);
|
|
296
296
|
try {
|
|
297
|
-
const
|
|
297
|
+
const t = await ue(e, r), n = t?.[t.length - 1], a = t !== null && n?.role === "user" ? [...t, {
|
|
298
298
|
id: D(16),
|
|
299
299
|
role: "assistant",
|
|
300
300
|
parts: [{ type: "text", text: "This session was interrupted. Please check back in a few minutes or start a new conversation." }]
|
|
301
|
-
}] :
|
|
301
|
+
}] : t;
|
|
302
302
|
a !== null && F(e, a);
|
|
303
303
|
} finally {
|
|
304
|
-
|
|
304
|
+
r?.aborted || pe(!1);
|
|
305
305
|
}
|
|
306
306
|
},
|
|
307
307
|
[F, ue, Z]
|
|
@@ -320,17 +320,17 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
320
320
|
}
|
|
321
321
|
})), {
|
|
322
322
|
messages: O,
|
|
323
|
-
sendMessage:
|
|
324
|
-
addToolApprovalResponse:
|
|
323
|
+
sendMessage: j,
|
|
324
|
+
addToolApprovalResponse: je,
|
|
325
325
|
isLoading: ge,
|
|
326
326
|
isStreaming: ve,
|
|
327
327
|
isBusy: ye,
|
|
328
|
-
error:
|
|
329
|
-
setError:
|
|
328
|
+
error: qe,
|
|
329
|
+
setError: w,
|
|
330
330
|
isSubmitDisabled: Q,
|
|
331
331
|
input: y,
|
|
332
332
|
handleInputChange: Te,
|
|
333
|
-
handleInputKeyDown:
|
|
333
|
+
handleInputKeyDown: We,
|
|
334
334
|
handleSubmit: V,
|
|
335
335
|
stop: Z,
|
|
336
336
|
clear: Ce,
|
|
@@ -342,13 +342,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
342
342
|
selectedWorkflow: $e,
|
|
343
343
|
setSelectedWorkflow: N,
|
|
344
344
|
isNewChat: He,
|
|
345
|
-
conversationId:
|
|
345
|
+
conversationId: s,
|
|
346
346
|
restoreSession: F,
|
|
347
347
|
loadAndRestoreSession: ze,
|
|
348
348
|
isSessionLoading: _e,
|
|
349
349
|
authToken: p ? M : B,
|
|
350
350
|
refreshSession: p ? re : L,
|
|
351
|
-
getCaptchaHeader:
|
|
351
|
+
getCaptchaHeader: S,
|
|
352
352
|
invalidateCaptcha: l
|
|
353
353
|
};
|
|
354
354
|
};
|
|
@@ -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.26",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.26",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|