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