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