@inkeep/agents-ui 0.15.8 → 0.15.10
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/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +21 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +83 -80
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +82 -79
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/styled/components/data-summary-group.cjs +1 -1
- package/dist/styled/components/data-summary-group.js +70 -63
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +271 -88
- package/dist/styled/components/ui/recipes/button.cjs +1 -1
- package/dist/styled/components/ui/recipes/button.d.ts +1 -1
- package/dist/styled/components/ui/recipes/button.js +6 -0
- package/dist/styled/inkeep.css.cjs +78 -0
- package/dist/styled/inkeep.css.js +78 -0
- package/dist/types/config/components.d.ts +6 -0
- package/package.json +4 -5
|
@@ -1,3 +1,3 @@
|
|
|
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 ee=require("@ai-sdk/react"),te=require("ai"),n=require("react"),se=require("../../providers/config-provider.cjs"),ne=require("../../hooks/use-media-query.cjs"),A=require("../../utils/generate-uid.cjs"),re=require("../../providers/base-events-provider.cjs"),oe=require("../../providers/chat-form-provider.cjs"),ae=require("../../providers/widget-provider.cjs"),ie=require("@radix-ui/react-use-controllable-state"),ce=require("../../hooks/use-streaming-events.cjs"),P=`Hmm..
|
|
2
2
|
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`,ue=()=>{const{baseSettings:C,aiChatSettings:i}=se.useInkeepConfig(),[t="",I]=ie.useControllableState({prop:i.conversationId,defaultProp:i.conversationId??""}),{logEvent:o}=re.useBaseEvents(),{setConversationId:N,emitToParent:u}=ce.useStreamingEvents(),[a,l]=n.useState(""),T=e=>l(e.target.value),{filters:b}=C,{onInputMessageChange:U,filters:y,agentUrl:w,context:d,headers:p,apiKey:g}=i,O=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${C.organizationDisplayName??"Administrator"}`;default:return P}},[H,m]=n.useState([]),[z,M]=n.useState(null),K=()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString()}),L=n.useMemo(()=>new te.DefaultChatTransport({api:w,headers:{...g?{Authorization:`Bearer ${g}`}:{},...p},body:{requestContext:d}}),[w,g,p,d]),{messages:h,sendMessage:_,addToolApprovalResponse:W,status:q,setMessages:x,stop:$,error:f}=ee.useChat({transport:L,onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:t}),await o({eventName:"assistant_message_received",properties:{conversationId:t}}),o({eventName:"assistant_answer_displayed",properties:{conversationId:t}})},onError(e){console.log("onError",e.message),o({eventName:"chat_error",properties:{conversationId:t,error:e.message}}),x(c=>{const r=[...c],s=r[r.length-1];if(s){const D=O(e);s.role==="user"?r.push({id:A.generateUid(16),role:"assistant",parts:[{type:"text",text:D}]}):s.parts=[{type:"text",text:D}]}return r})}}),F=q==="submitted",B=q==="streaming",G=h.length===0,v=!a.trim()||F,Q=ne.useMediaQuery("(max-width: 768px)"),[j,S]=n.useState(null);n.useEffect(()=>{f&&S(f)},[f]);const J=()=>S(null),R=n.useRef(null);n.useEffect(()=>{U?.(a)},[a]);const V=e=>{e.key==="Enter"&&!e.shiftKey&&!v&&!e.nativeEvent.isComposing&&(e.preventDefault(),E())},E=async(e=a)=>{if(v&&(!e||e.trim().length===0))return;m([]),l(""),await o({eventName:"user_message_submitted",properties:{conversationId:t}});const c=b||y?JSON.stringify({...b,...y}):void 0,r={...p};c&&(r["inkeep-filters"]=c);let s=t;s||(s=`conv_${A.generateUid(16)}`,I(s)),N(s),_({text:e},{headers:{...K(),...r},body:{conversationId:s,requestContext:d}})},Z=()=>{$().then(()=>{u("aborted",{conversationId:t})})},k=()=>{J(),x([]),I(""),m([]),M(null),o({eventName:"chat_clear_button_clicked",properties:{conversationId:t}})},{openForm:X}=oe.useChatForm(),Y=ae.useWidget();return n.useImperativeHandle(i.chatFunctionsRef,()=>({submitMessage:E,updateInputMessage(e){l(e)},clearChat:k,openForm:e=>{Y?.setView("chat"),X(e,void 0)},focusInput:()=>{R.current?.focus()}})),{messages:h,sendMessage:_,addToolApprovalResponse:W,isLoading:F,isStreaming:B,error:j,setError:S,isSubmitDisabled:v,input:a,handleInputChange:T,handleInputKeyDown:V,handleSubmit:E,stop:Z,clear:k,isEmpty:h.length===0,inputRef:R,isMobile:Q,messageAttachments:H,setMessageAttachments:m,selectedWorkflow:z,setSelectedWorkflow:M,isNewChat:G,conversationId:t}};exports.DEFAULT_ERROR_MESSAGE=P;exports.useInkeepChat=ue;
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import { KeyboardEvent, Dispatch, SetStateAction, RefObject } from 'react';
|
|
2
2
|
import { Message, MessageAttachment, Workflow } from '../../../types/index.ts';
|
|
3
|
+
import { FileUIPart, ChatRequestOptions, ChatAddToolApproveResponseFunction } from 'ai';
|
|
3
4
|
export declare const DEFAULT_ERROR_MESSAGE = "Hmm.. \n\nIt seems I might be having some issues right now. Please clear the chat and try again.";
|
|
4
5
|
export declare const useInkeepChat: () => {
|
|
5
6
|
messages: Message[];
|
|
7
|
+
sendMessage: (message?: (Omit<Message, "id" | "role"> & {
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
role?: "system" | "user" | "assistant" | undefined;
|
|
10
|
+
} & {
|
|
11
|
+
text?: never;
|
|
12
|
+
files?: never;
|
|
13
|
+
messageId?: string;
|
|
14
|
+
}) | {
|
|
15
|
+
text: string;
|
|
16
|
+
files?: FileList | FileUIPart[];
|
|
17
|
+
metadata?: unknown;
|
|
18
|
+
parts?: never;
|
|
19
|
+
messageId?: string;
|
|
20
|
+
} | {
|
|
21
|
+
files: FileList | FileUIPart[];
|
|
22
|
+
metadata?: unknown;
|
|
23
|
+
parts?: never;
|
|
24
|
+
messageId?: string;
|
|
25
|
+
} | undefined, options?: ChatRequestOptions) => Promise<void>;
|
|
26
|
+
addToolApprovalResponse: ChatAddToolApproveResponseFunction;
|
|
6
27
|
isLoading: boolean;
|
|
7
28
|
isStreaming: boolean;
|
|
8
29
|
error: Error | null;
|
|
@@ -1,68 +1,70 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { DefaultChatTransport as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { useInkeepConfig as
|
|
6
|
-
import { useMediaQuery as
|
|
7
|
-
import { generateUid as
|
|
8
|
-
import { useBaseEvents as
|
|
9
|
-
import { useChatForm as
|
|
10
|
-
import { useWidget as
|
|
11
|
-
import { useControllableState as
|
|
12
|
-
import { useStreamingEvents as
|
|
13
|
-
const
|
|
2
|
+
import { useChat as ee } from "@ai-sdk/react";
|
|
3
|
+
import { DefaultChatTransport as te } from "ai";
|
|
4
|
+
import { useState as c, useMemo as se, useEffect as R, useRef as ne, useImperativeHandle as oe } from "react";
|
|
5
|
+
import { useInkeepConfig as re } from "../../providers/config-provider.js";
|
|
6
|
+
import { useMediaQuery as ae } from "../../hooks/use-media-query.js";
|
|
7
|
+
import { generateUid as T } from "../../utils/generate-uid.js";
|
|
8
|
+
import { useBaseEvents as ie } from "../../providers/base-events-provider.js";
|
|
9
|
+
import { useChatForm as ce } from "../../providers/chat-form-provider.js";
|
|
10
|
+
import { useWidget as me } from "../../providers/widget-provider.js";
|
|
11
|
+
import { useControllableState as le } from "@radix-ui/react-use-controllable-state";
|
|
12
|
+
import { useStreamingEvents as pe } from "../../hooks/use-streaming-events.js";
|
|
13
|
+
const ue = `Hmm..
|
|
14
14
|
|
|
15
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,
|
|
16
|
-
const { baseSettings:
|
|
15
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, we = () => {
|
|
16
|
+
const { baseSettings: y, aiChatSettings: a } = re(), [t = "", E] = le({
|
|
17
17
|
prop: a.conversationId,
|
|
18
18
|
defaultProp: a.conversationId ?? ""
|
|
19
|
-
}), { logEvent: o } =
|
|
19
|
+
}), { logEvent: o } = ie(), { setConversationId: H, emitToParent: m } = pe(), [r, l] = c(""), O = (e) => l(e.target.value), {
|
|
20
20
|
/* shouldBypassCaptcha, */
|
|
21
|
-
filters:
|
|
22
|
-
} =
|
|
23
|
-
onInputMessageChange:
|
|
24
|
-
filters:
|
|
21
|
+
filters: b
|
|
22
|
+
} = y, {
|
|
23
|
+
onInputMessageChange: P,
|
|
24
|
+
filters: S,
|
|
25
25
|
agentUrl: w,
|
|
26
26
|
context: p,
|
|
27
27
|
headers: u,
|
|
28
|
-
apiKey:
|
|
29
|
-
} = a,
|
|
28
|
+
apiKey: d
|
|
29
|
+
} = a, q = (e) => {
|
|
30
30
|
switch (e.code) {
|
|
31
31
|
case 400:
|
|
32
32
|
return e.message;
|
|
33
33
|
case 403:
|
|
34
|
-
return `There seems to be a configuration error. Please contact ${
|
|
34
|
+
return `There seems to be a configuration error. Please contact ${y.organizationDisplayName ?? "Administrator"}`;
|
|
35
35
|
default:
|
|
36
|
-
return
|
|
36
|
+
return ue;
|
|
37
37
|
}
|
|
38
|
-
}, [
|
|
39
|
-
()
|
|
38
|
+
}, [z, g] = c([]), [K, x] = c(null), U = () => ({
|
|
39
|
+
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
40
|
+
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString()
|
|
41
|
+
}), W = se(
|
|
42
|
+
() => new te({
|
|
40
43
|
api: w,
|
|
41
44
|
headers: {
|
|
42
|
-
...
|
|
43
|
-
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
44
|
-
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
45
|
+
...d ? { Authorization: `Bearer ${d}` } : {},
|
|
45
46
|
...u
|
|
46
47
|
},
|
|
47
48
|
body: {
|
|
48
49
|
requestContext: p
|
|
49
50
|
}
|
|
50
51
|
}),
|
|
51
|
-
[w,
|
|
52
|
+
[w, d, u, p]
|
|
52
53
|
), {
|
|
53
54
|
messages: h,
|
|
54
|
-
sendMessage:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
sendMessage: M,
|
|
56
|
+
addToolApprovalResponse: $,
|
|
57
|
+
status: _,
|
|
58
|
+
setMessages: k,
|
|
59
|
+
stop: B,
|
|
58
60
|
error: f
|
|
59
|
-
} =
|
|
60
|
-
transport:
|
|
61
|
+
} = ee({
|
|
62
|
+
transport: W,
|
|
61
63
|
onData(e) {
|
|
62
|
-
|
|
64
|
+
m(e.type, e.data);
|
|
63
65
|
},
|
|
64
66
|
async onFinish() {
|
|
65
|
-
|
|
67
|
+
m("completion", { conversationId: t }), await o({
|
|
66
68
|
eventName: "assistant_message_received",
|
|
67
69
|
properties: {
|
|
68
70
|
conversationId: t
|
|
@@ -81,53 +83,52 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
81
83
|
conversationId: t,
|
|
82
84
|
error: e.message
|
|
83
85
|
}
|
|
84
|
-
}),
|
|
86
|
+
}), k((i) => {
|
|
85
87
|
const n = [...i], s = n[n.length - 1];
|
|
86
88
|
if (s) {
|
|
87
|
-
const
|
|
89
|
+
const A = q(e);
|
|
88
90
|
s.role === "user" ? n.push({
|
|
89
|
-
id:
|
|
91
|
+
id: T(16),
|
|
90
92
|
role: "assistant",
|
|
91
|
-
parts: [{ type: "text", text:
|
|
92
|
-
}) : s.parts = [{ type: "text", text:
|
|
93
|
+
parts: [{ type: "text", text: A }]
|
|
94
|
+
}) : s.parts = [{ type: "text", text: A }];
|
|
93
95
|
}
|
|
94
96
|
return n;
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
|
-
}),
|
|
98
|
-
|
|
99
|
+
}), D = _ === "submitted", L = _ === "streaming", G = h.length === 0, v = !r.trim() || D, J = ae("(max-width: 768px)"), [Q, I] = c(null);
|
|
100
|
+
R(() => {
|
|
99
101
|
f && I(f);
|
|
100
102
|
}, [f]);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const V = () => I(null), F = ne(null);
|
|
104
|
+
R(() => {
|
|
105
|
+
P?.(r);
|
|
104
106
|
}, [r]);
|
|
105
|
-
const
|
|
107
|
+
const Z = (e) => {
|
|
106
108
|
e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), C());
|
|
107
109
|
}, C = async (e = r) => {
|
|
108
110
|
if (v && (!e || e.trim().length === 0)) return;
|
|
109
|
-
|
|
111
|
+
g([]), l(""), await o({
|
|
110
112
|
eventName: "user_message_submitted",
|
|
111
113
|
properties: {
|
|
112
114
|
conversationId: t
|
|
113
115
|
}
|
|
114
116
|
});
|
|
115
|
-
const i =
|
|
116
|
-
...
|
|
117
|
-
...
|
|
117
|
+
const i = b || S ? JSON.stringify({
|
|
118
|
+
...b,
|
|
119
|
+
...S
|
|
118
120
|
}) : void 0, n = {
|
|
119
121
|
...u
|
|
120
122
|
};
|
|
121
123
|
i && (n["inkeep-filters"] = i);
|
|
122
124
|
let s = t;
|
|
123
|
-
s || (s = `conv_${
|
|
125
|
+
s || (s = `conv_${T(16)}`, E(s)), H(s), M(
|
|
124
126
|
{
|
|
125
127
|
text: e
|
|
126
128
|
},
|
|
127
129
|
{
|
|
128
130
|
headers: {
|
|
129
|
-
|
|
130
|
-
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
131
|
+
...U(),
|
|
131
132
|
...n
|
|
132
133
|
},
|
|
133
134
|
body: {
|
|
@@ -136,56 +137,58 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
);
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
}, j = () => {
|
|
141
|
+
B().then(() => {
|
|
142
|
+
m("aborted", { conversationId: t });
|
|
142
143
|
});
|
|
143
|
-
},
|
|
144
|
-
|
|
144
|
+
}, N = () => {
|
|
145
|
+
V(), k([]), E(""), g([]), x(null), o({
|
|
145
146
|
eventName: "chat_clear_button_clicked",
|
|
146
147
|
properties: {
|
|
147
148
|
conversationId: t
|
|
148
149
|
}
|
|
149
150
|
});
|
|
150
|
-
}, { openForm:
|
|
151
|
-
return
|
|
151
|
+
}, { openForm: X } = ce(), Y = me();
|
|
152
|
+
return oe(a.chatFunctionsRef, () => ({
|
|
152
153
|
submitMessage: C,
|
|
153
154
|
updateInputMessage(e) {
|
|
154
155
|
l(e);
|
|
155
156
|
},
|
|
156
|
-
clearChat:
|
|
157
|
+
clearChat: N,
|
|
157
158
|
openForm: (e) => {
|
|
158
|
-
|
|
159
|
+
Y?.setView("chat"), X(e, void 0);
|
|
159
160
|
},
|
|
160
161
|
focusInput: () => {
|
|
161
|
-
|
|
162
|
+
F.current?.focus();
|
|
162
163
|
}
|
|
163
164
|
})), {
|
|
164
165
|
messages: h,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
sendMessage: M,
|
|
167
|
+
addToolApprovalResponse: $,
|
|
168
|
+
isLoading: D,
|
|
169
|
+
isStreaming: L,
|
|
170
|
+
error: Q,
|
|
168
171
|
setError: I,
|
|
169
172
|
isSubmitDisabled: v,
|
|
170
173
|
input: r,
|
|
171
|
-
handleInputChange:
|
|
172
|
-
handleInputKeyDown:
|
|
174
|
+
handleInputChange: O,
|
|
175
|
+
handleInputKeyDown: Z,
|
|
173
176
|
handleSubmit: C,
|
|
174
|
-
stop:
|
|
175
|
-
clear:
|
|
177
|
+
stop: j,
|
|
178
|
+
clear: N,
|
|
176
179
|
isEmpty: h.length === 0,
|
|
177
|
-
inputRef:
|
|
178
|
-
isMobile:
|
|
180
|
+
inputRef: F,
|
|
181
|
+
isMobile: J,
|
|
179
182
|
// Additional state for attachments and workflow
|
|
180
|
-
messageAttachments:
|
|
181
|
-
setMessageAttachments:
|
|
182
|
-
selectedWorkflow:
|
|
183
|
+
messageAttachments: z,
|
|
184
|
+
setMessageAttachments: g,
|
|
185
|
+
selectedWorkflow: K,
|
|
183
186
|
setSelectedWorkflow: x,
|
|
184
|
-
isNewChat:
|
|
187
|
+
isNewChat: G,
|
|
185
188
|
conversationId: t
|
|
186
189
|
};
|
|
187
190
|
};
|
|
188
191
|
export {
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
ue as DEFAULT_ERROR_MESSAGE,
|
|
193
|
+
we as useInkeepChat
|
|
191
194
|
};
|
|
@@ -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 r=require("react"),L=require("./use-inkeep-chat.cjs");function M(l,u,C){const[p,k]=r.useState([]),[y,x]=r.useState(new Map),[w,A]=r.useState(Date.now()),[P,d]=r.useState(!1),S=r.useRef(0),D=r.useRef(0),R=r.useRef([]),m=r.useRef(y);m.current=y;const T=r.useCallback(()=>{const t=[];let e="",o=[],i=!1;l.length>S.current&&(A(Date.now()),S.current=l.length),D.current=0;const c=new Map,a=(n=!1)=>{if(o.length>0){const s=`group-${D.current++}`,h=m.current.get(s);h?c.set(s,{...h,isCompleted:n}):c.set(s,{isCompleted:n}),t.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const n of l)if(n.type==="text")a(!0),e+=n.text||"";else if(n.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),o.push(n.data);else if(n.type==="data-operation"){e.trim()&&(t.push({type:"text",text:e}),e="");const s=n.data;if(s?.type){if((s.type==="tool_call"||s.type==="tool_result")&&s.details?.data?.inDelegatedAgent===!1)continue;switch(s.type){case"agent_initializing":break;case"completion":{const{type:f}=s;o.push({type:f,label:"Completed"}),a(!0);break}case"error":{const f=s.message||"Unknown error";if(console.warn("Data operation error:",f),!t.length)a(!0),C(new Error(f)),i||(t.push({type:"text",text:L.DEFAULT_ERROR_MESSAGE}),i=!0);else{const{type:g,label:E}=s;o.push({type:g,label:E})}break}default:{const{type:f,label:g}=s;o.push({type:f,label:g});break}}}}else if(n.type==="data-artifact")if(n.data?.type?.toLowerCase()==="citation"){const s=n.data,h=s.artifactSummary||{title:s.name};e+=` ^${h?.title||s.name}^`}else e.trim()&&(t.push({type:"text",text:e}),e=""),t.push(n);else n.type==="data-component"?(e.trim()&&(t.push({type:"text",text:e}),e=""),a(!0),t.push(n)):(e.trim()&&(t.push({type:"text",text:e}),e=""),a(!0),t.push(n));return a(!u),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:c}},[l,u,C]);r.useEffect(()=>{if(R.current===l)return;R.current=l;const{processed:t,newTimings:e}=T();k(t),(e.size!==m.current.size||Array.from(e.entries()).some(([i,c])=>{const a=m.current.get(i);return!a||a.isCompleted!==c.isCompleted}))&&x(e)},[T,l]),r.useEffect(()=>{u||x(t=>{const e=new Map(t);let o=!1;for(const[i,c]of e.entries())c.isCompleted||(e.set(i,{...c,isCompleted:!0}),o=!0);return o?e:t})},[u]);const b=r.useCallback(()=>{const t=Date.now()-w,e=Array.from(m.current.values()).some(i=>!i.isCompleted),o=t>1e3&&!e;d(o)},[w]);r.useEffect(()=>{if(!u){d(!1);return}if(!(p.length>0)){d(!1);return}const e=setInterval(b,200);return()=>clearInterval(e)},[u,b,p.length]);const v=r.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:y,shouldShowInitialLoading:v,shouldShowStreamDelayLoading:P}}exports.useStreamProcessor=M;
|
|
@@ -1,119 +1,122 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as h, useRef as y, useCallback as R, useEffect as w, useMemo as z } from "react";
|
|
3
3
|
import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
|
|
4
|
-
function
|
|
5
|
-
const [
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
...
|
|
16
|
-
isCompleted:
|
|
17
|
-
}) :
|
|
18
|
-
isCompleted:
|
|
19
|
-
}),
|
|
4
|
+
function K(c, a, C) {
|
|
5
|
+
const [p, v] = h([]), [d, D] = h(/* @__PURE__ */ new Map()), [T, M] = h(Date.now()), [P, g] = h(!1), A = y(0), S = y(0), b = y([]), f = y(d);
|
|
6
|
+
f.current = d;
|
|
7
|
+
const k = R(() => {
|
|
8
|
+
const t = [];
|
|
9
|
+
let e = "", r = [], i = !1;
|
|
10
|
+
c.length > A.current && (M(Date.now()), A.current = c.length), S.current = 0;
|
|
11
|
+
const u = /* @__PURE__ */ new Map(), o = (n = !1) => {
|
|
12
|
+
if (r.length > 0) {
|
|
13
|
+
const s = `group-${S.current++}`, m = f.current.get(s);
|
|
14
|
+
m ? u.set(s, {
|
|
15
|
+
...m,
|
|
16
|
+
isCompleted: n
|
|
17
|
+
}) : u.set(s, {
|
|
18
|
+
isCompleted: n
|
|
19
|
+
}), t.push({
|
|
20
20
|
type: "summary-group",
|
|
21
|
-
summaries: [...
|
|
22
|
-
groupKey:
|
|
23
|
-
}),
|
|
21
|
+
summaries: [...r],
|
|
22
|
+
groupKey: s
|
|
23
|
+
}), r = [];
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
for (const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
else if (
|
|
30
|
-
|
|
31
|
-
else if (
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
26
|
+
for (const n of c)
|
|
27
|
+
if (n.type === "text")
|
|
28
|
+
o(!0), e += n.text || "";
|
|
29
|
+
else if (n.type === "data-summary")
|
|
30
|
+
e.trim() && (t.push({ type: "text", text: e }), e = ""), r.push(n.data);
|
|
31
|
+
else if (n.type === "data-operation") {
|
|
32
|
+
e.trim() && (t.push({ type: "text", text: e }), e = "");
|
|
33
|
+
const s = n.data;
|
|
34
|
+
if (s?.type) {
|
|
35
|
+
if ((s.type === "tool_call" || s.type === "tool_result") && s.details?.data?.inDelegatedAgent === !1)
|
|
36
|
+
continue;
|
|
37
|
+
switch (s.type) {
|
|
36
38
|
case "agent_initializing":
|
|
37
39
|
break;
|
|
38
40
|
case "completion": {
|
|
39
|
-
const { type:
|
|
40
|
-
|
|
41
|
+
const { type: l } = s;
|
|
42
|
+
r.push({ type: l, label: "Completed" }), o(!0);
|
|
41
43
|
break;
|
|
42
44
|
}
|
|
43
45
|
case "error": {
|
|
44
|
-
const
|
|
45
|
-
if (console.warn("Data operation error:",
|
|
46
|
-
|
|
46
|
+
const l = s.message || "Unknown error";
|
|
47
|
+
if (console.warn("Data operation error:", l), !t.length)
|
|
48
|
+
o(!0), C(new Error(l)), i || (t.push({ type: "text", text: G }), i = !0);
|
|
47
49
|
else {
|
|
48
|
-
const { type:
|
|
49
|
-
|
|
50
|
+
const { type: x, label: _ } = s;
|
|
51
|
+
r.push({ type: x, label: _ });
|
|
50
52
|
}
|
|
51
53
|
break;
|
|
52
54
|
}
|
|
53
55
|
default: {
|
|
54
|
-
const { type:
|
|
55
|
-
|
|
56
|
+
const { type: l, label: x } = s;
|
|
57
|
+
r.push({ type: l, label: x });
|
|
56
58
|
break;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
}
|
|
62
|
+
} else if (n.type === "data-artifact")
|
|
63
|
+
if (n.data?.type?.toLowerCase() === "citation") {
|
|
64
|
+
const s = n.data, m = s.artifactSummary || {
|
|
65
|
+
title: s.name
|
|
63
66
|
};
|
|
64
|
-
|
|
67
|
+
e += ` ^${m?.title || s.name}^`;
|
|
65
68
|
} else
|
|
66
|
-
|
|
67
|
-
else
|
|
68
|
-
return
|
|
69
|
-
}, [
|
|
69
|
+
e.trim() && (t.push({ type: "text", text: e }), e = ""), t.push(n);
|
|
70
|
+
else n.type === "data-component" ? (e.trim() && (t.push({ type: "text", text: e }), e = ""), o(!0), t.push(n)) : (e.trim() && (t.push({ type: "text", text: e }), e = ""), o(!0), t.push(n));
|
|
71
|
+
return o(!a), e.trim() && t.push({ type: "text", text: e }), { processed: t, newTimings: u };
|
|
72
|
+
}, [c, a, C]);
|
|
70
73
|
w(() => {
|
|
71
|
-
if (
|
|
74
|
+
if (b.current === c)
|
|
72
75
|
return;
|
|
73
|
-
|
|
74
|
-
const { processed:
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
return !
|
|
78
|
-
})) &&
|
|
79
|
-
}, [
|
|
80
|
-
a ||
|
|
81
|
-
const
|
|
82
|
-
let
|
|
83
|
-
for (const [i,
|
|
84
|
-
|
|
85
|
-
...
|
|
76
|
+
b.current = c;
|
|
77
|
+
const { processed: t, newTimings: e } = k();
|
|
78
|
+
v(t), (e.size !== f.current.size || Array.from(e.entries()).some(([i, u]) => {
|
|
79
|
+
const o = f.current.get(i);
|
|
80
|
+
return !o || o.isCompleted !== u.isCompleted;
|
|
81
|
+
})) && D(e);
|
|
82
|
+
}, [k, c]), w(() => {
|
|
83
|
+
a || D((t) => {
|
|
84
|
+
const e = new Map(t);
|
|
85
|
+
let r = !1;
|
|
86
|
+
for (const [i, u] of e.entries())
|
|
87
|
+
u.isCompleted || (e.set(i, {
|
|
88
|
+
...u,
|
|
86
89
|
isCompleted: !0
|
|
87
|
-
}),
|
|
88
|
-
return
|
|
90
|
+
}), r = !0);
|
|
91
|
+
return r ? e : t;
|
|
89
92
|
});
|
|
90
93
|
}, [a]);
|
|
91
|
-
const
|
|
92
|
-
const
|
|
94
|
+
const L = R(() => {
|
|
95
|
+
const t = Date.now() - T, e = Array.from(f.current.values()).some(
|
|
93
96
|
(i) => !i.isCompleted
|
|
94
|
-
),
|
|
95
|
-
g(
|
|
96
|
-
}, [
|
|
97
|
+
), r = t > 1e3 && !e;
|
|
98
|
+
g(r);
|
|
99
|
+
}, [T]);
|
|
97
100
|
w(() => {
|
|
98
101
|
if (!a) {
|
|
99
102
|
g(!1);
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
|
-
if (!(
|
|
105
|
+
if (!(p.length > 0)) {
|
|
103
106
|
g(!1);
|
|
104
107
|
return;
|
|
105
108
|
}
|
|
106
|
-
const
|
|
107
|
-
return () => clearInterval(
|
|
108
|
-
}, [a,
|
|
109
|
-
const
|
|
109
|
+
const e = setInterval(L, 200);
|
|
110
|
+
return () => clearInterval(e);
|
|
111
|
+
}, [a, L, p.length]);
|
|
112
|
+
const E = z(() => !!(!(p.length > 0) && a), [p.length, a]);
|
|
110
113
|
return {
|
|
111
|
-
processedParts:
|
|
112
|
-
summaryTimings:
|
|
113
|
-
shouldShowInitialLoading:
|
|
114
|
-
shouldShowStreamDelayLoading:
|
|
114
|
+
processedParts: p,
|
|
115
|
+
summaryTimings: d,
|
|
116
|
+
shouldShowInitialLoading: E,
|
|
117
|
+
shouldShowStreamDelayLoading: P
|
|
115
118
|
};
|
|
116
119
|
}
|
|
117
120
|
export {
|
|
118
|
-
|
|
121
|
+
K as useStreamProcessor
|
|
119
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.15.9",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
|
|
@@ -5,7 +5,7 @@ import { useInkeepConfig as g } from "./config-provider.js";
|
|
|
5
5
|
const a = d(void 0), P = ({ children: e }) => {
|
|
6
6
|
const { baseSettings: t, componentType: o } = g(), { tags: s, analyticsProperties: n } = t, r = u(
|
|
7
7
|
() => ({
|
|
8
|
-
widgetLibraryVersion: "0.15.
|
|
8
|
+
widgetLibraryVersion: "0.15.9",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("lucide-react"),r=require("../../primitives/components/data-summaries.cjs"),p=t=>{const{type:n,label:s}=t;return s||n.replace(/_/g," ").replace(/\b\w/g,i=>i.toUpperCase())},u={agent_generate:e.jsx(a.RefreshCw,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),agent_reasoning:e.jsx(a.Brain,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),tool_call:e.jsx(a.Hammer,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),tool_result:e.jsx(a.Hammer,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),transfer:e.jsx(a.ArrowRight,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),delegation_sent:e.jsx(a.Forward,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),delegation_returned:e.jsx(a.CheckCheck,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),artifact_saved:e.jsx(a.Download,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),error:e.jsx(a.TriangleAlert,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),agent_initializing:e.jsx(a.CircleDot,{className:"w-3 h-3 animate-spin"}),completion:e.jsx(a.CheckCheck,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),default:e.jsx(a.Dot,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"})},h={retrieve:e.jsx(a.Search,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),action:e.jsx(a.CheckCheck,{className:"w-3 h-3 text-gray-500 dark:text-white-alpha-500"}),...u},m=o.memo(({summary:t,showConnector:n})=>{const s=o.useMemo(()=>t.details&&Object.keys(t.details).length>0?JSON.stringify(t.details,null,2):null,[t.details]),i=o.useMemo(()=>p(t),[t]),c=o.useMemo(()=>h[t.type]||h.default,[t.type]);return e.jsxs(r.DataSummaryItem,{className:"flex items-start gap-2 text-xs relative",children:[n&&e.jsx(r.DataSummaryConnector,{className:"absolute left-1.5 top-4 bottom-0 w-px bg-gray-200 dark:bg-white-alpha-200 -mb-3"}),e.jsx(r.DataSummaryIconContainer,{className:"flex items-center justify-center w-3 h-3 relative z-10 mt-0.5",children:c}),e.jsxs(r.DataSummaryContent,{className:"flex-1",children:[e.jsx(r.DataSummaryLabel,{className:"text-gray-700 dark:text-white-alpha-600",children:i}),s&&e.jsx(r.DataSummaryDetails,{className:"mt-2 text-xs whitespace-pre-wrap font-mono bg-gray-50 dark:bg-gray-dark-900 p-2 rounded-md px-3 py-2",children:s})]})]})}),g=o.memo(({summaries:t,isCompleted:n})=>{const s=t.length>1,[i,c]=o.useState(!n||!s);o.useEffect(()=>{let l;return n&&s?l=setTimeout(()=>{c(!1)},1e3):c(!0),()=>{l&&clearTimeout(l)}},[n,s]);const d=o.useCallback(()=>{s&&c(!i)},[s,i]);return s?e.jsxs(r.DataSummaryGroup,{className:"flex flex-col items-start mb-2.5 mt-2.5 first:mt-1 relative",children:[e.jsx(r.DataSummaryToggle,{type:"button",onClick:d,"data-expanded":i,className:"inline-flex items-center group gap-2 text-xs text-gray-500 dark:text-white-alpha-600 hover:text-gray-700 dark:hover:text-white-alpha-700 transition-colors cursor-pointer",children:n?e.jsxs(e.Fragment,{children:[e.jsx(a.Check,{className:"check-icon w-3 h-3 text-gray-500 dark:text-white-alpha-500 transition-all duration-200 absolute opacity-100 group-hover:opacity-0 group-data-[expanded=true]:opacity-0"}),e.jsx(a.ChevronRight,{className:"chevron-icon w-3 h-3 text-gray-500 dark:text-white-alpha-500 transition-all duration-200 transform opacity-0 rotate-0 group-hover:opacity-100 group-data-[expanded=true]:opacity-100 group-data-[expanded=true]:rotate-90"}),e.jsx(r.DataSummaryToggleText,{className:"font-medium",children:"Completed"})]}):e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"w-3 h-3 animate-spin"}),e.jsx(r.DataSummaryToggleText,{className:"font-medium",children:"Thinking..."})]})}),e.jsx(r.DataSummaryCollapsible,{"data-expanded":i,className:"overflow-hidden transition-all duration-300 ease-in-out data-[expanded=true]:opacity-100 data-[expanded=false]:max-h-0 data-[expanded=false]:opacity-0 max-w-full",children:e.jsx(r.DataSummaryList,{className:"pb-2 mt-1.5 space-y-3 relative",children:t.map((l,x)=>e.jsx(m,{summary:l,showConnector:t.length>1&&x<t.length-1},`op-${l.type}-${x}`))})})]}):e.jsx(r.DataSummaryGroup,{className:"flex flex-col items-start mb-2.5 mt-2.5 first:mt-1 relative",children:e.jsx(r.DataSummaryList,{className:"pb-2 mt-1.5 space-y-3 relative",children:t.map((l,x)=>e.jsx(m,{summary:l,showConnector:!1},`op-${l.type}-${x}`))})})});exports.DataSummaryGroup=g;
|