@inkeep/agents-ui 0.14.15 → 0.14.16
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 +28 -28
- 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:f,aiChatSettings:o}=Z.useInkeepConfig(),[n="",v]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ie=()=>{const{baseSettings:f,aiChatSettings:o}=Z.useInkeepConfig(),[n="",v]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:R,emitToParent:E}=oe.useStreamingEvents(),[a,u]=t.useState(""),P=e=>u(e.target.value),{filters:S}=f,{onInputMessageChange:k,filters:C,agentUrl:A,context:D,headers:x,apiKey:I}=o,N=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return F}},[T,U]=t.useState({}),[B,l]=t.useState([]),[O,b]=t.useState(null),{messages:g,sendMessage:K,status:y,setMessages:w,stop:L,error:d}=X.useChat({transport:new Y.DefaultChatTransport({api:A,headers:{...I?{Authorization:`Bearer ${I}`}:{},...x},body:{requestContext:D}}),onData(e){E(e.type,e.data)},async onFinish(){E("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),w(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:N(e)}]),r})}}),M=y==="submitted",W=y==="streaming",$=g.length===0,m=!a.trim()||M,z=ee.useMediaQuery("(max-width: 768px)"),[G,p]=t.useState(null);t.useEffect(()=>{d&&p(d)},[d]);const H=()=>p(null),_=t.useRef(null);t.useEffect(()=>{k?.(a)},[a]);const Q=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),h())},h=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=S||C?JSON.stringify({...S,...C}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${te.generateUid(16)}`,v(s)),R(s),K({text:e},{headers:r,body:{conversationId:s}})},j=()=>{L()},q=()=>{H(),w([]),v(""),U({}),l([]),b(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:J}=ne.useChatForm(),V=re.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:h,updateInputMessage(e){u(e)},clearChat:q,openForm:e=>{V?.setView("chat"),J(e,void 0)},focusInput:()=>{_.current?.focus()}})),{messages:g,isLoading:M,isStreaming:W,error:G,setError:p,isSubmitDisabled:m,input:a,handleInputChange:P,handleInputKeyDown:Q,handleSubmit:h,stop:j,clear:q,messageButtons:T,isEmpty:g.length===0,inputRef:_,isMobile:z,messageAttachments:B,setMessageAttachments:l,selectedWorkflow:O,setSelectedWorkflow:b,isNewChat:$,conversationId:n}};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";
|
|
@@ -16,16 +16,16 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
16
16
|
const { baseSettings: f, aiChatSettings: a } = te(), [s = "", v] = ie({
|
|
17
17
|
prop: a.conversationId,
|
|
18
18
|
defaultProp: a.conversationId ?? ""
|
|
19
|
-
}), { logEvent: i } = oe(), { setConversationId:
|
|
19
|
+
}), { logEvent: i } = oe(), { setConversationId: k, emitToParent: I } = ce(), [o, m] = r(""), D = (e) => m(e.target.value), {
|
|
20
20
|
/* shouldBypassCaptcha, */
|
|
21
|
-
filters:
|
|
21
|
+
filters: C
|
|
22
22
|
} = f, {
|
|
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: y
|
|
29
29
|
} = a, P = (e) => {
|
|
30
30
|
switch (e.code) {
|
|
31
31
|
case 400:
|
|
@@ -35,18 +35,18 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
35
35
|
default:
|
|
36
36
|
return me;
|
|
37
37
|
}
|
|
38
|
-
}, [T, K] = r({}), [U, u] = r([]), [W,
|
|
38
|
+
}, [T, K] = r({}), [U, u] = r([]), [W, b] = r(null), {
|
|
39
39
|
messages: l,
|
|
40
40
|
sendMessage: $,
|
|
41
|
-
status:
|
|
42
|
-
setMessages:
|
|
41
|
+
status: w,
|
|
42
|
+
setMessages: S,
|
|
43
43
|
stop: z,
|
|
44
44
|
error: p
|
|
45
45
|
} = X({
|
|
46
46
|
transport: new Y({
|
|
47
47
|
api: A,
|
|
48
48
|
headers: {
|
|
49
|
-
...
|
|
49
|
+
...y ? { Authorization: `Bearer ${y}` } : {},
|
|
50
50
|
...B
|
|
51
51
|
},
|
|
52
52
|
body: {
|
|
@@ -54,10 +54,10 @@ 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
|
+
I(e.type, e.data);
|
|
58
58
|
},
|
|
59
59
|
async onFinish() {
|
|
60
|
-
await i({
|
|
60
|
+
I("completion", { conversationId: s }), await i({
|
|
61
61
|
eventName: "assistant_message_received",
|
|
62
62
|
properties: {
|
|
63
63
|
conversationId: s
|
|
@@ -70,17 +70,17 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
70
70
|
});
|
|
71
71
|
},
|
|
72
72
|
onError(e) {
|
|
73
|
-
console.log("onError", e.message),
|
|
73
|
+
console.log("onError", e.message), S((c) => {
|
|
74
74
|
const n = [...c], t = n[n.length - 1];
|
|
75
75
|
return t && (t.parts = [{ type: "text", text: P(e) }]), n;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
}),
|
|
79
|
-
|
|
78
|
+
}), M = w === "submitted", H = w === "streaming", L = l.length === 0, g = !o.trim() || M, O = se("(max-width: 768px)"), [q, d] = r(null);
|
|
79
|
+
F(() => {
|
|
80
80
|
p && d(p);
|
|
81
81
|
}, [p]);
|
|
82
|
-
const G = () => d(null),
|
|
83
|
-
|
|
82
|
+
const G = () => d(null), _ = Z(null);
|
|
83
|
+
F(() => {
|
|
84
84
|
N?.(o);
|
|
85
85
|
}, [o]);
|
|
86
86
|
const J = (e) => {
|
|
@@ -93,13 +93,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
93
93
|
conversationId: s
|
|
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
101
|
let t = s;
|
|
102
|
-
t || (t = `conv_${ne(16)}`, v(t)),
|
|
102
|
+
t || (t = `conv_${ne(16)}`, v(t)), k(t), $(
|
|
103
103
|
// { ...userMessage, files },
|
|
104
104
|
// { ...userMessage, },
|
|
105
105
|
{
|
|
@@ -114,8 +114,8 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
114
114
|
);
|
|
115
115
|
}, Q = () => {
|
|
116
116
|
z();
|
|
117
|
-
},
|
|
118
|
-
G(),
|
|
117
|
+
}, x = () => {
|
|
118
|
+
G(), S([]), v(""), K({}), u([]), b(null), i({
|
|
119
119
|
eventName: "chat_clear_button_clicked",
|
|
120
120
|
properties: {
|
|
121
121
|
conversationId: s
|
|
@@ -127,16 +127,16 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
127
127
|
updateInputMessage(e) {
|
|
128
128
|
m(e);
|
|
129
129
|
},
|
|
130
|
-
clearChat:
|
|
130
|
+
clearChat: x,
|
|
131
131
|
openForm: (e) => {
|
|
132
132
|
j?.setView("chat"), V(e, void 0);
|
|
133
133
|
},
|
|
134
134
|
focusInput: () => {
|
|
135
|
-
|
|
135
|
+
_.current?.focus();
|
|
136
136
|
}
|
|
137
137
|
})), {
|
|
138
138
|
messages: l,
|
|
139
|
-
isLoading:
|
|
139
|
+
isLoading: M,
|
|
140
140
|
isStreaming: H,
|
|
141
141
|
error: q,
|
|
142
142
|
setError: d,
|
|
@@ -146,16 +146,16 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
146
146
|
handleInputKeyDown: J,
|
|
147
147
|
handleSubmit: h,
|
|
148
148
|
stop: Q,
|
|
149
|
-
clear:
|
|
149
|
+
clear: x,
|
|
150
150
|
messageButtons: T,
|
|
151
151
|
isEmpty: l.length === 0,
|
|
152
|
-
inputRef:
|
|
152
|
+
inputRef: _,
|
|
153
153
|
isMobile: O,
|
|
154
154
|
// Additional state for attachments and workflow
|
|
155
155
|
messageAttachments: U,
|
|
156
156
|
setMessageAttachments: u,
|
|
157
157
|
selectedWorkflow: W,
|
|
158
|
-
setSelectedWorkflow:
|
|
158
|
+
setSelectedWorkflow: b,
|
|
159
159
|
isNewChat: L,
|
|
160
160
|
conversationId: s
|
|
161
161
|
};
|
|
@@ -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.15",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.15",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|