@inkeep/cxkit-primitives 0.5.43 → 0.5.44
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,4 +1,4 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("openai"),t=require("react"),Re=require("../../providers/config-provider.cjs"),Le=require("../../providers/conversation-provider.cjs"),xe=require("../../providers/chat-events-provider.cjs"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ae=require("openai"),t=require("react"),Re=require("../../providers/config-provider.cjs"),Le=require("../../providers/conversation-provider.cjs"),xe=require("../../providers/chat-events-provider.cjs"),D=require("../../utils/get-message-metadata.cjs"),Be=require("../../utils/misc.cjs"),ae=require("../../utils/reset-query-params.cjs"),De=require("../../providers/chat-form-provider.cjs"),Oe=require("../../providers/widget-provider.cjs"),Fe=require("../../hooks/use-media-query.cjs"),Te=require("./use-captcha.cjs"),Ke=require("../modal/modal-provider.cjs"),u=require("../../utils/generate-uid.cjs"),Qe=require("../../utils/tools/links-tool.cjs"),We=require("../../atoms/api/analytics/conversation.cjs"),Je=()=>{const{chatId:f,setConversation:re,conversation:N,resetConversation:ie}=Le.useInkeepConversation(),{baseSettings:b,aiChatSettings:O}=Re.useInkeepConfig(),{aiApiBaseUrl:F,shouldBypassCaptcha:T,filters:K}=b,Q=Ke.useModal(),{getSolution:ce,prefetchSolution:q,invalidateSolution:W}=Te.useCaptcha({fetchUrl:`${F}/v1/challenge`,shouldBypassCaptcha:T,shouldMakeInitialRequest:Q?Q.isOpen:!0}),le=new Ae({baseURL:`${F}/v1`,apiKey:b.apiKey,dangerouslyAllowBrowser:!0}),{onInputMessageChange:ue,getTools:ge,prompts:de,model:me,filters:J,onToolCall:fe}=O,[p,_]=t.useState(""),z=t.useRef(null);t.useEffect(()=>{ue?.(p)},[p]);const[g,l]=t.useState([]),[H,h]=t.useState(!1),[pe,v]=t.useState(!1),[he,j]=t.useState(null),[A,G]=t.useState(null),[y,S]=t.useState([]),ve=e=>{S(s=>[...s,e])},[ye,V]=t.useState({}),i=t.useRef([]),C=t.useRef(null),{logEvent:P}=xe.useChatEvents(),X=de?.map((e,s)=>({id:`system-${Date.now().toString()}-${u.generateUid(4)}-${s}`,role:"system",content:e})),[Se,Ce]=t.useState(!!f);t.useEffect(()=>{if(f){const{apiKey:e,analyticsApiBaseUrl:s}=b;We.getConversation(f,e,s).then(n=>{if(n){P({eventName:"shared_chat_loaded",properties:{conversation:n}}),Ce(!1),re({...n,id:""});const a=n.messages.map(c=>({id:Date.now().toString()+u.generateUid(4)+c.id,content:Be.parseIfJson(c.content),role:c.role,links:c.links}));l(a),i.current=a}})}},[f]);const Me=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${b.organizationDisplayName??"Administrator"}`;default:return`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),l(s=>{const n=[...s],a=n[n.length-1];return a&&(a.content=Me(e)),n}),h(!1),v(!1),W(),q()},
|
|
4
|
-
${
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},Y=e=>{j(e),l(s=>{const n=[...s],a=n[n.length-1];return a&&(a.content=Me(e)),n}),h(!1),v(!1),W(),q()},R=!p.trim()&&!y.length||H,we=e=>{e.key==="Enter"&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),L())},Ie=e=>{const s=e.target.value;_(s)},L=async(e=p)=>{if(R&&(!e||e.trim().length===0))return;h(!0);const s=A?g.length===2:g.length===0,n=D.getMessageMetadata(A,y,s);let a;const c=D.serializeAttachments(y);y.length&&c?a=[{type:"text",text:c}]:a=e;const ee={id:`${Date.now().toString()}-${u.generateUid(4)}-1`,role:"user",content:a,metadata:n},E=[...g.length?[]:X,ee];f&&ae.resetQueryParams(),l(M=>[...M,...E]),i.current=[...i.current,...E],S([]),_(""),P({eventName:"user_message_submitted",properties:{}},i.current);const te=[Qe.provideLinksTool,...ge?.({conversation:N})||[]];try{const M={model:me,messages:i.current,stream:!0,tools:te,tool_choice:"auto"},se=await ce(),ne=se?btoa(JSON.stringify(se)):null,oe=K||J?JSON.stringify({...K,...J}):void 0,U={};!T&&ne&&(U["X-INKEEP-CHALLENGE-SOLUTION"]=ne),oe&&(U["inkeep-filters"]=oe);const d=le.beta.chat.completions.stream(M,Object.keys(U).length>0?{headers:U}:void 0),o={id:`${Date.now().toString()}-${u.generateUid(4)}-2`,role:"assistant",content:"",links:[],toolCalls:[]};l(w=>[...w,o]),d.on("content",(w,I)=>{v(!0),o.content=I,l($=>{const r=[...$],x=r.findIndex(k=>k.id===o.id);return x===-1?[...r,o]:(r[x]={...o},r)})}),d.on("tool_calls.function.arguments.done",w=>{const{name:I,arguments:$}=w,r=te?.find(m=>m.function.name===I);if(!r)return;fe?.(w,{conversation:N});const k=("parse"in r.function?r.function.parse:JSON.parse)($),Ue=r.function.function?.(k,d),$e=r.renderMessageButtons?.({args:k,execution:Ue})??[];I==="provideLinks"?o.links=k.links??[]:V(m=>({...m,[o.id]:[...m[o.id]??[],...$e]})),o.toolCalls?.push({id:"call_"+u.generateUid(24),type:"function",function:{name:I,arguments:$}}),l(m=>{const B=[...m],Ne=B.findIndex(_e=>_e.id===o.id);return B[Ne]={...o},B})}),d.on("error",Y),d.finalChatCompletion().then(()=>{i.current=[...i.current,o],C.current=null,h(!1),v(!1),q(),P({eventName:"assistant_message_received",properties:{}},i.current)}),C.current=d.controller}catch(M){Y(M),h(!1),v(!1)}},ke=()=>{C.current&&(C.current.abort(),C.current=null),h(!1),v(!1),q()},Z=()=>{j(null),l([]),i.current=[],ie(),V({}),S([]),ae.resetQueryParams(),G(null),W(),q(),P({eventName:"chat_clear_button_clicked",properties:{conversation:N}})},be=e=>{G(e);const{initialReplyMessage:s,displayName:n}=e,a={id:g.length.toString()+u.generateUid(4),role:"user",content:n},c={id:(g.length+1).toString()+u.generateUid(4),role:"assistant",content:s,links:[]},E=[{id:`system-${Date.now().toString()}-${u.generateUid(4)}-${e.id}`,role:"system",content:`Company has asked user to follow this guided workflow:
|
|
4
|
+
${D.serializeWorkflow(e)}`},...X,a,c];l(E),S([])},{openForm:qe}=De.useChatForm(),Pe=Oe.useWidget();t.useImperativeHandle(O.chatFunctionsRef,()=>({submitMessage:L,updateInputMessage(e){_(e)},clearChat:Z,openForm:e=>{Pe?.setView("chat"),qe(e)},focusInput:()=>{z.current?.focus()}}));const Ee=Fe.useMediaQuery("(max-width: 768px)");return{messages:g,input:p,isLoading:H,isStreaming:pe,isLoadingConversation:Se,error:he,isSubmitDisabled:R,handleInputChange:Ie,handleInputKeyDown:we,handleSubmit:L,stop:ke,clear:Z,handleWorkflow:be,selectedWorkflow:A,messageAttachments:y,setMessageAttachments:S,addAttachment:ve,messageButtons:ye,isEmpty:g.length===0,inputRef:z,isMobile:Ee}};exports.useInkeepChat=Je;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import De from "openai";
|
|
3
|
-
import { useState as c, useRef as
|
|
3
|
+
import { useState as c, useRef as U, useEffect as ae, useImperativeHandle as Oe } from "react";
|
|
4
4
|
import { useInkeepConfig as Re } from "../../providers/config-provider.js";
|
|
5
5
|
import { useInkeepConversation as Pe } from "../../providers/conversation-provider.js";
|
|
6
6
|
import { useChatEvents as Ue } from "../../providers/chat-events-provider.js";
|
|
@@ -16,7 +16,7 @@ import { generateUid as u } from "../../utils/generate-uid.js";
|
|
|
16
16
|
import { provideLinksTool as qe } from "../../utils/tools/links-tool.js";
|
|
17
17
|
import { getConversation as Ge } from "../../atoms/api/analytics/conversation.js";
|
|
18
18
|
const gt = () => {
|
|
19
|
-
const { chatId: d, setConversation: ie, conversation:
|
|
19
|
+
const { chatId: d, setConversation: ie, conversation: x, resetConversation: ce } = Pe(), { baseSettings: b, aiChatSettings: F } = Re(), { aiApiBaseUrl: K, shouldBypassCaptcha: T, filters: W } = b, J = je(), { getSolution: le, prefetchSolution: $, invalidateSolution: z } = Qe({
|
|
20
20
|
fetchUrl: `${K}/v1/challenge`,
|
|
21
21
|
shouldBypassCaptcha: T,
|
|
22
22
|
shouldMakeInitialRequest: J ? J.isOpen : !0
|
|
@@ -31,13 +31,13 @@ const gt = () => {
|
|
|
31
31
|
model: de,
|
|
32
32
|
filters: H,
|
|
33
33
|
onToolCall: fe
|
|
34
|
-
} = F, [f,
|
|
34
|
+
} = F, [f, L] = c(""), Q = U(null);
|
|
35
35
|
ae(() => {
|
|
36
36
|
me?.(f);
|
|
37
37
|
}, [f]);
|
|
38
|
-
const [m, l] = c([]), [j, h] = c(!1), [he, y] = c(!1), [ye, q] = c(null), [
|
|
38
|
+
const [m, l] = c([]), [j, h] = c(!1), [he, y] = c(!1), [ye, q] = c(null), [B, G] = c(null), [C, w] = c([]), Ce = (e) => {
|
|
39
39
|
w((t) => [...t, e]);
|
|
40
|
-
}, [we, V] = c({}), r =
|
|
40
|
+
}, [we, V] = c({}), r = U([]), v = U(null), { logEvent: E } = Ue(), X = pe?.map((e, t) => ({
|
|
41
41
|
id: `system-${Date.now().toString()}-${u(4)}-${t}`,
|
|
42
42
|
role: "system",
|
|
43
43
|
content: e
|
|
@@ -80,15 +80,15 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
80
80
|
const s = [...t], o = s[s.length - 1];
|
|
81
81
|
return o && (o.content = Me(e)), s;
|
|
82
82
|
}), h(!1), y(!1), z(), $();
|
|
83
|
-
},
|
|
84
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
83
|
+
}, D = !f.trim() && !C.length || j, Se = (e) => {
|
|
84
|
+
e.key === "Enter" && !e.shiftKey && !D && !e.nativeEvent.isComposing && (e.preventDefault(), O());
|
|
85
85
|
}, ke = (e) => {
|
|
86
86
|
const t = e.target.value;
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
if (
|
|
87
|
+
L(t);
|
|
88
|
+
}, O = async (e = f) => {
|
|
89
|
+
if (D && (!e || e.trim().length === 0)) return;
|
|
90
90
|
h(!0);
|
|
91
|
-
const t =
|
|
91
|
+
const t = B ? m.length === 2 : m.length === 0, s = Fe(B, C, t);
|
|
92
92
|
let o;
|
|
93
93
|
const i = Ke(C);
|
|
94
94
|
C.length && i ? o = [{ type: "text", text: i }] : o = e;
|
|
@@ -98,14 +98,14 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
98
98
|
content: o,
|
|
99
99
|
metadata: s
|
|
100
100
|
}, N = [...m.length ? [] : X, ee];
|
|
101
|
-
d && re(), l((I) => [...I, ...N]), r.current = [...r.current, ...N], w([]),
|
|
101
|
+
d && re(), l((I) => [...I, ...N]), r.current = [...r.current, ...N], w([]), L(""), E(
|
|
102
102
|
{
|
|
103
103
|
eventName: "user_message_submitted",
|
|
104
104
|
properties: {}
|
|
105
105
|
},
|
|
106
106
|
r.current
|
|
107
107
|
);
|
|
108
|
-
const te = [qe, ...ge?.({ conversation:
|
|
108
|
+
const te = [qe, ...ge?.({ conversation: x }) || []];
|
|
109
109
|
try {
|
|
110
110
|
const I = {
|
|
111
111
|
model: de,
|
|
@@ -130,13 +130,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
130
130
|
};
|
|
131
131
|
l((M) => [...M, n]), g.on("content", (M, S) => {
|
|
132
132
|
y(!0), n.content = S, l((A) => {
|
|
133
|
-
const a = [...A],
|
|
134
|
-
return
|
|
133
|
+
const a = [...A], R = a.findIndex((k) => k.id === n.id);
|
|
134
|
+
return R === -1 ? [...a, n] : (a[R] = { ...n }, a);
|
|
135
135
|
});
|
|
136
136
|
}), g.on("tool_calls.function.arguments.done", (M) => {
|
|
137
137
|
const { name: S, arguments: A } = M, a = te?.find((p) => p.function.name === S);
|
|
138
138
|
if (!a) return;
|
|
139
|
-
fe?.(M);
|
|
139
|
+
fe?.(M, { conversation: x });
|
|
140
140
|
const k = ("parse" in a.function ? a.function.parse : JSON.parse)(A), Ae = a.function.function?.(k, g), xe = a.renderMessageButtons?.({ args: k, execution: Ae }) ?? [];
|
|
141
141
|
S === "provideLinks" ? n.links = k.links ?? [] : V((p) => ({
|
|
142
142
|
...p,
|
|
@@ -149,8 +149,8 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
149
149
|
arguments: A
|
|
150
150
|
}
|
|
151
151
|
}), l((p) => {
|
|
152
|
-
const
|
|
153
|
-
return
|
|
152
|
+
const P = [...p], Le = P.findIndex((Be) => Be.id === n.id);
|
|
153
|
+
return P[Le] = { ...n }, P;
|
|
154
154
|
});
|
|
155
155
|
}), g.on("error", Y), g.finalChatCompletion().then(() => {
|
|
156
156
|
r.current = [...r.current, n], v.current = null, h(!1), y(!1), $(), E(
|
|
@@ -170,7 +170,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
170
170
|
q(null), l([]), r.current = [], ce(), V({}), w([]), re(), G(null), z(), $(), E({
|
|
171
171
|
eventName: "chat_clear_button_clicked",
|
|
172
172
|
properties: {
|
|
173
|
-
conversation:
|
|
173
|
+
conversation: x
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
}, $e = (e) => {
|
|
@@ -193,9 +193,9 @@ ${Te(e)}`
|
|
|
193
193
|
l(N), w([]);
|
|
194
194
|
}, { openForm: Ee } = Je(), Ne = ze();
|
|
195
195
|
Oe(F.chatFunctionsRef, () => ({
|
|
196
|
-
submitMessage:
|
|
196
|
+
submitMessage: O,
|
|
197
197
|
updateInputMessage(e) {
|
|
198
|
-
|
|
198
|
+
L(e);
|
|
199
199
|
},
|
|
200
200
|
clearChat: Z,
|
|
201
201
|
openForm: (e) => {
|
|
@@ -213,14 +213,14 @@ ${Te(e)}`
|
|
|
213
213
|
isStreaming: he,
|
|
214
214
|
isLoadingConversation: ve,
|
|
215
215
|
error: ye,
|
|
216
|
-
isSubmitDisabled:
|
|
216
|
+
isSubmitDisabled: D,
|
|
217
217
|
handleInputChange: ke,
|
|
218
218
|
handleInputKeyDown: Se,
|
|
219
|
-
handleSubmit:
|
|
219
|
+
handleSubmit: O,
|
|
220
220
|
stop: be,
|
|
221
221
|
clear: Z,
|
|
222
222
|
handleWorkflow: $e,
|
|
223
|
-
selectedWorkflow:
|
|
223
|
+
selectedWorkflow: B,
|
|
224
224
|
messageAttachments: C,
|
|
225
225
|
setMessageAttachments: w,
|
|
226
226
|
addAttachment: Ce,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=t.useMemo(()=>({widgetLibraryVersion:"0.5.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),b=require("./user-provider.cjs"),p=t.createContext(void 0),f=({children:e})=>{const{baseSettings:s,componentType:n}=B.useInkeepConfig(),{apiKey:o,analyticsApiBaseUrl:r,tags:i,privacyPreferences:d,env:E}=s,{userProperties:c}=b.useUser(),a=t.useMemo(()=>({widgetLibraryVersion:"0.5.44",componentType:n,tags:i}),[n,i]),u=!d.optOutAllAnalytics&&E!=="development",g={logEvent:t.useCallback(async v=>{const m={...a,...v.properties},l={eventName:v.eventName,properties:m,userProperties:c};u&&y.logEvent(l,o,r),s.onEvent?.(l)},[u,s,o,r,c,a])};return P.jsx(p.Provider,{value:g,children:e})},x=()=>{const e=t.useContext(p);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=f;exports.useBaseEvents=x;
|
|
@@ -7,7 +7,7 @@ import { useUser as b } from "./user-provider.js";
|
|
|
7
7
|
const m = x(void 0), U = ({ children: e }) => {
|
|
8
8
|
const { baseSettings: t, componentType: o } = C(), { apiKey: n, analyticsApiBaseUrl: s, tags: r, privacyPreferences: u, env: l } = t, { userProperties: i } = b(), a = d(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
10
|
+
widgetLibraryVersion: "0.5.44",
|
|
11
11
|
componentType: o,
|
|
12
12
|
tags: r
|
|
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.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"remark-gfm": "^4.0.1",
|
|
60
60
|
"unist-util-visit": "^5.0.0",
|
|
61
61
|
"use-sync-external-store": "^1.4.0",
|
|
62
|
-
"@inkeep/cxkit-color-mode": "0.5.
|
|
63
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
64
|
-
"@inkeep/cxkit-types": "0.5.
|
|
62
|
+
"@inkeep/cxkit-color-mode": "0.5.44",
|
|
63
|
+
"@inkeep/cxkit-theme": "0.5.44",
|
|
64
|
+
"@inkeep/cxkit-types": "0.5.44"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "1.9.4",
|