@inkeep/cxkit-primitives 0.5.116 → 0.5.118
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/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/components/embedded-chat/use-inkeep-chat.js +103 -112
- package/dist/components/embedded-chat.cjs +5 -5
- package/dist/components/embedded-chat.js +47 -47
- package/dist/components/embedded-search.cjs +1 -1
- package/dist/components/embedded-search.js +149 -149
- package/dist/components/tagline-logo-icon.cjs +1 -1
- package/dist/components/tagline-logo-icon.js +11 -21
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/dist/utils/component-ids.cjs +1 -1
- package/dist/utils/component-ids.js +2 -2
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("openai"),t=require("react"),Oe=require("../../providers/config-provider.cjs"),De=require("../../providers/conversation-provider.cjs"),Fe=require("../../providers/chat-events-provider.cjs"),K=require("../../utils/get-message-metadata.cjs"),le=require("../../utils/reset-query-params.cjs"),Te=require("../../providers/chat-form-provider.cjs"),Ke=require("../../providers/widget-provider.cjs"),Qe=require("../../hooks/use-media-query.cjs"),We=require("./use-captcha.cjs"),Je=require("../modal/modal-provider.cjs"),d=require("../../utils/generate-uid.cjs"),ze=require("../../utils/tools/links-tool.cjs"),He=require("../../atoms/api/analytics/conversation.cjs"),je=require("../../utils/misc.cjs"),Ge=()=>{const{chatId:S,isSharedChat:ue,setConversation:ge,conversation:de,resetConversation:me}=De.useInkeepConversation(),{baseSettings:P,aiChatSettings:Q}=Oe.useInkeepConfig(),{aiApiBaseUrl:W,shouldBypassCaptcha:J,filters:z}=P,H=Je.useModal(),{getSolution:pe,prefetchSolution:E,invalidateSolution:j}=We.useCaptcha({fetchUrl:`${W}/v1/challenge`,shouldBypassCaptcha:J,shouldMakeInitialRequest:H?H.isOpen:!0}),fe=new ce({baseURL:`${W}/v1`,apiKey:P.apiKey??"",dangerouslyAllowBrowser:!0}),{onInputMessageChange:he,getTools:ve,prompts:ye,model:Se,filters:G,onToolCall:we}=Q,[w,x]=t.useState(""),V=t.useRef(null);t.useEffect(()=>{he?.(w)},[w]);const[m,l]=t.useState([]),[X,C]=t.useState(!1),[Ce,M]=t.useState(!1),[Me,Y]=t.useState(null),[B,Z]=t.useState(null),[I,b]=t.useState([]),Ie=e=>{b(s=>[...s,e])},[be,ee]=t.useState({}),o=t.useRef([]),k=t.useRef(null),{logEvent:_,getLatestConversation:te}=Fe.useChatEvents(),se=ye?.map((e,s)=>({id:`system-${Date.now().toString()}-${d.generateUid(4)}-${s}`,role:"system",content:e})),[ke,_e]=t.useState(!!S);t.useEffect(()=>{if(S){const{apiKey:e,analyticsApiBaseUrl:s}=P;He.getConversation(S,e,s).then(a=>{if(a){_({eventName:"shared_chat_loaded",properties:{conversation:a}}),_e(!1),ge({...a});const r=a.messages.map(p=>({...p,content:je.parseIfJson(p.content)}));l(r),o.current=r}})}},[S]);const $e=e=>
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("openai"),t=require("react"),Oe=require("../../providers/config-provider.cjs"),De=require("../../providers/conversation-provider.cjs"),Fe=require("../../providers/chat-events-provider.cjs"),K=require("../../utils/get-message-metadata.cjs"),le=require("../../utils/reset-query-params.cjs"),Te=require("../../providers/chat-form-provider.cjs"),Ke=require("../../providers/widget-provider.cjs"),Qe=require("../../hooks/use-media-query.cjs"),We=require("./use-captcha.cjs"),Je=require("../modal/modal-provider.cjs"),d=require("../../utils/generate-uid.cjs"),ze=require("../../utils/tools/links-tool.cjs"),He=require("../../atoms/api/analytics/conversation.cjs"),je=require("../../utils/misc.cjs"),Ge=()=>{const{chatId:S,isSharedChat:ue,setConversation:ge,conversation:de,resetConversation:me}=De.useInkeepConversation(),{baseSettings:P,aiChatSettings:Q}=Oe.useInkeepConfig(),{aiApiBaseUrl:W,shouldBypassCaptcha:J,filters:z}=P,H=Je.useModal(),{getSolution:pe,prefetchSolution:E,invalidateSolution:j}=We.useCaptcha({fetchUrl:`${W}/v1/challenge`,shouldBypassCaptcha:J,shouldMakeInitialRequest:H?H.isOpen:!0}),fe=new ce({baseURL:`${W}/v1`,apiKey:P.apiKey??"",dangerouslyAllowBrowser:!0}),{onInputMessageChange:he,getTools:ve,prompts:ye,model:Se,filters:G,onToolCall:we}=Q,[w,x]=t.useState(""),V=t.useRef(null);t.useEffect(()=>{he?.(w)},[w]);const[m,l]=t.useState([]),[X,C]=t.useState(!1),[Ce,M]=t.useState(!1),[Me,Y]=t.useState(null),[B,Z]=t.useState(null),[I,b]=t.useState([]),Ie=e=>{b(s=>[...s,e])},[be,ee]=t.useState({}),o=t.useRef([]),k=t.useRef(null),{logEvent:_,getLatestConversation:te}=Fe.useChatEvents(),se=ye?.map((e,s)=>({id:`system-${Date.now().toString()}-${d.generateUid(4)}-${s}`,role:"system",content:e})),[ke,_e]=t.useState(!!S);t.useEffect(()=>{if(S){const{apiKey:e,analyticsApiBaseUrl:s}=P;He.getConversation(S,e,s).then(a=>{if(a){_({eventName:"shared_chat_loaded",properties:{conversation:a}}),_e(!1),ge({...a});const r=a.messages.map(p=>({...p,content:je.parseIfJson(p.content)}));l(r),o.current=r}})}},[S]);const $e=e=>e.status===403||e.status===401?`There seems to be a configuration error. Please contact ${P.organizationDisplayName??"Administrator"}.`:e.error?.message??`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.`,ne=e=>{Y(e),l(s=>{const a=[...s],r=a[a.length-1];return r&&(r.content=$e(e)),a}),C(!1),M(!1),j(),E()},R=!w.trim()&&!I.length||X,qe=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),O())},Pe=e=>{const s=e.target.value;x(s)},O=async(e=w)=>{if(R&&(!e||e.trim().length===0))return;C(!0);const s=B?m.length===2:m.length===0,a=K.getMessageMetadata(B,I,s);let r;const p=K.serializeAttachments(I);I.length&&p?r=[{type:"text",text:p}]:r=e;const ae={id:`${Date.now().toString()}-${d.generateUid(4)}-1`,role:"user",content:r,metadata:a},f=[...m.length?[]:se,ae];if(ue&&S){le.resetQueryParams();const u=o.current.map((i,U)=>({id:`${i.id}-${d.generateUid(6)}-${U}`,role:i.role,...i.role==="assistant"?{links:i.links??[]}:{},content:i.content,metadata:i.metadata,tool_calls:i.tool_calls}));l([...u,...f]),o.current=[...u,...f]}else l(u=>[...u,...f]),o.current=[...o.current,...f];b([]),x(""),_({eventName:"user_message_submitted",properties:{}},o.current);const xe=te(),re=[ze.provideLinksTool,...ve?.({conversation:xe})||[]];try{const u={model:Se,messages:o.current,stream:!0,tools:re,tool_choice:"auto"},i=await pe(),U=i?btoa(JSON.stringify(i)):null,ie=z||G?JSON.stringify({...z,...G}):void 0,N={};!J&&U&&(N["X-INKEEP-CHALLENGE-SOLUTION"]=U),ie&&(N["inkeep-filters"]=ie);const h=fe.beta.chat.completions.stream(u,Object.keys(N).length>0?{headers:N}:void 0),n={id:`${Date.now().toString()}-${d.generateUid(4)}-2`,role:"assistant",content:"",links:[],tool_calls:[]};l(g=>[...g,n]),h.on("content",(g,$)=>{M(!0),n.content=$,l(A=>{const c=[...A],D=c.findIndex(q=>q.id===n.id);return D===-1?[...c,n]:(c[D]={...n},c)})}),h.on("tool_calls.function.arguments.done",async g=>{const{name:$,arguments:A}=g,c=re?.find(v=>v.function.name===$);if(!c)return;const q=("parse"in c.function?c.function.parse:JSON.parse)(A),Be=c.function.function?.(q,h);if($==="provideLinks")n.links=q.links??[];else{const v=c.renderMessageButtons?.({args:q,execution:Be})??[];v.length>0&&ee(y=>{const L=y[n.id]??[],F=new Set(L.map(T=>T.label)),Re=v.filter(T=>!F.has(T.label));return{...y,[n.id]:[...L,...Re]}})}n.tool_calls?.push({id:"call_"+d.generateUid(24),type:"function",function:{name:$,arguments:A}}),l(v=>{const y=[...v],L=y.findIndex(F=>F.id===n.id);return y[L]={...n},y}),we?.(g,{conversation:{...te(),messages:[...o.current,n]}})}),h.on("error",ne),h.finalChatCompletion().then(async()=>{o.current=[...o.current,n],k.current=null,C(!1),M(!1),E(),await _({eventName:"assistant_message_received",properties:{}},o.current),_({eventName:"assistant_answer_displayed",properties:{}})}).catch(g=>{g instanceof ce.APIUserAbortError||console.warn(g)}),k.current=h.controller}catch(u){ne(u),C(!1),M(!1)}},Ee=()=>{k.current&&(k.current.abort(),k.current=null),C(!1),M(!1),E()},oe=()=>{Y(null),l([]),o.current=[],me(),ee({}),b([]),le.resetQueryParams(),Z(null),j(),E(),_({eventName:"chat_clear_button_clicked",properties:{conversation:de}})},Ue=e=>{Z(e);const{initialReplyMessage:s,displayName:a}=e,r={id:m.length.toString()+d.generateUid(4),role:"user",content:a},p={id:(m.length+1).toString()+d.generateUid(4),role:"assistant",content:s,links:[]},f=[{id:`system-${Date.now().toString()}-${d.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
4
|
${K.serializeWorkflow(e)}`},...se,r,p];l(f),b([])},{openForm:Ne}=Te.useChatForm(),Ae=Ke.useWidget();t.useImperativeHandle(Q.chatFunctionsRef,()=>({submitMessage:O,updateInputMessage(e){x(e)},clearChat:oe,openForm:e=>{Ae?.setView("chat"),Ne(e)},focusInput:()=>{V.current?.focus()}}));const Le=Qe.useMediaQuery("(max-width: 768px)");return{messages:m,input:w,isLoading:X,isStreaming:Ce,isLoadingConversation:ke,error:Me,isSubmitDisabled:R,handleInputChange:Pe,handleInputKeyDown:qe,handleSubmit:O,stop:Ee,clear:oe,handleWorkflow:Ue,selectedWorkflow:B,messageAttachments:I,setMessageAttachments:b,addAttachment:Ie,messageButtons:be,isEmpty:m.length===0,inputRef:V,isMobile:Le}};exports.useInkeepChat=Ge;
|
|
@@ -1,103 +1,94 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import { useState as l, useRef as W, useEffect as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import { useInkeepConversation as
|
|
6
|
-
import { useChatEvents as
|
|
7
|
-
import { getMessageMetadata as
|
|
8
|
-
import { resetQueryParams as
|
|
9
|
-
import { useChatForm as
|
|
10
|
-
import { useWidget as
|
|
11
|
-
import { useMediaQuery as
|
|
12
|
-
import { useCaptcha as
|
|
13
|
-
import { useModal as
|
|
2
|
+
import Ut, { APIUserAbortError as Ft } from "openai";
|
|
3
|
+
import { useState as l, useRef as W, useEffect as ct, useImperativeHandle as Kt } from "react";
|
|
4
|
+
import { useInkeepConfig as Tt } from "../../providers/config-provider.js";
|
|
5
|
+
import { useInkeepConversation as Wt } from "../../providers/conversation-provider.js";
|
|
6
|
+
import { useChatEvents as Jt } from "../../providers/chat-events-provider.js";
|
|
7
|
+
import { getMessageMetadata as zt, serializeAttachments as Ht, serializeWorkflow as Qt } from "../../utils/get-message-metadata.js";
|
|
8
|
+
import { resetQueryParams as lt } from "../../utils/reset-query-params.js";
|
|
9
|
+
import { useChatForm as jt } from "../../providers/chat-form-provider.js";
|
|
10
|
+
import { useWidget as qt } from "../../providers/widget-provider.js";
|
|
11
|
+
import { useMediaQuery as Gt } from "../../hooks/use-media-query.js";
|
|
12
|
+
import { useCaptcha as Vt } from "./use-captcha.js";
|
|
13
|
+
import { useModal as Xt } from "../modal/modal-provider.js";
|
|
14
14
|
import { generateUid as g } from "../../utils/generate-uid.js";
|
|
15
|
-
import { provideLinksTool as
|
|
16
|
-
import { getConversation as
|
|
17
|
-
import { parseIfJson as
|
|
18
|
-
const
|
|
19
|
-
const { chatId: w, isSharedChat:
|
|
15
|
+
import { provideLinksTool as Yt } from "../../utils/tools/links-tool.js";
|
|
16
|
+
import { getConversation as Zt } from "../../atoms/api/analytics/conversation.js";
|
|
17
|
+
import { parseIfJson as te } from "../../utils/misc.js";
|
|
18
|
+
const ye = () => {
|
|
19
|
+
const { chatId: w, isSharedChat: ut, setConversation: mt, conversation: gt, resetConversation: pt } = Wt(), { baseSettings: N, aiChatSettings: J } = Tt(), { aiApiBaseUrl: z, shouldBypassCaptcha: H, filters: Q } = N, j = Xt(), { getSolution: dt, prefetchSolution: A, invalidateSolution: q } = Vt({
|
|
20
20
|
fetchUrl: `${z}/v1/challenge`,
|
|
21
21
|
shouldBypassCaptcha: H,
|
|
22
22
|
shouldMakeInitialRequest: j ? j.isOpen : !0
|
|
23
|
-
}),
|
|
23
|
+
}), ft = new Ut({
|
|
24
24
|
baseURL: `${z}/v1`,
|
|
25
25
|
apiKey: N.apiKey ?? "",
|
|
26
26
|
dangerouslyAllowBrowser: !0
|
|
27
27
|
}), {
|
|
28
|
-
onInputMessageChange:
|
|
29
|
-
getTools:
|
|
30
|
-
prompts:
|
|
31
|
-
model:
|
|
28
|
+
onInputMessageChange: ht,
|
|
29
|
+
getTools: yt,
|
|
30
|
+
prompts: vt,
|
|
31
|
+
model: wt,
|
|
32
32
|
filters: G,
|
|
33
|
-
onToolCall:
|
|
33
|
+
onToolCall: Ct
|
|
34
34
|
} = J, [C, O] = l(""), V = W(null);
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
ct(() => {
|
|
36
|
+
ht?.(C);
|
|
37
37
|
}, [C]);
|
|
38
|
-
const [p, c] = l([]), [X, I] = l(!1), [
|
|
39
|
-
b((
|
|
40
|
-
}, [
|
|
41
|
-
id: `system-${Date.now().toString()}-${g(4)}-${
|
|
38
|
+
const [p, c] = l([]), [X, I] = l(!1), [It, M] = l(!1), [Mt, Y] = l(null), [P, Z] = l(null), [S, b] = l([]), St = (t) => {
|
|
39
|
+
b((e) => [...e, t]);
|
|
40
|
+
}, [bt, tt] = l({}), n = W([]), k = W(null), { logEvent: _, getLatestConversation: et } = Jt(), st = vt?.map((t, e) => ({
|
|
41
|
+
id: `system-${Date.now().toString()}-${g(4)}-${e}`,
|
|
42
42
|
role: "system",
|
|
43
|
-
content:
|
|
44
|
-
})), [
|
|
45
|
-
|
|
43
|
+
content: t
|
|
44
|
+
})), [kt, _t] = l(!!w);
|
|
45
|
+
ct(() => {
|
|
46
46
|
if (w) {
|
|
47
|
-
const { apiKey:
|
|
48
|
-
|
|
47
|
+
const { apiKey: t, analyticsApiBaseUrl: e } = N;
|
|
48
|
+
Zt(w, t, e).then((o) => {
|
|
49
49
|
if (o) {
|
|
50
50
|
_({
|
|
51
51
|
eventName: "shared_chat_loaded",
|
|
52
52
|
properties: {
|
|
53
53
|
conversation: o
|
|
54
54
|
}
|
|
55
|
-
}),
|
|
55
|
+
}), _t(!1), mt({ ...o });
|
|
56
56
|
const a = o.messages.map((d) => ({
|
|
57
57
|
...d,
|
|
58
|
-
content:
|
|
58
|
+
content: te(d.content)
|
|
59
59
|
}));
|
|
60
60
|
c(a), n.current = a;
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
}, [w]);
|
|
65
|
-
const $
|
|
66
|
-
switch (e.code) {
|
|
67
|
-
case 400:
|
|
68
|
-
return e.message;
|
|
69
|
-
case 403:
|
|
70
|
-
return `There seems to be a configuration error. Please contact ${N.organizationDisplayName ?? "Administrator"}`;
|
|
71
|
-
default:
|
|
72
|
-
return `Hmm..
|
|
65
|
+
const $t = (t) => t.status === 403 || t.status === 401 ? `There seems to be a configuration error. Please contact ${N.organizationDisplayName ?? "Administrator"}.` : t.error?.message ?? `Hmm..
|
|
73
66
|
|
|
74
|
-
It seems I might be having some issues right now. Please clear the chat and try again
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const o = [...t], a = o[o.length - 1];
|
|
79
|
-
return a && (a.content = $e(e)), o;
|
|
67
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, nt = (t) => {
|
|
68
|
+
Y(t), c((e) => {
|
|
69
|
+
const o = [...e], a = o[o.length - 1];
|
|
70
|
+
return a && (a.content = $t(t)), o;
|
|
80
71
|
}), I(!1), M(!1), q(), A();
|
|
81
|
-
}, R = !C.trim() && !S.length || X,
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
const
|
|
85
|
-
O(
|
|
86
|
-
}, U = async (
|
|
87
|
-
if (R && (!
|
|
72
|
+
}, R = !C.trim() && !S.length || X, Et = (t) => {
|
|
73
|
+
t.key === "Enter" && !t.shiftKey && !R && !t.nativeEvent.isComposing && (t.preventDefault(), U());
|
|
74
|
+
}, Nt = (t) => {
|
|
75
|
+
const e = t.target.value;
|
|
76
|
+
O(e);
|
|
77
|
+
}, U = async (t = C) => {
|
|
78
|
+
if (R && (!t || t.trim().length === 0)) return;
|
|
88
79
|
I(!0);
|
|
89
|
-
const
|
|
80
|
+
const e = P ? p.length === 2 : p.length === 0, o = zt(P, S, e);
|
|
90
81
|
let a;
|
|
91
|
-
const d =
|
|
92
|
-
S.length && d ? a = [{ type: "text", text: d }] : a =
|
|
93
|
-
const
|
|
82
|
+
const d = Ht(S);
|
|
83
|
+
S.length && d ? a = [{ type: "text", text: d }] : a = t;
|
|
84
|
+
const at = {
|
|
94
85
|
id: `${Date.now().toString()}-${g(4)}-1`,
|
|
95
86
|
role: "user",
|
|
96
87
|
content: a,
|
|
97
88
|
metadata: o
|
|
98
|
-
}, f = [...p.length ? [] :
|
|
99
|
-
if (
|
|
100
|
-
|
|
89
|
+
}, f = [...p.length ? [] : st, at];
|
|
90
|
+
if (ut && w) {
|
|
91
|
+
lt();
|
|
101
92
|
const u = n.current.map((r, x) => ({
|
|
102
93
|
id: `${r.id}-${g(6)}-${x}`,
|
|
103
94
|
role: r.role,
|
|
@@ -116,20 +107,20 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
116
107
|
},
|
|
117
108
|
n.current
|
|
118
109
|
);
|
|
119
|
-
const
|
|
110
|
+
const Ot = et(), rt = [Yt, ...yt?.({ conversation: Ot }) || []];
|
|
120
111
|
try {
|
|
121
112
|
const u = {
|
|
122
|
-
model:
|
|
113
|
+
model: wt,
|
|
123
114
|
messages: n.current,
|
|
124
115
|
stream: !0,
|
|
125
|
-
tools:
|
|
116
|
+
tools: rt,
|
|
126
117
|
tool_choice: "auto"
|
|
127
|
-
}, r = await
|
|
118
|
+
}, r = await dt(), x = r ? btoa(JSON.stringify(r)) : null, it = Q || G ? JSON.stringify({
|
|
128
119
|
...Q,
|
|
129
120
|
...G
|
|
130
121
|
}) : void 0, L = {};
|
|
131
|
-
!H && x && (L["X-INKEEP-CHALLENGE-SOLUTION"] = x),
|
|
132
|
-
const h =
|
|
122
|
+
!H && x && (L["X-INKEEP-CHALLENGE-SOLUTION"] = x), it && (L["inkeep-filters"] = it);
|
|
123
|
+
const h = ft.beta.chat.completions.stream(
|
|
133
124
|
u,
|
|
134
125
|
Object.keys(L).length > 0 ? { headers: L } : void 0
|
|
135
126
|
), s = {
|
|
@@ -145,18 +136,18 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
145
136
|
return F === -1 ? [...i, s] : (i[F] = { ...s }, i);
|
|
146
137
|
});
|
|
147
138
|
}), h.on("tool_calls.function.arguments.done", async (m) => {
|
|
148
|
-
const { name: $, arguments: B } = m, i =
|
|
139
|
+
const { name: $, arguments: B } = m, i = rt?.find((y) => y.function.name === $);
|
|
149
140
|
if (!i) return;
|
|
150
|
-
const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B),
|
|
141
|
+
const E = ("parse" in i.function ? i.function.parse : JSON.parse)(B), Pt = i.function.function?.(E, h);
|
|
151
142
|
if ($ === "provideLinks")
|
|
152
143
|
s.links = E.links ?? [];
|
|
153
144
|
else {
|
|
154
|
-
const y = i.renderMessageButtons?.({ args: E, execution:
|
|
155
|
-
y.length > 0 &&
|
|
156
|
-
const D = v[s.id] ?? [], K = new Set(D.map((T) => T.label)),
|
|
145
|
+
const y = i.renderMessageButtons?.({ args: E, execution: Pt }) ?? [];
|
|
146
|
+
y.length > 0 && tt((v) => {
|
|
147
|
+
const D = v[s.id] ?? [], K = new Set(D.map((T) => T.label)), Rt = y.filter((T) => !K.has(T.label));
|
|
157
148
|
return {
|
|
158
149
|
...v,
|
|
159
|
-
[s.id]: [...D, ...
|
|
150
|
+
[s.id]: [...D, ...Rt]
|
|
160
151
|
};
|
|
161
152
|
});
|
|
162
153
|
}
|
|
@@ -170,13 +161,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
170
161
|
}), c((y) => {
|
|
171
162
|
const v = [...y], D = v.findIndex((K) => K.id === s.id);
|
|
172
163
|
return v[D] = { ...s }, v;
|
|
173
|
-
}),
|
|
164
|
+
}), Ct?.(m, {
|
|
174
165
|
conversation: {
|
|
175
|
-
...
|
|
166
|
+
...et(),
|
|
176
167
|
messages: [...n.current, s]
|
|
177
168
|
}
|
|
178
169
|
});
|
|
179
|
-
}), h.on("error",
|
|
170
|
+
}), h.on("error", nt), h.finalChatCompletion().then(async () => {
|
|
180
171
|
n.current = [...n.current, s], k.current = null, I(!1), M(!1), A(), await _(
|
|
181
172
|
{
|
|
182
173
|
eventName: "assistant_message_received",
|
|
@@ -188,77 +179,77 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
188
179
|
properties: {}
|
|
189
180
|
});
|
|
190
181
|
}).catch((m) => {
|
|
191
|
-
m instanceof
|
|
182
|
+
m instanceof Ft || console.warn(m);
|
|
192
183
|
}), k.current = h.controller;
|
|
193
184
|
} catch (u) {
|
|
194
|
-
|
|
185
|
+
nt(u), I(!1), M(!1);
|
|
195
186
|
}
|
|
196
|
-
},
|
|
187
|
+
}, At = () => {
|
|
197
188
|
k.current && (k.current.abort(), k.current = null), I(!1), M(!1), A();
|
|
198
|
-
},
|
|
199
|
-
Y(null), c([]), n.current = [],
|
|
189
|
+
}, ot = () => {
|
|
190
|
+
Y(null), c([]), n.current = [], pt(), tt({}), b([]), lt(), Z(null), q(), A(), _({
|
|
200
191
|
eventName: "chat_clear_button_clicked",
|
|
201
192
|
properties: {
|
|
202
|
-
conversation:
|
|
193
|
+
conversation: gt
|
|
203
194
|
}
|
|
204
195
|
});
|
|
205
|
-
},
|
|
206
|
-
Z(
|
|
207
|
-
const { initialReplyMessage:
|
|
196
|
+
}, xt = (t) => {
|
|
197
|
+
Z(t);
|
|
198
|
+
const { initialReplyMessage: e, displayName: o } = t, a = {
|
|
208
199
|
id: p.length.toString() + g(4),
|
|
209
200
|
role: "user",
|
|
210
201
|
content: o
|
|
211
202
|
}, d = {
|
|
212
203
|
id: (p.length + 1).toString() + g(4),
|
|
213
204
|
role: "assistant",
|
|
214
|
-
content:
|
|
205
|
+
content: e,
|
|
215
206
|
links: []
|
|
216
207
|
}, f = [{
|
|
217
|
-
id: `system-${Date.now().toString()}-${g(4)}-${
|
|
208
|
+
id: `system-${Date.now().toString()}-${g(4)}-${t.id}`,
|
|
218
209
|
role: "system",
|
|
219
210
|
content: `Company has asked user to follow this guided workflow:
|
|
220
|
-
${
|
|
221
|
-
}, ...
|
|
211
|
+
${Qt(t)}`
|
|
212
|
+
}, ...st, a, d];
|
|
222
213
|
c(f), b([]);
|
|
223
|
-
}, { openForm:
|
|
224
|
-
|
|
214
|
+
}, { openForm: Lt } = jt(), Bt = qt();
|
|
215
|
+
Kt(J.chatFunctionsRef, () => ({
|
|
225
216
|
submitMessage: U,
|
|
226
|
-
updateInputMessage(
|
|
227
|
-
O(
|
|
217
|
+
updateInputMessage(t) {
|
|
218
|
+
O(t);
|
|
228
219
|
},
|
|
229
|
-
clearChat:
|
|
230
|
-
openForm: (
|
|
231
|
-
|
|
220
|
+
clearChat: ot,
|
|
221
|
+
openForm: (t) => {
|
|
222
|
+
Bt?.setView("chat"), Lt(t);
|
|
232
223
|
},
|
|
233
224
|
focusInput: () => {
|
|
234
225
|
V.current?.focus();
|
|
235
226
|
}
|
|
236
227
|
}));
|
|
237
|
-
const
|
|
228
|
+
const Dt = Gt("(max-width: 768px)");
|
|
238
229
|
return {
|
|
239
230
|
messages: p,
|
|
240
231
|
input: C,
|
|
241
232
|
isLoading: X,
|
|
242
|
-
isStreaming:
|
|
243
|
-
isLoadingConversation:
|
|
244
|
-
error:
|
|
233
|
+
isStreaming: It,
|
|
234
|
+
isLoadingConversation: kt,
|
|
235
|
+
error: Mt,
|
|
245
236
|
isSubmitDisabled: R,
|
|
246
|
-
handleInputChange:
|
|
247
|
-
handleInputKeyDown:
|
|
237
|
+
handleInputChange: Nt,
|
|
238
|
+
handleInputKeyDown: Et,
|
|
248
239
|
handleSubmit: U,
|
|
249
|
-
stop:
|
|
250
|
-
clear:
|
|
251
|
-
handleWorkflow:
|
|
240
|
+
stop: At,
|
|
241
|
+
clear: ot,
|
|
242
|
+
handleWorkflow: xt,
|
|
252
243
|
selectedWorkflow: P,
|
|
253
244
|
messageAttachments: S,
|
|
254
245
|
setMessageAttachments: b,
|
|
255
|
-
addAttachment:
|
|
256
|
-
messageButtons:
|
|
246
|
+
addAttachment: St,
|
|
247
|
+
messageButtons: bt,
|
|
257
248
|
isEmpty: p.length === 0,
|
|
258
249
|
inputRef: V,
|
|
259
|
-
isMobile:
|
|
250
|
+
isMobile: Dt
|
|
260
251
|
};
|
|
261
252
|
};
|
|
262
253
|
export {
|
|
263
|
-
|
|
254
|
+
ye as useInkeepChat
|
|
264
255
|
};
|