@inkeep/cxkit-primitives 0.5.45 → 0.5.47

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