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