@inkeep/agents-ui 0.15.5 → 0.15.6
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 +98 -94
- 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 Y=require("@ai-sdk/react"),Z=require("ai"),s=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:o}=ee.useInkeepConfig(),[n="",b]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:D,emitToParent:u}=oe.useStreamingEvents(),[a,l]=s.useState(""),N=e=>l(e.target.value),{filters:y}=C,{onInputMessageChange:U,filters:I,agentUrl:M,context:d,headers:g,apiKey:p}=o,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]=s.useState([]),[H,w]=s.useState(null),K=s.useMemo(()=>new Z.DefaultChatTransport({api:M,headers:{...p?{Authorization:`Bearer ${p}`}:{},...g},body:{requestContext:d}}),[M,p,g,d]),{messages:h,sendMessage:L,status:q,setMessages:_,stop:W,error:f}=Y.useChat({transport:K,onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:n}),await i({eventName:"assistant_message_received",properties:{conversationId:n}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.log("onError",e.message),_(c=>{const r=[...c],t=r[r.length-1];if(t){const P=T(e);t.role==="user"?r.push({id:k.generateUid(16),role:"assistant",parts:[{type:"text",text:P}]}):t.parts=[{type:"text",text:P}]}return r})}}),x=q==="submitted",$=q==="streaming",z=h.length===0,v=!a.trim()||x,B=te.useMediaQuery("(max-width: 768px)"),[G,E]=s.useState(null);s.useEffect(()=>{f&&E(f)},[f]);const Q=()=>E(null),F=s.useRef(null);s.useEffect(()=>{U?.(a)},[a]);const j=e=>{e.key==="Enter"&&!e.shiftKey&&!v&&!e.nativeEvent.isComposing&&(e.preventDefault(),S())},S=async(e=a)=>{if(v&&(!e||e.trim().length===0))return;m([]),l(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=y||I?JSON.stringify({...y,...I}):void 0,r={...g};c&&(r["inkeep-filters"]=c);let t=n;t||(t=`conv_${k.generateUid(16)}`,b(t)),D(t),L({text:e},{headers:r,body:{conversationId:t,requestContext:d}})},J=()=>{W().then(()=>{u("aborted",{conversationId:n})})},R=()=>{Q(),_([]),b(""),m([]),w(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:V}=ne.useChatForm(),X=re.useWidget();return s.useImperativeHandle(o.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:a,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:n}};exports.DEFAULT_ERROR_MESSAGE=A;exports.useInkeepChat=ie;
|
|
@@ -1,58 +1,61 @@
|
|
|
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:
|
|
15
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, be = () => {
|
|
16
|
+
const { baseSettings: y, aiChatSettings: r } = ne(), [s = "", E] = ce({
|
|
17
17
|
prop: r.conversationId,
|
|
18
18
|
defaultProp: r.conversationId ?? ""
|
|
19
|
-
}), { logEvent: a } =
|
|
19
|
+
}), { logEvent: a } = re(), { setConversationId: P, emitToParent: m } = me(), [o, 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
|
-
} = r,
|
|
21
|
+
filters: b
|
|
22
|
+
} = y, {
|
|
23
|
+
onInputMessageChange: q,
|
|
24
|
+
filters: w,
|
|
25
|
+
agentUrl: S,
|
|
26
|
+
context: l,
|
|
27
|
+
headers: p,
|
|
28
|
+
apiKey: g
|
|
29
|
+
} = r, 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
|
},
|
|
@@ -70,106 +73,107 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
70
73
|
});
|
|
71
74
|
},
|
|
72
75
|
onError(e) {
|
|
73
|
-
console.log("onError", e.message),
|
|
76
|
+
console.log("onError", e.message), x((i) => {
|
|
74
77
|
const n = [...i], t = n[n.length - 1];
|
|
75
78
|
if (t) {
|
|
76
|
-
const
|
|
79
|
+
const N = H(e);
|
|
77
80
|
t.role === "user" ? n.push({
|
|
78
|
-
id:
|
|
81
|
+
id: R(16),
|
|
79
82
|
role: "assistant",
|
|
80
|
-
parts: [{ type: "text", text:
|
|
81
|
-
}) : t.parts = [{ type: "text", text:
|
|
83
|
+
parts: [{ type: "text", text: N }]
|
|
84
|
+
}) : t.parts = [{ type: "text", text: N }];
|
|
82
85
|
}
|
|
83
86
|
return n;
|
|
84
87
|
});
|
|
85
88
|
}
|
|
86
|
-
}),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, [
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
}), F = _ === "submitted", B = _ === "streaming", L = h.length === 0, v = !o.trim() || F, O = oe("(max-width: 768px)"), [G, C] = c(null);
|
|
90
|
+
A(() => {
|
|
91
|
+
f && C(f);
|
|
92
|
+
}, [f]);
|
|
93
|
+
const J = () => C(null), k = te(null);
|
|
94
|
+
A(() => {
|
|
95
|
+
q?.(o);
|
|
93
96
|
}, [o]);
|
|
94
|
-
const
|
|
95
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
96
|
-
},
|
|
97
|
-
if (
|
|
98
|
-
|
|
97
|
+
const Q = (e) => {
|
|
98
|
+
e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), I());
|
|
99
|
+
}, I = async (e = o) => {
|
|
100
|
+
if (v && (!e || e.trim().length === 0)) return;
|
|
101
|
+
d([]), u(""), await a({
|
|
99
102
|
eventName: "user_message_submitted",
|
|
100
103
|
properties: {
|
|
101
104
|
conversationId: s
|
|
102
105
|
}
|
|
103
106
|
});
|
|
104
|
-
const i =
|
|
105
|
-
...
|
|
106
|
-
...
|
|
107
|
-
}) : void 0, n = {
|
|
107
|
+
const i = b || w ? JSON.stringify({
|
|
108
|
+
...b,
|
|
109
|
+
...w
|
|
110
|
+
}) : void 0, n = {
|
|
111
|
+
...p
|
|
112
|
+
};
|
|
108
113
|
i && (n["inkeep-filters"] = i);
|
|
109
114
|
let t = s;
|
|
110
|
-
t || (t = `conv_${
|
|
111
|
-
// { ...userMessage, files },
|
|
112
|
-
// { ...userMessage, },
|
|
115
|
+
t || (t = `conv_${R(16)}`, E(t)), P(t), $(
|
|
113
116
|
{
|
|
114
117
|
text: e
|
|
115
118
|
},
|
|
116
119
|
{
|
|
117
120
|
headers: n,
|
|
118
121
|
body: {
|
|
119
|
-
conversationId: t
|
|
122
|
+
conversationId: t,
|
|
123
|
+
requestContext: l
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
);
|
|
123
|
-
},
|
|
124
|
-
|
|
127
|
+
}, V = () => {
|
|
128
|
+
z().then(() => {
|
|
125
129
|
m("aborted", { conversationId: s });
|
|
126
130
|
});
|
|
127
|
-
},
|
|
128
|
-
|
|
131
|
+
}, D = () => {
|
|
132
|
+
J(), x([]), E(""), d([]), M(null), a({
|
|
129
133
|
eventName: "chat_clear_button_clicked",
|
|
130
134
|
properties: {
|
|
131
135
|
conversationId: s
|
|
132
136
|
}
|
|
133
137
|
});
|
|
134
|
-
}, { openForm:
|
|
135
|
-
return
|
|
136
|
-
submitMessage:
|
|
138
|
+
}, { openForm: j } = ae(), X = ie();
|
|
139
|
+
return se(r.chatFunctionsRef, () => ({
|
|
140
|
+
submitMessage: I,
|
|
137
141
|
updateInputMessage(e) {
|
|
138
|
-
|
|
142
|
+
u(e);
|
|
139
143
|
},
|
|
140
|
-
clearChat:
|
|
144
|
+
clearChat: D,
|
|
141
145
|
openForm: (e) => {
|
|
142
|
-
|
|
146
|
+
X?.setView("chat"), j(e, void 0);
|
|
143
147
|
},
|
|
144
148
|
focusInput: () => {
|
|
145
|
-
|
|
149
|
+
k.current?.focus();
|
|
146
150
|
}
|
|
147
151
|
})), {
|
|
148
|
-
messages:
|
|
149
|
-
isLoading:
|
|
150
|
-
isStreaming:
|
|
151
|
-
error:
|
|
152
|
-
setError:
|
|
153
|
-
isSubmitDisabled:
|
|
152
|
+
messages: h,
|
|
153
|
+
isLoading: F,
|
|
154
|
+
isStreaming: B,
|
|
155
|
+
error: G,
|
|
156
|
+
setError: C,
|
|
157
|
+
isSubmitDisabled: v,
|
|
154
158
|
input: o,
|
|
155
|
-
handleInputChange:
|
|
156
|
-
handleInputKeyDown:
|
|
157
|
-
handleSubmit:
|
|
158
|
-
stop:
|
|
159
|
-
clear:
|
|
160
|
-
isEmpty:
|
|
161
|
-
inputRef:
|
|
159
|
+
handleInputChange: T,
|
|
160
|
+
handleInputKeyDown: Q,
|
|
161
|
+
handleSubmit: I,
|
|
162
|
+
stop: V,
|
|
163
|
+
clear: D,
|
|
164
|
+
isEmpty: h.length === 0,
|
|
165
|
+
inputRef: k,
|
|
162
166
|
isMobile: O,
|
|
163
167
|
// Additional state for attachments and workflow
|
|
164
|
-
messageAttachments:
|
|
165
|
-
setMessageAttachments:
|
|
166
|
-
selectedWorkflow:
|
|
167
|
-
setSelectedWorkflow:
|
|
168
|
+
messageAttachments: K,
|
|
169
|
+
setMessageAttachments: d,
|
|
170
|
+
selectedWorkflow: U,
|
|
171
|
+
setSelectedWorkflow: M,
|
|
168
172
|
isNewChat: L,
|
|
169
173
|
conversationId: s
|
|
170
174
|
};
|
|
171
175
|
};
|
|
172
176
|
export {
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
ue as DEFAULT_ERROR_MESSAGE,
|
|
178
|
+
be as useInkeepChat
|
|
175
179
|
};
|
|
@@ -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.5",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.5",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|