@inkeep/agents-ui 0.0.0-dev-20260721224224 → 0.0.0-dev-20260804222744
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/primitives/atoms/markdown/index.cjs +1 -1
- package/dist/primitives/atoms/markdown/index.d.ts +14 -2
- package/dist/primitives/atoms/markdown/index.js +105 -99
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +66 -60
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +1 -1
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +279 -261
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),f=require("react-markdown"),y=require("rehype-raw"),g=require("remark-gfm"),b=require("remark-supersub"),S=require("../../providers/markdown-provider.cjs"),q=require("../codeblock/index.cjs"),t=require("./components.cjs"),P=require("./rehype-inline-code-property.cjs");const C=[[g,{singleTilde:!1}],b],v=[y,P.rehypeInlineCodeProperty],j=l.memo(function({children:u,componentStyles:k,shouldOpenLinksInNewTab:c,onLinkClick:d,onCodeCopy:h,artifacts:m,...p}){const M=l.useMemo(()=>({h1:({children:r})=>e.jsx(t.MarkdownH1,{children:r}),h2:({children:r})=>e.jsx(t.MarkdownH2,{children:r}),p:({children:r})=>e.jsx(t.MarkdownP,{children:r}),li:({children:r})=>e.jsx(t.MarkdownLi,{children:r}),ul:({children:r})=>e.jsx(t.MarkdownUl,{children:r}),hr:()=>e.jsx(t.MarkdownHr,{}),input:({type:r,checked:o,disabled:n,readOnly:s,required:a,value:i})=>e.jsx(t.MarkdownInput,{type:r,checked:o,disabled:n,readOnly:s,required:a,value:i}),ol:({children:r,node:o})=>{const n=o?.properties?.start,s=typeof n=="number"?n:void 0;return e.jsx(t.MarkdownOl,{style:{"--start":n?.toString()??"0"},start:s,children:r})},a:({children:r,href:o})=>{const n=l.Children.toArray(r),s=n[0],a=typeof s=="string"&&/^\(\d+\)$/.test(s)&&n.length===1,i=a?s.match(/\d+/):r,x=e.jsx(t.MarkdownLink,{isExternal:c,href:o,onClick:()=>{d?.(o,i?.toString())},children:i});return a?e.jsx(t.MarkdownSourceLink,{children:x}):x},img:({src:r,alt:o})=>e.jsx(t.MarkdownImg,{src:r,alt:o}),table:({children:r})=>e.jsx(t.MarkdownTable,{children:r}),th:({children:r,isHeader:o})=>o?e.jsx(t.MarkdownTh,{children:r}):e.jsx(t.MarkdownTd,{children:r}),pre:({children:r})=>e.jsx("pre",{children:r}),code:({children:r,inline:o,className:n})=>o?e.jsx(t.MarkdownCode,{children:r}):e.jsx(q.CodeBlock,{className:n,onCopy:h,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 o=m?.find(n=>(n.data?.artifactSummary?.title||n.data?.name)===r);if(o){const n=o.data,s=n?.artifactSummary?.url,a=n?.artifactSummary?.title;if(!s)return null;const i=a||n?.name||r;return e.jsx(t.MarkdownSup,{children:e.jsx(t.MarkdownLink,{href:s,isExternal:c,onClick:()=>d?.(s,i),children:e.jsx("span",{children:i})})})}}return e.jsx("sup",{children:r})}}),[c,d,h,m]);if(!u)return null;const w=e.jsx(f,{remarkPlugins:C,rehypePlugins:v,components:M,disallowedElements:R,children:u.toString(),...p});return e.jsx(S.ChatMarkdownProvider,{componentStyles:k,children:w})});j.displayName="Markdown";const R=["script","iframe","frame","embed","meta","base","form","style","object"];exports.Markdown=j;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { default as React } from 'react';
|
|
2
2
|
import { CodeProps } from '../codeblock';
|
|
3
3
|
import { MarkdownComponentID } from '../../utils/component-ids';
|
|
4
4
|
import { ArtifactPart } from '../../../types/index.ts';
|
|
@@ -14,4 +14,16 @@ export interface MarkdownProps {
|
|
|
14
14
|
onLinkClick?: (href: string | undefined, label: string | undefined) => void;
|
|
15
15
|
artifacts?: ArtifactPart[];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* react-markdown does no memoization of its own: it builds a fresh unified
|
|
19
|
+
* processor and runs a full parse + rehype pass in its render body on every
|
|
20
|
+
* render (rehype-raw in particular re-serializes and re-parses the tree). In a
|
|
21
|
+
* streaming chat that means every already-complete message re-parses its whole
|
|
22
|
+
* body on every token, so cost grows with conversation length.
|
|
23
|
+
*
|
|
24
|
+
* `memo` is what prevents that: messages that are not currently streaming pass
|
|
25
|
+
* an unchanged `text` and memoized callbacks, so they bail out before any
|
|
26
|
+
* parsing happens. Keep the props passed here referentially stable at the call
|
|
27
|
+
* site or the memo is defeated and the parse comes back.
|
|
28
|
+
*/
|
|
29
|
+
export declare const Markdown: React.NamedExoticComponent<React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & MarkdownProps>;
|
|
@@ -1,113 +1,119 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import g from "react";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { ChatMarkdownProvider as
|
|
8
|
-
import { CodeBlock as
|
|
9
|
-
import { MarkdownSup as
|
|
10
|
-
import { rehypeInlineCodeProperty as
|
|
11
|
-
const
|
|
12
|
-
children:
|
|
13
|
-
componentStyles:
|
|
14
|
-
shouldOpenLinksInNewTab:
|
|
1
|
+
import { jsx as t, jsxs as w, Fragment as y } from "react/jsx-runtime";
|
|
2
|
+
import g, { memo as b, useMemo as S } from "react";
|
|
3
|
+
import x from "react-markdown";
|
|
4
|
+
import C from "rehype-raw";
|
|
5
|
+
import P from "remark-gfm";
|
|
6
|
+
import j from "remark-supersub";
|
|
7
|
+
import { ChatMarkdownProvider as E } from "../../providers/markdown-provider.js";
|
|
8
|
+
import { CodeBlock as H } from "../codeblock/index.js";
|
|
9
|
+
import { MarkdownSup as R, MarkdownLink as h, MarkdownCode as v, MarkdownTh as A, MarkdownTd as T, MarkdownTable as W, MarkdownImg as _, MarkdownSourceLink as B, MarkdownOl as D, MarkdownInput as F, MarkdownHr as G, MarkdownUl as I, MarkdownLi as U, MarkdownP as V, MarkdownH2 as $, MarkdownH1 as q } from "./components.js";
|
|
10
|
+
import { rehypeInlineCodeProperty as z } from "./rehype-inline-code-property.js";
|
|
11
|
+
const J = [[P, { singleTilde: !1 }], j], K = [C, z], Q = b(function({
|
|
12
|
+
children: l,
|
|
13
|
+
componentStyles: f,
|
|
14
|
+
shouldOpenLinksInNewTab: d,
|
|
15
15
|
onLinkClick: c,
|
|
16
|
-
onCodeCopy:
|
|
17
|
-
artifacts:
|
|
16
|
+
onCodeCopy: s,
|
|
17
|
+
artifacts: m,
|
|
18
18
|
...p
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
type: r,
|
|
32
|
-
checked: e,
|
|
33
|
-
disabled: n,
|
|
34
|
-
readOnly: o,
|
|
35
|
-
required: a,
|
|
36
|
-
value: i
|
|
37
|
-
}
|
|
38
|
-
),
|
|
39
|
-
ol: ({ children: r, node: e }) => {
|
|
40
|
-
const n = e?.properties?.start, o = typeof n == "number" ? n : void 0;
|
|
41
|
-
return /* @__PURE__ */ t(
|
|
42
|
-
W,
|
|
43
|
-
{
|
|
44
|
-
style: {
|
|
45
|
-
"--start": n?.toString() ?? "0"
|
|
46
|
-
},
|
|
47
|
-
start: o,
|
|
48
|
-
children: r
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
a: ({ children: r, href: e }) => {
|
|
53
|
-
const n = g.Children.toArray(r), o = n[0], a = typeof o == "string" && /^\(\d+\)$/.test(o) && n.length === 1, i = a ? o.match(/\d+/) : r, s = /* @__PURE__ */ t(
|
|
54
|
-
m,
|
|
19
|
+
}) {
|
|
20
|
+
const k = S(
|
|
21
|
+
() => ({
|
|
22
|
+
h1: ({ children: r }) => /* @__PURE__ */ t(q, { children: r }),
|
|
23
|
+
h2: ({ children: r }) => /* @__PURE__ */ t($, { children: r }),
|
|
24
|
+
p: ({ children: r }) => /* @__PURE__ */ t(V, { children: r }),
|
|
25
|
+
li: ({ children: r }) => /* @__PURE__ */ t(U, { children: r }),
|
|
26
|
+
ul: ({ children: r }) => /* @__PURE__ */ t(I, { children: r }),
|
|
27
|
+
hr: () => /* @__PURE__ */ t(G, {}),
|
|
28
|
+
input: ({ type: r, checked: e, disabled: n, readOnly: o, required: a, value: i }) => /* @__PURE__ */ t(
|
|
29
|
+
F,
|
|
55
30
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
31
|
+
type: r,
|
|
32
|
+
checked: e,
|
|
33
|
+
disabled: n,
|
|
34
|
+
readOnly: o,
|
|
35
|
+
required: a,
|
|
36
|
+
value: i
|
|
62
37
|
}
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
] }) : /* @__PURE__ */ t("sub", { children: r }),
|
|
76
|
-
sup: ({ children: r }) => {
|
|
77
|
-
if (r && typeof r == "string") {
|
|
78
|
-
const e = f?.find(
|
|
79
|
-
(n) => (n.data?.artifactSummary?.title || n.data?.name) === r
|
|
38
|
+
),
|
|
39
|
+
ol: ({ children: r, node: e }) => {
|
|
40
|
+
const n = e?.properties?.start, o = typeof n == "number" ? n : void 0;
|
|
41
|
+
return /* @__PURE__ */ t(
|
|
42
|
+
D,
|
|
43
|
+
{
|
|
44
|
+
style: {
|
|
45
|
+
"--start": n?.toString() ?? "0"
|
|
46
|
+
},
|
|
47
|
+
start: o,
|
|
48
|
+
children: r
|
|
49
|
+
}
|
|
80
50
|
);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
51
|
+
},
|
|
52
|
+
a: ({ children: r, href: e }) => {
|
|
53
|
+
const n = g.Children.toArray(r), o = n[0], a = typeof o == "string" && /^\(\d+\)$/.test(o) && n.length === 1, i = a ? o.match(/\d+/) : r, u = /* @__PURE__ */ t(
|
|
54
|
+
h,
|
|
55
|
+
{
|
|
56
|
+
isExternal: d,
|
|
57
|
+
href: e,
|
|
58
|
+
onClick: () => {
|
|
59
|
+
c?.(e, i?.toString());
|
|
60
|
+
},
|
|
61
|
+
children: i
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
return a ? /* @__PURE__ */ t(B, { children: u }) : u;
|
|
65
|
+
},
|
|
66
|
+
img: ({ src: r, alt: e }) => /* @__PURE__ */ t(_, { src: r, alt: e }),
|
|
67
|
+
table: ({ children: r }) => /* @__PURE__ */ t(W, { children: r }),
|
|
68
|
+
th: ({ children: r, isHeader: e }) => e ? /* @__PURE__ */ t(A, { 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(v, { children: r }) : /* @__PURE__ */ t(H, { className: n, onCopy: s, children: r }),
|
|
71
|
+
sub: ({ children: r }) => typeof r == "string" && (r.startsWith(" ") || r.endsWith(" ")) ? /* @__PURE__ */ w(y, { children: [
|
|
72
|
+
"~",
|
|
73
|
+
r,
|
|
74
|
+
"~"
|
|
75
|
+
] }) : /* @__PURE__ */ t("sub", { children: r }),
|
|
76
|
+
sup: ({ children: r }) => {
|
|
77
|
+
if (r && typeof r == "string") {
|
|
78
|
+
const e = m?.find(
|
|
79
|
+
(n) => (n.data?.artifactSummary?.title || n.data?.name) === r
|
|
80
|
+
);
|
|
81
|
+
if (e) {
|
|
82
|
+
const n = e.data, o = n?.artifactSummary?.url, a = n?.artifactSummary?.title;
|
|
83
|
+
if (!o) return null;
|
|
84
|
+
const i = a || n?.name || r;
|
|
85
|
+
return /* @__PURE__ */ t(R, { children: /* @__PURE__ */ t(
|
|
86
|
+
h,
|
|
87
|
+
{
|
|
88
|
+
href: o,
|
|
89
|
+
isExternal: d,
|
|
90
|
+
onClick: () => c?.(o, i),
|
|
91
|
+
children: /* @__PURE__ */ t("span", { children: i })
|
|
92
|
+
}
|
|
93
|
+
) });
|
|
94
|
+
}
|
|
94
95
|
}
|
|
96
|
+
return /* @__PURE__ */ t("sup", { children: r });
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
}),
|
|
99
|
+
[d, c, s, m]
|
|
100
|
+
);
|
|
101
|
+
if (!l) return null;
|
|
102
|
+
const M = /* @__PURE__ */ t(
|
|
103
|
+
x,
|
|
100
104
|
{
|
|
101
|
-
remarkPlugins:
|
|
102
|
-
rehypePlugins:
|
|
105
|
+
remarkPlugins: J,
|
|
106
|
+
rehypePlugins: K,
|
|
103
107
|
components: k,
|
|
104
|
-
disallowedElements:
|
|
105
|
-
children:
|
|
108
|
+
disallowedElements: X,
|
|
109
|
+
children: l.toString(),
|
|
106
110
|
...p
|
|
107
111
|
}
|
|
108
112
|
);
|
|
109
|
-
return /* @__PURE__ */ t(
|
|
110
|
-
}
|
|
113
|
+
return /* @__PURE__ */ t(E, { componentStyles: f, children: M });
|
|
114
|
+
});
|
|
115
|
+
Q.displayName = "Markdown";
|
|
116
|
+
const X = [
|
|
111
117
|
"script",
|
|
112
118
|
"iframe",
|
|
113
119
|
"frame",
|
|
@@ -119,5 +125,5 @@ const rr = ({
|
|
|
119
125
|
"object"
|
|
120
126
|
];
|
|
121
127
|
export {
|
|
122
|
-
|
|
128
|
+
Q as Markdown
|
|
123
129
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Xe=require("@ai-sdk/react"),Ze=require("./file-upload-input.cjs"),et=require("ai"),t=require("react"),tt=require("../../providers/config-provider.cjs"),st=require("../../providers/chat-auth-provider.cjs"),rt=require("../../hooks/use-media-query.cjs"),nt=require("../../hooks/use-conversation-loader.cjs"),at=require("../../hooks/use-initial-conversation.cjs"),
|
|
2
|
-
`)??"";t.useEffect(()=>{E.current=T?.length?T:void 0},[xe]);const ve=t.useRef(ge);ve.current=ge;const z=t.useRef(void 0);z.current=ne||de?JSON.stringify({...ne,...de}):void 0;const qe=e=>{if(s.isNetworkError(e))return N.current?.files?.length?s.NETWORK_ERROR_WITH_FILES_MESSAGE:s.NETWORK_ERROR_MESSAGE;switch(s.resolveHttpStatusCode(e)){case 400:try{const r=JSON.parse(e.message??"");return r.detail??r.error?.message??s.RECOVERABLE_FALLBACK_MESSAGE}catch{return e.message?.trim()||s.RECOVERABLE_FALLBACK_MESSAGE}case 401:return oe?"Authentication failed. Please try again.":s.DEFAULT_ERROR_MESSAGE;case 403:return`There seems to be a configuration error. Please contact ${se.organizationDisplayName??"Administrator"}`;case 413:return s.PAYLOAD_TOO_LARGE_MESSAGE;case 429:return s.RATE_LIMIT_MESSAGE;default:return s.DEFAULT_ERROR_MESSAGE}},[A,V]=t.useState([]),Be=t.useMemo(()=>new et.DefaultChatTransport({api:me,headers:()=>{const e=U??$.current??G.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),"x-inkeep-invocation-type":"chat_widget",...L?{"x-inkeep-app-id":L}:{},...e?{Authorization:`Bearer ${e}`}:{},...z.current?{"inkeep-filters":z.current}:{},...ve.current}},prepareSendMessagesRequest:async e=>{const l=await he.current(),r=e.messages[e.messages.length-1];return r||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:r?[r]:[],trigger:e.trigger,messageId:e.messageId,...K.current?{userProperties:K.current}:{},...H.current?{properties:H.current}:{}},headers:{...e.headers,...l}}},body:{requestContext:pe}}),[me,pe,L,U]),{messages:M,sendMessage:Y,addToolApprovalResponse:j,status:Se,setMessages:h,stop:P,error:x}=Xe.useChat({transport:Be,onData(e){k(e.type,e.data)},async onFinish({message:e}){k("completion",{conversationId:u}),await m({eventName:"assistant_message_received",properties:{conversationId:u,messageId:e.id}}),m({eventName:"assistant_answer_displayed",properties:{conversationId:u,messageId:e.id}})},onError(e){console.error("onError",{code:e.code,message:e.message});const l=ke||U?null:s.resolveStreamingAuthError(e);if(l!==null&&y.current<1){y.current++;const i=W.current,a=N.current;(async()=>{if(l==="session"&&oe){const o=await ie();if(!o)throw new Error("Auth token refresh failed");$.current=o}else if(l==="session"){const o=await ue();o&&(G.current=o)}else f();if(i){j(i);return}a&&(h(o=>{let c=[...o];return c.at(-1)?.role==="assistant"&&(c=c.slice(0,-1)),c.at(-1)?.role==="user"&&(c=c.slice(0,-1)),c}),Y({id:a.messageId,parts:[...a.content.trim()?[{type:"text",text:a.content}]:[],...a.files??[]]},{body:a.body}))})().catch(()=>{y.current=0,f(),h(o=>{const c=[...o],g=c[c.length-1];if(!g)return c;const d=s.DEFAULT_ERROR_MESSAGE;return g.role==="user"?c.push({id:
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Xe=require("@ai-sdk/react"),Ze=require("./file-upload-input.cjs"),et=require("ai"),t=require("react"),tt=require("../../providers/config-provider.cjs"),st=require("../../providers/chat-auth-provider.cjs"),rt=require("../../hooks/use-media-query.cjs"),nt=require("../../hooks/use-conversation-loader.cjs"),at=require("../../hooks/use-initial-conversation.cjs"),w=require("../../utils/generate-uid.cjs"),ot=require("../../providers/base-events-provider.cjs"),it=require("../../providers/chat-form-provider.cjs"),ct=require("../../providers/widget-provider.cjs"),ut=require("@radix-ui/react-use-controllable-state"),lt=require("../../hooks/use-streaming-events.cjs"),dt=require("../../hooks/use-input-notification.cjs"),s=require("./chat-error-helpers.cjs"),ft=50,pt=()=>{const{baseSettings:se,aiChatSettings:R}=tt.useInkeepConfig(),[u="",v]=ut.useControllableState({prop:R.conversationIdOverride,defaultProp:R.conversationIdOverride??""}),{logEvent:m}=ot.useBaseEvents(),{setConversationId:Oe,emitToParent:k}=lt.useStreamingEvents(),re=t.useRef(u);t.useEffect(()=>{const e=re.current;re.current=u,e!==u&&m({eventName:"chat_conversation_changed",properties:{conversationId:u,previousConversationId:e}})},[u,m]);const[I,C]=t.useState(""),we=e=>C(e.target.value),{shouldBypassCaptcha:ke,filters:ne,userProperties:B,analyticsProperties:D}=se,{authToken:ae,isAuthenticated:S,isAuthConfigured:oe,refreshAuthToken:ie,sessionToken:ce,refreshSession:ue,getCaptchaHeader:F,invalidateCaptcha:f,effectiveAuthToken:le,applicableRefreshSession:Fe}=st.useChatAuth(),{onInputMessageChange:Le,filters:de,baseUrl:fe,agentUrl:Ne,context:pe,headers:ge,appId:L,apiKey:U,files:T}=R,he=t.useRef(F);he.current=F;const me=Ne||`${fe}/run/api/chat`,{loadConversation:Ee}=nt.useConversationLoader({baseUrl:fe,appId:L,authToken:le,getCaptchaHeader:F,invalidateCaptcha:f,refreshSession:Fe}),[Pe,Re]=t.useState(!1),G=t.useRef(null);G.current=ce;const $=t.useRef(null);$.current=ae;const K=t.useRef(void 0);K.current=B&&Object.keys(B).length>0?B:void 0;const H=t.useRef(void 0);H.current=D&&Object.keys(D).length>0?D:void 0;const y=t.useRef(0),N=t.useRef(null),W=t.useRef(null),E=t.useRef(void 0),xe=T?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
2
|
+
`)??"";t.useEffect(()=>{E.current=T?.length?T:void 0},[xe]);const ve=t.useRef(ge);ve.current=ge;const z=t.useRef(void 0);z.current=ne||de?JSON.stringify({...ne,...de}):void 0;const qe=e=>{if(s.isNetworkError(e))return N.current?.files?.length?s.NETWORK_ERROR_WITH_FILES_MESSAGE:s.NETWORK_ERROR_MESSAGE;switch(s.resolveHttpStatusCode(e)){case 400:try{const r=JSON.parse(e.message??"");return r.detail??r.error?.message??s.RECOVERABLE_FALLBACK_MESSAGE}catch{return e.message?.trim()||s.RECOVERABLE_FALLBACK_MESSAGE}case 401:return oe?"Authentication failed. Please try again.":s.DEFAULT_ERROR_MESSAGE;case 403:return`There seems to be a configuration error. Please contact ${se.organizationDisplayName??"Administrator"}`;case 413:return s.PAYLOAD_TOO_LARGE_MESSAGE;case 429:return s.RATE_LIMIT_MESSAGE;default:return s.DEFAULT_ERROR_MESSAGE}},[A,V]=t.useState([]),Be=t.useMemo(()=>new et.DefaultChatTransport({api:me,headers:()=>{const e=U??$.current??G.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),"x-inkeep-invocation-type":"chat_widget",...L?{"x-inkeep-app-id":L}:{},...e?{Authorization:`Bearer ${e}`}:{},...z.current?{"inkeep-filters":z.current}:{},...ve.current}},prepareSendMessagesRequest:async e=>{const l=await he.current(),r=e.messages[e.messages.length-1];return r||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:r?[r]:[],trigger:e.trigger,messageId:e.messageId,...K.current?{userProperties:K.current}:{},...H.current?{properties:H.current}:{}},headers:{...e.headers,...l}}},body:{requestContext:pe}}),[me,pe,L,U]),{messages:M,sendMessage:Y,addToolApprovalResponse:j,status:Se,setMessages:h,stop:P,error:x}=Xe.useChat({transport:Be,experimental_throttle:ft,onData(e){k(e.type,e.data)},async onFinish({message:e}){k("completion",{conversationId:u}),await m({eventName:"assistant_message_received",properties:{conversationId:u,messageId:e.id}}),m({eventName:"assistant_answer_displayed",properties:{conversationId:u,messageId:e.id}})},onError(e){console.error("onError",{code:e.code,message:e.message});const l=ke||U?null:s.resolveStreamingAuthError(e);if(l!==null&&y.current<1){y.current++;const i=W.current,a=N.current;(async()=>{if(l==="session"&&oe){const o=await ie();if(!o)throw new Error("Auth token refresh failed");$.current=o}else if(l==="session"){const o=await ue();o&&(G.current=o)}else f();if(i){j(i);return}a&&(h(o=>{let c=[...o];return c.at(-1)?.role==="assistant"&&(c=c.slice(0,-1)),c.at(-1)?.role==="user"&&(c=c.slice(0,-1)),c}),Y({id:a.messageId,parts:[...a.content.trim()?[{type:"text",text:a.content}]:[],...a.files??[]]},{body:a.body}))})().catch(()=>{y.current=0,f(),h(o=>{const c=[...o],g=c[c.length-1];if(!g)return c;const d=s.DEFAULT_ERROR_MESSAGE;return g.role==="user"?c.push({id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:d}]}):g.parts=[{type:"text",text:d}],c})});return}y.current=0,l!==null&&f();const r=s.isRecoverableError(e)||s.isNetworkError(e),n=qe(e);if(m({eventName:"chat_error",properties:{conversationId:u,messageId:M.at(-1)?.id,error:e.message}}),r){const i=n===s.PAYLOAD_TOO_LARGE_MESSAGE?"Message too large":n===s.RATE_LIMIT_MESSAGE?"Rate limit reached":n===s.NETWORK_ERROR_MESSAGE||n===s.NETWORK_ERROR_WITH_FILES_MESSAGE?"Connection error":"Request failed";q({title:i,message:n},s.RECOVERABLE_NOTIFICATION_DURATION_MS),h(p=>{let o=[...p];return o.at(-1)?.role==="assistant"&&(o=o.slice(0,-1)),o.at(-1)?.role==="user"&&(o=o.slice(0,-1)),o});const a=N.current?.content;a&&C(a),Z.current=e;return}h(i=>{const a=[...i],p=a[a.length-1];return p&&(p.role==="user"?a.push({id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:n}]}):p.parts=[{type:"text",text:n}]),a})}}),ye=t.useRef(S);t.useEffect(()=>{const e=ye.current;ye.current=S,e!==S&&(P(),b(null),h([]),v(""),C(""),V([]),f())},[S,P,h,v,f]);const Ae=Se==="submitted",Q=Se==="streaming",De=t.useMemo(()=>{const e=i=>{if(!i||typeof i!="object")return!1;const a=i;return typeof a.type=="string"&&a.type.startsWith("tool-")},r=[...M??[]].reverse().find(i=>i.role==="assistant");if(!r)return!1;const n=r.parts?.at(-1);return!(!e(n)||n.state!=="output-available"||!n.approval?.id||Q)},[M,Q]),[Ue,J]=t.useState(!1),_e=Q||De&&!Ue,Ie=Ae||_e,Ge=M.length===0,X=!I.trim()&&A.length===0||Ie,$e=rt.useMediaQuery("(max-width: 768px)"),[Ke,b]=t.useState(null),Z=t.useRef(null);t.useEffect(()=>{if(x){if(Z.current===x){Z.current=null;return}b(x)}},[x]);const He=()=>b(null),{inputNotification:We,showInputNotification:q,clearInputNotification:ze}=dt.useInputNotification(),Ce=t.useRef(null);t.useEffect(()=>{Le?.(I)},[I]);const Ve=e=>{e.key==="Enter"&&!e.shiftKey&&!X&&!e.nativeEvent.isComposing&&(e.preventDefault(),ee())},ee=async(e=I)=>{if(X&&(!e||e.trim().length===0)&&A.length===0||!e.trim()&&!A.length&&!E.current?.length)return;if(s.estimateRequestBodyBytes({text:e,rawFileBytes:A.reduce((g,d)=>g+d.size,0),encodedPartsBytes:(E.current??[]).reduce((g,d)=>g+d.url.length,0)})>s.MAX_REQUEST_BODY_BYTES){q({title:"Message too large",message:s.PAYLOAD_TOO_LARGE_MESSAGE},s.RECOVERABLE_NOTIFICATION_DURATION_MS);return}const r=A;V([]),C(""),y.current=0,W.current=null,J(!1);let n=u;n||(n=`conv_${w.generateUid(16)}`,v(n));const i=w.generateUid(21);Oe(n),await m({eventName:"user_message_submitted",properties:{conversationId:n,messageId:i}});const a=E.current;E.current=void 0;let p=[];if(r.length>0)try{p=await Promise.all(r.map(g=>{const d=Ze.normalizeFileType(g);return new Promise((Je,be)=>{const O=new FileReader;O.onload=()=>{if(typeof O.result!="string"){be(new Error(`Failed to read file "${d.name}"`));return}Je({type:"file",url:O.result,mediaType:d.type,filename:d.name})},O.onerror=()=>be(new Error(`Failed to read file "${d.name}"`)),O.readAsDataURL(d)})}))}catch{q({title:"Failed to attach files",message:"Could not read one or more files. Please try again."});return}const o=p.length||a?.length?[...p,...a??[]]:void 0,c=[...e.trim()?[{type:"text",text:e}]:[],...o??[]];N.current={content:e,messageId:i,body:{conversationId:n},files:o},Y({id:i,parts:c},{body:{conversationId:n}})},Ye=t.useCallback(e=>{y.current=0,W.current=e,J(!1),j(e)},[j]),te=t.useCallback(()=>{J(!0),P().then(()=>{k("aborted",{conversationId:u})})},[P,u,k]),Te=()=>{He(),h([]),v(""),f(),E.current=T?.length?T:void 0,m({eventName:"chat_clear_button_clicked",properties:{conversationId:u}})},_=t.useCallback((e,l)=>{b(null),h(l),v(e),f(),E.current=void 0},[h,v,f]),Me=t.useCallback(async(e,l)=>{te(),_(e,[]),Re(!0);try{const r=await Ee(e,l);if(r===null)return!1;const i=r[r.length-1]?.role==="user"?[...r,{id:w.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:r;return _(e,i),!0}finally{l?.aborted||Re(!1)}},[_,Ee,te]);at.useInitialConversation({conversationId:R.conversationId,fetchedConversation:R.fetchedConversation,effectiveAuthToken:le,restoreSession:_,loadAndRestoreSession:Me,onLoadFailed:()=>_("",[])});const{openForm:je}=it.useChatForm(),Qe=ct.useWidget();return t.useImperativeHandle(R.chatFunctionsRef,()=>({submitMessage:ee,updateInputMessage(e){C(e)},clearChat:Te,openForm:e=>{Qe?.setView("chat"),je(e,void 0)},focusInput:()=>{Ce.current?.focus()}})),{messages:M,sendMessage:Y,addToolApprovalResponse:Ye,isLoading:Ae,isStreaming:_e,isBusy:Ie,error:Ke,setError:b,isSubmitDisabled:X,input:I,handleInputChange:we,handleInputKeyDown:Ve,handleSubmit:ee,stop:te,clear:Te,inputRef:Ce,isMobile:$e,files:A,setFiles:V,isNewChat:Ge,conversationId:u,restoreSession:_,loadAndRestoreSession:Me,isSessionLoading:Pe,authToken:S?ae:ce,refreshSession:S?ie:ue,getCaptchaHeader:F,invalidateCaptcha:f,inputNotification:We,showInputNotification:q,clearInputNotification:ze}};exports.useInkeepChat=pt;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useChat as lt } from "@ai-sdk/react";
|
|
3
3
|
import { normalizeFileType as ut } from "./file-upload-input.js";
|
|
4
4
|
import { DefaultChatTransport as dt } from "ai";
|
|
5
|
-
import { useRef as i, useEffect as
|
|
5
|
+
import { useRef as i, useEffect as b, useState as k, useMemo as Oe, useCallback as $, useImperativeHandle as pt } from "react";
|
|
6
6
|
import { useInkeepConfig as ft } from "../../providers/config-provider.js";
|
|
7
7
|
import { useChatAuth as mt } from "../../providers/chat-auth-provider.js";
|
|
8
8
|
import { useMediaQuery as gt } from "../../hooks/use-media-query.js";
|
|
@@ -12,16 +12,16 @@ import { generateUid as F } from "../../utils/generate-uid.js";
|
|
|
12
12
|
import { useBaseEvents as yt } from "../../providers/base-events-provider.js";
|
|
13
13
|
import { useChatForm as Rt } from "../../providers/chat-form-provider.js";
|
|
14
14
|
import { useWidget as Et } from "../../providers/widget-provider.js";
|
|
15
|
-
import { useControllableState as
|
|
16
|
-
import { useStreamingEvents as
|
|
15
|
+
import { useControllableState as St } from "@radix-ui/react-use-controllable-state";
|
|
16
|
+
import { useStreamingEvents as It } from "../../hooks/use-streaming-events.js";
|
|
17
17
|
import { useInputNotification as Ct } from "../../hooks/use-input-notification.js";
|
|
18
|
-
import { resolveStreamingAuthError as At, DEFAULT_ERROR_MESSAGE as ne, isRecoverableError as Tt, isNetworkError as Ne, RECOVERABLE_NOTIFICATION_DURATION_MS as Pe, PAYLOAD_TOO_LARGE_MESSAGE as oe, RATE_LIMIT_MESSAGE as Be, NETWORK_ERROR_MESSAGE as De, NETWORK_ERROR_WITH_FILES_MESSAGE as Le, resolveHttpStatusCode as
|
|
19
|
-
const
|
|
20
|
-
const { baseSettings: ae, aiChatSettings: v } = ft(), [c = "", y] =
|
|
18
|
+
import { resolveStreamingAuthError as At, DEFAULT_ERROR_MESSAGE as ne, isRecoverableError as Tt, isNetworkError as Ne, RECOVERABLE_NOTIFICATION_DURATION_MS as Pe, PAYLOAD_TOO_LARGE_MESSAGE as oe, RATE_LIMIT_MESSAGE as Be, NETWORK_ERROR_MESSAGE as De, NETWORK_ERROR_WITH_FILES_MESSAGE as Le, resolveHttpStatusCode as _t, RECOVERABLE_FALLBACK_MESSAGE as $e, estimateRequestBodyBytes as wt, MAX_REQUEST_BODY_BYTES as Mt } from "./chat-error-helpers.js";
|
|
19
|
+
const bt = 50, jt = () => {
|
|
20
|
+
const { baseSettings: ae, aiChatSettings: v } = ft(), [c = "", y] = St({
|
|
21
21
|
prop: v.conversationIdOverride,
|
|
22
22
|
defaultProp: v.conversationIdOverride ?? ""
|
|
23
|
-
}), { logEvent: g } = yt(), { setConversationId: Ue, emitToParent: x } =
|
|
24
|
-
|
|
23
|
+
}), { logEvent: g } = yt(), { setConversationId: Ue, emitToParent: x } = It(), ie = i(c);
|
|
24
|
+
b(() => {
|
|
25
25
|
const e = ie.current;
|
|
26
26
|
ie.current = c, e !== c && g({
|
|
27
27
|
eventName: "chat_conversation_changed",
|
|
@@ -32,7 +32,7 @@ const Wt = () => {
|
|
|
32
32
|
});
|
|
33
33
|
}, [c, g]);
|
|
34
34
|
const [C, A] = k(""), Ge = (e) => A(e.target.value), {
|
|
35
|
-
shouldBypassCaptcha:
|
|
35
|
+
shouldBypassCaptcha: He,
|
|
36
36
|
filters: ce,
|
|
37
37
|
userProperties: U,
|
|
38
38
|
analyticsProperties: G
|
|
@@ -46,30 +46,30 @@ const Wt = () => {
|
|
|
46
46
|
getCaptchaHeader: O,
|
|
47
47
|
invalidateCaptcha: d,
|
|
48
48
|
effectiveAuthToken: me,
|
|
49
|
-
applicableRefreshSession:
|
|
49
|
+
applicableRefreshSession: Ke
|
|
50
50
|
} = mt(), {
|
|
51
|
-
onInputMessageChange:
|
|
51
|
+
onInputMessageChange: ze,
|
|
52
52
|
filters: ge,
|
|
53
53
|
baseUrl: he,
|
|
54
54
|
agentUrl: qe,
|
|
55
55
|
context: ve,
|
|
56
56
|
headers: ye,
|
|
57
57
|
appId: N,
|
|
58
|
-
apiKey:
|
|
58
|
+
apiKey: H,
|
|
59
59
|
files: T
|
|
60
60
|
} = v, Re = i(O);
|
|
61
61
|
Re.current = O;
|
|
62
|
-
const Ee = qe || `${he}/run/api/chat`, { loadConversation:
|
|
62
|
+
const Ee = qe || `${he}/run/api/chat`, { loadConversation: Se } = ht({
|
|
63
63
|
baseUrl: he,
|
|
64
64
|
appId: N,
|
|
65
65
|
authToken: me,
|
|
66
66
|
getCaptchaHeader: O,
|
|
67
67
|
invalidateCaptcha: d,
|
|
68
|
-
refreshSession:
|
|
69
|
-
}), [We,
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
68
|
+
refreshSession: Ke
|
|
69
|
+
}), [We, Ie] = k(!1), K = i(null);
|
|
70
|
+
K.current = pe;
|
|
71
|
+
const z = i(null);
|
|
72
|
+
z.current = le;
|
|
73
73
|
const q = i(void 0);
|
|
74
74
|
q.current = U && Object.keys(U).length > 0 ? U : void 0;
|
|
75
75
|
const W = i(void 0);
|
|
@@ -78,7 +78,7 @@ const Wt = () => {
|
|
|
78
78
|
(e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
|
|
79
79
|
).join(`
|
|
80
80
|
`) ?? "";
|
|
81
|
-
|
|
81
|
+
b(() => {
|
|
82
82
|
h.current = T?.length ? T : void 0;
|
|
83
83
|
}, [je]);
|
|
84
84
|
const Ce = i(ye);
|
|
@@ -88,7 +88,7 @@ const Wt = () => {
|
|
|
88
88
|
const Ve = (e) => {
|
|
89
89
|
if (Ne(e))
|
|
90
90
|
return P.current?.files?.length ? Le : De;
|
|
91
|
-
switch (
|
|
91
|
+
switch (_t(e)) {
|
|
92
92
|
case 400:
|
|
93
93
|
try {
|
|
94
94
|
const t = JSON.parse(e.message ?? "");
|
|
@@ -107,11 +107,11 @@ const Wt = () => {
|
|
|
107
107
|
default:
|
|
108
108
|
return ne;
|
|
109
109
|
}
|
|
110
|
-
}, [
|
|
110
|
+
}, [S, Y] = k([]), Ye = Oe(
|
|
111
111
|
() => new dt({
|
|
112
112
|
api: Ee,
|
|
113
113
|
headers: () => {
|
|
114
|
-
const e =
|
|
114
|
+
const e = H ?? z.current ?? K.current;
|
|
115
115
|
return {
|
|
116
116
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
117
117
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -146,9 +146,9 @@ const Wt = () => {
|
|
|
146
146
|
requestContext: ve
|
|
147
147
|
}
|
|
148
148
|
}),
|
|
149
|
-
[Ee, ve, N,
|
|
149
|
+
[Ee, ve, N, H]
|
|
150
150
|
), {
|
|
151
|
-
messages:
|
|
151
|
+
messages: _,
|
|
152
152
|
sendMessage: J,
|
|
153
153
|
addToolApprovalResponse: Q,
|
|
154
154
|
status: Ae,
|
|
@@ -157,6 +157,12 @@ const Wt = () => {
|
|
|
157
157
|
error: D
|
|
158
158
|
} = lt({
|
|
159
159
|
transport: Ye,
|
|
160
|
+
// The SDK notifies React once per streamed chunk, which at typical token
|
|
161
|
+
// rates is 20-60 renders/sec of the whole chat tree. Coalescing to ~20fps
|
|
162
|
+
// is imperceptible while streaming text but caps the render work that grows
|
|
163
|
+
// with conversation length. Does not affect what is streamed, only how
|
|
164
|
+
// often React is told about it.
|
|
165
|
+
experimental_throttle: bt,
|
|
160
166
|
onData(e) {
|
|
161
167
|
x(e.type, e.data);
|
|
162
168
|
},
|
|
@@ -177,7 +183,7 @@ const Wt = () => {
|
|
|
177
183
|
},
|
|
178
184
|
onError(e) {
|
|
179
185
|
console.error("onError", { code: e.code, message: e.message });
|
|
180
|
-
const l =
|
|
186
|
+
const l = He || H ? null : At(e);
|
|
181
187
|
if (l !== null && E.current < 1) {
|
|
182
188
|
E.current++;
|
|
183
189
|
const o = j.current, r = P.current;
|
|
@@ -185,10 +191,10 @@ const Wt = () => {
|
|
|
185
191
|
if (l === "session" && ue) {
|
|
186
192
|
const n = await de();
|
|
187
193
|
if (!n) throw new Error("Auth token refresh failed");
|
|
188
|
-
|
|
194
|
+
z.current = n;
|
|
189
195
|
} else if (l === "session") {
|
|
190
196
|
const n = await fe();
|
|
191
|
-
n && (
|
|
197
|
+
n && (K.current = n);
|
|
192
198
|
} else
|
|
193
199
|
d();
|
|
194
200
|
if (o) {
|
|
@@ -228,7 +234,7 @@ const Wt = () => {
|
|
|
228
234
|
eventName: "chat_error",
|
|
229
235
|
properties: {
|
|
230
236
|
conversationId: c,
|
|
231
|
-
messageId:
|
|
237
|
+
messageId: _.at(-1)?.id,
|
|
232
238
|
error: e.message
|
|
233
239
|
}
|
|
234
240
|
}), t) {
|
|
@@ -253,41 +259,41 @@ const Wt = () => {
|
|
|
253
259
|
});
|
|
254
260
|
}
|
|
255
261
|
}), Te = i(R);
|
|
256
|
-
|
|
262
|
+
b(() => {
|
|
257
263
|
const e = Te.current;
|
|
258
|
-
Te.current = R, e !== R && (B(),
|
|
264
|
+
Te.current = R, e !== R && (B(), w(null), m([]), y(""), A(""), Y([]), d());
|
|
259
265
|
}, [R, B, m, y, d]);
|
|
260
|
-
const
|
|
266
|
+
const _e = Ae === "submitted", X = Ae === "streaming", Je = Oe(() => {
|
|
261
267
|
const e = (o) => {
|
|
262
268
|
if (!o || typeof o != "object") return !1;
|
|
263
269
|
const r = o;
|
|
264
270
|
return typeof r.type == "string" && r.type.startsWith("tool-");
|
|
265
|
-
}, t = [...
|
|
271
|
+
}, t = [..._ ?? []].reverse().find((o) => o.role === "assistant");
|
|
266
272
|
if (!t) return !1;
|
|
267
273
|
const s = t.parts?.at(-1);
|
|
268
274
|
return !(!e(s) || s.state !== "output-available" || !s.approval?.id || X);
|
|
269
|
-
}, [
|
|
270
|
-
|
|
275
|
+
}, [_, X]), [Qe, Z] = k(!1), we = X || Je && !Qe, Me = _e || we, Xe = _.length === 0, ee = !C.trim() && S.length === 0 || Me, Ze = gt("(max-width: 768px)"), [et, w] = k(null), te = i(null);
|
|
276
|
+
b(() => {
|
|
271
277
|
if (D) {
|
|
272
278
|
if (te.current === D) {
|
|
273
279
|
te.current = null;
|
|
274
280
|
return;
|
|
275
281
|
}
|
|
276
|
-
|
|
282
|
+
w(D);
|
|
277
283
|
}
|
|
278
284
|
}, [D]);
|
|
279
|
-
const tt = () =>
|
|
280
|
-
|
|
281
|
-
|
|
285
|
+
const tt = () => w(null), { inputNotification: st, showInputNotification: L, clearInputNotification: rt } = Ct(), be = i(null);
|
|
286
|
+
b(() => {
|
|
287
|
+
ze?.(C);
|
|
282
288
|
}, [C]);
|
|
283
289
|
const nt = (e) => {
|
|
284
290
|
e.key === "Enter" && !e.shiftKey && !ee && !e.nativeEvent.isComposing && (e.preventDefault(), se());
|
|
285
291
|
}, se = async (e = C) => {
|
|
286
|
-
if (ee && (!e || e.trim().length === 0) &&
|
|
292
|
+
if (ee && (!e || e.trim().length === 0) && S.length === 0 || !e.trim() && !S.length && !h.current?.length)
|
|
287
293
|
return;
|
|
288
|
-
if (
|
|
294
|
+
if (wt({
|
|
289
295
|
text: e,
|
|
290
|
-
rawFileBytes:
|
|
296
|
+
rawFileBytes: S.reduce((f, u) => f + u.size, 0),
|
|
291
297
|
encodedPartsBytes: (h.current ?? []).reduce(
|
|
292
298
|
(f, u) => f + u.url.length,
|
|
293
299
|
0
|
|
@@ -299,7 +305,7 @@ const Wt = () => {
|
|
|
299
305
|
);
|
|
300
306
|
return;
|
|
301
307
|
}
|
|
302
|
-
const t =
|
|
308
|
+
const t = S;
|
|
303
309
|
Y([]), A(""), E.current = 0, j.current = null, Z(!1);
|
|
304
310
|
let s = c;
|
|
305
311
|
s || (s = `conv_${F(16)}`, y(s));
|
|
@@ -369,16 +375,16 @@ const Wt = () => {
|
|
|
369
375
|
conversationId: c
|
|
370
376
|
}
|
|
371
377
|
});
|
|
372
|
-
},
|
|
378
|
+
}, I = $(
|
|
373
379
|
(e, l) => {
|
|
374
|
-
|
|
380
|
+
w(null), m(l), y(e), d(), h.current = void 0;
|
|
375
381
|
},
|
|
376
382
|
[m, y, d]
|
|
377
383
|
), Fe = $(
|
|
378
384
|
async (e, l) => {
|
|
379
|
-
re(),
|
|
385
|
+
re(), I(e, []), Ie(!0);
|
|
380
386
|
try {
|
|
381
|
-
const t = await
|
|
387
|
+
const t = await Se(e, l);
|
|
382
388
|
if (t === null) return !1;
|
|
383
389
|
const o = t[t.length - 1]?.role === "user" ? [
|
|
384
390
|
...t,
|
|
@@ -393,20 +399,20 @@ const Wt = () => {
|
|
|
393
399
|
]
|
|
394
400
|
}
|
|
395
401
|
] : t;
|
|
396
|
-
return
|
|
402
|
+
return I(e, o), !0;
|
|
397
403
|
} finally {
|
|
398
|
-
l?.aborted ||
|
|
404
|
+
l?.aborted || Ie(!1);
|
|
399
405
|
}
|
|
400
406
|
},
|
|
401
|
-
[
|
|
407
|
+
[I, Se, re]
|
|
402
408
|
);
|
|
403
409
|
vt({
|
|
404
410
|
conversationId: v.conversationId,
|
|
405
411
|
fetchedConversation: v.fetchedConversation,
|
|
406
412
|
effectiveAuthToken: me,
|
|
407
|
-
restoreSession:
|
|
413
|
+
restoreSession: I,
|
|
408
414
|
loadAndRestoreSession: Fe,
|
|
409
|
-
onLoadFailed: () =>
|
|
415
|
+
onLoadFailed: () => I("", [])
|
|
410
416
|
});
|
|
411
417
|
const { openForm: at } = Rt(), it = Et();
|
|
412
418
|
return pt(v.chatFunctionsRef, () => ({
|
|
@@ -419,17 +425,17 @@ const Wt = () => {
|
|
|
419
425
|
it?.setView("chat"), at(e, void 0);
|
|
420
426
|
},
|
|
421
427
|
focusInput: () => {
|
|
422
|
-
|
|
428
|
+
be.current?.focus();
|
|
423
429
|
}
|
|
424
430
|
})), {
|
|
425
|
-
messages:
|
|
431
|
+
messages: _,
|
|
426
432
|
sendMessage: J,
|
|
427
433
|
addToolApprovalResponse: ot,
|
|
428
|
-
isLoading:
|
|
429
|
-
isStreaming:
|
|
434
|
+
isLoading: _e,
|
|
435
|
+
isStreaming: we,
|
|
430
436
|
isBusy: Me,
|
|
431
437
|
error: et,
|
|
432
|
-
setError:
|
|
438
|
+
setError: w,
|
|
433
439
|
isSubmitDisabled: ee,
|
|
434
440
|
input: C,
|
|
435
441
|
handleInputChange: Ge,
|
|
@@ -437,13 +443,13 @@ const Wt = () => {
|
|
|
437
443
|
handleSubmit: se,
|
|
438
444
|
stop: re,
|
|
439
445
|
clear: ke,
|
|
440
|
-
inputRef:
|
|
446
|
+
inputRef: be,
|
|
441
447
|
isMobile: Ze,
|
|
442
|
-
files:
|
|
448
|
+
files: S,
|
|
443
449
|
setFiles: Y,
|
|
444
450
|
isNewChat: Xe,
|
|
445
451
|
conversationId: c,
|
|
446
|
-
restoreSession:
|
|
452
|
+
restoreSession: I,
|
|
447
453
|
loadAndRestoreSession: Fe,
|
|
448
454
|
isSessionLoading: We,
|
|
449
455
|
authToken: R ? le : pe,
|
|
@@ -456,5 +462,5 @@ const Wt = () => {
|
|
|
456
462
|
};
|
|
457
463
|
};
|
|
458
464
|
export {
|
|
459
|
-
|
|
465
|
+
jt as useInkeepChat
|
|
460
466
|
};
|