@inkeep/cxkit-primitives 0.5.94 → 0.5.96

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/index.d.cts CHANGED
@@ -63,6 +63,7 @@ import { RefAttributes } from 'react';
63
63
  import { RefObject } from 'react';
64
64
  import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
65
65
  import { SearchHit } from '@inkeep/cxkit-types';
66
+ import { SelectItem } from '@inkeep/cxkit-types';
66
67
  import { SetStateAction } from 'react';
67
68
  import { SourceItem } from '@inkeep/cxkit-types';
68
69
  import { SVGProps } from 'react';
@@ -397,7 +398,7 @@ export declare type ChatEventsContextValue = {
397
398
  * Pass messages if you want it to also log a conversation.
398
399
  * The conversation will be appended to the event properties.
399
400
  */
400
- logEvent: (event: InkeepEvent, messages?: Message[]) => void;
401
+ logEvent: (event: InkeepEvent, messages?: Message[]) => Promise<void>;
401
402
  /**
402
403
  * Log a conversation.
403
404
  */
@@ -3483,7 +3484,7 @@ declare const PrimitiveFooter: ForwardRefExoticComponent< PolymorphicProps & Omi
3483
3484
 
3484
3485
  declare const PrimitiveForm: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "_id"> & Partial<Pick< DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "_id">>>;
3485
3486
 
3486
- declare const PrimitiveFormCancel: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id">>>;
3487
+ declare const PrimitiveFormCancel: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "type" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "type" | "_id">>>;
3487
3488
 
3488
3489
  declare const PrimitiveFormClose: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id">>>;
3489
3490
 
@@ -3957,7 +3958,7 @@ declare const SelectIcon: React_2.ForwardRefExoticComponent<SelectIconProps & Re
3957
3958
  declare interface SelectIconProps extends PrimitiveSpanProps {
3958
3959
  }
3959
3960
 
3960
- declare const SelectItem: React_2.ForwardRefExoticComponent<SelectItemProps & React_2.RefAttributes<HTMLDivElement>>;
3961
+ declare const SelectItem_2: React_2.ForwardRefExoticComponent<SelectItemProps & React_2.RefAttributes<HTMLDivElement>>;
3961
3962
 
3962
3963
  declare interface SelectItemAlignedPositionProps extends PrimitiveDivProps_2, SelectPopperPrivateProps {
3963
3964
  }
@@ -4013,7 +4014,7 @@ declare namespace SelectPrimitive {
4013
4014
  SelectViewport,
4014
4015
  SelectGroup,
4015
4016
  SelectLabel,
4016
- SelectItem,
4017
+ SelectItem_2 as SelectItem,
4017
4018
  SelectItemText,
4018
4019
  SelectItemIndicator,
4019
4020
  SelectScrollUpButton,
@@ -4310,7 +4311,7 @@ export declare const useChatForm: () => ChatFormContextValue;
4310
4311
 
4311
4312
  export declare function useChatFormState(): {
4312
4313
  form: AIChatFormSettings | null;
4313
- openForm: (formSettings: AIChatFormSettings) => void;
4314
+ openForm: (formSettings: AIChatFormSettings, getHelpOption?: GetHelpOption) => void;
4314
4315
  closeForm: () => void;
4315
4316
  handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
4316
4317
  isSuccess: boolean;
@@ -4319,7 +4320,50 @@ export declare function useChatFormState(): {
4319
4320
  type: string | number;
4320
4321
  message: Message_2;
4321
4322
  }> | undefined;
4322
- fields: FormField[] | undefined;
4323
+ fields: ({
4324
+ inputType: "checkbox";
4325
+ defaultValue?: boolean;
4326
+ name: string;
4327
+ label: string;
4328
+ isRequired?: boolean;
4329
+ isHidden?: boolean;
4330
+ description?: string;
4331
+ } | {
4332
+ inputType: "file";
4333
+ name: string;
4334
+ label: string;
4335
+ isRequired?: boolean;
4336
+ isHidden?: boolean;
4337
+ description?: string;
4338
+ } | {
4339
+ inputType: "select";
4340
+ items: SelectItem[];
4341
+ defaultValue?: string;
4342
+ placeholder?: string;
4343
+ name: string;
4344
+ label: string;
4345
+ isRequired?: boolean;
4346
+ isHidden?: boolean;
4347
+ description?: string;
4348
+ } | {
4349
+ inputType: "email" | "text" | "textarea";
4350
+ defaultValue?: string;
4351
+ placeholder?: string;
4352
+ name: string;
4353
+ label: string;
4354
+ isRequired?: boolean;
4355
+ isHidden?: boolean;
4356
+ description?: string;
4357
+ } | {
4358
+ _type: "include_chat_session";
4359
+ inputType?: "checkbox";
4360
+ defaultValue?: boolean;
4361
+ name: string;
4362
+ label: string;
4363
+ isRequired?: boolean;
4364
+ isHidden?: boolean;
4365
+ description?: string;
4366
+ })[] | undefined;
4323
4367
  errors: FieldErrors<Record<string, any>>;
4324
4368
  control: Control<Record<string, any>, any>;
4325
4369
  defaultValues: Record<string, any>;
package/dist/index.d.ts CHANGED
@@ -63,6 +63,7 @@ import { RefAttributes } from 'react';
63
63
  import { RefObject } from 'react';
64
64
  import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
65
65
  import { SearchHit } from '@inkeep/cxkit-types';
66
+ import { SelectItem } from '@inkeep/cxkit-types';
66
67
  import { SetStateAction } from 'react';
67
68
  import { SourceItem } from '@inkeep/cxkit-types';
68
69
  import { SVGProps } from 'react';
@@ -397,7 +398,7 @@ export declare type ChatEventsContextValue = {
397
398
  * Pass messages if you want it to also log a conversation.
398
399
  * The conversation will be appended to the event properties.
399
400
  */
400
- logEvent: (event: InkeepEvent, messages?: Message[]) => void;
401
+ logEvent: (event: InkeepEvent, messages?: Message[]) => Promise<void>;
401
402
  /**
402
403
  * Log a conversation.
403
404
  */
@@ -3483,7 +3484,7 @@ declare const PrimitiveFooter: ForwardRefExoticComponent< PolymorphicProps & Omi
3483
3484
 
3484
3485
  declare const PrimitiveForm: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "_id"> & Partial<Pick< DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "_id">>>;
3485
3486
 
3486
- declare const PrimitiveFormCancel: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id">>>;
3487
+ declare const PrimitiveFormCancel: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "type" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "type" | "_id">>>;
3487
3488
 
3488
3489
  declare const PrimitiveFormClose: ForwardRefExoticComponent< PolymorphicProps & Omit< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id"> & Partial<Pick< DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "_id">>>;
3489
3490
 
@@ -3957,7 +3958,7 @@ declare const SelectIcon: React_2.ForwardRefExoticComponent<SelectIconProps & Re
3957
3958
  declare interface SelectIconProps extends PrimitiveSpanProps {
3958
3959
  }
3959
3960
 
3960
- declare const SelectItem: React_2.ForwardRefExoticComponent<SelectItemProps & React_2.RefAttributes<HTMLDivElement>>;
3961
+ declare const SelectItem_2: React_2.ForwardRefExoticComponent<SelectItemProps & React_2.RefAttributes<HTMLDivElement>>;
3961
3962
 
3962
3963
  declare interface SelectItemAlignedPositionProps extends PrimitiveDivProps_2, SelectPopperPrivateProps {
3963
3964
  }
@@ -4013,7 +4014,7 @@ declare namespace SelectPrimitive {
4013
4014
  SelectViewport,
4014
4015
  SelectGroup,
4015
4016
  SelectLabel,
4016
- SelectItem,
4017
+ SelectItem_2 as SelectItem,
4017
4018
  SelectItemText,
4018
4019
  SelectItemIndicator,
4019
4020
  SelectScrollUpButton,
@@ -4310,7 +4311,7 @@ export declare const useChatForm: () => ChatFormContextValue;
4310
4311
 
4311
4312
  export declare function useChatFormState(): {
4312
4313
  form: AIChatFormSettings | null;
4313
- openForm: (formSettings: AIChatFormSettings) => void;
4314
+ openForm: (formSettings: AIChatFormSettings, getHelpOption?: GetHelpOption) => void;
4314
4315
  closeForm: () => void;
4315
4316
  handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
4316
4317
  isSuccess: boolean;
@@ -4319,7 +4320,50 @@ export declare function useChatFormState(): {
4319
4320
  type: string | number;
4320
4321
  message: Message_2;
4321
4322
  }> | undefined;
4322
- fields: FormField[] | undefined;
4323
+ fields: ({
4324
+ inputType: "checkbox";
4325
+ defaultValue?: boolean;
4326
+ name: string;
4327
+ label: string;
4328
+ isRequired?: boolean;
4329
+ isHidden?: boolean;
4330
+ description?: string;
4331
+ } | {
4332
+ inputType: "file";
4333
+ name: string;
4334
+ label: string;
4335
+ isRequired?: boolean;
4336
+ isHidden?: boolean;
4337
+ description?: string;
4338
+ } | {
4339
+ inputType: "select";
4340
+ items: SelectItem[];
4341
+ defaultValue?: string;
4342
+ placeholder?: string;
4343
+ name: string;
4344
+ label: string;
4345
+ isRequired?: boolean;
4346
+ isHidden?: boolean;
4347
+ description?: string;
4348
+ } | {
4349
+ inputType: "email" | "text" | "textarea";
4350
+ defaultValue?: string;
4351
+ placeholder?: string;
4352
+ name: string;
4353
+ label: string;
4354
+ isRequired?: boolean;
4355
+ isHidden?: boolean;
4356
+ description?: string;
4357
+ } | {
4358
+ _type: "include_chat_session";
4359
+ inputType?: "checkbox";
4360
+ defaultValue?: boolean;
4361
+ name: string;
4362
+ label: string;
4363
+ isRequired?: boolean;
4364
+ isHidden?: boolean;
4365
+ description?: string;
4366
+ })[] | undefined;
4323
4367
  errors: FieldErrors<Record<string, any>>;
4324
4368
  control: Control<Record<string, any>, any>;
4325
4369
  defaultValues: Record<string, any>;
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.94",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("react/jsx-runtime"),t=require("react"),f=require("../atoms/api/analytics/events.cjs"),b=require("./config-provider.cjs"),x=require("./user-provider.cjs"),E=t.createContext(void 0),q=({children:e})=>{const{baseSettings:s,componentType:r}=b.useInkeepConfig(),{apiKey:i,analyticsApiBaseUrl:c,tags:a,privacyPreferences:m,env:g,analyticsProperties:v}=s,{userProperties:u}=x.useUser(),l=t.useMemo(()=>({widgetLibraryVersion:"0.5.96",componentType:r,tags:a}),[r,a]),d=!m.optOutAllAnalytics&&g!=="development",P={logEvent:t.useCallback(async n=>{const o={...l,...n.properties,...v},p={eventName:n.eventName,properties:o,userProperties:u},y=["modal_opened","modal_closed"].includes(n.eventName);if(d&&!y){if("conversation"in o&&!o.conversation?.id)return;f.logEvent(p,i,c)}s.onEvent?.(p)},[d,s,i,c,u,l,v])};return B.jsx(E.Provider,{value:P,children:e})},C=()=>{const e=t.useContext(E);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=q;exports.useBaseEvents=C;
@@ -7,7 +7,7 @@ import { useUser as A } from "./user-provider.js";
7
7
  const u = B(void 0), $ = ({ children: e }) => {
8
8
  const { baseSettings: t, componentType: s } = w(), { apiKey: r, analyticsApiBaseUrl: i, tags: a, privacyPreferences: d, env: E, analyticsProperties: c } = t, { userProperties: v } = A(), p = P(
9
9
  () => ({
10
- widgetLibraryVersion: "0.5.94",
10
+ widgetLibraryVersion: "0.5.96",
11
11
  componentType: s,
12
12
  tags: a
13
13
  }),
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),e=require("react"),R=require("../atoms/api/analytics/conversation.cjs"),U=require("./config-provider.cjs"),A=require("./conversation-provider.cjs"),O=require("./user-provider.cjs"),m=require("./base-events-provider.cjs"),B=require("../utils/generate-uid.cjs"),x=e.createContext(void 0),K=({children:o})=>{const{baseSettings:w,aiChatSettings:I}=U.useInkeepConfig(),{apiKey:p,analyticsApiBaseUrl:E,tags:f,privacyPreferences:{optOutAllAnalytics:a},env:c,analyticsProperties:v}=w,{conversationVisibility:g}=I,{userProperties:P}=O.useUser(),{logEvent:y}=m.useBaseEvents(),{conversation:u,setConversation:S,chatId:d,isSharedChat:l,setExternalChatId:b}=A.useInkeepConversation(),i=e.useRef(u),C=e.useRef(l?d:void 0);e.useEffect(()=>{i.current=u},[u]),e.useEffect(()=>{C.current=l?d:void 0},[d,l]);const h=e.useCallback(async r=>{const t=i.current;C.current&&(t.id="",b(void 0),C.current=void 0);const n=!a&&c!=="development";let s=Object.assign({},t,{messages:r});if(n){const q=await R.logConversation(t.id,{messages:r,tags:f,userProperties:P,properties:v,visibility:g},p,E);q&&(s=q)}else s.id="conv_"+B.generateUid(16);return s},[E,p,f,P,a,c,v,b,g]),j={logEvent:e.useCallback(async(r,t)=>{let n=i.current;t&&(n=await h(t),S(n),i.current=n);const s={...r,properties:{conversation:n,...r.properties}};y(s)},[y,h,a,c,v]),logConversation:h};return k.jsx(x.Provider,{value:j,children:o})},L=()=>{const o=e.useContext(x);if(!o)throw new Error("useChatEvents must be used within a ChatEventsProvider");return o};exports.ChatEventsProvider=K;exports.useChatEvents=L;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("react/jsx-runtime"),t=require("react"),A=require("../atoms/api/analytics/conversation.cjs"),L=require("./config-provider.cjs"),O=require("./conversation-provider.cjs"),m=require("./user-provider.cjs"),B=require("./base-events-provider.cjs"),M=require("../utils/generate-uid.cjs"),x=t.createContext(void 0),K=({children:a})=>{const{baseSettings:w,aiChatSettings:I}=L.useInkeepConfig(),{apiKey:E,analyticsApiBaseUrl:g,tags:f,privacyPreferences:{optOutAllAnalytics:c},env:v,analyticsProperties:u}=w,{conversationVisibility:P}=I,{userProperties:y}=m.useUser(),{logEvent:b}=B.useBaseEvents(),{conversation:d,setConversation:S,chatId:l,isSharedChat:C,setExternalChatId:q}=O.useInkeepConversation(),o=t.useRef(d),h=t.useRef(C?l:void 0);t.useEffect(()=>{o.current=d},[d]),t.useEffect(()=>{h.current=C?l:void 0},[l,C]);const p=t.useCallback(async r=>{const e=o.current;h.current&&(e.id="",q(void 0),h.current=void 0);const n=!c&&v!=="development";let s=Object.assign({},e,{messages:r});if(n){const i=await A.logConversation(e.id,{messages:r,tags:f,userProperties:y,properties:u,visibility:P},E,g);i&&(s=i)}else s.id="conv_"+M.generateUid(16);return s},[g,E,f,y,c,v,u,q,P]),j={logEvent:t.useCallback(async(r,e)=>{let n=o.current;if(e){const i=o.current.messages||[];(e.length!==i.length||e.some((k,R)=>k.id!==i[R]?.id))&&(n=await p(e),S(n),o.current=n)}const s={...r,properties:{conversation:n,...r.properties}};b(s)},[b,p,c,v,u]),logConversation:p};return U.jsx(x.Provider,{value:j,children:a})},T=()=>{const a=t.useContext(x);if(!a)throw new Error("useChatEvents must be used within a ChatEventsProvider");return a};exports.ChatEventsProvider=K;exports.useChatEvents=T;
@@ -1,87 +1,90 @@
1
1
  "use client";
2
- import { jsx as j } from "react/jsx-runtime";
3
- import { useRef as b, useEffect as P, useCallback as w, createContext as B, useContext as O } from "react";
4
- import { logConversation as K } from "../atoms/api/analytics/conversation.js";
5
- import { useInkeepConfig as L } from "./config-provider.js";
6
- import { useInkeepConversation as R } from "./conversation-provider.js";
7
- import { useUser as V } from "./user-provider.js";
8
- import { useBaseEvents as _ } from "./base-events-provider.js";
9
- import { generateUid as $ } from "../utils/generate-uid.js";
10
- const I = B(void 0), Q = ({ children: r }) => {
11
- const { baseSettings: k, aiChatSettings: A } = L(), {
12
- apiKey: d,
2
+ import { jsx as B } from "react/jsx-runtime";
3
+ import { useRef as b, useEffect as P, useCallback as w, createContext as O, useContext as K } from "react";
4
+ import { logConversation as M } from "../atoms/api/analytics/conversation.js";
5
+ import { useInkeepConfig as R } from "./config-provider.js";
6
+ import { useInkeepConversation as V } from "./conversation-provider.js";
7
+ import { useUser as _ } from "./user-provider.js";
8
+ import { useBaseEvents as $ } from "./base-events-provider.js";
9
+ import { generateUid as q } from "../utils/generate-uid.js";
10
+ const I = O(void 0), X = ({ children: i }) => {
11
+ const { baseSettings: k, aiChatSettings: A } = R(), {
12
+ apiKey: h,
13
13
  analyticsApiBaseUrl: f,
14
- tags: h,
15
- privacyPreferences: { optOutAllAnalytics: i },
16
- env: a,
17
- analyticsProperties: c
18
- } = k, { conversationVisibility: m } = A, { userProperties: E } = V(), { logEvent: g } = _(), { conversation: v, setConversation: S, chatId: u, isSharedChat: l, setExternalChatId: y } = R(), s = b(v), p = b(l ? u : void 0);
14
+ tags: m,
15
+ privacyPreferences: { optOutAllAnalytics: a },
16
+ env: c,
17
+ analyticsProperties: v
18
+ } = k, { conversationVisibility: g } = A, { userProperties: E } = _(), { logEvent: y } = $(), { conversation: u, setConversation: L, chatId: l, isSharedChat: d, setExternalChatId: x } = V(), n = b(u), p = b(d ? l : void 0);
19
19
  P(() => {
20
- s.current = v;
21
- }, [v]), P(() => {
22
- p.current = l ? u : void 0;
23
- }, [u, l]);
20
+ n.current = u;
21
+ }, [u]), P(() => {
22
+ p.current = d ? l : void 0;
23
+ }, [l, d]);
24
24
  const C = w(
25
- async (n) => {
26
- const t = s.current;
27
- p.current && (t.id = "", y(void 0), p.current = void 0);
28
- const e = !i && a !== "development";
29
- let o = Object.assign({}, t, { messages: n });
25
+ async (o) => {
26
+ const t = n.current;
27
+ p.current && (t.id = "", x(void 0), p.current = void 0);
28
+ const e = !a && c !== "development";
29
+ let r = Object.assign({}, t, { messages: o });
30
30
  if (e) {
31
- const x = await K(
31
+ const s = await M(
32
32
  t.id,
33
33
  {
34
- messages: n,
35
- tags: h,
34
+ messages: o,
35
+ tags: m,
36
36
  userProperties: E,
37
- properties: c,
38
- visibility: m
37
+ properties: v,
38
+ visibility: g
39
39
  },
40
- d,
40
+ h,
41
41
  f
42
42
  );
43
- x && (o = x);
43
+ s && (r = s);
44
44
  } else
45
- o.id = "conv_" + $(16);
46
- return o;
45
+ r.id = "conv_" + q(16);
46
+ return r;
47
47
  },
48
48
  [
49
49
  f,
50
- d,
51
50
  h,
51
+ m,
52
52
  E,
53
- i,
54
53
  a,
55
54
  c,
56
- y,
57
- m
55
+ v,
56
+ x,
57
+ g
58
58
  ]
59
- ), U = {
59
+ ), S = {
60
60
  logEvent: w(
61
- async (n, t) => {
62
- let e = s.current;
63
- t && (e = await C(t), S(e), s.current = e);
64
- const o = {
65
- ...n,
61
+ async (o, t) => {
62
+ let e = n.current;
63
+ if (t) {
64
+ const s = n.current.messages || [];
65
+ (t.length !== s.length || t.some((U, j) => U.id !== s[j]?.id)) && (e = await C(t), L(e), n.current = e);
66
+ }
67
+ const r = {
68
+ ...o,
66
69
  properties: {
67
70
  conversation: e,
68
- ...n.properties
71
+ ...o.properties
69
72
  }
70
73
  };
71
- g(o);
74
+ y(r);
72
75
  },
73
- [g, C, i, a, c]
76
+ [y, C, a, c, v]
74
77
  ),
75
78
  logConversation: C
76
79
  };
77
- return /* @__PURE__ */ j(I.Provider, { value: U, children: r });
78
- }, T = () => {
79
- const r = O(I);
80
- if (!r)
80
+ return /* @__PURE__ */ B(I.Provider, { value: S, children: i });
81
+ }, Y = () => {
82
+ const i = K(I);
83
+ if (!i)
81
84
  throw new Error("useChatEvents must be used within a ChatEventsProvider");
82
- return r;
85
+ return i;
83
86
  };
84
87
  export {
85
- Q as ChatEventsProvider,
86
- T as useChatEvents
88
+ X as ChatEventsProvider,
89
+ Y as useChatEvents
87
90
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),o=require("react"),w=require("react-hook-form"),x=require("./conversation-provider.cjs"),P=require("../components/modal/modal-provider.cjs"),M=require("../utils/form.cjs"),V="root.serverError",h=o.createContext(void 0);function S(){const[e,n]=o.useState(null),[v,u]=o.useState(!1),{conversation:i}=x.useInkeepConversation(),F=P.useModal(),C=t=>{n(t)},a=()=>{n(null),u(!1),e?.buttons.close?.action==="close_modal"&&F?.setOpen(!1)},c=o.useMemo(()=>e?.fields.map(t=>{const r=t;return"_type"in t&&t._type==="include_chat_session"&&(r.isRequired=!1,r.inputType="checkbox",i.id||(r.isHidden=!0)),r}),[e?.fields,i.id]),m=c?.find(t=>"_type"in t&&t._type==="include_chat_session"),s=o.useMemo(()=>M.getFormDefaultValues(c),[c]),{control:b,handleSubmit:p,formState:{errors:l,isSubmitting:E},setError:_,reset:d}=w.useForm({defaultValues:s});o.useEffect(()=>{s&&d(s)},[d,s]);const y=p(async t=>{const R=i.id&&m&&t[m.name]?i:null;try{await e?.buttons.submit.onSubmit({values:t,conversation:R}),u(!0),e?.successView||a()}catch(f){_(V,{message:f instanceof Error?f.message:"Something went wrong."})}}),g=l?.root?.serverError;return{form:e,openForm:C,closeForm:a,handleSubmit:y,isSuccess:v,isSubmitting:E,formError:g,fields:c,errors:l,control:b,defaultValues:s}}const j=({children:e})=>{const n=S();return q.jsx(h.Provider,{value:n,children:e})},k=()=>{const e=o.useContext(h);if(!e)throw new Error("useChatForm must be used within a ChatFormProvider");return e};exports.ChatFormProvider=j;exports.useChatForm=k;exports.useChatFormState=S;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),s=require("react"),H=require("react-hook-form"),O=require("./conversation-provider.cjs"),M=require("../components/modal/modal-provider.cjs"),T=require("../utils/form.cjs"),V=require("./chat-events-provider.cjs"),j="root.serverError",S=s.createContext(void 0);function g(){const[t,i]=s.useState(null),[a,u]=s.useState(null),[C,l]=s.useState(!1),{conversation:r}=O.useInkeepConversation(),F=M.useModal(),{logEvent:b}=V.useChatEvents(),E=(e,o)=>{i(e),u(o||null)},m=()=>{i(null),u(null),l(!1),t?.buttons.close?.action==="close_modal"&&F?.setOpen(!1)},c=s.useMemo(()=>t?.fields.map(e=>{const o={...e};return"_type"in e&&e._type==="include_chat_session"&&(o.inputType="checkbox",r.id?(o.isHidden=e.isHidden,o.isRequired=e.isRequired):(o.isHidden=!0,o.isRequired=!1)),o}),[t?.fields,r.id]),d=c?.find(e=>"_type"in e&&e._type==="include_chat_session"),n=s.useMemo(()=>T.getFormDefaultValues(c),[c]),{control:_,handleSubmit:q,formState:{errors:f,isSubmitting:y},setError:R,reset:p}=H.useForm({defaultValues:n});s.useEffect(()=>{n&&p(n)},[p,n]);const P=q(async e=>{const v=r.id&&d&&e[d.name]?r:null;try{await t?.buttons.submit.onSubmit({values:e,conversation:v}),a&&b({eventName:"user_escalation_indicated",properties:{escalationType:"support_form",getHelpOptionName:a.name,conversation:v||r}}),l(!0),t?.successView||m()}catch(h){R(j,{message:h instanceof Error?h.message:"Something went wrong."})}}),w=f?.root?.serverError;return{form:t,openForm:E,closeForm:m,handleSubmit:P,isSuccess:C,isSubmitting:y,formError:w,fields:c,errors:f,control:_,defaultValues:n}}const k=({children:t})=>{const i=g();return x.jsx(S.Provider,{value:i,children:t})},N=()=>{const t=s.useContext(S);if(!t)throw new Error("useChatForm must be used within a ChatFormProvider");return t};exports.ChatFormProvider=k;exports.useChatForm=N;exports.useChatFormState=g;
@@ -1,66 +1,74 @@
1
1
  "use client";
2
- import { jsx as g } from "react/jsx-runtime";
3
- import { useState as d, useMemo as p, useEffect as R, createContext as V, useContext as M } from "react";
4
- import { useForm as P } from "react-hook-form";
5
- import { useInkeepConversation as k } from "./conversation-provider.js";
6
- import { useModal as I } from "../components/modal/modal-provider.js";
7
- import { getFormDefaultValues as O } from "../utils/form.js";
8
- const j = "root.serverError", h = V(void 0);
9
- function q() {
10
- const [t, r] = d(null), [S, c] = d(!1), { conversation: n } = k(), b = I(), v = (o) => {
11
- r(o);
12
- }, a = () => {
13
- r(null), c(!1), t?.buttons.close?.action === "close_modal" && b?.setOpen(!1);
14
- }, i = p(() => t?.fields.map((o) => {
15
- const s = o;
16
- return "_type" in o && o._type === "include_chat_session" && (s.isRequired = !1, s.inputType = "checkbox", n.id || (s.isHidden = !0)), s;
17
- }), [t?.fields, n.id]), u = i?.find((o) => "_type" in o && o._type === "include_chat_session"), e = p(() => O(i), [i]), {
18
- control: C,
19
- handleSubmit: F,
20
- formState: { errors: m, isSubmitting: E },
21
- setError: _,
22
- reset: l
23
- } = P({
24
- defaultValues: e
2
+ import { jsx as O } from "react/jsx-runtime";
3
+ import { useState as c, useMemo as S, useEffect as V, createContext as q, useContext as M } from "react";
4
+ import { useForm as N } from "react-hook-form";
5
+ import { useInkeepConversation as P } from "./conversation-provider.js";
6
+ import { useModal as T } from "../components/modal/modal-provider.js";
7
+ import { getFormDefaultValues as k } from "../utils/form.js";
8
+ import { useChatEvents as G } from "./chat-events-provider.js";
9
+ const I = "root.serverError", g = q(void 0);
10
+ function j() {
11
+ const [t, r] = c(null), [a, u] = c(null), [C, m] = c(!1), { conversation: s } = P(), E = T(), { logEvent: b } = G(), F = (e, o) => {
12
+ r(e), u(o || null);
13
+ }, l = () => {
14
+ r(null), u(null), m(!1), t?.buttons.close?.action === "close_modal" && E?.setOpen(!1);
15
+ }, i = S(() => t?.fields.map((e) => {
16
+ const o = { ...e };
17
+ return "_type" in e && e._type === "include_chat_session" && (o.inputType = "checkbox", s.id ? (o.isHidden = e.isHidden, o.isRequired = e.isRequired) : (o.isHidden = !0, o.isRequired = !1)), o;
18
+ }), [t?.fields, s.id]), p = i?.find((e) => "_type" in e && e._type === "include_chat_session"), n = S(() => k(i), [i]), {
19
+ control: _,
20
+ handleSubmit: y,
21
+ formState: { errors: d, isSubmitting: R },
22
+ setError: w,
23
+ reset: f
24
+ } = N({
25
+ defaultValues: n
25
26
  });
26
- R(() => {
27
- e && l(e);
28
- }, [l, e]);
29
- const w = F(async (o) => {
30
- const y = n.id && u && o[u.name] ? n : null;
27
+ V(() => {
28
+ n && f(n);
29
+ }, [f, n]);
30
+ const x = y(async (e) => {
31
+ const h = s.id && p && e[p.name] ? s : null;
31
32
  try {
32
- await t?.buttons.submit.onSubmit({ values: o, conversation: y }), c(!0), t?.successView || a();
33
- } catch (f) {
34
- _(j, {
35
- message: f instanceof Error ? f.message : "Something went wrong."
33
+ await t?.buttons.submit.onSubmit({ values: e, conversation: h }), a && b({
34
+ eventName: "user_escalation_indicated",
35
+ properties: {
36
+ escalationType: "support_form",
37
+ getHelpOptionName: a.name,
38
+ conversation: h || s
39
+ }
40
+ }), m(!0), t?.successView || l();
41
+ } catch (v) {
42
+ w(I, {
43
+ message: v instanceof Error ? v.message : "Something went wrong."
36
44
  });
37
45
  }
38
- }), x = m?.root?.serverError;
46
+ }), H = d?.root?.serverError;
39
47
  return {
40
48
  form: t,
41
- openForm: v,
42
- closeForm: a,
43
- handleSubmit: w,
44
- isSuccess: S,
45
- isSubmitting: E,
46
- formError: x,
49
+ openForm: F,
50
+ closeForm: l,
51
+ handleSubmit: x,
52
+ isSuccess: C,
53
+ isSubmitting: R,
54
+ formError: H,
47
55
  fields: i,
48
- errors: m,
49
- control: C,
50
- defaultValues: e
56
+ errors: d,
57
+ control: _,
58
+ defaultValues: n
51
59
  };
52
60
  }
53
- const G = ({ children: t }) => {
54
- const r = q();
55
- return /* @__PURE__ */ g(h.Provider, { value: r, children: t });
56
- }, J = () => {
57
- const t = M(h);
61
+ const U = ({ children: t }) => {
62
+ const r = j();
63
+ return /* @__PURE__ */ O(g.Provider, { value: r, children: t });
64
+ }, W = () => {
65
+ const t = M(g);
58
66
  if (!t)
59
67
  throw new Error("useChatForm must be used within a ChatFormProvider");
60
68
  return t;
61
69
  };
62
70
  export {
63
- G as ChatFormProvider,
64
- J as useChatForm,
65
- q as useChatFormState
71
+ U as ChatFormProvider,
72
+ W as useChatForm,
73
+ j as useChatFormState
66
74
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("react/jsx-runtime"),n=require("react"),M=require("../atoms/api/analytics/feedback.cjs"),S=require("../components/embedded-chat/chat-provider.cjs"),l=require("../utils/misc.cjs"),E=require("./config-provider.cjs"),j=require("./conversation-provider.cjs"),I=require("./chat-events-provider.cjs"),R=require("./user-provider.cjs"),f=n.createContext(void 0);function U(){const{baseSettings:e}=E.useInkeepConfig(),{apiKey:s,analyticsApiBaseUrl:o,analyticsProperties:b}=e,[g,p]=n.useState(null),[F,P]=n.useState({}),{conversation:k}=j.useInkeepConversation(),{messages:r,selectedWorkflow:C}=S.useChat(),{userProperties:m}=R.useUser(),{logEvent:h}=I.useChatEvents(),c=n.useCallback(async(t,i,a=[])=>{const u=await M.submitFeedback({type:i,messageId:t,reasons:a,apiKey:s,apiUrl:o,userProperties:m,properties:b});u&&P(d=>({...d,[t]:{type:u.type,reasons:u.reasons}}));const v=r.findIndex(d=>d.id===t),w=r[v],x={conversationId:k.id,question:l.getMessageContent(r[v-1]),answer:l.getMessageContent(w),messageId:t,reasons:a,workflowId:C?.id};h({eventName:i==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:x})},[r,k]),q=n.useCallback(async t=>{c(t,"positive")},[c]),y=n.useCallback(async(t,i)=>{const a=A(i);c(t,"negative",a)},[c]);return{feedback:F,currentFeedback:g,setCurrentFeedback:p,submitPositiveFeedback:q,submitNegativeFeedback:y}}const N=({children:e})=>{const s=U();return _.jsx(f.Provider,{value:s,children:e})},$=()=>{const e=n.useContext(f);if(!e)throw new Error("useFeedback must be used within a FeedbackProvider");return e};function A(e){const s=[];for(const o in e)e[o]==="on"&&s.push({label:o,details:e[`${o}:description`]||""});return s.length>0?s:[]}exports.FeedbackProvider=N;exports.useMessageFeedback=$;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),n=require("react"),M=require("../atoms/api/analytics/feedback.cjs"),S=require("../components/embedded-chat/chat-provider.cjs"),p=require("../utils/misc.cjs"),E=require("./config-provider.cjs"),j=require("./conversation-provider.cjs"),I=require("./chat-events-provider.cjs"),N=require("./user-provider.cjs"),f=n.createContext(void 0);function R(){const{baseSettings:e}=E.useInkeepConfig(),{apiKey:s,analyticsApiBaseUrl:o,analyticsProperties:v}=e,[g,F]=n.useState(null),[P,C]=n.useState({}),{conversation:u}=j.useInkeepConversation(),{messages:c,selectedWorkflow:m}=S.useChat(),{userProperties:h}=N.useUser(),{logEvent:k}=I.useChatEvents(),i=n.useCallback(async(t,r,a=[])=>{const d=await M.submitFeedback({type:r,messageId:t,reasons:a,apiKey:s,apiUrl:o,userProperties:h,properties:v});d&&C(b=>({...b,[t]:{type:d.type,reasons:d.reasons}}));const l=c.findIndex(b=>b.id===t),w=c[l],_={conversationId:u.id,question:p.getMessageContent(c[l-1]),answer:p.getMessageContent(w),messageId:t,reasons:a,workflowId:m?.id};k({eventName:r==="positive"?"assistant_positive_feedback_submitted":"assistant_negative_feedback_submitted",properties:_}),r==="negative"&&k({eventName:"user_escalation_indicated",properties:{escalationType:"downvote",conversation:u}})},[c,u]),q=n.useCallback(async t=>{i(t,"positive")},[i]),y=n.useCallback(async(t,r)=>{const a=$(r);i(t,"negative",a)},[i]);return{feedback:P,currentFeedback:g,setCurrentFeedback:F,submitPositiveFeedback:q,submitNegativeFeedback:y}}const U=({children:e})=>{const s=R();return x.jsx(f.Provider,{value:s,children:e})},T=()=>{const e=n.useContext(f);if(!e)throw new Error("useFeedback must be used within a FeedbackProvider");return e};function $(e){const s=[];for(const o in e)e[o]==="on"&&s.push({label:o,details:e[`${o}:description`]||""});return s.length>0?s:[]}exports.FeedbackProvider=U;exports.useMessageFeedback=T;