@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/components/embedded-chat/use-chat-action.cjs +1 -1
- package/dist/components/embedded-chat/use-chat-action.js +22 -11
- package/dist/components/embedded-chat/use-inkeep-chat.cjs +3 -3
- package/dist/components/embedded-chat/use-inkeep-chat.js +45 -42
- package/dist/components/embedded-chat.cjs +6 -6
- package/dist/components/embedded-chat.js +95 -88
- package/dist/index.d.cts +50 -6
- package/dist/index.d.ts +50 -6
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/dist/providers/chat-events-provider.cjs +1 -1
- package/dist/providers/chat-events-provider.js +57 -54
- package/dist/providers/chat-form-provider.cjs +1 -1
- package/dist/providers/chat-form-provider.js +58 -50
- package/dist/providers/feedback-provider.cjs +1 -1
- package/dist/providers/feedback-provider.js +47 -41
- package/package.json +4 -4
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
|
|
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:
|
|
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
|
|
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:
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
3
|
-
import { useRef as b, useEffect as P, useCallback as w, createContext as
|
|
4
|
-
import { logConversation as
|
|
5
|
-
import { useInkeepConfig as
|
|
6
|
-
import { useInkeepConversation as
|
|
7
|
-
import { useUser as
|
|
8
|
-
import { useBaseEvents as
|
|
9
|
-
import { generateUid as
|
|
10
|
-
const I =
|
|
11
|
-
const { baseSettings: k, aiChatSettings: A } =
|
|
12
|
-
apiKey:
|
|
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:
|
|
15
|
-
privacyPreferences: { optOutAllAnalytics:
|
|
16
|
-
env:
|
|
17
|
-
analyticsProperties:
|
|
18
|
-
} = k, { conversationVisibility:
|
|
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
|
-
|
|
21
|
-
}, [
|
|
22
|
-
p.current =
|
|
23
|
-
}, [
|
|
20
|
+
n.current = u;
|
|
21
|
+
}, [u]), P(() => {
|
|
22
|
+
p.current = d ? l : void 0;
|
|
23
|
+
}, [l, d]);
|
|
24
24
|
const C = w(
|
|
25
|
-
async (
|
|
26
|
-
const t =
|
|
27
|
-
p.current && (t.id = "",
|
|
28
|
-
const e = !
|
|
29
|
-
let
|
|
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
|
|
31
|
+
const s = await M(
|
|
32
32
|
t.id,
|
|
33
33
|
{
|
|
34
|
-
messages:
|
|
35
|
-
tags:
|
|
34
|
+
messages: o,
|
|
35
|
+
tags: m,
|
|
36
36
|
userProperties: E,
|
|
37
|
-
properties:
|
|
38
|
-
visibility:
|
|
37
|
+
properties: v,
|
|
38
|
+
visibility: g
|
|
39
39
|
},
|
|
40
|
-
|
|
40
|
+
h,
|
|
41
41
|
f
|
|
42
42
|
);
|
|
43
|
-
|
|
43
|
+
s && (r = s);
|
|
44
44
|
} else
|
|
45
|
-
|
|
46
|
-
return
|
|
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
|
-
|
|
57
|
-
|
|
55
|
+
v,
|
|
56
|
+
x,
|
|
57
|
+
g
|
|
58
58
|
]
|
|
59
|
-
),
|
|
59
|
+
), S = {
|
|
60
60
|
logEvent: w(
|
|
61
|
-
async (
|
|
62
|
-
let e =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
...
|
|
71
|
+
...o.properties
|
|
69
72
|
}
|
|
70
73
|
};
|
|
71
|
-
|
|
74
|
+
y(r);
|
|
72
75
|
},
|
|
73
|
-
[
|
|
76
|
+
[y, C, a, c, v]
|
|
74
77
|
),
|
|
75
78
|
logConversation: C
|
|
76
79
|
};
|
|
77
|
-
return /* @__PURE__ */
|
|
78
|
-
},
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
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
|
|
85
|
+
return i;
|
|
83
86
|
};
|
|
84
87
|
export {
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
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
|
|
3
|
-
import { useState as
|
|
4
|
-
import { useForm as
|
|
5
|
-
import { useInkeepConversation as
|
|
6
|
-
import { useModal as
|
|
7
|
-
import { getFormDefaultValues as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
}, [
|
|
29
|
-
const
|
|
30
|
-
const
|
|
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:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
}),
|
|
46
|
+
}), H = d?.root?.serverError;
|
|
39
47
|
return {
|
|
40
48
|
form: t,
|
|
41
|
-
openForm:
|
|
42
|
-
closeForm:
|
|
43
|
-
handleSubmit:
|
|
44
|
-
isSuccess:
|
|
45
|
-
isSubmitting:
|
|
46
|
-
formError:
|
|
49
|
+
openForm: F,
|
|
50
|
+
closeForm: l,
|
|
51
|
+
handleSubmit: x,
|
|
52
|
+
isSuccess: C,
|
|
53
|
+
isSubmitting: R,
|
|
54
|
+
formError: H,
|
|
47
55
|
fields: i,
|
|
48
|
-
errors:
|
|
49
|
-
control:
|
|
50
|
-
defaultValues:
|
|
56
|
+
errors: d,
|
|
57
|
+
control: _,
|
|
58
|
+
defaultValues: n
|
|
51
59
|
};
|
|
52
60
|
}
|
|
53
|
-
const
|
|
54
|
-
const r =
|
|
55
|
-
return /* @__PURE__ */ g
|
|
56
|
-
},
|
|
57
|
-
const t = M(
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
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;
|