@inkeep/agents-ui 0.14.10 → 0.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +71 -68
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +110 -57
- package/dist/primitives/components/embedded-search/use-search-filter.cjs +1 -1
- package/dist/primitives/components/embedded-search/use-search-filter.js +1 -1
- package/dist/primitives/hooks/use-streaming-events.cjs +1 -0
- package/dist/primitives/hooks/use-streaming-events.js +140 -0
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +123 -120
- package/dist/styled/components/data-summary-group.cjs +1 -1
- package/dist/styled/components/data-summary-group.js +44 -34
- package/dist/styled/components/embedded-search.cjs +1 -1
- package/dist/styled/components/embedded-search.js +1 -1
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +39 -39
- package/dist/styled/inkeep.css.cjs +2 -9
- package/dist/styled/inkeep.css.js +2 -9
- package/dist/types/types.d.cts +5 -3
- package/dist/types/types.d.ts +5 -3
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1225,8 +1225,20 @@ export declare const dataAttr: (guard: boolean | undefined) => Booleanish;
|
|
|
1225
1225
|
|
|
1226
1226
|
declare type DataParts = {
|
|
1227
1227
|
operation: {
|
|
1228
|
-
type:
|
|
1228
|
+
type:
|
|
1229
|
+
| 'error'
|
|
1230
|
+
| 'agent_initializing'
|
|
1231
|
+
| 'completion'
|
|
1232
|
+
| 'agent_generate'
|
|
1233
|
+
| 'agent_reasoning'
|
|
1234
|
+
| 'tool_execution'
|
|
1235
|
+
| 'transfer'
|
|
1236
|
+
| 'delegation_sent'
|
|
1237
|
+
| 'delegation_returned'
|
|
1238
|
+
| 'artifact_saved'
|
|
1229
1239
|
ctx: Record<string, unknown>
|
|
1240
|
+
message?: string
|
|
1241
|
+
label?: string
|
|
1230
1242
|
}
|
|
1231
1243
|
summary: {
|
|
1232
1244
|
type: string
|
|
@@ -4908,6 +4920,7 @@ declare const useInkeepChat: () => {
|
|
|
4908
4920
|
isLoading: boolean;
|
|
4909
4921
|
isStreaming: boolean;
|
|
4910
4922
|
error: Error | null;
|
|
4923
|
+
setError: Dispatch<SetStateAction<Error | null>>;
|
|
4911
4924
|
isSubmitDisabled: boolean;
|
|
4912
4925
|
input: string;
|
|
4913
4926
|
handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1225,8 +1225,20 @@ export declare const dataAttr: (guard: boolean | undefined) => Booleanish;
|
|
|
1225
1225
|
|
|
1226
1226
|
declare type DataParts = {
|
|
1227
1227
|
operation: {
|
|
1228
|
-
type:
|
|
1228
|
+
type:
|
|
1229
|
+
| 'error'
|
|
1230
|
+
| 'agent_initializing'
|
|
1231
|
+
| 'completion'
|
|
1232
|
+
| 'agent_generate'
|
|
1233
|
+
| 'agent_reasoning'
|
|
1234
|
+
| 'tool_execution'
|
|
1235
|
+
| 'transfer'
|
|
1236
|
+
| 'delegation_sent'
|
|
1237
|
+
| 'delegation_returned'
|
|
1238
|
+
| 'artifact_saved'
|
|
1229
1239
|
ctx: Record<string, unknown>
|
|
1240
|
+
message?: string
|
|
1241
|
+
label?: string
|
|
1230
1242
|
}
|
|
1231
1243
|
summary: {
|
|
1232
1244
|
type: string
|
|
@@ -4908,6 +4920,7 @@ declare const useInkeepChat: () => {
|
|
|
4908
4920
|
isLoading: boolean;
|
|
4909
4921
|
isStreaming: boolean;
|
|
4910
4922
|
error: Error | null;
|
|
4923
|
+
setError: Dispatch<SetStateAction<Error | null>>;
|
|
4911
4924
|
isSubmitDisabled: boolean;
|
|
4912
4925
|
input: string;
|
|
4913
4926
|
handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
@@ -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 X=require("@ai-sdk/react"),Y=require("ai"),t=require("react"),Z=require("../../providers/config-provider.cjs"),ee=require("../../hooks/use-media-query.cjs"),te=require("../../utils/generate-uid.cjs"),se=require("../../providers/base-events-provider.cjs"),ne=require("../../providers/chat-form-provider.cjs"),re=require("../../providers/widget-provider.cjs"),ae=require("@radix-ui/react-use-controllable-state"),oe=require("../../hooks/use-streaming-events.cjs"),q=`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.`,ie=()=>{const{baseSettings:f,aiChatSettings:o}=Z.useInkeepConfig(),[n="",v]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:F,emitStreamError:R}=oe.useStreamingEvents(),[a,u]=t.useState(""),k=e=>u(e.target.value),{filters:S}=f,{onInputMessageChange:A,filters:E,agentUrl:P,context:x,headers:D,apiKey:C}=o,N=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return q}},[U,T]=t.useState({}),[B,l]=t.useState([]),[O,I]=t.useState(null),{messages:g,sendMessage:K,status:b,setMessages:y,stop:L,error:d}=X.useChat({transport:new Y.DefaultChatTransport({api:P,headers:{...C?{Authorization:`Bearer ${C}`}:{},...D},body:{requestContext:x}}),async onFinish(){await i({eventName:"assistant_message_received",properties:{conversationId:n}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.log("onError",e.message),R(e.message,void 0,e.code?.toString()),y(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:N(e)}]),r})}}),w=b==="submitted",W=b==="streaming",$=g.length===0,m=!a.trim()||w,z=ee.useMediaQuery("(max-width: 768px)"),[G,p]=t.useState(null);t.useEffect(()=>{d&&p(d)},[d]);const H=()=>p(null),M=t.useRef(null);t.useEffect(()=>{A?.(a)},[a]);const Q=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),h())},h=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=S||E?JSON.stringify({...S,...E}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${te.generateUid(16)}`,v(s)),F(s),K({text:e},{headers:r,body:{conversationId:s}})},j=()=>{L()},_=()=>{H(),y([]),v(""),T({}),l([]),I(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:J}=ne.useChatForm(),V=re.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:h,updateInputMessage(e){u(e)},clearChat:_,openForm:e=>{V?.setView("chat"),J(e,void 0)},focusInput:()=>{M.current?.focus()}})),{messages:g,isLoading:w,isStreaming:W,error:G,setError:p,isSubmitDisabled:m,input:a,handleInputChange:k,handleInputKeyDown:Q,handleSubmit:h,stop:j,clear:_,messageButtons:U,isEmpty:g.length===0,inputRef:M,isMobile:z,messageAttachments:B,setMessageAttachments:l,selectedWorkflow:O,setSelectedWorkflow:I,isNewChat:$,conversationId:n}};exports.DEFAULT_ERROR_MESSAGE=q;exports.useInkeepChat=ie;
|
|
@@ -1,58 +1,59 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { DefaultChatTransport as
|
|
4
|
-
import { useState as r, useEffect as x, useRef 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
|
-
|
|
13
|
-
|
|
2
|
+
import { useChat as X } from "@ai-sdk/react";
|
|
3
|
+
import { DefaultChatTransport as Y } from "ai";
|
|
4
|
+
import { useState as r, useEffect as x, useRef as Z, useImperativeHandle as ee } from "react";
|
|
5
|
+
import { useInkeepConfig as te } from "../../providers/config-provider.js";
|
|
6
|
+
import { useMediaQuery as se } from "../../hooks/use-media-query.js";
|
|
7
|
+
import { generateUid as ne } from "../../utils/generate-uid.js";
|
|
8
|
+
import { useBaseEvents as oe } from "../../providers/base-events-provider.js";
|
|
9
|
+
import { useChatForm as re } from "../../providers/chat-form-provider.js";
|
|
10
|
+
import { useWidget as ae } from "../../providers/widget-provider.js";
|
|
11
|
+
import { useControllableState as ie } from "@radix-ui/react-use-controllable-state";
|
|
12
|
+
import { useStreamingEvents as ce } from "../../hooks/use-streaming-events.js";
|
|
13
|
+
const me = `Hmm..
|
|
14
|
+
|
|
15
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`, Se = () => {
|
|
16
|
+
const { baseSettings: f, aiChatSettings: a } = te(), [s = "", v] = ie({
|
|
14
17
|
prop: a.conversationId,
|
|
15
18
|
defaultProp: a.conversationId ?? ""
|
|
16
|
-
}), { logEvent: i } =
|
|
19
|
+
}), { logEvent: i } = oe(), { setConversationId: F, emitStreamError: k } = ce(), [o, m] = r(""), N = (e) => m(e.target.value), {
|
|
17
20
|
/* shouldBypassCaptcha, */
|
|
18
|
-
filters:
|
|
19
|
-
} =
|
|
20
|
-
onInputMessageChange:
|
|
21
|
-
filters:
|
|
22
|
-
|
|
23
|
-
context:
|
|
24
|
-
headers:
|
|
25
|
-
apiKey:
|
|
26
|
-
} = a,
|
|
21
|
+
filters: I
|
|
22
|
+
} = f, {
|
|
23
|
+
onInputMessageChange: A,
|
|
24
|
+
filters: C,
|
|
25
|
+
agentUrl: D,
|
|
26
|
+
context: R,
|
|
27
|
+
headers: B,
|
|
28
|
+
apiKey: E
|
|
29
|
+
} = a, K = (e) => {
|
|
27
30
|
switch (e.code) {
|
|
28
31
|
case 400:
|
|
29
32
|
return e.message;
|
|
30
33
|
case 403:
|
|
31
|
-
return `There seems to be a configuration error. Please contact ${
|
|
34
|
+
return `There seems to be a configuration error. Please contact ${f.organizationDisplayName ?? "Administrator"}`;
|
|
32
35
|
default:
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`;
|
|
36
|
+
return me;
|
|
36
37
|
}
|
|
37
|
-
}, [
|
|
38
|
+
}, [P, T] = r({}), [U, u] = r([]), [W, S] = r(null), {
|
|
38
39
|
messages: l,
|
|
39
40
|
sendMessage: $,
|
|
40
|
-
status:
|
|
41
|
-
setMessages:
|
|
41
|
+
status: b,
|
|
42
|
+
setMessages: y,
|
|
42
43
|
stop: z,
|
|
43
44
|
error: p
|
|
44
|
-
} =
|
|
45
|
-
transport: new
|
|
46
|
-
api:
|
|
45
|
+
} = X({
|
|
46
|
+
transport: new Y({
|
|
47
|
+
api: D,
|
|
47
48
|
headers: {
|
|
48
|
-
...
|
|
49
|
-
...
|
|
49
|
+
...E ? { Authorization: `Bearer ${E}` } : {},
|
|
50
|
+
...B
|
|
50
51
|
},
|
|
51
52
|
body: {
|
|
52
|
-
requestContext:
|
|
53
|
+
requestContext: R
|
|
53
54
|
}
|
|
54
55
|
}),
|
|
55
|
-
async onFinish(
|
|
56
|
+
async onFinish() {
|
|
56
57
|
await i({
|
|
57
58
|
eventName: "assistant_message_received",
|
|
58
59
|
properties: {
|
|
@@ -66,22 +67,22 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
66
67
|
});
|
|
67
68
|
},
|
|
68
69
|
onError(e) {
|
|
69
|
-
console.log("onError", e.message),
|
|
70
|
+
console.log("onError", e.message), k(e.message, void 0, e.code?.toString()), y((c) => {
|
|
70
71
|
const n = [...c], t = n[n.length - 1];
|
|
71
|
-
return t && (t.parts = [{ type: "text", text:
|
|
72
|
+
return t && (t.parts = [{ type: "text", text: K(e) }]), n;
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
|
-
}),
|
|
75
|
+
}), w = b === "submitted", H = b === "streaming", L = l.length === 0, g = !o.trim() || w, O = se("(max-width: 768px)"), [q, d] = r(null);
|
|
75
76
|
x(() => {
|
|
76
|
-
p &&
|
|
77
|
+
p && d(p);
|
|
77
78
|
}, [p]);
|
|
78
|
-
const
|
|
79
|
+
const G = () => d(null), M = Z(null);
|
|
79
80
|
x(() => {
|
|
80
|
-
|
|
81
|
+
A?.(o);
|
|
81
82
|
}, [o]);
|
|
82
|
-
const
|
|
83
|
-
e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(),
|
|
84
|
-
},
|
|
83
|
+
const J = (e) => {
|
|
84
|
+
e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), h());
|
|
85
|
+
}, h = async (e = o) => {
|
|
85
86
|
if (g && (!e || e.trim().length === 0)) return;
|
|
86
87
|
u([]), m(""), await i({
|
|
87
88
|
eventName: "user_message_submitted",
|
|
@@ -89,13 +90,13 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
89
90
|
conversationId: s
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
|
-
const c =
|
|
93
|
-
...
|
|
94
|
-
...
|
|
93
|
+
const c = I || C ? JSON.stringify({
|
|
94
|
+
...I,
|
|
95
|
+
...C
|
|
95
96
|
}) : void 0, n = {};
|
|
96
97
|
c && (n["inkeep-filters"] = c);
|
|
97
98
|
let t = s;
|
|
98
|
-
t || (t = `conv_${
|
|
99
|
+
t || (t = `conv_${ne(16)}`, v(t)), F(t), $(
|
|
99
100
|
// { ...userMessage, files },
|
|
100
101
|
// { ...userMessage, },
|
|
101
102
|
{
|
|
@@ -108,53 +109,55 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
);
|
|
111
|
-
},
|
|
112
|
+
}, Q = () => {
|
|
112
113
|
z();
|
|
113
114
|
}, _ = () => {
|
|
114
|
-
|
|
115
|
+
G(), y([]), v(""), T({}), u([]), S(null), i({
|
|
115
116
|
eventName: "chat_clear_button_clicked",
|
|
116
117
|
properties: {
|
|
117
118
|
conversationId: s
|
|
118
119
|
}
|
|
119
120
|
});
|
|
120
|
-
}, { openForm:
|
|
121
|
-
return
|
|
122
|
-
submitMessage:
|
|
121
|
+
}, { openForm: V } = re(), j = ae();
|
|
122
|
+
return ee(a.chatFunctionsRef, () => ({
|
|
123
|
+
submitMessage: h,
|
|
123
124
|
updateInputMessage(e) {
|
|
124
125
|
m(e);
|
|
125
126
|
},
|
|
126
127
|
clearChat: _,
|
|
127
128
|
openForm: (e) => {
|
|
128
|
-
|
|
129
|
+
j?.setView("chat"), V(e, void 0);
|
|
129
130
|
},
|
|
130
131
|
focusInput: () => {
|
|
131
|
-
|
|
132
|
+
M.current?.focus();
|
|
132
133
|
}
|
|
133
134
|
})), {
|
|
134
135
|
messages: l,
|
|
135
|
-
isLoading:
|
|
136
|
+
isLoading: w,
|
|
136
137
|
isStreaming: H,
|
|
137
138
|
error: q,
|
|
139
|
+
setError: d,
|
|
138
140
|
isSubmitDisabled: g,
|
|
139
141
|
input: o,
|
|
140
|
-
handleInputChange:
|
|
141
|
-
handleInputKeyDown:
|
|
142
|
-
handleSubmit:
|
|
143
|
-
stop:
|
|
142
|
+
handleInputChange: N,
|
|
143
|
+
handleInputKeyDown: J,
|
|
144
|
+
handleSubmit: h,
|
|
145
|
+
stop: Q,
|
|
144
146
|
clear: _,
|
|
145
|
-
messageButtons:
|
|
147
|
+
messageButtons: P,
|
|
146
148
|
isEmpty: l.length === 0,
|
|
147
|
-
inputRef:
|
|
148
|
-
isMobile:
|
|
149
|
+
inputRef: M,
|
|
150
|
+
isMobile: O,
|
|
149
151
|
// Additional state for attachments and workflow
|
|
150
|
-
messageAttachments:
|
|
152
|
+
messageAttachments: U,
|
|
151
153
|
setMessageAttachments: u,
|
|
152
154
|
selectedWorkflow: W,
|
|
153
|
-
setSelectedWorkflow:
|
|
154
|
-
isNewChat:
|
|
155
|
+
setSelectedWorkflow: S,
|
|
156
|
+
isNewChat: L,
|
|
155
157
|
conversationId: s
|
|
156
158
|
};
|
|
157
159
|
};
|
|
158
160
|
export {
|
|
159
|
-
|
|
161
|
+
me as DEFAULT_ERROR_MESSAGE,
|
|
162
|
+
Se as useInkeepChat
|
|
160
163
|
};
|
|
@@ -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"),M=require("./use-inkeep-chat.cjs"),_=require("../../hooks/use-streaming-events.cjs"),q=require("../../../types/message.cjs");function z(u,l,g){const[m,D]=r.useState([]),[d,E]=r.useState(new Map),[y,I]=r.useState(Date.now()),[P,h]=r.useState(!1),w=r.useRef(0),S=r.useRef(0),x=r.useRef([]),f=r.useRef(d);f.current=d;const{emitArtifactSaved:k,emitCompletion:C,emitAgentInitializing:T,emitTextDelta:A}=_.useStreamingEvents(),R=r.useCallback(()=>{const n=[];let e="",o=[],c=!1;u.length>w.current&&(I(Date.now()),w.current=u.length),S.current=0;const p=new Map,i=(t=!1)=>{if(o.length>0){const s=`group-${S.current++}`,a=f.current.get(s);a?p.set(s,{...a,isCompleted:t}):p.set(s,{isCompleted:t}),n.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const t of u)if(t.type==="text")i(!0),t.text&&l&&A(t.text),e+=t.text||"";else if(t.type==="data-summary")e.trim()&&(n.push({type:"text",text:e}),e=""),o.push(t.data);else if(t.type==="data-operation"){e.trim()&&(n.push({type:"text",text:e}),e="");const s=t.data;if(s?.type)switch(s.type){case"completion":C("unknown",1),i(!0);break;case"agent_initializing":T("unknown","unknown");break;case"error":{i(!0);const a=s.message||"Unknown error";console.warn("Data operation error:",a),g(new Error(a)),c||(n.push({type:"text",text:M.DEFAULT_ERROR_MESSAGE}),c=!0);break}default:{const{type:a,label:L}=s;o.push({type:a,label:L});break}}}else if(t.type==="data-artifact")if(t.data?.type?.toLowerCase()===q.CITATION_ARTIFACT_TYPE){const s=t.data,a=s.artifactSummary||{title:s.name};e+=` ^${a?.title||s.name}^`}else e.trim()&&(n.push({type:"text",text:e}),e=""),n.push(t),t.data&&k(t.data.artifactId||"unknown",t.data.taskId||"unknown","unknown",t.data.artifactType||"unknown",t.data.artifactSummary||{},{},{name:t.data.name,description:t.data.description});else t.type==="data-component"&&(e.trim()&&(n.push({type:"text",text:e}),e=""),i(!0),n.push(t));return i(!l),e.trim()&&n.push({type:"text",text:e}),{processed:n,newTimings:p}},[u,l,k,C,T,A,g]);r.useEffect(()=>{if(x.current===u)return;x.current=u;const{processed:n,newTimings:e}=R();D(n),(e.size!==f.current.size||Array.from(e.entries()).some(([c,p])=>{const i=f.current.get(c);return!i||i.isCompleted!==p.isCompleted}))&&E(e)},[R,u]);const v=r.useCallback(()=>{const n=Date.now()-y,e=Array.from(f.current.values()).some(c=>!c.isCompleted),o=n>1e3&&!e;h(o)},[y]);r.useEffect(()=>{if(!l){h(!1);return}if(!(m.length>0)){h(!1);return}const e=setInterval(v,200);return()=>clearInterval(e)},[l,v,m.length]);const b=r.useMemo(()=>!(m.length>0),[m.length]);return{processedParts:m,summaryTimings:d,shouldShowInitialLoading:b,shouldShowStreamDelayLoading:P}}exports.useStreamProcessor=z;
|
|
@@ -1,82 +1,135 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { useState as p, useRef as d, useCallback as R, useEffect as E, useMemo as F } from "react";
|
|
3
|
+
import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
|
|
4
|
+
import { useStreamingEvents as O } from "../../hooks/use-streaming-events.js";
|
|
5
|
+
import { CITATION_ARTIFACT_TYPE as U } from "../../../types/message.js";
|
|
6
|
+
function j(i, u, g) {
|
|
7
|
+
const [m, L] = p([]), [h, P] = p(/* @__PURE__ */ new Map()), [w, b] = p(Date.now()), [M, y] = p(!1), x = d(0), k = d(0), S = d([]), f = d(h);
|
|
8
|
+
f.current = h;
|
|
9
|
+
const { emitArtifactSaved: T, emitCompletion: C, emitAgentInitializing: A, emitTextDelta: D } = O(), v = R(() => {
|
|
10
|
+
const n = [];
|
|
11
|
+
let t = "", s = [], c = !1;
|
|
12
|
+
i.length > x.current && (b(Date.now()), x.current = i.length), k.current = 0;
|
|
13
|
+
const l = /* @__PURE__ */ new Map(), o = (e = !1) => {
|
|
14
|
+
if (s.length > 0) {
|
|
15
|
+
const r = `group-${k.current++}`, a = f.current.get(r);
|
|
16
|
+
a ? l.set(r, {
|
|
17
|
+
...a,
|
|
16
18
|
isCompleted: e
|
|
17
|
-
}) :
|
|
19
|
+
}) : l.set(r, {
|
|
18
20
|
isCompleted: e
|
|
19
|
-
}),
|
|
21
|
+
}), n.push({
|
|
20
22
|
type: "summary-group",
|
|
21
|
-
summaries: [...
|
|
22
|
-
groupKey:
|
|
23
|
-
}),
|
|
23
|
+
summaries: [...s],
|
|
24
|
+
groupKey: r
|
|
25
|
+
}), s = [];
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
|
-
for (const e of
|
|
28
|
+
for (const e of i)
|
|
27
29
|
if (e.type === "text")
|
|
28
|
-
|
|
30
|
+
o(!0), e.text && u && D(e.text), t += e.text || "";
|
|
29
31
|
else if (e.type === "data-summary")
|
|
30
|
-
t.trim() && (
|
|
31
|
-
else if (e.type === "data-operation")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
t.trim() && (n.push({ type: "text", text: t }), t = ""), s.push(e.data);
|
|
33
|
+
else if (e.type === "data-operation") {
|
|
34
|
+
t.trim() && (n.push({ type: "text", text: t }), t = "");
|
|
35
|
+
const r = e.data;
|
|
36
|
+
if (r?.type)
|
|
37
|
+
switch (r.type) {
|
|
38
|
+
case "completion":
|
|
39
|
+
C(
|
|
40
|
+
"unknown",
|
|
41
|
+
// No agent ID available in current structure
|
|
42
|
+
1
|
|
43
|
+
// No iteration available in current structure
|
|
44
|
+
), o(!0);
|
|
45
|
+
break;
|
|
46
|
+
case "agent_initializing":
|
|
47
|
+
A(
|
|
48
|
+
"unknown",
|
|
49
|
+
// No session ID available in current structure
|
|
50
|
+
"unknown"
|
|
51
|
+
// No graph ID available in current structure
|
|
52
|
+
);
|
|
53
|
+
break;
|
|
54
|
+
case "error": {
|
|
55
|
+
o(!0);
|
|
56
|
+
const a = r.message || "Unknown error";
|
|
57
|
+
console.warn("Data operation error:", a), g(new Error(a)), c || (n.push({ type: "text", text: G }), c = !0);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
default: {
|
|
61
|
+
const { type: a, label: z } = r;
|
|
62
|
+
s.push({ type: a, label: z });
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else if (e.type === "data-artifact")
|
|
67
|
+
if (e.data?.type?.toLowerCase() === U) {
|
|
68
|
+
const r = e.data, a = r.artifactSummary || {
|
|
69
|
+
title: r.name
|
|
37
70
|
};
|
|
38
|
-
t += ` ^${
|
|
71
|
+
t += ` ^${a?.title || r.name}^`;
|
|
39
72
|
} else
|
|
40
|
-
t.trim() && (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
t.trim() && (n.push({ type: "text", text: t }), t = ""), n.push(e), e.data && T(
|
|
74
|
+
e.data.artifactId || "unknown",
|
|
75
|
+
e.data.taskId || "unknown",
|
|
76
|
+
"unknown",
|
|
77
|
+
// toolCallId not available in current structure
|
|
78
|
+
e.data.artifactType || "unknown",
|
|
79
|
+
e.data.artifactSummary || {},
|
|
80
|
+
// Use artifactSummary as summaryData
|
|
81
|
+
{},
|
|
82
|
+
// fullData not available in current structure
|
|
83
|
+
{ name: e.data.name, description: e.data.description }
|
|
84
|
+
// Use available fields as metadata
|
|
85
|
+
);
|
|
86
|
+
else e.type === "data-component" && (t.trim() && (n.push({ type: "text", text: t }), t = ""), o(!0), n.push(e));
|
|
87
|
+
return o(!u), t.trim() && n.push({ type: "text", text: t }), { processed: n, newTimings: l };
|
|
88
|
+
}, [
|
|
89
|
+
i,
|
|
90
|
+
u,
|
|
91
|
+
T,
|
|
92
|
+
C,
|
|
93
|
+
A,
|
|
94
|
+
D,
|
|
95
|
+
g
|
|
96
|
+
]);
|
|
97
|
+
E(() => {
|
|
98
|
+
if (S.current === i)
|
|
46
99
|
return;
|
|
47
|
-
|
|
48
|
-
const { processed:
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
return !
|
|
100
|
+
S.current = i;
|
|
101
|
+
const { processed: n, newTimings: t } = v();
|
|
102
|
+
L(n), (t.size !== f.current.size || Array.from(t.entries()).some(([c, l]) => {
|
|
103
|
+
const o = f.current.get(c);
|
|
104
|
+
return !o || o.isCompleted !== l.isCompleted;
|
|
52
105
|
})) && P(t);
|
|
53
|
-
}, [
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
(
|
|
57
|
-
),
|
|
58
|
-
y(
|
|
59
|
-
}, [
|
|
60
|
-
|
|
61
|
-
if (!
|
|
106
|
+
}, [v, i]);
|
|
107
|
+
const I = R(() => {
|
|
108
|
+
const n = Date.now() - w, t = Array.from(f.current.values()).some(
|
|
109
|
+
(c) => !c.isCompleted
|
|
110
|
+
), s = n > 1e3 && !t;
|
|
111
|
+
y(s);
|
|
112
|
+
}, [w]);
|
|
113
|
+
E(() => {
|
|
114
|
+
if (!u) {
|
|
62
115
|
y(!1);
|
|
63
116
|
return;
|
|
64
117
|
}
|
|
65
|
-
if (!(
|
|
118
|
+
if (!(m.length > 0)) {
|
|
66
119
|
y(!1);
|
|
67
120
|
return;
|
|
68
121
|
}
|
|
69
|
-
const t = setInterval(
|
|
122
|
+
const t = setInterval(I, 200);
|
|
70
123
|
return () => clearInterval(t);
|
|
71
|
-
}, [
|
|
72
|
-
const
|
|
124
|
+
}, [u, I, m.length]);
|
|
125
|
+
const _ = F(() => !(m.length > 0), [m.length]);
|
|
73
126
|
return {
|
|
74
|
-
processedParts:
|
|
127
|
+
processedParts: m,
|
|
75
128
|
summaryTimings: h,
|
|
76
|
-
shouldShowInitialLoading:
|
|
77
|
-
shouldShowStreamDelayLoading:
|
|
129
|
+
shouldShowInitialLoading: _,
|
|
130
|
+
shouldShowStreamDelayLoading: M
|
|
78
131
|
};
|
|
79
132
|
}
|
|
80
133
|
export {
|
|
81
|
-
|
|
134
|
+
j as useStreamProcessor
|
|
82
135
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),T=require("../../atoms/cmdk/index.cjs"),C=require("../../providers/search-events-provider.cjs"),E=require("../../providers/config-provider.cjs"),_=require("./search-provider.cjs"),k=
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),T=require("../../atoms/cmdk/index.cjs"),C=require("../../providers/search-events-provider.cjs"),E=require("../../providers/config-provider.cjs"),_=require("./search-provider.cjs"),k=250,P=()=>{const{setResultsList:t,setLoading:n,showSearchResults:i,setShowSearchResults:h}=_.useSearch(),{searchSettings:p}=E.useInkeepConfig(),{debounceTimeMs:b,onQueryChange:w,onSearch:f}=p,{logEvent:u}=C.useSearchEvents(),a=r.useRef({}),S=r.useRef(null),d=r.useRef(null),v=r.useCallback(async e=>{if(!f){console.warn("No search implementation provided. Please provide onSearch callback in searchSettings."),t([]);return}const s=new AbortController;S.current=s;try{n(!0);const o=await f(e,s.signal);a.current[e]=o,t(o)}catch(o){if(o.name==="AbortError")return;console.error("Search implementation failed:",o),t([])}finally{n(!1)}},[f,n,t]),R=r.useCallback(e=>{const s=a.current[e];u({eventName:"search_query_response_received",properties:{searchQuery:e,totalResults:s?.length}})},[u]),m=r.useCallback(()=>{S.current&&(S.current.abort(),n(!1))},[n]),g=r.useCallback(e=>{if(d.current&&window.clearTimeout(d.current),!e){m(),t([]);return}d.current=window.setTimeout(()=>{m(),u({eventName:"search_query_submitted",properties:{searchQuery:e}}),a.current[e]?(t(a.current[e]),R(e)):v(e).then(()=>{R(e)})},b)},[b,v,R,m,u,t]),c=T.useCommandState(e=>e.search),l=r.useRef(null);r.useEffect(()=>{const e=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},s=!!c;return s&&!i?(e(),l.current=window.setTimeout(()=>{h(!0)},k)):!s&&i&&(e(),h(!1)),e},[c,i,h]),r.useEffect(()=>{w?.(c),g(c)},[g,c,w])};exports.useSearchFetch=P;
|
|
@@ -4,7 +4,7 @@ import { useCommandState as _ } from "../../atoms/cmdk/index.js";
|
|
|
4
4
|
import { useSearchEvents as E } from "../../providers/search-events-provider.js";
|
|
5
5
|
import { useInkeepConfig as k } from "../../providers/config-provider.js";
|
|
6
6
|
import { useSearch as L } from "./search-provider.js";
|
|
7
|
-
const A =
|
|
7
|
+
const A = 250, O = () => {
|
|
8
8
|
const { setResultsList: t, setLoading: s, showSearchResults: h, setShowSearchResults: m } = L(), { searchSettings: C } = k(), { debounceTimeMs: w, onQueryChange: T, onSearch: f } = C, { logEvent: c } = E(), a = u({}), S = u(null), d = u(null), b = i(
|
|
9
9
|
async (e) => {
|
|
10
10
|
if (!f) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),p=require("../atoms/shadow/context.cjs");function x(){const c=p.useShadow()?.shadowHost,r=s.useRef(""),t=s.useCallback(e=>{if(!c){console.warn("useStreamingEvents: No host element available for event emission");return}const n={...e,conversationId:r.current,timestamp:Date.now()},a=new CustomEvent("streaming-event",{detail:n,bubbles:!0,composed:!0});c.dispatchEvent(a)},[c]),d=s.useCallback(e=>{r.current=e},[]),u=s.useCallback(e=>{t({kind:"text:delta",data:{text:e}})},[t]),m=s.useCallback((e,n,a)=>{t({kind:"stream:error",data:{message:e,agent:n,severity:"error",code:a}})},[t]),k=s.useCallback((e,n)=>{t({kind:"agent:reasoning",data:{agentId:e,parts:n}})},[t]),g=s.useCallback((e,n,a)=>{t({kind:"agent:generate",data:{agentId:e,parts:n,generationType:a}})},[t]),b=s.useCallback((e,n,a,o,i,l)=>{t({kind:"tool:execution",data:{agentId:e,toolName:n,args:a,result:o,toolId:i,duration:l}})},[t]),v=s.useCallback((e,n,a,o)=>{t({kind:"agent:transfer",data:{fromAgent:e,targetAgent:n,reason:a,context:o}})},[t]),C=s.useCallback((e,n,a,o,i)=>{t({kind:"delegation:sent",data:{delegationId:e,fromAgent:n,targetAgent:a,taskDescription:o,context:i}})},[t]),f=s.useCallback((e,n,a,o)=>{t({kind:"delegation:returned",data:{delegationId:e,fromAgent:n,targetAgent:a,result:o}})},[t]),E=s.useCallback((e,n,a,o,i,l,w)=>{t({kind:"artifact:saved",data:{artifactId:e,taskId:n,toolCallId:a,artifactType:o,summaryData:i,fullData:l,metadata:w}})},[t]),S=s.useCallback((e,n)=>{t({kind:"completion",data:{agent:e,iteration:n}})},[t]),h=s.useCallback((e,n)=>{t({kind:"agent:initializing",data:{sessionId:e,graphId:n}})},[t]);return{emitEvent:t,setConversationId:d,emitTextDelta:u,emitStreamError:m,emitAgentReasoning:k,emitAgentGenerate:g,emitToolExecution:b,emitAgentTransfer:v,emitDelegationSent:C,emitDelegationReturned:f,emitArtifactSaved:E,emitCompletion:S,emitAgentInitializing:h}}exports.useStreamingEvents=x;
|