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