@inkeep/agents-ui 0.14.10 → 0.14.11
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.js +55 -54
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +103 -64
- 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/package.json +1 -1
|
@@ -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 G=require("@ai-sdk/react"),X=require("ai"),t=require("react"),Y=require("../../providers/config-provider.cjs"),Z=require("../../hooks/use-media-query.cjs"),ee=require("../../utils/generate-uid.cjs"),te=require("../../providers/base-events-provider.cjs"),se=require("../../providers/chat-form-provider.cjs"),ne=require("../../providers/widget-provider.cjs"),re=require("@radix-ui/react-use-controllable-state"),ae=require("../../hooks/use-streaming-events.cjs"),oe=()=>{const{baseSettings:h,aiChatSettings:o}=Y.useInkeepConfig(),[n="",f]=re.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=te.useBaseEvents(),{setConversationId:_,emitStreamError:k}=ae.useStreamingEvents(),[a,u]=t.useState(""),F=e=>u(e.target.value),{filters:v}=h,{onInputMessageChange:P,filters:S,graphUrl:x,context:N,headers:D,apiKey:C}=o,A=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${h.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.`}},[
|
|
3
|
+
It seems I might be having some issues right now. Please clear the chat and try again.`}},[B,R]=t.useState({}),[U,l]=t.useState([]),[K,I]=t.useState(null),{messages:g,sendMessage:T,status:b,setMessages:y,stop:W,error:d}=G.useChat({transport:new X.DefaultChatTransport({api:x,headers:{...C?{Authorization:`Bearer ${C}`}:{},...D},body:{requestContext:N}}),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),k(e.message,void 0,e.code?.toString()),y(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:A(e)}]),r})}}),E=b==="submitted",$=b==="streaming",z=g.length===0,m=!a.trim()||E,H=Z.useMediaQuery("(max-width: 768px)"),[O,w]=t.useState(null);t.useEffect(()=>{d&&w(d)},[d]);const Q=()=>w(null),M=t.useRef(null);t.useEffect(()=>{P?.(a)},[a]);const j=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())},p=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=v||S?JSON.stringify({...v,...S}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${ee.generateUid(16)}`,f(s)),_(s),T({text:e},{headers:r,body:{conversationId:s}})},J=()=>{W()},q=()=>{Q(),y([]),f(""),R({}),l([]),I(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:L}=se.useChatForm(),V=ne.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:p,updateInputMessage(e){u(e)},clearChat:q,openForm:e=>{V?.setView("chat"),L(e,void 0)},focusInput:()=>{M.current?.focus()}})),{messages:g,isLoading:E,isStreaming:$,error:O,isSubmitDisabled:m,input:a,handleInputChange:F,handleInputKeyDown:j,handleSubmit:p,stop:J,clear:q,messageButtons:B,isEmpty:g.length===0,inputRef:M,isMobile:H,messageAttachments:U,setMessageAttachments:l,selectedWorkflow:K,setSelectedWorkflow:I,isNewChat:z,conversationId:n}};exports.useInkeepChat=oe;
|
|
@@ -1,29 +1,30 @@
|
|
|
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 be = () => {
|
|
14
|
+
const { baseSettings: h, aiChatSettings: a } = te(), [s = "", f] = ie({
|
|
14
15
|
prop: a.conversationId,
|
|
15
16
|
defaultProp: a.conversationId ?? ""
|
|
16
|
-
}), { logEvent: i } =
|
|
17
|
+
}), { logEvent: i } = oe(), { setConversationId: k, emitStreamError: F } = ce(), [o, m] = r(""), N = (e) => m(e.target.value), {
|
|
17
18
|
/* shouldBypassCaptcha, */
|
|
18
19
|
filters: v
|
|
19
20
|
} = h, {
|
|
20
|
-
onInputMessageChange:
|
|
21
|
+
onInputMessageChange: D,
|
|
21
22
|
filters: I,
|
|
22
|
-
graphUrl:
|
|
23
|
-
context:
|
|
24
|
-
headers:
|
|
23
|
+
graphUrl: A,
|
|
24
|
+
context: B,
|
|
25
|
+
headers: K,
|
|
25
26
|
apiKey: C
|
|
26
|
-
} = a,
|
|
27
|
+
} = a, P = (e) => {
|
|
27
28
|
switch (e.code) {
|
|
28
29
|
case 400:
|
|
29
30
|
return e.message;
|
|
@@ -34,25 +35,25 @@ const fe = () => {
|
|
|
34
35
|
|
|
35
36
|
It seems I might be having some issues right now. Please clear the chat and try again.`;
|
|
36
37
|
}
|
|
37
|
-
}, [
|
|
38
|
+
}, [R, W] = r({}), [$, u] = r([]), [z, b] = r(null), {
|
|
38
39
|
messages: l,
|
|
39
|
-
sendMessage:
|
|
40
|
+
sendMessage: H,
|
|
40
41
|
status: y,
|
|
41
42
|
setMessages: w,
|
|
42
|
-
stop:
|
|
43
|
+
stop: T,
|
|
43
44
|
error: p
|
|
44
|
-
} =
|
|
45
|
-
transport: new
|
|
46
|
-
api:
|
|
45
|
+
} = X({
|
|
46
|
+
transport: new Y({
|
|
47
|
+
api: A,
|
|
47
48
|
headers: {
|
|
48
49
|
...C ? { Authorization: `Bearer ${C}` } : {},
|
|
49
|
-
...
|
|
50
|
+
...K
|
|
50
51
|
},
|
|
51
52
|
body: {
|
|
52
|
-
requestContext:
|
|
53
|
+
requestContext: B
|
|
53
54
|
}
|
|
54
55
|
}),
|
|
55
|
-
async onFinish(
|
|
56
|
+
async onFinish() {
|
|
56
57
|
await i({
|
|
57
58
|
eventName: "assistant_message_received",
|
|
58
59
|
properties: {
|
|
@@ -66,20 +67,20 @@ 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), w((c) => {
|
|
70
|
+
console.log("onError", e.message), F(e.message, void 0, e.code?.toString()), w((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: P(e) }]), n;
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
|
-
}), E = y === "submitted",
|
|
75
|
+
}), E = y === "submitted", U = y === "streaming", q = l.length === 0, g = !o.trim() || E, J = se("(max-width: 768px)"), [L, S] = r(null);
|
|
75
76
|
x(() => {
|
|
76
|
-
p &&
|
|
77
|
+
p && S(p);
|
|
77
78
|
}, [p]);
|
|
78
|
-
const
|
|
79
|
+
const O = () => S(null), M = Z(null);
|
|
79
80
|
x(() => {
|
|
80
|
-
|
|
81
|
+
D?.(o);
|
|
81
82
|
}, [o]);
|
|
82
|
-
const
|
|
83
|
+
const Q = (e) => {
|
|
83
84
|
e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), d());
|
|
84
85
|
}, d = async (e = o) => {
|
|
85
86
|
if (g && (!e || e.trim().length === 0)) return;
|
|
@@ -95,7 +96,7 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
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)}`, f(t)), k(t), H(
|
|
99
100
|
// { ...userMessage, files },
|
|
100
101
|
// { ...userMessage, },
|
|
101
102
|
{
|
|
@@ -108,53 +109,53 @@ It seems I might be having some issues right now. Please clear the chat and try
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
);
|
|
111
|
-
},
|
|
112
|
-
|
|
112
|
+
}, V = () => {
|
|
113
|
+
T();
|
|
113
114
|
}, _ = () => {
|
|
114
|
-
|
|
115
|
+
O(), w([]), f(""), W({}), u([]), b(null), i({
|
|
115
116
|
eventName: "chat_clear_button_clicked",
|
|
116
117
|
properties: {
|
|
117
118
|
conversationId: s
|
|
118
119
|
}
|
|
119
120
|
});
|
|
120
|
-
}, { openForm:
|
|
121
|
-
return
|
|
121
|
+
}, { openForm: j } = re(), G = ae();
|
|
122
|
+
return ee(a.chatFunctionsRef, () => ({
|
|
122
123
|
submitMessage: d,
|
|
123
124
|
updateInputMessage(e) {
|
|
124
125
|
m(e);
|
|
125
126
|
},
|
|
126
127
|
clearChat: _,
|
|
127
128
|
openForm: (e) => {
|
|
128
|
-
|
|
129
|
+
G?.setView("chat"), j(e, void 0);
|
|
129
130
|
},
|
|
130
131
|
focusInput: () => {
|
|
131
|
-
|
|
132
|
+
M.current?.focus();
|
|
132
133
|
}
|
|
133
134
|
})), {
|
|
134
135
|
messages: l,
|
|
135
136
|
isLoading: E,
|
|
136
|
-
isStreaming:
|
|
137
|
-
error:
|
|
137
|
+
isStreaming: U,
|
|
138
|
+
error: L,
|
|
138
139
|
isSubmitDisabled: g,
|
|
139
140
|
input: o,
|
|
140
|
-
handleInputChange:
|
|
141
|
-
handleInputKeyDown:
|
|
141
|
+
handleInputChange: N,
|
|
142
|
+
handleInputKeyDown: Q,
|
|
142
143
|
handleSubmit: d,
|
|
143
|
-
stop:
|
|
144
|
+
stop: V,
|
|
144
145
|
clear: _,
|
|
145
|
-
messageButtons:
|
|
146
|
+
messageButtons: R,
|
|
146
147
|
isEmpty: l.length === 0,
|
|
147
|
-
inputRef:
|
|
148
|
-
isMobile:
|
|
148
|
+
inputRef: M,
|
|
149
|
+
isMobile: J,
|
|
149
150
|
// Additional state for attachments and workflow
|
|
150
|
-
messageAttachments:
|
|
151
|
+
messageAttachments: $,
|
|
151
152
|
setMessageAttachments: u,
|
|
152
|
-
selectedWorkflow:
|
|
153
|
+
selectedWorkflow: z,
|
|
153
154
|
setSelectedWorkflow: b,
|
|
154
|
-
isNewChat:
|
|
155
|
+
isNewChat: q,
|
|
155
156
|
conversationId: s
|
|
156
157
|
};
|
|
157
158
|
};
|
|
158
159
|
export {
|
|
159
|
-
|
|
160
|
+
be as useInkeepChat
|
|
160
161
|
};
|
|
@@ -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 a=require("react"),b=require("../../../types/message.cjs"),L=require("../../hooks/use-streaming-events.cjs");function E(r,c){const[u,A]=a.useState([]),[p,D]=a.useState(new Map),[d,P]=a.useState(Date.now()),[R,g]=a.useState(!1),h=a.useRef(0),y=a.useRef(0),w=a.useRef([]),l=a.useRef(p);l.current=p;const{emitArtifactSaved:S,emitCompletion:x,emitAgentInitializing:k,emitTextDelta:C}=L.useStreamingEvents(),T=a.useCallback(()=>{const n=[];let e="",o=[];r.length>h.current&&(P(Date.now()),h.current=r.length),y.current=0;const i=new Map,m=(t=!1)=>{if(o.length>0){const s=`group-${y.current++}`,f=l.current.get(s);f?i.set(s,{...f,isCompleted:t}):i.set(s,{isCompleted:t}),n.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const t of r)if(t.type==="text")m(!0),t.text&&c&&C(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"){const s=t.data;if(s?.type)switch(s.type){case"completion":x("unknown",1),m(!0);break;case"agent_initializing":k("unknown","unknown");break;case"error":console.warn("Data operation error:",s.ctx);break;case"agent_thinking":case"agent_ready":console.log("Agent state:",s.type,s.ctx);break}}else if(t.type==="data-artifact")if(t.data?.type?.toLowerCase()===b.CITATION_ARTIFACT_TYPE){const s=t.data,f=s.artifactSummary||{title:s.name};e+=` ^${f?.title||s.name}^`}else e.trim()&&(n.push({type:"text",text:e}),e=""),n.push(t),t.data&&S(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=""),n.push(t));return m(!c),e.trim()&&n.push({type:"text",text:e}),{processed:n,newTimings:i}},[r,c,S,x,k,C]);a.useEffect(()=>{if(w.current===r)return;w.current=r;const{processed:n,newTimings:e}=T();A(n),(e.size!==l.current.size||Array.from(e.entries()).some(([i,m])=>{const t=l.current.get(i);return!t||t.isCompleted!==m.isCompleted}))&&D(e)},[T,r]);const v=a.useCallback(()=>{const n=Date.now()-d,e=Array.from(l.current.values()).some(i=>!i.isCompleted),o=n>1e3&&!e;g(o)},[d]);a.useEffect(()=>{if(!c){g(!1);return}if(!(u.length>0)){g(!1);return}const e=setInterval(v,200);return()=>clearInterval(e)},[c,v,u.length]);const I=a.useMemo(()=>!(u.length>0),[u.length]);return{processedParts:u,summaryTimings:p,shouldShowInitialLoading:I,shouldShowStreamDelayLoading:R}}exports.useStreamProcessor=E;
|
|
@@ -1,82 +1,121 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState as f, useRef as p, useCallback as
|
|
3
|
-
import { CITATION_ARTIFACT_TYPE as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
c.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
l
|
|
2
|
+
import { useState as f, useRef as p, useCallback as D, useEffect as I, useMemo as z } from "react";
|
|
3
|
+
import { CITATION_ARTIFACT_TYPE as E } from "../../../types/message.js";
|
|
4
|
+
import { useStreamingEvents as M } from "../../hooks/use-streaming-events.js";
|
|
5
|
+
function $(r, i) {
|
|
6
|
+
const [c, P] = f([]), [d, L] = f(/* @__PURE__ */ new Map()), [g, R] = f(Date.now()), [b, h] = f(!1), y = p(0), w = p(0), x = p([]), u = p(d);
|
|
7
|
+
u.current = d;
|
|
8
|
+
const { emitArtifactSaved: k, emitCompletion: C, emitAgentInitializing: T, emitTextDelta: S } = M(), A = D(() => {
|
|
9
|
+
const n = [];
|
|
10
|
+
let e = "", s = [];
|
|
11
|
+
r.length > y.current && (R(Date.now()), y.current = r.length), w.current = 0;
|
|
12
|
+
const o = /* @__PURE__ */ new Map(), m = (t = !1) => {
|
|
13
|
+
if (s.length > 0) {
|
|
14
|
+
const a = `group-${w.current++}`, l = u.current.get(a);
|
|
15
|
+
l ? o.set(a, {
|
|
15
16
|
...l,
|
|
16
|
-
isCompleted:
|
|
17
|
-
}) :
|
|
18
|
-
isCompleted:
|
|
19
|
-
}),
|
|
17
|
+
isCompleted: t
|
|
18
|
+
}) : o.set(a, {
|
|
19
|
+
isCompleted: t
|
|
20
|
+
}), n.push({
|
|
20
21
|
type: "summary-group",
|
|
21
|
-
summaries: [...
|
|
22
|
-
groupKey:
|
|
23
|
-
}),
|
|
22
|
+
summaries: [...s],
|
|
23
|
+
groupKey: a
|
|
24
|
+
}), s = [];
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
|
-
for (const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
else if (
|
|
30
|
-
|
|
31
|
-
else if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
for (const t of r)
|
|
28
|
+
if (t.type === "text")
|
|
29
|
+
m(!0), t.text && i && S(t.text), e += t.text || "";
|
|
30
|
+
else if (t.type === "data-summary")
|
|
31
|
+
e.trim() && (n.push({ type: "text", text: e }), e = ""), s.push(t.data);
|
|
32
|
+
else if (t.type === "data-operation") {
|
|
33
|
+
const a = t.data;
|
|
34
|
+
if (a?.type)
|
|
35
|
+
switch (a.type) {
|
|
36
|
+
case "completion":
|
|
37
|
+
C(
|
|
38
|
+
"unknown",
|
|
39
|
+
// No agent ID available in current structure
|
|
40
|
+
1
|
|
41
|
+
// No iteration available in current structure
|
|
42
|
+
), m(!0);
|
|
43
|
+
break;
|
|
44
|
+
case "agent_initializing":
|
|
45
|
+
T(
|
|
46
|
+
"unknown",
|
|
47
|
+
// No session ID available in current structure
|
|
48
|
+
"unknown"
|
|
49
|
+
// No graph ID available in current structure
|
|
50
|
+
);
|
|
51
|
+
break;
|
|
52
|
+
case "error":
|
|
53
|
+
console.warn("Data operation error:", a.ctx);
|
|
54
|
+
break;
|
|
55
|
+
case "agent_thinking":
|
|
56
|
+
case "agent_ready":
|
|
57
|
+
console.log("Agent state:", a.type, a.ctx);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
} else if (t.type === "data-artifact")
|
|
61
|
+
if (t.data?.type?.toLowerCase() === E) {
|
|
62
|
+
const a = t.data, l = a.artifactSummary || {
|
|
63
|
+
title: a.name
|
|
37
64
|
};
|
|
38
|
-
|
|
65
|
+
e += ` ^${l?.title || a.name}^`;
|
|
39
66
|
} else
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
e.trim() && (n.push({ type: "text", text: e }), e = ""), n.push(t), t.data && k(
|
|
68
|
+
t.data.artifactId || "unknown",
|
|
69
|
+
t.data.taskId || "unknown",
|
|
70
|
+
"unknown",
|
|
71
|
+
// toolCallId not available in current structure
|
|
72
|
+
t.data.artifactType || "unknown",
|
|
73
|
+
t.data.artifactSummary || {},
|
|
74
|
+
// Use artifactSummary as summaryData
|
|
75
|
+
{},
|
|
76
|
+
// fullData not available in current structure
|
|
77
|
+
{ name: t.data.name, description: t.data.description }
|
|
78
|
+
// Use available fields as metadata
|
|
79
|
+
);
|
|
80
|
+
else t.type === "data-component" && (e.trim() && (n.push({ type: "text", text: e }), e = ""), n.push(t));
|
|
81
|
+
return m(!i), e.trim() && n.push({ type: "text", text: e }), { processed: n, newTimings: o };
|
|
82
|
+
}, [r, i, k, C, T, S]);
|
|
83
|
+
I(() => {
|
|
84
|
+
if (x.current === r)
|
|
46
85
|
return;
|
|
47
|
-
|
|
48
|
-
const { processed:
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
return !
|
|
52
|
-
})) &&
|
|
53
|
-
}, [
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
(
|
|
57
|
-
),
|
|
58
|
-
|
|
86
|
+
x.current = r;
|
|
87
|
+
const { processed: n, newTimings: e } = A();
|
|
88
|
+
P(n), (e.size !== u.current.size || Array.from(e.entries()).some(([o, m]) => {
|
|
89
|
+
const t = u.current.get(o);
|
|
90
|
+
return !t || t.isCompleted !== m.isCompleted;
|
|
91
|
+
})) && L(e);
|
|
92
|
+
}, [A, r]);
|
|
93
|
+
const v = D(() => {
|
|
94
|
+
const n = Date.now() - g, e = Array.from(u.current.values()).some(
|
|
95
|
+
(o) => !o.isCompleted
|
|
96
|
+
), s = n > 1e3 && !e;
|
|
97
|
+
h(s);
|
|
59
98
|
}, [g]);
|
|
60
|
-
|
|
61
|
-
if (!
|
|
62
|
-
|
|
99
|
+
I(() => {
|
|
100
|
+
if (!i) {
|
|
101
|
+
h(!1);
|
|
63
102
|
return;
|
|
64
103
|
}
|
|
65
|
-
if (!(
|
|
66
|
-
|
|
104
|
+
if (!(c.length > 0)) {
|
|
105
|
+
h(!1);
|
|
67
106
|
return;
|
|
68
107
|
}
|
|
69
|
-
const
|
|
70
|
-
return () => clearInterval(
|
|
71
|
-
}, [
|
|
72
|
-
const
|
|
108
|
+
const e = setInterval(v, 200);
|
|
109
|
+
return () => clearInterval(e);
|
|
110
|
+
}, [i, v, c.length]);
|
|
111
|
+
const _ = z(() => !(c.length > 0), [c.length]);
|
|
73
112
|
return {
|
|
74
|
-
processedParts:
|
|
75
|
-
summaryTimings:
|
|
76
|
-
shouldShowInitialLoading:
|
|
77
|
-
shouldShowStreamDelayLoading:
|
|
113
|
+
processedParts: c,
|
|
114
|
+
summaryTimings: d,
|
|
115
|
+
shouldShowInitialLoading: _,
|
|
116
|
+
shouldShowStreamDelayLoading: b
|
|
78
117
|
};
|
|
79
118
|
}
|
|
80
119
|
export {
|
|
81
|
-
|
|
120
|
+
$ as useStreamProcessor
|
|
82
121
|
};
|
|
@@ -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;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef as x, useCallback as o } from "react";
|
|
3
|
+
import { useShadow as A } from "../atoms/shadow/context.js";
|
|
4
|
+
function R() {
|
|
5
|
+
const r = A()?.shadowHost, c = x(""), e = o(
|
|
6
|
+
(t) => {
|
|
7
|
+
if (!r) {
|
|
8
|
+
console.warn("useStreamingEvents: No host element available for event emission");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const n = {
|
|
12
|
+
...t,
|
|
13
|
+
conversationId: c.current,
|
|
14
|
+
timestamp: Date.now()
|
|
15
|
+
}, a = new CustomEvent("streaming-event", {
|
|
16
|
+
detail: n,
|
|
17
|
+
bubbles: !0,
|
|
18
|
+
// Allow event to bubble up
|
|
19
|
+
composed: !0
|
|
20
|
+
// Allow event to escape Shadow DOM boundary
|
|
21
|
+
});
|
|
22
|
+
r.dispatchEvent(a);
|
|
23
|
+
},
|
|
24
|
+
[r]
|
|
25
|
+
), m = o((t) => {
|
|
26
|
+
c.current = t;
|
|
27
|
+
}, []), l = o(
|
|
28
|
+
(t) => {
|
|
29
|
+
e({
|
|
30
|
+
kind: "text:delta",
|
|
31
|
+
data: { text: t }
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
[e]
|
|
35
|
+
), u = o(
|
|
36
|
+
(t, n, a) => {
|
|
37
|
+
e({
|
|
38
|
+
kind: "stream:error",
|
|
39
|
+
data: {
|
|
40
|
+
message: t,
|
|
41
|
+
agent: n,
|
|
42
|
+
severity: "error",
|
|
43
|
+
code: a
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
[e]
|
|
48
|
+
), g = o(
|
|
49
|
+
(t, n) => {
|
|
50
|
+
e({
|
|
51
|
+
kind: "agent:reasoning",
|
|
52
|
+
data: { agentId: t, parts: n }
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
[e]
|
|
56
|
+
), v = o(
|
|
57
|
+
(t, n, a) => {
|
|
58
|
+
e({
|
|
59
|
+
kind: "agent:generate",
|
|
60
|
+
data: { agentId: t, parts: n, generationType: a }
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
[e]
|
|
64
|
+
), f = o(
|
|
65
|
+
(t, n, a, i, s, d) => {
|
|
66
|
+
e({
|
|
67
|
+
kind: "tool:execution",
|
|
68
|
+
data: { agentId: t, toolName: n, args: a, result: i, toolId: s, duration: d }
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
[e]
|
|
72
|
+
), k = o(
|
|
73
|
+
(t, n, a, i) => {
|
|
74
|
+
e({
|
|
75
|
+
kind: "agent:transfer",
|
|
76
|
+
data: { fromAgent: t, targetAgent: n, reason: a, context: i }
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
[e]
|
|
80
|
+
), E = o(
|
|
81
|
+
(t, n, a, i, s) => {
|
|
82
|
+
e({
|
|
83
|
+
kind: "delegation:sent",
|
|
84
|
+
data: { delegationId: t, fromAgent: n, targetAgent: a, taskDescription: i, context: s }
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
[e]
|
|
88
|
+
), p = o(
|
|
89
|
+
(t, n, a, i) => {
|
|
90
|
+
e({
|
|
91
|
+
kind: "delegation:returned",
|
|
92
|
+
data: { delegationId: t, fromAgent: n, targetAgent: a, result: i }
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
[e]
|
|
96
|
+
), h = o(
|
|
97
|
+
(t, n, a, i, s, d, b) => {
|
|
98
|
+
e({
|
|
99
|
+
kind: "artifact:saved",
|
|
100
|
+
data: { artifactId: t, taskId: n, toolCallId: a, artifactType: i, summaryData: s, fullData: d, metadata: b }
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
[e]
|
|
104
|
+
), w = o(
|
|
105
|
+
(t, n) => {
|
|
106
|
+
e({
|
|
107
|
+
kind: "completion",
|
|
108
|
+
data: { agent: t, iteration: n }
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
[e]
|
|
112
|
+
), S = o(
|
|
113
|
+
(t, n) => {
|
|
114
|
+
e({
|
|
115
|
+
kind: "agent:initializing",
|
|
116
|
+
data: { sessionId: t, graphId: n }
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
[e]
|
|
120
|
+
);
|
|
121
|
+
return {
|
|
122
|
+
emitEvent: e,
|
|
123
|
+
setConversationId: m,
|
|
124
|
+
// Convenience methods
|
|
125
|
+
emitTextDelta: l,
|
|
126
|
+
emitStreamError: u,
|
|
127
|
+
emitAgentReasoning: g,
|
|
128
|
+
emitAgentGenerate: v,
|
|
129
|
+
emitToolExecution: f,
|
|
130
|
+
emitAgentTransfer: k,
|
|
131
|
+
emitDelegationSent: E,
|
|
132
|
+
emitDelegationReturned: p,
|
|
133
|
+
emitArtifactSaved: h,
|
|
134
|
+
emitCompletion: w,
|
|
135
|
+
emitAgentInitializing: S
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
R as useStreamingEvents
|
|
140
|
+
};
|
|
@@ -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.14.
|
|
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.14.10",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.14.
|
|
8
|
+
widgetLibraryVersion: "0.14.10",
|
|
9
9
|
componentType: o,
|
|
10
10
|
tags: s
|
|
11
11
|
}),
|