@inkeep/cxkit-primitives 0.5.108 → 0.5.109

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 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../providers/conversation-provider.cjs"),a=require("../../providers/chat-events-provider.cjs"),p=require("../../providers/chat-form-provider.cjs"),c=require("../modal/modal-provider.cjs"),u=e=>{const{logEvent:n}=a.useChatEvents(),{conversation:o}=l.useInkeepConversation(),{openForm:t}=p.useChatForm(),i=c.useModal();return{handleAction:r=>{if(e.action.type==="open_form"){r?.onOpenForm?.();const s="name"in e?e:void 0;t?.(e.action.formSettings,s)}else e.action.type==="invoke_callback"&&(e.action.callback({conversation:o}),e.action.shouldCloseModal&&i?.setOpen(!1))},logHelpAction:()=>{"name"in e&&(n({eventName:"get_help_option_clicked",properties:{getHelpOption:e,conversation:o}}),e.action.type!=="open_form"&&n({eventName:"user_escalation_indicated",properties:{escalationType:"get_help_option",getHelpOption:e,conversation:o}}))}}};exports.useChatAction=u;
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"),a=require("../../providers/chat-form-provider.cjs"),p=require("../modal/modal-provider.cjs"),c=e=>{const{logEvent:n}=l.useChatEvents(),{conversation:o}=s.useInkeepConversation(),{openForm:t}=a.useChatForm(),r=p.useModal();return{handleAction:i=>{e.action.type==="open_form"?(i?.onOpenForm?.(),t?.(e.action.formSettings,e)):e.action.type==="invoke_callback"&&(e.action.callback({conversation:o}),e.action.shouldCloseModal&&r?.setOpen(!1))},logHelpAction:()=>{"name"in e&&(n({eventName:"get_help_option_clicked",properties:{getHelpOption:e,conversation:o}}),e.action.type!=="open_form"&&n({eventName:"user_escalation_indicated",properties:{escalationType:"get_help_option",getHelpOption:e,conversation:o}}))}}};exports.useChatAction=c;
@@ -1,16 +1,12 @@
1
1
  "use client";
2
- import { useInkeepConversation as l } from "../../providers/conversation-provider.js";
3
- import { useChatEvents as r } from "../../providers/chat-events-provider.js";
4
- import { useChatForm as a } from "../../providers/chat-form-provider.js";
5
- import { useModal as m } from "../modal/modal-provider.js";
6
- const v = (e) => {
7
- const { logEvent: n } = r(), { conversation: o } = l(), { openForm: t } = a(), p = m();
2
+ import { useInkeepConversation as s } from "../../providers/conversation-provider.js";
3
+ import { useChatEvents as l } from "../../providers/chat-events-provider.js";
4
+ import { useChatForm as r } from "../../providers/chat-form-provider.js";
5
+ import { useModal as a } from "../modal/modal-provider.js";
6
+ const g = (e) => {
7
+ const { logEvent: n } = l(), { conversation: o } = s(), { openForm: t } = r(), p = a();
8
8
  return { handleAction: (i) => {
9
- if (e.action.type === "open_form") {
10
- i?.onOpenForm?.();
11
- const s = "name" in e ? e : void 0;
12
- t?.(e.action.formSettings, s);
13
- } else e.action.type === "invoke_callback" && (e.action.callback({
9
+ e.action.type === "open_form" ? (i?.onOpenForm?.(), t?.(e.action.formSettings, e)) : e.action.type === "invoke_callback" && (e.action.callback({
14
10
  conversation: o
15
11
  }), e.action.shouldCloseModal && p?.setOpen(!1));
16
12
  }, logHelpAction: () => {
@@ -31,5 +27,5 @@ const v = (e) => {
31
27
  } };
32
28
  };
33
29
  export {
34
- v as useChatAction
30
+ g as useChatAction
35
31
  };
@@ -1,4 +1,4 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("openai"),t=require("react"),Le=require("../../providers/config-provider.cjs"),xe=require("../../providers/conversation-provider.cjs"),Be=require("../../providers/chat-events-provider.cjs"),F=require("../../utils/get-message-metadata.cjs"),re=require("../../utils/reset-query-params.cjs"),Oe=require("../../providers/chat-form-provider.cjs"),De=require("../../providers/widget-provider.cjs"),Fe=require("../../hooks/use-media-query.cjs"),Te=require("./use-captcha.cjs"),Ke=require("../modal/modal-provider.cjs"),g=require("../../utils/generate-uid.cjs"),Qe=require("../../utils/tools/links-tool.cjs"),We=require("../../atoms/api/analytics/conversation.cjs"),Je=require("../../utils/misc.cjs"),ze=()=>{const{chatId:y,isSharedChat:ie,setConversation:ce,conversation:A,resetConversation:le}=xe.useInkeepConversation(),{baseSettings:q,aiChatSettings:T}=Le.useInkeepConfig(),{aiApiBaseUrl:K,shouldBypassCaptcha:Q,filters:W}=q,J=Ke.useModal(),{getSolution:ue,prefetchSolution:P,invalidateSolution:z}=Te.useCaptcha({fetchUrl:`${K}/v1/challenge`,shouldBypassCaptcha:Q,shouldMakeInitialRequest:J?J.isOpen:!0}),de=new ae({baseURL:`${K}/v1`,apiKey:q.apiKey??"",dangerouslyAllowBrowser:!0}),{onInputMessageChange:ge,getTools:me,prompts:pe,model:fe,filters:H,onToolCall:he}=T,[S,R]=t.useState(""),j=t.useRef(null);t.useEffect(()=>{ge?.(S)},[S]);const[m,l]=t.useState([]),[G,M]=t.useState(!1),[ve,w]=t.useState(!1),[ye,V]=t.useState(null),[L,X]=t.useState(null),[C,I]=t.useState([]),Se=e=>{I(s=>[...s,e])},[Me,Y]=t.useState({}),o=t.useRef([]),k=t.useRef(null),{logEvent:b}=Be.useChatEvents(),Z=pe?.map((e,s)=>({id:`system-${Date.now().toString()}-${g.generateUid(4)}-${s}`,role:"system",content:e})),[we,Ce]=t.useState(!!y);t.useEffect(()=>{if(y){const{apiKey:e,analyticsApiBaseUrl:s}=q;We.getConversation(y,e,s).then(a=>{if(a){b({eventName:"shared_chat_loaded",properties:{conversation:a}}),Ce(!1),ce({...a});const r=a.messages.map(p=>({...p,content:Je.parseIfJson(p.content)}));l(r),o.current=r}})}},[y]);const Ie=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${q.organizationDisplayName??"Administrator"}`;default:return`Hmm..
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("openai"),t=require("react"),Be=require("../../providers/config-provider.cjs"),Oe=require("../../providers/conversation-provider.cjs"),De=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),re=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"),g=require("../../utils/generate-uid.cjs"),Je=require("../../utils/tools/links-tool.cjs"),ze=require("../../atoms/api/analytics/conversation.cjs"),He=require("../../utils/misc.cjs"),je=()=>{const{chatId:y,isSharedChat:ie,setConversation:ce,conversation:le,resetConversation:ue}=Oe.useInkeepConversation(),{baseSettings:q,aiChatSettings:F}=Be.useInkeepConfig(),{aiApiBaseUrl:T,shouldBypassCaptcha:K,filters:Q}=q,W=We.useModal(),{getSolution:de,prefetchSolution:P,invalidateSolution:J}=Qe.useCaptcha({fetchUrl:`${T}/v1/challenge`,shouldBypassCaptcha:K,shouldMakeInitialRequest:W?W.isOpen:!0}),ge=new ae({baseURL:`${T}/v1`,apiKey:q.apiKey??"",dangerouslyAllowBrowser:!0}),{onInputMessageChange:me,getTools:pe,prompts:fe,model:he,filters:z,onToolCall:ve}=F,[S,A]=t.useState(""),H=t.useRef(null);t.useEffect(()=>{me?.(S)},[S]);const[m,l]=t.useState([]),[j,w]=t.useState(!1),[ye,C]=t.useState(!1),[Se,G]=t.useState(null),[L,V]=t.useState(null),[M,I]=t.useState([]),we=e=>{I(s=>[...s,e])},[Ce,X]=t.useState({}),o=t.useRef([]),k=t.useRef(null),{logEvent:b,getLatestConversation:Y}=De.useChatEvents(),Z=fe?.map((e,s)=>({id:`system-${Date.now().toString()}-${g.generateUid(4)}-${s}`,role:"system",content:e})),[Me,Ie]=t.useState(!!y);t.useEffect(()=>{if(y){const{apiKey:e,analyticsApiBaseUrl:s}=q;ze.getConversation(y,e,s).then(a=>{if(a){b({eventName:"shared_chat_loaded",properties:{conversation:a}}),Ie(!1),ce({...a});const r=a.messages.map(p=>({...p,content:He.parseIfJson(p.content)}));l(r),o.current=r}})}},[y]);const ke=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${q.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.`}},ee=e=>{V(e),l(s=>{const a=[...s],r=a[a.length-1];return r&&(r.content=Ie(e)),a}),M(!1),w(!1),z(),P()},x=!S.trim()&&!C.length||G,ke=e=>{e.key==="Enter"&&!e.shiftKey&&!x&&!e.nativeEvent.isComposing&&(e.preventDefault(),B())},be=e=>{const s=e.target.value;R(s)},B=async(e=S)=>{if(x&&(!e||e.trim().length===0))return;M(!0);const s=L?m.length===2:m.length===0,a=F.getMessageMetadata(L,C,s);let r;const p=F.serializeAttachments(C);C.length&&p?r=[{type:"text",text:p}]:r=e;const se={id:`${Date.now().toString()}-${g.generateUid(4)}-1`,role:"user",content:r,metadata:a},f=[...m.length?[]:Z,se];if(ie&&y){re.resetQueryParams();const u=o.current.map((i,E)=>({id:`${i.id}-${g.generateUid(6)}-${E}`,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];I([]),R(""),b({eventName:"user_message_submitted",properties:{}},o.current);const ne=[Qe.provideLinksTool,...me?.({conversation:A})||[]];try{const u={model:fe,messages:o.current,stream:!0,tools:ne,tool_choice:"auto"},i=await ue(),E=i?btoa(JSON.stringify(i)):null,oe=W||H?JSON.stringify({...W,...H}):void 0,U={};!Q&&E&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=E),oe&&(U["inkeep-filters"]=oe);const h=de.beta.chat.completions.stream(u,Object.keys(U).length>0?{headers:U}:void 0),n={id:`${Date.now().toString()}-${g.generateUid(4)}-2`,role:"assistant",content:"",links:[],tool_calls:[]};l(d=>[...d,n]),h.on("content",(d,_)=>{w(!0),n.content=_,l(N=>{const c=[...N],O=c.findIndex($=>$.id===n.id);return O===-1?[...c,n]:(c[O]={...n},c)})}),h.on("tool_calls.function.arguments.done",async d=>{const{name:_,arguments:N}=d,c=ne?.find(v=>v.function.name===_);if(!c)return;const $=("parse"in c.function?c.function.parse:JSON.parse)(N),Ue=c.function.function?.($,h),Ne=c.renderMessageButtons?.({args:$,execution:Ue})??[];_==="provideLinks"?n.links=$.links??[]:Y(v=>({...v,[n.id]:[...v[n.id]??[],...Ne]})),n.tool_calls?.push({id:"call_"+g.generateUid(24),type:"function",function:{name:_,arguments:N}}),l(v=>{const D=[...v],Ae=D.findIndex(Re=>Re.id===n.id);return D[Ae]={...n},D}),he?.(d,{conversation:{...A,messages:[...o.current,n]}})}),h.on("error",ee),h.finalChatCompletion().then(async()=>{o.current=[...o.current,n],k.current=null,M(!1),w(!1),P(),await b({eventName:"assistant_message_received",properties:{}},o.current),b({eventName:"assistant_answer_displayed",properties:{}})}).catch(d=>{d instanceof ae.APIUserAbortError||console.warn(d)}),k.current=h.controller}catch(u){ee(u),M(!1),w(!1)}},_e=()=>{k.current&&(k.current.abort(),k.current=null),M(!1),w(!1),P()},te=()=>{V(null),l([]),o.current=[],le(),Y({}),I([]),re.resetQueryParams(),X(null),z(),P(),b({eventName:"chat_clear_button_clicked",properties:{conversation:A}})},$e=e=>{X(e);const{initialReplyMessage:s,displayName:a}=e,r={id:m.length.toString()+g.generateUid(4),role:"user",content:a},p={id:(m.length+1).toString()+g.generateUid(4),role:"assistant",content:s,links:[]},f=[{id:`system-${Date.now().toString()}-${g.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
4
- ${F.serializeWorkflow(e)}`},...Z,r,p];l(f),I([])},{openForm:qe}=Oe.useChatForm(),Pe=De.useWidget();t.useImperativeHandle(T.chatFunctionsRef,()=>({submitMessage:B,updateInputMessage(e){R(e)},clearChat:te,openForm:e=>{Pe?.setView("chat"),qe(e)},focusInput:()=>{j.current?.focus()}}));const Ee=Fe.useMediaQuery("(max-width: 768px)");return{messages:m,input:S,isLoading:G,isStreaming:ve,isLoadingConversation:we,error:ye,isSubmitDisabled:x,handleInputChange:be,handleInputKeyDown:ke,handleSubmit:B,stop:_e,clear:te,handleWorkflow:$e,selectedWorkflow:L,messageAttachments:C,setMessageAttachments:I,addAttachment:Se,messageButtons:Me,isEmpty:m.length===0,inputRef:j,isMobile:Ee}};exports.useInkeepChat=ze;
3
+ It seems I might be having some issues right now. Please clear the chat and try again.`}},ee=e=>{G(e),l(s=>{const a=[...s],r=a[a.length-1];return r&&(r.content=ke(e)),a}),w(!1),C(!1),J(),P()},R=!S.trim()&&!M.length||j,be=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),x())},_e=e=>{const s=e.target.value;A(s)},x=async(e=S)=>{if(R&&(!e||e.trim().length===0))return;w(!0);const s=L?m.length===2:m.length===0,a=D.getMessageMetadata(L,M,s);let r;const p=D.serializeAttachments(M);M.length&&p?r=[{type:"text",text:p}]:r=e;const se={id:`${Date.now().toString()}-${g.generateUid(4)}-1`,role:"user",content:r,metadata:a},f=[...m.length?[]:Z,se];if(ie&&y){re.resetQueryParams();const u=o.current.map((i,E)=>({id:`${i.id}-${g.generateUid(6)}-${E}`,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];I([]),A(""),await b({eventName:"user_message_submitted",properties:{}},o.current);const Ne=Y(),ne=[Je.provideLinksTool,...pe?.({conversation:Ne})||[]];try{const u={model:he,messages:o.current,stream:!0,tools:ne,tool_choice:"auto"},i=await de(),E=i?btoa(JSON.stringify(i)):null,oe=Q||z?JSON.stringify({...Q,...z}):void 0,U={};!K&&E&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=E),oe&&(U["inkeep-filters"]=oe);const h=ge.beta.chat.completions.stream(u,Object.keys(U).length>0?{headers:U}:void 0),n={id:`${Date.now().toString()}-${g.generateUid(4)}-2`,role:"assistant",content:"",links:[],tool_calls:[]};l(d=>[...d,n]),h.on("content",(d,_)=>{C(!0),n.content=_,l(N=>{const c=[...N],B=c.findIndex($=>$.id===n.id);return B===-1?[...c,n]:(c[B]={...n},c)})}),h.on("tool_calls.function.arguments.done",async d=>{const{name:_,arguments:N}=d,c=ne?.find(v=>v.function.name===_);if(!c)return;const $=("parse"in c.function?c.function.parse:JSON.parse)(N),Ae=c.function.function?.($,h),Le=c.renderMessageButtons?.({args:$,execution:Ae})??[];_==="provideLinks"?n.links=$.links??[]:X(v=>({...v,[n.id]:[...v[n.id]??[],...Le]})),n.tool_calls?.push({id:"call_"+g.generateUid(24),type:"function",function:{name:_,arguments:N}}),l(v=>{const O=[...v],Re=O.findIndex(xe=>xe.id===n.id);return O[Re]={...n},O}),ve?.(d,{conversation:{...Y(),messages:[...o.current,n]}})}),h.on("error",ee),h.finalChatCompletion().then(async()=>{o.current=[...o.current,n],k.current=null,w(!1),C(!1),P(),await b({eventName:"assistant_message_received",properties:{}},o.current),b({eventName:"assistant_answer_displayed",properties:{}})}).catch(d=>{d instanceof ae.APIUserAbortError||console.warn(d)}),k.current=h.controller}catch(u){ee(u),w(!1),C(!1)}},$e=()=>{k.current&&(k.current.abort(),k.current=null),w(!1),C(!1),P()},te=()=>{G(null),l([]),o.current=[],ue(),X({}),I([]),re.resetQueryParams(),V(null),J(),P(),b({eventName:"chat_clear_button_clicked",properties:{conversation:le}})},qe=e=>{V(e);const{initialReplyMessage:s,displayName:a}=e,r={id:m.length.toString()+g.generateUid(4),role:"user",content:a},p={id:(m.length+1).toString()+g.generateUid(4),role:"assistant",content:s,links:[]},f=[{id:`system-${Date.now().toString()}-${g.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
4
+ ${D.serializeWorkflow(e)}`},...Z,r,p];l(f),I([])},{openForm:Pe}=Fe.useChatForm(),Ee=Te.useWidget();t.useImperativeHandle(F.chatFunctionsRef,()=>({submitMessage:x,updateInputMessage(e){A(e)},clearChat:te,openForm:e=>{Ee?.setView("chat"),Pe(e)},focusInput:()=>{H.current?.focus()}}));const Ue=Ke.useMediaQuery("(max-width: 768px)");return{messages:m,input:S,isLoading:j,isStreaming:ye,isLoadingConversation:Me,error:Se,isSubmitDisabled:R,handleInputChange:_e,handleInputKeyDown:be,handleSubmit:x,stop:$e,clear:te,handleWorkflow:qe,selectedWorkflow:L,messageAttachments:M,setMessageAttachments:I,addAttachment:we,messageButtons:Ce,isEmpty:m.length===0,inputRef:H,isMobile:Ue}};exports.useInkeepChat=je;
@@ -1,68 +1,68 @@
1
1
  "use client";
2
- import Oe, { APIUserAbortError as Pe } from "openai";
3
- import { useState as l, useRef as K, useEffect as ae, useImperativeHandle as Re } 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";
2
+ import Re, { APIUserAbortError as Ue } from "openai";
3
+ import { useState as l, useRef as F, useEffect as ae, useImperativeHandle as Fe } from "react";
4
+ import { useInkeepConfig as Ke } from "../../providers/config-provider.js";
5
+ import { useInkeepConversation as Te } from "../../providers/conversation-provider.js";
6
+ import { useChatEvents as We } from "../../providers/chat-events-provider.js";
7
+ import { getMessageMetadata as Je, serializeAttachments as ze, serializeWorkflow as He } from "../../utils/get-message-metadata.js";
8
8
  import { resetQueryParams as re } from "../../utils/reset-query-params.js";
9
- import { useChatForm as ze } from "../../providers/chat-form-provider.js";
10
- import { useWidget as He } from "../../providers/widget-provider.js";
11
- import { useMediaQuery as Qe } from "../../hooks/use-media-query.js";
12
- import { useCaptcha as je } from "./use-captcha.js";
13
- import { useModal as qe } from "../modal/modal-provider.js";
9
+ import { useChatForm as Qe } from "../../providers/chat-form-provider.js";
10
+ import { useWidget as je } from "../../providers/widget-provider.js";
11
+ import { useMediaQuery as qe } from "../../hooks/use-media-query.js";
12
+ import { useCaptcha as Ge } from "./use-captcha.js";
13
+ import { useModal as Ve } from "../modal/modal-provider.js";
14
14
  import { generateUid as g } from "../../utils/generate-uid.js";
15
- import { provideLinksTool as Ge } from "../../utils/tools/links-tool.js";
16
- import { getConversation as Ve } from "../../atoms/api/analytics/conversation.js";
17
- import { parseIfJson as Xe } from "../../utils/misc.js";
18
- const dt = () => {
19
- const { chatId: w, isSharedChat: ie, setConversation: ce, conversation: B, resetConversation: le } = Fe(), { baseSettings: E, aiChatSettings: T } = Ue(), { aiApiBaseUrl: W, shouldBypassCaptcha: J, filters: z } = E, H = qe(), { getSolution: ue, prefetchSolution: N, invalidateSolution: Q } = je({
20
- fetchUrl: `${W}/v1/challenge`,
21
- shouldBypassCaptcha: J,
22
- shouldMakeInitialRequest: H ? H.isOpen : !0
23
- }), me = new Oe({
24
- baseURL: `${W}/v1`,
15
+ import { provideLinksTool as Xe } from "../../utils/tools/links-tool.js";
16
+ import { getConversation as Ye } from "../../atoms/api/analytics/conversation.js";
17
+ import { parseIfJson as Ze } from "../../utils/misc.js";
18
+ const ht = () => {
19
+ const { chatId: v, isSharedChat: ie, setConversation: ce, conversation: le, resetConversation: ue } = Te(), { baseSettings: E, aiChatSettings: K } = Ke(), { aiApiBaseUrl: T, shouldBypassCaptcha: W, filters: J } = E, z = Ve(), { getSolution: me, prefetchSolution: N, invalidateSolution: H } = Ge({
20
+ fetchUrl: `${T}/v1/challenge`,
21
+ shouldBypassCaptcha: W,
22
+ shouldMakeInitialRequest: z ? z.isOpen : !0
23
+ }), ge = new Re({
24
+ baseURL: `${T}/v1`,
25
25
  apiKey: E.apiKey ?? "",
26
26
  dangerouslyAllowBrowser: !0
27
27
  }), {
28
- onInputMessageChange: ge,
29
- getTools: pe,
30
- prompts: de,
31
- model: fe,
32
- filters: j,
33
- onToolCall: he
34
- } = T, [v, D] = l(""), q = K(null);
28
+ onInputMessageChange: pe,
29
+ getTools: de,
30
+ prompts: fe,
31
+ model: he,
32
+ filters: Q,
33
+ onToolCall: ye
34
+ } = K, [w, B] = l(""), j = F(null);
35
35
  ae(() => {
36
- ge?.(v);
37
- }, [v]);
38
- const [p, c] = l([]), [G, C] = l(!1), [ye, I] = l(!1), [we, V] = l(null), [O, X] = l(null), [M, S] = l([]), ve = (e) => {
36
+ pe?.(w);
37
+ }, [w]);
38
+ const [p, c] = l([]), [q, C] = l(!1), [ve, I] = l(!1), [we, G] = l(null), [D, V] = l(null), [M, S] = l([]), Ce = (e) => {
39
39
  S((t) => [...t, e]);
40
- }, [Ce, Y] = l({}), n = K([]), k = K(null), { logEvent: _ } = Ke(), Z = de?.map((e, t) => ({
40
+ }, [Ie, X] = l({}), n = F([]), k = F(null), { logEvent: _, getLatestConversation: Y } = We(), Z = fe?.map((e, t) => ({
41
41
  id: `system-${Date.now().toString()}-${g(4)}-${t}`,
42
42
  role: "system",
43
43
  content: e
44
- })), [Ie, Me] = l(!!w);
44
+ })), [Me, Se] = l(!!v);
45
45
  ae(() => {
46
- if (w) {
46
+ if (v) {
47
47
  const { apiKey: e, analyticsApiBaseUrl: t } = E;
48
- Ve(w, e, t).then((o) => {
48
+ Ye(v, e, t).then((o) => {
49
49
  if (o) {
50
50
  _({
51
51
  eventName: "shared_chat_loaded",
52
52
  properties: {
53
53
  conversation: o
54
54
  }
55
- }), Me(!1), ce({ ...o });
55
+ }), Se(!1), ce({ ...o });
56
56
  const a = o.messages.map((d) => ({
57
57
  ...d,
58
- content: Xe(d.content)
58
+ content: Ze(d.content)
59
59
  }));
60
60
  c(a), n.current = a;
61
61
  }
62
62
  });
63
63
  }
64
- }, [w]);
65
- const Se = (e) => {
64
+ }, [v]);
65
+ const ke = (e) => {
66
66
  switch (e.code) {
67
67
  case 400:
68
68
  return e.message;
@@ -74,21 +74,21 @@ const dt = () => {
74
74
  It seems I might be having some issues right now. Please clear the chat and try again.`;
75
75
  }
76
76
  }, ee = (e) => {
77
- V(e), c((t) => {
77
+ G(e), c((t) => {
78
78
  const o = [...t], a = o[o.length - 1];
79
- return a && (a.content = Se(e)), o;
80
- }), C(!1), I(!1), Q(), N();
81
- }, P = !v.trim() && !M.length || G, ke = (e) => {
82
- e.key === "Enter" && !e.shiftKey && !P && !e.nativeEvent.isComposing && (e.preventDefault(), R());
83
- }, _e = (e) => {
79
+ return a && (a.content = ke(e)), o;
80
+ }), C(!1), I(!1), H(), N();
81
+ }, O = !w.trim() && !M.length || q, _e = (e) => {
82
+ e.key === "Enter" && !e.shiftKey && !O && !e.nativeEvent.isComposing && (e.preventDefault(), P());
83
+ }, be = (e) => {
84
84
  const t = e.target.value;
85
- D(t);
86
- }, R = async (e = v) => {
87
- if (P && (!e || e.trim().length === 0)) return;
85
+ B(t);
86
+ }, P = async (e = w) => {
87
+ if (O && (!e || e.trim().length === 0)) return;
88
88
  C(!0);
89
- const t = O ? p.length === 2 : p.length === 0, o = Te(O, M, t);
89
+ const t = D ? p.length === 2 : p.length === 0, o = Je(D, M, t);
90
90
  let a;
91
- const d = We(M);
91
+ const d = ze(M);
92
92
  M.length && d ? a = [{ type: "text", text: d }] : a = e;
93
93
  const se = {
94
94
  id: `${Date.now().toString()}-${g(4)}-1`,
@@ -96,7 +96,7 @@ It seems I might be having some issues right now. Please clear the chat and try
96
96
  content: a,
97
97
  metadata: o
98
98
  }, f = [...p.length ? [] : Z, se];
99
- if (ie && w) {
99
+ if (ie && v) {
100
100
  re();
101
101
  const u = n.current.map((r, A) => ({
102
102
  id: `${r.id}-${g(6)}-${A}`,
@@ -109,29 +109,29 @@ It seems I might be having some issues right now. Please clear the chat and try
109
109
  c([...u, ...f]), n.current = [...u, ...f];
110
110
  } else
111
111
  c((u) => [...u, ...f]), n.current = [...n.current, ...f];
112
- S([]), D(""), _(
112
+ S([]), B(""), await _(
113
113
  {
114
114
  eventName: "user_message_submitted",
115
115
  properties: {}
116
116
  },
117
117
  n.current
118
118
  );
119
- const ne = [Ge, ...pe?.({ conversation: B }) || []];
119
+ const xe = Y(), ne = [Xe, ...de?.({ conversation: xe }) || []];
120
120
  try {
121
121
  const u = {
122
- model: fe,
122
+ model: he,
123
123
  messages: n.current,
124
124
  stream: !0,
125
125
  tools: ne,
126
126
  tool_choice: "auto"
127
- }, r = await ue(), A = r ? btoa(JSON.stringify(r)) : null, oe = z || j ? JSON.stringify({
128
- ...z,
129
- ...j
130
- }) : void 0, x = {};
131
- !J && A && (x["X-INKEEP-CHALLENGE-SOLUTION"] = A), oe && (x["inkeep-filters"] = oe);
132
- const h = me.beta.chat.completions.stream(
127
+ }, r = await me(), A = r ? btoa(JSON.stringify(r)) : null, oe = J || Q ? JSON.stringify({
128
+ ...J,
129
+ ...Q
130
+ }) : void 0, L = {};
131
+ !W && A && (L["X-INKEEP-CHALLENGE-SOLUTION"] = A), oe && (L["inkeep-filters"] = oe);
132
+ const h = ge.beta.chat.completions.stream(
133
133
  u,
134
- Object.keys(x).length > 0 ? { headers: x } : void 0
134
+ Object.keys(L).length > 0 ? { headers: L } : void 0
135
135
  ), s = {
136
136
  id: `${Date.now().toString()}-${g(4)}-2`,
137
137
  role: "assistant",
@@ -140,30 +140,30 @@ It seems I might be having some issues right now. Please clear the chat and try
140
140
  tool_calls: []
141
141
  };
142
142
  c((m) => [...m, s]), h.on("content", (m, b) => {
143
- I(!0), s.content = b, c((L) => {
144
- const i = [...L], U = i.findIndex(($) => $.id === s.id);
145
- return U === -1 ? [...i, s] : (i[U] = { ...s }, i);
143
+ I(!0), s.content = b, c((x) => {
144
+ const i = [...x], R = i.findIndex(($) => $.id === s.id);
145
+ return R === -1 ? [...i, s] : (i[R] = { ...s }, i);
146
146
  });
147
147
  }), h.on("tool_calls.function.arguments.done", async (m) => {
148
- const { name: b, arguments: L } = m, i = ne?.find((y) => y.function.name === b);
148
+ const { name: b, arguments: x } = m, i = ne?.find((y) => y.function.name === b);
149
149
  if (!i) return;
150
- const $ = ("parse" in i.function ? i.function.parse : JSON.parse)(L), xe = i.function.function?.($, h), Le = i.renderMessageButtons?.({ args: $, execution: xe }) ?? [];
151
- b === "provideLinks" ? s.links = $.links ?? [] : Y((y) => ({
150
+ const $ = ("parse" in i.function ? i.function.parse : JSON.parse)(x), Be = i.function.function?.($, h), De = i.renderMessageButtons?.({ args: $, execution: Be }) ?? [];
151
+ b === "provideLinks" ? s.links = $.links ?? [] : X((y) => ({
152
152
  ...y,
153
- [s.id]: [...y[s.id] ?? [], ...Le]
153
+ [s.id]: [...y[s.id] ?? [], ...De]
154
154
  })), s.tool_calls?.push({
155
155
  id: "call_" + g(24),
156
156
  type: "function",
157
157
  function: {
158
158
  name: b,
159
- arguments: L
159
+ arguments: x
160
160
  }
161
161
  }), c((y) => {
162
- const F = [...y], Be = F.findIndex((De) => De.id === s.id);
163
- return F[Be] = { ...s }, F;
164
- }), he?.(m, {
162
+ const U = [...y], Oe = U.findIndex((Pe) => Pe.id === s.id);
163
+ return U[Oe] = { ...s }, U;
164
+ }), ye?.(m, {
165
165
  conversation: {
166
- ...B,
166
+ ...Y(),
167
167
  messages: [...n.current, s]
168
168
  }
169
169
  });
@@ -179,22 +179,22 @@ It seems I might be having some issues right now. Please clear the chat and try
179
179
  properties: {}
180
180
  });
181
181
  }).catch((m) => {
182
- m instanceof Pe || console.warn(m);
182
+ m instanceof Ue || console.warn(m);
183
183
  }), k.current = h.controller;
184
184
  } catch (u) {
185
185
  ee(u), C(!1), I(!1);
186
186
  }
187
- }, be = () => {
187
+ }, $e = () => {
188
188
  k.current && (k.current.abort(), k.current = null), C(!1), I(!1), N();
189
189
  }, te = () => {
190
- V(null), c([]), n.current = [], le(), Y({}), S([]), re(), X(null), Q(), N(), _({
190
+ G(null), c([]), n.current = [], ue(), X({}), S([]), re(), V(null), H(), N(), _({
191
191
  eventName: "chat_clear_button_clicked",
192
192
  properties: {
193
- conversation: B
193
+ conversation: le
194
194
  }
195
195
  });
196
- }, $e = (e) => {
197
- X(e);
196
+ }, Ee = (e) => {
197
+ V(e);
198
198
  const { initialReplyMessage: t, displayName: o } = e, a = {
199
199
  id: p.length.toString() + g(4),
200
200
  role: "user",
@@ -208,48 +208,48 @@ It seems I might be having some issues right now. Please clear the chat and try
208
208
  id: `system-${Date.now().toString()}-${g(4)}-${e.id}`,
209
209
  role: "system",
210
210
  content: `Company has asked user to follow this guided workflow:
211
- ${Je(e)}`
211
+ ${He(e)}`
212
212
  }, ...Z, a, d];
213
213
  c(f), S([]);
214
- }, { openForm: Ee } = ze(), Ne = He();
215
- Re(T.chatFunctionsRef, () => ({
216
- submitMessage: R,
214
+ }, { openForm: Ne } = Qe(), Ae = je();
215
+ Fe(K.chatFunctionsRef, () => ({
216
+ submitMessage: P,
217
217
  updateInputMessage(e) {
218
- D(e);
218
+ B(e);
219
219
  },
220
220
  clearChat: te,
221
221
  openForm: (e) => {
222
- Ne?.setView("chat"), Ee(e);
222
+ Ae?.setView("chat"), Ne(e);
223
223
  },
224
224
  focusInput: () => {
225
- q.current?.focus();
225
+ j.current?.focus();
226
226
  }
227
227
  }));
228
- const Ae = Qe("(max-width: 768px)");
228
+ const Le = qe("(max-width: 768px)");
229
229
  return {
230
230
  messages: p,
231
- input: v,
232
- isLoading: G,
233
- isStreaming: ye,
234
- isLoadingConversation: Ie,
231
+ input: w,
232
+ isLoading: q,
233
+ isStreaming: ve,
234
+ isLoadingConversation: Me,
235
235
  error: we,
236
- isSubmitDisabled: P,
237
- handleInputChange: _e,
238
- handleInputKeyDown: ke,
239
- handleSubmit: R,
240
- stop: be,
236
+ isSubmitDisabled: O,
237
+ handleInputChange: be,
238
+ handleInputKeyDown: _e,
239
+ handleSubmit: P,
240
+ stop: $e,
241
241
  clear: te,
242
- handleWorkflow: $e,
243
- selectedWorkflow: O,
242
+ handleWorkflow: Ee,
243
+ selectedWorkflow: D,
244
244
  messageAttachments: M,
245
245
  setMessageAttachments: S,
246
- addAttachment: ve,
247
- messageButtons: Ce,
246
+ addAttachment: Ce,
247
+ messageButtons: Ie,
248
248
  isEmpty: p.length === 0,
249
- inputRef: q,
250
- isMobile: Ae
249
+ inputRef: j,
250
+ isMobile: Le
251
251
  };
252
252
  };
253
253
  export {
254
- dt as useInkeepChat
254
+ ht as useInkeepChat
255
255
  };
@@ -1,10 +1,10 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),ae=require("react-textarea-autosize"),ba=require("@radix-ui/react-avatar"),ga=require("@radix-ui/react-checkbox"),Pa=require("@radix-ui/react-popover"),Aa=require("@radix-ui/react-tooltip"),_a=require("@radix-ui/react-scroll-area"),I=require("../atoms/select.cjs"),A=require("../atoms/dialog.cjs"),Ea=require("../atoms/avatars/ai.cjs"),Fa=require("../atoms/avatars/user.cjs"),E=require("../atoms/icons/custom-icon.cjs"),x=require("../atoms/icons/built-in-icon-renderer.cjs"),ka=require("../atoms/link.cjs"),U=require("../atoms/markdown/index.cjs"),w=require("../providers/attachment-item-provider.cjs"),F=require("../providers/attachments-bar-provider.cjs"),B=require("../providers/source-item-provider.cjs"),p=require("../providers/config-provider.cjs"),L=require("../providers/conversation-provider.cjs"),O=require("../providers/chat-events-provider.cjs"),ne=require("../providers/feedback-provider.cjs"),q=require("../providers/message-attachments-provider.cjs"),P=require("../providers/message-provider.cjs"),be=require("../atoms/icons/checkbox-icon.cjs"),te=require("../hooks/use-copy-to-clipboard.cjs"),K=require("../providers/feedback-item-provider.cjs"),Ia=require("../utils/get-message-metadata.cjs"),h=require("../utils/misc.cjs"),a=require("./factory.cjs"),v=require("./embedded-chat/chat-provider.cjs"),Ma=require("./tagline-logo-icon.cjs"),Sa=require("../hooks/use-settle-action.cjs"),xa=require("../hooks/use-container-size.cjs"),se=require("./embedded-chat/use-chat-action.cjs"),ie=require("../providers/help-menu-provider.cjs"),_=require("../providers/chat-form-provider.cjs"),f=require("../providers/form-field-provider.cjs"),Ba=require("react-hook-form"),fa=require("../utils/highlight-emphasis.cjs"),Ta=require("./modal/modal-provider.cjs"),ja=require("@inkeep/cxkit-color-mode"),re=require("../utils/compose-refs.cjs"),u=require("../utils/compose-event-handlers.cjs"),ya=require("../hooks/use-scroll-to-bottom.cjs"),Ha=require("../atoms/api/analytics/conversation.cjs"),wa=require("../utils/transform-source/index.cjs"),La=require("../hooks/use-debounce.cjs"),oe=require("../providers/hover-popover-provider.cjs"),Da=require("./modal/widget-auto-focus.cjs");function R(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>t[i]})}}return e.default=t,Object.freeze(e)}const de=R(ba),z=R(ga),T=R(Pa),j=R(Aa),W=R(_a),Oa="__intro__",qa=a.ikp("div",{_id:"aiChatWrapper"}),ge=g.forwardRef((t,e)=>{const{...i}=t,{isHidden:s,isMobile:r}=v.useChat(),[o,d]=xa.useContainerSize(),c=re.useComposedRefs(e,o),m=d?.width?d.width>580:!0,l=Ta.useModal();return n.jsx(qa,{ref:c,"data-widget-md":h.dataAttr(m),"data-hidden":h.dataAttr(s),"data-in-modal":h.dataAttr(!!l),"data-mobile":h.dataAttr(r),...i})}),Ra=a.ikp("div",{_id:"aiChatConversationLoading"}),Pe=t=>{const{isLoadingConversation:e}=v.useChat();return e?n.jsx(Ra,{children:n.jsx("span",{children:"Loading..."}),...t}):null},Wa=a.ikp("div",{_id:"aiChatRoot"}),Ae=t=>{const{isLoadingConversation:e,isHidden:i}=v.useChat(),{form:s}=_.useChatForm();return e||s?null:n.jsx(Wa,{"data-hidden":h.dataAttr(i),...t})},Na=a.ikp("div",{_id:"aiChatHeader"}),_e=a.ikp("div",{_id:"aiChatHeader__Toolbar"}),Ee=a.ikp("div",{_id:"aiChatHeader__ToolbarHeaderWrapper"}),Qa=a.ikp("div",{_id:"aiChatHeader__ToolbarHeader"}),Fe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=`Ask ${e.aiAssistantName||"AI"}`;return n.jsx(Qa,{...t,children:i})}),ke=a.ikp("div",{_id:"aiChatContent"}),Ie=a.ikp(W.Root,{_id:"aiChatContentScrollArea"}),$a=a.ikp(W.Viewport,{_id:"aiChatContentScrollArea__Viewport"}),Me=g.forwardRef(({children:t,...e},i)=>{const{containerRef:s}=ya.useScrollToBottom(),r=re.useComposedRefs(i,s);return n.jsx($a,{ref:r,children:n.jsx("div",{"data-part":"grid",style:{display:"grid"},children:t}),...e})}),Se=a.ikp(W.ScrollAreaScrollbar,{_id:"aiChatContentScrollArea__Scrollbar"}),xe=a.ikp(W.ScrollAreaThumb,{_id:"aiChatContentScrollArea__Thumb"}),Be=a.ikp(W.Corner,{_id:"aiChatContentScrollArea__Corner"}),Va=a.ikp("div",{_id:"aiChatMessages"}),fe=t=>{const e=v.useChat(),{children:i,...s}=t;return n.jsx(Va,{children:h.maybeRender(i,e),...s})},Ua=a.ikp("div",{_id:"aiChatDisclaimer"}),Te=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),[i,s]=g.useState(!1),r=La.useDebounce(i,100);return e.disclaimerSettings?.isEnabled?n.jsx(oe.HoverPopoverProvider,{open:i,setOpen:s,children:n.jsx(T.Root,{open:r,onOpenChange:s,children:n.jsx(Ua,{...t})})}):null}),Ka=a.ikp("span",{_id:"aiChatDisclaimerLabel"}),je=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.disclaimerSettings;return n.jsx(Ka,{children:i?.label,...t})}),za=a.ikp(T.Trigger,{_id:"aiChatDisclaimerTrigger",children:n.jsx(E.CustomIcon,{iconKey:"info"})}),ye=g.memo(t=>{const{setOpen:e}=oe.useHoverPopover(),i=()=>e(!0),s=()=>e(!1);return n.jsx(za,{onMouseEnter:i,onMouseLeave:s,...t})}),Ga=a.ikp(T.Content,{_id:"aiChatDisclaimerContent"}),He=t=>{const{setOpen:e}=oe.useHoverPopover(),i=()=>e(!0),s=()=>e(!1);return n.jsx(Ga,{onMouseEnter:i,onMouseLeave:s,side:"top",sideOffset:8,align:"end",alignOffset:-10,...t})},Ya=a.ikp(U.Markdown,{_id:"aiChatDisclaimerText"}),we=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.aiAssistantName,r=e.disclaimerSettings?.tooltip||`Information provided by ${i||"this AI assistant"} is not guaranteed to be accurate or comprehensive.`;return n.jsx(Ya,{shouldOpenLinksInNewTab:!0,children:r,...t})}),Le=a.ikp(T.Arrow,{_id:"aiChatDisclaimerArrow"}),Ja=a.ikp("div",{_id:"aiChatExampleQuestions"}),De=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{messages:i}=v.useChat();return!e.exampleQuestions?.length||i.length?null:n.jsx(Ja,{...t})},Xa=a.ikp("h3",{_id:"aiChatExampleQuestionsLabel"}),Oe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(Xa,{children:e.exampleQuestionsLabel,...t})}),Za=a.ikp("div",{_id:"aiChatExampleQuestionsList"}),qe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.exampleQuestions,{children:s,...r}=t;return n.jsx(Za,{children:h.maybeRender(s,i),...r})}),en=a.ikp("div",{_id:"aiChatExampleQuestion"}),Re=g.forwardRef((t,e)=>{const{aiChatSettings:i}=p.useInkeepConfig(),s=i.isFirstExampleQuestionHighlighted;return n.jsx(en,{ref:e,"data-highlight":h.dataAttr(s),...t})}),tn=a.ikp("button",{_id:"aiChatExampleQuestionButton"}),We=t=>{const{question:e,onClick:i,...s}=t,{handleSubmit:r}=v.useChat();return n.jsx(tn,{onClick:u.composeEventHandlers(i,()=>r(e)),children:e,...s})},an=a.ikp("div",{_id:"aiChatWorkflows"}),Ne=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{messages:i}=v.useChat();return!e.workflows?.length||i.length?null:n.jsx(an,{...t})},nn=a.ikp("h3",{_id:"aiChatWorkflowsLabel"}),Qe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(nn,{children:e.workflowsHeader,...t})}),sn=a.ikp("div",{_id:"aiChatWorkflowsList"}),$e=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.workflows,{children:s,...r}=t;return n.jsx(sn,{children:h.maybeRender(s,i),...r})}),rn=a.ikp("button",{_id:"aiChatWorkflow"}),Ve=t=>{const{workflow:e,onClick:i,...s}=t,{handleWorkflow:r}=v.useChat();return n.jsx(rn,{onClick:u.composeEventHandlers(i,()=>r(e)),children:e.displayName,...s})},on=a.ikp("div",{_id:"aiChatMessageWrapper"}),ce=t=>{const{message:e,...i}=t;return e.role==="system"?null:n.jsx(P.MessageProvider,{message:e,children:n.jsx(on,{"data-role":e.role,...i})})},Ue=g.memo(t=>{const{message:e,...i}=t,{aiChatSettings:s,baseSettings:r}=p.useInkeepConfig(),o=s.aiAssistantName,d=o?`Hi, I'm ${o}!`:"Hi!",c=s.chatSubjectName??r.organizationDisplayName,m=`${d}
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),ae=require("react-textarea-autosize"),ba=require("@radix-ui/react-avatar"),ga=require("@radix-ui/react-checkbox"),Pa=require("@radix-ui/react-popover"),_a=require("@radix-ui/react-tooltip"),Aa=require("@radix-ui/react-scroll-area"),I=require("../atoms/select.cjs"),_=require("../atoms/dialog.cjs"),Ea=require("../atoms/avatars/ai.cjs"),Fa=require("../atoms/avatars/user.cjs"),E=require("../atoms/icons/custom-icon.cjs"),x=require("../atoms/icons/built-in-icon-renderer.cjs"),ka=require("../atoms/link.cjs"),U=require("../atoms/markdown/index.cjs"),w=require("../providers/attachment-item-provider.cjs"),F=require("../providers/attachments-bar-provider.cjs"),f=require("../providers/source-item-provider.cjs"),p=require("../providers/config-provider.cjs"),L=require("../providers/conversation-provider.cjs"),O=require("../providers/chat-events-provider.cjs"),ne=require("../providers/feedback-provider.cjs"),q=require("../providers/message-attachments-provider.cjs"),P=require("../providers/message-provider.cjs"),be=require("../atoms/icons/checkbox-icon.cjs"),te=require("../hooks/use-copy-to-clipboard.cjs"),K=require("../providers/feedback-item-provider.cjs"),Ia=require("../utils/get-message-metadata.cjs"),h=require("../utils/misc.cjs"),a=require("./factory.cjs"),v=require("./embedded-chat/chat-provider.cjs"),Ma=require("./tagline-logo-icon.cjs"),Sa=require("../hooks/use-settle-action.cjs"),xa=require("../hooks/use-container-size.cjs"),se=require("./embedded-chat/use-chat-action.cjs"),ie=require("../providers/help-menu-provider.cjs"),A=require("../providers/chat-form-provider.cjs"),B=require("../providers/form-field-provider.cjs"),fa=require("react-hook-form"),Ba=require("../utils/highlight-emphasis.cjs"),Ta=require("./modal/modal-provider.cjs"),ja=require("@inkeep/cxkit-color-mode"),re=require("../utils/compose-refs.cjs"),u=require("../utils/compose-event-handlers.cjs"),ya=require("../hooks/use-scroll-to-bottom.cjs"),Ha=require("../atoms/api/analytics/conversation.cjs"),wa=require("../utils/transform-source/index.cjs"),La=require("../hooks/use-debounce.cjs"),oe=require("../providers/hover-popover-provider.cjs"),Da=require("./modal/widget-auto-focus.cjs");function R(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const i in t)if(i!=="default"){const s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>t[i]})}}return e.default=t,Object.freeze(e)}const de=R(ba),z=R(ga),T=R(Pa),j=R(_a),W=R(Aa),Oa="__intro__",qa=a.ikp("div",{_id:"aiChatWrapper"}),ge=g.forwardRef((t,e)=>{const{...i}=t,{isHidden:s,isMobile:r}=v.useChat(),[o,d]=xa.useContainerSize(),c=re.useComposedRefs(e,o),m=d?.width?d.width>580:!0,l=Ta.useModal();return n.jsx(qa,{ref:c,"data-widget-md":h.dataAttr(m),"data-hidden":h.dataAttr(s),"data-in-modal":h.dataAttr(!!l),"data-mobile":h.dataAttr(r),...i})}),Ra=a.ikp("div",{_id:"aiChatConversationLoading"}),Pe=t=>{const{isLoadingConversation:e}=v.useChat();return e?n.jsx(Ra,{children:n.jsx("span",{children:"Loading..."}),...t}):null},Wa=a.ikp("div",{_id:"aiChatRoot"}),_e=t=>{const{isLoadingConversation:e,isHidden:i}=v.useChat(),{form:s}=A.useChatForm();return e||s?null:n.jsx(Wa,{"data-hidden":h.dataAttr(i),...t})},Na=a.ikp("div",{_id:"aiChatHeader"}),Ae=a.ikp("div",{_id:"aiChatHeader__Toolbar"}),Ee=a.ikp("div",{_id:"aiChatHeader__ToolbarHeaderWrapper"}),Qa=a.ikp("div",{_id:"aiChatHeader__ToolbarHeader"}),Fe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=`Ask ${e.aiAssistantName||"AI"}`;return n.jsx(Qa,{...t,children:i})}),ke=a.ikp("div",{_id:"aiChatContent"}),Ie=a.ikp(W.Root,{_id:"aiChatContentScrollArea"}),$a=a.ikp(W.Viewport,{_id:"aiChatContentScrollArea__Viewport"}),Me=g.forwardRef(({children:t,...e},i)=>{const{containerRef:s}=ya.useScrollToBottom(),r=re.useComposedRefs(i,s);return n.jsx($a,{ref:r,children:n.jsx("div",{"data-part":"grid",style:{display:"grid"},children:t}),...e})}),Se=a.ikp(W.ScrollAreaScrollbar,{_id:"aiChatContentScrollArea__Scrollbar"}),xe=a.ikp(W.ScrollAreaThumb,{_id:"aiChatContentScrollArea__Thumb"}),fe=a.ikp(W.Corner,{_id:"aiChatContentScrollArea__Corner"}),Va=a.ikp("div",{_id:"aiChatMessages"}),Be=t=>{const e=v.useChat(),{children:i,...s}=t;return n.jsx(Va,{children:h.maybeRender(i,e),...s})},Ua=a.ikp("div",{_id:"aiChatDisclaimer"}),Te=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),[i,s]=g.useState(!1),r=La.useDebounce(i,100);return e.disclaimerSettings?.isEnabled?n.jsx(oe.HoverPopoverProvider,{open:i,setOpen:s,children:n.jsx(T.Root,{open:r,onOpenChange:s,children:n.jsx(Ua,{...t})})}):null}),Ka=a.ikp("span",{_id:"aiChatDisclaimerLabel"}),je=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.disclaimerSettings;return n.jsx(Ka,{children:i?.label,...t})}),za=a.ikp(T.Trigger,{_id:"aiChatDisclaimerTrigger",children:n.jsx(E.CustomIcon,{iconKey:"info"})}),ye=g.memo(t=>{const{setOpen:e}=oe.useHoverPopover(),i=()=>e(!0),s=()=>e(!1);return n.jsx(za,{onMouseEnter:i,onMouseLeave:s,...t})}),Ga=a.ikp(T.Content,{_id:"aiChatDisclaimerContent"}),He=t=>{const{setOpen:e}=oe.useHoverPopover(),i=()=>e(!0),s=()=>e(!1);return n.jsx(Ga,{onMouseEnter:i,onMouseLeave:s,side:"top",sideOffset:8,align:"end",alignOffset:-10,...t})},Ya=a.ikp(U.Markdown,{_id:"aiChatDisclaimerText"}),we=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.aiAssistantName,r=e.disclaimerSettings?.tooltip||`Information provided by ${i||"this AI assistant"} is not guaranteed to be accurate or comprehensive.`;return n.jsx(Ya,{shouldOpenLinksInNewTab:!0,children:r,...t})}),Le=a.ikp(T.Arrow,{_id:"aiChatDisclaimerArrow"}),Ja=a.ikp("div",{_id:"aiChatExampleQuestions"}),De=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{messages:i}=v.useChat();return!e.exampleQuestions?.length||i.length?null:n.jsx(Ja,{...t})},Xa=a.ikp("h3",{_id:"aiChatExampleQuestionsLabel"}),Oe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(Xa,{children:e.exampleQuestionsLabel,...t})}),Za=a.ikp("div",{_id:"aiChatExampleQuestionsList"}),qe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.exampleQuestions,{children:s,...r}=t;return n.jsx(Za,{children:h.maybeRender(s,i),...r})}),en=a.ikp("div",{_id:"aiChatExampleQuestion"}),Re=g.forwardRef((t,e)=>{const{aiChatSettings:i}=p.useInkeepConfig(),s=i.isFirstExampleQuestionHighlighted;return n.jsx(en,{ref:e,"data-highlight":h.dataAttr(s),...t})}),tn=a.ikp("button",{_id:"aiChatExampleQuestionButton"}),We=t=>{const{question:e,onClick:i,...s}=t,{handleSubmit:r}=v.useChat();return n.jsx(tn,{onClick:u.composeEventHandlers(i,()=>r(e)),children:e,...s})},an=a.ikp("div",{_id:"aiChatWorkflows"}),Ne=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{messages:i}=v.useChat();return!e.workflows?.length||i.length?null:n.jsx(an,{...t})},nn=a.ikp("h3",{_id:"aiChatWorkflowsLabel"}),Qe=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(nn,{children:e.workflowsHeader,...t})}),sn=a.ikp("div",{_id:"aiChatWorkflowsList"}),$e=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig(),i=e.workflows,{children:s,...r}=t;return n.jsx(sn,{children:h.maybeRender(s,i),...r})}),rn=a.ikp("button",{_id:"aiChatWorkflow"}),Ve=t=>{const{workflow:e,onClick:i,...s}=t,{handleWorkflow:r}=v.useChat();return n.jsx(rn,{onClick:u.composeEventHandlers(i,()=>r(e)),children:e.displayName,...s})},on=a.ikp("div",{_id:"aiChatMessageWrapper"}),ce=t=>{const{message:e,...i}=t;return e.role==="system"?null:n.jsx(P.MessageProvider,{message:e,children:n.jsx(on,{"data-role":e.role,...i})})},Ue=g.memo(t=>{const{message:e,...i}=t,{aiChatSettings:s,baseSettings:r}=p.useInkeepConfig(),o=s.aiAssistantName,d=o?`Hi, I'm ${o}!`:"Hi!",c=s.chatSubjectName??r.organizationDisplayName,m=`${d}
2
2
 
3
3
  I'm an AI assistant trained on documentation, help articles, and other content.`,l=c?`
4
4
 
5
5
  Ask me anything about \`${c}\`.`:`
6
6
 
7
- Let me know how I can help.`,b={content:s.introMessage??`${m}${l}`,id:Oa,...e,role:"assistant",links:[]};return n.jsx(ce,{message:b,...i})}),dn=a.ikp("div",{_id:"aiChatMessageHeader"}),Ke=t=>{const{message:e}=P.useMessage();return n.jsx(dn,{"data-role":e.role,...t})},cn=a.ikp("div",{_id:"aiChatMessageLoading"}),ze=t=>{const{isLoading:e,isStreaming:i,messages:s}=v.useChat(),{message:r}=P.useMessage();return!(s.at(-1)?.id===r?.id)||r.role!=="assistant"||!e||i?null:n.jsx(cn,{children:"Thinking...",...t})},mn=a.ikp("div",{_id:"aiChatMessageAvatar"}),Ge=t=>{const{message:e}=P.useMessage();return n.jsx(mn,{"data-role":e.role,...t})},ln=a.ikp(de.Root,{_id:"aiChatMessageAvatarContent"}),Ye=t=>{const{message:e}=P.useMessage(),{baseSettings:i}=p.useInkeepConfig();return n.jsx(ln,{"data-username":h.dataAttr(e.role==="user"&&!!i.userProperties.name),"data-role":e.role,...t})},hn=a.ikp(de.Fallback,{_id:"aiChatMessageAvatarFallback"}),Je=g.memo(t=>{const{baseSettings:e}=p.useInkeepConfig(),{message:i}=P.useMessage();return e.userProperties.name?n.jsx(hn,{"data-role":i.role,children:h.getInitials(e.userProperties.name),...t}):null}),pe=a.ikp(de.Image,{_id:"aiChatMessageAvatarImage"}),Xe=g.memo(t=>{const{onLoadingStatusChange:e,...i}=t,{aiChatSettings:s,baseSettings:{userProperties:r}}=p.useInkeepConfig(),{message:o}=P.useMessage(),{aiAssistantAvatar:d}=s??{},c=typeof d=="string"?d:d?.light,m=(typeof d=="string"?d:d?.dark)??c,l=ja.useColorModeValue(c,m),[C,b]=g.useState(l);g.useEffect(()=>{b(l)},[l]);const k=y=>{y==="error"&&b(null)};return o.role==="user"?r.name?null:s.userAvatar?n.jsx(pe,{"data-type":"image",alt:"User avatar","data-role":o.role,src:s.userAvatar,...t}):n.jsx(Fa.default,{"data-type":"icon","data-role":o.role,...t}):C?n.jsx(pe,{src:C,alt:"AI assistant avatar","data-type":"image","data-role":o.role,onLoadingStatusChange:u.composeEventHandlers(e,k),...i}):n.jsx(Ea.default,{"data-type":"icon","data-role":o.role,...t})}),un=a.ikp("span",{_id:"aiChatMessageName"}),Ze=t=>{const{message:e}=P.useMessage();return n.jsx(un,{"data-role":e.role,children:e.role==="user"?"You":"AI assistant",...t})},Cn=a.ikp("div",{_id:"aiChatMessageContentWrapper"}),et=t=>{const{message:e}=P.useMessage(),{messageButtons:i}=v.useChat(),s=i[e.id]||[];return n.jsx(Cn,{"data-role":e.role,"data-has-message-buttons":h.dataAttr(!!s.length),...t})},pn=a.ikp("div",{_id:"aiChatMessageContent"}),tt=t=>{const{message:e}=P.useMessage();return n.jsx(pn,{"data-role":e.role,...t})},vn=a.ikp("div",{_id:"aiChatMessageAttachments"}),it=t=>{const{message:e}=P.useMessage(),i=e.metadata?.attributes?.attachments;return e.role!=="user"||!i?.length?null:n.jsx(q.MessageAttachmentsProvider,{children:n.jsx(vn,{...t})})},bn=a.ikp("div",{_id:"aiChatMessageAttachments__List"}),at=t=>{const{children:e,...i}=t,{message:s}=P.useMessage(),r=s.metadata?.attributes?.attachments;return r?n.jsx(bn,{children:h.maybeRender(e,r),...i}):null},gn=a.ikp("div",{_id:"aiChatMessageAttachments__Item"}),nt=t=>{const{attachment:e,onClick:i,...s}=t,{selectItem:r,onOpen:o}=q.useMessageAttachments(),d=()=>{r(e),o()};return n.jsx(w.AttachmentItemProvider,{attachment:e,children:n.jsx(gn,{onClick:u.composeEventHandlers(i,d),...s})})},Pn=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatMessageAttachments__ItemIcon"}),st=t=>{const{attachment:e}=w.useAttachmentItem(),i=e.contentType?.attachmentIcon;return i?n.jsx(Pn,{iconSettings:i,...t}):null},An=a.ikp("span",{_id:"aiChatMessageAttachments__ItemTitle"}),rt=t=>{const{attachment:e}=w.useAttachmentItem();return n.jsx(An,{children:e.title,...t})},_n=a.ikp(A.Root,{_id:"aiChatMessageAttachmentsPreview"}),ot=t=>{const{onOpenChange:e,...i}=t,{selectItem:s,isOpen:r,onClose:o,selectedItem:d}=q.useMessageAttachments(),c=m=>{m||(o(),s(null))};return n.jsx(_n,{open:r&&d!==null,onOpenChange:u.composeEventHandlers(e,c),...i})},dt=a.ikp(A.Overlay,{_id:"aiChatMessageAttachmentsPreview__Overlay"}),ct=a.ikp(A.Content,{_id:"aiChatMessageAttachmentsPreview__Content","aria-describedby":void 0}),En=a.ikp(A.Title,{_id:"aiChatMessageAttachmentsPreview__Header"}),mt=t=>{const{selectedItem:e}=q.useMessageAttachments();return n.jsx(En,{children:e?.title||"Attachment",...t})},lt=a.ikp(A.Close,{_id:"aiChatMessageAttachmentsPreview__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Fn=a.ikp("p",{_id:"aiChatMessageAttachmentsPreview__Body"}),ht=t=>{const{selectedItem:e}=q.useMessageAttachments();return n.jsx(Fn,{children:e?.content,...t})},ve=a.ikp("div",{_id:"aiChatMessage"}),ut=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{componentStyles:i,...s}=t,{message:r}=P.useMessage(),{logEvent:o}=O.useChatEvents(),d=h.getMessageContent(r),{conversation:c}=L.useInkeepConversation();return r.role==="user"?n.jsx(ve,{"data-role":r.role,children:d,...s}):n.jsx(ve,{"data-role":r.role,...s,children:n.jsx(U.Markdown,{children:d,componentStyles:i,shouldOpenLinksInNewTab:e.shouldOpenLinksInNewTab,onLinkClick:(m,l)=>{o({eventName:"assistant_message_inline_link_opened",properties:{title:l?.toString(),url:m}})},onCodeCopy:(m,l)=>{o({eventName:"assistant_code_block_copied",properties:{conversation:c,language:m,code:l}})}})})},kn=a.ikp("div",{_id:"aiChatMessageToolbar"}),Ct=t=>{const{isLoading:e,messages:i}=v.useChat(),{message:s}=P.useMessage();return i.at(-1)?.id===s?.id&&e||s.role==="user"?null:n.jsx(kn,{...t})},In=a.ikp("div",{_id:"aiChatMessageToolActions"}),pt=t=>{const{children:e,...i}=t,{message:s}=P.useMessage(),{messageButtons:r}=v.useChat(),o=r[s.id]||[];return n.jsx(In,{children:h.maybeRender(e,o),...i})},Mn=a.ikp("a",{_id:"aiChatMessageToolAction"}),Sn=a.ikp("button",{_id:"aiChatMessageToolAction"}),vt=t=>{const{onClick:e,action:i,...s}=t,{handleAction:r}=se.useChatAction(i),{logEvent:o}=O.useChatEvents(),{conversation:d}=L.useInkeepConversation(),c=()=>{r(),o({eventName:"user_escalation_indicated",properties:{escalationType:"contact_us",conversation:d}})},m=i.label||"Contact Support",l=n.jsxs(n.Fragment,{children:[i.icon&&n.jsx(x.BuiltInIconRenderer,{iconSettings:i.icon}),m]});return i.action.type==="open_link"?n.jsx(Mn,{href:i.action.url,target:"_blank",rel:"noopener","data-type":i.action.type,onClick:u.composeEventHandlers(e,c),children:l,...s}):n.jsx(Sn,{"data-type":i.action.type,onClick:u.composeEventHandlers(e,c),children:l,...s})},xn=a.ikp("button",{_id:"aiChatMessageAction"}),bt=t=>{const{action:e,onClick:i,className:s,...r}=t,{conversation:o}=L.useInkeepConversation(),{message:d}=P.useMessage(),{isStreaming:c,messages:m}=v.useChat(),[l,C]=te.useCopyToClipboard(),{feedback:b,submitPositiveFeedback:k,setCurrentFeedback:y,currentFeedback:N}=ne.useMessageFeedback(),{logEvent:J}=O.useChatEvents(),[Q,X]=Sa.useSettleAction(),{baseSettings:{privacyPreferences:he}}=p.useInkeepConfig(),{optOutAllAnalytics:Z}=he,ue=m.at(-1)?.id===d?.id,ee=d.role==="assistant";if(ue&&c||!ee||{copy:!1,upvote:Z,downvote:Z}[e])return null;const H={copy(){C(h.getMessageContent(d)),J({eventName:"assistant_message_copied",properties:{conversation:o}})},upvote(){k(d.id).then(()=>{X()})},downvote(){y(d.id)}},D={copy:"Copy Message",upvote:"Upvote Message",downvote:"Downvote Message"},M={copy:n.jsx(E.CustomIcon,{iconKey:l?"messageCopied":"messageCopy"}),upvote:n.jsx(E.CustomIcon,{iconKey:Q?"messageCopied":"thumbsUp"}),downvote:n.jsx(E.CustomIcon,{iconKey:"thumbsDown"})},S={copy:{"data-copied":h.dataAttr(l)},upvote:{"data-upvoted":h.dataAttr(b[d.id]?.type==="positive")},downvote:{"data-downvoted":h.dataAttr(b[d.id]?.type==="negative"),"data-state":N===null?"closed":"open"}};return n.jsx(xn,{"data-action":e,...S[e],children:M[e],"aria-label":D[e],className:`${s} ${e}`,onClick:u.composeEventHandlers(i,H[e]),...r})},Bn=a.ikp("div",{_id:"aiChatMessageSources"}),gt=t=>{const{message:e}=P.useMessage();return e.role!=="assistant"||!e.links?.length?null:n.jsx(Bn,{...t})},fn=a.ikp("div",{_id:"aiChatMessageSources__Header"}),Pt=t=>n.jsx(fn,{children:"Sources",...t}),Tn=a.ikp("div",{_id:"aiChatMessageSources__List"}),At=t=>{const{message:e}=P.useMessage(),{children:i,...s}=t,{baseSettings:{transformSource:r,organizationDisplayName:o},aiChatSettings:{shouldOpenLinksInNewTab:d},searchSettings:{tabs:c}}=p.useInkeepConfig();if(e.role!=="assistant")return null;const m=e.links.map(l=>{const C=wa.transformInkeepSource(l,"chatSourceItem",{organizationDisplayName:o,tabs:c,transformSource:r}),b=C.shouldOpenInNewTab!==void 0?C.shouldOpenInNewTab:d;return{...C,isExternal:b}});return n.jsx(Tn,{children:h.maybeRender(i,m),...s})},jn=a.ikp(ka.LinkWithQueryParams,{_id:"aiChatMessageSourceItem"}),_t=t=>{const{source:e,onClick:i,...s}=t,{logEvent:r}=O.useChatEvents(),{conversation:o}=L.useInkeepConversation(),d=()=>{r({eventName:"assistant_source_item_clicked",properties:{conversation:o,link:e}})};return n.jsx(B.SourceItemProvider,{source:e,children:n.jsx(jn,{"data-type":e.type,appendToUrl:e.appendToUrl,isExternal:e.isExternal,"data-breadcrumbs":!!e.breadcrumbs?.length,onClick:u.composeEventHandlers(i,d),...s})})},yn=a.ikp("div",{_id:"aiChatMessageSourceItem__Breadcrumbs"}),Et=t=>{const{source:e}=B.useSourceItem();return e.breadcrumbs?.length?n.jsx(yn,{"data-type":e.type,...t}):null},Hn=a.ikp(E.CustomIcon,{_id:"aiChatMessageSourceItem__BreadcrumbIcon",iconKey:"breadcrumbSeparator"}),wn=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatMessageSourceItem__Icon"}),Ft=t=>{const{source:e}=B.useSourceItem();return n.jsx(wn,{iconSettings:e.icon,"data-type":e.type,...t})},Ln=a.ikp("span",{_id:"aiChatMessageSourceItem__Title"}),kt=t=>{const{source:e}=B.useSourceItem();return n.jsx(Ln,{"data-type":e.type,children:e.title,...t})},Dn=a.ikp("span",{_id:"aiChatMessageSourceItem__Tag"}),It=t=>{const{source:e}=B.useSourceItem();return n.jsx(Dn,{"data-type":e.type,...t})},On=a.ikp("span",{_id:"aiChatMessageSourceItem__Description"}),Mt=t=>{const{source:e}=B.useSourceItem(),{children:i,...s}=t,r=g.useMemo(()=>e.description?fa.highlightEmphasis(e.description):[],[e.description]);return r.length?n.jsx(On,{"data-type":e.type,children:h.maybeRender(i,r),...s}):null},qn=a.ikp("span",{_id:"aiChatMessageSourceItem__DescriptionPart"}),St=t=>{const{part:e,...i}=t,{source:s}=B.useSourceItem();return typeof e=="string"?e:n.jsx(qn,{"data-type":s.type,children:e.content,"data-highlighted":h.dataAttr(e.highlighted),...i})},Rn=a.ikp(E.CustomIcon,{_id:"aiChatMessageSourceItem__Indicator"}),xt=t=>{const{source:e}=B.useSourceItem();return n.jsx(Rn,{iconKey:e.isExternal?"openLinkInNewTab":"openLinkInSameTab",...t})},Bt=a.ikp("div",{_id:"aiChatFooter"}),ft=a.ikp("div",{_id:"aiChatInput__Fieldset"}),Tt=a.ikp("div",{_id:"aiChatInput__Group"}),Wn=a.ikp("textarea",{_id:"aiChatInput"}),jt=g.forwardRef(({onChange:t,onKeyDown:e,...i},s)=>{const{handleInputChange:r,handleInputKeyDown:o,input:d,error:c,shouldAutoFocusInput:m,inputRef:l}=v.useChat(),{aiChatSettings:C}=p.useInkeepConfig(),b=re.useComposedRefs(s,l);return Da.useWidgetAutoFocus("chat",l,m),n.jsx(Wn,{asChild:!0,ref:b,maxLength:99999,placeholder:C.placeholder,value:d,onChange:u.composeEventHandlers(t,r),onKeyDown:u.composeEventHandlers(e,o),disabled:!!c||C.isViewOnly,...i,children:n.jsx(ae,{})})}),Nn=a.ikp("button",{_id:"aiChatInput__SendButton"}),yt=t=>{const{handleSubmit:e,isSubmitDisabled:i,error:s}=v.useChat(),{aiChatSettings:r}=p.useInkeepConfig(),{onClick:o,...d}=t;return n.jsx(Nn,{onClick:u.composeEventHandlers(o,()=>e()),"aria-label":"Send message",disabled:i||!!s||r.isViewOnly,...d})},Ht=a.ikp(E.CustomIcon,{_id:"aiChatInput__SendButtonIcon",iconKey:"chatSubmit"}),Qn=a.ikp("div",{_id:"aiChatAttachmentsBar"}),wt=t=>{const{selectedWorkflow:e}=v.useChat();return!e||!e.supportedInputs?.length?null:n.jsx(F.AttachmentsBarProvider,{children:n.jsx(Qn,{...t})})},$n=a.ikp("div",{_id:"aiChatAttachmentsBar__List"}),Lt=t=>{const{children:e,...i}=t,{messageAttachments:s}=v.useChat();return n.jsx($n,{children:h.maybeRender(e,s),...i})},Vn=a.ikp("div",{_id:"aiChatAttachmentsBar__Attachment"}),Dt=t=>{const{attachment:e,...i}=t;return n.jsx(w.AttachmentItemProvider,{attachment:e,children:n.jsx(Vn,{...i})})},Un=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatAttachmentsBar__AttachmentIcon"}),Ot=t=>{const{attachment:e}=w.useAttachmentItem(),i=e.contentType?.attachmentIcon;return i?n.jsx(Un,{iconSettings:i,...t}):null},Kn=a.ikp("span",{_id:"aiChatAttachmentsBar__AttachmentTitle"}),qt=t=>{const{attachment:e}=w.useAttachmentItem();return n.jsx(Kn,{children:e.title,...t})},zn=a.ikp("button",{_id:"aiChatAttachmentsBar__AttachmentDelete"}),Rt=t=>{const{onClick:e,...i}=t,{attachment:s}=w.useAttachmentItem(),{setMessageAttachments:r}=v.useChat(),o=()=>{r(d=>d.filter(c=>c.id!==s.id))};return n.jsx(zn,{"aria-label":"Remove attachment",children:n.jsx(E.CustomIcon,{iconKey:"close"}),onClick:u.composeEventHandlers(e,o),...i})},Wt=a.ikp("div",{_id:"aiChatAttachmentsBar__Actions"}),Nt=a.ikp(j.Tooltip,{_id:"aiChatAttachmentsBar__InfoTip",delayDuration:0}),Qt=a.ikp(j.Trigger,{_id:"aiChatAttachmentsBar__InfoTipIcon",children:n.jsx(E.CustomIcon,{iconKey:"info"})}),me=a.ikp(j.Arrow,{_id:"aiChatAttachmentsBar__InfoTipArrow"}),$t=a.ikp(j.Content,{_id:"aiChatAttachmentsBar__InfoTipText",side:"bottom",sideOffset:3,align:"center",children:n.jsxs(n.Fragment,{children:[n.jsx(me,{}),"Attachments will be kept in context for the entire conversation."]})}),Gn=a.ikp("div",{_id:"aiChatAttachmentsBar__Inputs"}),Vt=t=>{const{children:e,...i}=t,{selectedWorkflow:s}=v.useChat();return s?.supportedInputs?n.jsx(Gn,{children:h.maybeRender(e,s.supportedInputs),...i}):null},Yn=a.ikp("button",{_id:"aiChatAttachmentsBar__Input"}),Ut=t=>{const{input:e,onClick:i,...s}=t,{selectedWorkflow:r,messageAttachments:o,setMessageAttachments:d}=v.useChat(),{selectInput:c,onOpen:m}=F.useAttachmentsBar(),l=()=>{if(e.type==="FUNCTIONAL_MULTI_ATTACHMENT")return r?e.onInvoke(r,e,d,[...o]):void 0;c(e),m()};return n.jsx(Yn,{children:e.displayName,onClick:u.composeEventHandlers(i,l),...s})},Jn=a.ikp(A.Root,{_id:"aiChatAttachmentsBar__Modal"}),Kt=t=>{const{onOpenChange:e,...i}=t,{selectInput:s,isOpen:r,onClose:o,selectedInput:d}=F.useAttachmentsBar(),c=m=>{m||(o(),s(null))};return n.jsx(Jn,{open:r&&d!==null,onOpenChange:u.composeEventHandlers(e,c),...i})},zt=a.ikp(A.Overlay,{_id:"aiChatAttachmentsBar__ModalOverlay"}),Gt=a.ikp(A.Content,{_id:"aiChatAttachmentsBar__ModalContent","aria-describedby":void 0}),Yt=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalHeader"}),Xn=a.ikp(A.Title,{_id:"aiChatAttachmentsBar__ModalHeading"}),Jt=t=>{const{selectedInput:e}=F.useAttachmentsBar(),i=`Add ${e?.displayName}`;return n.jsx(Xn,{children:i,...t})},Zn=a.ikp("span",{_id:"aiChatAttachmentsBar__ModalDescription"}),Xt=t=>{const{selectedInput:e}=F.useAttachmentsBar(),i=e?.workflowModalProps?.modalHelpText;return i?n.jsx(Zn,{children:i,...t}):null},es=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalHelp"}),Zt=t=>{const{children:e,...i}=t,{selectedInput:s}=F.useAttachmentsBar(),r=s?.workflowModalProps?.modalHelpElement;return r?n.jsx(es,{asChild:!e,children:e||r,...i}):null},ei=a.ikp(A.Close,{_id:"aiChatAttachmentsBar__ModalClose",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),ti=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalBody"}),ts=a.ikp("form",{_id:"aiChatAttachmentsBar__Form"}),ii=t=>{const{onSubmit:e,...i}=t,{form:s}=F.useAttachmentsBar();return n.jsx(ts,{onSubmit:u.composeEventHandlers(e,s.onSubmit),...i})},ai=a.ikp("div",{_id:"aiChatAttachmentsBar__FormTitle",role:"group"}),is=a.ikp("label",{_id:"aiChatAttachmentsBar__FormTitleLabel"}),ni=t=>{const{form:e,selectedInput:i}=F.useAttachmentsBar();return n.jsx(is,{htmlFor:`${i?.id}-title`,children:e.labels.title,...t})},as=a.ikp("input",{_id:"aiChatAttachmentsBar__FormTitleInput"}),si=t=>{const{onChange:e,...i}=t,{form:s,selectedInput:r}=F.useAttachmentsBar();return n.jsx(as,{name:"title",value:s.data.title,id:`${r?.id}-title`,"data-invalid":h.dataAttr(!!s.errors.title),"aria-invalid":!!s.errors.title,onChange:u.composeEventHandlers(e,s.onChange),...i})},ns=a.ikp("span",{_id:"aiChatAttachmentsBar__FormTitleError"}),ri=t=>{const{form:e}=F.useAttachmentsBar();return e.errors.title?n.jsx(ns,{"aria-live":"polite",children:e.errors.title,...t}):null},oi=a.ikp("div",{_id:"aiChatAttachmentsBar__FormTitle",role:"group"}),ss=a.ikp("label",{_id:"aiChatAttachmentsBar__FormContentLabel"}),di=t=>{const{form:e,selectedInput:i}=F.useAttachmentsBar();return n.jsx(ss,{htmlFor:`${i?.id}-content`,children:e.labels.content,...t})},rs=a.ikp("textarea",{_id:"aiChatAttachmentsBar__FormTitleInput"}),ci=t=>{const{onChange:e,...i}=t,{form:s,selectedInput:r}=F.useAttachmentsBar();return n.jsx(rs,{asChild:!0,rows:4,name:"content",value:s.data.content,id:`${r?.id}-content`,"data-invalid":h.dataAttr(!!s.errors.content),"aria-invalid":!!s.errors.content,onChange:u.composeEventHandlers(e,s.onChange),...i,children:n.jsx(ae,{maxRows:10})})},os=a.ikp("span",{_id:"aiChatAttachmentsBar__FormContentError"}),mi=t=>{const{form:e}=F.useAttachmentsBar();return e.errors.content?n.jsx(os,{"aria-live":"polite",children:e.errors.content,...t}):null},li=a.ikp("button",{_id:"aiChatAttachmentsBar__FormSubmitButton",children:"Upload",type:"submit"}),hi=a.ikp("div",{_id:"aiChatActionBar"}),ui=a.ikp("div",{_id:"aiChat__ChatActions"}),Ci=a.ikp("div",{_id:"aiChatTagline__Container"}),pi=a.ikp("span",{_id:"aiChatTagline__Text",children:"Powered by"}),vi=a.ikp(Ma.default,{_id:"aiChatTagline__Logo"}),bi=a.ikp("a",{_id:"aiChatTagline__BrandName",children:"inkeep",href:"https://www.inkeep.com/",target:"_blank",rel:"noopener noreferrer"}),ds=a.ikp(j.Trigger,{_id:"aiChat__ChatAction"}),G=t=>{const{action:e,onClick:i,className:s,...r}=t,{clear:o,stop:d,isLoading:c,messages:m,selectedWorkflow:l}=v.useChat(),{conversation:C}=L.useInkeepConversation(),{aiChatSettings:b,baseSettings:k}=p.useInkeepConfig(),{logEvent:y}=O.useChatEvents(),[N,J]=te.useCopyToClipboard(),[Q,X]=te.useCopyToClipboard();if({help:!1,copy:m.length===0||!b.isCopyChatButtonVisible||c,share:m.length===0||!b.isShareButtonVisible||!C.id||!!l||c,clear:m.length===0||b.isViewOnly||c,stop:!c}[e])return null;const ee={help:()=>{},copy:()=>{const $=m.map(H=>{const D=`**${H.role==="assistant"?"AI Assistant":"User"}**`,M=h.getMessageContent(H),S=Ia.stringifyAttachments(H.metadata?.attributes?.attachments),V=S?`
7
+ Let me know how I can help.`,b={content:s.introMessage??`${m}${l}`,id:Oa,...e,role:"assistant",links:[]};return n.jsx(ce,{message:b,...i})}),dn=a.ikp("div",{_id:"aiChatMessageHeader"}),Ke=t=>{const{message:e}=P.useMessage();return n.jsx(dn,{"data-role":e.role,...t})},cn=a.ikp("div",{_id:"aiChatMessageLoading"}),ze=t=>{const{isLoading:e,isStreaming:i,messages:s}=v.useChat(),{message:r}=P.useMessage();return!(s.at(-1)?.id===r?.id)||r.role!=="assistant"||!e||i?null:n.jsx(cn,{children:"Thinking...",...t})},mn=a.ikp("div",{_id:"aiChatMessageAvatar"}),Ge=t=>{const{message:e}=P.useMessage();return n.jsx(mn,{"data-role":e.role,...t})},ln=a.ikp(de.Root,{_id:"aiChatMessageAvatarContent"}),Ye=t=>{const{message:e}=P.useMessage(),{baseSettings:i}=p.useInkeepConfig();return n.jsx(ln,{"data-username":h.dataAttr(e.role==="user"&&!!i.userProperties.name),"data-role":e.role,...t})},hn=a.ikp(de.Fallback,{_id:"aiChatMessageAvatarFallback"}),Je=g.memo(t=>{const{baseSettings:e}=p.useInkeepConfig(),{message:i}=P.useMessage();return e.userProperties.name?n.jsx(hn,{"data-role":i.role,children:h.getInitials(e.userProperties.name),...t}):null}),pe=a.ikp(de.Image,{_id:"aiChatMessageAvatarImage"}),Xe=g.memo(t=>{const{onLoadingStatusChange:e,...i}=t,{aiChatSettings:s,baseSettings:{userProperties:r}}=p.useInkeepConfig(),{message:o}=P.useMessage(),{aiAssistantAvatar:d}=s??{},c=typeof d=="string"?d:d?.light,m=(typeof d=="string"?d:d?.dark)??c,l=ja.useColorModeValue(c,m),[C,b]=g.useState(l);g.useEffect(()=>{b(l)},[l]);const k=y=>{y==="error"&&b(null)};return o.role==="user"?r.name?null:s.userAvatar?n.jsx(pe,{"data-type":"image",alt:"User avatar","data-role":o.role,src:s.userAvatar,...t}):n.jsx(Fa.default,{"data-type":"icon","data-role":o.role,...t}):C?n.jsx(pe,{src:C,alt:"AI assistant avatar","data-type":"image","data-role":o.role,onLoadingStatusChange:u.composeEventHandlers(e,k),...i}):n.jsx(Ea.default,{"data-type":"icon","data-role":o.role,...t})}),un=a.ikp("span",{_id:"aiChatMessageName"}),Ze=t=>{const{message:e}=P.useMessage();return n.jsx(un,{"data-role":e.role,children:e.role==="user"?"You":"AI assistant",...t})},Cn=a.ikp("div",{_id:"aiChatMessageContentWrapper"}),et=t=>{const{message:e}=P.useMessage(),{messageButtons:i}=v.useChat(),s=i[e.id]||[];return n.jsx(Cn,{"data-role":e.role,"data-has-message-buttons":h.dataAttr(!!s.length),...t})},pn=a.ikp("div",{_id:"aiChatMessageContent"}),tt=t=>{const{message:e}=P.useMessage();return n.jsx(pn,{"data-role":e.role,...t})},vn=a.ikp("div",{_id:"aiChatMessageAttachments"}),it=t=>{const{message:e}=P.useMessage(),i=e.metadata?.attributes?.attachments;return e.role!=="user"||!i?.length?null:n.jsx(q.MessageAttachmentsProvider,{children:n.jsx(vn,{...t})})},bn=a.ikp("div",{_id:"aiChatMessageAttachments__List"}),at=t=>{const{children:e,...i}=t,{message:s}=P.useMessage(),r=s.metadata?.attributes?.attachments;return r?n.jsx(bn,{children:h.maybeRender(e,r),...i}):null},gn=a.ikp("div",{_id:"aiChatMessageAttachments__Item"}),nt=t=>{const{attachment:e,onClick:i,...s}=t,{selectItem:r,onOpen:o}=q.useMessageAttachments(),d=()=>{r(e),o()};return n.jsx(w.AttachmentItemProvider,{attachment:e,children:n.jsx(gn,{onClick:u.composeEventHandlers(i,d),...s})})},Pn=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatMessageAttachments__ItemIcon"}),st=t=>{const{attachment:e}=w.useAttachmentItem(),i=e.contentType?.attachmentIcon;return i?n.jsx(Pn,{iconSettings:i,...t}):null},_n=a.ikp("span",{_id:"aiChatMessageAttachments__ItemTitle"}),rt=t=>{const{attachment:e}=w.useAttachmentItem();return n.jsx(_n,{children:e.title,...t})},An=a.ikp(_.Root,{_id:"aiChatMessageAttachmentsPreview"}),ot=t=>{const{onOpenChange:e,...i}=t,{selectItem:s,isOpen:r,onClose:o,selectedItem:d}=q.useMessageAttachments(),c=m=>{m||(o(),s(null))};return n.jsx(An,{open:r&&d!==null,onOpenChange:u.composeEventHandlers(e,c),...i})},dt=a.ikp(_.Overlay,{_id:"aiChatMessageAttachmentsPreview__Overlay"}),ct=a.ikp(_.Content,{_id:"aiChatMessageAttachmentsPreview__Content","aria-describedby":void 0}),En=a.ikp(_.Title,{_id:"aiChatMessageAttachmentsPreview__Header"}),mt=t=>{const{selectedItem:e}=q.useMessageAttachments();return n.jsx(En,{children:e?.title||"Attachment",...t})},lt=a.ikp(_.Close,{_id:"aiChatMessageAttachmentsPreview__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Fn=a.ikp("p",{_id:"aiChatMessageAttachmentsPreview__Body"}),ht=t=>{const{selectedItem:e}=q.useMessageAttachments();return n.jsx(Fn,{children:e?.content,...t})},ve=a.ikp("div",{_id:"aiChatMessage"}),ut=t=>{const{aiChatSettings:e}=p.useInkeepConfig(),{componentStyles:i,...s}=t,{message:r}=P.useMessage(),{logEvent:o}=O.useChatEvents(),d=h.getMessageContent(r),{conversation:c}=L.useInkeepConversation();return r.role==="user"?n.jsx(ve,{"data-role":r.role,children:d,...s}):n.jsx(ve,{"data-role":r.role,...s,children:n.jsx(U.Markdown,{children:d,componentStyles:i,shouldOpenLinksInNewTab:e.shouldOpenLinksInNewTab,onLinkClick:(m,l)=>{o({eventName:"assistant_message_inline_link_opened",properties:{title:l?.toString(),url:m}})},onCodeCopy:(m,l)=>{o({eventName:"assistant_code_block_copied",properties:{conversation:c,language:m,code:l}})}})})},kn=a.ikp("div",{_id:"aiChatMessageToolbar"}),Ct=t=>{const{isLoading:e,messages:i}=v.useChat(),{message:s}=P.useMessage();return i.at(-1)?.id===s?.id&&e||s.role==="user"?null:n.jsx(kn,{...t})},In=a.ikp("div",{_id:"aiChatMessageToolActions"}),pt=t=>{const{children:e,...i}=t,{message:s}=P.useMessage(),{messageButtons:r}=v.useChat(),o=r[s.id]||[];return n.jsx(In,{children:h.maybeRender(e,o),...i})},Mn=a.ikp("a",{_id:"aiChatMessageToolAction"}),Sn=a.ikp("button",{_id:"aiChatMessageToolAction"}),vt=t=>{const{onClick:e,action:i,...s}=t,{handleAction:r}=se.useChatAction(i),{logEvent:o}=O.useChatEvents(),{conversation:d}=L.useInkeepConversation(),c=()=>{r(),o({eventName:"tool_call_action_clicked",properties:{conversation:d}}),i.action.type!=="open_form"&&o({eventName:"user_escalation_indicated",properties:{escalationType:"contact_us",conversation:d}})},m=i.label||"Contact Support",l=n.jsxs(n.Fragment,{children:[i.icon&&n.jsx(x.BuiltInIconRenderer,{iconSettings:i.icon}),m]});return i.action.type==="open_link"?n.jsx(Mn,{href:i.action.url,target:"_blank",rel:"noopener","data-type":i.action.type,onClick:u.composeEventHandlers(e,c),children:l,...s}):n.jsx(Sn,{"data-type":i.action.type,onClick:u.composeEventHandlers(e,c),children:l,...s})},xn=a.ikp("button",{_id:"aiChatMessageAction"}),bt=t=>{const{action:e,onClick:i,className:s,...r}=t,{conversation:o}=L.useInkeepConversation(),{message:d}=P.useMessage(),{isStreaming:c,messages:m}=v.useChat(),[l,C]=te.useCopyToClipboard(),{feedback:b,submitPositiveFeedback:k,setCurrentFeedback:y,currentFeedback:N}=ne.useMessageFeedback(),{logEvent:J}=O.useChatEvents(),[Q,X]=Sa.useSettleAction(),{baseSettings:{privacyPreferences:he}}=p.useInkeepConfig(),{optOutAllAnalytics:Z}=he,ue=m.at(-1)?.id===d?.id,ee=d.role==="assistant";if(ue&&c||!ee||{copy:!1,upvote:Z,downvote:Z}[e])return null;const H={copy(){C(h.getMessageContent(d)),J({eventName:"assistant_message_copied",properties:{conversation:o}})},upvote(){k(d.id).then(()=>{X()})},downvote(){y(d.id)}},D={copy:"Copy Message",upvote:"Upvote Message",downvote:"Downvote Message"},M={copy:n.jsx(E.CustomIcon,{iconKey:l?"messageCopied":"messageCopy"}),upvote:n.jsx(E.CustomIcon,{iconKey:Q?"messageCopied":"thumbsUp"}),downvote:n.jsx(E.CustomIcon,{iconKey:"thumbsDown"})},S={copy:{"data-copied":h.dataAttr(l)},upvote:{"data-upvoted":h.dataAttr(b[d.id]?.type==="positive")},downvote:{"data-downvoted":h.dataAttr(b[d.id]?.type==="negative"),"data-state":N===null?"closed":"open"}};return n.jsx(xn,{"data-action":e,...S[e],children:M[e],"aria-label":D[e],className:`${s} ${e}`,onClick:u.composeEventHandlers(i,H[e]),...r})},fn=a.ikp("div",{_id:"aiChatMessageSources"}),gt=t=>{const{message:e}=P.useMessage();return e.role!=="assistant"||!e.links?.length?null:n.jsx(fn,{...t})},Bn=a.ikp("div",{_id:"aiChatMessageSources__Header"}),Pt=t=>n.jsx(Bn,{children:"Sources",...t}),Tn=a.ikp("div",{_id:"aiChatMessageSources__List"}),_t=t=>{const{message:e}=P.useMessage(),{children:i,...s}=t,{baseSettings:{transformSource:r,organizationDisplayName:o},aiChatSettings:{shouldOpenLinksInNewTab:d},searchSettings:{tabs:c}}=p.useInkeepConfig();if(e.role!=="assistant")return null;const m=e.links.map(l=>{const C=wa.transformInkeepSource(l,"chatSourceItem",{organizationDisplayName:o,tabs:c,transformSource:r}),b=C.shouldOpenInNewTab!==void 0?C.shouldOpenInNewTab:d;return{...C,isExternal:b}});return n.jsx(Tn,{children:h.maybeRender(i,m),...s})},jn=a.ikp(ka.LinkWithQueryParams,{_id:"aiChatMessageSourceItem"}),At=t=>{const{source:e,onClick:i,...s}=t,{logEvent:r}=O.useChatEvents(),{conversation:o}=L.useInkeepConversation(),d=()=>{r({eventName:"assistant_source_item_clicked",properties:{conversation:o,link:e}})};return n.jsx(f.SourceItemProvider,{source:e,children:n.jsx(jn,{"data-type":e.type,appendToUrl:e.appendToUrl,isExternal:e.isExternal,"data-breadcrumbs":!!e.breadcrumbs?.length,onClick:u.composeEventHandlers(i,d),...s})})},yn=a.ikp("div",{_id:"aiChatMessageSourceItem__Breadcrumbs"}),Et=t=>{const{source:e}=f.useSourceItem();return e.breadcrumbs?.length?n.jsx(yn,{"data-type":e.type,...t}):null},Hn=a.ikp(E.CustomIcon,{_id:"aiChatMessageSourceItem__BreadcrumbIcon",iconKey:"breadcrumbSeparator"}),wn=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatMessageSourceItem__Icon"}),Ft=t=>{const{source:e}=f.useSourceItem();return n.jsx(wn,{iconSettings:e.icon,"data-type":e.type,...t})},Ln=a.ikp("span",{_id:"aiChatMessageSourceItem__Title"}),kt=t=>{const{source:e}=f.useSourceItem();return n.jsx(Ln,{"data-type":e.type,children:e.title,...t})},Dn=a.ikp("span",{_id:"aiChatMessageSourceItem__Tag"}),It=t=>{const{source:e}=f.useSourceItem();return n.jsx(Dn,{"data-type":e.type,...t})},On=a.ikp("span",{_id:"aiChatMessageSourceItem__Description"}),Mt=t=>{const{source:e}=f.useSourceItem(),{children:i,...s}=t,r=g.useMemo(()=>e.description?Ba.highlightEmphasis(e.description):[],[e.description]);return r.length?n.jsx(On,{"data-type":e.type,children:h.maybeRender(i,r),...s}):null},qn=a.ikp("span",{_id:"aiChatMessageSourceItem__DescriptionPart"}),St=t=>{const{part:e,...i}=t,{source:s}=f.useSourceItem();return typeof e=="string"?e:n.jsx(qn,{"data-type":s.type,children:e.content,"data-highlighted":h.dataAttr(e.highlighted),...i})},Rn=a.ikp(E.CustomIcon,{_id:"aiChatMessageSourceItem__Indicator"}),xt=t=>{const{source:e}=f.useSourceItem();return n.jsx(Rn,{iconKey:e.isExternal?"openLinkInNewTab":"openLinkInSameTab",...t})},ft=a.ikp("div",{_id:"aiChatFooter"}),Bt=a.ikp("div",{_id:"aiChatInput__Fieldset"}),Tt=a.ikp("div",{_id:"aiChatInput__Group"}),Wn=a.ikp("textarea",{_id:"aiChatInput"}),jt=g.forwardRef(({onChange:t,onKeyDown:e,...i},s)=>{const{handleInputChange:r,handleInputKeyDown:o,input:d,error:c,shouldAutoFocusInput:m,inputRef:l}=v.useChat(),{aiChatSettings:C}=p.useInkeepConfig(),b=re.useComposedRefs(s,l);return Da.useWidgetAutoFocus("chat",l,m),n.jsx(Wn,{asChild:!0,ref:b,maxLength:99999,placeholder:C.placeholder,value:d,onChange:u.composeEventHandlers(t,r),onKeyDown:u.composeEventHandlers(e,o),disabled:!!c||C.isViewOnly,...i,children:n.jsx(ae,{})})}),Nn=a.ikp("button",{_id:"aiChatInput__SendButton"}),yt=t=>{const{handleSubmit:e,isSubmitDisabled:i,error:s}=v.useChat(),{aiChatSettings:r}=p.useInkeepConfig(),{onClick:o,...d}=t;return n.jsx(Nn,{onClick:u.composeEventHandlers(o,()=>e()),"aria-label":"Send message",disabled:i||!!s||r.isViewOnly,...d})},Ht=a.ikp(E.CustomIcon,{_id:"aiChatInput__SendButtonIcon",iconKey:"chatSubmit"}),Qn=a.ikp("div",{_id:"aiChatAttachmentsBar"}),wt=t=>{const{selectedWorkflow:e}=v.useChat();return!e||!e.supportedInputs?.length?null:n.jsx(F.AttachmentsBarProvider,{children:n.jsx(Qn,{...t})})},$n=a.ikp("div",{_id:"aiChatAttachmentsBar__List"}),Lt=t=>{const{children:e,...i}=t,{messageAttachments:s}=v.useChat();return n.jsx($n,{children:h.maybeRender(e,s),...i})},Vn=a.ikp("div",{_id:"aiChatAttachmentsBar__Attachment"}),Dt=t=>{const{attachment:e,...i}=t;return n.jsx(w.AttachmentItemProvider,{attachment:e,children:n.jsx(Vn,{...i})})},Un=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatAttachmentsBar__AttachmentIcon"}),Ot=t=>{const{attachment:e}=w.useAttachmentItem(),i=e.contentType?.attachmentIcon;return i?n.jsx(Un,{iconSettings:i,...t}):null},Kn=a.ikp("span",{_id:"aiChatAttachmentsBar__AttachmentTitle"}),qt=t=>{const{attachment:e}=w.useAttachmentItem();return n.jsx(Kn,{children:e.title,...t})},zn=a.ikp("button",{_id:"aiChatAttachmentsBar__AttachmentDelete"}),Rt=t=>{const{onClick:e,...i}=t,{attachment:s}=w.useAttachmentItem(),{setMessageAttachments:r}=v.useChat(),o=()=>{r(d=>d.filter(c=>c.id!==s.id))};return n.jsx(zn,{"aria-label":"Remove attachment",children:n.jsx(E.CustomIcon,{iconKey:"close"}),onClick:u.composeEventHandlers(e,o),...i})},Wt=a.ikp("div",{_id:"aiChatAttachmentsBar__Actions"}),Nt=a.ikp(j.Tooltip,{_id:"aiChatAttachmentsBar__InfoTip",delayDuration:0}),Qt=a.ikp(j.Trigger,{_id:"aiChatAttachmentsBar__InfoTipIcon",children:n.jsx(E.CustomIcon,{iconKey:"info"})}),me=a.ikp(j.Arrow,{_id:"aiChatAttachmentsBar__InfoTipArrow"}),$t=a.ikp(j.Content,{_id:"aiChatAttachmentsBar__InfoTipText",side:"bottom",sideOffset:3,align:"center",children:n.jsxs(n.Fragment,{children:[n.jsx(me,{}),"Attachments will be kept in context for the entire conversation."]})}),Gn=a.ikp("div",{_id:"aiChatAttachmentsBar__Inputs"}),Vt=t=>{const{children:e,...i}=t,{selectedWorkflow:s}=v.useChat();return s?.supportedInputs?n.jsx(Gn,{children:h.maybeRender(e,s.supportedInputs),...i}):null},Yn=a.ikp("button",{_id:"aiChatAttachmentsBar__Input"}),Ut=t=>{const{input:e,onClick:i,...s}=t,{selectedWorkflow:r,messageAttachments:o,setMessageAttachments:d}=v.useChat(),{selectInput:c,onOpen:m}=F.useAttachmentsBar(),l=()=>{if(e.type==="FUNCTIONAL_MULTI_ATTACHMENT")return r?e.onInvoke(r,e,d,[...o]):void 0;c(e),m()};return n.jsx(Yn,{children:e.displayName,onClick:u.composeEventHandlers(i,l),...s})},Jn=a.ikp(_.Root,{_id:"aiChatAttachmentsBar__Modal"}),Kt=t=>{const{onOpenChange:e,...i}=t,{selectInput:s,isOpen:r,onClose:o,selectedInput:d}=F.useAttachmentsBar(),c=m=>{m||(o(),s(null))};return n.jsx(Jn,{open:r&&d!==null,onOpenChange:u.composeEventHandlers(e,c),...i})},zt=a.ikp(_.Overlay,{_id:"aiChatAttachmentsBar__ModalOverlay"}),Gt=a.ikp(_.Content,{_id:"aiChatAttachmentsBar__ModalContent","aria-describedby":void 0}),Yt=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalHeader"}),Xn=a.ikp(_.Title,{_id:"aiChatAttachmentsBar__ModalHeading"}),Jt=t=>{const{selectedInput:e}=F.useAttachmentsBar(),i=`Add ${e?.displayName}`;return n.jsx(Xn,{children:i,...t})},Zn=a.ikp("span",{_id:"aiChatAttachmentsBar__ModalDescription"}),Xt=t=>{const{selectedInput:e}=F.useAttachmentsBar(),i=e?.workflowModalProps?.modalHelpText;return i?n.jsx(Zn,{children:i,...t}):null},es=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalHelp"}),Zt=t=>{const{children:e,...i}=t,{selectedInput:s}=F.useAttachmentsBar(),r=s?.workflowModalProps?.modalHelpElement;return r?n.jsx(es,{asChild:!e,children:e||r,...i}):null},ei=a.ikp(_.Close,{_id:"aiChatAttachmentsBar__ModalClose",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),ti=a.ikp("div",{_id:"aiChatAttachmentsBar__ModalBody"}),ts=a.ikp("form",{_id:"aiChatAttachmentsBar__Form"}),ii=t=>{const{onSubmit:e,...i}=t,{form:s}=F.useAttachmentsBar();return n.jsx(ts,{onSubmit:u.composeEventHandlers(e,s.onSubmit),...i})},ai=a.ikp("div",{_id:"aiChatAttachmentsBar__FormTitle",role:"group"}),is=a.ikp("label",{_id:"aiChatAttachmentsBar__FormTitleLabel"}),ni=t=>{const{form:e,selectedInput:i}=F.useAttachmentsBar();return n.jsx(is,{htmlFor:`${i?.id}-title`,children:e.labels.title,...t})},as=a.ikp("input",{_id:"aiChatAttachmentsBar__FormTitleInput"}),si=t=>{const{onChange:e,...i}=t,{form:s,selectedInput:r}=F.useAttachmentsBar();return n.jsx(as,{name:"title",value:s.data.title,id:`${r?.id}-title`,"data-invalid":h.dataAttr(!!s.errors.title),"aria-invalid":!!s.errors.title,onChange:u.composeEventHandlers(e,s.onChange),...i})},ns=a.ikp("span",{_id:"aiChatAttachmentsBar__FormTitleError"}),ri=t=>{const{form:e}=F.useAttachmentsBar();return e.errors.title?n.jsx(ns,{"aria-live":"polite",children:e.errors.title,...t}):null},oi=a.ikp("div",{_id:"aiChatAttachmentsBar__FormTitle",role:"group"}),ss=a.ikp("label",{_id:"aiChatAttachmentsBar__FormContentLabel"}),di=t=>{const{form:e,selectedInput:i}=F.useAttachmentsBar();return n.jsx(ss,{htmlFor:`${i?.id}-content`,children:e.labels.content,...t})},rs=a.ikp("textarea",{_id:"aiChatAttachmentsBar__FormTitleInput"}),ci=t=>{const{onChange:e,...i}=t,{form:s,selectedInput:r}=F.useAttachmentsBar();return n.jsx(rs,{asChild:!0,rows:4,name:"content",value:s.data.content,id:`${r?.id}-content`,"data-invalid":h.dataAttr(!!s.errors.content),"aria-invalid":!!s.errors.content,onChange:u.composeEventHandlers(e,s.onChange),...i,children:n.jsx(ae,{maxRows:10})})},os=a.ikp("span",{_id:"aiChatAttachmentsBar__FormContentError"}),mi=t=>{const{form:e}=F.useAttachmentsBar();return e.errors.content?n.jsx(os,{"aria-live":"polite",children:e.errors.content,...t}):null},li=a.ikp("button",{_id:"aiChatAttachmentsBar__FormSubmitButton",children:"Upload",type:"submit"}),hi=a.ikp("div",{_id:"aiChatActionBar"}),ui=a.ikp("div",{_id:"aiChat__ChatActions"}),Ci=a.ikp("div",{_id:"aiChatTagline__Container"}),pi=a.ikp("span",{_id:"aiChatTagline__Text",children:"Powered by"}),vi=a.ikp(Ma.default,{_id:"aiChatTagline__Logo"}),bi=a.ikp("a",{_id:"aiChatTagline__BrandName",children:"inkeep",href:"https://www.inkeep.com/",target:"_blank",rel:"noopener noreferrer"}),ds=a.ikp(j.Trigger,{_id:"aiChat__ChatAction"}),G=t=>{const{action:e,onClick:i,className:s,...r}=t,{clear:o,stop:d,isLoading:c,messages:m,selectedWorkflow:l}=v.useChat(),{conversation:C}=L.useInkeepConversation(),{aiChatSettings:b,baseSettings:k}=p.useInkeepConfig(),{logEvent:y}=O.useChatEvents(),[N,J]=te.useCopyToClipboard(),[Q,X]=te.useCopyToClipboard();if({help:!1,copy:m.length===0||!b.isCopyChatButtonVisible||c,share:m.length===0||!b.isShareButtonVisible||!C.id||!!l||c,clear:m.length===0||b.isViewOnly||c,stop:!c}[e])return null;const ee={help:()=>{},copy:()=>{const $=m.map(H=>{const D=`**${H.role==="assistant"?"AI Assistant":"User"}**`,M=h.getMessageContent(H),S=Ia.stringifyAttachments(H.metadata?.attributes?.attachments),V=S?`
8
8
 
9
9
  **Attachments**
10
10
 
@@ -14,4 +14,4 @@ ${M}${V}`}).join(`
14
14
 
15
15
  ---
16
16
 
17
- `);J($)},share:async()=>{const $={visibility:"public",tags:[],userProperties:{},messages:C.messages.map(S=>({...S,createdAt:void 0,updatedAt:void 0,id:Date.now().toString()+S.id,conversationId:void 0}))},{apiKey:H,analyticsApiBaseUrl:D}=k,M=await Ha.logConversation("",$,H,D);if(M){const V=`${b.shareChatUrlBasePath}?${L.SHARE_QUERY_PARAM}=${M?.id}`;X(V),y({eventName:"chat_share_button_clicked",properties:{sharedConversationId:M?.id,originalConversationId:C.id,sharedChatUrl:V,conversation:M}})}},clear:o,stop:d},Ce={copy:N,share:Q};return n.jsx(j.Tooltip,{delayDuration:0,open:Ce[e],children:n.jsx(ds,{"data-type":e,"data-copied":h.dataAttr(N||Q),className:`${s} ${e}`,children:n.jsx(le,{action:e}),onClick:u.composeEventHandlers(i,ee[e]),...r})})},cs=a.ikp("span",{_id:"aiChat__ChatActionLabel"}),le=t=>{const{action:e,...i}=t,{aiChatSettings:s}=p.useInkeepConfig(),r=s.toolbarButtonLabels??{},o={help:r.getHelp??"Get Help",copy:r.copyChat??"Copy",share:r.share??"Share",clear:r.clear??"Clear",stop:r.stop??"Stop"};return n.jsx(cs,{children:o[e],...i})},ms=a.ikp(j.TooltipContent,{_id:"aiChat__ChatActionFeeback"}),gi=t=>{const{action:e,children:i,...s}=t,r={copy:"Copied!",share:"Link copied!"};return n.jsxs(ms,{sideOffset:5,...s,children:[n.jsx(j.Arrow,{}),i||r[e]]})},ls=a.ikp(T.Root,{_id:"aiChatHelpActions"}),Pi=t=>{const{children:e,...i}=t,{aiChatSettings:s}=p.useInkeepConfig(),{getHelpOptions:r}=s;if(!r||(r??[]).length===0)return null;const{_pinned:o,_unpinned:d}=r.reduce((C,b)=>{const k=b.isPinnedToToolbar?"_pinned":"_unpinned";return{...C,[k]:[...C[k],b]}},{_pinned:[],_unpinned:[]}),c=d.length===1?[...o,d[0]]:o,m=d.length===1?[]:d,l=ie.useHelpMenuState();return n.jsx(ie.HelpMenuProvider,{value:l,children:n.jsx(ls,{open:l.open,onOpenChange:l.setOpen,children:h.maybeRender(e,{pinned:c,unpinned:m}),...i})})},hs=a.ikp(G,{_id:"aiChatHelpAction",action:"help"}),us=a.ikp("a",{_id:"aiChatHelpAction",target:"_blank",rel:"noreferrer"}),Ai=t=>{const{action:e,onClick:i,...s}=t,{handleAction:r,logHelpAction:o}=se.useChatAction(e),d=e.action.type,c={"aria-label":e.name,"data-name":e.name,children:e.name,onClick:u.composeEventHandlers(i,()=>{r(),o()}),...s};return d==="open_link"?n.jsx(us,{href:e.action.url,...c}):n.jsx(hs,{...c})},Cs=a.ikp(T.Trigger,{_id:"aiChatHelpActions__Trigger"}),_i=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(G,{action:"help",...t,asChild:!0,children:n.jsx(Cs,{children:e.toolbarButtonLabels?.getHelp??"Get Help"})})}),ps=a.ikp(T.Content,{_id:"aiChatHelpActions__Menu"}),Ei=t=>n.jsx(ps,{side:"top",sideOffset:8,align:"center",alignOffset:-10,...t}),Fi=a.ikp(T.Arrow,{_id:"aiChatHelpActions__MenuArrow"}),ki=t=>{const{action:e,onClick:i,...s}=t,{handleAction:r,logHelpAction:o}=se.useChatAction(e),{setOpen:d}=ie.useHelpMenu(),c=()=>{r({onOpenForm:()=>d(!1)}),o()},m=e.action.type,l=a.ikp(m==="open_link"?"a":"button",{_id:"aiChatHelpActions__MenuItem",children:e.name,"aria-label":e.name,"data-name":e.name,"data-type":e.action.type,...m==="open_link"&&{href:e.action.url,target:"_blank",rel:"noopener"},onClick:u.composeEventHandlers(i,c)});return n.jsx(l,{...s})},vs=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatHelpActions_MenuItemIcon"}),Ii=t=>{const{action:e,...i}=t;return e.icon?n.jsx(vs,{iconSettings:e.icon,...i}):null},bs=a.ikp(A.Root,{_id:"aiChatFeedbackModal"}),Mi=t=>{const{onOpenChange:e,...i}=t,{currentFeedback:s,setCurrentFeedback:r}=ne.useMessageFeedback();return n.jsx(bs,{open:s!==null,onOpenChange:u.composeEventHandlers(e,()=>r(null)),...i})},Si=a.ikp(A.Overlay,{_id:"aiChatFeedbackModal__Overlay"}),xi=a.ikp(A.Content,{_id:"aiChatFeedbackModal__Content","aria-describedby":void 0}),Bi=a.ikp(A.Title,{_id:"aiChatFeedbackModal__Header",children:"Help improve my answers!"}),fi=a.ikp(A.Close,{_id:"aiChatFeedbackModal__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Ti=a.ikp("div",{_id:"aiChatFeedbackModal__Body"}),gs=a.ikp("form",{_id:"aiChatFeedbackForm"}),ji=t=>{const{onSubmit:e,...i}=t,{submitNegativeFeedback:s,currentFeedback:r,setCurrentFeedback:o}=ne.useMessageFeedback(),d=c=>{c.preventDefault();const m=c.target,l=new FormData(m),C=Object.fromEntries(l.entries());r&&(s(r,C),o(null))};return n.jsx(gs,{onSubmit:u.composeEventHandlers(e,d),...i})},Ps=a.ikp("div",{_id:"aiChatFeedbackItem"}),yi=t=>{const{name:e,...i}=t;return n.jsx(K.FeedbackItemProvider,{name:e,children:n.jsx(Ps,{...i})})},As=a.ikp(z.Root,{_id:"aiChatFeedbackItem__Checkbox"}),Hi=t=>{const{name:e,focusItem:i}=K.useFeedbackItem(),{onCheckedChange:s,...r}=t,o=d=>{d&&i?.current?.focus()};return n.jsx(As,{id:`feedback-${e}`,name:e,onCheckedChange:u.composeEventHandlers(s,o),...r})},wi=a.ikp(z.Indicator,{_id:"aiChatFeedbackItem__CheckboxIndicator",children:n.jsx(be.CheckboxIcon,{})}),_s=a.ikp("label",{_id:"aiChatFeedbackItem__Label"}),Li=t=>{const{name:e}=K.useFeedbackItem(),i={unrelated_response:"Didn't answer my question",inaccurate_statement:"Inaccurate statement",inaccurate_code_snippet:"Inaccurate code snippet",irrelevant_citations:"Irrelevant citations"};return n.jsx(_s,{htmlFor:`feedback-${e}`,children:i[e],...t})},Es=a.ikp("textarea",{_id:"aiChatFeedbackItem__Description",placeholder:"Please describe"}),Di=t=>{const{name:e,focusItem:i}=K.useFeedbackItem();return n.jsx(Es,{ref:i,name:`${e}:description`,...t})},Oi=a.ikp("button",{_id:"aiChatFeedbackForm__SubmitButton",children:"Submit",type:"submit"}),Fs=a.ikp("div",{_id:"aiChatForm__Wrapper"}),qi=t=>{const{form:e}=_.useChatForm();return e?n.jsx(Fs,{...t}):null},ks=a.ikp("form",{_id:"aiChatForm"}),Ri=t=>{const{onSubmit:e,...i}=t,{handleSubmit:s,isSuccess:r}=_.useChatForm();return r?null:n.jsx(ks,{onSubmit:u.composeEventHandlers(e,s),...i})},Is=a.ikp("button",{_id:"aiChatForm__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Wi=t=>{const{onClick:e,...i}=t,{closeForm:s}=_.useChatForm();return n.jsx(Is,{onClick:u.composeEventHandlers(e,s),...i})},Ni=a.ikp("div",{_id:"aiChatForm__Header"}),Ms=a.ikp("h2",{_id:"aiChatForm__Heading"}),Qi=t=>{const{form:e}=_.useChatForm();return e?.heading?n.jsx(Ms,{children:e.heading,...t}):null},Ss=a.ikp(U.Markdown,{_id:"aiChatForm__Description"}),$i=t=>{const{form:e}=_.useChatForm();return e?.description?n.jsx(Ss,{children:e.description,...t}):null},xs=a.ikp("div",{_id:"aiChatForm__Content"}),Vi=t=>{const{children:e,...i}=t,{fields:s=[]}=_.useChatForm();return n.jsx(xs,{children:h.maybeRender(e,s),...i})},Bs=a.ikp("div",{_id:"aiChatForm__Field"}),Ui=t=>{const{field:e,autoFocus:i,...s}=t,{control:r,errors:o}=_.useChatForm();return n.jsx(Ba.Controller,{name:e.name,control:r,rules:{required:e.isRequired?`${e.label} is required.`:void 0},render:({field:d})=>{const c=d.value!==void 0||e.inputType==="file";return n.jsx(f.FormFieldProvider,{"data-invalid":h.dataAttr(!!o[e.name]),field:e,fieldProps:d,autoFocus:i,children:c&&n.jsx(Bs,{"data-input-type":e.inputType,"data-hidden":h.dataAttr(e.isHidden),...s})})}})},fs=a.ikp("label",{_id:"aiChatForm__FieldLabel"}),Ki=t=>{const{field:e}=f.useFormField();return n.jsx(fs,{"data-required":h.dataAttr(e.isRequired),htmlFor:e.name,children:e.label,...t})},Ts=a.ikp("input",{_id:"aiChatForm__FieldText",type:"text"}),Y=t=>{const{field:e,error:i,fieldProps:{onChange:s,onBlur:r,...o},autoFocus:d}=f.useFormField(),{onChange:c,onBlur:m,...l}=t;return n.jsx(Ts,{id:e.name,autoFocus:d,placeholder:"placeholder"in e?e.placeholder:void 0,"data-invalid":h.dataAttr(!!i),onChange:u.composeEventHandlers(c,s),onBlur:u.composeEventHandlers(m,r),...o,...l})},zi=a.ikp(Y,{_id:"aiChatForm__FieldEmail",type:"email"}),js=a.ikp("input",{_id:"aiChatForm__FieldFile",type:"file",multiple:!0}),Gi=t=>{const{field:e,error:i,fieldProps:{value:s,onChange:r,onBlur:o,...d},autoFocus:c}=f.useFormField(),{onChange:m,onBlur:l,...C}=t,b=k=>{const y=k.target.files;r(y)};return n.jsx(js,{id:e.name,autoFocus:c,"data-value":s,"data-invalid":h.dataAttr(!!i),...C,...d,onChange:u.composeEventHandlers(m,b),onBlur:u.composeEventHandlers(l,o)})},Yi=a.ikp(Y,{_id:"aiChatForm__FieldTextArea",type:"textarea",asChild:!0,children:n.jsx(ae,{maxRows:8})}),ys=a.ikp(z.Root,{_id:"aiChatForm__FieldCheckbox"}),Ji=t=>{const{field:e,error:i,fieldProps:s,autoFocus:r}=f.useFormField(),{onCheckedChange:o,...d}=t;return n.jsx(ys,{id:e.name,name:e.name,autoFocus:r,"data-invalid":h.dataAttr(!!i),checked:s.value,onCheckedChange:u.composeEventHandlers(o,s.onChange),...d})},Xi=a.ikp(z.Indicator,{_id:"aiChatForm__FieldCheckboxIndicator",children:n.jsx(be.CheckboxIcon,{})}),Hs=a.ikp(I.Root,{_id:"aiChatForm__FieldSelect"}),Zi=t=>{const{field:e,error:i,fieldProps:s}=f.useFormField(),{onValueChange:r,...o}=t;return n.jsx(Hs,{name:e.name,"data-invalid":h.dataAttr(!!i),value:s.value,onValueChange:u.composeEventHandlers(r,s.onChange),...o})},ea=a.ikp(I.Trigger,{_id:"aiChatForm__FieldSelect__Trigger"}),ws=a.ikp(I.Value,{_id:"aiChatForm__FieldSelect__Value"}),ta=t=>{const{field:e}=f.useFormField();return n.jsx(ws,{placeholder:"placeholder"in e?e.placeholder:void 0,...t})},ia=a.ikp(I.Icon,{_id:"aiChatForm__FieldSelect__Icon",asChild:!0,children:n.jsx(x.BuiltInIconRenderer,{iconSettings:{builtIn:"LuChevronDown"}})}),aa=a.ikp(I.Content,{_id:"aiChatForm__FieldSelect__Content",position:"popper"}),na=a.ikp(I.Viewport,{_id:"aiChatForm__FieldSelect__Viewport"}),sa=a.ikp(I.Item,{_id:"aiChatForm__FieldSelect__Item"}),ra=a.ikp(I.ItemText,{_id:"aiChatForm__FieldSelect__ItemText"}),oa=a.ikp(I.ItemIndicator,{_id:"aiChatForm__FieldSelect__ItemIndicator",asChild:!0,children:n.jsx(x.BuiltInIconRenderer,{iconSettings:{builtIn:"LuCheck"}})}),Ls=a.ikp("span",{_id:"aiChatForm__FieldError"}),da=t=>{const{error:e}=f.useFormField();return e?n.jsx(Ls,{children:e.message?.toString(),...t}):null},Ds=a.ikp("span",{_id:"aiChatForm__Error"}),ca=t=>{const{formError:e}=_.useChatForm();return e?n.jsx(Ds,{children:e.message,...t}):null},ma=a.ikp("div",{_id:"aiChatForm__Footer"}),Os=a.ikp("button",{_id:"aiChatForm__Cancel",children:"Cancel",type:"button"}),la=t=>{const{onClick:e,...i}=t,{closeForm:s}=_.useChatForm();return n.jsx(Os,{onClick:u.composeEventHandlers(e,s),...i})},qs=a.ikp("button",{_id:"aiChatForm__Submit",children:"Submit",type:"submit"}),ha=t=>{const{onClick:e,...i}=t,{isSubmitting:s,form:r}=_.useChatForm(),o=r?.buttons.submit.label||"Submit";return n.jsx(qs,{disabled:s,...i,children:o})},Rs=a.ikp("div",{_id:"aiChatForm__Success"}),ua=t=>{const{isSuccess:e}=_.useChatForm();return e?n.jsx(Rs,{...t}):null},Ws=a.ikp("h2",{_id:"aiChatForm__SuccessHeading"}),Ca=t=>{const{form:e}=_.useChatForm();return n.jsx(Ws,{children:e?.successView?.heading,...t})},Ns=a.ikp(U.Markdown,{_id:"aiChatForm__SuccessMessage"}),pa=t=>{const{form:e}=_.useChatForm();return n.jsx(Ns,{children:e?.successView?.message,...t})},Qs=a.ikp("button",{_id:"aiChatForm__SuccessButton"}),va=t=>{const{onClick:e,...i}=t,{form:s,closeForm:r}=_.useChatForm(),o=s?.successView?.doneButton;if(!o)return null;const d=o.icon&&n.jsx(x.BuiltInIconRenderer,{iconSettings:o.icon}),c=o.label;return n.jsx(Qs,{onClick:u.composeEventHandlers(e,r),children:n.jsxs(n.Fragment,{children:[d,c]}),...i})};exports.Provider=v.ChatProvider;exports.ActionBar=hi;exports.Actions=ui;exports.AttachmentsBar=wt;exports.AttachmentsBarActions=Wt;exports.AttachmentsBarAttachment=Dt;exports.AttachmentsBarAttachmentDelete=Rt;exports.AttachmentsBarAttachmentIcon=Ot;exports.AttachmentsBarAttachmentTitle=qt;exports.AttachmentsBarForm=ii;exports.AttachmentsBarFormContent=oi;exports.AttachmentsBarFormContentError=mi;exports.AttachmentsBarFormContentInput=ci;exports.AttachmentsBarFormContentLabel=di;exports.AttachmentsBarFormSubmitButton=li;exports.AttachmentsBarFormTitle=ai;exports.AttachmentsBarFormTitleError=ri;exports.AttachmentsBarFormTitleInput=si;exports.AttachmentsBarFormTitleLabel=ni;exports.AttachmentsBarInfoTip=Nt;exports.AttachmentsBarInfoTipArrow=me;exports.AttachmentsBarInfoTipIcon=Qt;exports.AttachmentsBarInfoTipText=$t;exports.AttachmentsBarInput=Ut;exports.AttachmentsBarInputs=Vt;exports.AttachmentsBarList=Lt;exports.AttachmentsBarModal=Kt;exports.AttachmentsBarModalBody=ti;exports.AttachmentsBarModalClose=ei;exports.AttachmentsBarModalContent=Gt;exports.AttachmentsBarModalDescription=Xt;exports.AttachmentsBarModalHeader=Yt;exports.AttachmentsBarModalHeading=Jt;exports.AttachmentsBarModalHelp=Zt;exports.AttachmentsBarModalOverlay=zt;exports.ChatAction=G;exports.ChatActionFeedback=gi;exports.ChatActionLabel=le;exports.ChatHelpAction=Ai;exports.Content=ke;exports.ContentScrollArea=Ie;exports.ContentScrollAreaCorner=Be;exports.ContentScrollAreaScrollbar=Se;exports.ContentScrollAreaThumb=xe;exports.ContentScrollAreaViewport=Me;exports.ConversationLoading=Pe;exports.Disclaimer=Te;exports.DisclaimerArrow=Le;exports.DisclaimerContent=He;exports.DisclaimerLabel=je;exports.DisclaimerText=we;exports.DisclaimerTrigger=ye;exports.EmbeddedChatPrimitiveActionBar=hi;exports.EmbeddedChatPrimitiveActions=ui;exports.EmbeddedChatPrimitiveAttachmentsBar=wt;exports.EmbeddedChatPrimitiveAttachmentsBarActions=Wt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachment=Dt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentDelete=Rt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentIcon=Ot;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentTitle=qt;exports.EmbeddedChatPrimitiveAttachmentsBarForm=ii;exports.EmbeddedChatPrimitiveAttachmentsBarFormContent=oi;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentError=mi;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentInput=ci;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentLabel=di;exports.EmbeddedChatPrimitiveAttachmentsBarFormSubmitButton=li;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitle=ai;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleError=ri;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleInput=si;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleLabel=ni;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTip=Nt;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipArrow=me;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipIcon=Qt;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipText=$t;exports.EmbeddedChatPrimitiveAttachmentsBarInput=Ut;exports.EmbeddedChatPrimitiveAttachmentsBarInputs=Vt;exports.EmbeddedChatPrimitiveAttachmentsBarList=Lt;exports.EmbeddedChatPrimitiveAttachmentsBarModal=Kt;exports.EmbeddedChatPrimitiveAttachmentsBarModalBody=ti;exports.EmbeddedChatPrimitiveAttachmentsBarModalClose=ei;exports.EmbeddedChatPrimitiveAttachmentsBarModalContent=Gt;exports.EmbeddedChatPrimitiveAttachmentsBarModalDescription=Xt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHeader=Yt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHeading=Jt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHelp=Zt;exports.EmbeddedChatPrimitiveAttachmentsBarModalOverlay=zt;exports.EmbeddedChatPrimitiveChatAction=G;exports.EmbeddedChatPrimitiveChatActionFeedback=gi;exports.EmbeddedChatPrimitiveChatActionLabel=le;exports.EmbeddedChatPrimitiveChatHelpAction=Ai;exports.EmbeddedChatPrimitiveContent=ke;exports.EmbeddedChatPrimitiveContentScrollArea=Ie;exports.EmbeddedChatPrimitiveContentScrollAreaCorner=Be;exports.EmbeddedChatPrimitiveContentScrollAreaScrollbar=Se;exports.EmbeddedChatPrimitiveContentScrollAreaThumb=xe;exports.EmbeddedChatPrimitiveContentScrollAreaViewport=Me;exports.EmbeddedChatPrimitiveConversationLoading=Pe;exports.EmbeddedChatPrimitiveDisclaimer=Te;exports.EmbeddedChatPrimitiveDisclaimerArrow=Le;exports.EmbeddedChatPrimitiveDisclaimerContent=He;exports.EmbeddedChatPrimitiveDisclaimerLabel=je;exports.EmbeddedChatPrimitiveDisclaimerText=we;exports.EmbeddedChatPrimitiveDisclaimerTrigger=ye;exports.EmbeddedChatPrimitiveExampleQuestion=Re;exports.EmbeddedChatPrimitiveExampleQuestionButton=We;exports.EmbeddedChatPrimitiveExampleQuestions=De;exports.EmbeddedChatPrimitiveExampleQuestionsLabel=Oe;exports.EmbeddedChatPrimitiveExampleQuestionsList=qe;exports.EmbeddedChatPrimitiveFeedbackForm=ji;exports.EmbeddedChatPrimitiveFeedbackItem=yi;exports.EmbeddedChatPrimitiveFeedbackItemCheckbox=Hi;exports.EmbeddedChatPrimitiveFeedbackItemCheckboxIndicator=wi;exports.EmbeddedChatPrimitiveFeedbackItemDescription=Di;exports.EmbeddedChatPrimitiveFeedbackItemLabel=Li;exports.EmbeddedChatPrimitiveFeedbackModal=Mi;exports.EmbeddedChatPrimitiveFeedbackModalBody=Ti;exports.EmbeddedChatPrimitiveFeedbackModalClose=fi;exports.EmbeddedChatPrimitiveFeedbackModalContent=xi;exports.EmbeddedChatPrimitiveFeedbackModalHeader=Bi;exports.EmbeddedChatPrimitiveFeedbackModalOverlay=Si;exports.EmbeddedChatPrimitiveFeedbackSubmitButton=Oi;exports.EmbeddedChatPrimitiveFooter=Bt;exports.EmbeddedChatPrimitiveForm=Ri;exports.EmbeddedChatPrimitiveFormCancel=la;exports.EmbeddedChatPrimitiveFormClose=Wi;exports.EmbeddedChatPrimitiveFormContent=Vi;exports.EmbeddedChatPrimitiveFormDescription=$i;exports.EmbeddedChatPrimitiveFormError=ca;exports.EmbeddedChatPrimitiveFormField=Ui;exports.EmbeddedChatPrimitiveFormFieldCheckbox=Ji;exports.EmbeddedChatPrimitiveFormFieldCheckboxIndicator=Xi;exports.EmbeddedChatPrimitiveFormFieldEmail=zi;exports.EmbeddedChatPrimitiveFormFieldError=da;exports.EmbeddedChatPrimitiveFormFieldFile=Gi;exports.EmbeddedChatPrimitiveFormFieldLabel=Ki;exports.EmbeddedChatPrimitiveFormFieldSelect=Zi;exports.EmbeddedChatPrimitiveFormFieldSelectContent=aa;exports.EmbeddedChatPrimitiveFormFieldSelectIcon=ia;exports.EmbeddedChatPrimitiveFormFieldSelectItem=sa;exports.EmbeddedChatPrimitiveFormFieldSelectItemIndicator=oa;exports.EmbeddedChatPrimitiveFormFieldSelectItemText=ra;exports.EmbeddedChatPrimitiveFormFieldSelectTrigger=ea;exports.EmbeddedChatPrimitiveFormFieldSelectValue=ta;exports.EmbeddedChatPrimitiveFormFieldSelectViewport=na;exports.EmbeddedChatPrimitiveFormFieldText=Y;exports.EmbeddedChatPrimitiveFormFieldTextArea=Yi;exports.EmbeddedChatPrimitiveFormFooter=ma;exports.EmbeddedChatPrimitiveFormHeader=Ni;exports.EmbeddedChatPrimitiveFormHeading=Qi;exports.EmbeddedChatPrimitiveFormSubmit=ha;exports.EmbeddedChatPrimitiveFormSuccess=ua;exports.EmbeddedChatPrimitiveFormSuccessButton=va;exports.EmbeddedChatPrimitiveFormSuccessHeading=Ca;exports.EmbeddedChatPrimitiveFormSuccessMessage=pa;exports.EmbeddedChatPrimitiveFormWrapper=qi;exports.EmbeddedChatPrimitiveHeaderToolbar=_e;exports.EmbeddedChatPrimitiveHelpActions=Pi;exports.EmbeddedChatPrimitiveHelpActionsMenu=Ei;exports.EmbeddedChatPrimitiveHelpActionsMenuArrow=Fi;exports.EmbeddedChatPrimitiveHelpActionsMenuItem=ki;exports.EmbeddedChatPrimitiveHelpActionsMenuItemIcon=Ii;exports.EmbeddedChatPrimitiveHelpActionsTrigger=_i;exports.EmbeddedChatPrimitiveInput=jt;exports.EmbeddedChatPrimitiveInputFieldset=ft;exports.EmbeddedChatPrimitiveInputGroup=Tt;exports.EmbeddedChatPrimitiveIntroMessageWrapper=Ue;exports.EmbeddedChatPrimitiveMessage=ut;exports.EmbeddedChatPrimitiveMessageAction=bt;exports.EmbeddedChatPrimitiveMessageAttachments=it;exports.EmbeddedChatPrimitiveMessageAttachmentsItem=nt;exports.EmbeddedChatPrimitiveMessageAttachmentsItemIcon=st;exports.EmbeddedChatPrimitiveMessageAttachmentsItemTitle=rt;exports.EmbeddedChatPrimitiveMessageAttachmentsList=at;exports.EmbeddedChatPrimitiveMessageAttachmentsPreview=ot;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewBody=ht;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewClose=lt;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewContent=ct;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewHeader=mt;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewOverlay=dt;exports.EmbeddedChatPrimitiveMessageAvatar=Ge;exports.EmbeddedChatPrimitiveMessageAvatarContent=Ye;exports.EmbeddedChatPrimitiveMessageAvatarFallback=Je;exports.EmbeddedChatPrimitiveMessageAvatarImage=Xe;exports.EmbeddedChatPrimitiveMessageContent=tt;exports.EmbeddedChatPrimitiveMessageContentWrapper=et;exports.EmbeddedChatPrimitiveMessageHeader=Ke;exports.EmbeddedChatPrimitiveMessageLoading=ze;exports.EmbeddedChatPrimitiveMessageName=Ze;exports.EmbeddedChatPrimitiveMessageSourceItem=_t;exports.EmbeddedChatPrimitiveMessageSourceItemBreadcrumbs=Et;exports.EmbeddedChatPrimitiveMessageSourceItemDescription=Mt;exports.EmbeddedChatPrimitiveMessageSourceItemDescriptionPart=St;exports.EmbeddedChatPrimitiveMessageSourceItemIcon=Ft;exports.EmbeddedChatPrimitiveMessageSourceItemIndicator=xt;exports.EmbeddedChatPrimitiveMessageSourceItemTag=It;exports.EmbeddedChatPrimitiveMessageSourceItemTitle=kt;exports.EmbeddedChatPrimitiveMessageSources=gt;exports.EmbeddedChatPrimitiveMessageSourcesHeader=Pt;exports.EmbeddedChatPrimitiveMessageSourcesList=At;exports.EmbeddedChatPrimitiveMessageToolAction=vt;exports.EmbeddedChatPrimitiveMessageToolActions=pt;exports.EmbeddedChatPrimitiveMessageToolbar=Ct;exports.EmbeddedChatPrimitiveMessageWrapper=ce;exports.EmbeddedChatPrimitiveMessages=fe;exports.EmbeddedChatPrimitiveRoot=Ae;exports.EmbeddedChatPrimitiveSendButton=yt;exports.EmbeddedChatPrimitiveSendButtonIcon=Ht;exports.EmbeddedChatPrimitiveTaglineBrandName=bi;exports.EmbeddedChatPrimitiveTaglineContainer=Ci;exports.EmbeddedChatPrimitiveTaglineLogo=vi;exports.EmbeddedChatPrimitiveTaglineText=pi;exports.EmbeddedChatPrimitiveToolbarHeader=Fe;exports.EmbeddedChatPrimitiveToolbarHeaderWrapper=Ee;exports.EmbeddedChatPrimitiveWorkflow=Ve;exports.EmbeddedChatPrimitiveWorkflows=Ne;exports.EmbeddedChatPrimitiveWorkflowsLabel=Qe;exports.EmbeddedChatPrimitiveWorkflowsList=$e;exports.EmbeddedChatPrimitiveWrapper=ge;exports.ExampleQuestion=Re;exports.ExampleQuestionButton=We;exports.ExampleQuestions=De;exports.ExampleQuestionsLabel=Oe;exports.ExampleQuestionsList=qe;exports.FeedbackForm=ji;exports.FeedbackItem=yi;exports.FeedbackItemCheckbox=Hi;exports.FeedbackItemCheckboxIndicator=wi;exports.FeedbackItemDescription=Di;exports.FeedbackItemLabel=Li;exports.FeedbackModal=Mi;exports.FeedbackModalBody=Ti;exports.FeedbackModalClose=fi;exports.FeedbackModalContent=xi;exports.FeedbackModalHeader=Bi;exports.FeedbackModalOverlay=Si;exports.FeedbackSubmitButton=Oi;exports.Footer=Bt;exports.Form=Ri;exports.FormCancel=la;exports.FormClose=Wi;exports.FormContent=Vi;exports.FormDescription=$i;exports.FormError=ca;exports.FormField=Ui;exports.FormFieldCheckbox=Ji;exports.FormFieldCheckboxIndicator=Xi;exports.FormFieldEmail=zi;exports.FormFieldError=da;exports.FormFieldFile=Gi;exports.FormFieldLabel=Ki;exports.FormFieldSelect=Zi;exports.FormFieldSelectContent=aa;exports.FormFieldSelectIcon=ia;exports.FormFieldSelectItem=sa;exports.FormFieldSelectItemIndicator=oa;exports.FormFieldSelectItemText=ra;exports.FormFieldSelectTrigger=ea;exports.FormFieldSelectValue=ta;exports.FormFieldSelectViewport=na;exports.FormFieldText=Y;exports.FormFieldTextArea=Yi;exports.FormFooter=ma;exports.FormHeader=Ni;exports.FormHeading=Qi;exports.FormSubmit=ha;exports.FormSuccess=ua;exports.FormSuccessButton=va;exports.FormSuccessHeading=Ca;exports.FormSuccessMessage=pa;exports.FormWrapper=qi;exports.Header=Na;exports.HeaderToolbar=_e;exports.HeaderToolbarWrapper=Ee;exports.HelpActions=Pi;exports.HelpActionsMenu=Ei;exports.HelpActionsMenuArrow=Fi;exports.HelpActionsMenuItem=ki;exports.HelpActionsMenuItemIcon=Ii;exports.HelpActionsTrigger=_i;exports.Input=jt;exports.InputFieldset=ft;exports.InputGroup=Tt;exports.IntroMessageWrapper=Ue;exports.Message=ut;exports.MessageAction=bt;exports.MessageAttachments=it;exports.MessageAttachmentsItem=nt;exports.MessageAttachmentsItemIcon=st;exports.MessageAttachmentsItemTitle=rt;exports.MessageAttachmentsList=at;exports.MessageAttachmentsPreview=ot;exports.MessageAttachmentsPreviewBody=ht;exports.MessageAttachmentsPreviewClose=lt;exports.MessageAttachmentsPreviewContent=ct;exports.MessageAttachmentsPreviewHeader=mt;exports.MessageAttachmentsPreviewOverlay=dt;exports.MessageAvatar=Ge;exports.MessageAvatarContent=Ye;exports.MessageAvatarFallback=Je;exports.MessageAvatarImage=Xe;exports.MessageContent=tt;exports.MessageContentWrapper=et;exports.MessageHeader=Ke;exports.MessageLoading=ze;exports.MessageName=Ze;exports.MessageSourceItem=_t;exports.MessageSourceItemBreadcrumbIcon=Hn;exports.MessageSourceItemBreadcrumbs=Et;exports.MessageSourceItemDescription=Mt;exports.MessageSourceItemDescriptionPart=St;exports.MessageSourceItemIcon=Ft;exports.MessageSourceItemIndicator=xt;exports.MessageSourceItemTag=It;exports.MessageSourceItemTitle=kt;exports.MessageSources=gt;exports.MessageSourcesHeader=Pt;exports.MessageSourcesList=At;exports.MessageToolAction=vt;exports.MessageToolActions=pt;exports.MessageToolbar=Ct;exports.MessageWrapper=ce;exports.Messages=fe;exports.Root=Ae;exports.SendButton=yt;exports.SendButtonIcon=Ht;exports.TaglineBrandName=bi;exports.TaglineContainer=Ci;exports.TaglineLogo=vi;exports.TaglineText=pi;exports.ToolbarHeader=Fe;exports.Workflow=Ve;exports.Workflows=Ne;exports.WorkflowsLabel=Qe;exports.WorkflowsList=$e;exports.Wrapper=ge;
17
+ `);J($)},share:async()=>{const $={visibility:"public",tags:[],userProperties:{},messages:C.messages.map(S=>({...S,createdAt:void 0,updatedAt:void 0,id:Date.now().toString()+S.id,conversationId:void 0}))},{apiKey:H,analyticsApiBaseUrl:D}=k,M=await Ha.logConversation("",$,H,D);if(M){const V=`${b.shareChatUrlBasePath}?${L.SHARE_QUERY_PARAM}=${M?.id}`;X(V),y({eventName:"chat_share_button_clicked",properties:{sharedConversationId:M?.id,originalConversationId:C.id,sharedChatUrl:V,conversation:M}})}},clear:o,stop:d},Ce={copy:N,share:Q};return n.jsx(j.Tooltip,{delayDuration:0,open:Ce[e],children:n.jsx(ds,{"data-type":e,"data-copied":h.dataAttr(N||Q),className:`${s} ${e}`,children:n.jsx(le,{action:e}),onClick:u.composeEventHandlers(i,ee[e]),...r})})},cs=a.ikp("span",{_id:"aiChat__ChatActionLabel"}),le=t=>{const{action:e,...i}=t,{aiChatSettings:s}=p.useInkeepConfig(),r=s.toolbarButtonLabels??{},o={help:r.getHelp??"Get Help",copy:r.copyChat??"Copy",share:r.share??"Share",clear:r.clear??"Clear",stop:r.stop??"Stop"};return n.jsx(cs,{children:o[e],...i})},ms=a.ikp(j.TooltipContent,{_id:"aiChat__ChatActionFeeback"}),gi=t=>{const{action:e,children:i,...s}=t,r={copy:"Copied!",share:"Link copied!"};return n.jsxs(ms,{sideOffset:5,...s,children:[n.jsx(j.Arrow,{}),i||r[e]]})},ls=a.ikp(T.Root,{_id:"aiChatHelpActions"}),Pi=t=>{const{children:e,...i}=t,{aiChatSettings:s}=p.useInkeepConfig(),{getHelpOptions:r}=s;if(!r||(r??[]).length===0)return null;const{_pinned:o,_unpinned:d}=r.reduce((C,b)=>{const k=b.isPinnedToToolbar?"_pinned":"_unpinned";return{...C,[k]:[...C[k],b]}},{_pinned:[],_unpinned:[]}),c=d.length===1?[...o,d[0]]:o,m=d.length===1?[]:d,l=ie.useHelpMenuState();return n.jsx(ie.HelpMenuProvider,{value:l,children:n.jsx(ls,{open:l.open,onOpenChange:l.setOpen,children:h.maybeRender(e,{pinned:c,unpinned:m}),...i})})},hs=a.ikp(G,{_id:"aiChatHelpAction",action:"help"}),us=a.ikp("a",{_id:"aiChatHelpAction",target:"_blank",rel:"noreferrer"}),_i=t=>{const{action:e,onClick:i,...s}=t,{handleAction:r,logHelpAction:o}=se.useChatAction(e),d=e.action.type,c={"aria-label":e.name,"data-name":e.name,children:e.name,onClick:u.composeEventHandlers(i,()=>{r(),o()}),...s};return d==="open_link"?n.jsx(us,{href:e.action.url,...c}):n.jsx(hs,{...c})},Cs=a.ikp(T.Trigger,{_id:"aiChatHelpActions__Trigger"}),Ai=g.memo(t=>{const{aiChatSettings:e}=p.useInkeepConfig();return n.jsx(G,{action:"help",...t,asChild:!0,children:n.jsx(Cs,{children:e.toolbarButtonLabels?.getHelp??"Get Help"})})}),ps=a.ikp(T.Content,{_id:"aiChatHelpActions__Menu"}),Ei=t=>n.jsx(ps,{side:"top",sideOffset:8,align:"center",alignOffset:-10,...t}),Fi=a.ikp(T.Arrow,{_id:"aiChatHelpActions__MenuArrow"}),ki=t=>{const{action:e,onClick:i,...s}=t,{handleAction:r,logHelpAction:o}=se.useChatAction(e),{setOpen:d}=ie.useHelpMenu(),c=()=>{r({onOpenForm:()=>d(!1)}),o()},m=e.action.type,l=a.ikp(m==="open_link"?"a":"button",{_id:"aiChatHelpActions__MenuItem",children:e.name,"aria-label":e.name,"data-name":e.name,"data-type":e.action.type,...m==="open_link"&&{href:e.action.url,target:"_blank",rel:"noopener"},onClick:u.composeEventHandlers(i,c)});return n.jsx(l,{...s})},vs=a.ikp(x.BuiltInIconRenderer,{_id:"aiChatHelpActions_MenuItemIcon"}),Ii=t=>{const{action:e,...i}=t;return e.icon?n.jsx(vs,{iconSettings:e.icon,...i}):null},bs=a.ikp(_.Root,{_id:"aiChatFeedbackModal"}),Mi=t=>{const{onOpenChange:e,...i}=t,{currentFeedback:s,setCurrentFeedback:r}=ne.useMessageFeedback();return n.jsx(bs,{open:s!==null,onOpenChange:u.composeEventHandlers(e,()=>r(null)),...i})},Si=a.ikp(_.Overlay,{_id:"aiChatFeedbackModal__Overlay"}),xi=a.ikp(_.Content,{_id:"aiChatFeedbackModal__Content","aria-describedby":void 0}),fi=a.ikp(_.Title,{_id:"aiChatFeedbackModal__Header",children:"Help improve my answers!"}),Bi=a.ikp(_.Close,{_id:"aiChatFeedbackModal__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Ti=a.ikp("div",{_id:"aiChatFeedbackModal__Body"}),gs=a.ikp("form",{_id:"aiChatFeedbackForm"}),ji=t=>{const{onSubmit:e,...i}=t,{submitNegativeFeedback:s,currentFeedback:r,setCurrentFeedback:o}=ne.useMessageFeedback(),d=c=>{c.preventDefault();const m=c.target,l=new FormData(m),C=Object.fromEntries(l.entries());r&&(s(r,C),o(null))};return n.jsx(gs,{onSubmit:u.composeEventHandlers(e,d),...i})},Ps=a.ikp("div",{_id:"aiChatFeedbackItem"}),yi=t=>{const{name:e,...i}=t;return n.jsx(K.FeedbackItemProvider,{name:e,children:n.jsx(Ps,{...i})})},_s=a.ikp(z.Root,{_id:"aiChatFeedbackItem__Checkbox"}),Hi=t=>{const{name:e,focusItem:i}=K.useFeedbackItem(),{onCheckedChange:s,...r}=t,o=d=>{d&&i?.current?.focus()};return n.jsx(_s,{id:`feedback-${e}`,name:e,onCheckedChange:u.composeEventHandlers(s,o),...r})},wi=a.ikp(z.Indicator,{_id:"aiChatFeedbackItem__CheckboxIndicator",children:n.jsx(be.CheckboxIcon,{})}),As=a.ikp("label",{_id:"aiChatFeedbackItem__Label"}),Li=t=>{const{name:e}=K.useFeedbackItem(),i={unrelated_response:"Didn't answer my question",inaccurate_statement:"Inaccurate statement",inaccurate_code_snippet:"Inaccurate code snippet",irrelevant_citations:"Irrelevant citations"};return n.jsx(As,{htmlFor:`feedback-${e}`,children:i[e],...t})},Es=a.ikp("textarea",{_id:"aiChatFeedbackItem__Description",placeholder:"Please describe"}),Di=t=>{const{name:e,focusItem:i}=K.useFeedbackItem();return n.jsx(Es,{ref:i,name:`${e}:description`,...t})},Oi=a.ikp("button",{_id:"aiChatFeedbackForm__SubmitButton",children:"Submit",type:"submit"}),Fs=a.ikp("div",{_id:"aiChatForm__Wrapper"}),qi=t=>{const{form:e}=A.useChatForm();return e?n.jsx(Fs,{...t}):null},ks=a.ikp("form",{_id:"aiChatForm"}),Ri=t=>{const{onSubmit:e,...i}=t,{handleSubmit:s,isSuccess:r}=A.useChatForm();return r?null:n.jsx(ks,{onSubmit:u.composeEventHandlers(e,s),...i})},Is=a.ikp("button",{_id:"aiChatForm__Close",children:n.jsx(E.CustomIcon,{iconKey:"close"})}),Wi=t=>{const{onClick:e,...i}=t,{closeForm:s}=A.useChatForm();return n.jsx(Is,{onClick:u.composeEventHandlers(e,s),...i})},Ni=a.ikp("div",{_id:"aiChatForm__Header"}),Ms=a.ikp("h2",{_id:"aiChatForm__Heading"}),Qi=t=>{const{form:e}=A.useChatForm();return e?.heading?n.jsx(Ms,{children:e.heading,...t}):null},Ss=a.ikp(U.Markdown,{_id:"aiChatForm__Description"}),$i=t=>{const{form:e}=A.useChatForm();return e?.description?n.jsx(Ss,{children:e.description,...t}):null},xs=a.ikp("div",{_id:"aiChatForm__Content"}),Vi=t=>{const{children:e,...i}=t,{fields:s=[]}=A.useChatForm();return n.jsx(xs,{children:h.maybeRender(e,s),...i})},fs=a.ikp("div",{_id:"aiChatForm__Field"}),Ui=t=>{const{field:e,autoFocus:i,...s}=t,{control:r,errors:o}=A.useChatForm();return n.jsx(fa.Controller,{name:e.name,control:r,rules:{required:e.isRequired?`${e.label} is required.`:void 0},render:({field:d})=>{const c=d.value!==void 0||e.inputType==="file";return n.jsx(B.FormFieldProvider,{"data-invalid":h.dataAttr(!!o[e.name]),field:e,fieldProps:d,autoFocus:i,children:c&&n.jsx(fs,{"data-input-type":e.inputType,"data-hidden":h.dataAttr(e.isHidden),...s})})}})},Bs=a.ikp("label",{_id:"aiChatForm__FieldLabel"}),Ki=t=>{const{field:e}=B.useFormField();return n.jsx(Bs,{"data-required":h.dataAttr(e.isRequired),htmlFor:e.name,children:e.label,...t})},Ts=a.ikp("input",{_id:"aiChatForm__FieldText",type:"text"}),Y=t=>{const{field:e,error:i,fieldProps:{onChange:s,onBlur:r,...o},autoFocus:d}=B.useFormField(),{onChange:c,onBlur:m,...l}=t;return n.jsx(Ts,{id:e.name,autoFocus:d,placeholder:"placeholder"in e?e.placeholder:void 0,"data-invalid":h.dataAttr(!!i),onChange:u.composeEventHandlers(c,s),onBlur:u.composeEventHandlers(m,r),...o,...l})},zi=a.ikp(Y,{_id:"aiChatForm__FieldEmail",type:"email"}),js=a.ikp("input",{_id:"aiChatForm__FieldFile",type:"file",multiple:!0}),Gi=t=>{const{field:e,error:i,fieldProps:{value:s,onChange:r,onBlur:o,...d},autoFocus:c}=B.useFormField(),{onChange:m,onBlur:l,...C}=t,b=k=>{const y=k.target.files;r(y)};return n.jsx(js,{id:e.name,autoFocus:c,"data-value":s,"data-invalid":h.dataAttr(!!i),...C,...d,onChange:u.composeEventHandlers(m,b),onBlur:u.composeEventHandlers(l,o)})},Yi=a.ikp(Y,{_id:"aiChatForm__FieldTextArea",type:"textarea",asChild:!0,children:n.jsx(ae,{maxRows:8})}),ys=a.ikp(z.Root,{_id:"aiChatForm__FieldCheckbox"}),Ji=t=>{const{field:e,error:i,fieldProps:s,autoFocus:r}=B.useFormField(),{onCheckedChange:o,...d}=t;return n.jsx(ys,{id:e.name,name:e.name,autoFocus:r,"data-invalid":h.dataAttr(!!i),checked:s.value,onCheckedChange:u.composeEventHandlers(o,s.onChange),...d})},Xi=a.ikp(z.Indicator,{_id:"aiChatForm__FieldCheckboxIndicator",children:n.jsx(be.CheckboxIcon,{})}),Hs=a.ikp(I.Root,{_id:"aiChatForm__FieldSelect"}),Zi=t=>{const{field:e,error:i,fieldProps:s}=B.useFormField(),{onValueChange:r,...o}=t;return n.jsx(Hs,{name:e.name,"data-invalid":h.dataAttr(!!i),value:s.value,onValueChange:u.composeEventHandlers(r,s.onChange),...o})},ea=a.ikp(I.Trigger,{_id:"aiChatForm__FieldSelect__Trigger"}),ws=a.ikp(I.Value,{_id:"aiChatForm__FieldSelect__Value"}),ta=t=>{const{field:e}=B.useFormField();return n.jsx(ws,{placeholder:"placeholder"in e?e.placeholder:void 0,...t})},ia=a.ikp(I.Icon,{_id:"aiChatForm__FieldSelect__Icon",asChild:!0,children:n.jsx(x.BuiltInIconRenderer,{iconSettings:{builtIn:"LuChevronDown"}})}),aa=a.ikp(I.Content,{_id:"aiChatForm__FieldSelect__Content",position:"popper"}),na=a.ikp(I.Viewport,{_id:"aiChatForm__FieldSelect__Viewport"}),sa=a.ikp(I.Item,{_id:"aiChatForm__FieldSelect__Item"}),ra=a.ikp(I.ItemText,{_id:"aiChatForm__FieldSelect__ItemText"}),oa=a.ikp(I.ItemIndicator,{_id:"aiChatForm__FieldSelect__ItemIndicator",asChild:!0,children:n.jsx(x.BuiltInIconRenderer,{iconSettings:{builtIn:"LuCheck"}})}),Ls=a.ikp("span",{_id:"aiChatForm__FieldError"}),da=t=>{const{error:e}=B.useFormField();return e?n.jsx(Ls,{children:e.message?.toString(),...t}):null},Ds=a.ikp("span",{_id:"aiChatForm__Error"}),ca=t=>{const{formError:e}=A.useChatForm();return e?n.jsx(Ds,{children:e.message,...t}):null},ma=a.ikp("div",{_id:"aiChatForm__Footer"}),Os=a.ikp("button",{_id:"aiChatForm__Cancel",children:"Cancel",type:"button"}),la=t=>{const{onClick:e,...i}=t,{closeForm:s}=A.useChatForm();return n.jsx(Os,{onClick:u.composeEventHandlers(e,s),...i})},qs=a.ikp("button",{_id:"aiChatForm__Submit",children:"Submit",type:"submit"}),ha=t=>{const{onClick:e,...i}=t,{isSubmitting:s,form:r}=A.useChatForm(),o=r?.buttons.submit.label||"Submit";return n.jsx(qs,{disabled:s,...i,children:o})},Rs=a.ikp("div",{_id:"aiChatForm__Success"}),ua=t=>{const{isSuccess:e}=A.useChatForm();return e?n.jsx(Rs,{...t}):null},Ws=a.ikp("h2",{_id:"aiChatForm__SuccessHeading"}),Ca=t=>{const{form:e}=A.useChatForm();return n.jsx(Ws,{children:e?.successView?.heading,...t})},Ns=a.ikp(U.Markdown,{_id:"aiChatForm__SuccessMessage"}),pa=t=>{const{form:e}=A.useChatForm();return n.jsx(Ns,{children:e?.successView?.message,...t})},Qs=a.ikp("button",{_id:"aiChatForm__SuccessButton"}),va=t=>{const{onClick:e,...i}=t,{form:s,closeForm:r}=A.useChatForm(),o=s?.successView?.doneButton;if(!o)return null;const d=o.icon&&n.jsx(x.BuiltInIconRenderer,{iconSettings:o.icon}),c=o.label;return n.jsx(Qs,{onClick:u.composeEventHandlers(e,r),children:n.jsxs(n.Fragment,{children:[d,c]}),...i})};exports.Provider=v.ChatProvider;exports.ActionBar=hi;exports.Actions=ui;exports.AttachmentsBar=wt;exports.AttachmentsBarActions=Wt;exports.AttachmentsBarAttachment=Dt;exports.AttachmentsBarAttachmentDelete=Rt;exports.AttachmentsBarAttachmentIcon=Ot;exports.AttachmentsBarAttachmentTitle=qt;exports.AttachmentsBarForm=ii;exports.AttachmentsBarFormContent=oi;exports.AttachmentsBarFormContentError=mi;exports.AttachmentsBarFormContentInput=ci;exports.AttachmentsBarFormContentLabel=di;exports.AttachmentsBarFormSubmitButton=li;exports.AttachmentsBarFormTitle=ai;exports.AttachmentsBarFormTitleError=ri;exports.AttachmentsBarFormTitleInput=si;exports.AttachmentsBarFormTitleLabel=ni;exports.AttachmentsBarInfoTip=Nt;exports.AttachmentsBarInfoTipArrow=me;exports.AttachmentsBarInfoTipIcon=Qt;exports.AttachmentsBarInfoTipText=$t;exports.AttachmentsBarInput=Ut;exports.AttachmentsBarInputs=Vt;exports.AttachmentsBarList=Lt;exports.AttachmentsBarModal=Kt;exports.AttachmentsBarModalBody=ti;exports.AttachmentsBarModalClose=ei;exports.AttachmentsBarModalContent=Gt;exports.AttachmentsBarModalDescription=Xt;exports.AttachmentsBarModalHeader=Yt;exports.AttachmentsBarModalHeading=Jt;exports.AttachmentsBarModalHelp=Zt;exports.AttachmentsBarModalOverlay=zt;exports.ChatAction=G;exports.ChatActionFeedback=gi;exports.ChatActionLabel=le;exports.ChatHelpAction=_i;exports.Content=ke;exports.ContentScrollArea=Ie;exports.ContentScrollAreaCorner=fe;exports.ContentScrollAreaScrollbar=Se;exports.ContentScrollAreaThumb=xe;exports.ContentScrollAreaViewport=Me;exports.ConversationLoading=Pe;exports.Disclaimer=Te;exports.DisclaimerArrow=Le;exports.DisclaimerContent=He;exports.DisclaimerLabel=je;exports.DisclaimerText=we;exports.DisclaimerTrigger=ye;exports.EmbeddedChatPrimitiveActionBar=hi;exports.EmbeddedChatPrimitiveActions=ui;exports.EmbeddedChatPrimitiveAttachmentsBar=wt;exports.EmbeddedChatPrimitiveAttachmentsBarActions=Wt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachment=Dt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentDelete=Rt;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentIcon=Ot;exports.EmbeddedChatPrimitiveAttachmentsBarAttachmentTitle=qt;exports.EmbeddedChatPrimitiveAttachmentsBarForm=ii;exports.EmbeddedChatPrimitiveAttachmentsBarFormContent=oi;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentError=mi;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentInput=ci;exports.EmbeddedChatPrimitiveAttachmentsBarFormContentLabel=di;exports.EmbeddedChatPrimitiveAttachmentsBarFormSubmitButton=li;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitle=ai;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleError=ri;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleInput=si;exports.EmbeddedChatPrimitiveAttachmentsBarFormTitleLabel=ni;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTip=Nt;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipArrow=me;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipIcon=Qt;exports.EmbeddedChatPrimitiveAttachmentsBarInfoTipText=$t;exports.EmbeddedChatPrimitiveAttachmentsBarInput=Ut;exports.EmbeddedChatPrimitiveAttachmentsBarInputs=Vt;exports.EmbeddedChatPrimitiveAttachmentsBarList=Lt;exports.EmbeddedChatPrimitiveAttachmentsBarModal=Kt;exports.EmbeddedChatPrimitiveAttachmentsBarModalBody=ti;exports.EmbeddedChatPrimitiveAttachmentsBarModalClose=ei;exports.EmbeddedChatPrimitiveAttachmentsBarModalContent=Gt;exports.EmbeddedChatPrimitiveAttachmentsBarModalDescription=Xt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHeader=Yt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHeading=Jt;exports.EmbeddedChatPrimitiveAttachmentsBarModalHelp=Zt;exports.EmbeddedChatPrimitiveAttachmentsBarModalOverlay=zt;exports.EmbeddedChatPrimitiveChatAction=G;exports.EmbeddedChatPrimitiveChatActionFeedback=gi;exports.EmbeddedChatPrimitiveChatActionLabel=le;exports.EmbeddedChatPrimitiveChatHelpAction=_i;exports.EmbeddedChatPrimitiveContent=ke;exports.EmbeddedChatPrimitiveContentScrollArea=Ie;exports.EmbeddedChatPrimitiveContentScrollAreaCorner=fe;exports.EmbeddedChatPrimitiveContentScrollAreaScrollbar=Se;exports.EmbeddedChatPrimitiveContentScrollAreaThumb=xe;exports.EmbeddedChatPrimitiveContentScrollAreaViewport=Me;exports.EmbeddedChatPrimitiveConversationLoading=Pe;exports.EmbeddedChatPrimitiveDisclaimer=Te;exports.EmbeddedChatPrimitiveDisclaimerArrow=Le;exports.EmbeddedChatPrimitiveDisclaimerContent=He;exports.EmbeddedChatPrimitiveDisclaimerLabel=je;exports.EmbeddedChatPrimitiveDisclaimerText=we;exports.EmbeddedChatPrimitiveDisclaimerTrigger=ye;exports.EmbeddedChatPrimitiveExampleQuestion=Re;exports.EmbeddedChatPrimitiveExampleQuestionButton=We;exports.EmbeddedChatPrimitiveExampleQuestions=De;exports.EmbeddedChatPrimitiveExampleQuestionsLabel=Oe;exports.EmbeddedChatPrimitiveExampleQuestionsList=qe;exports.EmbeddedChatPrimitiveFeedbackForm=ji;exports.EmbeddedChatPrimitiveFeedbackItem=yi;exports.EmbeddedChatPrimitiveFeedbackItemCheckbox=Hi;exports.EmbeddedChatPrimitiveFeedbackItemCheckboxIndicator=wi;exports.EmbeddedChatPrimitiveFeedbackItemDescription=Di;exports.EmbeddedChatPrimitiveFeedbackItemLabel=Li;exports.EmbeddedChatPrimitiveFeedbackModal=Mi;exports.EmbeddedChatPrimitiveFeedbackModalBody=Ti;exports.EmbeddedChatPrimitiveFeedbackModalClose=Bi;exports.EmbeddedChatPrimitiveFeedbackModalContent=xi;exports.EmbeddedChatPrimitiveFeedbackModalHeader=fi;exports.EmbeddedChatPrimitiveFeedbackModalOverlay=Si;exports.EmbeddedChatPrimitiveFeedbackSubmitButton=Oi;exports.EmbeddedChatPrimitiveFooter=ft;exports.EmbeddedChatPrimitiveForm=Ri;exports.EmbeddedChatPrimitiveFormCancel=la;exports.EmbeddedChatPrimitiveFormClose=Wi;exports.EmbeddedChatPrimitiveFormContent=Vi;exports.EmbeddedChatPrimitiveFormDescription=$i;exports.EmbeddedChatPrimitiveFormError=ca;exports.EmbeddedChatPrimitiveFormField=Ui;exports.EmbeddedChatPrimitiveFormFieldCheckbox=Ji;exports.EmbeddedChatPrimitiveFormFieldCheckboxIndicator=Xi;exports.EmbeddedChatPrimitiveFormFieldEmail=zi;exports.EmbeddedChatPrimitiveFormFieldError=da;exports.EmbeddedChatPrimitiveFormFieldFile=Gi;exports.EmbeddedChatPrimitiveFormFieldLabel=Ki;exports.EmbeddedChatPrimitiveFormFieldSelect=Zi;exports.EmbeddedChatPrimitiveFormFieldSelectContent=aa;exports.EmbeddedChatPrimitiveFormFieldSelectIcon=ia;exports.EmbeddedChatPrimitiveFormFieldSelectItem=sa;exports.EmbeddedChatPrimitiveFormFieldSelectItemIndicator=oa;exports.EmbeddedChatPrimitiveFormFieldSelectItemText=ra;exports.EmbeddedChatPrimitiveFormFieldSelectTrigger=ea;exports.EmbeddedChatPrimitiveFormFieldSelectValue=ta;exports.EmbeddedChatPrimitiveFormFieldSelectViewport=na;exports.EmbeddedChatPrimitiveFormFieldText=Y;exports.EmbeddedChatPrimitiveFormFieldTextArea=Yi;exports.EmbeddedChatPrimitiveFormFooter=ma;exports.EmbeddedChatPrimitiveFormHeader=Ni;exports.EmbeddedChatPrimitiveFormHeading=Qi;exports.EmbeddedChatPrimitiveFormSubmit=ha;exports.EmbeddedChatPrimitiveFormSuccess=ua;exports.EmbeddedChatPrimitiveFormSuccessButton=va;exports.EmbeddedChatPrimitiveFormSuccessHeading=Ca;exports.EmbeddedChatPrimitiveFormSuccessMessage=pa;exports.EmbeddedChatPrimitiveFormWrapper=qi;exports.EmbeddedChatPrimitiveHeaderToolbar=Ae;exports.EmbeddedChatPrimitiveHelpActions=Pi;exports.EmbeddedChatPrimitiveHelpActionsMenu=Ei;exports.EmbeddedChatPrimitiveHelpActionsMenuArrow=Fi;exports.EmbeddedChatPrimitiveHelpActionsMenuItem=ki;exports.EmbeddedChatPrimitiveHelpActionsMenuItemIcon=Ii;exports.EmbeddedChatPrimitiveHelpActionsTrigger=Ai;exports.EmbeddedChatPrimitiveInput=jt;exports.EmbeddedChatPrimitiveInputFieldset=Bt;exports.EmbeddedChatPrimitiveInputGroup=Tt;exports.EmbeddedChatPrimitiveIntroMessageWrapper=Ue;exports.EmbeddedChatPrimitiveMessage=ut;exports.EmbeddedChatPrimitiveMessageAction=bt;exports.EmbeddedChatPrimitiveMessageAttachments=it;exports.EmbeddedChatPrimitiveMessageAttachmentsItem=nt;exports.EmbeddedChatPrimitiveMessageAttachmentsItemIcon=st;exports.EmbeddedChatPrimitiveMessageAttachmentsItemTitle=rt;exports.EmbeddedChatPrimitiveMessageAttachmentsList=at;exports.EmbeddedChatPrimitiveMessageAttachmentsPreview=ot;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewBody=ht;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewClose=lt;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewContent=ct;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewHeader=mt;exports.EmbeddedChatPrimitiveMessageAttachmentsPreviewOverlay=dt;exports.EmbeddedChatPrimitiveMessageAvatar=Ge;exports.EmbeddedChatPrimitiveMessageAvatarContent=Ye;exports.EmbeddedChatPrimitiveMessageAvatarFallback=Je;exports.EmbeddedChatPrimitiveMessageAvatarImage=Xe;exports.EmbeddedChatPrimitiveMessageContent=tt;exports.EmbeddedChatPrimitiveMessageContentWrapper=et;exports.EmbeddedChatPrimitiveMessageHeader=Ke;exports.EmbeddedChatPrimitiveMessageLoading=ze;exports.EmbeddedChatPrimitiveMessageName=Ze;exports.EmbeddedChatPrimitiveMessageSourceItem=At;exports.EmbeddedChatPrimitiveMessageSourceItemBreadcrumbs=Et;exports.EmbeddedChatPrimitiveMessageSourceItemDescription=Mt;exports.EmbeddedChatPrimitiveMessageSourceItemDescriptionPart=St;exports.EmbeddedChatPrimitiveMessageSourceItemIcon=Ft;exports.EmbeddedChatPrimitiveMessageSourceItemIndicator=xt;exports.EmbeddedChatPrimitiveMessageSourceItemTag=It;exports.EmbeddedChatPrimitiveMessageSourceItemTitle=kt;exports.EmbeddedChatPrimitiveMessageSources=gt;exports.EmbeddedChatPrimitiveMessageSourcesHeader=Pt;exports.EmbeddedChatPrimitiveMessageSourcesList=_t;exports.EmbeddedChatPrimitiveMessageToolAction=vt;exports.EmbeddedChatPrimitiveMessageToolActions=pt;exports.EmbeddedChatPrimitiveMessageToolbar=Ct;exports.EmbeddedChatPrimitiveMessageWrapper=ce;exports.EmbeddedChatPrimitiveMessages=Be;exports.EmbeddedChatPrimitiveRoot=_e;exports.EmbeddedChatPrimitiveSendButton=yt;exports.EmbeddedChatPrimitiveSendButtonIcon=Ht;exports.EmbeddedChatPrimitiveTaglineBrandName=bi;exports.EmbeddedChatPrimitiveTaglineContainer=Ci;exports.EmbeddedChatPrimitiveTaglineLogo=vi;exports.EmbeddedChatPrimitiveTaglineText=pi;exports.EmbeddedChatPrimitiveToolbarHeader=Fe;exports.EmbeddedChatPrimitiveToolbarHeaderWrapper=Ee;exports.EmbeddedChatPrimitiveWorkflow=Ve;exports.EmbeddedChatPrimitiveWorkflows=Ne;exports.EmbeddedChatPrimitiveWorkflowsLabel=Qe;exports.EmbeddedChatPrimitiveWorkflowsList=$e;exports.EmbeddedChatPrimitiveWrapper=ge;exports.ExampleQuestion=Re;exports.ExampleQuestionButton=We;exports.ExampleQuestions=De;exports.ExampleQuestionsLabel=Oe;exports.ExampleQuestionsList=qe;exports.FeedbackForm=ji;exports.FeedbackItem=yi;exports.FeedbackItemCheckbox=Hi;exports.FeedbackItemCheckboxIndicator=wi;exports.FeedbackItemDescription=Di;exports.FeedbackItemLabel=Li;exports.FeedbackModal=Mi;exports.FeedbackModalBody=Ti;exports.FeedbackModalClose=Bi;exports.FeedbackModalContent=xi;exports.FeedbackModalHeader=fi;exports.FeedbackModalOverlay=Si;exports.FeedbackSubmitButton=Oi;exports.Footer=ft;exports.Form=Ri;exports.FormCancel=la;exports.FormClose=Wi;exports.FormContent=Vi;exports.FormDescription=$i;exports.FormError=ca;exports.FormField=Ui;exports.FormFieldCheckbox=Ji;exports.FormFieldCheckboxIndicator=Xi;exports.FormFieldEmail=zi;exports.FormFieldError=da;exports.FormFieldFile=Gi;exports.FormFieldLabel=Ki;exports.FormFieldSelect=Zi;exports.FormFieldSelectContent=aa;exports.FormFieldSelectIcon=ia;exports.FormFieldSelectItem=sa;exports.FormFieldSelectItemIndicator=oa;exports.FormFieldSelectItemText=ra;exports.FormFieldSelectTrigger=ea;exports.FormFieldSelectValue=ta;exports.FormFieldSelectViewport=na;exports.FormFieldText=Y;exports.FormFieldTextArea=Yi;exports.FormFooter=ma;exports.FormHeader=Ni;exports.FormHeading=Qi;exports.FormSubmit=ha;exports.FormSuccess=ua;exports.FormSuccessButton=va;exports.FormSuccessHeading=Ca;exports.FormSuccessMessage=pa;exports.FormWrapper=qi;exports.Header=Na;exports.HeaderToolbar=Ae;exports.HeaderToolbarWrapper=Ee;exports.HelpActions=Pi;exports.HelpActionsMenu=Ei;exports.HelpActionsMenuArrow=Fi;exports.HelpActionsMenuItem=ki;exports.HelpActionsMenuItemIcon=Ii;exports.HelpActionsTrigger=Ai;exports.Input=jt;exports.InputFieldset=Bt;exports.InputGroup=Tt;exports.IntroMessageWrapper=Ue;exports.Message=ut;exports.MessageAction=bt;exports.MessageAttachments=it;exports.MessageAttachmentsItem=nt;exports.MessageAttachmentsItemIcon=st;exports.MessageAttachmentsItemTitle=rt;exports.MessageAttachmentsList=at;exports.MessageAttachmentsPreview=ot;exports.MessageAttachmentsPreviewBody=ht;exports.MessageAttachmentsPreviewClose=lt;exports.MessageAttachmentsPreviewContent=ct;exports.MessageAttachmentsPreviewHeader=mt;exports.MessageAttachmentsPreviewOverlay=dt;exports.MessageAvatar=Ge;exports.MessageAvatarContent=Ye;exports.MessageAvatarFallback=Je;exports.MessageAvatarImage=Xe;exports.MessageContent=tt;exports.MessageContentWrapper=et;exports.MessageHeader=Ke;exports.MessageLoading=ze;exports.MessageName=Ze;exports.MessageSourceItem=At;exports.MessageSourceItemBreadcrumbIcon=Hn;exports.MessageSourceItemBreadcrumbs=Et;exports.MessageSourceItemDescription=Mt;exports.MessageSourceItemDescriptionPart=St;exports.MessageSourceItemIcon=Ft;exports.MessageSourceItemIndicator=xt;exports.MessageSourceItemTag=It;exports.MessageSourceItemTitle=kt;exports.MessageSources=gt;exports.MessageSourcesHeader=Pt;exports.MessageSourcesList=_t;exports.MessageToolAction=vt;exports.MessageToolActions=pt;exports.MessageToolbar=Ct;exports.MessageWrapper=ce;exports.Messages=Be;exports.Root=_e;exports.SendButton=yt;exports.SendButtonIcon=Ht;exports.TaglineBrandName=bi;exports.TaglineContainer=Ci;exports.TaglineLogo=vi;exports.TaglineText=pi;exports.ToolbarHeader=Fe;exports.Workflow=Ve;exports.Workflows=Ne;exports.WorkflowsLabel=Qe;exports.WorkflowsList=$e;exports.Wrapper=ge;
@@ -507,6 +507,11 @@ const ct = "__intro__", dt = i("div", {
507
507
  }), os = (t) => {
508
508
  const { onClick: e, action: a, ...s } = t, { handleAction: o } = me(a), { logEvent: r } = W(), { conversation: c } = O(), d = () => {
509
509
  o(), r({
510
+ eventName: "tool_call_action_clicked",
511
+ properties: {
512
+ conversation: c
513
+ }
514
+ }), a.action.type !== "open_form" && r({
510
515
  eventName: "user_escalation_indicated",
511
516
  properties: {
512
517
  escalationType: "contact_us",
package/dist/index.d.cts CHANGED
@@ -29,6 +29,7 @@ import { FormHTMLAttributes } from 'react';
29
29
  import { ForwardRefExoticComponent } from 'react';
30
30
  import { GetHelpOption } from '@inkeep/cxkit-types';
31
31
  import { HTMLAttributes } from 'react';
32
+ import { IkpChatAction } from '@inkeep/cxkit-types';
32
33
  import { ImgHTMLAttributes } from 'react';
33
34
  import { InkeepAIChatSettings } from '@inkeep/cxkit-types';
34
35
  import { InkeepBaseSettings } from '@inkeep/cxkit-types';
@@ -403,6 +404,10 @@ export declare type ChatEventsContextValue = {
403
404
  * Log a conversation.
404
405
  */
405
406
  logConversation: (messages: Message[]) => Promise<ConversationResponse | undefined>;
407
+ /**
408
+ * Get the latest conversation state (useful for accessing the conversation after it's been logged).
409
+ */
410
+ getLatestConversation: () => ConversationResponse;
406
411
  };
407
412
 
408
413
  export declare const ChatEventsProvider: React.FC<{
@@ -4311,7 +4316,7 @@ export declare const useChatForm: () => ChatFormContextValue;
4311
4316
 
4312
4317
  export declare function useChatFormState(): {
4313
4318
  form: AIChatFormSettings | null;
4314
- openForm: (formSettings: AIChatFormSettings, getHelpOption?: GetHelpOption) => void;
4319
+ openForm: (formSettings: AIChatFormSettings, triggeringAction?: IkpChatAction) => void;
4315
4320
  closeForm: () => void;
4316
4321
  handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
4317
4322
  isSuccess: boolean;
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ import { FormHTMLAttributes } from 'react';
29
29
  import { ForwardRefExoticComponent } from 'react';
30
30
  import { GetHelpOption } from '@inkeep/cxkit-types';
31
31
  import { HTMLAttributes } from 'react';
32
+ import { IkpChatAction } from '@inkeep/cxkit-types';
32
33
  import { ImgHTMLAttributes } from 'react';
33
34
  import { InkeepAIChatSettings } from '@inkeep/cxkit-types';
34
35
  import { InkeepBaseSettings } from '@inkeep/cxkit-types';
@@ -403,6 +404,10 @@ export declare type ChatEventsContextValue = {
403
404
  * Log a conversation.
404
405
  */
405
406
  logConversation: (messages: Message[]) => Promise<ConversationResponse | undefined>;
407
+ /**
408
+ * Get the latest conversation state (useful for accessing the conversation after it's been logged).
409
+ */
410
+ getLatestConversation: () => ConversationResponse;
406
411
  };
407
412
 
408
413
  export declare const ChatEventsProvider: React.FC<{
@@ -4311,7 +4316,7 @@ export declare const useChatForm: () => ChatFormContextValue;
4311
4316
 
4312
4317
  export declare function useChatFormState(): {
4313
4318
  form: AIChatFormSettings | null;
4314
- openForm: (formSettings: AIChatFormSettings, getHelpOption?: GetHelpOption) => void;
4319
+ openForm: (formSettings: AIChatFormSettings, triggeringAction?: IkpChatAction) => void;
4315
4320
  closeForm: () => void;
4316
4321
  handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
4317
4322
  isSuccess: boolean;
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.108",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.109",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
@@ -7,7 +7,7 @@ import { useUser as A } from "./user-provider.js";
7
7
  const u = B(void 0), $ = ({ children: e }) => {
8
8
  const { baseSettings: t, componentType: s } = w(), { apiKey: r, analyticsApiBaseUrl: i, tags: a, privacyPreferences: d, env: E, analyticsProperties: c } = t, { userProperties: v } = A(), p = P(
9
9
  () => ({
10
- widgetLibraryVersion: "0.5.108",
10
+ widgetLibraryVersion: "0.5.109",
11
11
  componentType: s,
12
12
  tags: a
13
13
  }),
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("react/jsx-runtime"),t=require("react"),A=require("../atoms/api/analytics/conversation.cjs"),L=require("./config-provider.cjs"),O=require("./conversation-provider.cjs"),m=require("./user-provider.cjs"),B=require("./base-events-provider.cjs"),M=require("../utils/generate-uid.cjs"),x=t.createContext(void 0),K=({children:a})=>{const{baseSettings:w,aiChatSettings:I}=L.useInkeepConfig(),{apiKey:E,analyticsApiBaseUrl:g,tags:f,privacyPreferences:{optOutAllAnalytics:c},env:v,analyticsProperties:u}=w,{conversationVisibility:P}=I,{userProperties:y}=m.useUser(),{logEvent:b}=B.useBaseEvents(),{conversation:d,setConversation:S,chatId:l,isSharedChat:C,setExternalChatId:q}=O.useInkeepConversation(),o=t.useRef(d),h=t.useRef(C?l:void 0);t.useEffect(()=>{o.current=d},[d]),t.useEffect(()=>{h.current=C?l:void 0},[l,C]);const p=t.useCallback(async r=>{const e=o.current;h.current&&(e.id="",q(void 0),h.current=void 0);const n=!c&&v!=="development";let s=Object.assign({},e,{messages:r});if(n){const i=await A.logConversation(e.id,{messages:r,tags:f,userProperties:y,properties:u,visibility:P},E,g);i&&(s=i)}else s.id="conv_"+M.generateUid(16);return s},[g,E,f,y,c,v,u,q,P]),j={logEvent:t.useCallback(async(r,e)=>{let n=o.current;if(e){const i=o.current.messages||[];(e.length!==i.length||e.some((k,R)=>k.id!==i[R]?.id))&&(n=await p(e),S(n),o.current=n)}const s={...r,properties:{conversation:n,...r.properties}};b(s)},[b,p,c,v,u]),logConversation:p};return U.jsx(x.Provider,{value:j,children:a})},T=()=>{const a=t.useContext(x);if(!a)throw new Error("useChatEvents must be used within a ChatEventsProvider");return a};exports.ChatEventsProvider=K;exports.useChatEvents=T;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react/jsx-runtime"),e=require("react"),O=require("../atoms/api/analytics/conversation.cjs"),m=require("./config-provider.cjs"),B=require("./conversation-provider.cjs"),M=require("./user-provider.cjs"),K=require("./base-events-provider.cjs"),T=require("../utils/generate-uid.cjs"),x=e.createContext(void 0),V=({children:c})=>{const{baseSettings:k,aiChatSettings:w}=m.useInkeepConfig(),{apiKey:p,analyticsApiBaseUrl:E,tags:f,privacyPreferences:{optOutAllAnalytics:a},env:u,analyticsProperties:v}=k,{conversationVisibility:P}=w,{userProperties:b}=M.useUser(),{logEvent:y}=K.useBaseEvents(),{conversation:l,setConversation:I,chatId:d,isSharedChat:C,setExternalChatId:q}=B.useInkeepConversation(),n=e.useRef(l),h=e.useRef(C?d:void 0);e.useEffect(()=>{n.current=l},[l]),e.useEffect(()=>{h.current=C?d:void 0},[d,C]);const g=e.useCallback(async o=>{const t=n.current;h.current&&(t.id="",q(void 0),h.current=void 0);const s=!a&&u!=="development";let r=Object.assign({},t,{messages:o});if(s){const i=await O.logConversation(t.id,{messages:o,tags:f,userProperties:b,properties:v,visibility:P},p,E);i&&(r=i)}else r.id="conv_"+T.generateUid(16);return r},[E,p,f,b,a,u,v,q,P]),S=e.useCallback(async(o,t)=>{let s=n.current;if(t){const i=n.current.messages||[];(t.length!==i.length||t.some((R,U)=>R.id!==i[U]?.id))&&(s=await g(t),I(s),n.current=s)}const r={...o,properties:{conversation:s,...o.properties}};y(r)},[y,g,a,u,v]),j=e.useCallback(()=>n.current,[]),L={logEvent:S,logConversation:g,getLatestConversation:j};return A.jsx(x.Provider,{value:L,children:c})},_=()=>{const c=e.useContext(x);if(!c)throw new Error("useChatEvents must be used within a ChatEventsProvider");return c};exports.ChatEventsProvider=V;exports.useChatEvents=_;
@@ -1,90 +1,91 @@
1
1
  "use client";
2
- import { jsx as B } from "react/jsx-runtime";
3
- import { useRef as b, useEffect as P, useCallback as w, createContext as O, useContext as K } from "react";
4
- import { logConversation as M } from "../atoms/api/analytics/conversation.js";
5
- import { useInkeepConfig as R } from "./config-provider.js";
6
- import { useInkeepConversation as V } from "./conversation-provider.js";
7
- import { useUser as _ } from "./user-provider.js";
8
- import { useBaseEvents as $ } from "./base-events-provider.js";
9
- import { generateUid as q } from "../utils/generate-uid.js";
10
- const I = O(void 0), X = ({ children: i }) => {
11
- const { baseSettings: k, aiChatSettings: A } = R(), {
2
+ import { jsx as K } from "react/jsx-runtime";
3
+ import { useRef as P, useEffect as w, useCallback as f, createContext as M, useContext as R } from "react";
4
+ import { logConversation as V } from "../atoms/api/analytics/conversation.js";
5
+ import { useInkeepConfig as _ } from "./config-provider.js";
6
+ import { useInkeepConversation as $ } from "./conversation-provider.js";
7
+ import { useUser as q } from "./user-provider.js";
8
+ import { useBaseEvents as z } from "./base-events-provider.js";
9
+ import { generateUid as D } from "../utils/generate-uid.js";
10
+ const I = M(void 0), Y = ({ children: i }) => {
11
+ const { baseSettings: L, aiChatSettings: k } = _(), {
12
12
  apiKey: h,
13
- analyticsApiBaseUrl: f,
14
- tags: m,
13
+ analyticsApiBaseUrl: m,
14
+ tags: g,
15
15
  privacyPreferences: { optOutAllAnalytics: a },
16
16
  env: c,
17
17
  analyticsProperties: v
18
- } = k, { conversationVisibility: g } = A, { userProperties: E } = _(), { logEvent: y } = $(), { conversation: u, setConversation: L, chatId: l, isSharedChat: d, setExternalChatId: x } = V(), n = b(u), p = b(d ? l : void 0);
19
- P(() => {
20
- n.current = u;
21
- }, [u]), P(() => {
22
- p.current = d ? l : void 0;
23
- }, [l, d]);
24
- const C = w(
18
+ } = L, { conversationVisibility: E } = k, { userProperties: y } = q(), { logEvent: x } = z(), { conversation: u, setConversation: A, chatId: l, isSharedChat: p, setExternalChatId: b } = $(), e = P(u), C = P(p ? l : void 0);
19
+ w(() => {
20
+ e.current = u;
21
+ }, [u]), w(() => {
22
+ C.current = p ? l : void 0;
23
+ }, [l, p]);
24
+ const d = f(
25
25
  async (o) => {
26
- const t = n.current;
27
- p.current && (t.id = "", x(void 0), p.current = void 0);
28
- const e = !a && c !== "development";
26
+ const t = e.current;
27
+ C.current && (t.id = "", b(void 0), C.current = void 0);
28
+ const n = !a && c !== "development";
29
29
  let r = Object.assign({}, t, { messages: o });
30
- if (e) {
31
- const s = await M(
30
+ if (n) {
31
+ const s = await V(
32
32
  t.id,
33
33
  {
34
34
  messages: o,
35
- tags: m,
36
- userProperties: E,
35
+ tags: g,
36
+ userProperties: y,
37
37
  properties: v,
38
- visibility: g
38
+ visibility: E
39
39
  },
40
40
  h,
41
- f
41
+ m
42
42
  );
43
43
  s && (r = s);
44
44
  } else
45
- r.id = "conv_" + q(16);
45
+ r.id = "conv_" + D(16);
46
46
  return r;
47
47
  },
48
48
  [
49
- f,
50
- h,
51
49
  m,
52
- E,
50
+ h,
51
+ g,
52
+ y,
53
53
  a,
54
54
  c,
55
55
  v,
56
- x,
57
- g
56
+ b,
57
+ E
58
58
  ]
59
- ), S = {
60
- logEvent: w(
61
- async (o, t) => {
62
- let e = n.current;
63
- if (t) {
64
- const s = n.current.messages || [];
65
- (t.length !== s.length || t.some((U, j) => U.id !== s[j]?.id)) && (e = await C(t), L(e), n.current = e);
59
+ ), S = f(
60
+ async (o, t) => {
61
+ let n = e.current;
62
+ if (t) {
63
+ const s = e.current.messages || [];
64
+ (t.length !== s.length || t.some((B, O) => B.id !== s[O]?.id)) && (n = await d(t), A(n), e.current = n);
65
+ }
66
+ const r = {
67
+ ...o,
68
+ properties: {
69
+ conversation: n,
70
+ ...o.properties
66
71
  }
67
- const r = {
68
- ...o,
69
- properties: {
70
- conversation: e,
71
- ...o.properties
72
- }
73
- };
74
- y(r);
75
- },
76
- [y, C, a, c, v]
77
- ),
78
- logConversation: C
72
+ };
73
+ x(r);
74
+ },
75
+ [x, d, a, c, v]
76
+ ), U = f(() => e.current, []), j = {
77
+ logEvent: S,
78
+ logConversation: d,
79
+ getLatestConversation: U
79
80
  };
80
- return /* @__PURE__ */ B(I.Provider, { value: S, children: i });
81
- }, Y = () => {
82
- const i = K(I);
81
+ return /* @__PURE__ */ K(I.Provider, { value: j, children: i });
82
+ }, Z = () => {
83
+ const i = R(I);
83
84
  if (!i)
84
85
  throw new Error("useChatEvents must be used within a ChatEventsProvider");
85
86
  return i;
86
87
  };
87
88
  export {
88
- X as ChatEventsProvider,
89
- Y as useChatEvents
89
+ Y as ChatEventsProvider,
90
+ Z as useChatEvents
90
91
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),s=require("react"),H=require("react-hook-form"),O=require("./conversation-provider.cjs"),M=require("../components/modal/modal-provider.cjs"),N=require("../utils/form.cjs"),T=require("./chat-events-provider.cjs"),V="root.serverError",g=s.createContext(void 0);function C(){const[t,i]=s.useState(null),[u,m]=s.useState(null),[F,l]=s.useState(!1),{conversation:r}=O.useInkeepConversation(),b=M.useModal(),{logEvent:d}=T.useChatEvents(),_=(e,o)=>{i(e),m(o||null)},p=()=>{i(null),m(null),l(!1),t?.buttons.close?.action==="close_modal"&&b?.setOpen(!1)},c=s.useMemo(()=>t?.fields.map(e=>{const o={...e};return"_type"in e&&e._type==="include_chat_session"&&(o.inputType="checkbox",r.id?(o.isHidden=e.isHidden,o.isRequired=e.isRequired):(o.isHidden=!0,o.isRequired=!1)),o}),[t?.fields,r.id]),f=c?.find(e=>"_type"in e&&e._type==="include_chat_session"),n=s.useMemo(()=>N.getFormDefaultValues(c),[c]),{control:E,handleSubmit:q,formState:{errors:v,isSubmitting:y},setError:R,reset:h}=H.useForm({defaultValues:n});s.useEffect(()=>{n&&h(n)},[h,n]);const P=q(async e=>{const a=r.id&&f&&e[f.name]?r:null;try{await t?.buttons.submit.onSubmit({values:e,conversation:a}),u&&d({eventName:"user_escalation_indicated",properties:{escalationType:"support_form",getHelpOptionName:u.name,conversation:a||r}}),d({eventName:"ai_chat_form_submitted",properties:{conversation:a||r,values:e}}),l(!0),t?.successView||p()}catch(S){R(V,{message:S instanceof Error?S.message:"Something went wrong."})}}),w=v?.root?.serverError;return{form:t,openForm:_,closeForm:p,handleSubmit:P,isSuccess:F,isSubmitting:y,formError:w,fields:c,errors:v,control:E,defaultValues:n}}const j=({children:t})=>{const i=C();return x.jsx(g.Provider,{value:i,children:t})},k=()=>{const t=s.useContext(g);if(!t)throw new Error("useChatForm must be used within a ChatFormProvider");return t};exports.ChatFormProvider=j;exports.useChatForm=k;exports.useChatFormState=C;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),s=require("react"),H=require("react-hook-form"),M=require("./conversation-provider.cjs"),O=require("../components/modal/modal-provider.cjs"),A=require("../utils/form.cjs"),N=require("./chat-events-provider.cjs"),T="root.serverError",b=s.createContext(void 0);function C(){const[t,c]=s.useState(null),[a,m]=s.useState(null),[g,d]=s.useState(!1),{conversation:r}=M.useInkeepConversation(),F=O.useModal(),{logEvent:v}=N.useChatEvents(),_=(e,o)=>{c(e),m(o||null)},f=()=>{c(null),m(null),d(!1),t?.buttons.close?.action==="close_modal"&&F?.setOpen(!1)},u=s.useMemo(()=>t?.fields.map(e=>{const o={...e};return"_type"in e&&e._type==="include_chat_session"&&(o.inputType="checkbox",r.id?(o.isHidden=e.isHidden,o.isRequired=e.isRequired):(o.isHidden=!0,o.isRequired=!1)),o}),[t?.fields,r.id]),p=u?.find(e=>"_type"in e&&e._type==="include_chat_session"),n=s.useMemo(()=>A.getFormDefaultValues(u),[u]),{control:E,handleSubmit:q,formState:{errors:h,isSubmitting:y},setError:R,reset:S}=H.useForm({defaultValues:n});s.useEffect(()=>{n&&S(n)},[S,n]);const P=q(async e=>{const l=r.id&&p&&e[p.name]?r:null;try{if(await t?.buttons.submit.onSubmit({values:e,conversation:l}),a){const i="name"in a;v({eventName:"user_escalation_indicated",properties:{escalationType:"support_form",getHelpOptionName:i?a?.name:void 0,toolCallActionLabel:i?void 0:a?.label,conversation:l||r}})}v({eventName:"ai_chat_form_submitted",properties:{conversation:l||r,values:e}}),d(!0),t?.successView||f()}catch(i){R(T,{message:i instanceof Error?i.message:"Something went wrong."})}}),w=h?.root?.serverError;return{form:t,openForm:_,closeForm:f,handleSubmit:P,isSuccess:g,isSubmitting:y,formError:w,fields:u,errors:h,control:E,defaultValues:n}}const V=({children:t})=>{const c=C();return x.jsx(b.Provider,{value:c,children:t})},j=()=>{const t=s.useContext(b);if(!t)throw new Error("useChatForm must be used within a ChatFormProvider");return t};exports.ChatFormProvider=V;exports.useChatForm=j;exports.useChatFormState=C;
@@ -1,74 +1,79 @@
1
1
  "use client";
2
- import { jsx as O } from "react/jsx-runtime";
3
- import { useState as a, useMemo as _, useEffect as N, createContext as V, useContext as q } from "react";
4
- import { useForm as M } from "react-hook-form";
5
- import { useInkeepConversation as P } from "./conversation-provider.js";
6
- import { useModal as T } from "../components/modal/modal-provider.js";
7
- import { getFormDefaultValues as k } from "../utils/form.js";
8
- import { useChatEvents as G } from "./chat-events-provider.js";
9
- const I = "root.serverError", g = V(void 0);
2
+ import { jsx as A } from "react/jsx-runtime";
3
+ import { useState as u, useMemo as S, useEffect as N, createContext as O, useContext as V } from "react";
4
+ import { useForm as q } from "react-hook-form";
5
+ import { useInkeepConversation as M } from "./conversation-provider.js";
6
+ import { useModal as P } from "../components/modal/modal-provider.js";
7
+ import { getFormDefaultValues as T } from "../utils/form.js";
8
+ import { useChatEvents as k } from "./chat-events-provider.js";
9
+ const I = "root.serverError", _ = O(void 0);
10
10
  function j() {
11
- const [t, r] = a(null), [u, m] = a(null), [b, l] = a(!1), { conversation: s } = P(), C = T(), { logEvent: p } = G(), E = (e, o) => {
12
- r(e), m(o || null);
13
- }, d = () => {
14
- r(null), m(null), l(!1), t?.buttons.close?.action === "close_modal" && C?.setOpen(!1);
15
- }, i = _(() => t?.fields.map((e) => {
11
+ const [t, i] = u(null), [c, l] = u(null), [g, d] = u(!1), { conversation: s } = M(), C = P(), { logEvent: p } = k(), E = (e, o) => {
12
+ i(e), l(o || null);
13
+ }, f = () => {
14
+ i(null), l(null), d(!1), t?.buttons.close?.action === "close_modal" && C?.setOpen(!1);
15
+ }, a = S(() => t?.fields.map((e) => {
16
16
  const o = { ...e };
17
17
  return "_type" in e && e._type === "include_chat_session" && (o.inputType = "checkbox", s.id ? (o.isHidden = e.isHidden, o.isRequired = e.isRequired) : (o.isHidden = !0, o.isRequired = !1)), o;
18
- }), [t?.fields, s.id]), f = i?.find((e) => "_type" in e && e._type === "include_chat_session"), n = _(() => k(i), [i]), {
18
+ }), [t?.fields, s.id]), h = a?.find((e) => "_type" in e && e._type === "include_chat_session"), n = S(() => T(a), [a]), {
19
19
  control: F,
20
20
  handleSubmit: y,
21
- formState: { errors: h, isSubmitting: R },
21
+ formState: { errors: v, isSubmitting: R },
22
22
  setError: w,
23
- reset: v
24
- } = M({
23
+ reset: b
24
+ } = q({
25
25
  defaultValues: n
26
26
  });
27
27
  N(() => {
28
- n && v(n);
29
- }, [v, n]);
28
+ n && b(n);
29
+ }, [b, n]);
30
30
  const x = y(async (e) => {
31
- const c = s.id && f && e[f.name] ? s : null;
31
+ const m = s.id && h && e[h.name] ? s : null;
32
32
  try {
33
- await t?.buttons.submit.onSubmit({ values: e, conversation: c }), u && p({
34
- eventName: "user_escalation_indicated",
35
- properties: {
36
- escalationType: "support_form",
37
- getHelpOptionName: u.name,
38
- conversation: c || s
39
- }
40
- }), p({
33
+ if (await t?.buttons.submit.onSubmit({ values: e, conversation: m }), c) {
34
+ const r = "name" in c;
35
+ p({
36
+ eventName: "user_escalation_indicated",
37
+ properties: {
38
+ escalationType: "support_form",
39
+ getHelpOptionName: r ? c?.name : void 0,
40
+ toolCallActionLabel: r ? void 0 : c?.label,
41
+ conversation: m || s
42
+ }
43
+ });
44
+ }
45
+ p({
41
46
  eventName: "ai_chat_form_submitted",
42
47
  properties: {
43
- conversation: c || s,
48
+ conversation: m || s,
44
49
  values: e
45
50
  }
46
- }), l(!0), t?.successView || d();
47
- } catch (S) {
51
+ }), d(!0), t?.successView || f();
52
+ } catch (r) {
48
53
  w(I, {
49
- message: S instanceof Error ? S.message : "Something went wrong."
54
+ message: r instanceof Error ? r.message : "Something went wrong."
50
55
  });
51
56
  }
52
- }), H = h?.root?.serverError;
57
+ }), H = v?.root?.serverError;
53
58
  return {
54
59
  form: t,
55
60
  openForm: E,
56
- closeForm: d,
61
+ closeForm: f,
57
62
  handleSubmit: x,
58
- isSuccess: b,
63
+ isSuccess: g,
59
64
  isSubmitting: R,
60
65
  formError: H,
61
- fields: i,
62
- errors: h,
66
+ fields: a,
67
+ errors: v,
63
68
  control: F,
64
69
  defaultValues: n
65
70
  };
66
71
  }
67
72
  const U = ({ children: t }) => {
68
- const r = j();
69
- return /* @__PURE__ */ O(g.Provider, { value: r, children: t });
73
+ const i = j();
74
+ return /* @__PURE__ */ A(_.Provider, { value: i, children: t });
70
75
  }, W = () => {
71
- const t = q(g);
76
+ const t = V(_);
72
77
  if (!t)
73
78
  throw new Error("useChatForm must be used within a ChatFormProvider");
74
79
  return t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/cxkit-primitives",
3
- "version": "0.5.108",
3
+ "version": "0.5.109",
4
4
  "description": "",
5
5
  "license": "Inkeep, Inc. Customer License (IICL) v1.1",
6
6
  "homepage": "",
@@ -67,9 +67,9 @@
67
67
  "remark-gfm": "^4.0.1",
68
68
  "unist-util-visit": "^5.0.0",
69
69
  "use-sync-external-store": "^1.4.0",
70
- "@inkeep/cxkit-color-mode": "^0.5.108",
71
- "@inkeep/cxkit-theme": "0.5.108",
72
- "@inkeep/cxkit-types": "0.5.108"
70
+ "@inkeep/cxkit-color-mode": "^0.5.109",
71
+ "@inkeep/cxkit-theme": "0.5.109",
72
+ "@inkeep/cxkit-types": "0.5.109"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@biomejs/biome": "1.9.4",