@inkeep/agents-ui 0.15.6 → 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 +108 -96
- 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
|
|
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,179 +1,191 @@
|
|
|
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:
|
|
17
|
-
prop:
|
|
18
|
-
defaultProp:
|
|
19
|
-
}), { logEvent:
|
|
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
|
+
prop: a.conversationId,
|
|
18
|
+
defaultProp: a.conversationId ?? ""
|
|
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
|
-
} =
|
|
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
|
-
conversationId:
|
|
68
|
+
conversationId: t
|
|
67
69
|
}
|
|
68
|
-
}),
|
|
70
|
+
}), o({
|
|
69
71
|
eventName: "assistant_answer_displayed",
|
|
70
72
|
properties: {
|
|
71
|
-
conversationId:
|
|
73
|
+
conversationId: t
|
|
72
74
|
}
|
|
73
75
|
});
|
|
74
76
|
},
|
|
75
77
|
onError(e) {
|
|
76
|
-
console.log("onError", e.message),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
console.log("onError", e.message), o({
|
|
79
|
+
eventName: "chat_error",
|
|
80
|
+
properties: {
|
|
81
|
+
conversationId: t,
|
|
82
|
+
error: e.message
|
|
83
|
+
}
|
|
84
|
+
}), _((i) => {
|
|
85
|
+
const n = [...i], s = n[n.length - 1];
|
|
86
|
+
if (s) {
|
|
87
|
+
const N = P(e);
|
|
88
|
+
s.role === "user" ? n.push({
|
|
89
|
+
id: O(16),
|
|
82
90
|
role: "assistant",
|
|
83
91
|
parts: [{ type: "text", text: N }]
|
|
84
|
-
}) :
|
|
92
|
+
}) : s.parts = [{ type: "text", text: N }];
|
|
85
93
|
}
|
|
86
94
|
return n;
|
|
87
95
|
});
|
|
88
96
|
}
|
|
89
|
-
}),
|
|
97
|
+
}), k = M === "submitted", $ = M === "streaming", B = h.length === 0, v = !r.trim() || k, L = oe("(max-width: 768px)"), [Z, I] = m(null);
|
|
90
98
|
A(() => {
|
|
91
|
-
f &&
|
|
99
|
+
f && I(f);
|
|
92
100
|
}, [f]);
|
|
93
|
-
const
|
|
101
|
+
const G = () => I(null), D = te(null);
|
|
94
102
|
A(() => {
|
|
95
|
-
|
|
96
|
-
}, [
|
|
97
|
-
const
|
|
98
|
-
e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(),
|
|
99
|
-
},
|
|
103
|
+
z?.(r);
|
|
104
|
+
}, [r]);
|
|
105
|
+
const J = (e) => {
|
|
106
|
+
e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), C());
|
|
107
|
+
}, C = async (e = r) => {
|
|
100
108
|
if (v && (!e || e.trim().length === 0)) return;
|
|
101
|
-
d([]),
|
|
109
|
+
d([]), l(""), await o({
|
|
102
110
|
eventName: "user_message_submitted",
|
|
103
111
|
properties: {
|
|
104
|
-
conversationId:
|
|
112
|
+
conversationId: t
|
|
105
113
|
}
|
|
106
114
|
});
|
|
107
|
-
const i =
|
|
108
|
-
...
|
|
109
|
-
...
|
|
115
|
+
const i = E || b ? JSON.stringify({
|
|
116
|
+
...E,
|
|
117
|
+
...b
|
|
110
118
|
}) : void 0, n = {
|
|
111
|
-
...
|
|
119
|
+
...u
|
|
112
120
|
};
|
|
113
121
|
i && (n["inkeep-filters"] = i);
|
|
114
|
-
let
|
|
115
|
-
|
|
122
|
+
let s = t;
|
|
123
|
+
s || (s = `conv_${O(16)}`, y(s)), R(s), U(
|
|
116
124
|
{
|
|
117
125
|
text: e
|
|
118
126
|
},
|
|
119
127
|
{
|
|
120
|
-
headers:
|
|
128
|
+
headers: {
|
|
129
|
+
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
130
|
+
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
131
|
+
...n
|
|
132
|
+
},
|
|
121
133
|
body: {
|
|
122
|
-
conversationId:
|
|
123
|
-
requestContext:
|
|
134
|
+
conversationId: s,
|
|
135
|
+
requestContext: p
|
|
124
136
|
}
|
|
125
137
|
}
|
|
126
138
|
);
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
}, Q = () => {
|
|
140
|
+
W().then(() => {
|
|
141
|
+
c("aborted", { conversationId: t });
|
|
130
142
|
});
|
|
131
|
-
},
|
|
132
|
-
|
|
143
|
+
}, F = () => {
|
|
144
|
+
G(), _([]), y(""), d([]), x(null), o({
|
|
133
145
|
eventName: "chat_clear_button_clicked",
|
|
134
146
|
properties: {
|
|
135
|
-
conversationId:
|
|
147
|
+
conversationId: t
|
|
136
148
|
}
|
|
137
149
|
});
|
|
138
|
-
}, { openForm:
|
|
139
|
-
return se(
|
|
140
|
-
submitMessage:
|
|
150
|
+
}, { openForm: V } = ae(), j = ie();
|
|
151
|
+
return se(a.chatFunctionsRef, () => ({
|
|
152
|
+
submitMessage: C,
|
|
141
153
|
updateInputMessage(e) {
|
|
142
|
-
|
|
154
|
+
l(e);
|
|
143
155
|
},
|
|
144
|
-
clearChat:
|
|
156
|
+
clearChat: F,
|
|
145
157
|
openForm: (e) => {
|
|
146
|
-
|
|
158
|
+
j?.setView("chat"), V(e, void 0);
|
|
147
159
|
},
|
|
148
160
|
focusInput: () => {
|
|
149
|
-
|
|
161
|
+
D.current?.focus();
|
|
150
162
|
}
|
|
151
163
|
})), {
|
|
152
164
|
messages: h,
|
|
153
|
-
isLoading:
|
|
154
|
-
isStreaming:
|
|
155
|
-
error:
|
|
156
|
-
setError:
|
|
165
|
+
isLoading: k,
|
|
166
|
+
isStreaming: $,
|
|
167
|
+
error: Z,
|
|
168
|
+
setError: I,
|
|
157
169
|
isSubmitDisabled: v,
|
|
158
|
-
input:
|
|
170
|
+
input: r,
|
|
159
171
|
handleInputChange: T,
|
|
160
|
-
handleInputKeyDown:
|
|
161
|
-
handleSubmit:
|
|
162
|
-
stop:
|
|
163
|
-
clear:
|
|
172
|
+
handleInputKeyDown: J,
|
|
173
|
+
handleSubmit: C,
|
|
174
|
+
stop: Q,
|
|
175
|
+
clear: F,
|
|
164
176
|
isEmpty: h.length === 0,
|
|
165
|
-
inputRef:
|
|
166
|
-
isMobile:
|
|
177
|
+
inputRef: D,
|
|
178
|
+
isMobile: L,
|
|
167
179
|
// Additional state for attachments and workflow
|
|
168
|
-
messageAttachments:
|
|
180
|
+
messageAttachments: q,
|
|
169
181
|
setMessageAttachments: d,
|
|
170
|
-
selectedWorkflow:
|
|
171
|
-
setSelectedWorkflow:
|
|
172
|
-
isNewChat:
|
|
173
|
-
conversationId:
|
|
182
|
+
selectedWorkflow: H,
|
|
183
|
+
setSelectedWorkflow: x,
|
|
184
|
+
isNewChat: B,
|
|
185
|
+
conversationId: t
|
|
174
186
|
};
|
|
175
187
|
};
|
|
176
188
|
export {
|
|
177
|
-
|
|
178
|
-
|
|
189
|
+
le as DEFAULT_ERROR_MESSAGE,
|
|
190
|
+
Ee as useInkeepChat
|
|
179
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
|
}),
|
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: {
|