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