@inkeep/agents-ui 0.16.2 → 0.16.4
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/hooks/use-events-api.cjs +1 -1
- package/dist/primitives/hooks/use-events-api.d.ts +3 -1
- package/dist/primitives/hooks/use-events-api.js +30 -29
- package/dist/primitives/hooks/use-feedback-api.cjs +1 -1
- package/dist/primitives/hooks/use-feedback-api.d.ts +3 -1
- package/dist/primitives/hooks/use-feedback-api.js +27 -26
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +33 -33
- package/dist/primitives/providers/feedback-provider.cjs +1 -1
- package/dist/primitives/providers/feedback-provider.js +19 -18
- 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 c=require("react"),f=require("./use-inkeep-api-client.cjs"),h=()=>{};function g({baseUrl:e,appId:a,authToken:r,getCaptchaHeader:u,invalidateCaptcha:l,refreshSession:p,headers:o}){const{fetchWithAuth:s}=f.useInkeepApiClient({appId:a,authToken:r,getCaptchaHeader:u,invalidateCaptcha:l??h,refreshSession:p}),i=c.useRef(o);return i.current=o,{logEvent:c.useCallback(async({body:v})=>{if(e)try{const t=`${e}/run/v1/events`,n=await s(t,{method:"POST",headers:{"Content-Type":"application/json",...i.current},body:JSON.stringify(v)});if(!n.ok){const d=await n.text().catch(()=>"<unreadable>");console.warn(`[events-api] log failed: ${n.status}`,d)}}catch(t){console.warn("[events-api] log threw",t)}},[e,s])}}exports.useEventsApi=g;
|
|
@@ -5,6 +5,8 @@ interface UseEventsApiOptions {
|
|
|
5
5
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
6
6
|
invalidateCaptcha?: () => void;
|
|
7
7
|
refreshSession?: () => Promise<string | null>;
|
|
8
|
+
/** Consumer-provided headers from `aiChatSettings.headers`. */
|
|
9
|
+
headers?: Record<string, string>;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Mirrors the backend's `EventApiInsertSchema` for /run/v1/events.
|
|
@@ -23,7 +25,7 @@ interface LogEventBody {
|
|
|
23
25
|
interface LogEventParams {
|
|
24
26
|
body: LogEventBody;
|
|
25
27
|
}
|
|
26
|
-
export declare function useEventsApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseEventsApiOptions): {
|
|
28
|
+
export declare function useEventsApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, headers, }: UseEventsApiOptions): {
|
|
27
29
|
logEvent: ({ body }: LogEventParams) => Promise<void>;
|
|
28
30
|
};
|
|
29
31
|
export {};
|
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
const
|
|
2
|
+
import { useRef as h, useCallback as v } from "react";
|
|
3
|
+
import { useInkeepApiClient as d } from "./use-inkeep-api-client.js";
|
|
4
|
+
const g = () => {
|
|
5
5
|
};
|
|
6
|
-
function
|
|
6
|
+
function C({
|
|
7
7
|
baseUrl: t,
|
|
8
|
-
appId:
|
|
9
|
-
authToken:
|
|
10
|
-
getCaptchaHeader:
|
|
11
|
-
invalidateCaptcha:
|
|
12
|
-
refreshSession:
|
|
8
|
+
appId: s,
|
|
9
|
+
authToken: c,
|
|
10
|
+
getCaptchaHeader: i,
|
|
11
|
+
invalidateCaptcha: u,
|
|
12
|
+
refreshSession: l,
|
|
13
|
+
headers: o
|
|
13
14
|
}) {
|
|
14
|
-
const { fetchWithAuth:
|
|
15
|
-
appId:
|
|
16
|
-
authToken:
|
|
17
|
-
getCaptchaHeader:
|
|
18
|
-
invalidateCaptcha:
|
|
19
|
-
refreshSession:
|
|
20
|
-
});
|
|
21
|
-
return { logEvent:
|
|
22
|
-
async ({ body:
|
|
23
|
-
if (
|
|
15
|
+
const { fetchWithAuth: a } = d({
|
|
16
|
+
appId: s,
|
|
17
|
+
authToken: c,
|
|
18
|
+
getCaptchaHeader: i,
|
|
19
|
+
invalidateCaptcha: u ?? g,
|
|
20
|
+
refreshSession: l
|
|
21
|
+
}), r = h(o);
|
|
22
|
+
return r.current = o, { logEvent: v(
|
|
23
|
+
async ({ body: p }) => {
|
|
24
|
+
if (t)
|
|
24
25
|
try {
|
|
25
|
-
const
|
|
26
|
+
const e = `${t}/run/v1/events`, n = await a(e, {
|
|
26
27
|
method: "POST",
|
|
27
|
-
headers: { "Content-Type": "application/json" },
|
|
28
|
-
body: JSON.stringify(
|
|
28
|
+
headers: { "Content-Type": "application/json", ...r.current },
|
|
29
|
+
body: JSON.stringify(p)
|
|
29
30
|
});
|
|
30
|
-
if (!
|
|
31
|
-
const
|
|
32
|
-
console.warn(`[events-api] log failed: ${
|
|
31
|
+
if (!n.ok) {
|
|
32
|
+
const f = await n.text().catch(() => "<unreadable>");
|
|
33
|
+
console.warn(`[events-api] log failed: ${n.status}`, f);
|
|
33
34
|
}
|
|
34
|
-
} catch (
|
|
35
|
-
console.warn("[events-api] log threw",
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.warn("[events-api] log threw", e);
|
|
36
37
|
}
|
|
37
38
|
},
|
|
38
|
-
[t,
|
|
39
|
+
[t, a]
|
|
39
40
|
) };
|
|
40
41
|
}
|
|
41
42
|
export {
|
|
42
|
-
|
|
43
|
+
C as useEventsApi
|
|
43
44
|
};
|
|
@@ -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 c=require("react"),h=require("./use-inkeep-api-client.cjs"),y=()=>{};function m({baseUrl:e,appId:o,authToken:r,getCaptchaHeader:u,invalidateCaptcha:a,refreshSession:d,headers:n}){const{fetchWithAuth:i}=h.useInkeepApiClient({appId:o,authToken:r,getCaptchaHeader:u,invalidateCaptcha:a??y,refreshSession:d}),s=c.useRef(n);return s.current=n,{submitFeedback:c.useCallback(async({conversationId:p,messageId:b,type:f,details:k})=>{if(!e)return;const l=`${e}/run/v1/feedback`,t=await i(l,{method:"POST",headers:{"Content-Type":"application/json",...s.current},body:JSON.stringify({conversationId:p,messageId:b,type:f,details:k})});if(!t.ok)throw new Error(`Feedback submission failed: ${t.status}`);return t.json()},[e,i])}}exports.useFeedbackApi=m;
|
|
@@ -6,6 +6,8 @@ interface UseFeedbackApiOptions {
|
|
|
6
6
|
getCaptchaHeader: () => Promise<Record<string, string>>;
|
|
7
7
|
invalidateCaptcha?: () => void;
|
|
8
8
|
refreshSession?: () => Promise<string | null>;
|
|
9
|
+
/** Consumer-provided headers from `aiChatSettings.headers`. */
|
|
10
|
+
headers?: Record<string, string>;
|
|
9
11
|
}
|
|
10
12
|
interface SubmitFeedbackParams {
|
|
11
13
|
conversationId: string;
|
|
@@ -13,7 +15,7 @@ interface SubmitFeedbackParams {
|
|
|
13
15
|
type: FeedbackType;
|
|
14
16
|
details?: string | null;
|
|
15
17
|
}
|
|
16
|
-
export declare function useFeedbackApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, }: UseFeedbackApiOptions): {
|
|
18
|
+
export declare function useFeedbackApi({ baseUrl, appId, authToken, getCaptchaHeader, invalidateCaptcha, refreshSession, headers, }: UseFeedbackApiOptions): {
|
|
17
19
|
submitFeedback: ({ conversationId, messageId, type, details }: SubmitFeedbackParams) => Promise<any>;
|
|
18
20
|
};
|
|
19
21
|
export {};
|
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback as
|
|
3
|
-
import { useInkeepApiClient as
|
|
4
|
-
const
|
|
2
|
+
import { useRef as m, useCallback as h } from "react";
|
|
3
|
+
import { useInkeepApiClient as l } from "./use-inkeep-api-client.js";
|
|
4
|
+
const y = () => {
|
|
5
5
|
};
|
|
6
|
-
function
|
|
6
|
+
function A({
|
|
7
7
|
baseUrl: e,
|
|
8
|
-
appId:
|
|
9
|
-
authToken:
|
|
10
|
-
getCaptchaHeader:
|
|
11
|
-
invalidateCaptcha:
|
|
12
|
-
refreshSession:
|
|
8
|
+
appId: r,
|
|
9
|
+
authToken: s,
|
|
10
|
+
getCaptchaHeader: c,
|
|
11
|
+
invalidateCaptcha: u,
|
|
12
|
+
refreshSession: a,
|
|
13
|
+
headers: n
|
|
13
14
|
}) {
|
|
14
|
-
const { fetchWithAuth:
|
|
15
|
-
appId:
|
|
16
|
-
authToken:
|
|
17
|
-
getCaptchaHeader:
|
|
18
|
-
invalidateCaptcha:
|
|
19
|
-
refreshSession:
|
|
20
|
-
});
|
|
21
|
-
return { submitFeedback:
|
|
22
|
-
async ({ conversationId:
|
|
23
|
-
if (!e
|
|
24
|
-
const
|
|
15
|
+
const { fetchWithAuth: o } = l({
|
|
16
|
+
appId: r,
|
|
17
|
+
authToken: s,
|
|
18
|
+
getCaptchaHeader: c,
|
|
19
|
+
invalidateCaptcha: u ?? y,
|
|
20
|
+
refreshSession: a
|
|
21
|
+
}), i = m(n);
|
|
22
|
+
return i.current = n, { submitFeedback: h(
|
|
23
|
+
async ({ conversationId: f, messageId: p, type: d, details: b }) => {
|
|
24
|
+
if (!e) return;
|
|
25
|
+
const k = `${e}/run/v1/feedback`, t = await o(k, {
|
|
25
26
|
method: "POST",
|
|
26
|
-
headers: { "Content-Type": "application/json" },
|
|
27
|
-
body: JSON.stringify({ conversationId:
|
|
27
|
+
headers: { "Content-Type": "application/json", ...i.current },
|
|
28
|
+
body: JSON.stringify({ conversationId: f, messageId: p, type: d, details: b })
|
|
28
29
|
});
|
|
29
|
-
if (!
|
|
30
|
-
return
|
|
30
|
+
if (!t.ok) throw new Error(`Feedback submission failed: ${t.status}`);
|
|
31
|
+
return t.json();
|
|
31
32
|
},
|
|
32
|
-
[e,
|
|
33
|
+
[e, o]
|
|
33
34
|
) };
|
|
34
35
|
}
|
|
35
36
|
export {
|
|
36
|
-
|
|
37
|
+
A as useFeedbackApi
|
|
37
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.16.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.16.4",a=t.useMemo(()=>({widgetLibraryVersion:c,componentType:o,tags:r}),[o,r,c]),v={logEvent:t.useCallback(async u=>{const E={...a,...u.properties,...i},d={eventName:u.eventName,properties:E};return s.onEvent?.(d)},[s,a,i])};return l.jsx(n.Provider,{value:v,children:e})},m=()=>{const e=t.useContext(n);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsContext=n;exports.BaseEventsProvider=g;exports.useBaseEvents=m;
|
|
@@ -3,7 +3,7 @@ import { jsx as u } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext as E, useMemo as d, useCallback as l, useContext as g } from "react";
|
|
4
4
|
import { useInkeepConfig as x } from "./config-provider.js";
|
|
5
5
|
const c = E(void 0), b = ({ children: e }) => {
|
|
6
|
-
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.16.
|
|
6
|
+
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.16.4", i = d(
|
|
7
7
|
() => ({
|
|
8
8
|
widgetLibraryVersion: r,
|
|
9
9
|
componentType: o,
|
|
@@ -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 j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.16.4",a=u.useMemo(()=>({widgetLibraryVersion:c,componentType:i}),[i,c]),{effectiveAuthToken:b,applicableRefreshSession:f,getCaptchaHeader:E,invalidateCaptcha:P}=O.useChatAuth(),{baseUrl:m,appId:A,analyticsApiBaseUrl:C,headers:I}=h,p=y?.optOutAllAnalytics??!1,{logEvent:l}=U.useEventsApi({baseUrl:C??m,appId:A,authToken:b,getCaptchaHeader:E,invalidateCaptcha:P,refreshSession:f,headers:I}),k={logEvent:u.useCallback(async s=>{const q={eventName:s.eventName,properties:{...a,...t?{tags:t}:{},...s.properties,...r}};if(!p){const e=s.properties??{},v=typeof e.conversationId=="string"?e.conversationId:void 0,d=typeof e.messageId=="string"?e.messageId:void 0,S=!!o&&Object.keys(o).length>0,w={...t?{tags:t}:{},...r??{}},T={...a,...s.properties};l({body:{type:s.eventName,...v?{conversationId:v}:{},...d?{messageId:d}:{},...S?{userProperties:o}:{},properties:w,metadata:T}})}try{return await n.onEvent?.(q)}catch(e){console.warn("[events] onEvent callback threw",e)}},[n,a,t,r,l,p,o])};return j.jsx(x.BaseEventsContext.Provider,{value:k,children:g})};exports.ChatBaseEventsProvider=M;
|
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useMemo as
|
|
4
|
-
import { useInkeepConfig as
|
|
5
|
-
import { useChatAuth as
|
|
6
|
-
import { useEventsApi as
|
|
7
|
-
import { BaseEventsContext as
|
|
8
|
-
const
|
|
9
|
-
const { baseSettings:
|
|
2
|
+
import { jsx as U } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo as x, useCallback as B } from "react";
|
|
4
|
+
import { useInkeepConfig as N } from "./config-provider.js";
|
|
5
|
+
import { useChatAuth as O } from "./chat-auth-provider.js";
|
|
6
|
+
import { useEventsApi as j } from "../hooks/use-events-api.js";
|
|
7
|
+
import { BaseEventsContext as M } from "./base-events-provider.js";
|
|
8
|
+
const F = ({ children: m }) => {
|
|
9
|
+
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.16.4", a = x(
|
|
10
10
|
() => ({
|
|
11
|
-
widgetLibraryVersion:
|
|
12
|
-
componentType:
|
|
11
|
+
widgetLibraryVersion: c,
|
|
12
|
+
componentType: i
|
|
13
13
|
}),
|
|
14
|
-
[
|
|
15
|
-
), { effectiveAuthToken:
|
|
14
|
+
[i, c]
|
|
15
|
+
), { effectiveAuthToken: h, applicableRefreshSession: u, getCaptchaHeader: y, invalidateCaptcha: b } = O(), { baseUrl: A, appId: E, analyticsApiBaseUrl: C, headers: I } = g, p = f?.optOutAllAnalytics ?? !1, { logEvent: l } = j({
|
|
16
16
|
baseUrl: C ?? A,
|
|
17
17
|
appId: E,
|
|
18
|
-
authToken:
|
|
18
|
+
authToken: h,
|
|
19
19
|
getCaptchaHeader: y,
|
|
20
20
|
invalidateCaptcha: b,
|
|
21
|
-
refreshSession:
|
|
22
|
-
|
|
21
|
+
refreshSession: u,
|
|
22
|
+
headers: I
|
|
23
|
+
}), P = { logEvent: B(
|
|
23
24
|
async (s) => {
|
|
24
|
-
const
|
|
25
|
+
const k = {
|
|
25
26
|
eventName: s.eventName,
|
|
26
27
|
properties: {
|
|
27
28
|
...a,
|
|
28
29
|
...t ? { tags: t } : {},
|
|
29
30
|
...s.properties,
|
|
30
|
-
...
|
|
31
|
+
...n
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
if (!
|
|
34
|
-
const e = s.properties ?? {},
|
|
34
|
+
if (!p) {
|
|
35
|
+
const e = s.properties ?? {}, v = typeof e.conversationId == "string" ? e.conversationId : void 0, d = typeof e.messageId == "string" ? e.messageId : void 0, w = !!o && Object.keys(o).length > 0, S = {
|
|
35
36
|
...t ? { tags: t } : {},
|
|
36
|
-
...
|
|
37
|
-
},
|
|
37
|
+
...n ?? {}
|
|
38
|
+
}, T = {
|
|
38
39
|
...a,
|
|
39
40
|
...s.properties
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
+
l({
|
|
42
43
|
body: {
|
|
43
44
|
type: s.eventName,
|
|
44
|
-
...
|
|
45
|
+
...v ? { conversationId: v } : {},
|
|
45
46
|
...d ? { messageId: d } : {},
|
|
46
|
-
...
|
|
47
|
-
properties:
|
|
48
|
-
metadata:
|
|
47
|
+
...w ? { userProperties: o } : {},
|
|
48
|
+
properties: S,
|
|
49
|
+
metadata: T
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
try {
|
|
53
|
-
return await
|
|
54
|
+
return await r.onEvent?.(k);
|
|
54
55
|
} catch (e) {
|
|
55
56
|
console.warn("[events] onEvent callback threw", e);
|
|
56
57
|
}
|
|
57
58
|
},
|
|
58
59
|
[
|
|
59
|
-
|
|
60
|
+
r,
|
|
60
61
|
a,
|
|
61
62
|
t,
|
|
62
|
-
|
|
63
|
-
v,
|
|
63
|
+
n,
|
|
64
64
|
l,
|
|
65
|
-
|
|
65
|
+
p,
|
|
66
66
|
o
|
|
67
67
|
]
|
|
68
68
|
) };
|
|
69
|
-
return /* @__PURE__ */
|
|
69
|
+
return /* @__PURE__ */ U(M.Provider, { value: P, children: m });
|
|
70
70
|
};
|
|
71
71
|
export {
|
|
72
|
-
|
|
72
|
+
F as ChatBaseEventsProvider
|
|
73
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),a=require("react"),T=require("../components/embedded-chat/chat-provider.cjs"),F=require("../utils/misc.cjs"),A=require("./config-provider.cjs"),E=require("./base-events-provider.cjs"),j=require("../hooks/use-feedback-api.cjs"),l=a.createContext(void 0);function y(){const{baseSettings:t,aiChatSettings:c}=A.useInkeepConfig(),[p,g]=a.useState(null),[f,C]=a.useState({}),{conversationId:o,messages:r,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}=T.useChat(),{analyticsProperties:d}=t,{logEvent:b}=E.useBaseEvents(),{submitFeedback:k}=j.useFeedbackApi({baseUrl:c.baseUrl,appId:c.appId,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}),i=a.useCallback(async(e,s,u)=>{C(n=>({...n,[e]:{type:s,messageId:e,details:u}})),t.onFeedback?t.onFeedback({type:s,messageId:e,details:u,properties:d}).catch(n=>console.warn("[feedback] onFeedback error:",n)):k({conversationId:o,messageId:e,type:s,details:u}).catch(n=>console.warn("[feedback] submitFeedbackToApi error:",n));const v=r.findIndex(n=>n.id===e),x=r[v],S={conversationId:o,question:F.getMessageContent(r[v-1]),answer:F.getMessageContent(x),messageId:e,details:u};b({eventName:s==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:S}),s==="negative"&&b({eventName:"user_escalation_indicated",properties:{escalationType:"downvote",conversationId:o,messageId:e}})},[r,o,d,t,b,k]),_=a.useCallback(async e=>{i(e,"positive")},[i]),w=a.useCallback(async(e,s)=>{i(e,"negative",s)},[i]);return{feedback:f,currentFeedback:p,setCurrentFeedback:g,submitPositiveFeedback:_,submitNegativeFeedback:w}}const N=({children:t})=>{const c=y();return M.jsx(l.Provider,{value:c,children:t})},R=()=>{const t=a.useContext(l);if(!t)throw new Error("useFeedback must be used within a FeedbackProvider");return t};exports.FeedbackProvider=N;exports.useMessageFeedback=R;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),a=require("react"),T=require("../components/embedded-chat/chat-provider.cjs"),F=require("../utils/misc.cjs"),A=require("./config-provider.cjs"),E=require("./base-events-provider.cjs"),j=require("../hooks/use-feedback-api.cjs"),l=a.createContext(void 0);function y(){const{baseSettings:t,aiChatSettings:c}=A.useInkeepConfig(),[p,g]=a.useState(null),[f,C]=a.useState({}),{conversationId:o,messages:r,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q}=T.useChat(),{analyticsProperties:d}=t,{logEvent:b}=E.useBaseEvents(),{submitFeedback:k}=j.useFeedbackApi({baseUrl:c.baseUrl,appId:c.appId,authToken:h,getCaptchaHeader:m,invalidateCaptcha:P,refreshSession:q,headers:c.headers}),i=a.useCallback(async(e,s,u)=>{C(n=>({...n,[e]:{type:s,messageId:e,details:u}})),t.onFeedback?t.onFeedback({type:s,messageId:e,details:u,properties:d}).catch(n=>console.warn("[feedback] onFeedback error:",n)):k({conversationId:o,messageId:e,type:s,details:u}).catch(n=>console.warn("[feedback] submitFeedbackToApi error:",n));const v=r.findIndex(n=>n.id===e),x=r[v],S={conversationId:o,question:F.getMessageContent(r[v-1]),answer:F.getMessageContent(x),messageId:e,details:u};b({eventName:s==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:S}),s==="negative"&&b({eventName:"user_escalation_indicated",properties:{escalationType:"downvote",conversationId:o,messageId:e}})},[r,o,d,t,b,k]),_=a.useCallback(async e=>{i(e,"positive")},[i]),w=a.useCallback(async(e,s)=>{i(e,"negative",s)},[i]);return{feedback:f,currentFeedback:p,setCurrentFeedback:g,submitPositiveFeedback:_,submitNegativeFeedback:w}}const N=({children:t})=>{const c=y();return M.jsx(l.Provider,{value:c,children:t})},R=()=>{const t=a.useContext(l);if(!t)throw new Error("useFeedback must be used within a FeedbackProvider");return t};exports.FeedbackProvider=N;exports.useMessageFeedback=R;
|
|
@@ -8,9 +8,9 @@ import { useBaseEvents as q } from "./base-events-provider.js";
|
|
|
8
8
|
import { useFeedbackApi as y } from "../hooks/use-feedback-api.js";
|
|
9
9
|
const f = M(void 0);
|
|
10
10
|
function B() {
|
|
11
|
-
const { baseSettings: t, aiChatSettings: n } = j(), [F, l] = m(null), [
|
|
11
|
+
const { baseSettings: t, aiChatSettings: n } = j(), [F, l] = m(null), [h, C] = m({}), {
|
|
12
12
|
conversationId: a,
|
|
13
|
-
messages:
|
|
13
|
+
messages: r,
|
|
14
14
|
authToken: g,
|
|
15
15
|
getCaptchaHeader: _,
|
|
16
16
|
invalidateCaptcha: w,
|
|
@@ -21,23 +21,24 @@ function B() {
|
|
|
21
21
|
authToken: g,
|
|
22
22
|
getCaptchaHeader: _,
|
|
23
23
|
invalidateCaptcha: w,
|
|
24
|
-
refreshSession: x
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
refreshSession: x,
|
|
25
|
+
headers: n.headers
|
|
26
|
+
}), c = d(
|
|
27
|
+
async (e, s, i) => {
|
|
28
|
+
C((o) => ({ ...o, [e]: { type: s, messageId: e, details: i } })), t.onFeedback ? t.onFeedback({ type: s, messageId: e, details: i, properties: u }).catch((o) => console.warn("[feedback] onFeedback error:", o)) : k({ conversationId: a, messageId: e, type: s, details: i }).catch(
|
|
29
|
+
(o) => console.warn("[feedback] submitFeedbackToApi error:", o)
|
|
29
30
|
);
|
|
30
|
-
const p =
|
|
31
|
+
const p = r.findIndex((o) => o.id === e), T = r[p], A = {
|
|
31
32
|
conversationId: a,
|
|
32
|
-
question: v(
|
|
33
|
+
question: v(r[p - 1]),
|
|
33
34
|
answer: v(T),
|
|
34
35
|
messageId: e,
|
|
35
36
|
details: i
|
|
36
37
|
};
|
|
37
38
|
b({
|
|
38
|
-
eventName:
|
|
39
|
+
eventName: s === "positive" ? "assistant_positive_feedback_submitted" : "assistant_negative_feedback_submitted",
|
|
39
40
|
properties: A
|
|
40
|
-
}),
|
|
41
|
+
}), s === "negative" && b({
|
|
41
42
|
eventName: "user_escalation_indicated",
|
|
42
43
|
properties: {
|
|
43
44
|
escalationType: "downvote",
|
|
@@ -46,20 +47,20 @@ function B() {
|
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
49
|
},
|
|
49
|
-
[
|
|
50
|
+
[r, a, u, t, b, k]
|
|
50
51
|
), P = d(
|
|
51
52
|
async (e) => {
|
|
52
|
-
|
|
53
|
+
c(e, "positive");
|
|
53
54
|
},
|
|
54
|
-
[
|
|
55
|
+
[c]
|
|
55
56
|
), S = d(
|
|
56
|
-
async (e,
|
|
57
|
-
|
|
57
|
+
async (e, s) => {
|
|
58
|
+
c(e, "negative", s);
|
|
58
59
|
},
|
|
59
|
-
[
|
|
60
|
+
[c]
|
|
60
61
|
);
|
|
61
62
|
return {
|
|
62
|
-
feedback:
|
|
63
|
+
feedback: h,
|
|
63
64
|
currentFeedback: F,
|
|
64
65
|
setCurrentFeedback: l,
|
|
65
66
|
submitPositiveFeedback: P,
|