@inkeep/cxkit-primitives 0.5.26 → 0.5.30

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