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