@inkeep/agents-ui 0.15.10 → 0.15.12
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/color-mode/index.d.ts +0 -1
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +1 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +132 -122
- package/dist/primitives/components/embedded-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat.js +145 -145
- package/dist/primitives/hooks/use-instant-update.d.ts +0 -1
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/utils/split-props.d.ts +0 -1
- package/dist/react/chat-button.d.ts +0 -2
- package/dist/types/config/ai.d.ts +13 -15
- package/dist/types/config/base.d.ts +0 -20
- package/dist/types/config/search.d.ts +0 -2
- package/dist/types/config/settings/actions.d.ts +68 -2
- package/dist/types/sources.d.ts +1 -9
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("@ai-sdk/react"),ae=require("ai"),n=require("react"),oe=require("../../providers/config-provider.cjs"),ie=require("../../hooks/use-media-query.cjs"),U=require("../../utils/generate-uid.cjs"),ce=require("../../providers/base-events-provider.cjs"),ue=require("../../providers/chat-form-provider.cjs"),le=require("../../providers/widget-provider.cjs"),pe=require("@radix-ui/react-use-controllable-state"),de=require("../../hooks/use-streaming-events.cjs"),O=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ge=()=>{const{baseSettings:C,aiChatSettings:l}=oe.useInkeepConfig(),[r="",I]=pe.useControllableState({prop:l.conversationId,defaultProp:l.conversationId??""}),{logEvent:o}=ce.useBaseEvents(),{setConversationId:B,emitToParent:p}=de.useStreamingEvents(),[i,d]=n.useState(""),H=e=>d(e.target.value),{filters:M}=C,{onInputMessageChange:W,filters:w,agentUrl:_,context:g,headers:m,apiKey:f}=l,z=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 O}},[K,h]=n.useState([]),[L,q]=n.useState(null),$=()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString()}),j=n.useMemo(()=>new ae.DefaultChatTransport({api:_,headers:{...f?{Authorization:`Bearer ${f}`}:{},...m},body:{requestContext:g}}),[_,f,m,g]),{messages:c,sendMessage:F,addToolApprovalResponse:G,status:x,setMessages:A,stop:Q,error:v}=re.useChat({transport:j,onData(e){p(e.type,e.data)},async onFinish(){p("completion",{conversationId:r}),await o({eventName:"assistant_message_received",properties:{conversationId:r}}),o({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.log("onError",e.message),o({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),A(u=>{const s=[...u],t=s[s.length-1];if(t){const a=z(e);t.role==="user"?s.push({id:U.generateUid(16),role:"assistant",parts:[{type:"text",text:a}]}):t.parts=[{type:"text",text:a}]}return s})}}),P=x==="submitted",S=x==="streaming",J=n.useMemo(()=>{const e=a=>{if(!a||typeof a!="object")return!1;const N=a;return typeof N.type=="string"&&N.type.startsWith("tool-")},s=[...c??[]].reverse().find(a=>a.role==="assistant");if(!s)return!1;const t=s.parts?.at(-1);return!(!e(t)||t.state!=="output-available"||!t.approval?.id||S)},[c,S]),R=S||J,k=P||R,V=c.length===0,y=!i.trim()||k,Z=ie.useMediaQuery("(max-width: 768px)"),[X,E]=n.useState(null);n.useEffect(()=>{v&&E(v)},[v]);const Y=()=>E(null),D=n.useRef(null);n.useEffect(()=>{W?.(i)},[i]);const ee=e=>{e.key==="Enter"&&!e.shiftKey&&!y&&!e.nativeEvent.isComposing&&(e.preventDefault(),b())},b=async(e=i)=>{if(y&&(!e||e.trim().length===0))return;h([]),d(""),await o({eventName:"user_message_submitted",properties:{conversationId:r}});const u=M||w?JSON.stringify({...M,...w}):void 0,s={...m};u&&(s["inkeep-filters"]=u);let t=r;t||(t=`conv_${U.generateUid(16)}`,I(t)),B(t),F({text:e},{headers:{...$(),...s},body:{conversationId:t,requestContext:g}})},te=()=>{Q().then(()=>{p("aborted",{conversationId:r})})},T=()=>{Y(),A([]),I(""),h([]),q(null),o({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},{openForm:se}=ue.useChatForm(),ne=le.useWidget();return n.useImperativeHandle(l.chatFunctionsRef,()=>({submitMessage:b,updateInputMessage(e){d(e)},clearChat:T,openForm:e=>{ne?.setView("chat"),se(e,void 0)},focusInput:()=>{D.current?.focus()}})),{messages:c,sendMessage:F,addToolApprovalResponse:G,isLoading:P,isStreaming:R,isBusy:k,error:X,setError:E,isSubmitDisabled:y,input:i,handleInputChange:H,handleInputKeyDown:ee,handleSubmit:b,stop:te,clear:T,isEmpty:c.length===0,inputRef:D,isMobile:Z,messageAttachments:K,setMessageAttachments:h,selectedWorkflow:L,setSelectedWorkflow:q,isNewChat:V,conversationId:r}};exports.DEFAULT_ERROR_MESSAGE=O;exports.useInkeepChat=ge;
|
|
@@ -26,6 +26,7 @@ export declare const useInkeepChat: () => {
|
|
|
26
26
|
addToolApprovalResponse: ChatAddToolApproveResponseFunction;
|
|
27
27
|
isLoading: boolean;
|
|
28
28
|
isStreaming: boolean;
|
|
29
|
+
isBusy: boolean;
|
|
29
30
|
error: Error | null;
|
|
30
31
|
setError: Dispatch<SetStateAction<Error | null>>;
|
|
31
32
|
isSubmitDisabled: boolean;
|
|
@@ -1,194 +1,204 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { DefaultChatTransport as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { useInkeepConfig as
|
|
6
|
-
import { useMediaQuery as
|
|
7
|
-
import { generateUid as
|
|
8
|
-
import { useBaseEvents as
|
|
9
|
-
import { useChatForm as
|
|
10
|
-
import { useWidget as
|
|
11
|
-
import { useControllableState as
|
|
12
|
-
import { useStreamingEvents as
|
|
13
|
-
const
|
|
2
|
+
import { useChat as re } from "@ai-sdk/react";
|
|
3
|
+
import { DefaultChatTransport as ae } from "ai";
|
|
4
|
+
import { useState as m, useMemo as H, useEffect as O, useRef as ie, useImperativeHandle as le } from "react";
|
|
5
|
+
import { useInkeepConfig as ce } from "../../providers/config-provider.js";
|
|
6
|
+
import { useMediaQuery as me } from "../../hooks/use-media-query.js";
|
|
7
|
+
import { generateUid as W } from "../../utils/generate-uid.js";
|
|
8
|
+
import { useBaseEvents as pe } from "../../providers/base-events-provider.js";
|
|
9
|
+
import { useChatForm as ue } from "../../providers/chat-form-provider.js";
|
|
10
|
+
import { useWidget as fe } from "../../providers/widget-provider.js";
|
|
11
|
+
import { useControllableState as ge } from "@radix-ui/react-use-controllable-state";
|
|
12
|
+
import { useStreamingEvents as de } from "../../hooks/use-streaming-events.js";
|
|
13
|
+
const he = `Hmm..
|
|
14
14
|
|
|
15
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
16
|
-
const { baseSettings:
|
|
17
|
-
prop:
|
|
18
|
-
defaultProp:
|
|
19
|
-
}), { logEvent:
|
|
15
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, Fe = () => {
|
|
16
|
+
const { baseSettings: S, aiChatSettings: c } = ce(), [n = "", E] = ge({
|
|
17
|
+
prop: c.conversationId,
|
|
18
|
+
defaultProp: c.conversationId ?? ""
|
|
19
|
+
}), { logEvent: r } = pe(), { setConversationId: q, emitToParent: p } = de(), [a, u] = m(""), z = (e) => u(e.target.value), {
|
|
20
20
|
/* shouldBypassCaptcha, */
|
|
21
|
-
filters:
|
|
22
|
-
} =
|
|
23
|
-
onInputMessageChange:
|
|
24
|
-
filters:
|
|
25
|
-
agentUrl:
|
|
26
|
-
context:
|
|
27
|
-
headers:
|
|
21
|
+
filters: w
|
|
22
|
+
} = S, {
|
|
23
|
+
onInputMessageChange: K,
|
|
24
|
+
filters: M,
|
|
25
|
+
agentUrl: x,
|
|
26
|
+
context: f,
|
|
27
|
+
headers: g,
|
|
28
28
|
apiKey: d
|
|
29
|
-
} =
|
|
29
|
+
} = c, U = (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 ${
|
|
34
|
+
return `There seems to be a configuration error. Please contact ${S.organizationDisplayName ?? "Administrator"}`;
|
|
35
35
|
default:
|
|
36
|
-
return
|
|
36
|
+
return he;
|
|
37
37
|
}
|
|
38
|
-
}, [
|
|
38
|
+
}, [$, h] = m([]), [L, _] = m(null), j = () => ({
|
|
39
39
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
40
40
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString()
|
|
41
|
-
}),
|
|
42
|
-
() => new
|
|
43
|
-
api:
|
|
41
|
+
}), G = H(
|
|
42
|
+
() => new ae({
|
|
43
|
+
api: x,
|
|
44
44
|
headers: {
|
|
45
45
|
...d ? { Authorization: `Bearer ${d}` } : {},
|
|
46
|
-
...
|
|
46
|
+
...g
|
|
47
47
|
},
|
|
48
48
|
body: {
|
|
49
|
-
requestContext:
|
|
49
|
+
requestContext: f
|
|
50
50
|
}
|
|
51
51
|
}),
|
|
52
|
-
[
|
|
52
|
+
[x, d, g, f]
|
|
53
53
|
), {
|
|
54
|
-
messages:
|
|
55
|
-
sendMessage:
|
|
56
|
-
addToolApprovalResponse:
|
|
57
|
-
status:
|
|
58
|
-
setMessages:
|
|
59
|
-
stop:
|
|
60
|
-
error:
|
|
61
|
-
} =
|
|
62
|
-
transport:
|
|
54
|
+
messages: i,
|
|
55
|
+
sendMessage: F,
|
|
56
|
+
addToolApprovalResponse: J,
|
|
57
|
+
status: k,
|
|
58
|
+
setMessages: A,
|
|
59
|
+
stop: Q,
|
|
60
|
+
error: v
|
|
61
|
+
} = re({
|
|
62
|
+
transport: G,
|
|
63
63
|
onData(e) {
|
|
64
|
-
|
|
64
|
+
p(e.type, e.data);
|
|
65
65
|
},
|
|
66
66
|
async onFinish() {
|
|
67
|
-
|
|
67
|
+
p("completion", { conversationId: n }), await r({
|
|
68
68
|
eventName: "assistant_message_received",
|
|
69
69
|
properties: {
|
|
70
|
-
conversationId:
|
|
70
|
+
conversationId: n
|
|
71
71
|
}
|
|
72
|
-
}),
|
|
72
|
+
}), r({
|
|
73
73
|
eventName: "assistant_answer_displayed",
|
|
74
74
|
properties: {
|
|
75
|
-
conversationId:
|
|
75
|
+
conversationId: n
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
},
|
|
79
79
|
onError(e) {
|
|
80
|
-
console.log("onError", e.message),
|
|
80
|
+
console.log("onError", e.message), r({
|
|
81
81
|
eventName: "chat_error",
|
|
82
82
|
properties: {
|
|
83
|
-
conversationId:
|
|
83
|
+
conversationId: n,
|
|
84
84
|
error: e.message
|
|
85
85
|
}
|
|
86
|
-
}),
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
id:
|
|
86
|
+
}), A((l) => {
|
|
87
|
+
const s = [...l], t = s[s.length - 1];
|
|
88
|
+
if (t) {
|
|
89
|
+
const o = U(e);
|
|
90
|
+
t.role === "user" ? s.push({
|
|
91
|
+
id: W(16),
|
|
92
92
|
role: "assistant",
|
|
93
|
-
parts: [{ type: "text", text:
|
|
94
|
-
}) :
|
|
93
|
+
parts: [{ type: "text", text: o }]
|
|
94
|
+
}) : t.parts = [{ type: "text", text: o }];
|
|
95
95
|
}
|
|
96
|
-
return
|
|
96
|
+
return s;
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
}), D =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
}), D = k === "submitted", y = k === "streaming", V = H(() => {
|
|
100
|
+
const e = (o) => {
|
|
101
|
+
if (!o || typeof o != "object") return !1;
|
|
102
|
+
const B = o;
|
|
103
|
+
return typeof B.type == "string" && B.type.startsWith("tool-");
|
|
104
|
+
}, s = [...i ?? []].reverse().find((o) => o.role === "assistant");
|
|
105
|
+
if (!s) return !1;
|
|
106
|
+
const t = s.parts?.at(-1);
|
|
107
|
+
return !(!e(t) || t.state !== "output-available" || !t.approval?.id || y);
|
|
108
|
+
}, [i, y]), N = y || V, T = D || N, Z = i.length === 0, I = !a.trim() || T, X = me("(max-width: 768px)"), [Y, C] = m(null);
|
|
109
|
+
O(() => {
|
|
110
|
+
v && C(v);
|
|
111
|
+
}, [v]);
|
|
112
|
+
const ee = () => C(null), R = ie(null);
|
|
113
|
+
O(() => {
|
|
114
|
+
K?.(a);
|
|
115
|
+
}, [a]);
|
|
116
|
+
const te = (e) => {
|
|
117
|
+
e.key === "Enter" && !e.shiftKey && !I && !e.nativeEvent.isComposing && (e.preventDefault(), b());
|
|
118
|
+
}, b = async (e = a) => {
|
|
119
|
+
if (I && (!e || e.trim().length === 0)) return;
|
|
120
|
+
h([]), u(""), await r({
|
|
112
121
|
eventName: "user_message_submitted",
|
|
113
122
|
properties: {
|
|
114
|
-
conversationId:
|
|
123
|
+
conversationId: n
|
|
115
124
|
}
|
|
116
125
|
});
|
|
117
|
-
const
|
|
118
|
-
...
|
|
119
|
-
...
|
|
120
|
-
}) : void 0,
|
|
121
|
-
...
|
|
126
|
+
const l = w || M ? JSON.stringify({
|
|
127
|
+
...w,
|
|
128
|
+
...M
|
|
129
|
+
}) : void 0, s = {
|
|
130
|
+
...g
|
|
122
131
|
};
|
|
123
|
-
|
|
124
|
-
let
|
|
125
|
-
|
|
132
|
+
l && (s["inkeep-filters"] = l);
|
|
133
|
+
let t = n;
|
|
134
|
+
t || (t = `conv_${W(16)}`, E(t)), q(t), F(
|
|
126
135
|
{
|
|
127
136
|
text: e
|
|
128
137
|
},
|
|
129
138
|
{
|
|
130
139
|
headers: {
|
|
131
|
-
...
|
|
132
|
-
...
|
|
140
|
+
...j(),
|
|
141
|
+
...s
|
|
133
142
|
},
|
|
134
143
|
body: {
|
|
135
|
-
conversationId:
|
|
136
|
-
requestContext:
|
|
144
|
+
conversationId: t,
|
|
145
|
+
requestContext: f
|
|
137
146
|
}
|
|
138
147
|
}
|
|
139
148
|
);
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
}, se = () => {
|
|
150
|
+
Q().then(() => {
|
|
151
|
+
p("aborted", { conversationId: n });
|
|
143
152
|
});
|
|
144
|
-
},
|
|
145
|
-
|
|
153
|
+
}, P = () => {
|
|
154
|
+
ee(), A([]), E(""), h([]), _(null), r({
|
|
146
155
|
eventName: "chat_clear_button_clicked",
|
|
147
156
|
properties: {
|
|
148
|
-
conversationId:
|
|
157
|
+
conversationId: n
|
|
149
158
|
}
|
|
150
159
|
});
|
|
151
|
-
}, { openForm:
|
|
152
|
-
return
|
|
153
|
-
submitMessage:
|
|
160
|
+
}, { openForm: ne } = ue(), oe = fe();
|
|
161
|
+
return le(c.chatFunctionsRef, () => ({
|
|
162
|
+
submitMessage: b,
|
|
154
163
|
updateInputMessage(e) {
|
|
155
|
-
|
|
164
|
+
u(e);
|
|
156
165
|
},
|
|
157
|
-
clearChat:
|
|
166
|
+
clearChat: P,
|
|
158
167
|
openForm: (e) => {
|
|
159
|
-
|
|
168
|
+
oe?.setView("chat"), ne(e, void 0);
|
|
160
169
|
},
|
|
161
170
|
focusInput: () => {
|
|
162
|
-
|
|
171
|
+
R.current?.focus();
|
|
163
172
|
}
|
|
164
173
|
})), {
|
|
165
|
-
messages:
|
|
166
|
-
sendMessage:
|
|
167
|
-
addToolApprovalResponse:
|
|
174
|
+
messages: i,
|
|
175
|
+
sendMessage: F,
|
|
176
|
+
addToolApprovalResponse: J,
|
|
168
177
|
isLoading: D,
|
|
169
|
-
isStreaming:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
isStreaming: N,
|
|
179
|
+
isBusy: T,
|
|
180
|
+
error: Y,
|
|
181
|
+
setError: C,
|
|
182
|
+
isSubmitDisabled: I,
|
|
183
|
+
input: a,
|
|
184
|
+
handleInputChange: z,
|
|
185
|
+
handleInputKeyDown: te,
|
|
186
|
+
handleSubmit: b,
|
|
187
|
+
stop: se,
|
|
188
|
+
clear: P,
|
|
189
|
+
isEmpty: i.length === 0,
|
|
190
|
+
inputRef: R,
|
|
191
|
+
isMobile: X,
|
|
182
192
|
// Additional state for attachments and workflow
|
|
183
|
-
messageAttachments:
|
|
184
|
-
setMessageAttachments:
|
|
185
|
-
selectedWorkflow:
|
|
186
|
-
setSelectedWorkflow:
|
|
187
|
-
isNewChat:
|
|
188
|
-
conversationId:
|
|
193
|
+
messageAttachments: $,
|
|
194
|
+
setMessageAttachments: h,
|
|
195
|
+
selectedWorkflow: L,
|
|
196
|
+
setSelectedWorkflow: _,
|
|
197
|
+
isNewChat: Z,
|
|
198
|
+
conversationId: n
|
|
189
199
|
};
|
|
190
200
|
};
|
|
191
201
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
202
|
+
he as DEFAULT_ERROR_MESSAGE,
|
|
203
|
+
Fe as useInkeepChat
|
|
194
204
|
};
|