@inkeep/cxkit-primitives 0.5.99 → 0.5.101
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-search/use-search-filter.cjs +1 -1
- package/dist/components/embedded-search/use-search-filter.js +1 -1
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.cjs +1 -1
- package/dist/components/intelligent-form/use-inkeep-intelligent-form.js +63 -57
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),F=require("../../atoms/cmdk/index.cjs"),L=require("../../providers/search-events-provider.cjs"),P=require("../../providers/config-provider.cjs"),U=require("../../utils/graphql-client.cjs"),B=require("./search-query.graphql.cjs"),H=require("./search-provider.cjs"),O=
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),F=require("../../atoms/cmdk/index.cjs"),L=require("../../providers/search-events-provider.cjs"),P=require("../../providers/config-provider.cjs"),U=require("../../utils/graphql-client.cjs"),B=require("./search-query.graphql.cjs"),H=require("./search-provider.cjs"),O=250,j=()=>{const{setResultsList:o,setLoading:u,showSearchResults:a,setShowSearchResults:i}=H.useSearch(),{baseSettings:_,searchSettings:k}=P.useInkeepConfig(),{apiKey:y,aiApiBaseUrl:A,userAuthToken:l,filters:R}=_,{maxResults:m,debounceTimeMs:S,onQueryChange:M,filters:b}=k,{logEvent:g}=L.useSearchEvents(),s=r.useRef({}),h=r.useRef(null),f=r.useRef(null),T=`${A}/graphql`,q=r.useMemo(()=>({Authorization:`Bearer ${y}`,"Content-Type":"application/json",...l?{"User-Token":l}:{}}),[y,l]),w=r.useCallback(async e=>{const t=new AbortController;h.current=t;try{const E=(await U.graphqlRequest(T,B.default,{searchInput:e},q,t.signal))?.search.searchHits;s.current[e.searchQuery]=E,o(E)}catch(C){if(C.name==="AbortError")return}finally{u(!1)}},[T,q]),Q=r.useCallback(e=>{const t=s.current[e.searchQuery];g({eventName:"search_query_response_received",properties:{searchQuery:e.searchQuery,totalResults:t?.length}})},[]),p=()=>{h.current&&(h.current.abort(),u(!1))},v=r.useCallback(e=>{if(f.current&&window.clearTimeout(f.current),!e.searchQuery){p(),o([]);return}f.current=window.setTimeout(()=>{p(),g({eventName:"search_query_submitted",properties:{searchQuery:e.searchQuery}}),s.current[e.searchQuery]?(o(s.current[e.searchQuery]),Q(e)):(u(!0),w(e).then(()=>{Q(e)}))},S)},[S,w]),c=F.useCommandState(e=>e.search),d=r.useMemo(()=>({searchQuery:c,filters:{...R,...b,limit:m}}),[c,m,R,b]),n=r.useRef(null);r.useEffect(()=>{const e=()=>{n.current!==null&&(window.clearTimeout(n.current),n.current=null)},t=!!c;return t&&!a?(e(),n.current=window.setTimeout(()=>{i(!0)},O)):!t&&a&&(e(),i(!1)),e},[c,a,i]),r.useEffect(()=>{M?.(d.searchQuery),v(d)},[v,d])};exports.useSearchFetch=j;
|
|
@@ -6,7 +6,7 @@ import { useInkeepConfig as x } from "../../providers/config-provider.js";
|
|
|
6
6
|
import { graphqlRequest as N } from "../../utils/graphql-client.js";
|
|
7
7
|
import O from "./search-query.graphql.js";
|
|
8
8
|
import { useSearch as $ } from "./search-provider.js";
|
|
9
|
-
const j =
|
|
9
|
+
const j = 250, V = () => {
|
|
10
10
|
const { setResultsList: c, setLoading: u, showSearchResults: a, setShowSearchResults: i } = $(), { baseSettings: L, searchSettings: U } = x(), { apiKey: R, aiApiBaseUrl: B, userAuthToken: l, filters: d } = L, { maxResults: p, debounceTimeMs: S, onQueryChange: F, filters: w } = U, { logEvent: T } = M(), t = n({}), h = n(null), m = n(null), Q = `${B}/graphql`, b = A(
|
|
11
11
|
() => ({
|
|
12
12
|
Authorization: `Bearer ${R}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("openai"),t=require("react"),J=require("react-hook-form"),W=require("../../utils/form.cjs"),X=require("./actions/qa-model-response.cjs"),z=require("./actions/context-model-response.cjs"),Y=require("../../providers/config-provider.cjs"),Z=require("../../providers/conversation-provider.cjs"),ee=require("../../providers/chat-events-provider.cjs"),se=require("./actions/qa-model-messages.cjs"),re=require("../embedded-chat/use-captcha.cjs"),te="root.serverError",
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("openai"),t=require("react"),J=require("react-hook-form"),W=require("../../utils/form.cjs"),X=require("./actions/qa-model-response.cjs"),z=require("./actions/context-model-response.cjs"),Y=require("../../providers/config-provider.cjs"),Z=require("../../providers/conversation-provider.cjs"),ee=require("../../providers/chat-events-provider.cjs"),se=require("./actions/qa-model-messages.cjs"),re=require("../embedded-chat/use-captcha.cjs"),te="root.serverError",R=async(u,s)=>{if(s)return;const o=await re.fetchAndSolveChallenge(`${u}/v1/challenge`);if(o)return{"X-INKEEP-CHALLENGE-SOLUTION":btoa(JSON.stringify(o))}},oe=u=>{const{formSettings:s}=u,{baseSettings:o}=Y.useInkeepConfig(),{conversation:m}=Z.useInkeepConversation(),{logEvent:a}=ee.useChatEvents(),{aiApiBaseUrl:c,shouldBypassCaptcha:S}=o,v=t.useMemo(()=>new $({baseURL:`${c}/v1`,apiKey:o.apiKey,dangerouslyAllowBrowser:!0}),[o.apiKey,c]),[q,w]=t.useState(!1),[M,V]=t.useState(!1),[A,f]=t.useState(!1),[F,h]=t.useState({}),d=t.useMemo(()=>{const{primary:n,secondary:i}=s;return W.getFormDefaultValues([...n.fields,...i.fields])},[s]),{control:b,handleSubmit:I,formState:{errors:C,isSubmitting:N,isSubmitSuccessful:P},reset:_,trigger:O,setValue:k,setError:H}=J.useForm({defaultValues:d});t.useEffect(()=>{d&&_(d)},[_,d]);const L=async n=>{try{await s.buttons.submit.onSubmit({values:n,conversation:m}),a({eventName:"intelligent_form_submitted",properties:{conversation:m,values:n}}),a({eventName:"user_escalation_indicated",properties:{escalationType:"intelligent_support_form",conversation:m}})}catch(i){H(te,{message:i instanceof Error?i.message:"Something went wrong."})}},x=async()=>{const n=s.primary.fields.map(e=>e.name);if(!await O(n))return;V(!0),w(!0);const B=b._formValues,E=s.primary.fields.reduce((e,l)=>(e[l.name]=B[l.name],e),{}),U=s.secondary.fields.filter(e=>e.shouldPrefillWithAI!==!1),g=se.getQAModelMessages(E);a({eventName:"intelligent_form_primary_section_submitted",properties:{}},g);try{const e=await R(c,S),l=await R(c,S),[r,p]=await Promise.all([X.generateQAModelResponse(g,v,e),z.generateContextModelResponse({primaryFieldValues:E,fieldsToGenerate:U},v,l)]);if(p.suggestedValues)for(const[G,Q]of Object.entries(p.suggestedValues))k(G,Q);const y=r.aiAnnotations?.answerConfidence,j=y&&["very_confident","somewhat_confident"].includes(y),D=r.recordsConsidered&&r.recordsConsidered.length>0;j&&D&&r.answer?(h({answer:r.answer,answerConfidence:y,recordsConsidered:r.recordsConsidered}),a({eventName:"intelligent_form_ai_response_provided",properties:{recordsConsidered:r.recordsConsidered}},[...g,{id:Date.now().toString(),role:"assistant",content:r.answer,links:[]}])):(f(!0),h({answer:null,recordsConsidered:r.recordsConsidered,suggestedValues:p.suggestedValues}))}catch(e){console.error(e),f(!0)}finally{w(!1)}},K=I(L),T=C?.root?.serverError;return{formSettings:s,control:b,errors:C,isSubmitSuccessful:P,isSubmitting:N,handleSubmit:K,loading:q,formError:T,submittedPrimaryForm:M,handleSubmitPrimaryForm:x,aiResponse:F,showSecondaryFields:A,setShowSecondaryFields:f}};exports.useInkeepIntelligentForm=oe;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import J from "openai";
|
|
3
|
-
import { useMemo as R, useState as
|
|
3
|
+
import { useMemo as R, useState as c, useEffect as W } from "react";
|
|
4
4
|
import { useForm as X } from "react-hook-form";
|
|
5
5
|
import { getFormDefaultValues as z } from "../../utils/form.js";
|
|
6
6
|
import { generateQAModelResponse as Y } from "./actions/qa-model-response.js";
|
|
@@ -8,50 +8,56 @@ import { generateContextModelResponse as Z } from "./actions/context-model-respo
|
|
|
8
8
|
import { useInkeepConfig as ee } from "../../providers/config-provider.js";
|
|
9
9
|
import { useInkeepConversation as se } from "../../providers/conversation-provider.js";
|
|
10
10
|
import { useChatEvents as re } from "../../providers/chat-events-provider.js";
|
|
11
|
-
import { getQAModelMessages as
|
|
12
|
-
import { fetchAndSolveChallenge as
|
|
13
|
-
const ne = "root.serverError", V = async (
|
|
11
|
+
import { getQAModelMessages as te } from "./actions/qa-model-messages.js";
|
|
12
|
+
import { fetchAndSolveChallenge as oe } from "../embedded-chat/use-captcha.js";
|
|
13
|
+
const ne = "root.serverError", V = async (m, s) => {
|
|
14
14
|
if (s) return;
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
15
|
+
const t = await oe(`${m}/v1/challenge`);
|
|
16
|
+
if (t)
|
|
17
17
|
return {
|
|
18
|
-
"X-INKEEP-CHALLENGE-SOLUTION": btoa(JSON.stringify(
|
|
18
|
+
"X-INKEEP-CHALLENGE-SOLUTION": btoa(JSON.stringify(t))
|
|
19
19
|
};
|
|
20
|
-
}, we = (
|
|
21
|
-
const { formSettings: s } =
|
|
20
|
+
}, we = (m) => {
|
|
21
|
+
const { formSettings: s } = m, { baseSettings: t } = ee(), { conversation: u } = se(), { logEvent: i } = re(), { aiApiBaseUrl: a, shouldBypassCaptcha: w } = t, S = R(
|
|
22
22
|
() => new J({
|
|
23
|
-
baseURL: `${
|
|
24
|
-
apiKey:
|
|
23
|
+
baseURL: `${a}/v1`,
|
|
24
|
+
apiKey: t.apiKey,
|
|
25
25
|
dangerouslyAllowBrowser: !0
|
|
26
26
|
}),
|
|
27
|
-
[
|
|
28
|
-
), [A, h] =
|
|
29
|
-
const { primary:
|
|
30
|
-
return z([...
|
|
27
|
+
[t.apiKey, a]
|
|
28
|
+
), [A, h] = c(!1), [F, N] = c(!1), [I, f] = c(!1), [M, _] = c({}), d = R(() => {
|
|
29
|
+
const { primary: o, secondary: n } = s;
|
|
30
|
+
return z([...o.fields, ...n.fields]);
|
|
31
31
|
}, [s]), {
|
|
32
|
-
control:
|
|
32
|
+
control: C,
|
|
33
33
|
handleSubmit: O,
|
|
34
|
-
formState: { errors:
|
|
35
|
-
reset:
|
|
34
|
+
formState: { errors: b, isSubmitting: P, isSubmitSuccessful: L },
|
|
35
|
+
reset: v,
|
|
36
36
|
trigger: k,
|
|
37
37
|
setValue: x,
|
|
38
38
|
setError: H
|
|
39
39
|
} = X({
|
|
40
|
-
defaultValues:
|
|
40
|
+
defaultValues: d
|
|
41
41
|
});
|
|
42
42
|
W(() => {
|
|
43
|
-
|
|
44
|
-
}, [
|
|
45
|
-
const K = async (
|
|
43
|
+
d && v(d);
|
|
44
|
+
}, [v, d]);
|
|
45
|
+
const K = async (o) => {
|
|
46
46
|
try {
|
|
47
47
|
await s.buttons.submit.onSubmit({
|
|
48
|
-
values:
|
|
49
|
-
conversation:
|
|
50
|
-
}),
|
|
48
|
+
values: o,
|
|
49
|
+
conversation: u
|
|
50
|
+
}), i({
|
|
51
51
|
eventName: "intelligent_form_submitted",
|
|
52
52
|
properties: {
|
|
53
|
-
conversation:
|
|
54
|
-
values:
|
|
53
|
+
conversation: u,
|
|
54
|
+
values: o
|
|
55
|
+
}
|
|
56
|
+
}), i({
|
|
57
|
+
eventName: "user_escalation_indicated",
|
|
58
|
+
properties: {
|
|
59
|
+
escalationType: "intelligent_support_form",
|
|
60
|
+
conversation: u
|
|
55
61
|
}
|
|
56
62
|
});
|
|
57
63
|
} catch (n) {
|
|
@@ -60,40 +66,40 @@ const ne = "root.serverError", V = async (c, s) => {
|
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
}, B = async () => {
|
|
63
|
-
const
|
|
64
|
-
if (!await k(
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
(e,
|
|
69
|
+
const o = s.primary.fields.map((e) => e.name);
|
|
70
|
+
if (!await k(o)) return;
|
|
71
|
+
N(!0), h(!0);
|
|
72
|
+
const q = C._formValues, E = s.primary.fields.reduce(
|
|
73
|
+
(e, l) => (e[l.name] = q[l.name], e),
|
|
68
74
|
{}
|
|
69
|
-
),
|
|
75
|
+
), D = s.secondary.fields.filter(
|
|
70
76
|
(e) => e.shouldPrefillWithAI !== !1
|
|
71
|
-
),
|
|
72
|
-
|
|
77
|
+
), p = te(E);
|
|
78
|
+
i(
|
|
73
79
|
{
|
|
74
80
|
eventName: "intelligent_form_primary_section_submitted",
|
|
75
81
|
properties: {}
|
|
76
82
|
},
|
|
77
|
-
|
|
83
|
+
p
|
|
78
84
|
);
|
|
79
85
|
try {
|
|
80
|
-
const e = await V(
|
|
81
|
-
Y(
|
|
86
|
+
const e = await V(a, w), l = await V(a, w), [r, g] = await Promise.all([
|
|
87
|
+
Y(p, S, e),
|
|
82
88
|
Z(
|
|
83
|
-
{ primaryFieldValues:
|
|
89
|
+
{ primaryFieldValues: E, fieldsToGenerate: D },
|
|
84
90
|
S,
|
|
85
|
-
|
|
91
|
+
l
|
|
86
92
|
)
|
|
87
93
|
]);
|
|
88
|
-
if (
|
|
89
|
-
for (const [$, j] of Object.entries(
|
|
94
|
+
if (g.suggestedValues)
|
|
95
|
+
for (const [$, j] of Object.entries(g.suggestedValues))
|
|
90
96
|
x($, j);
|
|
91
|
-
const
|
|
92
|
-
|
|
97
|
+
const y = r.aiAnnotations?.answerConfidence, G = y && ["very_confident", "somewhat_confident"].includes(y), Q = r.recordsConsidered && r.recordsConsidered.length > 0;
|
|
98
|
+
G && Q && r.answer ? (_({
|
|
93
99
|
answer: r.answer,
|
|
94
|
-
answerConfidence:
|
|
100
|
+
answerConfidence: y,
|
|
95
101
|
recordsConsidered: r.recordsConsidered
|
|
96
|
-
}),
|
|
102
|
+
}), i(
|
|
97
103
|
{
|
|
98
104
|
eventName: "intelligent_form_ai_response_provided",
|
|
99
105
|
properties: {
|
|
@@ -101,34 +107,34 @@ const ne = "root.serverError", V = async (c, s) => {
|
|
|
101
107
|
}
|
|
102
108
|
},
|
|
103
109
|
[
|
|
104
|
-
...
|
|
110
|
+
...p,
|
|
105
111
|
{ id: Date.now().toString(), role: "assistant", content: r.answer, links: [] }
|
|
106
112
|
]
|
|
107
|
-
)) : (
|
|
113
|
+
)) : (f(!0), _({
|
|
108
114
|
answer: null,
|
|
109
115
|
recordsConsidered: r.recordsConsidered,
|
|
110
|
-
suggestedValues:
|
|
116
|
+
suggestedValues: g.suggestedValues
|
|
111
117
|
}));
|
|
112
118
|
} catch (e) {
|
|
113
|
-
console.error(e),
|
|
119
|
+
console.error(e), f(!0);
|
|
114
120
|
} finally {
|
|
115
121
|
h(!1);
|
|
116
122
|
}
|
|
117
|
-
},
|
|
123
|
+
}, T = O(K), U = b?.root?.serverError;
|
|
118
124
|
return {
|
|
119
125
|
formSettings: s,
|
|
120
|
-
control:
|
|
121
|
-
errors:
|
|
126
|
+
control: C,
|
|
127
|
+
errors: b,
|
|
122
128
|
isSubmitSuccessful: L,
|
|
123
129
|
isSubmitting: P,
|
|
124
|
-
handleSubmit:
|
|
130
|
+
handleSubmit: T,
|
|
125
131
|
loading: A,
|
|
126
|
-
formError:
|
|
132
|
+
formError: U,
|
|
127
133
|
submittedPrimaryForm: F,
|
|
128
134
|
handleSubmitPrimaryForm: B,
|
|
129
135
|
aiResponse: M,
|
|
130
|
-
showSecondaryFields:
|
|
131
|
-
setShowSecondaryFields:
|
|
136
|
+
showSecondaryFields: I,
|
|
137
|
+
setShowSecondaryFields: f
|
|
132
138
|
};
|
|
133
139
|
};
|
|
134
140
|
export {
|
|
@@ -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.101",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.101",
|
|
11
11
|
componentType: s,
|
|
12
12
|
tags: a
|
|
13
13
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/cxkit-primitives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.101",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"remark-gfm": "^4.0.1",
|
|
68
68
|
"unist-util-visit": "^5.0.0",
|
|
69
69
|
"use-sync-external-store": "^1.4.0",
|
|
70
|
-
"@inkeep/cxkit-color-mode": "^0.5.
|
|
71
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
72
|
-
"@inkeep/cxkit-types": "0.5.
|
|
70
|
+
"@inkeep/cxkit-color-mode": "^0.5.101",
|
|
71
|
+
"@inkeep/cxkit-theme": "0.5.101",
|
|
72
|
+
"@inkeep/cxkit-types": "0.5.101"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@biomejs/biome": "1.9.4",
|