@inkeep/agents-ui 0.15.4 → 0.15.6

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 strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),w=require("react"),M=require("react-markdown"),f=require("rehype-raw"),y=require("remark-gfm"),g=require("remark-supersub"),S=require("../../providers/markdown-provider.cjs"),b=require("../codeblock/index.cjs"),n=require("./components.cjs"),q=require("./rehype-inline-code-property.cjs");const C=({children:c,componentStyles:h,shouldOpenLinksInNewTab:d,onLinkClick:l,onCodeCopy:m,artifacts:k,...p})=>{if(!c)return null;const x={h1:({children:r})=>e.jsx(n.MarkdownH1,{children:r}),h2:({children:r})=>e.jsx(n.MarkdownH2,{children:r}),p:({children:r})=>e.jsx(n.MarkdownP,{children:r}),li:({children:r})=>e.jsx(n.MarkdownLi,{children:r}),ul:({children:r})=>e.jsx(n.MarkdownUl,{children:r}),hr:()=>e.jsx(n.MarkdownHr,{}),input:({type:r,checked:o,disabled:t,readOnly:i,required:s,value:a})=>e.jsx(n.MarkdownInput,{type:r,checked:o,disabled:t,readOnly:i,required:s,value:a}),ol:({children:r,node:o})=>{const t=o?.properties?.start,i=typeof t=="number"?t:void 0;return e.jsx(n.MarkdownOl,{style:{"--start":t?.toString()??"0"},start:i,children:r})},a:({children:r,href:o})=>{const t=w.Children.toArray(r),i=t[0],s=typeof i=="string"&&/^\(\d+\)$/.test(i)&&t.length===1,a=s?i.match(/\d+/):r,u=e.jsx(n.MarkdownLink,{isExternal:d,href:o,onClick:()=>{l?.(o,a?.toString())},children:a});return s?e.jsx(n.MarkdownSourceLink,{children:u}):u},img:({src:r,alt:o})=>e.jsx(n.MarkdownImg,{src:r,alt:o}),table:({children:r})=>e.jsx(n.MarkdownTable,{children:r}),th:({children:r,isHeader:o})=>o?e.jsx(n.MarkdownTh,{children:r}):e.jsx(n.MarkdownTd,{children:r}),pre:({children:r})=>e.jsx("pre",{children:r}),code:({children:r,inline:o,className:t})=>o?e.jsx(n.MarkdownCode,{children:r}):e.jsx(b.CodeBlock,{className:t,onCopy:m,children:r}),sup:({children:r})=>{if(r&&typeof r=="string"){const o=k?.find(t=>(t.data?.artifactSummary?.title||t.data?.name)===r);if(o){const t=o.data,i=t?.artifactSummary?.url,s=t?.artifactSummary?.title||t?.name||r;return i?e.jsx(n.MarkdownSup,{children:e.jsx(n.MarkdownLink,{href:i,isExternal:d,onClick:()=>l?.(i,s),children:e.jsx("span",{children:s})})}):e.jsx(n.MarkdownSup,{children:e.jsx("span",{children:s})})}}return e.jsx("sup",{children:r})}},j=e.jsx(M,{remarkPlugins:[y,g],rehypePlugins:[f,q.rehypeInlineCodeProperty],components:x,disallowedElements:P,children:c.toString(),...p});return e.jsx(S.ChatMarkdownProvider,{componentStyles:h,children:j})},P=["script","iframe","frame","embed","meta","base","form","style","object"];exports.Markdown=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),w=require("react"),f=require("react-markdown"),M=require("rehype-raw"),y=require("remark-gfm"),g=require("remark-supersub"),b=require("../../providers/markdown-provider.cjs"),S=require("../codeblock/index.cjs"),n=require("./components.cjs"),q=require("./rehype-inline-code-property.cjs");const C=({children:c,componentStyles:h,shouldOpenLinksInNewTab:d,onLinkClick:l,onCodeCopy:m,artifacts:x,...j})=>{if(!c)return null;const p={h1:({children:r})=>e.jsx(n.MarkdownH1,{children:r}),h2:({children:r})=>e.jsx(n.MarkdownH2,{children:r}),p:({children:r})=>e.jsx(n.MarkdownP,{children:r}),li:({children:r})=>e.jsx(n.MarkdownLi,{children:r}),ul:({children:r})=>e.jsx(n.MarkdownUl,{children:r}),hr:()=>e.jsx(n.MarkdownHr,{}),input:({type:r,checked:s,disabled:t,readOnly:o,required:i,value:a})=>e.jsx(n.MarkdownInput,{type:r,checked:s,disabled:t,readOnly:o,required:i,value:a}),ol:({children:r,node:s})=>{const t=s?.properties?.start,o=typeof t=="number"?t:void 0;return e.jsx(n.MarkdownOl,{style:{"--start":t?.toString()??"0"},start:o,children:r})},a:({children:r,href:s})=>{const t=w.Children.toArray(r),o=t[0],i=typeof o=="string"&&/^\(\d+\)$/.test(o)&&t.length===1,a=i?o.match(/\d+/):r,u=e.jsx(n.MarkdownLink,{isExternal:d,href:s,onClick:()=>{l?.(s,a?.toString())},children:a});return i?e.jsx(n.MarkdownSourceLink,{children:u}):u},img:({src:r,alt:s})=>e.jsx(n.MarkdownImg,{src:r,alt:s}),table:({children:r})=>e.jsx(n.MarkdownTable,{children:r}),th:({children:r,isHeader:s})=>s?e.jsx(n.MarkdownTh,{children:r}):e.jsx(n.MarkdownTd,{children:r}),pre:({children:r})=>e.jsx("pre",{children:r}),code:({children:r,inline:s,className:t})=>s?e.jsx(n.MarkdownCode,{children:r}):e.jsx(S.CodeBlock,{className:t,onCopy:m,children:r}),sub:({children:r})=>typeof r=="string"&&(r.startsWith(" ")||r.endsWith(" "))?e.jsxs(e.Fragment,{children:["~",r,"~"]}):e.jsx("sub",{children:r}),sup:({children:r})=>{if(r&&typeof r=="string"){const s=x?.find(t=>(t.data?.artifactSummary?.title||t.data?.name)===r);if(s){const t=s.data,o=t?.artifactSummary?.url,i=t?.artifactSummary?.title||t?.name||r;return o?e.jsx(n.MarkdownSup,{children:e.jsx(n.MarkdownLink,{href:o,isExternal:d,onClick:()=>l?.(o,i),children:e.jsx("span",{children:i})})}):e.jsx(n.MarkdownSup,{children:e.jsx("span",{children:i})})}}return e.jsx("sup",{children:r})}},k=e.jsx(f,{remarkPlugins:[[y,{singleTilde:!1}],g],rehypePlugins:[M,q.rehypeInlineCodeProperty],components:p,disallowedElements:P,children:c.toString(),...j});return e.jsx(b.ChatMarkdownProvider,{componentStyles:h,children:k})},P=["script","iframe","frame","embed","meta","base","form","style","object"];exports.Markdown=C;
@@ -1,48 +1,48 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import y from "react";
3
- import g from "react-markdown";
4
- import S from "rehype-raw";
5
- import b from "remark-gfm";
6
- import C from "remark-supersub";
7
- import { ChatMarkdownProvider as P } from "../../providers/markdown-provider.js";
8
- import { CodeBlock as x } from "../codeblock/index.js";
9
- import { MarkdownSup as s, MarkdownLink as h, MarkdownCode as E, MarkdownTh as H, MarkdownTd as R, MarkdownTable as j, MarkdownImg as v, MarkdownSourceLink as A, MarkdownOl as I, MarkdownInput as T, MarkdownHr as _, MarkdownUl as B, MarkdownLi as D, MarkdownP as G, MarkdownH2 as L, MarkdownH1 as U } from "./components.js";
1
+ import { jsx as t, jsxs as y, Fragment as g } from "react/jsx-runtime";
2
+ import b from "react";
3
+ import S from "react-markdown";
4
+ import C from "rehype-raw";
5
+ import x from "remark-gfm";
6
+ import P from "remark-supersub";
7
+ import { ChatMarkdownProvider as j } from "../../providers/markdown-provider.js";
8
+ import { CodeBlock as E } from "../codeblock/index.js";
9
+ import { MarkdownSup as m, MarkdownLink as h, MarkdownCode as H, MarkdownTh as R, MarkdownTd as T, MarkdownTable as v, MarkdownImg as A, MarkdownSourceLink as I, MarkdownOl as W, MarkdownInput as _, MarkdownHr as B, MarkdownUl as D, MarkdownLi as F, MarkdownP as G, MarkdownH2 as L, MarkdownH1 as U } from "./components.js";
10
10
  import { rehypeInlineCodeProperty as V } from "./rehype-inline-code-property.js";
11
- const Z = ({
11
+ const rr = ({
12
12
  children: d,
13
- componentStyles: p,
13
+ componentStyles: u,
14
14
  shouldOpenLinksInNewTab: c,
15
15
  onLinkClick: l,
16
- onCodeCopy: u,
16
+ onCodeCopy: p,
17
17
  artifacts: f,
18
18
  ...k
19
19
  }) => {
20
20
  if (!d) return null;
21
21
  const w = {
22
- h1: ({ children: r }) => /* @__PURE__ */ n(U, { children: r }),
23
- h2: ({ children: r }) => /* @__PURE__ */ n(L, { children: r }),
24
- p: ({ children: r }) => /* @__PURE__ */ n(G, { children: r }),
25
- li: ({ children: r }) => /* @__PURE__ */ n(D, { children: r }),
26
- ul: ({ children: r }) => /* @__PURE__ */ n(B, { children: r }),
27
- hr: () => /* @__PURE__ */ n(_, {}),
28
- input: ({ type: r, checked: e, disabled: t, readOnly: o, required: i, value: a }) => /* @__PURE__ */ n(
29
- T,
22
+ h1: ({ children: r }) => /* @__PURE__ */ t(U, { children: r }),
23
+ h2: ({ children: r }) => /* @__PURE__ */ t(L, { children: r }),
24
+ p: ({ children: r }) => /* @__PURE__ */ t(G, { children: r }),
25
+ li: ({ children: r }) => /* @__PURE__ */ t(F, { children: r }),
26
+ ul: ({ children: r }) => /* @__PURE__ */ t(D, { children: r }),
27
+ hr: () => /* @__PURE__ */ t(B, {}),
28
+ input: ({ type: r, checked: e, disabled: n, readOnly: o, required: i, value: a }) => /* @__PURE__ */ t(
29
+ _,
30
30
  {
31
31
  type: r,
32
32
  checked: e,
33
- disabled: t,
33
+ disabled: n,
34
34
  readOnly: o,
35
35
  required: i,
36
36
  value: a
37
37
  }
38
38
  ),
39
39
  ol: ({ children: r, node: e }) => {
40
- const t = e?.properties?.start, o = typeof t == "number" ? t : void 0;
41
- return /* @__PURE__ */ n(
42
- I,
40
+ const n = e?.properties?.start, o = typeof n == "number" ? n : void 0;
41
+ return /* @__PURE__ */ t(
42
+ W,
43
43
  {
44
44
  style: {
45
- "--start": t?.toString() ?? "0"
45
+ "--start": n?.toString() ?? "0"
46
46
  },
47
47
  start: o,
48
48
  children: r
@@ -50,7 +50,7 @@ const Z = ({
50
50
  );
51
51
  },
52
52
  a: ({ children: r, href: e }) => {
53
- const t = y.Children.toArray(r), o = t[0], i = typeof o == "string" && /^\(\d+\)$/.test(o) && t.length === 1, a = i ? o.match(/\d+/) : r, m = /* @__PURE__ */ n(
53
+ const n = b.Children.toArray(r), o = n[0], i = typeof o == "string" && /^\(\d+\)$/.test(o) && n.length === 1, a = i ? o.match(/\d+/) : r, s = /* @__PURE__ */ t(
54
54
  h,
55
55
  {
56
56
  isExternal: c,
@@ -61,45 +61,50 @@ const Z = ({
61
61
  children: a
62
62
  }
63
63
  );
64
- return i ? /* @__PURE__ */ n(A, { children: m }) : m;
64
+ return i ? /* @__PURE__ */ t(I, { children: s }) : s;
65
65
  },
66
- img: ({ src: r, alt: e }) => /* @__PURE__ */ n(v, { src: r, alt: e }),
67
- table: ({ children: r }) => /* @__PURE__ */ n(j, { children: r }),
68
- th: ({ children: r, isHeader: e }) => e ? /* @__PURE__ */ n(H, { children: r }) : /* @__PURE__ */ n(R, { children: r }),
69
- pre: ({ children: r }) => /* @__PURE__ */ n("pre", { children: r }),
70
- code: ({ children: r, inline: e, className: t }) => e ? /* @__PURE__ */ n(E, { children: r }) : /* @__PURE__ */ n(x, { className: t, onCopy: u, children: r }),
66
+ img: ({ src: r, alt: e }) => /* @__PURE__ */ t(A, { src: r, alt: e }),
67
+ table: ({ children: r }) => /* @__PURE__ */ t(v, { children: r }),
68
+ th: ({ children: r, isHeader: e }) => e ? /* @__PURE__ */ t(R, { children: r }) : /* @__PURE__ */ t(T, { children: r }),
69
+ pre: ({ children: r }) => /* @__PURE__ */ t("pre", { children: r }),
70
+ code: ({ children: r, inline: e, className: n }) => e ? /* @__PURE__ */ t(H, { children: r }) : /* @__PURE__ */ t(E, { className: n, onCopy: p, children: r }),
71
+ sub: ({ children: r }) => typeof r == "string" && (r.startsWith(" ") || r.endsWith(" ")) ? /* @__PURE__ */ y(g, { children: [
72
+ "~",
73
+ r,
74
+ "~"
75
+ ] }) : /* @__PURE__ */ t("sub", { children: r }),
71
76
  sup: ({ children: r }) => {
72
77
  if (r && typeof r == "string") {
73
78
  const e = f?.find(
74
- (t) => (t.data?.artifactSummary?.title || t.data?.name) === r
79
+ (n) => (n.data?.artifactSummary?.title || n.data?.name) === r
75
80
  );
76
81
  if (e) {
77
- const t = e.data, o = t?.artifactSummary?.url, i = t?.artifactSummary?.title || t?.name || r;
78
- return o ? /* @__PURE__ */ n(s, { children: /* @__PURE__ */ n(
82
+ const n = e.data, o = n?.artifactSummary?.url, i = n?.artifactSummary?.title || n?.name || r;
83
+ return o ? /* @__PURE__ */ t(m, { children: /* @__PURE__ */ t(
79
84
  h,
80
85
  {
81
86
  href: o,
82
87
  isExternal: c,
83
88
  onClick: () => l?.(o, i),
84
- children: /* @__PURE__ */ n("span", { children: i })
89
+ children: /* @__PURE__ */ t("span", { children: i })
85
90
  }
86
- ) }) : /* @__PURE__ */ n(s, { children: /* @__PURE__ */ n("span", { children: i }) });
91
+ ) }) : /* @__PURE__ */ t(m, { children: /* @__PURE__ */ t("span", { children: i }) });
87
92
  }
88
93
  }
89
- return /* @__PURE__ */ n("sup", { children: r });
94
+ return /* @__PURE__ */ t("sup", { children: r });
90
95
  }
91
- }, M = /* @__PURE__ */ n(
92
- g,
96
+ }, M = /* @__PURE__ */ t(
97
+ S,
93
98
  {
94
- remarkPlugins: [b, C],
95
- rehypePlugins: [S, V],
99
+ remarkPlugins: [[x, { singleTilde: !1 }], P],
100
+ rehypePlugins: [C, V],
96
101
  components: w,
97
102
  disallowedElements: $,
98
103
  children: d.toString(),
99
104
  ...k
100
105
  }
101
106
  );
102
- return /* @__PURE__ */ n(P, { componentStyles: p, children: M });
107
+ return /* @__PURE__ */ t(j, { componentStyles: u, children: M });
103
108
  }, $ = [
104
109
  "script",
105
110
  "iframe",
@@ -112,5 +117,5 @@ const Z = ({
112
117
  "object"
113
118
  ];
114
119
  export {
115
- Z as Markdown
120
+ rr as Markdown
116
121
  };
@@ -1,3 +1,3 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("@ai-sdk/react"),Y=require("ai"),n=require("react"),Z=require("../../providers/config-provider.cjs"),ee=require("../../hooks/use-media-query.cjs"),R=require("../../utils/generate-uid.cjs"),te=require("../../providers/base-events-provider.cjs"),se=require("../../providers/chat-form-provider.cjs"),ne=require("../../providers/widget-provider.cjs"),re=require("@radix-ui/react-use-controllable-state"),ae=require("../../hooks/use-streaming-events.cjs"),x=`Hmm..
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("@ai-sdk/react"),Z=require("ai"),s=require("react"),ee=require("../../providers/config-provider.cjs"),te=require("../../hooks/use-media-query.cjs"),k=require("../../utils/generate-uid.cjs"),se=require("../../providers/base-events-provider.cjs"),ne=require("../../providers/chat-form-provider.cjs"),re=require("../../providers/widget-provider.cjs"),ae=require("@radix-ui/react-use-controllable-state"),oe=require("../../hooks/use-streaming-events.cjs"),A=`Hmm..
2
2
 
3
- It seems I might be having some issues right now. Please clear the chat and try again.`,oe=()=>{const{baseSettings:v,aiChatSettings:o}=Z.useInkeepConfig(),[s="",E]=re.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=te.useBaseEvents(),{setConversationId:P,emitToParent:u}=ae.useStreamingEvents(),[a,l]=n.useState(""),k=e=>l(e.target.value),{filters:S}=v,{onInputMessageChange:A,filters:b,agentUrl:D,context:N,headers:U,apiKey:y}=o,T=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${v.organizationDisplayName??"Administrator"}`;default:return x}},[O,d]=n.useState([]),[K,C]=n.useState(null),{messages:g,sendMessage:L,status:I,setMessages:w,stop:W,error:p}=X.useChat({transport:new Y.DefaultChatTransport({api:D,headers:{...y?{Authorization:`Bearer ${y}`}:{},...U},body:{requestContext:N}}),onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:s}),await i({eventName:"assistant_message_received",properties:{conversationId:s}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:s}})},onError(e){console.log("onError",e.message),w(c=>{const r=[...c],t=r[r.length-1];if(t){const F=T(e);t.role==="user"?r.push({id:R.generateUid(16),role:"assistant",parts:[{type:"text",text:F}]}):t.parts=[{type:"text",text:F}]}return r})}}),M=I==="submitted",$=I==="streaming",z=g.length===0,m=!a.trim()||M,B=ee.useMediaQuery("(max-width: 768px)"),[G,h]=n.useState(null);n.useEffect(()=>{p&&h(p)},[p]);const H=()=>h(null),_=n.useRef(null);n.useEffect(()=>{A?.(a)},[a]);const Q=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),f())},f=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;d([]),l(""),await i({eventName:"user_message_submitted",properties:{conversationId:s}});const c=S||b?JSON.stringify({...S,...b}):void 0,r={};c&&(r["inkeep-filters"]=c);let t=s;t||(t=`conv_${R.generateUid(16)}`,E(t)),P(t),L({text:e},{headers:r,body:{conversationId:t}})},j=()=>{W().then(()=>{u("aborted",{conversationId:s})})},q=()=>{H(),w([]),E(""),d([]),C(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:s}})},{openForm:J}=se.useChatForm(),V=ne.useWidget();return n.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:f,updateInputMessage(e){l(e)},clearChat:q,openForm:e=>{V?.setView("chat"),J(e,void 0)},focusInput:()=>{_.current?.focus()}})),{messages:g,isLoading:M,isStreaming:$,error:G,setError:h,isSubmitDisabled:m,input:a,handleInputChange:k,handleInputKeyDown:Q,handleSubmit:f,stop:j,clear:q,isEmpty:g.length===0,inputRef:_,isMobile:B,messageAttachments:O,setMessageAttachments:d,selectedWorkflow:K,setSelectedWorkflow:C,isNewChat:z,conversationId:s}};exports.DEFAULT_ERROR_MESSAGE=x;exports.useInkeepChat=oe;
3
+ It seems I might be having some issues right now. Please clear the chat and try again.`,ie=()=>{const{baseSettings:C,aiChatSettings:o}=ee.useInkeepConfig(),[n="",b]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:D,emitToParent:u}=oe.useStreamingEvents(),[a,l]=s.useState(""),N=e=>l(e.target.value),{filters:y}=C,{onInputMessageChange:U,filters:I,agentUrl:M,context:d,headers:g,apiKey:p}=o,T=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${C.organizationDisplayName??"Administrator"}`;default:return A}},[O,m]=s.useState([]),[H,w]=s.useState(null),K=s.useMemo(()=>new Z.DefaultChatTransport({api:M,headers:{...p?{Authorization:`Bearer ${p}`}:{},...g},body:{requestContext:d}}),[M,p,g,d]),{messages:h,sendMessage:L,status:q,setMessages:_,stop:W,error:f}=Y.useChat({transport:K,onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:n}),await i({eventName:"assistant_message_received",properties:{conversationId:n}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.log("onError",e.message),_(c=>{const r=[...c],t=r[r.length-1];if(t){const P=T(e);t.role==="user"?r.push({id:k.generateUid(16),role:"assistant",parts:[{type:"text",text:P}]}):t.parts=[{type:"text",text:P}]}return r})}}),x=q==="submitted",$=q==="streaming",z=h.length===0,v=!a.trim()||x,B=te.useMediaQuery("(max-width: 768px)"),[G,E]=s.useState(null);s.useEffect(()=>{f&&E(f)},[f]);const Q=()=>E(null),F=s.useRef(null);s.useEffect(()=>{U?.(a)},[a]);const j=e=>{e.key==="Enter"&&!e.shiftKey&&!v&&!e.nativeEvent.isComposing&&(e.preventDefault(),S())},S=async(e=a)=>{if(v&&(!e||e.trim().length===0))return;m([]),l(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=y||I?JSON.stringify({...y,...I}):void 0,r={...g};c&&(r["inkeep-filters"]=c);let t=n;t||(t=`conv_${k.generateUid(16)}`,b(t)),D(t),L({text:e},{headers:r,body:{conversationId:t,requestContext:d}})},J=()=>{W().then(()=>{u("aborted",{conversationId:n})})},R=()=>{Q(),_([]),b(""),m([]),w(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:V}=ne.useChatForm(),X=re.useWidget();return s.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:S,updateInputMessage(e){l(e)},clearChat:R,openForm:e=>{X?.setView("chat"),V(e,void 0)},focusInput:()=>{F.current?.focus()}})),{messages:h,isLoading:x,isStreaming:$,error:G,setError:E,isSubmitDisabled:v,input:a,handleInputChange:N,handleInputKeyDown:j,handleSubmit:S,stop:J,clear:R,isEmpty:h.length===0,inputRef:F,isMobile:B,messageAttachments:O,setMessageAttachments:m,selectedWorkflow:H,setSelectedWorkflow:w,isNewChat:z,conversationId:n}};exports.DEFAULT_ERROR_MESSAGE=A;exports.useInkeepChat=ie;
@@ -1,58 +1,61 @@
1
1
  "use client";
2
- import { useChat as X } from "@ai-sdk/react";
3
- import { DefaultChatTransport as Y } from "ai";
4
- import { useState as c, useEffect as k, useRef as Z, useImperativeHandle as ee } from "react";
5
- import { useInkeepConfig as te } from "../../providers/config-provider.js";
6
- import { useMediaQuery as se } from "../../hooks/use-media-query.js";
7
- import { generateUid as D } from "../../utils/generate-uid.js";
8
- import { useBaseEvents as ne } from "../../providers/base-events-provider.js";
9
- import { useChatForm as oe } from "../../providers/chat-form-provider.js";
10
- import { useWidget as re } from "../../providers/widget-provider.js";
11
- import { useControllableState as ae } from "@radix-ui/react-use-controllable-state";
12
- import { useStreamingEvents as ie } from "../../hooks/use-streaming-events.js";
13
- const ce = `Hmm..
2
+ import { useChat as Y } from "@ai-sdk/react";
3
+ import { DefaultChatTransport as Z } from "ai";
4
+ import { useState as c, useMemo as ee, useEffect as A, useRef as te, useImperativeHandle as se } from "react";
5
+ import { useInkeepConfig as ne } from "../../providers/config-provider.js";
6
+ import { useMediaQuery as oe } from "../../hooks/use-media-query.js";
7
+ import { generateUid as R } from "../../utils/generate-uid.js";
8
+ import { useBaseEvents as re } from "../../providers/base-events-provider.js";
9
+ import { useChatForm as ae } from "../../providers/chat-form-provider.js";
10
+ import { useWidget as ie } from "../../providers/widget-provider.js";
11
+ import { useControllableState as ce } from "@radix-ui/react-use-controllable-state";
12
+ import { useStreamingEvents as me } from "../../hooks/use-streaming-events.js";
13
+ const ue = `Hmm..
14
14
 
15
- It seems I might be having some issues right now. Please clear the chat and try again.`, ye = () => {
16
- const { baseSettings: v, aiChatSettings: r } = te(), [s = "", I] = ae({
15
+ It seems I might be having some issues right now. Please clear the chat and try again.`, be = () => {
16
+ const { baseSettings: y, aiChatSettings: r } = ne(), [s = "", E] = ce({
17
17
  prop: r.conversationId,
18
18
  defaultProp: r.conversationId ?? ""
19
- }), { logEvent: a } = ne(), { setConversationId: N, emitToParent: m } = ie(), [o, l] = c(""), A = (e) => l(e.target.value), {
19
+ }), { logEvent: a } = re(), { setConversationId: P, emitToParent: m } = me(), [o, u] = c(""), T = (e) => u(e.target.value), {
20
20
  /* shouldBypassCaptcha, */
21
- filters: C
22
- } = v, {
23
- onInputMessageChange: R,
24
- filters: y,
25
- agentUrl: P,
26
- context: T,
27
- headers: K,
28
- apiKey: E
29
- } = r, U = (e) => {
21
+ filters: b
22
+ } = y, {
23
+ onInputMessageChange: q,
24
+ filters: w,
25
+ agentUrl: S,
26
+ context: l,
27
+ headers: p,
28
+ apiKey: g
29
+ } = r, H = (e) => {
30
30
  switch (e.code) {
31
31
  case 400:
32
32
  return e.message;
33
33
  case 403:
34
- return `There seems to be a configuration error. Please contact ${v.organizationDisplayName ?? "Administrator"}`;
34
+ return `There seems to be a configuration error. Please contact ${y.organizationDisplayName ?? "Administrator"}`;
35
35
  default:
36
- return ce;
36
+ return ue;
37
37
  }
38
- }, [W, p] = c([]), [$, b] = c(null), {
39
- messages: u,
40
- sendMessage: z,
41
- status: w,
42
- setMessages: S,
43
- stop: B,
44
- error: g
45
- } = X({
46
- transport: new Y({
47
- api: P,
38
+ }, [K, d] = c([]), [U, M] = c(null), W = ee(
39
+ () => new Z({
40
+ api: S,
48
41
  headers: {
49
- ...E ? { Authorization: `Bearer ${E}` } : {},
50
- ...K
42
+ ...g ? { Authorization: `Bearer ${g}` } : {},
43
+ ...p
51
44
  },
52
45
  body: {
53
- requestContext: T
46
+ requestContext: l
54
47
  }
55
48
  }),
49
+ [S, g, p, l]
50
+ ), {
51
+ messages: h,
52
+ sendMessage: $,
53
+ status: _,
54
+ setMessages: x,
55
+ stop: z,
56
+ error: f
57
+ } = Y({
58
+ transport: W,
56
59
  onData(e) {
57
60
  m(e.type, e.data);
58
61
  },
@@ -70,106 +73,107 @@ It seems I might be having some issues right now. Please clear the chat and try
70
73
  });
71
74
  },
72
75
  onError(e) {
73
- console.log("onError", e.message), S((i) => {
76
+ console.log("onError", e.message), x((i) => {
74
77
  const n = [...i], t = n[n.length - 1];
75
78
  if (t) {
76
- const F = U(e);
79
+ const N = H(e);
77
80
  t.role === "user" ? n.push({
78
- id: D(16),
81
+ id: R(16),
79
82
  role: "assistant",
80
- parts: [{ type: "text", text: F }]
81
- }) : t.parts = [{ type: "text", text: F }];
83
+ parts: [{ type: "text", text: N }]
84
+ }) : t.parts = [{ type: "text", text: N }];
82
85
  }
83
86
  return n;
84
87
  });
85
88
  }
86
- }), M = w === "submitted", H = w === "streaming", L = u.length === 0, d = !o.trim() || M, O = se("(max-width: 768px)"), [q, h] = c(null);
87
- k(() => {
88
- g && h(g);
89
- }, [g]);
90
- const G = () => h(null), _ = Z(null);
91
- k(() => {
92
- R?.(o);
89
+ }), F = _ === "submitted", B = _ === "streaming", L = h.length === 0, v = !o.trim() || F, O = oe("(max-width: 768px)"), [G, C] = c(null);
90
+ A(() => {
91
+ f && C(f);
92
+ }, [f]);
93
+ const J = () => C(null), k = te(null);
94
+ A(() => {
95
+ q?.(o);
93
96
  }, [o]);
94
- const J = (e) => {
95
- e.key === "Enter" && !e.shiftKey && !d && !e.nativeEvent.isComposing && (e.preventDefault(), f());
96
- }, f = async (e = o) => {
97
- if (d && (!e || e.trim().length === 0)) return;
98
- p([]), l(""), await a({
97
+ const Q = (e) => {
98
+ e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), I());
99
+ }, I = async (e = o) => {
100
+ if (v && (!e || e.trim().length === 0)) return;
101
+ d([]), u(""), await a({
99
102
  eventName: "user_message_submitted",
100
103
  properties: {
101
104
  conversationId: s
102
105
  }
103
106
  });
104
- const i = C || y ? JSON.stringify({
105
- ...C,
106
- ...y
107
- }) : void 0, n = {};
107
+ const i = b || w ? JSON.stringify({
108
+ ...b,
109
+ ...w
110
+ }) : void 0, n = {
111
+ ...p
112
+ };
108
113
  i && (n["inkeep-filters"] = i);
109
114
  let t = s;
110
- t || (t = `conv_${D(16)}`, I(t)), N(t), z(
111
- // { ...userMessage, files },
112
- // { ...userMessage, },
115
+ t || (t = `conv_${R(16)}`, E(t)), P(t), $(
113
116
  {
114
117
  text: e
115
118
  },
116
119
  {
117
120
  headers: n,
118
121
  body: {
119
- conversationId: t
122
+ conversationId: t,
123
+ requestContext: l
120
124
  }
121
125
  }
122
126
  );
123
- }, Q = () => {
124
- B().then(() => {
127
+ }, V = () => {
128
+ z().then(() => {
125
129
  m("aborted", { conversationId: s });
126
130
  });
127
- }, x = () => {
128
- G(), S([]), I(""), p([]), b(null), a({
131
+ }, D = () => {
132
+ J(), x([]), E(""), d([]), M(null), a({
129
133
  eventName: "chat_clear_button_clicked",
130
134
  properties: {
131
135
  conversationId: s
132
136
  }
133
137
  });
134
- }, { openForm: V } = oe(), j = re();
135
- return ee(r.chatFunctionsRef, () => ({
136
- submitMessage: f,
138
+ }, { openForm: j } = ae(), X = ie();
139
+ return se(r.chatFunctionsRef, () => ({
140
+ submitMessage: I,
137
141
  updateInputMessage(e) {
138
- l(e);
142
+ u(e);
139
143
  },
140
- clearChat: x,
144
+ clearChat: D,
141
145
  openForm: (e) => {
142
- j?.setView("chat"), V(e, void 0);
146
+ X?.setView("chat"), j(e, void 0);
143
147
  },
144
148
  focusInput: () => {
145
- _.current?.focus();
149
+ k.current?.focus();
146
150
  }
147
151
  })), {
148
- messages: u,
149
- isLoading: M,
150
- isStreaming: H,
151
- error: q,
152
- setError: h,
153
- isSubmitDisabled: d,
152
+ messages: h,
153
+ isLoading: F,
154
+ isStreaming: B,
155
+ error: G,
156
+ setError: C,
157
+ isSubmitDisabled: v,
154
158
  input: o,
155
- handleInputChange: A,
156
- handleInputKeyDown: J,
157
- handleSubmit: f,
158
- stop: Q,
159
- clear: x,
160
- isEmpty: u.length === 0,
161
- inputRef: _,
159
+ handleInputChange: T,
160
+ handleInputKeyDown: Q,
161
+ handleSubmit: I,
162
+ stop: V,
163
+ clear: D,
164
+ isEmpty: h.length === 0,
165
+ inputRef: k,
162
166
  isMobile: O,
163
167
  // Additional state for attachments and workflow
164
- messageAttachments: W,
165
- setMessageAttachments: p,
166
- selectedWorkflow: $,
167
- setSelectedWorkflow: b,
168
+ messageAttachments: K,
169
+ setMessageAttachments: d,
170
+ selectedWorkflow: U,
171
+ setSelectedWorkflow: M,
168
172
  isNewChat: L,
169
173
  conversationId: s
170
174
  };
171
175
  };
172
176
  export {
173
- ce as DEFAULT_ERROR_MESSAGE,
174
- ye as useInkeepChat
177
+ ue as DEFAULT_ERROR_MESSAGE,
178
+ be as useInkeepChat
175
179
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),E=require("./use-inkeep-chat.cjs");function L(f,u,d){const[p,D]=n.useState([]),[h,w]=n.useState(new Map),[x,T]=n.useState(Date.now()),[A,y]=n.useState(!1),C=n.useRef(0),S=n.useRef(0),R=n.useRef([]),m=n.useRef(h);m.current=h;const b=n.useCallback(()=>{const t=[];let e="",a=[],i=!1;f.length>C.current&&(T(Date.now()),C.current=f.length),S.current=0;const c=new Map,l=(s=!1)=>{if(a.length>0){const r=`group-${S.current++}`,o=m.current.get(r);o?c.set(r,{...o,isCompleted:s}):c.set(r,{isCompleted:s}),t.push({type:"summary-group",summaries:[...a],groupKey:r}),a=[]}};for(const s of f)if(s.type==="text")l(!0),e+=s.text||"";else if(s.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),a.push(s.data);else if(s.type==="data-operation"){e.trim()&&(t.push({type:"text",text:e}),e="");const r=s.data;if(r?.type)switch(r.type){case"agent_initializing":break;case"completion":l(!0);break;case"error":{const o=r.message||"Unknown error";if(console.warn("Data operation error:",o),!t.length)l(!0),d(new Error(o)),i||(t.push({type:"text",text:E.DEFAULT_ERROR_MESSAGE}),i=!0);else{const{type:g,label:v}=r;a.push({type:g,label:v})}break}default:{const{type:o,label:g}=r;a.push({type:o,label:g});break}}}else if(s.type==="data-artifact")if(s.data?.type?.toLowerCase()==="citation"){const r=s.data,o=r.artifactSummary||{title:r.name};e+=` ^${o?.title||r.name}^`}else e.trim()&&(t.push({type:"text",text:e}),e=""),t.push(s);else s.type==="data-component"&&(e.trim()&&(t.push({type:"text",text:e}),e=""),l(!0),t.push(s));return l(!u),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:c}},[f,u,d]);n.useEffect(()=>{if(R.current===f)return;R.current=f;const{processed:t,newTimings:e}=b();D(t),(e.size!==m.current.size||Array.from(e.entries()).some(([i,c])=>{const l=m.current.get(i);return!l||l.isCompleted!==c.isCompleted}))&&w(e)},[b,f]),n.useEffect(()=>{u||w(t=>{const e=new Map(t);let a=!1;for(const[i,c]of e.entries())c.isCompleted||(e.set(i,{...c,isCompleted:!0}),a=!0);return a?e:t})},[u]);const k=n.useCallback(()=>{const t=Date.now()-x,e=Array.from(m.current.values()).some(i=>!i.isCompleted),a=t>1e3&&!e;y(a)},[x]);n.useEffect(()=>{if(!u){y(!1);return}if(!(p.length>0)){y(!1);return}const e=setInterval(k,200);return()=>clearInterval(e)},[u,k,p.length]);const P=n.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:h,shouldShowInitialLoading:P,shouldShowStreamDelayLoading:A}}exports.useStreamProcessor=L;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),E=require("./use-inkeep-chat.cjs");function L(f,u,d){const[p,D]=n.useState([]),[h,w]=n.useState(new Map),[C,T]=n.useState(Date.now()),[A,y]=n.useState(!1),x=n.useRef(0),S=n.useRef(0),R=n.useRef([]),m=n.useRef(h);m.current=h;const b=n.useCallback(()=>{const t=[];let e="",a=[],i=!1;f.length>x.current&&(T(Date.now()),x.current=f.length),S.current=0;const c=new Map,l=(s=!1)=>{if(a.length>0){const r=`group-${S.current++}`,o=m.current.get(r);o?c.set(r,{...o,isCompleted:s}):c.set(r,{isCompleted:s}),t.push({type:"summary-group",summaries:[...a],groupKey:r}),a=[]}};for(const s of f)if(s.type==="text")l(!0),e+=s.text||"";else if(s.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),a.push(s.data);else if(s.type==="data-operation"){e.trim()&&(t.push({type:"text",text:e}),e="");const r=s.data;if(r?.type)switch(r.type){case"agent_initializing":break;case"completion":{const{type:o}=r;a.push({type:o,label:"Completed"}),l(!0);break}case"error":{const o=r.message||"Unknown error";if(console.warn("Data operation error:",o),!t.length)l(!0),d(new Error(o)),i||(t.push({type:"text",text:E.DEFAULT_ERROR_MESSAGE}),i=!0);else{const{type:g,label:v}=r;a.push({type:g,label:v})}break}default:{const{type:o,label:g}=r;a.push({type:o,label:g});break}}}else if(s.type==="data-artifact")if(s.data?.type?.toLowerCase()==="citation"){const r=s.data,o=r.artifactSummary||{title:r.name};e+=` ^${o?.title||r.name}^`}else e.trim()&&(t.push({type:"text",text:e}),e=""),t.push(s);else s.type==="data-component"&&(e.trim()&&(t.push({type:"text",text:e}),e=""),l(!0),t.push(s));return l(!u),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:c}},[f,u,d]);n.useEffect(()=>{if(R.current===f)return;R.current=f;const{processed:t,newTimings:e}=b();D(t),(e.size!==m.current.size||Array.from(e.entries()).some(([i,c])=>{const l=m.current.get(i);return!l||l.isCompleted!==c.isCompleted}))&&w(e)},[b,f]),n.useEffect(()=>{u||w(t=>{const e=new Map(t);let a=!1;for(const[i,c]of e.entries())c.isCompleted||(e.set(i,{...c,isCompleted:!0}),a=!0);return a?e:t})},[u]);const k=n.useCallback(()=>{const t=Date.now()-C,e=Array.from(m.current.values()).some(i=>!i.isCompleted),a=t>1e3&&!e;y(a)},[C]);n.useEffect(()=>{if(!u){y(!1);return}if(!(p.length>0)){y(!1);return}const e=setInterval(k,200);return()=>clearInterval(e)},[u,k,p.length]);const P=n.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:h,shouldShowInitialLoading:P,shouldShowStreamDelayLoading:A}}exports.useStreamProcessor=L;
@@ -1,10 +1,10 @@
1
1
  "use client";
2
- import { useState as m, useRef as h, useCallback as R, useEffect as w, useMemo as z } from "react";
2
+ import { useState as m, useRef as h, useCallback as L, useEffect as w, useMemo as z } from "react";
3
3
  import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
4
4
  function F(l, a, x) {
5
- const [f, b] = m([]), [y, C] = m(/* @__PURE__ */ new Map()), [D, v] = m(Date.now()), [M, g] = m(!1), S = h(0), A = h(0), T = h([]), p = h(y);
5
+ const [f, R] = m([]), [y, C] = m(/* @__PURE__ */ new Map()), [D, v] = m(Date.now()), [M, g] = m(!1), S = h(0), A = h(0), T = h([]), p = h(y);
6
6
  p.current = y;
7
- const k = R(() => {
7
+ const b = L(() => {
8
8
  const e = [];
9
9
  let t = "", n = [], i = !1;
10
10
  l.length > S.current && (v(Date.now()), S.current = l.length), A.current = 0;
@@ -35,9 +35,11 @@ function F(l, a, x) {
35
35
  switch (r.type) {
36
36
  case "agent_initializing":
37
37
  break;
38
- case "completion":
39
- u(!0);
38
+ case "completion": {
39
+ const { type: o } = r;
40
+ n.push({ type: o, label: "Completed" }), u(!0);
40
41
  break;
42
+ }
41
43
  case "error": {
42
44
  const o = r.message || "Unknown error";
43
45
  if (console.warn("Data operation error:", o), !e.length)
@@ -69,12 +71,12 @@ function F(l, a, x) {
69
71
  if (T.current === l)
70
72
  return;
71
73
  T.current = l;
72
- const { processed: e, newTimings: t } = k();
73
- b(e), (t.size !== p.current.size || Array.from(t.entries()).some(([i, c]) => {
74
+ const { processed: e, newTimings: t } = b();
75
+ R(e), (t.size !== p.current.size || Array.from(t.entries()).some(([i, c]) => {
74
76
  const u = p.current.get(i);
75
77
  return !u || u.isCompleted !== c.isCompleted;
76
78
  })) && C(t);
77
- }, [k, l]), w(() => {
79
+ }, [b, l]), w(() => {
78
80
  a || C((e) => {
79
81
  const t = new Map(e);
80
82
  let n = !1;
@@ -86,7 +88,7 @@ function F(l, a, x) {
86
88
  return n ? t : e;
87
89
  });
88
90
  }, [a]);
89
- const L = R(() => {
91
+ const k = L(() => {
90
92
  const e = Date.now() - D, t = Array.from(p.current.values()).some(
91
93
  (i) => !i.isCompleted
92
94
  ), n = e > 1e3 && !t;
@@ -101,9 +103,9 @@ function F(l, a, x) {
101
103
  g(!1);
102
104
  return;
103
105
  }
104
- const t = setInterval(L, 200);
106
+ const t = setInterval(k, 200);
105
107
  return () => clearInterval(t);
106
- }, [a, L, f.length]);
108
+ }, [a, k, f.length]);
107
109
  const P = z(() => !!(!(f.length > 0) && a), [f.length, a]);
108
110
  return {
109
111
  processedParts: f,
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.3",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.5",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
@@ -5,7 +5,7 @@ import { useInkeepConfig as g } from "./config-provider.js";
5
5
  const a = d(void 0), P = ({ children: e }) => {
6
6
  const { baseSettings: t, componentType: o } = g(), { tags: s, analyticsProperties: n } = t, r = u(
7
7
  () => ({
8
- widgetLibraryVersion: "0.15.3",
8
+ widgetLibraryVersion: "0.15.5",
9
9
  componentType: o,
10
10
  tags: s
11
11
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-ui",
3
- "version": "0.15.4",
3
+ "version": "0.15.6",
4
4
  "description": "",
5
5
  "homepage": "",
6
6
  "repository": {