@antipopp/agno-react 0.2.0 → 0.4.0
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 +1 -0
- package/dist/index.d.mts +256 -4
- package/dist/index.d.ts +256 -4
- package/dist/index.js +709 -188
- package/dist/index.mjs +677 -188
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -46,35 +46,661 @@ function useToolHandlers() {
|
|
|
46
46
|
return useContext2(ToolHandlerContext);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// src/components/GenerativeUIRenderer.tsx
|
|
50
|
+
import React3 from "react";
|
|
51
|
+
|
|
52
|
+
// src/utils/component-registry.ts
|
|
53
|
+
var ComponentRegistry = class _ComponentRegistry {
|
|
54
|
+
constructor() {
|
|
55
|
+
this.components = /* @__PURE__ */ new Map();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the singleton instance
|
|
59
|
+
*/
|
|
60
|
+
static getInstance() {
|
|
61
|
+
if (!_ComponentRegistry.instance) {
|
|
62
|
+
_ComponentRegistry.instance = new _ComponentRegistry();
|
|
63
|
+
}
|
|
64
|
+
return _ComponentRegistry.instance;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Register a component renderer
|
|
68
|
+
*/
|
|
69
|
+
register(type, renderer) {
|
|
70
|
+
this.components.set(type, renderer);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Register multiple components at once
|
|
74
|
+
*/
|
|
75
|
+
registerBatch(components) {
|
|
76
|
+
Object.entries(components).forEach(([type, renderer]) => {
|
|
77
|
+
this.register(type, renderer);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get a registered component renderer
|
|
82
|
+
*/
|
|
83
|
+
get(type) {
|
|
84
|
+
return this.components.get(type);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if a component is registered
|
|
88
|
+
*/
|
|
89
|
+
has(type) {
|
|
90
|
+
return this.components.has(type);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Unregister a component
|
|
94
|
+
*/
|
|
95
|
+
unregister(type) {
|
|
96
|
+
this.components.delete(type);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get all registered component types
|
|
100
|
+
*/
|
|
101
|
+
getRegisteredTypes() {
|
|
102
|
+
return Array.from(this.components.keys());
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Clear all registered components
|
|
106
|
+
*/
|
|
107
|
+
clear() {
|
|
108
|
+
this.components.clear();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
function getComponentRegistry() {
|
|
112
|
+
return ComponentRegistry.getInstance();
|
|
113
|
+
}
|
|
114
|
+
function registerChartComponent(name, renderer) {
|
|
115
|
+
getComponentRegistry().register(`chart:${name}`, renderer);
|
|
116
|
+
}
|
|
117
|
+
function getChartComponent(name) {
|
|
118
|
+
return getComponentRegistry().get(`chart:${name}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/hooks/useAgnoToolExecution.ts
|
|
122
|
+
import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
123
|
+
var customRenderRegistry = /* @__PURE__ */ new Map();
|
|
124
|
+
function registerCustomRender(renderFn) {
|
|
125
|
+
const key = `custom-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
126
|
+
customRenderRegistry.set(key, renderFn);
|
|
127
|
+
return key;
|
|
128
|
+
}
|
|
129
|
+
function getCustomRender(key) {
|
|
130
|
+
return customRenderRegistry.get(key);
|
|
131
|
+
}
|
|
132
|
+
function isToolHandlerResult(value) {
|
|
133
|
+
return value && typeof value === "object" && ("data" in value || "ui" in value);
|
|
134
|
+
}
|
|
135
|
+
function isUIComponentSpec(value) {
|
|
136
|
+
return value && typeof value === "object" && "type" in value;
|
|
137
|
+
}
|
|
138
|
+
function processToolResult(result, _tool) {
|
|
139
|
+
if (isToolHandlerResult(result)) {
|
|
140
|
+
const { data, ui } = result;
|
|
141
|
+
let uiComponent = void 0;
|
|
142
|
+
if (ui) {
|
|
143
|
+
if (ui.type === "custom" && typeof ui.render === "function") {
|
|
144
|
+
const renderKey = registerCustomRender(ui.render);
|
|
145
|
+
uiComponent = {
|
|
146
|
+
...ui,
|
|
147
|
+
renderKey,
|
|
148
|
+
render: void 0
|
|
149
|
+
// Don't store the function itself
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
uiComponent = ui;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
resultData: typeof data === "string" ? data : JSON.stringify(data),
|
|
157
|
+
uiComponent
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (isUIComponentSpec(result)) {
|
|
161
|
+
let uiComponent;
|
|
162
|
+
if (result.type === "custom" && typeof result.render === "function") {
|
|
163
|
+
const renderKey = registerCustomRender(result.render);
|
|
164
|
+
uiComponent = {
|
|
165
|
+
...result,
|
|
166
|
+
renderKey,
|
|
167
|
+
render: void 0
|
|
168
|
+
};
|
|
169
|
+
} else {
|
|
170
|
+
uiComponent = result;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
resultData: JSON.stringify(result),
|
|
174
|
+
uiComponent
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
resultData: typeof result === "string" ? result : JSON.stringify(result),
|
|
179
|
+
uiComponent: void 0
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
183
|
+
const client = useAgnoClient();
|
|
184
|
+
const toolHandlerContext = useToolHandlers();
|
|
185
|
+
const mergedHandlers = useMemo2(() => {
|
|
186
|
+
const globalHandlers = toolHandlerContext?.handlers || {};
|
|
187
|
+
return { ...globalHandlers, ...handlers };
|
|
188
|
+
}, [toolHandlerContext?.handlers, handlers]);
|
|
189
|
+
const [pendingTools, setPendingTools] = useState2([]);
|
|
190
|
+
const [isPaused, setIsPaused] = useState2(false);
|
|
191
|
+
const [isExecuting, setIsExecuting] = useState2(false);
|
|
192
|
+
const [executionError, setExecutionError] = useState2();
|
|
193
|
+
useEffect2(() => {
|
|
194
|
+
const handleRunPaused = (event) => {
|
|
195
|
+
setIsPaused(true);
|
|
196
|
+
setPendingTools(event.tools);
|
|
197
|
+
setExecutionError(void 0);
|
|
198
|
+
};
|
|
199
|
+
const handleRunContinued = () => {
|
|
200
|
+
setIsPaused(false);
|
|
201
|
+
setPendingTools([]);
|
|
202
|
+
setIsExecuting(false);
|
|
203
|
+
setExecutionError(void 0);
|
|
204
|
+
};
|
|
205
|
+
client.on("run:paused", handleRunPaused);
|
|
206
|
+
client.on("run:continued", handleRunContinued);
|
|
207
|
+
return () => {
|
|
208
|
+
client.off("run:paused", handleRunPaused);
|
|
209
|
+
client.off("run:continued", handleRunContinued);
|
|
210
|
+
};
|
|
211
|
+
}, [client]);
|
|
212
|
+
const executeAndContinue = useCallback2(async () => {
|
|
213
|
+
if (!isPaused || pendingTools.length === 0) {
|
|
214
|
+
console.warn("[useAgnoToolExecution] Cannot execute: no pending tools");
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
setIsExecuting(true);
|
|
218
|
+
setExecutionError(void 0);
|
|
219
|
+
try {
|
|
220
|
+
const updatedTools = await Promise.all(
|
|
221
|
+
pendingTools.map(async (tool) => {
|
|
222
|
+
const handler = mergedHandlers[tool.tool_name];
|
|
223
|
+
if (!handler) {
|
|
224
|
+
return {
|
|
225
|
+
...tool,
|
|
226
|
+
result: JSON.stringify({
|
|
227
|
+
error: `No handler registered for ${tool.tool_name}`
|
|
228
|
+
})
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
try {
|
|
232
|
+
const result = await handler(tool.tool_args);
|
|
233
|
+
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
234
|
+
return {
|
|
235
|
+
...tool,
|
|
236
|
+
result: resultData,
|
|
237
|
+
ui_component: uiComponent
|
|
238
|
+
};
|
|
239
|
+
} catch (error) {
|
|
240
|
+
return {
|
|
241
|
+
...tool,
|
|
242
|
+
result: JSON.stringify({
|
|
243
|
+
error: error instanceof Error ? error.message : String(error)
|
|
244
|
+
})
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
const toolsWithUI = updatedTools.filter((t) => t.ui_component);
|
|
250
|
+
if (toolsWithUI.length > 0) {
|
|
251
|
+
client.emit("ui:render", {
|
|
252
|
+
tools: updatedTools,
|
|
253
|
+
runId: client.getState().pausedRunId
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
client.addToolCallsToLastMessage(updatedTools);
|
|
257
|
+
await client.continueRun(updatedTools);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
260
|
+
setExecutionError(errorMessage);
|
|
261
|
+
setIsExecuting(false);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}, [client, mergedHandlers, isPaused, pendingTools]);
|
|
265
|
+
useEffect2(() => {
|
|
266
|
+
const handleSessionLoaded = async (_sessionId) => {
|
|
267
|
+
const messages = client.getMessages();
|
|
268
|
+
for (const message of messages) {
|
|
269
|
+
if (!message.tool_calls)
|
|
270
|
+
continue;
|
|
271
|
+
for (const tool of message.tool_calls) {
|
|
272
|
+
if (tool.ui_component)
|
|
273
|
+
continue;
|
|
274
|
+
const handler = mergedHandlers[tool.tool_name];
|
|
275
|
+
if (!handler)
|
|
276
|
+
continue;
|
|
277
|
+
try {
|
|
278
|
+
const result = await handler(tool.tool_args);
|
|
279
|
+
const { uiComponent } = processToolResult(result, tool);
|
|
280
|
+
if (uiComponent) {
|
|
281
|
+
client.hydrateToolCallUI(tool.tool_call_id, uiComponent);
|
|
282
|
+
}
|
|
283
|
+
} catch (err) {
|
|
284
|
+
console.error(`Failed to hydrate UI for ${tool.tool_name}:`, err);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
client.on("session:loaded", handleSessionLoaded);
|
|
290
|
+
return () => {
|
|
291
|
+
client.off("session:loaded", handleSessionLoaded);
|
|
292
|
+
};
|
|
293
|
+
}, [client, mergedHandlers]);
|
|
294
|
+
const executeTools = useCallback2(
|
|
295
|
+
async (tools) => {
|
|
296
|
+
return Promise.all(
|
|
297
|
+
tools.map(async (tool) => {
|
|
298
|
+
const handler = mergedHandlers[tool.tool_name];
|
|
299
|
+
if (!handler)
|
|
300
|
+
return tool;
|
|
301
|
+
try {
|
|
302
|
+
const result = await handler(tool.tool_args);
|
|
303
|
+
const { resultData, uiComponent } = processToolResult(result, tool);
|
|
304
|
+
return {
|
|
305
|
+
...tool,
|
|
306
|
+
result: resultData,
|
|
307
|
+
ui_component: uiComponent
|
|
308
|
+
};
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return {
|
|
311
|
+
...tool,
|
|
312
|
+
result: JSON.stringify({
|
|
313
|
+
error: error instanceof Error ? error.message : String(error)
|
|
314
|
+
})
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
},
|
|
320
|
+
[mergedHandlers]
|
|
321
|
+
);
|
|
322
|
+
const continueWithResults = useCallback2(
|
|
323
|
+
async (tools) => {
|
|
324
|
+
if (!isPaused) {
|
|
325
|
+
throw new Error("No paused run to continue");
|
|
326
|
+
}
|
|
327
|
+
setIsExecuting(true);
|
|
328
|
+
try {
|
|
329
|
+
await client.continueRun(tools);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
setIsExecuting(false);
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
[client, isPaused]
|
|
336
|
+
);
|
|
337
|
+
useEffect2(() => {
|
|
338
|
+
if (autoExecute && isPaused && !isExecuting && pendingTools.length > 0) {
|
|
339
|
+
executeAndContinue();
|
|
340
|
+
}
|
|
341
|
+
}, [autoExecute, isPaused, isExecuting, pendingTools.length, executeAndContinue]);
|
|
342
|
+
return {
|
|
343
|
+
/** Whether the run is currently paused awaiting tool execution */
|
|
344
|
+
isPaused,
|
|
345
|
+
/** Whether tools are currently being executed */
|
|
346
|
+
isExecuting,
|
|
347
|
+
/** Tools awaiting execution */
|
|
348
|
+
pendingTools,
|
|
349
|
+
/** Execute all pending tools and continue the run */
|
|
350
|
+
executeAndContinue,
|
|
351
|
+
/** Execute specific tools and return results without continuing */
|
|
352
|
+
executeTools,
|
|
353
|
+
/** Continue the run with manually provided tool results */
|
|
354
|
+
continueWithResults,
|
|
355
|
+
/** Error from tool execution, if any */
|
|
356
|
+
executionError
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/components/GenerativeUIRenderer.tsx
|
|
361
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
362
|
+
var UIErrorBoundary = class extends React3.Component {
|
|
363
|
+
constructor(props) {
|
|
364
|
+
super(props);
|
|
365
|
+
this.state = { hasError: false };
|
|
366
|
+
}
|
|
367
|
+
static getDerivedStateFromError(error) {
|
|
368
|
+
return { hasError: true, error };
|
|
369
|
+
}
|
|
370
|
+
componentDidCatch(error, errorInfo) {
|
|
371
|
+
console.error("[GenerativeUIRenderer] Error rendering component:", error, errorInfo);
|
|
372
|
+
this.props.onError?.(error);
|
|
373
|
+
}
|
|
374
|
+
render() {
|
|
375
|
+
if (this.state.hasError) {
|
|
376
|
+
return this.props.fallback || /* @__PURE__ */ jsxs("div", { className: "p-4 border border-red-300 rounded-md bg-red-50 text-red-800", children: [
|
|
377
|
+
/* @__PURE__ */ jsx3("p", { className: "font-semibold", children: "Failed to render UI component" }),
|
|
378
|
+
/* @__PURE__ */ jsx3("p", { className: "text-sm mt-1", children: this.state.error?.message || "Unknown error" })
|
|
379
|
+
] });
|
|
380
|
+
}
|
|
381
|
+
return this.props.children;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
function GenerativeUIRenderer({
|
|
385
|
+
spec,
|
|
386
|
+
className,
|
|
387
|
+
onError
|
|
388
|
+
}) {
|
|
389
|
+
const registry = getComponentRegistry();
|
|
390
|
+
if (spec.type === "custom") {
|
|
391
|
+
const customSpec = spec;
|
|
392
|
+
if (customSpec.renderKey) {
|
|
393
|
+
const renderFn = getCustomRender(customSpec.renderKey);
|
|
394
|
+
if (renderFn) {
|
|
395
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsx3("div", { className, children: renderFn(customSpec.props || {}) }) });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return /* @__PURE__ */ jsxs("div", { className: `p-4 border border-yellow-300 rounded-md bg-yellow-50 text-yellow-800 ${className || ""}`, children: [
|
|
399
|
+
/* @__PURE__ */ jsx3("p", { className: "font-semibold", children: "Custom component not available" }),
|
|
400
|
+
/* @__PURE__ */ jsx3("p", { className: "text-sm mt-1", children: "The custom render function for this component is not available." })
|
|
401
|
+
] });
|
|
402
|
+
}
|
|
403
|
+
if (spec.type === "chart") {
|
|
404
|
+
const chartSpec = spec;
|
|
405
|
+
const chartType = `chart:${chartSpec.component}`;
|
|
406
|
+
if (registry.has(chartType)) {
|
|
407
|
+
const ChartRenderer = registry.get(chartType);
|
|
408
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsxs("div", { className, children: [
|
|
409
|
+
chartSpec.title && /* @__PURE__ */ jsx3("h3", { className: "font-semibold mb-2", children: chartSpec.title }),
|
|
410
|
+
chartSpec.description && /* @__PURE__ */ jsx3("p", { className: "text-sm text-gray-600 mb-4", children: chartSpec.description }),
|
|
411
|
+
/* @__PURE__ */ jsx3(ChartRenderer, { ...chartSpec.props })
|
|
412
|
+
] }) });
|
|
413
|
+
}
|
|
414
|
+
return /* @__PURE__ */ jsxs("div", { className: `p-4 border border-gray-300 rounded-md ${className || ""}`, children: [
|
|
415
|
+
/* @__PURE__ */ jsx3("p", { className: "font-semibold mb-2", children: chartSpec.title || "Chart Data" }),
|
|
416
|
+
chartSpec.description && /* @__PURE__ */ jsx3("p", { className: "text-sm text-gray-600 mb-2", children: chartSpec.description }),
|
|
417
|
+
/* @__PURE__ */ jsx3("pre", { className: "text-xs bg-gray-100 p-2 rounded overflow-auto", children: JSON.stringify(chartSpec.props.data, null, 2) })
|
|
418
|
+
] });
|
|
419
|
+
}
|
|
420
|
+
if (spec.type === "card-grid") {
|
|
421
|
+
const cardGridSpec = spec;
|
|
422
|
+
if (registry.has("card-grid")) {
|
|
423
|
+
const CardGridRenderer = registry.get("card-grid");
|
|
424
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsxs("div", { className, children: [
|
|
425
|
+
cardGridSpec.title && /* @__PURE__ */ jsx3("h3", { className: "font-semibold mb-2", children: cardGridSpec.title }),
|
|
426
|
+
cardGridSpec.description && /* @__PURE__ */ jsx3("p", { className: "text-sm text-gray-600 mb-4", children: cardGridSpec.description }),
|
|
427
|
+
/* @__PURE__ */ jsx3(CardGridRenderer, { ...cardGridSpec.props })
|
|
428
|
+
] }) });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (spec.type === "table") {
|
|
432
|
+
const tableSpec = spec;
|
|
433
|
+
if (registry.has("table")) {
|
|
434
|
+
const TableRenderer = registry.get("table");
|
|
435
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsxs("div", { className, children: [
|
|
436
|
+
tableSpec.title && /* @__PURE__ */ jsx3("h3", { className: "font-semibold mb-2", children: tableSpec.title }),
|
|
437
|
+
tableSpec.description && /* @__PURE__ */ jsx3("p", { className: "text-sm text-gray-600 mb-4", children: tableSpec.description }),
|
|
438
|
+
/* @__PURE__ */ jsx3(TableRenderer, { ...tableSpec.props })
|
|
439
|
+
] }) });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (spec.type === "markdown") {
|
|
443
|
+
const markdownSpec = spec;
|
|
444
|
+
if (registry.has("markdown")) {
|
|
445
|
+
const MarkdownRenderer = registry.get("markdown");
|
|
446
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsx3("div", { className, children: /* @__PURE__ */ jsx3(MarkdownRenderer, { ...markdownSpec.props }) }) });
|
|
447
|
+
}
|
|
448
|
+
return /* @__PURE__ */ jsx3("div", { className, children: markdownSpec.props.content });
|
|
449
|
+
}
|
|
450
|
+
if (spec.type === "artifact") {
|
|
451
|
+
const artifactSpec = spec;
|
|
452
|
+
return /* @__PURE__ */ jsx3(UIErrorBoundary, { onError, children: /* @__PURE__ */ jsxs("div", { className: `p-4 border rounded-md ${className || ""}`, children: [
|
|
453
|
+
artifactSpec.title && /* @__PURE__ */ jsx3("h3", { className: "font-semibold mb-4", children: artifactSpec.title }),
|
|
454
|
+
artifactSpec.description && /* @__PURE__ */ jsx3("p", { className: "text-sm text-gray-600 mb-4", children: artifactSpec.description }),
|
|
455
|
+
/* @__PURE__ */ jsx3("div", { className: "space-y-4", children: artifactSpec.props.content?.map((childSpec, index) => /* @__PURE__ */ jsx3(GenerativeUIRenderer, { spec: childSpec, onError }, index)) })
|
|
456
|
+
] }) });
|
|
457
|
+
}
|
|
458
|
+
return /* @__PURE__ */ jsxs("div", { className: `p-4 border border-gray-300 rounded-md ${className || ""}`, children: [
|
|
459
|
+
/* @__PURE__ */ jsx3("p", { className: "font-semibold", children: "Unsupported UI component" }),
|
|
460
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-gray-600 mt-1", children: [
|
|
461
|
+
"Component type: ",
|
|
462
|
+
spec.type
|
|
463
|
+
] })
|
|
464
|
+
] });
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/utils/ui-helpers.ts
|
|
468
|
+
function createBarChart(data, xKey, bars, options) {
|
|
469
|
+
return {
|
|
470
|
+
type: "chart",
|
|
471
|
+
component: "BarChart",
|
|
472
|
+
layout: options?.layout,
|
|
473
|
+
title: options?.title,
|
|
474
|
+
description: options?.description,
|
|
475
|
+
props: {
|
|
476
|
+
data,
|
|
477
|
+
xKey,
|
|
478
|
+
bars: bars.map((bar) => ({
|
|
479
|
+
key: bar.key,
|
|
480
|
+
label: bar.label || bar.key,
|
|
481
|
+
color: bar.color
|
|
482
|
+
})),
|
|
483
|
+
showLegend: options?.showLegend ?? true,
|
|
484
|
+
showGrid: options?.showGrid ?? true,
|
|
485
|
+
height: options?.height,
|
|
486
|
+
width: options?.width
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function createLineChart(data, xKey, lines, options) {
|
|
491
|
+
return {
|
|
492
|
+
type: "chart",
|
|
493
|
+
component: "LineChart",
|
|
494
|
+
layout: options?.layout,
|
|
495
|
+
title: options?.title,
|
|
496
|
+
description: options?.description,
|
|
497
|
+
props: {
|
|
498
|
+
data,
|
|
499
|
+
xKey,
|
|
500
|
+
lines: lines.map((line) => ({
|
|
501
|
+
key: line.key,
|
|
502
|
+
label: line.label || line.key,
|
|
503
|
+
color: line.color
|
|
504
|
+
})),
|
|
505
|
+
showLegend: options?.showLegend ?? true,
|
|
506
|
+
showGrid: options?.showGrid ?? true,
|
|
507
|
+
height: options?.height,
|
|
508
|
+
width: options?.width
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function createPieChart(data, dataKey, nameKey, options) {
|
|
513
|
+
return {
|
|
514
|
+
type: "chart",
|
|
515
|
+
component: "PieChart",
|
|
516
|
+
layout: options?.layout,
|
|
517
|
+
title: options?.title,
|
|
518
|
+
description: options?.description,
|
|
519
|
+
props: {
|
|
520
|
+
data,
|
|
521
|
+
pie: {
|
|
522
|
+
dataKey,
|
|
523
|
+
nameKey,
|
|
524
|
+
label: options?.showLabel ?? true
|
|
525
|
+
},
|
|
526
|
+
showLegend: options?.showLegend ?? true,
|
|
527
|
+
height: options?.height || 400,
|
|
528
|
+
width: options?.width
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
function createAreaChart(data, xKey, areas, options) {
|
|
533
|
+
return {
|
|
534
|
+
type: "chart",
|
|
535
|
+
component: "AreaChart",
|
|
536
|
+
layout: options?.layout,
|
|
537
|
+
title: options?.title,
|
|
538
|
+
description: options?.description,
|
|
539
|
+
props: {
|
|
540
|
+
data,
|
|
541
|
+
xKey,
|
|
542
|
+
areas: areas.map((area) => ({
|
|
543
|
+
key: area.key,
|
|
544
|
+
label: area.label || area.key,
|
|
545
|
+
color: area.color
|
|
546
|
+
})),
|
|
547
|
+
showLegend: options?.showLegend ?? true,
|
|
548
|
+
showGrid: options?.showGrid ?? true,
|
|
549
|
+
height: options?.height,
|
|
550
|
+
width: options?.width
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function createCardGrid(cards, options) {
|
|
555
|
+
return {
|
|
556
|
+
type: "card-grid",
|
|
557
|
+
layout: options?.layout,
|
|
558
|
+
title: options?.title,
|
|
559
|
+
description: options?.description,
|
|
560
|
+
props: {
|
|
561
|
+
cards,
|
|
562
|
+
columns: options?.columns || { default: 1, md: 2, lg: 3 },
|
|
563
|
+
variant: options?.variant || "default"
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function createCard(id, title, description, options) {
|
|
568
|
+
return {
|
|
569
|
+
id,
|
|
570
|
+
title,
|
|
571
|
+
description,
|
|
572
|
+
image: options?.image,
|
|
573
|
+
metadata: options?.metadata,
|
|
574
|
+
actions: options?.actions
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
function createTable(data, columns, options) {
|
|
578
|
+
return {
|
|
579
|
+
type: "table",
|
|
580
|
+
layout: options?.layout,
|
|
581
|
+
title: options?.title,
|
|
582
|
+
description: options?.description,
|
|
583
|
+
props: {
|
|
584
|
+
data,
|
|
585
|
+
columns,
|
|
586
|
+
sortable: options?.sortable ?? true,
|
|
587
|
+
filterable: options?.filterable,
|
|
588
|
+
pagination: options?.pagination,
|
|
589
|
+
density: options?.density || "comfortable"
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function createColumn(key, header, options) {
|
|
594
|
+
return {
|
|
595
|
+
key,
|
|
596
|
+
header,
|
|
597
|
+
width: options?.width,
|
|
598
|
+
sortable: options?.sortable,
|
|
599
|
+
cellType: options?.cellType || "text",
|
|
600
|
+
format: options?.format
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function createMarkdown(content, options) {
|
|
604
|
+
return {
|
|
605
|
+
type: "markdown",
|
|
606
|
+
layout: options?.layout,
|
|
607
|
+
title: options?.title,
|
|
608
|
+
description: options?.description,
|
|
609
|
+
props: {
|
|
610
|
+
content,
|
|
611
|
+
syntaxHighlight: options?.syntaxHighlight ?? true
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function createArtifact(content, options) {
|
|
616
|
+
return {
|
|
617
|
+
type: "artifact",
|
|
618
|
+
title: options?.title,
|
|
619
|
+
description: options?.description,
|
|
620
|
+
props: {
|
|
621
|
+
content,
|
|
622
|
+
variant: options?.variant || "default"
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function createSmartChart(data, options) {
|
|
627
|
+
if (!data || data.length === 0) {
|
|
628
|
+
return createBarChart([], "", [], options);
|
|
629
|
+
}
|
|
630
|
+
const firstItem = data[0];
|
|
631
|
+
const keys = Object.keys(firstItem);
|
|
632
|
+
const xKey = options?.xKey || keys.find(
|
|
633
|
+
(k) => ["name", "label", "category", "date", "time", "month", "year"].includes(k.toLowerCase())
|
|
634
|
+
) || keys[0];
|
|
635
|
+
const numericKeys = keys.filter((k) => k !== xKey && typeof firstItem[k] === "number");
|
|
636
|
+
const yKeys = options?.yKeys || numericKeys;
|
|
637
|
+
if ((options?.preferredType === "pie" || yKeys.length === 1) && typeof firstItem[xKey] === "string") {
|
|
638
|
+
return createPieChart(data, yKeys[0], xKey, options);
|
|
639
|
+
}
|
|
640
|
+
if (options?.preferredType === "line" || xKey.toLowerCase().includes("date") || xKey.toLowerCase().includes("time") || xKey.toLowerCase().includes("month") || xKey.toLowerCase().includes("year")) {
|
|
641
|
+
return createLineChart(
|
|
642
|
+
data,
|
|
643
|
+
xKey,
|
|
644
|
+
yKeys.map((key) => ({ key })),
|
|
645
|
+
options
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
return createBarChart(
|
|
649
|
+
data,
|
|
650
|
+
xKey,
|
|
651
|
+
yKeys.map((key) => ({ key })),
|
|
652
|
+
options
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
function createToolResult(data, ui) {
|
|
656
|
+
return { data, ui };
|
|
657
|
+
}
|
|
658
|
+
function resultWithBarChart(data, xKey, bars, options) {
|
|
659
|
+
return createToolResult(data, createBarChart(data, xKey, bars, options));
|
|
660
|
+
}
|
|
661
|
+
function resultWithSmartChart(data, options) {
|
|
662
|
+
return createToolResult(data, createSmartChart(data, options));
|
|
663
|
+
}
|
|
664
|
+
function resultWithCardGrid(cards, options) {
|
|
665
|
+
return createToolResult(cards, createCardGrid(cards, options));
|
|
666
|
+
}
|
|
667
|
+
function resultWithTable(data, columns, options) {
|
|
668
|
+
return createToolResult(data, createTable(data, columns, options));
|
|
669
|
+
}
|
|
670
|
+
|
|
49
671
|
// src/hooks/useAgnoChat.ts
|
|
50
|
-
import { useState as
|
|
672
|
+
import { useState as useState3, useEffect as useEffect3, useCallback as useCallback3 } from "react";
|
|
51
673
|
function useAgnoChat() {
|
|
52
674
|
const client = useAgnoClient();
|
|
53
|
-
const [messages, setMessages] =
|
|
54
|
-
const [state, setState] =
|
|
55
|
-
const [error, setError] =
|
|
56
|
-
|
|
675
|
+
const [messages, setMessages] = useState3(client.getMessages());
|
|
676
|
+
const [state, setState] = useState3(client.getState());
|
|
677
|
+
const [error, setError] = useState3();
|
|
678
|
+
useEffect3(() => {
|
|
57
679
|
const handleMessageUpdate = (updatedMessages) => {
|
|
58
|
-
console.log("[useAgnoChat] message:update event received, messages:", updatedMessages.length);
|
|
59
680
|
setMessages(updatedMessages);
|
|
60
681
|
};
|
|
61
682
|
const handleMessageComplete = (updatedMessages) => {
|
|
62
|
-
console.log("[useAgnoChat] message:complete event received, messages:", updatedMessages.length);
|
|
63
683
|
setMessages(updatedMessages);
|
|
64
684
|
};
|
|
65
685
|
const handleMessageError = (errorMessage) => {
|
|
66
|
-
console.log("[useAgnoChat] message:error event received:", errorMessage);
|
|
67
686
|
setError(errorMessage);
|
|
68
687
|
};
|
|
69
688
|
const handleStateChange = (newState) => {
|
|
70
|
-
console.log("[useAgnoChat] state:change event received");
|
|
71
689
|
setState(newState);
|
|
72
690
|
};
|
|
691
|
+
const handleUIRender = (event) => {
|
|
692
|
+
const { tools } = event;
|
|
693
|
+
for (const tool of tools) {
|
|
694
|
+
if (tool.ui_component) {
|
|
695
|
+
client.hydrateToolCallUI(tool.tool_call_id, tool.ui_component);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
};
|
|
73
699
|
client.on("message:update", handleMessageUpdate);
|
|
74
700
|
client.on("message:complete", handleMessageComplete);
|
|
75
701
|
client.on("message:error", handleMessageError);
|
|
76
702
|
client.on("state:change", handleStateChange);
|
|
77
|
-
|
|
703
|
+
client.on("ui:render", handleUIRender);
|
|
78
704
|
setMessages(client.getMessages());
|
|
79
705
|
setState(client.getState());
|
|
80
706
|
return () => {
|
|
@@ -82,9 +708,10 @@ function useAgnoChat() {
|
|
|
82
708
|
client.off("message:complete", handleMessageComplete);
|
|
83
709
|
client.off("message:error", handleMessageError);
|
|
84
710
|
client.off("state:change", handleStateChange);
|
|
711
|
+
client.off("ui:render", handleUIRender);
|
|
85
712
|
};
|
|
86
713
|
}, [client]);
|
|
87
|
-
const sendMessage =
|
|
714
|
+
const sendMessage = useCallback3(
|
|
88
715
|
async (message, options) => {
|
|
89
716
|
setError(void 0);
|
|
90
717
|
try {
|
|
@@ -97,7 +724,7 @@ function useAgnoChat() {
|
|
|
97
724
|
},
|
|
98
725
|
[client]
|
|
99
726
|
);
|
|
100
|
-
const clearMessages =
|
|
727
|
+
const clearMessages = useCallback3(() => {
|
|
101
728
|
client.clearMessages();
|
|
102
729
|
setMessages([]);
|
|
103
730
|
setError(void 0);
|
|
@@ -114,16 +741,16 @@ function useAgnoChat() {
|
|
|
114
741
|
}
|
|
115
742
|
|
|
116
743
|
// src/hooks/useAgnoSession.ts
|
|
117
|
-
import { useState as
|
|
744
|
+
import { useState as useState4, useEffect as useEffect4, useCallback as useCallback4 } from "react";
|
|
118
745
|
function useAgnoSession() {
|
|
119
746
|
const client = useAgnoClient();
|
|
120
|
-
const [sessions, setSessions] =
|
|
121
|
-
const [currentSessionId, setCurrentSessionId] =
|
|
747
|
+
const [sessions, setSessions] = useState4([]);
|
|
748
|
+
const [currentSessionId, setCurrentSessionId] = useState4(
|
|
122
749
|
client.getConfig().sessionId
|
|
123
750
|
);
|
|
124
|
-
const [isLoading, setIsLoading] =
|
|
125
|
-
const [error, setError] =
|
|
126
|
-
|
|
751
|
+
const [isLoading, setIsLoading] = useState4(false);
|
|
752
|
+
const [error, setError] = useState4();
|
|
753
|
+
useEffect4(() => {
|
|
127
754
|
const handleSessionLoaded = (sessionId) => {
|
|
128
755
|
setCurrentSessionId(sessionId);
|
|
129
756
|
};
|
|
@@ -147,7 +774,7 @@ function useAgnoSession() {
|
|
|
147
774
|
client.off("state:change", handleStateChange);
|
|
148
775
|
};
|
|
149
776
|
}, [client]);
|
|
150
|
-
const loadSession =
|
|
777
|
+
const loadSession = useCallback4(
|
|
151
778
|
async (sessionId) => {
|
|
152
779
|
setIsLoading(true);
|
|
153
780
|
setError(void 0);
|
|
@@ -165,7 +792,7 @@ function useAgnoSession() {
|
|
|
165
792
|
},
|
|
166
793
|
[client]
|
|
167
794
|
);
|
|
168
|
-
const fetchSessions =
|
|
795
|
+
const fetchSessions = useCallback4(async () => {
|
|
169
796
|
setIsLoading(true);
|
|
170
797
|
setError(void 0);
|
|
171
798
|
try {
|
|
@@ -191,12 +818,12 @@ function useAgnoSession() {
|
|
|
191
818
|
}
|
|
192
819
|
|
|
193
820
|
// src/hooks/useAgnoActions.ts
|
|
194
|
-
import { useState as
|
|
821
|
+
import { useState as useState5, useCallback as useCallback5 } from "react";
|
|
195
822
|
function useAgnoActions() {
|
|
196
823
|
const client = useAgnoClient();
|
|
197
|
-
const [isInitializing, setIsInitializing] =
|
|
198
|
-
const [error, setError] =
|
|
199
|
-
const initialize =
|
|
824
|
+
const [isInitializing, setIsInitializing] = useState5(false);
|
|
825
|
+
const [error, setError] = useState5();
|
|
826
|
+
const initialize = useCallback5(async () => {
|
|
200
827
|
setIsInitializing(true);
|
|
201
828
|
setError(void 0);
|
|
202
829
|
try {
|
|
@@ -210,7 +837,7 @@ function useAgnoActions() {
|
|
|
210
837
|
setIsInitializing(false);
|
|
211
838
|
}
|
|
212
839
|
}, [client]);
|
|
213
|
-
const checkStatus =
|
|
840
|
+
const checkStatus = useCallback5(async () => {
|
|
214
841
|
setError(void 0);
|
|
215
842
|
try {
|
|
216
843
|
return await client.checkStatus();
|
|
@@ -220,7 +847,7 @@ function useAgnoActions() {
|
|
|
220
847
|
return false;
|
|
221
848
|
}
|
|
222
849
|
}, [client]);
|
|
223
|
-
const fetchAgents =
|
|
850
|
+
const fetchAgents = useCallback5(async () => {
|
|
224
851
|
setError(void 0);
|
|
225
852
|
try {
|
|
226
853
|
return await client.fetchAgents();
|
|
@@ -230,7 +857,7 @@ function useAgnoActions() {
|
|
|
230
857
|
throw err;
|
|
231
858
|
}
|
|
232
859
|
}, [client]);
|
|
233
|
-
const fetchTeams =
|
|
860
|
+
const fetchTeams = useCallback5(async () => {
|
|
234
861
|
setError(void 0);
|
|
235
862
|
try {
|
|
236
863
|
return await client.fetchTeams();
|
|
@@ -240,7 +867,7 @@ function useAgnoActions() {
|
|
|
240
867
|
throw err;
|
|
241
868
|
}
|
|
242
869
|
}, [client]);
|
|
243
|
-
const updateConfig =
|
|
870
|
+
const updateConfig = useCallback5(
|
|
244
871
|
(updates) => {
|
|
245
872
|
client.updateConfig(updates);
|
|
246
873
|
},
|
|
@@ -256,169 +883,31 @@ function useAgnoActions() {
|
|
|
256
883
|
error
|
|
257
884
|
};
|
|
258
885
|
}
|
|
259
|
-
|
|
260
|
-
// src/hooks/useAgnoToolExecution.ts
|
|
261
|
-
import { useState as useState5, useEffect as useEffect4, useCallback as useCallback5, useMemo as useMemo2 } from "react";
|
|
262
|
-
function useAgnoToolExecution(handlers = {}, autoExecute = true) {
|
|
263
|
-
const client = useAgnoClient();
|
|
264
|
-
const toolHandlerContext = useToolHandlers();
|
|
265
|
-
const mergedHandlers = useMemo2(() => {
|
|
266
|
-
const globalHandlers = toolHandlerContext?.handlers || {};
|
|
267
|
-
return { ...globalHandlers, ...handlers };
|
|
268
|
-
}, [toolHandlerContext?.handlers, handlers]);
|
|
269
|
-
const [pendingTools, setPendingTools] = useState5([]);
|
|
270
|
-
const [isPaused, setIsPaused] = useState5(false);
|
|
271
|
-
const [isExecuting, setIsExecuting] = useState5(false);
|
|
272
|
-
const [executionError, setExecutionError] = useState5();
|
|
273
|
-
useEffect4(() => {
|
|
274
|
-
const handleRunPaused = (event) => {
|
|
275
|
-
console.log("[useAgnoToolExecution] Run paused event received");
|
|
276
|
-
console.log("[useAgnoToolExecution] Event:", event);
|
|
277
|
-
console.log("[useAgnoToolExecution] Tools:", event.tools);
|
|
278
|
-
console.log("[useAgnoToolExecution] Number of tools:", event.tools?.length);
|
|
279
|
-
event.tools?.forEach((tool, idx) => {
|
|
280
|
-
console.log(`[useAgnoToolExecution] Tool ${idx}:`, {
|
|
281
|
-
name: tool.tool_name,
|
|
282
|
-
id: tool.tool_call_id,
|
|
283
|
-
args_type: typeof tool.tool_args,
|
|
284
|
-
args: tool.tool_args
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
setIsPaused(true);
|
|
288
|
-
setPendingTools(event.tools);
|
|
289
|
-
setExecutionError(void 0);
|
|
290
|
-
};
|
|
291
|
-
const handleRunContinued = () => {
|
|
292
|
-
console.log("[useAgnoToolExecution] Run continued");
|
|
293
|
-
setIsPaused(false);
|
|
294
|
-
setPendingTools([]);
|
|
295
|
-
setIsExecuting(false);
|
|
296
|
-
setExecutionError(void 0);
|
|
297
|
-
};
|
|
298
|
-
client.on("run:paused", handleRunPaused);
|
|
299
|
-
client.on("run:continued", handleRunContinued);
|
|
300
|
-
return () => {
|
|
301
|
-
client.off("run:paused", handleRunPaused);
|
|
302
|
-
client.off("run:continued", handleRunContinued);
|
|
303
|
-
};
|
|
304
|
-
}, [client]);
|
|
305
|
-
const executeAndContinue = useCallback5(async () => {
|
|
306
|
-
if (!isPaused || pendingTools.length === 0) {
|
|
307
|
-
console.warn("[useAgnoToolExecution] Cannot execute: no pending tools");
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
setIsExecuting(true);
|
|
311
|
-
setExecutionError(void 0);
|
|
312
|
-
try {
|
|
313
|
-
console.log("[useAgnoToolExecution] Executing", pendingTools.length, "tools");
|
|
314
|
-
const updatedTools = await Promise.all(
|
|
315
|
-
pendingTools.map(async (tool) => {
|
|
316
|
-
const handler = mergedHandlers[tool.tool_name];
|
|
317
|
-
if (!handler) {
|
|
318
|
-
console.warn(`[useAgnoToolExecution] No handler for tool: ${tool.tool_name}`);
|
|
319
|
-
return {
|
|
320
|
-
...tool,
|
|
321
|
-
result: JSON.stringify({
|
|
322
|
-
error: `No handler registered for ${tool.tool_name}`
|
|
323
|
-
})
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
try {
|
|
327
|
-
console.log(`[useAgnoToolExecution] Executing tool: ${tool.tool_name}`, tool.tool_args);
|
|
328
|
-
const result = await handler(tool.tool_args);
|
|
329
|
-
console.log(`[useAgnoToolExecution] Tool result:`, result);
|
|
330
|
-
return {
|
|
331
|
-
...tool,
|
|
332
|
-
result: typeof result === "string" ? result : JSON.stringify(result)
|
|
333
|
-
};
|
|
334
|
-
} catch (error) {
|
|
335
|
-
console.error(`[useAgnoToolExecution] Tool execution error:`, error);
|
|
336
|
-
return {
|
|
337
|
-
...tool,
|
|
338
|
-
result: JSON.stringify({
|
|
339
|
-
error: error instanceof Error ? error.message : String(error)
|
|
340
|
-
})
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
);
|
|
345
|
-
console.log("[useAgnoToolExecution] Continuing run with results");
|
|
346
|
-
await client.continueRun(updatedTools);
|
|
347
|
-
} catch (error) {
|
|
348
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
349
|
-
console.error("[useAgnoToolExecution] Failed to continue run:", errorMessage);
|
|
350
|
-
setExecutionError(errorMessage);
|
|
351
|
-
setIsExecuting(false);
|
|
352
|
-
throw error;
|
|
353
|
-
}
|
|
354
|
-
}, [client, mergedHandlers, isPaused, pendingTools]);
|
|
355
|
-
const executeTools = useCallback5(
|
|
356
|
-
async (tools) => {
|
|
357
|
-
return Promise.all(
|
|
358
|
-
tools.map(async (tool) => {
|
|
359
|
-
const handler = mergedHandlers[tool.tool_name];
|
|
360
|
-
if (!handler)
|
|
361
|
-
return tool;
|
|
362
|
-
try {
|
|
363
|
-
const result = await handler(tool.tool_args);
|
|
364
|
-
return {
|
|
365
|
-
...tool,
|
|
366
|
-
result: typeof result === "string" ? result : JSON.stringify(result)
|
|
367
|
-
};
|
|
368
|
-
} catch (error) {
|
|
369
|
-
return {
|
|
370
|
-
...tool,
|
|
371
|
-
result: JSON.stringify({
|
|
372
|
-
error: error instanceof Error ? error.message : String(error)
|
|
373
|
-
})
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
})
|
|
377
|
-
);
|
|
378
|
-
},
|
|
379
|
-
[mergedHandlers]
|
|
380
|
-
);
|
|
381
|
-
const continueWithResults = useCallback5(
|
|
382
|
-
async (tools) => {
|
|
383
|
-
if (!isPaused) {
|
|
384
|
-
throw new Error("No paused run to continue");
|
|
385
|
-
}
|
|
386
|
-
setIsExecuting(true);
|
|
387
|
-
try {
|
|
388
|
-
await client.continueRun(tools);
|
|
389
|
-
} catch (error) {
|
|
390
|
-
setIsExecuting(false);
|
|
391
|
-
throw error;
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
[client, isPaused]
|
|
395
|
-
);
|
|
396
|
-
useEffect4(() => {
|
|
397
|
-
if (autoExecute && isPaused && !isExecuting && pendingTools.length > 0) {
|
|
398
|
-
console.log("[useAgnoToolExecution] Auto-executing tools");
|
|
399
|
-
executeAndContinue();
|
|
400
|
-
}
|
|
401
|
-
}, [autoExecute, isPaused, isExecuting, pendingTools.length, executeAndContinue]);
|
|
402
|
-
return {
|
|
403
|
-
/** Whether the run is currently paused awaiting tool execution */
|
|
404
|
-
isPaused,
|
|
405
|
-
/** Whether tools are currently being executed */
|
|
406
|
-
isExecuting,
|
|
407
|
-
/** Tools awaiting execution */
|
|
408
|
-
pendingTools,
|
|
409
|
-
/** Execute all pending tools and continue the run */
|
|
410
|
-
executeAndContinue,
|
|
411
|
-
/** Execute specific tools and return results without continuing */
|
|
412
|
-
executeTools,
|
|
413
|
-
/** Continue the run with manually provided tool results */
|
|
414
|
-
continueWithResults,
|
|
415
|
-
/** Error from tool execution, if any */
|
|
416
|
-
executionError
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
886
|
export {
|
|
420
887
|
AgnoProvider,
|
|
888
|
+
ComponentRegistry,
|
|
889
|
+
GenerativeUIRenderer,
|
|
421
890
|
ToolHandlerProvider,
|
|
891
|
+
createAreaChart,
|
|
892
|
+
createArtifact,
|
|
893
|
+
createBarChart,
|
|
894
|
+
createCard,
|
|
895
|
+
createCardGrid,
|
|
896
|
+
createColumn,
|
|
897
|
+
createLineChart,
|
|
898
|
+
createMarkdown,
|
|
899
|
+
createPieChart,
|
|
900
|
+
createSmartChart,
|
|
901
|
+
createTable,
|
|
902
|
+
createToolResult,
|
|
903
|
+
getChartComponent,
|
|
904
|
+
getComponentRegistry,
|
|
905
|
+
getCustomRender,
|
|
906
|
+
registerChartComponent,
|
|
907
|
+
resultWithBarChart,
|
|
908
|
+
resultWithCardGrid,
|
|
909
|
+
resultWithSmartChart,
|
|
910
|
+
resultWithTable,
|
|
422
911
|
useAgnoActions,
|
|
423
912
|
useAgnoChat,
|
|
424
913
|
useAgnoClient,
|