@inkeep/cxkit-primitives 0.5.5 → 0.5.8
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/api/analytics/events.cjs +1 -1
- package/dist/atoms/api/analytics/events.js +2 -2
- package/dist/components/embedded-chat/use-chat-action.cjs +1 -1
- package/dist/components/embedded-chat/use-chat-action.js +14 -16
- package/dist/components/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/components/embedded-chat/use-inkeep-chat.js +122 -128
- package/dist/components/embedded-chat.cjs +5 -5
- package/dist/components/embedded-chat.d.cts +9 -8
- package/dist/components/embedded-chat.d.ts +9 -8
- package/dist/components/embedded-chat.js +952 -963
- package/dist/components/embedded-search/use-inkeep-search.cjs +1 -1
- package/dist/components/embedded-search/use-inkeep-search.js +10 -10
- package/dist/components/embedded-search.d.cts +2 -2
- package/dist/components/embedded-search.d.ts +2 -2
- package/dist/components/embedded-search.js +79 -79
- package/dist/components/intelligent-form/intelligent-form-provider.cjs +1 -1
- package/dist/components/intelligent-form/intelligent-form-provider.d.cts +3 -3
- package/dist/components/intelligent-form/intelligent-form-provider.d.ts +3 -3
- package/dist/components/intelligent-form/intelligent-form-provider.js +2 -2
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.cjs +1 -1
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.d.cts +5 -5
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.d.ts +5 -5
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.js +88 -109
- package/dist/components/intelligent-form.cjs +1 -1
- package/dist/components/intelligent-form.d.cts +4 -3
- package/dist/components/intelligent-form.d.ts +4 -3
- package/dist/components/intelligent-form.js +191 -188
- package/dist/components/modal.cjs +1 -1
- package/dist/components/modal.d.cts +1 -1
- package/dist/components/modal.d.ts +1 -1
- package/dist/components/modal.js +26 -26
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/dist/providers/chat-events-provider.cjs +1 -1
- package/dist/providers/chat-events-provider.d.cts +9 -1
- package/dist/providers/chat-events-provider.d.ts +9 -1
- package/dist/providers/chat-events-provider.js +54 -57
- package/dist/providers/chat-form-provider.cjs +1 -1
- package/dist/providers/chat-form-provider.d.cts +3 -3
- package/dist/providers/chat-form-provider.d.ts +3 -3
- package/dist/providers/chat-form-provider.js +17 -17
- package/dist/providers/feedback-provider.cjs +1 -1
- package/dist/providers/feedback-provider.js +23 -23
- package/dist/utils/default-settings.cjs +1 -1
- package/dist/utils/default-settings.d.cts +1 -0
- package/dist/utils/default-settings.d.ts +1 -0
- package/dist/utils/default-settings.js +13 -11
- package/dist/utils/misc.cjs +1 -1
- package/dist/utils/misc.d.cts +2 -2
- package/dist/utils/misc.d.ts +2 -2
- package/dist/utils/misc.js +15 -13
- package/package.json +5 -4
- package/dist/atoms/dialog.cjs +0 -1
- package/dist/atoms/dialog.js +0 -185
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function a(e,o,s){const i=`${s}/events`,r={...e,type:e.eventName};if("searchQuery"in e.properties)r.entityType="search",r.searchQuery=e.properties.searchQuery;else if("messageId"in e.properties)r.entityType="message",r.messageId=e.properties.messageId;else{if(r.entityType="conversation",!e.properties.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function a(e,o,s){const i=`${s}/events`,r={...e,type:e.eventName};if("searchQuery"in e.properties)r.entityType="search",r.searchQuery=e.properties.searchQuery;else if("messageId"in e.properties)r.entityType="message",r.messageId=e.properties.messageId;else{if(r.entityType="conversation",!e.properties.conversation)return;r.conversationId=e.properties.conversation.id}const t=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(r)});if(!t.ok){const n=await t.text();throw new Error(`Failed to log event: ${n}`)}}exports.logEvent=a;
|
|
@@ -9,8 +9,8 @@ async function a(e, o, s) {
|
|
|
9
9
|
else if ("messageId" in e.properties)
|
|
10
10
|
r.entityType = "message", r.messageId = e.properties.messageId;
|
|
11
11
|
else {
|
|
12
|
-
if (r.entityType = "conversation", !e.properties.
|
|
13
|
-
r.conversationId = e.properties.
|
|
12
|
+
if (r.entityType = "conversation", !e.properties.conversation) return;
|
|
13
|
+
r.conversationId = e.properties.conversation.id;
|
|
14
14
|
}
|
|
15
15
|
const t = await fetch(i, {
|
|
16
16
|
method: "POST",
|
|
@@ -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 s=require("../../providers/conversation-provider.cjs"),l=require("../../providers/chat-events-provider.cjs"),c=require("../../providers/chat-form-provider.cjs"),a=require("../modal/modal-provider.cjs"),u=e=>{const{logEvent:n}=l.useChatEvents(),{conversation:o}=s.useInkeepConversation(),{openForm:t}=c.useChatForm(),r=a.useModal();return{handleAction:i=>{e.action.type==="open_form"?(i?.onOpenForm?.(),t?.(e.action.formSettings)):e.action.type==="invoke_callback"&&(e.action.callback({conversation:o}),e.action.shouldCloseModal&&r?.closeModal())},logHelpAction:()=>{"name"in e&&n({eventName:"get_help_option_clicked",properties:{getHelpOption:e,conversation:o}})}}};exports.useChatAction=u;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useInkeepConversation as
|
|
3
|
-
import { useChatEvents as
|
|
4
|
-
import { useChatForm as
|
|
5
|
-
import { useModal as
|
|
6
|
-
const
|
|
7
|
-
const { logEvent:
|
|
8
|
-
|
|
2
|
+
import { useInkeepConversation as r } from "../../providers/conversation-provider.js";
|
|
3
|
+
import { useChatEvents as s } from "../../providers/chat-events-provider.js";
|
|
4
|
+
import { useChatForm as p } from "../../providers/chat-form-provider.js";
|
|
5
|
+
import { useModal as a } from "../modal/modal-provider.js";
|
|
6
|
+
const v = (o) => {
|
|
7
|
+
const { logEvent: n } = s(), { conversation: e } = r(), { openForm: t } = p(), l = a();
|
|
8
|
+
return { handleAction: (i) => {
|
|
9
|
+
o.action.type === "open_form" ? (i?.onOpenForm?.(), t?.(o.action.formSettings)) : o.action.type === "invoke_callback" && (o.action.callback({
|
|
9
10
|
conversation: e
|
|
10
|
-
}), o.action.shouldCloseModal &&
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
"name" in o && t({
|
|
11
|
+
}), o.action.shouldCloseModal && l?.closeModal());
|
|
12
|
+
}, logHelpAction: () => {
|
|
13
|
+
"name" in o && n({
|
|
14
14
|
eventName: "get_help_option_clicked",
|
|
15
15
|
properties: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
url: s,
|
|
19
|
-
conversationId: e.id
|
|
16
|
+
getHelpOption: o,
|
|
17
|
+
conversation: e
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
20
|
} };
|
|
23
21
|
};
|
|
24
22
|
export {
|
|
25
|
-
|
|
23
|
+
v as useChatAction
|
|
26
24
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
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 ke=require("openai"),t=require("react"),be=require("../../atoms/api/analytics/conversation.cjs"),Pe=require("../../providers/config-provider.cjs"),qe=require("../../providers/conversation-provider.cjs"),Ee=require("../../providers/chat-events-provider.cjs"),$=require("../../utils/get-message-metadata.cjs"),Ne=require("../../utils/misc.cjs"),V=require("../../utils/reset-query-params.cjs"),_e=require("../../providers/chat-form-provider.cjs"),Ae=require("../../providers/widget-provider.cjs"),Re=require("../../hooks/use-media-query.cjs"),$e=require("./use-captcha.cjs"),De=require("../modal/modal-provider.cjs"),Le=()=>{const{chatId:m,setConversation:X,conversation:Y,resetConversation:Z}=qe.useInkeepConversation(),{baseSettings:I,aiChatSettings:D}=Pe.useInkeepConfig(),{aiApiBaseUrl:L,shouldBypassCaptcha:x}=I,O=De.useModal(),{getSolution:ee,prefetchSolution:k,invalidateSolution:K}=$e.useCaptcha({fetchUrl:`${L}/v1/challenge`,shouldBypassCaptcha:x,shouldMakeInitialRequest:O?O.isOpen:!0}),te=new ke({baseURL:`${L}/v1`,apiKey:I.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:se,tools:ne,prompts:oe,model:ae,onToolCall:re}=D,[h,q]=t.useState(""),T=t.useRef(null);t.useEffect(()=>{se?.(h)},[h]);const[u,l]=t.useState([]),[U,p]=t.useState(!1),[ie,f]=t.useState(!1),[ce,B]=t.useState(null),[E,F]=t.useState(null),[v,S]=t.useState([]),le=e=>{S(s=>[...s,e])},[ue,Q]=t.useState({}),i=t.useRef([]),y=t.useRef(null),{logEvent:b}=Ee.useChatEvents(),W=oe?.map((e,s)=>({id:`system-${Date.now().toString()}-${s}`,role:"system",content:e})),[de,ge]=t.useState(!!m);t.useEffect(()=>{if(m){const{apiKey:e,analyticsApiBaseUrl:s}=I;be.getConversation(m,e,s).then(n=>{if(n){console.log("res",n),b({eventName:"shared_chat_loaded",properties:{conversation:n}}),ge(!1),X({...n,id:""});const o=n.messages.map(c=>({id:Date.now().toString()+c.id,content:Ne.parseIfJson(c.content),role:c.role,links:c.links}));l(o),i.current=o}})}},[m]);const me=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${I.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.`}},
|
|
4
|
-
${$.serializeWorkflow(e)}`},...
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},z=e=>{B(e),l(s=>{const n=[...s],o=n[n.length-1];return o&&(o.content=me(e)),n}),p(!1),f(!1),K(),k()},N=!h.trim()&&!v.length||U,he=e=>{e.key==="Enter"&&!e.shiftKey&&!N&&!e.nativeEvent.isComposing&&(e.preventDefault(),_())},pe=e=>{const s=e.target.value;q(s)},_=async(e=h)=>{if(N&&(!e||e.trim().length===0))return;p(!0);const s=E?u.length===2:u.length===0,n=$.getMessageMetadata(E,v,s);let o;const c=$.serializeAttachments(v);v.length&&c?o=[{type:"text",text:c}]:o=e;const J={id:`${Date.now().toString()}1`,role:"user",content:o,metadata:n},P=[...u.length?[]:W,J];m&&V.resetQueryParams(),l(C=>[...C,...P]),i.current=[...i.current,...P],S([]),q(""),b({eventName:"user_message_submitted",properties:{}},i.current);try{const C={model:ae,messages:i.current,stream:!0,tools:ne,tool_choice:"auto"},j=await ee(),Me=j?btoa(JSON.stringify(j)):null,G=x?void 0:{"X-INKEEP-CHALLENGE-SOLUTION":Me},M=te.beta.chat.completions.stream(C,G?{headers:G}:void 0),a={id:`${Date.now().toString()}2`,role:"assistant",content:"",links:[]};l(d=>[...d,a]),M.on("content",(d,A)=>{f(!0),a.content=A,l(R=>{const r=[...R],g=r.findIndex(w=>w.id===a.id);return g===-1?[...r,a]:(r[g]={...a},r)})}),M.on("tool_calls.function.arguments.done",d=>{const{name:A,arguments:R}=d;if(A==="provideLinks"){const r=JSON.parse(R);r.links?.length>0&&(a.links=r.links,l(g=>{const w=[...g],we=w.findIndex(Ie=>Ie.id===a.id);return w[we]={...a},w}))}else{const r=re?.(d);r&&Q(g=>({...g,[a.id]:[...g[a.id]||[],r]}))}}),M.on("error",d=>{z(d)}),M.finalChatCompletion().then(()=>{i.current=[...i.current,a],y.current=null,p(!1),f(!1),k(),b({eventName:"assistant_message_received",properties:{}},i.current)}),y.current=M.controller}catch(C){z(C),p(!1),f(!1)}},fe=()=>{y.current&&(y.current.abort(),y.current=null),p(!1),f(!1),k()},H=()=>{B(null),l([]),i.current=[],Z(),Q({}),S([]),V.resetQueryParams(),F(null),K(),k(),b({eventName:"chat_clear_button_clicked",properties:{conversation:Y}})},ve=e=>{F(e);const{initialReplyMessage:s,displayName:n}=e,o={id:u.length.toString(),role:"user",content:n},c={id:(u.length+1).toString(),role:"assistant",content:s,links:[]},P=[{id:`system-${Date.now().toString()}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
|
+
${$.serializeWorkflow(e)}`},...W,o,c];l(P),S([])},{openForm:Se}=_e.useChatForm(),ye=Ae.useWidget();t.useImperativeHandle(D.chatFunctionsRef,()=>({submitMessage:_,updateInputMessage(e){q(e)},clearChat:H,openForm:e=>{ye?.setView("chat"),Se(e)},focusInput:()=>{T.current?.focus()}}));const Ce=Re.useMediaQuery("(max-width: 768px)");return{messages:u,input:h,isLoading:U,isStreaming:ie,isLoadingConversation:de,error:ce,isSubmitDisabled:N,handleInputChange:pe,handleInputKeyDown:he,handleSubmit:_,stop:fe,clear:H,handleWorkflow:ve,selectedWorkflow:E,messageAttachments:v,setMessageAttachments:S,addAttachment:le,messageToolCalls:ue,isEmpty:u.length===0,inputRef:T,isMobile:Ce}};exports.useInkeepChat=Le;
|
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import be from "openai";
|
|
3
|
-
import { useState as c, useRef as
|
|
4
|
-
import { getConversation as
|
|
5
|
-
import { useInkeepConfig as
|
|
3
|
+
import { useState as c, useRef as L, useEffect as X, useImperativeHandle as Ee } from "react";
|
|
4
|
+
import { getConversation as Ne } from "../../atoms/api/analytics/conversation.js";
|
|
5
|
+
import { useInkeepConfig as _e } from "../../providers/config-provider.js";
|
|
6
6
|
import { useInkeepConversation as Ae } from "../../providers/conversation-provider.js";
|
|
7
|
-
import { useChatEvents as
|
|
8
|
-
import { getMessageMetadata as
|
|
9
|
-
import { parseIfJson as
|
|
7
|
+
import { useChatEvents as $e } from "../../providers/chat-events-provider.js";
|
|
8
|
+
import { getMessageMetadata as xe, serializeAttachments as De, serializeWorkflow as Le } from "../../utils/get-message-metadata.js";
|
|
9
|
+
import { parseIfJson as Re } from "../../utils/misc.js";
|
|
10
10
|
import { resetQueryParams as j } from "../../utils/reset-query-params.js";
|
|
11
|
-
import { useChatForm as
|
|
11
|
+
import { useChatForm as Pe } 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
|
|
16
|
-
const
|
|
17
|
-
const { chatId:
|
|
18
|
-
fetchUrl: `${
|
|
14
|
+
import { useCaptcha as Ue } from "./use-captcha.js";
|
|
15
|
+
import { useModal as Be } from "../modal/modal-provider.js";
|
|
16
|
+
const et = () => {
|
|
17
|
+
const { chatId: d, setConversation: Y, conversation: Z, resetConversation: ee } = Ae(), { baseSettings: S, aiChatSettings: R } = _e(), { aiApiBaseUrl: P, shouldBypassCaptcha: K } = S, O = Be(), { getSolution: te, prefetchSolution: k, invalidateSolution: U } = Ue({
|
|
18
|
+
fetchUrl: `${P}/v1/challenge`,
|
|
19
19
|
shouldBypassCaptcha: K,
|
|
20
20
|
shouldMakeInitialRequest: O ? O.isOpen : !0
|
|
21
21
|
}), se = new be({
|
|
22
|
-
baseURL: `${
|
|
22
|
+
baseURL: `${P}/v1`,
|
|
23
23
|
apiKey: S.apiKey,
|
|
24
24
|
dangerouslyAllowBrowser: !0
|
|
25
|
-
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } =
|
|
25
|
+
}), { onInputMessageChange: ne, tools: oe, prompts: ae, model: re, onToolCall: ie } = R, [p, N] = c(""), B = L(null);
|
|
26
26
|
X(() => {
|
|
27
27
|
ne?.(p);
|
|
28
28
|
}, [p]);
|
|
29
|
-
const [u, l] = c([]), [
|
|
30
|
-
|
|
31
|
-
}, [me,
|
|
32
|
-
id: `system-${
|
|
29
|
+
const [u, l] = c([]), [T, f] = c(!1), [ce, h] = c(!1), [le, W] = c(null), [_, F] = c(null), [y, C] = c([]), ue = (e) => {
|
|
30
|
+
C((t) => [...t, e]);
|
|
31
|
+
}, [me, z] = c({}), r = L([]), w = L(null), { logEvent: b } = $e(), H = ae?.map((e, t) => ({
|
|
32
|
+
id: `system-${Date.now().toString()}-${t}`,
|
|
33
33
|
role: "system",
|
|
34
34
|
content: e
|
|
35
|
-
})), [
|
|
35
|
+
})), [ge, de] = c(!!d);
|
|
36
36
|
X(() => {
|
|
37
|
-
if (
|
|
38
|
-
const { apiKey: e, analyticsApiBaseUrl:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
37
|
+
if (d) {
|
|
38
|
+
const { apiKey: e, analyticsApiBaseUrl: t } = S;
|
|
39
|
+
Ne(d, e, t).then((s) => {
|
|
40
|
+
if (s) {
|
|
41
|
+
console.log("res", s), b({
|
|
42
|
+
eventName: "shared_chat_loaded",
|
|
43
|
+
properties: {
|
|
44
|
+
conversation: s
|
|
45
|
+
}
|
|
46
|
+
}), de(!1), Y({ ...s, id: "" });
|
|
47
|
+
const n = s.messages.map((i) => ({
|
|
48
48
|
id: Date.now().toString() + i.id,
|
|
49
|
-
content:
|
|
49
|
+
content: Re(i.content),
|
|
50
50
|
role: i.role,
|
|
51
51
|
links: i.links
|
|
52
52
|
}));
|
|
53
|
-
l(
|
|
53
|
+
l(n), r.current = n;
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
}, [
|
|
57
|
+
}, [d]);
|
|
58
58
|
const pe = (e) => {
|
|
59
59
|
switch (e.code) {
|
|
60
60
|
case 400:
|
|
@@ -66,40 +66,38 @@ const tt = () => {
|
|
|
66
66
|
|
|
67
67
|
It seems I might be having some issues right now. Please clear the chat and try again.`;
|
|
68
68
|
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
return
|
|
73
|
-
}), f(!1), h(!1),
|
|
74
|
-
},
|
|
75
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
69
|
+
}, J = (e) => {
|
|
70
|
+
W(e), l((t) => {
|
|
71
|
+
const s = [...t], n = s[s.length - 1];
|
|
72
|
+
return n && (n.content = pe(e)), s;
|
|
73
|
+
}), f(!1), h(!1), U(), k();
|
|
74
|
+
}, A = !p.trim() && !y.length || T, fe = (e) => {
|
|
75
|
+
e.key === "Enter" && !e.shiftKey && !A && !e.nativeEvent.isComposing && (e.preventDefault(), $());
|
|
76
76
|
}, he = (e) => {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
if (
|
|
77
|
+
const t = e.target.value;
|
|
78
|
+
N(t);
|
|
79
|
+
}, $ = async (e = p) => {
|
|
80
|
+
if (A && (!e || e.trim().length === 0)) return;
|
|
81
81
|
f(!0);
|
|
82
|
-
const
|
|
83
|
-
let
|
|
84
|
-
const i =
|
|
85
|
-
|
|
86
|
-
const
|
|
82
|
+
const t = _ ? u.length === 2 : u.length === 0, s = xe(_, y, t);
|
|
83
|
+
let n;
|
|
84
|
+
const i = De(y);
|
|
85
|
+
y.length && i ? n = [{ type: "text", text: i }] : n = e;
|
|
86
|
+
const q = {
|
|
87
87
|
id: `${Date.now().toString()}1`,
|
|
88
88
|
role: "user",
|
|
89
|
-
content:
|
|
90
|
-
metadata:
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
});
|
|
89
|
+
content: n,
|
|
90
|
+
metadata: s
|
|
91
|
+
}, E = [...u.length ? [] : H, q];
|
|
92
|
+
d && j(), l((I) => [...I, ...E]), r.current = [...r.current, ...E], C([]), N(""), b(
|
|
93
|
+
{
|
|
94
|
+
eventName: "user_message_submitted",
|
|
95
|
+
properties: {}
|
|
96
|
+
},
|
|
97
|
+
r.current
|
|
98
|
+
);
|
|
101
99
|
try {
|
|
102
|
-
const
|
|
100
|
+
const I = {
|
|
103
101
|
model: re,
|
|
104
102
|
messages: r.current,
|
|
105
103
|
stream: !0,
|
|
@@ -107,121 +105,117 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
107
105
|
tool_choice: "auto"
|
|
108
106
|
}, G = await te(), Me = G ? btoa(JSON.stringify(G)) : null, V = K ? void 0 : {
|
|
109
107
|
"X-INKEEP-CHALLENGE-SOLUTION": Me
|
|
110
|
-
},
|
|
111
|
-
|
|
108
|
+
}, v = se.beta.chat.completions.stream(
|
|
109
|
+
I,
|
|
112
110
|
V ? { headers: V } : void 0
|
|
113
|
-
),
|
|
111
|
+
), o = {
|
|
114
112
|
id: `${Date.now().toString()}2`,
|
|
115
113
|
role: "assistant",
|
|
116
114
|
content: "",
|
|
117
115
|
links: []
|
|
118
116
|
};
|
|
119
|
-
l((m) => [...m,
|
|
120
|
-
h(!0),
|
|
121
|
-
const a = [
|
|
122
|
-
return
|
|
117
|
+
l((m) => [...m, o]), v.on("content", (m, x) => {
|
|
118
|
+
h(!0), o.content = x, l((D) => {
|
|
119
|
+
const a = [...D], g = a.findIndex((M) => M.id === o.id);
|
|
120
|
+
return g === -1 ? [...a, o] : (a[g] = { ...o }, a);
|
|
123
121
|
});
|
|
124
|
-
}),
|
|
125
|
-
const { name:
|
|
126
|
-
if (
|
|
127
|
-
const a = JSON.parse(
|
|
128
|
-
a.links?.length > 0 && (
|
|
129
|
-
const
|
|
130
|
-
return
|
|
122
|
+
}), v.on("tool_calls.function.arguments.done", (m) => {
|
|
123
|
+
const { name: x, arguments: D } = m;
|
|
124
|
+
if (x === "provideLinks") {
|
|
125
|
+
const a = JSON.parse(D);
|
|
126
|
+
a.links?.length > 0 && (o.links = a.links, l((g) => {
|
|
127
|
+
const M = [...g], Se = M.findIndex((ke) => ke.id === o.id);
|
|
128
|
+
return M[Se] = { ...o }, M;
|
|
131
129
|
}));
|
|
132
130
|
} else {
|
|
133
131
|
const a = ie?.(m);
|
|
134
|
-
a &&
|
|
135
|
-
...
|
|
136
|
-
[
|
|
132
|
+
a && z((g) => ({
|
|
133
|
+
...g,
|
|
134
|
+
[o.id]: [...g[o.id] || [], a]
|
|
137
135
|
}));
|
|
138
136
|
}
|
|
139
|
-
}),
|
|
140
|
-
|
|
141
|
-
}),
|
|
142
|
-
r.current = [...r.current,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
}), C.current = M.controller;
|
|
154
|
-
} catch (v) {
|
|
155
|
-
q(v), f(!1), h(!1);
|
|
137
|
+
}), v.on("error", (m) => {
|
|
138
|
+
J(m);
|
|
139
|
+
}), v.finalChatCompletion().then(() => {
|
|
140
|
+
r.current = [...r.current, o], w.current = null, f(!1), h(!1), k(), b(
|
|
141
|
+
{
|
|
142
|
+
eventName: "assistant_message_received",
|
|
143
|
+
properties: {}
|
|
144
|
+
},
|
|
145
|
+
r.current
|
|
146
|
+
);
|
|
147
|
+
}), w.current = v.controller;
|
|
148
|
+
} catch (I) {
|
|
149
|
+
J(I), f(!1), h(!1);
|
|
156
150
|
}
|
|
157
|
-
},
|
|
158
|
-
|
|
151
|
+
}, ye = () => {
|
|
152
|
+
w.current && (w.current.abort(), w.current = null), f(!1), h(!1), k();
|
|
159
153
|
}, Q = () => {
|
|
160
|
-
|
|
161
|
-
eventName: "
|
|
154
|
+
W(null), l([]), r.current = [], ee(), z({}), C([]), j(), F(null), U(), k(), b({
|
|
155
|
+
eventName: "chat_clear_button_clicked",
|
|
162
156
|
properties: {
|
|
163
|
-
|
|
157
|
+
conversation: Z
|
|
164
158
|
}
|
|
165
159
|
});
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
const { initialReplyMessage:
|
|
160
|
+
}, Ce = (e) => {
|
|
161
|
+
F(e);
|
|
162
|
+
const { initialReplyMessage: t, displayName: s } = e, n = {
|
|
169
163
|
id: u.length.toString(),
|
|
170
164
|
role: "user",
|
|
171
|
-
content:
|
|
165
|
+
content: s
|
|
172
166
|
}, i = {
|
|
173
167
|
id: (u.length + 1).toString(),
|
|
174
168
|
role: "assistant",
|
|
175
|
-
content:
|
|
169
|
+
content: t,
|
|
176
170
|
links: []
|
|
177
|
-
},
|
|
178
|
-
id: `system-${e.id}`,
|
|
171
|
+
}, E = [{
|
|
172
|
+
id: `system-${Date.now().toString()}-${e.id}`,
|
|
179
173
|
role: "system",
|
|
180
174
|
content: `Company has asked user to follow this guided workflow:
|
|
181
|
-
${
|
|
175
|
+
${Le(
|
|
182
176
|
e
|
|
183
177
|
)}`
|
|
184
|
-
}, ...
|
|
185
|
-
l(
|
|
186
|
-
}, { openForm:
|
|
187
|
-
|
|
188
|
-
submitMessage:
|
|
178
|
+
}, ...H, n, i];
|
|
179
|
+
l(E), C([]);
|
|
180
|
+
}, { openForm: we } = Pe(), Ie = Ke();
|
|
181
|
+
Ee(R.chatFunctionsRef, () => ({
|
|
182
|
+
submitMessage: $,
|
|
189
183
|
updateInputMessage(e) {
|
|
190
|
-
|
|
184
|
+
N(e);
|
|
191
185
|
},
|
|
192
186
|
clearChat: Q,
|
|
193
187
|
openForm: (e) => {
|
|
194
|
-
|
|
188
|
+
Ie?.setView("chat"), we(e);
|
|
195
189
|
},
|
|
196
190
|
focusInput: () => {
|
|
197
|
-
|
|
191
|
+
B.current?.focus();
|
|
198
192
|
}
|
|
199
193
|
}));
|
|
200
194
|
const ve = Oe("(max-width: 768px)");
|
|
201
195
|
return {
|
|
202
196
|
messages: u,
|
|
203
197
|
input: p,
|
|
204
|
-
isLoading:
|
|
198
|
+
isLoading: T,
|
|
205
199
|
isStreaming: ce,
|
|
206
|
-
isLoadingConversation:
|
|
200
|
+
isLoadingConversation: ge,
|
|
207
201
|
error: le,
|
|
208
|
-
isSubmitDisabled:
|
|
202
|
+
isSubmitDisabled: A,
|
|
209
203
|
handleInputChange: he,
|
|
210
204
|
handleInputKeyDown: fe,
|
|
211
|
-
handleSubmit:
|
|
212
|
-
stop:
|
|
205
|
+
handleSubmit: $,
|
|
206
|
+
stop: ye,
|
|
213
207
|
clear: Q,
|
|
214
|
-
handleWorkflow:
|
|
215
|
-
selectedWorkflow:
|
|
216
|
-
messageAttachments:
|
|
217
|
-
setMessageAttachments:
|
|
208
|
+
handleWorkflow: Ce,
|
|
209
|
+
selectedWorkflow: _,
|
|
210
|
+
messageAttachments: y,
|
|
211
|
+
setMessageAttachments: C,
|
|
218
212
|
addAttachment: ue,
|
|
219
213
|
messageToolCalls: me,
|
|
220
214
|
isEmpty: u.length === 0,
|
|
221
|
-
inputRef:
|
|
215
|
+
inputRef: B,
|
|
222
216
|
isMobile: ve
|
|
223
217
|
};
|
|
224
218
|
};
|
|
225
219
|
export {
|
|
226
|
-
|
|
220
|
+
et as useInkeepChat
|
|
227
221
|
};
|