@agno-hq/chat-react 0.3.3 → 0.3.4
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/README.md +46 -0
- package/dist/chat/index.cjs +90 -86
- package/dist/chat/index.d.cts +55 -43
- package/dist/chat/index.d.ts +55 -43
- package/dist/chat/index.js +2 -2
- package/dist/{chunk-RE7ZT73K.js → chunk-5QKU7OPE.js} +2 -2
- package/dist/{chunk-RE7ZT73K.js.map → chunk-5QKU7OPE.js.map} +1 -1
- package/dist/{chunk-6V2YIPHF.js → chunk-BCVKAMSO.js} +22 -4
- package/dist/chunk-BCVKAMSO.js.map +1 -0
- package/dist/{chunk-3IEYJIYJ.cjs → chunk-ESV52ERB.cjs} +620 -318
- package/dist/chunk-ESV52ERB.cjs.map +1 -0
- package/dist/{chunk-2WM3CCFE.cjs → chunk-HBSF434L.cjs} +2 -2
- package/dist/{chunk-2WM3CCFE.cjs.map → chunk-HBSF434L.cjs.map} +1 -1
- package/dist/{chunk-E4CFQ457.js → chunk-OGDPK4Z3.js} +586 -285
- package/dist/chunk-OGDPK4Z3.js.map +1 -0
- package/dist/{chunk-55HQJGLP.cjs → chunk-Y34YRC5T.cjs} +22 -3
- package/dist/chunk-Y34YRC5T.cjs.map +1 -0
- package/dist/{client-DUyVqxU9.d.cts → client-Dwk6ThnW.d.cts} +24 -12
- package/dist/{client-DUyVqxU9.d.ts → client-Dwk6ThnW.d.ts} +24 -12
- package/dist/core/index.cjs +23 -23
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/index.cjs +113 -109
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/styles.css +22 -15
- package/package.json +11 -9
- package/dist/chunk-3IEYJIYJ.cjs.map +0 -1
- package/dist/chunk-55HQJGLP.cjs.map +0 -1
- package/dist/chunk-6V2YIPHF.js.map +0 -1
- package/dist/chunk-E4CFQ457.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkY34YRC5T_cjs = require('./chunk-Y34YRC5T.cjs');
|
|
4
4
|
var React8 = require('react');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var reactDom = require('react-dom');
|
|
@@ -11,6 +11,172 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
11
11
|
|
|
12
12
|
var React8__default = /*#__PURE__*/_interopDefault(React8);
|
|
13
13
|
|
|
14
|
+
function useRunView(initialMessages = []) {
|
|
15
|
+
const [view, setView] = React8.useState({
|
|
16
|
+
messages: initialMessages,
|
|
17
|
+
events: [],
|
|
18
|
+
status: "idle",
|
|
19
|
+
activity: null,
|
|
20
|
+
error: null
|
|
21
|
+
});
|
|
22
|
+
const viewRef = React8.useRef(view);
|
|
23
|
+
const update = React8.useCallback((key, action) => {
|
|
24
|
+
const value = typeof action === "function" ? action(viewRef.current[key]) : action;
|
|
25
|
+
if (Object.is(value, viewRef.current[key])) return;
|
|
26
|
+
viewRef.current = { ...viewRef.current, [key]: value };
|
|
27
|
+
setView(viewRef.current);
|
|
28
|
+
}, []);
|
|
29
|
+
const setters = React8.useMemo(() => ({
|
|
30
|
+
setMessages: (action) => update("messages", action),
|
|
31
|
+
setEvents: (action) => update("events", action),
|
|
32
|
+
setStatus: (action) => update("status", action),
|
|
33
|
+
setActivity: (action) => update("activity", action),
|
|
34
|
+
setError: (action) => update("error", action)
|
|
35
|
+
}), [update]);
|
|
36
|
+
return { ...view, ...setters, viewRef };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/chat/streaming/bufferTextEvents.ts
|
|
40
|
+
var DEFAULT_STREAMING_OPTIONS = Object.freeze({
|
|
41
|
+
enabled: true,
|
|
42
|
+
flushIntervalMs: 150,
|
|
43
|
+
maxBufferEvents: 100,
|
|
44
|
+
maxBufferChars: 16384
|
|
45
|
+
});
|
|
46
|
+
var MAX_TIMEOUT_MS = 2147483647;
|
|
47
|
+
var RICH_FIELDS = [
|
|
48
|
+
"tool",
|
|
49
|
+
"tools",
|
|
50
|
+
"response_audio",
|
|
51
|
+
"images",
|
|
52
|
+
"videos",
|
|
53
|
+
"audio",
|
|
54
|
+
"image",
|
|
55
|
+
"references",
|
|
56
|
+
"citations",
|
|
57
|
+
"extra_data"
|
|
58
|
+
];
|
|
59
|
+
function isPlainText(event) {
|
|
60
|
+
return (event.event === "RunContent" || event.event === "TeamRunContent") && typeof event.content === "string" && event.content.length > 0 && RICH_FIELDS.every((key) => event[key] == null);
|
|
61
|
+
}
|
|
62
|
+
function isContinuationOf(previous, next) {
|
|
63
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)]);
|
|
64
|
+
for (const key of keys) {
|
|
65
|
+
if (key === "content") continue;
|
|
66
|
+
const before = previous[key];
|
|
67
|
+
const after = next[key];
|
|
68
|
+
if (key === "event_index" && typeof before === "number" && typeof after === "number") {
|
|
69
|
+
if (after <= before) return false;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!Object.is(before, after)) return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
function boundedNumber(value, fallback, min) {
|
|
77
|
+
return value !== void 0 && Number.isFinite(value) && value >= min ? Math.min(Math.floor(value), MAX_TIMEOUT_MS) : fallback;
|
|
78
|
+
}
|
|
79
|
+
function bufferTextEvents(deliver, options = {}) {
|
|
80
|
+
const defaults = DEFAULT_STREAMING_OPTIONS;
|
|
81
|
+
const interval = boundedNumber(
|
|
82
|
+
options.flushIntervalMs,
|
|
83
|
+
defaults.flushIntervalMs,
|
|
84
|
+
0
|
|
85
|
+
);
|
|
86
|
+
const maxEvents = boundedNumber(
|
|
87
|
+
options.maxBufferEvents,
|
|
88
|
+
defaults.maxBufferEvents,
|
|
89
|
+
1
|
|
90
|
+
);
|
|
91
|
+
const maxChars = boundedNumber(
|
|
92
|
+
options.maxBufferChars,
|
|
93
|
+
defaults.maxBufferChars,
|
|
94
|
+
1
|
|
95
|
+
);
|
|
96
|
+
const enabled = (options.enabled ?? defaults.enabled) && interval > 0;
|
|
97
|
+
let events = [];
|
|
98
|
+
let chunks = [];
|
|
99
|
+
let chars = 0;
|
|
100
|
+
let hasText = false;
|
|
101
|
+
let disposed = false;
|
|
102
|
+
let timer;
|
|
103
|
+
const isHidden = () => typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
104
|
+
const onVisibilityChange = () => {
|
|
105
|
+
if (isHidden()) flush();
|
|
106
|
+
};
|
|
107
|
+
const stopObserving = () => {
|
|
108
|
+
if (typeof document !== "undefined")
|
|
109
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
110
|
+
};
|
|
111
|
+
const cancelScheduled = () => {
|
|
112
|
+
stopObserving();
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
timer = void 0;
|
|
115
|
+
};
|
|
116
|
+
const flush = () => {
|
|
117
|
+
cancelScheduled();
|
|
118
|
+
const batch = { events, chunks };
|
|
119
|
+
events = [];
|
|
120
|
+
chunks = [];
|
|
121
|
+
chars = 0;
|
|
122
|
+
if (!disposed && (batch.events.length || batch.chunks.length))
|
|
123
|
+
deliver(batch);
|
|
124
|
+
};
|
|
125
|
+
const schedule = () => {
|
|
126
|
+
if (timer !== void 0 || disposed) return;
|
|
127
|
+
if (isHidden()) return flush();
|
|
128
|
+
if (typeof document !== "undefined")
|
|
129
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
130
|
+
timer = setTimeout(() => {
|
|
131
|
+
timer = void 0;
|
|
132
|
+
flush();
|
|
133
|
+
}, interval);
|
|
134
|
+
};
|
|
135
|
+
const deliverNow = (event) => {
|
|
136
|
+
if (!disposed) deliver({ events: [event], chunks: [event] });
|
|
137
|
+
};
|
|
138
|
+
const append = (event) => {
|
|
139
|
+
const last = chunks[chunks.length - 1];
|
|
140
|
+
if (last && isContinuationOf(last, event)) {
|
|
141
|
+
chunks[chunks.length - 1] = {
|
|
142
|
+
...event,
|
|
143
|
+
content: String(last.content) + event.content
|
|
144
|
+
};
|
|
145
|
+
} else {
|
|
146
|
+
chunks.push(event);
|
|
147
|
+
}
|
|
148
|
+
events.push(event);
|
|
149
|
+
chars += String(event.content).length;
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
push(event) {
|
|
153
|
+
if (disposed) return;
|
|
154
|
+
if (!enabled || !isPlainText(event)) {
|
|
155
|
+
flush();
|
|
156
|
+
hasText = false;
|
|
157
|
+
deliverNow(event);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!hasText) {
|
|
161
|
+
hasText = true;
|
|
162
|
+
deliverNow(event);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
append(event);
|
|
166
|
+
if (events.length >= maxEvents || chars >= maxChars) flush();
|
|
167
|
+
else schedule();
|
|
168
|
+
},
|
|
169
|
+
flush,
|
|
170
|
+
dispose() {
|
|
171
|
+
disposed = true;
|
|
172
|
+
cancelScheduled();
|
|
173
|
+
events = [];
|
|
174
|
+
chunks = [];
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/chat/useAgnoChat.ts
|
|
14
180
|
var messageCounter = 0;
|
|
15
181
|
var nextId = () => `m${Date.now().toString(36)}-${(messageCounter++).toString(36)}`;
|
|
16
182
|
var nowSeconds = () => Math.floor(Date.now() / 1e3);
|
|
@@ -18,14 +184,22 @@ function useAgnoChat(options) {
|
|
|
18
184
|
const { entity, userId, onEvent, onSessionId } = options;
|
|
19
185
|
const client = React8.useMemo(() => {
|
|
20
186
|
if (options.client) return options.client;
|
|
21
|
-
return new
|
|
187
|
+
return new chunkY34YRC5T_cjs.AgnoClient({ baseUrl: options.baseUrl ?? "", headers: options.headers });
|
|
22
188
|
}, [options.client, options.baseUrl, JSON.stringify(options.headers)]);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
189
|
+
const {
|
|
190
|
+
messages,
|
|
191
|
+
events,
|
|
192
|
+
status,
|
|
193
|
+
activity,
|
|
194
|
+
error,
|
|
195
|
+
viewRef,
|
|
196
|
+
setMessages,
|
|
197
|
+
setEvents,
|
|
198
|
+
setStatus,
|
|
199
|
+
setActivity,
|
|
200
|
+
setError
|
|
201
|
+
} = useRunView(options.initialMessages);
|
|
202
|
+
const currentEvent = events[events.length - 1] ?? null;
|
|
29
203
|
const [sessionId, setSessionId] = React8.useState(options.sessionId);
|
|
30
204
|
const [sessions, setSessions] = React8.useState([]);
|
|
31
205
|
const [sessionsLoading, setSessionsLoading] = React8.useState(false);
|
|
@@ -35,10 +209,14 @@ function useAgnoChat(options) {
|
|
|
35
209
|
const backgroundRef = React8.useRef(/* @__PURE__ */ new Map());
|
|
36
210
|
const activeMsgIdRef = React8.useRef(null);
|
|
37
211
|
const runIdRef = React8.useRef(void 0);
|
|
212
|
+
const streamingRef = React8.useRef(options.streaming);
|
|
38
213
|
const entityRef = React8.useRef(entity);
|
|
39
214
|
const sessionIdRef = React8.useRef(options.sessionId);
|
|
40
215
|
const pendingSessionNameRef = React8.useRef(void 0);
|
|
41
216
|
const bumpedSessionRef = React8.useRef(void 0);
|
|
217
|
+
React8.useEffect(() => {
|
|
218
|
+
streamingRef.current = options.streaming;
|
|
219
|
+
}, [options.streaming]);
|
|
42
220
|
React8.useEffect(() => {
|
|
43
221
|
entityRef.current = entity;
|
|
44
222
|
}, [entity]);
|
|
@@ -58,44 +236,37 @@ function useAgnoChat(options) {
|
|
|
58
236
|
return [entry, ...rest];
|
|
59
237
|
});
|
|
60
238
|
}, []);
|
|
61
|
-
const viewRef = React8.useRef({ messages, events, status, activity, error });
|
|
62
|
-
React8.useEffect(() => {
|
|
63
|
-
viewRef.current = { messages, events, status, activity, error };
|
|
64
|
-
});
|
|
65
239
|
const writeMessages = React8.useCallback(
|
|
66
240
|
(chan, fn) => {
|
|
67
241
|
const park = chan?.park;
|
|
68
242
|
if (park) park.messages = fn(park.messages);
|
|
69
243
|
else setMessages(fn);
|
|
70
244
|
},
|
|
71
|
-
[]
|
|
245
|
+
[setMessages]
|
|
72
246
|
);
|
|
73
|
-
const writeEvents = React8.useCallback((chan,
|
|
74
|
-
const park = chan
|
|
75
|
-
if (park) park.events = [...park.events,
|
|
76
|
-
else
|
|
77
|
-
|
|
78
|
-
setCurrentEvent(e);
|
|
79
|
-
}
|
|
80
|
-
}, []);
|
|
247
|
+
const writeEvents = React8.useCallback((chan, incoming) => {
|
|
248
|
+
const park = chan.park;
|
|
249
|
+
if (park) park.events = [...park.events, ...incoming];
|
|
250
|
+
else setEvents((previous) => [...previous, ...incoming]);
|
|
251
|
+
}, [setEvents]);
|
|
81
252
|
const writeStatus = React8.useCallback((chan, status2) => {
|
|
82
253
|
const park = chan?.park;
|
|
83
254
|
if (park) park.status = status2;
|
|
84
255
|
else setStatus(status2);
|
|
85
|
-
}, []);
|
|
256
|
+
}, [setStatus]);
|
|
86
257
|
const writeActivity = React8.useCallback((chan, activity2) => {
|
|
87
258
|
const park = chan?.park;
|
|
88
259
|
if (park) park.activity = activity2;
|
|
89
260
|
else setActivity(activity2);
|
|
90
|
-
}, []);
|
|
261
|
+
}, [setActivity]);
|
|
91
262
|
const writeError = React8.useCallback((chan, message) => {
|
|
92
263
|
const park = chan?.park;
|
|
93
264
|
if (park) park.error = message;
|
|
94
265
|
else setError(message);
|
|
95
|
-
}, []);
|
|
266
|
+
}, [setError]);
|
|
96
267
|
const patchActive = React8.useCallback(
|
|
97
268
|
(chan, patch) => {
|
|
98
|
-
const id = chan
|
|
269
|
+
const id = chan ? chan.messageId : activeMsgIdRef.current;
|
|
99
270
|
if (!id) return;
|
|
100
271
|
writeMessages(chan, (prev) => prev.map((m) => m.id === id ? patch(m) : m));
|
|
101
272
|
},
|
|
@@ -103,10 +274,7 @@ function useAgnoChat(options) {
|
|
|
103
274
|
);
|
|
104
275
|
const applyEvent = React8.useCallback(
|
|
105
276
|
(chan, e) => {
|
|
106
|
-
|
|
107
|
-
patchActive(chan, (m) => ({ ...m, events: [...m.events ?? [], e] }));
|
|
108
|
-
onEvent?.(e);
|
|
109
|
-
const label2 = chunk55HQJGLP_cjs.activityLabel(e);
|
|
277
|
+
const label2 = chunkY34YRC5T_cjs.activityLabel(e);
|
|
110
278
|
if (label2) writeActivity(chan, label2);
|
|
111
279
|
if (e.session_id && !chan?.park && e.session_id !== sessionIdRef.current) {
|
|
112
280
|
sessionIdRef.current = e.session_id;
|
|
@@ -123,16 +291,16 @@ function useAgnoChat(options) {
|
|
|
123
291
|
if (chan?.park) chan.park.runId = e.run_id;
|
|
124
292
|
else runIdRef.current = e.run_id;
|
|
125
293
|
}
|
|
126
|
-
if (
|
|
127
|
-
const kind = entityRef.current?.type === "workflow" ? "executor" : "member";
|
|
128
|
-
patchActive(chan, (m) =>
|
|
294
|
+
if (chunkY34YRC5T_cjs.isSubRunEvent(e)) {
|
|
295
|
+
const kind = (chan?.entityType ?? entityRef.current?.type) === "workflow" ? "executor" : "member";
|
|
296
|
+
patchActive(chan, (m) => chunkY34YRC5T_cjs.applySubRunEvent(m, e, kind));
|
|
129
297
|
return;
|
|
130
298
|
}
|
|
131
|
-
if (
|
|
132
|
-
patchActive(chan, (m) =>
|
|
299
|
+
if (chunkY34YRC5T_cjs.isStepEvent(e)) {
|
|
300
|
+
patchActive(chan, (m) => chunkY34YRC5T_cjs.applyStepEvent(m, e));
|
|
133
301
|
return;
|
|
134
302
|
}
|
|
135
|
-
if (
|
|
303
|
+
if (chunkY34YRC5T_cjs.isStartedEvent(e)) {
|
|
136
304
|
patchActive(chan, (m) => ({
|
|
137
305
|
...m,
|
|
138
306
|
run_id: e.run_id ?? m.run_id,
|
|
@@ -141,23 +309,23 @@ function useAgnoChat(options) {
|
|
|
141
309
|
}));
|
|
142
310
|
return;
|
|
143
311
|
}
|
|
144
|
-
if (
|
|
145
|
-
const incoming =
|
|
312
|
+
if (chunkY34YRC5T_cjs.isToolEvent(e)) {
|
|
313
|
+
const incoming = chunkY34YRC5T_cjs.toolsFromEvent(e);
|
|
146
314
|
if (incoming.length) {
|
|
147
315
|
patchActive(chan, (m) => {
|
|
148
316
|
let tool_calls = m.tool_calls ?? [];
|
|
149
|
-
for (const t of incoming) tool_calls =
|
|
317
|
+
for (const t of incoming) tool_calls = chunkY34YRC5T_cjs.mergeTool(tool_calls, t);
|
|
150
318
|
return { ...m, tool_calls };
|
|
151
319
|
});
|
|
152
320
|
}
|
|
153
321
|
return;
|
|
154
322
|
}
|
|
155
|
-
if (
|
|
156
|
-
patchActive(chan, (m) =>
|
|
323
|
+
if (chunkY34YRC5T_cjs.isContentEvent(e)) {
|
|
324
|
+
patchActive(chan, (m) => chunkY34YRC5T_cjs.applyContentEvent(m, e));
|
|
157
325
|
return;
|
|
158
326
|
}
|
|
159
|
-
if (
|
|
160
|
-
const incoming =
|
|
327
|
+
if (chunkY34YRC5T_cjs.isReasoningStepEvent(e)) {
|
|
328
|
+
const incoming = chunkY34YRC5T_cjs.reasoningStepsFromEvent(e);
|
|
161
329
|
if (incoming.length) {
|
|
162
330
|
patchActive(chan, (m) => ({
|
|
163
331
|
...m,
|
|
@@ -166,36 +334,36 @@ function useAgnoChat(options) {
|
|
|
166
334
|
}
|
|
167
335
|
return;
|
|
168
336
|
}
|
|
169
|
-
if (
|
|
170
|
-
const steps =
|
|
171
|
-
if (steps
|
|
337
|
+
if (chunkY34YRC5T_cjs.isReasoningCompletedEvent(e)) {
|
|
338
|
+
const steps = chunkY34YRC5T_cjs.reasoningStepsFromEvent(e);
|
|
339
|
+
if (steps.length) patchActive(chan, (m) => ({ ...m, reasoning_steps: steps }));
|
|
172
340
|
return;
|
|
173
341
|
}
|
|
174
|
-
if (
|
|
342
|
+
if (chunkY34YRC5T_cjs.isFollowupsCompletedEvent(e)) {
|
|
175
343
|
const followups = e.followups;
|
|
176
344
|
if (followups?.length) patchActive(chan, (m) => ({ ...m, followups }));
|
|
177
345
|
return;
|
|
178
346
|
}
|
|
179
|
-
if (
|
|
347
|
+
if (chunkY34YRC5T_cjs.isPausedEvent(e)) {
|
|
180
348
|
const requirements = e.requirements ?? [];
|
|
181
|
-
const pausedTools2 =
|
|
349
|
+
const pausedTools2 = chunkY34YRC5T_cjs.toolsFromEvent(e);
|
|
182
350
|
writeStatus(chan, "paused");
|
|
183
351
|
writeActivity(chan, "Waiting for input");
|
|
184
352
|
patchActive(chan, (m) => {
|
|
185
353
|
let tool_calls = m.tool_calls ?? [];
|
|
186
|
-
for (const t of pausedTools2) tool_calls =
|
|
187
|
-
return { ...m, status: "paused", streaming: false, requirements, tool_calls };
|
|
354
|
+
for (const t of pausedTools2) tool_calls = chunkY34YRC5T_cjs.mergeTool(tool_calls, t);
|
|
355
|
+
return { ...m, status: "paused", streaming: false, requirements, step_requirements: e.step_requirements ?? m.step_requirements, tool_calls };
|
|
188
356
|
});
|
|
189
357
|
return;
|
|
190
358
|
}
|
|
191
|
-
if (
|
|
359
|
+
if (chunkY34YRC5T_cjs.isCompletedEvent(e)) {
|
|
192
360
|
patchActive(chan, (m) => {
|
|
193
361
|
const next = { ...m, streaming: false, status: "completed" };
|
|
194
362
|
if (typeof e.content === "string" && e.content) next.content = e.content;
|
|
195
|
-
const tools =
|
|
363
|
+
const tools = chunkY34YRC5T_cjs.toolsFromEvent(e);
|
|
196
364
|
if (tools.length) {
|
|
197
365
|
let tc = m.tool_calls ?? [];
|
|
198
|
-
for (const t of tools) tc =
|
|
366
|
+
for (const t of tools) tc = chunkY34YRC5T_cjs.mergeTool(tc, t);
|
|
199
367
|
next.tool_calls = tc;
|
|
200
368
|
}
|
|
201
369
|
if (e.reasoning_steps?.length) next.reasoning_steps = e.reasoning_steps;
|
|
@@ -209,12 +377,12 @@ function useAgnoChat(options) {
|
|
|
209
377
|
});
|
|
210
378
|
return;
|
|
211
379
|
}
|
|
212
|
-
if (
|
|
380
|
+
if (chunkY34YRC5T_cjs.isCancelledEvent(e)) {
|
|
213
381
|
patchActive(chan, (m) => ({ ...m, streaming: false, status: "cancelled" }));
|
|
214
382
|
writeStatus(chan, "cancelled");
|
|
215
383
|
return;
|
|
216
384
|
}
|
|
217
|
-
if (
|
|
385
|
+
if (chunkY34YRC5T_cjs.isErrorEvent(e)) {
|
|
218
386
|
const msg = typeof e.content === "string" ? e.content : e.error || "Error during run";
|
|
219
387
|
patchActive(chan, (m) => ({ ...m, streaming: false, status: "error", error: msg }));
|
|
220
388
|
writeError(chan, msg);
|
|
@@ -223,13 +391,11 @@ function useAgnoChat(options) {
|
|
|
223
391
|
}
|
|
224
392
|
},
|
|
225
393
|
[
|
|
226
|
-
onEvent,
|
|
227
394
|
onSessionId,
|
|
228
395
|
patchActive,
|
|
229
396
|
upsertSession,
|
|
230
397
|
writeActivity,
|
|
231
398
|
writeError,
|
|
232
|
-
writeEvents,
|
|
233
399
|
writeStatus
|
|
234
400
|
]
|
|
235
401
|
);
|
|
@@ -267,12 +433,11 @@ function useAgnoChat(options) {
|
|
|
267
433
|
bumpedSessionRef.current = park.bumped;
|
|
268
434
|
setMessages(park.messages);
|
|
269
435
|
setEvents(park.events);
|
|
270
|
-
setCurrentEvent(park.events[park.events.length - 1] ?? null);
|
|
271
436
|
setStatus(park.status);
|
|
272
437
|
setActivity(park.activity);
|
|
273
438
|
setError(park.error);
|
|
274
439
|
return true;
|
|
275
|
-
}, []);
|
|
440
|
+
}, [setMessages, setEvents, setStatus, setActivity, setError]);
|
|
276
441
|
const releaseCurrentRun = React8.useCallback(() => {
|
|
277
442
|
const chan = channelRef.current;
|
|
278
443
|
if (!chan || chan.park) return;
|
|
@@ -288,29 +453,64 @@ function useAgnoChat(options) {
|
|
|
288
453
|
const drive = React8.useCallback(
|
|
289
454
|
async (starter) => {
|
|
290
455
|
const controller = new AbortController();
|
|
291
|
-
|
|
456
|
+
let finished = false;
|
|
457
|
+
const isCurrent = () => !controller.signal.aborted && (channelRef.current === chan || Boolean(chan.park && backgroundRef.current.get(chan.park.sessionId) === chan));
|
|
458
|
+
const chan = {
|
|
459
|
+
controller,
|
|
460
|
+
park: null,
|
|
461
|
+
messageId: activeMsgIdRef.current,
|
|
462
|
+
entityType: entityRef.current?.type,
|
|
463
|
+
buffer: bufferTextEvents(({ events: incoming, chunks }) => {
|
|
464
|
+
if (!isCurrent()) return;
|
|
465
|
+
if (incoming.length) {
|
|
466
|
+
writeEvents(chan, incoming);
|
|
467
|
+
patchActive(chan, (m) => ({ ...m, events: [...m.events ?? [], ...incoming] }));
|
|
468
|
+
}
|
|
469
|
+
for (const chunk of chunks) applyEvent(chan, chunk);
|
|
470
|
+
}, streamingRef.current)
|
|
471
|
+
};
|
|
472
|
+
controller.signal.addEventListener("abort", () => chan.buffer.dispose(), { once: true });
|
|
292
473
|
channelRef.current = chan;
|
|
293
474
|
abortRef.current = controller;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
475
|
+
writeError(chan, null);
|
|
476
|
+
writeStatus(chan, "streaming");
|
|
477
|
+
const complete = () => {
|
|
478
|
+
if (finished || !isCurrent()) return;
|
|
479
|
+
chan.buffer.flush();
|
|
480
|
+
finished = true;
|
|
481
|
+
chan.buffer.dispose();
|
|
482
|
+
writeActivity(chan, null);
|
|
483
|
+
patchActive(chan, (m) => m.streaming ? { ...m, streaming: false, status: "completed" } : m);
|
|
484
|
+
const status2 = chan.park?.status ?? viewRef.current.status;
|
|
485
|
+
if (status2 === "streaming") writeStatus(chan, "completed");
|
|
486
|
+
};
|
|
487
|
+
const fail = (err) => {
|
|
488
|
+
if (finished || !isCurrent()) return;
|
|
489
|
+
chan.buffer.flush();
|
|
490
|
+
finished = true;
|
|
491
|
+
chan.buffer.dispose();
|
|
492
|
+
patchActive(chan, (m) => ({ ...m, streaming: false, status: "error", error: err.message }));
|
|
493
|
+
writeActivity(chan, null);
|
|
494
|
+
writeError(chan, err.message);
|
|
495
|
+
writeStatus(chan, "error");
|
|
496
|
+
};
|
|
497
|
+
try {
|
|
498
|
+
await starter({
|
|
499
|
+
signal: controller.signal,
|
|
500
|
+
onEvent: (e) => {
|
|
501
|
+
if (finished || !isCurrent()) return;
|
|
502
|
+
onEvent?.(e);
|
|
503
|
+
if (isCurrent()) chan.buffer.push(e);
|
|
504
|
+
},
|
|
505
|
+
onError: fail,
|
|
506
|
+
onComplete: complete
|
|
507
|
+
});
|
|
508
|
+
complete();
|
|
509
|
+
} catch (error2) {
|
|
510
|
+
fail(error2 instanceof Error ? error2 : new Error(String(error2)));
|
|
511
|
+
} finally {
|
|
512
|
+
chan.buffer.dispose();
|
|
513
|
+
}
|
|
314
514
|
if (chan.park) {
|
|
315
515
|
const { sessionId: sessionId2 } = chan.park;
|
|
316
516
|
setBackgroundRunning((prev) => prev.filter((s) => s !== sessionId2));
|
|
@@ -319,7 +519,7 @@ function useAgnoChat(options) {
|
|
|
319
519
|
abortRef.current = null;
|
|
320
520
|
}
|
|
321
521
|
},
|
|
322
|
-
[applyEvent, patchActive, writeActivity, writeError, writeStatus]
|
|
522
|
+
[applyEvent, onEvent, patchActive, writeActivity, writeError, writeEvents, writeStatus]
|
|
323
523
|
);
|
|
324
524
|
const sendMessage = React8.useCallback(
|
|
325
525
|
async (message, sendOptions) => {
|
|
@@ -348,7 +548,6 @@ function useAgnoChat(options) {
|
|
|
348
548
|
};
|
|
349
549
|
activeMsgIdRef.current = agentMsg.id;
|
|
350
550
|
setEvents([]);
|
|
351
|
-
setCurrentEvent(null);
|
|
352
551
|
setMessages((prev) => [...prev, userMsg, agentMsg]);
|
|
353
552
|
await drive(
|
|
354
553
|
(cb) => client.run({
|
|
@@ -362,7 +561,7 @@ function useAgnoChat(options) {
|
|
|
362
561
|
})
|
|
363
562
|
);
|
|
364
563
|
},
|
|
365
|
-
[client, drive, userId]
|
|
564
|
+
[client, drive, setEvents, setMessages, userId]
|
|
366
565
|
);
|
|
367
566
|
const continueRun = React8.useCallback(
|
|
368
567
|
async (resolution) => {
|
|
@@ -372,7 +571,7 @@ function useAgnoChat(options) {
|
|
|
372
571
|
setError("No paused run to continue.");
|
|
373
572
|
return;
|
|
374
573
|
}
|
|
375
|
-
patchActive(null, (m) => ({ ...m, streaming: true, status: "streaming", requirements: void 0 }));
|
|
574
|
+
patchActive(null, (m) => ({ ...m, streaming: true, status: "streaming", requirements: void 0, step_requirements: void 0 }));
|
|
376
575
|
await drive(
|
|
377
576
|
(cb) => client.continueRun({
|
|
378
577
|
type: ent.type,
|
|
@@ -381,6 +580,7 @@ function useAgnoChat(options) {
|
|
|
381
580
|
sessionId: sessionIdRef.current,
|
|
382
581
|
userId,
|
|
383
582
|
tools: resolution.tools,
|
|
583
|
+
requirements: resolution.requirements,
|
|
384
584
|
stepRequirements: resolution.stepRequirements,
|
|
385
585
|
...cb
|
|
386
586
|
})
|
|
@@ -399,8 +599,12 @@ function useAgnoChat(options) {
|
|
|
399
599
|
const respondToConfirmation = React8.useCallback(
|
|
400
600
|
async (approve) => {
|
|
401
601
|
const ent = entityRef.current;
|
|
602
|
+
if (ent?.type === "team" && activeMessage?.requirements?.length) {
|
|
603
|
+
await continueRun({ requirements: activeMessage.requirements.map((r) => ({ ...r, confirmation: approve })) });
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
402
606
|
if (ent?.type === "workflow") {
|
|
403
|
-
const reqs = (activeMessage?.requirements ?? []).map((r) => ({ ...r, confirmation: approve }));
|
|
607
|
+
const reqs = activeMessage?.step_requirements?.length ? activeMessage.step_requirements.map((r) => ({ ...r, confirmed: approve })) : (activeMessage?.requirements ?? []).map((r) => ({ ...r, confirmation: approve }));
|
|
404
608
|
await continueRun({ stepRequirements: reqs });
|
|
405
609
|
return;
|
|
406
610
|
}
|
|
@@ -412,6 +616,17 @@ function useAgnoChat(options) {
|
|
|
412
616
|
const submitUserInput = React8.useCallback(
|
|
413
617
|
async (values) => {
|
|
414
618
|
const ent = entityRef.current;
|
|
619
|
+
if (ent?.type === "team" && activeMessage?.requirements?.length) {
|
|
620
|
+
const requirements = activeMessage.requirements.map((r) => ({
|
|
621
|
+
...r,
|
|
622
|
+
user_input_schema: (r.user_input_schema ?? r.tool_execution?.user_input_schema ?? []).map((f) => ({
|
|
623
|
+
...f,
|
|
624
|
+
value: f.name in values ? values[f.name] : f.value
|
|
625
|
+
}))
|
|
626
|
+
}));
|
|
627
|
+
await continueRun({ requirements });
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
415
630
|
if (ent?.type === "workflow") {
|
|
416
631
|
const reqs = (activeMessage?.requirements ?? []).map((r) => ({
|
|
417
632
|
...r,
|
|
@@ -436,15 +651,16 @@ function useAgnoChat(options) {
|
|
|
436
651
|
[activeMessage, continueRun, pausedTools]
|
|
437
652
|
);
|
|
438
653
|
const cancel = React8.useCallback(async () => {
|
|
654
|
+
channelRef.current?.buffer.flush();
|
|
439
655
|
abortRef.current?.abort();
|
|
440
656
|
channelRef.current = null;
|
|
441
657
|
const ent = entityRef.current;
|
|
442
658
|
const runId = runIdRef.current;
|
|
443
|
-
|
|
444
|
-
|
|
659
|
+
writeStatus(null, "cancelled");
|
|
660
|
+
writeActivity(null, null);
|
|
445
661
|
patchActive(null, (m) => m.streaming ? { ...m, streaming: false, status: "cancelled" } : m);
|
|
446
662
|
if (ent && runId) await client.cancelRun(ent.type, ent.id, runId, sessionIdRef.current);
|
|
447
|
-
}, [client, patchActive]);
|
|
663
|
+
}, [client, patchActive, writeActivity, writeStatus]);
|
|
448
664
|
const refreshSessions = React8.useCallback(async () => {
|
|
449
665
|
const ent = entityRef.current;
|
|
450
666
|
if (!ent) {
|
|
@@ -464,6 +680,14 @@ function useAgnoChat(options) {
|
|
|
464
680
|
setSessionsLoading(false);
|
|
465
681
|
}
|
|
466
682
|
}, [client]);
|
|
683
|
+
const clearRunView = React8.useCallback(() => {
|
|
684
|
+
activeMsgIdRef.current = null;
|
|
685
|
+
runIdRef.current = void 0;
|
|
686
|
+
setEvents([]);
|
|
687
|
+
setStatus("idle");
|
|
688
|
+
setActivity(null);
|
|
689
|
+
setError(null);
|
|
690
|
+
}, [setEvents, setStatus, setActivity, setError]);
|
|
467
691
|
const loadSession = React8.useCallback(
|
|
468
692
|
async (id) => {
|
|
469
693
|
const ent = entityRef.current;
|
|
@@ -474,21 +698,15 @@ function useAgnoChat(options) {
|
|
|
474
698
|
setSessionId(id);
|
|
475
699
|
onSessionId?.(id);
|
|
476
700
|
if (resumeRun(id)) return;
|
|
477
|
-
|
|
478
|
-
runIdRef.current = void 0;
|
|
479
|
-
setEvents([]);
|
|
480
|
-
setCurrentEvent(null);
|
|
481
|
-
setStatus("idle");
|
|
482
|
-
setActivity(null);
|
|
483
|
-
setError(null);
|
|
701
|
+
clearRunView();
|
|
484
702
|
try {
|
|
485
703
|
const runs = await client.getSessionRuns(ent.type, id, ent.db_id);
|
|
486
|
-
setMessages(
|
|
704
|
+
setMessages(chunkY34YRC5T_cjs.sessionRunsToMessages(runs));
|
|
487
705
|
} catch (err) {
|
|
488
706
|
setError(err instanceof Error ? err.message : String(err));
|
|
489
707
|
}
|
|
490
708
|
},
|
|
491
|
-
[client, onSessionId, releaseCurrentRun, resumeRun]
|
|
709
|
+
[client, clearRunView, onSessionId, releaseCurrentRun, resumeRun, setMessages]
|
|
492
710
|
);
|
|
493
711
|
const deleteSession = React8.useCallback(
|
|
494
712
|
async (id) => {
|
|
@@ -503,29 +721,27 @@ function useAgnoChat(options) {
|
|
|
503
721
|
}
|
|
504
722
|
setSessions((prev) => prev.filter((s) => s.session_id !== id));
|
|
505
723
|
if (sessionIdRef.current === id) {
|
|
724
|
+
channelRef.current?.controller.abort();
|
|
725
|
+
channelRef.current = null;
|
|
726
|
+
abortRef.current = null;
|
|
727
|
+
clearRunView();
|
|
506
728
|
sessionIdRef.current = void 0;
|
|
507
729
|
setSessionId(void 0);
|
|
508
730
|
setMessages([]);
|
|
509
731
|
}
|
|
510
732
|
}
|
|
511
733
|
},
|
|
512
|
-
[client]
|
|
734
|
+
[client, clearRunView, setMessages]
|
|
513
735
|
);
|
|
514
736
|
const reset = React8.useCallback(() => {
|
|
515
737
|
releaseCurrentRun();
|
|
516
|
-
|
|
517
|
-
runIdRef.current = void 0;
|
|
738
|
+
clearRunView();
|
|
518
739
|
sessionIdRef.current = void 0;
|
|
519
740
|
pendingSessionNameRef.current = void 0;
|
|
520
741
|
bumpedSessionRef.current = void 0;
|
|
521
742
|
setMessages([]);
|
|
522
|
-
setEvents([]);
|
|
523
|
-
setCurrentEvent(null);
|
|
524
|
-
setStatus("idle");
|
|
525
|
-
setActivity(null);
|
|
526
|
-
setError(null);
|
|
527
743
|
setSessionId(void 0);
|
|
528
|
-
}, [releaseCurrentRun]);
|
|
744
|
+
}, [clearRunView, releaseCurrentRun, setMessages]);
|
|
529
745
|
React8.useEffect(() => {
|
|
530
746
|
const background = backgroundRef.current;
|
|
531
747
|
return () => {
|
|
@@ -1226,6 +1442,16 @@ function Followups({
|
|
|
1226
1442
|
}
|
|
1227
1443
|
var isBoolField = (f) => f.field_type === "bool" || f.field_type === "boolean";
|
|
1228
1444
|
function buildAsks(message, entityType) {
|
|
1445
|
+
if (entityType === "workflow" && message.step_requirements?.length) {
|
|
1446
|
+
return message.step_requirements.map((r) => ({
|
|
1447
|
+
id: r.step_id,
|
|
1448
|
+
name: r.step_name,
|
|
1449
|
+
needsConfirmation: Boolean(r.requires_confirmation) && r.confirmed == null,
|
|
1450
|
+
fields: [],
|
|
1451
|
+
stepRequirement: r,
|
|
1452
|
+
unsupported: !r.requires_confirmation || Boolean(r.requires_user_input || r.requires_route_selection || r.requires_output_review)
|
|
1453
|
+
}));
|
|
1454
|
+
}
|
|
1229
1455
|
const fromTools = (message.tool_calls ?? []).filter((t) => t.requires_confirmation || t.requires_user_input).map((t) => ({
|
|
1230
1456
|
id: t.tool_call_id ?? `${t.tool_name}`,
|
|
1231
1457
|
name: t.tool_name,
|
|
@@ -1238,11 +1464,11 @@ function buildAsks(message, entityType) {
|
|
|
1238
1464
|
id: r.id,
|
|
1239
1465
|
name: r.tool_execution?.tool_name,
|
|
1240
1466
|
args: r.tool_execution?.tool_args,
|
|
1241
|
-
needsConfirmation: Boolean(r.tool_execution?.requires_confirmation) || r.confirmation == null,
|
|
1467
|
+
needsConfirmation: entityType === "workflow" ? Boolean(r.tool_execution?.requires_confirmation) || r.confirmation == null : Boolean(r.tool_execution?.requires_confirmation) && r.confirmation == null,
|
|
1242
1468
|
fields: r.user_input_schema ?? r.tool_execution?.user_input_schema ?? [],
|
|
1243
1469
|
requirement: r
|
|
1244
1470
|
}));
|
|
1245
|
-
if (entityType === "workflow") return fromReqs.length ? fromReqs : fromTools;
|
|
1471
|
+
if (entityType === "workflow" || entityType === "team") return fromReqs.length ? fromReqs : fromTools;
|
|
1246
1472
|
return fromTools.length ? fromTools : fromReqs;
|
|
1247
1473
|
}
|
|
1248
1474
|
function HumanInput({
|
|
@@ -1261,11 +1487,26 @@ function HumanInput({
|
|
|
1261
1487
|
const setValue = (id, name, value) => setValues((v) => ({ ...v, [id]: { ...v[id] ?? {}, [name]: value } }));
|
|
1262
1488
|
const valueFor = (ask, field) => values[ask.id]?.[field.name] ?? field.value ?? (isBoolField(field) ? false : "");
|
|
1263
1489
|
const fillFields = (ask) => ask.fields.map((f) => ({ ...f, value: valueFor(ask, f) }));
|
|
1264
|
-
const ready = asks.every((a) => !a.needsConfirmation || choices[a.id]);
|
|
1490
|
+
const ready = asks.every((a) => !a.unsupported && (!a.needsConfirmation || choices[a.id]));
|
|
1265
1491
|
const submit = () => {
|
|
1492
|
+
if (entityType === "team" && asks.every((a) => a.requirement)) {
|
|
1493
|
+
const requirements = asks.map((a) => ({
|
|
1494
|
+
...a.requirement,
|
|
1495
|
+
...a.needsConfirmation ? { confirmation: choices[a.id] === "confirm" } : {},
|
|
1496
|
+
...a.fields.length ? { user_input_schema: fillFields(a) } : {},
|
|
1497
|
+
...reasons[a.id] ? { confirmation_note: reasons[a.id] } : {}
|
|
1498
|
+
}));
|
|
1499
|
+
onResolve({ requirements });
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1266
1502
|
if (entityType === "workflow") {
|
|
1267
1503
|
const stepRequirements = asks.map((a) => {
|
|
1268
1504
|
const approved = a.needsConfirmation ? choices[a.id] === "confirm" : true;
|
|
1505
|
+
if (a.stepRequirement) return {
|
|
1506
|
+
...a.stepRequirement,
|
|
1507
|
+
confirmed: approved,
|
|
1508
|
+
...reasons[a.id] ? { rejection_feedback: reasons[a.id] } : {}
|
|
1509
|
+
};
|
|
1269
1510
|
return {
|
|
1270
1511
|
id: a.id,
|
|
1271
1512
|
confirmation: approved,
|
|
@@ -1278,7 +1519,7 @@ function HumanInput({
|
|
|
1278
1519
|
return;
|
|
1279
1520
|
}
|
|
1280
1521
|
const tools = asks.map((a) => {
|
|
1281
|
-
const base = a.tool ?? { tool_call_id: a.id, tool_name: a.name };
|
|
1522
|
+
const base = a.tool ?? a.requirement?.tool_execution ?? { tool_call_id: a.id, tool_name: a.name };
|
|
1282
1523
|
const approved = a.needsConfirmation ? choices[a.id] === "confirm" : true;
|
|
1283
1524
|
return {
|
|
1284
1525
|
...base,
|
|
@@ -1291,6 +1532,7 @@ function HumanInput({
|
|
|
1291
1532
|
};
|
|
1292
1533
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx("agno-hitl", className), children: [
|
|
1293
1534
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "agno-hitl__title", children: "Your input is needed" }),
|
|
1535
|
+
asks.some((a) => a.unsupported) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "agno-hitl__notice", role: "status", children: "This workflow needs an input type this chat does not support yet." }),
|
|
1294
1536
|
asks.map((ask) => {
|
|
1295
1537
|
const choice = choices[ask.id];
|
|
1296
1538
|
const hasArgs = ask.args && Object.keys(ask.args).length > 0;
|
|
@@ -1535,73 +1777,6 @@ var SourcesProvider = SourcesContext.Provider;
|
|
|
1535
1777
|
function useSources() {
|
|
1536
1778
|
return React8.useContext(SourcesContext);
|
|
1537
1779
|
}
|
|
1538
|
-
var THEMES = { light: "github-light", dark: "monokai" };
|
|
1539
|
-
var highlighter;
|
|
1540
|
-
var booting;
|
|
1541
|
-
var loading = /* @__PURE__ */ new Map();
|
|
1542
|
-
var loaded = /* @__PURE__ */ new Set();
|
|
1543
|
-
var unsupported = /* @__PURE__ */ new Set();
|
|
1544
|
-
async function boot() {
|
|
1545
|
-
if (highlighter) return highlighter;
|
|
1546
|
-
booting ?? (booting = (async () => {
|
|
1547
|
-
const [{ createHighlighterCore }, { createJavaScriptRegexEngine }, { bundledThemes }] = await Promise.all([import('shiki/core'), import('shiki/engine/javascript'), import('shiki/themes')]);
|
|
1548
|
-
highlighter = await createHighlighterCore({
|
|
1549
|
-
themes: [bundledThemes[THEMES.light], bundledThemes[THEMES.dark]],
|
|
1550
|
-
langs: [],
|
|
1551
|
-
// No WASM: the JS engine keeps this a plain import. `forgiving` skips
|
|
1552
|
-
// the odd grammar rule it can't translate rather than failing the block.
|
|
1553
|
-
engine: createJavaScriptRegexEngine({ forgiving: true })
|
|
1554
|
-
});
|
|
1555
|
-
return highlighter;
|
|
1556
|
-
})());
|
|
1557
|
-
return booting;
|
|
1558
|
-
}
|
|
1559
|
-
function ensureLanguage(lang) {
|
|
1560
|
-
let pending = loading.get(lang);
|
|
1561
|
-
if (!pending) {
|
|
1562
|
-
pending = (async () => {
|
|
1563
|
-
const [core, { bundledLanguages }] = await Promise.all([boot(), import('shiki/langs')]);
|
|
1564
|
-
const grammar = bundledLanguages[lang];
|
|
1565
|
-
if (!grammar) {
|
|
1566
|
-
unsupported.add(lang);
|
|
1567
|
-
return;
|
|
1568
|
-
}
|
|
1569
|
-
await core.loadLanguage(grammar);
|
|
1570
|
-
loaded.add(lang);
|
|
1571
|
-
})().catch(() => {
|
|
1572
|
-
unsupported.add(lang);
|
|
1573
|
-
});
|
|
1574
|
-
loading.set(lang, pending);
|
|
1575
|
-
}
|
|
1576
|
-
return pending;
|
|
1577
|
-
}
|
|
1578
|
-
function normalizeLanguage(language) {
|
|
1579
|
-
const lang = language?.trim().toLowerCase();
|
|
1580
|
-
return lang || void 0;
|
|
1581
|
-
}
|
|
1582
|
-
function useHighlight(code, language) {
|
|
1583
|
-
const [, rerender] = React8.useReducer((n) => n + 1, 0);
|
|
1584
|
-
const lang = normalizeLanguage(language);
|
|
1585
|
-
const ready = Boolean(lang && loaded.has(lang));
|
|
1586
|
-
React8.useEffect(() => {
|
|
1587
|
-
if (!lang || ready || unsupported.has(lang)) return;
|
|
1588
|
-
let cancelled = false;
|
|
1589
|
-
void ensureLanguage(lang).then(() => {
|
|
1590
|
-
if (!cancelled) rerender();
|
|
1591
|
-
});
|
|
1592
|
-
return () => {
|
|
1593
|
-
cancelled = true;
|
|
1594
|
-
};
|
|
1595
|
-
}, [lang, ready]);
|
|
1596
|
-
return React8.useMemo(() => {
|
|
1597
|
-
if (!lang || !ready || !highlighter) return null;
|
|
1598
|
-
try {
|
|
1599
|
-
return highlighter.codeToTokens(code, { lang, themes: THEMES, defaultColor: false }).tokens;
|
|
1600
|
-
} catch {
|
|
1601
|
-
return null;
|
|
1602
|
-
}
|
|
1603
|
-
}, [code, lang, ready]);
|
|
1604
|
-
}
|
|
1605
1780
|
var useIsomorphicLayoutEffect = typeof window === "undefined" ? React8.useEffect : React8.useLayoutEffect;
|
|
1606
1781
|
var caches = /* @__PURE__ */ new WeakMap();
|
|
1607
1782
|
var inflight = /* @__PURE__ */ new WeakMap();
|
|
@@ -1807,6 +1982,100 @@ function HoverPreview({
|
|
|
1807
1982
|
}
|
|
1808
1983
|
);
|
|
1809
1984
|
}
|
|
1985
|
+
function sourceForUrl(url, sources) {
|
|
1986
|
+
return url ? sources.find((source) => source.url === url) : void 0;
|
|
1987
|
+
}
|
|
1988
|
+
function citationForLink(label2, href, ctx) {
|
|
1989
|
+
if (!/^\d+$/.test(label2.trim())) return void 0;
|
|
1990
|
+
return sourceForUrl(href, ctx.sources) ?? ctx.sources.find((source) => source.index === Number(label2.trim()));
|
|
1991
|
+
}
|
|
1992
|
+
function CitationMarker({
|
|
1993
|
+
source,
|
|
1994
|
+
className,
|
|
1995
|
+
Link: Link2
|
|
1996
|
+
}) {
|
|
1997
|
+
const props = {
|
|
1998
|
+
className: cx("agno-cite", className),
|
|
1999
|
+
href: source.url ?? `#${source.anchorId}`,
|
|
2000
|
+
"aria-label": `Source ${source.index}: ${source.title}`
|
|
2001
|
+
};
|
|
2002
|
+
return /* @__PURE__ */ jsxRuntime.jsx(HoverPreview, { source, className: "agno-cite__wrap", children: Link2 && source.url ? /* @__PURE__ */ jsxRuntime.jsx(Link2, { ...props, children: source.index }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2003
|
+
"a",
|
|
2004
|
+
{
|
|
2005
|
+
...props,
|
|
2006
|
+
target: source.url ? "_blank" : void 0,
|
|
2007
|
+
rel: source.url ? "noreferrer noopener" : void 0,
|
|
2008
|
+
children: source.index
|
|
2009
|
+
}
|
|
2010
|
+
) });
|
|
2011
|
+
}
|
|
2012
|
+
var THEMES = { light: "github-light", dark: "monokai" };
|
|
2013
|
+
var highlighter;
|
|
2014
|
+
var booting;
|
|
2015
|
+
var loading = /* @__PURE__ */ new Map();
|
|
2016
|
+
var loaded = /* @__PURE__ */ new Set();
|
|
2017
|
+
var unsupported = /* @__PURE__ */ new Set();
|
|
2018
|
+
async function boot() {
|
|
2019
|
+
if (highlighter) return highlighter;
|
|
2020
|
+
booting ?? (booting = (async () => {
|
|
2021
|
+
const [{ createHighlighterCore }, { createJavaScriptRegexEngine }, { bundledThemes }] = await Promise.all([import('shiki/core'), import('shiki/engine/javascript'), import('shiki/themes')]);
|
|
2022
|
+
highlighter = await createHighlighterCore({
|
|
2023
|
+
themes: [bundledThemes[THEMES.light], bundledThemes[THEMES.dark]],
|
|
2024
|
+
langs: [],
|
|
2025
|
+
// No WASM: the JS engine keeps this a plain import. `forgiving` skips
|
|
2026
|
+
// the odd grammar rule it can't translate rather than failing the block.
|
|
2027
|
+
engine: createJavaScriptRegexEngine({ forgiving: true })
|
|
2028
|
+
});
|
|
2029
|
+
return highlighter;
|
|
2030
|
+
})());
|
|
2031
|
+
return booting;
|
|
2032
|
+
}
|
|
2033
|
+
function ensureLanguage(lang) {
|
|
2034
|
+
let pending = loading.get(lang);
|
|
2035
|
+
if (!pending) {
|
|
2036
|
+
pending = (async () => {
|
|
2037
|
+
const [core, { bundledLanguages }] = await Promise.all([boot(), import('shiki/langs')]);
|
|
2038
|
+
const grammar = bundledLanguages[lang];
|
|
2039
|
+
if (!grammar) {
|
|
2040
|
+
unsupported.add(lang);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
await core.loadLanguage(grammar);
|
|
2044
|
+
loaded.add(lang);
|
|
2045
|
+
})().catch(() => {
|
|
2046
|
+
unsupported.add(lang);
|
|
2047
|
+
});
|
|
2048
|
+
loading.set(lang, pending);
|
|
2049
|
+
}
|
|
2050
|
+
return pending;
|
|
2051
|
+
}
|
|
2052
|
+
function normalizeLanguage(language) {
|
|
2053
|
+
const lang = language?.trim().toLowerCase();
|
|
2054
|
+
return lang || void 0;
|
|
2055
|
+
}
|
|
2056
|
+
function useHighlight(code, language) {
|
|
2057
|
+
const [, rerender] = React8.useReducer((n) => n + 1, 0);
|
|
2058
|
+
const lang = normalizeLanguage(language);
|
|
2059
|
+
const ready = Boolean(lang && loaded.has(lang));
|
|
2060
|
+
React8.useEffect(() => {
|
|
2061
|
+
if (!lang || ready || unsupported.has(lang)) return;
|
|
2062
|
+
let cancelled = false;
|
|
2063
|
+
void ensureLanguage(lang).then(() => {
|
|
2064
|
+
if (!cancelled) rerender();
|
|
2065
|
+
});
|
|
2066
|
+
return () => {
|
|
2067
|
+
cancelled = true;
|
|
2068
|
+
};
|
|
2069
|
+
}, [lang, ready]);
|
|
2070
|
+
return React8.useMemo(() => {
|
|
2071
|
+
if (!lang || !ready || !highlighter) return null;
|
|
2072
|
+
try {
|
|
2073
|
+
return highlighter.codeToTokens(code, { lang, themes: THEMES, defaultColor: false }).tokens;
|
|
2074
|
+
} catch {
|
|
2075
|
+
return null;
|
|
2076
|
+
}
|
|
2077
|
+
}, [code, lang, ready]);
|
|
2078
|
+
}
|
|
1810
2079
|
var COPIED_FOR = 1600;
|
|
1811
2080
|
var CLIPBOARD_TIMEOUT = 400;
|
|
1812
2081
|
async function writeClipboard(text) {
|
|
@@ -1855,58 +2124,24 @@ function CopyButton({ text, label: label2 = "Copy", size = 14, className }) {
|
|
|
1855
2124
|
}
|
|
1856
2125
|
);
|
|
1857
2126
|
}
|
|
1858
|
-
function el(tag, className) {
|
|
1859
|
-
return function Element({ node: _node, className: _theirs, ...rest }) {
|
|
1860
|
-
return React8__default.default.createElement(tag, { className, ...rest });
|
|
1861
|
-
};
|
|
1862
|
-
}
|
|
1863
|
-
function sourceForUrl(url, sources) {
|
|
1864
|
-
return url ? sources.find((s) => s.url === url) : void 0;
|
|
1865
|
-
}
|
|
1866
|
-
function citationForLink(label2, href, ctx) {
|
|
1867
|
-
if (!/^\d+$/.test(label2.trim())) return void 0;
|
|
1868
|
-
return sourceForUrl(href, ctx.sources) ?? ctx.sources.find((s) => s.index === Number(label2.trim()));
|
|
1869
|
-
}
|
|
1870
|
-
function labelOf(children) {
|
|
1871
|
-
if (typeof children === "string") return children;
|
|
1872
|
-
if (Array.isArray(children) && children.length === 1 && typeof children[0] === "string") {
|
|
1873
|
-
return children[0];
|
|
1874
|
-
}
|
|
1875
|
-
return "";
|
|
1876
|
-
}
|
|
1877
|
-
function CitationMarker({
|
|
1878
|
-
source,
|
|
1879
|
-
className,
|
|
1880
|
-
Link
|
|
1881
|
-
}) {
|
|
1882
|
-
const props = {
|
|
1883
|
-
className: cx("agno-cite", className),
|
|
1884
|
-
href: source.url ?? `#${source.anchorId}`,
|
|
1885
|
-
"aria-label": `Source ${source.index}: ${source.title}`
|
|
1886
|
-
};
|
|
1887
|
-
return /* @__PURE__ */ jsxRuntime.jsx(HoverPreview, { source, className: "agno-cite__wrap", children: Link && source.url ? /* @__PURE__ */ jsxRuntime.jsx(Link, { ...props, children: source.index }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1888
|
-
"a",
|
|
1889
|
-
{
|
|
1890
|
-
...props,
|
|
1891
|
-
target: source.url ? "_blank" : void 0,
|
|
1892
|
-
rel: source.url ? "noreferrer noopener" : void 0,
|
|
1893
|
-
children: source.index
|
|
1894
|
-
}
|
|
1895
|
-
) });
|
|
1896
|
-
}
|
|
1897
2127
|
function textOf(children) {
|
|
1898
2128
|
if (typeof children === "string") return children;
|
|
1899
2129
|
if (typeof children === "number") return String(children);
|
|
1900
2130
|
if (Array.isArray(children)) return children.map(textOf).join("");
|
|
1901
|
-
if (React8__default.default.isValidElement(children))
|
|
2131
|
+
if (React8__default.default.isValidElement(children))
|
|
2132
|
+
return textOf(children.props.children);
|
|
1902
2133
|
return "";
|
|
1903
2134
|
}
|
|
1904
2135
|
function fencedCode(children) {
|
|
1905
2136
|
const child = Array.isArray(children) ? children[0] : children;
|
|
1906
|
-
if (!React8__default.default.isValidElement(
|
|
2137
|
+
if (!React8__default.default.isValidElement(
|
|
2138
|
+
child
|
|
2139
|
+
)) {
|
|
1907
2140
|
return { code: textOf(children) };
|
|
1908
2141
|
}
|
|
1909
|
-
const language = /(?:^|\s)language-([^\s]+)/.exec(
|
|
2142
|
+
const language = /(?:^|\s)language-([^\s]+)/.exec(
|
|
2143
|
+
child.props.className ?? ""
|
|
2144
|
+
)?.[1];
|
|
1910
2145
|
return { language, code: textOf(child.props.children).replace(/\n$/, "") };
|
|
1911
2146
|
}
|
|
1912
2147
|
function plainLines(code) {
|
|
@@ -1915,93 +2150,159 @@ function plainLines(code) {
|
|
|
1915
2150
|
function CodeBlock({
|
|
1916
2151
|
children,
|
|
1917
2152
|
copyClass,
|
|
1918
|
-
codeCopy
|
|
2153
|
+
codeCopy,
|
|
2154
|
+
streaming
|
|
1919
2155
|
}) {
|
|
1920
2156
|
const { language, code } = React8.useMemo(() => fencedCode(children), [children]);
|
|
1921
|
-
const highlighted = useHighlight(code, language);
|
|
1922
|
-
const lines = highlighted ?? plainLines(code);
|
|
2157
|
+
const highlighted = useHighlight(streaming ? "" : code, language);
|
|
2158
|
+
const lines = streaming ? plainLines(code) : highlighted ?? plainLines(code);
|
|
1923
2159
|
const label2 = normalizeLanguage(language) ?? "text";
|
|
1924
2160
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "agno-md-code-block", "data-language": label2, children: [
|
|
1925
2161
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "agno-md-code-head", children: [
|
|
1926
2162
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "agno-md-code-lang", children: label2 }),
|
|
1927
|
-
codeCopy && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2163
|
+
codeCopy && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2164
|
+
CopyButton,
|
|
2165
|
+
{
|
|
2166
|
+
className: cx("agno-md-copy", copyClass),
|
|
2167
|
+
text: () => code,
|
|
2168
|
+
label: "Copy code",
|
|
2169
|
+
size: 13
|
|
2170
|
+
}
|
|
2171
|
+
)
|
|
1928
2172
|
] }),
|
|
1929
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2173
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2174
|
+
"pre",
|
|
2175
|
+
{
|
|
2176
|
+
className: "agno-md-pre",
|
|
2177
|
+
style: {
|
|
2178
|
+
"--agno-code-gutter": `${String(lines.length).length}ch`
|
|
2179
|
+
},
|
|
2180
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("code", { className: language ? `language-${language}` : void 0, children: lines.map((tokens, i) => /* @__PURE__ */ jsxRuntime.jsxs(React8__default.default.Fragment, { children: [
|
|
2181
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "agno-md-line", children: tokens.map((token, j) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2182
|
+
"span",
|
|
2183
|
+
{
|
|
2184
|
+
style: token.htmlStyle,
|
|
2185
|
+
children: token.content
|
|
2186
|
+
},
|
|
2187
|
+
j
|
|
2188
|
+
)) }),
|
|
2189
|
+
i < lines.length - 1 && "\n"
|
|
2190
|
+
] }, i)) })
|
|
2191
|
+
}
|
|
2192
|
+
)
|
|
1933
2193
|
] });
|
|
1934
2194
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
2195
|
+
var InlineRenderContext = React8.createContext({
|
|
2196
|
+
sources: [],
|
|
2197
|
+
canResolve: false,
|
|
2198
|
+
codeCopy: true
|
|
2199
|
+
});
|
|
2200
|
+
function el(tag, className) {
|
|
2201
|
+
return function Element({
|
|
1937
2202
|
node: _node,
|
|
1938
2203
|
className: _theirs,
|
|
1939
|
-
href,
|
|
1940
|
-
children,
|
|
1941
2204
|
...rest
|
|
1942
2205
|
}) {
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2206
|
+
return React8__default.default.createElement(tag, { className, ...rest });
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
function Link({
|
|
2210
|
+
node: _node,
|
|
2211
|
+
className: _theirs,
|
|
2212
|
+
href,
|
|
2213
|
+
children,
|
|
2214
|
+
...rest
|
|
2215
|
+
}) {
|
|
2216
|
+
const ctx = React8.useContext(InlineRenderContext);
|
|
2217
|
+
const cited = citationForLink(textOf(children), href, ctx);
|
|
2218
|
+
if (cited)
|
|
1948
2219
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1949
|
-
|
|
2220
|
+
CitationMarker,
|
|
1950
2221
|
{
|
|
1951
|
-
source:
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
kind: "url",
|
|
1955
|
-
url: href,
|
|
1956
|
-
title: labelOf(children) || sourceHost(href) || href
|
|
1957
|
-
},
|
|
1958
|
-
children: link
|
|
2222
|
+
source: cited,
|
|
2223
|
+
className: ctx.markerClass,
|
|
2224
|
+
Link: ctx.Link
|
|
1959
2225
|
}
|
|
1960
2226
|
);
|
|
1961
|
-
};
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
return
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
sub: el("sub"),
|
|
1977
|
-
sup: el("sup"),
|
|
1978
|
-
h1: el("h2", "agno-md-heading"),
|
|
1979
|
-
h2: el("h3", "agno-md-heading"),
|
|
1980
|
-
h3: el("h4", "agno-md-heading"),
|
|
1981
|
-
h4: el("h5", "agno-md-heading"),
|
|
1982
|
-
h5: el("h6", "agno-md-heading"),
|
|
1983
|
-
h6: el("h6", "agno-md-heading"),
|
|
1984
|
-
ul: el("ul", "agno-md-list"),
|
|
1985
|
-
ol: el("ol", "agno-md-list"),
|
|
1986
|
-
li: el("li"),
|
|
1987
|
-
pre: function Pre({ children }) {
|
|
1988
|
-
return /* @__PURE__ */ jsxRuntime.jsx(CodeBlock, { copyClass: ctx.copyClass, codeCopy: ctx.codeCopy, children });
|
|
1989
|
-
},
|
|
1990
|
-
blockquote: el("blockquote", "agno-md-quote"),
|
|
1991
|
-
hr: el("hr", "agno-md-rule"),
|
|
1992
|
-
table: function Table({ node: _node, className: _theirs, ...rest }) {
|
|
1993
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "agno-md-table-wrap", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: "agno-md-table", ...rest }) });
|
|
1994
|
-
},
|
|
1995
|
-
thead: el("thead"),
|
|
1996
|
-
tbody: el("tbody"),
|
|
1997
|
-
tr: el("tr"),
|
|
1998
|
-
th: el("th"),
|
|
1999
|
-
td: el("td"),
|
|
2000
|
-
img: function Image({ node: _node, className: _theirs, ...rest }) {
|
|
2001
|
-
return /* @__PURE__ */ jsxRuntime.jsx("img", { className: "agno-md-img", ...rest });
|
|
2227
|
+
const link = ctx.Link && href ? /* @__PURE__ */ jsxRuntime.jsx(ctx.Link, { href, ...rest, children }) : /* @__PURE__ */ jsxRuntime.jsx("a", { href, target: "_blank", rel: "noreferrer noopener", ...rest, children });
|
|
2228
|
+
const source = sourceForUrl(href, ctx.sources);
|
|
2229
|
+
if (!href || !/^https?:\/\//i.test(href) || !source && !ctx.canResolve)
|
|
2230
|
+
return link;
|
|
2231
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2232
|
+
HoverPreview,
|
|
2233
|
+
{
|
|
2234
|
+
source: source ?? {
|
|
2235
|
+
index: 0,
|
|
2236
|
+
anchorId: "",
|
|
2237
|
+
kind: "url",
|
|
2238
|
+
url: href,
|
|
2239
|
+
title: textOf(children) || sourceHost(href) || href
|
|
2240
|
+
},
|
|
2241
|
+
children: link
|
|
2002
2242
|
}
|
|
2003
|
-
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
2245
|
+
function Code({ node: _node, className, ...rest }) {
|
|
2246
|
+
const fenced = typeof className === "string" && className.includes("language-");
|
|
2247
|
+
return /* @__PURE__ */ jsxRuntime.jsx("code", { className: fenced ? className : "agno-md-code", ...rest });
|
|
2004
2248
|
}
|
|
2249
|
+
function Pre({ children }) {
|
|
2250
|
+
const ctx = React8.useContext(InlineRenderContext);
|
|
2251
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2252
|
+
CodeBlock,
|
|
2253
|
+
{
|
|
2254
|
+
copyClass: ctx.copyClass,
|
|
2255
|
+
codeCopy: ctx.codeCopy,
|
|
2256
|
+
streaming: ctx.streaming,
|
|
2257
|
+
children
|
|
2258
|
+
}
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
function Table({ node: _node, className: _theirs, ...rest }) {
|
|
2262
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "agno-md-table-wrap", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: "agno-md-table", ...rest }) });
|
|
2263
|
+
}
|
|
2264
|
+
function Image({ node: _node, className: _theirs, ...rest }) {
|
|
2265
|
+
return /* @__PURE__ */ jsxRuntime.jsx("img", { className: "agno-md-img", ...rest });
|
|
2266
|
+
}
|
|
2267
|
+
var MARKDOWN_COMPONENTS = {
|
|
2268
|
+
a: Link,
|
|
2269
|
+
code: Code,
|
|
2270
|
+
p: el("p", "agno-md-p"),
|
|
2271
|
+
// Streamdown renders `**bold**` as a Tailwind-classed <span>, which is not
|
|
2272
|
+
// bold anywhere Tailwind isn't. These stay real elements, styled by the
|
|
2273
|
+
// browser and read correctly by a screen reader.
|
|
2274
|
+
strong: el("strong"),
|
|
2275
|
+
em: el("em"),
|
|
2276
|
+
del: el("del"),
|
|
2277
|
+
sub: el("sub"),
|
|
2278
|
+
sup: el("sup"),
|
|
2279
|
+
h1: el("h2", "agno-md-heading"),
|
|
2280
|
+
h2: el("h3", "agno-md-heading"),
|
|
2281
|
+
h3: el("h4", "agno-md-heading"),
|
|
2282
|
+
h4: el("h5", "agno-md-heading"),
|
|
2283
|
+
h5: el("h6", "agno-md-heading"),
|
|
2284
|
+
h6: el("h6", "agno-md-heading"),
|
|
2285
|
+
ul: el("ul", "agno-md-list"),
|
|
2286
|
+
ol: el("ol", "agno-md-list"),
|
|
2287
|
+
li: el("li"),
|
|
2288
|
+
pre: Pre,
|
|
2289
|
+
blockquote: el("blockquote", "agno-md-quote"),
|
|
2290
|
+
hr: el("hr", "agno-md-rule"),
|
|
2291
|
+
table: Table,
|
|
2292
|
+
thead: el("thead"),
|
|
2293
|
+
tbody: el("tbody"),
|
|
2294
|
+
tr: el("tr"),
|
|
2295
|
+
th: el("th"),
|
|
2296
|
+
td: el("td"),
|
|
2297
|
+
img: Image
|
|
2298
|
+
};
|
|
2299
|
+
var STREAMING_MOTION = {
|
|
2300
|
+
animation: "fadeIn",
|
|
2301
|
+
duration: 400,
|
|
2302
|
+
easing: "ease-out",
|
|
2303
|
+
sep: "word",
|
|
2304
|
+
stagger: 0
|
|
2305
|
+
};
|
|
2005
2306
|
function Markdown({
|
|
2006
2307
|
content,
|
|
2007
2308
|
className,
|
|
@@ -2018,30 +2319,33 @@ function Markdown({
|
|
|
2018
2319
|
const providerLink = useLinkComponent();
|
|
2019
2320
|
const cited = sources ?? fromMessage;
|
|
2020
2321
|
const copy = codeCopy ?? fromProvider ?? true;
|
|
2021
|
-
const
|
|
2022
|
-
const
|
|
2023
|
-
() =>
|
|
2322
|
+
const Link2 = linkComponent ?? providerLink;
|
|
2323
|
+
const inlineContext = React8.useMemo(
|
|
2324
|
+
() => ({
|
|
2024
2325
|
sources: cited,
|
|
2025
2326
|
canResolve,
|
|
2026
2327
|
markerClass: cn.citationMarker,
|
|
2027
2328
|
copyClass: cn.copyButton,
|
|
2028
2329
|
codeCopy: copy,
|
|
2029
|
-
Link
|
|
2330
|
+
Link: Link2,
|
|
2331
|
+
streaming
|
|
2030
2332
|
}),
|
|
2031
|
-
[cited, canResolve, cn.citationMarker, cn.copyButton, copy,
|
|
2333
|
+
[cited, canResolve, cn.citationMarker, cn.copyButton, copy, Link2, streaming]
|
|
2032
2334
|
);
|
|
2033
2335
|
const text = React8.useMemo(() => linkCitations(content, cited), [content, cited]);
|
|
2034
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2336
|
+
return /* @__PURE__ */ jsxRuntime.jsx(InlineRenderContext.Provider, { value: inlineContext, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2035
2337
|
streamdown.Streamdown,
|
|
2036
2338
|
{
|
|
2037
2339
|
className: cx("agno-md", className),
|
|
2038
|
-
components,
|
|
2340
|
+
components: MARKDOWN_COMPONENTS,
|
|
2039
2341
|
mode: streaming ? "streaming" : "static",
|
|
2040
2342
|
parseIncompleteMarkdown: streaming !== false,
|
|
2343
|
+
animated: streaming ? STREAMING_MOTION : false,
|
|
2344
|
+
isAnimating: Boolean(streaming),
|
|
2041
2345
|
...options,
|
|
2042
2346
|
children: text
|
|
2043
2347
|
}
|
|
2044
|
-
);
|
|
2348
|
+
) });
|
|
2045
2349
|
}
|
|
2046
2350
|
function statusOf(tool) {
|
|
2047
2351
|
if (tool.tool_call_error) return { label: "error", cls: "error" };
|
|
@@ -2112,7 +2416,7 @@ function isNoiseEvent(e) {
|
|
|
2112
2416
|
}
|
|
2113
2417
|
var isMemoryEvent = (e) => eventName(e).includes("MemoryUpdate");
|
|
2114
2418
|
var isMemoryCompleted = (e) => eventName(e).includes("MemoryUpdateCompleted");
|
|
2115
|
-
var isReasoningEvent = (e) =>
|
|
2419
|
+
var isReasoningEvent = (e) => chunkY34YRC5T_cjs.isReasoningStepEvent(e) || chunkY34YRC5T_cjs.isReasoningCompletedEvent(e) || eventName(e).includes("ReasoningStarted");
|
|
2116
2420
|
function formatDuration(seconds) {
|
|
2117
2421
|
return seconds < 10 ? `${seconds.toFixed(1)}s` : `${Math.round(seconds)}s`;
|
|
2118
2422
|
}
|
|
@@ -2146,14 +2450,14 @@ function stepsFromEvents(message, { hideReasoning, hideTools }) {
|
|
|
2146
2450
|
if (member) put(`member:${runId}`, { kind: "member", id: `member-${runId}`, member });
|
|
2147
2451
|
continue;
|
|
2148
2452
|
}
|
|
2149
|
-
if (
|
|
2453
|
+
if (chunkY34YRC5T_cjs.isToolEvent(e)) {
|
|
2150
2454
|
if (hideTools) continue;
|
|
2151
|
-
for (const tool of
|
|
2455
|
+
for (const tool of chunkY34YRC5T_cjs.toolsFromEvent(e)) {
|
|
2152
2456
|
const key = `tool:${tool.tool_call_id ?? tool.tool_name}`;
|
|
2153
2457
|
const at = indexOf.get(key);
|
|
2154
2458
|
const previous = at != null ? steps[at].tool : void 0;
|
|
2155
2459
|
const merged = { ...previous, ...tool };
|
|
2156
|
-
if (!
|
|
2460
|
+
if (!chunkY34YRC5T_cjs.isToolCompletedEvent(e) && previous?.result != null) merged.result = previous.result;
|
|
2157
2461
|
put(key, { kind: "tool", id: key, tool: merged });
|
|
2158
2462
|
}
|
|
2159
2463
|
continue;
|
|
@@ -2163,8 +2467,8 @@ function stepsFromEvents(message, { hideReasoning, hideTools }) {
|
|
|
2163
2467
|
const key = `reasoning:${e.run_id ?? "run"}`;
|
|
2164
2468
|
const at = indexOf.get(key);
|
|
2165
2469
|
const previous = at != null ? steps[at].steps : [];
|
|
2166
|
-
const incoming =
|
|
2167
|
-
const completed =
|
|
2470
|
+
const incoming = chunkY34YRC5T_cjs.reasoningStepsFromEvent(e);
|
|
2471
|
+
const completed = chunkY34YRC5T_cjs.isReasoningCompletedEvent(e);
|
|
2168
2472
|
put(key, {
|
|
2169
2473
|
kind: "reasoning",
|
|
2170
2474
|
id: key,
|
|
@@ -2199,7 +2503,7 @@ function stepsFromEvents(message, { hideReasoning, hideTools }) {
|
|
|
2199
2503
|
label: "Run Continued",
|
|
2200
2504
|
icon: "continued"
|
|
2201
2505
|
});
|
|
2202
|
-
} else if (
|
|
2506
|
+
} else if (chunkY34YRC5T_cjs.isCompletedEvent(e)) {
|
|
2203
2507
|
put(`completed:${runKey}`, {
|
|
2204
2508
|
kind: "status",
|
|
2205
2509
|
id: `completed-${runKey}`,
|
|
@@ -2207,16 +2511,16 @@ function stepsFromEvents(message, { hideReasoning, hideTools }) {
|
|
|
2207
2511
|
detail: durationOf(e),
|
|
2208
2512
|
icon: "run"
|
|
2209
2513
|
});
|
|
2210
|
-
} else if (
|
|
2514
|
+
} else if (chunkY34YRC5T_cjs.isPausedEvent(e)) {
|
|
2211
2515
|
put(`paused:${runKey}`, { kind: "status", id: `paused-${runKey}`, label: "Run Paused", icon: "run" });
|
|
2212
|
-
} else if (
|
|
2516
|
+
} else if (chunkY34YRC5T_cjs.isCancelledEvent(e)) {
|
|
2213
2517
|
put(`cancelled:${runKey}`, {
|
|
2214
2518
|
kind: "status",
|
|
2215
2519
|
id: `cancelled-${runKey}`,
|
|
2216
2520
|
label: "Run Cancelled",
|
|
2217
2521
|
icon: "run"
|
|
2218
2522
|
});
|
|
2219
|
-
} else if (
|
|
2523
|
+
} else if (chunkY34YRC5T_cjs.isErrorEvent(e)) {
|
|
2220
2524
|
const detail = typeof e.content === "string" ? e.content : e.error;
|
|
2221
2525
|
put(`error:${runKey}`, { kind: "status", id: `error-${runKey}`, label: detail || "Run Error", icon: "run" });
|
|
2222
2526
|
}
|
|
@@ -2264,7 +2568,7 @@ function runDuration(message) {
|
|
|
2264
2568
|
function liveActivity(message) {
|
|
2265
2569
|
const events = message.events ?? [];
|
|
2266
2570
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
2267
|
-
const label2 =
|
|
2571
|
+
const label2 = chunkY34YRC5T_cjs.activityLabel(events[i]);
|
|
2268
2572
|
if (label2) return label2;
|
|
2269
2573
|
}
|
|
2270
2574
|
return message.activity ?? null;
|
|
@@ -2439,7 +2743,7 @@ function SourceCard({
|
|
|
2439
2743
|
className
|
|
2440
2744
|
}) {
|
|
2441
2745
|
const cn = useResolvedClassNames();
|
|
2442
|
-
const
|
|
2746
|
+
const Link2 = useLinkComponent();
|
|
2443
2747
|
const { preview } = useLinkPreview(source.url, false);
|
|
2444
2748
|
const body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2445
2749
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2455,8 +2759,8 @@ function SourceCard({
|
|
|
2455
2759
|
source.url && /* @__PURE__ */ jsxRuntime.jsx(LinkIcon, { className: "agno-source__link" })
|
|
2456
2760
|
] });
|
|
2457
2761
|
const classes = cx("agno-source", `agno-source--${source.kind}`, cn.sourceCard, className);
|
|
2458
|
-
if (source.url &&
|
|
2459
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2762
|
+
if (source.url && Link2) {
|
|
2763
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Link2, { id: source.anchorId, className: classes, href: source.url, title: source.url, children: body });
|
|
2460
2764
|
}
|
|
2461
2765
|
return source.url ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2462
2766
|
"a",
|
|
@@ -2689,10 +2993,7 @@ function Message({
|
|
|
2689
2993
|
classNames: cn
|
|
2690
2994
|
}
|
|
2691
2995
|
),
|
|
2692
|
-
content ? /* @__PURE__ */ jsxRuntime.
|
|
2693
|
-
renderMarkdown ? renderMarkdown(content) : /* @__PURE__ */ jsxRuntime.jsx(Markdown, { content, className: cn.markdown, streaming: message.streaming }),
|
|
2694
|
-
message.streaming && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "agno-msg__caret", "aria-hidden": true })
|
|
2695
|
-
] }) : isAgent && message.streaming && hasActivity && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "agno-msg__activity", role: "status", "aria-live": "polite", children: [
|
|
2996
|
+
content ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cx("agno-msg__content", cn.messageContent), children: renderMarkdown ? renderMarkdown(content) : /* @__PURE__ */ jsxRuntime.jsx(Markdown, { content, className: cn.markdown, streaming: message.streaming }) }) : isAgent && message.streaming && hasActivity && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "agno-msg__activity", role: "status", "aria-live": "polite", children: [
|
|
2696
2997
|
/* @__PURE__ */ jsxRuntime.jsx(GridLoader, {}),
|
|
2697
2998
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "agno-msg__activity-label", children: activity ?? "Working..." })
|
|
2698
2999
|
] }),
|
|
@@ -3193,7 +3494,7 @@ function SessionList({
|
|
|
3193
3494
|
}
|
|
3194
3495
|
function AgnoChat(props) {
|
|
3195
3496
|
const client = React8.useMemo(
|
|
3196
|
-
() => props.client ?? new
|
|
3497
|
+
() => props.client ?? new chunkY34YRC5T_cjs.AgnoClient({ baseUrl: props.baseUrl ?? "", headers: props.headers }),
|
|
3197
3498
|
[props.client, props.baseUrl, props.headers]
|
|
3198
3499
|
);
|
|
3199
3500
|
const [discovered, setDiscovered] = React8.useState(props.entities ?? []);
|
|
@@ -3214,7 +3515,7 @@ function AgnoChat(props) {
|
|
|
3214
3515
|
};
|
|
3215
3516
|
}, [client, props.entity, props.entities, props.showEntityPicker]);
|
|
3216
3517
|
const entity = props.entity ?? selected;
|
|
3217
|
-
const chat = useAgnoChat({ client, entity, userId: props.userId });
|
|
3518
|
+
const chat = useAgnoChat({ client, entity, userId: props.userId, streaming: props.streaming });
|
|
3218
3519
|
const { refreshSessions } = chat;
|
|
3219
3520
|
React8.useEffect(() => {
|
|
3220
3521
|
if (props.showSessions && entity) refreshSessions();
|
|
@@ -3498,7 +3799,7 @@ function fold(events) {
|
|
|
3498
3799
|
last.created_at = e.created_at ?? last.created_at;
|
|
3499
3800
|
continue;
|
|
3500
3801
|
}
|
|
3501
|
-
rows.push({ event: name, source, count: 1, created_at: e.created_at, detail:
|
|
3802
|
+
rows.push({ event: name, source, count: 1, created_at: e.created_at, detail: chunkY34YRC5T_cjs.activityLabel(e) });
|
|
3502
3803
|
}
|
|
3503
3804
|
return rows;
|
|
3504
3805
|
}
|
|
@@ -3544,6 +3845,7 @@ exports.Citations = Citations;
|
|
|
3544
3845
|
exports.Close = Close;
|
|
3545
3846
|
exports.Copy = Copy;
|
|
3546
3847
|
exports.CopyButton = CopyButton;
|
|
3848
|
+
exports.DEFAULT_STREAMING_OPTIONS = DEFAULT_STREAMING_OPTIONS;
|
|
3547
3849
|
exports.EntityBadge = EntityBadge;
|
|
3548
3850
|
exports.EntitySelector = EntitySelector;
|
|
3549
3851
|
exports.EventLog = EventLog;
|
|
@@ -3611,5 +3913,5 @@ exports.useResolvedClassNames = useResolvedClassNames;
|
|
|
3611
3913
|
exports.useSources = useSources;
|
|
3612
3914
|
exports.withoutSourcesLine = withoutSourcesLine;
|
|
3613
3915
|
exports.writeClipboard = writeClipboard;
|
|
3614
|
-
//# sourceMappingURL=chunk-
|
|
3615
|
-
//# sourceMappingURL=chunk-
|
|
3916
|
+
//# sourceMappingURL=chunk-ESV52ERB.cjs.map
|
|
3917
|
+
//# sourceMappingURL=chunk-ESV52ERB.cjs.map
|