@inkeep/agents-ui 0.15.6 → 0.15.7
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 +43 -37
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/types/events.d.ts +8 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("@ai-sdk/react"),Z=require("ai"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("@ai-sdk/react"),Z=require("ai"),n=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.`,ie=()=>{const{baseSettings:C,aiChatSettings:
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ie=()=>{const{baseSettings:C,aiChatSettings:i}=ee.useInkeepConfig(),[t="",b]=ae.useControllableState({prop:i.conversationId,defaultProp:i.conversationId??""}),{logEvent:a}=se.useBaseEvents(),{setConversationId:D,emitToParent:u}=oe.useStreamingEvents(),[o,l]=n.useState(""),N=e=>l(e.target.value),{filters:y}=C,{onInputMessageChange:U,filters:I,agentUrl:M,context:d,headers:g,apiKey:p}=i,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]=n.useState([]),[H,w]=n.useState(null),K=n.useMemo(()=>new Z.DefaultChatTransport({api:M,headers:{...p?{Authorization:`Bearer ${p}`}:{},...g},body:{requestContext:d}}),[M,p,g,d]),{messages:h,sendMessage:L,status:_,setMessages:q,stop:W,error:f}=Y.useChat({transport:K,onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:t}),await a({eventName:"assistant_message_received",properties:{conversationId:t}}),a({eventName:"assistant_answer_displayed",properties:{conversationId:t}})},onError(e){console.log("onError",e.message),a({eventName:"chat_error",properties:{conversationId:t,error:e.message}}),q(c=>{const r=[...c],s=r[r.length-1];if(s){const P=T(e);s.role==="user"?r.push({id:k.generateUid(16),role:"assistant",parts:[{type:"text",text:P}]}):s.parts=[{type:"text",text:P}]}return r})}}),x=_==="submitted",$=_==="streaming",z=h.length===0,v=!o.trim()||x,B=te.useMediaQuery("(max-width: 768px)"),[G,E]=n.useState(null);n.useEffect(()=>{f&&E(f)},[f]);const Q=()=>E(null),F=n.useRef(null);n.useEffect(()=>{U?.(o)},[o]);const j=e=>{e.key==="Enter"&&!e.shiftKey&&!v&&!e.nativeEvent.isComposing&&(e.preventDefault(),S())},S=async(e=o)=>{if(v&&(!e||e.trim().length===0))return;m([]),l(""),await a({eventName:"user_message_submitted",properties:{conversationId:t}});const c=y||I?JSON.stringify({...y,...I}):void 0,r={...g};c&&(r["inkeep-filters"]=c);let s=t;s||(s=`conv_${k.generateUid(16)}`,b(s)),D(s),L({text:e},{headers:r,body:{conversationId:s,requestContext:d}})},J=()=>{W().then(()=>{u("aborted",{conversationId:t})})},R=()=>{Q(),q([]),b(""),m([]),w(null),a({eventName:"chat_clear_button_clicked",properties:{conversationId:t}})},{openForm:V}=ne.useChatForm(),X=re.useWidget();return n.useImperativeHandle(i.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:o,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:t}};exports.DEFAULT_ERROR_MESSAGE=A;exports.useInkeepChat=ie;
|
|
@@ -13,10 +13,10 @@ import { useStreamingEvents as me } from "../../hooks/use-streaming-events.js";
|
|
|
13
13
|
const ue = `Hmm..
|
|
14
14
|
|
|
15
15
|
It seems I might be having some issues right now. Please clear the chat and try again.`, be = () => {
|
|
16
|
-
const { baseSettings: y, aiChatSettings:
|
|
17
|
-
prop:
|
|
18
|
-
defaultProp:
|
|
19
|
-
}), { logEvent:
|
|
16
|
+
const { baseSettings: y, aiChatSettings: a } = ne(), [t = "", E] = ce({
|
|
17
|
+
prop: a.conversationId,
|
|
18
|
+
defaultProp: a.conversationId ?? ""
|
|
19
|
+
}), { logEvent: o } = re(), { setConversationId: P, emitToParent: m } = me(), [r, u] = c(""), T = (e) => u(e.target.value), {
|
|
20
20
|
/* shouldBypassCaptcha, */
|
|
21
21
|
filters: b
|
|
22
22
|
} = y, {
|
|
@@ -26,7 +26,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
26
26
|
context: l,
|
|
27
27
|
headers: p,
|
|
28
28
|
apiKey: g
|
|
29
|
-
} =
|
|
29
|
+
} = a, H = (e) => {
|
|
30
30
|
switch (e.code) {
|
|
31
31
|
case 400:
|
|
32
32
|
return e.message;
|
|
@@ -60,48 +60,54 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
60
60
|
m(e.type, e.data);
|
|
61
61
|
},
|
|
62
62
|
async onFinish() {
|
|
63
|
-
m("completion", { conversationId:
|
|
63
|
+
m("completion", { conversationId: t }), await o({
|
|
64
64
|
eventName: "assistant_message_received",
|
|
65
65
|
properties: {
|
|
66
|
-
conversationId:
|
|
66
|
+
conversationId: t
|
|
67
67
|
}
|
|
68
|
-
}),
|
|
68
|
+
}), o({
|
|
69
69
|
eventName: "assistant_answer_displayed",
|
|
70
70
|
properties: {
|
|
71
|
-
conversationId:
|
|
71
|
+
conversationId: t
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
},
|
|
75
75
|
onError(e) {
|
|
76
|
-
console.log("onError", e.message),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
console.log("onError", e.message), o({
|
|
77
|
+
eventName: "chat_error",
|
|
78
|
+
properties: {
|
|
79
|
+
conversationId: t,
|
|
80
|
+
error: e.message
|
|
81
|
+
}
|
|
82
|
+
}), x((i) => {
|
|
83
|
+
const n = [...i], s = n[n.length - 1];
|
|
84
|
+
if (s) {
|
|
85
|
+
const D = H(e);
|
|
86
|
+
s.role === "user" ? n.push({
|
|
81
87
|
id: R(16),
|
|
82
88
|
role: "assistant",
|
|
83
|
-
parts: [{ type: "text", text:
|
|
84
|
-
}) :
|
|
89
|
+
parts: [{ type: "text", text: D }]
|
|
90
|
+
}) : s.parts = [{ type: "text", text: D }];
|
|
85
91
|
}
|
|
86
92
|
return n;
|
|
87
93
|
});
|
|
88
94
|
}
|
|
89
|
-
}), F = _ === "submitted", B = _ === "streaming", L = h.length === 0, v = !
|
|
95
|
+
}), F = _ === "submitted", B = _ === "streaming", L = h.length === 0, v = !r.trim() || F, O = oe("(max-width: 768px)"), [G, C] = c(null);
|
|
90
96
|
A(() => {
|
|
91
97
|
f && C(f);
|
|
92
98
|
}, [f]);
|
|
93
|
-
const J = () => C(null),
|
|
99
|
+
const J = () => C(null), N = te(null);
|
|
94
100
|
A(() => {
|
|
95
|
-
q?.(
|
|
96
|
-
}, [
|
|
101
|
+
q?.(r);
|
|
102
|
+
}, [r]);
|
|
97
103
|
const Q = (e) => {
|
|
98
104
|
e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), I());
|
|
99
|
-
}, I = async (e =
|
|
105
|
+
}, I = async (e = r) => {
|
|
100
106
|
if (v && (!e || e.trim().length === 0)) return;
|
|
101
|
-
d([]), u(""), await
|
|
107
|
+
d([]), u(""), await o({
|
|
102
108
|
eventName: "user_message_submitted",
|
|
103
109
|
properties: {
|
|
104
|
-
conversationId:
|
|
110
|
+
conversationId: t
|
|
105
111
|
}
|
|
106
112
|
});
|
|
107
113
|
const i = b || w ? JSON.stringify({
|
|
@@ -111,42 +117,42 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
111
117
|
...p
|
|
112
118
|
};
|
|
113
119
|
i && (n["inkeep-filters"] = i);
|
|
114
|
-
let
|
|
115
|
-
|
|
120
|
+
let s = t;
|
|
121
|
+
s || (s = `conv_${R(16)}`, E(s)), P(s), $(
|
|
116
122
|
{
|
|
117
123
|
text: e
|
|
118
124
|
},
|
|
119
125
|
{
|
|
120
126
|
headers: n,
|
|
121
127
|
body: {
|
|
122
|
-
conversationId:
|
|
128
|
+
conversationId: s,
|
|
123
129
|
requestContext: l
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
);
|
|
127
133
|
}, V = () => {
|
|
128
134
|
z().then(() => {
|
|
129
|
-
m("aborted", { conversationId:
|
|
135
|
+
m("aborted", { conversationId: t });
|
|
130
136
|
});
|
|
131
|
-
},
|
|
132
|
-
J(), x([]), E(""), d([]), M(null),
|
|
137
|
+
}, k = () => {
|
|
138
|
+
J(), x([]), E(""), d([]), M(null), o({
|
|
133
139
|
eventName: "chat_clear_button_clicked",
|
|
134
140
|
properties: {
|
|
135
|
-
conversationId:
|
|
141
|
+
conversationId: t
|
|
136
142
|
}
|
|
137
143
|
});
|
|
138
144
|
}, { openForm: j } = ae(), X = ie();
|
|
139
|
-
return se(
|
|
145
|
+
return se(a.chatFunctionsRef, () => ({
|
|
140
146
|
submitMessage: I,
|
|
141
147
|
updateInputMessage(e) {
|
|
142
148
|
u(e);
|
|
143
149
|
},
|
|
144
|
-
clearChat:
|
|
150
|
+
clearChat: k,
|
|
145
151
|
openForm: (e) => {
|
|
146
152
|
X?.setView("chat"), j(e, void 0);
|
|
147
153
|
},
|
|
148
154
|
focusInput: () => {
|
|
149
|
-
|
|
155
|
+
N.current?.focus();
|
|
150
156
|
}
|
|
151
157
|
})), {
|
|
152
158
|
messages: h,
|
|
@@ -155,14 +161,14 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
155
161
|
error: G,
|
|
156
162
|
setError: C,
|
|
157
163
|
isSubmitDisabled: v,
|
|
158
|
-
input:
|
|
164
|
+
input: r,
|
|
159
165
|
handleInputChange: T,
|
|
160
166
|
handleInputKeyDown: Q,
|
|
161
167
|
handleSubmit: I,
|
|
162
168
|
stop: V,
|
|
163
|
-
clear:
|
|
169
|
+
clear: k,
|
|
164
170
|
isEmpty: h.length === 0,
|
|
165
|
-
inputRef:
|
|
171
|
+
inputRef: N,
|
|
166
172
|
isMobile: O,
|
|
167
173
|
// Additional state for attachments and workflow
|
|
168
174
|
messageAttachments: K,
|
|
@@ -170,7 +176,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
170
176
|
selectedWorkflow: U,
|
|
171
177
|
setSelectedWorkflow: M,
|
|
172
178
|
isNewChat: L,
|
|
173
|
-
conversationId:
|
|
179
|
+
conversationId: t
|
|
174
180
|
};
|
|
175
181
|
};
|
|
176
182
|
export {
|
|
@@ -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.6",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.6",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|
package/dist/types/events.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ type ExtendPropertiesWithCommon<T> = T extends {
|
|
|
43
43
|
export type InkeepEventWithCommon = ExtendPropertiesWithCommon<InkeepEvent>;
|
|
44
44
|
export type InkeepCallbackEvent = InkeepEventWithCommon;
|
|
45
45
|
export type SearchEvent = SearchQueryResponseReceivedEvent | SearchQuerySubmittedEvent | SearchResultClickedEvent;
|
|
46
|
-
export type ChatEvent = AssistantMessageReceivedEvent | AssistantAnswerDisplayedEvent | UserMessageSubmittedEvent | UserEscalationIndicatedEvent | SharedChatLoadedEvent | AssistantPositiveFeedbackSubmittedEvent | AssistantNegativeFeedbackSubmittedEvent | ChatClearButtonClickedEvent | AssistantMessageCopiedEvent | GetHelpOptionClickedEvent | ChatShareButtonClickedEvent | AssistantSourceItemClickedEvent | AssistantMessageLinkOpenedEvent | AssistantCodeBlockCopiedEvent;
|
|
46
|
+
export type ChatEvent = AssistantMessageReceivedEvent | AssistantAnswerDisplayedEvent | UserMessageSubmittedEvent | UserEscalationIndicatedEvent | SharedChatLoadedEvent | AssistantPositiveFeedbackSubmittedEvent | AssistantNegativeFeedbackSubmittedEvent | ChatClearButtonClickedEvent | AssistantMessageCopiedEvent | GetHelpOptionClickedEvent | ChatShareButtonClickedEvent | AssistantSourceItemClickedEvent | AssistantMessageLinkOpenedEvent | AssistantCodeBlockCopiedEvent | ChatErrorEvent;
|
|
47
47
|
export type WidgetEvent = ModalOpenedEvent | ModalClosedEvent | ChatBubbleOpenedEvent | ChatBubbleClosedEvent;
|
|
48
48
|
export type InkeepEvent = SearchEvent | ChatEvent | WidgetEvent;
|
|
49
49
|
export interface AssistantMessageReceivedEvent {
|
|
@@ -141,6 +141,13 @@ export interface AssistantMessageLinkOpenedEvent {
|
|
|
141
141
|
url?: string;
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
+
export interface ChatErrorEvent {
|
|
145
|
+
eventName: 'chat_error';
|
|
146
|
+
properties: {
|
|
147
|
+
conversationId: string;
|
|
148
|
+
error?: string;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
144
151
|
export interface SearchResultClickedEvent {
|
|
145
152
|
eventName: 'search_result_clicked';
|
|
146
153
|
properties: {
|